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 = list(map(int,input().strip().split()))

# 2次元配列
student = []
for i in range(n):
    array = list(map(int, input().strip().split()))
    student.append(array)

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

result = [0] * n
for i in range(n):
  dis_min = 10**9
  for j in range(m):
    dis = abs(student[i][0]-cp[j][0]) + abs(student[i][1] - cp[j][1])
    if dis < dis_min:
      dis_min = dis
      result[i] = j+1

for i in result:
  print(i)

Submission status: Accepted

Solution code:

if __name__ == '__main__':
    a, b = map(int, input().split())
    lista=[]
    for i in range(a):
        c = [int(i) for i in input().split()]
        lista.append(c)

    listb=[]
    for i in range(b):
        c = [int(i) for i in input().split()]
        listb.append(c)

    listc =[]

    for i in lista:
        min = 10**9
        minroot=-1
        for j in range(len(listb)):
            root = abs(i[0] - listb[j][0])  + abs(i[1] - listb[j][1])
            if root <min:
                min =root
                minroot=j+1
        listc.append(minroot)
    for i in listc:
        print(i)

Submission status: Accepted

Solution code:
def d(x, y):
  return abs(x[0] - y[0]) + abs(x[1] - y[1])
n, m = map(int, input().split())
x = [tuple(map(int, input().split())) for i in range(n)]
y = [tuple(map(int, input().split())) for i in range(m)]
for i in range(n):
  p = 0
  for j in range(1, m):
    if d(x[i], y[j]) < d(x[i], y[p]):
      p = j
  print(p + 1)

Submission status: Accepted

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)]

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

Submission status: Accepted

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

ans = [-1] * N
for i in range(N):
    min_dist = float("inf")
    min_idx = -1
    for j in range(M):
        dist = abs(students[i][0] - cps[j][0]) + abs(students[i][1] - cps[j][1])
        if dist < min_dist:
            min_dist = dist
            min_idx = j + 1
    ans[i] = min_idx
print("\n".join(map(str, ans)))

Submission status: Accepted

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

ans = []
for a in A:
    cur = float('inf')
    for i, b in enumerate(B):
        x = abs(a[0] - b[0]) + abs(a[1] - b[1])
        if  x < cur:
            cur = x
            checkpoint = i + 1
    ans.append(checkpoint)
    
for i in range(n):
    print(ans[i])

Submission status: Accepted

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

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

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

ans_lis = []


for i in range(len(studentlis)):
    ans = int(10**100)

    tmpstudentlis = studentlis[i]

    x1 = tmpstudentlis[0]
    y1 = tmpstudentlis[1]
    
    for j in range(len(checkpointlis)):
        tmpcheckpointlis = checkpointlis[j]

        x2 = tmpcheckpointlis[0]
        y2 = tmpcheckpointlis[1]
        
        distance = (abs(x1-x2) + abs(y1-y2))

        if distance < ans:
            ans = distance
            num = j

        if j == len(checkpointlis)-1:
            ans_lis.append(num+1)


for i in ans_lis:
    print(i)

Submission status: Accepted

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

for i in students:
  d_min=100000000000000000000
  p=0
  for j in checkpoints:
    p+=1
    d = abs(i[0] - j[0])+abs(i[1] - j[1])
    if d < d_min:
      d_min = d
      point=p
  print(point)

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):
    ans = 0
    tmp = 10**9
    for j in range(m):
        dt = abs(a[i][0]-b[j][0]) + abs(a[i][1]-b[j][1])
        if dt < tmp:
            ans = j+1
            tmp = dt
    print(ans)

Submission status: Accepted

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=10**18
  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: 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):
    d = (10**8)*4
    result = 0
    for j in range(m):
        if abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]) < d:
            d = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
            result = j+1
    print(result)

Submission status: Accepted

Solution code:
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:
	minv = p = float('inf')
	for i, (c, d) in enumerate(CD):
		dist = abs(a - c) + abs(b - d)
		if dist < minv:
			minv = dist
			p = i + 1
	print(p)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
S = []
for _ in range(n):
	a, b = map(int, input().split())
	S.append([a, b])
