Problem:
 Score : 200 points    Problem Statement There are N students and M checkpoints on the xy -plane. The coordinates of the i -th student (1 \leq i \leq N) is (a_i,b_i) , and the coordinates of the checkpoint numbered j  (1 \leq j \leq M) is (c_j,d_j) . When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance . The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2| . Here, |x| denotes the absolute value of x . If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index. Which checkpoint will each student go to?      Constraints  1 \leq N,M \leq 50  -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8  All input values are integers.         Input The input is given from Standard Input in the following format:  N  M  a_1  b_1  :  a_N  b_N  c_1  d_1  :  c_M  d_M       Output Print N lines. The i -th line (1 \leq i \leq N) should contain the index of the checkpoint for the i -th student to go.        Sample Input 1 2 2
2 0
0 0
-1 0
1 0      Sample Output 1 2
1  The Manhattan distance between the first student and each checkpoint is:   For checkpoint 1 : |2-(-1)|+|0-0|=3  For checkpoint 2 : |2-1|+|0-0|=1   The nearest checkpoint is checkpoint 2 . Thus, the first line in the output should contain 2 .  The Manhattan distance between the second student and each checkpoint is:   For checkpoint 1 : |0-(-1)|+|0-0|=1  For checkpoint 2 : |0-1|+|0-0|=1   When there are multiple nearest checkpoints, the student will go to the checkpoint with the smallest index. Thus, the second line in the output should contain 1 .       Sample Input 2 3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5      Sample Output 2 3
1
2  There can be multiple checkpoints at the same coordinates.       Sample Input 3 5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000      Sample Output 3 5
4
3
2
1

Solution (Python):
n,m=map(int,input().split())
al=[]
bl=[]
ansl=[]
for i in range(n):
  al.append(input())
for i in range(m):
  bl.append(input())
for i in range(n):
  a1,a2=map(int,al[i].split())
  b1,b2=map(int,bl[0].split())
  mi=dis=abs(b1-a1)+abs(b2-a2)
  c=1
  for j in range(1,m):
    b1,b2=map(int,bl[j].split())
    dis=abs(b1-a1)+abs(b2-a2)
    if mi>dis:
      mi=dis
      c=j+1
  ansl.append(c)
for i in range(len(ansl)):
  print(ansl[i])

Solution (Python):
a, b = map(int, input().split())
x1 = []
y1 = []
x2 = []
y2 = []
for i in range(a):
    x, y = map(int, input().split())
    x1.append(x)
    y1.append(y)


for j in range(b):
    x, y = map(int, input().split())
    x2.append(x)
    y2.append(y)
ans = -1
min=1000000000000
for i in range(a):
    for j in range(b):
        xx = x1[i] - x2[j]
        yy = y1[i] - y2[j]
        if(xx<0):
            xx= -xx
        if(yy<0):
            yy = -yy
        if(xx+yy<min):
            min=xx+yy
            ans=j+1
    print(ans)
    min = 100000000000
    ans=-1

Solution (Python):
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
cd=[list(map(int,input().split())) for j in range(m)]
for a,b in ab:
    abcd=[abs(a-c)+abs(b-d) for c,d in cd]
    print(abcd.index(min(abcd))+1)

Solution (Python):
N, M = map(int, input().split())
a = [0 for _ in range(N)]
b = [0 for _ in range(N)]
c = [0 for _ in range(M)]
d = [0 for _ in range(M)]
distance = []
for i in range(N):
    a[i], b[i] = map(int, input().split())
for j in range(M):
    c[j], d[j] = map(int, input().split())

for i in range(N):
    for j in range(M):
        distance.append(abs(a[i]-c[j])+abs(b[i]-d[j]))
    print(distance.index(min(distance))+1)
    distance = []

Solution (Python):
n,m=map(int,input().split())
ans=10**9
tmp_ans=10**9
prin=0
a=[]
b=[]
for i in range(n):
    x,y=map(int,input().split())
    a.append([x,y])
for i in range(m):
    x,y=map(int,input().split())
    b.append([x,y])
for i in range(n):
    tmp_x=a[i][0]
    tmp_y=a[i][1]
    for j in range(m):
        ans=min((abs(tmp_x-b[j][0])+abs(tmp_y-b[j][1])),ans)
        if tmp_ans!=ans:
            prin=j+1
            tmp_ans=ans
    print(prin)
    ans=10**9
    tmp_ans=10**9

