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



Sample input:
2 2
2 0
0 0
-1 0
1 0


Sample output:
2
1

Submission status: Accepted

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

for x1 in ab:
    min_dist = 10**10
    min_idx = 0
    for idx,x2 in enumerate(cd):
        dist = abs(x1[0]-x2[0]) + abs(x1[1]-x2[1])
        if dist < min_dist:
            min_dist = dist
            min_idx = idx
    
    print(min_idx+1)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
ab = [[int(i) for i in input().split()] for _ in range(N)]
cd = [[int(i) for i in input().split()] for _ in range(M)]
 
for a,b in ab:
    num = 0
    d = 10**10
    for i in range(M):
        if abs(a-cd[i][0])+abs(b-cd[i][1])<d:
            num = i+1
            d = abs(a-cd[i][0])+abs(b-cd[i][1])
    print(num)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
o,p,q,r=[],[],[],[]
def kyori(a,b,c,d):return abs(a-c)+abs(b-d)
for i in range(n):
  a,b=map(int,input().split())
  o.append(a)
  p.append(b)
for i in range(m):
  a,b=map(int,input().split())
  q.append(a)
  r.append(b)
for i in range(n):
  mind=kyori(o[i],p[i],q[0],r[0])
  minn=1
  for j in range(m-1):
    a=kyori(o[i],p[i],q[j+1],r[j+1])
    if a<mind:
      mind=a
      minn=j+2
  print(minn)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
y = [list(map(int,input().split())) for i in range(m)]
for i in range(n):
    res = 10**9+7
    ans = 0
    for j in range(m):
        temp = abs(x[i][0]-y[j][0])+abs(x[i][1]-y[j][1])
        if temp<res:
            res = temp
            ans = j+1
    print(ans)

Submission status: Accepted

Solution code:
N, M =map(int, input().split())
ab = list(list(map(int ,input().split())) for _ in range(N))
cd = list(list(map(int ,input().split())) for _ in range(M))

lst = [ [0] * M for _ in range(N)] 
for i in range(N):
    for j in range(M):
        lst[i][j] = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])

for i in range(N):
    print(lst[i].index(min(lst[i])) + 1)

Submission status: Accepted

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

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

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

mini = [3*10**8]*n
index = [0]*n

for i in range(n):
    for j in range(m):
        dist = abs(stu[i][0]-check[j][0]) + abs(stu[i][1]-check[j][1])
        if dist < mini[i]:
            mini[i] = dist
            index[i] = j+1
    
    
            
for i in index:
    print(i)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
stu=[]
che=[]
for i in range(N):
    stu.append(list(map(int,input().split())))
for j in range(M):
    che.append(list(map(int,input().split())))
for i in range(N):
    l=abs(stu[i][0]-che[0][0])+abs(stu[i][1]-che[0][1])
    n=0
    for j in range(1,M):
        ll=abs(stu[i][0]-che[j][0])+abs(stu[i][1]-che[j][1])
        if l>ll:
            l=ll
            n=j
    print(n+1)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
sutdent = []
point = []
INF = float("inf")
anss = []
for i in range(N):
    a,b = map(int,input().split())
    sutdent.append((a,b))
for i in range(M):
    c,d = map(int,input().split())
    point.append((c,d))
for a,b in sutdent:
    ans = INF
    index = 0
    for num,(c,d) in enumerate(point):
        count = abs(a-c)+abs(b-d)
        if count<ans:
            ans=count
            index = num+1
    anss.append(index)
for a in anss:
    print(a)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l1=[]
l2=[]
for i in range(n):
  l1.append(list(map(int,input().split())))
for i in range(m):
  l2.append(list(map(int,input().split())))
for i in range(n):
  l=abs(l1[i][0]-l2[0][0])+abs(l1[i][1]-l2[0][1])
  n=0
  for j in range(1,m):
    if l>abs(l1[i][0]-l2[j][0])+abs(l1[i][1]-l2[j][1]):
      l=abs(l1[i][0]-l2[j][0])+abs(l1[i][1]-l2[j][1])
      n=j
    else:
      pass
  print(n+1)

Submission status: Accepted

Solution code:
import numpy as np


