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())
a=[[int(i) for i in input().split()] for l in range(n)]
b=[[int(i) for i in input().split()] for l in range(m)]
for A in a:
    c=1
    r=0
    m=10000000000
    for B in b:
        k=abs(A[0]-B[0])+abs(A[1]-B[1])
        if m>k:
            m=k
            r=c
        c+=1
    print(r)

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

Solution (Python):
f = lambda k:[list(map(int,input().split())) for _ in range(k)]
n,m = map(int,input().split())
lln = f(n)
llm = f(m)

for a,b in lln:
  mi,p = 10**9,m
  for i, [c,d] in enumerate(llm):
    di = abs(c-a)+abs(d-b)
    if di < mi:
      mi,p = di,i+1
  print(p)

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)
ans=[]
for i in range(N):
    ans.append(10**9)
for i in range(N):
    for j in range(M):
        m=abs(a[i]-c[j])+abs(b[i]-d[j])
        ans[i]=min(m,ans[i])

n=[[] for _ in range(N)]
for i in range(N):
    for j in range(M):
        m=abs(a[i]-c[j])+abs(b[i]-d[j])
        if ans[i]==m:
            n[i].append(j+1)
for i in range(N):
    print(n[i][0])

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):
    d = [0]*m
    for j in range(m):
        d[j] = abs(A[i]-C[j])+abs(B[i]-D[j])
    print(d.index(min(d))+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=ab[i][0]
    y=ab[i][1]
    ans = [float('inf')] * 2
    for j in range(m):
        man=abs(x-cd[j][0])+abs(y-cd[j][1])
        if ans[0]>man:
            ans=[man,j+1]

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

for i in range(n):
    x=ab[i][0]
    y=ab[i][1]
    ans = [float('inf')] * 2
    for j in range(m):
        man=abs(x-cd[j][0])+abs(y-cd[j][1])
        if ans[0]>man:
            ans=[man,j+1]

    print(ans[1])

Solution (Python):
n, m = map(int, input().split())
student = [tuple(map(int, input().split())) for _ in range(n)]
check_points = [tuple(map(int, input().split())) for _ in range(m)]
for a, b in student:
    dst_min = float('inf')
    ans = float('inf')
    for i, (c, d) in enumerate(check_points):
        now = abs(a - c) + abs(b - d)
        if now < dst_min:
            dst_min = now
            ans = i + 1
    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 i in range (M):
	C[i],D[i]=map(int,input().split())
E=[10000000000]*N
F=[1]*N
tmp=('inf')
for i in range (N):
	for j in range (M):
		tmp=(abs(A[i]-C[j])+abs(B[i]-D[j]))
		if E[i]>tmp:
			F[i]=j+1
			E[i]=tmp
		
for i in range (N):
	print(F[i])

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

ans = []
for a, b in AB:
    dist = 10 ** 9
    goal = -1
    for i, cd in enumerate(CD):
        c, d = cd
        di = abs(a-c)+abs(b-d)
        if di < dist:
            goal = i + 1
            dist = di
    ans.append(goal)

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

Solution (Python):
n, m = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
c = []
d = []
for _ in range(m):
    ci, di = map(int, input().split())
    c.append(ci)
    d.append(di)
ans = [float('inf')] * n
cnt = [float('inf')] * n

for i in range(n):
    for j in range(m):
        now = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if cnt[i] > now:
            cnt[i] = now
            ans[i] = j + 1
print(*ans, sep='\n')

Solution (Python):
def main():
    N, M = (int(i) for i in 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:
        cur = 10**12
        cur_ans = -1
        for i, cd in enumerate(CD):
            if cur > abs(a-cd[0])+abs(b-cd[1]):
                cur = abs(a-cd[0])+abs(b-cd[1])
                cur_ans = i
        print(cur_ans+1)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
st = []
res = [0] * N
for _ in range(N):
  a, b = map(int, input().split())
  st.append((a, b))
cp = []
for _ in range(M):
  a, b = map(int, input().split())
  cp.append((a, b))
for i in range(N):
  a, b = st[i]
  for j in range(M):
    c, d = cp[j]
    x, y = cp[res[i]]
    if abs(c - a) + abs(d - b) < abs(x - a) + abs(y - b):
      res[i] = j
  res[i] += 1
for r in res: print(r)

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

for a,b in AB:
    ans = -1
    mind = float('inf')
    for i,(c,d) in enumerate(CD):
        dist = abs(a-c) + abs(b-d)
        if dist < mind:
            mind = dist
            ans = i+1
    print(ans)

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

Solution (Python):
N,M = map(int, input().split())
a,b = [0]*N,[0]*N
c,d = [0]*M,[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):
    index = float('inf')
    mini = float('inf')
    for j in range(M):
        if mini > abs(a[i]-c[j])+abs(b[i]-d[j]):
            index = j
            mini = min(mini, abs(a[i]-c[j])+abs(b[i]-d[j]))
    print(index+1)

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

abl = []
for _ in range(n):
    ab = list(map(int, input().split()))
    abl.append(ab)

cdl = []
for _ in range(m):
    cd = list(map(int, input().split()))
    cdl.append(cd)

ansl = [0 for _ in range(n)]
for i, ab in enumerate(abl):
    ans = 10**10
    for j, cd in enumerate(cdl):
        if abs(ab[0]-cd[0]) + abs(ab[1]-cd[1]) < ans:
            ansl[i] = j
            ans = abs(ab[0]-cd[0]) + abs(ab[1]-cd[1])

for ans in ansl:
    print(ans+1)

Solution (Python):
import math

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 i in range(N):
    dist = float("inf")
    point = 0
    for j in range(M):
        if abs(student[i][0]-check[j][0])+abs(student[i][1]-check[j][1])<dist:
            dist=abs(student[i][0]-check[j][0])+abs(student[i][1]-check[j][1])
            point=j+1
        
    print(point)

Solution (Python):
def solve(n, m, AB, CD):
    ret = []
    for a, b in AB:
        minval = 10 ** 10
        minidx = -1
        for j, (c, d) in enumerate(CD):
            if abs(a - c) + abs(b - d) < minval:
                minval = abs(a - c) + abs(b - d)
                minidx = j
        ret.append(minidx + 1)
    return ret

_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)]
print(*solve(_n, _m, _AB, _CD), sep='\n')

