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

for i in range(n):
    a, b = AB[i]
    res = float("inf")
    for j in range(m):
        c, d = CD[j]
        dist = abs(a - c) + abs(b - d)
        if res > dist:
            res = dist
            ans = j + 1
    print(ans)

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)]
for i in range(N):
  m = 1000000000
  cnt = -1
  pnt = p[i][:]
  for j in range(M):
    d = abs(pnt[0] - q[j][0]) + abs(pnt[1] - q[j][1])
    if m > d:
      cnt = j
      m = d
  print(cnt+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)]
INF = 4*10**9+1

for i in range(N):
    ans,dist = 0,INF
    for j in range(M):
        if dist > abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]):
            ans = j + 1
            dist = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
    print(ans)

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

check=[]
for i in range(m):
    check.append([int(i) for i in input().split()])
ans=[]
for i in students:
    x,y=i
    move=None
    minhat=1000000000
    for j in  range(m):
        x2,y2=check[j]
        manhat=abs(x-x2)+abs(y-y2)
        if manhat<minhat:
            minhat=manhat
            move=j
    ans.append(move+1)
for i in range(len(ans)):
    print(ans[i])

Solution (Python):

import math





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

a = []
b = []
c = []
d = []

for i in range(n):
    x,y = [int(j) for j in input().split()]
    a.append(x)
    b.append(y)

for i in range(m):
    x,y = [int(j) for j in input().split()]
    c.append(x)
    d.append(y)

for i in range(n):
    dist_min = 1000000000
    dist_index = n+m
    for j in range(m):
        dist = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if dist <= dist_min:
            if dist!=dist_min:
                dist_index = j
            dist_min = dist

        
        
    print(dist_index+1)

Solution (Python):








INF = 1000000007

N, M = map(int, input().split())

ab = []

for i in range(N):
    ab.append([int(i) for i in input().split()])

cd = []

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

for i in range(N):
    ans = 0
    dst = INF
    for j in range(M):
        tmp = abs(cd[j][0] - ab[i][0]) + abs(cd[j][1] - ab[i][1])

        if tmp < dst:
            
            dst = tmp
            ans = j + 1

    print(ans)

Solution (Python):
import math

n, m = map(int, input().split())
ns, ms = range(n), range(m)
students = []
for i in ns:
    a, b = map(int, input().split())
    students.append([a, b])
checkpoints = []
for i in ms:
    c, d = map(int, input().split())
    checkpoints.append([c, d])

for i in ns:
    ans = [0, float('inf')]
    for j in ms:
        dist = abs(students[i][0] - checkpoints[j][0]) + abs(students[i][1] - checkpoints[j][1])
        if dist < ans[1]:
            ans = [j + 1, dist]
    print(ans[0])

Solution (Python):
n,m=map(int,input().split())
stu=[]
far=[]
plc=[]
for i in range(n):
    a,b=map(int,input().split())
    stu.append([a,b])
for i in range(m):
    c,d=map(int,input().split())
    plc.append([c,d])
for i in range(n):
    far=[]
    for j in range(m):
        far.append(abs(stu[i][0]-plc[j][0])+abs(stu[i][1]-plc[j][1]))
    print(far.index(min(far))+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 ab:
    ans = []
    for j in cd:
        ans.append(abs(i[0] - j[0]) + abs(i[1] - j[1]))
    print(ans.index(min(ans))+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):
    ans=[]
    for j in range(m):
        ans.append(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]))
    print(ans.index(min(ans))+1)

Solution (Python):



N,M = list(map(int, input().split()))
a,b = [],[]
for n in range(N):
    a_n,b_n = [int(i) for i in input().split()]
    a.append(a_n)
    b.append(b_n)
c,d = [],[]
for m in range(M):
    c_m,d_m = [int(i) for i in input().split()]
    c.append(c_m)
    d.append(d_m)


nearest_checkpoint_list = []
for n in range(N):
    a_n = a[n]
    b_n = b[n]

    nearest_checkpoint = 0
    min_manhattan_distance = abs(a_n - c[0]) + abs(b_n - d[0])

    for m in range(1, M):
        manhattan_distance = abs(a_n - c[m]) + abs(b_n - d[m])
        if min_manhattan_distance > manhattan_distance:
            min_manhattan_distance = manhattan_distance
            nearest_checkpoint = m

    nearest_checkpoint_list.append(nearest_checkpoint + 1)