N, M = list(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 s in students:
    measure = []
    for c in checkpoints:
        tmp = abs(c[0]-s[0]) + abs(c[1]-s[1])
        measure.append(tmp)
    print(np.argmin(measure) + 1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a_b=[list(map(int,input().split())) for _ in range(n)]
c_d=[list(map(int,input().split())) for _ in range(m)]
for i in range(n):
  res=1
  d=abs(a_b[i][0]-c_d[0][0])+abs(a_b[i][1]-c_d[0][1])
  for j in range(1,m):
    t=abs(a_b[i][0]-c_d[j][0])+abs(a_b[i][1]-c_d[j][1])
    if t<d:
      d=t
      res=j+1
  print(res)

Submission status: Accepted

Solution code:
def main():
    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)]
    for a, b in S:
        dist = float("inf")
        ans = 0
        for i in range(M):
            c, d = C[i]
            x = abs(a-c) + abs(b-d)
            if x < dist:
                ans = i+1
                dist = x
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
stu = []
cha = []
for _ in range(N):
    a,b = map(int,input().split())
    stu.append([a,b])
for _ in range(M):
    a,b = map(int,input().split())
    cha.append([a,b])
for s in stu:
    ch = 0
    min_d = 1000000000
    for i,c in enumerate(cha):
        d = abs(s[0] - c[0]) + abs(s[1] - c[1])
        if d < min_d:
            ch = i
            min_d = d
    print(ch+1)

Submission status: Accepted

Solution code:
N,M=map(int,input().split(' '))
S = [list(map(int,input().split(' '))) for i in range(N)]
C = [list(map(int,input().split(' '))) for i in range(M)]
for i in range(N):
  l = [abs(S[i][0]-C[j][0])+abs(S[i][1]-C[j][1]) for j in range(M)]
  print(l.index(min(l))+1)

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())

rem = pow(10,9)+7

#n = ip()                                     #入力整数1つ
x,y= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[input() for i in range(x)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
sa = []
for  i in range(x):
    sa.append([int(i) for i in input().split()])
sb = []
for  i in range(y):
    sb.append([int(i) for i in input().split()])
for i in range(x):
    s = []
    for k in range(y):
        s.append(abs(sa[i][0]-sb[k][0]) + abs(sa[i][1] - sb[k][1]))
    print(s.index(min(s))+1)

Submission status: Accepted

Solution code:
(n,m),*a=[list(map(int,s.split()))for s in open(0).readlines(0)]
for i,j in a[:n]:l=[abs(x-i)+abs(y-j)for x,y in a[n:]];print(1+l.index(min(l)))

Submission status: Accepted

Solution code:

(n,m),*a=[list(map(int,s.split()))for s in open(0).readlines(0)]
for i,j in a[:n]:l=[abs(x-i)+abs(y-j)for x,y in a[n:]];print(1+l.index(min(l)))

Submission status: Accepted

Solution code:
from numpy import*;(n,m),*a=[list(map(int,s.split()))for s in open(0).readlines(0)]
for i,j in a[:n]:print(1+argmin([abs(x-i)+abs(y-j)for x,y in a[n:]]))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
students=[tuple(map(int,input().split())) for i in range(N)]
point=[tuple(map(int,input().split())) for i in range(M)]
inf=float('inf')
for n in students:
    ans=0
    Min=inf
    for j in range(M):
        if abs(n[0]-point[j][0])+abs(n[1]-point[j][1])<Min:
            ans=j+1
            Min=abs(n[0]-point[j][0])+abs(n[1]-point[j][1])
    print(ans)

Submission status: Accepted

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

s = []
t = []

for i in range(n):
    for j in range(m):
        s.append(abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]))
    t.append(s.index(min(s)) + 1)
    s = []

for i in range(len(t)):
    print(t[i])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
ans = [0] * n
det = [400000001]*n
for i in range(m):
    c, d = map(int, input().split())
    for p in range(n):
        dif = abs(c-x[p][0])+abs(d-x[p][1])
        if det[p] > dif:
            ans[p] = i
            det[p] = dif
for i in ans:
    print(i+1)

Submission status: Accepted

Solution code:
N, M = [ int(x) for x in input().split() ]
ab_s = [ [ int(x) for x in input().split() ] for _ in range(N) ]
cds = [ [ int(x) for x in input().split() ] for _ in range(M) ]

ans = []
for i in range(N):
    a, b = ab_s[i]
    r = -1
    d_min = -1
    for j in range(M):
        c, d = cds[j]
        distance = abs(a - c) + abs(b - d)
        if d_min < 0 or d_min > distance:
            r = j
            d_min = distance
    ans.append(r + 1)

print("\n".join(map(str, ans)))

Submission status: Accepted

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

