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: Runtime Error

Solution code:
m,n = map(int,input().split())#m学生 nチェックポイント
student = []
checkpoint = []
for i in range(n):
    student.append(list(map(int,input().split())))
for i in range(m):
    checkpoint.append(list(map(int,input().split())))

for i in range(m):
    ans = 0 #答えの初期化
    tmp = 10000000000000
    for j in range(m):
        if tmp < abs(student[i][0] - checkpoint[i][0]) + abs(student[i][1] - checkpoint[i][1]):
            ans = i
            tmp = abs(student[i][0] - checkpoint[i][0]) + abs(student[i][1] - checkpoint[i][1])
    print(ans+1)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
student=[list(map(int,input().split())) for i in range(n)]
point=[list(map(int,input().split())) for i in range(n)]
for a,b in student:
  length=10**10
  pn=0
  for j in range(m):
    c,d=point[j]
    if abs(a-c)+abs(b-d)<length:
      length=abs(a-c)+abs(b-d)
      pn=1+j
  print(pn)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
student=[list(map(int,input().split())) for i in range(n)]
point=[list(map(int,input().split())) for i in range(n)]
for a,b in student:
  length=10**10
  pn=0
  for j in range(m):
    c,d=point[j]
    if abs(a-c)+abs(b-d)<length:
      length=abs(a-c)+abs(b-d)
      pn+=1
  print(pn)

Submission status: Runtime Error

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

student = []

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

point = []

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

for a, b in student:
    length = 10 ** 10
    pn = 0
    for j in range(m):
        c, d = point[j]
        if abs(a-c) + abs(b-d) < length:
            length = abs(a-c) + abs(b-d)
            pn = j + 1
    print(pn)

Submission status: Runtime Error

Solution code:
a

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

n,m=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n)]
cd=[tuple(map(int,input().split())) for i in range(m)]
for a,b in ab:
    tmp=inf
    candi=0
    for j in range(n):
        c=cd[j][0]
        d=cd[j][1]
        k=abs(a-c)+abs(b-d)
        if tmp>k:
            tmp=k
            candi=j
    print(candi+1)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
std = [list(map(int,input().split())) for i in range(n)]
chk = [list(map(int,input().split())) for i in range(m)]
for s in std:
  print(min(lambda i:abs(s[0]-chk[i][0])+abs(s[1]-chk[i][1])))

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

Solution code:
import math

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

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

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

  """
1 2
2 0
-1 0
1 0
  """

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
struct node
{
    ll x,y;
} a[N],b[N];
ll d(node c,node d)
{
    return abs(c.x-d.x)+abs(c.y-d.y);
}
int main()
{
    std::ios::sync_with_stdio(false);
    int n,m;
    while(cin>>n>>m)
    {
        for(int i=1; i<=n; i++)
        {
            cin>>a[i].x>>a[i].y;
        }
        for(int i=1; i<=m; i++)
        {
            cin>>b[i].x>>b[i].y;
        }
        for(int i=1; i<=n; i++)
        {
            ll dis=1e18,p=0;
            for(int j=1; j<=m; j++)
            {
                if(d(a[i],b[j])<dis)
                {
                    dis=d(a[i],b[j]);
                    p=j;
                }
            }
            cout<<p<<endl;
        }
    }
    return 0;
}

Submission status: Runtime Error

Solution code:
# ABC 057: B – Checkpoints
n, m = [int(s) for s in input().split()]

a = []
b = []

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

c = []
d = []

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

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

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
S = [list(map(int,input().split())) for i in range(a)]
CP = [list(map(int,input().split())) for i in range(a)]


for s in S:
  count = 0
  ab = 10**8
  p = 10**8
  for cp in CP:
    total = abs(s[0]-cp[0]) + abs(s[1]-cp[1])
    count +=1
    if ab > total:
      ab = total
      p = count
  print(p)

Submission status: Runtime Error

