Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys,queue,math,copy,itertools,bisect,collections
LI = lambda : [int(x) for x in sys.stdin.readline().split()]

N,M = LI()
data = [LI() for _ in range(N)]
dp = [0] * (M+1)

data.sort(key=lambda x:x[1], reverse=True)
for a,b in data:
    for i in range(M-a,-1,-1):
        if b > dp[i]:
            dp[i] = b
            break
print(sum(dp))

Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections
LI = lambda : [int(x) for x in sys.stdin.readline().split()]

N,M = LI()
data = [LI() for _ in range(N)]
dp = [0] * (M+1)
data.sort(key=lambda x:x[1], reverse=True)

N0 = 2 ** M.bit_length()
seg = [0] * (2*N0)

def seg_set(i,x):
    i = i + N0- 1
    seg[i] = x
    while i > 0:
        i = (i-1) // 2
        seg[i] = max(seg[i*2+1],seg[i*2+2])

def seg_query(i):
    i = i + N0 - 1
    ret = seg[i]
    while i ^ (i+1) < i+1:
        i = (i-2) // 2
        ret = max(ret,seg[i])
    return ret

for i in range(M+1):
    seg_set(i,i)

for a,b in data:
    if a <= M:
        i = seg_query(M-a+1)
        if i > 0:
            dp[i] = b
            seg_set(i,0)
print(sum(dp))
Buggy python submission (verdict: Time Limit Exceeded):
import sys,queue,math,copy,itertools,bisect,collections
MOD = 10**9 + 7
S = sys.stdin.readline().rstrip()
dp = [[0] * 13 for _ in range(len(S)+1)]
dp[0][0] = 1

for i in range(1,len(S)+1):
    x = S[i-1]
    if x == '?':
        for j in range(10):
            for k in range(13):
                dp[i][(k * 10 + j) % 13] += dp[i - 1][k]
    else:
        for k in range(13):
            dp[i][(k * 10 + int(x)) % 13] += dp[i - 1][k]
    for j in range(13):
        dp[i][j] %= MOD

print (dp[-1][5])


Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections
MOD = 10**9 + 7
S = sys.stdin.readline().rstrip()
dp = [[0] * 13 for _ in range(len(S)+1)]
dp[0][0] = 1

for i in range(1,len(S)+1):
    x = S[i-1]
    if x == '?':
        for j in range(10):
            for k in range(13):
                dp[i][(k * 10 + j) % 13] += dp[i - 1][k]
    else:
        for k in range(13):
            dp[i][(k * 10 + int(x)) % 13] += dp[i - 1][k]
    for j in range(13):
        dp[i][j] %= MOD

print (dp[-1][5])

Buggy python submission (verdict: Time Limit Exceeded):
import sys,queue,math,copy,itertools,bisect,collections
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()
dp = [[0] * 13 for _ in range(len(S)+1)]
dp[0][0] = 1

def add_dp(i,j):
    for k in range(13):
        l = (k * 10 + j) % 13
        dp[i][l] += dp[i-1][k]

for i in range(1,len(S)+1):
    x = S[i-1]
    if x == '?':
        for j in range(10):
            add_dp(i,j)
    else:
        add_dp(i,int(x))
    for j in range(13):
        dp[i][j] %= MOD

print (dp[-1][5])


Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections
MOD = 10**9 + 7
S = sys.stdin.readline().rstrip()
dp = [[0] * 13 for _ in range(len(S)+1)]
dp[0][0] = 1

for i in range(1,len(S)+1):
    x = S[i-1]
    if x == '?':
        for j in range(10):
            for k in range(13):
                dp[i][(k * 10 + j) % 13] += dp[i - 1][k]
    else:
        for k in range(13):
            dp[i][(k * 10 + int(x)) % 13] += dp[i - 1][k]
    for j in range(13):
        dp[i][j] %= MOD

print (dp[-1][5])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
A = [int(input()) for _ in range(N)]

