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

Submission status: Runtime Error

Solution code:
def mh(a,b,c,d):
    return abs(a-c)+abs(b-d)

n,m = map(int,input().split())
stu = []
for i in range(n):
    a,b = map(int,input().split())
    stu.append([a,b])
ans = [[99,1000000000] for i in range(m)]
#ans[1][1] = 0
#print(ans)
for j in range(1,m+1):
    x,y = map(int,input().split())
    for i in range(n):
        tmp = mh(stu[i][0],stu[i][1],x,y)
        if tmp < ans[i][1]:
            ans[i][0] = j
            ans[i][1] = tmp
for i in range(n):
    print(ans[i][0])

Submission status: Runtime Error

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

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

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

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

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

distance = []
for a, b in ab:
  for c, d in cd:
    distance.append(abs(a-c)+abs(b-d))
  print(distance.index(min(distance))+1)
  distance.clear()

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

d = {}
for i in range(len(ab)):
  for j in range(len(cd)):
    d[j+1] = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
  print(min(d, key=d.get))

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
N, M = list(map(int, input().split()))
P, CP = [], []
 
for i in range(N):
    P.append(list(map(int, input().split())))
for i in range(M):
    CP.append(list(map(int, input().split())))
 
for i in range(N):
    a, b = P[i][0], P[i][1]
    now = 10**8*2+1
    for j in reversed(range(M)):
        c, d = CP[j][0], CP[j][1]
        distance = abs(a-c)+abs(b-d)
        if distance <= now:
            result = j+1
            now = distance
    print(result)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n, m = [int(w) for w in input().split()]
ls = [[int(w) for w in input().split()] for _ in range(n)]
lp = [[int(w) for w in input().split()] for _ in range(n)]

for a, b in ls:
    ans = -1
    dist = 10e10
    for i, (c, d) in enumerate(lp):
        d = abs(a-c) + abs(b-d)
        if d < dist:
            ans = i
            dist = d
    print(ans+1)

Submission status: Runtime Error

Solution code:
import bisect
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)]
AB = sorted(ab)
for x,y in cd:
    a = bisect.bisect_left(AB, [x,y])
    print(ab.index(AB[a])+1)

Submission status: Runtime Error

Solution code:
def solve():
  N, M = map(int, input().split())
  ans = [0]*N
  A = [0]*N
  B = [0]*N
  for i in range(N):
    A[i],B[i] = map(int, input().split())
  X = [0]*M
  Y = [0]*M
  for i in range(M):
    X[i],Y[i] = map(int, input().split())
  for i in range(N):
    ind = -1
    d_min = float('inf')
    for j in range(N):
      d = ((A[i]-X[j])**2+(B[i]-Y[j])**2)**0.5
      if d<d_min:
        d_min = d
        ind = j+1
    ans[i] = ind
  return ans
print(*solve(),sep='\n')

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
st=[]
ch=[]
def mht(ax,ay,bx,by):
  return abs(ax-bx)+abs(ay-by)

for i in range(n):
  st.append(list(map(int,input().split())))
for i in range(m):
  ch.append(list(map(int,input().split())))
  
for i in st:
  ax=i[0]
  ay=i[1]
  mn=100000000
  for (j,k) in zip(ch,range(len(ch))):
    bx=j[0]
    by=j[1]
    mh=mht(ax,ay,bx,by)
    if mh<mn:
      mn=mh
      nm=k
  print(nm+1)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
st=[]
ch=[]
def mht(ax,ay,bx,by):
  return abs(ax-bx)+abs(ay-by)

for i in range(n):
  st.append(list(map(int,input().split())))
for i in range(m):
  ch.append(list(map(int,input().split())))
  
for i in st:
  ax=i[0]
  ay=i[1]
  mn=100000000
  for (j,k) in zip(ch,range(len(ch))):
    bx=j[0]
    by=j[1]
    mh=mht(ax,ay,bx,by)
    if mh<mn:
      mn=mh
      nm=k
  print(nm)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
st=[]
ch=[]
def mht(ax,ay,bx,by):
  return abs(ax-bx)+abs(ay-by)

for i in range(n):
  st.append(list(map(int,input().split())))
for i in range(m):
  ch.append(list(map(int,input().split())))
  
