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())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(M)]
ans = []
t = 0

def distance(xy1, xy2):
    return (abs(xy1[0] - xy2[0]) + abs(xy1[1] - xy2[1]))

for xy in ab:
    temp = float('inf')
    for j, xy2 in enumerate(cd):
        dis = distance(xy, xy2)
        if temp > dis:
            temp = dis
            t = j
    ans.append(t+1)
for a in ans:
    print(a)

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

def dist(si, cj):
    return abs(students[si][0] - checkpoints[cj][0]) + abs(students[si][1] - checkpoints[cj][1])

ans = []
for i in range(n):
    ans_i = 0
    for j in range(1, m):
        if dist(i, ans_i) > dist(i, j):
            ans_i = j
    ans.append(ans_i+1)

print(*ans, sep='\n')

Solution (Python):
n,m=map(int,input().split())
li1=[list(map(int,input().split())) for i in range(n)]
li2=[list(map(int,input().split())) for i in range(m)]
for i in li1:
  a=i[0]
  b=i[1]
  mini=float("inf")
  ans=0
  for j in range(m):
    c=li2[j][0]
    d=li2[j][1]
    if abs(a-c)+abs(b-d)<mini:
      ans=j+1
    mini=min(mini,abs(a-c)+abs(b-d))
  print(ans)

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)
for i in range(N):
  tmp=10**9
  index=-1
  for j in range(M):
    if tmp>abs(a[i]-c[j])+abs(b[i]-d[j]):
      tmp = abs(a[i]-c[j])+abs(b[i]-d[j])
      index=j
  print(index+1)

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

for i in range(N):
    count = float("inf")
    for j in range(M):
        calc = abs(student[i][0]-checkpoint[j][0]) + \
            abs(student[i][1]-checkpoint[j][1])
        if count > calc:
            count = calc
            num = j+1

    print(num)

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

d = 10**17
for i in range(n):
    for j in range(m):
        r = abs(s[i][0] - c[j][0]) + abs(s[i][1] - c[j][1])
        if r < d:
            d = r
            ans = j+1
    print(ans)
    d = 10**17

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 ab in AB:
    man = [(abs(ab[0]-CD[i][0]) + abs(ab[1]-CD[i][1])) for i in range(len(CD))]
    print(man.index(min(man))+1)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    cd = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    for i, a in enumerate(ab):
        a, b = a
        no = 0
        mt = 10 ** 10
        for j, c in enumerate(cd):
            c, d = c
            tt = abs(a - c) + abs(b - d)
            if tt < mt:
                mt = tt
                no = j + 1
        print(no)


if __name__ == '__main__':
    slove()

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

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

x_2=[]
y_2=[]
for i in range(m):
    c,d=map(int,input().split())
    x_2.append(c)
    y_2.append(d)
    
for i in range(n):
    min_l=abs(x_1[i]-x_2[0])+abs(y_1[i]-y_2[0])
    ans=0
    for j in range(m):
        e=abs(x_1[i]-x_2[j])+abs(y_1[i]-y_2[j])
    
        if min_l >e:
            min_l=e
            ans=j
    print(ans+1)

Solution (Python):
n, m = map(int, input().split())
list_place_student = []
for _ in range(n):
  a, b = map(int, input().split())
  list_place_student.append((a, b))
list_checkpoint = []
for _ in range(m):
  c, d = map(int, input().split())
  list_checkpoint.append((c, d))
  
result = []
for place in list_place_student:
  min_dist = 10 ** 9
  min_point = 100
  for i, point in enumerate(list_checkpoint):
    temp_dist = abs(place[0] - point[0]) + abs(place[1] - point[1])
    if temp_dist < min_dist:
      min_dist = temp_dist
      min_point = i + 1
  result.append(min_point)

for one_result in result:
  print(one_result)

Solution (Python):
n,m=map(int,input().split())
a=[list(map(int, input().split())) for i in range(n)]
c=[list(map(int, input().split())) for i in range(m)]
r=[]
for i in range(n):
    l=[0]*(m)
    for j in range(m):
        l[j]=abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])
    r.append(l)

for i in range(n):
    q=min(r[i])
    for j in range(m):
        if r[i][j]==q:
            print(j+1)
            break

