f | import math | f | import math |
| | | |
n | def distance(galaxy1, galaxy2): | n | def calculate_distance(galaxy_a, galaxy_b): |
| return math.sqrt((galaxy1[0] - galaxy2[0]) ** 2 + (galaxy1[1] - gala | | return math.sqrt((galaxy_a[0] - galaxy_b[0]) ** 2 + (galaxy_a[1] - g |
| xy2[1]) ** 2 + (galaxy1[2] - galaxy2[2]) ** 2) | | alaxy_b[1]) ** 2 + (galaxy_a[2] - galaxy_b[2]) ** 2) |
| galaxies = [] | | galaxy_list = [] |
| while True: | | while True: |
n | line = input().strip() | n | input_line = input().strip() |
| if ' ' not in line: | | if ' ' not in input_line: |
| break | | break |
t | x, y, z, name = line.split() | t | coord_x, coord_y, coord_z, galaxy_name = input_line.split() |
| galaxies.append((float(x), float(y), float(z), name)) | | galaxy_list.append((float(coord_x), float(coord_y), float(coord_z), |
| | | galaxy_name)) |
| max_distance = 0 | | max_distance_found = 0 |
| farthest_galaxies = ('', '') | | most_distant_galaxies = ('', '') |
| for i in range(len(galaxies)): | | for first_galaxy_index in range(len(galaxy_list)): |
| for j in range(i + 1, len(galaxies)): | | for second_galaxy_index in range(first_galaxy_index + 1, len(galaxy_ |
| | | list)): |
| d = distance(galaxies[i], galaxies[j]) | | distance_between = calculate_distance(galaxy_list[first_galaxy_i |
| | | ndex], galaxy_list[second_galaxy_index]) |
| if d > max_distance: | | if distance_between > max_distance_found: |
| max_distance = d | | max_distance_found = distance_between |
| farthest_galaxies = tuple(sorted([galaxies[i][3], galaxies[j | | most_distant_galaxies = tuple(sorted([galaxy_list[first_gala |
| ][3]])) | | xy_index][3], galaxy_list[second_galaxy_index][3]])) |
| print(farthest_galaxies[0], farthest_galaxies[1]) | | print(most_distant_galaxies[0], most_distant_galaxies[1]) |