for i in st:
  ax=i[0]
  ay=i[1]
  mn=100000000
  for (j,k) in zip(ch,len(ch)):
    bx=j[0]
    by=j[1]
    mh=mht(ax,ay,bx,by)
    if mh<mn:
      mn=mh
      nm=k
  print(nm)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
st=[]
ch=[]
def mht(ax,ay,bx,by):
  return abs(ax-bx)+abs(ay-by)

for i in range(n):
  st.append(list(map(int,input().split())))
for i in range(m):
  ch.append(list(map(int,input().split())))
  
for i in st:
  ax=i[0]
  ay=i[1]
  mn=100000000
  for (j,k) in zip(ch,range(1,m+1)):
    bx=j[0]
    by=j[1]
    mh=mht(ax,ay,bx,by)
    if mh<mn:
      mn=mh
      nm=k
  print(nm)

Submission status: Runtime Error

Solution code:
s = input().split()

n = int(s[0])
m = int(s[1])

x = []
y = []

check_x = []
check_y = []

dis = 0
mindis = 1000000000
answer = []
for i in range(m):
    answer.append(0)

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

for i in range(m):
    a = input().split()
    check_x.append(int(a[0]))
    check_y.append(int(a[1]))

for j in range(n):
    dis = 0
    mindis = 1000000000
    for i in range(m):
        dis = abs(x[j] - check_x[i]) + abs(y[j] - check_y[i])
        if dis < mindis:
            mindis = dis
            answer[j] = i + 1

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

Submission status: Runtime Error

Solution code:
N = int(input())

y = []

for i in range(1, N//2):
    if N % i == 0:
        y.append( max( len(str(i)),  len(str(int(N/i))) ) )
print(min(y))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]
y = [list(map(int, input().split())) for _ in range(M)]
for a,b in ab:
    z = [abs(a-c) + abs(b-d) for c,d in cd]
    print(z.index(min(z))+1)

Submission status: Runtime Error

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

index_list = []
for i in range(N):
    min_dist = 10000000
    for j in range(M):
        dist = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if dist<min_dist:
            min_dist = dist
            index=j
    index_list.append(index)

for i in index_list:
    print(i+1)

Submission status: Runtime Error

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

index_list = []
for i in range(N):
    min_dist = 10000
    for j in range(M):
        dist = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if dist<min_dist:
            min_dist = dist
            index=j
    index_list.append(index)

for i in index_list:
    print(i+1)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
student = [list(map(int,input().split())) for _ in range(N)]
cpoint = [list(map(int,input().split())) for _ in range(M)]
for i in range(N):
    mannmn = 10**8
    for j in range(M):
        mann = abs(student[i][0] - cpoint[j][0])+abs(student[i][1] - cpoint[j][1])
        if mann <= mannmn:
            mannmn = mann
            ref = j
    print(ref+1)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
student = [list(map(int,input().split())) for _ in range(N)]
cpoint = [list(map(int,input().split())) for _ in range(M)]
for i in range(N):
    mannmn = 10**8
    for j in range(M):
        mann = abs(student[i][0] - cpoint[j][0])+abs(student[i][1] - cpoint[j][1])
        if mann < mannmn:
            mannmn = mann
            ref = j+1
    print(ref)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cctype>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> A(N), B(N), C(M), D(M);
    REP(i, N) cin >> A[i] >> B[i];
    REP(i, M) cin >> C[i] >> D[i];
    REP(i, N) {
        int ans = 0;
        ll d = INF;
        REP(j, M) {
            if (abs(A[i] - C[j]) + abs(B[i] - D[j]) < d) {
                ans = j + 1;
                d = abs(A[i] - C[j]) + abs(B[i] - D[j]);
            }
        }
        cout << ans << "\n";
    }
    return 0;
}

Submission status: Runtime Error

Solution code:
n,m=map(int, input().split())
a_list=[]
b_list=[]
for i in range(n):
  a,b=map(int, input().split())
  a_list.append(a)
  b_list.append(b)
c_list=[]
d_list=[]
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=0
  min_number=0
  for j in range(m):
    d=abs(a[i]-c[j])+abs(b[i]-d[j])
    if d<min:
      min=d
      min_number=j
  print(min_number)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
