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 math


argv = [int(x) for x in input().split(" ")]


student_coordinates = []
for i in range(argv[0]):
    student_coordinates.append([int(x) for x in input().split(" ")])


check_points = []
for i in range(argv[1]):
    check_points.append([int(x) for x in input().split(" ")])

def manhattan_dist(point_1, point_2):
    return math.fabs(point_1[0] - point_2[0]) + math.fabs(point_1[1] - point_2[1])

def select_check_point(student):
    dist_list = []
    for i in range(argv[1]):
        dist_list.append(manhattan_dist(student, check_points[i]))
    return dist_list.index(min(dist_list))

for i in range(argv[0]):
    print(select_check_point(student_coordinates[i]) + 1)

Solution (Python):
[N,M] = map(int, raw_input().split())
sl = []
for i in range(N):
    sl.append(map(int, raw_input().split()))
pl = []
for i in range(M):
    pl.append(map(int, raw_input().split()))
ans = []
for (x,y) in sl:
    dmin = 400000001
    imin = -1
    for (i, (px, py)) in enumerate(pl):
        d = abs(x - px) + abs(y - py)
        if(d < dmin):
            dmin = d
            imin = i
    ans.append(imin+1)
for i in ans:
    print i

Solution (Python):


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

a_list, b_list, c_list, d_list = [], [], [], []


for i in range(N):
	a, b = map(int, input().split())
	a_list.append(a)
	b_list.append(b)


for i in range(M):
	c, d = map(int, input().split())
	c_list.append(c)
	d_list.append(d)

for j in range(N):
	dist = []
	for k in range(M):
		dist.append(abs(a_list[j] - c_list[k]) + abs(b_list[j] - d_list[k]))
	print(dist.index(min(dist))+1)

Solution (Python):


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

students = [map(int,raw_input().split()) for _ in range(n)]
checkpoints = [map(int,raw_input().split()) for _ in range(m)]



for a,b in students:
    idx = -1
    dist = 10**9
    for j in range(m):
        c,d = checkpoints[j]
        manhat = abs(a-c)+abs(b-d)
        if manhat < dist:
            dist = manhat
            idx = j+1
    print(idx)

Solution (Python):
data = list(map(int,input().split(" ")))
stdnt = []
for i in range(data[0]):
	stdnt.append(list(map(int,input().split(" "))))
point = []
for i in range(data[1]):
	point.append(list(map(int,input().split(" "))))
def check(st,po):
	for i in range(len(st)):
                distance = []
                for j in range(len(po)):
                        distance.append(abs(st[i][0]-po[j][0])+abs(st[i][1]-po[j][1]))
                print(distance.index(min(distance)) + 1)
check(stdnt,point)

Solution (Python):

N, M = map(int, input().split())
coordinate = []
checkpoint = []
tmplist = []
for tmp in range(N):
    a, b = map(int, input().split())
    coordinate.append((a,b))
for tmp in range(M):
    c, d = map(int, input().split())
    checkpoint.append((c,d))
for i in range(N):
    for j in range(M):
        tmplist.append(abs(coordinate[i][0]-checkpoint[j][0])+abs(coordinate[i][1]-checkpoint[j][1]))
    print(tmplist.index(min(tmplist))+1)
    tmplist = []

Solution (Python):


import sys
import os


N, M = list(map(int, input().split()))
students = []
checkpoints = []

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

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

for student in students:
    min_dist = float('inf')
    min_i = None
    for i, checkpoint in enumerate(checkpoints):
        manhattan_dist = abs(checkpoint[0] - student[0]) + abs(checkpoint[1] - student[1])
        if manhattan_dist < min_dist:
            min_dist = manhattan_dist
            min_i = i
    print(min_i + 1)

Solution (Python):
import sys

if __name__=="__main__":
    ab=[]
    cd=[]
    [n,m]=map(int,input().split(" "))
    for i in range(n):
        ab.append(list(map(int,input().split(" "))))
    for j in range(m):
        cd.append(list(map(int,input().split(" "))))
    for i in range(n):
        min=sys.maxsize
        index=0
        for j in range(m):
            distance = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            if min > distance :
                min=distance 
                index=j
        print(index+1)

Solution (Python):
import sys

if __name__=="__main__":
    ab=[]
    cd=[]
    [n,m]=map(int,input().split(" "))
    for i in range(n):
        ab.append(list(map(int,input().split(" "))))
    for j in range(m):
        cd.append(list(map(int,input().split(" "))))
    for i in range(n):
        min=sys.maxsize
        index=0
        for j in range(m):
            distance = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            if min > distance :
                min=distance 
                index=j
        print(index+1)

