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

Fixed submission:
import sys

N, M = map(int, input().split())
x = sorted(map(int, input().split()))

if N >= M:
    print(0)
    sys.exit()
diff = [0]*(M-1)
for i in range(M-1):
    diff[i] = x[i+1] - x[i]
diff.sort()
ans = sum(diff[:M-N])
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
x = sorted([int(x) for x in input().split()])

diff = sorted([i - j for i, j in zip(x[1:], x[:-1])], reverse=True)
diff0 = diff[:N-1]
diff1 = set(diff[:N-1])


if N >= M:
    print(0)
elif N == 1:
    print(max(x)-min(x))
else:
    j = 0
    ans = 0
    for i in range(M-1):
        a = x[i+1] - x[i]
        if a in diff1 and len(diff0) != 0:
            if i - j >= 1:
                ans += x[i] - x[j]
            diff0.remove(a)
            j = i+1
            if len(diff0) == 0:
                ans += x[-1] - x[i+1]
                break
    print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
x = sorted([int(x) for x in input().split()])

diff = sorted([i - j for i, j in zip(x[1:], x[:-1])], reverse=True)
diff0 = diff[:N-1]
diff1 = set(diff[:N-1])


if N == 1:
    print(max(x)-min(x))
else:
    j = 0
    ans = 0
    for i in range(M-1):
        a = x[i+1] - x[i]
        if a in diff1 and len(diff0) != 0:
            if i - j >= 1:
                ans += x[i] - x[j]
            diff0.remove(a)
            j = i+1
            if len(diff0) == 0:
                ans += x[-1] - x[i+1]
                break
    print(ans)
Problem p03295 (python)

Fixed submission:
def IslandsWar():
    n, m = map(int, input().split())
    a = [list(map(int,input().split())) for _ in range(m)]
    a.sort(key=lambda x: x[1])
    removes = [a[0][1]]

    for i, j in a[1:]:
        check = False
        for k in removes:
            if i < k:
                check = True
                break
        if not check:
            removes.append(j)
    print(len(removes))
            
if __name__ == "__main__":
    IslandsWar()

Buggy submission (verdict: Runtime Error):
def IslandsWar():
    n, m = map(int, input().split())
    a = [0 for _ in range(n-1)]
    INF = float('INF')
    for _ in range(m):
        x, y = map(int, input().split())
        for i in range(x-1, y-1):
            if abs(x-y) == 1:
                a[i] = INF
            else:
                a[i] += 1

    ans =  0
    count = 0
    status = False
    for i in range(n-2):
        if a[i] == INF:
            ans += 1
        elif a[i] < a[i+1]:
            status = True
        elif a[i] > a[i+1] and status:
            ans += 1
            count = 0
            status = False
        elif a[i] == a[i+1]:
            count += 1
        else:
            if count != 0:
                ans += 1
            count = 0
    if count != 0:
        ans += 1
    if a[-2] < a[-1]:
        ans += 1
    if a[-1] == INF:
        ans += 1
    print(ans)
            
if __name__ == "__main__":
    IslandsWar()
Problem p03329 (python)

Fixed submission:
n = int(input())
index6, index9, num6, num9 = 0, 0, 0, 0
INF = float('inf')    
a = [INF for _ in range(n+1)]
a[n] = 0

for i in range(n, -1, -1):
    if a[i] == INF:
        continue
    j = 1
    while i-9**j >= 0:
        a[i-9**j] = min(a[i]+1, a[i-9**j])
        j += 1
    j = 1
    while i-6**j >= 0:
        a[i-6**j] = min(a[i]+1, a[i-6**j])
        j += 1
    if i-1 >= 0:
        a[i-1] = min(a[i]+1, a[i-1])
print(a[0])

Buggy submission (verdict: Runtime Error):
n = int(input())
ans, index6, index9, num6, num9 = 0, 0, 0, 0, 0
INF = float('inf')

