#!/usr/bin/python3 def diag_coords(x, y): diag_num = x - y return (diag_num, y) def diag_coords2(x, y): diag_num = x + y return (diag_num, y) # cannons jsou trojice (i, x, y), setřízené primárně podle čísla diagonály a sekundárně podle y def get_threatened(cannons, diag_coord_func): previous_diag_num = None previous_cannon_id = None # projdeme kanóny postupně for cannon_id, x, y in cannons: diag_num, _ = diag_coord_func(x, y) # pokud je kanón ve stejné diagonále jako předchozí, tak se dvojice ohrožuje if previous_diag_num is not None and previous_diag_num == diag_num: print(previous_cannon_id, cannon_id) return True previous_diag_num = diag_num previous_cannon_id = cannon_id W, H, N = map(int, input().split()) cannons = [] for i in range(N): x, y = map(int, input().split()) cannons.append((i, x, y)) # třídění podle první diagonály (x-y, y) first_diag = sorted(cannons, key=lambda ixy: diag_coords(ixy[1], ixy[2])) # třídění podle druhé diagonály (x+y, y) second_diag = sorted(cannons, key=lambda ixy: diag_coords2(ixy[1], ixy[2])) # zkusíme první diagonálu if not get_threatened(first_diag, diag_coords): # a pokud nic nenajdeme, tak i druhou get_threatened(second_diag, diag_coords2)