Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def calc(cum, p1, p2, p3):
    arr = [0]*4
    arr[0] = cum[p1]
    arr[1] = cum[p2] - cum[p1]
    arr[2] = cum[p3] - cum[p2]
    arr[3] = cum[-1] - cum[p3]
    return max(arr) - min(arr)

def main():
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(n-1):
        a[i+1] += a[i]
    ans = float("inf")
    for i in range(1, n-2):
        p2 = i
        v = a[i]
        L, R = 0, p2
        while L+1 < R:
            P = (L+R)//2
            if a[P] <= v//2:
                L = P
            else:
                R = P
        p1 = L
        L, R = -1, p2-1
        while L+1 < R:
            P = (L+R+1)//2
            if a[P] <= v//2:
                L = P
            else:
                R = P
        p1_ = R
        L, R = p2+1, n-1
        while L+1 < R:
            P = (L+R)//2
            if a[P]-v <= (a[-1]-v)//2:
                L = P
            else:
                R = P
        p3 = L
        L, R = p2, n-2
        while L+1 < R:
            P = (L+R+1)//2
            if a[P]-v <= (a[-1]-v)//2:
                L = P
            else:
                R = P
        p3_ = R
        arr = [0]*4
        arr[0] = calc(a, p1, p2, p3)
        arr[1] = calc(a, p1_, p2, p3)
        arr[2] = calc(a, p1, p2, p3_)
        arr[3] = calc(a, p1_, p2, p3_)
        x = min(arr)
        if x < ans:
            ans = x
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
def calc(cum, p1, p2, p3):
    arr = [0]*4
    arr[0] = cum[p1]
    arr[1] = cum[p2] - cum[p1]
    arr[2] = cum[p3] - cum[p2]
    arr[3] = cum[-1] - cum[p3]
    return max(arr) - min(arr)

