Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

ns = lambda: stdin.readline()[:-1] # s = ns()
ni = lambda: int(stdin.readline()) # N = ni()
na = lambda: list(map(int, stdin.readline().split())) # Arr = na()

H, W = na()
A = []
for _ in range(H):
    A.append(na())

A = np.array(A, ndmin=2)
target_y, target_x = np.where(A % 2 != 0)

def print_path(s, t):
    # s: start(x, y)
    # t: target(x, y)
    diff = t - s
    res = []

    # yaxis
    sign = np.sign(diff[1])
    for i in range(np.abs(diff[1])):
        res.append([s[1], s[0], s[1] + sign, s[0]])
        s[1] += sign

    # xaxis
    sign = np.sign(diff[0])
    for i in range(np.abs(diff[0])):
        res.append([s[1], s[0], s[1], s[0] + sign])
        s[0] += sign
    return res


idx = 0
Num = len(target_y)
ans = []
last = []
while idx < Num:
    if idx == Num-1:
        last.append(np.array([target_x[idx]+1, target_y[idx]+1]))
        break

    if target_y[idx] == target_y[idx+1]:
        ans.extend(print_path(np.array([target_x[idx]+1, target_y[idx]+1]),\
            np.array([target_x[idx+1]+1, target_y[idx+1]+1])))
        idx += 2
    else:
        last.append(np.array([target_x[idx]+1, target_y[idx]+1]))
        idx += 1

for i in range(0, len(last)-1, 2):
    ans.extend(print_path(last[i], np.array([W, last[i][1]])))
    ans.extend(print_path(np.array([W, last[i][1]]), np.array([W, last[i+1][1]])))
    ans.extend(print_path(np.array([W, last[i+1][1]]), last[i+1]))

print(len(ans))
for a in ans:
    print(a[0], a[1], a[2], a[3])


Fixed submission:
# -*- coding: utf-8 -*-

from sys import stdin


ns = lambda: stdin.readline()[:-1] # s = ns()
ni = lambda: int(stdin.readline()) # N = ni()
na = lambda: list(map(int, stdin.readline().split())) # Arr = na()

H, W = na()

a_list = []
for _ in range(H):
    a_list.append(na())
a_list.append([0]*W)  # for simple loop code

operation = []
for y in range(H):
    if y % 2 == 0:
        for x in range(W-1):
            if a_list[y][x] % 2 == 1:
                a_list[y][x+1] += 1
                operation.append([y+1, x+1, y+1, x+2])
        if a_list[y][W-1] % 2 == 1:
            a_list[y+1][W-1] += 1
            operation.append([y+1, W, y+2, W])
    else:
        for x in range(W-1, 0, -1):
            if a_list[y][x] % 2 == 1:
                a_list[y][x-1] += 1
                operation.append([y+1, x+1, y+1, x])
        if a_list[y][0] % 2 == 1:
            a_list[y+1][0] += 1
            operation.append([y+1, 1, y+2, 1])

if operation != [] and operation[-1][2] == H+1:
    operation.pop()

# Result
print(len(operation))
for op in operation:
    print(op[0], op[1], op[2], op[3])
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
res = (A-1)*(B-1)

print(int(res))


Fixed submission:
A, B = map(int, input().split())
res = (A-1)*(B-1)

print(int(res))

Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())

print((A-1)*(B-1))


Fixed submission:
A, B = map(int, input().split())
res = (A-1)*(B-1)

print(int(res))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

res = np.zeros((N, N), dtype=int)

for _ in range(M):
    l, r = map(int, input().split())
    res[:l, r-1:] += 1

query = []
for _ in range(Q):
    query.append(list(map(int, input().split())))

for q in query:
    print(res[q[0]-1, q[1]-1])


Fixed submission:
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N, M, Q = ds_in()

section = np.zeros((N, N), dtype=int)
for _ in range(M):
    p, q = ds_in()
    section[N-p, q-1] += 1

cumlist = np.cumsum(np.cumsum(section, axis=0), axis=1)

query = []
for _ in range(Q):
    query.append(ds_in())

for q in query:
    print(cumlist[N-q[0], q[1]-1])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from collections import defaultdict

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

