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

Fixed submission:
import collections

N = int(input())
V = list(map(int,input().split()))

L1 = []
L2 = []

for i in range(N):
  if i % 2 == 0:
    L1.append(V[i])
  else:
    L2.append(V[i])
    
con1 = collections.Counter(L1).most_common()
con2 = collections.Counter(L2).most_common()

nums = 0

#全てが同じなら全体の半数を変える
if len(set(V)) == 1:
  print(N // 2)

#分割数列のそれぞれが全て等しい数からできているなら変える必要はない
elif len(set(L1)) == 1 and len(set(L2)) == 1:
  print(0)
#
else:
  ans = 0
  total = 0
  if con1[0][0] == con2[0][0]:
  
    for i in range(1,len(con1)):
      total += con1[i][1]
    for i in range(2,len(con2)):
      total += con2[i][1]
    total += con2[0][1]
    
    for i in range(1,len(con2)):
      ans += con2[i][1]
    for i in range(2,len(con1)):
      ans += con1[i][1]
    ans += con1[0][1]
    
    ans = min(ans,total)
    
  else:
    for i in range(1,len(con1)):
      ans += con1[i][1]
    for i in range(1,len(con2)):
      ans += con2[i][1]
    
  print(ans)

Buggy submission (verdict: Runtime Error):
import collections

N = int(input())
V = list(map(int,input().split()))

L1 = []
L2 = []

for i in range(N):
  if i % 2 == 0:
    L1.append(V[i])
  else:
    L2.append(V[i])
    
con1 = collections.Counter(L1).most_common()
con2 = collections.Counter(L2).most_common()

nums = 0


#全てが同じなら全体の半数を変える
if len(set(V)) == 1:
  print(N // 2)

#分割数列のそれぞれが全て等しい数からできているなら変える必要はない
elif len(set(L1)) == 1 and len(set(L2)) == 1:
  print(0)

else:
  ans = 0
  total = 0
  if con1[0][0] == con2[0][0]:
    for i in range(1,len(con1)):
      total += con1[i][1]
    for i in range(2,len(con2)):
      total += con2[i][1]
    total += con[0][1]
    for i in range(1,len(con2)):
      ans += con2[i][1]
    for i in range(2,len(con1)):
      ans += con1[i][1]
    ans += con1[0][1]
    ans = min(ans,total)
  else:
    for i in range(1,len(con1)):
      ans += con1[i][1]
    for i in range(1,len(con2)):
      ans += con2[i][1]
    
  print(ans)
Problem p03273 (python)

Fixed submission:
H,W = map(int,input().split())

A = ""

for _ in range(H):
  s = input()
  if len(set(s)) == 1 and s == "." * W:
    H -= 1
  else:
    for i in s:
      A += i

if len(A) == 0:
  print(A)

else:
  M = []

  for i in range(W):
    if A[i] == ".":
      for j in range(i + W,H * W,W):
        if A[j] == "#":
          break
      else:
        M.append(i)

  A = [A[i] for i in range(H * W) if not (i % W) in M]
  W = W - len(M)
  
  S = ""
  
  for i in range(H * W):
    S += A[i]
    if (i + 1) % W == 0:
      print(S)
      S = ""

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())

A = ""

for _ in range(H):
  s = input()
  if len(set(s)) == 1 and s == "." * W:
    H -= 1
  else:
    for i in s:
      A.append(i)

if len(A) == 0:
  print(A)

else:
  M = []

  for i in range(W):
    if A[i] == ".":
      for j in range(i + W,H * W,W):
        if A[j] == "#":
          break
      else:
        M.append(i)

  A = [A[i] for i in range(H * W) if not (i % W) in M]
  W = W - len(M)
  
  S = ""
  
  for i in range(H * W):
    S += A[i]
    if (i + 1) % W == 0:
      print(S)
      S = ""

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())

A = []

for _ in range(H):
  s = input()
  if len(set(s)) == 1:
    H -= 1
  else:
    for i in s:
      A.append(i)

M = []

for i in range(W):
  if A[i] == ".":
    for j in range(i + W,H * W,W):
      if A[j] == "#":
        break
    else:
      M.append(i)
      
A = [A[i] for i in range(H * W) if not (i % W) in M]
W = W - len(M)

S = ""

for i in range(H * W):
  S += A[i]
  if (i + 1) % W == 0:
    print(S)
    S = ""
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())