def main():
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(n-1):
        a[i+1] += a[i]
    ans = float("inf")
    for i in range(1, n-2):
        p2 = i
        v = a[i]
        L, R = 0, p2
        while L+1 < R:
            P = (L+R)//2
            if a[P] <= v//2:
                L = P
            else:
                R = P
        p1 = L
        L, R = -1, p2-1
        while L+1 < R:
            P = (L+R+1)//2
            if a[P] <= v//2:
                L = P
            else:
                R = P
        p1_ = R
        L, R = p2+1, n-1
        while L+1 < R:
            P = (L+R)//2
            if a[P]-v <= (a[-1]-v)//2:
                L = P
            else:
                R = P
        p3 = L
        L, R = p2, n-2
        while L+1 < R:
            P = (L+R+1)//2
            if a[P]-v <= (a[-1]-v)//2:
                L = P
            else:
                R = P
        p3_ = R
        arr = [0]*4
        arr[0] = calc(a, p1, p2, p3)
        arr[1] = calc(a, p1_, p2, p3)
        arr[2] = calc(a, p1, p2, p3_)
        arr[3] = calc(a, p1_, p2, p3_)
        x = min(arr)
        if x < ans:
            ans = x
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    b = [0]*n
    f = True
    ans = 0
    for i in reversed(range(n)):
        if i < a[i] or a[i] < b[i]:
            f = False
            break
        if b[i] < a[i]:
            for j in range(i-a[i], i):
                ans += 1
                b[j+1] = b[j]+1
    if f:
        print(ans)
    else:
        print(-1)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    f = True
    ans = 0
    L = n-1
    for i in reversed(range(n)):
        if i < a[i] or a[i] < i-L:
            f = False
            break
        if i-L < a[i]:
            ans += a[i]
            L = i - a[i]
    if f:
        print(ans)
    else:
        print(-1)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = [input() for _ in range(n)]
    ans = 0
    for j in range(n):
        f = True
        for i in range(n-1):
            for k in range(i+1, n):
                if a[(0+i)%n][(j+k)%n] != a[(0+k)%n][(j+i)%n]:
                    f = False
                    break
            if not f:
                break
        if f:
            ans += n
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n = int(input())
    a = [input() for _ in range(n)]
    ans = 0
    for j in range(n):
        f = True
        for i in range(n-1):
            for k in range(i+1, n):
                if a[(0+i)%n][(j+k)%n] != a[(0+k)%n][(j+i)%n]:
                    f = False
                    break
            if not f:
                break
        if f:
            ans += n
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = [input() for _ in range(n)]
    ans = 0
    for j in range(n):
        f = True
        for i in range(n):
            for k in range(n):
                if a[(0+i)%n][(j+k)%n] != a[(0+k)%n][(j+i)%n]:
                    f = False
                    break
            if not f:
                break
        if f:
            ans += n
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n = int(input())
    a = [input() for _ in range(n)]
    ans = 0
    for j in range(n):
        f = True
        for i in range(n-1):
            for k in range(i+1, n):
                if a[(0+i)%n][(j+k)%n] != a[(0+k)%n][(j+i)%n]:
                    f = False
                    break
            if not f:
                break
        if f:
            ans += n
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = [input() for _ in range(n)]
    ans = 0
    for i in range(n):
        a[i] += a[i][:-1]
    for j in range(n):
        f = True
        for i in range(n):
            for k in range(n):
                if a[0+i][j+k] != a[0+k][j+i]:
                    f = False
                    break
            if not f:
                break
        if f:
            ans += n
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n = int(input())
    a = [input() for _ in range(n)]
    ans = 0
    for j in range(n):
        f = True
        for i in range(n-1):
            for k in range(i+1, n):
                if a[(0+i)%n][(j+k)%n] != a[(0+k)%n][(j+i)%n]:
                    f = False
                    break
            if not f:
                break
        if f:
            ans += n
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n, c = map(int, input().split())
    sushi = [None]*n
    for i in range(n):
        sushi[i] = list(map(int, input().split()))
    cal_r = [None] * n
    cal_l = [None] * n
    max_r = [None] * n
    max_l = [None] * n
    cal_r[0] = sushi[0][1] - sushi[0][0]
    max_r[0] = cal_r[0]
    for i in range(1, n):
        cal_r[i] = cal_r[i-1] + sushi[i][1] - (sushi[i][0] - sushi[i-1][0])
        max_r[i] = max(max_r[i-1], cal_r[i])
    cal_l[n-1] = sushi[n-1][1] - (c - sushi[n-1][0])
    max_l[n-1] = cal_l[n-1]
    for i in reversed(range(n-1)):
        cal_l[i] = cal_l[i+1] + sushi[i][1] - (sushi[i+1][0] - sushi[i][0])
        max_l[i] = max(max_l[i+1], cal_l[i])
    ans = max(0, *max_r, *max_l)
    cal_r_2 = [None] * n
    cal_l_2 = [None] * n
    cal_r_2[n-1] = 0
    cal_l_2[0] = 0
    for i in range(n-1):
        cal_r_2[i] = cal_r[i] - sushi[i][0] + max_l[i+1]
    for i in reversed(range(1, n)):
        cal_l_2[i] = cal_l[i] - (c - sushi[i][0]) + max_r[i-1]
    ans = max(ans, *cal_r_2, *cal_l_2)
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n, c = map(int, input().split())
    sushi = [None]*n
    for i in range(n):
        sushi[i] = list(map(int, input().split()))
    cal_r = [None] * n
    cal_l = [None] * n
    max_r = [None] * n
    max_l = [None] * n
    cal_r[0] = sushi[0][1] - sushi[0][0]
    max_r[0] = cal_r[0]
    for i in range(1, n):
        cal_r[i] = cal_r[i-1] + sushi[i][1] - (sushi[i][0] - sushi[i-1][0])
        max_r[i] = max(max_r[i-1], cal_r[i])
    cal_l[n-1] = sushi[n-1][1] - (c - sushi[n-1][0])
    max_l[n-1] = cal_l[n-1]
    for i in reversed(range(n-1)):
        cal_l[i] = cal_l[i+1] + sushi[i][1] - (sushi[i+1][0] - sushi[i][0])
        max_l[i] = max(max_l[i+1], cal_l[i])
    max_r_1 = max(max_r)
    max_l_1 = max(max_l)
    ans = max(0, max_r_1, max_l_1)
    cal_r_2 = [None] * n
    cal_l_2 = [None] * n
    cal_r_2[n-1] = 0
    cal_l_2[0] = 0
    for i in range(n-1):
        cal_r_2[i] = cal_r[i] - sushi[i][0] + max_l[i+1]
    for i in reversed(range(1, n)):
        cal_l_2[i] = cal_l[i] - (c - sushi[i][0]) + max_r[i-1]
    max_r_2 = max(cal_r_2)
    max_l_2 = max(cal_l_2)
    ans = max(ans, max_l_2, max_r_2)
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def calc(n, N, x):
    m, M = -1, -1
    L, R = 0, 10**18
    while L+1 < R:
        P = (L+R)//2
        if n <= x*P:
            R = P
        else:
            L = P
    if n <= x*R <= N:
        m = x*R
    L, R = 0, 10**18
    while L+1 < R:
        P = (L+R)//2
        if N < x*P:
            R = P
        else:
            L = P
    if n <= x*L <= N:
        M = x*L + (x-1)
    return m, M