P = []
for _ in range(m):
	c, d = map(int, input().split())
	P.append([c, d])
sorted(P)
for s in S:
	sx, sy = s[0], s[1]
	minv = float('inf')
	minvp = -1
	for i, p in enumerate(P):
		px, py = p[0], p[1]
		d = abs(px - sx) + abs(py - sy)
		if d < minv:
			minv = d
			minvp = i
	print(minvp + 1)

Submission status: Accepted

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

for i in range(n):
    chk_id = 0
    d = float("inf")
    for j in range(m):
        d1 = abs(std[i][0] - chk[j][0]) + abs(std[i][1] - chk[j][1])
        if d1 < d:
            d = d1
            chk_id = j+1
    print(chk_id)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
for i in range(n):
  at,bt=map(int,input().split())
  a.append(at)
  b.append(bt)
for j in range(m):
  ct,dt=map(int,input().split())
  c.append(ct)
  d.append(dt)
for i in range(n):
  temp=0
  man=99999999999999999
  for j in range(m):
    if abs(a[i]-c[j])+abs(b[i]-d[j])<man:
      man=abs(a[i]-c[j])+abs(b[i]-d[j])
      temp=j+1
  print(temp)

Submission status: Accepted

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 j in range(M)]
for i in range(N):
    d=(10**8)*4
    ans=0
    for j in range(M):
        if abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1])<d:
            d=abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1])
            ans=j+1
    print(ans)

Submission status: Accepted

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

for i in range(n):
    bag = []
    for k in range(m):
        bag.append(abs(a[i][0] - c[k][0]) + abs(a[i][1] - c[k][1]))
    ind = bag.index(min(bag))
    print(ind + 1)

Submission status: Accepted

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

for i in range(n):
    x = loc[i][0]
    y = loc[i][1]
    cnt = int(1e18)
    ans = 0
    for j in range(m):
        x1 = che[j][0]
        y1 = che[j][1]
        u = abs(x-x1)+abs(y-y1)
        if cnt > u:
            ans = j+1
            cnt = u
    print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
 
x = []
y = []
 
for _ in range(n):
    a,b = map(int,input().split())
    x.append((a,b))

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

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a, b = [0]*n, [0]*n
c, d = [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):
    l = 10 ** 9
    for j in range(m):
        if abs(a[i] - c[j]) + abs(b[i] - d[j]) < l:
            l = abs(a[i] - c[j]) + abs(b[i] - d[j])
            idx = j + 1

    print(idx)

Submission status: Accepted

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]*n
    ansin=[0]*n
    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: Accepted

Solution code:

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

x = []
y = []

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

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

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

Submission status: Accepted

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, xy in enumerate(cp):
    d = abs(xy[0]-a) + abs(xy[1]-b)
    if d < nearest:
      nearest = d
      idousaki = i+1
      
  idou.append(idousaki)
  
for i in idou:
  print(i)

Submission status: Accepted

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

for x in range(N):
    d1 = 999999999999999999
    for y in range(M):
        d = abs(ab[x][0] - cd[y][0]) + \
            abs(ab[x][1] - cd[y][1])
        if d < d1:
            d1 = d
            ans = y + 1
    print(ans)

Submission status: Accepted

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)]

ans = []
for i, (a, b) in enumerate(ab):
  min_dist = 10**20
  idx = -1
  for j, (c, d) in enumerate(cd):
    dij = abs(a - c) + abs(b - d)
    if dij < min_dist:
      min_dist = dij
      idx = j
  ans.append(idx+1)

print(*ans, sep='\n')

Submission status: Accepted

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

for student in students:
  a, b = student
  ans = None
  dist = 10**10
  for i in range(len(points)):
    c, d = points[i]
    tmp = abs(a-c) + abs(b-d)
    if tmp < dist:
      ans = i+1
      dist = tmp
      
  print(ans)

Submission status: Accepted

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