colors = 0
a = A
while True:
    colors += 1
    p = [a[0]]
    pp = [0]
    for i in range(1,len(a)):
        if p[-1] < a[i]:
            p.append(a[i])
            pp.append(i)
        else:
            pos = bisect.bisect_left(p,a[i])
            p[pos] = a[i]
            pp[pos] = i

    if len(p) == len(a):
        break
    a = [a[x] for x in range(len(a)) if x not in pp]
print (colors)

Fixed submission:
import bisect

N = int(input())
A = [-int(input()) for _ in range(N)]

p = [A[0]]
for i in A[1:]:
    if p[-1] <= i:
        p.append(i)
    else:
        p[bisect.bisect_right(p,i)] = i
print (len(p))
Buggy python submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    H,W = LI()
    f = [[0] * W for _ in range(H)]
    q = collections.deque()
    for i in range(H):
        for j,x in enumerate(sys.stdin.readline().rstrip()):
            if x == '#':
                f[i][j] = 1
                q.append((i,j,0))
    ans = 0
    while q:
        y,x,c = q.popleft()
        ans = max(ans,c)
        for dy,dx in ((0,1),(1,0),(-1,0),(0,-1)):
            if 0 <= x+dx < W and 0 <= y+dy < H:
                if f[x+dx][y+dy] == 0:
                    f[x+dx][y+dy] = 1
                    q.append((y+dy,x+dx,c+1))
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    H,W = LI()
    f = [[0] * W for _ in range(H)]
    q = collections.deque()
    for i in range(H):
        for j,x in enumerate(sys.stdin.readline().rstrip()):
            if x == '#':
                f[i][j] = 1
                q.append((i,j,0))
    ans = 0
    while q:
        y,x,c = q.popleft()
        ans = max(ans,c)
        for dy,dx in ((0,1),(1,0),(-1,0),(0,-1)):
            if 0 <= x+dx < W and 0 <= y+dy < H:
                if f[y+dy][x+dx] == 0:
                    f[y+dy][x+dx] = 1
                    q.append((y+dy,x+dx,c+1))
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    A = [0 for _ in range(N+1)]
    S = [1 for _ in range(N+1)]
    C = [NI() for _ in range(N)]
    P = 1
    A[C[0]] = 1
    for i in range(1,N):
        if C[i] != C[i-1] and A[C[i]] > 0:
            S[C[i]] = S[C[i]] + P
        else:
            S[C[i]] = P
        A[C[i]] = 1
        P = S[C[i]]
    print(P)




if __name__ == '__main__':
    main()

Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    CMAX = 2*10**5
    A = [0 for _ in range(CMAX+1)]
    S = [1 for _ in range(CMAX+1)]
    C = [NI() for _ in range(N)]
    P = 1
    A[C[0]] = 1
    for i in range(1,N):
        if C[i] != C[i-1] and A[C[i]] > 0:
            S[C[i]] = S[C[i]] + P
        else:
            S[C[i]] = P
        A[C[i]] = 1
        P = S[C[i]] % MOD
    print(P)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys,queue,math
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in input().split()]
_LI = lambda : [int(x)-1 for x in input().split()]

N,M = LI()
B = [_LI() for _ in range(M)]

g = [i for i in range(N)]
c = [1 for _ in range(N)]

def root(x):
    if x != g[x]: g[x] = root(g[x])
    return g[x]

def union(x,y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        g[ry] = rx
        c[rx] += c[ry]
        c[ry] = 0

ans = []
B.reverse()
for a,b in B:
    ra = root(a)
    rb = root(b)
    if ra == rb:
        ans.append(0)
    else:
        ans.append(c[ra]*c[rb])
        union(ra,rb)

ans.reverse()
x = 0
for a in ans:
    x += a
    print (x)

Fixed submission:
import sys,queue,math
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in input().split()]
_LI = lambda : [int(x)-1 for x in input().split()]

N,M = LI()
B = [_LI() for _ in range(M)]

g = [i for i in range(N)]
c = [1 for _ in range(N)]

def root(x):
    if x != g[x]: g[x] = root(g[x])
    return g[x]

