Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
K = int(input())
val = ''
A = set()
for i,s in enumerate(S):
    val = ''
    for j in range(i,len(S)):
        val += (S[j])
        A.add(val)
A_sort = sorted(list(A))
print(A_sort[K-1])

Fixed submission:
S = input()
K = int(input())
val = ''
A = set()
for i,s in enumerate(S):
    val = ''
    for j in range(i,min(i+5,len(S))):
        val += (S[j])
        A.add(val)
A_sort = sorted(list(A))
print(A_sort[K-1])
Buggy python submission (verdict: Runtime Error):
A,B  =map(int,input().split())
K = 50
S = [['.']*(2*K) for _ in range(2*K)]
for i in range(K):
    for j in range(2*K):
        S[i][j] ='#'
i,j = 0,0
A-=1
B-=1
while A>0:
    S[i][j] ='.'
    if j +2 <2*K:
        j +=2
    else:
        i += 1
    A-=1
i,j = 2*K-1,2*K-1
while B>0:
    S[i][j]='#'
    if j-2>0:
        j-=2
    else:
        i-=1
    B-=1
for s in S:
    print(''.join(s))

Fixed submission:
A,B  =map(int,input().split())
K = 50
S = [['.']*(2*K) for _ in range(2*K)]
for i in range(K):
    for j in range(2*K):
        S[i][j] ='#'
i,j = 0,0
A-=1
B-=1
while A>0:
    S[i][j] ='.'
    if j +2 <2*K:
        j +=2
    else:
        i += 2
        j=0
    A-=1
i,j = 2*K-1,2*K-1
while B>0:
    S[i][j]='#'
    if j-2>0:
        j-=2
    else:
        i-=2
        j=2*K-1
    B-=1
print(str(2*K)+' '+str(2*K))
for s in S:
    print(''.join(s))

Buggy python submission (verdict: Runtime Error):
A,B  =map(int,input().split())
K = 50
S = [['.']*(2*K) for _ in range(2*K)]
for i in range(K):
    for j in range(2*K):
        S[i][j] ='#'
i,j = 0,0
while A>0:
    S[i][j] ='.'
    if j +2 <2*K:
        j +=2
    else:
        i += 1
    A-=1
i,j = 2*K-1,2*K-1
while B>0:
    S[i][j]='#'
    if j-2>0:
        j-=2
    else:
        i-=1
    B-=1
for s in S:
    print(''.join(s))


Fixed submission:
A,B  =map(int,input().split())
K = 50
S = [['.']*(2*K) for _ in range(2*K)]
for i in range(K):
    for j in range(2*K):
        S[i][j] ='#'
i,j = 0,0
A-=1
B-=1
while A>0:
    S[i][j] ='.'
    if j +2 <2*K:
        j +=2
    else:
        i += 2
        j=0
    A-=1
i,j = 2*K-1,2*K-1
while B>0:
    S[i][j]='#'
    if j-2>0:
        j-=2
    else:
        i-=2
        j=2*K-1
    B-=1
print(str(2*K)+' '+str(2*K))
for s in S:
    print(''.join(s))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a=list(map(int,input().split()))
b_=list(map(int,input().split()))
ans=0
from bisect import bisect_left as bl
def helper(l,r,b):
    return bl(b,r)-bl(b,l)

for i in range(29):
    T = pow(2,i)
    tmp = 0
    b=sorted([x%(2*T) for x in b_])
    for ai in a:
        ai%=2*T
        tmp += helper(T-ai,2*T-ai,b)
        tmp += helper(3*T-ai,4*T-ai,b)
    ans += T*(tmp%2)
print(ans)

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


n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
l = [[] for i in range(29)]
for i in range(29):
    mod = 2**(i+1)
    for j in b:
        l[i].append(j%mod)
    l[i].sort()