Solution (Python):
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(M)]

for a, b in ab:
    ans = 0
    temp_min = float("inf")
    for i, (c, d) in enumerate(cd):
        dist = abs(a - c) + abs(b - d)
        if dist < temp_min:
            ans = i + 1
            temp_min = dist
        
    print(ans)

Solution (Python):
T = input().rstrip().split(" ")
N = int(T[0])
M = int(T[1])
ss = []
for i in range(N):
    T = input().rstrip().split(" ")
    ss.append(T)
dd = []
for i in range(M):
    T = input().rstrip().split(" ")
    dd.append(T)
ans = []
for i in range(N):
    px = int(ss[i][0])
    py = int(ss[i][1])
    list = []
    for j in range(M):
        dx = int(dd[j][0])
        dy = int(dd[j][1])
        MD = abs(px - dx) + abs(py - dy)
        list.append(MD)
    ans.append(list.index(min(list))+1)
for i in range(len(ans)):
    print(ans[i])

Solution (Python):



def main():
    """Function."""
    n, m = map(int, input().split())

    n_map, m_map = [], []
    for _ in range(n):
        n_map.append(list(map(int, input().split())))
    for _ in range(m):
        m_map.append(list(map(int, input().split())))

    for st in n_map:
        min_index = 1
        min_val = abs(st[1] - m_map[0][1]) + abs(st[0] - m_map[0][0])
        counter = 1
        for pl in m_map:
            temp = abs(st[1] - pl[1]) + abs(st[0] - pl[0])
            if temp < min_val:
                min_val = temp
                min_index = counter
            counter += 1
        print(min_index)


if __name__ == "__main__":
    main()

Solution (Python):
N, M = map(int,input().split())
S = [list(map(int,input().split())) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(M)]

result = []
for s in S:
  a = s[0]
  b = s[1]
  for p in P:
    c = p[0]
    d = p[1]
    direct = abs(a-c)+abs(b-d)
    result.append(direct)
  point = min(result)
  print(result.index(point) + 1)
  result = []

Solution (Python):
N, M = [ int(i) for i in input().split() ]
students = []
for i in range(N):
    students.append([int(i) for i in input().split()])
points = []
for i in range(M):
    points.append([int(i) for i in input().split()])
for x, y in students:
    shortest = 2000000000
    index = 0
    for j, (xx, yy) in enumerate(points):
        l = abs(x-xx) + abs(y-yy)
        if l < shortest:
            shortest = l
            index = j
    print(index+1)

Solution (Python):
def dist(p0, p1):
    return abs(p0[0] - p1[0]) + abs(p0[1] - p1[1])


def main():
    n, m = map(int, input().split())
    ss = [list(map(int, input().split())) for _ in range(n)]
    pp = [list(map(int, input().split())) for _ in range(m)]
    for i in range(n):
        d_min = dist(ss[i], pp[0])
        d_min_j = 0
        for j in range(1, m):
            d = dist(ss[i], pp[j])
            if d < d_min:
                d_min = d
                d_min_j = j
        print(d_min_j + 1)


if __name__ == '__main__':
    main()

Solution (Python):
n, m = [int(i) for i in input().split()]
a = [[0, 0] for _ in range(n)]
c = [[0, 0] for _ in range(m)]
for i in range(n):
    a[i] = [int(i) for i in input().split()]
for i in range(m):
    c[i] = [int(i) for i in input().split()]

for i in range(n):
    _min = [10 ** 10, 0]
    for j in range(m):
        if abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]) < _min[0]:
            _min[0] = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
            _min[1] = j + 1
    print(_min[1])

Solution (Python):
N,M = [int(i) for i in input().split()]
student_location = []
for i in range(N) :
    student_location.append([int(i) for i in input().split()])

checkpoint_location = []
for i in range(M) :
    checkpoint_location.append([int(i) for i in input().split()])

for student_loc in student_location :
    min_distance = 9999999999
    min_distance_index = -1
    index = 0
    for checkpoint_loc in checkpoint_location :
        index += 1
        d = abs(student_loc[0] - checkpoint_loc[0]) + abs(student_loc[1] - checkpoint_loc[1])
        if (d < min_distance) :
            min_distance = d
            min_distance_index = index
    
    print(min_distance_index)

