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

Fixed submission:
import sys
input()
A = list(map(int, input().split()))
ans = 1

if 0 in A:
    print(0)
    sys.exit()

else:
    for a in A:
        ans *= a
        if ans > 10**18:
            print(-1)
            sys.exit()
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input()
A = list(map(int, input().split()))
ans = 1

if 0 in A:
    print(0)
    sys.exit()

else
    for a in A:
        ans *= a
        if ans > 10**18
        print(-1)
        sys.exit()
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input()
A = list(map(int, input().split()))
ans = 1

if 0 in A:
    print(0)
    sys.exit()

else
    for a in map(int, input().split()):
        ans *= a
        if ans > 10**18
        print(-1)
        sys.exit()
    print(ans)
Problem p02660 (python)

Fixed submission:
from collections import Counter
import math

def div(n):
    prime = []
    tmp = int(math.sqrt(n)) + 1
    
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            prime.append(num)
    
    if n != 1:
        prime.append(n)
    return prime

n = int(input())
prime_div = Counter(div(n))
ans = 0

for p, ex in prime_div.items():
    k = 1
    while ex >= k:
        ex -= k
        ans += 1
        k += 1

print(ans)

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

def div(n):
    if n == 1:
        return []
    prime = []
    tmp = int(math.sqrt(n)) + 1
    
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            prime.append(num)
    
    if len(prime) == 0:
        return [1]
    else:
        return prime

n = int(input())
prime_div = dict(Counter(div(n)))
ans = 0
divs = list(prime_div.values())

for i in range(len(divs)):
    k = 0
    for j in range(1, 10):
        k += j
        if k > divs[i]:
            tmp = divs[i] - k + j
            break
        ans += 1

theta = 0
for i in range(1, 10):
    theta += i 
    if theta >= tmp:
        break
    ans += 1

print(ans)
Problem p02678 (python)

Fixed submission:
import sys
from collections import deque

N, M = map(int, input().split())
G = [[] for _ in range(N)]
goal = False

for _ in range(M):
    A, B = map(int, input().split())
    G[A - 1].append(B - 1)
    G[B - 1].append(A - 1)
    if A == 1 or B == 1:
        goal = True

if goal:
    print("Yes")
else:
    print("No")
    sys.exit()

d = deque([0])
ans = [-1] * N

while d:
     q = d.popleft()
     for g in G[q]:
         if ans[g] == -1:
             ans[g] = q + 1
             d.append(g)

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

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

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

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

N, M = MI()
room = [[] for _ in range(N)]

for _ in range(M):
    A, B = MI()
    room[A - 1].append(B - 1)
    room[B - 1].append(A - 1)

print(room)
print("Yes")

def bfs(G, start, step = 0):
    global visited
    visited[start] = True 
    
    for g in G[start]:
        if g == 0:
            print(step + 1)
            
        elif not visited[g]:
            bfs(G, g, step + 1)

for i in range(1, N):
    visited = [False] * N
    bfs(room, i)
Problem p02713 (python)

Fixed submission:
from collections import deque
from functools import reduce
from math import gcd

def gcd3(*numbers):
    return reduce(gcd, numbers)

K = int(input())
ans = 0

for _ in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans += gcd3(_, b, c)
print(ans)

Buggy submission (verdict: Runtime Error):
def main():
    from collections import deque
    from functools import reduce
    from math import gcd

    def gcd3(*numbers):
        return reduce(gcd, numbers)

    K = int(input())
    ans = 0

    for _ in range(1, K + 1):
        for _ in range(1, K + 1):
            for _ in range(1, K + 1):
                ans += gcd3(_, b, c)
    print(ans)

if __name__ == "__main__":
    main()
Problem p02756 (python)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
is_reversed = 1
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        is_reversed *= -1
    
    else:
        if is_reversed == 1:
            if query[1] == "1":
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if query[1] == "2":
                S.appendleft(query[2])
            else:
                S.append(query[2])

