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):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
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()
P = []
C = []
for i in range(N):
    a, b = MAP()
    P.append([a, b])
for j in range(M):
    c, d = MAP()
    C.append([c, d])

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

for i in range(N):
    min_d = INF
    for j in range(M):
        tmp_d = calculate_manhattan_distance(P[i][0], P[i][1], C[j][0], C[j][1])
        if tmp_d < min_d:
            min_d = tmp_d
            ans_c_id = j + 1
    print(ans_c_id)

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
from bisect import bisect, bisect_left, bisect_right

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()
AB = [LIST() for i in range(N)]
CD = [LIST() for i in range(M)]
ans = []
for a, b in AB:
    i = 0
    num = 0
    mi = 10 ** 9
    for c, d in CD:
        dist = abs(a - c) + abs(b - d)
        if mi > dist:
            num = i
            mi = dist
        i += 1
    ans.append(num + 1)

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
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 functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, M = MAP()
    AB = [LIST() for _ in range(N)]
    CD = [LIST() for _ in range(M)]

    for a, b in AB:
        dist = INF

        for i, cd in enumerate(CD):
            if dist > abs(a - cd[0]) + abs(b - cd[1]):
                dist = abs(a - cd[0]) + abs(b - cd[1])
                num = i + 1

        print(num)


if __name__ == '__main__':
    main()

Solution (Python):
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):
  c=10**10
  e=0
  for j in range(m):
    d=abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1])
    if d<c:
      c=d
      e=j
  print(e+1)

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

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

ans=[0 for i in range(N)]
for i in range(N):
    dis=10**9
    for j in range(M):
        xx=abs(ab[i][0]-cd[j][0])
        yy=abs(ab[i][1]-cd[j][1])
        temp=xx+yy
        if dis>temp:
            dis=temp
            ans[i]=j
for a in ans:
    print(a+1)

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

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

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

for s in range(N):
    x=[]
    a,b=stu[s]
    for t in range(M):
        c,d=che[t]
        x.append(abs(a-c)+abs(b-d))
    num=x.index(min(x))
    print(num+1)

Solution (Python):


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

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

Solution (Python):

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

for i in range(N):
    x = 0
    y = 0
    dist = 10**20
    ans = 0
    for j in range(M):
        x = abs(a[i] - c[j])
        y = abs(b[i] - d[j])
        if x + y < dist:
            dist = x + y
            ans = j + 1
    print(ans)

Solution (Python):
N,M=map(int,input().split())
stu=[list(map(int,input().split()))for i in range(N)]
zahyou=[list(map(int,input().split()))for i in range(M)]
ans=list()
for i in range(N):
    tmp=10**10
    tmp2=0
    for j in range(M):
        dist=abs(stu[i][1]-zahyou[j][1])+abs(stu[i][0]-zahyou[j][0])
        if dist <tmp:
            tmp=dist
            tmp2=j+1
    ans.append(tmp2)        
for i in ans:
    print(i)

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 s in ab:
        tmp = 10 ** 10
        ans = 0
        for i, t in enumerate(cd, 1):
            if tmp > abs(s[0]-t[0]) + abs(s[1]-t[1]):
                ans = i
                tmp = abs(s[0]-t[0]) + abs(s[1]-t[1])
        print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n,m=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]
B=[list(map(int,input().split())) for i in range(m)]
for a in A:
    m=float('Inf')
    p=0
    for i,b in enumerate(B):
        if m>abs(a[0]-b[0])+abs(a[1]-b[1]):
            m=abs(a[0]-b[0])+abs(a[1]-b[1])
            p=i+1
    print(p)

Solution (Python):
N,M = (int(T) for T in input().split())
Stud = [[] for TN in range(0,N)]
Check = [[] for TM in range(0,M)]
for TN in range(0,N):
    Stud[TN] = [int(T) for T in input().split()]
for TM in range(0,M):
    Check[TM] = [int(T) for T in input().split()]