con = 0

for i in range(0,len(S)):
  if S[i] == "1":
    con += 1
  else:break

if K <= con:
  print(1)
else:
  if S[0] == "1":
    S = S.replace("1","")
    print(int(S[0]))
  else:
    print(int(S[0]))

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())

con = 0

for i in range(0,len(S)):
  if S[i] == "1":
    con += 1
  else:break
    

if K < con:
  print(1)
else:
  if S[0] == "1":
    print(int(S[1]))
  else:
    print(int(S[0]))

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())

con = 0

for i in S:
  if i == "1":
    con += 1
    


if S[0] == "1":
  print(int(S[1]))
else:print(int(S[0]))

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())

con = 0

for i in S:
  if i == "1":
    con += 1
    

if K < con:
  print(1)
else:
  if S[0] == "1":
    print(int(S[1]))
  else:
    print(int(S[0]))
Problem p03292 (python)

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

ans = (max(A) - min(A))

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

cur = T.find(S[0])
i = 0
con = len(S)

while con != 0:
  if S[i] == T[cur]:
    con -= 1
    
    if con == 0:
      print("Yes")
    
    i += 1
    if cur == (len(S) - 1):
      cur = 0
    else:
      cur += 1
  else:
    print("No")
    break
Problem p03360 (python)

Fixed submission:
ABC = sorted(list(map(int,input().split())))
K = int(input())

print(sum(ABC[:2]) + (ABC[-1]) * (2 ** K))

Buggy submission (verdict: Runtime Error):
ABC = sorted(list(map(int,input().split())))
K = int(input())

print(sum(ABC[:2]) + (ABC[-1] * 2( **  K))
Problem p03361 (python)

Fixed submission:
H,W = map(int,input().split())
grid = [[]] * H

for i in range(H):
  c = list(input())
  grid[i] = c
  
black = "#"
white = "."

ans = "Yes"

for i in range(H):
  for j in range(W):
    if grid[i][j] == black:
      around = ""
      #ヨコ
      for t in range(max(0,j - 1),min(W,j + 2)):
        if t != j:
          around += grid[i][t]
      #タテ
      for k in range(max(0,i - 1),min(H,i + 2)):
        if k != i:
          around += grid[k][j]
      
      if all([s == white for s in around]):
        ans = "No"
        break
  if ans == "No":
    break
      
print(ans)

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
grid = [[]] * H

for i in range(H):
  c = list(input())
  grid[i] = c
  
black = "#"
white = "."

ans = "Yes"


for i in range(H):
  for j in range(W):
    if grid[i][j] == black:
      here = grid[i][j]
      around = ""
      
      if i == 0:
        around += grid[i + 1][j]
      elif i == W - 1:
        around += grid[i - 1][j]
      else:
        around += (grid[i - 1][j] + grid[i + 1][j])
      
      if j == 0:
        around += grid[i][j + 1]
      elif j == H - 1:
        around += grid[i][j - 1]
      else:
        around += (grid[i][j + 1] + grid[i][j - 1])
      
      if all([i == white for i in around]):
        ans = "No"
        break

print(ans)
Problem p03373 (python)

Fixed submission:
A,B,C,X,Y = map(int,input().split())

C2 = C * 2
diff = abs(X - Y)

ans = 0


if C2 > A + B:
  ans = (A * X) + (B * Y)

elif C2 <= A + B:
  if X > Y:
    ans = min(C2 * Y + A * diff,C2 * X)

  else:
    ans = min(C2 * X + B * diff,C2 * Y)
    
print(ans)

Buggy submission (verdict: Runtime Error):
A,B,C,X,Y = map(int,input().split())

D = (A + B) // 2
C2 = C * 2

ans = 0

if C2 <= min(A,B):
  ans += C2 * max(X,Y)
  print(ans)
elif C2 > max(A,B):
  ans += (A * X) + (B * Y)
  print(ans)
else:
  if D >= C:
    if X > Y:
    ans += C2 * Y
    ans += A * (X - Y)
    print(ans)
  else:
    ans += (A * X) + (B * Y)
    print(ans)
Problem p03393 (python)

Fixed submission:
S = input()

if len(S) < 26:
  N = [chr(i) for i in range(97,123) if chr(i) not in S]
  print(S + N[0])
else:
  for i in range(26):
    for j in range(i+1):
      if S[-(i + 1)] < S[-(j + 1)]:
          print(S[:-(i+1)]+S[-(j+1)])
          exit()
  else:
    print(-1)

Buggy submission (verdict: Runtime Error):
S = input()
N = [chr(i) for i in range(97,123) if chr(i) not in S]

if len(S) == 26:
  if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    LS = list(S)
    sLS = sorted(LS)
    for i in range(0,27):
      if LS[i] != sLS[i]:
        S = S[:i - 1] + sLS[i]
        break
else:
  S = S + N[0]
  print(S)

Buggy submission (verdict: Runtime Error):
S = input()
N = [chr(i) for i in range(97,123) if chr(i) not in S]

if len(S) == 26:
  if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    LS = list(S)
    sLS = sorted(LS)
    print(LS)
    print(sLS)
    for i in range(0,27):
      if LS[i] != sLS[i]:
        S = S[:i - 1] + sLS[i]
        break
else:
  S = S + N[0]
  
print(S)
Problem p03403 (python)

Fixed submission:
N = int(input())
A = [0]
A = A + list(map(int,input().split()))
A = A + [0]

D = 0

for i in range(N + 1):
  D += abs(A[i + 1] - A[i])
  
for i in range(1,N + 1):
  ans = D + abs(A[i + 1] - A[i - 1]) - (abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i]))
  print(ans)

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

