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

Fixed submission:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    dx = [1,0]
    dy = [0,1]
    INF = float('inf')
    h,w = readInts()
    dp = [[INF]*w for _ in range(h)]
    FIELD = [input() for _ in range(h)]
    # dp[j][i] = i番目とj番目にかかる魔法の度合い
    # 初期値 魔法1, なし 0
    if FIELD[0][0] == '#':
        dp[0][0] = 1
    else:
        dp[0][0] = 0
    for i in range(w):
        for j in range(h):
            for x,y in dx,dy:
                ny = j + y
                nx = i + x
                if ny >= h or nx >= w:
                    continue
                add = 0
                if FIELD[ny][nx] == '#' and FIELD[j][i] == '.':
                    add = 1
                dp[ny][nx] = min(dp[ny][nx], dp[j][i] + add)
    print(dp[h-1][w-1])
if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    dx = [1,0]
    dy = [0,1]
    INF = float('inf')
    h,w = readInts()
    dp = [[INF]*w for _ in range(h)]
    FIELD = [input() for _ in range(h)]
    # dp[j][i] = i番目とj番目にかかる魔法の度合い
    # 初期値 魔法1, なし 0
    if FIELD[0][0] == '#':
        dp[0][0] = 1
    else:
        dp[0][0] = 0
    for i in range(w):
        for j in range(h):
            for x,y in dx,dy:
                ny = j + y
                nx = i + x
                if ny >= h or nx >= w:
                    continue
                add = 0
                if FIELD[ny][nx] == '#' and FIELD[j][i] == '.':
                    add = 1
                dp[ny][nx] = min(dp[ny][nx], dp[j][i] + add)
    print(dp[h-1][w-1])
if __name__ == '__main__':
  main()
Problem p02754 (python)

Fixed submission:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
def main():
  n,a,b = map(int,input().split())
  ans = n//(a+b) * a
  rem = n % (a+b)
  ans += min(rem,a)
  print(ans)
if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
def main():
  n,a,b = map(int,input().split())
  cnt = 0
  new = ""
  while True:
    if cnt + a <= n:
      cnt += a
      new += 'b' * a
    else:
      #print(cnt)
      a = n-cnt
      cnt += n-cnt
      #print(n-cnt)
      new += 'b' * (a)
      break
    if cnt + b <= n:
      cnt += b
      new += 'r'*b
    else:
      a = n-cnt
      cnt += n-cnt
      new += 'r' * (a)
      break
  #print(new)
  print(new.count('b'))
if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
def main():
  n,a,b = map(int,input().split())
  cnt = 0
  new = ""
  while True:
    if cnt + a <= n:
      cnt += a
      new += 'b' * a
    else:
      #print(cnt)
      a = n-cnt
      cnt += n-cnt
      #print(n-cnt)
      new += 'b' * (a)
      break
    if cnt + b <= n:
      cnt += b
      new += 'r'*b
    else:
      a = n-cnt
      cnt += n-cnt
      new += 'r' * (a)
      break
  print(new)
  print(new.count('b'))
if __name__ == '__main__':
  main()
Problem p03013 (python)

Fixed submission:
MOD = 10**9 + 7

n,m = map(int,input().split())

ban = [False] * (n + 1)

for i in range(m):
    a = int(input())
    ban[a] = True

dp = [0] * (n + 1)
dp[0] = 1

for i in range(n):
    dp[i] %= MOD
    if ban[i]:dp[i] = 0
    #print(i, dp[i])
    if i + 1 <= n:
        dp[i + 1] += dp[i]
    if i + 2 <= n:
        dp[i + 2] += dp[i]

print(dp[n] % MOD)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
dp = [0] * (n+1)

mod = 10**9 + 7
for i in range(m):
    dp[int(input())] = -1 # 壊れているので、-1としておこう?

dp[0] = 0 # 0段目にいるとしよう
# 1段目が行けなかったら...?
dp[1] = 1 if dp[1] != -1 else -1 # 1段目にいく方法は1通り?
dp[2] = 2 if dp[1] != -1 else (1 if dp[2] != -1 else -1) # 2段目に行く方法は2通り?
for i in range(3,n+1):
    if dp[i] != -1 and dp[i-1] != -1:
        dp[i] += dp[i-1]
        dp[i] %= mod
    if i > 1:
        if dp[i] != -1 and dp[i-2] != -1:
            dp[i] += dp[i-2]
            dp[i] %= mod
print(dp[n]%mod)
Problem p03038 (python)

