Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02793 (python)

Fixed submission:
def prime_factors(n):
    d = {}
    while n%2 == 0:
        d[2] = d.get(2, 0) + 1
        n //= 2
    i = 3
    while i*i <= n:
        while n%i == 0:
            d[i] = d.get(i, 0) + 1
            n //= i
        i += 2
    if n > 2:
        d[n] = d.get(n, 0) + 1
    return d

MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
G = {}
for a in A:
    pf = prime_factors(a)
    for k,v in pf.items():
        G[k] = max(G.get(k, 0), v)
lcm = 1
for k,v in G.items():
    lcm *= pow(k, v, MOD)
    lcm %= MOD
ans = 0
for a in A:
    ans += lcm * pow(a, MOD-2, MOD) % MOD
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
import math
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
now = A[0]
ans = 0
for i in range(1,N):
    now = now//math.gcd(now, A[i])*A[i]
for i in range(N):
    ans += now//A[i]
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
import math
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
now = A[0]
ans = 0
for i in range(1,N):
    now = (now*A[i])//math.gcd(now, A[i])
for i in range(N):
    ans += now//A[i]
    ans %= MOD
print(ans)
Problem p02851 (python)

Fixed submission:
from collections import defaultdict

N, K = map(int, input().split())
A = list(map(int, input().split()))
cum = [0]*(N+1)
for i in range(1,N+1):
    cum[i] = cum[i-1] + A[i-1]
ans = 0
dic = defaultdict(int)
v_by_indx = defaultdict(int)
for i in range(N+1):
    if i-K >= 0:
        dic[v_by_indx[i-K]] -= 1
    diff = (cum[i]-i)%K
    ans += dic[diff]
    dic[diff] += 1
    v_by_indx[i] = diff
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

N, K = map(int, input().split())
A = list(map(int, input().split()))
cum = [0]*(N+1)
for i in range(1,N+1):
    cum[i] = cum[i-1] + A[i-1]
ans = 0
dic = defaultdict(int)
v_by_indx = defaultdict(int)
for i in range(N+1):
    if i-K >= 0:
        dic[v_by_indx[i-K]] -= 1
    diff = (cum[i]-i)%K
    ans += dic[diff]
    dic[diff] += 1
    v_by_indx[i] = diff
print(ans)
from collections import defaultdict

N, K = map(int, input().split())
A = list(map(int, input().split()))
cum = [0]*(N+1)
for i in range(1,N+1):
    cum[i] = cum[i-1] + A[i-1]
ans = 0
dic = defaultdict(int)
v_by_indx = defaultdict(int)
for i in range(N+1):
    if i-K >= 0:
        dic[v_by_indx[i-K]] -= 1
    diff = (cum[i]-i)%K
    ans += dic[diff]
    dic[diff] += 1
    v_by_indx[i] = diff
print(ans)
Problem p02925 (python)

Fixed submission:
N = int(input())
A = [list(map(lambda n: int(n)-1, input().split())) for i in range(N)]
cur = [0 for i in range(N)]
que = [i for i in range(N)]
ans = 0
while len(que) > 0:
    done = {}
    que2 = []
    for n in que:
        if done.get(n):
            continue
        pair = A[n][cur[n]]
        if done.get(pair):
            continue
        if n == A[pair][cur[pair]]:
            cur[n] += 1
            cur[pair] += 1
            done[n] = True
            done[pair] = True
            if cur[n] < N-1:
                que2.append(n)
            if cur[pair] < N-1:
                que2.append(pair)
    if len(done) > 0:
        ans += 1
    que = que2
ok = True
for i in range(N):
    if cur[i] < N-1:
        ok = False
if ok:
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
def toId(i, j):
    pair = A[i][j]
    if i > pair:
        i, pair = pair, i
    return ids[i][pair]

def dfs(x):
    if dp[x] != -1:
        if done[x]:
            return dp[x]
        else:
            return -1
    dp[x] = 1
    for y in G[x]:
        res = dfs(y)
        if res == -1:
            return -1
        dp[x] = max(dp[x], dfs(y)+1)
    done[x] = True
    return dp[x]

