Problem:


星座探し  

問題

あなたは星空の写真の中から星座を探している．写真には必ず，探したい星座と同じ形・向き・大きさの図形がちょうど一つ含まれている．ただし，写真の中には星座を構成する星以外に余分な星が写っている可能性がある．

例えば，図 1 の星座は図 2 の写真に含まれている（丸で囲んで示した）．与えられた星座の星の座標を x 方向に 2， y 方向に −3 だけ平行移動すると写真の中の位置になる．

探したい星座の形と写真に写っている星の位置が与えられたとき，星座の座標を写真の中の座標に変換するために平行移動するべき量を答えるプログラムを書け． 

  
  

  
図 1: 探したい星座図 2: 星空の写真

入力

入力は複数のデータセットからなる．各データセットは以下の形式で与えられる．

入力の 1 行目には探したい星座を構成する星の個数 m が書かれている．続く m 行には探したい星座を構成する m 個の星の x 座標と y 座標を示す整数が空白区切りで書かれている． m+2 行目には写真に写っている星の個数 n が書かれている．続く n 行には写真に写っている n 個の星の x 座標と y 座標を示す整数が空白区切りで書かれている．

星座を構成する m 個の星の位置はすべて異なる．また，写真に写っている n 個の星の位置はすべて異なる． 1 ≤ m ≤ 200， 1 ≤ n ≤ 1000 である．星の x 座標と y 座標はすべて 0 以上 1000000 以下である．

m が 0　のとき入力の終わりを示す. データセットの数は 5 を超えない．

出力

各データセットの出力は 1 行からなり， 2 個の整数を空白区切りで書く．これらは探したい星座の座標をどれだけ平行移動すれば写真の中の座標になるかを表す．最初の整数が x 方向に平行移動する量，次の整数が y 方向に平行移動する量である．

入出力例

入力例

5
8 5
6 4
4 3
7 10
0 10
10
10 5
2 7
9 7
8 10
10 2
1 2
8 1
6 7
6 0
0 9
5
904207 809784
845370 244806
499091 59863
638406 182509
435076 362268
10
757559 866424
114810 239537
519926 989458
461089 424480
674361 448440
81851 150384
459107 795405
299682 6700
254125 362183
50795 541942
0

出力例

2 -3
-384281 179674

入出力例の１つ目は上の図に対応している．

上記問題文と自動審判に使われるデータは、情報オリンピック日本委員会が作成し公開している問題文と採点用テストデータです。



Sample input:
5
8 5
6 4
4 3
7 10
0 10
10
10 5
2 7
9 7
8 10
10 2
1 2
8 1
6 7
6 0
0 9
5
904207 809784
845370 244806
499091 59863
638406 182509
435076 362268
10
757559 866424
114810 239537
519926 989458
461089 424480
674361 448440
81851 150384
459107 795405
299682 6700
254125 362183
50795 541942
0


Sample output:
2 -3
-384281 179674

Submission status: Accepted

Solution code:
import operator
for e in iter(input,'0'):
    target = [[*map(int,input().split())]for _ in[0]*int(e)]
    s,t = min(target)
    target = {(x - s, y - t) for x, y in target}
    max_tx = max(target)[0]
    b = {tuple(map(int,input().split()))for _ in[0]*int(input())}
    max_sx = max(map(operator.itemgetter(0), b))
    lim_x = max_sx - max_tx
    for x,y in b:
        if x > lim_x:continue
        for u,v in target:
            if (x + u, y + v) not in b:break
        else:
            print(x - s, y - t)
            break

Submission status: Accepted

Solution code:
import operator
for e in iter(input,'0'):
    target = [[*map(int,input().split())]for _ in[0]*int(e)]
    s,t = min(target)
    b = {tuple(map(int,input().split()))for _ in[0]*int(input())}
    m=max(b)[0] - max(target)[0] + s
    for x,y in b:
        if x>m:continue
        for u,v in target:
            if (x + u - s, y + v - t) not in b:break
        else:
            print(x - s, y - t)
            break

Submission status: Accepted

Solution code:
for e in iter(input,'0'):
 a=[[*map(int,input().split())]for _ in[0]*int(e)]
 s,t=min(a)
 b={tuple(map(int,input().split()))for _ in[0]*int(input())}
 m=max(b)[0]-max(a)[0]+s
 for x,y in b:
  if x>m:continue
  for u,v in a:
   if(x+u-s,y+v-t)not in b:break
  else:print(x-s,y-t);break