Solution (Python):
n,m=map(int,input().split())
ab=[]
cd=[]

min = 10**9

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

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

for i in range(n):
    for j in range(m):
        dis= abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if dis < min:
            min = dis
            buf = j+1
        elif dis == min:
            continue
    print(buf)
    min=10**9

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

man = lambda x,y:abs(x[0] - y[0]) + abs(x[1] - y[1])

for i in range(n):
    a,b = ab[i]
    cost = float('INF')
    pos = 0
    for j in range(m):
        c,d = cd[j]
        c = man(ab[i], cd[j])
        if c < cost:
            cost = c
            pos = j+1
    print(pos)

Solution (Python):
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(n)]
m=[list(map(int,input().split())) for _ in range(m)]
for i in s:
  a,b=i[0],i[1]
  md=[abs(c[0]-a)+abs(c[1]-b) for c in m]
  print(md.index(min(md))+1)

Solution (Python):




def main():
    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):
        for j in range(M):
            if j == 0:
                result = abs(AB[i][0] - CD[j][0]) + abs(AB[i][1] - CD[j][1])
                count = j + 1
            elif result > abs(AB[i][0] - CD[j][0]) + abs(AB[i][1] - CD[j][1]):
                result = abs(AB[i][0] - CD[j][0]) + abs(AB[i][1] - CD[j][1])
                count = j + 1
        print(count)


if __name__ == "__main__":
    main()

