Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,t=map(int,input().split())
dish=[list(map(int,input().split())) for i in range(n)]
dish.sort()
dp=[0]*6001
for i in range(n):
    a,b=dish[i]
    for j in range(t-1,-1,-1):
        dp[j+a]=max(dp[j+a],dp[j]+b)
print(max(dp))

Fixed submission:
n,t=map(int,input().split())
dish=[list(map(int,input().split())) for i in range(n)]
dish.sort()
dp=[0]*6001
for i in range(n):
    a,b=dish[i]
    for j in range(t-1,-1,-1):
        dp[j+a]=max(dp[j+a],dp[j]+b)
print(max(dp))

Buggy python submission (verdict: Time Limit Exceeded):
#典型dp
n,t=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x:x[0])
m=ab[-1][0]
dp=[0]*(t+m)

for i in range(n):
    dp_sub=[0]*(t+m)
    for j in range(t):
        if j==0:
            #print(ab[i][1])
            dp_sub[ab[i][0]]=ab[i][1]
        else:
            if dp[j]!=0:
                #print(ab[i][0])
                #print()
                dp_sub[j+ab[i][0]]=dp[j]+ab[i][1]
    for j in range(t+m):
        dp[j]=max(dp[j],dp_sub[j])
print(max(dp))
#print(len(dp))


Fixed submission:
n,t=map(int,input().split())
dish=[list(map(int,input().split())) for i in range(n)]
dish.sort()
dp=[0]*6001
for i in range(n):
    a,b=dish[i]
    for j in range(t-1,-1,-1):
        dp[j+a]=max(dp[j+a],dp[j]+b)
print(max(dp))

Buggy python submission (verdict: Time Limit Exceeded):
#典型dp
n,t=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x:x[0],reverse=True)
m=ab[0][0]
ab.sort(key=lambda x:x[0])
dp=[0]*(t+m)

for i in range(n):
    dp_sub=[0]*(t+m)
    for j in range(t):
        if j==0:
            #print(ab[i][1])
            dp_sub[ab[i][0]]=ab[i][1]
        else:
            if dp[j]!=0:
                #print(ab[i][0])
                #print()
                dp_sub[j+ab[i][0]]=dp[j]+ab[i][1]
    for j in range(t+m):
        dp[j]=max(dp[j],dp_sub[j])
print(max(dp))
#print(len(dp))


Fixed submission:
n,t=map(int,input().split())
dish=[list(map(int,input().split())) for i in range(n)]
dish.sort()
dp=[0]*6001
for i in range(n):
    a,b=dish[i]
    for j in range(t-1,-1,-1):
        dp[j+a]=max(dp[j+a],dp[j]+b)
print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
import math

n=int(input())