for i in range(N):
  now = 0
  ans = 0
  for j in range(N):
    if i != j:
      next = A[j]
      ans += abs(next - now)
      now = next
  ans += abs(B[-1])
  print(ans)
Problem p03436 (python)

Fixed submission:
from collections import deque

H,W = map(int,input().split())
maze = [[] for i in range(H)]
con = 0
inf = 10 ** 6
distance = [[inf] * W for i in range(H)]

for i in range(H):
  m = list(input())
  maze[i] = m
  con += m.count("#")

def bfs(maze, distance, sh, sw):
  queue = deque([[sh, sw]])
  distance[sh][sw] = 0
  while queue:
    h,w = queue.popleft()
    if h == H - 1 and w == W - 1:
      return distance[H - 1][W - 1]
    for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
      new_h, new_w = h + j, w + k
      if new_h < 0 or new_h >= H or \
        new_w < 0 or new_w >= W:
          continue
      elif maze[new_h][new_w] != "#" and \
        distance[new_h][new_w] > distance[h][w] + 1:
        distance[new_h][new_w] = distance[h][w] + 1

        queue.append([new_h, new_w])
  
minpath = bfs(maze,distance,0,0)

if minpath == None:
  print(-1)
else:
  print(H * W - minpath - con - 1)

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

H,W = map(int,input().split())
maze = [[] for i in range(H)]
con = 0
inf = 10 ** 9
distance = [[inf] * W for i in range(H)]

for i in range(H):
  m = list(input())
  maze[i] = m
  con += m.count("#")

def bfs(maze, disrance, sh, sw):
  queue = deque([[sh, sw]])
  distance[sh][sw] = 0
  while queue:
    h,w = queue.popleft()
    if h == H - 1 and w == W - 1:
      return distance[h][w]
    for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
      new_h, new_w = h + j, w + k
      if new_h < 0 or new_h >= H or \
        new_w < 0 or new_w >= W:
          continue
      elif maze[new_h][new_w] != "#" and \
        distance[new_h][new_w] > distance[h][w] + 1:
        distance[new_h][new_w] = distance[h][w] + 1

        queue.append([new_h, new_w])
        
minpath = bfs(maze,distance,0,0)

print(H * W - con - minpath - 1)

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

H,W = map(int,input().split())
maze = [[] for i in range(H)]
con = 0
inf = 10 ** 9
distance = [[inf] * W for i in range(H)]

for i in range(H):
  m = list(input())
  maze[i] = m
  con += m.count("#")

def bfs(maze, disrance, sh, sw):
  queue = deque([[sh, sw]])
  distance[sh][sw] = 0
  while queue:
    h,w = queue.popleft()

    if h == H - 1 and w == W - 1:
      return distance[h][w] - 1
    for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
      new_h, new_w = h + j, w + k
      if new_h < 0 or new_h >= H or \
        new_w < 0 or new_w >= W:
          continue
      elif maze[new_h][new_w] != "#" and \
        distance[new_h][new_w] == inf:
        distance[new_h][new_w] = distance[h][w] + 1

        queue.append([new_h, new_w])
        