N = int(input())
A = [list(map(lambda x: int(x)-1, input().split())) for i in range(N)]
ids = [[0]*N for i in range(N)]
num = 0
for i in range(N):
    for j in range(N):
        if i < j:
            ids[i][j] = num
            num += 1
allv = N*(N-1)//2
G = [[] for i in range(allv)]
for i in range(N):
    for j in range(N-2):
        G[toId(i,j+1)].append(toId(i,j))
dp = [-1 for i in range(allv)]
done = [False for i in range(allv)]
ans = 0
for i in range(allv):
    res = dfs(i)
    if res == -1:
        print(-1)
        exit()
    ans = max(ans, dfs(i))
print(ans)
Problem p02570 (python)

Fixed submission:
D,T,S = map(int,input().split())

if S*T >= D:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
D,T,S = input().split()

if S*T >= D:
  print("Yes")
else:
  print("No")
Problem p02711 (python)

Fixed submission:
N = int(input())
A = [0, 0, 0]
bool = 0
for i in range(3):
  A[i] = N % 10
  N = (N - A[i])/10
  if A[i] == 7:
    print('Yes')
    bool = 1
    break
if bool == 0:
    print('No')

Buggy submission (verdict: Runtime Error):
N = inport()
Ans = 0
for i in range(1,N):
  if not i % 3 == 0:
    if not i % 5 == 0:
      Ans = Ans + i
Ans

Buggy submission (verdict: Runtime Error):
n = input():
A = [0, 0, 0]
bool = 0
for i in range(3):
  A[i] = N % 10
  N = (N - A[i])/10
  if A[i] == 7:
    print('Yes')
    bool = 1
    break
if bool == 0:
    print('No')

Buggy submission (verdict: Runtime Error):
A = [0, 0, 0]
bool = 0
for i in range(3):
  A[i] = N % 10
  N = (N - A[i])/10
  if A[i] == 7:
    print('Yes')
    bool = 1
    break
if bool == 0:
    print('No')
Problem p02987 (python)

Fixed submission:
s = sorted(input())
if (s[0] == s[1]) and (s[2] == s[3]) and (s[0] != s[2]):
        print('Yes')
elif (s[0] == s[2]) and (s[1] == s[3]) and (s[0] != s[1]):
        print('Yse')
elif (s[0] == s[3]) and (s[1] == s[2]) and (s[0] != s[1]):
        print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input()
a = 0
for _ in s:
    a += 1 
if  a != 4:
    print('No')
elif s[0] == s[1] and s[2] == s[3] and s[0] != s[2]:
    print('Yes')
elif s[0] == s[2] and s[1] == s[3] and s[0] != s[1]:
    print('Yes')
elif s[0] == s[3] and s[1] == s[2] and a[0] != s[1]:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input()
    if s[0] == s[1] ==s[2]:
        print('No')
    elif s[0] == s[2] == s[3]:
        print('No')
    elif s[1] == s[2] == s[3]:
        print('No')
    elif s[0] == s[1] == s[2] == s[3]:
        print('No')
    elif s[0] == s[1]:
        if s[2] == s[3]:
            print('Yes')
        else:
            print('No')
    elif s[0] == s[2]:
        if s[1] == s[3]:
            print('Yse')
        else:
            print('No')
    elif s[0] == s[3]:
        if s[1] == s[2]:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')
Problem p02862 (python)

Fixed submission:
import math
mod = (10**9) + 7

def kaijo(n):
    result = 1
    for i in reversed(range(1,n+1)):
        result = (result * i) % mod
    return result
def combinations_count(n, r):
    return (kaijo(n)) //(kaijo(n - r) * kaijo(r))

def nCk(n, k):
    ret = 1
    mo = 10**9 + 7
    for i in range(k):
        ret = ret * (n - i) * pow(i + 1, mo - 2, mo) % mo
    return ret


