Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
import functools

def lcm(a,b):
    return  a*b/math.gcd(a,b)
    
n=int(input())
t=[int(input()) for i in range(n)]
if n==1:
    print(t[0])
else:
    anser=1
    for i in t:
        anser=lcm(anser,i)
    print(anser)

Fixed submission:
def gcd(a,b):
    r=a%b
    while r!=0:
        a=b
        b=r
        r=a%b
    return b

def lcm(a,b):
    return  a*b//gcd(a,b)
    
n=int(input())
t=[int(input()) for i in range(n)]

anser=1
for i in t:
    anser=lcm(anser,i)
print(anser)

Buggy python submission (verdict: Runtime Error):
import math
import functools

def lcm(a,b):
    return  int(a*b/math.gcd(a,b))
    
n=int(input())
t=[int(input()) for i in range(n)]
if n==1:
    print(t[0])
else:
    anser=1
    for i in t:
        anser=lcm(anser,i)
    print(anser)

Fixed submission:
def gcd(a,b):
    r=a%b
    while r!=0:
        a=b
        b=r
        r=a%b
    return b

def lcm(a,b):
    return  a*b//gcd(a,b)
    
n=int(input())
t=[int(input()) for i in range(n)]

anser=1
for i in t:
    anser=lcm(anser,i)
print(anser)

Buggy python submission (verdict: Runtime Error):
import math
import functools

def lcm(a,b):
    return  int(a*b/math.gcd(a,b))
    
n=int(input())
t=[int(input()) for i in range(n)]
if n==1:
    print(t[0])
else:
    print(functools.reduce(lcm,t))

Fixed submission:
def gcd(a,b):
    r=a%b
    while r!=0:
        a=b
        b=r
        r=a%b
    return b

def lcm(a,b):
    return  a*b//gcd(a,b)
    
n=int(input())
t=[int(input()) for i in range(n)]

anser=1
for i in t:
    anser=lcm(anser,i)
print(anser)

Buggy python submission (verdict: Runtime Error):
import math
import functools

def lcm(a,b):
    return  int(a*b/math.gcd(a,b))
    
n=int(input())
t=[int(input()) for i in range(n)]
if n==1:
    print(t[0])
else:
    print(functools.reduce(lcm,t))

Fixed submission:
def gcd(a,b):
    r=a%b
    while r!=0:
        a=b
        b=r
        r=a%b
    return b

def lcm(a,b):
    return  a*b//gcd(a,b)
    
n=int(input())
t=[int(input()) for i in range(n)]

anser=1
for i in t:
    anser=lcm(anser,i)
print(anser)

Buggy python submission (verdict: Runtime Error):
import math
import functools

def lcm(a,b):
    return  int(a*b/math.gcd(a,b))
    
N=int(input())
t=[int(input()) for i in range(N)]

print(functools.reduce(lcm,t))

Fixed submission:
def gcd(a,b):
    r=a%b
    while r!=0:
        a=b
        b=r
        r=a%b
    return b

def lcm(a,b):
    return  a*b//gcd(a,b)
    
n=int(input())
t=[int(input()) for i in range(n)]

anser=1
for i in t:
    anser=lcm(anser,i)
print(anser)
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())

sum  =0


for i in range(1,N):
    sum += i
    if sum>=N:
        break

for j in range(1,i+1):
    if j == sum-N:
        continue
    print(j)

Fixed submission:
N = int(input())

sum = 0

if N <= 2:
    print(N)
else:

    for i in range(1, N):
        sum += i
        if sum >= N:
            break

    for j in range(1, i + 1):
        if j == sum - N:
            continue
        print(j)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 1000000007