def a10_to_n(x, n):
    if x//n:
        return a10_to_n(x//n, n)+str(x%n)
    else:
        return str(x)

def index(n, num6, index6, num9, index9):
    val = str(a10_to_n(n, 6))
    for i, j in enumerate(val):
        if int(j) != 0:
            num6 = int(j)
            index6 = len(val)-i-1
            break
    val = str(a10_to_n(n, 9))
    for i, j in enumerate(val):
        if int(j) != 0:
            num9 = int(j)
            index9 = len(val)-i-1
            break
    return num6, index6, num9, index9

num6, index6, num9, index9 = index(n, num6, index6, num9, index9)
while index6 > 1 or index9 > 1:
    if 6**index6 <= 9**index9:
        n -= num9*9**index9
        ans += num9
    else:
        n -= num6*6**index6
        ans += num6
    num6, index6, num9, index9 = index(n, num6, index6, num9, index9)
    
a = [INF for _ in range(n+1)]
a[n] = 0
for i in range(n, -1, -1):
    if i-9 >= 0:
        a[i-9] = min(a[i]+1, a[i-9])
    if i-6 >= 0:
        a[i-6] = min(a[i]+1, a[i-6])
    if i-1 >= 0:
        a[i-1] = min(a[i]+1, a[i-1])
print(ans+a[0])
Problem p02693 (python)

Fixed submission:
import sys

K = int(input())
A,B = map(int, sys.stdin.readline().strip().split())

if A % K:
    i = (A // K) + 1
    ans = A <= (i * K) <= B
else:
    ans = A <= B

if ans:
    print('OK')
else:
    print('NG')

Buggy submission (verdict: Runtime Error):
K = int(input())
A,B = map(int, sys.stdin.readline().strip().split())

if B < K:
    print('NG')
    sys.exit()

if int(A + K - 1 / K) <= B:
    print('OK')
else:
    print('NG')
Problem p03137 (python)

Fixed submission:
import sys

# N: コマ数
# M: 地点数

N,M,*X = map(int, open(0).read().split())

# コマ数が地点数以上の場合、各地点にコマを配置できる
# よって 0 回の移動で目的を達成できる
if N >= M:
    print(0)
    sys.exit()

X.sort()
ans = []
for i in range(M-1):
    ans.append(abs(X[i+1] - X[i]))

ans.sort(reverse=True)
print(X[-1] - X[0] - sum(ans[:N-1]))

Buggy submission (verdict: Runtime Error):
import sys

# N: コマ数
# M: 地点数

# N,M,*X = map(int, open(0).read().split())

# コマ数が地点数以上の場合、各地点にコマを配置できる
# よって 0 回の移動で目的を達成できる
if N >= M:
    print(0)
    sys.exit()

X.sort()
ans = []
for i in range(M-1):
    ans.append(abs(X[i+1] - X[i]))

print(X[-1] - X[0] - sum(sorted(ans)[::-1][:N-1]))

Buggy submission (verdict: Runtime Error):
N,M,*X = map(int, open(0).read().split())

X.sort()

ans = []
for i in range(len(X)-1):
    ans.append(abs(X[i+1] - X[i]))

if len(ans) == 0:
    print(0)
    sys.exit()

ans.sort()
print(sum(ans[:-(N-1)]))

Buggy submission (verdict: Runtime Error):
import sys
N,M,*X = map(int, open(0).read().split())

X.sort()

ans = []
for i in range(len(X)-1):
    ans.append(abs(X[i+1] - X[i]))

if len(ans) == 0:
    print(0)
    sys.exit()

ans.sort()
for _ in range(N-1):
    ans.pop()

print(sum(ans))
Problem p02629 (python)

Fixed submission:
N = int(input())

s = ""
for i in range(12):
    if 26*(26**i-1)/25 < N and N <= 26*(26**(i+1)-1)/25:
        t = i#桁数-1
        break

#print(t + 1)
N = int(N - 26*(26**t-1)/25 - 1)

a = [0] * (t + 1)

for i in range(t + 1):
    a[t - i] = N%26
    N = N //26

#print(a)

for i in range(0, len(a)):
    a[i] = chr(97+int(a[i]))
    s += a[i]

#s += chr(97+a[len(a)-1])

print(s)

Buggy submission (verdict: Runtime Error):
N = int(input())
N = N - 1
#N = 100
a = []
s = ""

while N != 0:
    a.insert(0, N % 26)
    N = N //26

#print(a)

for i in range(0, len(a)-1):
    a[i] = chr(96+a[i])
    s += a[i]

s += chr(97+a[len(a)-1])

print(s)
Problem p03038 (python)

Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
bc = [0] * M
for i in range(M):
    bc[i] = list(map(int, input().split()))

bc = sorted(bc, key= lambda x: x[1], reverse=True)

n = 0
f = 0
for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1]:
            A[n] = bc[i][1]
            n += 1
            if n == N:
                f = 1
                break
        else:
            f = 1
    if f == 1:
        break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
bc = [0] * M
for i in range(M):
    bc[i] = list(map(int, input().split()))

bc = sorted(bc, key= lambda x: x[1])[::-1]

n = 0
f = 0
for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1] and n < N:
            A[n] = bc[i][1]
            n += 1
        else:
            f == 1
    if f == 1:
        break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