Solution (Python):
n, m = map(int, input().split())
list_student = []
list_ckeckpoint = []
for x in range(n):
    a, b = map(int, input().split())
    list_student.append([a, b])
for y in range(m):
    c, d = map(int, input().split())
    list_ckeckpoint.append([c, d])
    
def distance(lista, listb):
    return abs(lista[0] - listb[0]) + abs(lista[1] - listb[1])

for no in range(n):
    minValue = 2 * 10**8
    minid = 1
    for id in range(m):
        dis = distance(list_student[no], list_ckeckpoint[id])
        if minValue > dis: minid = id + 1
        minValue = min([minValue, dis])
    print(minid)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
A = [LIST() for i in range(N)]
C = [LIST() for i in range(M)]
L = []
for i in range(N):
    index = 0
    mi = INF
    for j in range(M):
        a, b = A[i][0], A[i][1]
        c, d = C[j][0], C[j][1]
        m = abs(a - c) + abs(b - d)
        if mi > min(mi, m):
            mi = min(mi, m)
            index = j
    L.append(index)
for l in L:
    print(l+1)

Solution (Python):
n,m = map(int, input().split())
st = []
cp = []
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())
    cp.append([c,d])

ans = []
for x in st:
    t = []
    for y in cp:
        t.append(abs(x[0]-y[0])+abs(x[1]-y[1]))
    ans.append(t.index(min(t))+1)

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

Solution (Python):
def ac(n,m,a,c):
    ans = []
    for i in range(n):
        min = 10000000000000
        bang = 0
        for w in range(m):
            if abs(a[i][0] - c[w][0]) + abs(a[i][1] - c[w][1]) < min:
                min = abs(a[i][0] - c[w][0]) + abs(a[i][1] - c[w][1])
                bang = w + 1
        ans.append(bang)
    return ans

def main():
    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)]
    ans = ac(n , m , a , c)
    for i in range(len(ans)):
        print(ans[i])

if __name__ == '__main__':
    main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
ab = [LIST() for _ in range(N)]
cd = [LIST() for _ in range(M)]

def dist(p1, p2):
	return abs(p1[0]-p2[0]) + abs(p1[1]-p2[1])

for p1 in ab:
	tmp_dist = INF
	tmp_idx = None
	for i, p2 in enumerate(cd):
		d = dist(p1, p2)
		if d < tmp_dist:
			tmp_dist = d
			tmp_idx = i+1
	print(tmp_idx)

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


class StudentCoord:

    def __init__(self, x, y):
        self.x = x
        self.y = y

    def distance(self, x, y):
        return abs(x - self.x) + abs(y - self.y)

    def nearest_checkpoint_idx(self, checkpoints):
        min_idx = -1
        min_distance = float('inf')
        for idx, checkpoint in enumerate(checkpoints):
            d = self.distance(checkpoint[0], checkpoint[1])
            if d < min_distance:
                min_idx = idx
                min_distance = d
        return min_idx+1


students = []
for _ in range(N):
    x, y = tuple(map(int, input().split()))
    student = StudentCoord(x, y)
    students.append(student)

checkpoints = []
for _ in range(M):
    checkpoint = tuple(map(int, input().split()))
    checkpoints.append(checkpoint)

for student in students:
    idx = student.nearest_checkpoint_idx(checkpoints)
    print(idx)

Solution (Python):
n, m = map(int,input().split())
students = [None]*n
points = [None]*m
for i in range(n):
  students[i] = tuple(map(int,input().split()))
for i in range(m):
  points[i] = tuple(map(int,input().split()))

ans = []
for s in students:
  tmp = []
  for p in points:
    tmp.append(abs(s[0] - p[0]) + abs(s[1] - p[1]))
  ans.append(tmp.index(min(tmp)) + 1)
for i in range(n):
  print(ans[i])

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 dist(list1,list2):
  return abs(list1[0]-list2[0])+abs(list1[1]-list2[1])
