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: Wrong Answer

Solution code:
board = [[False]*1000001]*1000001
while True:
    m = int(input())
    if m == 0: break
    star = tuple(tuple(map(int, input().split())) for i in range(m))
    sx, sy = star[0]
    
    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)-1):
            dx = starlist[i][0] + star[j][0] - sx
            dy = starlist[i][1] + star[j][1] - sy
            if dx < 0 or 1000000 < dx or dy < 0 or 1000000 < dy or board[dx][dy] == False:
                flag = False
                break

        if flag == True:
            print("{} {}".format(starlist[i][0] - sx, starlist[i][1] -sy))
            break

Submission status: Wrong Answer

Solution code:
while 1:
    n = input()
    if n == 0: break
    p = set([tuple(map(int, raw_input().split())) for i in range(n)])
    m = input()
    q = set([tuple(map(int, raw_input().split())) for i in xrange(m)])
    for px, py in p:
        for qx, qy in q:
            dx = qx - px
            dy = qy - py
            for x, y in p:
                mx = x + dx
                my = y + dy
                if (mx, my) not in q:
                    break
            else:
                print dx, dy
                break

Submission status: Wrong Answer

Solution code:
while 1:
    n = input()
    if n == 0: break
    p = set([tuple(map(int, raw_input().split())) for i in range(n)])
    m = input()
    q = set([tuple(map(int, raw_input().split())) for i in xrange(m)])
    for px, py in p:
        for qx, qy in q:
            dx = qx - px
            dy = qy - py
            for x, y in p:
                mx = x + dx
                my = y + dy
                if (mx, my) not in q:
                    break
            else:
                print dx, dy
            break

Submission status: Wrong Answer

Solution code:
while 1:
    n = input()
    if n == 0: break
    p = set([tuple(map(int, raw_input().split())) for i in range(n)])
    m = input()
    q = set([tuple(map(int, raw_input().split())) for i in xrange(m)])
    for px, py in p:
        for qx, qy in q:
            f = 0
            dx = qx - px
            dy = qy - py
            for x, y in p:
                mx = x + dx
                my = y + dy
                if (mx, my) not in q:
                    break
            else:
                f = 1
                print dx, dy
            if f: break

Submission status: Wrong Answer

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])
    print(a)
    print(b)
    for s,t in b:
        u,v=a[0]
        x,y=s-u,t-v
        if not set((u+x,v+y)for u,v in a)-set(b):print(x,y);break

Submission status: Wrong Answer

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-u,y-v)
f()

Submission status: Wrong Answer

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:break
   else:return print(x-u,y-v)
f()

Submission status: Wrong Answer

Solution code:
def f():
 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:return print(x,y)
f()

Submission status: Wrong Answer

Solution code:
import operator
for e in iter(input,'0'):
    target = [[*map(int,input().split())]for _ in[0]*int(e)]
    s,t = min(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 + u - s, y + v - t) not in b:break
        else:
            print(x - s, y - t)
            break

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
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)
        da = deepcopy(a)
        for i in range(1,len(da)+1):
            da[-i][0] -= da[0][0]
            da[-i][1] -= da[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):
            for d in da:
                if bx.count(bx[i]+d[0]) == 0 or by.count(by[i]+d[1]) == 0:
                	break
            else:
                print b[i][0]-a[i][0],b[i][1]-a[i][1]
                break
    except:
        break

Submission status: Wrong Answer

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()))
        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()))
        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: Time Limit Exceeded

Solution code:
while 1:
    n = input()
    if n == 0: break
    p = sorted([map(int, raw_input().split()) for i in range(n)])
    d = [[p[i][0] - p[0][0], p[i][1] - p[0][1]] for i in range(1,n)]
    m = input()
    q = 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 p1[0] + d[i][0] == p2[0] and p1[1] + d[i][1] == p2[1]:
                    f = False
                    break
            if f: break
        else:
            print p1[0] - p[0][0], p1[1] - p[0][1]

Submission status: Time Limit Exceeded

Solution code:
while 1:
    m=input()
    if m==0:break
    st=[map(int,raw_input().split()) for _ in xrange(m)]
    n=input()
    pi=[map(int,raw_input().split()) for _ in xrange(n)]
    d=[[] for _ in xrange(m)]
    for i in xrange(m):
        for j in xrange(m):
            if i==j:continue
            d[i].append([st[j][0]-st[i][0],st[j][1]-st[i][1]])
    f=0
    for i in xrange(n):
        if f==1:break
        mo=[]
        f=0
        for j in xrange(n):
            mo.append([pi[j][0]-pi[i][0],pi[j][1]-pi[i][1]])
        for k in xrange(m):
            cnt=0
            for l in d[k]:
                if not l in mo:continue
                else:cnt+=1
                if cnt==len(d[k]):
                    print pi[i][0]-st[k][0],pi[i][1]-st[k][1]
                    f=1
                    break
            if f==1:break