for n in range(N):
    print(nearest_checkpoint_list[n])

Solution (Python):
def distance(ab, cd):
  return abs(ab[0] - cd[0]) + abs(ab[1] - cd[1])

N, M = map(int, input().split())
AB = []
for _ in range(N):
  a, b = map(int, input().split())
  AB.append((a, b))

CD = []
for _ in range(M):
  c, d = map(int, input().split())
  CD.append((c, d))

check_index = []
for i, ab in enumerate(AB):
  min_index = 0
  for j, cd in enumerate(CD):
    check_dis = distance(ab, cd)
    min_dis = distance(ab, CD[min_index])
    if(min_dis > check_dis):
      min_index = j
  
  check_index.append(min_index)

for ci in check_index:
  print(ci + 1)

Solution (Python):
N, M = map(int, input().split())
man = [[int(x) for x in input().split()] for _ in range(N)]
check = [[int(x) for x in input().split()] for _ in range(M)]

for a, b in man:
    tmp = 1000000000
    ans = 1
    for i, (c, d) in enumerate(check):
        if tmp > (abs(a-c) + abs(b-d)):
            tmp = min(tmp, abs(a-c) + abs(b-d))
            ans = i+1
    print(ans)

Solution (Python):




"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""








def main():
  n,m = map(int,input().split())
  
  AB = [map(int,input().split()) for _ in range(n)]
  CD = [list(map(int,input().split())) for _ in range(m)]
  idx = 1

  for i in range(n):
    a,b = AB[i]
    man = float("inf")
    for j in range(m-1,-1,-1):
      c,d = CD[j]
      if abs(a-c) + abs(b-d) <= man:
        man = abs(a-c) + abs(b-d)
        idx = j
    print(idx+1)
      
  
if __name__ == '__main__':
  main()

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):
    l=[]
    for j in range(m):
        l.append(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]))
    k=l.index(min(l))+1
    print(k)

Solution (Python):
n,m = map(int,input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
cd = []
for _ in range(m):
    c, d = (int(x) for x in input().split())
    cd.append([c, d])

for a,b in ab:
    ans = 10000000000000000000000
    for k,c in enumerate(cd):
        memo = abs(a-c[0])+abs(b-c[1])
        if memo<ans:
            ans=memo
            ansnum=k
    print(ansnum+1)

Solution (Python):
n, m = [int(_) for _ in input().split()]
student = [[int(x) for x in input().split()] for i in range(n)]
check = [[int(x) for x in input().split()] for i in range(m)]
for s in student:
  d = 10**12
  i = -1
  for ii, c in enumerate(check, 1):
    dd = abs(s[0] - c[0]) + abs(s[1] - c[1])
    if dd < d:
      d = dd
      i = ii
  print(i)

Solution (Python):
import numpy as np
N,M = map(int, input().split())

p = [tuple(map(int,input().split()))for i in range(N)]
c = [tuple(map(int,input().split()))for i in range(M)]

def distance(a,b):
  return abs(a[0]-b[0]) + abs(a[1]- b[1])

for i in p:
  print(np.argmin([distance(i,j)for j in c])+1)

Solution (Python):
n,m = map(int,input().split())
x = [list(map(int,input().split()))for i in range(n)]
y = [list(map(int,input().split()))for i in range(m)]
ans = []
for a,b in x:
    dif = 10**9
    index = -1
    for i in range(m):
        c,d = y[i]
        if dif>abs(a-c)+abs(b-d):
            dif=abs(a-c)+abs(b-d)
            index = i+1
    ans.append(index)
for i in ans:
    print(i)

Solution (Python):
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, M = MI()
AB = [tuple(MI()) for _ in range(N)]
CD = [tuple(MI()) for _ in range(M)]
for a, b in AB:
    min_dist = INF
    ans = 0
    for i, (c, d) in enumerate(CD):
        dist = abs(a - c) + abs(b - d)
        if dist < min_dist:
            min_dist = dist
            ans = i + 1
    print(ans)

Solution (Python):
import math
n,m = map(int,input().split())
a = []
c = []
for i in range(n):
    a.append(input().split())
for i in range(m):
    c.append(input().split())
for i in range(n):
    d = float('inf')
    for j in range(m):
        b = abs(int(a[i][0]) - int(c[j][0])) + abs(int(a[i][1]) - int(c[j][1]))
        if d > b:
            d = b
            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)]