for human in ab:
  for i in range(m):
    if i==0:
      d=dist(human,cd[0])
      index=1
    else:
      d_new=dist(human,cd[i])
      if d>d_new:
        d=d_new
        index=i+1
  print(index)

Solution (Python):

n,m = map(int,input().split())
a = [0]*n
b = [0]*n
x = [0]*m
y = [0]*m
for i in range(n):
    s,t = map(int,input().split())
    a[i],b[i] = s,t
for i in range(m):
    s,t = map(int,input().split())
    x[i],y[i] = s,t

for i in range(n):
    min_idx = 1 
    min_dist = 10**9
    for j in range(m):
        if abs(x[j]-a[i])+abs(y[j]-b[i]) < min_dist:
            min_dist = abs(x[j]-a[i])+abs(y[j]-b[i])
            min_idx = 1 + j
            
            

    print(min_idx)

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

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

for s in students:
    dis = [abs(s[0] - c[0]) + abs(s[1] - c[1]) for c in checks]
    print(dis.index(min(dis))+1)

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)]
f = lambda ab: min((abs(ab[0]-CD[i][0])+abs(ab[1]-CD[i][1]),i+1) for i in range(M))[1]
print(*[f(ab) for ab in AB], sep="\n")

Solution (Python):
arr = input().split()
n = int(arr[0])
m = int(arr[1])
a = [0] * n
b = [0] * n
for i in range(n):
    tmp = input().split()
    tmp = list(map(int,tmp))
    a[i] = tmp[0]
    b[i] = tmp[1]

c = [0] * m
d = [0] * m
for i in range(m):
    tmp = input().split()
    tmp = list(map(int,tmp))
    c[i] = tmp[0]
    d[i] = tmp[1]

def calc_dist(a,b,c,d):
    return abs(a-c) + abs(b-d)
    
for i in range(n):

    line = 10000000000
    index = 0
    for k in range(m):
        now = calc_dist(a[i],b[i],c[k],d[k])
        if line > now:
            line = now
            index = k
    print(index+1)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    inf=10**9
    n,m=MI()
    s=[LI() for _ in range(n)]
    c=[LI() for _ in range(m)]
    ans=[0]*n
    for si,(sx,sy) in enumerate(s):
        mn=inf
        mi=0
        for ci,(cx,cy) in enumerate(c):
            d=abs(cx-sx)+abs(cy-sy)
            if d<mn:
                mn=d
                mi=ci
        ans[si]=mi
    for a in ans:
        print(a+1)

main()

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

for a, b in students:
    min_dist = 10 ** 9
    ans = -1
    for i in range(M):
        c, d = checkpoints[i]
        distance = abs(a - c) + abs(b - d)
        if distance < min_dist:
            min_dist = distance
            ans = i + 1
    print(ans)

Solution (Python):
N,M = map(int,input().split())
gakusei = []
for i in range(N):
    a,b = map(int,input().split())
    gakusei.append((a,b))
check = []
for i in range(1,M+1):
    c,d = map(int,input().split())
    check.append((c,d))
for i in range(N):
    a,b = gakusei[i]
    z = 10**9
    m = 0
    for j in range(1,M+1):
        c,d = check[j-1]
        x = max(a-c,c-a) + max(b-d,d-b)
        if x < z:
            m = j
            z = x
    print(m)

Solution (Python):

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

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

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

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

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

ans = []
for x,y in lst1:
    res = 10**9
    for i,seq in enumerate(lst2):
        a = seq[0]
        b = seq[1]
        if res > abs(a-x)+abs(b-y):
            ct = i
            res = abs(a-x)+abs(b-y)
    ans.append(ct)

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

Solution (Python):
n,m = map(int,input().split())
x = []
y = []
for _ in range(n):
    a,b = map(int,input().split())
    x.append([a,b])
for _ in range(m):
    c,d = map(int,input().split())
    y.append([c,d])