X,Y = map(int,input().split(' '))

if (X+Y)%3 == 0:
    flag = False
    if X > Y:
        diff = X - Y
        all_num = (X+Y)//3
        count_2 = Y - all_num
        if X > Y*2:
            flag = True
    elif Y > X:
        diff = Y - X
        all_num = (X+Y)//3
        count_2 = X - all_num
        if Y > X*2:
            flag = True
    else:
        all_num = (X+Y)//3
        count_2 = all_num//2
    if flag:
        print(0)
    else:
        print(nCk(all_num,count_2))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import math
mod = (10**9) + 7

def kaijo(n):
    result = 1
    for i in reversed(range(1,n+1)):
        result = (result * i) % mod
    return result
def combinations_count(n, r):
    return (kaijo(n)) //(kaijo(n - r) * kaijo(r))

def nCk(n, k):
    ret = 1
    mo = 10**9 + 7
    for i in range(k):
        ret = ret * (n - i) * pow(i + 1, mo - 2, mo) % mo
    return ret


X,Y = map(int,input().split(' '))

if (X+Y)%3 == 0:
    flag = False
    if X > Y:
        diff = X - Y
        all_num = (X+Y)//3
        count_2 = (X+Y)//2 - diff//2 - all_num
        if X > Y*2:
            flag = True
    elif Y > X:
        diff = Y - X
        all_num = (X+Y)//3
        count_2 = (X+Y)//2 - diff//2　- all_num
        if Y > X*2:
            flag = True
    else:
        all_num = (X+Y)//3
        count_2 = all_num//2
    if flag:
        print(0)
    else:
        print(nCk(all_num,count_2))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
X,Y = map(int,input().split(' '))

if (X+Y)%3 == 0:
    if X > Y:
        diff = X - Y
        all_num = (X+Y)//3
        count_2 = all_num//2 + diff//2
    elif Y > X:
        diff = Y - X
        all_num = (X+Y)//3
        count_2 = all_num//2 + diff//2
    else:
        all_num = (X+Y)//3
        count_2 = all_num//2 
    print(combinations_count(all_num,count_2)%((10**9) + 7))
else:
    print(0)
Problem p02948 (python)

Fixed submission:
import heapq
NM = input()
N = int(NM.split(' ')[0])
M = int(NM.split(' ')[1])
each_days_list = [[] for _ in range(M)]
 
for i in range(N):
    ab = input()
    a = int(ab.split(' ')[0])
    b = int(ab.split(' ')[1])
    if a <= M:
        each_days_list[a-1].append(b)

max_list = []
salary_count = 0
for i in range(M):
    for j in range(len(each_days_list[i])): 
        heapq.heappush(max_list,-each_days_list[i][j])
    if len(max_list) > 0:
        salary_count += -heapq.heappop(max_list)
        
print(salary_count)

Buggy submission (verdict: Runtime Error):
NM = input()
N = int(NM.split(' ')[0])
M = int(NM.split(' ')[1])
each_days_map = {}
max_sort_list = [0]

def insert_max_sort(b):
    for idx in range(len(max_sort_list)):
        if b > max_sort_list[idx]:
            max_sort_list.insert(idx,b)
            if len(max_sort_list) > M:
                max_sort_list.pop()
            break

for i in range(N):
    ab = input()
    a = int(ab.split(' ')[0])
    b = int(ab.split(' ')[1])
    if a > M or b < max_sort_list[len(max_sort_list)-1]:
        continue
    if a in each_days_map.keys():
        a_len = len(each_days_map[a])
        if b > each_days_map[a][a_len-1]:
            for idx in range(a_len):
                if b > each_days_map[a][idx]:
                    each_days_map[a].insert(idx,b)
                    if a_len > (M - a + 1):
                        removed_num = each_days_map[a][a_len-1]
                        each_days_map[a].pop()
                        max_sort_list.remove(removed_num)
                    insert_max_sort(b)
                    break
        else:
            if M > a_len and (M - a + 1) > a_len:
                each_days_map[a].append(b)
                insert_max_sort(b)
    else:
        each_days_map[a] = [b]
        insert_max_sort(b)