Solution code:

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

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for(int i = 0; i < (int)n; ++i)
int main()
{
    int N, M;
    scanf("%d %d", &N, &M);
    int a[N], b[N];
    REP(i, N) scanf("%d %d", &a[i], &b[i]);
    int c[M], d[M];
    REP(i, M) scanf("%d %d", &c[i], &d[i]);
    REP(i, N) {
        int res = -1;
        int dis = 1e9;
        REP(j, M) {
            int tmp = abs(c[j] - a[i]) + abs(d[j] - b[i]);
            if(tmp < dis) dis = tmp, res = j + 1;
        }
        printf("%d\n", res);
    }
    return 0;
}

Submission status: Runtime Error

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

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

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

for n in range(N):
  man=200000001
  for m in range(M):
    dis=abs(student[n][0]-check[m][0])+abs(student[n][1]-check[m][1])
    point=m+1
    if dis<man:
      man=dis
      ans=point
  print(ans)

Submission status: Runtime Error

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

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

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

for n in range(N):
  man=100000001
  for m in range(M):
    dis=abs(student[n][0]-check[m][0])+abs(student[n][1]-check[m][1])
    point=m+1
    if dis<man:
      man=dis
      ans=point
  print(ans)

Submission status: Runtime Error

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

AB = []

for _ in range(N):
    AB.append(list(map(int, input().split())))

CD = []

for _ in range(M):
    CD.append(list(map(int, input().split())))

for i in range(N):
    distance = 10**8+7
    for j in range(M)[::-1]:
        temp = abs(AB[i][0] - CD[j][0]) + abs(AB[i][1] - CD[j][1])
        # print(AB[i][0] - CD[j][0],AB[i][1] - CD[j][1])
        # print('temp=',temp,'j=',j)
        if temp <= distance:
            distance = temp
            ans = j+1
            # print('ans=',ans)
    print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
CD = [tuple(map(int, input().split())) for _ in range(N)]

for a, b in AB:
    ans, maxD = 0, 10 ** 10
    for i, (c, d) in enumerate(CD):
        if abs(a - c) + abs(b - d) < maxD:
            ans, maxD = i + 1, abs(a - c) + abs(b - d)
    print(ans)

Submission status: Runtime Error

Solution code:

#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N, M = ISI()
ab = [list(ISI()) for _ in range(N)]
cd = [list(ISI()) for _ in range(M)]
for i in range(N):
    min = 100
    for j in range(M):
        n = abs(ab[i][0] - cd[j][0]) +  abs(ab[i][1] - cd[j][1])
        if min > n:
            min = n
            point = j+1
    print(point)

Submission status: Runtime Error

Solution code:
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N, M = ISI()
ab = [list(ISI()) for _ in range(N)]
cd = [list(ISI()) for _ in range(M)]
for i in range(N):
    min = 100
    for j in range(M):
        n = abs(ab[i][0] - cd[j][0]) +  abs(ab[i][1] - cd[j][1])
        if min > n:
            min = n
            point = j+1
    print(point)

Submission status: Runtime Error

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

a = [0 for i in range(N)]
b = [0 for i in range(N)]
c = [0 for i in range(N)]
d = [0 for i in range(N)]

for i in range(N):
    a[i], b[i] = map(int, input().split())
for i in range(M):
    c[i], d[i] = map(int, input().split())
    
for i in range(N):
    closest_ind = -1
    closest_dist = 10000000000
    for j in range(M):
        if closest_dist > abs(a[i] - c[j]) + abs(b[i] - d[j]):
            closest_ind = j
            closest_dist = abs(a[i] - c[j]) + abs(b[i] - d[j])
    print(closest_ind + 1)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

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

# solve & output
for i in range(N):
    min_diff = 10 ** 8
    for j in range(M):
        diff = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if min_diff > diff:
            min_diff = diff
            ans = j + 1
    print(ans)

Submission status: Runtime Error

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

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

ca = []
for i in la:
    a, b = map(int, input().split())
    ca.append((a,b))

for i in range(len(la)):
    mi = 1000000001
    ans = 0
    for j in range(len(ca)):
        p = abs(la[i][0]-ca[j][0]) + abs(la[i][1]-ca[j][1])
        if  p < mi:
            mi = p
            ans = j+1
    print(ans)

Submission status: Runtime Error

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

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

ca = []
for i in la:
    a, b = map(int, input().split())
    ca.append((a,b))

