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

Fixed submission:
def solve():
    N, K = list(map(int, input().split()))

    TABLE = [[-1 for x in range(K + 3)] for y in range(N + 3)]

    def recur(i, k):
        if not i < N:
            return 1

        if not TABLE[i][k] == -1:
            return TABLE[i][k]

        ans = 0
        for a in range(K):
            if not a == k:
                ans += recur(i + 1, a)

        TABLE[i][k] = ans
        return TABLE[i][k]

    return recur(0, -1)


if __name__ == '__main__':
    res = solve()
    print(res)

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

    TABLE = [[-1 for x in range(K + 3)] for y in range(N + 3)]

    def recur(i, k):
        if not i < N:
            return 1

        if not TABLE[i][k] == -1:
            return TABLE[i][k]

        ans = 0
        for a in range(K):
            if not a == k:
                ans += recur(i + 1, a)

        TABLE[i][k] = ans
        return TABLE[i][k]

    return recur(0, -1)


if __name__ == '__main__':
    res = solve()
    print(res)

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

    TABLE = [[-1 for x in range(K + 3)] for y in range(N + 3)]

    def recur(i, k):
        if not TABLE[i][k] == -1:
            return TABLE[i][k]

        if not i < N:
            return 1

        ans = 0
        for a in range(K):
            if not a == k:
                ans += recur(i + 1, a)

        TABLE[i][k] = ans
        return TABLE[i][k]

    return recur(0, -1)


if __name__ == '__main__':
    res = solve()
    print(res)

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

    TABLE = [[-1 for x in range(K + 1)] for y in range(N + 1)]

    def recur(i, k):
        if not TABLE[i][k] == -1:
            return TABLE[i][k]

        if not i < N:
            return 1

        ans = 0
        for a in range(K):
            if not a == k:
                ans += recur(i + 1, a)

        TABLE[i][k] = ans
        return TABLE[i][k]

    return recur(0, -1)


if __name__ == '__main__':
    res = solve()
    print(res)
Problem p04011 (python)

Fixed submission:
args = []
for _ in range(4):
    args.append(int(input()))

N, K, X, Y = args


def solve():
    if N <= K:
        return N * X

    first = K
    second = N - first

    return first * X + second * Y

res = solve()
print(res)

Buggy submission (verdict: Runtime Error):
def solve():
    def recur(i, n, total):
        # print("i, n, total", i, n, total)

        if not TABLE[i][n][total] == -1:
            # print('cache!')
            return TABLE[i][n][total]

        if not i < N:
            if n > 0 and total == A * n:
                return 1
            return 0

        ans1 = recur(i + 1, n, total)
        ans2 = recur(i + 1, n + 1, total + XS[i])

        # print(ans1, ans2)

        TABLE[i][n][total] = ans1 + ans2
        return TABLE[i][n][total]

    N, A = tuple(map(int, input().split()))
    XS = tuple(map(int, input().split()))

    TABLE = []
    for _ in range(N + 1):
        lines = [[-1 for x in range(N * 50 + 1)] for y in range(N + 1)]
        TABLE.append(lines)

    return recur(0, 0, 0)


if __name__ == '__main__':
    print(solve())

Buggy submission (verdict: Runtime Error):
def solve():
    def recur(i, n, total):
        # print("i, n, total", i, n, total)

        if not TABLE[i][n][total] == -1:
            # print('cache!')
            return TABLE[i][n][total]

        if not i < N:
            if n > 0 and total == A * n:
                TABLE[i][n][total] = 1
                return 1
            TABLE[i][n][total] = 0
            return 0

        ans1 = recur(i + 1, n, total)
        ans2 = recur(i + 1, n + 1, total + XS[i])

        # print(ans1, ans2)

        return ans1 + ans2

    N, A = tuple(map(int, input().split()))
    XS = tuple(map(int, input().split()))

    TABLE = []
    for _ in range(N + 1):
        lines = [[-1 for x in range(N * 50 + 1)] for y in range(N + 1)]
        TABLE.append(lines)

    return recur(0, 0, 0)


if __name__ == '__main__':
    print(solve())
Problem p04032 (python)

Fixed submission:
S = input()