print(sum(max_sort_list))

Buggy submission (verdict: Runtime Error):
NM = input()
N = int(NM.split(' ')[0])
M = int(NM.split(' ')[1])
each_days_map = {}
max_sort_list = [0]

def insert_max_sort(b):
    for idx in range(len(max_sort_list)):
        if b > max_sort_list[idx]:
            max_sort_list.insert(idx,b)
            if len(max_sort_list) > M:
                max_sort_list.pop()
            break

for i in range(N):
    ab = input()
    a = int(ab.split(' ')[0])
    b = int(ab.split(' ')[1])
    insert_flag = True
    if a > M or b < max_sort_list[len(max_sort_list)-1]:
        continue
    if a in each_days_map.keys():
        a_len = len(each_days_map[a])
        for idx in range(a_len):
            if b > each_days_map[a][idx]:
                each_days_map[a].insert(idx,b)
                if a_len > (M - a + 1):
                    removed_num = each_days_map[a][a_len-1]
                    each_days_map[a].pop()
                    max_sort_list.remove(removed_num)
                insert_max_sort(b)
                insert_flag = False
                break
        if insert_flag and M > a_len and (M - a + 1) > a_len:
            each_days_map[a].append(b)
            insert_max_sort(b)
    else:
        each_days_map[a] = [b]
        insert_max_sort(b)
print(sum(max_sort_list))
Problem p03013 (python)

Fixed submission:
import math

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

'''
factorial_list = [1] * (N+1)
for i in range(1,N+1):
    factorial_list[i] = factorial_list[i-1] * i

def combinations_count(n, r):
    return factorial_list[n] // (factorial_list[n - r] * factorial_list[r])
'''

feruma_list = [1] * (N+1)
for i in range(2,N+1):
    feruma_list[i] = feruma_list[i-2] + feruma_list[i-1]


def nCk(n, k):
    ret = 1
    mo = 10**9 + 7
    for i in range(k):
        ret = ret * (n - i) * pow(i + 1, mo - 2, mo) % mo
    return ret

def one_two_comb(N):
    two_n = N//2
    comb_list = []
    for i in range(1,two_n+1):
        comb_list.append([N-i,i])
    return comb_list

def sum_comb(comb_list):
    comb_sum = 0
    for val in comb_list:
        comb_sum += nCk(val[0],val[1])
    return comb_sum
    

diff_list = []
current_num = 0
max_diff = -1
for a in An:
    diff = a - current_num
    if diff == 0:
        print(0)
        exit(0)
    diff_list.append(diff)
    current_num = a +1
diff = N+1 - current_num
diff_list.append(diff)
#print(diff_list)


all_sum = 1
for idx,diff in enumerate(diff_list):
    
    if idx == 0 or len(diff_list):
        diff -= 1
    '''
    if diff == 0:
        all_sum *= 1
    else:
        internal_comb_list = one_two_comb(diff)
        comb_count = sum_comb(internal_comb_list) + 1
        if all_sum > 10**9+7:
            all_sum = all_sum%(10**9+7)
        all_sum *= comb_count
    '''

    comb_count = feruma_list[diff]
    if all_sum > 10**9+7:
        all_sum = all_sum%(10**9+7)
    all_sum *= comb_count

print(all_sum%(10**9+7))

Buggy submission (verdict: Runtime Error):
import math

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