Solution (Python):
N, M = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(N)]
C = [[int(i) for i in input().split()] for j in range(M)]

ls1 = []
for i in range(N):
    ls2 = []
    for j in range(M):
        ls2.append(abs(A[i][0] - C[j][0]) + abs(A[i][1] - C[j][1]))
    a = min(ls2)
    ls1.append(ls2.index(a))
for i in ls1:
    print(i+1)

Solution (Python):
n,m=map(int,input().split())
AB=[]
CD=[]
for i in range(n):
  AB.append(list(map(int,input().split())))
for i in range(m):
  CD.append(list(map(int,input().split())))

for a,b in AB:
  dis=[abs(a-c)+abs(b-d) for c,d in CD]
  print(dis.index(min(dis))+1)

Solution (Python):
n,m=map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
cd = [list(map(int,input().split())) for j in range(m)]

for x in range(n):
    e = []
    for y in range(m):
        e.append(abs(ab[x][0]-cd[y][0]) + abs(ab[x][1]-cd[y][1]))

    print(e.index(min(e))+1)

Solution (Python):
N, M = map(int, raw_input().split())
a = []
b = []
for i in range(N):
    _a, _b = map(int, raw_input().split())
    a.append(_a)
    b.append(_b)
c = []
d = []
for i in range(M):
    _c, _d = map(int, raw_input().split())
    c.append(_c)
    d.append(_d)

dist = [[float("inf")] * M for i in range(N)]
for i in range(N):
    for j in range(M):
        dist[i][j] = abs(a[i] - c[j]) + abs(b[i] - d[j])
for i in range(N):
    print dist[i].index(min(dist[i])) + 1

Solution (Python):
n,m=map(int,input().split())
AB=[]
CD=[]
for i in range(n):
  AB.append(list(map(int,input().split())))
for i in range(m):
  CD.append(list(map(int,input().split())))

for a,b in AB:
  dis=[abs(a-c)+abs(b-d) for c,d in CD]
  print(dis.index(min(dis))+1)

Solution (Python):
n, m = map(int, input().split())
ab = []
for i in range(n):
    ab.append([int(m) for m in input().split()])
cd = []
for i in range(m):
    cd.append([int(m) for m in input().split()])
dis = [float("inf")]*n
dn = [-1]*n
for i in range(n):
    for j in range(m):
        t = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if t < dis[i]:
            dis[i] = t
            dn[i] = j
    print(dn[i] + 1)

Solution (Python):
N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(N)]
C = [[int(_) for _ in input().split()] + [_+1] for _ in range(M)]
for a, b in AB:
    ans = []
    for c in C:
        ans += [[(abs(c[0]-a)+abs(c[1]-b))*100+c[2], c[2]]]
    print(sorted(ans)[0][1])

Solution (Python):
n,m=map(int,input().split())
s_p=[list(map(int,input().split()))for i in range(n)]
c_p=[list(map(int,input().split()))for i in range(m)]
for s in s_p:
    d=abs(c_p[0][0]-s[0])+abs(c_p[0][1]-s[1])
    a=1
    for i in range(1,m):
        if d>abs(c_p[i][0]-s[0])+abs(c_p[i][1]-s[1]):
            a=i+1
            d=abs(c_p[i][0]-s[0])+abs(c_p[i][1]-s[1])
    print(a)

Solution (Python):
N,M = map(int,input().split())
A = []
B = []
C = []
D = []
for i in range(N):
    x,y = map(int,input().split())
    A.append(x)
    B.append(y)
for i in range(M):
    x,y = map(int,input().split())
    C.append(x)
    D.append(y)
k = 0
for i in range(N):
    g = 100000000000
    for j in range(M):
        t = abs(A[i]-C[j])+abs(B[i]-D[j])
        
        if t < g:
            k = j+1
            g = t
    print(k)

Solution (Python):

class Point(object):
    def __init__(self, x, y):
        self.x = int(x)
        self.y = int(y)

    @staticmethod
    def manhattan(p1, p2):
        return abs(p1.x - p2.x) + abs(p1.y - p2.y)

