Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = list(input())
index_A = [i for i, v in enumerate(S) if v == 'A']

for i in range(Q):
    ans = 0
    l, r = map(int, input().split())
    for j in index_A:
        if l-1 <= j <= r-2:
            if S[i + 1] == 'C':
                ans += 1
    print(ans)


Fixed submission:
N, Q = map(int, input().split())
S = input()
t= [0] * (N + 1)

for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)

for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
Buggy python submission (verdict: Runtime Error):
S = input()
s = S[4:6] + S[7:9]
s = int(s)

if s < 501:
  print('Heisei')
else:
  print('TBD')

Fixed submission:
S = input()
s = S[5:7] + S[8:10]
s = int(s)

if s < 501:
  print('Heisei')
else:
  print('TBD')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

# dpテーブル
dp = [10 ** 9] * N

# 初期値
dp[0] = 0
dp[1] = abs(h[1] - h[0])

# ループ
for i in range(2, N):
    dp[i] = min((dp[i - j] + abs(h[i] - h[i - j])) for j in range(min(i + 1, K + 1)))
        
# 解を出力
print(dp[N - 1])


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

# DPテーブル
dp = [10 ** 10] * N

# 初期値
dp[0] = 0

# ループ
for i in range(1, N):
    for j in range(1, K + 1):
        if i - j < 0:
            pass
        else:
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

# 解を出力
print(dp[N - 1])

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

# dpテーブル
dp = [10 ** 9] * N

# 初期値
dp[0] = 0
dp[1] = abs(h[1] - h[0])

# ループ
for i in range(2, N):
    for j in range(min(i + 1, K + 1)):
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

# 解を出力
print(dp[N - 1])


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

# DPテーブル
dp = [10 ** 10] * N

# 初期値
dp[0] = 0

# ループ
for i in range(1, N):
    for j in range(1, K + 1):
        if i - j < 0:
            pass
        else:
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

# 解を出力
print(dp[N - 1])

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

# DPテーブル
dp = [10 ** 10] * N

# 初期値
dp[0] = 0

# ループ
for i in range(1, N):
    for j in range(1, K + 1):
        if i - j < 0:
            pass
        else:
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

# 解を出力
print(dp[N - 1]) 


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

# DPテーブル
dp = [10 ** 10] * N

# 初期値
dp[0] = 0

# ループ
for i in range(1, N):
    for j in range(1, K + 1):
        if i - j < 0:
            pass
        else:
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

# 解を出力
print(dp[N - 1])
Buggy python submission (verdict: Runtime Error):
D = int(input())

if D = 25:
  print('Christmas')
elif D = 24:
  print('Christmas Eve')
elif D = 23:
  print('Christmas Eve Eve')
else:
  print('Christmas Eve Eve Eve')

Fixed submission:
D = int(input())

if D == 25:
  print('Christmas')
elif D == 24:
  print('Christmas Eve')
elif D == 23:
  print('Christmas Eve Eve')
else:
  print('Christmas Eve Eve Eve')
Buggy python submission (verdict: Runtime Error):
N = int(input())
XYH = [list(map(int, input().split())) for _ in range(N)]
H_list= [XYH[i][2] for i in range(N)]
H_max = max(H_list)
H_min = min(H_list)
H_diff = H_max - H_min
ans = []

# 高さH,中心座標を(Cx, Cy)として総当たりで試す
for H in range(H_max - (200 - H_diff), H_max + (201 - H_diff)):
    for Cx in range(0, 101):
        for Cy in range(0, 101):
            count = 0
            for X, Y, h in XYH:
                if h == max(H - abs(X - Cx) - abs(Y - Cy), 0):
                    count += 1
                else:
                    break

            if count == N:
                ans = [str(Cx), str(Cy), str(H)]

print(' '.join(ans))




Fixed submission:
N = int(input())
if N == 1:
  print('Hello World')
else:
  A = int(input())
  B = int(input())
  print(A + B)

Buggy python submission (verdict: Runtime Error):
N = int(input())
if N == 1:
  print('Hello World')
else:
  A, B = map(int, input().split())
  print(A + B)

Fixed submission:
N = int(input())
if N == 1:
  print('Hello World')
else:
  A = int(input())
  B = int(input())
  print(A + B)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
XYH = [list(map(int, input().split())) for _ in range(N)]
H_max = max([XYH[i][2] for i in range(N)])

ans = []

