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

Fixed submission:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
ts=time.time()
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
show_flg=False
#show_flg=True

ans=0
n,m=MI()
ed=[-1]*n
bg=[[] for _ in range(n)]
A=[0]*n
B=[0]*n
r=[]
for i in range(m):
    a,b=LI_()
    r+=[(a,b)]
    bg[a].append(b)
    ed[a]=b
    A[a]+=1
    B[b]+=1

show(r,A,B)
q=[]
for i in range(n):
    show(i,'q=',q,ans,end=' | ')
    if B[i]>0:
        ans+=1
        for j in q:
            B[j]-=1
        q=[]
    if A[i]>0:
        q+=bg[i]
    show(i,'q=',q,'ans=',ans,'A,B=',A,B)    
print(ans)

Buggy submission (verdict: Runtime Error):
a
Problem p03317 (python)

Fixed submission:
n,k=map(int,input().split())
print((n+k-3)//(k-1))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
print(int((n-1)/(k-1))
Problem p03725 (python)

Fixed submission:
h,w,k=map(int,input().split())
b=[]
v=[[0]*w for _ in range(h)]
sh=0
sw=0
for i in range(h):
    s=list(input())
    b.append(s)
    
    if 'S' in s:
        sh=i
        sw=s.index('S')
#ans=10**18
d=[[0,1],[1,0],[-1,0],[0,-1]]

def bfs(y,x):
    ans=10**18
    c=0
    q=[(y,x)]
    v[y][x]=1
    ans=min(y,x,h-1-y,w-1-x)
    while c<k:
        p=[]
        c+=1
        for i,j in q:
            for di,dj in d:
                if 0<=i+di<h and 0<=j+dj<w and v[i+di][j+dj]!=1 and b[i+di][j+dj]!='#':
                    p.append((i+di,j+dj))
                    v[i+di][j+dj]=1
                    ans=min(ans,i+di,j+dj,h-1-i-di,w-1-j-dj)
        q=p
    return ans
ans=bfs(sh,sw)
print(1+(ans+k-1)//k)

Buggy submission (verdict: Runtime Error):
h,w,k=map(int,input().split())
b=[]
v=[[0]*w for _ in range(h)]
sh=0
sw=0
for i in range(h):
    s=list(input())
    b.append(s)
    
    if 'S' in s:
        sh=i
        sw=s.index('S')
#ans=10**18
d=[[0,1],[1,0],[-1,0],[0,-1]]

def bfs(y,x):
    ans=10**18
    c=0
    q=[(y,x)]
    v[y][x]=1
    while c<k:
        p=[]
        c+=1
        for i,j in q:
            for di,dj in d:
                if v[i+di][j+dj]!=1 and b[i+di][j+dj]!='#' and 0<=i+di<h and 0<=j+dj<w:
                    p.append((i+di,j+dj))
                    v[i+di][j+dj]=1
                    ans=min(ans,i+di,j+dj,h-1-i-di,w-1-j-dj)
        q=p
    return ans
ans=bfs(sh,sw)
print(1+(ans+k-1)//k)
#print(b,sh,sw)
#print(v)

Buggy submission (verdict: Runtime Error):
h,w,k=map(int,input().split())
b=[]
v=[[0]*w for _ in range(h)]
sh=0
sw=0
for i in range(h):
    s=list(input())
    b.append(s)
    
    if 'S' in s:
        sh=i
        sw=s.index('S')
#ans=10**18
d=[[0,1],[1,0],[-1,0],[0,-1]]

def bfs(y,x):
    ans=10**18
    c=0
    q=[(y,x)]
    v[y][x]=1
    while c<k:
        p=[]
        c+=1
        for i,j in q:
            for di,dj in d:
                if v[i+di][j+dj]!=1 and b[i+di][j+dj]!='#':
                    p.append((i+di,j+dj))
                    v[i+di][j+dj]=1
                    ans=min(ans,i+di,j+dj,h-1-i-di,w-1-j-dj)
        q=p
    return ans
ans=bfs(sh,sw)
print(1+(ans+k-1)//k)
#print(b,sh,sw)
#print(v)
Problem p03745 (python)

Fixed submission:
n=int(input())
pre=0
ans=1
t=0
for i in input().split():
    a=int(i)
    if pre==0:
        pre=a
    else:
        if pre>a:
            if -t<0 and t**2==1:
                ans+=1
                t=-2
            else:
                t=-1
        elif pre<a:
            if t<0 and t**2==1:
                ans+=1
                t=2
            else:
                t=1
        else:
            continue
        pre=a
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
ans=1
t=0
for i in input().split():
    a=int(i)
    if pre==0:
        pre=a
    else:
        if pre>a:
            if -t<0 and t**2==1:
                ans+=1
                t=-2
            else:
                t=-1
        elif pre<a:
            if t<0 and t**2==1:
                ans+=1
                t=2
            else:
                t=1
        else:
            continue
print(ans)
Problem p03767 (python)

Fixed submission:
n=int(input())
a=sorted([int(i) for i in input().split()])[::-1]
print(sum(a[1:2*n:2]))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(i) for i in input().split()]
a=sorted(a)[::-1]
print(sum[1:2*n:2])

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(i) in input().split()]
a=sorted(a)[::-1]
print(sum[1:2*n:2])

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(i) in input().split()]
a=a.sort()[::-1]
print(sum[1:2*n:2])

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(i) in input().split()]
a.sort()[::-1]
print(sum[1:2*n:2])
Problem p03986 (python)

Fixed submission:
s=input()
q=[]
cnt=0
for i in s:
    if i=='S':
        q.append('S')
    else:  # t
        if q:
            q.pop()
            cnt+=2
print(len(s)-cnt)

Buggy submission (verdict: Runtime Error):
import bisect
n=int(input())
p=[0]*(n+2)
c=1
for i in input().split():
    p[int(i)]=c
    c+=1

q=[0,n+1]

for i in range(1,n+1):
    l=bisect.bisect(q,a)
    r=l+1
    print()

print(p)
Problem p02659 (python)

Fixed submission:
# coding: utf-8

a, b = map(str,input().split())

a = int(a)
b = b.replace('.', '')
#print(b)
b = int(b)
print(a*b//100)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
#C
a, b = map(float,input().split())
a = int(a)
b = int(b*100)

ans = a * b

ans = int(str(ans)[:-2])
print(ans)
Problem p02695 (python)

Fixed submission:
# coding: utf-8
import itertools
N, M, Q = map(int,input().split())
L = list(itertools.combinations_with_replacement(range(1, M + 1), N))
D = []
for i in range(Q):
    D.append(list(map(int,input().split())))

#print(l)
#全てのA

ans = 0
for A in L:
    tmp = 0
    for i in range(Q):
        a = D[i][0]
        b = D[i][1]
        c = D[i][2]
        d = D[i][3]
        if A[b-1] - A[a-1] == c:
            tmp += d
        
        ans = max(ans,tmp)

print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8

N, M, Q = map(int,input().split())
L = []
A = [1] * N
ans = 0

for i in range(Q):
    l = list(map(int,input().split()))
    L.append(l)

L.sort(key=lambda x:x[3])

for i in range(Q):
    a=L[i][0]
    b=L[i][1]
    c=L[i][2]
    d=L[i][3]
    if A[b-1] <= A[a-1] + c <= M:
        ans += d
        #print(ans)
        A[b-1:] = [A[a-1] + c] * (N-A[a-1]+c-1)
print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8

N, M, Q = map(int,input().split())
L = []
A = [1] * N
ans = 0

for i in range(Q):
    l = list(map(int,input().split()))
    L.append(l)

L.sort(key=lambda x:x[3])

for i in range(Q):
    a=L[i][0]
    b=L[i][1]
    c=L[i][2]
    d=L[i][3]
    if A[b-1] <= A[a-1] + c <= M:
        ans += d
        #print(ans)
        A[b-1:] = [A[a-1] + c] * (N-A[a-1]+c-1)
print(ans)
Problem p02766 (python)

Fixed submission:
# coding: utf-8
N,k=map(int,input().split())
idx=1
for i in range(N):
    if k**i>N:
        idx=i
        break
print(idx)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
N,k=map(int,input().split())

for i in range(N):
    if k**i>N:
        idx=i
        break
print(idx)
Problem p02793 (python)

Fixed submission:
# coding: utf-8
# Your code here!
import fractions
from functools import reduce
N=int(input())
A=list(map(int,input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
l=lcm_list(A)
ans=0

for i in range(N):
    ans+=(l//A[i])
print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import fractions
N=int(input())
A=list(map(int,input().split()))
#def lcm(x,y):
 #   l=x*y/fractions.gcd(x,y)
  #  return l
l=A[0]
for i in range(N-1):
    l=int((A[i+1]*l)/fractions.gcd(A[i+1],l))
ans=0
for i in range(N):
    ans+=l//A[i]
print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import fractions
N=int(input())
A=list(map(int,input().split()))
def lcm(x,y):
    l=x*y/fractions.gcd(x,y)
    return l
l=A[0]
for i in range(N-1):
    l=int(A[i+1]*l/fractions.gcd(A[i+1],l))
ans=0
for i in range(N):
    ans+=l//A[i]
print(ans%(10**9+7))
Problem p02881 (python)

Fixed submission:
import math
N=int(input())
L=[]
for i in range(1,int(math.sqrt(N))+1):
  if N%i==0:
    L.append(i+int(N/i)-2)
  else:
    pass
print(min(L))

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
L=[]
for i in range(1,int(math.sqrt(N))):
  if N%i==0:
    L.append(i+int(N/i)-2)
  else:
    pass
print(min(L))
Problem p02915 (python)

Fixed submission:
N=int(input())
print(N**3)

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
print(math,factorial(N))
Problem p02970 (python)

Fixed submission:
N,d = map(int,input().split())
 
if N%(2*d+1)==0:
  print(int(N/(2*d+1)))
else:
  print(int((N/(2*d+1))+1))

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

if N%(2*d+1)==0:
  print(N/(2*d+1))
else:
  print((N/(2*d+1))+1)
Problem p02622 (python)

Fixed submission:
#関数リスト
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))


s = input().rstrip()
t = input().rstrip()
result = 0
for i in range(len(s)):
    if s[i] != t[i]:
        result += 1
        
print(result)

Buggy submission (verdict: Runtime Error):
#関数リスト
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))


s = input().rstrip()
t = intput().rstrip()
result = 0
for i in range(len(s)):
    if s[i] != t[i]:
        result += 1
        
print(result)
Problem p02572 (python)

Fixed submission:
mod=10**9 + 7
n=int(input())
a=list(map(int,input().split()))
ans=0
total=sum(a)
for i in a:
  total -= i
  ans += total*i
print(ans%mod)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [list(map(str,input().split()) for i in range(N))]
mod = 10**9+7
ans=0
for i in range(2**N):
  cl = [False]*N
  for j in range(N):
    if ((i>>j)&1):
      cl[N-1-j] = True
  total=''
  if cl.count(True) == 2:
    for k in range(len(cl)):
      if cl[k]:
        total+= A[k] + '*'
      total+= '1'
  ans += eval(total)

print(ans%mod)
Problem p02578 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
count=0
for i in range(N):
  try:
    a = A[i]
    b = A[i+1]
    if a <= b:
      pass
    else:
      c = abs(a-b)
      A[i+1] = b+c
      count+=c
  except:
    pass
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(input().split()))
count=0
for i in range(N):
  try:
    a=A[i]
    b=A[i+1]
    while a>b:
      b+=1
      count+=1
  except:
    pass