Solution (Python):
import sys

if __name__=="__main__":
    ab=[]
    cd=[]
    [n,m]=map(int,input().split(" "))
    for i in range(n):
        ab.append(list(map(int,input().split(" "))))
    for j in range(m):
        cd.append(list(map(int,input().split(" "))))
    for i in range(n):
        min=sys.maxsize
        index=0
        for j in range(m):
            distance = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            if min > distance :
                min=distance 
                index=j
        print(index+1)

Solution (Python):
import sys

if __name__=="__main__":
    ab=[]
    cd=[]
    [n,m]=map(int,raw_input().split(" "))
    for i in range(n):
        ab.append( map(int,raw_input().split(" ")) )
    for j in range(m):
        cd.append( map(int,raw_input().split(" ")) )
    for i in range(n):
        min=sys.maxint
        index=0
        for j in range(m):
            distance = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            if min > distance :
                min=distance 
                index=j
        print(index+1)

Solution (Python):
import sys

if __name__=="__main__":
    ab=[]
    cd=[]
    [n,m]=map(int,raw_input().split(" "))
    for i in range(n):
        ab.append( map(int,raw_input().split(" ")) )
    for j in range(m):
        cd.append( map(int,raw_input().split(" ")) )
    for i in range(n):
        min=sys.maxint
        index=0
        for j in range(m):
            distance = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            if min > distance :
                min=distance 
                index=j
        print(index+1)

Solution (Python):
import numpy as np

def manhattan(x,y):
    return np.abs(x[0]-y[0]) + np.abs(x[1]-y[1])

N,M = map(int,raw_input().split())
students = np.zeros((N,2))
checkpoints = np.zeros((M,2))
for i in range(N):
    students[i][0],students[i][1] = map(int,raw_input().split())

for j in range(M):
    checkpoints[j][0],checkpoints[j][1] = map(int,raw_input().split())

index = np.zeros(N)
for i in range(N):
    min = 200000000
    for j in range(M):
        d = manhattan(students[i],checkpoints[j])
        if min > d:
            min = d
            index[i] = j
    print (index[i]+1).astype(np.int32)

Solution (Python):
import os
import sys


def manhatten(tupleA,tupleB):
	return abs(tupleA[0]-tupleB[0]) + abs(tupleA[1]-tupleB[1])

header = input().split()
N,M = int(header[0]),int(header[1])
students = []
checkpoints = []

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

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

for student in students:
	distance = []
	for checkpoint in checkpoints:
		d = manhatten(student,checkpoint)
		distance.append(d)
	print(distance.index(min(distance))+ 1)

Solution (Python):
import math

def main():
    N, M = tuple(map(int, input().split(' ')))
    man_list = []
    point_list = []
    for i in range(N):
        man_list.append(tuple(map(int, input().split(' '))))
    for i in range(M):
        point_list.append(tuple(map(int, input().split(' '))))

    result = []
    for i, man in enumerate(man_list):
        a, b = man
        min_ = float('inf')
        for j, point in enumerate(point_list):
            c, d = point
            v = abs(a-c)+ abs(b-d)
            if len(result) < i+1:
                min_ = v
                result.append(j+1)
                continue
            if v < min_:
                result[i] = j+1
                min_ = v


    for r in result:
        print('{}'.format(r))


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    
    n, m = [int(x) for x in input().split()]
    students = []
    cpoints = []
    for _ in range(n):
        students.append([int(x) for x in input().split()])
    for _ in range(m):
        cpoints.append([int(x) for x in input().split()])
    for student in students:
        res = 1
        closest_dis = man_dis(student[0], cpoints[0][0], student[1], cpoints[0][1])
        for c_idx in range(1, m):
            this_dis = man_dis(student[0], cpoints[c_idx][0], student[1], cpoints[c_idx][1])
            if this_dis < closest_dis:
                closest_dis = this_dis
                res = c_idx + 1
        print(res)
    


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


if __name__ == "__main__":
    main()

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

if __name__ == "__main__":
    nums = [int(num) for num in input().split()]
    N = nums[0]
    M = nums[1]
    students = []
    cps = []
    for i in range(N):
        coord = [int(num) for num in input().split()]
        students.append((coord[0], coord[1]))
    for i in range(M):
        coord = [int(num) for num in input().split()]
        cps.append((coord[0], coord[1]))

    cps2 = []
    for s in students:
        idx = -1
        d = 0
        for i, c in enumerate(cps):
            dd = dis(s, c)
            if idx == -1 or d > dd:
                idx = i
                d = dd
        cps2.append(idx+1)

    for c in cps2:
        print(c)

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

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

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

