Problem:
 Score : 200 points    Problem Statement There are N students and M checkpoints on the xy -plane. The coordinates of the i -th student (1 \leq i \leq N) is (a_i,b_i) , and the coordinates of the checkpoint numbered j  (1 \leq j \leq M) is (c_j,d_j) . When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance . The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2| . Here, |x| denotes the absolute value of x . If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index. Which checkpoint will each student go to?      Constraints  1 \leq N,M \leq 50  -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8  All input values are integers.         Input The input is given from Standard Input in the following format:  N  M  a_1  b_1  :  a_N  b_N  c_1  d_1  :  c_M  d_M       Output Print N lines. The i -th line (1 \leq i \leq N) should contain the index of the checkpoint for the i -th student to go.        Sample Input 1 2 2
2 0
0 0
-1 0
1 0      Sample Output 1 2
1  The Manhattan distance between the first student and each checkpoint is:   For checkpoint 1 : |2-(-1)|+|0-0|=3  For checkpoint 2 : |2-1|+|0-0|=1   The nearest checkpoint is checkpoint 2 . Thus, the first line in the output should contain 2 .  The Manhattan distance between the second student and each checkpoint is:   For checkpoint 1 : |0-(-1)|+|0-0|=1  For checkpoint 2 : |0-1|+|0-0|=1   When there are multiple nearest checkpoints, the student will go to the checkpoint with the smallest index. Thus, the second line in the output should contain 1 .       Sample Input 2 3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5      Sample Output 2 3
1
2  There can be multiple checkpoints at the same coordinates.       Sample Input 3 5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000      Sample Output 3 5
4
3
2
1

Solution (Python):
N,M = map(int,input().split())
a=[]
b=[]
for i in range(1,N+1):
    A,B = map(int,input().split())
    a.append(A)
    b.append(B)
c=[]
d=[]
for j in range(1,M+1):
    C,D = map(int,input().split())
    c.append(C)
    d.append(D)
for i in range(1,N+1):
    e=[]
    for j in range(1,M+1):
        E = abs(a[i-1]-c[j-1])+abs(b[i-1]-d[j-1])
        e.append(E)
    x = min(e)
    print(e.index(x)+1)

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

	
for i in range(n):
	mindis = 500000000
	minCheckPoint = -1
	for j in range(m):
		dis = abs(a[i]-c[j]) + abs(b[i]-d[j])
		if mindis > dis:
			mindis = dis
			minCheckPoint = j + 1
	print(minCheckPoint)

Solution (Python):
n, m = map(int, input().split())
nab = [list(map(int, input().split())) for x in range(n)]
mab = [list(map(int, input().split())) + [x + 1] for x in range(m)]
print("\n".join(map(str, [min(mab, key=lambda x: abs(x[0] - a) + abs(x[1] - b))[-1] for a, b in nab])))

Solution (Python):
import math;

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

cd = [];
for i in range(0, m):
    cd.append(input().split(" "));

for i in range(0, n):
    dist=9999999999999
    nearm=0;
    for j in range(0, m):
         dist2 = math.fabs(int(ab[i][0]) - int(cd[j][0])) + math.fabs(int(ab[i][1]) - int(cd[j][1]));
         if dist2 < dist:
            dist = dist2;
            nearm=j;
    print(nearm+1);

Solution (Python):
n,m = map(int,input().split())
student = []
check = []
ans = []

def add(num,point):
    for i in range(num):
        point.append(input().split())
    for i in range(len(point)):
        for j in range(len(point[i])):
            point[i][j] = int(point[i][j])

add(n,student)
add(m,check)

for i in range(n):
    for j in range(m):
        ans.append(abs(student[i][0] - check[j][0]) + abs(student[i][1] - check[j][1]))
    print(ans.index(min(ans)) + 1)
    ans = []

Solution (Python):
N, M = list(map(int, input().split()))
a = []
l = []
for i in range(N+M):
    a.append(list(map(int, input().split())))
for i in range(0, N):
    l = []
    for j in range(0, M):
        d = abs((a[i][0] - a[N+j][0])) + abs((a[i][1] - a[N+j][1]))
        l.append(d)
    
    print(l.index(min(l))+1)

Solution (Python):