ans = 0
for i in range(29):
    al = []
    count = 0
    mod = 2**i
    for j in a:
        al.append(j%(2*mod))
    al.sort(reverse = True)
    r1 = r2 = r3 = 0
    for j in al:
        while r1 < n and l[i][r1]+j < mod:
            r1 += 1
        while r2 < n and l[i][r2]+j < 2*mod:
            r2 += 1
        while r3 < n and l[i][r3]+j < 3*mod:
            r3 += 1
        count += n-r3+r2-r1
    ans += (count%2) << i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x,y = [],[]
for i in range(n):
    a,b = map(int,input().split())
    x.append([a,i])
    y.append([b,i])
x.sort()
y.sort()
g = [[] for _ in range(n)]
for i in range(n-1):
    g[x[i][1]].append([abs(x[i+1][0]-x[i][0]),x[i+1][1]])
    g[x[i+1][1]].append([abs(x[i+1][0]-x[i][0]),x[i][1]])
    g[y[i][1]].append([abs(y[i+1][0]-y[i][0]),y[i+1][1]])
    g[y[i+1][1]].append([abs(y[i+1][0]-y[i][0]),y[i][1]])
import heapq
hq = []
for d,e in g[0]:
    heapq.heappush(hq,[d,e])
cnt = 1
visit = [False]*n
visit[0] = True
ans = 0
while cnt <n:
    cost, end = heapq.heappop(hq)
    if not visit[end]:
        ans += cost
        visit[end] = True
        cnt += 1
        for d,e in g[end]:
            heapq.heappush(hq,[d,e])
print(ans)
        


Fixed submission:
n = int(input())
x,y = [],[]
for i in range(n):
    a,b = map(int,input().split())
    x.append([a,i])
    y.append([b,i])
x.sort()
y.sort()
g = [[] for _ in range(n)]
for i in range(n-1):
    g[x[i][1]].append([abs(x[i+1][0]-x[i][0]),x[i+1][1]])
    g[x[i+1][1]].append([abs(x[i+1][0]-x[i][0]),x[i][1]])
    g[y[i][1]].append([abs(y[i+1][0]-y[i][0]),y[i+1][1]])
    g[y[i+1][1]].append([abs(y[i+1][0]-y[i][0]),y[i][1]])
import heapq
hq = []
for d,e in g[0]:
    heapq.heappush(hq,[d,e])
cnt = 1
visit = [False]*n
visit[0] = True
ans = 0
while cnt <n:
    cost, end = heapq.heappop(hq)
    if visit[end]: continue
    ans += cost
    visit[end] = True
    cnt += 1
    for d,e in g[end]:
        if not visit[e]:
            heapq.heappush(hq,[d,e])
print(ans)
Buggy python submission (verdict: Runtime Error):
N,A,B=map(int, [input() for i in range(3)])
s=0
for i in range(1,N+1):
    k=0
    j=i
    while(j>0):
        k+=j%10
        j=j//10
    if (A<=k and k<=B):
        s=s+i
print(s)

Fixed submission:
N,A,B=map(int, input().split())
s=0
for i in range(1,N+1):
    k=0
    j=i
    while(j>0):
        k+=j%10
        j=j//10
    if (A<=k and k<=B):
        s=s+i
print(s)

Buggy python submission (verdict: Runtime Error):
A=int(input())
B=int(input())
s=0
for i in range(1,N+1):
    k=0
    j=i
    while(j>0):
        k+=j%10
        j=j//10
    if (A<=k and k<=B):
        s=s+i
print(s)


Fixed submission:
N,A,B=map(int, input().split())
s=0
for i in range(1,N+1):
    k=0
    j=i
    while(j>0):
        k+=j%10
        j=j//10
    if (A<=k and k<=B):
        s=s+i
print(s)

Buggy python submission (verdict: Runtime Error):
#include <stdio.h>
int some_sum(int n){
    int n1,n2,n3,n4,n5,temp;
    n1=n%10;
    n=n/10;
    n2=n%10;
    n=n/10;
    n3=n%10;
    n=n/10;
    n4=n%10;
    n=n/10;
    n5=n%10;
    temp=n1+n2+n3+n4+n5;
    return temp;
}
int main(void){
    int N,A,B;
    scanf("%d",&N);
    scanf("%d",&A);
    scanf("%d",&B);
    int i,sum;
    sum=0;
    for (i=1;i<=N;i++){
        int mp;
        mp=some_sum(i);
        if((A<=mp)&&(mp<=B))
            sum+=i;
    }
    printf("%d",sum);
}