for i in range(N):
    ans = min(range(M), key=lambda j: abs(a[i] - c[j]) + abs(b[i] - d[j]))
    print(ans + 1)

Solution (Python):
from functools import reduce
import sys

n, m = [int(i) for i in input().split(" ")]
student = []
checkpoint = []
for i in range(n):
    student.append([int(i) for i in input().split(" ")])
for i in range(m):
    checkpoint.append([int(i) for i in input().split(" ")])
    
def calc_dist(loc1, loc2):
    return abs(loc1[0]-loc2[0])+abs(loc1[1]-loc2[1])

dist_list = list(map(lambda s: [calc_dist(s, c) for c in checkpoint], student))
near_checkpoint = list(map(lambda d: d.index(min(d)), dist_list))
for x in near_checkpoint:
    print(x+1)

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

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

student = []
checkpoint = []

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

for j in range(0, m):
    c, d = map(int, input().split())
    checkpoint.append((c, d))

for i in range(0, n):
    dist = 100000000000
    ans_num = 0
    for j in range(0, m):
        if distance(student[i], checkpoint[j]) < dist:
            dist = distance(student[i], checkpoint[j])
            ans_num = j + 1
    print(ans_num)

Solution (Python):
N, M = map(int, raw_input().split())
P = [map(int, raw_input().split()) for _ in range(N)]
Q = [map(int, raw_input().split()) for _ in range(M)]

for x1, y1 in P:
    dist = 10 ** 9
    ans = -1
    for i, (x2, y2) in enumerate(Q):
        if abs(x1 - x2) + abs(y1 - y2) < dist:
            dist = abs(x1 - x2) + abs(y1 - y2)
            ans = i + 1
    print ans

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

M,N=[int(x) for x in input().split()]

student=[]
check=[]
for i in range(0,M):
    a,b=[int(x) for x in input().split()]
    student.append((a,b))

for j in range(0,N):
    c,d=[int(x) for x in input().split()]
    check.append((c,d))


for i in range(0,M):
    dist=distance(student[i],check[N-1])
    num=N-1
    for j in range(0,N):
        k=N-j-1
        if dist>=distance(student[i],check[k]):
            dist=distance(student[i],check[k])
            num=k
    print(num+1)

Solution (Python):
num = list(map(int, input().split()))
n = num[0]
m = num[1]
students = [list(map(int, input().split())) for i in range(n)]
points = [list(map(int, input().split())) for i in range(m)]

ans = [0] * n
for i, student in enumerate(students):
    for j, point in enumerate(points):
        distance = abs(student[0] - point[0]) + abs(student[1] - point[1])
        if j == 0:
            mini = distance
        elif distance < mini:
            mini = distance
            ans[i] = j

for num in ans:
    print(num + 1)

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

Solution (Python):
n,m=map(int,input().split())
std=[]
tgt=[]
for _ in range(n):
    std.append(list(map(int,input().split())))
for _ in range(m):
    tgt.append(list(map(int,input().split())))
for i in range(n):
    lt=100000000000000000
    li=0
    for j in range(m):
        if abs(std[i][0]-tgt[j][0])+abs(std[i][1]-tgt[j][1])<lt:
            lt=abs(std[i][0]-tgt[j][0])+abs(std[i][1]-tgt[j][1])
            li=j
    print(li+1)

Solution (Python):

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

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

for i in range(N):
    mincp = -1
    mindist = -1
    for j in range(M):
        dist = abs(students[i][0]-checkpoints[j][0]) + abs(students[i][1]-checkpoints[j][1])
        if mincp == -1:
            mincp = j
            mindist = dist
        else:
            if dist < mindist:
                mindist = dist
                mincp = j
    print("%d" % (mincp+1))

Solution (Python):


n,m=map(int,raw_input().split())
ab=[]
for i in xrange(n):
 a,b=map(int,raw_input().split())
 ab.append([a,b])
cd=[]
for i in xrange(m):
 c,d=map(int,raw_input().split())
 cd.append([c,d])

for i in xrange(n):
 res=-1
 lm=10**9
 for j in xrange(m):
  l=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
  if l<lm:
   lm=l
   res=j
 print res+1

Solution (Python):
import math

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


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