import sys
import subprocess
import json
import time
import math
import re
import sqlite3

N, M = map(int, input().split())
a = []
b = []
c = []
d = []

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

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

for i in range(N):
    res_id = 0
    res = 10000000000
    for j in range(M):
        j_res = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if j_res < res:
            res_id = j
            res = j_res
    print(res_id + 1)

Solution (Python):
def calcManhattanDistance(student, checkpoint):
    return abs(student[0] - checkpoint[0]) + abs(student[1] - checkpoint[1])


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

    
    for student in students:
        distance_list = []

        for checkpoint in checkpoints:
            distance_list.append(calcManhattanDistance(student, checkpoint))

        
        minval = min(distance_list)
        print(distance_list.index(minval) + 1)

Solution (Python):
import sys




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


def read_str_list():
    return input().split()


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


def read_str():
    return input()


def distance(p1, p2):
    x1, y1 = p1
    x2, y2 = p2
    return abs(x1-x2) + abs(y1 - y2)


n, m = read_int_list()
students = [read_int_list() for i in range(n)]
checkpoints = [read_int_list() for j in range(m)]

for student in students:
    dist = 10 ** 20
    res = -1
    for index, checkpoint in enumerate(checkpoints):
        distance1 = distance(student, checkpoint)
        if distance1 < dist:
            dist = distance1
            res = index + 1
    print(res)

Solution (Python):



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

nn = range(2*n)
mm = range(2*m)
for i in range(n):
    nn[i*2], nn[i*2 + 1] = map(int, raw_input().split())
for i in range(m):
    mm[i*2], mm[i*2 + 1] = map(int, raw_input().split())

for i in range(n):
    for j in range(m):
        s = abs(mm[j*2]-nn[i*2]) + abs(mm[j*2+1]-nn[i*2+1])
        if j == 0:
            ma = s
            p = j + 1
        elif s < ma:
            ma = s
            p = j + 1
    print p

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

a = []
b = []
ans = []
dis = []

for i in range(n):
    p, q = map(int, input().split())
    a.append(p)
    b.append(q)
    ans.append(-1)
    dis.append(100000000000)

for i in range(m):
    x, y = map(int, input().split())
    
    for j in range(n):
        calc_dis = abs(a[j]-x) + abs(b[j]-y)

        if dis[j] > calc_dis:
            ans[j] = i+1
            dis[j] = calc_dis

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

Solution (Python):


import numpy as np
n,m = [int(x) for x in input().split(' ')]
chil = []
check = []
minlist = []
for i in range(n):
    chil.append([int(x) for x in input().split(' ')])
for i in range(m):
    check.append([int(x) for x in input().split(' ')])
for c in chil:
    min = 10**12
    index = 0
    for inde,ch in enumerate(check):
        if abs(ch[1]-c[1]) + abs(ch[0]-c[0]) < min:
            min = abs(ch[1]-c[1]) + abs(ch[0]-c[0])
            index = inde
    minlist.append(index + 1)
for i in minlist:
    print(i)

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

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

results = [[] for i in range(n)]

for std in std_map:
    print(min(enumerate([abs(std[0] - ch[0]) + abs(std[1] - ch[1]) for ch in ch_map], 1), key=lambda x: x[1])[0])

Solution (Python):
a = input().split()
students = int(a[0])
checkpoints = int(a[1])

st_coord = []
for i in range(students):
    b = input().split()
    st_coord.append((int(b[0]), int(b[1])))

ch_coord = []
for j in range(checkpoints):
    c = input().split()
    ch_coord.append((int(c[0]), int(c[1])))


shortest = abs(st_coord[0][0] - ch_coord[0][0]) + abs(st_coord[0][1] - ch_coord[0][1])
for k in range(len(st_coord)):
    index = 1
    shortest = abs(st_coord[k][0] - ch_coord[0][0]) + abs(st_coord[k][1] - ch_coord[0][1])
    for l in range(len(ch_coord)):
        distance = abs(st_coord[k][0] - ch_coord[l][0]) + abs(st_coord[k][1] - ch_coord[l][1])
        if distance < shortest:
            shortest = distance
            index = l + 1
    print(index)

Solution (Python):


def dist(v1, v2):
    return abs(v1[0] - v2[0]) + abs(v1[1] - v2[1])