S = "".join(S)
print(S[::is_reversed])

Buggy submission (verdict: Runtime Error):
def main():
    from collections import deque
    S = input()
    Q = int(input())

    for _ in range(Q):
        query = deque(input().split())
        if query[0] == "1":
            S.reverse()
        elif query[1] == "1":
            S = query[2] + S
        elif query[1] == "2":
            S = S + query[2]

    print("".join(map(str, S)))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    from collections import deque
    S = input()
    Q = int(input())

    for _ in range(Q):
        query = deque(input().split())
        if query[0] == "1":
            S.reverse()
        elif query[1] == "1":
            S = query[2] + S
        elif query[1] == "2":
            S = S + query[2]

    print("".join(map(str, S)))

if __name__ == "__main__":
    main()
Problem p02761 (python)

Fixed submission:
def INT():
    return int(input())

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

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

import sys

N, M = MI()
ans = ""
num = [[] for _ in range(N)]

for _ in range(M):
    s, c = MI()
    num[s - 1].append(str(c))

    if (N != 1 and (s, c) == (1, 0)) or len(set(num[s - 1])) != 1:
        print(-1)
        sys.exit()

if num[0] == []:
    ans += str(int(N != 1))
else:
    ans += num[0][0]

for n in num[1:]:
    if n == []:
        ans += "0"
        continue
        
    ans += n[0]

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(M)]
s = [sc[i][0] for i in range(M)]
c = [sc[j][1] for j in range(M)]
box = [0] * M
ans = str()
for m in range(M):
    box[s[m] - 1] = c[m]

for k in box:
    ans += str(k)

if box[0] != 0:
    print(int(ans))
else:
    print(-1)
Problem p02783 (python)