check = []
for j in range(m):
    c, d = map(int, input().split())
    check.append([c, d])


for s in student:
    distance = 10e9
    near = 0
    for index, k in enumerate(check):
        v = math.fabs(s[0] - k[0]) + math.fabs(s[1] - k[1])
        if v < distance:
            distance = v
            near = index + 1
    print(near)

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

ab = [map(int, raw_input().split()) for _ in xrange(N)]
cd = [map(int, raw_input().split()) for _ in xrange(M)]

for i in xrange(N):
    for j in xrange(M):

        d = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])

        if j == 0:
            t = d
            ans = 1

        elif t > d:
            t = d
            ans = j+1

    print ans

Solution (Python):
import math

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

ab = [map(int, raw_input().split()) for _ in xrange(N)]
cd = [map(int, raw_input().split()) for _ in xrange(M)]

for i in xrange(N):
    for j in xrange(M):

        d = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])

        if j == 0:
            t = d
            ans = 1

        elif t > d:
            t = d
            ans = j+1

    print ans

Solution (Python):




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


n, m = map(int, input().split())
st = [[int(a) for a in input().split()] for _ in range(n)]
cp = [[int(a) for a in input().split()] for _ in range(m)]

for s in st:
    index, dist = 0, 9999999999999999999999
    for i, c in enumerate(cp):
        if distance(s, c) < dist:
            index, dist = i, distance(s, c)
    print(index + 1)

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

for a, b in students:
    min_d = float("inf")
    ans = None
    for i, (c, d) in enumerate(checkpoints):
        dist = abs(a - c) + abs(b - d)
        if dist < min_d:
            min_d = dist
            ans = i+1
    print (ans)

Solution (Python):

import math
num_N, num_M = map(int, input().split())
l_stu = [list(map(int, input().split())) for __ in range(num_N)]
l_che = [list(map(int, input().split())) for __ in range(num_M)]

for stu in l_stu:
    dis_ind = []
    for index, che in enumerate(l_che):
        dis = math.fabs(che[0] - stu[0]) + math.fabs(che[1] - stu[1])
        dis_ind.append([dis, index + 1])

    dis_ind.sort(key=lambda x: (x[0], x[1]))
    print(dis_ind[0][1])

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

cp=[]
for i in range(m):
    c,d=map(int,input().split())
    cp.append([i+1,c,d])

Q=[]

for i in range(n):
    
    man = 10**8*4

    for j in range(m):

        if abs(cp[j][1]-st[i][0])+abs(cp[j][2]-st[i][1]) < man:
            man = abs(cp[j][1]-st[i][0])+abs(cp[j][2]-st[i][1])
            ans = cp[j][0]

    Q.append(ans)


for i in Q:
    print(i)

Solution (Python):



N, M = map(int, input().split()) 
ABs = [] 
CDs = [] 


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


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

for a,b in ABs:
    
    distance = [abs(a-c) + abs(b-d) for c,d in CDs]
    
    
    
    print(distance.index(min(distance)) + 1)

Solution (Python):
from math import *


def read(): return list(map(int, input().split()))


n, m = read()
per = []
for i in range(n):
    per.append(read())

point = []
for i in range(m):
    point.append(read())

for p in per:
    mi = 1145141919
    ans = 0
    for i in range(m - 1, -1, -1):
        d = abs(p[0] - point[i][0]) + abs(p[1] - point[i][1])
        if d <= mi:
            mi = d
            ans = i
    print(ans + 1)

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


def findshortest(s, checkpoints):
    shortest = 0
    for i in range(1, len(checkpoints)):
        if distance(s, checkpoints[i]) < distance(s, checkpoints[shortest]):
            shortest = i
    return shortest

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

for s in students:
    print(findshortest(s, checkpoints) + 1)

Solution (Python):
n, m = map(int, input().split())
pos = []
che = []
for i in range(n):
    a, b = map(int,input().split())
    pos.append([a,b])
for i in range(m):
    a, b = map(int,input().split())
    che.append([a,b])
 
for i in range(n):
    dis = []
    for j in range(m):
        dis.append(abs(pos[i][0]-che[j][0])+abs(pos[i][1]-che[j][1]))
    print(dis.index(min(dis))+1)

Solution (Python):
import math
n,m=map(int,raw_input().split())
a=[]
b=[]
for i in range(n):
	ia,ib=map(int,raw_input().split())
	a.append(ia)
	b.append(ib)
c=[]
d=[]
for i in range(m):
	ic,id=map(int,raw_input().split())
	c.append(ic)
	d.append(id)