N, M = (int(e) for e in input().split())

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

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

for i in students:
    min_dist = 1e9
    to = None
    for j, cp in enumerate(checkpoints):
        d = dist(i, cp)
        if min_dist > d:
            to = j+1
            min_dist = d
    print(to)

Solution (Python):
def solve():
  ar = raw_input().split(' ')
  N = int(ar[0])
  M = int(ar[1])
  sts = []
  for n in range(N) :
    ar = raw_input().split(' ')
    a = int(ar[0])
    b = int(ar[1])
    sts.append((a, b))
  cks = []
  for m in range(M) :
    ar = raw_input().split(' ')
    c = int(ar[0])
    d = int(ar[1])
    cks.append((c, d))

  for st in sts :
    
    mind = float('inf')
    mini = -1
    for i in range(M):
      ckx = cks[i][0]
      cky = cks[i][1]
      d = abs(st[0] - ckx) + abs(st[1] - cky)
      
      if d < mind :
        mind = d
        mini = i
    
    print mini + 1

if __name__ == '__main__':
  solve()

Solution (Python):
class Point:
	def __init__(self, x, y):
		self.x = x
		self.y = y

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

	def __repr__(self):
		return "({0}, {1})".format(self.x, self.y)

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

a = []
c = []
for _ in range(N):
	x, y = [int(p) for p in input().split(" ")]
	a.append(Point(x, y))

for _ in range(M):
	x, y = [int(p) for p in input().split(" ")]
	c.append(Point(x, y))

for a_i in a:
	min_d = 250000000
	min_i = 0
	for i in range(len(c)):
		d = a_i.getDistance(c[i])
		if d < min_d:
			min_d = d
			min_i = i
	print(min_i + 1)

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



n_list = []
m_list = []

for i in range(int(N)):
    tmp_n_list = []
    num = input()
    tmp_num = num.split()
    tmp_n_list.append(int(tmp_num[0]))
    tmp_n_list.append(int(tmp_num[1]))
    n_list.append(tmp_n_list)

for j in range(int(M)):
    tmp_m_list = []
    num = input()
    tmp_num = num.split()
    tmp_m_list.append(int(tmp_num[0]))
    tmp_m_list.append(int(tmp_num[1]))
    m_list.append(tmp_m_list)

for k in range(int(N)):
    for l in range(int(M)):
        if l==0:
            dis = abs(n_list[k][0]-m_list[l][0])+abs(n_list[k][1]-m_list[l][1])
            point = l
        else:
            tmp_dis = abs(n_list[k][0]-m_list[l][0])+abs(n_list[k][1]-m_list[l][1])
            if dis>tmp_dis:
                dis = tmp_dis
                point = l
    print(point+1)

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

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

Solution (Python):
N,M = map(int,input().split())
S = []
T = []
for _ in range(N):
  a,b = map(int,input().split())
  S.append( (a,b) )
for _ in range(M):
  a,b = map(int,input().split())
  T.append( (a,b) )
for (a,b) in S:
  ans = 0
  best = 0
  for i in range(M):
    c,d = T[i]
    here = abs(a-c)+abs(b-d)
    if ans == 0 or best > here:
      ans = (i+1)
      best = here
  print(ans)

Solution (Python):
N,M=list(map(int, input().split()))
a=[]
c=[]
for n in range (0,N):
  a.append(list(map(int, input().split())))
for m in range(0,M):
  c.append(list(map(int, input().split())))

ans=[]
for n in range (0,N):
  place=1
  dist=abs(a[n][0]-c[0][0])+abs(a[n][1]-c[0][1])
  for m in range(1,M):
    if abs(a[n][0]-c[m][0])+abs(a[n][1]-c[m][1])<dist:
      dist=abs(a[n][0]-c[m][0])+abs(a[n][1]-c[m][1])
      place=m+1
  ans.append(place)

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

Solution (Python):
import numpy as np
N, M = map(int, raw_input().split())
a, b, c, d = [], [], [], []
for i in range(N):
    x, y = map(int, raw_input().split())
    a.append(x)
    b.append(y)
for j in range(M):
    x, y = map(int, raw_input().split())
    c.append(x)
    d.append(y)