GoPoint = [0]*N
for TN in range(0,N):
    MIND = 10**9
    for TM in range(0,M):
        Dist = abs(Stud[TN][0]-Check[TM][0])+abs(Stud[TN][1]-Check[TM][1])
        if Dist<MIND:
            MIND = Dist
            MINI = TM
    GoPoint[TN] = MINI+1
print('\n'.join(str(T) for T in GoPoint))

Solution (Python):
N, M = map(int, input().split())
student = [[0] for _ in range(N+1)]
point = [[0] for _ in range(M+1)]
for i in range(1, N+1):
    student[i] = list(map(int, input().split()))
for i in range(1, M+1):
    point[i] = list(map(int, input().split()))

for i in range(1, N+1):
    this_ans = 0
    pre_min_dict = 2000000001 * 2
    for j in range(1, M+1):
        this_dict = abs(student[i][0] - point[j][0]) + abs(student[i][1] - point[j][1])
        if pre_min_dict > this_dict:
            this_ans = j
            pre_min_dict = this_dict
    print(this_ans)

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

closest = {}
for s in student:
    min_dist = 'INF'
    ans = 1
    for c in checkpoint:
        dist = abs(s[0]-c[0]) + abs(s[1]-c[1])
        if min_dist == 'INF' or dist < min_dist:
            min_dist = dist
            closest[s] = ans
        ans += 1

for s in student:
    print(closest[s])

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N, M = map(int, input().split())
    student = []
    for _ in range(N):
        a, b = map(int, input().split())
        student.append((a, b))
    checkpoint = []
    for _ in range(M):
        c, d = map(int, input().split())
        checkpoint.append((c, d))

    for a, b in student:
        point, dist = -1, 10**18
        for i in range(M):
            c, d = checkpoint[i]
            if abs(a - c) + abs(b - d) < dist:
                point = i
                dist = abs(a - c) + abs(b - d)
        print(point + 1)



if __name__ == "__main__":
    main()

Solution (Python):
from operator import itemgetter
n,m = map(int,input().split())
stu = list(list(map(int,input().split())) for i in range(n))
cp = list(list(map(int,input().split())) for i in range(m))

for sx,sy in stu:
    dis = {}
    cnt = 1
    for cx,cy in cp:
        dis[cnt] = (abs(sx - cx) + abs(sy - cy))
        cnt += 1
    print(min(dis.items(), key = itemgetter(1))[0])

Solution (Python):
N, M = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(N)]
c = [list(map(int, input().split())) for _ in range(M)]
for i in range(N):
    m = 0
    for j in range(M):
        if abs(s[i][0]-c[m][0]) + abs(s[i][1]-c[m][1]) > abs(s[i][0]-c[j][0]) + abs(s[i][1]-c[j][1]):
            m = j
    print(m+1)

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

c = []
for _ in range(m):
    c.append([int(i) for i in input().split()])

for i in range(n):
    ans = 0
    l = 10**16
    for j in range(m):
        tmp = abs(g[i][0] - c[j][0]) + abs(g[i][1] - c[j][1])
        
        if tmp < l:
            l = tmp
            ans = j + 1
            
    print(ans)

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

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

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

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

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

Solution (Python):
from scipy.spatial.distance import cityblock

N,M = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for _ in range(N)]
C = [[int(i) for i in input().split()] for _ in range(M)]
d = [0]*M

for i in range(N):
    for j in range(M):
        d[j] = cityblock(S[i],C[j])
    print(d.index(min(d))+1)

Solution (Python):
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(m)]
for a,b in s:
    k=float('inf')
    f=0
    for i,(c,d) in enumerate(p,start=1):
        t=abs(a-c)+abs(b-d)
        if k>t:
            k=t
            f=i
    print(f)

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

    mr = 10 ** 9
    cp = 1

    for i, cd in enumerate(CD, 1):
        c = cd[0]
        d = cd[1]

        l = abs(a-c) + abs(b-d)

        if l < mr:
            mr = l
            cp = i

    print(cp)

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

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):
    dist_list = []
    for j in range(m):
        dist = abs(AB[i][0] - CD[j][0]) + abs(AB[i][1] - CD[j][1])
        dist_list.append(dist)
    
    print(dist_list.index(min(dist_list))+1)

