Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

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

answer = max(C)
for i in range(N):
  pos = P[i] - 1
  score = C[pos]
  score_list = [score]
  step = 1
  while pos!=i and step<K:
    pos = P[pos] - 1
    score += C[pos]
    score_list.append(score)
    step += 1
  if score_list[-1]>0 and step<K:
    loop = K//step
    amari = K%step
    score_max_tmp = 0
    for j in range(step):
      if j<amari:
        score_max_tmp = max(score_max_tmp, score_list[-1]+score_list[j])
      else:
        score_max_tmp = max(score_max_tmp, score_list[j])
    score_max = score_max_tmp+score_list[-1]*(loop-1)
  else:
    score_max = max(score_list)
  answer = max(answer,score_max)

print(answer)


Fixed submission:
# -*- coding: utf-8 -*-

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

answer = max(C)
for i in range(N):
  pos = P[i] - 1
  score = C[pos]
  score_list = [score]
  step = 1
  while pos!=i and step<K:
    pos = P[pos] - 1
    score += C[pos]
    score_list.append(score)
    step += 1
  score_max = max(score_list)
  if score_list[-1]>0 and step<K:
    loop = K//step
    amari = K%step
    for j in range(step):
      if j<amari:
        score_max = max(score_max, score_list[-1]*loop+score_list[j])
      else:
        score_max = max(score_max, score_list[-1]*(loop-1)+score_list[j])
  answer = max(answer,score_max)

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

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

answer = max(C)
for i in range(N):
  pos = P[i] - 1
  score = C[pos]
  score_list = [score]
  step = 1
  while pos!=i and step<K:
    pos = P[pos] - 1
    score += C[pos]
    score_list.append(score)
    step += 1
  score_max = max(score_list)
  if score_list[-1]>0 and step<K:
    loop = K//step
    amari = K%step
    for j in range(step):
      if j<amari:
        score_max = max(score_max, score_list[-1]*loop+score_list[j])
      else:
        score_max = max(score_max, score_list[-1]*(loop-1)+score_list[j])
  answer = max(answer,score_max)

print(answer)

Fixed submission:
# -*- coding: utf-8 -*-

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

answer = max(C)
for i in range(N):
  pos = P[i] - 1
  score = C[pos]
  score_list = [score]
  step = 1
  while pos!=i and step<K:
    pos = P[pos] - 1
    score += C[pos]
    score_list.append(score)
    step += 1
  score_max = max(score_list)
  if score_list[-1]>0 and step<K:
    loop = K//step
    amari = K%step
    for j in range(step):
      if j<amari:
        score_max = max(score_max, score_list[-1]*loop+score_list[j])
      else:
        score_max = max(score_max, score_list[-1]*(loop-1)+score_list[j])
  answer = max(answer,score_max)

print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N = int(input())
A = [input() for _ in range(N)]

def count(a):
  if '.' in a:
    c = a.split('.')
    n = int(c[0]+c[1])
    count2 = count5 = 9 - len(c[1])
  else:
    n = int(a)
    count2 = count5 = 9
  while n%2==0 and count2<18:
    n //= 2
    count2 += 1
  while n%5==0 and count5<18:
    n //= 5
    count5 += 1
  return count2, count5

Z = [[0 for _ in range(19)] for _ in range(19)]
answer = 0
for a in A:
  c2, c5 = count(a)
  answer += Z[18-c2][18-c5]
  for i in range(c2+1):
    for j in range(c5+1):
      Z[i][j] += 1

print(answer)

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
from decimal import Decimal

N = int(input())
A = [int(10**9*Decimal(input())) for _ in range(N)]

Z = np.zeros((20,20), dtype=int)

def count2(a):
  n = a
  count = 0
  while n%2 == 0:
    n //= 2
    count += 1
  return count

def count5(a):
  n = a
  count = 0
  while n%5 == 0:
    n //= 5
    count += 1
  return count