minpath = bfs(maze,distance,0,0)

print(H * W - con - minpath)
Problem p03476 (python)

Fixed submission:
import sys
input = sys.stdin.readline

def isprime(x):
  if x <= 1:
    return False
  for i in range(2, int(x**0.5) + 1):
    if x % i == 0:
      return False
  return True


A = [0] * 10 ** 5
B = [0] * 10 ** 5
con = 0

for i in range(10 ** 5):
  if isprime(i):
    A[i] = 1
  if A[i] and A[(i + 1) // 2]:
    con += 1
  B[i] = con

Q = int(input())

for _ in range(Q):
  l, r = map(int, input().split())
  print(B[r] - B[l - 1])

Buggy submission (verdict: Runtime Error):
import bisect

def primetable(n):
  list = [True for _ in range(n + 1)]
  i = 2
  while i * i <= n:
    if list[i]:
      j = i + i
      while j <= n:
        list[j] = False
        j += i
    i += 1
  table = [i for i in range(n + 1) if list[i] and i >= 1]
  return table

prime = primetable(10 ** 5)
accume = [0] * (len(prime))
con = 0

for i,p in enumerate(prime):
  if p <= 2:
    continue
  q = (p + 1) // 2
  if q in prime:
    con += 1
  accume[i] = con

Q = int(input())

for i in range(Q):
  l,r = map(int,input().split())
  if l == 1:
    l += 1
  R = bisect.bisect_left(prime,r)
  L = bisect.bisect_left(prime,l)
  print(accume[R] - accume[L - 1])
Problem p03503 (python)

Fixed submission:
N = int(input())
F = []
P = []

for i in range(N):
  f = list(map(int,input().split()))
  F.append(f)
  
for i in range(N):
  p = list(map(int,input().split()))
  P.append(p)
  
value = 0

ans = - (10 ** 9)

def recur(list):
  con = len(list)
  #list = [0,0, ... ~ 0] ~ [1,1, ... ~ 1]
  if con == 10:
    #1がない = 出店していない場合は何も返さない
    if list.count(1) == 0:
      return
    value = 0
    #インデックス番号とF[i] = 店の出店リストを取得
    for n,shop in enumerate(F):
      con = 0
      for j in range(10):
          #j日に自店が出店し、かつ他店nも出店するならば、カウントする
          if list[j] == 1 and shop[j] == 1:
              con += 1
      #出店リストlistのパターンに応じた店nごとの利益を
      #同時出店日数conから算出し足し合わせる
      value += P[n][con]
 
    global ans
  
    ans = max(ans, value)
    
  else:
    #出店しない
    recur(list + [0])
    #出店する
    recur(list + [1])
    
recur([])
    
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
F = []
P = []

for i in range(N):
  f = list(map(int,input().split()))
  F.append(f)
  
for i in range(N):
  p = list(map(int,input().split()))
  P.append(p)
  
value = 0

ans = - (10 ** 9)

def recur(list):
  con = len(list)
  #list = [0,0, ... ~ 0] ~ [1,1, ... ~ 1]
  if con == 10:
    #1がない = 出店していない場合は何も返さない
    if list.count(1) == 0:
        return
    value = 0
    #インデックス番号とF[i] = 店の出店リストを取得
    for n,shop in enumerate(F):
        con = 0
        for j in range(10):
          	#j日に自店が出店し、かつ他店nも出店するならば、カウントする
            if list[j] == 1 and shop[j] == 1:
                con += 1
        #出店リストlistのパターンに応じた店nごとの利益を
        #同時出店日数conから算出し足し合わせる
        value += P[n][con]
 
    global ans
  　
    ans = max(ans, value)
    
  else:
    #出店しない
    recur(list + [0])
    #出店する
    recur(list + [1])
    
recur([])
    
print(ans)
Problem p03559 (python)

Fixed submission:
import bisect

N = int(input())
parts = [[] for i in range(3)]
con = [0] * N

ans = 0

for i in range(3):
  t = sorted(list(map(int,input().split())))
  parts[i] = t

under =parts[2]
middle = parts[1]
upper = parts[0]

for i in range(N):
  p = middle[i]
  ans += bisect.bisect_left(upper,p) * (N - bisect.bisect_right(under,p))
    
print(ans)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    int con;
    con = 0;
    vector<vector<int>> parts(3, vector<int>(N));

    for(int i = 0;i < 3; i++){
        for(int j = 0;j < N; j++){
            cin >> parts[i][j];
        }
    }

    for (int i = 0;i < N; i ++){
        for (int j = 0;j < N; j++){
            if (parts[2][i] > parts[1][j]){
                for (int k = 0;k < N; k++){
                    if (parts[1][j] > parts[0][k]){
                        con += 1;

                    } 
                }
            }
        }
    }
    cout << con << endl;
}