Submission status: Time Limit Exceeded

Solution code:
while 1:
    m=int(raw_input())
    if m==0:break
    st=[map(int,raw_input().split()) for _ in xrange(m)]
    n=int(raw_input())
    pi=[map(int,raw_input().split()) for _ in xrange(n)]
    d=[[st[i][0]-st[0][0],st[i][1]-st[0][1]] for i in xrange(1,m)]
    for i in xrange(n):
        mo=[[pi[j][0]-pi[i][0],pi[j][1]-pi[i][1]] for j in xrange(n)]
        cnt=0
        for k in xrange(m-1):
            if not d[k] in mo:continue
            else:cnt+=1
        if cnt==m-1:
            print pi[i][0]-st[0][0],pi[i][1]-st[0][1]
            break

Submission status: Time Limit Exceeded

Solution code:
def searchstar(i,j):
    global vector
    global star
    global n
    flag = False
    for k in range(n):
        if star[i][0] + vector[j][0] == star[k][0] and star[i][1] + vector[j][1] == star[k][1]:
            flag = True
            break
    return flag

while True:
    m = int(input())
    if m==0: break

    vector = []

    x1,y1 = map(int, input().split())
    for i in range(m-1):
        x2,y2 = map(int, input().split())
        vector.append([x2-x1,y2-y1])

    star = []
    n = int(input())
    for i in range(n):
        a,b = map(int, input().split())
        star.append([a,b])

    for i in range(n):
        for j in range(m-1):
            if not searchstar(i, j):
                break
        else:
            print(star[i][0] - x1, star[i][1] - y1)

Submission status: Time Limit Exceeded

Solution code:
def searchstar(i,j):
    global vector
    global star
    global n
    flag = False
    for k in range(n):
        if star[i][0] + vector[j][0] == star[k][0] and star[i][1] + vector[j][1] == star[k][1]:
            flag = True
            break
    return flag

while True:
    m = int(input())
    if m==0: break

    vector = []

    x1,y1 = map(int, input().split())
    for i in range(m-1):
        x2,y2 = map(int, input().split())
        vector.append([x2-x1,y2-y1])

    star = []
    n = int(input())
    for i in range(n):
        a,b = map(int, input().split())
        star.append([a,b])

    for i in range(n):
        for j in range(m-1):
            if not searchstar(i, j):
                break
        else:
            print(star[i][0] - x1, star[i][1] - y1)
            break

Submission status: Accepted

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 0 <= dx <= 1000000 and 0 <= dy <= 1000000 and 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: Accepted

Solution code:
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):
        flag = True
        for j in range(len(star)):
            dx = starlist[i][0] + star[j][0]
            dy = starlist[i][1] + star[j][1]
            if (dx, dy) not in starlist:
                flag = False
                break
        if flag == True:
            print("{} {}".format(str(starlist[i][0] - sx), str(starlist[i][1] -sy)))
            break

Submission status: Accepted

Solution code:
board = [[False]*1000001]*1000001
while True:
    m = int(input())
    if m == 0: break
    star = tuple(tuple(map(int, input().split())) for i in range(m))
    sx, sy = star[0]
    
    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] - sx
            dy = starlist[i][1] + star[j][1] - sy
            if 0 <= dx <= 1000000 and 0 <= dy <= 1000000 and 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: Accepted

Solution code:
board = [[False]*1000001]*1000001
while True:
    m = int(input())
    if m == 0: break
    star = tuple(tuple(map(int, input().split())) for i in range(m))
    sx, sy = star[0]
    
    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)-1):
            dx = starlist[i][0] + star[j+1][0] - sx
            dy = starlist[i][1] + star[j+1][1] - sy
            if dx < 0 or 1000000 < dx or dy < 0 or 1000000 < dy or board[dx][dy] == False:
                flag = False
                break

        if flag == True:
            print("{} {}".format(starlist[i][0] - sx, starlist[i][1] -sy))
            break

Submission status: Accepted