kouho = [[] for _ in range(N)]

n = 0
for i, j in ab:
    for k, l in cd:
        kouho[n].append(abs(i-k) + abs(j-l))
    n += 1

for i in range(N):
    Nmin = min(kouho[i])
    for j, k in enumerate(kouho[i]):
        if k == Nmin:
            print(j+1)
            break

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()
ab = nan(n)
cd = nan(m)

ans = [-1] * n
for i in range(n):
    a, b = ab[i]
    min_val = inf
    for j in range(m):
        c, d = cd[j]
        dist = abs(a - c) + abs(b - d)
        if min_val > dist:
            min_val = dist
            ans[i] = j + 1

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

Solution (Python):
N, M = list(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)]

def checkdist(student,checkpoint):
    a, b = student
    c, d = checkpoint
    
    distance = abs(a-c) + abs(b-d)
    return distance

result = {}

for i in range(len(students)):
    result[i] = 0
    
for i, student in enumerate(students):
    lowest_dist = checkdist(student, checkpoints[0])
    for j, checkpoint in enumerate(checkpoints):
        distance = checkdist(student,checkpoint)
        if distance < lowest_dist:
            result[i] = j
            lowest_dist = distance

for i in range(len(students)):
    print(result[i] + 1)

Solution (Python):

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



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

for i in range(n):
    templ=[]
    a=corl[i][0]
    b=corl[i][1]
    for j in range(m):
        c=chkl[j][0]
        d=chkl[j][1]
        templ.append([j,abs(a-c)+abs(b-d)])
    templ.sort(key=lambda x:(x[1],x[0]))
    print(templ[0][0]+1)

Solution (Python):
n,m=map(int,input().split())
A=[]
B=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
C=[]
D=[]
for i in range(m):
    c,d=map(int,input().split())
    C.append(c)
    D.append(d)

for i in range(n):
    d=100000000000000000
    for j in range(m):
        now=abs(A[i]-C[j])+abs(B[i]-D[j])
        if now<d:
            d=now
    for j in range(m):
        now=abs(A[i]-C[j])+abs(B[i]-D[j])
        if now==d:
            print(j+1)
            break

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 i in range(N):
    ans = float('Inf')
    for j in range(M):
        dist = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if dist < ans:
            ans = dist
            output = j
    print(output + 1)

Solution (Python):
n, m = map(int, input().split())
a_list = []
b_list = []
for i in range(n):
	a, b = map(int, input().split())
	a_list.append(a)
	b_list.append(b)
c_list = []
d_list = []
for i in range(m):
	c, d = map(int, input().split())
	c_list.append(c)
	d_list.append(d)
for i, x1 in enumerate(a_list):
	y1 = b_list[i]
	v_list = []
	for j, x2 in enumerate(c_list):
		y2 = d_list[j]
		v_list.append(abs(x1 - x2) + abs(y1 - y2))
	print(v_list.index(min(v_list)) + 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):
    k=0
    ans=1
    num=10**9
    for j in range(m):
        k=abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])
        
    
        if num>k:
            num=k
            ans=j+1
            
    else:
        print(ans)

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 j in range(M):
  c[j],d[j] = map(int,input().split())

e=[0]*N
for k in range(N):
  dist=float("inf")
  pos=0
  for l in range(M):
    tmp = abs(c[l]-a[k])+abs(d[l]-b[k])
    if dist>tmp:
      dist=tmp
      pos=l
  e[k]=pos+1
  
for ans in e:
  print(ans)

Solution (Python):
N,M = map(int,input().split())
a,b = list(),list()
res = list()
for i in range(N):
  t = input().split()
  a.append(int(t[0]))
  b.append(int(t[1]))
  res.append([0,0])
for n in range(M):
  c,d = map(int,input().split())
  for i in range(N):
    if n == 0:
      res[i][0] = abs(a[i]-c) + abs(b[i]-d) 
    elif res[i][0] > abs(a[i]-c) + abs(b[i]-d):
      res[i][0] = abs(a[i]-c) + abs(b[i]-d)
      res[i][1] = n
for m in range(N):
  print(res[m][1] + 1)

