Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
j = 0
for i in unique_l:
    cnt = 0
    
    while l[j] == i and j < len(l):
        cnt += 1
        j += 1
    j += 1
    if cnt == i:
        pass
    elif cnt > i:
        ans += cnt - 1
    elif cnt < i:
        ans += cnt
print(ans)

Fixed submission:
N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
unique_l.sort()
l.sort()
l.append(0)
ans = 0
j = 0
cnt =[]
for i in unique_l:
    temp = 0
    while l[j] == i and j < N:
        temp += 1
        j += 1
    cnt.append(temp)
for i, j in zip(unique_l, cnt):
    if i == j:
        pass
    elif j > i:
        ans += j - i
    elif j < i:
        ans += j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
ans = 0
for i in unique_l:
    cnt = l.count(i)
    if cnt==i:
        pass
    elif cnt > i:
        ans += cnt - i
    elif cnt < i:
        ans += cnt
print(ans)

Fixed submission:
N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
unique_l.sort()
l.sort()
l.append(0)
ans = 0
j = 0
cnt =[]
for i in unique_l:
    temp = 0
    while l[j] == i and j < N:
        temp += 1
        j += 1
    cnt.append(temp)
for i, j in zip(unique_l, cnt):
    if i == j:
        pass
    elif j > i:
        ans += j - i
    elif j < i:
        ans += j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = list(map(int, input().split()))
N_MAX =  int(1e+9 + 1)
cnt = [0 for _ in range(N_MAX)]
for i in l:
    cnt[i] += 1
ans = 0
for idx, val in enumerate(cnt):
    if val == 0 or val == idx:
        pass
    elif val < idx:
        ans += val
    elif idx < val:
        ans += val - idx
print(ans)

Fixed submission:
N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
unique_l.sort()
l.sort()
l.append(0)
ans = 0
j = 0
cnt =[]
for i in unique_l:
    temp = 0
    while l[j] == i and j < N:
        temp += 1
        j += 1
    cnt.append(temp)
for i, j in zip(unique_l, cnt):
    if i == j:
        pass
    elif j > i:
        ans += j - i
    elif j < i:
        ans += j
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
l = list(map(int, input().split()))
N_MAX =  int(1e+5 + 1)
cnt = [0 for _ in range(N_MAX)]
for i in l:
    cnt[i] += 1
ans = 0
for idx, val in enumerate(cnt):
    if val == 0 or val == idx:
        pass
    elif val < idx:
        ans += val
    elif idx < val:
        ans += val - idx
print(ans)

Fixed submission:
N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
unique_l.sort()
l.sort()
l.append(0)
ans = 0
j = 0
cnt =[]
for i in unique_l:
    temp = 0
    while l[j] == i and j < N:
        temp += 1
        j += 1
    cnt.append(temp)
for i, j in zip(unique_l, cnt):
    if i == j:
        pass
    elif j > i:
        ans += j - i
    elif j < i:
        ans += j
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))
k = 0
while True:
    for i in l :
        if i % 2 != 0:
            break
        elif i == 2:
            break
        i = i/2
    k += 1
print(k)


Fixed submission:
n = int(input())
l = list(map(int,input().split()))
k = 0
m = 0
for _ in range(100):
    for i in range(len(l)) :
        if l[i] % 2 != 0  :
            m = 10
            break
        else:
            l[i] = l[i]/2
    if m != 0 :
        break
    k += 1
print(k)
Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
if a>=b:
    print('{}'.format((a+b)/2))
else :
    print('{}'.format((b-a)/2))

Fixed submission:
a = int(input())
g = int(input())