# 高さH,中心座標を(Cx, Cy)として総当たりで試す
for H in range(H_max - 200, H_max + 201):
    for Cx in range(0, 101):
        for Cy in range(0, 101):
            count = 0
            for X, Y, h in XYH:
                if h == max(H - abs(X - Cx) - abs(Y - Cy), 0):
                    count += 1
                else:
                    break

            if count == N:
                ans = [str(Cx), str(Cy), str(H)]

print(' '.join(ans))



Fixed submission:
N = int(input())
XYH = [list(map(int, input().split())) for _ in range(N)]
H_list= [XYH[i][2] for i in range(N)]
H_max = max(H_list)
H_min = min(H_list)
H_diff = H_max - H_min
ans = []

# 高さH,中心座標を(Cx, Cy)として総当たりで試す
for H in range(H_max - (200 - H_diff), H_max + (201 - H_diff)):
    for Cx in range(0, 101):
        for Cy in range(0, 101):
            count = 0
            for X, Y, h in XYH:
                if h == max(H - abs(X - Cx) - abs(Y - Cy), 0):
                    count += 1
                else:
                    break

            if count == N:
                ans = [str(Cx), str(Cy), str(H)]

print(' '.join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
XYH = [list(map(int, input().split())) for _ in range(N)]
H_max = max([XYH[i][2] for i in range(N)])

ans = []

# 高さH,中心座標を(Cx, Cy)として総当たりで試す
for H in range(H_max - 200, H_max + 201):
    for Cx in range(0, 101):
        for Cy in range(0, 101):
            count = 0
            for X, Y, h in XYH:
                if h == max(H - abs(X - Cx) - abs(Y - Cy), 0):
                    count += 1
                else:
                    pass

            if count == N:
                ans = [str(Cx), str(Cy), str(H)]

print(' '.join(ans))


Fixed submission:
N = int(input())
XYH = [list(map(int, input().split())) for _ in range(N)]
H_list= [XYH[i][2] for i in range(N)]
H_max = max(H_list)
H_min = min(H_list)
H_diff = H_max - H_min
ans = []

# 高さH,中心座標を(Cx, Cy)として総当たりで試す
for H in range(H_max - (200 - H_diff), H_max + (201 - H_diff)):
    for Cx in range(0, 101):
        for Cy in range(0, 101):
            count = 0
            for X, Y, h in XYH:
                if h == max(H - abs(X - Cx) - abs(Y - Cy), 0):
                    count += 1
                else:
                    break

            if count == N:
                ans = [str(Cx), str(Cy), str(H)]

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

M = max(A, B, C)

SUM = M*(2**K)

if M == A:
	SUM+=(B+C)

if M == B:
	SUM+=(A+C)

if M == C:
	SUM+=(A+B)

print(SUM)


Fixed submission:
a, b = map(int, input().split())

if b < a:
	print(a-1)
else:
	print(a)

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

M = max(A, B, C)

SUM = M*(2**K)

print(M)

if M == A:
	SUM+=(B+C)

if M == B:
	SUM+=(A+C)

if M == C:
	SUM+=(A+B)

print(SUM)


Fixed submission:
a, b = map(int, input().split())

if b < a:
	print(a-1)
else:
	print(a)

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

M = max(A, B, C)

SUM = M*(2**K)

print(M)

if M == A:
	SUM+=(B+C)

if M == B:
	SUM+=(A+C)

if M == C:
	SUM+=(A+B)

print(SUM)


Fixed submission:
a, b = map(int, input().split())

if b < a:
	print(a-1)
else:
	print(a)
Buggy python submission (verdict: Runtime Error):
S = sort(input())

if S == 'abc':
	print('Yes')
else:
	print('No')

Fixed submission:
S = list(input())
S.sort()
a = ''.join(S)
if a == 'abc':
	print('Yes')
else:
	print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A_set = set(A)

A_dict = {}
for i in A_set:
    A_dict[i] = A.count(i)
A_dict = sorted(A_dict.items(), key=lambda x:x[1])

ans = 0
if len(A_set) > K:
    for i in range(len(A_set) - K):
        ans += A_dict[i][1]
        
print(ans)


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

A_dict = {x:0 for x in A_set}
for i in A:
    A_dict[i] += 1
A_dict = sorted(A_dict.items(), key=lambda x:x[1])

ans = 0
if len(A_set) > K:
    for i in range(len(A_set) - K):
        ans += A_dict[i][1]
        
print(ans)

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

A_dict = {}
for i in A_set:
    A_dict[i] = A.count(i)
A_dict = sorted(A_dict.items(), key=lambda x:x[1])

ans = 0
if len(A_set) > K:
    for i in range(len(A_set) - K):
        ans += A_dict[i][1]
        
print(ans)


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

A_dict = {x:0 for x in A_set}
for i in A:
    A_dict[i] += 1
A_dict = sorted(A_dict.items(), key=lambda x:x[1])

ans = 0
if len(A_set) > K:
    for i in range(len(A_set) - K):
        ans += A_dict[i][1]
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A_set = set(A)
A_set_len = len(A_set)
rewrite_set = A_set_len - K

A_dict = {}
for i in A_set:
    A_dict[i] = A.count(i)

A_dict_values = sorted(A_dict.values())

ans = 0
if rewrite_set > 0:
    ans = sum(A_dict_values[:rewrite_set])

print(ans)

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

A_dict = {x:0 for x in A_set}
for i in A:
    A_dict[i] += 1
A_dict = sorted(A_dict.items(), key=lambda x:x[1])

ans = 0
if len(A_set) > K:
    for i in range(len(A_set) - K):
        ans += A_dict[i][1]
        
print(ans)
Buggy python submission (verdict: Runtime Error):
ABCD = input()

for i in range(2 ** 3):
    op = format(i, '03b')
    op = op.replace('1', '+').replace('0', '-')
    formula = ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2]
    if eval(formula) == 7:
        print(formula + '=7')
        break

