f | from itertools import permutations | f | from itertools import permutations |
| | | |
n | def get_input_sequence() -> list[list[int]]: | n | def get_sequence() -> list[list[int]]: |
| triples = [] | | triplets = [] |
| while True: | | while True: |
n | triple = input() | n | triplet = input() |
| if not triple: | | if not triplet: |
| break | | break |
n | triples.append([int(x) for x in triple.split(',')]) | n | triplets.append([int(x) for x in triplet.split(',')]) |
| return triples | | return triplets |
| | | |
n | def is_not_less(a: list[int], b: list[int]) -> bool: | n | def is_greater_or_equal(first: list[int], second: list[int]) -> bool: |
| for i, j, k in permutations([0, 1, 2]): | | for i, j, k in permutations([0, 1, 2]): |
n | if a[0] <= b[i] and a[1] <= b[j] and (a[2] <= b[k]): | n | if first[0] <= second[i] and first[1] <= second[j] and (first[2] |
| | | <= second[k]): |
| if a[0] < b[i] or a[1] < b[j] or a[2] < b[k]: | | if first[0] < second[i] or first[1] < second[j] or first[2] |
| | | < second[k]: |
| return False | | return False |
| return True | | return True |
| | | |
n | def find_first_not_less(triples) -> int: | n | def find_first_greater_or_equal(triplets) -> int: |
| n = len(triples) | | n = len(triplets) |
| for i in range(n): | | for i in range(n): |
n | is_not_less_than_all = True | n | is_greater_or_equal_to_all = True |
| for j in range(i + 1, n): | | for j in range(i + 1, n): |
n | if not is_not_less(triples[i], triples[j]): | n | if not is_greater_or_equal(triplets[i], triplets[j]): |
| is_not_less_than_all = False | | is_greater_or_equal_to_all = False |
| break | | break |
n | if is_not_less_than_all: | n | if is_greater_or_equal_to_all: |
| return i | | return i |
| return 0 | | return 0 |
| | | |
n | def sort_triples(triples: list[list[int]]) -> list[list[int]]: | n | def sort_triplets(triplets: list[list[int]]) -> list[list[int]]: |
| sorted_triples = [] | | sorted_triplets = [] |
| while triples: | | while triplets: |
| idx = find_first_not_less(triples) | | idx = find_first_greater_or_equal(triplets) |
| sorted_triples.insert(0, triples.pop(idx)) | | sorted_triplets.insert(0, triplets.pop(idx)) |
| return reversed(sorted_triples) | | return reversed(sorted_triplets) |
| | | |
n | def absolute_supreme() -> None: | n | def absolute_supremacy() -> None: |
| triples = get_input_sequence() | | triplets = get_sequence() |
| sorted_triples = sort_triples(triples) | | sorted_triplets = sort_triplets(triplets) |
| for triple in sorted_triples: | | for triplet in sorted_triplets: |
| print(', '.join(map(str, triple))) | | print(', '.join(map(str, triplet))) |
| if __name__ == '__main__': | | if __name__ == '__main__': |
t | absolute_supreme() | t | absolute_supremacy() |