Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

class BIT:
    def __init__(self, N):
        self.N = N
        self.bit = [0 for _ in range(N+1)]
    def add(self, x, a):
        while x <= self.N:
            self.bit[x] += a
            x += x & -x
    def sum(self, x):
        ret = 0
        while x != 0:
            ret += self.bit[x]
            x -= x & -x
        return ret

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort(key = lambda x: -x[0])
ab.sort(key = lambda x: -x[1])
f = [0] * M
cnt, ans = 0, 0
bit = BIT(M+1)
for a, b in ab:
    if M-a >= 0 and bit.sum(M-a+1) - bit.sum(0, 1) <= M-a:
        ans += b
        cnt += 1
        if cnt == M:
            break
        bit.add(M-a+1, 1)
print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

class UnionFind:

    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.height = [0 for i in range(n)]
        self.size = [1 for i in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def getsize(self, x):
        return self.size[self.find(x)]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.height[x] < self.height[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = self.par[x]
            self.size[x] += self.size[y]
            if self.height[x] == self.height[x]:
                self.height[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

class BIT:
    def __init__(self, N):
        self.N = N
        self.bit = [0 for _ in range(N+1)]
    def add(self, x, a):
        while x <= self.N:
            self.bit[x] += a
            x += x & -x
    def sum(self, x):
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= x & -x
        return ret

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort(key = lambda x: x[0])
ab.sort(key = lambda x: -x[1])
ans = 0
# print(ab)
uf = UnionFind(M+2)
bit = BIT(M)
ub = M+1
for a, b in ab:
    # print([bit.sum(i) for i in range(1, M+1)])
    i = M-a+1
    # print(bit.sum(i), i, ub)
    if 0 < i and bit.sum(i) < i:
        ans += b
        if bit.sum(i-1) == bit.sum(i):
            bit.add(i, 1)
            uf.unite(i, i+1)
        else:
            lb, ub = 0, i
            while lb+1 < ub:
                mid = (lb+ub)//2
                if uf.same(mid, ub):
                    ub = mid
                else:
                    lb = mid
            bit.add(lb, 1)
            uf.unite(lb, ub)
# print([bit.sum(i) for i in range(1, M+1)])
# print()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
from math import sqrt
S = int(input())
inf = 10**9
for X in range(max(0, int(sqrt(max(0, S-6*10**11)))), int(sqrt(S))+1):
    Y = S-X*X
    for i in range(1, int(sqrt(Y)+1)):
        if Y % i == 0 and 0 <= Y//i <= inf:
            if abs(X*X-Y) == S:
                print(0, 0, i, X, X, Y//i)
                quit()
for X in range(int(sqrt(S)), int(sqrt(S+10**11))):
    Y = X*X-S
    for i in range(1, int(sqrt(max(0,Y))+1)):
        if Y % i == 0 and 0 <= Y//i <= inf:
            if abs(X*X-Y) == S:
                print(0, 0, i, X, X, Y//i)
                quit()


Fixed submission:
S = int(input())
t = 10**9
print(0, 0, 1, t, S//t+(S%t!=0), (t-S%t)%t)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

from queue import *
N, M = map(int, input().split())
N *= 3
es = [[] for i in range(N)]
for i in range(M):
    u, v = map(lambda x : (int(x)-1)*3, input().split())
    es[u].append(v+1)
    es[u+1].append((v+2))
    es[u+2].append((v))
S, T = map(lambda x : (int(x)-1)*3, input().split())
dist = [-1 for i in range(N)]
dist[S] = 0
q = Queue()
q.put(S)
while not q.empty():
    v = q.get()
    for u in es[v]:
        if dist[u] == -1:
            dist[u] = dist[v] + 1
            q.put(u)
if dist[T] != -1:
    print(dist[T] // 3)
else:
    print(-1)

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

from queue import *
N, M = map(int, input().split())
N *= 3
es = [[] for i in range(N)]
for i in range(M):
    u, v = map(lambda x : (int(x)-1)*3, input().split())
    es[u].append(v+1)
    es[u+1].append((v+2))
    es[u+2].append((v))
S, T = map(lambda x : (int(x)-1)*3, input().split())
dist = [-1 for i in range(N)]
dist[S] = 0
q = Queue()
q.put(S)
while not q.empty():
    v = q.get()
    for u in es[v]:
        if dist[u] == -1:
            dist[u] = dist[v] + 1
            q.put(u)
if dist[T] != -1:
    print(dist[T] // 3)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
S = list(input().split())
T = list(input().split())
MOD = 10**9+7
dp = [[0] * (M+1) for _ in range(N+1)]
sum = [[0] * (M+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N+1):
    sum[i][0] = 1
for j in range(M+1):
    sum[0][j] = 1
for i in range(N):
    for j in range(M):
        dp[i+1][j+1] = (S[i] == T[j]) * sum[i][j]
        sum[i+1][j+1] = (sum[i+1][j] + sum[i][j+1] - sum[i][j] + dp[i+1][j+1]) % MOD
print(sum[N][M])

Fixed submission:
N, M = map(int, input().split())
S = list(input().split())
T = list(input().split())
MOD = 10**9+7
dp = [[0] * (M+1) for _ in range(N+1)]
sum = [[0] * (M+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N+1):
    sum[i][0] = 1
for j in range(M+1):
    sum[0][j] = 1
for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            dp[i+1][j+1] = sum[i][j]
        sum[i+1][j+1] = (sum[i+1][j] + sum[i][j+1] - sum[i][j] + dp[i+1][j+1]) % MOD
print(sum[N][M])

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
S = list(input().split())
T = list(input().split())
MOD = 10**9+7
dp = [[0] * (M+1) for _ in range(N+1)]
sum = [[0] * (M+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N+1):
    sum[i][0] = 1
for j in range(M+1):
    sum[0][j] = 1
for i in range(N):
    for j in range(M):
        dp[i+1][j+1] = (S[i] == T[j]) * sum[i][j] % MOD
        sum[i+1][j+1] = (sum[i+1][j] + sum[i][j+1] - sum[i][j] + dp[i+1][j+1]) % MOD
print(sum[N][M])

Fixed submission:
N, M = map(int, input().split())
S = list(input().split())
T = list(input().split())
MOD = 10**9+7
dp = [[0] * (M+1) for _ in range(N+1)]
sum = [[0] * (M+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N+1):
    sum[i][0] = 1
for j in range(M+1):
    sum[0][j] = 1
for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            dp[i+1][j+1] = sum[i][j]
        sum[i+1][j+1] = (sum[i+1][j] + sum[i][j+1] - sum[i][j] + dp[i+1][j+1]) % MOD
print(sum[N][M])
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
mod = 10**9+7

N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
cnt = defaultdict(int)
for i in range(N):
    for j in range(i+1, N):
        a, b = xy[j][0]-xy[i][0], xy[j][1]-xy[i][1]
        cnt[(a, b)] += 1
        cnt[(-a, -b)] += 1
print(N-max(cnt.values()))


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
mod = 10**9+7

N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
xy.sort()
Ans = N
for i in range(N):
    for j in range(i+1, N):
        a, b = xy[j][0]-xy[i][0], xy[j][1]-xy[i][1]
        ans = N
        for k in range(N):
            for l in range(k+1, N):
                if xy[k][0]+a == xy[l][0] and xy[k][1]+b == xy[l][1]:
                    ans -= 1
        Ans = min(Ans, ans)
print(Ans)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
dic=defaultdict(int)
for i, (x,y)in enumerate(p):
  for j, (u,v) in enumerate(p):
    if i==j:
      continue
    dic[(x-u,y-v)]+=1
print(n-max(dic,key=lambda z:z[1])[1])

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
mod = 10**9+7

N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
xy.sort()
Ans = N
for i in range(N):
    for j in range(i+1, N):
        a, b = xy[j][0]-xy[i][0], xy[j][1]-xy[i][1]
        ans = N
        for k in range(N):
            for l in range(k+1, N):
                if xy[k][0]+a == xy[l][0] and xy[k][1]+b == xy[l][1]:
                    ans -= 1
        Ans = min(Ans, ans)
print(Ans)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
dic=defaultdict(int)
for i, (x,y)in enumerate(p):
  for j, (u,v) in enumerate(p):
    if i==j:
      continue
    dic[(x-u,y-v)]+=1
print(n-max(dic,key=lambda z:z[1]))

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
mod = 10**9+7

N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
xy.sort()
Ans = N
for i in range(N):
    for j in range(i+1, N):
        a, b = xy[j][0]-xy[i][0], xy[j][1]-xy[i][1]
        ans = N
        for k in range(N):
            for l in range(k+1, N):
                if xy[k][0]+a == xy[l][0] and xy[k][1]+b == xy[l][1]:
                    ans -= 1
        Ans = min(Ans, ans)
print(Ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
MOD = 10**9 + 7
exist = [1 for _ in range(N+2)]
for _ in range(M):
    exist[int(input())] = 0
dp = [0 for _ in range(N+2)]
dp[0] = 1
for i in range(N):
    dp[i+1] = (dp[i+1] + dp[i] * exist[i+1]) % MOD
    dp[i+2] = (dp[i+2] + dp[i] * exist[i+2]) % MOD
print(dp[N])

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
from collections import *
from math import atan2, pi
from bisect import *
mod = 10**9+7

L = input()
N = len(L)
dp = [0] * N
dp[0] = 1
T = 2
for i in range(1, N):
    if L[i] == '1':
        dp[i] = (dp[i-1] * 3 + T) % mod
        T = T * 2 % mod
    else:
        dp[i] = dp[i-1] * 3 % mod
print((dp[-1] + T) % mod)
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import *
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
heapify(A)
B_C = [list(map(int, input().split())) for i in range(M)]
B_C.sort(key = lambda x : x[1])
for i in range(M):
    cnt = 0
    while cnt < B_C[i][0]:
        x = heappop(A)
        if x < B_C[i][1]:
            heappush(A, B_C[i][1])
        else:
            heappush(A, x)
            break
        cnt += 1
print(sum(A))

Fixed submission:
from heapq import *
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
heapify(A)
B_C = [list(map(int, input().split())) for i in range(M)]
B_C.sort(key = lambda x : x[1], reverse = True)
for i in range(M):
    cnt = 0
    while cnt < B_C[i][0]:
        x = heappop(A)
        if x < B_C[i][1]:
            heappush(A, B_C[i][1])
        else:
            heappush(A, x)
            break
        cnt += 1
print(sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import *
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
heapify(A)
for i in range(M):
    B, C = map(int, input().split())
    cnt = 0
    while cnt < B and cnt < N:
        x = heappop(A)
        if x < C:
            heappush(A, C)
        else:
            heappush(A, x)
            break
        cnt += 1
print(sum(A))

Fixed submission:
from heapq import *
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
heapify(A)
B_C = [list(map(int, input().split())) for i in range(M)]
B_C.sort(key = lambda x : x[1], reverse = True)
for i in range(M):
    cnt = 0
    while cnt < B_C[i][0]:
        x = heappop(A)
        if x < B_C[i][1]:
            heappush(A, B_C[i][1])
        else:
            heappush(A, x)
            break
        cnt += 1
print(sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import *
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
heapify(A)
for i in range(M):
    B, C = map(int, input().split())
    cnt = 0
    while cnt < B and cnt < N:
        x = heappop(A)
        if x < C:
            heappush(A, C)
        else:
            heappush(A, x)
            break
        cnt += 1
ans = 0
while len(A) > 0:
    ans += heappop(A)
print(ans)

Fixed submission:
from heapq import *
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
heapify(A)
B_C = [list(map(int, input().split())) for i in range(M)]
B_C.sort(key = lambda x : x[1], reverse = True)
for i in range(M):
    cnt = 0
    while cnt < B_C[i][0]:
        x = heappop(A)
        if x < B_C[i][1]:
            heappush(A, B_C[i][1])
        else:
            heappush(A, x)
            break
        cnt += 1
print(sum(A))
Buggy python submission (verdict: Runtime Error):
import math

N, K = map(int, input().split())
ans = 0
for m in range(1, N+1):
    x = math.log2(K / m)
    if x - int(x) > 0:
        x += 1
    if x > 1:
        ans += (1/2) ** int(x) / N
    else:
        ans += 1 / N
print(ans)

Fixed submission:
import math

N, K = map(int, input().split())
ans = 0
for m in range(1, N+1):
    x = math.log2(K / m)
    if x - int(x) > 0:
        x += 1
    if x > 1:
        ans += (1/2) ** int(x) / N
    else:
        ans += 1 / N
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
n = int(math.sqrt(N))
if n * n != N:
    n += 1
ans = 0
for i in range(1, n):
    if N % i ==  0:
        ans += N // i - 1
if N <= 2:
    ans = 0
print(ans)

Fixed submission:
N, K = map(int, input().split())
print(N - K + 1)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
n = int(math.sqrt(N))
ans = 0
for x in range(1, n+1):
    m = N // x - 1
    if N % x == 0 and x == N % m:
        ans += m
print(ans)

Fixed submission:
import math
N = int(input())
n = int(math.sqrt(N))
ans = 0
for x in range(1, n+1):
    m = N // x - 1
    if m > 0 and N % x == 0 and x == N % m:
        ans += m
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from copy import *

H, W = map(int, input().split())
A = [input() for i in range(H)]
q = deque()
c = [[-1] * W for i in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            q.append((i, j))
            c[i][j] = 0
D = [[0, 1], [1, 0], [0, -1], [-1, 0]]
while q:
    y, x = q.popleft()
    for dy, dx in D:
        ny, nx = y+dy, x+dx
        if 0 <= ny < H and 0 <= nx < W and c[ny][nx] == -1:
            q.append((ny, nx))
            c[ny][nx] = c[y][x]+1
print(max([max(l) for l in c]))


Fixed submission:
import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from copy import *

H, W = map(int, input().split())
A = [input() for i in range(H)]
q = deque()
c = [[-1] * W for i in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            q.append((i, j))
            c[i][j] = 0
D = [[0, 1], [1, 0], [0, -1], [-1, 0]]
while q:
    y, x = q.popleft()
    for dy, dx in D:
        ny, nx = y+dy, x+dx
        if 0 <= ny < H and 0 <= nx < W and c[ny][nx] == -1:
            q.append((ny, nx))
            c[ny][nx] = c[y][x]+1
print(max([max(l) for l in c]))
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

n = int(input())
S = input()
ans = 0
l = 0
while l < n and S[l] == '.':
    l += 1
for r in range(l, n-1):
    if S[r:r+2] == '#.':
        m = r
    if S[r:r+2] == '.#':
        ans += min(r-m, m-l)+1
        l = r+1
if S[-1] == '.':
    ans += min(r-m, m-l)+1
print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

n = int(input())
S = input()
f = [0] * (n+1)
for i in range(n):
    f[i+1] = f[i] + (S[i] == '#')
g = [0] * (n+1)
for i in range(n):
    g[i+1] = g[i] + (S[i] == '.')
k = S.index('#') if '#' in S else 0
ans = min(f[n], g[n]-g[k])
lst = []
for i in range(n-1):
    if S[i:i+2] == '#.':
        lst.append(i)
for i, j in zip(lst, lst[1:]):
    ans = min(ans, f[i+1]+g[n]-g[j])
print(ans)


# N, M, K = map(int, input().split())
# A = list(map(int, input().split()))
Buggy python submission (verdict: Runtime Error):
A, B, k = map(int, input().split())
lst = []
for i in range(1, 100):
  if A % i and B % i == 0:
    lst.append(i)
print(lst[-k])


Fixed submission:
A, B, k = map(int, input().split())
lst = []
for i in range(1, 101):
  if A % i == 0 and B % i == 0:
    lst.append(i)
print(lst[-k])
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N, M = map(int, input().split())
d = defaultdict(int)
for i in range(N):
    lst = list(map(int, input().split()))
    for a in range(1, len(lst)):
        d[lst[a]] += 1
ans = 0
for i in range(1, M+1):
    if d[i] == N:
        ans += 1
print(ans)
from collections import defaultdict
N, M = map(int, input().split())
d = defaultdict(int)
for i in range(N):
    lst = list(map(int, input().split()))
    for a in range(1, len(lst)):
        d[lst[a]] += 1
ans = 0
for i in range(1, M+1):
    if d[i] == N:
        ans += 1
print(ans)


Fixed submission:
N, M = map(int, input().split())
d = {}
for i in range(N):
    lst = list(map(int, input().split()))
    for a in range(1, len(lst)):
        if lst[a] in d:
            d[lst[a]] += 1
        else:
            d[lst[a]] = 1
ans = 0
for key in d:
    if d[key] == N:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >= M:
    print(0)
else:
    X = sorted(X)
    L = []
    for i in range(0, M-1):
        L.append(X[i+1] - X[i])
        L = sorted(L, reverse = True)
        S = 0
    for i in range(N-1):
        S += L[i]
    res = X[M-1] - X[0] - S
    print(res)


Fixed submission:
N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >= M:
    print(0)
else:
    X = sorted(X)
    L = []
    for i in range(0, M-1):
        L.append(X[i+1] - X[i])
    L = sorted(L, reverse = True)
    S = 0
    for i in range(N-1):
        S += L[i]
    res = X[M-1] - X[0] - S
    print(res)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
if N >= M:
  	print(0)
else:
	X = list(map(int, input().split()))
	X = sorted(X)
	L = []
	for i in range(0, M-1):
    	L.append(X[i+1] - X[i])
	L = sorted(L, reverse = True)
	S = 0
	for i in range(N-1):
    	S += L[i]
	res = X[M-1] - X[0] - S
	print(res)

Fixed submission:
N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >= M:
    print(0)
else:
    X = sorted(X)
    L = []
    for i in range(0, M-1):
        L.append(X[i+1] - X[i])
    L = sorted(L, reverse = True)
    S = 0
    for i in range(N-1):
        S += L[i]
    res = X[M-1] - X[0] - S
    print(res)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
X = list(map(int, input().split()))
X = sorted(X)
L = []
for i in range(0, M-1):
    L.append(X[i+1] - X[i])
L = sorted(L, reverse = True)
S = 0
for i in range(N-1):
    S += L[i]
res = X[M-1] - X[0] - S
print(res)

Fixed submission:
N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >= M:
    print(0)
else:
    X = sorted(X)
    L = []
    for i in range(0, M-1):
        L.append(X[i+1] - X[i])
    L = sorted(L, reverse = True)
    S = 0
    for i in range(N-1):
        S += L[i]
    res = X[M-1] - X[0] - S
    print(res)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print(a＊b/2)

Fixed submission:
a, b, c = map(int, input().split())
print(int(a * b / 2))
Buggy python submission (verdict: Runtime Error):
s = int(input())
lst = []
lst.append(s)
i = 2
while true:
  if i % 2 == 0:
    a = i / 2
  else:
    a = 3 * i + 1
  if a in lst:
    print(i)
    break
  lst.append(a)

Fixed submission:
s = int(input())
lst = []
lst.append(s)
a = s
i = 2
while True:
  if a % 2 == 0:
    b = int(a / 2)
  else:
    b = 3 * a + 1
  if b in lst:
    print(i)
    break
  lst.append(b)
  a = b
  i += 1
Buggy python submission (verdict: Runtime Error):
def solve(lst):
    def rec(left, right):
        if left == right:
            return 0
        res = 0
        if not 0 in lst[left:right]:
            m = min(lst)
            for i in range(left, right):
                lst[i] = lst[i] - m
            res += m
        m = 1000
        for i in range(left, right):
            if lst[i] > 0:
                m = min(m, lst[i])
            else:
                for j in range(left, i):
                    lst[j] = lst[j] - m
                if left != i:
                    res += m
                return res + rec(left, i) + rec(i+1, right)
    return rec(0, len(lst))


N = int(input())
lst = list(map(int, input().split()))
print(solve(lst))

Fixed submission:
def rec(lst, left, right):
    if left == right:
        return 0
    if not 0 in lst[left:right]:
        m = min(lst[left:right])
        lst[left:right] = [x - m for x in lst[left:right]]
        return m + rec(lst, left, right)
    k = lst[left:right].index(0)
    return rec(lst, left, left + k) + rec(lst, left + k+1, right)


N = int(input())
lst = list(map(int, input().split()))
print(rec(lst, 0, len(lst)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lst = list(map(int, input().split()))
res = 0
pre_left = 0
while True:
  Max = 0
  w = 0
  left = 0
  right = n
  flag = False
  for i in range(n):
    if lst[i] > 0 and not flag:
      if i == n-1:
        if Max:
          break
      w = 1
      pre_left = left
      left = i
      flag = True
      if i == n-1:
        right = n
        Max = 1
    elif lst[i] > 0 and flag:
      w += 1
      if i == n-1:
        if Max < w:
          Max = w
          right = n
        else:
          left = pre_left
    elif lst[i] <= 0 and flag:
      if Max < w:
        Max = w
        right = i
        flag = False
      else:
        left = pre_left
      w = 0
  if w == n:
    Max = n
  if Max == 0:
    break
  d = min(lst[left:right])
  for i in range(left, right):
    lst[i] -= d
  res += d
      
print(res)

Fixed submission:
def rec(lst, left, right):
    if left == right:
        return 0
    if not 0 in lst[left:right]:
        m = min(lst[left:right])
        lst[left:right] = [x - m for x in lst[left:right]]
        return m + rec(lst, left, right)
    k = lst[left:right].index(0)
    return rec(lst, left, left + k) + rec(lst, left + k+1, right)


N = int(input())
lst = list(map(int, input().split()))
print(rec(lst, 0, len(lst)))