def solve():
    
    n, m = map(int, input().split())
    students = []
    for _ in range(n):
        students.append(Point(*input().split()))

    checkpoints = []
    for _ in range(m):
        checkpoints.append(Point(*input().split()))

    for student in students:
        min_dist = 4 * (10 ** 8)
        min_index = 1
        for index, cp in enumerate(checkpoints):
            manhattan = Point.manhattan(student, cp)
            if min_dist > manhattan:
                min_dist = manhattan
                min_index = index + 1
        print(min_index)


if __name__ == '__main__':
    solve()

Solution (Python):
a=list(map(int,input().split()))
N=a[0]
M=a[1]
posx=[]
posy=[]
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    posx.append(x1)
    posy.append(y1)
students=[10**9]*N
aim=[0,]*N
for i in range(M):
    pointx,pointy=[int(i) for i in input().split()]
    for j in range(N):
        if students[j] > abs(pointx-posx[j]) + abs(pointy-posy[j]):
            students[j] = abs(pointx-posx[j]) + abs(pointy-posy[j])
            aim[j]=i+1
for i in range(N):
    print(str(aim[i]))

Solution (Python):

N, M = map(int, input().split())
students = [list(map(int, input().split())) for _ in range(N)]
c_points = [list(map(int, input().split())) for _ in range(M)]

for a,b in students:
    m_dis = [abs(a-c) + abs(b-d) for c,d in c_points]
    print(m_dis.index(min(m_dis)) + 1)

Solution (Python):

def manhattan(x1, y1, x2, y2):
    return abs(x1-x2) + abs(y1-y2)

N, M = map(int, input().split())
students = [input() for _ in range(N)]
c_points = [input() for _ in range(M)]

for s in students:
    val = 400000001
    ans = 0
    a, b = map(int, s.split())
    for j, c in enumerate(c_points):
        c, d = map(int, c.split())
        m_dis = manhattan(a,b,c,d)
        if m_dis < val:
            val = m_dis
            ans = j+1
    print(ans)

Solution (Python):
def man(a,b):
    return abs(a[0]-b[0])+abs(a[1]-b[1])
n,m=map(int,input().split())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
cd=[]
for j in range(m):
    cd.append(list(map(int,input().split())))
for i in range(n):
    ans=0
    dis=man(ab[i],cd[0])
    for j in range(m):
        if dis >man(ab[i],cd[j]):
            ans = j
            dis = man(ab[i],cd[j])
    print(ans+1)

Solution (Python):
n, m = list(map(int, input().split()))

st = [list(map(int, input().split())) for i in range(n)]

ch = [list(map(int, input().split())) for i in range(m)]

ans = []

for i, p in enumerate(st):
	l = 500000000
	ans.append(0)
	
	for j, d in enumerate(ch):
		if abs(p[0] - d[0]) + abs(p[1] - d[1]) < l:
			ans[i] = j + 1
			l = abs(p[0] - d[0]) + abs(p[1] - d[1])
		
		
for a in ans:
	print(a)

Solution (Python):
N, M = map(int, input().split())
students = [list(map(int, input().split())) for i in range(N)]
checkpoints = [list(map(int, input().split())) for i in range(M)]

for s in students:
    min_distance = 4 * 10**8 + 1
    for i, c in enumerate(checkpoints):
        distance = abs(s[0] - c[0]) + abs(s[1] - c[1]) 
        if min_distance > distance:
            min_distance = distance
            point = i+1
    print(point)

Solution (Python):
n, m = map(int, input().split())
A = [tuple(map(int, input().split())) for i in range(n)]
C = [tuple(map(int, input().split())) for j in range(m)]
for i in range(n):
  res = 1 
  ans = abs(A[i][0] - C[0][0]) + abs(A[i][1] - C[0][1])
  for j in range(m):
    tmp = abs(A[i][0] - C[j][0]) + abs(A[i][1] - C[j][1])
    if tmp < ans:
      ans = tmp
      res = j+1
  print(res)

Solution (Python):




"""
https://beta.atcoder.jp/contests/abc057/tasks/abc57_1
"""

import sys
import math
from inspect import currentframe

def debug(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args), file=sys.stderr)

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
CD = [tuple(map(int, input().split())) for _ in range(M)]

for ab in AB:
    dist = [abs(cd[0] - ab[0]) + abs(cd[1] - ab[1]) for cd in CD]
    
    print(dist.index(min(dist)) + 1)