Solution code:
board = [[False]*1000001]*1000001
while True:
    m = int(input())
    if m == 0: break
    star = list(set(tuple(tuple(map(int, input().split())) for i in range(m))))
    sx, sy = star[0]
    
    n = int(input())
    starlist = list(set([tuple(map(int, input().split())) for i in range(n)]))
    for i in range(len(starlist)):
        board[starlist[i][0]][starlist[i][1]] = True
    for i in range(n):
        flag = True
        for j in range(len(star)-1):
            dx = starlist[i][0] + star[j+1][0] - sx
            dy = starlist[i][1] + star[j+1][1] - sy
            if dx < 0 or 1000000 < dx or dy < 0 or 1000000 < dy or board[dx][dy] == False:
                flag = False
                break

        if flag == True:
            print("{} {}".format(starlist[i][0] - sx, starlist[i][1] -sy))
            break

Submission status: Accepted

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

        if flag == True:
            print("{} {}".format(starlist[i][0] - sx, starlist[i][1] -sy))
            break

Submission status: Accepted

Solution code:
while True:
    m = int(input())
    if m == 0: break
    star = list({tuple(map(int, input().split())) for i in range(m)})
    sx, sy = star[0]
    
    n = int(input())
    starset = {tuple(map(int, input().split())) for i in range(n)}
    for x, y in starset:
        flag = True
        for j in range(len(star)-1):
            dx = x + star[j+1][0] - sx
            dy = y + star[j+1][1] - sy
            if (dx, dy) not in starset:
                flag = False
                break

        if flag == True:
            print(x - sx, y - sy)
            break

Submission status: Accepted

Solution code:
while(1):
    M=int(raw_input())
    if M==0:
        break
    else:
        starxy=[]
        constxy=[]
        constdirect=[]
        for i in range(M):
            constxy.append([int(x) for x in raw_input().split()])
        N=int(raw_input())
        for j in range(N):
            starxy.append([int(x) for x in raw_input().split()])
        for i in range(1,M):
            constdirect.append([constxy[i][0]-constxy[0][0],constxy[i][1]-constxy[0][1]])
        const0=constxy[0]
        for star in starxy:
            fin=1
            for nextvector in constdirect:
                if not [star[0]+nextvector[0],star[1]+nextvector[1]] in starxy:
                    fin=0
                    break
            if fin:
                print star[0]-const0[0],star[1]-const0[1]
                break

Submission status: Accepted

Solution code:
while True:
    m = int(raw_input())
    if m==0:break
    seiza = [] # pos. of const.
    for i in range(m):
        seiza.append(map(int,raw_input().split()))
    seiza.sort()
    n = int(raw_input())
    hoshi = []
    for j in range(n):
        hoshi.append(map(int,raw_input().split()))
    hoshi.sort()
    
    try:
        for xs,ys in seiza:
            for xh,yh in hoshi:
                dx = xh-xs
                dy = yh-ys
                tmp = [[x+dx,y+dy] for x,y in seiza]
                cnt = 0
                for item in tmp:
                    if item in hoshi:
                        cnt += 1
                        if cnt == len(tmp):
                            raise ZeroDivisionError
                    else:
                        break
    except ZeroDivisionError:
        print dx,dy

Submission status: Accepted

Solution code:
while 1:
    n = input()
    if n == 0: break
    p = set([tuple(map(int, raw_input().split())) for i in range(n)])
    m = input()
    q = set([tuple(map(int, raw_input().split())) for i in xrange(m)])
    ret = False
    for px, py in p:
        if ret: break
        for qx, qy in q:
            if ret: break
            dx = qx - px
            dy = qy - py
            for x, y in p:
                mx = x + dx
                my = y + dy
                if (mx, my) not in q:
                    break
            else:
                print dx, dy
                ret = True

Submission status: Accepted

Solution code:
while 1:
    m=int(raw_input())
    if m==0:break
    st=[map(int,raw_input().split()) for _ in xrange(m)]
    n=int(raw_input())
    pi=[map(int,raw_input().split()) for _ in xrange(n)]
    d=[[st[i][0]-st[0][0],st[i][1]-st[0][1]] for i in xrange(1,m)]
    for i in xrange(n):
        mo=[[pi[j][0]-pi[i][0],pi[j][1]-pi[i][1]] for j in xrange(n)]
        cnt=0
        cnt1=0
        for k in xrange(m-1):
            if not d[k] in mo:break
            else:cnt+=1
        if cnt==m-1:
            print pi[i][0]-st[0][0],pi[i][1]-st[0][1]
            break

Submission status: Accepted

Solution code:
import operator

while True:
    m = int(input())
    if not m:
        break
    target = [tuple(map(int, input().split())) for _ in range(m)]
    bx, by = min(target)
    target = {(x - bx, y - by) for x, y in target}
    max_tx = max(map(operator.itemgetter(0), target))

    n = int(input())
    sky = {tuple(map(int, input().split())) for _ in range(n)}
    max_sx = max(map(operator.itemgetter(0), sky))

    lim_x = max_sx - max_tx

    for x, y in sky:
        if x > lim_x:
            continue
        for tx, ty in target:
            if (x + tx, y + ty) not in sky:
                break
        else:
            print(x - bx, y - by)
            break