print(count)
Problem p02622 (python)

Fixed submission:
s = input()
t = input()
count=0
for (i,j) in zip(s,t):
  if i != j:
    count+=1
print(count)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
count=0
for i in len(s):
  if s[i] != t[i]:
    count+=1
print(count)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
count=0
for i in len(s):
  if s[i] == t[i]:
    count+=1
print(count)
Problem p02682 (python)

Fixed submission:
A, B, C, K = map(int, input().split())
print(min(K, A)-max(0, K-A-B))

Buggy submission (verdict: Runtime Error):
, B, C, K = map(int, input().split())
print(max(K, A)+min(0, K-A-B))

Buggy submission (verdict: Runtime Error):
, B, C, K = map(int, input().split())
print(min(K, A)-max(0, K-A-B))
Problem p02712 (python)

Fixed submission:
N = int(input())
x = 0
for i in range(1, N+1):
    if (i % 3) != 0 and (i % 5) != 0:
        x = x+i
print(x)

Buggy submission (verdict: Runtime Error):
N = int(input())
for i in range(1,1+N):
  if N % 3 != 0 or N%5 !=0:
    x += i
print(x)

Buggy submission (verdict: Runtime Error):
N = int(input())
for i in range N:
  if i % 3 ==0 or i % 5 ==0:
    x += i