Solution (Python):
n,m = map(int,input().split())
l_n =list(list(map(int,input().split())) for i in range(n))
l_m =list(list(map(int,input().split())) for i in range(m))
for i in range(n):
  q = 10**9
  for t in range(m):
    a,b = l_n[i]
    c,d = l_m[t]
    v= abs(a-c)+abs(b-d)
    if v<q:
      q = v
      z = t
  print(z+1)

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

for student_pos in student_pos_list:
    min_d = 20**8+1
    min_pt_index = m+1
    for i, checkpt in enumerate(checkpoint_list):
        d = abs(student_pos[0] - checkpt[0]) + abs(student_pos[1] - checkpt[1])
        if d < min_d:
            min_d = d
            min_pt_index = i+1

    print(min_pt_index)

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

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

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

for s in student:
    dist = float('inf')
    ans = 0
    for i, c in enumerate(check):
        tmp = abs(s[0]-c[0]) + abs(s[1]-c[1])
        if tmp<dist:
            ans = i+1
            dist = tmp
    print(ans)

Solution (Python):
import numpy as np
N, M = [int(i) for i in input().split()]

a = np.ones(N)
b = np.ones(N)

c = np.ones(M)
d = np.ones(M)

for i in range(N):
    a[i],b[i] = [int(i) for i in input().split()]
    
for i in range(M):
    c[i],d[i] = [int(i) for i in input().split()]
    
    
for i in range(N):
    ans = 1
    min_sofar = abs(a[i]-c[0]) + abs(b[i] - d[0])
    for j in range(M):
        candid = abs(a[i]-c[j]) + abs(b[i] - d[j])
        if min_sofar > candid:
            ans = j+1
            min_sofar = candid
        
    print(int(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):
    min_ = 10**10
    index = 0
    for j in range(M):
        if abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]) < min_:
            index = j+1
            min_ = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
    print(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)]

ans=[]
for i in range(n):
    MIN=10**10
    index=0
    for g in range(m):
        if MIN>abs(ab[i][0]-cd[g][0])+abs(ab[i][1]-cd[g][1]):
            MIN=abs(ab[i][0]-cd[g][0])+abs(ab[i][1]-cd[g][1])
            index=g+1
    ans.append(index)

for i in range(n):
    print(ans[i])

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

Solution (Python):
import math
N, M = map(int,input().split())
st = dict()
cp = dict()
for i in range(N):
    st[i+1] = list(map(int,input().split()))

for j in range(M):
    cp[j+1] = list(map(int,input().split()))

for k in st.keys():
    a, b = st[k]
    ans = dict()
    for l in cp.keys():
        c, d = cp[l]
        pi = abs(a-c) + abs(b-d)
        ans[l] = pi
    st[k] = min(ans,key=ans.get)
        

for m in st.keys():
    print(st[m])

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

Solution (Python):
from collections import defaultdict

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

aa = []
bb = []
cc = []
dd = []
answer = []

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

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

for i in range(n):
    ans = float('inf')
    for j in range(m):
        distance = abs(aa[i]-cc[j]) + abs(bb[i]-dd[j])
        if ans > distance:
            ans = min(distance, ans)
            num = j+1
    answer.append(num)

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

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:
    mn = 10 ** 9
    record = 0
    for j, v in enumerate(c):
        temp = abs(i[0] - v[0]) + abs(i[1] - v[1])
        if temp < mn:
            mn = temp
            record = j + 1
    print(record)

Solution (Python):
N,M = map(int,input().split(" "))
students = [tuple(map(int,input().split(" "))) for _ in range(N)]
checkpoints = [tuple(map(int,input().split(" "))) for _ in range(M)]
Ans = [(0,4*(10**8))]*N




i = 0
for n in students:
    j=0
    for m in checkpoints:
        j+=1
        dist = abs(n[0]-m[0])+abs(n[1]-m[1])
        if dist<Ans[i][1]:
            Ans[i] = (j,dist)
    i+=1
    


for ans in Ans:
    print(ans[0])

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

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

cs = []
for m in range(M):
  cs.append(list(map(int, input().split())))
  
for n in range(N):
  min_d = 100000000000000
  min_i = -1
  for m in range(M):
    d = abs(st[n][0]-cs[m][0]) + abs(st[n][1]-cs[m][1])
    if d < min_d:
      min_d = d
      min_i = m
  print(min_i+1)

Solution (Python):