for a, b in ab:
    ans = 1
    d = abs(a - cd[0][0]) + abs(b - cd[0][1])
    for i in range(1, m):
        temp_d = abs(a - cd[i][0]) + abs(b - cd[i][1])
        if temp_d < d:
            d = temp_d
            ans = i + 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
A = []
B = []
C = []
D = []
for x in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
for y in range(m):
    c,d = map(int,input().split())
    C.append(c)
    D.append(d)
for i in range(n):
    d = []
    for j in range(m):
        d.append(abs(A[i]-C[j])+abs(B[i]-D[j]))
    print(d.index(min(d))+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
student=[]
check=[]
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())
    check.append([a,b])
for i in student:
    minimam=10**10
    point=0
    for j in range(m):
        if abs(i[0]-check[j][0])+abs(i[1]-check[j][1]) < minimam:
            minimam=abs(i[0]-check[j][0])+abs(i[1]-check[j][1])
            point = j+1
    print(point)

Submission status: Accepted

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

check = [[] for i in range(m)]
for i in range(n):
    for j in range(m):
        check[j] = abs(a[i]-c[j])+abs(b[i]-d[j])
    print(check.index(min(check))+1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
student = [list(map(int, input().split())) for _ in range(N)]
chpoint = [list(map(int, input().split())) for _ in range(M)]
ans = []
for i in range(N):
    mdisstance_tmp = float('inf')
    ans_tmp = 0
    for j in range(M):
        mdistance = abs(student[i][0]-chpoint[j][0])+abs(student[i][1]-chpoint[j][1])
        if mdisstance_tmp > mdistance:
            mdisstance_tmp = mdistance
            ans_tmp = j+1
    ans.append(ans_tmp)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
Students = [tuple(map(int, input().split())) for i in range(n)]
CheckPoints = [tuple([i] + list(map(int, input().split()))) for i in range(m)]

for student in Students:
    ManhattanDistanceList = []
    for point in CheckPoints:
        sx, sy = student
        px, py = point[1], point[2]
        ManhattanDistanceList.append(
            tuple([point[0], abs(sx - px) + abs(sy - py)]))
    ManhattanDistanceList.sort(key=lambda x: x[1])
    print(ManhattanDistanceList[0][0]+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=[int(i) for i in input().split()]
ab=[]
cd=[]
for i in range(n):
    a,b=[int(j) for j in input().split()]
    ab.append((a,b))

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

for i in range(n):
    mini=10000000000000000
    for j in range(m):
        dis=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if mini>dis:
            mini=dis
            point=j+1
    print(point)

Submission status: Accepted

Solution code:
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 sx,sy in ab:
    dist_min = float('inf')
    num_min = -1
    for i in range(M):
        tmp = abs(sx-cd[i][0]) + abs(sy-cd[i][1])
        if dist_min > tmp:
            num_min = i + 1
            dist_min = tmp
    print(num_min)

Submission status: Accepted

Solution code:
""" AtCoder """

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

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = []
B = []
C = []
D = []
check = []

def Manhattan(a,b,c,d):
  distant = abs(a-c)+abs(b-d)
  return distant

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

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

  
for i in range(N):
  for j in range(M):
   if(j == 0):
    min = Manhattan(A[i],B[i],C[j],D[j])
    check.append(j+1)
   else:
    tmp = Manhattan(A[i],B[i],C[j],D[j])
    if(min > tmp):
      min = tmp
      check[i] = j+1
  print(check[i])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
a = []
b = []
c = []
d = []
for i in range(N+M):
    x,y = map(int,input().split())
    if i<N:
        a.append(x)
        b.append(y)
    else:
        c.append(x)
        d.append(y)
for i in range(N):
    min_man = 10**10
    min_j = 0
    for j in range(M):
        man = abs(a[i]-c[j])+abs(b[i]-d[j])
        if min_man > man:
            min_man = man
            min_j = j
    print(min_j+1)

Submission status: Accepted

Solution code:
# coding: utf-8
N, M = map(int, input().split())
st = [list(map(int, input().split())) for _ in range(N)]
ch = [list(map(int, input().split())) for _ in range(M)]
for i, j in st:
    min = float('inf')
    min_num = 0
    for num, xy in enumerate(ch):
        if abs(i - xy[0]) + abs(j - xy[1]) < min:
            min = abs(i - xy[0]) + abs(j - xy[1])
            min_num = num + 1
    print(min_num)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
coord_student = [list(map(int,input().split())) for i in range(n)]
coord_check =  [list(map(int,input().split())) for i in range(m)]

for stu in range(n):
  ans = float("inf")
  for che in range(m):
    tmp_ans = abs(coord_student[stu][0]-coord_check[che][0])+abs(coord_student[stu][1]-coord_check[che][1])
    if tmp_ans < ans:
      ans = tmp_ans
      index = che
  print(index+1)

Submission status: Accepted

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

for i in range(N):
    point = 1
    min_dst = 1e20
    for j in range(M):
        dst = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if dst < min_dst:
            min_dst = dst
            point = j+1
    print(point)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
aa = [0] * n
bb = [0] * n
cc = [0] * m
dd = [0] * m

for i in range(n):
    aa[i], bb[i] = map(int, input().split())
for i in range(m):
    cc[i], dd[i] = map(int, input().split())

for i in range(n):
    d = [abs(aa[i] - cc[j]) + abs(bb[i] - dd[j]) for j in range(m)]
    print(d.index(min(d))+1)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
L = []
ans = 0
for i in range(N):
  L.append(list(map(int,input().split())))
K = []
for i in range(M):
  K.append(list(map(int,input().split())))
for j in range(N):
  S = float('inf')
  ans = 0
  for k in range(M):
    if abs(L[j][0]-K[k][0])+abs(L[j][1]-K[k][1]) < S:
      S = abs(L[j][0]-K[k][0])+abs(L[j][1]-K[k][1])
      ans = k+1 
  print(ans)

Submission status: Accepted

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

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

for i in range(n):
    min=19**9+1
    arg=1
    for j in range(m):
        if min > abs(a[i]-c[j])+abs(b[i]-d[j]):
            min = abs(a[i]-c[j])+abs(b[i]-d[j])
            arg = j+1
    print(arg)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
AB = [[int(i) for i in input().split()] for i in range(n)]
CD = [[int(i) for i in input().split()] for i in range(m)]

for a, b in AB:
    dist = 10 ** 12
    for i, cd in enumerate(CD):
        tmp = abs(a - cd[0]) + abs(b - cd[1])
        if tmp < dist:
            dist = tmp
            ans = i + 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
  ans = -1
  for j in range(M):
    if ans==-1 or abs(a[i]-c[j])+abs(b[i]-d[j]) < abs(a[i]-c[ans])+abs(b[i]-d[ans]):
      ans = j
  print ans+1

Submission status: Accepted

Solution code:
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)]

