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

students = []
for i in range(N):
    students.append(input().split())

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

for x1, y1 in students:
    result = 99999999999
    index = 1
    for x2, y2 in checkpoints:
        val = abs(int(x1) - int(x2)) + abs(int(y1) - int(y2))
        if result > val:
            ans = index
            result = val
        index += 1
    print(ans)

Solution (Python):
def getDist(a,b,c,d):
  return abs(a-c) + abs(b-d)
def findSmallest(student, checkPoints):
  [a,b] = student
  shortest = 99999999999
  index = 1
  for checkPoint in checkPoints:
    [c,d] = checkPoint
    dist = getDist(a,b,c,d)
    if dist < shortest:
      shortest = dist
      indexAns = index
    index += 1
  return indexAns

n,m=[int(x) for x in input().split()]
students = []
for x in range(n):
  students.append([int(x) for x in input().split()])
checkPoints = []
for x in range(m):
  checkPoints.append([int(x) for x in input().split()])

for student in students:
  print(findSmallest(student, checkPoints[:]))

Solution (Python):
nm = [int(x) for x in input().split()]
n = nm[0]
m = nm[1]
students = []
checkpoints = []
distances = []
for i in range(n):
  students.append([int(x) for x in input().split()])
for i in range(m):
  checkpoints.append([int(x) for x in input().split()])
  
for i in students:
  for j in checkpoints:
    distances.append(abs(j[0]-i[0])+abs(j[1]-i[1]))
  print(distances.index(min(distances))+1)
  distances = []

Solution (Python):
import math

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

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

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

for _ in range(m):
	tc, td = map(int, input().split())
	c.append(tc)
	d.append(td)

index = [0]*n

for sti in range(len(a)):
	di = abs(a[sti]-c[0])+abs(b[sti]-d[0])
	index[sti] = 1
	for chi in range(len(c)):
		if di > abs(a[sti]-c[chi])+abs(b[sti]-d[chi]):
			di = abs(a[sti]-c[chi])+abs(b[sti]-d[chi])
			index[sti] = chi+1

for num in index:
	print(num)

Solution (Python):
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
lc = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

for i in range(n):
    kyo = []
    for j in range(m):
        kyo.append(abs(li[i][0]-lc[j][0])+abs(li[i][1]-lc[j][1]))
    print(kyo.index(min(kyo))+1)

Solution (Python):
n, m = [int(i) for i in 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 a, b in ab:
  dmin = float("inf")
  cp = -1
  for i in range(len(cd)):
    c, d = cd[i]
    d = abs(a - c) + abs(b - d)
    if d < dmin:
      cp = i + 1
      dmin = d
  print(cp)

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):
  L = 2*10**8+1
  n = 0
  for p in range(M):
    if abs(a[i]-c[p]) + abs(b[i]-d[p]) < L:
      n = p
      L = abs(a[i]-c[p]) + abs(b[i]-d[p])
    if p == M-1:
      print(n + 1)

Solution (Python):
import numpy as np

N,M=list(map(int,input().split(" ")))
S=np.zeros((N,2))
C=np.zeros((M,2))


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


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


for s in S:
    
    

    d=np.abs(C-s).sum(axis=1)
    Cnear=np.argmin(d) 

    if type(Cnear)!=np.int64: 
        Cnear=Cnear[0]

    print(Cnear+1)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M=MI()
    AB = LLIN(N)
    CD = LLIN(M)
    for a,b in AB:
        mini = inf
        mini_idx = -1
        for i,(c,d) in enumerate(CD,start=1):
            d = abs(c-a) + abs(d-b)
            if mini>d:
                mini = d
                mini_idx = i
        print(mini_idx)
        
if __name__ == '__main__':
    main()

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

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


for i in X:
    MAX = 10 ** 9
    ans = 0
    for j in range(M):
        LENGE = abs(i[0] - Y[j][0]) + abs(i[1] - Y[j][1])
        if LENGE < MAX:
            MAX = LENGE
            ans = j + 1
    print(ans)