bc = [0] * M
for i in range(M):
    bc[i] = list(map(int, input().split()))

bc = sorted(bc, key= lambda x: x[1])[::-1]

n = 0
f = 0
for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1] and n < N:
            A[n] = bc[i][1]
            n += 1
        else:
            f == 1
    if f == 1:
        break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
bc = [0] * M
for i in range(M):
    bc[i] = list(map(int, input().split()))

bc = sorted(bc, key= lambda x: x[1])[::-1]

n = 0
f = 0
for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1]:
            A[n] = bc[i][1]
            n += 1
        else:
            f == 1
    if f == 1:
        break

print(sum(A))
Problem p02623 (python)

Fixed submission:
N,M,K = map(int,input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
AA = [0]
BB = [0]
r = 0
for i in A:
    r += i
    AA.append(r)
r = 0
for i in B:
    r += i
    BB.append(r)
ans = 0
a = N
b = 0
while AA[a]+BB[b] > K:
    a -= 1
ans = a+b

while a >= 0:
    while b < M:
        if AA[a]+BB[b+1] <= K:
            b += 1
        else:
            break
    if ans < a+b:
        ans = a+b
    if b == M:
        break
    a -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
M,N,K = map(int,input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
m = 0
c = 0
while True:
    if len(A) == 0:
        r = B.pop(0)
    elif len(B) == 0:
        r = A.Pop(0)
    elif A[0] > B[0]:
        r = B.pop(0)
    else:
        r = A.pop(0)
    if m+r > K:
        break
    c += 1
    m += r
    if m+r >= K:
        break
print(c)
Problem p03326 (python)

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

dp = []
for i in range(m+1):
    dp.append([0 for j in range(n+1)])

def f(fn):
    global dp, a
    for i in range(1,m+1):
        for j in range(i,n+1):
            if j == i:
                dp[i][j] = sum(map(fn, a[:j]))
            else:
                dp[i][j] = max(dp[i][j-1], dp[i-1][j-1] + fn(a[j-1]))

ans = []
f(lambda x: x[0]+x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: x[0]+x[1]-x[2])
ans.append(dp[m][n])
f(lambda x: x[0]-x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: x[0]-x[1]-x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]+x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]+x[1]-x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]-x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]-x[1]-x[2])
ans.append(dp[m][n])

print(max(ans))

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