Solution (Python):
n, m = map(int, input().split())
stud = []
poit = []
for i in range(n):
    a, b = map(int, input().split())
    stud.append([a, b])
for i in range(m):
    c, d = map(int, input().split())
    poit.append([c, d])
    
for a, b in stud:
    dist = float('inf')
    for i, info in enumerate(poit):
        c = info[0]
        d = info[1]
        mdist = abs(a-c) + abs(b-d)
        if dist > mdist:
            dist = mdist
            ans = i+1
    print(ans)

Solution (Python):
n, m = map(int, input().split())
s = [0] * n
t = [0] * m
for i in range(n):
    a, b = map(int, input().split())
    s[i] = (a, b)
for j in range(m):
    c, d = map(int, input().split())
    t[j] = (c, d)

for i in range(n):
    ans = 0
    mi = float('inf')
    for j in range(m):
        u = abs(s[i][0] - t[j][0]) + abs(s[i][1] - t[j][1])
        if u < mi:
            mi = u
            ans = j + 1
    print(ans)

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

def dis(st, cp):
  return abs(st[0] - cp[0]) + abs(st[1] - cp[1])

for n in range(N):
  min_dis = dis(st[n], cp[0])
  ans = 1
  for m in range(1, M):
    cur_dis = dis(st[n], cp[m])
    if cur_dis < min_dis:
      min_dis = cur_dis
      ans = m + 1
  print(ans)

Solution (Python):
n, m = map(int, input().split())
a, b, c, d = [0] * n, [0] * n, [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):
    min_dist, min_c = 10**9, -1
    for j in range(m):
        dist = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if dist < min_dist:
            min_dist = dist
            min_c = j
    print(min_c+1)

Solution (Python):
L=list()
R=list()
N,M=map(int,input().split())
for i in range(N):
  a,b=map(int,input().split())
  L.append([a,b])
for i in range(M):
  a,b=map(int,input().split())
  R.append([a,b])
ans=[0]*M
for i in range(N):
  K=[0]*M
  a,b=L[i]
  for j in range(M):
    K[j]=abs(a-R[j][0])+abs(b-R[j][1])
  s=min(K)
  q=K.index(s)
  print(q+1)

Solution (Python):
N,M=map(int,input().split())
stu=[]
for i in range(N):
  a,b=map(int,input().split())
  stu.append([a,b])
pl=[]
for j in range(M):
  c,d=map(int,input().split())
  pl.append([c,d])
for k in range(N):
  met=4*(10**8)+1
  pr=0
  for l in range(M):
    if abs(pl[l][0]-stu[k][0])+abs(pl[l][1]-stu[k][1])<met:
      met=abs(pl[l][0]-stu[k][0])+abs(pl[l][1]-stu[k][1])
      pr=l+1
  print(pr)

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

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

for i in range(N):
  dist = list(map(lambda x:calc_dict(s[i],x),c))
  print(dist.index(min(dist))+1)

Solution (Python):
N, M = list(map(lambda x: int(x), input().split(" ")))
ppl = []
chk = []
for i in range(N):
  ppl.append(list(map(lambda y: int(y), input().split(" "))))
for j in range(M):
  chk.append(list(map(lambda z: int(z), input().split(" "))))

goal = [0] * N
for i in range(N):
  stu = ppl[i]
  min_d = -1
  dest = 0

  for j in range(M):
    point = chk[-j-1]
    d = abs(stu[0] - point[0]) + abs(stu[1] - point[1])
    if min_d < 0 or d <= min_d:
      min_d = d
      dest = M - j
  
  goal[i] = dest