for i in range(n):
	dist=10**9
	ans=0
	for j in range(m):
		ndist=abs(a[i]-c[j])+abs(b[i]-d[j])
		if ndist<dist:
			dist=ndist
			ans=j+1
	print ans

Solution (Python):


nm = [int(i) for i in input().split()]
n = nm[0]
m = nm[1]

a = list()
b = list()
c = list()
d = list()

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

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

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

Solution (Python):
import sys, array, re, functools
input = lambda: sys.stdin.readline()
@functools.lru_cache(maxsize = 10000)

def Main():
  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)
    
  cnt  = 0
  res = []
  zemi = []
  mn = 123456789256913
  
  bal = 0
  sal = M
  rez = []
  zakia , zemi = [], []
  for i in range(N):
    for j in range( M):
      X = abs(A[i] - C[j]) + abs(B[i] - D[j])
      zemi.append(X)
    zakia = zemi
    
    chk = min(zemi)
    
    
    for l in range(len(zakia)):
      if chk == zakia[l]:
        
        rez.append(l+1)
        break
    
    zemi.clear()
 
  for i in range(len(rez)):
    print(rez[i])
  

if __name__ == '__main__':
  Main()

Solution (Python):
n, m = map(int, input().split())
data1 = [list(map(int, input().split())) for i in range(n)]
data2 = [list(map(int, input().split())) for i in range(m)]
def d(i,j):
  return abs(data1[i][0] - data2[j][0]) + abs(data1[i][1] - data2[j][1])
for i in range(n):
  rv = d(i,0)
  rj = 0
  for j in range(1,m):
    v = d(i,j)  
    if v < rv:
      rv = v
      rj = j
  print(rj+1)

Solution (Python):
from sys import stdin 
n,m = map(int,stdin.readline().split())
a = []
b = []
valid = [0] * m
for i in xrange(n):
    x,y = map(int,stdin.readline().split())
    a.append((x,y))
for i in xrange(m):
    x,y = map(int,stdin.readline().split())
    b.append((x,y))
for i in xrange(n):
    ans = 10**18 
    ind = -1
    for j in xrange(m):
        
         
        fir = a[i][0] - b[j][0]
        sec = a[i][1] - b[j][1]
        if fir < 0:
            fir = -fir 
        if sec < 0:
            sec = -sec
        if fir + sec < ans:
            ans = fir + sec 
            ind = j 
    print ind + 1

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

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

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

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

for i in range(0, n):
    v = -1
    index = 0
    for j in range(0, m):

        l=abs(a[i] - c[j]) + abs(b[i] - d[j])
        if v == -1 or v > l:
            index = j
            v = l
    print(index + 1)

Solution (Python):


N, M = [int(x) for x in input().split()]
ABs = []
for n in range(N):
    ABs.append([int(x) for x in input().split()])
CDs = []
for m in range(M):
    CDs.append([int(x) for x in input().split()])
for a, b in ABs:
    dists = [abs(a - c) + abs(b - d) for c, d in CDs]
    print(dists.index(min(dists)) + 1)

Solution (Python):
import numpy as np

N, M= list(map(int, raw_input().split()))
student = [list(map(int, raw_input().split())) for i in range(N)]
checkpoint = [list(map(int, raw_input().split())) for i in range(M)]

student = np.array(student)
checkpoint = np.array(checkpoint)

for i in range(N):
    print(np.abs(checkpoint - student[i]).sum(axis=1).argmin()+1)

Solution (Python):
n,m=map(int,raw_input().split())
stu=[]
point=[]


for i in xrange(n):
    stu.append(map(int,raw_input().split()))
for j in xrange(m):
    point.append(map(int,raw_input().split()))


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



for co in stu:
    ctr=1
    l=[]
    for po in point:
        l.append((dis(po,co),ctr))
        ctr+=1
    l.sort()
    print l[0][1]

Solution (Python):
n, m = map(int, raw_input().split())
lx, ly, lxx, lyy = [], [], [], []
for i in range(n):
	x, y = map(int, raw_input().split())
	lx.append(x)
	ly.append(y)

for i in range(m):
	x, y = map(int, raw_input().split())
	lxx.append(x)
	lyy.append(y)

for i in range(n):
	mi = 10000000000
	note = 0
	for j in range(m):
		if abs(lx[i] - lxx[j]) + abs(ly[i] - lyy[j]) < mi:
			mi = abs(lx[i] - lxx[j]) + abs(ly[i] - lyy[j])
			note = j + 1
	print note

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

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

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