def solve2():
    head = 0
    tail = 2
    while head < len(S):
        # print(S[head:tail])
        # print("\t" + S[head:tail][0:1])
        # print("\t" + S[head:tail][1:2])
        if S[head:tail][0:1] == S[head:tail][1:2]:
            return head + 1, tail
        head += 1
        tail += 1

    head = 0
    tail = 3
    while head < len(S):
        # print(S[head:tail])
        # print("\t" + S[head:tail][0:1])
        # print("\t" + S[head:tail][1:2])
        # print("\t" + S[head:tail][2:3])
        if S[head:tail][0:1] == S[head:tail][2:3]:
            return head + 1, tail
        head += 1
        tail += 1

    return -1, -1

res = solve2()
print(res[0], res[1])

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


def solve():
    # print(S)
    diff = ord("a")

    head = 0
    while head < len(S):
        tail = head + 1
        while tail <= len(S):
            # print(S[head:tail])
            table = [0 for _ in range(abs(ord("z") - ord("a")))]
            for j in range(len(S[head:tail])):
                # print("\t{}".format(S[head:tail][j:j+1]))
                index = ord(S[head:tail][j:j+1]) - diff
                table[index] += 1
                # print(table[index], len(S[head:tail]), table[index] / len(S[head:tail]))
                if len(S[head:tail]) >= 2 and table[index] / len(S[head:tail]) > 0.5:
                    # print("hit:" + S[head:tail])
                    # print(head + 1, tail)
                    return head + 1, tail

            tail += 1
        head += 1

    # print("no hit")
    return -1, -1

res = solve()
print(res[0], res[1])
Problem p03160 (python)

Fixed submission:
import sys
n = int(input())

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

dp = [sys.maxsize]*n
dp[0] = 0
for i in range(n):
  for j in range(i+1,i+2+1):
    if j<n:
      dp[j]= min(dp[j],dp[i]+abs(a[i]-a[j]))
      
      
print(dp[n-1])

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

dp = [sys.maxsize]*n
dp[0]=0

for i in range(n):
	for j in range(i+1,i+2+1):
      if j<n:
        dp[j] = min(dp[j],dp[i]+abs(a[i]-a[j]))
        
print(dp[n-1])

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

dp = [sys.maxsize]*n
dp[0]=0

for i in range(n):
	for j in range(i+1,i+2+1):
      if j<n:
        dp[j] = min(dp[j],dp[i]+abs(a[i]-a[j]))
        
print(dp[n-1])
Problem p03166 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10**9)

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

g = [[] for i in range(n)]

dp = [-1] *n
for _ in range(m):
  v1 , v2 = map(int,input().split())
  v1 -=1; v2 -=1
  g[v1].append(v2)
  
# finding longest path for vertice i
def dfs(i):
  if dp[i]!=-1:
    return dp[i]
  temp = 0
  for nv in g[i]:
    temp = max(temp, dfs(nv)+1)
  
  dp[i]=temp
  return temp
  
# finding overall longest path  
res = 0  
for i in range(n):
  res = max(res, dfs(i))
  
print(res)

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

g = [[] for i in range(n)]

for _ in range(m):
  v1 , v2 = map(int,input().split())
  v1 -=1; v2 -=1
  g[v1].append(v2)

# longest path from vertice i
def dfs(i):
  temp = 0
  for nv in g[i]:
    temp = max(temp,dfs(nv)+1)
  return temp

# iterate over all vertices

res = 0
for i in range(n):
  res = max(res, dfs(i))
  
print(res)
Problem p03167 (python)

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

grid = []

for i in range(n):
  temp = list(input())
  grid.append(temp)
  
#dp[n][m]
mod = 10**9+7
dp = [[0 for i in range(m)] for j in range(n)]
dp[0][0] = 1

for i in range(n):
  for j in range(m):
    if grid[i][j]=='#':
      continue
    if i>0:
      dp[i][j] += dp[i-1][j]%mod
    if j>0:
      dp[i][j] +=dp[i][j-1]%mod
      
print(dp[n-1][m-1]%mod)

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define ppi pair<int, int>
#define endl "\n"
#define nl cout << "\n"
#define deb(x) cout << #x << " " << x << endl;

const int N = 1010;
const int mod = 1e9 + 7;
int H, W;
char grid[N][N];

// dp[i][j] = #Ways to reach from (i, j) to (H, W)
int dp[N][N];

int Top_Down(int x = 1, int y = 1) {
    // Base Case
    if(x == H && y == W) return (dp[x][y] = 1);
    // Choice
    if(dp[x][y] != -1) return dp[x][y];
    int ways = 0;
    if(x <= H && grid[x+1][y] == '.') ways += Top_Down(x+1, y)%(mod);
    if(y <= W && grid[x][y+1] == '.') ways += Top_Down(x, y+1)%(mod);
    return (dp[x][y]=ways%(mod));
}