Solution (Python):
n, m = map(int, input().split())
list1 = []
list2 = []
result = []
for i in range(n):
    a, b = map(int, input().split())
    list_ab = [a,b]
    list1.append(list_ab)
for i in range(m):
    c, d = map(int, input().split())
    list_cd = [c,d]
    list2.append(list_cd)
for i in range(n):
    for j in range(m):
        ab = abs(list1[i][0]-list2[j][0])+abs(list1[i][1]-list2[j][1]) 
        result.append(ab)
        num = result.index(min(result))
    print(num+1)
    result = []

Solution (Python):
n,m=map(int,input().split())
abList= [list(map(int, input().split())) for _ in range(n)]
cdList= [list(map(int, input().split())) for _ in range(m)]

for ab in abList:
    i = 0
    bestPoint = 0
    bestScore = float('inf')
    for cd in cdList:
        dist = abs(ab[0] - cd[0]) + abs(ab[1] - cd[1])
        if dist < bestScore:
            bestScore = dist
            bestPoint = i + 1
        i += 1
    print(bestPoint)

Solution (Python):
n,m = (int(_) for _ in input().split())

ni = [0 for i in range(n)]
nj = [0 for i in range(n)]

mi = [0 for i in range(m)]
mj = [0 for i in range(m)]

for i in range(n):
    ni[i],nj[i] = (int(_) for _ in input().split())

for i in range(m):
    mi[i],mj[i] = (int(_) for _ in input().split())

ans = [0 for i in range(n)]

for i in range(n):
    min_dist = abs(ni[i]-mi[0])+abs(nj[i]-mj[0])
    ans[i] = 1
    for j in range(m):
        cur_dist = abs(ni[i]-mi[j])+abs(nj[i]-mj[j])
        if(min_dist > cur_dist):
            min_dist = cur_dist
            ans[i] = j+1

for i in ans:
    print(i)

Solution (Python):
n,m=map(int,input().split())
stu=[]
chk=[]
for i in range(n):
    tmp,tmp1=map(int,input().split())
    stu.append([tmp,tmp1])
for i in range(m):
    tmp,tmp1=map(int,input().split())
    chk.append([tmp,tmp1])
for student in stu:
    dist = [abs(j[0]-student[0])+abs(j[1]-student[1]) for j in chk]
    print(dist.index(min(dist))+1)

Solution (Python):
N, M = map(int,input().split())
st = [[int(i) for i in input().split()] for j in range(N)]
cp = [[int(i) for i in input().split()] for j in range(M)]
for i in st:
    L = [abs(i[0] - j[0])+abs(i[1] - j[1]) for j in cp]
    m = min(L)
    print(L.index(m)+1)

Solution (Python):
N, M = list(map(int, input().rstrip().split()))


st = []
for i in range(N):
    a, b = list(map(int, input().rstrip().split()))
    st.append((a, b))



ct = []
for i in range(M):
    c, d = list(map(int, input().rstrip().split()))
    ct.append((c, d))

for i in range(N):
    cp = 0
    dist = -1
    for j in range(len(ct) - 1, -1, -1):
        tmp = abs(st[i][0] - ct[j][0]) + abs(st[i][1] - ct[j][1])
        if dist < 0:
            cp = j + 1
            dist = tmp
        else:
            if tmp <= dist:
                cp = j + 1
                dist = tmp


    print(cp)

Solution (Python):
N, M = map(int, raw_input().split())
a = [0]*N
b = [0]*N
for i in range(N):
  a[i], b[i] = map(int, raw_input().split())
c = [0]*M
d = [0]*M
for j in range(M):
  c[j], d[j] = map(int, raw_input().split())
for i in range(N):
  mj = 0
  md = abs(a[i]-c[0])+abs(b[i]-d[0])
  for j in range(1, M):
    dj = abs(a[i]-c[j])+abs(b[i]-d[j])
    if dj < md:
      mj = j
      md = dj
  print mj+1

Solution (Python):
N,M = map(int,input().split())
st = []
ch = []
for i in range(N):
  a,b = map(int,input().split())
  st.append([a,b])
for i in range(M):
  c,d = map(int,input().split())
  ch.append([c,d])