Solution (Python):
n,m = map(int,input().split())       
a = [list(map(int,input().split())) for i in range(n)]
c = [list(map(int,input().split())) for i in range(m)]
for i in a:
  index = 1;
  ans = abs(i[0]-c[0][0])+abs(i[1]-c[0][1])
  for o,j in enumerate(c[1:]):
    ans_ = abs(i[0]-j[0])+abs(i[1]-j[1])
    if ans > ans_:
      ans = ans_
      index = o+2
  print(index)

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 i in range(n):
    mi=10000000000000
    ans=-1
    for j in range(m):
        k=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if mi>k:
            ans=j+1
            mi=k
    print(ans)

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

student_points = list(map(lambda _: list(map(int, input().split())), range(n)))
check_points = list(map(lambda _: list(map(int, input().split())), range(m)))

for s_p in student_points:
    min_index = 0
    min_distance = abs(s_p[0] - check_points[0][0]) + abs(s_p[1] - check_points[0][1])
    for j, c_p in enumerate(check_points):
        d = abs(s_p[0] - check_points[j][0]) + abs(s_p[1] - check_points[j][1])
        if d < min_distance:
            min_distance = d
            min_index = j
    print(min_index + 1)

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

student_points = list(map(lambda _: list(map(int, input().split())), range(n)))
check_points = list(map(lambda _: list(map(int, input().split())), range(m)))

for s_p in student_points:
    min_index = 0
    min_distance = abs(s_p[0] - check_points[0][0]) + abs(s_p[1] - check_points[0][1])
    for j, c_p in enumerate(check_points):
        d = abs(s_p[0] - check_points[j][0]) + abs(s_p[1] - check_points[j][1])
        if d < min_distance:
            min_distance = d
            min_index = j
    print(min_index + 1)

Solution (Python):
N,M=map(int,input().split())
S=[list(map(int,input().split())) for n in range(N)]
C=[list(map(int,input().split())) for m in range(M)]
for s in S:
    l=[]
    for c in C:
        l.append(abs(s[0]-c[0])+abs(s[1]-c[1]))
    print(l.index(min(l))+1)

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

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

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

for n in range(N):
  man=400000001
  for m in range(M):
    dis=abs(student[n][0]-check[m][0])+abs(student[n][1]-check[m][1])
    point=m+1
    if dis<man:
      man=dis
      ans=point
  print(ans)

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 i in range(N):
  tmp = float("inf")
  ans = 0
  for j in range(M):
    if abs(AB[i][0]-CD[j][0]) + abs(AB[i][1]-CD[j][1]) < tmp:
      tmp = abs(AB[i][0]-CD[j][0]) + abs(AB[i][1]-CD[j][1])
      ans = j + 1
  print(ans)

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 i in range(n):
    min_dis = float("inf")
    min_idx = 0
    for j in range(m):
        dis = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if dis < min_dis:
            min_dis = dis
            min_idx = j
    print(min_idx + 1)

Solution (Python):
n, m = map(int, input().split())
A = [0] * n
B = [0] * n
C = [0] * m
D = [0] * m
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):
  min_len = 10**8 * 2 + 1
  min_j = 0
  for j in range(m):
    if abs(A[i] - C[j]) + abs(B[i] - D[j]) < min_len:
      min_len = abs(A[i] - C[j]) + abs(B[i] - D[j])
      min_j = j
  print(min_j + 1)

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 i in range(N):
    res = 1000000000
    tidx = 0
    for j in range(M):
        dist = abs(AB[i][0]-CD[j][0]) + abs(AB[i][1]-CD[j][1])
        if res > dist:
            res = dist
            tidx = j+1
    print(tidx)

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):
    x=[]
    for j in range(m):
        x.append([abs(a[i]-c[j])+abs(b[i]-d[j]),j+1])
    x.sort()
    print(x[0][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 i in range(m)]

for i in range(n):
  x=[]
  for j in range(m):
    x.append(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]))
  print(x.index(min(x))+1)

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

for s in S:
    a,b = s
    l = 10**8*2
    ans = 0
    for i,p in enumerate(P):
        c,d = p
        if abs(a-c) + abs(b-d) < l:
            l = abs(a-c) + abs(b-d)
            ans = i
    print(ans+1)

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