int32_t main() {
    IOS;
    memset(dp, -1, sizeof(dp));
    cin >> H >> W;
    for(int i = 1; i <= H; ++i) 
        for(int j = 1; j <= W; ++j) {
            cin >> grid[i][j];
        }
    //
    for(int i = 1; i <= H; ++i){
        for(int j = 1; j <= W; ++j)
            if((i == H and j == W) and grid[i][j]=='.') dp[i][j] = 1;
    }
    cout << Top_Down()%(mod) << endl;
    // for(int i = 1; i <= H; ++i){
    //     for(int j = 1; j <= W; ++j) cout << dp[i][j] << " ";
    //     cout << endl;
    // }
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define ppi pair<int, int>
#define endl "\n"
#define nl cout << "\n"
#define deb(x) cout << #x << " " << x << endl;

const int N = 1010;
const int mod = 1e9 + 7;
int H, W;
char grid[N][N];

// dp[i][j] = #Ways to reach from (i, j) to (H, W)
int dp[N][N];

int Top_Down(int x = 1, int y = 1) {
    // Base Case
    if(x == H && y == W) return (dp[x][y] = 1);
    // Choice
    if(dp[x][y] != -1) return dp[x][y];
    int ways = 0;
    if(x <= H && grid[x+1][y] == '.') ways += Top_Down(x+1, y)%(mod);
    if(y <= W && grid[x][y+1] == '.') ways += Top_Down(x, y+1)%(mod);
    return (dp[x][y]=ways%(mod));
}

int32_t main() {
    IOS;
    memset(dp, -1, sizeof(dp));
    cin >> H >> W;
    for(int i = 1; i <= H; ++i) 
        for(int j = 1; j <= W; ++j) {
            cin >> grid[i][j];
        }
    //
    for(int i = 1; i <= H; ++i){
        for(int j = 1; j <= W; ++j)
            if((i == H and j == W) and grid[i][j]=='.') dp[i][j] = 1;
    }
    cout << Top_Down()%(mod) << endl;
    // for(int i = 1; i <= H; ++i){
    //     for(int j = 1; j <= W; ++j) cout << dp[i][j] << " ";
    //     cout << endl;
    // }
}
Problem p03169 (python)

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

ones , twos, threes = 0,0,0

for i in a:
  if i ==1:
    ones+=1
  elif i ==2:
    twos+=1
  else:
    threes+=1

max_ones = ones+twos+threes
max_twos = twos+threes
max_threes = threes
# dp[n][n][n]
dp = [[[0.0]*(n+1) for i in range(n+1)] for j in range(n+1)]

for k in range(max_threes+1):
  for j in range(max_twos+1-k):
    for i in range(max_ones+1-j-k):
      if i+j+k==0:
        continue
      else:
        dp[i][j][k] = n/(i+j+k)
        if i>0:
          dp[i][j][k] += (dp[i-1][j][k]*i)/(i+j+k)
        if j>0:
          dp[i][j][k] += (dp[i+1][j-1][k]*j)/(i+j+k)
        if k>0:
          dp[i][j][k] += (dp[i][j+1][k-1]*k)/(i+j+k)
          
          
print(dp[i][j][k])

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

ones , twos, threes = 0,0,0

for i in a:
  if i ==1:
    ones+=1
  elif i ==2:
    twos+=1
  else:
    threes+=1

max_ones = ones+twos+threes
max_twos = twos+threes
max_threes = threes
# dp[n][n][n]
dp = [[[0.0]*(n+1) for i in range(n+1)] for j in range(n+1)]

for k in range(max_threes+1):
  for j in range(max_twos+1-k):
    for i in range(max_ones+1-j-k):
      if i+j+k==0:
        continue
      else:
        dp[i][j][k] = n/i+j+k
        if i>0:
          dp[i][j][k] += (dp[i-1][j][k]*i)/(i+j+k)
        if j>0:
          dp[i][j][k] += (dp[i+1][j-1][k]*j)/(i+j+k)
        if k>0:
          dp[i][j][k] += (dp[i][j+1][k-1]*k)/(i+j+k)
          
          
print(dp[i][j][k])
Problem p03160 (python)

Fixed submission:
def printArray(arr):
  for i in range(0, len(arr)):
    print(arr[i])
    
def minimumCost(n, hights):  
  if (n < 2):
    print("0")
  else:
    memo = []
    memo.append(0)
    memo.append(abs(hights[0] - hights[1]))
    for i in range(2, n):
      memo.append(min(
        (abs(hights[i] - hights[i - 1]) + memo [i - 1]), 
        (abs(hights[i] - hights[i - 2]) + memo [i - 2])
      ))
    print(memo[n-1])
    
n = int(input())
hights = list(map(int,input().split()))
minimumCost(n, hights)

Buggy submission (verdict: Runtime Error):
(n, W) = map(int,input().split())
pre = [0] * (W+1)
cur = [0] * (W+1)
#a = [[0] * (W+1) for i in range(n)]
for i in range(0, n):
  (w, v) = map(int,input().split())
  for j in range(w, W + 1):
    cur[j] = max(pre[j], pre[j-w] + v)
  pre = list(cur)
print(cur[W])

Buggy submission (verdict: Runtime Error):
import numpy as np
 
(n, k) = map(int,input().split())
hights = list(map(int,input().split()))
memo = [-1] * n
memo[0]

print(' '.join([str(elem) for elem in memo]))

Buggy submission (verdict: Runtime Error):
import numpy as np
 
(n, k) = map(int,input().split())
hights = list(map(int,input().split()))
memo.append(0)
for i in range(1, n):
  memo.append(np.iinfo(np.int64).max)
  for j in range(max(i - k, 0), i):
    memo[i] = min(memo[i], (abs(hights[i] - hights[j]) + memo [j]))
print(memo[n-1])

Buggy submission (verdict: Runtime Error):
def printArray(arr):
  for i in range(0, len(arr)):
    print(arr[i])
    
def minimumCost(n, k, hights):  
  if (n < 2):
    print("0")
  else:
    memo = []
    memo.append(0)
    memo.append(abs(hights[0] - hights[1]))
    for i in range(2, n):
      memo.append(abs(hights[i] - hights[i - 1]) + memo [i - 1])
      for j in range(2, k + 1):
        if (i - j) >= 0:
        	memo[i] = min(memo[i],
                      (abs(hights[i] - hights[i - j]) + memo [i - j]))
    print(memo[n-1])
    
(n, k) = map(int,input().split())
hights = list(map(int,input().split()))
minimumCost(n, k, hights)

Buggy submission (verdict: Runtime Error):
def minimumCost(n, hights):
  if (n < 2):
    print "0"
  else:
    memo = []
    memo[0] = 0
    memo[1] = abs(hights[0] - hights[1])
    for i in range(2, n):
      memo[i] = min((hights[i] - hights[i - 1] + memo [i - 1]), (hights[i] - hights[i - 2] + memo [i - 2]))
    print memo[n-1]
Problem p03160 (python)

Fixed submission:
n = int(raw_input())
arr = map(int,raw_input().split())
dp = [float("inf")]*(n)
dp[0]=0
for i in range(n):
    for j in [i+1,i+2]:
        if j < n: 
            dp[j] = min(dp[j], dp[i]+abs(arr[i]-arr[j]))
print dp[n-1]

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
arr = map(int,raw_input().split())
dp = [float("inf")]*(n)
 
for i in range(n):
  for j in (i+1,i+2)
    if j < n:
      dp[j] = min(dp[j], dp[i]+abs(arr[i]-arr[j]))
print dp[n-1]

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
arr = map(int,raw_input().split())
dp = [float("inf")]*(n)
 
for i in range(n):
  for j in range(i+1,i+3):
    if j < n:
      dp[j] = min(dp[j], dp[i]+abs(arr[i]-arr[h]))
print dp[n-1]

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
arr = map(int,raw_input().split())
dp = [float("inf")]*(n)

for i in range(n):
  for j in range(i,i+2):
    if j < n:
      dp[j] = min(dp[j], dp[i]+abs(arr[i]-arr[h]))
print dp[n-1]
Problem p03162 (python)

Fixed submission:
n = int(raw_input())

dp = [0]*(3)

for i in range(n):
    dp_new = [0]*3
    c=map(int,raw_input().split())
    
    for i in range(3):
        for j in range(3):
            if i != j:
                dp_new[j] = max(dp_new[j],dp[i]+c[j])
    dp = dp_new
print(max(dp))

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

mat = []
for i in range(n):
    mat.append(map(int,raw_input().split()))
    
dp = [0,0,0]

for day in range(n):
    ndp = [0,0,0]
    data = mat[day]
    
    for i in range(n):
        for j in range(n):
            if i != j:
                ndp[j] = max(ndp[j], dp[i]+data[j])
    dp = ndp
print max(dp)
Problem p03164 (python)

Fixed submission:
N, W = [int(i) for i in input().split()]
weight = []
value = []
for i in range(N):
  w, val = [int(i) for i in input().split()]
  weight.append(w)
  value.append(val)
# changing to value max as W_max ~ 10^9 and val_max ~= 1000 * next
val_max = 0
for i in range(N):
  val_max += value[i]
dp = [float('inf') for i in range(val_max+1)] # dp[i] is the min weight required for the value 
# hence our ans would be in the max value where the weight < knapsack weight
dp[0] = 0
for i in range(N):
  for v in range(val_max-value[i], -1, -1): # range of kanpsack weight in which i can push the current item
    dp[v + value[i]] = min(dp[v + value[i]], dp[v] + weight[i])
    #print(dp)
sol = 0
for i in range(val_max+1):
  if dp[i] <= W:
    sol = i
print("%s" % sol)

Buggy submission (verdict: Runtime Error):
N,W = [int(i) for i in input().split()]
w = [] # limit weight to knapsack capacity
v = [] # maximize value
for i in range(N):
  line = input().split()
  w.append(int(line[0]))
  v.append(int(line[1]))
mem = [[0]*(W+1) for i in range(N)]
for i in range(w[0], W+1):
  mem[0][i] = v[0]
for i in range(1, N):
  for j in range(1, W+1):
    if w[i] > j:
      mem[i][j] = mem[i-1][j]
    else:
      mem[i][j] = max(mem[i-1][j], v[i] + mem[i-1][j - w[i]])
#print(mem)
print("%s" % mem[N-1][W])
Problem p03166 (python)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(100000000)
from collections import defaultdict
from collections import deque
# starting with start node and then looking for the kids
# and the solving the sub-problem with kids
def recursive_dfs(graph, start_node, map1):
  if start_node not in graph:
    map1[start_node] = 0
    return 0
  dist = 0
  for child in graph[start_node]:
    if child not in map1:
      dist = max(recursive_dfs(graph, child, map1), dist)
    else:
      dist = max(map1[child], dist)
  map1[start_node] = dist + 1
  #print(map1)
  return (dist + 1)
 
N,M = [int(i) for i in input().split()] # nodes, edges
graph = defaultdict(list)
for i in range(M):
  s,d = [i for i in input().split()]
  graph[s].append(d)
map1 = defaultdict(int)
ans = 0
for i in range(1, N+1):
  if i in map1:
    ans = max(ans, map1[str(i)])
  else:
    ans = max(recursive_dfs(graph, str(i), map1), ans)
print("%s" % ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from collections import deque
# starting with start node and then looking for the kids
# and the solving the sub-problem with kids
def recursive_dfs(graph, start_node, map1):
  if start_node not in graph:
    map1[start_node] = 0
    return 0
  dist = 0
  for child in graph[start_node]:
    if child not in map1:
      dist = max(recursive_dfs(graph, child, map1), dist)
    else:
      dist = max(map1[child], dist)
  map1[start_node] = dist + 1
  #print(map1)
  return (dist + 1)

N,M = [int(i) for i in input().split()] # nodes, edges
graph = defaultdict(list)
for i in range(M):
  s,d = [i for i in input().split()]
  graph[s].append(d)
map1 = defaultdict(int)
ans = 0
for i in range(1, N+1):
  if i in map1:
    ans = max(ans, map1[str(i)])
  else:
    ans = max(recursive_dfs(graph, str(i), map1), ans)
print("%s" % ans)
Problem p03160 (python)

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

dp = [0]*N
dp[N-1], dp[N-2] = 0, abs(h[N-1] - h[N-2])
for i in range(N-3,-1,-1):
    dp[i] = min(abs(h[i] - h[i+1]) + dp[i+1], abs(h[i] - h[i+2]) + dp[i+2])
print(dp[0])

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
N = int(input())
h = list(map(int, input().split()))

@lru_cache(None)
def dp(i):
    if i >= N: return 0
    if i + 1 == N - 1: return abs(h[i] - h[i+1])
    if i + 2 == N - 1: return abs(h[i] - h[i+2])
    return min(abs(h[i] - h[i+1]) + dp(i+1), abs(h[i] - h[i+2]) + dp(i+2))

print(dp(0))
Problem p03161 (python)

Fixed submission:
def main2(N,h,K):
    dp = [0] * N
    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
    return dp[-1]

N, K = map(int, input().split())
h = list(map(int, input().split()))
print(main2(N,h,K))

Buggy submission (verdict: Runtime Error):
def f(N,K,h):
    dp = [0]*N

    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0,i-K), i)])
    print(dp[-1])