Submission status: Accepted

Solution code:
for e in iter(input,'0'):
 a=[[*map(int,input().split())]for _ in[0]*int(e)]
 s,t=min(a)
 b={tuple(map(int,input().split()))for _ in[0]*int(input())}
 m=max(b)[0]-max(a)[0]+s
 for x,y in b:
  if x<=m:
   for u,v in a:
    if(x+u-s,y+v-t)not in b:break
   else:print(x-s,y-t);break

Submission status: Accepted

Solution code:
def f(e):
 a=[[*map(int,input().split())]for _ in[0]*int(e)]
 s,t=min(a)
 b={tuple(map(int,input().split()))for _ in[0]*int(input())}
 m=max(b)[0]-max(a)[0]+s
 for x,y in b:
  if x<=m:
   for u,v in a:
    if(x+u-s,y+v-t)not in b:break
   else:return print(x-s,y-t)
for e in iter(input,'0'):f(e)

Submission status: Accepted

Solution code:
def f(e):
 a=[[*map(int,input().split())]for _ in[0]*int(e)]
 s,t=min(a)
 b={tuple(map(int,input().split()))for _ in[0]*int(input())}
 m=max(b)[0]-max(a)[0]+s
 for x,y in b:
  if x<=m:
   for u,v in a:
    if(x+u-s,y+v-t)not in b:break
   else:print(x-s,y-t);break
for e in iter(input,'0'):f(e)

Submission status: Accepted

Solution code:
# AOJ 0524: Searching Constellation
# Python3 2018.7.1 bal4u

def check(dx, dy):
	f = True
	for x, y in goal:
		if (x+dx, y+dy) not in star: 
			f = False
			break
	return f

while True:
	m = int(input())
	if m == 0: break
	goal, star = [], []
	for i in range(m):
		x, y = map(int, input().split())
		goal.append((x, y))
	for i in range(int(input())):
		x, y = map(int, input().split())
		star.append((x, y))
	for x, y in star:
		dx, dy = x-goal[0][0], y-goal[0][1]
		if check(dx, dy): break
	print(dx, dy)

Submission status: Accepted

Solution code:
# AOJ 0524: Searching Constellation
# Python3 2018.7.1 bal4u

def check(dx, dy):
	f = True
	for x, y in goal:
		if (x+dx, y+dy) not in tbl: 
			f = False
			break
	return f

while True:
	m = int(input())
	if m == 0: break
	goal, star, tbl = [], [], {}
	for i in range(m):
		goal.append(tuple(map(int, input().split())))
	for i in range(int(input())):
		x, y = map(int, input().split())
		star.append((x, y))
		tbl[x,y] = 1
	for x, y in star:
		dx, dy = x-goal[0][0], y-goal[0][1]
		if check(dx, dy): break
	print(dx, dy)

Submission status: Accepted

Solution code:
def int_array_input():
    return map(int, raw_input().split(' '))

while True:
    n = int(raw_input())
    if n == 0:
        break

    stars = [tuple(int_array_input()) for x in xrange(n)]

    m = int(raw_input())
    sky = set(tuple(int_array_input()) for x in xrange(m))

    for (nx, ny) in sky:
        dx = nx - stars[0][0]
        dy = ny - stars[0][1]

        f = True

        for (tx, ty) in stars[1:]:
            tx += dx
            ty += dy
            if not ((tx, ty) in sky):
                f = False
                break

        if f:
            print dx, dy
            break

Submission status: Accepted

Solution code:
while 1:
    m = int(raw_input())
    if m == 0:
        break
    mxys = [map(int, raw_input().split()) for i in range(m)]
    nxys = set(tuple(map(int, raw_input().split())) for i in range(int(raw_input())))
    for nxy in nxys:
        dx = nxy[0] - mxys[0][0]
        dy = nxy[1] - mxys[0][1]
        txys = set((mxy[0] + dx, mxy[1] + dy) for mxy in mxys)
        if txys.issubset(nxys):
            print dx, dy
            break

Submission status: Accepted

Solution code:
import sys

#fp = open("input.txt", "r")
fp = sys.stdin

while True:
    n = int(fp.readline()[:-1])
    if n == 0:
        break

    stella = [map(int, fp.readline()[:-1].split(" ")) for i in xrange(n)]

    m = int(fp.readline()[:-1])
    sky = [map(int, fp.readline()[:-1].split(" ")) for i in xrange(m)]

    trans_x = 0
    trans_y = 0
    for star in sky:
        trans_x = star[0] - stella[0][0]
        trans_y = star[1] - stella[0][1]
        flg = True
        for s in stella[1:]:
            if not [s[0] +trans_x, s[1]+trans_y] in sky:
                flg = False
                break
        if flg:
            break
    print trans_x,trans_y