Solution (Python):
N, M = map(int, input().split())
stu = list(list(map(int, input().split())) for _ in range(N))
gol = list(list(map(int, input().split())) for _ in range(M))


for i in range(N):
    l_new = 10 ** 16
    num = 0
    for j in range(M):
        l_old = abs(stu[i][0] - gol[j][0]) + abs(stu[i][1]-gol[j][1])
        if l_old < l_new:
            l_new = l_old
            num = j+1
    print(num)

Solution (Python):
def dis(XY1, XY2):
    return abs(XY1[0]-XY2[0]) + abs(XY1[1]-XY2[1])

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

for ab in AB:
    mini = 2*(10**9)
    id = 0
    for cd in CD:
        if mini > dis(ab,cd):
            mini = dis(ab,cd)
            id = CD.index(cd)+1
    print(id)

Solution (Python):
N,M = map(int,input().split())
ab = []
for i in range(N):
    a,b = map(int,input().split())
    ab.append((a,b))
cd = []
for i in range(M):
    c,d = map(int,input().split())
    cd.append((c,d))
ans = []
for i in range(len(ab)):
    aaa = 1000000000
    for j in range(len(cd)):
        man = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if(man < aaa):
            aaa = man
            cnt = j + 1
    ans.append(cnt)
for i in ans:
    print(i)

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)]
last_ans = []
for i in range(len(a)):
    middle_ans = []
    for i1 in range(len(c)):
        tmp_a = a[i]
        tmp_c = c[i1]
        
        tmp = abs(tmp_a[0]-tmp_c[0]) + abs(tmp_a[1]-tmp_c[1])
        middle_ans.append(tmp)
    
    last_ans.append(middle_ans.index(min(middle_ans))+1)
[print(i) for i in last_ans]

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

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

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

ans = []
for i in range(n):
    dist = 10**9
    toward = -1
    for j in range(m):
        if abs(a[i] - c[j]) + abs(b[i] - d[j]) < dist:
            dist = abs(a[i] - c[j]) + abs(b[i] - d[j])
            toward = j + 1
    ans.append(toward)
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):
    dis = 5 * 10**8
    n = 1
    k = 0
    for j in range(M):
        k = abs(a[i]-c[j])+abs(b[i]-d[j])
        if k < dis:
            dis = k
            n = j+1
    print(n)

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

student = [[0, 0]] * n
checkpoint = [[0, 0]] * m

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


for i in range(n) :
    distancelist = []
    for j in range(m) :
        distancelist += [abs(student[i][0]-checkpoint[j][0]) + abs(student[i][1]-checkpoint[j][1])]
        closestdistance = min(distancelist)
        closestcheckpoint = distancelist.index(closestdistance) + 1
    print(closestcheckpoint)

Solution (Python):
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
c=[0]*m
d=[0]*m
cnt=1000000000000000
ans=0
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())
count=[]
for i in range(n):
    for j in range(m):
        if cnt>abs(a[i]-c[j])+abs(b[i]-d[j]):
            cnt=abs(a[i]-c[j])+abs(b[i]-d[j])
            ans=j+1
    count.append(ans)
    ans=0
    cnt=1000000000000000

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

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

a_b = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    a_b.append(array)

c_d = []
for i in range(M):
    array = list(map(int, input().strip().split()))
    c_d.append(array)