Fixed submission:
N,A,B=map(int, input().split())
s=0
for i in range(1,N+1):
    k=0
    j=i
    while(j>0):
        k+=j%10
        j=j//10
    if (A<=k and k<=B):
        s=s+i
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
# alter altar
# WRとなっては行けない
# all W or all R 
# RRRRRWWWWWW 左にR、右にWを集める
length = int(input())
stone = input()
mini = 200000
for sep in range(length+1):
	red = 0
	white = 0
	for left in range(0, sep):
		# print(left, end="")
		if(stone[left] == "W"):
			white += 1
	for right in range(sep, length):
		# print(right, end="")
		if(stone[right] == "R"):
			red += 1
	# print(white)
	# print(red)
	trial = max(white, red)
	mini = min(mini, trial)
print(mini)

Fixed submission:
# alter altar
length = int(input())
stone = input()
red = [0] * (length + 1)
white = [0] * (length + 1)
[red_num, white_num] = [0, 0]
for i in range(1, length + 1):
	if(stone[i-1] == "W"):
		white_num += 1
	if(stone[length-i] == "R"):
		red_num += 1
	white[i] = white_num
	red[length - i] = red_num
# print(white)
# print(red)
mini = 200000
for i in range(0, length+1):
	trial = max(white[i], red[i])
	mini = min(mini, trial)
print(mini)
Buggy python submission (verdict: Runtime Error):
import math
N = input()
N = int(N)
x = N / 3
x = int(x)
p = 10 ** 9 + 7
sum = 0
if x == 0:
  print(0)
else:
  for k in range(x):
    y =  N - 3*k - 3
    l = k 
    M = y + l
    a = math.factorial(l)
    b = math.factorial(M) 
    c = math.factorial(y)
    z = b / a / c 
    z = z % p
    sum += z
    sum = sum %p

  sum = int(sum)
  print(sum)

  

  

Fixed submission:
import math
N = input()
N = int(N)
x = N // 3
x = int(x)
p = 10 ** 9 + 7
sum = 0
if x == 0:
  print(0)
else:
  for k in range(x):
    y =  N - 3*k - 3
    l = k 
    M = y + l
    a = math.factorial(l)
    b = math.factorial(M) 
    c = math.factorial(y)
    d = a * c
    z = b // d
    z = z % p
    sum += z
    sum = sum %p

  sum = int(sum)
  print(sum)

Buggy python submission (verdict: Runtime Error):
import math
N = input()
N = int(N)
x = N / 3
p = 10 **9 + 7
if x == 0:
  print(0)
sum = 0
else:
  for k in range(x):
  y = N - 3 * k
  l = k - 1
  M = y + l
  a = math.factorial(l)
  b = math.factorial(M) 
  c = math.factorial(y)
  z = b / a / c
  z = z % p
  sum += z

print(z)

  

  

Fixed submission:
import math
N = input()
N = int(N)
x = N // 3
x = int(x)
p = 10 ** 9 + 7
sum = 0
if x == 0:
  print(0)
else:
  for k in range(x):
    y =  N - 3*k - 3
    l = k 
    M = y + l
    a = math.factorial(l)
    b = math.factorial(M) 
    c = math.factorial(y)
    d = a * c
    z = b // d
    z = z % p
    sum += z
    sum = sum %p

  sum = int(sum)
  print(sum)
Buggy python submission (verdict: Runtime Error):
X, K, D = map(int, input().split())


for i in range(K):
    if abs(X + D) < abs(X - D):
        X = X + D
    else:
        X = X - D
    if abs(X - D) > abs(X) and abs(X + D) > abs(X):
        if (K - i - 1) % 2 == 1:
            if abs(X - D) < abs(X + D):
                X = X - D
            else:
                X = X + D
        break