for i in range(N):
    print np.argmin([abs(a[i] - c[j]) + abs(b[i] - d[j]) for j in range(M)]) + 1

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

student = [  tuple( map(int, input().split()) ) for x in range(N)]
point = [ tuple( map(int, input().split()) ) for x in range(M)]


for (x1, y1) in student :
    data =  [ abs(x1 - x2) + abs(y1 - y2) for (x2, y2) in point ]
    ans = data.index(min(data))
    print(ans + 1)

Solution (Python):
b = input().split()
a = [int(b[i]) for i in range(len(b))]

p = []

for j in range(a[0]):
  tmp = input().split()
  tmp = [int(tmp[i]) for i in range(2)]
  p.append((tmp[0], tmp[1]))

c = []

for j in range(a[1]):
  tmp = input().split()
  tmp = [int(tmp[i]) for i in range(2)]
  c.append((tmp[0], tmp[1]))

ans = []

for i in range(a[0]):
  min = (10000000000, 0)
  for j in range(a[1]):
    if(min[0] > abs(p[i][0] - c[j][0]) + abs(p[i][1] - c[j][1])):
      min = (abs(p[i][0] - c[j][0]) + abs(p[i][1] - c[j][1]), j+1)

  ans.append(min[1])

for j in range(a[0]):
  print(ans[j])

Solution (Python):
N, M = map(int, input().split(" "))
 
student = [];
pos = [];
for i in range(N) :
	a, b = map(int, input().split(" "))
	student.append((a, b))
 
for i in range(M) :
	a, b = map(int, input().split(" "))
	pos.append((a,b))
 
for st in student :
	ans = -1;
	score = 10**10;
	for i in range(M) :
		tmpscore = abs(st[0] - pos[i][0]) + abs(st[1] - pos[i][1])
		if score > tmpscore :
			score = tmpscore;
			ans = i;
	print(ans+1);

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

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

a = []
b = []

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

c = []
d = []

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

for i in range(n):
    tmp = abs(a[i] - c[0]) + abs(b[i] - d[0])
    s = 1
    for j in range(m):
        tmp3 = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if tmp3 < tmp:
            tmp = tmp3
            s = j + 1
    print(s)

Solution (Python):
N,M = list(map(int, input().split()))
a = [0]*N
b = [0]*N
c = [0]*M
d = [0]*M
for k in range(N):
     a[k],b[k] = list(map(int, input().split()))
for l in range(M):
     c[l],d[l] = list(map(int, input().split()))

for i in range(N):
    s=10**9
    for j in range(M):
        if  s>abs(a[i]-c[j])+abs(b[i]-d[j]):
             s=abs(a[i]-c[j])+abs(b[i]-d[j])
             e=j+1
    print(e)

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

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

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

def calc_dst(n, m):
    return abs(a[n]-c[m]) + abs(b[n]-d[m])

for n in range(N):
    nearest_id = 0
    nearest_dst = calc_dst(n, 0)
    for m in range(1, M):
        dst = calc_dst(n, m)
        if nearest_dst > dst:
            nearest_id = m
            nearest_dst = dst

    print(nearest_id + 1)

Solution (Python):
x = list(map(int, input().split()))

n = x[0]
m = x[1]

a = []
for i in range(0, n):
    y = list(map(int, input().split()))
    a.append([y[0],y[1]])

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

for i in range(0, n):
    s_ = 9999999999
    s = 0
    for j in range(0, m):
        t = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if t < s_:
            s_ = t
            s = j + 1
    print(s)

Solution (Python):
n, m = map(int, raw_input().split())
P = [map(int, raw_input().split()) for i in xrange(n)]
C = [map(int, raw_input().split()) for i in xrange(m)]
for a, b in P:
    idx = -1; mi = ()
    for i, (c, d) in enumerate(C):
        di = abs(a-c) + abs(b-d)
        if di < mi:
            mi = di
            idx = i
    print idx+1

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

for i in range(m):
    check.append(list(map(int, input().split())))


ans = []

for i in range(n):
    dist = []
    for j in range(m):
        tmp = abs(stu[i][0] - check[j][0]) + abs(stu[i][1] - check[j][1])
        dist.append(tmp)
    mi = dist.index(min(dist))
    ans.append(mi)


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