print("\n".join([str(g) for g in goal]))

Solution (Python):
def main():
    n, m = map(int, input().split())
    A, X = [], []
    for _ in range(n):
        A.append(list(map(int, input().split())))
    for _ in range(m):
        X.append(list(map(int, input().split())))
    for a, b in A:
        ans, dist = 0, 10e+10
        for i, (x, y) in enumerate(X):
            if (d := abs(x - a) + abs(y - b)) < dist:
                dist = d
                ans = i + 1
        print(ans)

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

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

total = []
for i in range(n):
    temp = []
    for j in range(m):
        distance = abs(g[i][0] - c[j][0]) + abs(g[i][1] - c[j][1])
        temp.append(distance)
    total.append(temp)


for i in range(n):
    midx = 0
    mv = 99999999999999999999999999
    for j in range(m):
        if (mv > total[i][j]):
            midx = j
            mv = total[i][j]
    print(midx+1)

Solution (Python):
def resolve():
    N, M = map(int, input().split())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    C = []
    D = []
    for __ in range(M):
        c, d = map(int, input().split())
        C.append(c)
        D.append(d)
    for i in range(N):
        count = abs(A[i]-C[0]) + abs(B[i]-D[0])
        ans = 1
        for j in range(1, M):
            if count > abs(A[i]-C[j]) + abs(B[i]-D[j]):
                count = abs(A[i]-C[j]) + abs(B[i]-D[j])
                ans = j+1
        print(ans)
resolve()

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

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

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

for i in range(N):
    l0=abs(a[i]-c[0])+abs(b[i]-d[0])
    ans=1
    for j in range(1,M):
        l=abs(a[i]-c[j])+abs(b[i]-d[j])
        if l0>l:
            l0=l
            ans=j+1
    
    print(ans)

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

lsans = []
for i in range(N):
    max1 = 4*10**8+100
    ans = 0
    for j in range(M):
        dis = abs(lsab[i][0]-lscd[j][0])+abs(lsab[i][1]-lscd[j][1])
        if dis < max1:
            ans = j+1
            max1 = dis
    lsans.append(ans)

for i in range(N):
    print(lsans[i])

Solution (Python):
n,m=map(int,input().split())
stu=[[0,0] for i in range(n)]
po=[[0,0] for i in range(m)]
for i in range(n):
    a,b=map(int,input().split())
    stu[i][0]=a
    stu[i][1]=b
for i in range(m):
    c,d=map(int,input().split())
    po[i][0]=c
    po[i][1]=d
ans=[]
for i in range(n):
    x=stu[i][0]
    y=stu[i][1]
    dis=[]
    for j in range(m):
        dis.append(abs(x-po[j][0])+abs(y-po[j][1]))
    ans.append(dis.index(min(dis)))
for i in range(n):
    print(ans[i]+1)

Solution (Python):
n,m=map(int,input().split())
ss=[list(map(int,input().split())) for i in range(n)]
che=[list(map(int,input().split())) for i in range(m)]
for i in range(n):
    ans=100000000000000000000000000000000000000000000000000000
    x,y=ss[i]
    for  j in range(m):
        if ans>abs(x-che[j][0])+abs(y-che[j][1]):
            ans=abs(x-che[j][0])+abs(y-che[j][1])
            ind=j
    print(ind+1)

Solution (Python):
n,m = map(int,input().split())
a = [list(map(int,input().split())) for A in range(n)]
c = [list(map(int,input().split())) for C in range(m)]
for i in range(n):
    ans = []
    for j in range(m):
        ans.append((abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])))
    print(ans.index(min(ans))+1)

Solution (Python):
n, m = list(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 student in s:
    index = 1000
    idist = 1e9

    for i in range(m):
        dist = abs(student[0] - c[i][0]) + abs(student[1] - c[i][1])
        if (dist < idist):
            idist = dist
            index = i

    print(index + 1)

Solution (Python):
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))
  