memo = {}
def f(a, s, fn):
    global m
    l = len(a)
    if s >= m or l == 0:
        return 0
    if (l,s) in memo:
        return memo[(l,s)]
    elif len(a) == 1:
        ans = max(0, fn(a[0]))
    else:
        ans = max(f(a[1:], s, fn), fn(a[0]) + f(a[1:], s+1, fn))
    memo[(l,s)] = ans
    return ans

ans = []
ans.append(f(a,0, lambda x: x[0]+x[1]+x[2]))
memo.clear()
ans.append(f(a,0, lambda x: x[0]+x[1]-x[2]))
memo.clear()
ans.append(f(a,0, lambda x: x[0]-x[1]+x[2]))
memo.clear()
ans.append(f(a,0, lambda x: x[0]-x[1]-x[2]))
memo.clear()
ans.append(f(a,0, lambda x: -x[0]+x[1]+x[2]))
memo.clear()
ans.append(f(a,0, lambda x: -x[0]+x[1]-x[2]))
memo.clear()
ans.append(f(a,0, lambda x: -x[0]-x[1]+x[2]))
memo.clear()
ans.append(f(a,0, lambda x: -x[0]-x[1]-x[2]))
print(max(ans))

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

memo = {}
def f(a, s, fn):
    global m
    l = len(a)
    if s >= m or l == 0:
        return 0
    if (l,s) in memo:
        return memo[(l,s)]
    elif len(a) == 1:
        return max(0, fn(a[0]))
    else:
        return max(f(a[1:], s, fn), fn(a[0]) + f(a[1:], s+1, fn))

ans = []
ans.append(f(a,0, lambda x: x[0]+x[1]+x[2]))
memo.clear()
ans.append(f(a,0, lambda x: x[0]+x[1]-x[2]))
memo.clear()
ans.append(f(a,0, lambda x: x[0]-x[1]+x[2]))
memo.clear()
ans.append(f(a,0, lambda x: x[0]-x[1]-x[2]))
memo.clear()
ans.append(f(a,0, lambda x: -x[0]+x[1]+x[2]))
memo.clear()
ans.append(f(a,0, lambda x: -x[0]+x[1]-x[2]))
memo.clear()
ans.append(f(a,0, lambda x: -x[0]-x[1]+x[2]))
memo.clear()
ans.append(f(a,0, lambda x: -x[0]-x[1]-x[2]))
memo.clear()
print(max(ans))
Problem p02546 (python)

Fixed submission:
S = input()
if S[-1] == 's':
    a = S+'es'
else:
    a = S+'s'
print(a)

Buggy submission (verdict: Runtime Error):
n, x, m = map(int, input().split())
a = x
s = 0
h = []
h.append(a)
i = 0
fl = 0
while i < n:
    s += a
    a = (a*a) % m
    if a == 0:
      break
    i += 1
    if fl == 0 and a in h:
      fl = 1
      po = h.index(a)
      ss = 0
      for j in range(po):
        ss += h[j]
      s2 = s - ss
      f = (n - po) // (i - po)
      s2 *= f
      s = s2 + ss
      i2 = i - po
      i2 *= f
      i = i2 + po
    else:
      h.append(a)
print(s)
Problem p02577 (python)

Fixed submission:
n = str(input())
a = int(0)
for i in range(len(n)):
    a = a + int(n[i])
if a % 9 == 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
a = 0
while True:
  while n > 0:
    a = a + (n % 10)
    n = int(n / 10)
  if a < 10:
      break
  n = a
  a = 0
if a == 9:
    print("Yes")
else:
    print("No")
Problem p02571 (python)

Fixed submission:
s = input()
t = input()

len_s = len(s)
len_t = len(t)

ans = 1000
max_cnt = 0
for i in range(len_s - len_t + 1):
    cnt = 0
    l = []
    for j in range(len_t):
        if s[i : i + len_t][j] == t[j]:
            cnt += 1
        if s[i : i + len_t][j] != t[j]:
            cnt += 0
    max_cnt = max(max_cnt, cnt)

ans = min(ans, len_t - max_cnt)