for i in range(n):
    t = 10**8*3
    ans = 0
    for j in range(m):
        if t > abs(y[j][0]-x[i][0])+abs(y[j][1]-x[i][1]):
            ans = j+1
            t = abs(y[j][0]-x[i][0])+abs(y[j][1]-x[i][1])
    print(ans)

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)]
ans=[[] for _ in range(n)]
for i in range(n):
  p,q=a[i]
  for j in range(m):
    r,s=c[j]
    d=abs(p-r)+abs(q-s)
    ans[i].append((d,j+1))
  ans[i]=sorted(ans[i])
for i in ans:
  print(i[0][1])

Solution (Python):
def main():
    n, m = map(int, input().split())
    Students = [list(map(int,input().split())) for _ in range(n)]
    Check = [list(map(int,input().split())) for _ in range(m)]
    for s in Students:
        ans = 1
        for i, c in enumerate(Check, 1):
            dist = abs(c[0]-s[0]) + abs(c[1]-s[1])
            if i<2:
                min_dist = dist
            elif dist < min_dist:
                min_dist = dist
                ans = i
        print(ans)
main()

Solution (Python):
def man(q,r,s,t):
    
    return (abs(q-s)) + (abs(r-t))

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

a=[]
b=[]

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

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

for i in range(n):
    nia = 10**10
    ans = 0
    for j in range(m):
        if nia > man(a[i],b[i],c[j],d[j]):
            nia = man(a[i],b[i],c[j],d[j])
            ans = j + 1
    print(ans)

Solution (Python):
n,m = map(int, input().split())
students = [list(map(int, input().split())) for _ in range(n)]
chkpoints = [list(map(int, input().split())) for _ in range(m)]
dist = 0
ans = 0
for student in students:
  min_dist = 1000000000
  for i in range(m):
    dist = abs(student[0]-chkpoints[i][0])+abs(student[1]-chkpoints[i][1])
    if dist < min_dist:
      min_dist = dist
      ans = i+1
  print(ans)

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

for nll in nl:
  c=0
  ii=1
  for i,mll in enumerate(ml):
    cc = abs(nll[0]-mll[0])+abs(nll[1]-mll[1])
    if i == 0:
      c = cc
      continue
    
    if c > cc:
      ii = i+1
      c = cc
    
  ans.append(ii)
  
[print(x) for x in ans]

Solution (Python):
N,M = [int(i) for i in input().split()]
ab = [0] * N
cd = [0] * M
index = [-1] * N
for i in range(N) :
    ab[i] = [int(j) for j in input().split()]
for i in range(M) :
    cd[i] = [int(j) for j in input().split()]
for i in range(N) :
    indexa = []
    min = 10000000000
    for j in range(M) :
        l = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if l < min :
            indexa.clear()
            indexa.append(j+1)
            min = l
        elif l == min :
            indexa.append(j+1)
    if len(indexa) == 1 :
        index[i] = indexa[0]
    else :
        indexa.sort()
        index[i] = indexa[0]
for i in range(N) :
    print(index[i])

Solution (Python):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,m=INTM()
    A=[]
    C=[]
    for i in range(n):
        A.append(LIST())
    for i in range(m):
        C.append(LIST())
    for i in range(n):
        temp=10**9
        a,b=A[i][0],A[i][1]
        for j in range(m):
            c,d=C[(m-1)-j][0],C[(m-1)-j][1]
            
            man=abs(a-c)+abs(b-d)
            
            if man<=temp:
                
                ans=m-j
                temp=man
        print(ans)
            
    
if __name__ == '__main__':
    do()

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

for i in g:
    tmp=10**9
    
    for j in range(m):
        t2=abs(i[0]-c[j][0]) + abs(i[1]-c[j][1])
        if t2 <tmp:
            no=j+1
            tmp=t2
            
    print(no)

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

Solution (Python):
N, M = map(int, input().split())
student_positions = [input().split() for _ in range(N)]
student_positions = [[int(a[0]), int(a[1])] for a in student_positions]
check_points = [input().split() for _ in range(M)]
check_points = [[int(a[0]), int(a[1])] for a in check_points]


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