st=[]
ch=[]
def mht(a,b):
  return abs(a[0]-b[0])+abs(a[1]-b[1])

for i in range(n):
  st.append(list(map(int,input().split())))
for i in range(m):
  ch.append(list(map(int,input().split())))
  
for i in st:
  mn=100000000
  for (j,k) in zip(ch,range(1,m+1)):
    mh=mht(i,j)
    if mh<mn:
      mn=mh
      nm=k
  print(nm)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
st=[]
ch=[]
def mht(a,b):
  try:
    return abs(a[0]-b[0])+abs(a[1]-b[1])
  except:
    return 0
for i in range(n):
  st.append(list(map(int,input().split())))
for i in range(m):
  ch.append(list(map(int,input().split())))
  
for i in st:
  mn=100000000
  for (j,k) in zip(ch,range(m)):
    mh=mht(i,j)
    if mh<mn:
      mn=mh
      nm=k+1
  print(nm)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
st=[]
ch=[]
def mht(a,b):
  return abs(a[0]-b[0])+abs(a[1]-b[1])
for i in range(n):
  st.append(list(map(int,input().split())))
for i in range(m):
  ch.append(list(map(int,input().split())))
  
for i in st:
  mn=100000000
  for (j,k) in zip(ch,range(m)):
    mh=mht(i,j)
    if mh<mn:
      mn=mh
      nm=k+1
  print(nm)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
st=[]
ch=[]
def mht(a,b):
  return abs(a[0]-b[0])+abs(a[1]-b[1])
for i in range(n):
  st.append(list(map(int,input().split())))
for i in range(m):
  ch.append(list(map(int,input().split())))
  
for i in st:
  mn=100000000
  for (j,k) in zip(ch,range(m)):
    mh=mht(i,j)
    if mh<mn:
      mn=mh
      nm=k+1
  print(nm)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header
ll calc(ll x1, ll y1, ll x2, ll y2){
	return abs(x1-x2)+abs(y1-y2);
}
int main() {
	ll n, m;
	cin >> n >> m;
	vector<P> x(n);
	vector<P> y(m);
	rep(i,n){
		ll a, b; cin >> a >> b;
		x[i].first = a;
		x[i].second = b;
	}
	rep(i,m){
		ll c, d; cin >> c >> d;
		y[i].first = c;
		y[i].second = d;
	}
	for(auto k : x){
		ll min = INF, ans;
		rep(i,m){
			ll dist = calc(k.first, k.second, y[i].first, y[i].second);
			if(dist < min){
				min = dist;
				ans = i+1;
			}
			//cout << ans << " ";
		}
		//cout << endl;
		cout << ans << endl;
	}
 	return 0;
}

Submission status: Runtime Error

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

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

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

for a, b in S:
    ans = None
    min_dist = int(2e8)
    for i, (c, d) in enumerate(C):
        dist = abs(c - a) + abs(d - b)
        if dist < min_dist:
            min_dist = dist
            ans = i
    print(ans + 1)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
  x,y=map(int,input().split())
  a.append(x,y)
for i in range(m):
  x,y=map(int,input().split())
  b.append(x,y)
for i in a:
  ans=10**18
  t=0
  for j in range(m):
    if abs(i[0]-b[j][0])+abs(i[1]-b[j][1])<ans:
      t=j+1
      ans=abs(i[0]-b[j][0])+abs(i[1]-b[j][1])
  print(t)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
  x,y=map(int,input().split())
  a.append(x,y)
for i in range(m):
  x,y=map(int,input().split())
  b.append(x,y)
for i in a:
  ans=10**18
  t=0
  for j in b:
    if abs(i[0]-j[0])+abs(i[1]-j[1])<ans:
      t=j+1
      ans=abs(i[0]-j[0])+abs(i[1]-j[1])
  print(t)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
x=[]
y=[]
l=[]
p=[]

for i in range(n):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
    
for j in range(m):
    ci,di=map(int,input().split())
    c.append(ci)
    d.append(di)
    
for i in range(n):
    for j in range(m):
        x.append(abs(a[i]-c[j]))
        y.append(abs(b[i]-d[j]))
        l.append(x[i]+y[i])
    
    p.append(l.index(min(l))+1)   
    l=[]
    x=[]
    y=[]
    