for i in range(N):
  d_list = []
  for j in range(M):
    d = abs(st[i][0] - ch[j][0]) + abs(st[i][1] - ch[j][1])
    d_list.append(d)
  print(d_list.index(min(d_list)) + 1)

Solution (Python):
n,m = map(int, input().split())
ab = []
cd = []
for _ in range(n):
    ab.append(list(map(int, input().split())))
for _ in range(m):
    cd.append(list(map(int, input().split())))
    
dis = [[-1]*m for _ in range(n)]
for nn in range(n):
    a, b = ab[nn]
    for mm in range(m):
        c, d = cd[mm]
        dis[nn][mm] = abs(a-c) + abs(b-d)
        

  
for nn in range(n):
    min_d = min(dis[nn])
    for mm in range(m):
        if dis[nn][mm]==min_d:
            print(mm+1)
            break

Solution (Python):
n,m = map(int,input().split())
stus, ps = [], []
ans = []
for i in range(n):
    stus.append(list(map(int,input().split())))
for i in range(m):
    ps.append(list(map(int,input().split())))

for i in range(n):
    tmp = -1
    ans.append('')
    for j in range(m):
        dist = abs(ps[j][0] - stus[i][0]) + abs(ps[j][1] - stus[i][1])
        if tmp == -1 or dist < tmp:
            tmp = dist
            ans[i] = j+1

print('\n'.join(list(map(str,ans))))

Solution (Python):
def main():
    n, m = map(int, input().split())
    students = []
    points = []

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

    for _ in range(m):
        x, y = map(int, input().split())
        points.append((x, y))

    for s in students:
        idx = 0
        r = distance(s, points[0])

        for i in range(1, m):
            d = distance(s, points[i])
            if d < r:
                idx = i
                r = d
        print(idx + 1)

def distance(s, p):
    return abs(p[0] - s[0]) + abs(p[1] - s[1])

main()

Solution (Python):
n, m = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(n)]
C = [list(map(int, input().split())) for _ in range(m)]

for s in S:
    x, ans = 10**9, 0
    for i, c in enumerate(C):
        y = abs(s[0]-c[0]) + abs(s[1]-c[1])
        if y < x:
            x, ans = y, i+1
    print(ans)

Solution (Python):
N, M = map(int, input().split())
a = []
b = []
c = []
d = []

for i in range(N):
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)
for i in range(M):
    C, D = map(int, input().split())
    c.append(C)
    d.append(D)

for i in range(N):
    distmin = 500000000
    for j in range(M):
        dist = abs(a[i]-c[j]) + abs(b[i]-d[j])
        distmin = min(dist, distmin)
        
    for j in range(M):
        if distmin == abs(a[i]-c[j]) + abs(b[i]-d[j]):
            print(j+1)
            break

Solution (Python):
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for x in range(n)]
cd = [list(map(int, input().split())) for x in range(m)]
for i in ab:
    atemp = 1000000000
    ans = 0
    for f in range(len(cd)):
        temp = abs(i[0] - cd[f][0]) + abs(i[1] - cd[f][1])
        if atemp > temp:
            atemp = temp
            ans = f + 1
    print(ans)

Solution (Python):
from sys import stdin
from sys import maxsize


def main() -> int:
    n = next_int()
    m = next_int()

    students = [tuple(map(int, input().split())) for _ in range(n)]
    check_points = [tuple(map(int, input().split())) for _ in range(m)]

    for i in range(n):
        index = 0
        value = maxsize
        for j in range(m):
            x1 = students[i][0]
            y1 = students[i][1]
            x2 = check_points[j][0]
            y2 = check_points[j][1]
            calc_result = calc(x1, x2, y1, y2)

            if calc_result < value:
                index = j
                value = calc_result
        print(index + 1)
    return 0


def calc(x1, x2, y1, y2: int) -> int:
    return abs(x1 - x2) + abs(y1 - y2)


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Solution (Python):
def create_list(n):
    result = [[i for i in map(int,input().split())] for j in range(n)]
    return result 

n,m = map(int,input().split())
x_list   = create_list(n)
y_list   = create_list(m)

for x in x_list:
    ans   = 0
    min_n = float('inf')
    for i,y in enumerate(y_list):
        temp = abs(x[0]-y[0]) + abs(x[1]-y[1])
        if temp < min_n:
            min_n = temp
            ans = i+1
    print(ans)