result = []
for a, b in AB:
  tmp = []
  for c, d in CD:
    tmp.append(abs(a-c) + abs(b-d))
  result.append(tmp.index(min(tmp))+1)
for r in result:
  print(r)

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def calc_distance(s, p):
    x, y = s
    x_, y_ = p

    return abs(x - x_) + abs(y - y_)


def main():
    N, M = li_input()
    S = [li_input() for _ in range(N)]
    P = [li_input() for _ in range(M)]

    for s in S:
        ans_d = -1
        ans_i = -1
        for i, p in enumerate(P, start=1):
            d = calc_distance(s, p)

            if ans_d == -1 or d < ans_d:
                ans_d = d
                ans_i = i
        
        print(ans_i)

main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
B = []
C = []
D = []

for _ in [0]*N:
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

for _ in [0]*M:
    c, d = map(int, input().split())
    C.append(c)
    D.append(d)

for i in range(N):
    ans = [300000000, 0]
    for j in range(M):
        s = abs(A[i] - C[j]) + abs(B[i] - D[j])
        if ans[0] > s:
            ans = [s, j+1]
    print(ans[1])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
h=[]
p=[]
def man(a,c,b,d):
    s=abs(a-c)+abs(b-d)
    return s
for i in range(n):
    h.append(list(map(int,input().split())))
for j in range(m):
    p.append(list(map(int,input().split())))
for k in range(n):
    l=float("inf")
    for v in range(m):
        x=man(h[k][0],p[v][0],h[k][1],p[v][1])
        if x<l:
            l=x
            y=v+1
    print(y)

Submission status: Accepted

Solution code:
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):
    mnh=0
    tmp=100000000000000000000
    ans=0
    for j  in range(m):
        mnh=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if tmp>mnh:
            tmp=mnh
            ans=j+1
    print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [tuple(map(int, input().split())) for i in range(n)]
b = [0] + [tuple(map(int, input().split())) for i in range(m)]

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

for i in range(n):
    c = 1
    t = d(a[i], b[1])
    for j in range(2, m+1):
        if d(a[i], b[j]) < t:
            c = j
            t = d(a[i], b[j])
    print(c)

Submission status: Accepted

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