Fixed submission:
ABCD = input()

for i in range(2 ** 3):
    op = format(i, '03b')
    op = op.replace('1', '+').replace('0', '-')
    formula = ABCD[0] + op[0] + ABCD[1] + op[1] + ABCD[2] + op[2] + ABCD[3]
    if eval(formula) == 7:
        print(formula + '=7')
        break
Buggy python submission (verdict: Runtime Error):
X, Y = input().split()

if X > Y:
  print('>')
elif X = Y:
  print('=')
else:
  print('<')

Fixed submission:
X, Y = input().split()

if X > Y:
  print('>')
elif X == Y:
  print('=')
else:
  print('<')
Buggy python submission (verdict: Runtime Error):
C1 = input()
C2 = input()

if C1[0] == C[2] and C1[1] == C2[1] and C1[2] == C2[0]:
  print('YES')
else:
  print('NO')

Fixed submission:
C1 = input()
C2 = input()

if C1[0] == C2[2] and C1[1] == C2[1] and C1[2] == C2[0]:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
if A == B:
  print('C')
elif B == C:
  print('A')
else:
  print('B)

Fixed submission:
A, B, C = map(int, input().split())
if A == B:
  print(C)
elif B == C:
  print(A)
else:
  print(B)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()

ans = 0
a = A[0]
work = 1
for i in (1, N):
    if A[i] == a:
        work += 1
    else:
        if work % 2 == 0:
            pass
        else:
            ans += 1
        work = 1
        a = A[i]

print(ans)

Fixed submission:
'''
全量のリストを用いると検索対象が大きくなってしまうため、ディクショナリで都度追加/削除する
'''

N = int(input())

A = {}

for _ in range(N):
    tmp = int(input())
    if tmp in A:
        del A[tmp]
    else:
        A[tmp] = 1

print(len(A))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]
As = set(A)

ans = 0
for a in As:
    if A.count(a) % 2 == 0:
        pass
    else:
        ans += 1

print(ans)

Fixed submission:
'''
全量のリストを用いると検索対象が大きくなってしまうため、ディクショナリで都度追加/削除する
'''

N = int(input())

A = {}

for _ in range(N):
    tmp = int(input())
    if tmp in A:
        del A[tmp]
    else:
        A[tmp] = 1

print(len(A))

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

A = []
for _ in range(N):
    a = int(input())
    if a in A:
        A.remove(a)
    else:
        A.append(a)

print(len(A))

Fixed submission:
'''
全量のリストを用いると検索対象が大きくなってしまうため、ディクショナリで都度追加/削除する
'''

N = int(input())

A = {}

for _ in range(N):
    tmp = int(input())
    if tmp in A:
        del A[tmp]
    else:
        A[tmp] = 1

print(len(A))

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

A = []
for _ in range(N):
    a = int(input())
    if a in A:
        A.remove(a)
    else:
        A.append(a)

print(len(A))

Fixed submission:
'''
全量のリストを用いると検索対象が大きくなってしまうため、ディクショナリで都度追加/削除する
'''

N = int(input())

A = {}