for i in range(N):
    distance = abs(a[i] - c[0]) + abs(b[i] - d[0])
    check_point = 1
    for j in range(M):
        temp = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if distance > temp:
            distance = temp
            check_point = j + 1
    print(check_point)

Solution (Python):
n,m=map(int,input().split())
al=[]
cl=[]
for i in range(n):
    al.append(list(map(int,input().split())))
for i in range(m):
    cl.append(list(map(int,input().split())))
for i in range(n):
    cost=[]
    for j in range(m):
        cost.append(abs(al[i][0]-cl[j][0])+abs(al[i][1]-cl[j][1]))
    print(cost.index(min(cost))+1)

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

for student in students:
    nearst_index = 0
    _min = 10**10
    for point_index in range(len(checkpoints)):
        diff = abs(student[0] - checkpoints[point_index][0])+abs(student[1] - checkpoints[point_index][1])
        if diff < _min:
            _min = diff
            nearst_index = point_index+1
    print(nearst_index)

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)]
m = 10**9
for i in range(N):
    for l in range(M):
        c = abs(ab[i][0]-cd[l][0])+abs(ab[i][1]-(cd[l][1]))
        if c < m :
            m = c
            t = l+1
    print(t)
    m = 10**9

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

temp = []
for n in range(N):
    temp = list(map(int, input().split())) 
    a.append(temp[0])
    b.append(temp[1])

temp = []
for m in range(M):
    temp = list(map(int, input().split())) 
    c.append(temp[0])
    d.append(temp[1])

ans = []
st = []
i = 0
while i < N:
    st.append(abs(a[i] - c[0]) + abs(b[i] - d[0]))
    ans.append(1)
    k = 1
    while k < M:
        temp = abs(a[i] - c[k]) + abs(b[i] - d[k])
        if temp < st[i]:
            st[i] = temp
            ans[i] = k + 1
        k += 1
    i += 1

for i in ans:
    print(i)

Solution (Python):
n,m = map(int,input().split())
st = [[int(i) for i in input().split()] for j in range(n)]
ch = [[int(i) for i in input().split()] for j in range(m)]
ans =[]
for i in range(n):
    a = st[i][0]
    b = st[i][1]
    md = [abs(a-ch[j][0]) + abs(b -ch[j][1]) for j in range(m)]
    ans += [md.index(min(md))+1]
for i in range(n):
    print(ans[i])

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    V=[tuple(map(int,input().split())) for _ in range(n)]
    C=[tuple(map(int,input().split())) for _ in range(m)]
    ans=[0]*n
    for i in range(n):
        dist=INF
        ind=0
        for j in range(m):
            d=abs(V[i][0]-C[j][0])+abs(V[i][1]-C[j][1])
            if d<dist:
                ind=j
                dist=d
        print(ind+1)
resolve()

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

for i in range(N):
  min=abs(li[i][0]-check[0][0])+abs(li[i][1]-check[0][1])
  minindex=0
  for j in range(M):
    dis=abs(check[j][0]-li[i][0])+abs(check[j][1]-li[i][1])
    if dis<min:
      min=dis
      minindex=j
  print(minindex+1)

Solution (Python):
from collections import deque

N, M = [int(n) for n in input().split()]
P = deque([tuple(map(lambda n: int(n), input().split())) for _ in range(N)])
C = [tuple(map(lambda n: int(n), input().split())) for _ in range(M)]

def nearest(p, checkpoints):
    d = float('inf')
    x, y = p
    for i, c in enumerate(checkpoints):
        xi, yi = c
        dn = abs(x - xi) + abs(y - yi)
        if d > dn:
            d = dn
            idx = i
    return str(idx + 1)

def main():
    ans = []
    while P:
        p = P.popleft()
        ans.append(nearest(p, C))
    print('\n'.join(ans))

if __name__ == '__main__':
    main()

Solution (Python):
n, m = map(int, input().split())
ls0 = [list(map(int, input().split())) for _ in range(n)]
ls1 = [list(map(int, input().split())) for _ in range(m)]
for i in range(n):
    x0, y0 = ls0[i]
    index = 0
    md = float('inf')
    for j in range(m):
        x1, y1 = ls1[j]
        d = abs(x0 - x1) + abs(y0 - y1)
        if d < md:
            md = d
            index = j
    print(index + 1)

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