def main():
    k = int(input())
    a = list(map(int, input().split()))
    f = True
    m, M = 2, 2
    for i in reversed(range(k)):
        m, M = calc(m, M, a[i])
        if m == -1 or M == -1:
            f = False
            break
    if f:
        print(m, M)
    else:
        print(-1)

if __name__ == "__main__":
    main()

Fixed submission:
def calc(n, N, x):
    m, M = -1, -1
    L, R = 0, 10**13
    while L+1 < R:
        P = (L+R)//2
        if n <= x*P:
            R = P
        else:
            L = P
    if n <= x*R <= N:
        m = x*R
    L, R = 0, 10**13
    while L+1 < R:
        P = (L+R)//2
        if N < x*P:
            R = P
        else:
            L = P
    if n <= x*L <= N:
        M = x*L + (x-1)
    return m, M

def main():
    k = int(input())
    a = list(map(int, input().split()))
    f = True
    m, M = 2, 2
    for i in reversed(range(k)):
        m, M = calc(m, M, a[i])
        if m == -1 or M == -1:
            f = False
            break
    if f:
        print(m, M)
    else:
        print(-1)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = map(int, input().split())
    arr = [list(map(int, input().split())) for _ in range(n)]
    ans = 0
    for a, b in arr:
        f = True
        for i in range(32):
            if k & (1<<i) == 0 and a & (1<<i) != 0:
                f = False
                break
        if f:
            ans += b
    for i in range(32):
        p = 1<<i
        tmp = 0
        if p & k == 0:
            continue
        for a, b in arr:
            if a <= k and a&p == 0:
                f = True
                for j in range(i+1, 32):
                    if k & (1<<j) == 0 and a & (1<<j) != 0:
                        f = False
                        break
                if f:
                    tmp += b
        if ans < tmp:
            ans = tmp
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n, k = map(int, input().split())
    arr = [list(map(int, input().split())) for _ in range(n)]
    ans = 0
    for a, b in arr:
        f = True
        for i in range(32):
            if k & (1<<i) == 0 and a & (1<<i) != 0:
                f = False
                break
        if f:
            ans += b
    for i in range(32):
        p = 1<<i
        tmp = 0
        if p & k == 0:
            continue
        for a, b in arr:
            if a <= k and a&p == 0:
                f = True
                for j in range(i+1, 32):
                    if k & (1<<j) == 0 and a & (1<<j) != 0:
                        f = False
                        break
                if f:
                    tmp += b
        if ans < tmp:
            ans = tmp
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    ans = 0
    if sum(a) >= k:
        for i in range(n):
            if k <= a[i]:
                continue
            dp = np.zeros((k+1), dtype=np.bool)
            dp[0] = True
            for j in range(n):
                if k <= a[j] or j == i:
                    continue
                dp[a[j]:] |= dp[:-a[j]]
            f = False
            for j in range(k-a[i], k):
                f |= dp[j]
            if not f:
                ans += 1
    else:
        ans = n
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import numpy as np

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    if sum(a) >= k:
        a.sort()
        L, R = -1, n-1
        while L+1 < R:
            P = (L+R+1)//2
            if k <= a[P]:
                R = P
                continue
            dp = np.zeros((k+1), dtype=np.bool)
            dp[0] = True
            for j in range(n):
                if k <= a[j] or j == P:
                    continue
                dp[a[j]:] |= dp[:-a[j]]
            f = False
            for j in range(k-a[P], k):
                f |= dp[j]
            if f:
                R = P
            else:
                L = P
        print(R)
    else:
        print(n)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(n):
        if k <= a[i]:
            continue
        dp = np.zeros((k+1), dtype=np.bool)
        dp[0] = True
        for j in range(n):
            if k <= a[j] or j == i:
                continue
            dp[a[j]:] |= dp[:-a[j]]
        f = False
        for j in range(k-a[i], k):
            f |= dp[j]
        if not f:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import numpy as np

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    if sum(a) >= k:
        a.sort()
        L, R = -1, n-1
        while L+1 < R:
            P = (L+R+1)//2
            if k <= a[P]:
                R = P
                continue
            dp = np.zeros((k+1), dtype=np.bool)
            dp[0] = True
            for j in range(n):
                if k <= a[j] or j == P:
                    continue
                dp[a[j]:] |= dp[:-a[j]]
            f = False
            for j in range(k-a[P], k):
                f |= dp[j]
            if f:
                R = P
            else:
                L = P
        print(R)
    else:
        print(n)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def mid(x, y, z):
    if x <= y <= z or z <= y <= x:
        return y
    elif y <= x <= z or z <= x <= y:
        return x
    return z