print(abs(X))

Fixed submission:
s = input("")
n = 0

if s[0] == "R":
    if s[1] == "R":
        if s[2] == "R":
            n = 3
        else:
            n = 2
    else:
        n = 1

elif s[1] == "R":
    if s[2] == "R":
        n = 2
    else:
        n = 1

elif s[2] == "R":
    n = 1

else:
    n = 0

print(n)
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**6)

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

A = input("").split(" ")
A = [int(i) for i in A]


for i in range(1, N-K+1):
    score = 1
    p_score = 1

    for j in range(i, i+K):
        score = score * A[j]
        p_score = p_score * A[j-1]

    if score > p_score:
        print("Yes")
    else:
        print("No")

Fixed submission:
N = int(input(""))

if N >= 1800:
    print("1")
elif N >= 1600:
    print("2")
elif N >= 1400:
    print("3")
elif N >= 1200:
    print("4")
elif N >= 1000:
    print("5")
elif N >= 800:
    print("6")
elif N >= 600:
    print("7")
elif N >= 400:
    print("8")

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

A = input("").split(" ")
A = [int(i) for i in A]


for i in range(1, N-K+1):
    score = 1
    p_score = 1

    for j in range(i, i+K):
        score = score * A[j]
        p_score = p_score * A[j-1]

    if score > p_score:
        print("Yes")
    else:
        print("No")

Fixed submission:
N = int(input(""))

if N >= 1800:
    print("1")
elif N >= 1600:
    print("2")
elif N >= 1400:
    print("3")
elif N >= 1200:
    print("4")
elif N >= 1000:
    print("5")
elif N >= 800:
    print("6")
elif N >= 600:
    print("7")
elif N >= 400:
    print("8")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input(""))
A = list(map(int, input("").split()))
n = 1

for i in range(N):
    n = n * A[i]

if n > 10 ** 18:
    n = -1

print(n)

Fixed submission:
N = int(input(""))
A = list(map(int, input("").split()))
n = 1

if 0 in A:
    print(0)
else:
    for i in range(N):
        n = n * A[i]
        if n > 10 ** 18:
            n = -1
            break

    print(n)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input(""))
A = input("").split()
A = [int(i) for i in A]

import functools
import operator

n = functools.reduce(operator.mul, A)

if n > 10 ** 18:
    n = -1

print(n)


Fixed submission:
N = int(input(""))
A = list(map(int, input("").split()))
n = 1

if 0 in A:
    print(0)
else:
    for i in range(N):
        n = n * A[i]
        if n > 10 ** 18:
            n = -1
            break

    print(n)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input(""))
A = input("").split()
A = [int(i) for i in A]
n = 1


for i in range(N):
    n = n * A[i]

if n > 10 ** 18:
    n = -1

print(n)



Fixed submission:
N = int(input(""))
A = list(map(int, input("").split()))
n = 1

if 0 in A:
    print(0)
else:
    for i in range(N):
        n = n * A[i]
        if n > 10 ** 18:
            n = -1
            break

    print(n)
Buggy python submission (verdict: Time Limit Exceeded):
f=lambda:map(int,input().split())
n,m=f()
# Union Find
p=[-1]*n
def root(x):
  while p[x]>=0: x=p[x]
  return x
def unite(x,y):
  x,y=root(x),root(y)
  if x==y: return
  if x>y: x,y=y,x
  p[x]+=p[y]
  p[y]=x
def same(x,y):
  return root(x)==root(y)
def size(x):
  return -p[root(x)]

for i in range(m):
  a,b=f()
  unite(a-1,b-1)
print(max(size(i) for i in range(n)))

Fixed submission:
f=lambda:map(int,input().split())
n,m=f()
# Union Find
p=[-1]*n
def root(x):
  while p[x]>=0: x=p[x]
  return x
def unite(x,y):
  x,y=root(x),root(y)
  if x==y: return
  if x>y: x,y=y,x
  p[x]+=p[y]
  p[y]=x