Solution (Python):
n,m= map(int,input().split())

s=[]
for i in range(n):
	s.append(list(map(int,input().split())))
c=[]
for i in range(m):
	c.append(list(map(int,input().split())))

for i in range(n):
	p = (abs(s[i][0]-c[0][0])+abs(s[i][1]-c[0][1]))
	q = 0
	for j in range(m-1):
		p = min(p,abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1]))
		if abs(s[i][0]-c[j+1][0])+abs(s[i][1]-c[j+1][1])<p:
			q = j+1
	print(q+1)

Solution (Python):
N, M =map(int, input().split())
a, b = [0]*N, [0]*N
c, d = [0]*M, [0]*M
ans = []
for i in range(N):
    a[i], b[i] = map(int, input().split())
for i in range(M):
    c[i], d[i] = map(int, input().split())
    

for i in range(N):
    length = 10**9
    ind = 0
    for j in range(M):
        man =  abs(a[i] - c[j])+abs(b[i] - d[j])
        if length > man:
            length = man
            ind = j+1
    ans.append(ind)

for i in ans:
    print(i)

Solution (Python):
n,m=map(int,input().split())
s=[]
p=[]
md=[[None,float('INF')] for i in range(n)]
for i in range(n):
    t1,t2=map(int,input().split())
    s.append([t1,t2])
for i in range(m):
    t1,t2=map(int,input().split())
    p.append([t1,t2])
for i in range(n):
    for j in range(m):
        if md[i][1]>abs(s[i][0]-p[j][0])+abs(s[i][1]-p[j][1]):
            md[i][0]=j+1
            md[i][1]=abs(s[i][0]-p[j][0])+abs(s[i][1]-p[j][1])
for i in range(n):
    print(md[i][0])

Solution (Python):
N, M = map(int, input().split())
S = [[int(i) for i in input().split()] for j in range(N)]
C = [[int(i) for i in input().split()] for j in range(M)]

for i in range(N):
    minlength = float("inf")
    nearpoint = 0
    for j in range(M):
        if minlength > abs(S[i][0] - C[j][0]) + abs(S[i][1] - C[j][1]):
            minlength = abs(S[i][0] - C[j][0]) + abs(S[i][1] - C[j][1])
            nearpoint = j+1
    print(nearpoint)

Solution (Python):
n, m = map(int, input().split())

listForStudent = []
index=0
while index < n:
    listI = list(map(int, input().split()))
    listForStudent.append(listI)
    index+=1

listForCheck=[]
index2=0
while index2 < m:
    listI2= list(map(int, input().split()))
    listForCheck.append(listI2)
    index2+=1

index3=0
listForAnswer=[]
while index3 < len(listForStudent):
    answer=2*(10**8)
    index4=0
    while index4 < len(listForCheck):
        if index4==0:
            indexA = index4+1
        distX = max(listForCheck[index4][0], listForStudent[index3][0]) - \
            min(listForCheck[index4][0], listForStudent[index3][0])
        distY = max(listForCheck[index4][1], listForStudent[index3][1]) - \
            min(listForCheck[index4][1], listForStudent[index3][1])
        totalDist = distX+distY
        if answer > totalDist:
            answer = totalDist
            indexA = index4+1
        index4+=1
    listForAnswer.append(indexA)
    index3+=1

for ans in listForAnswer:
    print(ans)

Solution (Python):
n, m = map(int, input().split())

a=[]
for i in range(n):
  x, y = map(int, input().split())
  a.append(x)
  a.append(y)
  
c=[]
for i in range(m):
  x, y = map(int, input().split())
  c.append(x)
  c.append(y)
  
for i in range(n):
  min = abs(a[2*i]-c[0])+abs(a[2*i+1]-c[1])
  p = 0
  for j in range(1,m):
    d = abs(a[2*i]-c[2*j])+abs(a[2*i+1]-c[2*j+1])
    if d < min:
      min = d
      p = j
  print(p+1)

Solution (Python):
N, M = map(int, input().split())

ab_list = []
cd_list = []

for i in range(N):
    ab = list(map(int, input().split()))
    ab_list.append(ab)

for i in range(M):
    cd = list(map(int, input().split()))
    cd_list.append(cd)