Submission status: Accepted

Solution code:
while True:
    m = int(input())
    if not m:
        break
    target = [tuple(map(int, input().split())) for _ in range(m)]
    bx, by = min(target)
    target = {(x - bx, y - by) for x, y in target}

    n = int(input())
    sky = {tuple(map(int, input().split())) for _ in range(n)}
    sky_s = sorted(sky)

    for x, y in sky_s:
        for tx, ty in target:
            if (x + tx, y + ty) not in sky:
                break
        else:
            print(x - bx, y - by)
            break

Submission status: Accepted

Solution code:
while True:
    m = int(input())
    if not m:
        break
    target = {tuple(map(int, input().split())) for _ in range(m)}
    base = min(target)
    target.remove(base)
    bx, by = base
    target = {(x - bx, y - by) for x, y in target}

    n = int(input())
    sky = {tuple(map(int, input().split())) for _ in range(n)}

    for x, y in sorted(sky):
        for tx, ty in target:
            if (x + tx, y + ty) not in sky:
                break
        else:
            print(x - bx, y - by)
            break

Submission status: Accepted

Solution code:
def searchstar(i,j):
    global vector
    global star
    global n
    flag = False
    for k in range(n):
        if star[i][0] + vector[j][0] == star[k][0] and star[i][1] + vector[j][1] == star[k][1]:
            flag = True
            break
    return flag

while True:
    m = int(input())
    if m==0: break

    vector = []

    x1,y1 = map(int, input().split())
    for i in range(m-1):
        x2,y2 = map(int, input().split())
        vector.append([x2-x1,y2-y1])

    star = []
    n = int(input())
    for i in range(n):
        a,b = map(int, input().split())
        star.append([a,b])

    for i in range(n-1,-1,-1):
        for j in range(m-1):
            if not searchstar(i, j):
                break
        else:
            print(star[i][0] - x1, star[i][1] - y1)
            break

Submission status: Accepted

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: Accepted

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
  if not set((u+x,v+y)for u,v in a)-set(b):print(x,y);break

Submission status: Accepted

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:
  x,y=s-a[0][0],t-a[0][1]
  if not set((u+x,v+y)for u,v in a)-set(b):print(x,y);break

Submission status: Accepted

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: Accepted

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: Accepted

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: Accepted

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

Submission status: Accepted

Solution code:
def f(e):
 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:return print(x,y)
for e in iter(input,'0'):f(e)

Submission status: Accepted

Solution code:
def f(e):
 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:return print(x,y)
for e in iter(input,'0'):f(e)

Submission status: Accepted

Solution code:
while True:
    m = int(input())
    if m == 0: break
    star = list({tuple(map(int, input().split())) for i in range(m)})
    sx, sy = star[0]
    
    n = int(input())
    starset = {tuple(map(int, input().split())) for i in range(n)}
    for x, y in starset:
        flag = True
        for j in range(len(star)-1):
            dx = x + star[j+1][0] - sx
            dy = y + star[j+1][1] - sy
            if (dx, dy) not in starset:
                flag = False
                break

        if flag == True:
            print(x - sx, y - sy)
            break

Submission status: Accepted

Solution code:
for e in iter(input,'0'):
    a=list({tuple(map(int, input().split())) for i in range(int(e))})
    s,t=a[0]
    b={tuple(map(int, input().split())) for i 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: Accepted

Solution code:
for e in iter(input,'0'):
 a=[list(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: Accepted

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={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: Accepted

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=[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: Accepted

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={tuple(map(int,input().split())) for _ in range(int(input()))}
 for x,y in b:
  f=1
  for u,v in a[1:]:
   if(x+u-s,y+v-t)not in b:f=0;break
  if f:print(x-s,y-t);break

Submission status: Accepted

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={tuple(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:print(x-s,y-t);break

Submission status: Accepted

Solution code:
def f(e):
 a=list(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:
  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: Accepted

Solution code:
def f(e):
 a=list(list(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:
  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: Accepted

Solution code:
def f(e):
 a=list([*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:
  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: Accepted

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 + u, y + v) not in b:break
        else:
            print(x - bx, y - by)
            break

Submission status: Accepted

Solution code:
import operator
for e in iter(input,'0'):
    target = [[*map(int,input().split())]for _ in[0]*int(e)]
    bx, by = target[0]
    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 + u, y + v) not in b:break
        else:
            print(x - bx, y - by)
            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)
    target = {(x - s, y - t) 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