N,M = map(int,input().split())
L1 = []
L2 = []

for i in range(N):
    a,b = map(int,input().split())
    L1.append([a,b])
for m in range(M):
    c,d = map(int,input().split())
    L2.append([c,d])

for j in range(N):
    L3 = []
    for l in range(M):
        L3.append(abs(L1[j][0]-L2[l][0]) + abs(L1[j][1]-L2[l][1]))
    print(L3.index(min(L3))+1)

Solution (Python):
N, M = map(int, input().split())
slist = []
plist = []

for i in range(N):
  a, b = map(int, input().split())
  slist.append([a,b])  
  
for i in range(M):
  c, d = map(int, input().split())
  plist.append([c,d])

for i in range(N):
  list = []
  for j in range(M):
    list.append(abs(slist[i][0] - plist[j][0]) + abs(slist[i][1] - plist[j][1]))
  print(list.index(min(list)) + 1)

Solution (Python):
N,M=map(int,input().split())
a=[[int(b) for b in input().split()] for i in range(N)]
c=[[int(d) for d in input().split()] for i in range(M)]
for i in range(N):
  p=a[i]
  tmp=10**10
  pos=-1
  for j in range(M):
    cp=c[j]
    dist=abs(cp[0]-p[0])+abs(cp[1]-p[1])
    if dist < tmp:
      tmp=dist
      pos=j+1
      
  print(pos)

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

li = [[0] * m for _ in range(n)]

for i in range(n):
    for j in range(m):
        li[i][j] = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])

for i in range(n):
    print(li[i].index(min(li[i]))+1)

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

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

for i in range(N):
    ans = 0
    a = a_b[i][0]
    b = a_b[i][1]

    for j in range(M):
        c_ans = c_d[ans][0]
        d_ans = c_d[ans][1]
        c = c_d[j][0]
        d = c_d[j][1]
        
        if abs(a-c) + abs(b-d) < abs(a-c_ans) + abs(b-d_ans):
             ans = j
    print(ans+1)

Solution (Python):

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

for i in range(n):
    inf = pow(10, 15)
    for j in range(m):
        if abs(cd[j][0] - ab[i][0]) + abs(cd[j][1] - ab[i][1]) < inf:
            inf = abs(cd[j][0] - ab[i][0]) + abs(cd[j][1] - ab[i][1])
            ans = j + 1
    print(ans)

Solution (Python):
n, m = map(int, input().split())
student = [tuple(map(int, input().split())) for _ in range(n)]
check = [tuple(map(int, input().split())) for _ in range(m)]

for x, y in student:
    d = 10 ** 18
    ans = -1
    for i, (a, b) in enumerate(check):
        if d > abs(x - a) + abs(y - b):
            d = abs(x - a) + abs(y - b)
            ans = i+1
    print(ans)

Solution (Python):
n,m = [int(x) for x in input().split()]
ab = []
cd = []
for _ in range(n):
    tmp = [int(x) for x in input().split()]
    ab.append(tmp)
for _ in range(m):
    tmp = [int(x) for x in input().split()]
    cd.append(tmp)

for i in range(n):
    ans = 0
    man = 10**9
    for j in range(m):
        tmp = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
        if man > tmp:
            man = tmp
            ans = j + 1

    print(ans)

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


for i in range(n):
    ans = 0
    man = 10 ** 9

    for j in range(m):
        tmp = abs(T1[i][0] - T2[j][0]) + abs(T1[i][1] - T2[j][1])
        if man > tmp:
            man = tmp
            ans = j + 1

    print(ans)

Solution (Python):
n,m=map(int,input().split())
s = [list(map(int,input().split())) for i in range(n)]
p = [[0,10**18] for i in range(n)]
for j in range(m):
  c,d=map(int,input().split())
  for k in range(n):
    if p[k][1]>(abs(c-s[k][0])+abs(d-s[k][1])):
      p[k][0]=j+1
      p[k][1]=(abs(c-s[k][0])+abs(d-s[k][1]))