for i in ab:
  s = float("inf")
  for j in range(m):
    t = abs(i[0]-cd[j][0]) + abs(i[1]-cd[j][1])
    if t < s:
      s = t
      ans = j+1
  print(ans)

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

for i in range(N):
  dmin=10**9
  for j in range(M):
    dcurr=abs(x[i]-c[j])+abs(y[i]-d[j])
    if dcurr<dmin:
      ans[i]=j+1
      dmin=dcurr

for n in ans:
  print(n)

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

student =[] 
for _ in range(n):
    a,b=map(int,input().split())
    student.append([a,b])

check=[]

for _ in range(m):
    a,b=map(int,input().split())
    check.append([a,b])

for s in student:
    ans=10**9
    i=0
    for j in range(m):
        c=check[j]
        dist = abs(c[0]-s[0]) + abs(c[1]-s[1])
        if dist<ans:
            ans=dist
            i=j+1

    print(i)

Solution (Python):
n,m=map(int,input().split())
stu=[list(map(int, input().split())) for _ in range(n)]
che=[list(map(int, input().split())) for _ in range(m)]
for i in range(n):
    a=stu[i][0]
    b=stu[i][1]
    minche=50
    minlen=10**10
    for j in range(m):
        x=che[j][0]
        y=che[j][1]
        kyori=abs(a-x)+abs(b-y)
        if kyori<minlen:
            minlen=kyori
            minche=j+1
    print(minche)

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

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

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

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

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

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

Solution (Python):
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, M = read_ints()
    students, checkpoints = [], []
    for _ in range(N):
        students.append(read_ints())
    for _ in range(M):
        checkpoints.append(read_ints())
    for s in students:
        min_dist = math.inf
        min_j = math.inf
        for j, c in enumerate(checkpoints, start=1):
            if abs(s[0]-c[0])+abs(s[1]-c[1]) < min_dist:
                min_dist = abs(s[0]-c[0])+abs(s[1]-c[1]) 
                min_j = j
        print(min_j)


if __name__ == '__main__':
    solve()

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

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

for a,b in St:
    dis = [abs(a-c) + abs(b-d) for c,d in Pt]
    print(dis.index(min(dis)) + 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 i in range(n):
    r = 999999999999999999
    cp = -1
    for j in range(m):
        if abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]) < r:
            r = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            cp = j
    print(cp+1)

Solution (Python):

n,m = map(int,input().split())
ab = []
cd = []
for i in range(n):
    ab.append(list(map(int,input().split())))
for i in range(m):
    cd.append(list(map(int,input().split())))
    
for i in range(n):
    Min = [0,float("inf")]
    for j in range(m):
        l = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if Min[1]>l:
            Min = [j+1,l]
    print(Min[0])

Solution (Python):

n,m = map(int,input().split())
ab = []
cd = []
for i in range(n):
    ab.append(list(map(int,input().split())))
for i in range(m):
    cd.append(list(map(int,input().split())))
    
for i in range(n):
    Max = [0,float("inf")]
    for j in range(m):
        l = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if Max[1]>l:
            Max = [j+1,l]
    print(Max[0])

Solution (Python):
N, M = list(map(int, input().split()))
P, CP = [], []

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

for i in range(N):
    a, b = P[i][0], P[i][1]
    now = 10**10
    for j in reversed(range(M)):
        c, d = CP[j][0], CP[j][1]
        distance = abs(a-c)+abs(b-d)
        if distance <= now:
            result = j+1
            now = distance
    print(result)

Solution (Python):
n, m = [int(x) for x in input().split()]
s_list = [[int(x) for x in input().split()] for _ in range(n)]
c_list = [[int(x) for x in input().split()] for _ in range(m)]
for i in range(n):
    d = 10 ** 9
    p = 0
    for j in range(m):
        temp_d = abs(s_list[i][0] - c_list[j][0]) + abs(s_list[i][1] - c_list[j][1])
        if temp_d < d:
            d = temp_d
            p = j + 1
    print(p)

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