print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()

len_s = len(s)
len_t = len(t)

ans = 1000
for i in range(len_s - len_t + 1):
    cnt = 0
    l = []
    for j in range(len_t):
        if s[i + j] == t[j]:
            cnt += 1
        else:
            l.append(cnt)
            cnt = 0

    ans = min(ans, len_t - max(l))

print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()

len_s = len(s)
len_t = len(t)

ans = 1000
for i in range(len_s - len_t):
    cnt = 0
    l = []
    for j in range(len_t):
        if s[i + j] == t[j]:
            cnt += 1
        else:
            l.append(cnt)
            cnt = 0

    ans = min(ans, len_t - max(l))

print(ans)
Problem p02572 (python)

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

sum_sq_a = 0
for i in range(n):
    sum_sq_a += a[i]**2

ans = ((sum(a))**2 - sum_sq_a) // 2

print(ans % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())), dtype = 'object')
mod = 10**9 + 7

sq_sum_a = sum(a)**2
sum_sq_a = sum(a**2)

sum_cross = (sq_sum_a - sum_sq_a) // 2
ans = sum_cross % mod
# xy = ((x + y)**2 - (x**2 + y**2)) // 2

print(ans)

Buggy submission (verdict: Runtime Error):
import itertools as it

n = int(input())
a = list(map(int, input().split()))

c = list(it.combinations(a, 2))

ans = 0
for i in range(n):
    ans += int(c[i][0]) * int(c[i][1])

print(ans % (10**9 + 7))
Problem p02689 (python)

Fixed submission:
n, m = map(int, input().split())
h = list(map(int, input().split()))
l = []
for _ in range(m):
  l.append(list(map(int, input().split())))

bad = []
for i in range(m):
  if h[l[i][0] - 1] > h[l[i][1] - 1]:
    bad.append(l[i][1])
  elif h[l[i][0] - 1] < h[l[i][1] - 1]:
    bad.append(l[i][0])
  else:
    bad.append(l[i][0])
    bad.append(l[i][1])

print(n - len(set(bad)))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
H=list(map(int,input().split()))
P=[]
for i in range(M):
    P.append(list(map(int,input().split()))) #2次元配列、P[A_i,B_i]

ans=[]