for i in ca:
    mi = 1000000001
    ans = 0
    for j in range(len(ca)):
        if abs(i[0]-ca[j][0]) + abs(i[1]-ca[j][1]) < mi:
            mi = abs(i[0]-ca[j][0]) + abs(i[1]-ca[j][1])
            ans = j+1
    print(ans)

Submission status: Runtime Error

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

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

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

for i in la:
    mi = 1000000001
    ans = 0
    for k,j in enumerate(ca):
        if abs(i[0]-j[0]) + abs(i[1]-j[1]) < mi:
            mi = abs(i[0]-j[0]) + abs(i[1]-j[1])
            ans = k+1
    print(ans)

Submission status: Runtime Error

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

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

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

for i in la:
    mi = 1000000001
    ans = 0
    for k,j in enumerate(ca):
        if abs(i[0]-j[0]) + abs(i[1]-j[1]) < mi:
            mi = abs(i[0]-j[0]) + abs(i[1]-j[1])
            ans = k+1
    print(ans)

Submission status: Runtime Error

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


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

ans = []

for i in range(n):
    min_dis = 1000
    for j in range(m):

        distance = abs(c[j] - a[i]) + abs(d[j] - b[i])

        #print("学生{}, {} チェックポイント{}, {}".format(a[i], b[i], c[j], d[j]))
        #print("距離番号{} = {}".format(j, distance))
        
        if min_dis > distance:
            min_dis = distance
            min_num = j
            #print("更新")
        
    ans.append(min_num)
    
for i in range(n):
    print(ans[i] + 1)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print((a+b)%24)
    return

#B
def B():
    n, m = LI()
    ab = LIR(n)
    cd = LIR(m)
    for a, b in ab:
        ans = inf
        an = 0
        for num, cdi in cd:
            c, d = cdi
            if ans > abs(a - c) + abs(b - d):
                an = num
        print(an) 
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Runtime Error

Solution code:
def main():
    n, m = map(int, input().split())
    students = [tuple(map(int, input().split())) for i in range(n)]
    check_points = [tuple(map(int, input().split())) for i in range(m)]

    for a, b in students:
        dist = [abs(a - c) + abs(b - d) for c, d in check_points]
        print(check_points.index(min(dist) + 1))
        
    # for st in students:
    #     min_pt = check_points[0]
    #     for pt in check_points:
    #         if abs(pt[0] - st[0]) + abs(pt[1] - st[1]) < \
    #            abs(min_pt[0] - st[0]) + abs(min_pt[1] - st[1]):
    #             min_pt = pt
    #     print(check_points.index(min_pt) + 1)


if __name__ == "__main__":

    main()

Submission status: Runtime Error

Solution code:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
students = []
for _ in range(N):
    students.append([int(x) for x in stdin.readline().rstrip().split()])

checkpoints = []
for _ in range(M):
    checkpoints.append([int(x) for x in stdin.readline().rstrip().split()])

for i in students:
    tmp = 10000 
    for ind,j in enumerate(checkpoints):
        dist = abs(i[0] - j[0]) + abs(i[1] - j[1])
        if dist < tmp:
            tmp = dist
            ans = ind+1
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N, M = map(int, input().split())
A = [map(int, input().split()) for _ in range(N)]
B = [map(int, input().split()) for _ in range(M)]

for (x, y) in A:
    d = np.array([])
    for q in B:
        print("q = ", q)
        print("*q=", *q,)
        a, b = q
        d = np.append(d, abs(x-a) + abs(y-b))
    print(np.argmin(d) + 1)

Submission status: Runtime Error

Solution code:
n,m=map(int, input().split())
s=[list(map(int, input().split())) for _ in range(n)]
c=[list(map(int, input().split())) for _ in range(m)]
for a,b in s:
  k=[]
  for c,d in c:
    k.append(abs(a-c)+abs(b-d))
  print(k.index(min(k))+1)

Submission status: Runtime Error

Solution code:
import math
n,m = map(int, input().split())
dat_n = []
dat_m = []
for i in range(n):
    a,b = map(int, input().split())
    dat_n.append((a, b))
for i in range(m):
    a,b = map(int, input().split())
    dat_m.append((a, b))
