Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from math import floor


def solve(n, m):
    ans = 0
    if m % n == 0:
        ans = m // n
    else:
        factor = [f for f in range(1, floor(m//n)) if m % f == 0]
        if len(factor) > 0:
            ans = factor[-1]
        else:
            ans = 1

    return ans


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve(n, m))


Fixed submission:
from math import floor


def solve(n, m):
    factor = [1]
    if m % n == 0:
        ans = m // n
    else:
        for f in range(floor(m//n), 1,-1):
            if m % f == 0:
                factor.append(f)
                break
        ans = factor[-1]

    return ans


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve(n, m))
Buggy python submission (verdict: Runtime Error):
from math import gcd


def solve(n, ax):
    lcm = 1
    for ai in ax:
        lcm = lcm*ai//gcd(lcm, ai)
    m=lcm-1
    return sum(list(map(lambda x: (lcm-1)%x, ax)))


if __name__ == '__main__':
    n = int(input())
    ax = list(map(int, input().split()))
    print(solve(n, ax))


Fixed submission:
from fractions import gcd


def solve(n, ax):
    lcm = 1
    for ai in ax:
        lcm = lcm*ai//gcd(lcm, ai)
    m = lcm-1
    return sum(list(map(lambda x: m % x, ax)))


if __name__ == '__main__':
    n = int(input())
    ax = list(map(int, input().split()))
    print(solve(n, ax))
Buggy python submission (verdict: Time Limit Exceeded):
def solve(n, ax):
    ans = float('inf')
    substract_ax_from_i = []

    for i in range(n):
        substract_ax_from_i.append(ax[i]-i-1)
    #    print('ax: ', ax[i], 'ax-i: ', ax[i]-i-1)
    substract_ax_from_i.sort()
    #print(substract_ax_from_i)

    for i in substract_ax_from_i:
        list_when_choose_i = list(map(lambda x: abs(x-i), substract_ax_from_i))
        sum_of_list_when_choose_i = sum(list_when_choose_i)
        ans = min(ans, sum_of_list_when_choose_i)
        #print(i, list_when_choose_i, ans)

    return ans


if __name__ == '__main__':
    n = int(input())
    ax = list(map(int, input().split()))
    print(solve(n, ax))


Fixed submission:
import numpy as np


#@profile
def solve(n, ax):
    substract_ax_from_i = []

    for i in range(n):
        substract_ax_from_i.append(ax[i]-i-1)
    substract_ax_from_i.sort()
    med = int(np.median(substract_ax_from_i))
    ans = sum(list(map(lambda x: abs(x-med), substract_ax_from_i)))

    return ans


if __name__ == '__main__':
    n = int(input())
    ax = list(map(int, input().split()))
    print(solve(n, ax))
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
from bisect import bisect_left


def solve(n, h):
    a = []
    b = []

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

    if n == 1:
        ans = ceil((h-b[n-1])/a[n-1])+1

    else:
        over_amax = b[bisect_left(b, a[n-1]):]
        if h <= sum(over_amax):
            ans = len(over_amax)
        else:
            ans = ceil((h - sum(over_amax)) / a[n-1]) + len(over_amax)

    return ans


if __name__ == '__main__':
    n, h = map(int, input().split())
    print(solve(n, h))


Fixed submission:
from math import ceil
from bisect import bisect_left


def solve(n, h):
    a = []
    b = []

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

    amax = max(a)
    b.sort()

    if n == 1:
        ans = ceil((h-b[n-1])/amax)+1

    else:
        over_amax = b[bisect_left(b, amax):]
        if h <= sum(over_amax):
            for j in range(n-1, -1, -1):
                h -= b[j]
                if h <= 0:
                    ans = n-j
                    break

        else:
            ans = ceil((h - sum(over_amax)) / amax) + len(over_amax)

    return ans


if __name__ == '__main__':
    n, h = map(int, input().split())
    print(solve(n, h))

Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil


def solve(n, h):
    a = []
    b = []
    ans = 1

    for i in range(n):
        ai, bi = map(int, input().split())
        a.append(ai)
        b.append(bi)
        a.sort(reverse=True)
        b.sort(reverse=True)

    if n == 1:
        ans += ceil((h-b[0])/a[0])

    else:
        h = h-b[0]
        i = 1
        while 0 < h:
            if i < n and a[0] <= b[i]:
                ans += 1
                h = h-b[i]
                i += 1
            else:
                ans += ceil(h/a[0])
                break

    return ans


if __name__ == '__main__':
    n, h = map(int, input().split())
    print(solve(n, h))


Fixed submission:
from math import ceil
from bisect import bisect_left


def solve(n, h):
    a = []
    b = []

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

    amax = max(a)
    b.sort()

    if n == 1:
        ans = ceil((h-b[n-1])/amax)+1

    else:
        over_amax = b[bisect_left(b, amax):]
        if h <= sum(over_amax):
            for j in range(n-1, -1, -1):
                h -= b[j]
                if h <= 0:
                    ans = n-j
                    break

        else:
            ans = ceil((h - sum(over_amax)) / amax) + len(over_amax)

    return ans


if __name__ == '__main__':
    n, h = map(int, input().split())
    print(solve(n, h))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

n = int(input())
a = list(map(int, sys.stdin.readline().split()))
ans = []
for i in range(n):
    if i % 2 == 0:
        ans.insert(0, a[i])
    else:
        ans.append(a[i])

if len(a) % 2 == 0:
    ans.reverse()
print(' '.join(map(str,ans)))


Fixed submission:
import sys

n = int(input())
a = list(map(int, sys.stdin.readline().split()))

odd = a[1::2]
even = a[0::2]
odd.reverse()
ans = odd+even

if(len(a) % 2 != 0):
    ans.reverse()

print(' '.join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
xs = []
ys = []

for i in range(n):
    x, y = map(int, input().split())
    xs.append((x, i))
    ys.append((y, i))


xs.sort()
ys.sort()

es = []

for i in range(n-1):
    es.append((xs[i+1][0] - xs[i][0], xs[i][1], xs[i+1][1]))
    es.append((ys[i+1][0] - ys[i][0], ys[i][1], ys[i+1][1]))

es.sort()


class UF:
    def __init__(self):
        self.p = {}
    def find(self, x):
        if x not in self.p:
            self.p[x] = x
        if x == self.p[x]:
            return x
        self.p[x] = self.find(self.p[x])
        return self.p[x]
    def merge(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            self.p[x] = y


uf= UF()
ans = 0
for d, i0, i1 in es:
    c0 = uf.find(i0)
    c1 = uf.find(i1)
    if c0 == c1:
        continue
    ans += d
    uf.merge(i0, i1)
print(ans)


Fixed submission:
n = int(input())
xs = []
ys = []

for i in range(n):
    x, y = map(int, input().split())
    xs.append((x, i))
    ys.append((y, i))


xs.sort()
ys.sort()

es = []

for i in range(n-1):
    es.append((xs[i+1][0] - xs[i][0], xs[i][1], xs[i+1][1]))
    es.append((ys[i+1][0] - ys[i][0], ys[i][1], ys[i+1][1]))

es.sort()

class UF:
    def __init__(self):
        self.p = {}
    def find(self, x):
        if x not in self.p:
            self.p[x] = x
        if x == self.p[x]:
            return x
        self.p[x] = self.find(self.p[x])
        return self.p[x]
    def merge(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            self.p[x] = y


uf = UF()
ans = 0
try:
    for d, i0, i1 in es:
        c0 = uf.find(i0)
        c1 = uf.find(i1)
        if c0 == c1:
            continue
        ans += d
        uf.merge(i0, i1)
    print(ans)
except:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
h, w = input().split()
h = int(h)
w = int(w)

n = input()
n = int(n)

an = input().split()
an = [int(a) for a in an]

field = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
    for j in range(w):
        if i % 2 != 0:
            j = -j - 1
        for k in range(n):
            if an[k] > 0:
                an[k] -= 1
                field[i][j] = k+1
                break

for i in range(h):
    output = [str(c) for c in field[i]]
    print(" ".join(output))



Fixed submission:
h, w = input().split()
h = int(h)
w = int(w)

n = input()
n = int(n)

an = input().split()
an = [int(a) for a in an]

field = [[0 for _ in range(w)] for _ in range(h)]

k = 0
for i in range(h):
    for j in range(w):
        if i % 2 != 0:
            j = -j - 1
        if an[k] > 0:
            pass
        else:
            k += 1
        an[k] -= 1
        field[i][j] = k+1

for i in range(h):
    output = [str(c) for c in field[i]]
    print(" ".join(output))
Buggy python submission (verdict: Runtime Error):
a, b, c = int(input())

if b-a == c-b:
    print('YES')
else:
    print('NO')


Fixed submission:
a, b, c = [int(i) for i in input().split(' ')]

if b-a == c-b:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
from math import factorial as fc

N,K = map(int,input().split())

for i in range(1,K+1):
    bunbo = fc(i)*fc(N-K+1-i)*fc(i-1)*fc(K-i)
    bunsi = fc(N-K+1)*fc(K-1)
    print(bunsi//bunbo)

Fixed submission:
from math import factorial as fc

N,K = map(int,input().split())
MOD = (10 ** 9)+ 7

for i in range(1,K+1):
    if N-K+1<i:
        print(0)
        continue
    bunbo = fc(i)*fc(N-K+1-i)*fc(i-1)*fc(K-i)
    bunsi = fc(N-K+1)*fc(K-1)
    print((bunsi//bunbo)%MOD)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

N = int(input())

D = defaultdict(list) 
S = defaultdict(lambda: -1) #STEPD
R = defaultdict(int) #ROOT
for i in range(N-1):
    u,v,w = map(int,input().split())
    D[u].append(v)
    D[v].append(u)
    R["{}-{}".format(u,v)] = w
    
T = [(1,0)]
S[n] = 0
while T:
    n,w = T.pop()
    for d in D[n]:
        wr = R["{}-{}".format(n,d)]
        if S[d]>=0:continue
        else: S[d] = (w+wr)%2
        T.append((d,(w+wr)%2))
        
for k in sorted(S.keys()):
    print(S[k])

Fixed submission:
from collections import defaultdict

N = int(input())

D = defaultdict(list) 
S = {} #STEPD
for i in range(1,N+1):S[i] = -1
R = defaultdict(int) #ROOT
for i in range(N-1):
    u,v,w = map(int,input().split())
    D[u].append(v)
    D[v].append(u)
    R["{}-{}".format(u,v)] = w
    R["{}-{}".format(v,u)] = w
    
T = [(1,0)]
S[1] = 0
while T:
    n,w = T.pop()
    for d in D[n]:
        wr = R["{}-{}".format(n,d)]
        if S[d]>=0:continue
        else: S[d] = (w+wr)%2
        T.append((d,(w+wr)%2))
        
for k in range(1,N+1):
    print(S[k] if S[k]>=0 else 0)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())

S = input()

C = []

one = True
c = 0
ans = 0
for s in S:
    if s=="0":
        if one:
            one = False
            C.append(c)
            c = 1
        else:
            c += 1
    else:
        if one:
            c += 1
        else:
            one = True
            C.append(c)
            c = 1
            
C.append(c)
CC = []
for i in range(0,max(min(N-K,len(C)),1))[::2]:
    CC.append(sum(C[i:i+(2*K)+1]))
    
print(max(CC))

Fixed submission:
from queue import Queue as q

N,K = map(int,input().split())

S = input()

C = q()

one = True
subK = 0
c = 0
ans = 0
Mans = 0
for s in S:
    if s=="1":
        if one:
            c += 1
        else:
            one = True
            C.put(c)
            c = 1
    else:
        if one:
            one = False
            subK += 1
            C.put(c)
            c = 1
        else:
            c += 1
    ans += 1
    if subK>K:
        subK -= 1
        ans -= (C.get()+C.get())
    #print(ans)
    if ans > Mans:
        Mans = ans
    
print(Mans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

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

A = defaultdict(list)
D = defaultdict(list)
DLen = defaultdict(int)
R = [i for i in range(1,N+1)]
for i in range(N+M-1):
    a,b = map(int,input().split())
    A[a].append(b)
    D[b].append(a)
    DLen[b] += 1
    try:
        R.remove(b)
    except ValueError:
        pass
    
D[R[0]].append(0)
Search = [(R[0],A[R[0]])]
Stepd = [R[0]]

while Search:
    now,NEX = Search.pop()
    for s in NEX:
        if DLen[s]>=2:
            DLen[s] -= 1
        else:
            D[s] = [now]
            Stepd.append(s)
            Search.append((s,A[s]))
            
for i in range(1,N+1):
    print(D[i][0])

Fixed submission:
from collections import defaultdict
from collections import Counter

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

A = defaultdict(list)
D = defaultdict(list)
DLen = defaultdict(int)
for i in range(N+M-1):
    a,b = map(int,input().split())
    A[a].append(b)
    #D[b].append(a)
    DLen[b] += 1

start = 0
for i in range(1,N+1):
    if DLen[i] == 0:
        start = i
        break
        
D[start].append(0)
Search = [(start,A[start])]
Stepd = [start]

while Search:
    now,NEX = Search.pop()
    for s in NEX:
        if DLen[s]>=2:
            DLen[s] -= 1
        else:
            D[s] = [now]
            Stepd.append(s)
            Search.append((s,A[s]))
            
for i in range(1,N+1):
    print(D[i][0])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

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

A = defaultdict(list)
D = defaultdict(list)
R = [i for i in range(1,N+1)]
for i in range(N+M-1):
    a,b = map(int,input().split())
    A[a].append(b)
    D[b].append(a)
    try:
        R.remove(b)
    except ValueError:
        pass
    
D[R[0]].append(0)
Search = [(R[0],A[R[0]])]
Stepd = [R[0]]

while Search:
    now,NEX = Search.pop()
    for s in NEX:
        if len(D[s])>=2:
            D[s].remove(now)
        else:
            Stepd.append(s)
            Search.append((s,A[s]))
            
for i in range(1,N+1):
    print(D[i][0])

Fixed submission:
from collections import defaultdict
from collections import Counter

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

A = defaultdict(list)
D = defaultdict(list)
DLen = defaultdict(int)
for i in range(N+M-1):
    a,b = map(int,input().split())
    A[a].append(b)
    #D[b].append(a)
    DLen[b] += 1

start = 0
for i in range(1,N+1):
    if DLen[i] == 0:
        start = i
        break
        
D[start].append(0)
Search = [(start,A[start])]
Stepd = [start]

while Search:
    now,NEX = Search.pop()
    for s in NEX:
        if DLen[s]>=2:
            DLen[s] -= 1
        else:
            D[s] = [now]
            Stepd.append(s)
            Search.append((s,A[s]))
            
for i in range(1,N+1):
    print(D[i][0])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=True)
B = sorted(list(map(int,input().split())),reverse=True)
mod = pow(10,9)+7

n,m = 0,0
ans = 1

def istwo(L):
    if len(list(filter(lambda x:x>1,Counter(L).values())))>0:
        return True
    else:
        return False

if istwo(A) or istwo(B):
    print(0)
else:
    for i in range(1,(N*M)+1)[::-1]:
        if n<N and i<=A[n]:n+=1
        if m<M and i<=B[m]:m+=1
        if i in A and i in B:
            ans = ans%mod
        elif i in A:
            ans = (ans*(m))%mod
        elif i in B:
            ans = (ans*(n))%mod
        else:
            ans = (ans*(n*m-(N*M-i)))%mod
        #print(i,n,m,ans)
    print(ans)

Fixed submission:
from collections import Counter

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=True)
B = sorted(list(map(int,input().split())),reverse=True)
mod = pow(10,9)+7

n,m = 0,0
ans = 1

def istwo(L):
    if len(list(filter(lambda x:x>1,Counter(L).values())))>0:
        return True
    else:
        return False

if istwo(A) or istwo(B):
    print(0)
else:
    for i in range(1,(N*M)+1)[::-1]:
        if n<N and i<=A[n]:n+=1
        if m<M and i<=B[m]:m+=1
        if n>0 and m>0 and i == A[n-1] and i == B[m-1]:
            ans = ans%mod
        elif n>0 and i == A[n-1]:
            ans = (ans*(m))%mod
        elif m>0 and i == B[m-1]:
            ans = (ans*(n))%mod
        else:
            ans = (ans*(n*m-(N*M-i)))%mod
        #print(i,n,A[n-1],m,B[m-1],ans)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

S = input()
T = input()

AS = defaultdict(list)
AT = defaultdict(list)

isok = True
for i in range(len(S)):
    AS[S[i]].append(i)
    AT[T[i]].append(i)
    if AS[S[i]]!=AT[T[i]]:
        isok = False
        break
        
if isok:
    print("Yes")
else:
    print("No")

Fixed submission:
from collections import defaultdict

S = input()
T = input()

A = {}
B = {}

isok = True
for i in range(len(S)):
    if S[i] in A:
        if T[i] != A[S[i]]:
            isok = False
            break
    else:
        A[S[i]] = T[i]
    if T[i] in B:
        if S[i] != B[T[i]]:
            isok = False
            break
    else:
        B[T[i]] = S[i]
        
if isok:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

S = input()
T = input()

AS = defaultdict(list)
AT = defaultdict(list)

for i in range(len(S)):
    AS[S[i]].append(i)
    AT[T[i]].append(i)
    
isok = True
for i in range(len(S)):
    if AS[S[i]]!=AT[T[i]]:
        isok = False
        break
        
if isok:
    print("Yes")
else:
    print("No")

Fixed submission:
from collections import defaultdict

S = input()
T = input()

A = {}
B = {}

isok = True
for i in range(len(S)):
    if S[i] in A:
        if T[i] != A[S[i]]:
            isok = False
            break
    else:
        A[S[i]] = T[i]
    if T[i] in B:
        if S[i] != B[T[i]]:
            isok = False
            break
    else:
        B[T[i]] = S[i]
        
if isok:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
from math import gcd

N,X = map(int,input().split())

A = sorted(list(map(int,input().split()))+[X])

B = []
for i in range(len(A)-1):
    B.append(A[i+1]-A[i])

G = B[0]
if G>1:
    for b in B[1:]:
        G = gcd(G,b)
        if G==1:break
            
print(G)

Fixed submission:
from fractions import gcd

N,X = map(int,input().split())

A = sorted(list(map(int,input().split()))+[X])

B = []
for i in range(len(A)-1):
    B.append(A[i+1]-A[i])

G = B[0]
if G>1:
    for b in B[1:]:
        G = gcd(G,b)
        if G==1:break
            
print(G)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
N,M = map(int,input().split())

D = defaultdict(lambda: N+1)
for i in range(M):
    a,b = map(int,input().split())
    if b<D[a]:D[a]=b
        
side_b = []
ans = 0
for i in range(1,N+1):
    if i in side_b:
        side_b = []
        ans += 1
    side_b.append(D[i])
    #print(i,side_b)
    
print(ans)

Fixed submission:
from collections import defaultdict
N,M = map(int,input().split())

D = defaultdict(lambda: N+1)
for i in range(M):
    a,b = map(int,input().split())
    if b<D[a]:D[a]=b
        
side_b_min = N+1
ans = 0
for i in range(1,N+1):
    if i == side_b_min:
        side_b_min = N+1
        ans += 1
    if D[i] < side_b_min: side_b_min = D[i]
    #print(i,side_b_min)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
SNK = [1,2,3,4,5,6,7,8,9] #1桁目

for i in range(1,10): SNK.append((i*10)+9) #2桁目
for i in range(1,10): SNK.append((i*100)+99) #3桁目

for j in range(9): #4-12桁目
    SNK_sub = [19,29,39,49,59,69,79,89,99]
    SNK_sub = list(map(lambda x:(x*pow(10,2+j))+(pow(10,2+j)-1),SNK_sub))
    for i in range(10,20+(10*j)):
        SNK.append(i*pow(10,2+j)+(pow(10,2+j)-1))
    SNK += SNK_sub[j+1:]
    
for j in range(3): #13,14桁目
    for i in range(10,100):
        SNK.append(i*pow(10,10+j)+(pow(10,10+j)-1))

K = int(input())

for i in range(K):
    print(SNK[i])

Fixed submission:
LEN = 0

SNK = [1,2,3,4,5,6,7,8,9]
#SNK.append("SUNUKE!:"+str(1))
LEN +=1

for i in range(1,10): SNK.append(i*10+9)
#SNK.append("SUNUKE!:"+str(2))
LEN +=1

#for i in range(1,10): SNK.append(i*100+99)
#SNK.append("SUNUKE!:"+str(3))
LEN +=1

for loop in range(2):
    SNK_sub = list(range(pow(10,loop),pow(10,loop+1)))
    SNK += list(map(lambda x:(x*pow(10,LEN-1))+(pow(10,LEN-1)-1),SNK_sub))
    LEN += len(str(max(SNK_sub)))-1
    for d in SNK_sub: #loop=0のとき，d=1-9
        SNK += [(i*pow(10,LEN-1))+(pow(10,LEN-1)-1) for i in range(10,10*(d+1))]
        SNK += list(map(lambda x:(x*pow(10,LEN))+(pow(10,LEN)-1),SNK_sub[SNK_sub.index(d)+1:]))
        #SNK.append("SUNUKE!:"+str(LEN+3))
        LEN += 1+loop
        if LEN>20:break

print("\n".join(str(i) for i in SNK[:int(input())]))

Buggy python submission (verdict: Runtime Error):
SNK = [1,2,3,4,5,6,7,8,9] #1桁目

for i in range(1,10): SNK.append((i*10)+9) #2桁目
for i in range(1,10): SNK.append((i*100)+99) #3桁目

for j in range(9): #4-12桁目
    SNK_sub = [19,29,39,49,59,69,79,89,99]
    SNK_sub = list(map(lambda x:(x*pow(10,2+j))+(pow(10,2+j)-1),SNK_sub))
    for i in range(10,20+(10*j)):
        SNK.append(i*pow(10,2+j)+(pow(10,2+j)-1))
    SNK += SNK_sub[j+1:]
    
for j in range(2): #13,14桁目
    for i in range(10,100):
        SNK.append(i*pow(10,10+j)+(pow(10,10+j)-1))

K = int(input())

for i in range(K):
    print(SNK[i])

Fixed submission:
LEN = 0

SNK = [1,2,3,4,5,6,7,8,9]
#SNK.append("SUNUKE!:"+str(1))
LEN +=1

for i in range(1,10): SNK.append(i*10+9)
#SNK.append("SUNUKE!:"+str(2))
LEN +=1

#for i in range(1,10): SNK.append(i*100+99)
#SNK.append("SUNUKE!:"+str(3))
LEN +=1

for loop in range(2):
    SNK_sub = list(range(pow(10,loop),pow(10,loop+1)))
    SNK += list(map(lambda x:(x*pow(10,LEN-1))+(pow(10,LEN-1)-1),SNK_sub))
    LEN += len(str(max(SNK_sub)))-1
    for d in SNK_sub: #loop=0のとき，d=1-9
        SNK += [(i*pow(10,LEN-1))+(pow(10,LEN-1)-1) for i in range(10,10*(d+1))]
        SNK += list(map(lambda x:(x*pow(10,LEN))+(pow(10,LEN)-1),SNK_sub[SNK_sub.index(d)+1:]))
        #SNK.append("SUNUKE!:"+str(LEN+3))
        LEN += 1+loop
        if LEN>20:break

print("\n".join(str(i) for i in SNK[:int(input())]))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

ans = 0

for i in range(N):
    C = np.cumsum(A[i:])
    ans +=len(C[C==0])

print(ans)

Fixed submission:
from collections import defaultdict

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

C = defaultdict(int)

ans = 0
sumA = 0
for a in A:
    sumA += a
    C[sumA] += 1
    if C[sumA] >=2:
        ans += C[sumA]-1
        
for i in range(1,C[0]+1): ans+= 1
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

C = []
ans = 0
for i in range(N):
    C.append(0)
    C = list(map(lambda x:x+A[i],C))
    ans += len(list(filter(lambda x:x==0,C)))
    
print(ans)

Fixed submission:
from collections import defaultdict

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

C = defaultdict(int)

ans = 0
sumA = 0
for a in A:
    sumA += a
    C[sumA] += 1
    if C[sumA] >=2:
        ans += C[sumA]-1
        
for i in range(1,C[0]+1): ans+= 1
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

C = []
for i in range(N):
    C.append(sum(A[i:]))
    
ans = len(list(filter(lambda x:x==0,C)))

for j in range(0,N)[::-1]:
    C = list(map(lambda x:x-A[j],C))[:j]
    ans += len(list(filter(lambda x:x==0,C)))
    
print(ans)

Fixed submission:
from collections import defaultdict

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

C = defaultdict(int)

ans = 0
sumA = 0
for a in A:
    sumA += a
    C[sumA] += 1
    if C[sumA] >=2:
        ans += C[sumA]-1
        
for i in range(1,C[0]+1): ans+= 1
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

ans = 0
for i in range(N):
    for j in range(i+1,N+1):
        if sum(A[i:j])==0:
            ans+=1
            
print(ans)

Fixed submission:
from collections import defaultdict

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

C = defaultdict(int)

ans = 0
sumA = 0
for a in A:
    sumA += a
    C[sumA] += 1
    if C[sumA] >=2:
        ans += C[sumA]-1
        
for i in range(1,C[0]+1): ans+= 1
    
print(ans)