Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


L = LI2()
N = len(L)
mod = 10**9+7

ans = 0
a = 1
for i in range(N):
    if L[i] == 1:
        ans += pow(3,N-i-1)*a
        ans %= mod
        a *= 2
        a %= mod

print((ans+a) % mod)


Fixed submission:
import sys

def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし

L = LI2()
l = len(L)
mod = 10**9+7

A = []
for i in range(l):
    if L[i] == 1:
        A.append(l-i-1)
A.append(0)

ans = 0
for i in range(len(A)):
    ans += pow(3,A[i],mod)*pow(2,i,mod)
    ans %= mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = list(map(int,input().split()))
data = [list(map(int,input().split())) for i in range(M)]

A.sort()

from operator import itemgetter

data = sorted(data,key = itemgetter(1),reverse=True)

B = []
for i,j in data:
    B += [j]*i

for i in range(min(N,len(B))):
    if A[i] < B[i]:
        A[i] = B[i]
print(sum(A))

Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
data = [list(map(int,input().split())) for i in range(M)]

A.sort()

from operator import itemgetter

data = sorted(data,key = itemgetter(1),reverse=True)

B = []
for i,j in data:
    if len(B) > N:
        break
    else:
        B += [j]*i

for i in range(min(N,len(B))):
    if A[i] < B[i]:
        A[i] = B[i]
print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque,defaultdict

N,M = map(int,input().split())
data = [list(map(int,input().split())) for i in range(M)]

G = defaultdict(list)
for i in range(M):
    G[data[i][0]].append(data[i][1])
    G[data[i][1]].append(data[i][0])

D = [0]+[-1]*(N)

c = 0
for i in range(1,N+1):
    if D[i] != -1:
        continue
    else:
        q = deque([i])
        while q:
            n = q.pop()
            D[n] = 0
            for d in G[n]:
                if D[d] != -1:
                    continue
                else:
                    q.append(d)
        c += 1

print(c)

Fixed submission:
from collections import deque,defaultdict

N,M = map(int,input().split())
data = [list(map(int,input().split())) for i in range(M)]

G = defaultdict(list)
for i in range(M):
    G[data[i][0]].append(data[i][1])
    G[data[i][1]].append(data[i][0])

D = [0]+[-1]*(N)

c = 0
for i in range(1,N+1):
    if D[i] != -1:
        continue
    else:
        q = deque([i])
        while q:
            n = q.pop()
            D[n] = 0
            for d in G[n]:
                if D[d] != -1:
                    continue
                else:
                    q.append(d)
        c += 1

print(c)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H,W = map(int,input().split())
A = [list(input()) for i in range(H)]

directions = [[-1,0],[1,0],[0,-1],[0,1]]

D = [[-1]*W for i in range(H)]

B = []
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            B.append([i,j])
            D[i][j] = 0

q = deque(B)

while q:
    nh,nw= q.pop()
    for dh,dw in directions:
        if not (0<= nh+dh < H and 0 <= nw+dw < W):
            continue
        elif D[nh+dh][nw+dw] != -1:
            continue
        elif A[nh+dh][nw+dw] == '#':
            D[nh+dh][nw+dw] = D[nh][nw]
            q.append([nh+dh,nw+dw])
        elif A[nh+dh][nw+dw] == '.':
            D[nh+dh][nw+dw] = D[nh][nw]+1
            q.appendleft([nh+dh,nw+dw])

print(max(max(D[i]) for i in range(H)))

Fixed submission:
from collections import deque

H,W = map(int,input().split())
A = [list(input()) for i in range(H)]

directions = [[-1,0],[1,0],[0,-1],[0,1]]

D = [[-1]*W for i in range(H)]

B = []
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            B.append([i,j])
            D[i][j] = 0

q = deque(B)

while q:
    nh,nw= q.pop()
    for dh,dw in directions:
        if not (0<= nh+dh < H and 0 <= nw+dw < W):
            continue
        elif D[nh+dh][nw+dw] != -1:
            continue
        elif A[nh+dh][nw+dw] == '#':
            D[nh+dh][nw+dw] = D[nh][nw]
            q.append([nh+dh,nw+dw])
        elif A[nh+dh][nw+dw] == '.':
            D[nh+dh][nw+dw] = D[nh][nw]+1
            q.appendleft([nh+dh,nw+dw])