for n in range(N):
    mind = 1000000007
    for m in range(M):
        dist = abs(a_b[n][0] - c_d[m][0]) + abs(a_b[n][1] - c_d[m][1])
        if dist < mind:
            mind = dist
            checkpoint = m + 1
    print(checkpoint)

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):
    mi = 1<<100
    for j in range(M):
        d = abs(X[i][0] - Y[j][0]) + abs(X[i][1] - Y[j][1])
        if d < mi:
            ans = j + 1
            mi = d
    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:
  ans = float("inf")
  for j in range(m):
    c, d = cd[j]
    temp = abs(a-c) + abs(b-d)
    if temp < ans:
      ans = temp
      cur = j+1
  print(cur)

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(N, M, inputs):
    students = list(map(string_to_int, inputs[:N]))
    points = list(map(string_to_int, inputs[N:]))
    s_p = []

    for s in students:
        min_d = None
        min_p = None
        for i, p in enumerate(points):
            d = abs(s[0] - p[0]) + abs(s[1] - p[1])
            if min_d is None or min_d > d:
                min_d = d
                min_p = i
        s_p.append(min_p+1)
    return s_p


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    [N, M] = string_to_int(input())
    ret = solve(N, M, inputs(N+M))
    for r in ret:
        print(r)

Solution (Python):
import numpy as np
N,M = map(int,input().split())
ab = [np.array(list(map(int,input().split()))) for i in range(N)]
cd = [np.array(list(map(int,input().split()))) for i in range(M)]
ans = []
for i in range(N):
    tmp = []
    for j in range(M):
        tmp.append(sum(list(map(abs,list(ab[i] - cd[j])))))
    ans.append(tmp.index(min(tmp)))
for i in ans:
    print(i+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)]

Ans = [0]*N

for i in range(N):
    dis = 10**10
    a,b = AB[i]
    for j in range(M):
        c,d = CD[j]
        tmp_dis = abs(a-c)+abs(b-d)
        if dis > tmp_dis:
            dis = tmp_dis
            Ans[i] = j+1

for ans in Ans:
    print(ans)

Solution (Python):
n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for m in range(n)]
c=[[int(i) for i in input().split()] for m in range(m)]
for i in a:
    ans=float('inf')
    for x,j in enumerate(c):
        dis=abs(i[0]-j[0])+abs(i[1]-j[1])
        if ans>dis:
            ans=dis
            point=(x+1)
    print(point)

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:
    ans=[abs(i[0]-j[0])+abs(i[1]-j[1]) for j in C]
    ans_min=min(ans)
    print(ans.index(ans_min)+1)

Solution (Python):
def examB(inf):
    N, M = LI()
    ab = [LI() for _ in range(N)]
    cd = [LI() for _ in range(M)]
    ans = []
    for i in range(N):
        cur = inf
        for j in range(M):
            k = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
            if cur>k:
                cur = k
                ansC = j
        ans.append(ansC+1)
    for v in ans:
        print(v)

import sys
import copy
import bisect
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB(inf)

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

for i in range(n):
    s.append(list(map(int, input().split())))
for i in range(m):
    c.append(list(map(int, input().split())))
for i in range(n):
    d_min = 10**17
    for j in range(m):
        mah = abs(s[i][0]-c[j][0]) + abs(s[i][1]-c[j][1])
        if mah < d_min:
            d_min = mah
            ans = j+1
    print(ans)

Solution (Python):

n, m = [int(s) for s in input().split()]

a = []
b = []

for i in range(n):
    tmp = [int(s) for s in input().split()]
    a.append(tmp[0])
    b.append(tmp[1])

c = []
d = []

for j in range(m):
    tmp = [int(s) for s in input().split()]
    c.append(tmp[0])
    d.append(tmp[1])

for i in range(n):
    checkpoint = 0
    distance = abs(c[0] - a[i]) + abs(d[0] - b[i])
    
    for j in range(m):
        if distance > abs(c[j] - a[i]) + abs(d[j] - b[i]):
            distance = abs(c[j] - a[i]) + abs(d[j] - b[i])
            checkpoint = j
    
    print(checkpoint + 1)

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

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

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