for a in A:
    distance = 10**9
    point = 0
    for i, c in enumerate(C):
        if abs(a[0] - c[0]) + abs(a[1] - c[1]) < distance:
            distance = abs(a[0] - c[0]) + abs(a[1] - c[1])
            point = i
    print(point + 1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = [[int(i) for i in input().split()] for i in range(N)]
b = [[int(i) for i in input().split()] for i in range(M)]
d_listed = list()
for n in range(len(a)):
  d_listed = list()
  for m in range(len(b)):
    D = abs(a[n][0] - b[m][0]) + abs(a[n][1] - b[m][1])
    d_listed.append(D)
  print(d_listed.index(min(d_listed))+ 1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, m = mi()
    person = [lmi() for _ in range(n)]
    check = [lmi() for _ in range(m)]

    for x, y in person:
        nearest = None
        dist = inf
        for i in range(m):
            cx, cy = check[i]
            if dist > abs(cx - x) + abs(cy - y):
                dist = abs(cx - x) + abs(cy - y)
                nearest = i
        print(nearest + 1)



if __name__ == "__main__":
    main()

Submission status: Accepted

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

    student_position = list()
    for i in range(n):
        a, b = map(int, input().split())
        student_position.append([a, b])
    
    check_point = list()
    for i in range(m):
        c, d = map(int, input().split())
        check_point.append([c, d])

    ans = list()
    for student_num in range(n):
        delta_list = list()
        for point_num in range(m):
            x = abs(student_position[student_num][0] - check_point[point_num][0])
            y = abs(student_position[student_num][1] - check_point[point_num][1])
            delta = x + y
            delta_list.append(delta * 100 + point_num)
        nearest_index = min(delta_list)
        point = nearest_index % 100 + 1
        ans.append(point)
    
    for an in ans:
        print(an)
resolve()

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)]
ans = []


for a, b in ab:
    num = float('inf')
    for i in range(M):
        if num > abs(a - cd[i][0]) + abs(b - cd[i][1]):
            num = abs(a - cd[i][0]) + abs(b - cd[i][1])
            check = i + 1
    ans.append(check)

for i in ans:
    print(i)

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):
  tmp=10**9
  for j in range(m):
    man=abs(a[i][0]-b[j][0]) + abs(a[i][1]-b[j][1])
    if man < tmp:
      tmp=man
      ans=j+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 a, b in ab:
    ans = 10 ** 10
    dist = 10 ** 10
    for i in range(m):
        c, d = cd[i]
        temp = abs(a - c) + abs(b - d)
        if dist > temp:
            dist = temp
            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 a, b in ab:
    ans = []
    for c, d in cd:
        tmp = abs(a - c) + abs(b - d)
        ans.append(tmp)
    print(ans.index(min(ans)) + 1)

Submission status: Accepted

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

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

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

for i in range(n):
    ans = 0
    min_man = 10e8
    num=0
    for j in range(m):
        man = abs(a[i]-c[j])+abs(b[i]-d[j])
        num+=1
        if min_man > man:
            min_man = man
            ans = num
    print(ans)

Submission status: Accepted

Solution code:
#B
n, m = map(int, input().split())
students = []
cpoints = []
ans = []
for i in range(n):
    students.append(list(map(int,input().split())))
for i in range(m):
    cpoints.append(list(map(int,input().split())))
for i in range(n):
    nearest = 10**9
    a = students[i][0]
    b = students[i][1]
    for j in range(m):
        if nearest == abs(a-cpoints[j][0]) + abs(b-cpoints[j][1]):
                    continue
        if nearest > abs(a-cpoints[j][0]) + abs(b-cpoints[j][1]):
                    i_point = j
                    nearest = abs(a-cpoints[j][0]) + abs(b-cpoints[j][1])
    ans.append(i_point+1)
for i in range(n):
    print(ans[i])

Submission status: Accepted

Solution code:
def manhattan_distance(p, q) -> int:
    return abs(p[0] - q[0]) + abs(p[1] - q[1])


N, M = map(int, input().split())
students = [tuple(map(int, input().split())) for _ in range(N)]
checkpoints = [tuple(map(int, input().split())) for _ in range(M)]

for student in students:
    p = min([(manhattan_distance(student, checkpoint), idx) for idx, checkpoint in enumerate(checkpoints, start=1)])
    print(p[1])