Solution (Python):
n, m = map(int, input().split())
s = []
d = []
for i in range(n):
    x, y = map(int, input().split())
    s.append([x, y])
for i in range(m):
    x, y = map(int, input().split())
    d.append([x, y])
for i in s:
    a = 1
    c = abs(i[0] - d[0][0]) + abs(i[1] - d[0][1])
    for j in range(1, m):
        c_t = abs(i[0] - d[j][0]) + abs(i[1] - d[j][1])
        if c_t < c:
            c = min(c, c_t)
            a = j + 1
    print(a)

Solution (Python):
import sys, math

n,m = [int(x) for x in sys.stdin.readline().split()]

def LI(): return [int(x) for x in sys.stdin.readline().split()]

s = [LI() for _ in range(n)]
p = [LI() for _ in range(m)]

def manhattan(a,b):
	return math.fabs(a[0]-b[0]) + math.fabs(a[1]-b[1])

def nearest(a):
	r = 1
	d = manhattan(a,p[0])
	for (i,x) in enumerate(p):
		pd = manhattan(a,x)
		if pd<d:
			r = i+1
			d = pd
	return r

for (i,x) in enumerate(s):
	print(nearest(x))

Solution (Python):
a = list(map(int,input().split(" ")))
b = list()
c = list()
ans = list()

for i in range(a[0]):
    b.append(list(map(int,input().split(" "))))

for i in range(a[1]):
    c.append(list(map(int,input().split(" "))))

for i in range(a[0]):
    d = 0
    e = 9999999999
    for ii in range(a[1]):
        if e > abs(b[i][0] - c[ii][0]) + abs(b[i][1] - c[ii][1]):
            e = abs(b[i][0] - c[ii][0]) + abs(b[i][1] - c[ii][1])
            d = ii
    ans.append(d+1)
    
for i in range(a[0]):
    print(ans[i])

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

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

for j in range(M):
    checks.append(list(map(int, input().split())))

for i in range(N):
    argMin, distMin = None, float('inf')
    for j in range(M):
        dist = abs(nodes[i][0] - checks[j][0]) + abs(nodes[i][1] - checks[j][1])
        if dist < distMin: argMin, distMin = j, dist
    print(argMin + 1)

Solution (Python):
import sys
import numpy as np

N, M = (int(i) for i in input().split(" "))
S = [input().split(" ") for i in range(N + M)]

seito = S[0:N]
check = S[N:N+M]

kyori = np.zeros(M)

for j in range(0,N):
	for i in range(0,M):
		kyori[i] = abs(int(seito[j][0]) - int(check[i][0])) + abs(int(seito[j][1]) - int(check[i][1]))
	

	num = np.argmin(kyori) + 1
	print(num)

Solution (Python):
n,m=(int(i)for i in input().split())
g=[]
t=[]
for i in range(n):
    g.append([int(i)for i in input().split()])
for i in range(m):
    t.append([int(i)for i in input().split()])
for i in range(n):
    kyr=400000001
    min=-1
    for j in range(m):
        kr=abs(g[i][0]-t[j][0])+abs(g[i][1]-t[j][1])
        if kr<kyr:
            kyr=kr
            min=j+1
    print(min)

Solution (Python):
N,M = list(map(int, input().split()))
 
s = [list(map(int,input().split())) for i in range(N)]
c = [list(map(int,input().split())) for j in range(M)]
 
for t1 in s:
    l = list(map(lambda x: abs(t1[0] - x[0]) + abs(t1[1] - x[1]), c))
    print(l.index(min(l)) + 1)

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

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

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

for t1 in s:
    l = list(map(lambda x: abs(t1[0] - x[0]) + abs(t1[1] - x[1]), c))
    print(l.index(min(l)) + 1)

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

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

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

ans = [0] * N

for i in range(N):
	mindif = 4 * 10**8 + 1
	for j in range(M):
		dif = abs(students[i][0] - checkpoints[j][0]) + abs(students[i][1] - checkpoints[j][1])
		if dif < mindif:
			mindif = dif
			ans[i] = j + 1

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

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

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

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