for i in range(N):
    x = float('inf')
    c = 0
    
    for j in range(M):
        if abs(st[i][0]-ch[j][0])+abs(st[i][1]-ch[j][1]) < x:
            x = abs(st[i][0]-ch[j][0])+abs(st[i][1]-ch[j][1])
            c = j+1
    
    print(c)

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:
    ans=[abs(i[0]-j[0])+abs(i[1]-j[1]) for j in C]
    ans_min=min(ans)
    print(ans.index(ans_min)+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):
    min_distance = 10 ** 10
    min_index = 0
    for j in range(M):
        distance = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if  distance < min_distance:
            min_distance = distance
            min_index = j
    print(min_index+1)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m = inpl()
ab = [inpl() for i in range(n)]
cd = [inpl() for i in range(m)]
for i in ab:
    res = 0
    mmm = float('inf')
    for j,k in enumerate(cd):
        tmp = abs(i[0] - k[0]) + abs(i[1] - k[1])
        if tmp < mmm:
            mmm = tmp
            res = j+1
    print(res)

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

for a, b in ablist:
    min_distance = 10**9 + 7
    min_index = 0
    for index, cd in enumerate(cdlist, 1):
        c, d = cd
        distance = abs(a - c) + abs(b - d)
        if distance < min_distance:
            min_distance = distance
            min_index = index
    print(min_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)]
minn = 10 ** 9
for i in range(n):
	for j in range(m):
		x = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
		if x < minn:
			minn = x
			ans = j + 1
	print (ans)
	minn = 10 ** 9

Solution (Python):
a,b = map(int,input().split())
S = [list(map(int,input().split())) for i in range(a)]
CP = [list(map(int,input().split())) for i in range(b)]
for s in S:
  count = 0
  ab = 10**9
  p = 10**9
  for i,cp in zip(range(b),CP):
    total = abs(s[0]-cp[0]) + abs(s[1]-cp[1])
    count +=1
    if ab > total:
      ab = total
      p = i+1
      
  print(p)

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):
    index = 0
    lowest = pow(10, 8) * 4
    for j in range(M):
        dist = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if lowest > dist:
            lowest = dist
            index = j
    print(index + 1)

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

for n in range(N):
    x,y = ST[n]
    ansp = -1
    minp = 10**10
    for p in range(M):
        px,py = CH[p]
        d = abs(px-x)+abs(py-y)
        if d < minp:
            minp = d
            ansp = p+1
    print(ansp)

Solution (Python):
n,m = map(int, input().split())
student = dict()
checkpoint = dict()
distance = dict()

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

for i in range(m):
    checkpoint[i] = list(map(int, input().split()))
    
for key in student:
    x1,y1 = student[key]
    minD = 10000000001
    minP = 10000000001
    for p in checkpoint:
        x2, y2 = checkpoint[p]
        d =  abs(x1 - x2) + abs(y1 - y2)
        if d < minD:
            minP = p
            minD = d
    print(minP+1)

Solution (Python):
N, M = map(int,input().split())
def read(List,N):
  for _ in range(N):
    x, y = input().split()
    x,y = int(x),int(y)
    List.append((x,y))
  return List
students = []
points = []
students = read(students,N)
points = read(points,M)

def distance(A,B):
  distance = abs(A[0] - B[0]) + abs(A[1] - B[1])
  return distance

Answer_list = []
for i in range(N):
  answer = -1
  tempdistance = 10**17
  
  for j in range(M):
    candidate = distance(students[i],points[j])
    if candidate < tempdistance:
      answer = j
      tempdistance = candidate
  Answer_list.append(answer)