factorial_list = [1] * ((N+1)//2)
for i in range(1,((N+1)//2)):
    factorial_list[i] = factorial_list[i-1] * i

def combinations_count(n, r):
    return factorial_list[n] // (factorial_list[n - r] * factorial_list[r])


'''
def nCk(n, k):
    ret = 1
    mo = 10**9 + 7
    for i in range(k):
        ret = ret * (n - i) * pow(i + 1, mo - 2, mo) % mo
    return ret
'''

def one_two_comb(N):
    two_n = N//2
    comb_list = []
    for i in range(1,two_n+1):
        comb_list.append([N-i,i])
    return comb_list

def sum_comb(comb_list):
    comb_sum = 0
    for val in comb_list:
        comb_sum += combinations_count(val[0],val[1])
    return comb_sum
    

diff_list = []
current_num = 0
max_diff = -1
for a in An:
    diff = a - current_num
    if diff == 0:
        print(0)
        exit(0)
    diff_list.append(diff)
    current_num = a +1
diff = N+1 - current_num
diff_list.append(diff)
#print(diff_list)


all_sum = 1
for idx,diff in enumerate(diff_list):
    if idx == 0 or len(diff_list):
        diff -= 1
    '''
    else:
        diff -= 2
    '''

    if diff == 0:
        all_sum *= 1
    else:
        internal_comb_list = one_two_comb(diff)
        comb_count = sum_comb(internal_comb_list) + 1
        if all_sum > 10**9+7:
            all_sum = all_sum%(10**9+7)
        all_sum *= comb_count
print(all_sum%(10**9+7))
Problem p03038 (python)

Fixed submission:
import heapq
N,M = map(int,input().split(' '))
An = list(map(int,input().split(' ')))
heapq.heapify(An)
BC_list = []
for i in range(M):
    BC = list(map(int,input().split(' ')))
    BC_list.append(BC)
BC_list.sort(reverse=True,key=lambda x: x[1])
flag = False
decided_sum = []
for val in BC_list:
    B = val[0]
    C = val[1]
    for i in range(B):
        tmp_min = heapq.heappop(An)
        if tmp_min > C:
            #heapq.heappush(An,tmp_min)
            decided_sum.append(tmp_min)
            flag = True
            break
        decided_sum.append(C)
        if len(An) == 0:
            flag = True
            break
    if flag:
        break
print(sum(decided_sum) + sum(An))

Buggy submission (verdict: Runtime Error):
import heapq
N,M = map(int,input().split(' '))
An = list(map(int,input().split(' ')))
heapq.heapify(An)
BC_list = []
for i in range(M):
    BC = list(map(int,input().split(' ')))
    BC_list.append(BC)
BC_list.sort(reverse=True,key=lambda x: x[1])
flag = False
decided_sum = []
for val in BC_list:
    B = val[0]
    C = val[1]
    for i in range(B):
        tmp_min = heapq.heappop(An)
        if tmp_min > C:
            #heapq.heappush(An,tmp_min)
            decided_sum.append(tmp_min)
            flag = True
            break
        decided_sum.append(C)
        #heapq.heappush(An,C)
    if flag:
        break
print(sum(decided_sum) + sum(An))

Buggy submission (verdict: Runtime Error):
import heapq
N,M = map(int,input().split(' '))
An = list(map(int,input().split(' ')))
heapq.heapify(An)
BC_list = []
for i in range(M):
    BC = list(map(int,input().split(' ')))
    BC_list.append(BC)
BC_list.sort(reverse=True,key=lambda x: x[1])
flag = False
decided_sum = 0
for val in BC_list:
    B = val[0]
    C = val[1]
    for i in range(B):
        tmp_min = heapq.heappop(An)
        if tmp_min > C:
            #heapq.heappush(An,tmp_min)
            decided_sum += tmp_min
            flag = True
            break
        decided_sum += C
        #heapq.heappush(An,C)
    if flag:
        break
print(decided_sum + sum(An))
Problem p02570 (python)

Fixed submission:
d, t, s = input().split()
d = int(d)
t = int(t)
s = int(s)
if(d/s <= t):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
d, t, s = input().split()
int(d)
int(t)
int(s)
if(d/s <= t):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
d, t, s = int(input().split())
if(d/s <= t):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
d, t, s = input().split()
if(d/s <= t):
    print('Yes')
else:
    print('No')
Problem p02594 (python)

Fixed submission:
a=int(input())
if a>=30:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
a=int(input())
a>=30:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
a=int(input())
a>=30:
  print('Yes')
 else:
  print('No')

Buggy submission (verdict: Runtime Error):
temperature=input()
if temperature >= 30:
  print('Yes')
 else:
  print('No')
Problem p02912 (python)

Fixed submission:
from heapq import heappop,heappush

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

H = []

for i in A:
    heappush(H, -i)

for _ in range(M):
    heappush(H, -((-heappop(H)//2)) )

print(-sum(H))

Buggy submission (verdict: Runtime Error):
from collections import deque

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

A = deque(A)
A = sorted(A)

for i in range(M):
    temp = A.pop() // 2

    for j in range(N)[::-1]:
        if j>0:
            if A[j-1] <= temp:
                A.insert(j,temp)
                print(A)
                break
        else:
            A.insert(0,temp)

print(sum(A))
Problem p03038 (python)

Fixed submission:
N,M=map(int, input().split())

A = list(map(int, input().split()))
S = [list(map(int,input().split())) for i in range(M)]

A.sort()
S.sort(key=lambda x: x[1], reverse=True)

idx = 0

for i in range(M):
    for j in range(idx, min(N, idx + S[i][0])):
        if A[j] < S[i][1]:
            A[j] = S[i][1]
            idx += 1
        else:
            break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N,M=map(int, input().split())

A = list(map(int, input().split()))
S = [list(map(int,input().split())) for i in range(M)]

A.sort()
S.sort(key=lambda x: x[1], reverse=True)

X = [0]*(len(A))
idx = 0

for i in range(M):
    if idx < len(A):
        X[idx:S[i][0]] = [S[i][1]] * S[i][0]
        idx += S[i][0]

for i in range(idx):
    A[i] = max(A[i], X[i])

print(sum(A))

Buggy submission (verdict: Runtime Error):
N,M=map(int, input().split())

A = list(map(int, input().split()))
S = [list(map(int,input().split())) for i in range(M)]

A.sort()
S.sort(key=lambda x: x[1], reverse=True)

X = [0]*(len(A))
idx = 0

for i in range(M):
    for _ in range(S[i][0]):
        if idx <= len(A):
            X[idx]=S[i][1]
            idx += 1

for i in range(idx):
    A[i] = max(A[i], X[i])

print(sum(A))

Buggy submission (verdict: Runtime Error):
N,M=map(int, input().split())

A = list(map(int, input().split()))

for _ in range(M):
    B,C = map(int, input().split())
    A.sort()

    for i in range(B):
        if A[i]<C:
            A[i] = C
            print(A)
            print('-----------\n')

print(sum(A))
Problem p03221 (python)

Fixed submission:
N,M = map(int, input().split())

PY = [[i] for i in range(1,M+1)]

for i in range(M):
    temp1, temp2 = map(int, input().split())
    PY[i].append(temp1)
    PY[i].append(temp2)


PY.sort(key=lambda val: val[2])
# print(PY)
PY.sort(key=lambda val: val[1])
# print(PY)
city = 0

for i, value in enumerate(PY):
    if value[1] != city:
        j = 0
    j += 1
    value.append(j)
    city = value[1]

PY.sort(key=lambda val:val[0])

# print(PY)

for i in PY:
    ans = str(i[1]).zfill(6)+str(i[3]).zfill(6)
    print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
PY_originals = tuple(PY)
N_counter = [0] * N
M_counter = [0] * M

PY.sort(key=lambda val: val[1])

for i in range(M):
    N_counter[PY[1]-1] += 1
    M_counter[i] = N_counter[PY[1]-1]

for i in PY_originals:
    ans = str(i[0]).zfill(6)+str(M_counter[PY.index(i)]).zfill(6)
    print(ans)
Problem p03774 (python)

Fixed submission:
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**9+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)

Buggy submission (verdict: Runtime Error):
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)