answer = 0
for a in A:
  c2 = count2(a)
  c5 = count5(a)
  t2 = max(18-c2,0)
  t5 = max(18-c5,0)
  #answer += np.sum(Z[t2:,t5:])
  #Z[min(19,c2),min(19,c5)] += 1
  answer += Z[t2,t5]
  Z[:min(19,c2)+1,:min(19,c5)+1] += 1

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np
from decimal import Decimal

N = int(input())
A = [Decimal(input()) for _ in range(N)]

Z = np.zeros((50,50), dtype=int)

def count2(a):
  n = a
  count = 0
  while n%2 == 0:
    n //= 2
    count += 1
  return count

def count5(a):
  n = a
  count = 0
  while n%5 == 0:
    n //= 5
    count += 1
  return count

answer = 0
for i in range(N):
  a = int(A[i]*10**9)
  c2 = count2(a)
  c5 = count5(a)
  t2 = max(18-c2,0)
  t5 = max(18-c5,0)
  if i>0:
    answer += np.sum(Z[t2:,t5:])
  Z[c2,c5] += 1

print(answer)

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
from decimal import Decimal

N = int(input())
A = [int(10**9*Decimal(input())) for _ in range(N)]

Z = np.zeros((20,20), dtype=int)

def count2(a):
  n = a
  count = 0
  while n%2 == 0:
    n //= 2
    count += 1
  return count

def count5(a):
  n = a
  count = 0
  while n%5 == 0:
    n //= 5
    count += 1
  return count

answer = 0
for a in A:
  c2 = count2(a)
  c5 = count5(a)
  t2 = max(18-c2,0)
  t5 = max(18-c5,0)
  #answer += np.sum(Z[t2:,t5:])
  #Z[min(19,c2),min(19,c5)] += 1
  answer += Z[t2,t5]
  Z[:min(19,c2)+1,:min(19,c5)+1] += 1

print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys

N,*A = map(int, sys.stdin.buffer.read().split())

A = sorted(A)
setA = set(A)