def union(x,y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        if c[ry] > c[rx]: ry,rx = rx,ry
        g[ry] = rx
        c[rx] += c[ry]
        c[ry] = 0

ans = []
B.reverse()
for a,b in B:
    ra = root(a)
    rb = root(b)
    if ra == rb:
        ans.append(0)
    else:
        ans.append(c[ra]*c[rb])
        union(ra,rb)

ans.reverse()
x = 0
for a in ans:
    x += a
    print (x)

Buggy python submission (verdict: Runtime Error):
import sys,queue,math,numpy as np,scipy as sc
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in input().split()]
_LI = lambda : [int(x)-1 for x in input().split()]

N,M = LI()
B = [_LI() for _ in range(M)]

g = [i for i in range(N)]
c = [1 for _ in range(N)]

def root(x):
    if x != g[x]: g[x] = root(g[x])
    return g[x]

def union(x,y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        g[ry] = rx
        c[rx] += c[ry]
        c[ry] = 0

k = []



ans = []
B.reverse()
for a,b in B:
    ra = root(a)
    rb = root(b)
    if ra == rb:
        ans.append(0)
    else:
        ans.append(c[ra]*c[rb])
        union(ra,rb)

ans.reverse()
x = 0
for a in ans:
    x += a
    print (x)

Fixed submission:
import sys,queue,math
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in input().split()]
_LI = lambda : [int(x)-1 for x in input().split()]

N,M = LI()
B = [_LI() for _ in range(M)]

g = [i for i in range(N)]
c = [1 for _ in range(N)]

def root(x):
    if x != g[x]: g[x] = root(g[x])
    return g[x]