for a, b in ab_list:
    num = -1
    min_num = 10 ** 10 + 1
    count = 0
    for c, d in cd_list:
        count += 1
        distance = abs(a-c) + abs(b-d)
        if distance < min_num:
            min_num = distance
            num = count
    print(num)

Solution (Python):
n, m = map(int, input().split())

a = []
b = []

c = []
d = []

for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)

for i in range(m):
    c_, d_ = map(int, input().split())
    c.append(c_)
    d.append(d_)



for i in range(n):
    buf = 1000000000
    ans = 0
    for j in range(m):
        cal = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if cal < buf:
            buf = cal
            ans = j

        elif cal == buf:
            buf = cal
            ans = min(ans, j)

    print(ans + 1)

Solution (Python):
N, M  = map( int, input().split())
A = [ list( map( int, input().split())) for _ in range(N)]
C = [ list( map( int, input().split())) for _ in range(M)]
for i in range(N):
    ans = 1
    x, y = A[i]
    path = abs(x-C[0][0]) + abs(y-C[0][1])
    for j in range(1,M):
        if path > abs(x-C[j][0]) + abs(y-C[j][1]):
            ans = j+1
            path = abs(x-C[j][0]) + abs(y-C[j][1])
    print(ans)

Solution (Python):
n,m = map(int, input().split())
list_stu = []
for i in range(0,n):
    list_stu.append(list((map(int, input().split()))))

list_check = []
for i in range(0,m):
    list_check.append(list((map(int, input().split()))))

for stu in list_stu:
    min = 10 ** 9
    min_point = 0
    for check in list_check:
        
        if min > (abs(stu[0] - check[0]) + abs(stu[1] - check[1])):
            min = abs(stu[0] - check[0]) + abs(stu[1] - check[1])
            min_point = list_check.index(check) + 1
    print(min_point)

Solution (Python):
n,m = map(int,input().split())
a = []
for i in range(n):
    li = list(map(int,input().split()))	
    a.append(li)
c =[]
for i in range(m):
    li = list(map(int,input().split()))	
    c.append(li)

for i in range(n):
    k = 1
    l = abs(a[i][0]-c[0][0])+abs(a[i][1]-c[0][1])
    for j in range(m):
        if l > abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1]):
            l = abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])
            k = j+1
    print(k)

Solution (Python):
n, m = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(n)]
q = [list(map(int, input().split())) for _ in range(m)]
ans = [0]*n
for i in range(n):
    comp = abs(p[i][0]-q[0][0]) + abs(p[i][1]-q[0][1])
    for j in range(m):
        temp = abs(p[i][0]-q[j][0]) + abs(p[i][1]-q[j][1])
        if temp < comp:
            ans[i] = j
            comp = temp
for i in range(n):
    print(ans[i]+1)

Solution (Python):
n,m = map(int,input().split())
a = []
b = []
c = []
d = []
ansmin = 10**10
for i in range(n):
    tempa,tempb = map(int,input().split())
    a.append(tempa)
    b.append(tempb)
for j in range(m):
    tempc,tempd = map(int,input().split())
    c.append(tempc)
    d.append(tempd)

for i in range(n):
    ansindex = 10**10
    ansmin = 10**10
    for j in range(m):
        temp_min = abs(a[i]-c[j])+abs(b[i]-d[j]) 
        if temp_min < ansmin:
            ansindex = j+1
            ansmin = temp_min
    print(ansindex)

Solution (Python):
N,M = map(int,input().split())
A = []
B = []
C = []
D = []
for i in range(N) :
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
for j in range(M) :
    c,d = map(int,input().split())
    C.append(c)
    D.append(d)
for k in range(N) :
    distance = 10**17
    answer = -1
    for l in range(M) :
        p = abs(A[k]-C[l])
        q = abs(B[k]-D[l])
        d = p+q
        if d < distance :
            distance = d
            answer = l+1
    print(answer)

Solution (Python):
N,M=map(int,input().split())
a=[list(map(int,input().split())) for i in range(N)]
b=[list(map(int,input().split())) for i in range(M)]
for i in range(N):
    dmin=abs(a[i][0]-b[0][0])+abs(a[i][1]-b[0][1])
    num=1
    for j in range(M):
        dist=abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1])
        if dmin>dist:
            dmin=dist
            num=j+1
    print(num)