for s in a:
    max_d = 1e9
    cp = 0
    for k,v in enumerate(b):
        tmp_d = dis(s, v)
        if(tmp_d < max_d):
            max_d = tmp_d
            cp = k
    print(cp+1)

Solution (Python):


NM = raw_input().split()
N = int(NM[0])
M = int(NM[1])

a = []
b = []
c = []
d = []
for i in xrange(N):
    ab = raw_input().split()
    a.append(int(ab[0]))
    b.append(int(ab[1]))

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

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

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

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

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

def manhattan(n, m):
    return abs(A[n]-C[m]) + abs(B[n]-D[m])


for n in range(N):
    ind = 0
    dis = manhattan(n, 0)
    for m in range(M):
        dis_m = manhattan(n, m)
        if dis > dis_m:
            ind = m
            dis = dis_m
    print(ind+1)

Solution (Python):

import sys

def myabs(a):
    return a if a >= 0 else -a

def dist(x1, y1, x2, y2):
    return myabs(x1-x2) + myabs(y1-y2)

def calc(people_points, check_points):
    ans = []

    
    for x_p, y_p in people_points:
        dists = [ dist(x_p, y_p, check_point[0], check_point[1]) for check_point in check_points ]
        ans_ind, ans_dist = sorted(list(enumerate(dists)), key=lambda tpl:tpl[1])[0]
        ans_tpl = (ans_ind, ans_dist)
        ans.append(ans_tpl)


    return ans

def main():
    n_m = sys.stdin.readline().split()
    n = int(n_m[0])
    m = int(n_m[1])

    people_points = []
    check_points = []

    for i in range(n):
        a_b = sys.stdin.readline().split()
        a = int(a_b[0])
        b = int(a_b[1])
        people_points.append((a, b))

    for i in range(m):
        c_d = sys.stdin.readline().split()
        c = int(c_d[0])
        d = int(c_d[1])
        check_points.append((c, d))

    ans = [ind + 1 for ind, dist in calc(people_points, check_points)]
    print("\n".join([str(i) for i in ans]))

    return 0

if __name__ == '__main__':
    sys.exit(main())

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

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

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


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

Solution (Python):


n, m = map(int, input().split())
persons = []
checks = []
for i in range(n):
    point = tuple(map(int, input().split()))
    persons.append(point)
for i in range(m):
    point = tuple(map(int, input().split()))
    checks.append(point)



    
def get_distance(person, check):
    return abs(person[0] - check[0]) + abs(person[1] - check[1])
    
for i in range(n):
    min_distance = 10 ** 10
    min_distance_point_num = -1

    
    for j in range(m):
        distance = get_distance(persons[i], checks[j])
        if distance < min_distance:
            min_distance = distance
            min_distance_point_num = j + 1

    print(min_distance_point_num)

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

A=[]
B=[]
C=[]
D=[]


for _ in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
    
for _ in range(M):
    c,d=map(int,input().split())
    C.append(c)
    D.append(d)
     
for i in range(N):
        L=[]
        for j in range(M):
            K=abs(A[i]-C[j])+abs(B[i]-D[j])  
            L.append(K)  
        next
        P=L.index(min(L))
        print(P+1)

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

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

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

m = []
for i in range(N):
    mdis = distance(i,0)
    mn = 0+1
    for j in range(1,M):
        if(mdis > distance(i,j)):
            mdis = distance(i,j)
            mn = j+1

    m.append(mn)

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

Solution (Python):

import numpy as np
n, m = map(int, input().split())
student = np.zeros([n,2])
check_point = np.zeros([m,2])
res = np.ones([n,m])
for i in range(n):
    student[i,0], student[i,1] = map(int, input().split())
for i in range(m):
    check_point[i,0], check_point[i,1] = map(int, input().split())
    res[:,i] = abs(student[:,0]-check_point[i,0])+abs(student[:,1]-check_point[i,1])
for i in range(n):
    print(np.argmin(res[i,:])+1)

Solution (Python):

import numpy as np
import math

N,M = map(int, raw_input().split())
a = np.zeros(N,dtype='int')
b = np.zeros(N,dtype='int')
c = np.zeros(M,dtype='int')
d = np.zeros(M,dtype='int')
for i in range(N):
    a[i],b[i] = map(int, raw_input().split())