for i in range(n):
    a, b = dat_n[i]
    index = -1
    distance = math.inf
    for j in range(m):
        c,d = dat_m[j]
        t = abs(a-c) + abs(b-d)
        if t < distance:
            index = j + 1
            distance = t
    print(index)

Submission status: Runtime Error

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):
    a, b = map(int, input().split())
    ans = abs(a-cd[0][0]) + abs(b-cd[0][1])
    for j in range(m):
        dif = abs(a - cd[j][0]) + abs(b - cd[j][1])
        ans = min(dif, ans)
    print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
students=[]
checks=[]
def mdistance([a,b],[c,d]):
  return abs(a-c)+abs(b-d)
for i in range(n):
  a=list(map(int,input().split()))
  students.append(a)
for i in range(m):
  checks.append(list(map(int,input().split())))
for i in range(n):
  anspoint=0
  for j in range(m):
    if mdistance(students[i],checks[j])<mdistance(students[i],checks[anspoint]):
      anspoint=j
  print(j)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

abs = [list(map(int, input().split())) for _ in range(n)]
cds = [list(map(int, input().split())) for _ in range(m)]

for a, b in abs:
  min_distance = float("inf")
  min_checkpoint = 0
  for i, cd in enumerate(cds):
    c, d = cd
    if abs(c - a) + abs(d - b) < min_checkpoint:
      min_checkpoint = i + 1
  print(min_checkpoint)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
x = [0]*n
y = [0]*n
mx = [0]*m
my = [0]*m
for i in range(n):
    x[i],y[i] = map(int,input().split())
for j in range(m):
    mx[j],my[j] = map(int,input().split())
#print(x)
#print(y)
#print(mx)
#print(my)
ans = [0]*n
#print(ans)
for k in range(n):
    dis = 1000000000
    cnt = 1
    for l in range(n):
        if abs(x[k]-mx[l])+abs(y[k]-my[l]) < dis:
            dis = abs(x[k]-mx[l])+abs(y[k]-my[l])
            cnt = l+1
    ans[k] = cnt
for h in ans:
    print(h)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
x = [0]*n
y = [0]*n
mx = [0]*m
my = [0]*m
for i in range(n):
    x[i],y[i] = map(int,input().split())
for j in range(m):
    mx[j],my[j] = map(int,input().split())
ans = [0]*n
for k in range(n):
    dis = 1000000000
    cnt = 1
    for l in range(n):
        if abs(x[k]-mx[l])+abs(y[k]-my[l]) < dis:
            dis = abs(x[k]-mx[l])+abs(y[k]-my[l])
            cnt = l+1
    ans[k] = cnt
for h in ans:
    print(h)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
x = [0]*n
y = [0]*n
mx = [0]*m
my = [0]*m
for i in range(n):
    x[i],y[i] = map(int,input().split())
for j in range(m):
    mx[j],my[j] = map(int,input().split())
ans = [0]*n
for k in range(n):
    dis = 0
    cnt = 1
    for l in range(n):
        if abs(x[k]-xs[l])+abs(y[k]-ys[l]) > dis:
            dis = abs(x[k]-xs[l])+abs(y[k]-ys[l])
            cnt = l+1
    ans[k] = cnt
for h in ans:
    print(h)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a=[]
b=[]
c=[]
d=[]
for i in range(n):
    a1,b1=map(int,input().split())
    a.append(a1)
    b.append(b1)
for i in range(m):
    c1,d1=map(int,input().split())
    c.append(c1)
    d.append(d1)
for i in range(n):
    min_len = 100000000
    for j in range(m):
        len = abs(c[j]-a[i])+abs(d[j]-b[i])
        if len < min_len:
            min_len=len
            cnt = j+1
    print(cnt)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
stu = []
che = []
for i in range(N):
  stu.append(list(map(int, input().split())))
for i in range(M):
  che.append(list(map(int, input().split())))
  
for i in stu:
  x, y = i[0], i[1]
  ans = 0
  tmp = 99999999999999
  for j in che:
    if abs(x-j[0])+abs(y-j[1]) < tmp:
      tmp = abs(x-j[0])+abs(y-j[1])
      ans = j + 1
  print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
stu = []
for _ in range(N):
  stu.append(tuple(map(int, input().split())))
