Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02757 (python)

Fixed submission:
from collections import Counter
n, p = map(int, input().split( ))
s = input()
#n,p = 10000,5
#s = "7"*10000
#p=2,5は例外
#例外でなければ累積和
if p==2:
    ans = 0
    for i in range(n):
        if int(s[i])%2==0:
            ans += i+1
    print(ans)
    exit()
if p==5:
    ans=0###
    for i in range(n):
        if int(s[i])%5==0:
            ans += i+1
    print(ans)
    exit()


accm = [0]
s = s[::-1]
#print(s)
sm = 0
beki_p = 1
for i in range(n):
    sm += int(s[i])*beki_p
    sm %=p
    accm.append(sm)
    beki_p *=10
    beki_p%=p

aC = Counter(accm)
ans = 0
for k in aC:
    ans += aC[k]*(aC[k]-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n, p = map(int, input().split( ))
s = input()
#n,p = 10000,7
#s = "1"*10000
#p=2,5は例外
#例外でなければ累積和
if p==2:
    ans = 0
    for i in range(n):
        if int(s[i])%2==0:
            ans += i+1
    print(ans)
    exit()
if p==5:
    for i in range(n):
        if int(s[i])%5==0:
            ans += i+1
    print(ans)
    exit()


accm = [0]
s = s[::-1]
sm = 0
beki_p = 1
for i in range(n):
    sm += int(s[i])*beki_p
    sm %=p
    accm.append(sm)
    beki_p *=10
    beki_p%=p

aC = Counter(accm)
ans = 0
for k in aC:
    ans += aC[k]*(aC[k]-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n, p = map(int, input().split( ))
s = input()

#p=2,5は例外
#例外でなければ累積和
if p==2:
    ans = 0
    for i in range(n):
        if int(s[i])%2==0:
            ans += i+1
    print(ans)
    exit()
if p==5:
    for i in range(n):
        if int(s[i])%5==0:
            ans += i+1
    print(ans)
    exit()
s = int(s)

accm = [0]

for i in range(n):
    si = s%(10**(i+1))
    sip = si%p
    accm.append(sip)

aC = Counter(accm)
ans = 0
for k in aC:
    ans += aC[k]*(aC[k]-1)//2
print(ans)
Problem p02793 (python)

Fixed submission:

from fractions import gcd
import random
n = int(input())
a = list(map(int, input().split( )))
random.shuffle(a)
#最小公倍数でよいか？
#全てのjについてAiBiはAjで割り切れる
#計算時間は？

mod =10**9+7
def lcd(x,y):
    g = gcd(x,y)
    return x*y//g

ag1 = 1
for i in range(n//2):
    ag1 = lcd(ag1,a[i])
ag2 = 1
for i in range(n//2,n):
    ag2 = lcd(ag2,a[i])

ag3 = lcd(ag1,ag2)

ans = 0

for i in range(n//2):
    ans += ag1//a[i]
ans*=ag3//ag1
ans %=mod
ans2 = 0
for i in range(n//2,n):
    ans2 += ag2//a[i]
ans2*= ag3//ag2
ans2%=mod 
ans += ans2
ans %=mod
print(ans)

Buggy submission (verdict: Runtime Error):
def lcd(x,y):
    g = gcd(x,y)
    return x*y//g
n = int(input())
a = list(map(int, input().split( )))

#最小公倍数でよいか？
#全てのjについてAiBiはAjで割り切れる
#途中でmod処理は無理
#計算時間は？
from fanctions import gcd:
mod =10**9+7

Ag　= 1
for i in range(n):
    Ag = lcd(Ag,a[i])

ans = 0

for i in range(n):
    ans += Ag//a[i]
    ans %= mod

print(ans)
Problem p02851 (python)

Fixed submission:
from bisect import bisect_left
n,k = map(int,input().split( ))
a = list(map(int, input().split( )))
ans = 0
for i in range(n):
    a[i] -= 1
sm= 0
a_sm = [0]
for i in range(n):
    sm += a[i]
    sm%=k
    a_sm.append(sm)

dic = {}
for i in range(n+1):
    if a_sm[i] in dic:
        dic[a_sm[i]].append(i)
    else:
        dic[a_sm[i]]=[i]

for t in dic:
    for j in range(len(dic[t])-1):
        dm = bisect_left(dic[t],dic[t][j]+k)
        ans += dm - j - 1

       
print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
n,k = map(int,input().split( ))
a = list(map(int, input().split( )))
ans = 0
for i in range(n):
    #if a[i]%k==1:
    #    ans+=1
    a[i] -= 1
sm= 0
a_sm = [0]
for i in range(n):
    sm += a[i]
    sm%=k
    a_sm.append(sm)
#print(a_sm)
dic = {i:[] for i in range(n)}
for i in range(n+1):
    dic[a_sm[i]].append(i)
#print(dic)
for i in range(n):
    for j in range(len(dic[i])-1):
        dm = bisect_left(dic[i],dic[i][j]+k)
        #print(ans)
        #print(i,j,dm)
        ans += dm - j-1
        #print("test",ans)
       
print(ans)
Problem p02864 (python)

Fixed submission:
n,k = map(int, input().split( ))
if n==k:
    print(0)
    exit()
h = list(map(int, input().split( )))
#h = [0]+h#h[0]=0追加
inf = 10**15

dp = [[inf]*n for _ in range(n+1)] #dp[i][j]右端がi、j+1本残す
mn = h[0]
for i in range(n):
    #mn = min(mn,h[i])
    dp[i][0] = h[i]#min(mn,h[i])

for i in range(1,n):##右端
    for j in range(i+1):#本数
        for t in range(j-1,i):#右から2番目,
            dp[i][j] = min(dp[i][j], dp[t][j-1] + max(h[i]-h[t], 0))

ans = inf 

for i in range(n):
    ans = min(ans, min(dp[i][n-k-1:]))###
print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split( ))
if n==k:
    print(0)
    exit()
#h = [0]+h#h[0]=0追加
inf = 10**15

dp = [[inf]*n for _ in range(n+1)] #dp[i][j]右端がi、j+1本残す
mn = h[0]
for i in range(n):
    #mn = min(mn,h[i])
    dp[i][0] = h[i]#min(mn,h[i])

for i in range(1,n):##右端
    for j in range(i+1):#本数
        for t in range(j-1,i):#右から2番目,
            dp[i][j] = min(dp[i][j], dp[t][j-1] + max(h[i]-h[t], 0))

ans = inf 

for i in range(n):
    ans = min(ans, min(dp[i][n-k-1:]))###
print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split( ))
h = list(map(int, input().split( )))
#h = [0]+h#h[0]=0追加
inf = 10**15

dp = [[inf]*n for _ in range(n)] #dp[i][j]右端がi、j本残す
mn = h[0]
for i in range(n):
    mn = min(mn,h[i])
    dp[i][0] = min(mn,h[i])

for i in range(n):##右端
    for j in range(i+1):#本数
        for t in range(i):#右から2番目
            dp[i][j] = min(dp[i][j],dp[t][j-1] +max(h[i]-h[t], 0))

###print(dp[n-1][n-k-1])これでは意味が無い
ans = inf 

for i in range(n):
    ans = min(ans, dp[i][n-k-1])
print(ans)
n,k = map(int, input().split( ))
h = list(map(int, input().split( )))
#h = [0]+h#h[0]=0追加
inf = 10**15

dp = [[inf]*n for _ in range(n)] #dp[i][j]右端がi、j本残す
mn = h[0]
for i in range(n):
    mn = min(mn,h[i])
    dp[i][0] = min(mn,h[i])

for i in range(n):##右端
    for j in range(i+1):#本数
        for t in range(i):#右から2番目
            dp[i][j] = min(dp[i][j],dp[t][j-1] +max(h[i]-h[t], 0))

###print(dp[n-1][n-k-1])これでは意味が無い
ans = inf 

for i in range(n):
    ans = min(ans, dp[i][n-k-1])
print(ans)
Problem p02933 (python)

Fixed submission:
a=int(input())
s=input()
if a>=3200:
    print(s)
else:
    print("red")

Buggy submission (verdict: Runtime Error):
from collections import deque

n, q = map(int, input().split( ))
Edg=[[] for i in range(n+1)]

for i in range(n-1):
    a, b = map(int, input().split( ))
    Edg[a].append(b)
Ans=[0 for i in range(n+1)]
P = [0 for i in range(n+1)]
for i in range(q):
    p, x = map(int, input().split( ))
    P[p]+=x
#print(*P)
Chld=[[] for i in range(n+1)]
for p in range(n+1):
    Task=deque()
    Task.append(p)
    while True:
        try:
            p_=Task.popleft()
            for child in Edg[p_]:
                Chld[p].append(child)
                Task.append(child)
        except:
            break
#print(Chld)
for p in range(n+1):
    tmp = P[p]
    Ans[p]+=tmp
    for c in Chld[p]:
            Ans[c]+=tmp

print(*Ans[1:])
Problem p03013 (python)

Fixed submission:
import sys
n,m = map(int, input().split( ))
a = [] 

mod = 10**9+7
for _ in range(m):
    a.append(int(input()))

dp = [0]*(n+1)
dp[0] = 1
dp[1] = 1
if a:
    if a[0]==1:
        dp[1] = 0

A = set(a)
 
for i in range(2,n+1):
    if i not in A:
        dp[i] = (dp[i-1]+dp[i-2])%mod
print(dp[n])

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split( ))
a = [] 
mod = 10**9+7
for _ in range(m):
    a.append(int(input()))

dp = [0]*(n+1)
dp[0] = 1
if a[0]!=1:
    dp[1] = 1

A = set(a)
 
for i in range(2,n+1):
    if i not in A:
        dp[i] = (dp[i-1]+dp[i-2])%mod
print(dp[n])
Problem p03127 (python)

Fixed submission:
import fractions

n = int(input())
a = list(map(int, input().split( )))
ans = 0
for i in range(n):
    ans = fractions.gcd(ans,a[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import fractions

n = int(input())
a = list(map(int, input().split( )))
ans = 0
for i in range(n):
    ans = math.gcd(ans,a[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
a = list(map(int, input().split( )))
ans = 0
for i in range(n):
    ans = math.gcd(ans,a[i])
print(ans)
Problem p03465 (python)

Fixed submission:
#解説参照
n = int(input())
a = list(map(int, input().split( )))

dp = 1
for i in range(n):
    dp |= dp<<a[i]
ans = (sum(a)+1)//2
tmp = 1<<ans
for i in range(ans):
    if dp&tmp:
        print(ans)
        exit()
    ans+=1
    tmp <<=1
print(ans)

Buggy submission (verdict: Runtime Error):
#解説参照
n = int(input())
a = list(map(int, input().split( )))

dp = 1
for i in range(n):
    dp |= dp<<a[i]
ans = (sum(a)+1)//2
tmp = 1<<sn
for i in range(ans):
    if dp&tmp:
        print(ans)
        exit()
    ans+=1
    tmp <<=1 
print(ans)
Problem p03745 (python)

Fixed submission:
def f(n,a):
    if n==1:
        print(1)
        exit()
    pre=a[1]-a[0]
    ans=1
    for i in range(2,n):
        if pre*(a[i]-a[i-1])<0:
            pre=0
            ans+=1
        else:
            if a[i]-a[i-1]:###
                pre=a[i]-a[i-1]
    return ans

n=int(input())
*a,=map(int,input().split())
print(f(n,a))

Buggy submission (verdict: Runtime Error):
#editorial
n=int(input())
*a,=map(int, input().split())
pre=a[1]-a[0]
ans=1
for i in range(2,n):
    if pre*(a[i]-a[i-1])<0:
        pre=0
        ans+=1
    else:
        pre=a[i]-a[i-1]
print(ans)
Problem p03804 (python)

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

flag = False  
for i in range(n-m+1):
    #flag = True
    for k in range(n-m+1):
        flag=True#ここ
        for j in range(i,i+m):
            #if i==k==3:
            #    print(a[j][k:k+m],b[j-i],a[j][k:k+m]==b[j-i],flag)
            if a[j][k:k+m]!=b[j-i]:
                flag = False
                break
        if flag:
            break
    if flag:
        break
#print(i,k,flag)        
print("Yes" if flag else "No")

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())
a = []
b = []
for i in range(n):
    ai = input()
    a.append(ai)
for i in range(m):
    bi = input()
    b.append(bi)
flag = True    
for i in range(n-m+1):
    flag = True
    for k in range(n-m+1):
        for j in range(i,i+m+1):
        
            if a[j][k:k+m]!=b[j-i]:
                flag = False
                break
        if flag:
            break
    if flag:
        break
#print(i,k,flag)        
print("Yes" if flag else "No")
Problem p02623 (python)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a_s = [0] * (len(A)+1)
b_s = [0] * (len(B)+1)
for i in range(len(A)):
    a_s[i+1] = a_s[i] + A[i]
for i in range(len(B)):
    b_s[i + 1] = b_s[i] + B[i]

ans = 0
j = M
for i in range(len(a_s)):
    if a_s[i] > K:
        break
    while b_s[j] + a_s[i] > K:
        j -= 1
    ans = max(ans, i+j)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
N, M, K = map(int, input().split())
A = deque(list(map(int, input().split())))
B = deque(list(map(int, input().split())))
dp = [0] * (len(A)+len(B)+1)
i = j = 0
for idx in range(len(dp)):
    if i >= len(A) and j >= len(B):
        print(i+j)
        exit()
    if i >= len(A):
        dp[idx+1] = dp[idx] + B[j]
        j += 1
    elif j >= len(B):
        dp[idx+1] = dp[idx] + A[j]
    elif dp[idx] + A[i] < dp[idx] + B[j]:
        dp[idx+1] = dp[idx] + A[i]
        i += 1
    else:
        dp[idx+1] = dp[idx] + B[j]
        j += 1
    if dp[idx+1] > K:
        break
print(i+j-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
N, M, K = map(int, input().split())
A = deque(list(map(int, input().split())))
B = deque(list(map(int, input().split())))
dp = [0] * (len(A)+len(B)+1)
i = j = 0
for idx in range(len(dp)):
    if i >= len(A) and j >= len(B):
        break
    if i >= len(A):
        dp[idx+1] = dp[idx] + B[j]
        j += 1
    elif j >= len(B):
        dp[idx+1]
    elif dp[idx] + A[i] < dp[idx] + B[j]:
        dp[idx+1] = dp[idx] + A[i]
        i += 1
    else:
        dp[idx+1] = dp[idx] + B[j]
        j += 1
    if dp[idx+1] > K:
        break
print(idx)
Problem p02695 (python)

Fixed submission:
import itertools
N, M, Q = map(int, input().split())
q_list = []
final_score = 0
for i in range(Q):
    q_list.append(list(map(int, input().split())))
for A in itertools.combinations_with_replacement(range(1,M+1), N):
    score = 0
    for q in q_list:
        if A[q[1]-1] - A[q[0]-1] == q[2]:
            score += q[3]
        final_score = max([final_score, score])
print(final_score)

Buggy submission (verdict: Runtime Error):
import itertools
N, M, Q = map(int, input().split())
for i in range(Q):
    q_list.append(list(map(int, input().split())))

q_list = []
final_score = 0
for A in itertools.combinations_with_replacement(range(1,11), N):
    score = 0
    for q in q_list:
        if A[q[1]-1] - A[q[0]-1] == q[2]:
            score += q[3]
        final_score = max([final_score, score])
print(final_score)
Problem p02793 (python)

Fixed submission:
def gcd(a,b):
  if b==0:
    return a
  return gcd(b,a%b)
def lcm(arr):
  ans = 1
  for i in arr:
    ans = (ans*i)//gcd(ans,i)
  return ans
n = int(input())
arr = list(map(int,input().split())) #list(map(int, input().split()))
l = lcm(arr)
ans = 0;
for i in arr:
  ans+= l//i
print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair
using namespace std;

int inf = 1e18;
const int N = 5e5+5;
int mod = 1e9+7;
int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
       int n;
       cin>>n;
       unordered_map<int,int> mp;
       int arr[n];
       rep(i,0,n)
       cin>>arr[i];
       rep(i,0,n)
       {
           int ct = 0;
           int x = arr[i];
           for(int i=2;i*i<=x;++i)
           {

               if(x%i==0)
               {
                  ct = 0;
                 while(x%i==0)
                 {
                     ct++;
                     x/=i;
                 }
                 mp[i]= max(mp[i],ct);mp[i]= max(mp[i],ct);
               }

           }
           if(x!=1)
            mp[x] = max(mp[x],1LL);
       }
       int lcm = 1;
       for(auto x:mp)
        lcm = (lcm*powmod(x.ff,x.ss))%mod;
        int ans = 0;
        rep(i,0,n)
       {
           ans = (ans + (lcm*powmod(arr[i],mod-2))%mod)%mod;
       }
        cout<<ans<<el;
    }


        return 0;
    }
Problem p02595 (python)

Fixed submission:
import math
n, d = list(map(int, input().split()))
data = [list(map(int, input().split())) for i in range(n)]
def dist(x, y):
    return math.sqrt(x**2 + y**2)


count = 0
for i in range(n):
    dis = dist(data[i][0], data[i][1])
    if dis <= d:
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):
import math
data = [list(map(int, input().split())) for i in range(n)]
def dist(x, y):
    return math.sqrt(x**2 + y**2)
count = 0
for i in range(n):
    dis = dist(data[i][0], data[i][1])
    if dis <= d:
        count += 1

print(count)
Problem p02627 (python)

Fixed submission:
a = str(input())
oomoji = ["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
komoji = ["abcdefghijklmnopqrstuvwxyz"]

if a.isupper():
    print("A")
else:
    print("a")

Buggy submission (verdict: Runtime Error):
a = str(input())
oomoji = ["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
komoji = ["abcdefghijklmnopqrstuvwxyz"]

if a.isupper():
    print("A")
else:
    print("a"a)
Problem p02832 (python)

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


count = 0
c = 1

for i in range(N):
    #print(a)
    if c != a[i]:
       # del a[i]
        count += 1
    else:
        c+=1

#print(c-1)
#print(count)
#print(len(a)-count)
if c-1==0 and count > 1:
    print(-1)
else:
    print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))

count = 0
for i in range(N-1):
    if i+1 != a[i]:
        del a[i]
        count += 1

ans = True
for i in range(int(len(a))-1):
    if i+1!=a[i]:
        ans = False

if ans:
    print(count)
else:
    print(-1)
Problem p02879 (python)

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

if  data[0]<= 9 and data[1] <= 9:
    print(data[0]*data[1])
else:
    print("-1")

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())

if A <= 9 and B <= 9:
    print(A*B)
else:
    print("-1")
Problem p03013 (python)

Fixed submission:
n, m = list(map(int, input().split()))
# a, b, c = list(map(int, input().split()))
a = [int(input()) for i in range(m)]

mod = pow(10, 9)+7
point = [0]*(n+1)
point[0] = 1
j = 0
if 1 in a:
    point[1] = 0
    if m >= 2:
        j += 1
else:
    point[1] = 1

if m == 0:
    a = [0]

for i in range(2, n+1):
    if i == a[j]:
        if j < m-1:
            j += 1
    else:
        point[i] = point[i-1]+point[i-2]
        point[i] %= mod

print(point[-1] % mod)

Buggy submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
# a, b, c = list(map(int, input().split()))
a = [int(input()) for i in range(m)]

mod = pow(10, 9)+7
point = [0]*(n+1)
point[0] = 1
j = 0
if 1 in a:
    point[1] = 0
    j += 1
else:
    point[1] = 1

if m == 0:
    a = [0]

for i in range(2, n+1):
    if i == a[j]:
        if j < m-1:
            j += 1
    else:
        point[i] = point[i-1]+point[i-2]
        point[i] %= mod

print(point[-1] % mod)

Buggy submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
# a, b, c = list(map(int, input().split()))
a = [int(input()) for i in range(m)]

mod = pow(10, 9)+7
point = [0]*(n+1)
point[0] = 1
j = 0
if 1 in a:
    point[1] = 0
    j += 1
else:
    point[1] = 1

for i in range(2, n+1):
    if i == a[j]:
        if j < m-1:
            j += 1
    else:
        point[i] = point[i-1]+point[i-2]
        point[i] %= mod

print(point[-1] % mod)

Buggy submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
# a, b, c = list(map(int, input().split()))
a = []
for i in range(m):
    a.append(int(input()))

mod = pow(10, 9)+7
point = [0]*(n+1)
point[0] = 1
if a[0] != 1:
    point[1] = 1

for i in range(2, n+1):
    if i in a:
        point[i] = 0
    else:
        point[i] = point[i-1]+point[i-2]
        point[i] %= mod

# print(point)
print(point[-1] % mod)

Buggy submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
# a, b, c = list(map(int, input().split()))
a = []
for i in range(m):
    a.append(int(input()))

for i in range(1, m):
    if a[i]-a[i-1] == 1:
        print(0)
        exit()
mod = pow(10, 9)+7
point = [0]*(n+1)
point[0] = 1
if a[0] != 1:
    point[1] = 1

for i in range(2, n+1):
    if not(i in a):
        point[i] = point[i-1]+point[i-2]
        point[i] %= mod


print(point[-1] % mod)
Problem p03075 (python)

Fixed submission:

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())


if abs(a-b) > k or abs(b-c) > k or abs(c-d) > k or abs(d-e) > k or abs(a-d) > k or abs(a-c) > k or abs(a-e) > k or abs(b-d) > k or abs(b-e) > k or abs(c-e) > k:
    print(":(")
else:
    print("Yay!")

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())


if abs(a-b) > k or abs(b-c) > k or abs(c-d) > k or abs(d-e) > k or abs(a-d) > k
or abs(a-c) > k or abs(a-e) > k or abs(b-d) > k or abs(b-e) > k or abs(c-e) > k:
    print(":(")
else:
    print("Yay!")
Problem p03077 (python)

Fixed submission:
import math
n = int(input())
#n, m = list(map(int, input().split()))
# a, b, c = list(map(int, input().split()))
abc = [int(input()) for i in range(5)]
_min = min(abc)
min_idx = abc.index(min(abc))
count = math.ceil(n/_min)
count += min_idx+(4-min_idx)
print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
#n, m = list(map(int, input().split()))
# a, b, c = list(map(int, input().split()))
abc = [int(input()) for i in range(5)]
count = 0
start = math.ceil(n/abc[0])-1
_min = abc[0]
for i in range(5):
    if abc[i] < _min:
        count += math.ceil((_min-abc[i])/abc[i])
        _min = abc[i]

print(count+start+5)
Problem p03804 (python)

Fixed submission:
n, m = list(map(int, input().split()))
#a = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())

for i in range(n-m+1):
    for j in range(len(a[0])-len(b[0])+1):
        count = 0
        if b[0] == a[i][j:j+len(b[0])]:
            # print("aaaa")
            for k in range(m):
                if b[k] == a[i+k][j:j+len(b[0])]:
                    count += 1
            if count == m:
                print("Yes")
                exit()
# print(count)
print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
# n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
check = False
for i in range(n):
    if a[i] % 2 != 0:
        check = True
        break
count = 0
while check == False:
    for i in range(n):
        a[i] /= 2
        if a[i] % 2 != 0:
            check = True
            break
    count += 1
print(count)
Problem p03835 (python)

Fixed submission:
k, s = list(map(int, input().split()))
count = 0
for x in range(k+1):
    for y in range(min(k+1, s-x+1)):
        z = s-x-y
        ans = x+y+z
        if y <= k and z <= k:
            count += 1
print(count)

Buggy submission (verdict: Runtime Error):

import math
import itertools
import statistics
#import numpy as np
import collections
#n = int(input())
k, s = list(map(int, input().split()))
#a = list(map(int, input().split()))
count = 0
for x in range(k+1):
    for y in range(s-x+1):
        z = s-x-y
        ans = x+y+z
        if ans==s and y <= k and z <= k:
            count += 1
print(count)
Problem p02550 (python)

Fixed submission:
import sys
def input(): return sys.stdin.readline().strip()

def main():
    n, x, m = map(int, input().split())
    if x == 0:
        print(0)
        return
    if x == 1:
        print(n)
        return

    d = {}
    d_idx = {}
    d_unit = {}
    idx = 0
    pow_x = x
    unit = 0
    while idx < n and pow_x not in d:
        d[pow_x] = idx
        d_idx[idx] = pow_x
        unit += pow_x
        d_unit[idx] = unit

        pow_x *= pow_x
        pow_x %= m
        idx += 1
    # x^{2^idx} = 1

    if idx == n:
        print(unit)
        return
    pre_idx = d[pow_x]
    pre_unit = d_unit[pre_idx] - d_idx[pre_idx]
    iter_unit = unit - pre_unit
    ans = pre_unit + iter_unit * ((n - pre_idx) // (idx - pre_idx))
    for i in range((n - pre_idx) % (idx - pre_idx)):
        ans += d_idx[i + pre_idx]
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().strip()

def main():
    n, x, m = map(int, input().split())
    if x == 0:
        print(0)
        return
    if x == 1:
        print(n)
        return

    d = {}
    d_idx = {}
    d_unit = {}
    idx = 0
    pow_x = x
    unit = 0
    while idx < n and pow_x not in d:
        d[pow_x] = idx
        d_idx[idx] = pow_x
        unit += pow_x
        d_unit[idx] = unit

        pow_x *= pow_x
        pow_x %= m
        idx += 1
    # x^{2^idx} = 1

    if idx == n - 1:
        print(unit)
        return
    pre_idx = d[pow_x]
    pre_unit = d_unit[pre_idx] - d_idx[pre_idx]
    iter_unit = unit - pre_unit
    ans = pre_unit + iter_unit * ((n - pre_idx) // (idx - pre_idx))
    for i in range((n - pre_idx) % (idx - pre_idx)):
        ans += d_idx[i + pre_idx]
    print(ans)

if __name__ == "__main__":
    main()