Submission status: Accepted

Solution code:
while 1:
    f = []; s = [];
    m = input()
    if m==0: break
    comp = lambda x, y: cmp(x[1],y[1]) if x[0]==y[0] else cmp(x[0], y[0])
    for i in xrange(m):
        f.append(map(int, raw_input().split()))
    f.sort(cmp = comp)
    n = input()
    for i in xrange(n):
        s.append(map(int, raw_input().split()))
    s.sort(cmp = comp)

    for i in xrange(n):
        x0 = s[i][0] - f[0][0]
        y0 = s[i][1] - f[0][1]
        c = 1
        for j in xrange(i+1,n):
            if f[c][0]+x0==s[j][0] and f[c][1]+y0==s[j][1]:
                c+=1
            elif f[c][0]+x0<s[j][0] or (f[c][0]+x0==s[j][0] and f[c][1]+y0<s[j][1]):
                break
            if c==m : break;
        if c==m: break
    print "%d %d"%(x0, y0)

Submission status: Accepted

Solution code:
while 1:
    f = []; s = [];
    m = input()
    if m==0: break
    for i in xrange(m):
        f.append(map(int, raw_input().split()))
    n = input()
    for i in xrange(n):
        s.append(map(int, raw_input().split()))
    for i in range(n):
        x0 = s[i][0] - f[0][0]
        y0 = s[i][1] - f[0][1]
        flg = True
        for j in range(m):
            ff = [f[j][0]+x0, f[j][1]+y0]
            if not (ff in s):
                 flg = False; break;
        if flg:
            print "%d %d"%(x0, y0)
            break;

Submission status: Accepted

Solution code:
def Judge(dx, dy):
    for x, y in star:
        mx = x + dx
        my = y + dy
        if (mx, my) not in pic:
            return False
    return True

def search():
    for sx, sy in star:
        for px, py in pic:
            dx = px-sx
            dy = py-sy
            if Judge(dx, dy):
                print dx, dy
                return
while True:
    m = input()
    if m==0: break
    star = set([tuple(map(int, raw_input().split())) for i in range(m)])
    n = input()
    pic = set([tuple(map(int, raw_input().split())) for i in range(n)])
    search()

Submission status: Accepted