print(x)
Problem p02753 (python)

Fixed submission:
S = input()
print('Yes' if len(set(S)) == 2 else 'No')

Buggy submission (verdict: Runtime Error):
S = input()
print('Yes' len(set(S)) == 2 else 'No')
Problem p02880 (python)

Fixed submission:
N = int(input())
Suji_check = False
for s in range(1,10):
  for t in range(1,10):
    if s*t == N:
      Suji_check = True
      break
if Suji_check:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
Suji=[]
for i in range(1,9):
  Suji.append(i)
N = int(input())
Suji_check=False
for s in Suji:
  A = N%s
  try A != 0:
      for t in Suji:
      if A == t:
        Suji_check = True
  except:
    pass
if Suji_check:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
Suji=[]
for i in range(1:9):
  Suji.append(i)
N = int(input())
Suji_check=False
for s in Suji:
  A = N%s
  try A != 0:
      for t in Suji:
      if A == t:
        Suji_check = True
  except:
    pass
if Suji_check:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
Suji=[]
for i in range(1:9):
  Suji.append(i)
N = int(input())
Suji_check=False
for s in Suji:
  A = N%s
  for t in Suji:
    if A == t:
      Suji_check = True
if Suji_check:
  print('Yes')
else:
  print('No')
Problem p03012 (python)