Fixed submission:
n,m = map(int,input().split())
A = list(map(int,input().split()))
tehuda = []
for i in range(m):
    b,c = map(int,input().split())
    tehuda.append((b,c))
# とりあえず和
sumA = sum(A)
import heapq
heapq.heapify(A)
tehuda = sorted(tehuda,key = lambda x:x[1])
#print(tehuda)
over = True
while tehuda:
    if not over:
        break
    b,c = tehuda.pop()
    while True:
        m = heapq.heappop(A)
        #print(m,c)
        if m >= c:
            over = False
            break
        else:
            b -= 1
            sumA -= m
            sumA += c
            heapq.heappush(A,c)
            if b == 0:
                break
print(sumA)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
A = list(map(int,input().split()))
tehuda = []
for i in range(m):
    b,c = map(int,input().split())
    tehuda.append((b,c))
# とりあえず和
sumA = sum(A)
import heapq
heapq.heapify(A)
tehuda = sorted(tehuda,key = lambda x:x[1])
#print(tehuda)
over = True
while tehuda:
    if not over:
        break
    b,c = tehuda.pop()
    while True:
        m = heapq.heappop(A)
        #print(m,c)
        if m >= c:
            over = False
            break
        else:
            b -= 1
            #print(sumA)
            sumA -= m
            #print(sumA)
            sumA += c
            #print(sumA)
            if b == 0:
                break
print(sumA)
Problem p03077 (python)