def yakusu(x):
  if x==1:
    return []
  result = [1]
  y = 2
  while y**2<=x:
    if x%y==0:
      result.append(y)
      result.append(x//y)
    y += 1
  return result

count = N
for i in range(N):
  a = A[i]
  if i>0 and a==A[i-1]:
    count -= 1
    continue
  if i<N-1 and a==A[i+1]:
    count -= 1
    continue
  y = 1
  while y**2<=a:
    if a%y==0:
      if y!=a and y in setA:
        count -= 1
        break
      if a//y!=a and a//y in setA:
        count -= 1
        break
    y += 1

print(count)

Fixed submission:
# -*- coding: utf-8 -*-
import sys

N,*A = map(int, sys.stdin.buffer.read().split())

S = [0 for _ in range(10**6+1)]
T = [0 for _ in range(10**6+1)]

for a in A:
  S[a] += 1

count = 0
for i in range(1,10**6+1):
  if T[i] == 1:
    continue
  if S[i] == 0:
    continue
  if S[i] == 1:
    count += 1
  for j in range(10**6//i+1):
    T[i*j] = 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys

N,*A = map(int, sys.stdin.buffer.read().split())

A = sorted(A)
setA = set(A)

def yakusu(x):
  if x==1:
    return []
  result = [1]
  y = 2
  while y**2<=x:
    if x%y==0:
      result.append(y)
      result.append(x//y)
    y += 1
  return result

count = N
for i in range(N):
  a = A[i]
  if i>0 and a==A[i-1]:
    count -= 1
    continue
  if i<N-1 and a==A[i+1]:
    count -= 1
    continue
  for y in yakusu(a):
    if y in setA:
      count -= 1
      break

print(count)

Fixed submission:
# -*- coding: utf-8 -*-
import sys

N,*A = map(int, sys.stdin.buffer.read().split())

S = [0 for _ in range(10**6+1)]
T = [0 for _ in range(10**6+1)]

for a in A:
  S[a] += 1

count = 0
for i in range(1,10**6+1):
  if T[i] == 1:
    continue
  if S[i] == 0:
    continue
  if S[i] == 1:
    count += 1
  for j in range(10**6//i+1):
    T[i*j] = 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

H,W,K = map(int, input().split())
x1,y1,x2,y2 = map(int, input().split())

C = [input() for _ in range(H)]
T = [[-1 for _ in range(W)] for _ in range(H)]
T[x1-1][y1-1] = 0

que = [(x1-1,y1-1)]
step = 1

while len(que)>0:
  que_next = []
  for q in que:
    x,y = q[0],q[1]
    for i in range(1,K+1):
      if x-i<0:
        break
      if C[x-i][y]=='@' or T[x-i][y]==1:
        break
      if x-i==x2-1 and y==y2-1:
        print(step)
        exit()
      que_next.append((x-i,y))
    for i in range(1,K+1):
      if x+i>H-1:
        break
      if C[x+i][y]=='@' or T[x+i][y]==1:
        break
      if x+i==x2-1 and y==y2-1:
        print(step)
        exit()
      que_next.append((x+i,y))
    for i in range(1,K+1):
      if y-i<0:
        break
      if C[x][y-i]=='@' or T[x][y-i]==1:
        break
      if x==x2-1 and y-i==y2-1:
        print(step)
        exit()
      que_next.append((x,y-i))
    for i in range(1,K+1):
      if y+i>W-1:
        break
      if C[x][y+i]=='@' or T[x][y+i]==1:
        break
      if x==x2-1 and y+i==y2-1:
        print(step)
        exit()
      que_next.append((x,y+i))
  que = que_next
  for q in que:
    T[q[0]][q[1]] = 1
  step += 1

print(-1)

Fixed submission:
# -*- coding: utf-8 -*-

H,W,K = map(int, input().split())
x1,y1,x2,y2 = map(int, input().split())

C = [input() for _ in range(H)]
T = [[-1 for _ in range(W)] for _ in range(H)]
T[x1-1][y1-1] = 0

que = {(x1-1,y1-1):0}
step = 1

while len(que)>0:
  que_next = {}
  for q in que.keys():
    x,y = q[0],q[1]
    for i in range(1,K+1):
      if x-i<0:
        break
      if C[x-i][y]=='@' or T[x-i][y]==1:
        break
      if x-i==x2-1 and y==y2-1:
        print(step)
        exit()
      que_next[(x-i,y)] = 0
    for i in range(1,K+1):
      if x+i>H-1:
        break
      if C[x+i][y]=='@' or T[x+i][y]==1:
        break
      if x+i==x2-1 and y==y2-1:
        print(step)
        exit()
      que_next[(x+i,y)] = 0
    for i in range(1,K+1):
      if y-i<0:
        break
      if C[x][y-i]=='@' or T[x][y-i]==1:
        break
      if x==x2-1 and y-i==y2-1:
        print(step)
        exit()
      que_next[(x,y-i)] = 0
    for i in range(1,K+1):
      if y+i>W-1:
        break
      if C[x][y+i]=='@' or T[x][y+i]==1:
        break
      if x==x2-1 and y+i==y2-1:
        print(step)
        exit()
      que_next[(x,y+i)] = 0
  que = que_next
  for q in que.keys():
    T[q[0]][q[1]] = 1
  step += 1

print(-1)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys

N,K,*A = map(int, sys.stdin.buffer.read().split())

for _ in range(K):
  Anext = [0 for _ in range(N+1)]
  for i in range(N):
    Anext[max(0,i-A[i])] += 1
    Anext[min(N,i+A[i]+1)] -= 1
  cumsum = 0
  for i in range(N):
    cumsum += Anext[i]
    A[i] = cumsum
  if min(A)==N:
    break

print(' '.join([str(a) for a in A]))

Fixed submission:
# -*- coding: utf-8 -*-

S = input()
print(S[:3])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys

N,K,*A = map(int, sys.stdin.buffer.read().split())

for _ in range(K):
  Anext = [0 for _ in range(N+1)]
  for i in range(N):
    Anext[max(0,i-A[i])] += 1
    Anext[min(N,i+A[i]+1)] -= 1
  cumsum = 0
  for i in range(N):
    cumsum += Anext[i]
    A[i] = cumsum
  if min(A)==N:
    break

print(' '.join([str(a) for a in A]))

Fixed submission:
# -*- coding: utf-8 -*-
import sys

N,K,*A = map(int, sys.stdin.buffer.read().split())

for _ in range(K):
  Anext = [0 for _ in range(N+1)]
  for i in range(N):
    Anext[max(0,i-A[i])] += 1
    Anext[min(N,i+A[i]+1)] -= 1
  cumsum = 0
  for i in range(N):
    cumsum += Anext[i]
    A[i] = cumsum
  if min(A)==N:
    break

print(' '.join([str(a) for a in A]))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
S = input()
dict_amari = {}
count = 0

henkan = {i: [(10*j+i)%2019 for j in range(2019)] for i in range(1,10)}

def amari_new(dict_amari, s, henkan):
  dict_amari_new = {henkan[k] : v for k,v in dict_amari.items()}
  if s in dict_amari_new.keys():
    dict_amari_new[s] += 1
  else:
    dict_amari_new[s] = 1
  return dict_amari_new

for s in S:
  dict_amari = amari_new(dict_amari, int(s), henkan[int(s)])
  if 0 in dict_amari.keys():
    count += dict_amari[0]

print(count)


Fixed submission:
# -*- coding: utf-8 -*-
S = input()
list_amari = [0 for i in range(2019)]
amari_prev = 0
X = 1

for i in range(len(S)):
  amari = (int(S[-i-1])*X+amari_prev)%2019
  list_amari[amari] += 1
  amari_prev = amari
  X = (10*X)%2019

count = list_amari[0]
for v in list_amari:
  count += v*(v-1)//2

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
S = input()
dict_amari = {}
count = 0

henkan = {i: [(10*j+i)%2019 for j in range(2019)] for i in range(1,10)}

def amari_new(dict_amari, s, henkan):
  dict_amari_new = {henkan[k] : v for k,v in dict_amari.items()}
  if s in dict_amari_new.keys():
    dict_amari_new[s] += 1
  else:
    dict_amari_new[s] = 1
  return dict_amari_new

for s in S:
  dict_amari = amari_new(dict_amari, int(s), henkan[int(s)])
  if 0 in dict_amari.keys():
    count += dict_amari[0]

print(count)

Fixed submission:
# -*- coding: utf-8 -*-
S = input()
list_amari = [0 for i in range(2019)]
amari_prev = 0
X = 1

for i in range(len(S)):
  amari = (int(S[-i-1])*X+amari_prev)%2019
  list_amari[amari] += 1
  amari_prev = amari
  X = (10*X)%2019

count = list_amari[0]
for v in list_amari:
  count += v*(v-1)//2

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
S = input()
dict_amari = {}
count = 0

def amari_new(dict_amari, s):
  dict_amari_new = {(10*k+s)%2019 : v for k,v in dict_amari.items()}
  if s in dict_amari_new.keys():
    dict_amari_new[s] += 1
  else:
    dict_amari_new[s] = 1
  return dict_amari_new

for s in S:
  dict_amari = amari_new(dict_amari, int(s))
  if 0 in dict_amari.keys():
    count += dict_amari[0]

print(count)

Fixed submission:
# -*- coding: utf-8 -*-
S = input()
list_amari = [0 for i in range(2019)]
amari_prev = 0
X = 1

for i in range(len(S)):
  amari = (int(S[-i-1])*X+amari_prev)%2019
  list_amari[amari] += 1
  amari_prev = amari
  X = (10*X)%2019

count = list_amari[0]
for v in list_amari:
  count += v*(v-1)//2

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

answer = [max(A[0],A[1])]

for i in range(2,N):
  if i==2:
    answer.append(max(A[0],A[1],A[2]))
  elif i%2==0:
    answer.append(max(answer[-1], answer[-2]+A[i]))
  else:
    answer.append(max(answer[-2]+A[i], sum(A[:i-1:2])))

print(answer[-1])

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

answer = [max(A[0],A[1])]

list_sum = A[::2]
for i in range(1,len(list_sum)):
  list_sum[i] += list_sum[i-1]

for i in range(2,N):
  if i==2:
    answer.append(max(A[0],A[1],A[2]))
  elif i%2==0:
    answer.append(max(answer[-1], answer[-2]+A[i]))
  else:
    answer.append(max(answer[-2]+A[i], list_sum[(i-1)//2]))

print(answer[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans=0

for i in range(N-2):
    for j in range(i+1,N-1):
        if S[i]==S[j]:
            continue
        for k in range(j+1,N):
            if S[i]!=S[k] and S[j]!=S[k] and j-i!=k-j:
                ans+=1
print(ans)


Fixed submission:
N = int(input())
S = input()
ans=0

r=0
g=0
b=0

for i in range(N):
    if S[i]=="R":
        r+=1
    elif S[i]=="G":
        g+=1
    else:
        b+=1

ans=r*g*b

for j in range(1,N-1):
    for d in range(1,min(j,N-j-1)+1):
        if S[j-d]!= S[j] and S[j]!= S[j+d] and S[j-d]!= S[j+d]:
            ans-=1
print(ans)
Buggy python submission (verdict: Runtime Error):
X, Y, A, B, C = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]
R = [int(i) for i in input().split()]

 P = sorted(P)
 Q = sorted(Q)
 R = sorted(R)

 
A= P[:X] + Q[:Y] + R
A = sorted(A)
print(sum(A[:X+Y]))

Fixed submission:
X, Y, A, B, C = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]
R = [int(i) for i in input().split()]

P = sorted(P, reverse=True)
Q = sorted(Q, reverse=True)
R = sorted(R, reverse=True)

 
A= P[:X] + Q[:Y] + R
A = sorted(A, reverse=True)
print(sum(A[:X+Y]))
Buggy python submission (verdict: Runtime Error):

N, M=(int(i) for i in input().split())
P=[[int(i) for i in input().split()] for  _ in range(M)]
P=[[P[i][0]-1,P[i][1]] for i in range(M)]
f=True

ans=["*"]*N
for i in range(M):
    if ans[P[i][0]]!="*" and ans[P[i][0]]!=str(P[i][1]):
        print(-1)
        f=False
    else:
        ans[P[i][0]]=str(P[i][1])
if N==1 and P[0][1]==0 and f:
    print(0)
else:
    if f:
        if ans[0]=="*":
            ans[0]="1"
        for i in range(1,N):
            if ans[i]=="*":
                ans[i]="0"
        if len(str(int("".join(ans))))==N:
            print(int("".join(ans)))
        else:
            print(-1)

Fixed submission:

N, M=(int(i) for i in input().split())
P=[[int(i) for i in input().split()] for  _ in range(M)]
P=[[P[i][0]-1,P[i][1]] for i in range(M)]
f=True

ans=["*"]*N
for i in range(M):
    if ans[P[i][0]]!="*" and ans[P[i][0]]!=str(P[i][1]):
        print(-1)
        f=False
    else:
        ans[P[i][0]]=str(P[i][1])
if M>0:
    if N==1 and P[0][1]==0 and f:
        print(0)
    else:
        if f:
            if ans[0]=="*":
                ans[0]="1"
            for i in range(1,N):
                if ans[i]=="*":
                    ans[i]="0"
            if len(str(int("".join(ans))))==N:
                print(int("".join(ans)))
            else:
                print(-1)
else:
    if N==1:
        print(0)
    elif N==2:
        print(10)
    else:
        print(100)

Buggy python submission (verdict: Runtime Error):

N, M=(int(i) for i in input().split())
P=[[int(i) for i in input().split()] for  _ in range(M)]
P=[[P[i][0]-1,P[i][1]] for i in range(M)]
f=True

ans=["*"]*N
for i in range(M):
    if ans[P[i][0]]!="*" and ans[P[i][0]]!=str(P[i][1]):
        print(-1)
        f=False
    else:
        ans[P[i][0]]=str(P[i][1])
if N==1 and P[0][1]==0 and f:
    print(0)
else:
    if f:
        if ans[0]=="*":
            ans[0]=1
        for i in range(1,N):
            if ans[i]=="*":
                ans[i]="0"
        if len(str(int("".join(ans))))==N:
            print(int("".join(ans)))
        else:
            print(-1)


Fixed submission:

N, M=(int(i) for i in input().split())
P=[[int(i) for i in input().split()] for  _ in range(M)]
P=[[P[i][0]-1,P[i][1]] for i in range(M)]
f=True

ans=["*"]*N
for i in range(M):
    if ans[P[i][0]]!="*" and ans[P[i][0]]!=str(P[i][1]):
        print(-1)
        f=False
    else:
        ans[P[i][0]]=str(P[i][1])
if M>0:
    if N==1 and P[0][1]==0 and f:
        print(0)
    else:
        if f:
            if ans[0]=="*":
                ans[0]="1"
            for i in range(1,N):
                if ans[i]=="*":
                    ans[i]="0"
            if len(str(int("".join(ans))))==N:
                print(int("".join(ans)))
            else:
                print(-1)
else:
    if N==1:
        print(0)
    elif N==2:
        print(10)
    else:
        print(100)
Buggy python submission (verdict: Time Limit Exceeded):
#確率は(p_i+1)/2
N, K=(int(i) for i in input().split())
P=[int(i) for i in input().split()]

Q=[(P[i]+1)/2 for i in range(len(P))]
R=[sum(Q[:i]) for i in range(len(Q)+1)]
maxp=0
for i in range(N-K+1):
        maxp=max((R[i+K]-R[i]), maxp)
print(maxp)

Fixed submission:
#確率は(p_i+1)/2
N, K=(int(i) for i in input().split())
P=[int(i) for i in input().split()]

Q=[(P[i]+1)/2 for i in range(len(P))]
R=[0]*(len(Q)+1)
for i in range(1,len(R)):
    R[i] = R[i-1] + Q[i-1]
maxp=0
for i in range(N-K+1):
        maxp=max((R[i+K]-R[i]), maxp)
print(maxp)
Buggy python submission (verdict: Time Limit Exceeded):
N, K=(int(i) for i in input().split())
A=[int(i) for i in input().split()]
A= sorted(A)

from math import factorial

inf=10**9+7
ans=0

for i in range(K, N+1):
    #(N-1)C(K-1)
    ans+=(A[i-1]*factorial(i-1) // factorial(K-1) // factorial(i-1-K+1))%inf
for i in range(1, N-K+2):
    #(N-i)C(K-1)
    ans-=(A[i-1]*factorial(N-i) // factorial(K-1) // factorial(N-i-K+1))%inf
print(ans%inf)



Fixed submission:

N, K=(int(i) for i in input().split())
A=[int(i) for i in input().split()]
A= sorted(A)

from math import factorial

inf=10**9+7
ans=0

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
p = 10 ** 9 + 7
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)


for i in range(K, N+1):
    #(N-1)C(K-1)
    ans+=(A[i-1]*cmb(i-1, K-1,p))%inf
for i in range(1, N-K+2):
    #(N-i)C(K-1)
    ans-=(A[i-1]*cmb(N-i, K-1,p))%inf
print(ans%inf)
Buggy python submission (verdict: Runtime Error):
a, b=(int(i) for i in input().split())

import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

print(lcm(a, b))
# 12



Fixed submission:

A=int(input())
B=int(input())

if (A==1) and (B==2):
    print(3)
elif (A==1) and (B==3):
    print(2)
elif (A==2) and (B==1):
    print(3)
elif (A==2) and (B==3):
    print(1)
elif (A==3) and (B==1):
    print(2)
elif (A==3) and (B==2):
    print(1)
Buggy python submission (verdict: Runtime Error):

a, b=(int(i) for i in input().split())

import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(a, b))


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

import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

print(lcm(a, b))
Buggy python submission (verdict: Time Limit Exceeded):

N=int(input())
S=input()

tree_1=[]
tree_2=[]
tree_3=[]

for i in range(0,N):
    for e2 in tree_2:
        if len(tree_3)!=0:
            if (e2+S[i] in tree_3)!=True:
                tree_3.append(e2+S[i])
        else:
            tree_3.append(e2+S[i])
    for e1 in tree_1:
        if len(tree_2)!=0:
            if (e1+S[i] in tree_2)!=True:
                tree_2.append(e1+S[i])
        else:
            tree_2.append(e1+S[i])
    if len(tree_1)!=0:
        if (S[i] in tree_1)!=True:
            tree_1.append(S[i])
    else:
        tree_1.append(S[i])
print(len(tree_3))

Fixed submission:

N=int(input())
S=input()

tree_1=[]
tree_2=[]
tree_3=[]

for i in range(0,N):
    for e2 in tree_2:
        tree_3.append(e2+S[i])
    for e1 in tree_1:
        if len(tree_2)!=0:
            if (e1+S[i] in tree_2)!=True:
                tree_2.append(e1+S[i])
        else:
            tree_2.append(e1+S[i])
    if len(tree_1)!=0:
        if (S[i] in tree_1)!=True:
            tree_1.append(S[i])
    else:
        tree_1.append(S[i])
print(len(set(tree_3)))
Buggy python submission (verdict: Runtime Error):

import sys
sys.setrecursionlimit(10000000)

N=int(input())

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


c=[0,0,0]
ans=1

for i in range(N):
    s=sum([c[j]==A[i] for j in range(0,3)])
    c[c.index(A[i])]+=1
    ans=(ans*s)%1000000007

print(ans%1000000007)

Fixed submission:

N=int(input())

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


c=[0,0,0]
ans=1
uncho=True

for i in range(N):
    s=sum([c[j]==A[i] for j in range(0,3)])
    if s==0:
        uncho=False
        print(0)
        break
    c[c.index(A[i])]+=1
    ans=(ans*s)%1000000007

if uncho:
    print(ans%1000000007)

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

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


c=[0,0,0]
ans=1

for i in range(N):
    s=sum([c[j]==A[i] for j in range(0,3)])
    c[c.index(A[i])]+=1
    ans=(ans*s)%1000000007

print(ans%1000000007)

Fixed submission:

N=int(input())

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


c=[0,0,0]
ans=1
uncho=True

for i in range(N):
    s=sum([c[j]==A[i] for j in range(0,3)])
    if s==0:
        uncho=False
        print(0)
        break
    c[c.index(A[i])]+=1
    ans=(ans*s)%1000000007

if uncho:
    print(ans%1000000007)

Buggy python submission (verdict: Runtime Error):


N=int(input())

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


c=[0,0,0]
ans=1

for i in range(N):
    s=sum([c[j]==A[i] for j in range(0,3)])
    c[c.index(A[i])]+=1
    ans=ans*s

print(ans%1000000007)



Fixed submission:

N=int(input())

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


c=[0,0,0]
ans=1
uncho=True

for i in range(N):
    s=sum([c[j]==A[i] for j in range(0,3)])
    if s==0:
        uncho=False
        print(0)
        break
    c[c.index(A[i])]+=1
    ans=(ans*s)%1000000007

if uncho:
    print(ans%1000000007)