for i in range(n):
    num = []
    for j in range(m):
        num.append(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]))
    else:
        mini = min(num)
        print(num.index(mini)+1)
        num = []

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)]

ans=[]
for ab in AB:
  min_m=10**10
  for i,cd in enumerate(CD):
    
    m=abs(ab[0]-cd[0])+abs(ab[1]-cd[1])
    if min_m>m:
      min_m=m
      min_i=i+1
  ans.append(min_i)


for a in ans:
  print(a)

Solution (Python):
a,b = map(int,input().split())
st,ch = [],[]
for i in range(a):
    c,d = map(int,input().split())
    st.append([c,d])
for i in range(b):
    c,d = map(int,input().split())
    ch.append([c,d])    

for i in range(len(st)):
    li = []
    for j in range(len(ch)):
        dis = abs(st[i][0] - ch[j][0]) + abs(st[i][1] - ch[j][1])
        li.append(dis)
    
    print(li.index(min(li))+1)

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

a=[]

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

c=[]

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


for i in range(N):
    ans=1000
    min=1000000000
    for j in range(M):
        d=abs(c[j][0]-a[i][0])+abs(c[j][1]-a[i][1])
        if d <min:
            ans=j+1
            min=d
    print(ans)

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 i in range(M)]

for i in range(N):
    ans = 0
    a,b = AB[i]
    tmp = float("inf")
    for j in range(M):
        c,d = CD[j]
        if abs(a-c)+abs(b-d) < tmp:
            tmp = abs(a-c)+abs(b-d)
            ans = j+1
    print(ans)

Solution (Python):
def resolve():
    n, m = map(int, input().split())
    ab = list(list(map(int, input().split())) for _ in range(n))
    cd = list(list(map(int, input().split())) for _ in range(m))
    for a, b in ab:
        p = min(cd, key=lambda x: abs(x[0] - a) + abs(x[1] - b))
        print(cd.index(p) + 1)


if __name__ == "__main__":
    resolve()

Solution (Python):
N,M = map(int,input().split())
students = [list(map(int, input().split())) for _ in range(N)]
points =  [list(map(int, input().split())) for _ in range(M)]
for student in students:
  dis_list = [abs(student[0]-point[0]) + abs(student[1]-point[1]) for point in points]
  min_dis = min(dis_list)
  print(dis_list.index(min_dis)+1)

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

AB = []

for _ in range(N):
    AB.append(list(map(int, input().split())))

CD = []

for _ in range(M):
    CD.append(list(map(int, input().split())))

for i in range(N):
    distance = 10**9+7
    for j in range(M)[::-1]:
        temp = abs(AB[i][0] - CD[j][0]) + abs(AB[i][1] - CD[j][1])
        
        
        if temp <= distance:
            distance = temp
            ans = j+1
            
    print(ans)

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:
    dis = float('inf')
    for i, cd in enumerate(CD):
        now_dis = abs(a - cd[0]) + abs(b - cd[1])
        if now_dis < dis:
            dis = now_dis
            checkpoint = i+1
    print(checkpoint)

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)]

def f(a, b, x, y):
    return abs(a-x) + abs(b-y)

ans = [0] * N
for i, _ab in enumerate(ab):
    temp = float("inf")
    for j, _cd in enumerate(cd):
        dist = f(_ab[0], _ab[1], _cd[0], _cd[1])
        if dist < temp: 
            temp, ans[i] = dist, j + 1

for r in ans:
    print(r)

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 i in range(n):
    minNum, minCnt = 0, -1
    for j in range(m):
        abcdLen = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
        if minCnt == -1 or minCnt > abcdLen:
            minCnt, minNum = abcdLen, j + 1
    print(minNum)

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 i in range(n):
    a, b = ab[i][0], ab[i][1]
    minNum, minCnt = 0, -1
    for j in range(m):
        c, d = cd[j][0], cd[j][1]
        abcdLen = abs(a-c) + abs(b-d)
        if minCnt == -1 or minCnt > abcdLen:
            minCnt, minNum = abcdLen, j + 1
    print(minNum)

Solution (Python):

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