Solution code:
while True:
    try:
        a,da, b = [], [], []
        m = int(raw_input())
        for i in range(m):
            a.append(map(int, raw_input().split()))
        a = sorted(a)
        dax,day = [],[]
        for i in range(m):
            dax.append(a[i][0]-a[0][0])
            day.append(a[i][1]-a[0][1])
        n = int(raw_input())
        for i in range(n):
            b.append(map(int, raw_input().split()))
        b = sorted(b)
        bx,by = [],[]
        for i in b:
            bx.append(i[0])
            by.append(i[1])
        for i in range(n-m+1):
            for j in range(m):
                if bx.count(bx[i]+dax[j]) == 0 or by.count(by[i]+day[j]) == 0:
                    break
            else:
                print bx[i]-a[0][0],by[i]-a[0][1]
                break
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        a,da, b = [], [], []
        m = int(raw_input())
        for i in range(m):
            a.append(map(int, raw_input().split()))
        a = sorted(a)
        dax = []
        for i in range(m):
            dax.append(a[i][0]-a[0][0])
        n = int(raw_input())
        for i in range(n):
            b.append(map(int, raw_input().split()))
        b = sorted(b)
        bx = []
        for i in b:
            bx.append(i[0])
        for i in range(n-m+1):
            for j in range(m):
                if bx.count(bx[i]+dax[j]) == 0:
                    break
            else:
                print b[i][0]-a[0][0],b[i][1]-a[0][1]
                break
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        a,dax,b,bx = [],[],[],[]
        m = int(raw_input())
        for i in range(m):
            a.append(map(int, raw_input().split()))
        a = sorted(a)
        for i in range(m):
            dax.append(a[i][0]-a[0][0])
        n = int(raw_input())
        for i in range(n):
            b.append(map(int, raw_input().split()))
        b = sorted(b)
        for i in b:
            bx.append(i[0])
        for i in range(n-m+1):
            for j in range(m):
                if bx.count(bx[i]+dax[j]) == 0:
                    break
            else:
                print b[i][0]-a[0][0],b[i][1]-a[0][1]
                break
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        dax,bx = [],[]
        m = int(raw_input())
        a = sorted([list(map(int, raw_input().split())) for i in range(m)])
        for i in range(m):
            dax.append(a[i][0]-a[0][0])
        n = int(raw_input())
        b = sorted([list(map(int, raw_input().split())) for i in range(n)])
        for i in b:
            bx.append(i[0])
        for i in range(n-m+1):
            for j in range(m):
                if bx.count(bx[i]+dax[j]) == 0:
                    break
            else:
                print b[i][0]-a[0][0],b[i][1]-a[0][1]
                break
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        m = int(raw_input())
        a = sorted([list(map(int, raw_input().split())) for i in range(m)])
        dax = [a[i][0]-a[0][0] for i in range(m)]
        n = int(raw_input())
        b = sorted([list(map(int, raw_input().split())) for i in range(n)])
        bx = [b[i][0] for i in range(n)]
        for i in range(n-m+1):
            for j in range(m):
                if bx[i]+dax[j] not in bx:
                    break
            else:
                print b[i][0]-a[0][0],b[i][1]-a[0][1]
                break
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        m = int(raw_input())
        a = sorted([list(map(int, raw_input().split())) for i in xrange(m)])
        dax = [a[i][0]-a[0][0] for i in xrange(m)]
        n = int(raw_input())
        b = sorted([list(map(int, raw_input().split())) for i in xrange(n)])
        bx = [b[i][0] for i in xrange(n)]
        for i in xrange(n-m+1):
            for j in xrange(m):
                if bx[i]+dax[j] not in bx:
                    break
            else:
                print b[i][0]-a[0][0],b[i][1]-a[0][1]
                break
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        m = int(raw_input())
        a = sorted([list(map(int, raw_input().split())) for i in range(m)])
        dax = [a[i][0]-a[0][0] for i in range(m)]
        
        n = int(raw_input())
        b = sorted([list(map(int, raw_input().split())) for i in range(n)])
        bx = [b[i][0] for i in range(n)]
        
        for i in range(n-m):
            for da in dax:
                if bx[i]+da not in bx:
                    break
            else:
                print b[i][0]-a[0][0],b[i][1]-a[0][1]
                break
    except:
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Searching Constellation
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0524