Fixed submission:
N = int(input())
W = list(map(int,input().split()))
L = []
for i in range(1,N):
  L.append(abs(sum(W[:i])-sum(W[i:])))
print(min(L))

Buggy submission (verdict: Runtime Error):
N = int(input())
W = list(map(int,input().split()))
L = []
for i in range(1,N):
  L.append(abs(sum(N[:i])-sum(N[i:])))
print(min(L))

Buggy submission (verdict: Runtime Error):
N = int(input())
W = map(int,input().split())
L = []
for i in range(1,N):
  L.append(abs(sum(N[:i])-sum(N[i:])))
print(min(L))
Problem p03135 (python)

Fixed submission:
T,X = map(float,input().split())
print(T/X)

Buggy submission (verdict: Runtime Error):
T,X = input().split()
print(T/X)
Problem p03207 (python)

Fixed submission:
N = int(input())
p = [int(input()) for i in range(N)]
print(sorted(p)[-1]//2 + sum(sorted(p)[:N-1]))

Buggy submission (verdict: Runtime Error):
N = int(input())
p = [int(input()) for i in N]
print(sorted(p)[-1]//2 + sum(sorted(p)[:N-1]))
Problem p03242 (python)

Fixed submission:
n = input()
print(n.replace('1','x').replace('9','1').replace('x','9'))

Buggy submission (verdict: Runtime Error):
n = input()
print(n.replace('1','x').replace('9','1').replace('x','9')
Problem p03250 (python)

Fixed submission:
a,b,c = sorted(map(int,input().split()))
d=str(c)+str(b)
print(a+int(d))

Buggy submission (verdict: Runtime Error):
a,b,c = sorted(int(input().split()))
print(c*10+b+a)
Problem p03345 (python)

Fixed submission:
a,b,c,k = map(int,input().split())
if k % 2 == 0:
  print(a-b)
else:
  print(b-a)

Buggy submission (verdict: Runtime Error):
a,b,c,k = map(int,input().split())
count = 0
if k = 0:
  print(a-b)
  exit()

while count = k:
  a1 = a
  b1 = b
  c1 = c
  a = b1+c1
  b = a1+c1
  c = a1+b1
  count +=1
print(a-b)
Problem p03631 (python)

Fixed submission:
N = input()
print('Yes' if N[0] == N[-1] else 'No')

Buggy submission (verdict: Runtime Error):
N = int(input())
print('Yes' if N[0] == N[-1] else 'No')
Problem p03834 (python)

Fixed submission:
a,b,c = input().split(',')
print(a,b,c)

Buggy submission (verdict: Runtime Error):
a,b,c = input().split()
print(a+" "+b+" "+c)

Buggy submission (verdict: Runtime Error):
a,b,c = input().split()
print(a,b,c)
Problem p02627 (python)

Fixed submission:
import sys
import math
import collections
 
def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin
 
 
def int_input():
    return list(map(int, input().split()))
 
 
if __name__ == '__main__':
    # set_debug(True)
 
    t = input()
    
    if 'A' <= t <= 'Z':
        print('A')
    else:
        print('a')

Buggy submission (verdict: Runtime Error):
import sys
import math
import collections

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin


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


if __name__ == '__main__':
    # set_debug(True)

    t = input()
    
    if t.is_upper():
        print('A')
    else:
        print('a')
Problem p02753 (python)

Fixed submission:
S=input()
if S[0]==S[1] and S[1]==S[2]:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
S=input()
if S[0]==S[1] and S[1]==S[2]:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
S=input('S')
if S[0]==S[1] and S[1]==S[2]:
    print('No')
else:
    print('Yes')
Problem p02550 (python)

Fixed submission:
n,x,m = map(int, input().split())
b = x%m
add = 0

# nがm以下なら全部足せば良い
ans = 0
if n <= m:
    for i in range(n):
        ans += b    
        b = pow(b,2,m)
    print(ans)
    exit()

# nがmより大のとき、効率化
cnt = 0
while 2 ** cnt < m:
    cnt += 1

# 位数と初期値を出す
s = set()
tmp = 0
for i in range(m):
    if i < cnt:
        add += b
        tmp = b
    else:
        s.add(b)
    b = pow(b, 2, m)

# cnt以降、和*位数+残りの和で計算
rest = (n-cnt)%len(s)
div = (n-cnt)//len(s)

rep = []
for i in range(len(s)):
    tmp = pow(tmp, 2, m)
    rep.append(tmp)

ans = add + sum(rep)*div + sum(rep[:rest])
print(ans)

Buggy submission (verdict: Runtime Error):
n,x,m = map(int, input().split())
b = x%m
add = 0

# nがm以下なら全部足せば良い
ans = 0
if n <= m:
    for i in range(n):
        ans += b    
        b = pow(b,2,m)
    print(ans)
    exit()

# nがmより大のとき、効率化
cnt = 0
while 2 ** cnt < m:
    cnt += 1

# 位数と初期値を出す
s = set()
for i in range(m):
    if i < cnt:
        add += b
        tmp = b
    else:
        s.add(b)
    b = pow(b, 2, m)

if len(s) == 0:
    print(add)
    exit()
# cnt以降、和*位数+残りの和で計算
rest = (n-cnt)%len(s)
div = (n-cnt)//len(s)

rep = []
for i in range(len(s)):
    tmp = pow(tmp, 2, m)
    rep.append(tmp)

ans = add + sum(rep)*div + sum(rep[:rest])
print(ans)

Buggy submission (verdict: Runtime Error):
n,x,m = map(int, input().split())
b = x%m
add = 0

# nがm以下なら全部足せば良い
ans = 0
if n <= m:
    for i in range(n):
        ans += b    
        b = pow(b,2,m)
    print(ans)
    exit()

# nがmより大のとき、効率化
cnt = 0
while 2 ** cnt < m:
    cnt += 1

# 位数と初期値を出す
s = set()
for i in range(m):
    if i < cnt:
        add += b
        tmp = b
    else:
        s.add(b)
    b = pow(b, 2, m)
# cnt以降、和*位数+残りの和で計算
rest = (n-cnt)%len(s)
div = (n-cnt)//len(s)

rep = []
for i in range(len(s)):
    tmp = pow(tmp, 2, m)
    rep.append(tmp)

ans = add + sum(rep)*div + sum(rep[:rest])
print(ans)

Buggy submission (verdict: Runtime Error):
n,x,m = map(int, input().split())
b = x%m
add = 0

# nがm以下なら全部足せば良い
ans = 0
if n <= m:
    for i in range(n):
        ans += b    
        b = pow(b,2,m)
    print(ans)
    exit()

# nがmより大のとき、効率化
cnt = 0
while 2 ** cnt < m:
    cnt += 1

# 位数と初期値を出す
s = set()
for i in range(m):
    if i < cnt:
        add += b
        tmp = b
    else:
        s.add(b)
    b = pow(b, 2, m)
# cnt以降、和*位数+残りの和で計算
rest = (n-cnt)%len(s)
div = (n-cnt)//len(s)

rep = []
for i in range(len(s)):
    tmp = pow(tmp, 2, m)
    rep.append(tmp)

print(len(s),len(rep))
ans = add + sum(rep)*div + sum(rep[:rest])
print(ans)
Problem p02598 (python)

Fixed submission:
n,k = map(int, input().split())
As = list(map(int, input().split()))

def f(x):
    # サイズxで切る
    cnt = 0
    for a in As:
        # 斬らなければイケない本数
        cnt += int((a-0.01)/x)
        if cnt > k:
            return False
    # 斬らなければいけない本数がk本以下
    return cnt <= k

l = 10**-2
r = 10**9
while r-l > 10**-1:
    m = (l*r)**0.5
    if f(m):
        r = m
    else:
        l = m
print(int(l)+1)

Buggy submission (verdict: Runtime Error):
import numpy as np
n,k = map(int, input().split())
As = list(map(int, input().split()))

def f(x):
    # サイズxで切る
    cnt = 0
    for a in As:
        # 斬らなければイケない本数
        cnt += int(np.ceil(a/x))-1
    # 斬らなければいけない本数がk本以下
    return cnt <= k

l = 10**-6
r = 10**9
while r-l > 10**-5:
    # print(l,r)
    m = (l+r)/2
    if f(m):
        r = m
    else:
        l = m
print(int(np.ceil(l)))
Problem p02685 (python)

Fixed submission:
n,m,k = map(int, input().split())
mod = 998244353

def modconb(n,k,mod):
    # テーブルを作る
    fac = [0]*(n+1)
    finv = [0]*(n+1)
    inv = [0]*(n+1)  

    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2,n+1):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) % mod
        finv[i] = finv[i-1] * inv[i] %mod
    # 計算
    if n<k: return 0
    if n<0 or k<0: return 0
    
    modcombs = [1]
    for k in range(1,n+1):
        modcombs.append(fac[n]*(finv[k]*finv[n-k]%mod)%mod)
    return modcombs

if n == 1:
    print(m)
    exit()

mods = modconb(n-1,n-1,mod)
cnt = 0
for i in range(k+1):
    cnt += m*mods[i]*pow(m-1,n-i-1,mod)
    cnt %= mod
print(cnt)


# cnt = 100
# for i in range(99):
#     cnt *= 99
#     cnt %= mod

# print(cnt)

Buggy submission (verdict: Runtime Error):
n,m,k = map(int, input().split())
mod = 998244353

def modconb(n,k,mod):
    # テーブルを作る
    fac = [0]*(n+1)
    finv = [0]*(n+1)
    inv = [0]*(n+1)  

    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2,n+1):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) % mod
        finv[i] = finv[i-1] * inv[i] %mod
    # 計算
    if n<k: return 0
    if n<0 or k<0: return 0
    
    modcombs = [1]
    for k in range(1,n+1):
        modcombs.append(fac[n]*(finv[k]*finv[n-k]%mod)%mod)
    return modcombs