for i in range(M):
    if H[P[i][0]-1]>H[P[i][1]-1]:   #H[A_i]>H[B_i]ならばA_iを加える
        ans.append([P[i][0])
    elif H[P[i][0]-1]<H[P[i][1]-1]: #H[A_i]<H[B_i]ならばB_iを加える
        ans.append(P[i][1])       
    else:                           #H[A_i]=H[B_i]ならば何もしない
        continue                    
    
list=[]

for j in range(M): 
    list+=P[j]

print(len(set(ans))+N-len(set(list)))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
H=list(map(int,input().split()))
P=[]
for i in range(M):
    P.append(list(map(int,input().split())))

ans=[]

for i in range(M):
  if H[P[i][0]-1]>H[P[i][1]-1]:
    ans.append(H[P[i][0]])
  elif H[P[i][0]-1]<H[P[i][1]-1]:
    ans.append(H[P[i][1]-1])
  else:
    continue
    
list=[]

for j in range(M): 
    list+=P[j]

print(len(set(ans))+N-len(set(list)))
Problem p02693 (python)

Fixed submission:
k=int(input())
a,b=map(int,input().split())

for i in range(1,1001):
  n=k*i
  if a<=n<=b:
    print('OK')
    exit()
  else:
    continue

print('NG')

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

for i in range(1,1001):
  n==k*i
  if a<=n<=b:
    print('OK')
    exit()
  else:
    continue

print('NG')
Problem p02754 (python)

Fixed submission:
n, a, b = map(int, input().split())

if a == 0:
    print(0)
elif n >= a + b:
    if n % (a + b) <= a:
        print(a * (n // (a + b)) + (n % (a + b)))
    else:
        print(a * (n // (a + b)) + a)
        
else:
    if n < a:
        print(n)
    else:
        print(a)

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

red = [0] * a
blue = [1] * b
l = []

while len(l) < n:
    l += red
    l += blue
m = l[:n]
print(m.count(0))
Problem p02935 (python)

Fixed submission:
n = int(input())
v = sorted(map(int, input().split()))

ans = v[0]

for i in range(1, n):
    ans = (ans + v[i]) / 2

print(ans)

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

ans = v[0]

for i in range(1, N):
    ans = (ans + v[i]) / 2

print(ans)
Problem p03775 (python)

Fixed submission:
N=int(input())
ans=float('inf')

for i in range(1,int(N**0.5+1)):
    if N%i==0:
        ans=min(ans,len(str(N//i)))
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
ans=float('inf')

for i in range(1,N**0.5+1):
    if N%i==0:
        ans=min(ans,len(str(N//i)))
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
f=[]
for i in range(1,(N+1)//2):
    if N%i==0:
        f.append(max(len(str(i)),len(str(N//i))))
print(min(f))

Buggy submission (verdict: Runtime Error):
N=int(input())
f=[]
for i in range(1,(N+1)//2):
    if N%i==0:
        f.append(min(len(str(i)),len(str(N//i))))
print(max(f))

Buggy submission (verdict: Runtime Error):
N=int(input())
f=[]
for i in range(1,(N+1)//2):
    if N%i==0:
        f.append(min(len(str(i)),len(str(N//i))))
max(f)
Problem p02552 (python)

Fixed submission:
x = int(input())

if(x == 0):
    print('1')
elif(x == 1):
    print('0')
else:
    pass

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

if(x == 0):
    print('1')
elif(x == 1):
    print('0')
else:
Problem p02777 (python)

Fixed submission:
S, T = map(str,input().split())
A, B = map(int,input().split())
U = str(input())

if(S == U):
    A -= 1
elif(T == U):
    B -= 1
else:
    A
    B
    
print("{} {}".format(A, B))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = []
A = input().split()
ans = 1

for x in range(N):
    for y in range(N):
        if(x == y):
            continue
        if(A[x] == A[y]):
            ans = 0
            break

if(ans == 1):
    print("YES")
else:
    print("NO")
Problem p03013 (python)

Fixed submission:
N, M = map(int, raw_input().split())
S = [True]*(N+1)
for _ in range(M):
  a = input()
  S[a] = False
T = [0]*(N+1)
T[0] = 1
T[1] = 1 if S[1] else 0
for i in range(2, N+1):
  if S[i]:
    T[i] = (T[i-1]+T[i-2])%1000000007
print T[N]

Buggy submission (verdict: Runtime Error):
N, M = map(int, raw_input().split())
S = [True]*(N+1)
for _ in range(M):
  a = input()
  S[a] = False
T = [0]*(N+1)
T[0] = 1
T[1] = 1 if S[1] else 0
for i in range(2, N+1):
  if S[i]:
    T[i] = (T[i-1]+T[i-2])%1000000007
print(T[N])
Problem p03209 (python)

Fixed submission:
N,X = map(int, raw_input().split())
A = [0]*N
B = [0]*N
A[0] = 1
B[0] = 1
for i in range(1,N):
  A[i] = 2*A[i-1]+3
  B[i] = 2*B[i-1]+1

def f(N,X):
  if N==0:
    return 1
  if X<=1:
    return 0
  if X<=1+A[N-1]:
    return f(N-1, X-1)
  if X<=1+A[N-1]+1:
    return B[N-1]+1
  if X<=1+A[N-1]+1+A[N-1]:
    return B[N-1]+1+f(N-1, X-2-A[N-1])
  if X<=1+A[N-1]+1+A[N-1]+1:
    return 2*B[N-1]+1
  print N,X

print f(N,X)

Buggy submission (verdict: Runtime Error):
N,X = map(int, raw_input().split())
A = [0]*N
B = [0]*N
A[0] = 1
B[0] = 1
for i in range(1,N):
  A[i] = 2*A[i-1]+3
  B[i] = 2*B[i-1]+1

def f(N,X):
  if N==0:
    return 1
  if X<=1:
    return 0
  if X<=1+A[N-1]:
    return f(N-1, X-1)
  if X<=1+A[N-1]+1:
    return B[N-1]+1
  if X<=1+A[N-1]+1+A[N-1]:
    return B[N-1]+1+f(N-1, X-2-A[N-1])
  if X<=1+A[N-1]+1+A[N-1]<=1:
    return 2*B[N-1]+1
  print N,X

print f(N,X)
Problem p03232 (python)

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

"""
import itertools

ans = 0
for p in itertools.permutations(range(N)):
  F = [True]*N
  for i in range(N):
    ans += A[p[i]]
    F[p[i]] = False
    t = p[i]-1
    while 0<=t and F[t]:
      ans += A[t]
      t -= 1
    t = p[i]+1
    while t<N and F[t]:
      ans += A[t]
      t += 1
print ans
"""

if N==1:
  print A[0]
  exit(0)

M = 10**9+7

F = [0]*(N+1)
F[0] = 1
for i in range(1,N+1):
  F[i] = F[i-1]*i%M

R = [0]*(N+1)
for i in range(1,N+1):
  R[i] = pow(i, M-2, M)

T = [F[N]]*N
for i in range(N):
  T[i] = T[i]*R[i+1]%M

ans = 0
x = sum(T)
for i in range((N+1)/2):
  ans += (A[i] + (A[N-i-1] if N-i-1!=i else 0))*x
  ans %= M
  x -= T[-i-1]
  x += T[i+1]
  x %= M
print ans

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

"""
import itertools

ans = 0
for p in itertools.permutations(range(N)):
  F = [True]*N
  for i in range(N):
    ans += A[p[i]]
    F[p[i]] = False
    t = p[i]-1
    while 0<=t and F[t]:
      ans += A[t]
      t -= 1
    t = p[i]+1
    while t<N and F[t]:
      ans += A[t]
      t += 1
print ans
"""

M = 10**9+7

F = [0]*(N+1)
F[0] = 1
for i in range(1,N+1):
  F[i] = F[i-1]*i%M

R = [0]*(N+1)
for i in range(1,N+1):
  R[i] = pow(i, M-2, M)

T = [F[N]]*N
for i in range(N):
  T[i] = T[i]*R[i+1]%M

ans = 0
x = sum(T)
for i in range((N+1)/2):
  ans += (A[i] + (A[N-i-1] if N-i-1!=i else 0))*x
  ans %= M
  x -= T[-i-1]
  x += T[i+1]
  x %= M
print ans
Problem p02572 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
zenbu = sum(a)
ans = 0

for i in range(n):
  ans += a[i]*(zenbu-a[i])
 
print(ans // 2 % 1000000007)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = list(map(int, input().split()))
zenbu = sum(a)
ans = 0

for i in range(n):
  ans += a[i]*(zenbu-a[i])
 
print(ans // 2 % (1000000000+7))
Problem p02659 (python)

Fixed submission:
A,B = input().split()
iA = int(A)
iB = int(float(B) * 100 + 0.5)

ans = (iA * iB) // 100
print(ans)

Buggy submission (verdict: Runtime Error):
import math

A,B = input().split()
iA = int(A)
fB = float(B)
iB = math.floor(fB)
fB100 = math.floor(fB*100 - iB*100)

ans = iA * iB
ans += (fB100 * iA) // 100
print(ans

Buggy submission (verdict: Runtime Error):
A,B = input().split()
iA = int(A)
iB = int(B)
fB100 = int(float(B)*100 - iB*100)

ans = iA * iB
ans += (fB100 * iA) // 100
print(ans)