Fixed submission:
H, A = map(int, input().split())
if H % A == 0:
    print(H // A)
else:
    print(H // A + 1)

Buggy submission (verdict: Runtime Error):
H, A = map(int, input().split())
if N % A == 0:
    print(H // A)
else:
    print(H // A + 1)
Problem p02899 (python)

Fixed submission:
from collections import deque

N = int(input())
A = list(map(int, input().split()))
A = list(enumerate(A))
A.sort(key = lambda x: x[1])

ans = deque()

for a in A:
    ans.append(a[0] + 1)

print(" ".join(map(str, ans)))

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

N = int(input())
A = list(map(int, input().split()))
B = A.copy()
heapq.heapify(B)
ans = deque()

for i in range(N - 1):
    ans.append(A.index(heapq.heappop(B)) + 1)

print(" ".join(map(str, list(ans) + [A.index(B[0]) + 1])))
Problem p02982 (python)

Fixed submission:
from math import sqrt

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
ans = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        dist = 0
    
        for k in range(D):
            dist += (X[i][k] - X[j][k])**2
        
        if sqrt(dist) % 1 == 0:
            ans += 1
    
print(ans)

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

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

for i in range(N - 1):
    dist = 0
    for j in range(i + 1, N):
        for k in range(D):
            dist += (X[i][k] - X[j][k]) ** 2
        if sqrt(dist) % 1 == 0:
            ans += 1
    
print(ans)
Problem p02983 (python)

Fixed submission:
L, R = map(int, input().split())

L_q = L // 2019
R_q = R // 2019
mod = 2018

if L_q + R_q == 0:
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            mod = min(i * j % 2019, mod)

    print(mod)

else:
    if R_q - L_q > 1:
        print(0)

    else:
        for i in range(L, R):
            for j in range(i + 1, R + 1):
                mod = min(i * j % 2019, mod)

        print(mod)

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())

L_q = L // 2019
R_q = R // 2019
mod = 2018

if L_q + R_q == 0:
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            mod = min(i * j % 2019, mod)

    print(mod)

else:
    if R_q - L_q > 1:
        print(0)

    else:
        for i in range(L, R):
        for j in range(i + 1, R + 1):
            mod = min(i * j % 2019, mod)

    print(mod)
Problem p02995 (python)

Fixed submission:
from fractions import gcd
A, B, C, D = map(int, input().split())
CD = C * D // gcd(C, D)

U = B - A + 1
U_c = (B // C) - (A // C) + int(A % C == 0)
U_d = (B // D) - (A // D) + int(A % D == 0)
U_cd = (B // CD) - (A // CD) + int(A % CD == 0)

ans = U - (U_c + U_d - U_cd)
print(ans)

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

U = B - A + 1
U_c = U // C
U_d = U // D
U_cd = U // (C * D // gcd(C, D))

ans = U - (U_c + U_d - U_cd)
if A % 4 == 0 or B % 4 == 0:
    ans -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())
s = list(range(A, B + 1))
cnt = [-1] * 2 

for i in s:
    if i % C == 0 and cnt[0] == -1:
        cnt[0] = s.index(i)
    if i % D == 0 and cnt[1] == -1:
        cnt[1] = s.index(i)
    if cnt[0] != -1 and cnt[1] != -1:
        break

t = s[cnt[0] :: C]
u = s[cnt[1] :: D]

ans = len(s) - (len(set(t)) + len(set(u)) - len(set(t) & set(u)))
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
A, B, C, D = map(int, input().split())
s = np.array(list(range(A, B + 1)))
s = s[s % C != 0]
t = s[s % D != 0]
s = set(s)
t = set(t)
print(len(s & t))
Problem p03001 (python)

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

is_center = int(x * 2 == W and y * 2 == H)
min_sq = W * H / 2

print("{} {}".format(min_sq, is_center))

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

is_center = if x * 2 == W and y * 2 == H
min_square = W * H / 2

print(min_square, is_center)

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

if W // x == 2 and H // y == 2:
    print("{} {}".format(W * H / 2, 1))
else:
    print("{} {}".format(W * H / 2, 0))

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

area_H = sorted([x * H, (W - x) * H])
area_W = sorted([y * W, (H - y) * W])

area_h = area_H[0]
area_w = area_W[0]

area = sorted([area_h, area_w])
switch = int(area[0] == area[1])

print(f"{float(area[1])} {switch}")

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

area_H = sorted([x * H, (W - x) * H])
area_W = sorted([y * W, (H - y) * W])

area_h = area_H[0]
area_w = area_W[0]

area = sorted([area_h, area_w])
switch = int(area_h == area_w)

print(f"{area[1]} {switch}")
Problem p03086 (python)

Fixed submission:
ans = []
cnt = 0

for s in input():

    if not s in "ACGT":
        ans.append(cnt)
        cnt = 0
        continue
    
    cnt += 1

ans.append(cnt)

print(max(ans) if len(ans) != 0 else 0)

Buggy submission (verdict: Runtime Error):
acgt = list("ACGT")
ans = []
cnt = 0

for s in input():

    if not s in acgt:
        ans.append(cnt)
        continue
    
    cnt += 1

print(max(ans))
Problem p03196 (python)

Fixed submission:
def INT():
    return int(input())

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

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

def factrize(P):
    fac = {}
    
    for i in range(2, int(P**0.5) + 1):
        e = 0
        while P % i == 0:
            P //= i
            e += 1
            
        if e > 0:
            fac[i] = e
    
    if P > 1:
        fac[P] = 1
    
    return fac

N, P = MI()
ans = 1

for f, e in factrize(P).items():
    if e >= N:
        ans *= f**(e // N)
        
print(ans)

Buggy submission (verdict: Runtime Error):
def INT():
    return int(input())

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

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

N, P = MI()
g = 1
mod = 1
ans = 0

while mod <= P:
    mod = pow(g, N)
    
    if P % pow(g, N) == 0:
        ans = max(ans, g)
    
    g += 1
    mod = pow(g, N)
    
print(ans)
Problem p03380 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()
m1 = A[-1]
m2 = m1 // 2 + int(m1 % 2 == 1)
ans = [m1, 0]
tmp = 10**9 + 1

for a in A[:len(A) - 1]:
    if tmp > abs(m2 - a):
        tmp = abs(m2 - a)
        ans[1] = a

print(*ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
m1 = max(A)
m2 = m // 2 + int(m % 2 == 1)
ans = [m1, m2]
tmp = 10000000

for a in A:
    if tmp > abs(m2 - a):
        tmp = abs(m2 - a)
        ans[1] = a

print(*ans)
Problem p03826 (python)

Fixed submission:
def INT():
    return int(input())

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

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

A, B, C, D = MI()

print(max(A * B, C * D))

Buggy submission (verdict: Runtime Error):
A, B, C, D = MI()

print(max(A * B, C * D))
Problem p03323 (python)

Fixed submission:
a,b=map(int,input().split())
if (a<9)&(b<9):
  print("Yay!")
else:
    print(":(")

Buggy submission (verdict: Runtime Error):
a,b=map(int,input.split())
if a<9&&b<9:
  print("Yay!")
  else:
    print(":(")
Problem p04043 (python)

Fixed submission:
a=list(map(int,input().split()))
if sorted(a)==[5,5,7]:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
a=list(map(int,input.split()))
if a.sort==[5,5,7]:
  print("YES")
else:
  print("NO")
Problem p02576 (python)

Fixed submission:
n, x, t = map(int, input().split())

if n % x == 0:
  print(t * (n // x))
else:
  print(t * ((n // x) + 1))

Buggy submission (verdict: Runtime Error):
n, x, t = map(int, input())

if n % x == 0:
  print(t * (n // x))
else:
  print(t * ((n // x) + 1))
Problem p02767 (python)

Fixed submission:
n = int(input())
xs = [int(elem) for elem in input().split()]
 
min_ = min(xs)
max_ = max(xs)
result = []
for p in range(min_, max_+1):
  res = 0
  for x in xs:
    res += (x - p) ** 2
  result.append(res)
print(min(result))

Buggy submission (verdict: Runtime Error):
n = int(input())
xs = [int(elem) for elem in input().split()]

min_ = min(xs)
max_ = max(xs)
result = []
for p in range(min_, max_):
  res = 0
  for x in xs:
    res += (x - p) ** 2
  result.append(res)
print(min(result))
Problem p02780 (python)

Fixed submission:
n, k = [int(elem) for elem in input().split()]
ps = [int(elem) for elem in input().split()]

sum_max = 0
for i in range(k - 1, n):
    if i == k - 1:
        sum_now = sum(ps[:i + 1])
    else:
        sum_now = sum_now + ps[i] - ps[i - k]
    sum_max = max(sum_max, sum_now)
    
print(float(sum_max + k) / 2)

Buggy submission (verdict: Runtime Error):
n, k = [int(elem) for elem in input().split()]
ps = [int(elem) for elem in input().split()]

exs = []
for p in ps:
  exs.append((1.0+p)/2)
res = [sum(exs[i:i+k]) for i in range(0, n-k)]
print(max(res))
Problem p02900 (python)

Fixed submission:
a, b = [int(elem) for elem in input().split()]

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

a_lst = factorize(a)
b_lst = factorize(b)
res = list(set(a_lst) & set(b_lst))
print(len(res) + 1)

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

a, b = [int(elem) for elem in input().split()]

cf = []
for i in range(1, min(a, b)+1):
    if a % i == 0 and b % i == 0:
       cf.append(i)

res = [cf[0], cf[1]]
cf.pop(0)
cf.pop(0)

j = 0
while True:
    if j >= len(cf):
        break
    flag = 0
    for elem in res[1:]:
        if cf == []:
            break
        if gcd(cf[j], elem) != 1:
            cf.pop(j)
            flag = 1
            break
    if flag == 0:
        res.append(cf[j])
        cf.pop(j)
print(len(res))
Problem p02947 (python)

Fixed submission:
n = int(input())

dic = {}
for i in range(n):
  s = ''.join(sorted(list(input())))
  if not s in dic:
    dic[s] = 1
  else:
    dic[s] += 1

res = 0
for v in dic.values():
  if v >= 2:
    res += v*(v-1)
print(res//2)

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

dic = {}
for i in range(n):
  s = ''.join(sorted(list(input())))
  if not s in dic:
    dic[s] = 1
  else:
    dic[s] += 1

res = 0
for v in dic.values():
	if v >= 2:
      res += v*(v-1)
print(res//2)
Problem p02953 (python)

Fixed submission:
n = int(input())
h = [int(elem) for elem in input().split()]

flg = 0
max = 0
if n > 1 :
  for i in range(n):
    if h[i] > max:
      max = h[i]
    elif h[i] < max-1 :
      flg = 1
      break
 
if flg == 1 :
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
n = int(input())
hs = [int(elem) for elem in input().split()]

if n == 1:
  print("Yes")
else:
  flag = 0
  for i, h in enumerate(hs):
    if i == 0:
      pass
    else:
      if hs[i-1] == h + 1:
        hs[i-1] -= 1
      elif hs[i-1] > h + 1:
        flag = 1
        break
      else:
        pass
  
if flag == 0:
  print("Yes")
else:
  print("No")
Problem p02995 (python)

Fixed submission:
import fractions

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

a, b, c, d = [int(elem) for elem in input().split()]

res = (b+1 - a) - ((b) // c) - ((b) // d) + ((a-1) // c) + ((a-1) // d) + ((b) // lcm(c, d)) - ((a-1) // lcm(c, d))
print(res)

Buggy submission (verdict: Runtime Error):
import math

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

a, b, c, d = [int(elem) for elem in input().split()]
print((b+1 - a) - ((b+1) // c) - ((b+1) // d) + (a // c) + (a // d) + ((b+1) // lcm(c, d)) - (a // lcm(c, d)))
Problem p03043 (python)

Fixed submission:
import math

n, k = [int(elem) for elem in input().split()]

res = 0.0
for i in range(1, n+1):
  if not (k//i) == 0:
    if (k/i) == (k//i):
      if math.log2(k//i) == int(math.log2(k//i)):
        x = int(math.log2(k//i))
      else:
        x = int(math.log2(k//i)) + 1
    else:
      x = int(math.log2(k//i)) + 1
  else:
    x = 0
  res += (1/n) * (0.5 ** x)
print(res)

Buggy submission (verdict: Runtime Error):
import math

n, k = [int(elem) for elem in input().split()]

res = 0.0
for i in range(1, n+1):
  if not (k//i) == 0:
    if (k/i) == (k//i):
    	if math.log2(k//i) == int(math.log2(k//i)):
      		x = int(math.log2(k//i))
    	else:
      	x = int(math.log2(k//i)) + 1
  	else:
     	x = int(math.log2(k//i)) + 1
  else:
    x = 0
  res += (1/n) * (0.5 ** x)
print(res)

Buggy submission (verdict: Runtime Error):
import math

n, k = [int(elem) for elem in input().split()]

res = 0.0
for i in range(1, n+1):
  if (k/i) == (k//i):
    if math.log2(k//i) == int(math.log2(k//i)):
      x = int(math.log2(k//i))
    else:
      x = int(math.log2(k//i)) + 1
  else:
     x = int(math.log2(k//i)) + 1
  res += (1/n) * (0.5 ** x)
print(res)
Problem p03061 (python)

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

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

left_gcd = [0]*(n+1)
right_gcd = [0]*(n+1)
left_gcd[1] = a[0]
right_gcd[1] = a[-1]

for i in range(1,n):
    left_gcd[i+1] = gcd(left_gcd[i],a[i])
    right_gcd[i+1] = gcd(right_gcd[i],a[-1-i])

ans = right_gcd[n-1]
for i in range(n):
    ans = max(ans,gcd(left_gcd[i],right_gcd[n-1-i]))
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

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

n = int(input())
a_lst = [int(elem) for elem in input().split()]

res_lst = []
for i, a in enumerate(a_lst):
    new_lst = list(a_lst)
    new_lst.pop(i)
    res = gcd_list(new_lst)
    res_lst.append(res)
print(max(res_lst))
Problem p03138 (python)

Fixed submission:
# - coding : utf-8 -*-

if __name__ == "__main__":

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

    p = [1] * 41
    for i in range(40):
        p[i+1] = p[i] * 2
        
    ans = 0
    x = 0
    for i in range(41):
        t = p[40-i]
        if x + t > k:
            cnt = 0
            for j in range(n):
                if an[j] & t == t:
                    cnt += 1
            ans += cnt * t
        else:
            cnt = 0
            for j in range(n):
                if an[j] & t == t:
                    cnt += 1
            if cnt <= n/2:
                x += t
            ans += max(cnt, n-cnt) * t
    print(ans)

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

if __name__ == "__main__":

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

    p = [1] * 41
    for i in range(40):
        p[i+1] = p[i] * 2

    import pdb;pdb.set_trace()
        
    ans = 0
    x = 0
    for i in range(41):
        t = p[40-i]
        if x + t > k:
            cnt = 0
            for j in range(n):
                if an[j] & t == t:
                    cnt += 1
            ans += cnt * t
        else:
            cnt = 0
            for j in range(n):
                if an[j] & t == t:
                    cnt += 1
            if cnt <= n/2:
                x += t
            ans += max(cnt, n-cnt) * t
    print(ans)
Problem p03160 (python)

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
h = [int(elem) for elem in raw_input().split()]
cost = [0] * n

def calc_cost(k):
    if cost[k] != 0:
        return cost[k]
    if k == 1:
        cost[k] = calc_cost(k-1) + abs(h[k] - h[k-1])
    elif k == 0:
        cost[k] = 0
    else:
        cost[k] = min(calc_cost(k-1) + abs(h[k] - h[k-1]),
                      calc_cost(k-2) + abs(h[k] - h[k-2]))
    return cost[k]

print calc_cost(n-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [int(elem) for elem in input().split()]
cost = [0] * n

def calc_cost(k):
    if cost[k] != 0:
        return cost[k]
    if k == 1:
        cost[k] = calc_cost(k-1) + abs(h[k] - h[k-1])
    elif k == 0:
        cost[k] = 0
    else:
        cost[k] = min(calc_cost(k-1) + abs(h[k] - h[k-1]),
                      calc_cost(k-2) + abs(h[k] - h[k-2]))
    return cost[k]

print(calc_cost(n-1))

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [int(elem) for elem in input().split()]
cost = [0] * n

def calc_cost(k):
    if cost[k] != 0:
        return cost[k]
    if k == 1:
        cost[k] = calc_cost(k-1) + abs(h[k] - h[k-1])
    elif k == 0:
        return 0
    else:
        cost[k] = min(calc_cost(k-1) + abs(h[k] - h[k-1]),
                      calc_cost(k-2) + abs(h[k] - h[k-2]))
    return cost[k]

print(calc_cost(n-1))
Problem p03200 (python)

Fixed submission:
cnt = ans = 0
for c in input():
  if c is 'W':
    ans += cnt
  else:
    cnt += 1
print(ans)

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

def func(num, lst):
  if num == 0:
    return len(lst[num])
  else:
    return func(num - 1, lst) + len(lst[num])

s = s.lstrip("W")
s = s.rstrip("B")
if 'W' in s:
  lst = s.split('W')
  out = 0
  for i in range(0, len(lst)):
    if not lst[i] == '':
      out += func(i, lst) 
  print(out)
else:
  print(0)

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

def func(num, lst):
  if num == 0:
    return len(lst[num])
  else:
    return func(num - 1, lst) + len(lst[num])

lst = s.split('W')
out = 0
for i in range(0, len(lst)):
  if not lst[i] == '':
  	out += func(i, lst)
  
print(out)