for _ in range(N):
    tmp = int(input())
    if tmp in A:
        del A[tmp]
    else:
        A[tmp] = 1

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

# aiの各値の個数を数える
a_dict = {}
for i in a_set:
    a_dict[i] = a.count(i)

ans = 0
for i in range(1, 10 ** 5):
    work = 0
    if (i - 1) in a_set:
        work += a_dict[i - 1]
    if i in a_set:
        work += a_dict[i]
    if (i + 1) in a_set:
        work += a_dict[i + 1]
    ans = max(ans, work)

print(ans)

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

# ある値がaに存在するとき、その＋ー1の値を足す
## ans_list[-1]となる場合向けにlistは1個余分に値を設けておく
ans_list = [0] * (10 ** 5 + 2)

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

ans = max(ans_list)

print(ans)

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

# aiの各値の個数を数える
a_dict = {}
for i in a_set:
    a_dict[i] = a.count(i)

ans = 0
for i in range(1, 10 ** 5):
    work = 0
    if (i - 1) in a_set:
        work += a_dict[i - 1]
    if i in a_set:
        work += a_dict[i]
    if (i + 1) in a_set:
        work += a_dict[i + 1]
    ans = max(ans, work)

print(ans)

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

# ある値がaに存在するとき、その＋ー1の値を足す
## ans_list[-1]となる場合向けにlistは1個余分に値を設けておく
ans_list = [0] * (10 ** 5 + 2)

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

ans = max(ans_list)