for j in range(n):
  best=100000000000
  for i in range(m):
    d=abs(ml[i][0]-nl[j][0]) + abs(ml[i][1]-nl[j][1])
    if best>d:
      best=d
      ans=i+1
  print(ans)

Solution (Python):
class Coodinate (object):
    """Coodinate object
    This class contains infomation about the coodinates.
    Each instance can have up to 3-dimensional(x,y,z) space coodinates.
    
    params
    ------------------------------
    x : int or floot ,default 0
    y : int or floot ,default 0
    z : int or floot ,default 0


    This class have following methods.
    ------------------------------
    distance : Calculate the straight-line distance between 2 points in Euclidean space.
    midpoint : Calculate the midpoint(halfway) between 2 points.
    manhattan_distance : Calculate the distance between 2 points that is sum of the absolute values their Cartesian coordinates.
    """

    def __init__(self,x=0,y=0,z=0):
        self.x=x
        self.y=y
        self.z=z
    
    def distance(self,other):
        """Calculate the straight-line distance between 2 points in Euclidean space.

        params
        ----------
        self : Coodinate object
        other : Coodinate object

        return
        ----------
        distance : floot

        """
        x_diff_sq=(self.x-other.x)**2
        y_diff_sq=(self.y-other.y)**2
        z_diff_sq=(self.z-other.z)**2
        return (x_diff_sq + y_diff_sq +z_diff_sq)**0.5
    

    def midpoint(self,other):
        """Calculate the midpoint(halfway) between 2 points.

        params
        ----------
        self : Coodinate object
        other : Coodinate object

        return
        ----------
        midpoint : tupul
        
        """
        x_midpoint=(self.x+other.x)/2
        y_midpoint=(self.y+other.y)/2
        z_midpoint=(self.z+other.z)/2
        if self.z == other.z ==0 :
            if self.y == other.y==0:
                return(x_midpoint)
            else:
                return(x_midpoint,y_midpoint) 
        return(x_midpoint,y_midpoint,z_midpoint)

    def manhattan_distance(self,other):
        """Calculate the distance between 2 points that is sum of the absolute values their Cartesian coordinates.

        params
        ----------
        self : Coodinate object
        other : Coodinate object

        return
        ----------
        manhattan_distance : floot

        """

        x_diff_abs=abs(self.x - other.x)
        y_diff_abs=abs(self.y - other.y)
        z_diff_abs=abs(self.z - other.z)
        return(x_diff_abs + y_diff_abs + z_diff_abs)




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

C=[]
for j in range(M):
    c,d=map(int,input().split())
    C.append(Coodinate(c,d))

for k in range (N):
    t1=10**9
    t2=-1
    for l in range (M):
        temp=Coodinate.manhattan_distance(S[k],C[l])
        if temp<t1:
            t1=temp
            t2=l+1
    print(t2)

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):
    cj, dj = map(int, input().split())
    c.append(cj)
    d.append(dj)

for i in range(n):
    dist_min = 10 ** 9
    ans = 0
    for j in range(m):
        dist = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if dist < dist_min:
            dist_min = dist
            ans = j+1
    print(ans)

Solution (Python):
N,M = [int(i) for i in input().split()]
student = [[int(i) for i in input().split()] for j in range(N)]
check = [[int(i) for i in input().split()] + [j+1] for j in range(M)]
print("\n".join(map(str, [min(check, key=lambda x: abs(i[0] - x[0]) + abs(i[1] - x[1]))[-1] for i in student])))

Solution (Python):
n , m = map(int , input().split())
a =[]
b=[]
for i in range(n):
	a.append(list(map(int , input().split())))
for i in range(m):
	b.append(list(map(int, input().split())))
for i in range(n):
	now =10**9+90000
	idx=0
	for j in range(m):
		d=abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1])
		if(d<now):
			now=d
			idx=j+1
	print(idx)