Buggy submission (verdict: Runtime Error):
N = int(input())
parts = [[] for i in range(3)]
bigger = [[0] * N for i in range(2)]

m = 0

for i in range(3):
  t = list(map(int,input().split()))
  t = [i for i in t if i >= m]
  parts[i] = t
  m = min(t)

under =parts[2]
middle = parts[1]
upper = parts[0]

con = 0

for i in range(len(under)):
  p = under[i]
  for j in range(len(middle)):
    q = middle[j]
    if p > q:
      for k in range(len(upper)):
        r = upper[k]
        if q > r:
          con += 1
          
print(con)
Problem p03601 (python)

Fixed submission:
A,B,C,D,E,F = map(int,input().split())

conc = 0
total = 0

ans = [100 * A,0]

for a in range(0,31):
  for b in range(0,31):
    water = (A * a + B * b) * 100
    if water > F:
      break
    else:
      for c in range(3001):
        water = (A * a + B * b) * 100
        if water == 0:
          break
        #探索中の水量に解かせる砂糖の量
        sugar_limit = int(water * E / 100)
        #操作Cで投入された砂糖の量
        sugarC = c * C
        
        if sugarC > sugar_limit:
          break
        #ビーカーに溶かせる容量
        else:
          rest = F - water - sugarC
          #水に溶かせられる砂糖量
          sugar_rest = sugar_limit - sugarC
          
          if rest < 0:
            break
          
          else:
            #操作Dで溶かせられる砂糖領
            sugarD = (min(rest,sugar_rest) // D) * D
            sugar = sugarC + sugarD
            temp = (sugar) / (water + sugar)
            if conc < temp and temp < E:
              conc = temp
              total = water + sugar
              ans = [total,sugar]
        
print(ans[0],ans[1])

Buggy submission (verdict: Runtime Error):
A,B,C,D,E,F = map(int,input().split())

conc = 0
total = 0

for a in range(0,31):
  for b in range(0,31):
    water = (A * a + B * b) * 100
    if water > F:
      break
    else:
      for c in range(3001):
        water = (A * a + B * b) * 100
        
        if water == 0:
          break
        #探索中の水の量に溶かせられる砂糖の限界量
        sugar_limit = int(water * E / 100)
        #操作Cで投入された砂糖の量
        sugarC = c * C
        
        if sugarC > sugar_limit:
          break
        #ビーカーに溶かせる容量
        else:
          rest = F - water - sugarC
          #水に溶かせられる砂糖量
          sugar_rest = sugar_limit - sugarC
          
          if rest < 0:
            break
          
          else:
            #操作Dで溶かせられる砂糖の量
            sugarD = (min(rest,sugar_rest) // D) * D
            sugar = sugarC + sugarD
            temp = (sugar) / (water + sugar)
            if conc < temp and temp < E:
              conc = temp
              total = water + sugar
              ans = [total,sugar]
        
print(ans[0],ans[1])
Problem p03632 (python)

Fixed submission:
A,B,C,D = map(int,input().split())
 
alice = [i for i in range(A,B + 1)]
bob = [i for i in range(C,D + 1)]
 
common = [i for i in bob if i in alice]

if len(common) == 0:
  print(0)
else:
  print(len(common)-1)

Buggy submission (verdict: Runtime Error):
A,B,C,D = map(int,input().split())

inter1 = [i for i in range(A,B + 1)]
inter2 = [i for i in range(C,D + 1)]

inter3 = []

for i in range(0,max(B,D)):
  if i in inter1 and i in inter2:
    inter3.append(i)
    
print(max(inter3) - min(inter3))
Problem p03651 (python)

Fixed submission:
import fractions
from functools import reduce

N,K = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse = True)

def gcd_list(numbers):
  return reduce(fractions.gcd, numbers)

GCD = gcd_list(A)

if K > A[0]:
  print("IMPOSSIBLE")
elif K % GCD != 0:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse = True)