def get_nearest_point(x, candidates):
    min_distance = 10 ** 10
    for idx, candidate in enumerate(candidates):
        distance = calc_manhattan_distance(x, candidate)
        if distance < min_distance:
            min_distance = distance
            nearest_point = idx
    return nearest_point


for p in student_positions:
    print(get_nearest_point(p, check_points)+1)

Solution (Python):
N, M = map(int, input().split())
student_positions = [input().split() for _ in range(N)]
student_positions = [[int(a[0]), int(a[1])] for a in student_positions]
check_points = [input().split() for _ in range(M)]
check_points = [[int(a[0]), int(a[1])] for a in check_points]


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


def get_closest_point(x, candidates):
    prev_distance = 10 ** 10
    for idx, candidate in enumerate(candidates):
        distance = calc_manhattan_distance(x, candidate)
        if distance < prev_distance:
            prev_distance = distance
            target_idx = idx
    return target_idx


for p in student_positions:
    print(get_closest_point(p, check_points)+1)

Solution (Python):
import sys
input = sys.stdin.readline
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):
    le=float("inf")
    a,b=ab[i][0],ab[i][1]
    for j in range(m):
        c,d=cd[j][0],cd[j][1]
        if le>abs(a-c)+abs(b-d):
            ans=j+1
            le=abs(a-c)+abs(b-d)
    print(ans)

Solution (Python):


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


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

cp = []
for _ in range(M):
    cp.append(list(map(int, input().split())))
    

goal = [10**9 for _ in range(N)]

ans = [0 for _ in range(N)]


for n in range(N):
    for m in range(M):
        
        x = abs(student[n][0] - cp[m][0])
        y = abs(student[n][1] - cp[m][1])
        
        
        
        if goal[n] > x+y:
            goal[n] = x+y
            ans[n] = m +1
            


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

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

for stu in ab:
    mind = float("inf")
    for i,cp in enumerate(cd,1):
        d = sum(map(abs,(stu[0]-cp[0],stu[1]-cp[1])))
        if mind > d:
            ans = i
            mind = d
    else:
        print(ans)

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

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

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

for s in students:
    distants = [abs(s[0]-p[0]) + abs(s[1]-p[1]) for p in points]
    print(distants.index(min(distants)) + 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):
    dim, num = 10**9,-1
    for j in range(m):
        if abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1]) < dim:
            dim = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
            num = j
    print(num +1)

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

sList = []
for i in range(n):
  sList.append(tuple(map(int,input().split())))

pList = []
for i in range(m):
  pList.append(tuple(map(int,input().split())))

for i in range(n):
  for j in range(m):
      if j == 0 :
        mD = abs(sList[i][0]-pList[0][0])+abs(sList[i][1]-pList[0][1])
        minDIndex = 0
      else:
        mDT = abs(sList[i][0]-pList[j][0])+abs(sList[i][1]-pList[j][1])
        if mD > mDT:
          mD = mDT
          minDIndex = j 
  
  print(minDIndex+1)

Solution (Python):
INF = 10**10
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())))         

for abi in ab:
  dist = INF
  nearest = -1
  for i,cdi in enumerate(cd):
    tmp = abs(abi[0]-cdi[0]) + abs(abi[1]-cdi[1])
    if tmp<dist:
      dist = tmp
      nearest = i+1
    dist = min(tmp,dist)
    
  print(nearest)

Solution (Python):
import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().split()]
ab = []
for _ in range(N):
    ab.append([int(x) for x in input().split()])
cd = []
for _ in range(M):
    cd.append([int(x) for x in input().split()])
for i in ab:
    a, b = i
    ans = [10 ** 9, 0]
    for j in range(M):
        c, d = cd[j]
        j += 1
        if abs(a - c) + abs(b - d) < ans[0]:
            ans = [abs(a - c) + abs(b - d), j]
    print(ans[1])