print(ans)
Buggy python submission (verdict: Runtime Error):
x, a, b = map(int, input().split())
if (abs(x - a) < abs(x - b):
    print('A')
else:
    print('B')

Fixed submission:
x, a, b = map(int, input().split())
if abs(x - a) < abs(x - b):
    print('A')
else:
    print('B')
Buggy python submission (verdict: Runtime Error):
r, g, b = input().split()
print('YES' int(g+b)%4==0 else 'NO')

Fixed submission:
r, g, b = input().split()
print('YES' if int(g+b)%4==0 else 'NO')
Buggy python submission (verdict: Runtime Error):
w = list(input())
s = set(w)
ans = 'Yes'

for i in range(len(s)):
  if w.count(s[0]) % 2 == 1:
    ans = 'No'
    break

    print(ans)

Fixed submission:
w = list(input())
s = set(w)
s = list(s)
ans = 'Yes'

for i in range(len(s)):
  if w.count(s[i]) % 2 == 1:
    ans = 'No'
    break

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

print(int((1 + N) * N / 2)

Fixed submission:
N = int(input())

print(int((1 + N) * N / 2))
Buggy python submission (verdict: Runtime Error):
N = int(input())
d = {}
d['AC'] = 0
d['WA'] = 0
d['TLE'] = 0
d['RE'] = 0

for i in range(N):
  x = input()
  d[x] +=1
for j in d.keys():
  print(j + " " + "x" + " " + str(d[j]))
  print("\n")
 
  


Fixed submission:
N = int(input())
if N%1000 == 0:
  print(0)
else:
  
  a = N//1000 + 1
  print(a*1000 -N)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
x = 1

for i in range(N):
  x*= A[i]
  
if x>pow(10,18):
  print(-1)
else:
  print(x)
  
  


Fixed submission:
A,B = map(int,input().split())
print(A*B)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
x = 1
t = 0
for i in range(N):
  x*= A[i]
  
if x>10**18:
  print(-1)
else:
  print(x)
  
  


Fixed submission:
N = int(input())
A = list(map(int,input().split()))
x = 1
t = 0
A.sort()
for i in range(N):
  x*= A[i]
  if x>10**18:
    t = 1
    break
  
if t == 1:
  print(-1)
else:
  print(x)
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
if (T[:-1] == S):
  return "Yes"
else :
  return "No"

Fixed submission:
S = input()
T = input()
if T[:-1] == S :
  print("Yes")
else :
  print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
l = []
for i in range(N):
  x = input()
  l.append(x)
s = len(list(set(l))
print(s)


Fixed submission:
N = int(input())
l = []
for i in range(N):
    x = input()
    l.append(x)
s = set(l)
t = list(s)
print(len(t))
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[10]:


N,K = map(int,input().split())
new = abs(N-K)
while(new<N):
    N = new
    new = abs(new-K)
print(N)



Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[10]:


N,K = map(int,input().split())
new = N % K
n2 = K - new

print(min(new,n2))

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

# In[10]:


N,K = int(input()), int(input())
new = abs(N-K)
while(new<N):
    N = new 
    new = abs(new-K)
print(N)



Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[10]:


N,K = map(int,input().split())
new = N % K
n2 = K - new

print(min(new,n2))

Buggy python submission (verdict: Runtime Error):
N = int(input())
K = int(input())
n1 = N%K
n2 = K -n1
print(min(n1,n2))

Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[10]:


N,K = map(int,input().split())
new = N % K
n2 = K - new

print(min(new,n2))

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

# In[10]:


N,K = int(input()), int(input())
new = abs(N%K)
while(new<N):
    N = new
    new = abs(new%K)
print(N)



Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[10]:


N,K = map(int,input().split())
new = N % K
n2 = K - new

print(min(new,n2))

Buggy python submission (verdict: Runtime Error):
N,K = int(input()), int(input())
new = abs(N-K)
while(new<N):
    N = new
    new = abs(new-K)
print(N)



Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[10]:


N,K = map(int,input().split())
new = N % K
n2 = K - new

print(min(new,n2))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
dp = [0 for i in range(N)]
dp[0] = 0
dp[1] = abs(A[1] - A[0])
for i in range(2,N):
  dp[i] = min( dp[i-1] + abs(A[i] - A[i-1]),dp[i-2] + abs(A[i] - A[i-2]))
  
print(dp[n-1])


Fixed submission:
N = int(input())
A = list(map(int,input().split()))
dp = [0 for i in range(N)]
dp[0] = 0
dp[1] = abs(A[1] - A[0])
for i in range(2,N):
  dp[i] = min( dp[i-1] + abs(A[i] - A[i-1]),dp[i-2] + abs(A[i] - A[i-2]))
  
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
#!/usr/local/bin/python3

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

def f(x, m):
    return x**2 % m

check = [False for _ in range(M)]
d = [X]
max_x = 0
for _ in range(1, N+1):
    X = f(X, M)
    if check[X]:
        break
    else:
        check[X] = True
    d.append(X)

idx = d.index(X)
ans = sum(d[:idx])
N -= idx
d = d[idx:]

sumd = sum(d)
ans += N//len(d) * sumd

ans += sum(d[:N%len(d)])

print(ans)


Fixed submission:
S = input()
if S[-1] == 's':
    print(S+'es')
else:
    print(S+'s')
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/local/bin/python3

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

def f(x, m):
    return x**2 % m

d = [X]
for _ in range(1, N+1):
    X = f(X, M)
    if X in d:
        break
    d.append(X)

idx = d.index(X)
ans = sum(d[:idx])
N -= idx
d = d[idx:]

sumd = sum(d)
ans += N//len(d) * sumd

ans += sum(d[:N%len(d)])

print(ans)


Fixed submission:
#!/usr/local/bin/python3

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

def f(x, m):
    return x**2 % m

check = [False for _ in range(M)]
d = [X]
max_x = 0
for _ in range(1, N+1):
    X = f(X, M)
    if check[X]:
        break
    else:
        check[X] = True
    d.append(X)

idx = d.index(X)
ans = sum(d[:idx])
N -= idx
d = d[idx:]

sumd = sum(d)
ans += N//len(d) * sumd

ans += sum(d[:N%len(d)])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/local/bin/python3
N = int(input())
A = list(map(int, input().split()))[::-1]

ans = 0
while N != 0:
    m = max(A)
    idx = A.index(m) + 1
    ans += (len(A[:idx]) * m) - sum(A[:idx])
    A = A[idx:]
    N -= idx

print(ans)


Fixed submission:
#!/usr/local/bin/python3
N = int(input())
A = list(map(int, input().split()))

m = ans = 0
for i in range(N):
    m = max(m, A[i])
    ans += m - A[i]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/local/bin/python3
_ = int(input())
A = list(map(int, input().split()))[::-1]

ans = 0
while len(A) != 0:
    m = max(A)
    idx = A.index(m) + 1
    for i in A[:idx]:
        ans += m - i
    A = A[idx:]

print(ans)


Fixed submission:
#!/usr/local/bin/python3
N = int(input())
A = list(map(int, input().split()))

m = ans = 0
for i in range(N):
    m = max(m, A[i])
    ans += m - A[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

if __name__ == "__main__":
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    score = reduce(mul, A[:K])
    for i in range(K, len(A)):
        if A[i-K] < A[i]:
            print("Yes")
        else:
            print("No")


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

    for i in range(K, len(A)):
        if A[i-K] < A[i]:
            print("Yes")
        else:
            print("No")