for i in range(n):
    print(p[i])

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N,M = [int(i) for i in input().strip().split()]
    students = [[int(i) for i in input().strip().split()] for _ in range(N)]
    checkpoints = [[int(i) for i in input().strip().split()] for _ in range(N)]
    ans = [0] * N

    for i,student in enumerate(students):
        dist = [float("inf")] * M
        for j, checkpoint in enumerate(checkpoints):
            dist[j] = abs(student[0] - checkpoint[0]) + abs(student[1] - checkpoint[1])
        ans[i] = dist.index(min(dist)) + 1

    return ans


if __name__ == "__main__":
    for n in main():
        print(n)

Submission status: Runtime Error

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

student = list()

for x in range(n):
    student.append(list(map(int, input().split())))

checkpoint = list()

for y in range(m):
    checkpoint.append(list(map(int, input().split())))

tmp = 10**8+1

for x in range(n):
    for y in range(m-1, -1, -1):
        distance = abs(student[x][0] - checkpoint[y][0]) + \
            abs(student[x][1] - checkpoint[y][1])
        if tmp >= distance:
            tmp = distance
            ans = y
    print(ans+1)

Submission status: Runtime Error

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

for a, b in ab:
  cost, idx = 10**18, 0
  for i, (c, d) in enumerate(cd):
    if cost > abs(a - c) + abs(b - d):
      cost = abs(a - c) + abs(b - d)
      idx = i + 1
  print(idx)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
st=[]
for i in range(n):
  s_d=list(input())
  st.append(s_d)
cp=[]
for i in range(m):
  c_d=list(input())
  cp.append(c_d)
sc=[]
for i in range(n):
  scd=[]
  for j in range(m):
    scd_d=abs(st[i][0]-cp[j][0])+abs(st[i][1]-cp[j][1])
    scd.append(scd_d)
  sc.append(min(scd))
  
for i in range(n):
  print(sc[i])

Submission status: Runtime Error

Solution code:
n,m map(int,input().split())
st=[]
for i in range(n):
  s_d=list(input())
  st.append(s_d)
cp=[]
for i in range(m):
  c_d=list(input())
  cp.append(c_d)
sc=[]
for i in range(n):
  scd=[]
  for j in range(m):
    scd_d=abs(st[i][0]-cp[j][0])+abs(st[i][1]-cp[j][1])
    scd.append(scd_d)
  sc.append(min(scd))
  
for i in range(n):
  print(sc[i])

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
P=[]
for i in range(N):
  x,y=map(int, input().split())
  P.append([x,y])
C=[]
for i in range(M):
  a,b=map(int, input().split())
  C.append([a,b])

for p in P:
  mind=10000000
  for j in range(M):
    d=abs(p[0]-C[j][0])+abs(p[1]-C[j][1])
    if d<mind:
      ans=j+1
      mind=d
  print(ans)

Submission status: Runtime Error

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

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter
#from collections import deque

#input = stdin.readline


j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])#

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ
#intを取ると文字列分解に使える
'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"


#a,b=map(int, input().split())  #int style 複数数値入力　「A B」みたいなスペース空いた入力のとき

#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


##############################################################################################
##############################################################################################
#under this line explains example calculation



'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''

#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD

combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位ｎ個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
 #(1, 6)
#(3, 3)
#(4, 1)
'''


#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        #sqrt(n)+1以上は考えて約数はないので却下
        if n % k == 0:
            return False
            #割り切れたらFalse
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  # [1, 0, 3]

'''

def factorial(x, mod=10**9+7):
    # x!
    # 階乗
    # ex) factorial(5) = 120
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp
    '''
    Basically, when you do a**d % n, you actually have to calculate a**d, which could be quite large.
    But there are ways of computing a**d % n without having to compute a**d itself, and that is what pow does.
    '''


########################################################################
########################################################################
#b2=a[:]  #1次元のときはコピーはこれで良い
#print(b2)

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a)  #2次元配列はこうコピーする
#print(b3)