N, K = map(int, input().split())
h = list(map(int, input().split()))
f()
Problem p03168 (python)

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

dp = [0 for j in range(n + 1)]
dp[0] = 1
for i in range(n):
    pi = p[i]
    for j in range(i, -1, -1):
        dp[j + 1] = dp[j + 1] * pi + dp[j] * (1 - pi)
    dp[0] *= pi
print(sum(dp[:n // 2 + 1]))

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
def head_prob(N,p):
    @lru_cache(None)
    def f(i,k):
        if i <0 or k <0: return 0
        if i == 0 and k == 1:
            return p[0]
        if i == 0 and k == 0:
            return 1 - p[0]
        return p[i]*f(i-1,k-1) + (1-p[i])*f(i-1,k)

    probs = [(f(N-1,k),k) for k in range(1,N+1)]
    return sum(prob[0] for prob in probs if prob[1] > N/2)



N = int(input())
p = list(map(float, input().split()))
print(head_prob(N,p))
Problem p03160 (python)

Fixed submission:
def dp_a_frog1(stones):
    if len(stones) == 0:
        return 0
    dp = [0] * len(stones)
    for i in range(1, len(stones)):
        cost_jump = dp[i - 1] + abs(stones[i - 1] - stones[i])
        if i > 1:
            cost_jump_2 = dp[i - 2] + abs(stones[i - 2] - stones[i])
            cost_jump = min(cost_jump, cost_jump_2)
        dp[i] = cost_jump
    return dp[len(stones) - 1]


if __name__ == '__main__':
    N = int(input())
    h = list(map(int, input().split()))
    print(dp_a_frog1(h))

Buggy submission (verdict: Runtime Error):
def dp_a_frog1(stones):
    if len(stones) == 0:
        return 0
    dp = [0] * len(stones)
    for i in range(1, len(stones)):
        cost_jump = dp[i-1] + abs(stones[i-1] - stones[i])
        if i > 1:
            cost_jump_2 = dp[i-2] + abs(stones[i-2] - stones[i])
            cost_jump = min(cost_jump, cost_jump_2)
        dp[i] = cost_jump
    return dp[len(stones) - 1]
 

if __name__ == '__main__':
	N = int(input())
	h = list(map(int, input().split()))
    print(dp_a_frog1(h))
Problem p03160 (python)

Fixed submission:
number = int(input())
scaffolds = list(map(int, input().split()))
costs = [ 0 for i in range(number)]

for i in range(len(costs)):
    hight = scaffolds[i]

    i_1 = -1
    if 0 <= i - 1:
        min_v = costs[i - 1]
        hight_1 = scaffolds[i - 1]
        i_1 = min_v + abs(hight_1 - hight)

    i_2 = -1
    if 0 <= i - 2:
        min_v = costs[i - 2]
        hight_2 = scaffolds[i - 2]
        i_2 = min_v + abs(hight_2 - hight)
    if i_1 < 0 and i_2 < 0:
        costs[i] = 0
    elif i_1 < 0:   
        costs[i] = i_2
    elif i_2 < 0:
        costs[i] = i_1
    else:
        costs[i] = min(i_1, i_2)  
    
    
print(costs[number - 1])

Buggy submission (verdict: Runtime Error):
a = list(map(int, input().split()))
b = [list(map(int, input().split())) for i in range(a[0])]

result = []

max_weight = a[1]

def calc(i, queue):
    if len(b) <= i:
        return

    current = b[i]
    # print(queue)
    # print(i - 1)
    prev = queue[-1] if 0 < len(queue) else [0, 0] 
    
    if current[0] + prev[0] <= max_weight:
        result.append(prev[1] + current[1])
    
    next_queue = queue[:]
    next_queue.append([prev[0] + current[0], prev[1] + current[1]])
    # print(next_queue)
    # print(queue)
    calc(i + 1, next_queue)
    calc(i + 1, queue)

calc(0, [])

print(max(result))