def test():
    from random import shuffle
    for _ in range(5):
        arr = [i for i in range(1, 11 + 1)]
        shuffle(arr)
        print(arr, end=" : ")
        while len(arr) > 1:
            tmp = [mid(arr[i], arr[i+1], arr[i+2]) for i in range(len(arr)-2)]
            arr = tmp
        print(arr[0])

def main():
    n, x = map(int, input().split())
    if x == 1 or x == 2*n-1:
        print("No")
    else:
        print("Yes")
        if n == 2:
            for i in range(1, 4):
                print(i)
        else:
            ans = [None]*(2*n - 1)
            st = set(i for i in range(1, 2*n))
            ans[n-1] = x
            st.remove(x)
            if x == 2:
                ans[n-3] = 4
                ans[n-2] = 1
                ans[n] = 3
                st.remove(1)
                st.remove(3)
                st.remove(4)
            else:
                ans[n-3] = x-2
                ans[n-2] = x+1
                ans[n] = x-1
                st.remove(x-2)
                st.remove(x+1)
                st.remove(x-1)
            for i in range(2*n-1):
                if ans[i] is None:
                    rm = -1
                    for v in st:
                        rm = v
                        break
                    ans[i] = rm
                    st.remove(rm)
            for v in ans:
                print(v)

if __name__ == "__main__":
    main()

Fixed submission:
def mid(x, y, z):
    if x <= y <= z or z <= y <= x:
        return y
    elif y <= x <= z or z <= x <= y:
        return x
    return z

def test():
    from random import shuffle
    for _ in range(5):
        arr = [i for i in range(1, 11 + 1)]
        shuffle(arr)
        print(arr, end=" : ")
        while len(arr) > 1:
            tmp = [mid(arr[i], arr[i+1], arr[i+2]) for i in range(len(arr)-2)]
            arr = tmp
        print(arr[0])