def query(x):
    res_i = 0
    res = 1e+18 + 7
    for i in range(m):
        dist = abs(a[x] - c[i]) + abs(b[x] - d[i])
        if res > dist:
            res_i = i
            res = dist
    return res_i+1

for i in range(n):
    print(query(i))

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

    ab = []
    i = 0
    while i < N:
        ab += [tuple(map(int, input().split()))]
        i += 1

    cd = []
    i = 0
    while i < M:
        cd += [tuple(map(int, input().split()))]
        i += 1

    i = 0
    while i < N:
        j = 0
        l = []
        while j < M:
            l.append(abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]))
            j += 1
        i += 1
        print(l.index(min(l)) + 1)
main()

Solution (Python):
import math

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

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

for i in xrange(N):
    s = map(int, raw_input().split())
    a.append(s[0])
    b.append(s[1])

for i in xrange(M):
    s = map(int, raw_input().split())
    c.append(s[0])
    d.append(s[1])


ans = 0
t = 0
for i in xrange(N):
    for j in xrange(M):
        if j == 0:
            t = abs(a[i]-c[j]) + abs(b[i]-d[j])
            ans = 1
        elif t > abs(a[i]-c[j]) + abs(b[i]-d[j]):
            t = abs(a[i]-c[j]) + abs(b[i]-d[j])
            ans = j+1
        
        
    print ans

Solution (Python):
def dist(a,b,c,d):
    return abs(a-c)+abs(b-d)

N,M=map(int,raw_input().split())
ns=[]
for i in xrange(N):
    a,b=map(int,raw_input().split())
    ns.append((a,b))
ms=[]
for i in xrange(M):
    c,d=map(int,raw_input().split())
    ms.append((c,d))

for a,b in ns:
    mini=None
    idx=None
    cnt=1
    for c,d in ms:
        
        di = dist(a,b,c,d)
        if di < mini or mini==None:
            idx=cnt
            mini=di
        cnt+=1
    print idx

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

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

ans = []
for i in range(N):
    x = a[i]
    y = b[i]
    ind = 0
    distance = 4*10**8
    for j in range(M):
        if(distance > abs(x - c[j]) + abs(y - d[j])):
            ind = j
            distance = abs(x - c[j]) + abs(y - d[j])
    ans.append(ind)

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

Solution (Python):


N,M=map(int,raw_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,raw_input().split())
for j in range(M):
    c[j],d[j]=map(int,raw_input().split())
for i in range(N):
    dist=[0]*M
    for j in range(M):
        dist[j]=abs(a[i]-c[j])+abs(b[i]-d[j])
        
    print [i for i,x in enumerate(dist) if x==min(dist)][0]+1

Solution (Python):
import numpy as np
N, M = map(int, input().split())
list_coStu = []
list_coChe = []
for i in range(N):
    list_coStu.append(list(map(int, input().split())))
for i in range(M):
    list_coChe.append(list(map(int, input().split())))



for iS in range(len(list_coStu)):
    coStu = np.array(list_coStu[iS])
    min_iC = 0
    d = 4 * 10**8 + 1
    for iC in range(len(list_coChe)):
        coChe = np.array(list_coChe[iC])
        dif = coChe - coStu
        dist = np.sum(np.abs(dif))
        if dist < d:
            min_iC = iC
            d = dist
    print(min_iC + 1)

Solution (Python):


N, M = map(int, raw_input().split())
n = []
m = []
for i in range(N):
    n.append(map(int, raw_input().split()))

for i in range(M):
    m.append(map(int, raw_input().split()))

for i in range(N):
    distances = [abs(n[i][0] - m[j][0]) + abs(n[i][1] - m[j][1]) for j in range(M)]
    print(distances.index(min(distances)) + 1)

Solution (Python):
N, M = list(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_list in ab:
    min_distance = 400000000
    checkpoint = 0
    for cd_list in cd:
        checkpoint += 1
        distance = abs(ab_list[0] - cd_list[0]) + abs(ab_list[1] - cd_list[1])
        if distance < min_distance:
            min_distance = distance
            ans = checkpoint
    print(ans)

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

for i in range(n):
    res=min(range(m),key=lambda j:abs(a[i]-c[j])+abs(b[i]-d[j]))
    print(res+1)

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

for i in range(n):
    res=min(range(m),key=lambda j:abs(a[i]-c[j])+abs(b[i]-d[j]))
    print(res+1)