for item in Answer_list:
  print(item+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 j in range(m):
  c[j],d[j]=map(int,input().split())
e=[0]*n
g=[0]*m
for k in range(n):
  for l in range(m):
    g[l]=abs(a[k]-c[l])+abs(b[k]-d[l])
  e[k]=int(g.index(min(g))+1)
  print(e[k])

Solution (Python):
N,M=map(int,input().split())
a=[];b=[]
for i in range(N):
    ai,bi=map(int,input().split())
    a.append(ai);b.append(bi)
c=[];d=[]
for j in range(M):
    cj,dj=map(int,input().split())
    c.append(cj);d.append(dj)
for i in range(N):
    ind=0;dis=10**9
    for j in range(M):
        if abs(a[i]-c[j])+abs(b[i]-d[j])<dis:
            ind=j;dis=abs(a[i]-c[j])+abs(b[i]-d[j])
    print(ind+1)

Solution (Python):
N, M = map(int, input().split())
s = []
for i in range(0, N):
  x, y = map(int, input().split())
  s.append([x, y])
ch = []
for i in range(0, M):
  x, y = map(int, input().split())
  ch.append([x, y])
  
for x,y in s:
  dist_min = 10000000000
  min_n = 0
  n = 0
  for c, d in ch:
    n += 1
    dist = abs(x-c)+ abs(y-d)
    if dist_min > dist:
      dist_min = dist
      min_n = n
  print(min_n)

Solution (Python):
n, m = [int(x) for x in input().split()]
s_coords = [[int(_) for _ in input().split()] for i in range(n)]
c_coords = [[int(_) for _ in input().split()] for j in range(m)]

for i in s_coords:
    for j in range(1, m+1):
        man_dist = abs(c_coords[j - 1][0] - i[0]) + abs(c_coords[j - 1][1] - i[1])
        if j == 1:
            min_dist = man_dist
            destn_index = 1
        if min_dist > man_dist:
            min_dist = man_dist
            destn_index = j
    print(destn_index)

Solution (Python):
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(N)]
c = [list(map(int, input().split())) for _ in range(M)]
for i in range(N):
  x, y = s[i][0], s[i][1]
  mnht = float("inf")
  res = 0
  for j in range(M):
    cx, cy = c[j][0], c[j][1]
    if abs(cx - x) + abs(cy - y) < mnht:
      mnht = abs(cx - x) + abs(cy - y)
      res = j + 1
  print(res)

Solution (Python):

si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n,m = nm()

AB = [[] for _ in range(n)]
CD = [[] for _ in range(m)]

ans = 0
for i in range(n):
    a,b = nm()
    AB[i].append(a)
    AB[i].append(b)

for i in range(m):
    c,d = nm()
    CD[i].append(c)
    CD[i].append(d)

for i in range(n):
    distance = 10**10
    for j in range(m):
        t = abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1])
        if t<distance:
            distance = 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())
p_s = [list(map(int, input().split())) for _ in range(N)]
p_f = [list(map(int, input().split())) for _ in range(M)]
length = []

for s in p_s:
    for f in p_f:
        length.append(abs(s[0]-f[0]) + abs(s[1]-f[1]))
    print(length.index(min(length))+1)
    length = []

Solution (Python):
n, m = map(int, input().split())
A = []
B = []
C = []
D = []
for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
for j in range(m):
    c, d = map(int, input().split())
    C.append(c)
    D.append(d)
for i in range(n):
    v_min = float('inf')
    for j in range(m):
        v = abs(A[i] - C[j]) + abs(B[i] - D[j])
        if v_min > v:
            v_min = v
            ans = j + 1
    print(ans)

Solution (Python):

N, M = map(int, input().split())
states = []
for i in range(N):
    state = list(map(int, input().split()))
    states.append(state[:])
checkpoints = []
for i in range(M):
    check = list(map(int, input().split()))
    checkpoints.append(check[:])

for s in states:
    a, b = s
    top = 10**9
    for i, c in enumerate(checkpoints):
        ca, cb = c
        distance = abs(a-ca) + abs(b - cb)
        if top > distance:
            top = distance
            ans = i+1
    print(ans)

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

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

for i in range(N):
    dic = [100000000000, 0]
    a,b = ab[i][0],ab[i][1]
    for j in range(M):
        cj, dj = cd[j][0], cd[j][1]
        dist = abs(a-cj)+abs(b-dj)
        if dist < dic[0]:
            dic[0] = dist
            dic[1] = j+1
    print(dic[1])