for i in range(n):
    ans = 0
    dis = float("inf")
    for j in range(m):
        mnh = abs(A[i][0]-C[j][0]) + abs(A[i][1]-C[j][1])
        if mnh < dis:
            
            dis = mnh
            ans = j
    print(ans+1)

Solution (Python):
N, M = tuple(map(int, input().split()))
A, B = [], []
for i in range(N):
    a, b = tuple(map(int, input().split()))
    A.append(a)
    B.append(b)
C, D = [], []
for i in range(M):
    c, d = tuple(map(int, input().split()))
    C.append(c)
    D.append(d)
ans = [0] * N
for i, (a, b) in enumerate(zip(A, B)):
    min_diff = float('inf')
    for idx, (c, d) in enumerate(zip(C, D), 1):
        diff = abs(a - c) + abs(b - d)
        if diff < min_diff:
            ans[i] = idx
            min_diff = diff
for x in ans:
    print(x)

Solution (Python):
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 a, b in AB:
    ans, maxD = 0, 10 ** 10
    for i, (c, d) in enumerate(CD):
        if abs(a - c) + abs(b - d) < maxD:
            ans, maxD = i + 1, abs(a - c) + abs(b - d)
    print(ans)

Solution (Python):
import math
import heapq
from collections import defaultdict, Counter
import sys
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7


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

    for i in range(n):
        c = float("inf")
        ans = 0
        for j in range(m):
            if c > abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]):
                c = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
                ans = j + 1
        print(ans)


if __name__ == '__main__':
    main()

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

student = [[0 for i in range(3)] for j in range(n)]
check_point = [[0 for i in range(2)] for j in range(m)]

for i in range(n):
  student[i][0], student[i][1] = map(int, input().split())
for i in range(m):
  check_point[i][0], check_point[i][1] = map(int, input().split())

for i in range(n):
  minlen = 400000001  
  for j in range(m):
    length = abs(student[i][0] - check_point[j][0]) + abs(student[i][1] - check_point[j][1])
    if length < minlen:
      minlen = length
      student[i][2] = j + 1
  
  print(student[i][2])

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(N)]
    cd = [list(map(int, input().split())) for i in range(M)]

    ans = [0] * N
    for i in range(N):
        x, y = ab[i]
        c, d = cd[0]
        min_d = abs(c - x) + abs(d - y)
        min_index = 0
        for j in range(M):
            c, d = cd[j]
            tmp = abs(c - x) + abs(d - y)
            if tmp < min_d:
                min_d = tmp
                min_index = j
        ans[i] = min_index
    
    for i in range(N):
        print(ans[i]+1)
            

if __name__ == "__main__":
    main()

Solution (Python):
n,m = map(int,input().split())
l1 = []
l2 = []
for _ in range(n):
	a,b = map(int,input().split())
	l1.append((a,b))
for _ in range(m):
	c,d = map(int,input().split())
	l2.append((c,d))
for a,b in l1:
	mi = 1e9
	i = 0
	for j,(c,d) in enumerate(l2):
		dist = abs(a-c)+abs(b-d)
		if dist < mi:
			mi = dist
			i = j
	print(i+1)

Solution (Python):


n, m = map(int, input().split())

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









        
for v_s in students:
    print(min(range(1, m + 1), key=lambda i: abs(checkpoint[i - 1][0] - v_s[0]) + abs(checkpoint[i - 1][1] - v_s[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 i in range(M)]
ans = [0]*N
for i in range(N):
    dist = 4*(10**8)
    for j in range(M):
        if abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])<dist:
            dist = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            ans[i] = j+1
for i in range(N):
    print(ans[i])

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)]
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):
    ans=0
    mi=float('inf')
    for j in range(m):
        if(mi>abs(a[i]-c[j])+abs(b[i]-d[j])):
            ans=j+1
            mi=abs(a[i]-c[j])+abs(b[i]-d[j])
    print(ans)

Solution (Python):
N,M=map(int,input().split());A=[map(int,input().split())for _ in range(N)];C=[list(map(int,input().split()))for _ in range(M)]
for a,b in A:print(min([(i,abs(c-a)+abs(d-b))for i,(c,d)in enumerate(C,1)],key=lambda x:x[1])[0])

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 i in range(m)]