print(max(max(D[i]) for i in range(H)))
Buggy python submission (verdict: Runtime Error):
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()

ans = 0
for i in range(N):
    v,c = LI()
    if v-c > 0:
        ans += v-c

print(ans)

Fixed submission:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
V = LI()
C = LI()

ans = 0
for i in range(N):
    v,c = V[i],C[i]
    if v-c > 0:
        ans += v-c

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

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()

from functions import gcd

L = [0]*N  # L[i] = A[0]からA[i]までの最大公約数
R = [0]*N  # R[i] = A[i]からA[N-1]までの最大公約数

for i in range(N-1):
    if i == 0:
        L[i] = A[i]
        R[N-1-i] = A[N-1-i]
    else:
        L[i] = gcd(L[i-1],A[i])
        R[N-1-i] = gcd(R[N-i],A[N-1-i])

a = max(L[N-1],R[1])

if N == 2:
    print(a)
else:
    print(max(a,max(gcd(L[i],R[i+2]) for i in range(N-2))))

Fixed submission:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()

from fractions import gcd

L = [0]*N  # L[i] = A[0]からA[i]までの最大公約数
R = [0]*N  # R[i] = A[i]からA[N-1]までの最大公約数

for i in range(N-1):
    if i == 0:
        L[i] = A[i]
        R[N-1-i] = A[N-1-i]
    else:
        L[i] = gcd(L[i-1],A[i])
        R[N-1-i] = gcd(R[N-i],A[N-1-i])

a = max(L[N-2],R[1])

if N == 2:
    print(a)
else:
    print(max(a,max(gcd(L[i],R[i+2]) for i in range(N-2))))

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

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()

from math import gcd

L = [0]*N  # L[i] = A[0]からA[i]までの最大公約数
R = [0]*N  # R[i] = A[i]からA[N-1]までの最大公約数

for i in range(N-1):
    if i == 0:
        L[i] = A[i]
        R[N-1-i] = A[N-1-i]
    else:
        L[i] = gcd(L[i-1],A[i])
        R[N-1-i] = gcd(R[N-i],A[N-1-i])

a = max(L[N-1],R[1])

if N == 2:
    print(a)
else:
    print(max(a,max(gcd(L[i],R[i+2]) for i in range(N-2))))

Fixed submission:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()

from fractions import gcd

L = [0]*N  # L[i] = A[0]からA[i]までの最大公約数
R = [0]*N  # R[i] = A[i]からA[N-1]までの最大公約数

for i in range(N-1):
    if i == 0:
        L[i] = A[i]
        R[N-1-i] = A[N-1-i]
    else:
        L[i] = gcd(L[i-1],A[i])
        R[N-1-i] = gcd(R[N-i],A[N-1-i])

a = max(L[N-2],R[1])

if N == 2:
    print(a)
else:
    print(max(a,max(gcd(L[i],R[i+2]) for i in range(N-2))))
Buggy python submission (verdict: Runtime Error):
import sys

def S(): return sys.stdin.readline().rstrip()

A,B = map(int,S().split())

def f(n):  # 0からnまでのxor
    res = 0
    while n % 4 != 3:
        res ^= n
        n -= 1

print(f(B) ^ f(A-1))

Fixed submission:
import sys

def S(): return sys.stdin.readline().rstrip()

A,B = map(int,S().split())