def same(x,y):
  return root(x)==root(y)
def size(x):
  return -p[root(x)]

for i in range(m):
  a,b=f()
  unite(a-1,b-1)
print(-min(p))

Buggy python submission (verdict: Time Limit Exceeded):
f=lambda:map(int,input().split())
n,m=f()
# Union Find
p=[-1]*n
def root(x):
  while p[x]>=0: x=p[x]
  return x
def unite(x,y):
  x,y=root(x),root(y)
  if x==y: return
  if x>y: x,y=y,x
  p[x]+=p[y]
  p[y]=x
def same(x,y):
  return root(x)==root(y)
def size(x):
  return -p[root(x)]

for i in range(m):
  a,b=f()
  unite(a-1,b-1)
print(max(size(i) for i in range(n)))

Fixed submission:
f=lambda:map(int,input().split())
n,m=f()
# Union Find
p=[-1]*n
def root(x):
  while p[x]>=0: x=p[x]
  return x
def unite(x,y):
  x,y=root(x),root(y)
  if x==y: return
  if x>y: x,y=y,x
  p[x]+=p[y]
  p[y]=x
def same(x,y):
  return root(x)==root(y)
def size(x):
  return -p[root(x)]

for i in range(m):
  a,b=f()
  unite(a-1,b-1)
print(-min(p))
Buggy python submission (verdict: Time Limit Exceeded):
M=10**6+1
f=lambda p: exit(print(['pairwise','setwise','not'][p]+' coprime'))
n,*l=map(int,open(0).read().split())
from math import *
g=l[0]
for x in l: g=gcd(g,x)
if g>1: f(2)
C=[0]*M
for x in l: C[x]=1
for i in range(2,M):
  if sum(C[j] for j in range(i,M,i))>1: f(1)
f(0)

Fixed submission:
n=int(input())
l=[*map(int,input().split())]
from math import *
g=l[0]
for x in l:
  g=gcd(g,x)
if g>1: exit(print('not coprime'))
from collections import *
d=Counter()
b=0
for x in l:
  if x%2<1:
    if d[2]:
      b=1
      break
    d[2]=1
  while x%2<1: x//=2
  for i in range(3,int(x**0.5)+1,2):
    if x%i<1:
      if d[i]:
        b=1
        break
      d[i]=1
    while x%i<1: x//=i
    if x<2: break
  if x>1:
    if d[x]:
      b=1
      break
    d[x]=d.get(x,0)+1
print(['pair','set'][b]+'wise coprime')

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[*map(int,input().split())]
f=lambda p: exit(print(['pairwise','setwise','not'][p]+' coprime'))
from math import *
g=l[0]
for x in l: g=gcd(g,x)
if g>1: f(2)
from collections import *
C=Counter()
b=0
for x in l:
  if x%2<1:
    if C[2]: f(1)
    C[2]=1
  while x%2<1: x//=2
  for i in range(3,int(x**0.5)+1,2):
    if x%i<1:
      if C[i]: f(1)
      C[i]=1
    while x%i<1: x//=i
    if x<2: break
  if x>1:
    if C[x]: f(1)
    C[x]=1
f(0)

Fixed submission:
n=int(input())
l=[*map(int,input().split())]
from math import *
g=l[0]
for x in l:
  g=gcd(g,x)
if g>1: exit(print('not coprime'))
from collections import *
d=Counter()
b=0
for x in l:
  if x%2<1:
    if d[2]:
      b=1
      break
    d[2]=1
  while x%2<1: x//=2
  for i in range(3,int(x**0.5)+1,2):
    if x%i<1:
      if d[i]:
        b=1
        break
      d[i]=1
    while x%i<1: x//=i
    if x<2: break
  if x>1:
    if d[x]:
      b=1
      break
    d[x]=d.get(x,0)+1
print(['pair','set'][b]+'wise coprime')
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
f=lambda:map(int,input().split())
R,C,K=f()
g=np.zeros((R+1,C+1),int)
for _ in range(K):
  r,c,v=f()
  g[r][c]=v