Fixed submission:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    # 例えば、(A,B,C,D,E) = (5,3,4,2,6) だったら、D = 2の部分で絶対に人が詰まる
    # Dはボトルネック(一番処理がﾀﾞﾒ)
    # N = 100だとすると、最初にDに来てからはずっと2人ずつのせていく
    # 時間で言うと N // 2 = 50 分 かかる計算になる
    # しかし、全員ぴったりくるわけではないので、 (N + bottleneck - 1) // bottleneckにする
    # Dが一番小さいのだから、
    # Dにくるまでは、A,B,C の　3分
    # Dを過ぎてからはE の　1分
    # これは、ボトルネックがDの場合に限らない 合計で 4分
    n = int(input())
    bottleneck = float('inf')
    A = []
    for i in range(5):
        a = int(input())
        A.append(a)
    for i in range(5):
        bottleneck = min(bottleneck,A[i])
    #print(bottleneck)
    print((n + bottleneck - 1) // bottleneck + 4) # ボトネで処理するもの　と　来るまでと来た後　の合計

if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    # 例えば、(A,B,C,D,E) = (5,3,4,2,6) だったら、D = 2の部分で絶対に人が詰まる
    # Dはボトルネック(一番処理がﾀﾞﾒ)
    # N = 100だとすると、最初にDに来てからはずっと2人ずつのせていく
    # 時間で言うと N // 2 = 50 分 かかる計算になる
    # しかし、全員ぴったりくるわけではないので、 (N + bottleneck - 1) // bottleneckにする
    # Dが一番小さいのだから、
    # Dにくるまでは、A,B,C の　3分
    # Dを過ぎてからはE の　1分
    # これは、ボトルネックがDの場合に限らない 合計で 4分
    n = int(input())
    bottleneck = int(input())
    for i in range(n-1):
        bottleneck = min(bottleneck,int(input()))
    #print(bottleneck)
    print((n + bottleneck - 1) // bottleneck + 4) # ボトネで処理するもの　と　来るまでと来た後　の合計

if __name__ == '__main__':
  main()
Problem p03127 (python)

Fixed submission:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    import fractions
    n = int(input())
    A = readInts()
    g = fractions.gcd(A[0],A[1])
    for i in range(2,n):
        g = fractions.gcd(g,A[i])
    print(g)


if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
n = int(input())
import math
A = list(map(int,input().split()))
g = 0
for i in range(n):
    g = math.gcd(g,A[i])
print(g)
Problem p03617 (python)

Fixed submission:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    q,h,s,d = readInts()
    n = int(input())
    # 2A < B なら 0.25 のみ
    # 2A > B なら　0.5 のみ。
    # "入力は整数であるから、小数点を考える必要がない"
    # よって、0.25 -> 1, 0.5 -> 1 として、かつ1と比較する
    one = min(q*4, h*2, s)
    # そして、1gだけで行けるか、
    # 2gだけで買えるだけ買って、余った分を1gでやる
    print(min(one*n, d*(n//2) + one * (n%2)))#n//2 は 2g ずつなので、 n%2 は1gするか

if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
q,h,s,d = map(int,input().split())
N = int(input())
one = min(q*4,h*2,s)
print(min(one*N,d*(N//2)+one*(n%2)))
Problem p03634 (python)

Fixed submission:
n = int(input())
import sys
sys.setrecursionlimit(10**8)
def D(now,pre,SUM):
    dist[now] = SUM
    for BC in G[now]:
        if BC[0] == pre:
            continue
        D(BC[0],now,SUM+BC[1])



G = [[] for _ in range(n)]
for i in range(n-1):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append((b,c))
    G[b].append((a,c))
q,k = map(int,input().split())
# xから頂点kまでの最短経路を求めておいて、kからyまでの最短経路を求めておく
k -= 1
# ここで作っとく?
dist = [0] * n
D(k,-1,0)
for i in range(q):
    x,y = map(lambda m:int(m)-1, input().split())
    print(dist[x] + dist[y])

Buggy submission (verdict: Runtime Error):
n = int(input())

def D(now,pre,SUM):
    dist[now] = SUM
    for BC in G[now]:
        if BC[0] == pre:
            continue
        D(BC[0],now,SUM+BC[1])



G = [[] for _ in range(n)]
for i in range(n-1):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append([b,c])
    G[b].append([a,c])
q,k = map(int,input().split())
# xから頂点kまでの最短経路を求めておいて、kからyまでの最短経路を求めておく
k -= 1
# ここで作っとく?
dist = [0] * n
D(k,-1,0)
for i in range(q):
    x,y = map(lambda x:int(x)-1, input().split())
    print(dist[x] + dist[y])
Problem p03745 (python)

Fixed submission:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    A = readInts()
    res = 0
    # 同じおなじやつは同じ奴でずっと続く
    i = 0
    while i < n:
        # 同じもの
        while i+1 < n:
            if A[i] == A[i+1]:
                i += 1
            else:
                break
        # 無くなったら、
        # もし先に上のものを見つけたら、ずっと上を探索する
        if i+1 < n:
            if A[i] < A[i+1]:
                while i+1 < n:
                    if A[i] <= A[i+1]:
                        i+=1
                    else:
                        break
        # どちらかなので、elifで。
            elif i + 1 < n:
                if A[i] > A[i+1]:
                    while i + 1 < n:
                        if A[i] >= A[i+1]:
                            i += 1
                        else:
                            break
        # ここで1ループは終わりなので、カウントに+1する
        #print(i)
        res += 1
        i += 1
    print(res)
if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
#from statistics import median
import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
S = readInts()
i = 0
cnt = 0
while i < n:
    while i+1 < n:
        if S[i] == S[i+1]:
            i += 1
        else:
            break
    if i + 1 < n:
        if S[i] < S[i+1]:
            while i + 1 < n:
                if S[i] =< S[i+1]:
                    i += 1
                else:
                    break
        else:
            while i + 1 < n:
                if S[i] >= S[i+1]:
                    i += 1
                else:
                    break
    cnt += 1
    i += 1
print(cnt)
Problem p03774 (python)

Fixed submission:
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

# Written by NoKnowledgeGG @YlePhan

#import math
#mod = 10**9+7



def main():
  n,m = map(int,input().split())
  
  AB = [map(int,input().split()) for _ in range(n)]
  CD = [list(map(int,input().split())) for _ in range(m)]
  idx = 1

  for i in range(n):
    a,b = AB[i]
    man = float("inf")
    for j in range(m-1,-1,-1):
      c,d = CD[j]
      if abs(a-c) + abs(b-d) <= man:
        man = abs(a-c) + abs(b-d)
        idx = j
    print(idx+1)
      
  
if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

# Written by NoKnowledgeGG @YlePhan

#import math
#mod = 10**9+7



def main():
  n,m = map(int,input().split())
  
  AB = [map(int,input().split()) for _ in range(n)]
  #print(AB)
  CD = [map(int,input().split()) for _ in range(m)]
  idx = 1
  man = float("inf")
  for i in range(n):
    a,b = AB[i]
    for j in range(m-1,-1,-1):
      c,d = CD[j]
      if abs(a-c) + abs(b-d) <= man:
        man = abs(a-c) + abs(b-d)
        idx = j
      print(j+1)
      
  
if __name__ == '__main__':
  main()
Problem p02873 (python)

Fixed submission:
a=input()
n=len(a)
p=0
q=0
r=0
i=0
while i<n:
  while a[i]=="<":
    i+=1
    p+=1
    if i==n:
      print(r+p*(p+1)//2)
      exit(0)
  while a[i]==">":
    i+=1
    q+=1
    if i==n:
      break
  r+=p*(p+1)//2+q*(q+1)//2-min(p,q)
  p=0
  q=0
print(r)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=input()
p=0
q=0
r=0
i=0
while i<n-1:
  while a[i]=="<":
    i+=1
    p+=1
    if i==n-1:
      print(r+p*(p+1)//2)
      exit(0)
  while a[i]==">":
    i+=1
    q+=1
    if i==n-1:
      break
  r+=p*(p+1)//2+q*(q+1)//2-min(p,q)
  p=0
  q=0
print(r)
Problem p02915 (python)

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

Buggy submission (verdict: Runtime Error):
print((int(input())**3)
Problem p03013 (python)

Fixed submission:
n,m=map(int,input().split())
a=[0]*(n+1)
b=[int(input()) for i in range(m)]
a[0]=a[1]=1
if m==0:
  for i in range(2,n+1):
    a[i]=(a[i-1]+a[i-2])%(10**9+7)
else:
  j=0
  if b[0]==1:
    a[1]=0
    if m>1:
      j=1
  for i in range(2,n+1):
    if i==b[j]:
      if j<m-1:
        j+=1
    else:
      a[i]=(a[i-1]+a[i-2])%(10**9+7)
print(a[n])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[0]*(n+1)
b=[int(input()) for i in range(m)]
a[0]=1
j=0
if b[0]==1:
  a[1]=0
  if j!=1:
    j=1
else:
  a[1]=1
for i in range(2,n+1):
  if i==b[j]:
    if j<m-1:
      j+=1
  else:
    a[i]=(a[i-1]+a[i-2])%(10**9+7)
print(a[n])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[0]*(n+1)
b=[int(input()) for i in range(m)]
a[0]=1
j=0
if b[0]==1:
  a[1]=0
  j=1
else:
  a[1]=1
for i in range(2,n+1):
  if i==b[j]:
    if j<m-1:
      j+=1
  else:
    a[i]=(a[i-1]+a[i-2])%(10**9+7)
print(a[n])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[0]*(n+1)
b=[int(input()) for i in range(m)]
a[0]=1
j=0
if b[0]==1:
  a[1]=0
  j=1
else:
  a[1]=1
for i in range(2,n+1):
  if i==b[j]:
    if j<m-1:
      j+=1
  else:
    a[i]=a[i-1]+a[i-2]
print(a[n])
Problem p02623 (python)

Fixed submission:
from itertools import accumulate
from bisect import bisect_right
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

def ruiseki(lst):
    return [0]+list(accumulate(lst))

ar = ruiseki(A)
br = ruiseki(B)
ans = 0
for i in range(1+N):
    left = K - ar[i]
    if left < 0:
        continue
    bidx = bisect_right(br, left) - 1
    ans = max(ans,i+bidx)

print(ans)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0
def dfs(a, b, t):
    global cnt
    cnt = max(cnt, a+b)
    if a < N and t + A[a] <= K:
        dfs(a+1, b, t+A[a])
    if b < M and t + B[b] <= K:
        dfs(b+1, a, t+B[b])
    
dfs(0, 0, 0)
print(cnt)
Problem p02685 (python)

Fixed submission:
N, M, K = map(int, input().split())
mod = 998244353
# 全て異なる色で塗った場合のリストを作る
d = [0] * (N+1)
d[0] = M
for i in range(N):
    d[i+1] = d[i] * (M-1) % mod

def createFacArr(n, mod):
    fac = [0] * n
    finv = [0] * n
    inv = [0] * n
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, n):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod
    return fac, finv

def comb(n ,k, mod, fac, finv):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod

fac, finv = createFacArr(N+10, mod)
ans = d[N-1]
#print(d)
for i in range(K):
    ans += d[N-2-i] * comb(N-1, i+1, mod, fac, finv)
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
mod = 998244353
# 全て異なる色で塗った場合のリストを作る
d = [0] * (N+1)
d[0] = M
for i in range(N):
    d[i+1] = d[i] * (M-1) % mod

def createFacArr(n, mod):
    '''
    二項係数計算用の配列の作成

    Parameters
    n : int
        配列のサイズ
    mod : int
        あまり

    Returns
    fac : list
        階乗のリスト
    finv : list
        modの逆元のリスト
    ivn : list
    '''
    fac = [0] * n
    finv = [0] * n
    inv = [0] * n
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, n):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod
    return fac, finv

def comb(n ,k, mod, fac, finv):
    '''
    二項係数の計算

    Parameters
    n : int
        元集合
    k : int
        元集合から選択する数
    mod : int
        あまり
    fac : list
        階乗のリスト
    finv : list
        逆元のリスト
    
    Returns
    c : int
        nCkの組み合わせの数
    '''
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod

fac, finv = createFacArr(N, mod)
ans = d[N-1]
#print(d)
for i in range(K):
    ans += d[N-2-i] * comb(N-1, i+1, mod, fac, finv)
    ans %= mod

print(ans)
Problem p02695 (python)

Fixed submission:
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]

def calc(p):
    ret = 0
    # 各条件を満たしていれば、dを加算していく
    for a, b, c, d in abcd:
        if p[b-1] - p[a-1] == c:
            ret += d
    return ret

ans = [0]
def dfs(s):
    if len(s) == N:
        ans[0] = max(ans[0], calc(s))
        return
    for i in range(s[-1],M+1):
        dfs(s+[i])

for i in range(1, M+1):
    dfs([i])

print(ans[0])

Buggy submission (verdict: Runtime Error):
from itertools import permutations
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]

def calc(p):
    ret = 0
    # 各条件を満たしていれば、dを加算していく
    for a, b, c, d in abcd:
        if p[b-1] - p[a-1] == c:
            ret += d
    return ret

ans = 0
for p in permutations(range(1,1+M)):
    p = list(p)[:N]
    ans = max(ans, calc(p))
print(ans)
Problem p02726 (python)

Fixed submission:
from collections import Counter
N, X, Y = map(int, input().split())
X, Y = X-1, Y-1
ans = []

for i in range(N):
    for j in range(i+1, N):
        ans.append(min(j-i, 1+abs(i-X)+abs(j-Y)))

c = Counter(ans)
for i in range(1,N):
    print(c[i])

Buggy submission (verdict: Runtime Error):
from collections import Counter
N, X, Y = map(int, input().split())
ans = []

for i in range(N):
    for j in range(i+1, N):
        ans.append(min(j-i, 1+abs(i-x)+abs(j-Y)))

c = Counter(ans)
for i in range(1,N):
    print(c[i])
Problem p02735 (python)

Fixed submission:
H, W = map(int, input().split())
#field = [list(input()) for _ in range(H)]
field =[["."] * (W+1)]
for _ in range(H):
    tmp = ["."]
    tmp.extend(list(input()))
    field.append(tmp)

dp = [[10**9] * (W+1) for _ in range(H+1)]
dp[1][0] = 0
dp[0][1] = 0
for h in range(1,H+1):
    for w in range(1,W+1):
        if field[h][w] == ".":
            dp[h][w] = min(dp[h-1][w], dp[h][w-1])
        else:
            u = dp[h-1][w] if field[h-1][w] == "#" else dp[h-1][w] + 1
            l = dp[h][w-1] if field[h][w-1] == "#" else dp[h][w-1] + 1
            dp[h][w] = min(u,l)

print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

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

goal_cnt = [10**20]
def dfs(x, y, cnt):
    if cnt >= goal_cnt[0]:
        return
    if field[x][y] == "#":
        cnt += 1
    if x == W-1 and y == H-1:
        goal_cnt[0] = min(goal_cnt[0], cnt)
        return
    for nx, ny in ((1,0),(0,1)):
        nx += x
        ny += y
        if nx >= W or ny >= H:
            continue
        dfs(nx, ny, cnt)

dfs(0,0,0)
print(goal_cnt[0])

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
field = [list(input()) for _ in range(H)]

goal_set = set()

def dfs(x, y, cnt):
    if field[x][y] == "#":
        cnt += 1
    if x == W-1 and y == H-1:
        goal_set.add(cnt)
    for nx, ny in ((1,0),(0,1)):
        nx += x
        ny += y
        if nx >= W or ny >= H:
            continue
        dfs(nx, ny, cnt)

dfs(0,0,0)
print(min(goal_set))
Problem p02754 (python)

Fixed submission:
N, A, B = map(int, input().split())
s = A+B
num = N // s * A
mod = N % s
num += min(mod, A)
print(num)

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

c = n // (a + b)
if c == 0:
    d = a + b
    assert False
else:
    d = n - (c * (a+b))

if d > a:
    ans = (c*a) + a
else:
    ans = (c*a) + d
    
print(ans)