def union(x,y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        if c[ry] > c[rx]: ry,rx = rx,ry
        g[ry] = rx
        c[rx] += c[ry]
        c[ry] = 0

ans = []
B.reverse()
for a,b in B:
    ra = root(a)
    rb = root(b)
    if ra == rb:
        ans.append(0)
    else:
        ans.append(c[ra]*c[rb])
        union(ra,rb)

ans.reverse()
x = 0
for a in ans:
    x += a
    print (x)
Buggy python submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools,bisect,collections,heapq
LI = lambda : [float(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N = NI()
p = LI()
dp = [0] * (N+1)
dp[0][0] = 1
for i in range(1,N+1):
    for j in range(0,i+1):
        if j > 0:
            dp[j] = dp[j-1] * p[i-1] + dp[j] * (1-p[i-1])
        else:
            dp[j] = dp[j] *  (1-p[i-1])

print(sum(dp[N//2+1:]))


Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections,heapq
LI = lambda : [float(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N = NI()
p = [0.0] + LI()
dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
    for j in range(0,i+1):
        if j > 0: dp[i][j] = dp[i-1][j-1] * p[i]
        dp[i][j] += dp[i-1][j] * (1-p[i])

print(sum(dp[-1][N//2+1:]))

Buggy python submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools,bisect,collections,heapq
LI = lambda : [float(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N = NI()
p = LI()
dp = [0] * (N+1)
dp[0][0] = 1
for i in range(1,N+1):
    for j in range(0,i+1):
        if j > 0:
            dp[j] = dp[j-1] * p[i-1] + dp[j] * (1-p[i-1])
        else:
            dp[j] = dp[j] *  (1-p[i-1])

print(sum(dp[-1][N//2+1:]))


Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections,heapq
LI = lambda : [float(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N = NI()
p = [0.0] + LI()
dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
    for j in range(0,i+1):
        if j > 0: dp[i][j] = dp[i-1][j-1] * p[i]
        dp[i][j] += dp[i-1][j] * (1-p[i])

print(sum(dp[-1][N//2+1:]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    L = 100000

    N = NI()

    s = 1 if N > 0 else -1
    n = abs(N)

    bit = [0] * L

    i = 0
    while n > 0:
        if n % 2:
            bit[i] += 1
            if s > 0 and i % 2 == 1 or s < 0 and i % 2 == 0:
                bit[i+1] += 1
        n //= 2
        i += 1

    for i in range(L-2):
        if bit[i] > 1:
            bit[i+2] += bit[i] // 2
            bit[i+1] += bit[i] // 2
            bit[i] = bit[i] % 2

    f = False
    ans = ''
    for i in range(L-1,-1,-1):
        if bit[i] == 1:
            ans = ''.join((ans,'1'))
            f = True
        elif f:
            ans = ''.join((ans,'0'))
    if ans == '': ans = '0'

    print(ans)





if __name__ == '__main__':
    main()

Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    L = 1000

    N = NI()
    if N == 0:
        print(0)
        exit(0)

    s = 1 if N > 0 else -1
    n = abs(N)

    bit = [0] * L

    i = 0
    while n > 0:
        if n % 2:
            bit[i] += 1
            if s > 0 and i % 2 == 1 or s < 0 and i % 2 == 0:
                bit[i+1] += 1
        n //= 2
        i += 1

    for i in range(L-2):
        b = bit[i]
        if b > 1:
            b1 = bit[i+1]
            if b1 > 0:
                if b1 >= b//2:
                    bit[i+1] -= b//2
                    bit[i] = b % 2
                else:
                    bit[i+1] = 0
                    bit[i] -= b1 * 2
            if bit[i] > 1:
                bit[i+2] += bit[i] // 2
                bit[i+1] += bit[i] // 2
                bit[i] = bit[i] % 2

    bit.reverse()
    i = bit.index(1)
    print(*bit[i:],sep='')

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    INF = 10**5
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    D,G = LI()
    pc = [LI() for _ in range(D)]
    ans = INF
    for p in itertools.permutations([0,1,2,3,4,5,6,7,8,9]):
        g = G
        cnt = 0
        for i in p:
            if g < pc[i][0] * (i+1) * 100:
                cnt += math.ceil(g/((i+1)*100))
                break
            else:
                cnt += pc[i][0]
                g -= pc[i][0] * (i+1) * 100 + pc[i][1]
            if g <= 0: break
        ans = min(ans,cnt)

    print(ans)


if __name__ == '__main__':
    main()

Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    D,G = LI()
    pc = [LI() for _ in range(D)]

    ans = INF
    for p in itertools.permutations(range(D)):
        g = G
        cnt = 0
        for i in p:
            if g < pc[i][0] * (i+1) * 100:
                cnt += math.ceil(g/((i+1)*100))
                break
            else:
                cnt += pc[i][0]
                g -= pc[i][0] * (i+1) * 100 + pc[i][1]
            if g <= 0: break
        ans = min(ans,cnt)

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n = [False,False ] + [True for _ in range(10**5-1)]

def check_prime(x):
    for i in range(x*2,10**5+1,x):
        n[i] = False

check_prime(2)
for i in range(3,10**5+1,2):
    check_prime(i)

for _ in range(int(input())):
    l,r = map(int,input().split())
    ans = 0
    for i in range(l,r+1):
        if i % 2 == 1 and n[i] and n[(i+1)//2]:
           ans += 1
    print (ans)


Fixed submission:
import math
n = [0,0,1] + [1 for _ in range(10**5-2)]

def check_prime(x):
    for i in range(x*2,10**5+1,x):
        n[i] = 0

check_prime(2)
for i in range(3,int(math.sqrt(10**5))+1,2):
    check_prime(i)

c = [0 for _ in range(10**5+1)]
for i in range(1,10**5+1):
    c[i] = c[i-1] + (n[i] * n[(i+1)//2])

for _ in range(int(input())):
    l,r = map(int,input().split())
    ans = c[r] - c[l-1]
    print (ans)
Buggy python submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

ans = len(S)
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        ans = min(ans,max(i+1,len(S)-i-1))

print (ans)



Fixed submission:
import sys,queue,math,copy,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

S = input()
ans = len(S)
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        ans = min(ans,max(i+1,len(S)-i-1))

print (ans)

Buggy python submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

ans = 10**5+1
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        ans = min(ans,max(i+1,len(S)-i-1))
if ans == 0: ans = len(S)

print (ans)



Fixed submission:
import sys,queue,math,copy,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

S = input()
ans = len(S)
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        ans = min(ans,max(i+1,len(S)-i-1))

print (ans)
Buggy python submission (verdict: Runtime Error):
import sys
from bisect import bisect
input = sys.stdin.readline

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
b.sort()
c.sort()

bc = [0 for _ in range(n)]
for i in range(len(b)):
    if b[i] >= c[n-1]:
        break
    p = bisect(c,b[i])
    bc[i] = (n-p)

for i in range(len(b)-1,0,-1):
    bc[i-1] += bc[i]
ans = 0
for x in a:
    if x < b[n-1]:
        p = bisect(b,a[i])
        ans += bc[p]

print(ans)

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

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()

bc = [0 for _ in range(n)]
for i in range(len(b)):
    if b[i] >= c[n-1]:
        break
    p = bisect(c,b[i])
    bc[i] = (n-p)

for i in range(len(b)-1,0,-1):
    bc[i-1] += bc[i]
ans = 0
for i in range(len(a)):
    if a[i] >= b[n-1]:
        break
    p = bisect(b,a[i])
    ans += bc[p]

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    A,B,C,D,E,F = LI()

    w = set()
    for i in range(int(F/A/100)+1):
        for j in range(int(F/B/100)+1):
            #if 0 < A*i+B*j <= int(F/100):
                w.add((A*i+B*j)*100)
    s = set()
    for i in range(int(F*E/(100+E)/C)+1):
        for j in range(int(F*E/(100+E)/D)+1):
            if 0 <= C*i+D*j <= int(F*E/(100+E)):
                s.add(C*i+D*j)

    max_E = -1.0
    ans_w = 0
    ans_s = 0
    for x in w:
        for y in s:
            if x + y <= F and y/x*100 <= E and max_E < y/(x+y) * 100:
                max_E = y/(x+y) * 100
                ans_w = x + y
                ans_s = y
    print(ans_w,ans_s)

if __name__ == '__main__':
    main()

Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    A,B,C,D,E,F = LI()

    w = set()
    for i in range(int(F/A/100)+1):
        for j in range(int(F/B/100)+1):
            if 0 < A*i+B*j <= int(F/100):
                w.add((A*i+B*j)*100)
    s = set()
    for i in range(int(F*E/(100+E)/C)+1):
        for j in range(int(F*E/(100+E)/D)+1):
            if 0 <= C*i+D*j <= int(F*E/(100+E)):
                s.add(C*i+D*j)

    max_E = -1.0
    ans_w = 0
    ans_s = 0
    for x in w:
        for y in s:
            if x + y <= F and y <= x/100 * E and max_E < y/(x+y) * 100:
                max_E = y/(x+y) * 100
                ans_w = x + y
                ans_s = y
    print(ans_w,ans_s)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,M = LI()
    A = [LI() for _ in range(N)]

    ctr = [0] * N

    sp = [0] * (M+1)
    for i in range(N):
        sp[A[i][ctr[i]]] += 1
    ans = max(sp)

    for _ in range(N-1):
        m = 0
        mi = -1
        for i in range(1,M+1):
            if sp[i] > m:
                m = sp[i]
                mi = i
        sp[mi] = -1
        for i in range(N):
            if A[i][ctr[i]] == mi:
                while sp[A[i][ctr[i]]] < 0:
                    ctr[i] += 1
                sp[A[i][ctr[i]]] += 1
        ans = min(ans,max(sp))

    print(ans)


if __name__ == '__main__':
    main()

Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,M = LI()
    A = [LI() for _ in range(N)]

    ctr = [0] * N

    sp = [0] * (M+1)
    for i in range(N):
        sp[A[i][ctr[i]]] += 1
    ans = max(sp)

    for _ in range(M-1):
        m = 0
        mi = -1
        for i in range(1,M+1):
            if sp[i] > m:
                m = sp[i]
                mi = i
        sp[mi] = -1
        for i in range(N):
            if A[i][ctr[i]] == mi:
                while sp[A[i][ctr[i]]] < 0:
                    ctr[i] += 1
                sp[A[i][ctr[i]]] += 1
        ans = min(ans,max(sp))

    print(ans)


if __name__ == '__main__':
    main()