Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(list(input()))
lr = [[0] * w for i in range(h)]
#print(lr)
for i in range(h):
    cnt = 0
    lis = []
    for j in range(w):

        if s[i][j] == '#':
            lis.append(cnt)
            cnt = 0
        elif j == w-1:
            if s[i][j] == '.':
                cnt += 1
            lis.append(cnt)
        else:
            cnt += 1
    p = 0
    #print(lis)
    for j in range(w):
        if s[i][j] == '.':
            #print(p)
            #print(lr)
            lr[i][j] = lis[p]
        else:
            p += 1
#print(lr)

ud = [[0] * w for i in range(h)]
#print(ud)
for j in range(w):
    cnt = 0
    lis = []
    for i in range(h):
        #print(s[i][j])
        if s[i][j] == '#':
            lis.append(cnt)
            cnt = 0
        elif i == h-1:
            if s[i][j] == '.':
                cnt += 1
            lis.append(cnt)
        else:
            cnt += 1
    p = 0
    #print(lis)
    for i in range(h):
        #print(p,i,j,)
        #print(lis[p])
        #print(ud[j][i])
        if s[i][j] == '.':
            #print(p)
            #print(lr)
            ud[i][j] = lis[p]
        else:
            p += 1
        #print(p)
#print(ud)
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, lr[i][j] + ud[i][j] - 1)
print(ans)


Fixed submission:
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(list(input()))
lr = [[0] * w for i in range(h)]
#print(lr)
for i in range(h):
    cnt = 0
    lis = []
    for j in range(w):

        if s[i][j] == '#':
            lis.append(cnt)
            cnt = 0
        elif j == w-1:
            if s[i][j] == '.':
                cnt += 1
            lis.append(cnt)
        else:
            cnt += 1
    p = 0
    #print(lis)
    for j in range(w):
        if s[i][j] == '.':
            #print(p)
            #print(lr)
            lr[i][j] = lis[p]
        else:
            p += 1
#print(lr)

ud = [[0] * w for i in range(h)]
#print(ud)
for j in range(w):
    cnt = 0
    lis = []
    for i in range(h):
        #print(s[i][j])
        if s[i][j] == '#':
            lis.append(cnt)
            cnt = 0
        elif i == h-1:
            if s[i][j] == '.':
                cnt += 1
            lis.append(cnt)
        else:
            cnt += 1
    p = 0
    #print(lis)
    for i in range(h):
        #print(p,i,j,)
        #print(lis[p])
        #print(ud[j][i])
        if s[i][j] == '.':
            #print(p)
            #print(lr)
            ud[i][j] = lis[p]
        else:
            p += 1
        #print(p)
#print(ud)
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, lr[i][j] + ud[i][j] - 1)
print(ans)
Buggy python submission (verdict: Runtime Error):
3
5 2 4

Fixed submission:
import math

n,k =  map(int,input().split())
lis = []
for i in range(n):
    if i+1 >= k:
        lis.append(0)
    else:
        lis.append(math.ceil(math.log2((k/(i+1)))))

#print(lis)


ans = []
for i in range(n):
    ans.append(1/n * (1/2)**lis[i])

print(sum(ans))
Buggy python submission (verdict: Time Limit Exceeded):
r, g, b, n = map(int,input().split())
cnt = 0
for i in range(n+1):
    for j in range(n+1):
        if ((n - ((i*r) + j*g)) % b == 0) and ((n - ((i*r) + (j*g))) >= 0) :
            #print(n - (i*r) + (j*g))
            cnt += 1
print(cnt)

Fixed submission:
r, g, b, n = map(int, input().split())
cnt = 0
for i in range(n+1):
    for j in range(n+1):
        if ((n - (r*(i) + g*(j))) >= 0) and ((n - (r*(i) + g*(j))) % b == 0):
            cnt += 1
            #print(i)
            #print(j)
print(cnt)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())


