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

Fixed submission:
def abp(a, b, p):
    if b == 0:
        return 1
    if b % 2 == 0:
        tmp = abp(a, b // 2, p)
        return (tmp * tmp) % p
    if b % 2 == 1:
        return (a * abp(a, b - 1, p)) % p

def nCr(n, r, p):
    total = 1
    for i in range(r):
        total *= (n - i) * abp(r - i, p - 2, p)
        total %= p
    return total

n, a, b = map(int, input().split())
p = 1000000007
ret = abp(2, n, p) - nCr(n, a, p) - nCr(n, b, p) - 1
print(ret % p)

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

mod = 10 ** 9 + 7
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル

for i in range(2, max(a, b) + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((- inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

def nCr(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod

p = 1000000007
total = (2 ** n - 1) % p
total = (total - nCr(n, a, p) - nCr(n, b, p)) % p
print(total)
Problem p02789 (python)

Fixed submission:
n, m = map(int, input().split())
print('Yes' if n == m else 'No')

Buggy submission (verdict: Runtime Error):
n, m = map(input().split())
print('Yes' if n == m else 'No')
Problem p02811 (python)

Fixed submission:
k, x = map(int, input().split())
print('Yes' if 500 * k >= x else 'No')

Buggy submission (verdict: Runtime Error):
k, x = map(int, input())
print('Yes' if 500 * k >= x else 'No')
Problem p02837 (python)

Fixed submission:
from itertools import product

n = int(input())

d = {}
for i in range(n):
  a = int(input())
  for _ in range(a):
    x, y = map(int, input().split())
    if i + 1 not in d:
      d[i + 1] = []
    d[i + 1].append((x, y))

ret = 0
for x in product((0, 1), repeat=n):
  tmp = [-1] * n
  ok = True
  for i in range(n):
    if x[i] == 1 and i + 1 in d:
      for y in d[i + 1]:
        if tmp[y[0] - 1] == -1:
          tmp[y[0] - 1] = y[1]
        elif tmp[y[0] - 1] != y[1]:
          ok = False
          break
    if not ok:
      break
  if ok and all(a == b or b == -1 for a, b in zip(x, tmp)):
    ret = max(ret, sum(x))

print(ret)

Buggy submission (verdict: Runtime Error):
from itertools import product

n = int(input())

d = {}
for i in range(n):
  a = int(input())
  for _ in range(a):
    x, y = map(int, input().split())
    if i + 1 not in d:
      d[i + 1] = []
    d[i + 1].append((x, y))

ret = 0
for x in product((0, 1), repeat=n):
  tmp = [-1] * n
  ok = True
  for i in range(n):
    if x[i] == 1:
      for y in d[i + 1]:
        if tmp[y[0] - 1] == -1:
          tmp[y[0] - 1] = y[1]
        elif tmp[y[0] - 1] != y[1]:
          ok = False
          break
    if not ok:
      break
  if ok and all(a == b or b == -1 for a, b in zip(x, tmp)):
    ret = max(ret, sum(x))

print(ret)
Problem p02843 (python)

Fixed submission:
x = int(input())
dp = [False] * max(106, x + 1)
for i in range(100, 106):
    dp[i] = True
for i in range(106, x + 1):
    dp[i] = any(dp[i - j] for j in range(100, 106))
print(1 if dp[x] else 0)

Buggy submission (verdict: Runtime Error):
x = int(input())
dp = [False] * (x + 1)
for i in range(100, 106):
    dp[i] = True
for i in range(106, x + 1):
    dp[i] = any(dp[i - j] for j in range(100, 106))
print(1 if dp[x] else 0)
Problem p02856 (python)

Fixed submission:
m = int(input())
CD = [list(map(int, input().split())) for _ in range(m)]
count = 0
tmp = -1
total = 0
for c, d in CD:
  q, m = divmod(tmp + c * d, 9)
  count += q
  tmp = m
  total += d
print(total - 1 + count)

Buggy submission (verdict: Runtime Error):
m = int(input())
CD = [list(map(input().split())) for _ in range(m)]
count = 0
tmp = -1
total = 0
for c, d in CD:
  q, m = divmod(c * d, 9)
  count += q
  tmp += m
  if tmp >= 9:
    count += 1
    tmp %= 9
  total += d
print(total - 1 + count)
Problem p02900 (python)

Fixed submission:
from math import ceil
from fractions import gcd

a, b = map(int, input().split())
c = gcd(a, b)
count = 1
for num in range(2, ceil(c**0.5) + 1):
  if c % num == 0:
    count += 1
    while c % num == 0:
      c = c // num
if c > 1:
  count += 1
print(count)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

a, b = map(int, input().split())
c = gcd(a, b)
count = 1
for num in primes(c):
  if c % num == 0:
    count += 1
print(count)
Problem p02936 (python)

Fixed submission:
from collections import defaultdict, deque

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

tree = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

count = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    count[p - 1] += x

ret = [0] * n
q = deque(maxlen = n)
q.append((0, 0))
while len(q) > 0:
    f, c = q.popleft()
    ret[c] = count[c] + ret[f]
    for n in tree[c]:
        if n != f:
            q.append((c, n))

print(*ret)

Buggy submission (verdict: Runtime Error):
from queue import Queue
from collections import defaultdict

count = defaultdict(int)
tree = defaultdict(lambda: [])

n, q = map(int, input().split())
for _ in range(_q):
    p, x = map(int, input().split())
    count[p] += x
for _ in range(_n - 1):
    a, b = map(int, input().split())
    tree[a].append(b)

ret = [0] * n
q = Queue()
q.put((0, 1))
while not q.empty():
    f, c = q.get()
    ret[c - 1] = count[c] + ret[f - 1]
    for n in tree[c]:
        if n != f:
            q.put((c, n))

print(*ret)

Buggy submission (verdict: Runtime Error):
from queue import Queue
from collections import defaultdict

def solve(n, q, AB, PX):
    count = defaultdict(int)
    for p, x in PX:
        count[p] += x

    tree = defaultdict(lambda: [])
    for a, b in AB:
        tree[a].append(b)

    ret = [0] * n
    q = Queue()
    q.put((1, 1))
    while not q.empty():
        f, c = q.get()
        ret[c - 1] = count[c] + ret[f - 1]
        for n in tree[c]:
            if f != c:
                q.put((c, n))

    return ret

_n, _q = map(int, input().split())
_AB = [map(int, input().split()) for _ in xrange(_n - 1)]
_PX = [map(int, input().split()) for _ in xrange(_q)]
print(*solve(_n, _q, _AB, _PX))
Problem p02947 (python)

Fixed submission:
from collections import defaultdict

def solve(n, S):
    counts = defaultdict(lambda: 0)
    for s in S:
        counts[''.join(sorted(list(s)))] +=  1
    total = 0
    for v in counts.values():
        if v > 1:
            total += int(v * (v - 1) / 2)
    return total

_n = int(input())
_S = [input() for _ in range(_n)]
print(solve(_n, _S))

Buggy submission (verdict: Runtime Error):
from math import factorial
from collections import OrderedDict

def solve(n, S):
    total = 0
    l = {}
    for s in S:
        key = ''.join(sorted(s))
        l[key] = (l[key] + 1) if key in l else 1
    for v in l.values():
        if v > 1:
            total += int(factorial(v) / factorial(2) / factorial(v - 2))
    return total

_n = int(input())
_S = [input() for _ in range(_n)]
print(solve(_n, _S))
Problem p02958 (python)

Fixed submission:
def solve(n, A):
    def check(L):
        for i in range(1, len(L)):
            if L[i] < L[i - 1]:
                return False
        return True
    if check(A):
        return 'YES'
    for i in range(n):
        for j in range(i + 1, n):
            if check(A[0:i] + [A[j]] + A[i + 1:j] + [A[i]] + A[j + 1:]):
                return 'YES'
    return 'NO'

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
def check(L):
  for i in range(1, len(L)):
    if L[i] < L[i - 1]:
      return False
  return True
for i in range(n):
  for j in range(i + 1, n):
    if check(A[0:i] + [A[j]] + A[i+1:j] + [A[i]] + A[j+1:]):
      print('YES')
      return
print('NO')
Problem p03050 (python)

Fixed submission:
from math import ceil
n = int(input())

total = 0
for i in range(ceil(n ** 0.5) + 1):
  if n % (i + 1) == 0:
    a = n // (i + 1) - 1
    if a >= 2 and n // a == n % a:
      total += a

print(total)

Buggy submission (verdict: Runtime Error):
from math import ceil
n = int(input())

total = 0
for i in range(ceil(n ** 0.5) + 1):
  if n % (i + 1) == 0:
    a = n // (i + 1) - 1
    if n // a == n % a:
      total += a

print(total)
Problem p03262 (python)

Fixed submission:
def solve(n, x0, X):

    def gcd(a, b):
        if a > b:
            a, b = b, a
        while a % b != 0:
            a, b = b, a % b
        return b

    X = [abs(x - x0) for x in X]
    g = X.pop()
    for x in X:
        g = gcd(g, x)
    return g

_n , _x0 = map(int, input().split())
_X = map(int, input().split())
print(solve(_n, _x0, _X))

Buggy submission (verdict: Runtime Error):
from math import gcd

def solve(n, x0, X):
    X = [abs(x - x0) for x in X]
    g = X.pop()
    for x in X:
        g = gcd(g, x)
    return g

_n , _x0 = map(int, input().split())
_X = map(int, input().split())
print(solve(_n, _x0, _X))

Buggy submission (verdict: Runtime Error):
import math

def solve(n, x0, X):
    X = [x - x0 for x in X]
    g = X.pop()
    for x in X:
        g = math.gcd(g, x)
    return g

_n , _x0 = map(int, input().split())
_X = map(int, input().split())
print(solve(_n, _x0, _X))
Problem p03309 (python)

Fixed submission:
from math import floor

def solve(n, A):
    B = sorted([a - (i + 1) for i, a in enumerate(A)])
    b = B[n // 2]
    ret = sum(abs(a - (b + i + 1)) for i, a in enumerate(A))
    if n % 2 == 0:
        b = B[n // 2 + 1]
        tmp = sum(abs(a - (b + i + 1)) for i, a in enumerate(A))
        if tmp < ret:
            ret = tmp
    return ret

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))

Buggy submission (verdict: Runtime Error):
from math import floor

def solve(n, A):
    A.sort()
    b = A[n // 2 + 1]
    return sum(abs(a - (b + i + 1)) for i, a in enumerate(A))

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))
Problem p03341 (python)

Fixed submission:
from collections import Counter
n = int(input())
s = input()
c = Counter(s)
tmp = c['E']
best = tmp - (1 if s[0] == 'E' else 0)
for i in range(1, n):
    if s[i - 1] == 'W':
        tmp += 1
    else:
        tmp -= 1
    if tmp - (1 if s[i] == 'E' else 0) < best:
        best = tmp - (1 if s[i] == 'E' else 0)
print(best)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
s = input()
c = Counter(s)
tmp = c['E'] - (1 if s[0] == 'E' else 0)
best = tmp
for i in range(1, n):
    if s[i - 1] == 'W'
        tmp += 1
    else:
        tmp -= 1
    if tmp < best:
        best = tmp
print(best)
Problem p03352 (python)

Fixed submission:
x = int(input())
print(max(i ** j for i in range(1, 34) for j in range(2, 11) if i ** j <= x))

Buggy submission (verdict: Runtime Error):
x = int(input())
print(max(i ** j for i in range(2, 34) for j in range(2, 11) if i ** j <= x))
Problem p03625 (python)

Fixed submission:
from collections import Counter

def solve(n, A):
    c = Counter(A)
    cands = sorted(filter(lambda kv: kv[1] >= 2, c.items()),  key=lambda kv: -kv[0])
    ret = 0
    if len(cands) >= 1 and cands[0][1] >= 4:
        ret = cands[0][0] * cands[0][0]
    elif len(cands) >= 2:
        ret = cands[0][0] * cands[1][0]
    return ret

_n = int(input())
_A = map(int, input().split())
print(solve(_n, _A))

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

def solve(n, A):
    c = Counter(A)
    cands = sorted(filter(lambda kv: kv[1] >= 2, c.items()),  key=lambda kv: -kv[0])
    ret = 0
    if cands[0][1] >= 4:
        ret = cands[0][0] * cands[0][0]
    elif len(cands) >= 2:
        ret = cands[0][0] * cands[1][0]
    return ret

_n = int(input())
_A = map(int, input().split())
print(solve(_n, _A))
Problem p03636 (python)

Fixed submission:
s = input()
print(s[0] + str((len(s) - 2)) + s[-1])

Buggy submission (verdict: Runtime Error):
s = input()
print(s[0] + (len(s) - 2) + s[-1])
Problem p03645 (python)

Fixed submission:
from collections import deque

def solve(n, m, AB):
    g = [[] for _ in range(n)]
    for a, b in AB:
        g[a - 1].append(b - 1)
        g[b - 1].append(a - 1)

    q = deque(maxlen = n)
    q.append((0, 0))
    used = {0}
    while len(q) > 0:
        i, d = q.popleft()
        if d >= 2:
            break
        for c in g[i]:
            if c in used:
                continue
            if d == 1 and c == n - 1:
                return 'POSSIBLE'
            q.append((c, d + 1))
            used.add(c)
    return 'IMPOSSIBLE'

_n, _m = map(int, input().split())
_AB = [map(int, input().split()) for _ in range(_m)]
print(solve(_n, _m, _AB))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(_m)]
cands = set(b if a == 1 else a for a, b in AB if a == 1 or b == 1)
if any(a in cands and b == n or b in cands and a == n for a, b in AB):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
Problem p03651 (python)

Fixed submission:
def gcd(a, b):
  if a > b:
    a, b = b, a
  while a % b != 0:
    a, b = b, a % b
  return b

n, k = map(int, input().split())
A = list(map(int, input().split()))

g = A[0]
for i in range(1, n):
  g = gcd(g, A[i])

if k in A or max(A) > k and k % g == 0:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
  if a > b:
    a, b = b, a
  while a % b != 0:
    a, b = b, a % b
  return b

n, k = map(int, input().split())
A = list(map(int, input().split()))

l = A.pop()
for a in A:
  l = gcd(l, a)

print('POSSIBLE' if k % l == 0 and max(A) >= k else 'IMPOSSIBLE')
Problem p03680 (python)

Fixed submission:
n = int(input())
A = [int(input()) for _ in range(n)]
used = {1}
pos = 1
count = 0
for _ in range(n):
  pos = A[pos - 1]
  count += 1
  if pos in used:
    print(-1)
    break
  used.add(pos)
  if pos == 2:
    print(count)
    break

Buggy submission (verdict: Runtime Error):
n = int(input())
A = [int(input()) for _ in range(n)]
used = {1}
pos = 1
count = 0
for _ in range(n):
  pos = A[pos - 1]
  count += 1
  if pos in used:
    print(-1)
    break
  used.append(pos)
  if pos == 2:
    print(count)
    break
Problem p03695 (python)

Fixed submission:
n = input()
A = list(map(int, input().split()))
flags = [False] * 8
count = 0
for a in A:
  if a < 3200:
    flags[a // 400] = True
  else:
    count += 1
print(max(sum(flags), 1), sum(flags) + count)

Buggy submission (verdict: Runtime Error):
n = input()
A = list(map(int, input().split()))
flags = [0] * 8
count = 0
for a in A:
  if a < 3200:
    flags[a // 400] += True
  else:
    counts += 1
print(sum(flags), sum(flags) + count)
Problem p03715 (python)

Fixed submission:
def solve(h, w):
    if h % 3 == 0 or w % 3 == 0:
        return 0
    if w < h:
        h, w = w, h
    if h == 1:
        return 1
    min_diff = h * w
    vals = [0, 0, 0]
    for i in range(1, w // 2 + 1):
        vals[0] = i * h
        if h % 2 == 0:
            vals[1] = (w - i) * (h // 2)
            vals[2] = vals[1]
        else:
            vals[1] = (w - i) * (h // 2 + 1)
            vals[2] = (w - i) * (h // 2)
        diff = max(vals) - min(vals)
        if diff < min_diff:
            min_diff = diff
        if (w - i) % 2 == 0:
            vals[1] = h * ((w - i) // 2)
            vals[2] = vals[1]
        else:
            vals[1] = h * ((w - i) // 2 + 1)
            vals[2] = h * ((w - i) // 2)
        diff = max(vals) - min(vals)
        if diff < min_diff:
            min_diff = diff
    h, w = w, h
    for i in range(1, w // 2 + 1):
        vals[0] = i * h
        if h % 2 == 0:
            vals[1] = (w - i) * (h // 2)
            vals[2] = vals[1]
        else:
            vals[1] = (w - i) * (h // 2 + 1)
            vals[2] = (w - i) * (h // 2)
        diff = max(vals) - min(vals)
        if diff < min_diff:
            min_diff = diff
        if (w - i) % 2 == 0:
            vals[1] = h * ((w - i) // 2)
            vals[2] = vals[1]
        else:
            vals[1] = h * ((w - i) // 2 + 1)
            vals[2] = h * ((w - i) // 2)
        diff = max(vals) - min(vals)
        if diff < min_diff:
            min_diff = diff
    return min_diff

_h, _w = map(int, input().split())
print(solve(_h, _w))

Buggy submission (verdict: Runtime Error):
def solve(h, w):
    if h % 3 == 0 or w % 3 == 0:
        return 0
    if h == 1 or w == 1:
        return 1
    min_diff = h * w
    vals = [0, 0, 0]
    def f(a, b):
        for i in range(1, a // 2 + 1):
            vals[0] = i * b
            vals[1] = (a - i) * (b // 2 + b % 2)
            vals[2] = (a - i) * (b // 2)
            diff = max(vals) - min(vals)
            if diff < min_diff:
                min_diff = diff
            vals[1] = b * ((a - i) // 2 + (a - i) % 2)
            vals[2] = b * ((a - i) // 2)
            diff = max(vals) - min(vals)
            if diff < min_diff:
                min_diff = diff
    f(h, w)
    f(w, h)
    return min_diff

_h, _w = map(int, input().split())
print(solve(_h, _w))
Problem p02683 (python)

Fixed submission:
import numpy as np
import itertools

def check():
    N,M,X = map(int, input().split())
    A = np.array([[int(i) for i in input().split()] for _ in range(N)])
    total = np.sum(A,axis=0)
    flag = True if all((a>=X  for a in total[1:])) else False
    ans = total[0]

    if flag:
        for i in range(1,N+1):
            for v in itertools.combinations([i for i in range(N)], i):
                B = np.array([A[j] for j in v])
                total2 = np.sum(B, axis=0)
                sabun = total-total2
                if all(a>=X for a in sabun[1:]):
                    ans = min(ans, sabun[0])
    print(ans if flag else -1)
    
check()

Buggy submission (verdict: Runtime Error):
N,M,X = map(int, input().split())
A = np.array([[int(i) for i in input().split()] for _ in range(N)])
total = np.sum(A,axis=0)
flag = True if all((a>=X  for a in total[1:])) else False
ans = total[0]

if flag:
    for i in range(1,N+1):
        for v in itertools.combinations([i for i in range(N)], i):
            B = np.array([A[j] for j in v])
            total2 = np.sum(B, axis=0)
            sabun = total-total2
            if all(a>=X for a in sabun[1:]):
                ans = min(ans, sabun[0])
print(ans if flag else -1)
Problem p02684 (python)

Fixed submission:
from collections import defaultdict

N,K = map(int, input().split())
A = [int(i) for i in input().split()]
used_dict = defaultdict(int)
used_dict[0] += 1
now_town = 0
flag = False

for i in range(min(N,K)):
    now_town = A[now_town]-1
    if used_dict[now_town]:
        used_dict[now_town] += 1
        break
    used_dict[now_town] += 1
else:
    flag = True

if not flag:
    now_town2 = 0
    cnt = 0
    while 1:
        if now_town2 == now_town:
            for _ in range((K-cnt)%(i-cnt+1)):
                now_town = A[now_town]-1
            break
        now_town2 = A[now_town2]-1
        cnt += 1
print(now_town+1)

Buggy submission (verdict: Runtime Error):
N,K = map(int, input().split())
A = [int(i) for i in input().split()]
used = [0]
now_town = 0
flag = False

for i,_ in enumerate(range(K)):
    now_town = A[now_town]-1
    if now_town in used:
        break        
    used.append(now_town)
else:
    flag = True

roop_first = used.index(now_town)
ans_index = (K-roop_first)%(i-roop_first+1)

print(now_town+1 if flag else used[roop_first:][ans_index]+1)
Problem p02761 (python)

Fixed submission:
def check():
    N, M = map(int, input().split())
    keta = ['?']*N
    
    for _ in range(M):
        s, c = map(int, input().split())      
        if keta[s-1] == '?' or keta[s-1] == c:
            keta[s-1] = c
        else:
            return -1
    if keta[0] == 0 and N !=1:
        return -1
    
    keta = [0 if num == '?' else num for num in keta]
    
    if N == 1:
        return keta[0]
    
    keta = [1 if i==0 and num==0 else num for i,num in enumerate(keta)]
    
    return ''.join(map(str, keta))
  
print(check())

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
keta = ['?']*N

for _ in range(M):
    s, c = map(int, input().split())        
    if keta[s-1] == '?' or keta[s-1] == c:
        keta[s-1] = c
    else:
        return -1
if keta[0] == 0:
    return -1

keta = [0 if num == '?' else num for num in keta]

print(''.join(map(str, keta)))
Problem p02768 (python)

Fixed submission:
def pow_self(x,n):
    ans = 1
    while n>0:
        if n&1 == 1:
            ans = (ans*x)%(10**9+7)
            
        x = (x*x)%(10**9+7)
        n >>= 1
    return ans

  
n,a,b = map(int, input().split())        
X,Y = 1,1
for i in range(b):
    X *= n-i
    X %= 10**9+7
    Y *= i+1
    Y %= 10**9+7

    if a-1 == i:
        Xa,Ya = X,Y

comb_a = (Xa*pow_self(Ya,10**9+5))%(10**9+7)
comb_b = (X*pow_self(Y,10**9+5))%(10**9+7)

result = pow_self(2,n)-1-comb_a-comb_b
while result <0:
    result += 10**9+7
print(result)

Buggy submission (verdict: Runtime Error):
n,a,b = map(int, input().split())
if n/2 < a: a=n-a
if n/2 < b: b=n-b
total, combination = 0,1

for i in range(1,(n-1)//2+1):
    combination = combination*(n-i+1)/i
    total += combination
    if a == i: a_cnt = combination
    if b == i: b_cnt = combination
        
    total = total%(10**9+7)

if n == 2:
    print(0)
elif n%2==0:
    answer = total*2+combination*(n-i)/(i+1)-a_cnt-b_cnt+1
    print(answer%(10**9+7))
else:
    answer = total*2-a_cnt-b_cnt+1
    print(answer%(10**9+7))

Buggy submission (verdict: Runtime Error):
n,a,b = map(int, input().split())
if n/2 < a: a=n-a
if n/2 < b: b=n-b
total, combination = 0,1

for i in range(1,(n-1)//2+1):
    combination = combination*(n-i+1)/i
    total += combination
    if a == i: a_cnt = combination
    if b == i: b_cnt = combination
        
    total = total%(10**9+7)

if n%2==0:
    print(total*2+combination*(n-i)/(i+1)-a_cnt-b_cnt+1)
else:
    print(total*2-a_cnt-b_cnt+1)
Problem p02917 (python)

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

total = B[0]
for i in range(N-2):
    total += min(B[i],B[i+1])
total += B[N-2]

print(total)

Buggy submission (verdict: Runtime Error):
def check():
    N = int(input())
    B = [int(i) for i in input().split(' ')]

    total = B[0]
    for i in range(N):
        total += B[i]
    print(total)

check()
Problem p02924 (python)

Fixed submission:
N = int(input())
print(N*(N-1)//2)

Buggy submission (verdict: Runtime Error):
N = long(input())

print(long(N*(N-1)*0.5))
Problem p03220 (python)

Fixed submission:
N = int(input())
T,A = [int(i) for i in input().split(' ')]
H = [int(i) for i in input().split(' ')]
minTemp = 600

for i,h in enumerate(H):
    temp = T - h * 0.006
    if abs(temp-A) < minTemp:
        minTemp = abs(temp-A)
        place = i+1
print(place)

Buggy submission (verdict: Runtime Error):
    N = int(input())
    T,A = [int(i) for i in input().split(' ')]
    H = [int(i) for i in input().split(' ')]
    minTemp = 600
    
    for i,h in enumerate(H):
        temp = T - h * 0.006
        if abs(temp-A) < minTemp:
            minTemp = abs(temp-A)
            place = i+1
    print(place)
Problem p03231 (python)

Fixed submission:
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def check():
    N, M = map(int, input().split())
    S = input()
    T = input()
    length = lcm(N,M)
        
    for i in [a*(length//N) for a in range(N)]:
        if i%(length//M)==0:
            if S[i//(length//N)] != T[i//(length//M)]:
                return -1
    return length
  
print(check())

Buggy submission (verdict: Runtime Error):
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


N, M = map(int, input().split())
S = input()
T = input()
length = lcm(N,M)
    
for i in range(length):
    if i%(length//N)==0 and i%(length//M)==0:
        if S[i//(length//N)] != T[i//(length//M)]:
            return -1
return length