def CheckPoint(x,y):
    ans = 1
    before = abs(cd[0][0]-x) + abs(cd[0][1]-y)
    for i in range(m):
        if abs(cd[i][0]-x) + abs(cd[i][1]-y) < before:
            before = abs(cd[i][0]-x) + abs(cd[i][1]-y)
            ans = i+1
    return ans

for xy in ab:
    print(CheckPoint(xy[0],xy[1]))

Solution (Python):
n,m = map(int,input().split())
students = []
for i in range(n):
    student = list(map(int,input().split()))
    students.append(student)
checkpoints = []
for i in range(m):
    checkpoint = list(map(int,input().split()))
    checkpoints.append(checkpoint)

for student in students:
    for i in range(m):
        if i == 0:
            judge = abs(student[0]-checkpoints[i][0]) + abs(student[1]-checkpoints[i][1])
            place = 0
        manhattan = abs(student[0]-checkpoints[i][0]) + abs(student[1]-checkpoints[i][1])
        if judge > manhattan:
            judge = manhattan
            place = i
    print(place+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 A:
  D=[abs(i[0]-j[0])+abs(i[1]-j[1]) for j in C]
  print(D.index(min(D))+1)

Solution (Python):
N, M = map(int, input().split())
stu = []
che = []
for i in range(N):
    A = list(map(int, input().split()))
    stu.append(A)
for i in range(M):
    B = list(map(int, input().split()))
    che.append(B)
for i in range(N):
    poi = []
    for j in range(M):
        poi.append(abs(stu[i][0]-che[j][0])+abs(stu[i][1]-che[j][1]))
    print(poi.index(min(poi))+1)

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

for i in range(m[0]):
    p=[]
    for j in range(m[1]):
      p.append( abs( a[i][0]-c[j][0])+ abs( a[i][1]-c[j][1]) )
    print(p.index(min(p))+1 )

Solution (Python):
N,M = map(int,input().split())
ab = [[int(x) for x in input().split()]for i in range(N)]
cd = [[int(x) for x in input().split()]for i in range(M)]
for i in range(N):
  a,b = ab[i]
  ans = [10**9,-1]
  for j in range(M):
    if ans[0] > abs(cd[j][0]-a)+abs(cd[j][1]-b):
      ans = [abs(cd[j][0]-a)+abs(cd[j][1]-b),j+1]
  print(ans[1])

Solution (Python):
n,m=map(int,input().split())
ab=[]
for _ in range(n):
    ab.append(list(map(int,input().split())))
cd=[]
for _ in range(m):
    cd.append(list(map(int,input().split())))
for i in range(n):
    tmp=float('inf')
    ans=0
    for j in range(m):
        if tmp>abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]):
            tmp=abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
            ans=j+1
    print(ans)

Solution (Python):
N, M = map(int, input().split())
AB = []
for i in range(N):
  AB.append(list(map(int, input().split())))
CD = []
for i in range(M):
  CD.append(list(map(int, input().split())))
idx = 0
for i in range(N):
  d0 = 9900000000
  for j in range(M):
    d = abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1])
    if d0 > d:
      d0 = d
      idx = j+1
  print(idx)

Solution (Python):
a,c = map(int,input().split())
ax = []
ay = []
cx = []
cy = []
mindistance = 10 ** 10
point = 0
for hogehoge in range(a):
         axx,ayy = input().split()
         ax.append(int(axx))
         ay.append(int(ayy))
for hogehoge in range(c):
         cxx,cyy = input().split()
         cx.append(int(cxx))
         cy.append(int(cyy))
for i in range(a):
         for j in range(c):
                  temp = (abs(ax[i] - cx[j]) + abs(ay[i] - cy[j]))
                  if mindistance > temp:
                           mindistance = temp
                           point = j
         else:
                  print(point+1)
                  mindistance = 10 ** 10
                  point = 0

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 i in range(n):
    mn = 10 ** 9
    ans = 0
    for j in range(m):
        diff = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if diff < mn:
            mn = diff
            ans = j + 1
    print(ans)

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

for a,b in ab:
    check=float('inf')
    for i in range(m):
        if abs(a-cd[i][0])+abs(b-cd[i][1]) < check:
            ans=i
            check=abs(a-cd[i][0])+abs(b-cd[i][1])
    print(ans+1)