minimum=n-1
for i in range(1,n):
    if(n%i==0):
        minimum=min(minimum,(n//i-1)+(i-1))

print(minimum)


Fixed submission:
import math

n=int(input())
n2=int(math.sqrt(n))

minimum=n-1
for i in range(1,n2+1):
    if(n%i==0):
        minimum=min(minimum,(n//i-1)+(i-1))

print(minimum)
Buggy python submission (verdict: Runtime Error):
import math


a,b,x=map(int,input().split())

if 2*x<a*a*b:
    sit=math.acos(2*x/(a*b*b))
    print(math.degrees(sit))
elif x==a*a*b:
    print(0)
elif 2*x>a*a*b:
    p1=2*(a*a*b-x)
    p2=a*a*a
    sit=math.atan(p1/p2)
    print(math.degrees(sit))
else:
    print(45.00000)


Fixed submission:
import math


a,b,x=map(int,input().split())

if 2*x<a*a*b:
    sit=math.atan((a*b*b)/(2*x))
    print(math.degrees(sit))
elif 2*x>a*a*b:
    p1=2*(a*a*b-x)
    p2=a*a*a
    sit=math.atan(p1/p2)
    print(math.degrees(sit))
else:
    print(45.00000)

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


a,b,x=map(int,input().split())

if 2*x<a*a*b:
    sit=math.acos(2*x/(a*b*b))
    print(math.degrees(sit))
elif 2*x>a*a*b:
    p1=2*(a*a*b-x)
    p2=a*a*a
    sit=math.atan(p1/p2)
    print(math.degrees(sit))
else:
    print(45.00000)


Fixed submission:
import math


a,b,x=map(int,input().split())

if 2*x<a*a*b:
    sit=math.atan((a*b*b)/(2*x))
    print(math.degrees(sit))
elif 2*x>a*a*b:
    p1=2*(a*a*b-x)
    p2=a*a*a
    sit=math.atan(p1/p2)
    print(math.degrees(sit))
else:
    print(45.00000)

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


a,b,x=map(int,input().split())

if x<=(a**2)*b/2:
    sit=math.acos(2*x/(a*b*b))
    print(math.degrees(sit))
else:
    p1=a*a*b-x
    p2=a*a*a/2
    #print((-p1+math.sqrt(p1*p1+4*p2*p2))/2)
    sit=math.atan(p1/p2)
    print(math.degrees(sit))


Fixed submission:
import math


a,b,x=map(int,input().split())

if 2*x<a*a*b:
    sit=math.atan((a*b*b)/(2*x))
    print(math.degrees(sit))
elif 2*x>a*a*b:
    p1=2*(a*a*b-x)
    p2=a*a*a
    sit=math.atan(p1/p2)
    print(math.degrees(sit))
else:
    print(45.00000)
Buggy python submission (verdict: Time Limit Exceeded):
#OK牧場
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
#こっちは変えられない
f=sorted(list(map(int,input().split())),reverse=True)
l,r=0,10**12
def cal(x):
    global n,f,a,k
    ret=0
    for i in range(n):
        ret+=max(0,a[i]-(x//f[i]))
    #print(ret,x)
    return ret
while l+1<r:
    x=l+(r-l)//2
    if cal(x)<=k:
        r=x
    else:
        l=x
if cal(l)<=k:
    print(l)
else:
    print(r)

Fixed submission:
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
#こっちは変えられない
f=sorted(list(map(int,input().split())),reverse=True)
l,r=0,10**12
def cal(x):
    global n,f,a,k
    ret=0
    for i in range(n):
        ret+=max(0,a[i]-(x//f[i]))
    #print(ret,x)
    return ret
while l+1<r:
    x=l+(r-l)//2
    if cal(x)<=k:
        r=x
    else:
        l=x
if cal(l)<=k:
    print(l)
else:
    print(r)

Buggy python submission (verdict: Time Limit Exceeded):
import math

n,k=map(int,input().split())
a=sorted([int(i) for i in input().split()],reverse=True)
f=sorted([int(i) for i in input().split()])
c=[[a[i],f[i]] for i in range(n)]
c.sort(key=lambda x:x[0]*x[1],reverse=True)

if n==1:
    print(max(0,(c[0][0]-k)*c[0][1]))
else:
    while True:
        #print(c)
        if k==0 or c[0][0]==0:
            break
        elif c[0][0]*c[0][1]-c[1][0]*c[1][1]==0:
            k-=1
            c[0][0]-=1
        elif c[0][0]*c[0][1]-c[1][0]*c[1][1] < c[0][1]:
            k-=1
            c[0][0]-=1
        else:
            l=math.ceil((c[0][0]*c[0][1]-c[1][0]*c[1][1])/c[0][1])
            m=min(l,c[0][0])
            k-=m
            c[0][0]-=m
        for i in range(n-1):
            if c[i][0]*c[i][1]<=c[i+1][0]*c[i+1][1]:
                c[i],c[i+1]=c[i+1],c[i]
            else:
                break

    #print(c)
    print(c[0][0]*c[0][1])


Fixed submission:
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
#こっちは変えられない
f=sorted(list(map(int,input().split())),reverse=True)
l,r=0,10**12
def cal(x):
    global n,f,a,k
    ret=0
    for i in range(n):
        ret+=max(0,a[i]-(x//f[i]))
    #print(ret,x)
    return ret
while l+1<r:
    x=l+(r-l)//2
    if cal(x)<=k:
        r=x
    else:
        l=x
if cal(l)<=k:
    print(l)
else:
    print(r)
Buggy python submission (verdict: Runtime Error):
#二部グラフにできるのか
#ここからよ
#実は奇サイクルを含まない=二部グラフとなる
#それぞれのレベルで奇サイクルかどうか
#二部グラフを考えて残りでもどんどん二部グラフを考えるイメージ

#最終的には1or2の状態で残る
N=int(input())
ans=[[0]*N for j in range(N)]
#nはvecの長さ
#次の通路のレベル
def dfs(n,vec,level):
    global ans
    #print(vec)
    #print(n)
    l=vec[:n//2]
    r=vec[n//2:]
    for i in l:
        for j in r:
            ans[i][j]=level
    if len(l)>1:
        dfs(len(l),l,level+1)
    if len(r)>1:
        dfs(len(r),r,level+1)


dfs(N,[i for i in range(N)],1)
for i in range(N-1):
    a=[]
    for j in range(N):
        if i<j:
            a.append(str(ans[i][j]))
    print(" ".join(a))

Fixed submission:
m,d=input().split()
m,d=int(m),int(d)

c=0
if d<22:
    print(0)
else:
    for j in range(m):
        for i in range(d-21):
            d1,d10=int(str(i+22)[1]),int(str(i+22)[0])
            #print(d1)
            #print(d10)
            if d1>1 and d10>1 and d1*d10==j+1:
                c+=1
                #print(j+1,i+22)
    print(c)
Buggy python submission (verdict: Runtime Error):
N=int(input())
dic={}
for i in range(N):
    k="".join(sorted(list(input())))
    if k in dic:
        dic[k]+=1
    else:
        dic[k]=1
c=0
for i in dic:
    c += i*(i-1)

print(c//2)


Fixed submission:
N=int(input())
dic={}
for i in range(N):
    k="".join(sorted(list(input())))
    if k in dic:
        dic[k]+=1
    else:
        dic[k]=1
c=0
for i in dic.values():
    c += i*(i-1)

print(c//2)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s=[]
n=[]
for i in range(N):
    k="".join(sorted(list(input())))
    if k in s:
        n[s.index(k)]+=1
    else:
        s.append(k)
        n.append(1)
c=0
for i in n:
    c += i*(i-1)

print(c//2)


Fixed submission:
N=int(input())
dic={}
for i in range(N):
    k="".join(sorted(list(input())))
    if k in dic:
        dic[k]+=1
    else:
        dic[k]=1
c=0
for i in dic.values():
    c += i*(i-1)

print(c//2)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s=[]
for i in range(N):
    s.append(list(input()))
    s[i].sort()
    s[i]="".join(s[i])

c=0

for i in set(s):
    n=s.count(i)
    if n>1:
        c += (n*(n-1)//2)

print(c)


Fixed submission:
N=int(input())
dic={}
for i in range(N):
    k="".join(sorted(list(input())))
    if k in dic:
        dic[k]+=1
    else:
        dic[k]=1
c=0
for i in dic.values():
    c += i*(i-1)

print(c//2)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s=[]
for i in range(N):
    s.append(list(input()))
    s[i].sort()
    s[i]="".join(s[i])

sn=[x for x in set(s) if s.count(x) > 1]

c=0
for i in sn:
    n=s.count(i)
    c += (n*(n-1)//2)

print(c)


Fixed submission:
N=int(input())
dic={}
for i in range(N):
    k="".join(sorted(list(input())))
    if k in dic:
        dic[k]+=1
    else:
        dic[k]=1
c=0
for i in dic.values():
    c += i*(i-1)

print(c//2)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s=[]
for i in range(N):
    s.append(list(input()))
    s[i].sort()


c=0
for i in range(N):
    for j in range(N-i-1):
        if s[i]==s[j+i+1]:
            c+=1
print(c)


Fixed submission:
N=int(input())
dic={}
for i in range(N):
    k="".join(sorted(list(input())))
    if k in dic:
        dic[k]+=1
    else:
        dic[k]=1
c=0
for i in dic.values():
    c += i*(i-1)

print(c//2)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s=[]
for i in range(N):
    s.append(list(input()))
    
for i in range(N):
    s[i].sort()

c=0
for j in range(N):
    for i in range(N):
        if i<j:
            if s[i]==s[j]:
                c+=1
        else:
            break

print(c)


Fixed submission:
N=int(input())
dic={}
for i in range(N):
    k="".join(sorted(list(input())))
    if k in dic:
        dic[k]+=1
    else:
        dic[k]=1
c=0
for i in dic.values():
    c += i*(i-1)

print(c//2)
Buggy python submission (verdict: Runtime Error):
N=input()
H=[int(i) for i in input().split()]

#len(H)==1は別でOK
for i in range(len(H)-1):
    if H[i] > H[i+1]+1:
        print("No")
        break
    elif H[i] == H[i+1]+1:
        H[i]-=1
    elif i=0:
        H[i]-=1
    elif H[i-1] < H[i]:
        H[i]-=1
else:
    for i in range(len(H)-1):
        if H[i] > H[i+1]:
            print("No")
            break
    else:
        print("Yes")


Fixed submission:
N=input()
H=[int(i) for i in input().split()]

#len(H)==1は別でOK
for i in range(len(H)-1):
    if H[i] > H[i+1]+1:
        print("No")
        break
    elif H[i] == H[i+1]+1:
        H[i]-=1
    elif i==0:
        H[i]-=1
    elif H[i-1] < H[i]:
        H[i]-=1
else:
    for i in range(len(H)-1):
        if H[i] > H[i+1]:
            print("No")
            break
    else:
        print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
#LとRが変わる点に着目
#その点でどちらに行くかを繰り返す
#lの連続しているところの一番左に行く、rの連続しているところの右に行く
#偶数と奇数の時で変わりそう
#二つ入れた時にその繰り返しになったら止めれば良さそう
#二回を繰り返しの単位としてその二回でできたものが同じになっていれば終了
#deepcopyは使うなあほ
import copy
s=input()
n=len(s)

def make_new_list(a_1,a_2):
    for i in range(n):
        if s[i]=="L":
            a_2[i-1]+=a_1[i]
        else:
            a_2[i+1]+=a_1[i]



a0=[1]*n
a1=[0]*n
make_new_list(a0,a1)
a2=[0]*n
make_new_list(a1,a2)
a3=[0]*n
make_new_list(a2,a3)
a4=[0]*n
make_new_list(a3,a4)

while a1!=a3 or a2!=a4:
    a1=copy.deepcopy(a3)
    a2=copy.deepcopy(a4)
    a3=[0]*n
    make_new_list(a2,a3)
    a4=[0]*n
    make_new_list(a3,a4)

print(" ".join(list(map(str,a4))))


Fixed submission:
#こういう問題で実際に動かすやつはあほ、普通にチェンジするとこまで行って、どっちか(偶数だけ離れてるとこ)に集まるやろ
s=input()
n=len(s)
#変わる点というより変わる点にくる集まりを考えるべき
d=0
a=[]
ax=[0]

for i in range(n):
    l=len(ax)
    if l==1:
        if s[i]=="L":
            ax.append(i-1)
            ax.append(i)
        if i==n-1:
            ax.append(i)
            a.append(ax)
    elif l==3:
        if s[i]=="R":
            ax.append(i-1)
            a.append(ax)
            ax=[i]
        elif i==n-1:
            ax.append(i)
            a.append(ax)
m=len(a)
c=[0]*n
for i in range(m):
    #print(type(a[i][1]))
    #print(type(c[a[i][1]]))
    c[a[i][1]]=(a[i][1]-a[i][0])//2+(a[i][3]-a[i][1])//2+1
    c[a[i][2]]=(a[i][2]-a[i][0])//2+(a[i][3]-a[i][2])//2+1

print(" ".join(list(map(str,c))))

Buggy python submission (verdict: Time Limit Exceeded):
#LとRが変わる点に着目
#その点でどちらに行くかを繰り返す
#lの連続しているところの一番左に行く、rの連続しているところの右に行く
#偶数と奇数の時で変わりそう
#二つ入れた時にその繰り返しになったら止めれば良さそう
#二回を繰り返しの単位としてその二回でできたものが同じになっていれば終了
import copy
s=input()
n=len(s)

a=[1]*n

def make_new_list():
    global s,n,a
    ax=[0]*n
    for i in range(n):
        if s[i]=="L":
            ax[i-1]+=a[i]
        else:
            ax[i+1]+=a[i]
    a=copy.deepcopy(ax)
    return ax



a1=make_new_list()
#print(a1)
a2=make_new_list()
#print(a2)
a3=make_new_list()
#print(a3)
a4=make_new_list()
#print(a4)
while a1!=a3 or a2!=a4:
    #print(a1)
    #print(a2)
    #print(a3)
    #print(a4)
    a1=copy.deepcopy(a3)
    a2=copy.deepcopy(a4)
    a3=make_new_list()
    a4=make_new_list()
print(" ".join(list(map(str,a4))))


Fixed submission:
#こういう問題で実際に動かすやつはあほ、普通にチェンジするとこまで行って、どっちか(偶数だけ離れてるとこ)に集まるやろ
s=input()
n=len(s)
#変わる点というより変わる点にくる集まりを考えるべき
d=0
a=[]
ax=[0]

for i in range(n):
    l=len(ax)
    if l==1:
        if s[i]=="L":
            ax.append(i-1)
            ax.append(i)
        if i==n-1:
            ax.append(i)
            a.append(ax)
    elif l==3:
        if s[i]=="R":
            ax.append(i-1)
            a.append(ax)
            ax=[i]
        elif i==n-1:
            ax.append(i)
            a.append(ax)
m=len(a)
c=[0]*n
for i in range(m):
    #print(type(a[i][1]))
    #print(type(c[a[i][1]]))
    c[a[i][1]]=(a[i][1]-a[i][0])//2+(a[i][3]-a[i][1])//2+1
    c[a[i][2]]=(a[i][2]-a[i][0])//2+(a[i][3]-a[i][2])//2+1

print(" ".join(list(map(str,c))))
Buggy python submission (verdict: Time Limit Exceeded):
mod=10**9+7
s=input()[::-1]
l=len(s)
dp=[[0]*13 for i in range(l+1)]
dp[0][0]=1
for i in range(l):
    s_sub=s[i]
    if s_sub=="?":
        for j in range(13):
            for k in range(10):
                dp[i+1][(j+k*(10**i))%13]+=dp[i][j]
                dp[i+1][(j+k*(10**i))%13]%=mod
    else:
        k=int(s_sub)
        for j in range(13):
            dp[i+1][(j+k*(10**i))%13]+=dp[i][j]
            dp[i+1][(j+k*(10**i))%13]%=mod
print(dp[l][5]%mod)


Fixed submission:
mod=10**9+7
s=input()[::-1]
l=len(s)
dp=[[0]*13 for i in range(l+1)]
dp[0][0]=1
#累乗が大きすぎるので前計算
p=[0]*l
p[0]=1
for i in range(l-1):
    p[i+1]=(p[i]*10)%13
for i in range(l):
    s_sub=s[i]
    if s_sub=="?":
        for j in range(13):
            for k in range(10):
                dp[i+1][(j+k*p[i])%13]+=dp[i][j]
                dp[i+1][(j+k*p[i])%13]%=mod
    else:
        k=int(s_sub)
        for j in range(13):
            dp[i+1][(j+k*p[i])%13]+=dp[i][j]
            dp[i+1][(j+k*p[i])%13]%=mod
print(dp[l][5])
Buggy python submission (verdict: Runtime Error):
#また長さが1の時を考慮していない
#出来るだけループの外で計算する
n=int(input())
a=[int(input()) for i in range(n)]
m1=max(a)
m2=sorted(a,reverse=True)[1]
for i in range(n):
    if m==a[i]:
        print(m2)
    else:
        print(m1)


Fixed submission:
#また長さが1の時を考慮していない
#出来るだけループの外で計算する
n=int(input())
a=[int(input()) for i in range(n)]
m1=max(a)
m2=sorted(a,reverse=True)[1]
for i in range(n):
    if m1==a[i]:
        print(m2)
    else:
        print(m1)
Buggy python submission (verdict: Runtime Error):
#まだ自信をもっと答えられないんだよな
#掛け算じゃなくて最小公倍数や
#デバッグの後消す
import math
a,b,c,d=[int(i) for i in input().split()]
c1=b//c-a//c
if a%c==0:
    c1+=1
d1=b//d-a//d
if a%d==0:
    d1+=1
cd1=b//(c*d//math.gcd(c,d))-a//(c*d//math.gcd(c,d))
if a%(c*d)==0:
    cd1+=1
#print(c1)
#print(d1)
#print(cd1)
print(b-a+1-c1-d1+cd1)


Fixed submission:
#まだ自信をもっと答えられないんだよな
#掛け算じゃなくて最小公倍数や
#デバッグの後消す
import fractions
a,b,c,d=[int(i) for i in input().split()]
c1=b//c-a//c
if a%c==0:
    c1+=1
d1=b//d-a//d
if a%d==0:
    d1+=1
cd1=b//(c*d//fractions.gcd(c,d))-a//(c*d//fractions.gcd(c,d))
if a%(c*d)==0:
    cd1+=1
#print(c1)
#print(d1)
#print(cd1)
print(b-a+1-c1-d1+cd1)
#役立つhttps://qiita.com/chun1182/items/ddf2b6cba932b2bb0d4e

Buggy python submission (verdict: Runtime Error):
#まだ自信をもっと答えられないんだよな
#掛け算じゃなくて最小公倍数や
import math
a,b,c,d=[int(i) for i in input().split()]
c1=b//c-a//c
if a%c==0:
    c1+=1
d1=b//d-a//d
if a%d==0:
    d1+=1
cd1=b//(c*d//math.gcd(c,d))-a//(c*d//math.gcd(c,d))
if a%(c*d)==0:
    cd1+=1
print(c1)
print(d1)
print(cd1)
print(b-a+1-c1-d1+cd1)



Fixed submission:
#まだ自信をもっと答えられないんだよな
#掛け算じゃなくて最小公倍数や
#デバッグの後消す
import fractions
a,b,c,d=[int(i) for i in input().split()]
c1=b//c-a//c
if a%c==0:
    c1+=1
d1=b//d-a//d
if a%d==0:
    d1+=1
cd1=b//(c*d//fractions.gcd(c,d))-a//(c*d//fractions.gcd(c,d))
if a%(c*d)==0:
    cd1+=1
#print(c1)
#print(d1)
#print(cd1)
print(b-a+1-c1-d1+cd1)
#役立つhttps://qiita.com/chun1182/items/ddf2b6cba932b2bb0d4e
Buggy python submission (verdict: Runtime Error):
n=int(input())
path=[[] for i in range(n)]
for i in range(n-1):
    u,v,w=map(int,input().split())
    path[u-1].append((v-1,w%2))
    path[v-1].append((u-1,w%2))
ans=[0]+[-1]*(n-1)
def dfs(i):
    global n,path,ans
    for j in path[i]:
        if ans[j[0]]==-1:
            if j[1]:
                ans[j[0]]=1-ans[i]
                dfs(j[0])
            else:
                ans[j[0]]=ans[i]
                dfs(j[0])
dfs(0)
print("\n".join(map(str,ans)))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
path=[[] for i in range(n)]
for i in range(n-1):
    u,v,w=map(int,input().split())
    path[u-1].append((v-1,w%2))
    path[v-1].append((u-1,w%2))
ans=[0]+[-1]*(n-1)
def dfs(i):
    global n,path,ans
    for j in path[i]:
        if ans[j[0]]==-1:
            if j[1]:
                ans[j[0]]=1-ans[i]
                dfs(j[0])
            else:
                ans[j[0]]=ans[i]
                dfs(j[0])
dfs(0)
print("\n".join(map(str,ans)))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[int(input()) for _ in range(5)]
t1=[n if _==0 else 0 for _ in range(6)]
t2=[n if _==5 else 0 for _ in range(6)]
c=0
while True:
    for i in range(5):
        if t1[-i-2]>s[-i-1]:
            t1[-i-1]+=s[-i-1]
            t1[-i-2]-=s[-i-1]
        else:
            t1[-i-1]+=t1[-i-2]
            t1[-i-2]=0

    #print(t1)


    c+=1

    if t1==t2:
        break
print(c)


Fixed submission:
import math
n=int(input())
x=[int(input()) for i in range(5)]

m=0
for i in range(5):
    if x[m]>x[i]:
        m=i
if m==0:
    print(5+math.ceil(n/x[0])-1)
else:
    print(5+math.ceil(n/x[m])-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
c=[i for i in range(n-1) if (s[i]=="A" and s[i+1]=="C")]
d=[list(map(int,input().split())) for i in range(q)]
for i in range(q):
    e=0
    for j in c:
        if d[i][0]-1<=j and j+1<=d[i][1]-1:
            e+=1
    print(e)


Fixed submission:
n,q=map(int,input().split())
s=input()
c1=[1 if (s[i]=="A" and s[i+1]=="C") else 0 for i in range(n-1) ]
#print(c1)
d=[list(map(int,input().split())) for i in range(q)]
c2=[0]*n
for i in range(1,n):
    #print(i)
    c2[i]=c2[i-1]+c1[i-1]
#print(c2)
for i in range(q):
    print(c2[d[i][1]-1]-c2[d[i][0]-1])
Buggy python submission (verdict: Runtime Error):
n=int(input())
alph=["A","C","G","T"]
a=[alph[i]+alph[j]+alph[k] for i in range(4) for j in range(4) for k in range(4)]
d1={l:0 for l in a}
for i in d1:
    if i!="AGC" and i!="ACG" and i!="GAC":
        d1[i]=1
d2={l:0 for l in a}
for i in range(n-3):
    for j in d1:
        next=[j+alph[k] for k in range(4)]
        for k in range(4):
            l=next[k]
            check1=l[1:]=="GAC" or l[1:]=="ACG" or l[1:]=="AGC"
            check2=l[1:]=="GAC" or l[1:]=="ACG" or l[1:]=="AGC"
            if (not check1) and (not check2)
                d2[l[1:]]+=d1[j]
    for j in d1:
        d1[j]=d2[j]%1000000007
        d2[j]=0
print(sum(d1.values())%1000000007)

Fixed submission:
n=int(input())
alph=["A","C","G","T"]
a=[alph[i]+alph[j]+alph[k] for i in range(4) for j in range(4) for k in range(4)]
#print(len(a))
d1={l:0 for l in a}
for i in d1:
    if i!="AGC" and i!="ACG" and i!="GAC":
        d1[i]=1
d2={l:0 for l in a}
for i in range(n-3):
    for j in d1:
        next=[j+alph[k] for k in range(4)]
        for k in range(4):
            l=next[k]
            if l[1:]=="GAC" or l[1:]=="ACG" or l[1:]=="AGC":
                #print(l)
                pass
            elif l[0]=="A" and l[3]=="C" and (l[1]=="G" or l[2]=="G"):
                #rint(l)
                pass
            else:
                d2[l[1:]]+=d1[j]
    for j in d1:
        d1[j]=d2[j]
        d2[j]=0
print(sum(d1.values())%(1000000007))
Buggy python submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
n=math.floor(math.log2(b))+1
ans=[0]*n
form="0"+str(n)+"b"
sa=format(a,form)
sb=format(b,form)
for i in range(n):
    if i==n-1:
        if (b-a+1)%2==0:
            ans[i]=((b-a+1)//2)%2
        else:
            if sa[i]=="1":
                ans[i]=((b-a+1)//2+1)%2
            else:
                ans[i]=((b-a+1)//2)%2
        break
    if sa[i]=="1" and sb[i]=="0":
        s_compa=sa[:i]+"1"*(n-i)
        cmpa=int(s_compa,2)
        ans[i]=(cmpa-a+1)%2
    elif sa[i]=="0" and sb[i]=="1":
        s_compb=sb[:i]+"1"+"0"*(n-i)
        cmpb=int(s_compb,2)
        ans[i]=(b-cmpb+1)%2
    elif sa[i]=="1" and sb[i]=="1":
        s_compa=sa[:i]+"1"*(n-i)
        cmpa=int(s_compa,2)
        s_compb=sb[:i]+"1"+"0"*(n-i)
        cmpb=int(s_compb,2)
        if cmpa>a:#cmpb<b
            ans[i]=((b-cmpb+1)+(cmpa-a+1))%2
        else:
            ans[i]=(b-a+1)%2
cnt=0
for i in range(n):
    cnt+=(ans[i]*2**(n-i-1))
print(cnt)


Fixed submission:
import math
import sys
a,b=map(int,input().split())
if b==0:
    print(0)
    sys.exit()
n=math.floor(math.log2(b))+1
ans=[0]*n
form="0"+str(n)+"b"
sa=format(a,form)
sb=format(b,form)
for i in range(n):
    if i==n-1:
        if (b-a+1)%2==0:
            ans[i]=((b-a+1)//2)%2
        else:
            if sa[i]=="1":
                ans[i]=((b-a+1)//2+1)%2
            else:
                ans[i]=((b-a+1)//2)%2
        break
    if sa[i]=="1" and sb[i]=="0":
        s_compa=sa[:i]+"1"*(n-i)
        cmpa=int(s_compa,2)
        ans[i]=(cmpa-a+1)%2
    elif sa[i]=="0" and sb[i]=="1":
        s_compb=sb[:i]+"1"+"0"*(n-i)
        cmpb=int(s_compb,2)
        ans[i]=(b-cmpb+1)%2
    elif sa[i]=="1" and sb[i]=="1":
        s_compa=sa[:i]+"1"*(n-i)
        cmpa=int(s_compa,2)
        s_compb=sb[:i]+"1"+"0"*(n-i)
        cmpb=int(s_compb,2)
        if cmpa>a:#cmpb<b
            ans[i]=((b-cmpb+1)+(cmpa-a+1))%2
        else:
            ans[i]=(b-a+1)%2
cnt=0
for i in range(n):
    cnt+=(ans[i]*2**(n-i-1))
print(cnt)