x = defaultdict(int)
y = defaultdict(int)

for i in range(N):
    temp = x.copy()
    x.clear()
    r = A_list[i] % M
    for t in temp.items():
        y[t[0]] = y[t[0]] + t[1]
        x[int(t[0] + r) % M] = t[1]
    x[r] += 1

print(int(x[0] + y[0]))


Fixed submission:
from collections import Counter
import numpy as np


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

A = np.cumsum(A) % M
C = Counter(A)

res = 0
for c in C.items():
    if c[1] > 1:
        res += (c[1]*(c[1]-1)) // 2
    if c[0] == 0:
        res += c[1]

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

Query = []
for _ in range(M):
    Query.append(list(map(int, input().split())))


Query.sort(key = lambda x : x[1])

count = 0
while len(Query) > 0:
    Query = list(filter(lambda x: x[0] >= Query[0][1], Query))
    count += 1

print(count)


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

Query = []
for _ in range(M):
    Query.append(list(map(int, input().split())))


Query.sort(key = lambda x : x[1])

count = 1
last = Query[0][1]
for i in range(1, M):
    if Query[i][0] >= last:
        count += 1
        last = Query[i][1]
print(count)
Buggy python submission (verdict: Runtime Error):
import math

T = int(input())

for _ in range(T):
    A, B, C, D = map(int, input().split())
    if (A < B) or (D < B):
        print('No')
        continue
    elif (C+1 >= B):
        print('Yes')
        continue
    else:
        s_res = A % B
        s_k = int((C + 1 - s_res - 0.1) // B + 1)
        X = math.gcd(B, (D%B))
        if X == 1:
            print('No')
            continue
        else:
            s_0 = s_k * B + s_res
            if (s_0 - (C+1)) % X > (B-C-2):
                print('Yes')
            else:
                print('No')



Fixed submission:

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


T = int(input())

for _ in range(T):
    A, B, C, D = map(int, input().split())
    if (A < B) or (D < B):
        print('No')
        continue
    elif (C+1 >= B):
        print('Yes')
        continue
    else:
        s_res = A % B
        s_k = int((C + 1 - s_res - 0.1) // B + 1)
        X = gcd(B, (D%B))
        if X == 1:
            print('No')
            continue
        else:
            s_0 = s_k * B + s_res
            if (s_0 - (C+1)) % X > (B-C-2):
                print('Yes')
            else:
                print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n, m, d = map(int, input().split())

tot = n ** m

if d == 0:
    print((m-1)/n)
else:
    print((m-1) * 2 * (n-d) / n ** 2)


Fixed submission:
n, m, d = map(int, input().split())

if d == 0:
    print((m-1)/n)
else:
    print((m-1) * 2 * (n-d) / n ** 2)

Buggy python submission (verdict: Runtime Error):
n, m, d = map(int, input().split())

tot = n ** m

if d == 0:
    c = n
else:
    c = 2 * (n - d)
   
print(c/(n-1) * ((1 - 1/tot)/(n-1) - m/tot))


Fixed submission:
n, m, d = map(int, input().split())

if d == 0:
    print((m-1)/n)
else:
    print((m-1) * 2 * (n-d) / n ** 2)
Buggy python submission (verdict: Runtime Error):
import heapq
import numpy as np

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

Yen_cost = np.ones((n, n)) * np.inf
Snuuk_cost = np.ones((n, n)) * np.inf

for _ in range(m):
    u, v, a, b = map(int, input().split())
    u -= 1
    v -= 1
    Yen_cost[u, v] = a
    Yen_cost[v, u] = a
    Snuuk_cost[u, v] = b
    Snuuk_cost[v, u] = b


def Digkstra(Cost_list, start):   
    dist = np.ones(n) * np.inf
    dist[start] = 0
    q = []
    heapq.heappush(q, (0, start))

    while len(q) != 0:
        prov_cost, src = heapq.heappop(q)

        if dist[src] < prov_cost:
            continue

        for dest in range(n):
            cost = Cost_list[src, dest]
            if dist[dest] > dist[src] + cost:
                dist[dest] = dist[src] + cost
                heapq.heappush(q, (dist[dest], dest))
    return dist

Yen_dist = Digkstra(Yen_cost, s-1).astype(int)
Snuuk_dist = Digkstra(Snuuk_cost, t-1).astype(int)

First = 10**15
Money = []
Money.append(int(First - Yen_dist[-1] - Snuuk_dist[-1]))
for year in range(n-2, -1, -1):
    temp = First - Yen_dist[year] - Snuuk_dist[year]
    if temp > Money[-1]:
        Money.append(temp)
    else:
        Money.append(Money[-1])

for i in range(n):
    print(Money[-1-i])



Fixed submission:
import heapq

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

Yen_cost = dict([[i, []] for i in range(n)])
Snuuk_cost = dict([[i, []] for i in range(n)])
for _ in range(m):
    u, v, a, b = map(int, input().split())
    u -= 1
    v -= 1
    Yen_cost[u].append((v, a))
    Yen_cost[v].append((u, a))
    Snuuk_cost[u].append((v, b))
    Snuuk_cost[v].append((u, b))

def Digkstra(Cost_dict, start):   
    dist = [float('inf') for _ in range(n)]
    dist[start] = 0
    q = []
    heapq.heappush(q, (0, start))

    while len(q) != 0:
        prov_cost, src = heapq.heappop(q)

        if dist[src] < prov_cost:
            continue

        for dest, cost in Cost_dict[src]:
            if dist[dest] > dist[src] + cost:
                dist[dest] = dist[src] + cost
                heapq.heappush(q, (dist[dest], dest))
    return dist

Yen_dist = Digkstra(Yen_cost, s-1)
Snuuk_dist = Digkstra(Snuuk_cost, t-1)

First = 10**15
Money = []
Money.append(int(First - Yen_dist[-1] - Snuuk_dist[-1]))
for year in range(n-2, -1, -1):
    temp = First - Yen_dist[year] - Snuuk_dist[year]
    if temp > Money[-1]:
        Money.append(temp)
    else:
        Money.append(Money[-1])

for i in range(n):
    print(Money[-1-i])
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from sys import stdin
import math

d_in = lambda: int(stdin.readline())  # N = d_in()


def decimal2bit(n, m):
    """
    nのm進数表現
    """
    order = int(math.log(n, m))
    ans = []
    for i in range(order, -1, -1):
        ans.append(n // (m ** i))
        n -= m ** i * ans[-1]
    return ans


def search(n):
    ans = sum(decimal2bit(n, 6))
    for i in range(1, n // 9 + 1):
        nine = decimal2bit(9 * i, 9)
        six = decimal2bit(n - 9 * i, 6)
        ans = min(ans, sum(nine) + sum(six))
    print(ans)


if __name__ == '__main__':
    N = d_in()
    search(N)

Fixed submission:
# -*- coding: utf-8 -*-
from sys import stdin


d_in = lambda: int(stdin.readline())  # N = d_in()


def get_order(n, m):
    order = 0
    while n > 0:
        n = n // m
        order += 1
    return order


def decimal2bit(n, m):
    """
    nのm進数表現
    """
    if n == 0:
        return []
    order = get_order(n, m)
    ans = []
    for i in range(order, -1, -1):
        ans.append(n // (m ** i))
        n -= m ** i * ans[-1]
    return ans


def search(n):
    ans = float('inf')
    for i in range(n // 9 + 1):
        nine = decimal2bit(9 * i, 9)
        six = decimal2bit(n - 9 * i, 6)
        ans = min(ans, sum(nine) + sum(six))
    print(ans)


if __name__ == '__main__':
    N = d_in()
    search(N)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())

spot = np.array(list(map(int, input().split())))

for i in range(N):
    temp = np.zeros(N)
    temp[1:] = np.delete(spot, i)
    print(int(np.abs(np.roll(temp, 1) - temp).sum()))

Fixed submission:
import numpy as np
import math

N = int(input())

spot = np.zeros(N + 1)
spot[1:] = np.array(list(map(int, input().split())))

tot = int(np.abs(np.roll(spot, 1) - spot).sum())

for i in range(1, N+1):
    print(int(tot - math.fabs(spot[i] - spot[i-1]) - math.fabs(spot[(i+1) % (N+1)] - spot[i])\
            + math.fabs(spot[(i+1) % (N+1)] - spot[i-1])))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from sys import stdin
import bisect
import functools


s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()

ORDER = 28


def under_order(x, n):
    """
    x: int
        target int number

    n: int, [0, 27]
        specific order
    """
    binary = bin(x)[2:]
    # binary = '0' * (ORDER - len(binary)) + binary
    binary = '0' * (28 - len(binary)) + binary
    return int(binary[-n-1:], 2)


def calc_count(b_, a_list_, pow2, N_):
    c1 = bisect.bisect_left(a_list_, pow2 - b_)
    c2 = bisect.bisect_left(a_list_, 2*pow2 - b_)
    c3 = bisect.bisect_left(a_list_, 3*pow2 - b_)
    return N_ - c3 + c2 - c1

N = d_in()
a_list = ds_in()
b_list = ds_in()

a_order_list = []
for i in range(ORDER):
    temp_list = list(map(under_order, a_list, [i] * N))
    temp_list.sort()
    a_order_list.append(temp_list)

temp_list = list(map(under_order, a_list, [ORDER-1] * N))
temp_list.sort()
a_order_list.append(temp_list)


ans = ''
for i in range(ORDER):
    count = list(map(functools.partial(calc_count, a_list_=a_order_list[i],
        pow2=2**i, N_=N), map(functools.partial(under_order, n=i), b_list)))

    if sum(count) % 2 == 1:
        ans += '1'
    else:
        ans += '0'


count = list(map(functools.partial(calc_count, a_list_=a_order_list[-1],
    pow2=2**ORDER, N_=N), b_list))
if sum(count) % 2 == 1:
    ans += '1'
else:
    ans += '0'

print(int(ans[::-1], 2))


Fixed submission:
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np


d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()

ORDER = 28


def np_search(b_list_, a_list_, pow2, N_):
    c1 = np.searchsorted(a_list_, pow2 - b_list_)
    c2 = np.searchsorted(a_list_, 2*pow2 - b_list_)
    c3 = np.searchsorted(a_list_, 3*pow2 - b_list_)
    return N_**2 - c3.sum() + c2.sum() - c1.sum()



N = d_in()
a_list = ds_in()
b_list = ds_in()


np_a = np.array(a_list)
np_b = np.array(b_list)
a_order_list = np.zeros((ORDER, N), dtype=int)
b_order_list = np.zeros((ORDER, N), dtype=int)
for i in range(1, ORDER+1):
    a_order_list[i-1, :] = np_a % 2**i
    b_order_list[i-1, :] = np_b % 2**i

a_order_list.sort(axis=1)

ans = ''
for i in range(ORDER):
    count = np_search(b_list_=b_order_list[i], a_list_=a_order_list[i],
            pow2=2**i, N_=N)
    if count % 2 == 1:
        ans += '1'
    else:
        ans += '0'

count = np_search(b_list_=b_order_list[-1], a_list_=a_order_list[-1],
        pow2=2**ORDER, N_=N)

if count % 2 == 1:
    ans += '1'
else:
    ans += '0'

print(int(ans[::-1], 2))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = []
visited = []
place = 1
for i in range(N):
    a.append(int(input()))
for i in range(N):
    if place in visited:
        print(-1)
        exit()
    elif a[place - 1] == 2:
        print(i + 1)
        exit()
    else:
        visited.append(place)
        place = a[place - 1]

Fixed submission:
N = int(input())
a = []
visited = []
place = 1
for i in range(N):
    a.append(int(input()))
for i in range(N):
    visited.append(place)
    place = a[place - 1]
if 2 in visited:
    print(visited.index(2))
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())
C_arr = np.zeros(N)
B_arr = np.zeros(N)
for i in range(N):
    A, B = map(int, input().split())
    C_arr[i], B_arr[i] = (B-A)%B, B
count = 0
for i in range(N-1, -1, -1):
    count += C_arr[i]
    C_arr[:i] = (C_arr[:i] - C_arr[i]) % B_arr[:i]
print(int(count))


Fixed submission:
N = int(input())

B_list = []
C_list = []
for i in range(N):
    A, B = map(int, input().split())
    B_list.append(B)
    C_list.append((B-A) % B)

count = 0
for i in range(N-1, -1, -1):
    count += (C_list[i] - count) % B_list[i]
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
sum=1
for i in range(n):
    if a[i]==0:
        print(0)
        exit()
    sum*=a[i]
if sum>10**18:
        print(-1) 
        exit()  
print(sum)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
sum=1
check=0
a.sort()

for i in range(n):
    x=a[i]
    if x==0:
        print(0)
        exit()
    if not check==-1:
        sum*=x
        if sum>10**18:
            check=-1
if check==-1:
        print(-1) 
        exit()  
print(sum)
Buggy python submission (verdict: Runtime Error):
import queue
def main():
    n,m=map(int,input().split())
    root=[[0 for i in range(n)] for i in range(n)]
    for i in range(m):
        a,b=map(int,input().split())
        root[a-1][b-1]=1
        root[b-1][a-1]=1
    min=[-1 for i in range(n)]
    min[0]=2
    dict={}
    for i in range(n):
        dict[i]=-1

    start=0
    check=[False]*n
    toVis=queue.Queue()
    check[start]=True
    for i in range(len(root[0])):
        if root[0][i]==1:
            toVis.put(i)
            dict[i]=start
        #   print(i,":",start)
            check[i]=True
    while(toVis.empty()!=True):
        now=toVis.get()
        #print(now)
        check[now]=True
        for i in range(n):
            if root[now][i]==1 and check[i]==False:
                toVis.put(i)
                dict[i]=now
            # print(i,":",now)
                check[i]=True
    #print(dict)  
    for i in range(1,n):
        if dict[i]==-1:
            print("No")
            return 0
    print("Yes")
    for i in range(1,n):
        print(dict[i]+1)         


if __name__=="__main__":
    main()

Fixed submission:
n=input()

if n[-1]=="3":
    print("bon")
elif n[-1]=="0" or n[-1]=="1" or n[-1]=="6" or n[-1]=="8":
    print("pon")
else:
    print("hon")
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k=map(int,input().split())
sum=0
while k>0:
    if a>0:
        sum+=1
        a-=1
        k-=1
    elif b>0:
        sum+=0
        b-=1
        k-=1
    else:
        c-=1
        sum-=1
        k-=1
print(sum)

Fixed submission:
a,b,c,k=map(int,input().split())
sum=0
while k>0:
    if a>0:
        if k>=a:
            sum+=a
            k=k-a
            a=0
        else:
            sum+=k
            k=0

    elif b>0:
        if k>=b:
            sum+=0
            k=k-b
            b=0
        else:
            sum+=0
            k=0
    else:
        sum-=k
        k=0
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
dict={}
for i in range(n):
    dict[i]=a[i]-1 #i番目の町からどこにつくか
tmp=0#現在知
num2city={}
city2num={}
city2num[0]=0#どのまちが何回目か
num2city[0]=0#j回目にどこにいるか
for j in range(1,k+1):
    if tmp==dict[tmp]:
        break
    tmp=dict[tmp]#現在地更新
    if tmp not in num2city.values():#現在地がまだきたことない
        num2city[j]=tmp
        city2num[tmp]=j
    else:
        mae=city2num[tmp]
        term=j-mae 
        res=k-j
        r=res%term
  #      print(mae,term,res,r,mae+r,num2city[mae+r])
        tmp=num2city[mae+r]
 #       print(tmp)
        break
   # print(tmp+1)
    
#print(num2city)
#print(city2num)
print(tmp+1)



Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
dict={}
for i in range(n):
    dict[i]=a[i]-1 #i番目の町からどこにつくか
tmp=0#現在知
num2city={}
city2num={}
city2num[0]=0#どのまちが何回目か
num2city[0]=0#j回目にどこにいるか
alre=[-1]*n
alre[0]=1
for j in range(1,k+1):
    if tmp==dict[tmp]:
        break
    tmp=dict[tmp]#現在地更新
    if alre[tmp]==-1:#tmp not in num2city.values():#現在地がまだきたことない
        alre[tmp]=1
        num2city[j]=tmp
        city2num[tmp]=j
    else:
        mae=city2num[tmp]
        term=j-mae 
        res=k-j
        r=res%term
  #      print(mae,term,res,r,mae+r,num2city[mae+r])
        tmp=num2city[mae+r]
 #       print(tmp)
        break
   # print(tmp+1)
    
#print(num2city)
#print(city2num)
print(tmp+1)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
dict={}
for i in range(n):
    dict[i]=a[i]-1 #i番目の町からどこにつくか
tmp=0#現在知
num2city={}
city2num={}
city2num[0]=0#どのまちが何回目か
num2city[0]=0#j回目にどこにいるか
for j in range(k):
    tmp=dict[tmp]#現在地更新
    if tmp not in num2city.values():#現在地がまだきたことない
        num2city[j]=tmp
        city2num[tmp]=j
    else:
        mae=city2num[tmp]
        term=j-mae 
        res=k-j-1
        r=res%term
        #print(mae,term,res,r)
        temp=num2city[mae+r]
        break
  #  print(tmp+1)
    

print(tmp+1)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
dict={}
for i in range(n):
    dict[i]=a[i]-1 #i番目の町からどこにつくか
tmp=0#現在知
num2city={}
city2num={}
city2num[0]=0#どのまちが何回目か
num2city[0]=0#j回目にどこにいるか
alre=[-1]*n
alre[0]=1
for j in range(1,k+1):
    if tmp==dict[tmp]:
        break
    tmp=dict[tmp]#現在地更新
    if alre[tmp]==-1:#tmp not in num2city.values():#現在地がまだきたことない
        alre[tmp]=1
        num2city[j]=tmp
        city2num[tmp]=j
    else:
        mae=city2num[tmp]
        term=j-mae 
        res=k-j
        r=res%term
  #      print(mae,term,res,r,mae+r,num2city[mae+r])
        tmp=num2city[mae+r]
 #       print(tmp)
        break
   # print(tmp+1)
    
#print(num2city)
#print(city2num)
print(tmp+1)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000000)
s=input()
n=len(s)
def mod10(x):
    p=x//10000000
    q=x-10000000*p
    if p==0:
        return (10**q)%2019
    return ((10**q)*mod10(p))%2019

def T(i):
    if i==n-1:
        return int(s[n-1])
    return T(i+1)+10**(n-1-i)*int(s[i])
dict={}
def modi(i,dict):
    if i in dict.keys():
        return dict[i]
    else:
        if i==n-1:
            dict[i]=int(s[i])
            return int(s[i])
        else:
           # c=modi(i+1,dict)+(10**(n-1-i)*int(s[i]))
            c=modi(i+1,dict)+(mod10(n-1-i)*int(s[i]))
            c=c%2019
            dict[i]=c
            return c

modnum={}
for i in range(n):
    #print(T(i))
    if int(s[i])==0:
        continue
    x=modi(i,dict)
 #   print(T(i),x)
    if x not in modnum.keys():
        modnum[x]=1
    else:
        modnum[x]+=1
sum=0
for md in modnum.keys():
    a=modnum[md]
    if md==0:
        sum+=a
        sum+=-(a*(a-1)//2)
   # print(a*(a-1)//2)
    sum+=a*(a-1)//2
#print(modnum)
print(sum)


Fixed submission:
s,w=map(int,input().split())
if w<s:
    print("safe")
else:
    print("unsafe")
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a,b):
    if a>b:
        r=a%b
        if r==0:
            return b
        return gcd(b,r)
    elif a<b:
        r=b%a
        if r==0:
            return a
        return gcd(a,b%a)
    else:
        return a
k=int(input())
sum=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            sum+=gcd(i,gcd(j,l))
print(sum)


Fixed submission:
def gcd(a,b):
    if a>b:
        r=a%b
        if r==0:
            return b
        return gcd(b,r)
    elif a<b:
        r=b%a
        if r==0:
            return a
        return gcd(a,b%a)
    else:
        return a
k=int(input())
sum=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            sum+=gcd(i,gcd(j,l))
print(sum)
Buggy python submission (verdict: Runtime Error):
x,y,z=input().split()＃これは文字
x=int(x)
y=int(y)
z=int(z)
print(z,x,y)





Fixed submission:
x,y,z=map(int,input().split())
print(z,x,y)