'''
ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digits = '0123456789'
hexdigits = '0123456789abcdefABCDEF'
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv...\xaf\xb0...
lowercase = 'abcdefghijklmnopqrstuvwxyz'
octdigits = '01234567'
printable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU...
punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
whitespace = '\t\n\x0b\x0c\r '
'''
'''
引数endに任意の文字列を指定すると、その文字列が改行の代わりに最後に挿入される。例えば連続するprint()の出力を改行なしで単純に連結したい場合は空文字列''を指定すればよい。

print('abc', end='---')
print('xyz')
# abc---xyz

print('abc', end='')
print('xyz')
# abcxyz
source: print_basic.py
なお、デフォルトで改行されるのは引数endのデフォルト値が改行文字'\n'に設定されているから。
'''

def main():
    n=3
    steps=0
    state=0
    w=1
    j=0
    k=0
    #lenを変数に置くと事故るから注意
    #n=int(input())
    #a,b=input().split(" ")#a,bがともに文字列のとき
    n,m=map(int, input().split(" "))
    #mapでとってもstrで変換すればappend可能
    #s=input()
    a=[0]*n
    b=[0]*n
    for i in range(n):
        a[i],b[i]=map(int, input().split(" "))
    c=[0]*m
    d=[0]*m
    for j in range(m):
        c[j],d[j]=map(int, input().split(" "))
    ansln=[10**10]*m
    ansin=[0]*m
    for i in range(n):
     for j in range(m):
        #print(a[i],c[j],b[i],)
        lengh=abs(a[i]-c[j])+abs(b[i]-d[j])
        if lengh < ansln[i]:
         ansln[i]=lengh
         ansin[i]=j+1
    for i in range(n):
     print(ansin[i])


    #a=[i for i in s]#int(i)にすれば数字も行ける
    #nl=list(map(int, input().split(" ")))#数字の時
    #print(a)
    #brray=[list(map(int, input().split(" ")))for i in range(N)]
    #print(brray)


    #for i in range(1,n+1,2):#これで1個飛ばしループになる
    # pass
     #print(i)

    l = ['aaa', 'bbb', 'ccc']
    x=l.index('aaa')#ある要素のインデックス番号を取得
    #s = ''.join(l)
    #s = " ".join(map(str,a))#スペースを空ける時はこう
    #print(s)
    # aaabbbccc

    #if state in known_states and not flag: # state => 2 steps => 5
        #こうやってある要素がリストの中にあるか探すのか
    #print(f'steps: {steps}, state: {state}')
    #こう書いてあるとデバックしやすい

    #dp= [[0]*3 for i in range(5)]#列　行
    #dp用の0の入ったやつ
    #dp= [[0]*(w+1) for i in range(n+1)]#0からwまでのw+1回計算するから
    #print(dp)＃初期条件が入る分計算回数+1列分必要(この場合は判断すべきものの数)
    DP = np.zeros(w+1, dtype=int)#これでも一次元リストが作れる
    exdp=np.zeros((3,4)) # ３×４の２次元配列を生成。2次元ならこう
    #dtypeは指定しないとfloatになる
    #for i in range(n):#ちょっとした入力に便利
    #    a, b = map(int, input().split())
        #dp[i][0] += [a]
        #これだとintとlistをつなぐことになって不適
    #    dp[i] += [a]
    #    dp[i] += [b]
        #これはうまくいく
        #やり方はいろいろあるということ
    #print(dp)


    #brray=[list(map(int, input().split(" ")))for i in range(N)
    #print(brray)



    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]#内包表記に慣れろ
    #print(pin_l)

    ls = ["a", "b", "c", "d", "e"]


    #print(ls[2:5])
    #スライスでの取得

    #print(ls[:-3])
    #一番左端から右から3番目より左まで取得

    #print(ls[:4:2])
    #スライスで1個飛ばしで取得
    #ないときは左端スタート
    #始点のインデックス番号 : 終点のインデックス番号 : スキップする数+1
    #print(ls[::2])
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

idou = []
for a, b in student:
  idousaki = -1
  nearest = 1000000000
  for i, x, y in enumerate(cp):
    d = abs(x-a) + abs(y-b)
    if d < nearest:
      nearest = d
      idousaki = i+1
      
  idou.append(idousaki)
  
for i in idou:
  print(i)