print('{}'.format((2*g-a)))
Buggy python submission (verdict: Runtime Error):
print('{}'.format(int(input())**2-int(input()))

Fixed submission:
print('{}'.format(int(input())**2-int(input())))
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = []
    X = sum(l)
    x = 0
    for i in range(N-1):
        x += l[i]
        ans.append(abs(X-2*x))
    print(min(ans))
if __name__ == '__main__':
    main()

Fixed submission:
a , b = map(int, input().split())
if a%3==0 or b%3==0 or (a+b)%3==0:
    print('Possible')
else:
    print('Impossible')

Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = []
    X = sum(l)
    for i in range(N-1):
      	X = abs(X-2*l[i])
        ans.append(X)
    print(min(ans))
if __name__ == '__main__':
    main()


Fixed submission:
a , b = map(int, input().split())
if a%3==0 or b%3==0 or (a+b)%3==0:
    print('Possible')
else:
    print('Impossible')
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = []
    X = sum(l)
    for i in range(N-1):
      	X = abs(X-2*l[i])
        ans.append(X)
    print(min(ans))
if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = []
    sunuke = 0
    arai = sum(l)
    for i in range(N-1):
        sunuke += l[i]
        arai   -= l[i]
        ans.append(abs(sunuke-arai))
    print(min(ans))
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    len_s = 0
    ans = -1
    dic = {}
    N, K = map(int, input().split())
    for _ in range(N):
        a, b = map(int, input().split())
        if a not in dic:
            dic[a] = b
        else:
            dic[a] = b + dic[a].values
    dic = sorted(dic.items())
    for key, value in dic:
        len_s += value
        if len_s >= K and ans == -1:
            ans = key
    print(ans)
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    len_s = 0
    ans = -1
    dic = {}
    N, K = map(int, input().split())
    for _ in range(N):
        a, b = map(int, input().split())
        if a not in dic:
            dic[a] = b
        else:
            dic[a] += b
    dic = sorted(dic.items())
    for key, value in dic:
        len_s += value
        if len_s >= K and ans == -1:
            ans = key
    print(ans)
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
m = 1
for i in range(1,int(input())+1):
    m = m * i
k = int(m % (1000000007))
print(k)



Fixed submission:
m = 1
for i in range(1,int(input())+1):
    m = m * i % 1000000007
print(m)
Buggy python submission (verdict: Time Limit Exceeded):
k , s = map(int,input().split())
a = 0
for i in range(k+1):
    for j in range(k+1):
        for h in range(k+1):
            if (i + j + h ) == s:
                a += 1
print(a)


Fixed submission:
k, s = map(int,input().split())
ans = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z and z <= k:
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
s = list(input())
l = []
for i in range(len(s)):
    if s[i] == 'S':
        l.append('S')
    elif l[-1] == 'T' or not l:
        l.append('T')
    else:
        l.pop()
print(len(l))



Fixed submission:
s = list(input())
l = []
for i in range(len(s)):
    if s[i] == 'S':
        l.append('S')
    elif not l:
        l.append('T')
    elif l[-1] == 'T':
        l.append('T')
    else:
        l.pop()
print(len(l))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()

for _ in range(int(len(s)/2)):
    s = s.replace('ST', '')
print(len(s))



Fixed submission:
s = list(input())
l = []
for i in range(len(s)):
    if s[i] == 'S':
        l.append('S')
    elif not l:
        l.append('T')
    elif l[-1] == 'T':
        l.append('T')
    else:
        l.pop()
print(len(l))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()

for _ in range(100000):
    s = s.replace('ST', '')
print(len(s))



Fixed submission:
s = list(input())
l = []
for i in range(len(s)):
    if s[i] == 'S':
        l.append('S')
    elif not l:
        l.append('T')
    elif l[-1] == 'T':
        l.append('T')
    else:
        l.pop()
print(len(l))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()

for _ in range(100000):
    s = s.replace('ST', '', 1)
print(len(s))



Fixed submission:
s = list(input())
l = []
for i in range(len(s)):
    if s[i] == 'S':
        l.append('S')
    elif not l:
        l.append('T')
    elif l[-1] == 'T':
        l.append('T')
    else:
        l.pop()
print(len(l))
Buggy python submission (verdict: Time Limit Exceeded):
def heikin(index, num, cnt):
    global A, ans, x, N
    if index < N:
        heikin(index+1, num + x[index], cnt+1)
        heikin(index+1, num, cnt)
    elif index == N:
        if num == A * cnt:
            ans += 1


if __name__ == "__main__":
    N, A = map(int, input().split())
    x = [i for i in map(int, input().split())]
    ans = 0
    heikin(0, 0, 0)
    print(ans-1)
    


Fixed submission:

if __name__ == "__main__":
    N, A = map(int, input().split())
    x = [i-A for i in map(int, input().split())]
    X = max(x + [A])
    dp = [[0] * (2*N*X + 1) for _ in range(N+1)]
    for row in range(N+1):
        for column in range(2*N*X):
            if row == 0 and column == N*X:
                dp[row][column] = 1
            elif row >=1 and (column - x[row-1] < 0 or column - x[row-1] > 2*N*X):
                    dp[row][column] = dp[row-1][column]
            elif row >=1 and 0 <= column - x[row-1] <= 2*N*X:
                dp[row][column] = dp[row-1][column] + dp[row-1][column-x[row-1]]
            else:
                dp[row][column] = 0
    print(dp[N][N*X]-1)
Buggy python submission (verdict: Runtime Error):
n,x=map(int,raw_input().split())
m=[int(raw_input()) for xrange(n)]
m.sort()

cnt = n
x -= sum(m)
cnt += x / m[0]

print cnt

Fixed submission:
n,x=map(int,raw_input().split())
m=[int(raw_input()) for j in xrange(n)]
m.sort()

cnt = n
x -= sum(m)
cnt += x / m[0]

print cnt
Buggy python submission (verdict: Runtime Error):
if ''.join((sorted(raw_input())) == 'abc':
  print 'Yes'
else:
  print 'No'

Fixed submission:
if ''.join(sorted(raw_input())) == 'abc':
  print 'Yes'
else:
  print 'No'
Buggy python submission (verdict: Runtime Error):
s=raw_input()
t=raw_input()
sa=''.join(sorted(s))
tz=''.join(sorted(t,reverse=True))
if sa < tz:
  print 'Yes'
else:
  pritn 'No'

Fixed submission:
s=raw_input()
t=raw_input()
sa=''.join(sorted(s))
tz=''.join(sorted(t,reverse=True))
if sa < tz:
  print 'Yes'
else:
  print 'No'
Buggy python submission (verdict: Runtime Error):
N=int(raw_input())
A=map(int,raw_input().split())
def f(x):
  cnt = 0
  while x >= 2:
    x /= 2
    cnt += 1
  return cnt
C=map(f,A)
pritn min(C)
    

Fixed submission:
N=int(raw_input())
A=map(int,raw_input().split())
def f(x):
  cnt = 0
  while x >= 2 and x % 2 == 0:
    x /= 2
    cnt += 1
  return cnt
C=map(f,A)
print min(C)
Buggy python submission (verdict: Runtime Error):
s=raw_input()
t='CODEFESTIVAL2016'
c=0
for i in range(16);
  if s[i] != t[i]:
    c += 1
print c

Fixed submission:
s=raw_input()
t='CODEFESTIVAL2016'
c=0
for i in range(16):
  if s[i] != t[i]:
    c += 1
print c
Buggy python submission (verdict: Runtime Error):
s = {}
s['a']=raw_input()
s['b']=raw_input()
s['c']=raw_input()
def solve(s):
  turn = 'a'
  while True:
    if len(s[turn]) == 0:
      return turn.upper()
    nxt, s[turn] = s[turn][0], s[turn][1:]
   	turn = nxt
print solve(s)

Fixed submission:
def solve(s):
  turn = 'a'
  while True:
    if len(s[turn]) == 0:
      return turn.upper()
    nxt, s[turn] = s[turn][0], s[turn][1:]
    turn = nxt

s = {}
s['a']=raw_input()
s['b']=raw_input()
s['c']=raw_input()
print solve(s)

Buggy python submission (verdict: Runtime Error):
s = {}
s['a']=raw_input()
s['b']=raw_input()
s['c']=raw_input()
def solve(s):
  turn = 'a'
  while True:
    nxt, s[turn] = s[turn][0], s[turn][1:]
    if len(s[turn]) == 0:
      return turn.upper()
   	turn = nxt
print solve(s)

Fixed submission:
def solve(s):
  turn = 'a'
  while True:
    if len(s[turn]) == 0:
      return turn.upper()
    nxt, s[turn] = s[turn][0], s[turn][1:]
    turn = nxt

s = {}
s['a']=raw_input()
s['b']=raw_input()
s['c']=raw_input()
print solve(s)
Buggy python submission (verdict: Runtime Error):
S = input()
if S[-1] == 's':
  ans += 'es'
else:
  ans += 's'
print(ans)

Fixed submission:
S = input()
if S[-1] == 's':
    ans = S+'es'
else:
    ans = S+'s'
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 0
mod = pow(10,9)+7
for i in range(N-1):
    for j in range(i+1,N):
        ans += (A[i]*A[j])%mod
        ans = ans%mod
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 0
mod = pow(10,9)+7

B = []
x = 0
for i in range(N-1):
    x += A[i]
    x %= mod
    B.append(x)

ans = 0
for i in range(1,N):
    ans += A[i]*B[i-1]
    ans %= mod

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
c = input()

first_R = c.index('R')
num_R = c.count('R')

print(first_R+c[first_R:first_R+num_R].count('W'))


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

num_R = c.count('R')

print(c[:num_R].count('W'))
Buggy python submission (verdict: Runtime Error):
if S == 'ABC':
  S = 'ARC'
else:
  S = 'ABC'
  
print(S)

Fixed submission:
S = input()

if S == 'ABC':
  S = 'ARC'
else:
  S = 'ABC'
  
print(S)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int, input().split())


for i in range(N,-1,-1):
    if (N+1)//B-1 == i//B:
        ans_i = i
        break

if N//B == 0:
    ans_i = N

print((A*ans_i)//B - A*(ans_i//B))


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


if N//B == 0:
    ans_i = N
else :
    ans_i = B*(N//B)-1

print((A*ans_i)//B - A*(ans_i//B))

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

floor_floor = []
for x in range(N+1):
    floor_floor.append((A*x)//B - A*(x//B))

print(max(floor_floor))


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


if N//B == 0:
    ans_i = N
else :
    ans_i = B*(N//B)-1

print((A*ans_i)//B - A*(ans_i//B))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

for i in range(1,N+1):
    print(A.count(i))


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

ans = [0]*N
for i in A:
    ans[i-1]+=1
print('\n'.join(map(str,ans)))
Buggy python submission (verdict: Time Limit Exceeded):
import math

K = int(input())

ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            ans += math.gcd(a, math.gcd(b,c))

print(ans)


Fixed submission:
import math

K = int(input())

ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        num = math.gcd(a,b)
        for c in range(1,K+1):
            ans += math.gcd(num,c)

print(ans)
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int,input().split())

if A == 0:
    print(0)
    exit()

s = N // (A+B)
p = (N%(A+B))
if p//A == 0:
    ans = s*A+p
elif p//A == 1:
    ans = s*A+A
print(ans)


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

if A == 0:
    print(0)
    exit()

s = N // (A+B)
p = N%(A+B)
if p//A == 0:
    ans = s*A+p
else:
    ans = s*A+A
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = map(int, input().split())
A = []
for i in range(Q):
    A.append(int(input()))

if K > Q:
    for i in range(N):
        print('Yes')
    exit()

for i in range(N):
    B = Q-A.count(i+1)
    if B >= K:
        print('No')
    else:
        print('Yes')


Fixed submission:
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

cnt = [0] * n

for i in a:
    cnt[i - 1] += 1

for c in cnt:
    if k - (q - c) > 0:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = map(int, input().split())
A = []
for i in range(Q):
    A.append(int(input()))

for i in range(N):
    B = Q-A.count(i+1)
    if B >= K:
        print('No')
    else:
        print('Yes')


Fixed submission:
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

cnt = [0] * n

for i in a:
    cnt[i - 1] += 1

for c in cnt:
    if k - (q - c) > 0:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
X = set(range(1,N+1))
for i in range(M):
    L, R = map(int, input().split())
    Y = set(range(L,R+1))
    X = X & Y
print(len(X))


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

min, max = map(int, input().split())

for i in range(1, M):
    L, R = map(int, input().split())
    if L > max or R < min:
        print(0)
        exit()
    elif min < L <= max:
        min = L
    elif min <= R < max:
        max = R
print(max-min+1)
Buggy python submission (verdict: Runtime Error):
import sympy

N = int(input())

ans = 0
for i in range(1, int(N/2)+1):
    if len(sympy.divisors(2*i+1))==8:
        ans += 1

print(ans)


Fixed submission:
N = int(input())

ans = 0
for n in range(1,int(N/2)+1):
    if 2*n+1 > N:
        break
    for i in range(1,int(N**(1/2)/2)+1):
        for j in range(i+1,int(N**(1/2)/2)+1):
            for k in range(j+1,int(N**(1/2)/2)+1):
                if 2*n+1 == (2*i+1)*(2*j+1)*(2*k+1):
                    ans += 1

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

B = {}
for i in range(N):
    if A[i] not in list(B.keys()):
        B[A[i]] = A.count(A[i])

num = len(B)
C = list(B.values())
C.sort()
ans = 0
if num>K:
    ans = sum(C[0:num-K])
print(ans)


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

B = [0]*N
for i in range(N):
    B[A[i]-1]+=1

B.sort()

print(sum(B[0:N-K]))

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

B = {A[0]:A.count(A[0])}
for i in range(1,len(A)):
    B[A[i]] = A.count(A[i])

num = len(B)
C = list(B.values())
C.sort()
ans = 0
if num>K:
    ans = sum(C[0:num-K])
print(ans)


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

B = [0]*N
for i in range(N):
    B[A[i]-1]+=1

B.sort()

print(sum(B[0:N-K]))
Buggy python submission (verdict: Runtime Error):
N = int(input())

L_2 = 2
L_1 = 1
for i in range(N-1):
    L = L_1+L_2
    L_2 = L_1
    L_1 = L
print(L)


Fixed submission:
N = int(input())

if N == 0:
    print(2)
    exit()
elif N == 1:
    print(1)
    exit()

L_2 = 2
L_1 = 1
for i in range(N-1):
    L = L_1+L_2
    L_2 = L_1
    L_1 = L
print(L)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = []
for i in range(N):
    A = int(input())
    if A not in ans:
        ans.append(A)
    else:
        ans.remove(A)
print(len(ans))


Fixed submission:
N = int(input())
num = {}
for i in range(N):
    A = int(input())
    if A in num.keys():
        num[A] += 1
    else:
        num[A] = 1
ans = 0
for i, j in num.items():
    if j%2 == 1:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = []
for i in range(N):
    A = int(input())
    if A in ans:
        ans.append(A)
    else:
        ans.remove(A)
print(len(ans))

Fixed submission:
N = int(input())
num = {}
for i in range(N):
    A = int(input())
    if A in num.keys():
        num[A] += 1
    else:
        num[A] = 1
ans = 0
for i, j in num.items():
    if j%2 == 1:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B = map(int,input(),split())
if A+B >= 10:
  print('error')
else:
  print(A+B)

Fixed submission:
A, B = map(int,input().split())
if A+B >= 10:
    print('error')
else:
    print(A+B)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
cnt = 0
for a in range(1, n):
    for b in range(1, ((n-1)//a)+1):
        if n - a*b <= 0: break
        cnt += 1
print(cnt)


Fixed submission:
n = int(input())
cnt = 0
for a in range(1, n):
    bn = (n-1) // a
    for b in range(1, bn+1):
        c = n-(a*b)
        if c<=0: break
        if a*b + c == n:
            cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
# a*b + c=n (a,b,c) いくつ？
cnt = 0
for a in range(1, n+1):
    bn = (n) // a
    for b in range(1, bn+1):
        c = n-(a*b)
        if c<=0: break
        if a*b + c == n:
            cnt += 1


print(cnt)


Fixed submission:
n = int(input())
cnt = 0
for a in range(1, n):
    bn = (n-1) // a
    for b in range(1, bn+1):
        c = n-(a*b)
        if c<=0: break
        if a*b + c == n:
            cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [*map(int, input().split())]
MOD = (10**9)+7
ans = 0
for i in range(n):
    for j in range(i+1, n):
        ans = (ans + A[i]*A[j]%MOD) % MOD
ans = (ans + MOD) % MOD
print(ans)


Fixed submission:
n = int(input())
A = [*map(int, input().split())]
MOD = (10**9)+7
ans = 0

# print(A)

sum_a = [0] * (n+1)
for i in range(n):
    sum_a[i+1] = sum_a[i] + A[i]

# print(sum_a)

for i in range(n):
    ai = A[i]
    ans = (ans + ai*(sum_a[-1] - sum_a[i+1])) % MOD
    # print(sum_a[-1], sum_a[i+1],sum_a[-1] - sum_a[i+1] )

# for i in range(n):
#     for j in range(i+1, n):
#         ans = (ans + A[i]*A[j]%MOD) % MOD
ans = (ans + MOD) % MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
r, g, b = map(int, input().split())
t = 0
while r >= g: g *= 2; t += 1
while g >= b: b *= 2; t += 1
print('No' if t > int(input()) else 'Yes')


Fixed submission:
n, k = map(int, input().split())
A = [*map(int, input().split())]
for i in range(k, n):
    if A[i-k] < A[i]: print('Yes')
    else: print('No')

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A = [*map(int, input().split())]

pre = 1
for i in range(k):
    pre *= A[i]

for i in range(k,n):
    now = pre//A[i-k] *A[i]
    if pre < now:
        print('Yes')
    else:
        print('No')
    pre = now


Fixed submission:
n, k = map(int, input().split())
A = [*map(int, input().split())]
for i in range(k, n):
    if A[i-k] < A[i]: print('Yes')
    else: print('No')

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A = [*map(int, input().split())]
# print(n,k)
# print(A)

pre = 1
for i in range(k):
    pre *= A[i]


now = pre
for i in range(k,n):
    now *= A[i]
    now /= A[i-k]
    if pre < now:
        print('Yes')
    else:
        print('No')
    pre = now


Fixed submission:
n, k = map(int, input().split())
A = [*map(int, input().split())]
for i in range(k, n):
    if A[i-k] < A[i]: print('Yes')
    else: print('No')

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A = [*map(int, input().split())]
# print(n,k)
# print(A)

pre = 1
for i in range(k):
    pre *= A[i]


now = pre
for i in range(k,n):
    now *= A[i]
    now /= A[i-k]
    if pre < now:
        print('Yes')
    else:
        print('No')
    pre = now


Fixed submission:
n, k = map(int, input().split())
A = [*map(int, input().split())]
for i in range(k, n):
    if A[i-k] < A[i]: print('Yes')
    else: print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [*map(int, input().split())]

def dfs(i, yen, kabu_yen, kabu_n):
    # print(i, yen, kabu_yen, kabu_n)

    if i>=n:
        return yen

    a = b = c = 0
    if yen >= A[i]: # 買える
        m = yen // A[i]
        a = dfs(i+1, yen - m*A[i], kabu_yen + m*A[i], kabu_n + m) # 買う
    if kabu_n > 0: # 売れる
        b = dfs(i+1,  yen + kabu_n*A[i], 0, 0) # 売る
    c = dfs(i+1, yen, kabu_yen, kabu_n) # 何もしない
    mx = max(a,b,c)
    return mx

mx = dfs(0, 1000, 0,0)
print(mx)



Fixed submission:
n = int(input())
A = [*map(int, input().split())] + [0]

yen = 1000
kabu_yen = 0
kabu_n = 0
last_buy = -1
for i in range(1,n+1):
    if A[i-1] < A[i]: # buy : after up
        tanka = A[i-1]
        m = yen // tanka
        cost = tanka * m
        yen -= cost
        kabu_yen += cost
        kabu_n += m

    elif A[i-1] > A[i]: # sell: after down
        yen += A[i-1] * kabu_n
        kabu_yen = 0
        kabu_n = 0

print(yen)