dp=np.zeros((R+2,C+2,4),int)
for i in range(1,R+1):
  for j in range(1,C+1):
    for k in range(3,-1,-1):
      if k: dp[i][j][k]=max(dp[i][j][k],dp[i][j][k-1]+g[i][j])
      dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k])
      dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k])
print(max(dp[R][C]))

Fixed submission:
f=lambda:map(int,input().split())
R,C,K=f()
g=[[0]*(R+1) for _ in range(C+1)]
for _ in range(K):
  r,c,v=f()
  g[c][r]=v
dp=[[0]*4 for _ in range(R+1)]
for i in range(1,C+1):
  for j in range(1,R+1):
    t=g[i][j]
    if t:
      for k in range(3,0,-1):
        dp[j][k]=max(dp[j][k],dp[j][k-1]+t)
      dp[j][1]=max(dp[j][k],max(dp[j-1])+t)
    dp[j][0]=max(dp[j][0],max(dp[j-1]))
print(max(dp[R]))

Buggy python submission (verdict: Time Limit Exceeded):
f=lambda:map(int,input().split())
R,C,K=f()
g=[[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
  r,c,v=f()
  g[r][c]=v
dp=[[[0]*4 for _ in range(C+2)] for _ in range(R+2)]
for i in range(1,R+1):
  for j in range(1,C+1):
    for k in range(3,-1,-1):
      if k: dp[i][j][k]=max(dp[i][j][k],dp[i][j][k-1]+g[i][j])
      dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k])
      dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k])
print(max(dp[R][C][k] for k in range(4)))

Fixed submission:
f=lambda:map(int,input().split())
R,C,K=f()
g=[[0]*(R+1) for _ in range(C+1)]
for _ in range(K):
  r,c,v=f()
  g[c][r]=v
dp=[[0]*4 for _ in range(R+1)]
for i in range(1,C+1):
  for j in range(1,R+1):
    t=g[i][j]
    if t:
      for k in range(3,0,-1):
        dp[j][k]=max(dp[j][k],dp[j][k-1]+t)
      dp[j][1]=max(dp[j][k],max(dp[j-1])+t)
    dp[j][0]=max(dp[j][0],max(dp[j-1]))
print(max(dp[R]))

Buggy python submission (verdict: Time Limit Exceeded):
f=lambda:map(int,input().split())
R,C,K=f()
g=[[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
  r,c,v=f()
  g[r][c]=v
dp=[[[0]*4 for _ in range(C+2)] for _ in range(R+2)]
for i in range(1,R+1):
  for j in range(1,C+1):
    for k in range(3,-1,-1):
      if k: dp[i][j][k]=max(dp[i][j][k],dp[i][j][k-1]+ｇ[i][j])
      dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k])
      dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k])
print(max(dp[R][C][k] for k in range(4)))

Fixed submission:
f=lambda:map(int,input().split())
R,C,K=f()
g=[[0]*(R+1) for _ in range(C+1)]
for _ in range(K):
  r,c,v=f()
  g[c][r]=v
dp=[[0]*4 for _ in range(R+1)]
for i in range(1,C+1):
  for j in range(1,R+1):
    t=g[i][j]
    if t:
      for k in range(3,0,-1):
        dp[j][k]=max(dp[j][k],dp[j][k-1]+t)
      dp[j][1]=max(dp[j][k],max(dp[j-1])+t)
    dp[j][0]=max(dp[j][0],max(dp[j-1]))
print(max(dp[R]))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[*map(int,input().split())]
a=1000
c=0
for i in range(n-1):
  if l[i]>l[i+1]:
    a+=c*l[i]
    c=0
  if l[i]<l[i+1]:
    while a>=l[i]:
      a-=l[i]
      c+=1
print(a+c*l[n-1])

Fixed submission:
n=int(input())
l=[*map(int,input().split())]
a=1000
c=0
for i in range(n-1):
  if l[i]>l[i+1]:
    a+=c*l[i]
    c=0
  if l[i]<l[i+1]:
    while a>=l[i]:
      t=a//l[i]
      a-=t*l[i]
      c+=t