che = []
for _ in range(M):
  che.append(tuple(map(int, input().split())))

for i in range(N):
  ans = 0
  min_l = pow(10, 10)
  for j in range(M):
    l = abs(stu[i][0] - che[i][0]) + abs(stu[i][1] - che[i][1])
    if l < min_l:
      min_l = l
      ans = j+1
  print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]
C = [list(map(int, input().split())) for _ in range(N)]

for s in S:
    minC = 10**10
    idx = 0
    for i, c in enumerate(C):
        d = abs(s[0]-c[0]) + abs(s[1]-c[1])
        if d < minC:
            minC = d
            idx = i + 1
    print(idx)

Submission status: Runtime Error

Solution code:
a,b = map(int, input().split())
x = []
z = []
m =19999999999999
s  = 1
for i in range(a):
    ta , tb = map(int, input().split()) 
    x.append([ta,tb])
for i in range(a):
    ta , tb = map(int, input().split())
    z.append([ta,tb])
for ta , tb in x:
    s = 0
    m =19999999999999
    for n,(s,y) in enumerate(z):
        print(n,s,y)
        # print(m , abs(s-ta)+abs(y-tb))
        if m >= abs(s-ta)+abs(y-tb):
            m = abs(s-ta)+abs(y-tb)
            s = n
    print(s+1)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
a_list = []
b_list = []
c_list = []
d_list = []
lists = []
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 i in range(N):
    min = abs(a_list[0] - c_list[0]) + abs(b_list[0] - d_list[0])
    for j in range(M):
        distance = abs(a_list[i] - c_list[j]) + abs(b_list[i] - d_list[j])
        if min > distance:
            min = distance
            index = j
    lists.append(index+1)
for i in range(len(lists)):
    print(lists[i])

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
a_list = []
b_list = []
c_list = []
d_list = []
lists = []
max = 0
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 i in range(N):
    min = 9999
    for j in range(M):
        distance = abs(a_list[i] - c_list[j]) + abs(b_list[i] - d_list[j])
        if min > distance:
            min = distance
            index = j
    lists.append(index+1)
for i in range(len(lists)):
    print(lists[i])

Submission status: Runtime Error

Solution code:
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 j in range(M):
    x, y = map(int, input().split())
    c.append(x)
    d.append(y)

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

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
pos1=[list(map(int,input().split())) for _ in range(n)]
pos2=[list(map(int,input().split())) for _ in range(m)]
ans=[0]*n
for i in range(n):
  lim=10**9
  for j in range(m):
    tmp=abs(pos1[i][0]-pos2[i][0])+abs(pos1[i][1]-pos2[i][1])
    if tmp<lim:
      tmp=lim
      ans[i]=j
for i in range(n):
  print(ans[i])

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
students = []
points = []
for i in range(N):
  students.append(list(map(int,input().split())))
for j in range(M):
  points.append(list(map(int,input().split())))
for k in range(N):
  Q = 999999999999999
  for l in range(M):
    x_ = students[k,0]-points[l,0]
    y_ = students[k,1]-points[l,0]
    if (x_<0):
      x_ = x_ *(-1)
    if (y_<0):
      y_ = y_ *(-1)
    L = x_ + y_
    z = 0
    if(L<Q):
      Q = L
      z = l+1
    else:
      None
  print(z)

Submission status: Runtime Error

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

for i in range(N):
  ai, bi = map(int, input().split())
  a.append(ai)
  b.append(bi)
#  print(a, b)
for j in range(M):
  cj, dj = map(int, input().split())
  c.append(cj)
  d.append(dj)
  
#print(a,b,c,d)
  
for i in range(N):
  dist, min_dist = 0, INF
  ans = 1
  for j in range(M):
    dist = abs(c[j] - a[i]) + abs(d[j] - b[i])
    if dist < min_dist:
      ans = j+1
      min_dist = dist
#    print("ai:{}, bi:{}, cj:{}, dj:{}, dist:{}, ans:{}".format(a[i], b[i], c[j], d[j], dist, ans))
#    print("i:{}, j:{}, dist:{}, min_dist:{}, ans:{}".format(i, j, dist, min_dist, ans))
#    min_dist = min(dist, min_dist)
  print(ans)