def main():
    n, x = map(int, input().split())
    if x == 1 or x == 2*n-1:
        print("No")
    else:
        print("Yes")
        if n == 2:
            for i in range(1, 4):
                print(i)
        else:
            ans = [None]*(2*n - 1)
            st = set(i for i in range(1, 2*n))
            ans[n-1] = x
            st.remove(x)
            if x == 2:
                ans[n-3] = 4
                ans[n-2] = 1
                ans[n] = 3
                st.remove(1)
                st.remove(3)
                st.remove(4)
            else:
                ans[n-3] = x-2
                ans[n-2] = x+1
                ans[n] = x-1
                st.remove(x-2)
                st.remove(x+1)
                st.remove(x-1)
            for i in range(2*n-1):
                if ans[i] is None:
                    ans[i] = st.pop()
            for v in ans:
                print(v)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
s = input()
if s.contains("RRR"):
  print(3)
elif s.contains("RR"):
  print(2)
elif s.contains("R"):
  print(1)
else:
  print(0)

Fixed submission:
s = input()
if "RRR" in s:
  print(3)
elif "RR" in s:
  print(2)
elif "R" in s:
  print(1)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
import sys
s = sys.stdin.readline()
print eval(s)

Fixed submission:
import sys
s = sys.stdin.readline()
print(eval(s))
Buggy python submission (verdict: Runtime Error):
import re
n=int(input())

s = ""
for _ in range(n):
    d1,d2 = input().split()
    if d1==d2:
        s+="1"
    else:
        s+="0"
#print(s)
a = max([len(x) for x in re.findall(r"1+", s)])
if a >= 3:
    print("Yes")
else:
    print("No")

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

s = ""
for _ in range(n):
    d1,d2 = input().split()
    if d1==d2:
        s+="1"
    else:
        s+="0"
#print(s)
try:
    a = max([len(x) for x in re.findall(r"1+", s)])
    if a >= 3:
        print("Yes")
    else:
        print("No")
except:
    print("No")
Buggy python submission (verdict: Runtime Error):
S=list(input())                                                                                                                                        
T=list(input())                                                                                                                                        
                                                                                                                                                       
T_size = len(T)                                                                                                                                        
                                                                                                                                                       
def match_num(x):                                                                                                                                      
    return T_size - sum([1 for a,t in zip(x, T) if a==t])                                                                                              
                                                                                                                                                       
b=[]                                                                                                                                                   
for i in range(len(S)-T_size):                                                                                                                         
    b.append(match_num(S[i:i+T_size]))                                                                                                                 
                                                                                                                                                       
print(min(b))

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

size = len(t)
ms = []
for i in range(len(s)-size+1):
    # print(s[i:i+size])
    m = sum([a==b for a,b in zip(s[i:i+size], t)])
    ms.append(m)

print(size - max(ms))
Buggy python submission (verdict: Runtime Error):
from itertools import combinations


N,M,X=map(int,input().split())

mtable = [None]*N
cs = []
for n in range(N):
    aa = list(map(int,input().split()))
    c = aa.pop(0)
    cs.append(c)
    ms = aa
    mtable[n] = ms
    

# print(mtable)
idxes = list(range(N))

prices = []
for i in range(1, N+1):
    for c in combinations(idxes, i):
        sums = [0]*M
        for idx in c:
            for i, m in enumerate(mtable[idx]):
                sums[i] += m
        if all(map(lambda x:x >= X, sums)):
            price = 0
            for idx in c:
                price += cs[idx]

            prices.append(price)
print(min(prices))

Fixed submission:
from itertools import combinations


N,M,X=map(int,input().split())

mtable = [None]*N
cs = []
for n in range(N):
    aa = list(map(int,input().split()))
    c = aa.pop(0)
    cs.append(c)
    ms = aa
    mtable[n] = ms
    

# print(mtable)
idxes = list(range(N))

prices = []
for i in range(1, N+1):
    for c in combinations(idxes, i):
        sums = [0]*M
        for idx in c:
            for i, m in enumerate(mtable[idx]):
                sums[i] += m
        if all(map(lambda x:x >= X, sums)):
            price = 0
            for idx in c:
                price += cs[idx]

            prices.append(price)
if prices == []:
    print(-1)
else:
    print(min(prices))