for i in range(n):
  print(p[i][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 a, b in ab:
    ans = -1
    m = 10**9
    i = 1
    for c, d in cd:
        t = abs(c-a)+abs(d-b)
        if t < m:
            m = t
            ans = i
        i += 1
    print(ans)

Solution (Python):
N,M=map(int,input().split())
S=[]
T=[]
for i in range(N):
  S.append(list(map(int,input().split())))
for i in range(M):
  T.append(list(map(int,input().split())))
for i in range(N):
  min=abs(S[i][0]-T[0][0])+abs(S[i][1]-T[0][1])
  num=1
  for j in range(1,M):
    if abs(S[i][0]-T[j][0])+abs(S[i][1]-T[j][1])<min:
      min=abs(S[i][0]-T[j][0])+abs(S[i][1]-T[j][1])
      num=j+1
  print(num)

Solution (Python):
n,m=list(map(int,input().split()))
st=[]
for i in range(n):
    a,b=list(map(int,input().split()))
    st.append([a,b])
cp=[]
for j in range(m):
    c,d=list(map(int,input().split()))
    cp.append([c,d])
g=[]
for i in range(n):
    m_dt=abs(st[i][0]-cp[0][0])+abs(st[i][1]-cp[0][1])
    idx=1
    for j in range(1,m):
        dt=abs(st[i][0]-cp[j][0])+abs(st[i][1]-cp[j][1])
        if dt<m_dt:
            m_dt=dt
            idx=j+1
    print(idx)

Solution (Python):


N,M = list(map(int, input().rstrip().split()))
ab_list = [list(map(int, input().rstrip().split())) for i in range(N)]
cd_list = [list(map(int, input().rstrip().split())) for i in range(M)]


for a,b in ab_list:
    dist = (10**8)*2*2 + 1
    
    for i,[c,d] in enumerate(cd_list):
        temp_dist = abs(a-c) + abs(b-d)
        
        if dist > temp_dist:
            dist = temp_dist
            check = i

    print(check+1)

Solution (Python):
N, M = map(int, input().split())
ns = [list(map(int, input().split())) for _ in range(N)]
ms = [list(map(int, input().split())) for _ in range(M)]
for n in ns:
  dmin = 2002002002
  num = -1
  for i, m in enumerate(ms):
    d = abs(n[0]-m[0])+abs(n[1]-m[1])
    if d < dmin:
      dmin = d
      num = i
  print(num+1)

Solution (Python):

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

for p in student:
    distance=1001001001
    i=1
    ans=0
    for c in checkpoint:
        d=abs(p[0]-c[0])+abs(p[1]-c[1])
        if distance>d:
            distance=d
            ans=i
        i+=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)]
def dist(AB, CD):
  return abs(AB[0]-CD[0]) + abs(AB[1]-CD[1])

for i in range(N):
  d = 10**18; ans = -1;
  for j in range(M):
    tmp = dist(AB[i], CD[j])
    if tmp < d:
      d = tmp; ans = j+1;
  print(ans)

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

A = []
B = []
for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
C = []
D = []
for i in range(m):
    a, b = map(int, input().split())
    C.append(a)
    D.append(b)

for i in range(n):
    t = 0
    T = []
    for j in range(m):
        t = abs(A[i] - C[j]) + abs(B[i] - D[j])
        T.append(t)
    print(T.index(min(T)) + 1)

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

ans=[]
ith_checkpt=0

INF=float('inf')
tmp=INF

for i in range(N):
    tmp=INF
    for j in range(M):
        m=abs(H[i][0]-C[j][0])+abs(H[i][1]-C[j][1])
        if m==tmp:
            pass
        if m<tmp:
            tmp=m
            ith_checkpt=j+1
    ans.append(ith_checkpt)
            
for a in ans:
    print(a)

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

D=[float('inf') for _ in range(N)]
ans=[0]*N
for i in range(M):
    c,d=map(int,input().split())
    for j in range(N):
        a,b=AB[j][0],AB[j][1]
        res=abs(c-a)+abs(d-b)
        if D[j]>res:
            D[j]=res
            ans[j]=i+1
for a in ans:
    print(a)

Solution (Python):

import sys


def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    for i in range(N):
        min_dist = 10**9
        min_index = None
        for j in range(M):
            dist = abs(a[i]-c[j])+abs(b[i]-d[j])
            if dist < min_dist:
                min_dist = dist
                min_index = j
        
        print(min_index+1)


    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    a = [int()] * (N)  
    b = [int()] * (N)  
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    c = [int()] * (M)  
    d = [int()] * (M)  
    for i in range(M):
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, M, a, b, c, d)

if __name__ == '__main__':
    main()