print(a+c*l[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
r=range(1,int(2*n**.5)+1)
l=[0]*-~n
for i in r:
  for j in r:
    for k in r:
      t=(j+k)**2+(k+i)**2+(i+j)**2
      if t<=n*2 and t%2<1: l[t//2]+=1
for i in range(n): print(l[i+1])

Fixed submission:
n=int(input())
r=range(1,int((2*10**4)**.5)+1)
l=[0]*-~n
for i in r:
  for j in r:
    for k in r:
      t=(j+k)**2+(k+i)**2+(i+j)**2
      if t<=n*2 and t%2<1:
        l[t//2]+=1
for i in range(n): print(l[i+1])
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
M,F=10**9+7,[1]
for i in range(m): F+=[-~i*F[i]%M]
c=lambda n,r: F[n]*pow(F[r]*F[n-r],-1,M)
p=lambda n,r: F[n]*pow(F[n-r],-1,M)
print(sum((-1)**k*c(n,k)*p(m,k)*p(m-k,n-k)**2 for k in range(n+1))%M)

Fixed submission:
M=10**9+7
n,m=map(int,input().split())
F=[1]
for i in range(1,m+1): F+=[i*F[-1]%M]
a=0
for k in range(n+1):
  a+=(-1)**k*F[m-k]*pow(F[k]*F[n-k],-1,M)%M
print(a*F[n]*F[m]*pow(F[m-n]**2,-1,M)%M)

Buggy python submission (verdict: Time Limit Exceeded):
M=10**9+7
n,m=map(int,input().split())
F=[1]
for i in range(1,m+1): F+=[i*F[-1]%M]
c=lambda n,r: F[n]*pow(F[r]*F[n-r],-1,M)%M
p=lambda n,r: F[n]*pow(F[n-r],-1,M)%M
a=0
for k in range(n+1):
  a+=(-1)**k*c(n,k)*p(m,k)*p(m-k,n-k)**2%M
print(a%M)

Fixed submission:
M=10**9+7
n,m=map(int,input().split())
F=[1]
for i in range(1,m+1): F+=[i*F[-1]%M]
a=0
for k in range(n+1):
  a+=(-1)**k*F[m-k]*pow(F[k]*F[n-k],-1,M)%M
print(a*F[n]*F[m]*pow(F[m-n]**2,-1,M)%M)

Buggy python submission (verdict: Runtime Error):
M=10**9+7
n,m=map(int,input().split())
import sys, functools as ft
sys.setrecursionlimit(10**18)
@ft.lru_cache(None)
def f(n):
  if n<2: return 1
  return n*f(n-1)%M
a=0
for k in range(n+1):
  a+=(-1)**k*f(m-k)*pow(f(k)*f(n-k),-1,M)%M
print(a*f(n)*f(m)*pow(f(m-n)**2,-1,M)%M)

Fixed submission:
M=10**9+7
n,m=map(int,input().split())
F=[1]
for i in range(1,m+1): F+=[i*F[-1]%M]
a=0
for k in range(n+1):
  a+=(-1)**k*F[m-k]*pow(F[k]*F[n-k],-1,M)%M
print(a*F[n]*F[m]*pow(F[m-n]**2,-1,M)%M)

Buggy python submission (verdict: Runtime Error):
M=10**9+7
n,m=map(int,input().split())
import sys, functools as ft
sys.setrecursionlimit(10**9)
@ft.lru_cache(None)
def f(n):
  if n<2: return 1
  return n*f(n-1)%M
a=0
for k in range(n+1):
  a+=(-1)**k*f(m-k)*pow(f(k)*f(n-k),-1,M)%M
print(a*f(n)*f(m)*pow(f(m-n)**2,-1,M)%M)

Fixed submission:
M=10**9+7
n,m=map(int,input().split())
F=[1]
for i in range(1,m+1): F+=[i*F[-1]%M]
a=0
for k in range(n+1):
  a+=(-1)**k*F[m-k]*pow(F[k]*F[n-k],-1,M)%M
print(a*F[n]*F[m]*pow(F[m-n]**2,-1,M)%M)

Buggy python submission (verdict: Runtime Error):
M=10**9+7
n,m=map(int,input().split())
import sys, functools as ft
sys.setrecursionlimit(10**6)
@ft.lru_cache(None)
def f(n):
  if n<2: return 1
  return n*f(n-1)%M
a=0
for k in range(n+1):
  a+=(-1)**k*f(m-k)*pow(f(k)*f(n-k),-1,M)%M
print(a*f(n)*f(m)*pow(f(m-n)**2,-1,M)%M)

Fixed submission:
M=10**9+7
n,m=map(int,input().split())
F=[1]
for i in range(1,m+1): F+=[i*F[-1]%M]
a=0
for k in range(n+1):
  a+=(-1)**k*F[m-k]*pow(F[k]*F[n-k],-1,M)%M
print(a*F[n]*F[m]*pow(F[m-n]**2,-1,M)%M)
Buggy python submission (verdict: Runtime Error):
n,*a=map(int,open(0).read().split())
s,*l=[0]*100001
for i in a[:n]: s+=i; l[i]+=1
for b,c in zip(*[iter(a[n+1:])]*2): s+=(c-b)*l[b]; l[c]+=l[b]; l[b]=0; print(s)

Fixed submission:
f=lambda:list(map(int,input().split()))
n,l,q=f()[0],f(),f()[0]
from collections import *
C=Counter(l)
s=sum(k*C[k] for k in C)
for _ in range(q):
  b,c=f()
  v=C[b]
  C[b]-=v
  C[c]+=v
  s+=(c-b)*v
  print(s)
Buggy python submission (verdict: Runtime Error):
M=10**9+7
k,n=int(input()),len(input())
a=t=pow(26,k,M)
for i in range(k):
  t=t*25*(i+n)*pow(26*-~i,-1,M)%M
  a+=t
print(a%M)

Fixed submission:
M=10**9+7
k,n=int(input()),len(input())
a=t=pow(26,k,M)
for i in range(1,k+1):
  t=t*25*(i+n-1)*pow(26*i,-1,M)%M
  a+=t
print(a%M)
Buggy python submission (verdict: Time Limit Exceeded):
n,k,*l=map(int,open(0).read().split())
for _ in range(k):
  s=[0]*(n+1)
  for i in range(n):
    s[max(i-l[i],0)]+=1
    s[min(i+l[i]+1,n)]-=1
  for i in range(n):
    s[i+1]+=s[i]
  s.pop()
  if s==l: break
  l=s
print(*l)

Fixed submission:
n,k,*l=map(int,open(0).read().split())
for _ in range(min(k,99)):
  s=[0]*(n+1)
  for i in range(n):
    s[max(i-l[i],0)]+=1
    s[min(i+l[i]+1,n)]-=1
  l[0]=min(s[0],n)
  for i in range(1,n):
    l[i]=min(l[i-1]+s[i],n)
print(*l)

Buggy python submission (verdict: Time Limit Exceeded):
n,k,*l=map(int,open(0).read().split())
for _ in range(k):
  s=[0]*(n+1)
  for i in range(n):
    s[max(i-l[i],0)]+=1
    s[min(i+l[i]+1,n)]-=1
  s[0]=min(s[0],n)
  for i in range(1,n):
    s[i]=min(s[i-1]+s[i],n)
  if s==l[:n]: break
  l=s[:n]
print(*l)

Fixed submission:
n,k,*l=map(int,open(0).read().split())
for _ in range(min(k,99)):
  s=[0]*(n+1)
  for i in range(n):
    s[max(i-l[i],0)]+=1
    s[min(i+l[i]+1,n)]-=1
  l[0]=min(s[0],n)
  for i in range(1,n):
    l[i]=min(l[i-1]+s[i],n)
print(*l)