dp = [[0] * (K+10) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for j in range(K,-1,-1):
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= MOD
        if j + A[i] + 1 <= K+1:
            dp[i+1][j+A[i]+1] = (dp[i+1][j+A[i]+1] - dp[i][j] + MOD) % MOD
    
    for j in range(K+1):
        dp[i+1][j+1] += dp[i+1][j]
        dp[i+1][j+1] %= MOD

print(dp[N][K])


Fixed submission:
N,K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 1000000007

dp = [[0] * (K+10) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for j in range(K,-1,-1):
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= MOD
        if j + A[i] + 1 <= K+1:
            dp[i+1][j+A[i]+1] = (dp[i+1][j+A[i]+1] - dp[i][j] + MOD) % MOD
    
    for j in range(K+1):
        dp[i+1][j+1] += dp[i+1][j]
        dp[i+1][j+1] %= MOD

print(dp[N][K])

Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split())
A = list(map(int, input().split()))

dp = [[0] * (K+10) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for j in range(K,0,-1):
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= MOD
        if j + a[i] + 1 <= K+1:
            dp[i+1][j+a[i]+1] = (dp[i+1][j+a[i]+1] - dp[i][j] + MOD) % MOD
    
    for j in range(K+1):
        dp[i+1][j+1] += dp[i+1][j]
        dp[i+1][j+1] %= MOD

print(dp[N][K])


Fixed submission:
N,K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 1000000007

dp = [[0] * (K+10) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for j in range(K,-1,-1):
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= MOD
        if j + A[i] + 1 <= K+1:
            dp[i+1][j+A[i]+1] = (dp[i+1][j+A[i]+1] - dp[i][j] + MOD) % MOD
    
    for j in range(K+1):
        dp[i+1][j+1] += dp[i+1][j]
        dp[i+1][j+1] %= MOD

print(dp[N][K])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
S = list(raw_input())

ans = N
for i in range(N):
    left = S[:i].count('W')
    right = S[i:].count('E')
    ans = min(ans, left+right)

print(ans)

Fixed submission:
N = int(raw_input())
S = list(raw_input())

ans = N
min_ans = N
for i in range(N):
    if i == 0:
        ans = S[1:].count('E')
        min_ans = ans
    else:
        if S[i-1] == 'W':
            ans += 1
        if S[i] == 'E':
            ans -= 1
        min_ans = min(min_ans, ans)

print(min_ans)
Buggy python submission (verdict: Time Limit Exceeded):
def calc(A,i,j):
    num_2 = 0
    num_10 = 0
    for k in range(i,j+1):
        num_2 = A[k] ^ num_2
        num_10 = num_10 + A[k]
    if num_10 == int(num_2):
        return True
    else:
        return False

if __name__ == '__main__':
    N = int(raw_input())
    A = map(int, raw_input().split())

    ans = 0
    for i in range(N):
        for j in range(i,N):
            if calc(A,i,j) == True:
                ans += 1
            else:
                break

    print(ans)

Fixed submission:
if __name__ == '__main__':
    N = int(raw_input())
    A = map(int, raw_input().split())
    head = 0
    tail = 0
    num_2 = 0
    num_10 = 0
    ans = 0
    now_len = 0
    while(head < N):
        num_2 = num_2 ^ A[head]
        num_10 += A[head]
        if num_2 == num_10:
            head += 1
            now_len += 1
            ans += now_len
        else:
            num_2 ^= A[tail]
            num_10 -= A[tail]
            num_2 ^= A[head]
            num_10 -= A[head]
            tail += 1
            now_len -= 1

    print(ans)
Buggy python submission (verdict: Runtime Error):
s = raw_input()
K = int(raw_input())

arr = []
for i in range(len(s)):
    for j in  range(len(s) + 1):
        arr.append(s[i:i+j])
arr = list(set(arr))
arr.remove('')
arr = sorted(arr)
print(arr[K - 1])

Fixed submission:
s = raw_input()
K = int(raw_input())

arr = []
length = min(5, len(s))
for i in range(len(s)):
    for j in  range(length + 1):
        arr.append(s[i:i+j])
arr = list(set(arr))
arr.remove('')
arr = sorted(arr)
print(arr[K - 1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
N = int(raw_input())
nums = map(int, raw_input().split())
for i in range(N):
    nums_tmp = nums[0:i] + nums[i+1:N]
    nums_tmp = np.array(nums_tmp)
    print(int(np.median(nums_tmp)))
sys.exit()
num_t = []
index_t = []
for i,num in enumerate(nums):
    num_t.append([num, i])
num_t = sorted(num_t, key=lambda x: x[0])
for a in num_t:
    index_t.append(a[1])
for i in range(N):
    num_tmp = num_t
    idx = index_t.index(i)
    num_tmp = num_tmp[0:idx] + num_tmp[idx+1:N]
    print(num_tmp[(N/2) - 1][0])

Fixed submission:
N = int(raw_input())
nums = map(int, raw_input().split())
num_tmp = []
for a in nums:
    num_tmp.append(a)
nums.sort()
med_1 = nums[N/2 - 1]
med_2 = nums[N/2]
for i in range(N):
    if num_tmp[i] <= med_1:
        print(med_2)
    elif num_tmp[i] >= med_2:
        print(med_1)

Buggy python submission (verdict: Runtime Error):
from statistics import mean, median,variance,stdev
import sys
N = int(raw_input())
nums = map(int, raw_input().split())
for i in range(N):
    nums_tmp = nums[0:i] + nums[i+1:N]
    print(median(nums_tmp))
sys.exit()
num_t = []
index_t = []
for i,num in enumerate(nums):
    num_t.append([num, i])
num_t = sorted(num_t, key=lambda x: x[0])
for a in num_t:
    index_t.append(a[1])
for i in range(N):
    num_tmp = num_t
    idx = index_t.index(i)
    num_tmp = num_tmp[0:idx] + num_tmp[idx+1:N]
    print(num_tmp[(N/2) - 1][0])

Fixed submission:
N = int(raw_input())
nums = map(int, raw_input().split())
num_tmp = []
for a in nums:
    num_tmp.append(a)
nums.sort()
med_1 = nums[N/2 - 1]
med_2 = nums[N/2]
for i in range(N):
    if num_tmp[i] <= med_1:
        print(med_2)
    elif num_tmp[i] >= med_2:
        print(med_1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
nums = map(int, raw_input().split())
num_t = []
index_t = []
for i,num in enumerate(nums):
    num_t.append([num, i])
num_t = sorted(num_t, key=lambda x: x[0])
for a in num_t:
    index_t.append(a[1])
for i in range(N):
    num_tmp = num_t
    idx = index_t.index(i)
    num_tmp = num_tmp[0:idx] + num_tmp[idx+1:N]
    print(num_tmp[(N/2) - 1][0])



Fixed submission:
N = int(raw_input())
nums = map(int, raw_input().split())
num_tmp = []
for a in nums:
    num_tmp.append(a)
nums.sort()
med_1 = nums[N/2 - 1]
med_2 = nums[N/2]
for i in range(N):
    if num_tmp[i] <= med_1:
        print(med_2)
    elif num_tmp[i] >= med_2:
        print(med_1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())
nums = map(int, raw_input().split())
num_t = []
for i,num in enumerate(nums):
    num_t.append([num, i])
num_t = sorted(num_t, key=lambda x: x[0])
for i in range(N):
    num_tmp = num_t
    for j, a in enumerate(num_tmp):
        if a[1] == i:
            num_tmp = num_tmp[0:j] + num_tmp[j+1:N]
    print(num_tmp[(N/2) - 1][0])

Fixed submission:
N = int(raw_input())
nums = map(int, raw_input().split())
num_tmp = []
for a in nums:
    num_tmp.append(a)
nums.sort()
med_1 = nums[N/2 - 1]
med_2 = nums[N/2]
for i in range(N):
    if num_tmp[i] <= med_1:
        print(med_2)
    elif num_tmp[i] >= med_2:
        print(med_1)
Buggy python submission (verdict: Runtime Error):
A,B,K = map(int, raw_input().split())
  
for i in range(B+1):
    if i >= A and i <= A + K - 1:
        print(i)
    elif (i >= A and i >= B - K + 1 and i <= B):
        print(i)

Fixed submission:
A,B,K = map(int, raw_input().split())
  
for i in range(K):
    if A + i >= A and A + i <= B:
        print(A + i)
for i in range(K):
    if B - K + 1 + i >= A and B - K + 1 + i <= B and B - K + 1 + i > A + K -1:
        print(B - K + 1 + i)

Buggy python submission (verdict: Runtime Error):
A,B,K = map(int, raw_input().split())
  
for i in range(B+1):
    if (i >= A and i <= A + K - 1) or (i >= B - K + 1 and i <= B):
        print(i)

Fixed submission:
A,B,K = map(int, raw_input().split())
  
for i in range(K):
    if A + i >= A and A + i <= B:
        print(A + i)
for i in range(K):
    if B - K + 1 + i >= A and B - K + 1 + i <= B and B - K + 1 + i > A + K -1:
        print(B - K + 1 + i)

Buggy python submission (verdict: Runtime Error):
A,B,K = map(int, raw_input().split())
  
for i in range(A,B+1):
    #if (i >= A and i <= A + K - 1) or (i >= B - K + 1 and i <= B):
    print(i)



Fixed submission:
A,B,K = map(int, raw_input().split())
  
for i in range(K):
    if A + i >= A and A + i <= B:
        print(A + i)
for i in range(K):
    if B - K + 1 + i >= A and B - K + 1 + i <= B and B - K + 1 + i > A + K -1:
        print(B - K + 1 + i)

Buggy python submission (verdict: Runtime Error):
A,B,K = map(int, raw_input().split())
  
for i in range(A,B+1):
    if (i >= A and i <= A + K - 1) or (i >= B - K + 1 and i <= B):
        print(i)
        

Fixed submission:
A,B,K = map(int, raw_input().split())
  
for i in range(K):
    if A + i >= A and A + i <= B:
        print(A + i)
for i in range(K):
    if B - K + 1 + i >= A and B - K + 1 + i <= B and B - K + 1 + i > A + K -1:
        print(B - K + 1 + i)

Buggy python submission (verdict: Runtime Error):
A,B,K = map(int, raw_input().split())
  
for i in range(A,B+1):
    if (i >= A and i <= A + K - 1) or (i >= B - K + 1 and i <= B):
        print(i)

Fixed submission:
A,B,K = map(int, raw_input().split())
  
for i in range(K):
    if A + i >= A and A + i <= B:
        print(A + i)
for i in range(K):
    if B - K + 1 + i >= A and B - K + 1 + i <= B and B - K + 1 + i > A + K -1:
        print(B - K + 1 + i)
Buggy python submission (verdict: Runtime Error):
a = []
for i in range(4):
  a.append(input())
print(min(a[0],a[1]) + min(a[2],a[3])

Fixed submission:
a = []
for i in range(4):
    a.append(input())
print(min(a[0],a[1]) + min(a[2],a[3]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

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

seg_el=1<<((N+1).bit_length()) # Segment treeの台の要素数

SEG=[N-2]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
SEG2=[N-2]*(2*seg_el)

def getvalue(n,seg_el): # 一点の値を取得
    i=n+seg_el
    ANS=N-2
    
    ANS=min(SEG[i],ANS)
    i>>=1# 子ノードへ
    
    while i!=0:
        ANS=min(SEG[i],ANS)
        i>>=1

    return ANS

def getvalue2(n,seg_el): # 一点の値を取得
    i=n+seg_el
    ANS=N-2
    
    ANS=min(SEG2[i],ANS)
    i>>=1# 子ノードへ
    
    while i!=0:
        ANS=min(SEG2[i],ANS)
        i>>=1

    return ANS

def updates(l,r,x): # 区間[l,r)のminを更新.
    L=l+seg_el
    R=r+seg_el

    while L<R:
        if L & 1:
            SEG[L]=min(x,SEG[L])
            L+=1

        if R & 1:
            R-=1
            SEG[R]=min(x,SEG[R])
        L>>=1
        R>>=1

def updates2(l,r,x): # 区間[l,r)のminを更新.
    L=l+seg_el
    R=r+seg_el

    while L<R:
        if L & 1:
            SEG2[L]=min(x,SEG2[L])
            L+=1

        if R & 1:
            R-=1
            SEG2[R]=min(x,SEG2[R])
        L>>=1
        R>>=1

ANS=(N-2)*(N-2)

MINX=N
MINY=N

for queries in range(Q):
    t,x=map(int,input().split())

    if t==1:
        v=getvalue(x,seg_el)
        ANS-=v
        updates2(1,MINY,x-2)
        MINX=min(MINX,x)

    else:
        v=getvalue2(x,seg_el)
        ANS-=v
        updates(1,MINX,x-2)
        MINY=min(MINY,x)

print(ANS)

Fixed submission:
import sys
input = sys.stdin.readline

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

seg_el=1<<((N+1).bit_length()) # Segment treeの台の要素数

SEG=[N-2]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
SEG2=[N-2]*(2*seg_el)

def getvalue(n,seg_el): # 一点の値を取得
    i=n+seg_el
    ANS=N-2
    
    ANS=min(SEG[i],ANS)
    i>>=1# 子ノードへ
    
    while i!=0:
        ANS=min(SEG[i],ANS)
        i>>=1

    return ANS

def getvalue2(n,seg_el): # 一点の値を取得
    i=n+seg_el
    ANS=N-2
    
    ANS=min(SEG2[i],ANS)
    i>>=1# 子ノードへ
    
    while i!=0:
        ANS=min(SEG2[i],ANS)
        i>>=1

    return ANS

def updates(l,r,x): # 区間[l,r)のminを更新.
    L=l+seg_el
    R=r+seg_el

    while L<R:
        if L & 1:
            SEG[L]=min(x,SEG[L])
            L+=1

        if R & 1:
            R-=1
            SEG[R]=min(x,SEG[R])
        L>>=1
        R>>=1

def updates2(l,r,x): # 区間[l,r)のminを更新.
    L=l+seg_el
    R=r+seg_el

    while L<R:
        if L & 1:
            SEG2[L]=min(x,SEG2[L])
            L+=1

        if R & 1:
            R-=1
            SEG2[R]=min(x,SEG2[R])
        L>>=1
        R>>=1

ANS=(N-2)*(N-2)

MINX=N
MINY=N

for queries in range(Q):
    t,x=map(int,input().split())

    if t==1:
        v=getvalue(x,seg_el)
        ANS-=v
        updates2(1,MINY,x-2)
        MINX=min(MINX,x)

    else:
        v=getvalue2(x,seg_el)
        ANS-=v
        updates(1,MINX,x-2)
        MINY=min(MINY,x)

print(ANS)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

H,W,M=map(int,input().split())
B=set([tuple(map(int,input().split())) for i in range(M)])

HH=[0]*(H+1)
WW=[0]*(W+1)

for x,y in B:
    HH[x]+=1
    WW[y]+=1

MAXH=max(HH)
MAXW=max(WW)

ANS=MAXH+MAXW-1

for i in range(1,H+1):
    if HH[i]!=MAXH:
        continue
    for j in range(1,W+1):
        if WW[j]!=MAXW:
            continue

        if (i,j) in B:
            continue
        else:
            print(ANS+1)
            sys.exit()
print(ANS)

        


Fixed submission:
import sys
input = sys.stdin.readline

H,W,M=map(int,input().split())
B=set([tuple(map(int,input().split())) for i in range(M)])

HH=[0]*(H+1)
WW=[0]*(W+1)

for x,y in B:
    HH[x]+=1
    WW[y]+=1

MAXH=max(HH)
MAXW=max(WW)

ANS=MAXH+MAXW-1

HLIST=[]
WLIST=[]
for i in range(1,H+1):
    if HH[i]==MAXH:
        HLIST.append(i)

for j in range(1,W+1):
    if WW[j]==MAXW:
        WLIST.append(j)

for i in HLIST:
    for j in WLIST:
        if (i,j) in B:
            continue
        else:
            print(ANS+1)
            sys.exit()
print(ANS)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N=int(input())
A=[input().strip() for i in range(N)]

X=[]

for a in A:
    TWO=0
    FIVE=0

    if "." in a:
        x=a.split(".")
        L=len(x[1])
        #print(x,L)
        TWO-=L
        FIVE-=L

        x=int("".join(x))

        #print(x)

        while x%2==0:
            x//=2
            TWO+=1

        while x%5==0:
            x//=5
            FIVE+=1

        #print(TWO,FIVE)

    else:
        x=int(a)
        while x%2==0:
            x//=2
            TWO+=1

        while x%5==0:
            x//=5
            FIVE+=1

    X.append((TWO,FIVE))

LIST=[[0]*30 for i in range(30)]

for x,y in X:
    LIST[x+15][y+15]+=1

#for l in LIST:
#    print(*l)

#print()

for i in range(30):
    for j in range(28,-1,-1):
        LIST[i][j]+=LIST[i][j+1]

for j in range(30):
    for i in range(28,-1,-1):
        LIST[i][j]+=LIST[i+1][j]

#for l in LIST:
#    print(*l)

ANS=0

for x,y in X:
    x2=-x
    y2=-y

    if x>=x2 and y>=y2:
        ANS-=1

    ANS+=LIST[x2+15][y2+15]

    #print(x,y,ANS)

print(ANS//2)




Fixed submission:
import sys
input = sys.stdin.readline

N=int(input())
A=[input().strip() for i in range(N)]

X=[]

for a in A:
    TWO=0
    FIVE=0

    if "." in a:
        x=a.split(".")
        L=len(x[1])
        #print(x,L)
        TWO-=L
        FIVE-=L

        x=int("".join(x))

        #print(x)

        while x%2==0:
            x//=2
            TWO+=1

        while x%5==0:
            x//=5
            FIVE+=1

        #print(TWO,FIVE)

    else:
        x=int(a)
        while x%2==0:
            x//=2
            TWO+=1

        while x%5==0:
            x//=5
            FIVE+=1

    X.append((TWO,FIVE))

LIST=[[0]*100 for i in range(100)]

for x,y in X:
    LIST[x+35][y+35]+=1

#for l in LIST:
#    print(*l)

#print()

for i in range(100):
    for j in range(98,-1,-1):
        LIST[i][j]+=LIST[i][j+1]

for j in range(100):
    for i in range(98,-1,-1):
        LIST[i][j]+=LIST[i+1][j]

#for l in LIST:
#    print(*l)

ANS=0

for x,y in X:
    x2=-x
    y2=-y

    if x>=x2 and y>=y2:
        ANS-=1

    ANS+=LIST[x2+35][y2+35]

    #print(x,y,ANS)

print(ANS//2)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=[input() for i in range(N)]
S.sort(key=len)

VLIST=[[set() for j in range(len(S[i]))] for i in range(N)]

for i in range(N):
    for j in range(len(S[i])):
        VLIST[i][j]=VLIST[i][j-1]|{S[i][j]}

# ing木

Next_node_id=[[-1]*26] # "a"～"z"それぞれについて、対応する次のノードのid
Parent_id=[-1] # 親ノード
End=[[]] # そのノードを終端とするStringがあるか

ANS=0

Nodes_id=1
for i in range(N):
    S2=S[i]
    L=len(S2)

    NOW=0
    for j in range(L-1,-1,-1):
        for s in End[NOW]:
            if s in VLIST[i][j]:
                ANS+=1

        if j==0:
            End[NOW].append(S2[0])
            continue
        
        NEXT=ord(S2[j])-97
        
        if Next_node_id[NOW][NEXT]==-1: # Nodeを追加する場合
            Next_node_id[NOW][NEXT]=Nodes_id

            Next_node_id.append([-1]*26)
            Parent_id.append(NOW)
            End.append([])

            NOW=Nodes_id         
            Nodes_id+=1

        else: # 追加しない場合
            NOW=Next_node_id[NOW][NEXT]

print(ANS)


Fixed submission:
import sys
input = sys.stdin.readline

N=int(input())
S=[input().strip() for i in range(N)]
S.sort(key=len)

VLIST=[[set() for j in range(len(S[i]))] for i in range(N)]

for i in range(N):
    for j in range(len(S[i])):
        VLIST[i][j]=VLIST[i][j-1]|{S[i][j]}

# ing木

Next_node_id=[[-1]*26] # "a"～"z"それぞれについて、対応する次のノードのid
Parent_id=[-1] # 親ノード
End=[[]] # そのノードを終端とするStringがあるか

ANS=0

Nodes_id=1
for i in range(N):
    S2=S[i]
    L=len(S2)

    NOW=0
    for j in range(L-1,-1,-1):
        for s in End[NOW]:
            if s in VLIST[i][j]:
                ANS+=1

        if j==0:
            End[NOW].append(S2[0])
            continue
        
        NEXT=ord(S2[j])-97
        
        if Next_node_id[NOW][NEXT]==-1: # Nodeを追加する場合
            Next_node_id[NOW][NEXT]=Nodes_id

            Next_node_id.append([-1]*26)
            Parent_id.append(NOW)
            End.append([])

            NOW=Nodes_id         
            Nodes_id+=1

        else: # 追加しない場合
            NOW=Next_node_id[NOW][NEXT]

print(ANS)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

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

OK=10**9
NG=-1

while OK-NG>1:
    mid=(OK+NG)//2

    ANS=0
    for a in A:
        ANS+=(a-0.01)//mid

    if ANS<=K:
        OK=mid
    else:
        NG=mid
print(OK)


Fixed submission:
import sys
input = sys.stdin.readline

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

OK=10**9
NG=0

while OK-NG>1:
    mid=(OK+NG)//2

    ANS=0
    for a in A:
        ANS+=(a-0.01)//mid

    if ANS<=K:
        OK=mid
    else:
        NG=mid
print(OK)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import random
import time
import copy
time0=time.time()

D=int(input())
C=[0]+list(map(int,input().split()))
S=[0]+[[0]+list(map(int,input().split())) for i in range(D)]

T=[0]
for i in range(1,D+1):
    MAX=-1
    for j in range(1,27):
        if S[i][j]>MAX:
            k=j
            MAX=S[i][j]
    T.append(j)

ANS=0
LAST=[[0]*27 for i in range(D+1)]
for day in range(1,D+1):
    for j in range(1,27):
        LAST[day][j]=LAST[day-1][j]
    t=T[day]
    ANS+=S[day][t]
    LAST[day][t]=day

    for j in range(1,27):
        ANS-=C[j]*(day-LAST[day][j])

while time.time()-time0<1.9:
    BT=copy.deepcopy(T)
    BLAST=copy.deepcopy(LAST)
    BANS=ANS
    
    d=random.randint(1,D)
    after_t=random.randint(1,26)

    before_t=T[d]

    ANS+=S[d][after_t]-S[d][before_t]

    T[d]=after_t

    for day in range(d,D+1):
        if T[day]!=before_t:
            ANS+=C[before_t]*(day-LAST[day][before_t])
            LAST[day][before_t]=LAST[day-1][before_t]
            ANS-=C[before_t]*(day-LAST[day][before_t])
        else:
            break

    ANS+=C[after_t]*(d-LAST[d][after_t])
    LAST[d][after_t]=d

    for day in range(d+1,D+1):    
        if T[day]!=after_t:
            ANS+=C[after_t]*(day-LAST[day][after_t])
            LAST[day][after_t]=LAST[day-1][after_t]
            ANS-=C[after_t]*(day-LAST[day][after_t])

    if ANS<BANS:
        T=BT
        LAST=BLAST
        ANS=BANS

print(*T[1:])

Fixed submission:
import sys
input = sys.stdin.readline

D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
#t=[int(input()) for i in range(D)]

for i in range(D):
    print(13)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
t=[int(input()) for i in range(D)]

for i in range(D):
    print(13)

Fixed submission:
import sys
input = sys.stdin.readline

D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
#t=[int(input()) for i in range(D)]

for i in range(D):
    print(13)