Solution (Python):
def dist(x,y):
    return abs(x[0]-y[0])+abs(x[1]-y[1])
N,M = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
B = [list(map(int,input().split())) for _ in range(M)]
for i in range(N):
    dmin = 10**9
    ind = -1
    for j in range(M):
        if dist(A[i],B[j])<dmin:
            dmin = dist(A[i],B[j])
            ind = j
    print(ind+1)

Solution (Python):
N, M = map(int, input().split())
students    = [ 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 = float('inf')

  for i in range(M):
    c, d = checkpoints[i]

    dist = abs(a - c) + abs(b - d)
    if dist < min_dist:
      min_dist = dist
      answer = i + 1
  print(answer)

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 Manhattan(P1,P2):
    ManDis=0
    for i in range(len(P1)):
        ManDis+=abs(P1[i]-P2[i])
    return(ManDis)

for i in range(N):
    ansp=10**10
    ansn=-1
    for j in range(M):
        MD=Manhattan(AB[i],CD[j])
        if ansp>MD:
            ansp=MD
            ansn=j
    print(ansn+1)

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

for _ab in ab:
    ans = 0
    d = 10**9
    for _cd in cd:
        _d = abs(_ab[0] - _cd[0]) + abs(_ab[1] - _cd[1])
        if _d < d:
            ans = cd.index(_cd)+1
            d = _d

    print(ans)

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

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

cd = []
for j in range(m):
    temp = map(int, input().split())
    cd.append(tuple(temp))


for i in ab:
    temp_ind = -1
    temp = 10 ** 17
    for ind, j in enumerate(cd):
        md = abs(i[0]-j[0])+abs(i[1]-j[1])
        if md < temp:
            temp_ind = ind
            temp = abs(i[0]-j[0])+abs(i[1]-j[1])
    print(temp_ind+1)

Solution (Python):
N,M = map(int,input().split())
A = [0] * N
B = [0] * N
C = [0] * M
D = [0] * M
ans = [0] * N
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):
    li = []
    for j in range(M):
        li.append(abs(A[i] - C[j]) + abs(B[i] - D[j]))
    ans[i] = li.index(min(li)) + 1
for i in range (N):
    print(ans[i])

Solution (Python):
n,m=map(int,input().split())
stu=[]
for i in range(n):
    a,b=map(int,input().split())
    stu.append([a,b])
che=[]
for i in range(m):
    a,b=map(int,input().split())
    che.append([a,b])
check=che 
ans=[0]*n 
for i in range(n):
    a,b=stu[i][0],stu[i][1]
    mini=10**433
    ind=-1 
    for j in range(m): 
        c,d=check[j][0],check[j][1]
        if abs(a-c)+abs(d-b)<mini: 
            mini=abs(a-c)+abs(d-b)
            ind=j+1 
    ans[i]=ind 
print(*ans,sep='\n')

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)


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 a, b in ab:
        arr = []
        for c, d in cd:
            arr.append(abs(a-c) + abs(b-d))
        print(arr.index(min(arr)) + 1)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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 a, b in ab:
        arr = []
        for c, d in cd:
            arr.append(abs(a-c)+abs(b-d))
        print(arr.index(min(arr))+1)


if __name__ == '__main__':
    main()

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

for i in p:
    cnt=1
    d=10**9
    for j in c:
        if abs(i[0]-j[0])+abs(i[1]-j[1])<d:
            d=abs(i[0]-j[0])+abs(i[1]-j[1])
            ans=cnt
        cnt+=1
    print(ans)

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 i in range(N):
    c = -1
    min_dis = 10**9
    for j in range(M):
        k = abs(students[i][0]-points[j][0]) + abs(students[i][1]-points[j][1])
        if k < min_dis:
            min_dis = k
            c = j+1
    print(c)