mods = modconb(n-1,n-1,mod)
# print(mods)
cnt = 0
for i in range(k+1):
    cnt += m*mods[i]*pow(m-1,n-i-1,mod)
    cnt %= mod
print(cnt)
Problem p02695 (python)

Fixed submission:
# 重複順列　19C10
from itertools import combinations_with_replacement as cw

n,m,q = map(int, input().split())
a_candidates = cw([i+1 for i in range(m)],n)
fs = [list(map(int, input().split())) for i in range(q)]

def calc(fs,As):
    cnt = 0
    for a,b,c,d in fs:
        a -= 1
        b -= 1
        if As[b]-As[a] == c: cnt += d
    return cnt

ans = 0
for As in list(a_candidates):
    ans = max(ans, calc(fs,As))

print(ans)

Buggy submission (verdict: Runtime Error):
# 重複順列　19C10
from itertools import combinations_with_replacement as cw

n,m,q = map(int, input().split())
a_candidates = cw([i+1 for i in range(m)],m)
fs = [list(map(int, input().split())) for i in range(q)]

def calc(fs,As):
    cnt = 0
    for a,b,c,d in fs:
        a -= 1
        b -= 1
        if As[b]-As[a] == c: cnt += d
    return cnt

ans = 0
for As in list(a_candidates):
    ans = max(ans, calc(fs,As))

print(ans)

Buggy submission (verdict: Runtime Error):
# 重複順列　19C10
from itertools import combinations_with_replacement as cw

n,m,q = map(int, input().split())
a_candidates = cw([i+1 for i in range(m)],m)
fs = [list(map(int, input().split())) for i in range(q)]

def calc(fs,As):
    cnt = 0
    for a,b,c,d in fs:
        if As[b]-As[a] == c: cnt += d
    return cnt

ans = 0
for As in list(a_candidates):
    ans = max(ans, calc(fs,As))

print(ans)
Problem p02777 (python)

Fixed submission:
S,T = input().split()
a,b = map(int, input().split())
U = input()
if U == S:
    print(a-1,b)
else:
    print(a,b-1)

Buggy submission (verdict: Runtime Error):
red blue
5 5
blue