"""
import sys


def solve(targets, stars):
    for tx, ty in targets:
        for sx, sy in stars:
            dx, dy = sx-tx, sy-ty
            s_starts = set(stars)
            for x, y in targets:
                px, py = x+dx, y+dy
                if (px, py) in s_starts:
                    s_starts.remove((px, py))
                else:
                    break
            else:
                return dx, dy


def main(args):
    while True:
        m = int(input())
        if m == 0:
            break
        targets = [tuple(int(x) for x in input().split()) for _ in range(m)]
        n = int(input())
        stars = [tuple(int(x) for x in input().split()) for _ in range(n)]
        ans = solve(targets, stars)
        print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
while 1:
    m = int(input())
    if m == 0:
        break

    target = []
    for _ in range(m):
        x, y = map(int, input().split())
        target.append([x, y])
    tx = target[0][0]
    ty = target[0][1]

    n = int(input())
    stars = []
    for _ in range(n):
        x, y = map(int, input().split())
        stars.append([x, y])

    for star in stars:
        off_x = star[0] - tx
        off_y = star[1] - ty
        for t in target:
            x = t[0] + off_x
            y = t[1] + off_y
            if [x, y] not in stars:
                break
        else:
            print(off_x, off_y)
            break

Submission status: Runtime Error

Solution code:
board = [[False]*1000001]*1000001
while True:
    m = int(input())
    if m == 0: break
    sx, sy = map(int, input().split())
    star = []
    for i in range(m-1):
        x, y = map(int, input().split())
        star.append((x-sx, y-sy))
    
    
    n = int(input())
    starlist = [tuple(map(int, input().split())) for i in range(n)]
    for i in range(n):
        board[starlist[i][0]][starlist[i][1]] = True
    for i in range(n):
        flag = True
        for j in range(len(star)):
            dx = starlist[i][0] + star[j][0]
            dy = starlist[i][1] + star[j][1]
            if board[dx][dy] == False:
                flag = False
                break
        if flag == True:
            print("{} {}".format(str(starlist[i][0] - sx), str(starlist[i][1] -sy)))
            break

Submission status: Runtime Error

Solution code:
import numpy as np
while 1:
    n = input()
    if n == 0: break
    p = np.array(sorted([map(int, raw_input().split()) for i in range(n)]))
    dist = [p[i] - p[0] for i in range(1,n)]
    m = input()
    q = np.array(sorted([map(int, raw_input().split()) for i in xrange(m)]))
    for p1 in q:
        for i in range(n-1):
            f = True
            for p2 in q:
                if np.all(p1 + dist[i] == p2):
                    f = False
                    break
            if f: break
        else:
            print p1[0] - p[0][0], p1[1] - p[0][1]

Submission status: Runtime Error

Solution code:
def main()
  while True:
    m = int(input())
    if not m: break
    seiza = []
    for i in range(m):
      seiza.append(list(map(int,input().split())))
    kijun = seiza.pop(0)
    
    n = int(input())
    hosi = []
    point = {}
    
    for i in range(n):
      x,y = map(int,input().split())
      point[x,y] = 1
      hosi.append([x,y])
  
    for a in hosi:
      dx,dy = a[0] - kijun[0], a[1] - kijun[1]
      for b in seiza:
        if not (b[0] + dx, b[1] + dy) in point:
          break
      else:
        print(dx,dy)
        break
main()

Submission status: Runtime Error

Solution code:
for e in iter(input,'0'):
 a=sorted([list(map(int,input().split()))for _ in[0]*int(e)],key=lambda x:x[0])
 b=sorted([tuple(map(int,input().split()))for _ in[0]*int(input())],key=lambda x:x[0])
 for s,t in b:
  if not set((u+s-a[0][0],v+t-a[0][1])for u,v in a)-set(b):print(x,y);break

Submission status: Runtime Error

Solution code:
for e in iter(input,'0'):
 a=sorted([list(map(int,input().split()))for _ in[0]*int(e)],key=lambda x:x[0])
 b=sorted([tuple(map(int,input().split()))for _ in[0]*int(input())],key=lambda x:x[0])
 for s,t in b:
  u,v=a[0]
  x,y=s-u,t-v
  for u,v in a:
   if (u+x,v+y)not in b:break
  else:print(x,y)

Submission status: Runtime Error

Solution code:
for e in iter(input,'0'):
 a=sorted([list(map(int,input().split()))for _ in[0]*int(e)],key=lambda x:x[0])
 b=sorted([list(map(int,input().split()))for _ in[0]*int(input())],key=lambda x:x[0])
 for s,t in b:
  u,v=a[0]
  x,y=s-u,t-v
  for u,v in a:
   if[u+x,v+y]not in b:break
  else:print(x,y)

Submission status: Runtime Error

Solution code:
for e in iter(input,'0'):
 a=[list(map(int,input().split()))for _ in[0]*int(e)]
 b=[list(map(int,input().split()))for _ in[0]*int(input())]
 for s,t in b:
  u,v=a[0]
  x,y=s-u,t-v
  for u,v in a:
   if[u+x,v+y]not in b:break
  else:print(x,y)

Submission status: Runtime Error

Solution code:
def f():
 for e in iter(input,'0'):
  a=[list(map(int,input().split()))for _ in[0]*int(m)]
  u,v=a[0]
  b=[tuple(map(int,input().split()))for _ in[0]*int(input())]
  for x,y in b:
   for s,t in a[1:]:
    if(x+s-u,y+t-v)not in b:return print(x-sx,y-sy)
f()

Submission status: Runtime Error

Solution code:
def f():
 for e in iter(input,'0'):
  a=[list(map(int,input().split()))for _ in[0]*int(e)]
  u,v=a[0]
  b=[tuple(map(int,input().split()))for _ in[0]*int(input())]
  for x,y in b:
   for s,t in a[1:]:
    if(x+s-u,y+t-v)not in b:return print(x-sx,y-sy)
f()

Submission status: Runtime Error

Solution code:
for e in iter(input,'0'):
 a=list({tuple(map(int,input().split())) for _ in range(int(e))})
 s,t=a[0]
 b={list(map(int,input().split())) for _ in range(int(input()))}
 for x,y in b:
  flag = True
  for u,v in a[1:]:
   if [x + u - s, y + v - t] not in b:
    flag = False
    break
  if flag == True:
   print(x - s, y - t)
   break

Submission status: Runtime Error

Solution code:
for e in iter(input,'0'):
 a={tuple(map(int,input().split())) for _ in range(int(e))}
 s,t=a[0]
 b={tuple(map(int,input().split())) for _ in range(int(input()))}
 for x,y in b:
  flag = True
  for u,v in a[1:]:
   if(x+u-s,y+v-t}not in b:
    flag = False
    break
  if flag == True:
   print(x - s, y - t)
   break

Submission status: Runtime Error

Solution code:
for e in iter(input,'0'):
 a={tuple(map(int,input().split())) for _ in range(int(e))}
 s,t=a[0]
 b={tuple(map(int,input().split())) for _ in range(int(input()))}
 for x,y in b:
  flag = True
  for u,v in a[1:]:
   if(x+u-s,y+v-t)not in b:
    flag = False
    break
  if flag == True:
   print(x - s, y - t)
   break

Submission status: Runtime Error

Solution code:
def f(e):
 a=list([*map(int,input().split())]for _ in range(int(e)))
 s,t=a[0]
 b={(*map(int,input().split()))for _ in range(int(input()))}
 for x,y in b:
  for u,v in a[1:]:
   if(x+u-s,y+v-t)not in b:break
  else:return print(x-s,y-t)
for e in iter(input,'0'):f(e)

Submission status: Runtime Error

Solution code:
import operator
for e in iter(input,'0'):
    target = [[*map(int,input().split()))]for _ in[0]*int(e)]
    bx, by = min(target)
    target = {(x - bx, y - by) for x, y in target}
    max_tx = max(map(operator.itemgetter(0), target))
    b = {tuple(map(int,input().split()))for _ in[0]*int(input())}
    max_sx = max(map(operator.itemgetter(0), b))
    lim_x = max_sx - max_tx
    for x,y in b:
        if x > lim_x:continue
        for u,v in a:
            if (x + tx, y + ty) not in b:break
        else:
            print(x - bx, y - by)
            break

Submission status: Runtime Error

Solution code:
import operator
for e in iter(input,'0'):
    target = [[*map(int,input().split())]for _ in[0]*int(e)]
    bx, by = min(target)
    target = {(x - bx, y - by) for x, y in target}
    max_tx = max(map(operator.itemgetter(0), target))
    b = {tuple(map(int,input().split()))for _ in[0]*int(input())}
    max_sx = max(map(operator.itemgetter(0), b))
    lim_x = max_sx - max_tx
    for x,y in b:
        if x > lim_x:continue
        for u,v in a:
            if (x + tx, y + ty) not in b:break
        else:
            print(x - bx, y - by)
            break

Submission status: Runtime Error

Solution code:
import operator
for e in iter(input,'0'):
    target = [[*map(int,input().split())]for _ in[0]*int(e)]
    bx, by = min(target)
    target = {(x - bx, y - by) for x, y in target}
    max_tx = max(map(operator.itemgetter(0), target))
    b = {tuple(map(int,input().split()))for _ in[0]*int(input())}
    max_sx = max(map(operator.itemgetter(0), b))
    lim_x = max_sx - max_tx
    for x,y in b:
        if x > lim_x:continue
        for u,v in target:
            if (x + tx, y + ty) not in b:break
        else:
            print(x - bx, y - by)
            break

Submission status: Runtime Error

Solution code:
import operator
for e in iter(input,'0'):
    target = [[*map(int,input().split())]for _ in[0]*int(e)]
    s,t = min(target)
    target = {(x - bx, y - by) for x, y in target}
    max_tx = max(map(lambda x:x[0], target))
    b = {tuple(map(int,input().split()))for _ in[0]*int(input())}
    max_sx = max(map(operator.itemgetter(0), b))
    lim_x = max_sx - max_tx
    for x,y in b:
        if x > lim_x:continue
        for u,v in target:
            if (x + u, y + v) not in b:break
        else:
            print(x - bx, y - by)
            break

Submission status: Runtime Error

Solution code:
import operator
for e in iter(input,'0'):
    target = [[*map(int,input().split())]for _ in[0]*int(e)]
    s,t = min(target)
    target = {(x - bx, y - by) for x, y in target}
    max_tx = max(map(lambda x:x[0], target))
    b = {tuple(map(int,input().split()))for _ in[0]*int(input())}
    max_sx = max(map(operator.itemgetter(0), b))
    lim_x = max_sx - max_tx
    for x,y in b:
        if x > lim_x:continue
        for u,v in target:
            if (x + u, y + v) not in b:break
        else:
            print(x - s, y - t)
            break