def f(n):  # 0からnまでのxor
    res = 0
    for i in range(41):  # 2**iの位
        if i == 0:
            res += ((n+1)//2) % 2
        else:
            a = n - ((n >> (i+1)) << (i+1))
            if a < 2**i or a % 2 == 1:
                continue
            else:
                res += 1 << i
    return res

print(f(B) ^ f(A-1))
Buggy python submission (verdict: Runtime Error):
rom collections import Counter

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

A = []
B = []
for i in range(n):
    if i % 2 == 0:
        A.append(v[i])
    else:
        B.append(v[i])

C = Counter(A)
D = Counter(B)

E = C.most_common()
F = D.most_common()

E += [(-1,0)]
F += [(-1,0)]

if E[0][0] != F[0][0]:
    print(n-E[0][1]-F[0][1])
else:
    print(n-max(E[0][1]+F[1][1],E[1][1]+F[0][1]))

Fixed submission:
from collections import Counter

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

A = []
B = []
for i in range(n):
    if i % 2 == 0:
        A.append(v[i])
    else:
        B.append(v[i])

C = Counter(A)
D = Counter(B)

E = C.most_common()
F = D.most_common()

E += [(-1,0)]
F += [(-1,0)]

if E[0][0] != F[0][0]:
    print(n-E[0][1]-F[0][1])
else:
    print(n-max(E[0][1]+F[1][1],E[1][1]+F[0][1]))
Buggy python submission (verdict: Runtime Error):
import sys

N,K = map(int,sys.stdin.readline().rstrip().split())

print(0 if N % K == 0 else 1)

Fixed submission:
import sys

def I():
    return int(sys.stdin.readline().rstrip())

N = I()

A = [1,2,3,5,6,9,10,13,17]
if N in A:
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
A = LI()
for i in range(N):
    A[i] -= i+1
A.sort()

x = A[N//2]
y = A[(N-1)//2]
z = (A[x]+A[y])//2

print(sum(abs(A[i]-z) for i in range(N)))


Fixed submission:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
A = LI()
for i in range(N):
    A[i] -= i+1
A.sort()


def f(x):
    return sum(abs(A[i]-x) for i in range(N))


print(f((A[(N-1)//2]+A[N//2])//2))
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
mod = 10**9+7

if N == 2:
    print(1)
    exit()
elif N == 3:
    print(4)
    exit()

kaijou = [1]
for i in range(1,N+1):
    kaijou.append((kaijou[-1]*i) % mod)

kaijou_inverse = [1]
for i in range(1,N+1):
    kaijou_inverse[i] = pow(kaijou[i],mod-2,mod)

def nCr(n,r):
    if n < r:
        return 0
    return (kaijou_inverse[n]*kaijou_inverse[r]*kaijou_inverse[n-r]) % mod

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

print(ans)


Fixed submission:
import sys
def I(): return int(sys.stdin.readline().rstrip())


N = I()
mod = 10**9+7


fac = [1]*(N+1)
for i in range(1,N+1):
    fac[i] = (fac[i-1]*i) % mod

fac_inverse = [1]*(N+1)
for i in range(1,N+1):
    fac_inverse[i] = pow(fac[i],mod-2,mod)


def nCr(n,r):
    if n < r:
        return 0
    return (fac[n]*fac_inverse[r]*fac_inverse[n-r]) % mod


A = [0]*(N+1)  # Ai = i回以下マシンを稼働することで、全て黒く塗られるような順列の個数
for i in range(N+1):
    A[i] = (fac[i]*fac[N-1-i]*nCr(i-1,N-1-i)) % mod

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

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

A,B = MI()

if B > 1:
    q1,r1 = (B-1)//50,(B-1)%50
    q1 += 1
else:
    q1 = 0
if A > 1:
    q2,r2 = (A-1)//50,(A-1)%50
    q2 += 1
else:
    q2 = 0

print(2*(q1+q2),100)

for i in range(2*q1):
    if i % 2 == 1:
        print(''.join(['.']*100))
    elif i != 2*q1-2:
        print(''.join(*['.','#']*50))
    else:
        print(''.join(['.','#']*r1 + ['.']*(100-2*r1)))

for i in range(2*q2):
    if i % 2 == 0:
        print(''.join(['#']*100))
    elif i != 2*q2-1:
        print(''.join(['#','.']*50))
    else:
        print(''.join(['#','.']*r2 + ['#']*(100-2*r2)))


Fixed submission:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

A,B = MI()

q1,r1 = (B-1)//50,(B-1)%50
q1 += 1
q2,r2 = (A-1)//50,(A-1)%50
q2 += 1

if B > 1 and A > 1:
    print(2*(q1+q2),100)
elif (B == 1 and A > 1) or (B > 1 and A == 1):
    print(2*(q1+q2)-1,100)
else:
    print(2,100)

if B > 1:
    for i in range(2 * q1):
        if i % 2 == 1:
            print(''.join(['.'] * 100))
        elif i != 2 * q1 - 2:
            print(''.join(['.', '#'] * 50))
        else:
            print(''.join(['.', '#'] * r1 + ['.'] * (100 - 2 * r1)))
else:
    print(''.join(['.']*100))


if A > 1:
    for i in range(2 * q2):
        if i % 2 == 0:
            print(''.join(['#'] * 100))
        elif i != 2 * q2 - 1:
            print(''.join(['#', '.'] * 50))
        else:
            print(''.join(['#', '.'] * r2 + ['#'] * (100 - 2 * r2)))
else:
    print(''.join(['#']*100))
Buggy python submission (verdict: Runtime Error):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,C = MI()
A = [[0]*(10**5+1) for i in range(C+1)]
for i in range(N):
    s,t,c = MI()
    A[c][s] += 1
    A[c][t+1] -= 1

from itertools import accumulate

for i in range(1,C+1):
    A[i] = list(accumulate(A[i]))

# A[i][j] が正 ⇔ チャンネル i が時刻 j に録画機が必要

ans = 0
for j in range(10**5+1):
    ans = max(ans,sum(A[i][j] > 0 for i in range(1,C+1)))

print(ans)


Fixed submission:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,C = MI()
A = [[0]*(10**5+2) for i in range(C+1)]
for i in range(N):
    s,t,c = MI()
    A[c][s] += 1
    A[c][t+1] -= 1

from itertools import accumulate

for i in range(1,C+1):
    A[i] = list(accumulate(A[i]))

# A[i][j] が正 ⇔ チャンネル i が時刻 j に録画機が必要

ans = 0
for j in range(10**5+2):
    ans = max(ans,sum(A[i][j] > 0 for i in range(1,C+1)))

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
def I(): return int(sys.stdin.readline().rstrip())

K = I()

Graph = [0]*K
for i in range(K):
    if (i+1) % K != (10*i) % K:
        Graph[i] = [(1,(i+1) % K),(0,(10*i) % K)]  # 1を加える,10倍する
    else:
        Graph[i] = [(0,(10*i) % K)]

# dijkstra

from heapq import heappush,heappop

d = [100]*K
d[1] = 1
q = []
heappush(q,(1,1))
v = [False]*K
while q:
    a,n = heappop(q)
    if v[n]:
        continue
    v[a] = True
    for da,dn in Graph[n]:
        if v[dn]:
            continue
        if a+da < d[dn]:
            d[dn] = a+da
            heappush(q,(a+da,dn))

print(d[0])


Fixed submission:
import sys
def I(): return int(sys.stdin.readline().rstrip())

K = I()

Graph = [0]*K
for i in range(K):
    if (i+1) % K != (10*i) % K:
        Graph[i] = [((i+1) % K,1),((10*i) % K,0)]  # 1を加える,10倍する
    else:
        Graph[i] = [((10*i) % K,0)]

from collections import deque

q = deque([1])
d = [100]*K
d[1] = 1
# 01-BFS
while q:
    n = q.pop()
    if n == 0:
        continue
    else:
        for a,b in Graph[n]:
            if d[a] > d[n]+b:
                d[a] = d[n]+b
                if b == 0:
                    q.append(a)
                else:
                    q.appendleft(a)

print(d[0])
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,K = MI()
S = LI2()

A = []
a = 1
for i in range(1,N):
    if S[i-1] == S[i]:
        a += 1
    else:
        A.append(a)
        a = 1
A.append(a)

l = len(A)
if l <= 2*K-1:
    print(N)
    exit()

if S[0] == 1:
    A = [1]+A
if S[-1] == 1:
    A = A+[1]

A = [0]+A
l = len(A)

from itertools import accumulate

A = list(accumulate(A))
ans = 0
for i in range(l//2-K+1):
    if i == 0:
        ans = max(ans,A[2*(K+i)]-A[2*i])
    elif i == l//2-K:
        ans = max(ans,A[2*(K+i)-1]-A[2*i-1])
    else:
        ans = max(ans,A[2*(K+i)]-A[2*i-1])

print(ans)


Fixed submission:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


A = LS2()
N = len(A)

from collections import defaultdict

d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1


ans = 0
for key in d.keys():
    ans += d[key]*(N-d[key])

ans //= 2
ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

def I(): return int(sys.stdin.readline().rstrip())

N = I()
T = [I() for _ in range(N)]

from math import gcd

ans = T[0]
for i in range(N-1):
    ans = (ans*T[i+1])//gcd(ans,T[i+1])

print(ans)

Fixed submission:
import sys

def I(): return int(sys.stdin.readline().rstrip())

N = I()
T = [I() for _ in range(N)]

from fractions import gcd

ans = T[0]
for i in range(N-1):
    ans = (ans*T[i+1])//gcd(ans,T[i+1])

print(ans)
Buggy python submission (verdict: Runtime Error):
N = I()
A = LI()
B = [0]*(10**5+1)
for a in A:
    B[a] += 1

print(sum(B[i] != 0 for i in range(10**5+1))-(sum(max(0,B[i]-1) for i in range(10**5+1)) % 2))


Fixed submission:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
A = LI()
B = sorted(set(A))
d = {}
for b in B:
    d[b] = 0
for a in A:
    d[a] += 1

C = [d[b] for b in B]

ans = len(B)
x = sum(c-1 for c in C)
if x % 2 == 1:
    ans -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from copy import deepcopy
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,x = MI()
A = LI()
B = deepcopy(A)
A += A

ans = sum(B)
for k in range(1,N+1):
    for i in range(N):
        B[i] = min(B[i],A[N+i-k])
        ans = min(ans,sum(B)+k*x)

print(ans)


Fixed submission:
import sys
from copy import deepcopy
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,x = MI()
A = LI()
B = deepcopy(A)
A += A

ans = sum(B)
for k in range(1,N+1):
    for i in range(N):
        B[i] = min(B[i],A[N+i-k])
    ans = min(ans,sum(B)+k*x)

print(ans)
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
T = int(input())

count = 0
x = int((T+0.5)/A)
for i in range(1,x+1):
    count += B

print(count)

Fixed submission:
A, B, T = (int(i) for i in input().split())

count = 0
for i in range(0, int(T/A)):
    count += B

print(count)
Buggy python submission (verdict: Runtime Error):
k = int(input())
s = ''
for i in range(K):
  s += 'ACL'
print(s)

Fixed submission:
k = int(input())
s = ''
for i in range(k):
  s += 'ACL'
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# from time import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

# mod = int(1e9+7)
mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n,k = readInt()
    s = set()
    for i in range(k):
        l,r = readInt()
        for j in range(l,r+1):
            s.add(j)
    s = list(s)
    s.sort()
    dp = [0 for i in range(n)]
    dp[0] = 1
    for i in range(n):
        if dp[i]==-1:
            continue
        for j in range(len(s)):
            if i+s[j]>=n:
                break
            dp[i+s[j]] += dp[i]
            dp[i+s[j]] %= mod
    print(dp[n-1])
    return

if __name__=='__main__':
    main()


Fixed submission:
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
import bisect
# import heapq # priolity-queue
# from time import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

# mod = int(1e9+7)
mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n,k = readInt()
    l = []
    r = []
    for i in range(k):
        a,b = readInt()
        l.append(a)
        r.append(b)
    dp = [0 for i in range(n+1)]
    dp[1] = 1
    dpsum = [0 for i in range(n+1)]
    dpsum[1] = 1
    for i in range(2,n+1):
        for j in range(k):
            lj = max(1,i - r[j])
            rj = i - l[j]
            if rj<1:
                continue
            dp[i] += dpsum[rj] - dpsum[lj-1]
            dp[i] %= mod
        dpsum[i] = dpsum[i-1] + dp[i]
    print(dp[n])
    return

if __name__=='__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n%9==0:
  print("Yes")
else:
  prinrt("No")

Fixed submission:
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n = input()
    res = 0
    for i in range(len(n)):
        res += int(n[i])
    if res%9==0:
        print("Yes")
    else:
        print("No")
    return

if __name__=='__main__':
    main()