def f(keta, x):
    val = 2**keta
    if x < (2 ** (keta)):
        return False
    else:
        x -= (val-1)
        ans = x // (2*val) * val
        ans += min(val,x-val*2*(x//(2*val)))
        return ans

ans = []
i = 0
while f(i,b) != False:
    #print(i)
    val = f(i,b)
    if f(i,a-1) != False:
        val -= f(i,a-1)
    #print(val)
    ans += str(val % 2)
    i += 1
ans.reverse()
print(int(''.join(ans),2))

# print(ans)
# print(f(2, 4))
# print(f(1,4))
# print(bin(435))
# print(f(0,4),f(0,1))


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


def f(keta, x):
    val = 2**keta
    if x < (2 ** (keta)):
        return False
    else:
        x -= (val-1)
        ans = x // (2*val) * val
        ans += min(val,x-val*2*(x//(2*val)))
        return ans
if b == 0:
    print(0)
    exit()
ans = []
i = 0
while f(i,b) != False:
    #print(i)
    val = f(i,b)
    if f(i,a-1) != False:
        val -= f(i,a-1)
    #print(val)
    ans += str(val % 2)
    i += 1

ans.reverse()
print(int(''.join(ans),2))

# print(ans)
# print(f(2, 4))
# print(f(1,4))
# print(bin(435))
# print(f(0,4),f(0,1))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ln = len(s)
for _ in range(100000):
    s = s.replace('10', '').replace('01', '')
#print(s)
print(ln - len(s))


Fixed submission:
s = input()

red = s.count('0')
blue = s.count('1')

print(min(red, blue) * 2)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
INF = 10**11
A,B,Q = map(int,input().split())
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(B)] + [INF]
def binary_search(lis,x):
    ok = 0
    ng = len(lis)-1
    while ng-ok > 1:
        mid = (ok+ng)//2
        if lis[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok
#print(s,t)
for _ in range(Q):
    x = int(input())
    ps = binary_search(s,x)
    pt = binary_search(t,x)
    ans = INF
    #print(ps,pt)
    for i in range(ps,ps+2):
        for j in range(pt,pt+2):
            ans = min(ans,abs(s[i]-X)+abs(s[i]-t[j]), abs(t[j]-X)+abs(t[j]-s[i]))
    print(ans)  
            


Fixed submission:
import sys
input = sys.stdin.readline
INF = 10**11
A,B,Q = map(int,input().split())
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
s.sort()
t = [-INF] + [int(input()) for _ in range(B)] + [INF]
t.sort()
def binary_search(lis,x):
    ok = 0
    ng = len(lis)-1
    while ng-ok > 1:
        mid = (ok+ng)//2
        if lis[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok
#print(s,t)
for _ in range(Q):
    x = int(input())
    ps = binary_search(s,x)
    pt = binary_search(t,x)
    ans = INF
    #print(ps,pt)
    for i in range(ps,ps+2):
        for j in range(pt,pt+2):
            ds = x - s[i]
            dt = x - t[j]
            
            if (ds < 0 and dt < 0) or (ds > 0 and dt > 0):
                ans = min(ans,max(abs(ds),abs(dt)))
            else:
                ans = min(ans,abs(ds)+abs(dt)+min(abs(ds),abs(dt)))
    print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque
N = int(input())
lis = []

A = []
B = []
for i in range(N):
    Ain,Bin = map(int,input().split())
    A.append(Ain)
    B.append(Bin)
    lis.append((Ain+Bin,i))
lis.sort()
lis.reverse()
lis = deque(lis)

takacnt = 0
aocnt = 0

# print(taka)
# print(ao)

for i in range(N):
    if i % 2 == 0:
        val = lis.popleft()
        st.add(val[1])
        takacnt += A[val[1]]
    else:
        val = lis.popleft()
        st.add(val[1])
        aocnt += B[val[1]]
print(takacnt-aocnt)


Fixed submission:
from collections import deque
N = int(input())
taka = []
ao = []
A = []
B = []
for i in range(N):
    Ain,Bin = map(int,input().split())
    A.append(Ain)
    B.append(Bin)
    taka.append((Bin+Ain,i))
    ao.append((Ain+Bin,i))
taka.sort()
taka.reverse()
ao.sort()
ao.reverse()
taka = deque(taka)
ao = deque(ao)
takacnt = 0
aocnt = 0
st = set()

# print(taka)
# print(ao)

for i in range(N):
    if i % 2 == 0:
        while True:
            val = taka.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        takacnt += A[val[1]]
    else:
        while True:
            val = ao.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        aocnt += B[val[1]]
print(takacnt-aocnt)

Buggy python submission (verdict: Runtime Error):
from collections import deque
N = int(input())
lis = []

A = []
B = []
for i in range(N):
    Ain,Bin = map(int,input().split())
    A.append(Ain)
    B.append(Bin)
    lis.append((Ain+Bin,i))
lis.sort()
lis.reverse()
lis = deque(taka)

takacnt = 0
aocnt = 0
st = set()

# print(taka)
# print(ao)

for i in range(N):
    if i % 2 == 0:
        while True:
            val = lis.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        takacnt += A[val[1]]
    else:
        while True:
            val = lis.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        aocnt += B[val[1]]
print(takacnt-aocnt)


Fixed submission:
from collections import deque
N = int(input())
taka = []
ao = []
A = []
B = []
for i in range(N):
    Ain,Bin = map(int,input().split())
    A.append(Ain)
    B.append(Bin)
    taka.append((Bin+Ain,i))
    ao.append((Ain+Bin,i))
taka.sort()
taka.reverse()
ao.sort()
ao.reverse()
taka = deque(taka)
ao = deque(ao)
takacnt = 0
aocnt = 0
st = set()

# print(taka)
# print(ao)

for i in range(N):
    if i % 2 == 0:
        while True:
            val = taka.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        takacnt += A[val[1]]
    else:
        while True:
            val = ao.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        aocnt += B[val[1]]
print(takacnt-aocnt)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * n
for i in range(1, n):
    mn = int(1e10)


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

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * n
for i in range(1, n):
    mn = int(1e10)


    for j in range(1,min(i,k)+1):
        if abs(h[i] - h[i-j]) + dp[i-j] < mn:
            mn = abs(h[i] - h[i-j]) + dp[i-j]
    dp[i] = mn
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
lis = [[0, 0]]
for i in  range(n):
    lis.append(list(map(int, input().split())))

dp = [[0 for i in range(w+1)] for i in range(n+1)]
#print(dp)
#print(lis)

for i in range(1, n+1):
    for j in range(w+1):
        if j - lis[i][0] < 0:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-lis[i][0]] + lis[i][1])
print(dp[n][w])

Fixed submission:
n, w = map(int, input().split())
lis = [[0, 0]]
for i in  range(n):
    lis.append(list(map(int, input().split())))

dp = [[0 for i in range(w+1)] for i in range(n+1)]
#print(dp)
#print(lis)

for i in range(1, n+1):
    for j in range(w+1):
        if j - lis[i][0] < 0:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-lis[i][0]] + lis[i][1])
print(dp[n][w])
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
val = m//n
i = val
while i > 0 :
    if m % i == 0:
        print(i)
        exit()
    i -= 1

Fixed submission:
n, m = map(int, input().split())
val = m//n
i = val
while i > 0 :
    if m % i == 0:
        print(i)
        exit()
    i -= 1
Buggy python submission (verdict: Runtime Error):
s = list(input())
t = list(input())
dic = {}
flg = 'Yes'
for i in range(len(s)):
    if s[i] in dic.keys():
        if t[i] !=  dic.values(s[i]):
            flg = 'No'
    else:
        dic[s[i]] = t[i]
print(flg)

Fixed submission:
s = list(input())
t = list(input())
dic = {}
flg = 'Yes'
for i in range(len(s)):
    if s[i] in dic.keys():
        if dic[s[i]] != t[i]:
            flg = 'No'
    else:
        dic[s[i]] = t[i]
dic2 = {}
for i in range(len(s)):
    if t[i] in dic2.keys():
        if dic2[t[i]] != s[i]:
            flg = 'No'
    else:
        dic2[t[i]] = s[i]
#print(dic)
print(flg)
Buggy python submission (verdict: Runtime Error):
import fractions
import math

n,X= map(int,input().split())
x = list(map(int, input().split()))
x.append(x)
x = sorted(X)

#print(x)

difflis = [0] * (n)

for i in range(n):
    difflis[i] = math.fabs(x[i+1] - x[i])

ans = difflis[0]
for i in range(i,len(difflis)):
    ans = fractions.gcd(ans,difflis[i])
print(int(ans))

Fixed submission:
import fractions


n,X= map(int,input().split())
x = list(map(int, input().split()))
x.append(X)
x = sorted(x)

#print(x)

difflis = [0] * (n)

for i in range(n):
    difflis[i] = x[i+1] - x[i]

ans = difflis[0]
for i in range(1,len(difflis)):
    ans = fractions.gcd(ans,difflis[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
import fractions
import math

n,X= map(int,input().split())
x = list(map(int, input().split()))
ins = 0
for i in range(n):
    if x[i] >=X:
        ins = i
        break
#x.insert(ins,X)
x = sorted(x)

print(x)

difflis = [0] * (n)

for i in range(n):
    difflis[i] = math.fabs(x[i+1] - x[i])

ans = difflis[0]
for i in range(i,len(difflis)):
    ans = fractions.gcd(ans,difflis[i])
print(int(ans))

Fixed submission:
import fractions


n,X= map(int,input().split())
x = list(map(int, input().split()))
x.append(X)
x = sorted(x)

#print(x)

difflis = [0] * (n)

for i in range(n):
    difflis[i] = x[i+1] - x[i]

ans = difflis[0]
for i in range(1,len(difflis)):
    ans = fractions.gcd(ans,difflis[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque
n = int(input())

lis = set()
def dfs():
    d = ['3','5','7']
    que = deque(['3','5','7'])
    while len(que) != 0:
        val = que.pop()
        #print(val)
        if len(val) < 10:
            #print(len(str(val)))
            for i in range(3):
                val2 = val + d[i]
                #print(val3[-1])
                l = list(val2)
                if '3' in l and '5' in l and '7' in l:
                    lis.add(int(val2))
                que.append(val2)

    return lis
lis = dfs()
ans = 0
for i in lis:
    if int(i) < n:
        ans += 1
print(ans)


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

if k % 2 == 0:
    b = 0
    for i in range(1, n+1):
        if i % k == k // 2:
            b += 1
    print(a ** 3 + b ** 3)
else:
    print(a ** 3)
Buggy python submission (verdict: Runtime Error):
n, m = map(int(input().split()))
if m > 3 and n > 3:
    print((m-2) * (n-2))
else:
    print((max(m,n)-2) * min(m,n))

Fixed submission:
n, m = map(int,input().split())
if m >= 3 and n >= 3:
    print((m-2) * (n-2))
elif (m == 2 or n == 2):
    print(0)
elif m >= 3 or n >= 3:
    print((max(m,n)-2) * min(m,n))
else:
    if (m * n) % 2 == 0:
        print(0)
    else:
        print(m * n)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int(input().split())))
cnt = [0] * int(1e6)
for i in a:
    cnt[i-1] += 1
    cnt[i] += 1
    cnt[i+1] += 1
print(max(cnt))


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
cnt = [0] * int(1e6)
for i in a:
    cnt[i-1] += 1
    cnt[i] += 1
    cnt[i+1] += 1
print(max(cnt))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1
#print(a)

for i in range(n-1):
    for j in range(i+1, n):
        if a[j] > a[i] + 2:
            #print(i, j)
            if (j - i) > ans:
                ans = (j - i)
            break
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
cnt = [0] * int(1e6)
for i in a:
    cnt[i-1] += 1
    cnt[i] += 1
    cnt[i+1] += 1
print(max(cnt))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
    b.append(a[i])
    b.reverse()
for i in range(n):
    print(b[i])


Fixed submission:
from math import ceil
n = int(input())
a = list(map(int, input().split()))
a.reverse()
b = [0] * n
for i in range(n):
    if i % 2 == 0:
        b[i//2] = a[i]
    else:
        b[-(ceil(i/2))] = a[i]

#print(b)
for i in range(n):
    print(b[i])
Buggy python submission (verdict: Runtime Error):
N = int(input())
M = int(input())
for i in range(M):
    a,b = map(int,input().split())

if N % 2 == 0 and M % 2 == 0:
    print('Yes')
else:
    print('No')


Fixed submission:
N,M = map(int,input().split())
lis = [0] * N
for i in range(M):
    a,b = map(int,input().split())
    lis[a-1] += 1
    lis[b-1] += 1
ans = 'YES'
for i in lis:
    if i % 2 == 1:
        ans = 'NO'
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import ceil
x = int(input())
ans = ceil(x / 11 * 2)
if (x % 11) % 6 == 0 or (x % 11) % 5 == 0:

print(ans)

Fixed submission:
x = int(input())
ans = (x // 11 * 2)


if  x % 11 <= 6 and x % 11 != 0:
    ans += 1
elif x % 11 >= 7:
    ans += 2

print(ans)

Buggy python submission (verdict: Runtime Error):
from math import ceil
x = int(input())
ans = ceil(x / 11 * 2)
if (x % 11) % 6 == 0 or if (x % 11) % 5 == 0:

print(ans)

Fixed submission:
x = int(input())
ans = (x // 11 * 2)


if  x % 11 <= 6 and x % 11 != 0:
    ans += 1
elif x % 11 >= 7:
    ans += 2

print(ans)
Buggy python submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.d = [-1] * n

    def find(self, x):
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.d[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        else:
            if self.d[x] > self.d[y]:
                x, y = y, x
            self.d[x] += self.d[y]
            self.d[y] = x
            return True

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


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


n, k, l = map(int, input().split())
uf = UnionFind(n)
for i in range(k):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    uf.unite(p, q)
ans = [1] * n
for i in range(l):
    r, s = map(int, input().split())
    r -= 1
    s -= 1
    if uf.same(r, s) == True:
# print(uf.d)
print(' '.join(map(str, ans)))

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.d = [-1] * n

    def find(self, x):
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.d[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        else:
            if self.d[x] > self.d[y]:
                x, y = y, x
            self.d[x] += self.d[y]
            self.d[y] = x
            return True

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


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


n, k, l = map(int, input().split())
uf1 = UnionFind(n)
for i in range(k):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    uf1.unite(p, q)
uf2 = UnionFind(n)
for i in range(l):
    r, s = map(int, input().split())
    r -= 1
    s -= 1
    uf2.unite(r, s)
dic = {}
for i in range(n):
    val = (uf1.find(i), uf2.find(i))
    if val in dic:
        dic[val] += 1
    else:
        dic[val] = 1

for i in range(n):
    print(dic[(uf1.find(i), uf2.find(i))])
Buggy python submission (verdict: Time Limit Exceeded):
N, X, M = map(int, input().split())

Visited = [0]*(M+1)
Mods = [0]*(M+1)
count = 0

for i in range (0, M):
	if (i**2)%M == i:
		Mods[i]=1
        
latest = 0
        
for i in range (0, N):
	if X in Mods:
		count+=((N-i)*X)
		for j in range (0, M+1):
			count+=(j*Visited[j])
		print(count)
		exit()
	if Visited[X] > 0:
		latest = X
		break
	Visited[X]+= 1
	X = (X**2)%M

P = sum(Visited)

for j in range (0, M+1):
	count+=(j*Visited[j])

Visited = [0]*(M+1)

if P == N:
	print(count)
	exit()

crouch = [0]
looper = 0
debu = 0 

for i in range (0, N-P):
	if Visited[X] > 0:
		looper = i
		debu = 1
		break
	else:
		crouch.append(X+crouch[-1])
	Visited[X]+= 1
	X = (X**2)%M
    
if debu == 0:
	for j in range (0, M+1):
		count+=(j*Visited[j])
	print(count)
	exit()
else:
	loops = 0
	for j in range (0, M+1):
		loops+=(j*Visited[j])
	count+=(loops*((N-P)//looper))
	count+=crouch[(N-P)%looper]
print(count)

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

Visited = [0]*(M+1)
latestvisit = [0]*(M+1)
count = 0
latest = 0
proper = 0
        
for i in range (0, N):
	if Visited[X] > 0:
		latest = X
		latestvisit[X] = i
		proper = 1
		break
	latestvisit[X] = i
	Visited[X]+= 1
	X = (X**2)%M

for j in range (0, M+1):
	count+=(j*Visited[j])

if proper == 0:
	print(count)
	exit()
    
P = sum(Visited)
A = latestvisit[X]
B = latestvisit[(X**2)%M]
slouch = 0

for i in range (0, M):
	if latestvisit[i] >=B and latestvisit[i] <= A:
		slouch+=i

count+=((N-P)//(A-B+1))*slouch


for i in range (0, (N-P)%(A-B+1)):
	count+=X
	X = (X**2)%M

print(count)
Buggy python submission (verdict: Runtime Error):
print(1-input())

Fixed submission:
x = int(input())
print(1-x)
Buggy python submission (verdict: Time Limit Exceeded):
N, M , K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

Used = [0]*M

total_max = 0
A_count = 0
B_count = 0

counter = 0

for i in range (0, N):
	if A[i] <= K and counter ==0:
		A_count+=1
		K-=A[i]
	else:
		counter = 1
		break

counter = 0

for i in range (0, M):
	if B[i] <= K and counter ==0:
		B_count+=1
		K-=B[i]
	else:
		counter = 1
		break

totalmax = A_count+B_count


for i in range (0, A_count):
	counter = 0
	D = K + sum(A[A_count-1-i:A_count])
	for j in range (0, M):
		zencount = A_count-i-1
		if sum(B[0:j]) <= D:
			zencount+=(j+1)
		if zencount >= totalmax:
			totalmax = zencount

print(totalmax)

Fixed submission:
import bisect

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

for i in range (1, N):
    A[i]+=A[i-1]

for i in range (1, M):
    B[i]+=B[i-1]

V = 0
ACount = bisect.bisect_right(A, K)
if ACount !=0:
    V = K- A[ACount-1]
else:
    V=K

AInitial = ACount

BCount = bisect.bisect_right(B, V)
final = ACount+BCount

for i in range (1, AInitial):
    V = K - A[AInitial-1-i]
    BCount = bisect.bisect_right(B, V)
    final = max(final, AInitial-i+BCount)

final = max(final, bisect.bisect_right(B,K))
print(final)

Buggy python submission (verdict: Runtime Error):
N, M , K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

total_max = 0
A_count = 0
B_count = 0

P = K

for i in range (0, N):
	if A[i] < P:
		A_count+=1
		P = P-A[i]
	else:
 		break

for j in range (0, M):
	if B[i] < P:
		B_count+=1
		P = P-B[i]
	else:
 		break

totalmax = A_count+B_count

for i in range (0, A_count):
	D = P + A[A_count-1-i]
	E = D
	zencount = A_count-(i+1)
	for j in range (0, M):
		if B[j] < E:
			E-=B[j]
			zencount+=1
		else:
			break
	if zencount >= totalmax:
		totalmax = zencount

print(totalmax)


Fixed submission:
import bisect

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

for i in range (1, N):
    A[i]+=A[i-1]

for i in range (1, M):
    B[i]+=B[i-1]

V = 0
ACount = bisect.bisect_right(A, K)
if ACount !=0:
    V = K- A[ACount-1]
else:
    V=K

AInitial = ACount

BCount = bisect.bisect_right(B, V)
final = ACount+BCount

for i in range (1, AInitial):
    V = K - A[AInitial-1-i]
    BCount = bisect.bisect_right(B, V)
    final = max(final, AInitial-i+BCount)

final = max(final, bisect.bisect_right(B,K))
print(final)