diff = [0] * (N - 1)

for i in range(N - 1):
  diff[i] = A[i] - A[i + 1]
  
if K > A[0]:
  print("IMPOSSIBLE")
elif len(set(diff)) == 1 and A[0] % diff[0] == 0:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")
Problem p03661 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
P = []

S = sum(A)

snuke = 0
ans = 10 ** 12

for i in range(N - 1):
  snuke += A[i]
  dif = abs(S - (2 * snuke))
  
  if ans >= dif:
    ans = dif
    
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
P = []

S = sum(A)

snuke = 0
ans = 10 ** 9

for i in range(0,N - 1):
  snuke += A[i]
  ans = (S - 2 * snuke)
  
  if ans >= dif:
    ans = dif
    
print(ans)
Problem p03683 (python)

Fixed submission:
import sys
from functools import reduce,lru_cache
import math
from operator import mul

def main():
  #sys.setrecursionlimit(10 ** 5 + 1)
  N,M = map(int,input().split())
  
  @lru_cache(maxsize = None)
  def recur(n):
    if n == 0:
      return 1
    else:
      m = n * recur(n - 1)
      return m
      
  if N == M:
    L = [i for i in range(1,N + 1)]
    #ans = (reduce(mul,L) ** 2) * 2  % (10 ** 9 + 7)
    ans = (math.factorial(M) ** 2) * 2 % ((10 ** 9) + 7)
    print(ans)
  elif abs(M - N) == 1: 
    ans = math.factorial(N) * math.factorial(M) % ((10 ** 9) + 7)
    print(ans)
    
  else:
    print(0)
    
main()

Buggy submission (verdict: Runtime Error):
import sys
from functools import reduce,lru_cache
from operator import mul

def main():
  sys.setrecursionlimit(10 ** 5)
  N,M = map(int,input().split())
  
  @lru_cache(maxsize = None)
  def recur(n):
    if n == 0:
      return 1
    else:
      m = n * recur(n - 1)
      return m
      
  if N == M:
    L = [i for i in range(1,N + 1)]
    #ans = (reduce(mul,L) ** 2) * 2  % (10 ** 9 + 7)
    ans = (recur(N) % (10 ** 9 + 7))
    print(ans)
  elif abs(M - N) == 1: 
    ans = 1
    ans *= (recur(N) % (10 ** 9 + 7)) 
    ans *= (recur(M) % (10 ** 9 + 7))
    print(ans)
    
  else:
    print(0)
    
main()
Problem p03739 (python)

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

#値を修正する場合、1か−1にすればよい
##そのためには、値の絶対値に1を足した数を加えればよい

#正、負のパターンと負、正のパターンの両方について算出し、小さい方を出力する
##没解だと、所与のA[0]の符号を基準としたまま、答えを提出していたが、
##当然、それが最適値であるとは限らない！！！

total = 0
ans = 0
total2 = 0
ans2 = 0

for i in range(N):
    total += A[i]
    #奇数番目を正にする
    if i % 2 == 0:
        #1より小さい == 0以下
        if total < 1:
            ans += 1 - total
            total = 1
    else:
        #0以上
        if total > -1:
            ans += (1 + total)
            total = -1

for i in range(N):
    total2 += A[i]
    #偶数番目を正にする
    if i % 2 == 1:
        if total2 < 1:
            ans2 += 1 - total2
            total2 = 1
    else:
        if total2 > -1:
            ans2 += 1 + total2
            total2 = -1

print(min(ans,ans2))

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

totals = [0] * N
totals[0] = A[0]
con = 0

if totals[0] == 0:
  for i in range(1,N):
    if A[i] != 0:
      f = A[i]
      if f > 0:
        totals[0] = -1
      else:
        totals[0] = 1
    break
  else:
    totals[0] = 1
  con += 1

for i in range(1,N):
  totals[i] = totals[i - 1] + A[i]
  if totals[i - 1] * totals[i] >= 0:
    if totals[i - 1] < 0:
      con += abs(1 - totals[i])
      totals[i] += abs(1 - totals[i])
    elif totals[i - 1] > 0:
      con += abs(-1 - totals[i])
      totals[i] -= abs(-1 - totals[i])
  print(totals[:i + 1])
  
print(con)