for a, b in ab:
    dist = 10 ** 9
    for i, (c, d) in enumerate(cd, 1):
        tmp = abs(a - c) + abs(b - d)
        if tmp < dist:
            dist = tmp
            ans = i
    print(ans)

Submission status: Accepted

Solution code:
INF = 1000000007

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

ab = []

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

cd = []

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

for i in range(N):
    ans = 0
    dst = INF
    for j in range(M):
        tmp = abs(cd[j][0] - ab[i][0]) + abs(cd[j][1] - ab[i][1])

        if tmp < dst:
            # 0-indexed
            dst = tmp
            ans = j + 1

    print(ans)

Submission status: Accepted

Solution code:
def gcd(A, B, C, D):
	l, L = A-C, B-D
	if l<0:
		l = l*(-1)
	if L<0:
		L = L*(-1)
	return l+L
	
N, M = map(int, input().split())
x = []
y = []
n = 0
m = 0
ans = 1
for i in range(N):
	x1, y1 = map(int, input().split())
	x.append(x1)
	y.append(y1)
X = []
Y = []
for l in range(M):
	x2, y2 = map(int, input().split())
	X.append(x2)
	Y.append(y2)
for a in range(N):
	m = gcd(x[a], y[a], X[0], Y[0])
	for b in range(M):
		n = gcd(x[a], y[a], X[b], Y[b])
		if n < m:
			m = n
			ans = b+1
	print(ans)
	ans = 1

Submission status: Accepted

Solution code:
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):
  man=1000000000
  ans=0
  for j in range(m):
    if abs(A[i][0]-B[j][0])+abs(A[i][1]-B[j][1])<man:
      man=abs(A[i][0]-B[j][0])+abs(A[i][1]-B[j][1])
      ans=j+1
  print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
L1,L2,L3=[],[],[]
for s in range(n):
  L1.append(list(map(int,input().split())))
for s in range(m):
  L2.append(list(map(int,input().split())))
for x in L1:
  L3=[]
  for y in L2:
    L3.append(abs(x[0]-y[0])+abs(x[1]-y[1]))
  print(L3.index(min(L3))+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a,b,c,d=[],[],[],[]
for i in range(n):
    o = list(map(int, input().split()))
    a.append(o[0])
    b.append(o[1])
for i in range(m):
    o = list(map(int, input().split()))
    c.append(o[0])
    d.append(o[1])
s = []
for i in range(n):
    g = float('inf')
    h = 0
    for j in range(m):
        if g > abs(a[i]-c[j])+abs(b[i]-d[j]):
            g = abs(a[i]-c[j])+abs(b[i]-d[j])
            h = j+1
    s.append(h)
for i in s:
    print(i)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
AB = [[int(i) for i in input().split()] for i in range(n)]
CD = [[int(i) for i in input().split()] for i in range(m)]

for ab in AB:
    dist = [abs(ab[0] - cd[0]) + abs(ab[1] - cd[1]) for cd in CD]
    print(dist.index(min(dist)) + 1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
AB = [[int(i) for i in input().split()] for i in range(n)]
CD = [[int(i) for i in input().split()] for i in range(m)]

for ab in AB:
    ans = 10 ** 12
    id = 0
    for i, cd in enumerate(CD):
        tmp = abs(ab[0] - cd[0]) + abs(ab[1] - cd[1])
        if tmp < ans:
            ans = tmp
            id = i + 1
    print(id)

Submission status: Accepted

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

for student in students:
    dist = []
    for checkpoint in checkpoints:
        dist.append(abs(student[0] - checkpoint[0]) + abs(student[1] - checkpoint[1]))
    print(dist.index(min(dist)) + 1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
AB = [[int(i) for i in input().split()] for j in range(n)]
CD = [[int(k) for k in input().split()] for l in range(m)]

ans = [0]*n
for ab in AB:
    a,b = ab[0],ab[1]
    distance = 1000000000
    for cd in CD:
        c,d = cd[0], cd[1]
        if distance > abs(a-c) + abs(b-d):
            distance = abs(a-c) + abs(b-d)
            ans[AB.index(ab)] = CD.index(cd)+1
        
for _ in ans:
    print(_)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
stu,kyo = [],[]
for i in range(n):
    stu.append(list(map(int,input().split())))
for i in range(m):
    kyo.append(list(map(int,input().split())))
for i in range(n):
    ans = []
    for j in range(m):
        ans.append(abs(stu[i][0]-kyo[j][0])+abs(stu[i][1]-kyo[j][1]))
    print(1+ans.index(min(ans)))