for i in range(M):
    c[i],d[i] = map(int, raw_input().split())
    
for i in range(N):
    MinDist = 999999999
    CheckPoint = -1
    for j in range(M):
        ManhattanDist = math.fabs(a[i]-c[j])+math.fabs(b[i]-d[j])
        if(MinDist>ManhattanDist):
            MinDist = ManhattanDist
            CheckPoint = j+1
    print(CheckPoint)

Solution (Python):
import math

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

a,b,c,d,L=[],[],[],[],[]
for i in range(N):
    f,g=map(int,input().split())
    a.append(f)
    b.append(g)

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

for i in range(N):
    L.clear()
    for j in range(M):
        L.append(int(math.fabs(a[i]-c[j])+math.fabs(b[i]-d[j])))
    for k in range(M):
        if L[k]==min(L):
            print(k+1)
            break

Solution (Python):
(n, m) = [int(x) for x in input().split(' ')]
a = []
b = []
for i in range(n):
  s = input().split(' ')
  a.append(int(s[0]))
  b.append(int(s[1]))
c = []
d = []
for j in range(m):
  s = input().split(' ')
  c.append(int(s[0]))
  d.append(int(s[1]))

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

Solution (Python):
def mDistance(a, b):
    axisDist = [abs(x0 - x1) for x0, x1 in zip(a, b)]
    return(sum(axisDist))


N, M = map(int, input().split())
An, Am = ([], [])

while len(An) < N:
    An.append(tuple(map(int, input().split())))

while len(Am) < M:
    Am.append(tuple(map(int, input().split())))

for a in An:
    B = map(lambda b: mDistance(a, b), Am)
    I, _ = min(enumerate(list(B)), key=lambda b: b[1])
    print(I + 1)

Solution (Python):

import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

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

for i, (a, b) in enumerate(ab):
    mn = 1e10
    p = -1
    for j, (c, d) in enumerate(cd, 1):
        tmp = abs(a - c) + abs(b - d)
        if tmp < mn:
            mn = tmp
            p = j
    print p

Solution (Python):

"""
Created on Wed Apr  5 11:25:59 2017

@author: syaga
"""
import math


def getMan(x, y):
    man = math.fabs(x[0]-y[0])+math.fabs(x[1]-y[1])
    return man

if __name__ == "__main__":
    student = []
    check = []
    answer = []
    N, M = list(map(int, input().split()))
    for i in range(N):
        student.append(list(map(int, input().split())))
    for i in range(M):
        check.append(list(map(int, input().split())))
    for i in student:
        min_tmp = 1000000000000000000
        min_index = 0
        for j in check:
            man = getMan(i, j)
            if min_tmp > man:
                min_tmp = man
                min_index = check.index(j)+1
        answer.append(min_index)
    for i in answer:
        print(i)

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 sx, sy in students:
    mindist = 10 ** 9
    num = 0
    for i in range(M):
        cx, cy = checkpoints[i]
        dist = abs(sx-cx) + abs(sy-cy)
        if mindist > dist:
            mindist = dist
            num = i
    print(num+1)

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

stu = []
for _ in range(n):
    stu.append((map(int, raw_input().split())))

che = []
for _ in range(m):
    che.append((map(int, raw_input().split())))


for st in range(n):
    min_dis = float("inf")
    idx = -1
    for ch in range(m):
        dist = abs(stu[st][0] - che[ch][0]) + abs(stu[st][1] - che[ch][1])
        if dist < min_dis:
            min_dis = dist
            idx = ch
    print idx + 1

Solution (Python):
import math

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

    def distanceTo(self, point):
        dist = math.fabs(self.x - point.x) + math.fabs(self.y - point.y)
        return dist

students = []
checkpoints = []

N, M = map(int, raw_input().split(" "))
for i in range(0, N):
    x, y = map(int, raw_input().split(" "))
    students.append(Point(x, y))

for i in range(0, M):
    x, y = map(int, raw_input().split(" "))
    checkpoints.append(Point(x, y))


for student in students:
    minDist = 1000000000
    minIndex = 0
    for i in range(0, M):
        dist = student.distanceTo(checkpoints[i])
        if dist < minDist:
            minDist = dist
            minIndex = i
    print minIndex + 1