Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
D = 60

N, K = map(int, input().split())
to = [[None] * N for _ in range(D)]
to[0] = list(map(lambda x: int(x)-1, input().split()))

for i in range(D-1):
    for j in range(N):
        to[i+1][j] = to[i][to[i][j]]

v = 0
for i in range(D, -1, -1):
    hops = 1 << i
    if K >= hops:
        K -= hops
        v = to[i][v]

print(v+1)


Fixed submission:
N, K = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))

town = 0
visited = [town]
index = 0
visited_index = {town: index}
loop = None
while K > 0:
    K -= 1
    town = A[town]
    if town in visited_index:
        loop = visited[visited_index[town]:]
        break
    visited.append(town)
    index += 1
    visited_index[town] = index

if loop:
    K %= len(loop)
    print(loop[K]+1)
else:
    print(town+1)

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

town = 0
visited = [town]
loop = None
while K > 0:
    K -= 1
    town = A[town]
    if town in visited:
        loop = visited[visited.index(town):]
        break
    visited.append(town)

if loop:
    K %= len(loop)
    print(loop[K]+1)
else:
    print(town+1)


Fixed submission:
N, K = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))

town = 0
visited = [town]
index = 0
visited_index = {town: index}
loop = None
while K > 0:
    K -= 1
    town = A[town]
    if town in visited_index:
        loop = visited[visited_index[town]:]
        break
    visited.append(town)
    index += 1
    visited_index[town] = index

if loop:
    K %= len(loop)
    print(loop[K]+1)
else:
    print(town+1)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

N = int(input())
A = list(map(int, input().split()))
index = list(range(N))
ans = 0
for combination in combinations(index, 2):
    if A[combination[0]]+A[combination[1]] == combination[1] - combination[0]:
        ans += 1
print(ans)


Fixed submission:
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_plus_index = list(A[i]+i+1 for i in range(N))
    A_plus_index = Counter(A_plus_index)
    index_minus_A = list(i+1-A[i] for i in range(N))
    ans = 0
    for a in index_minus_A:
        ans += A_plus_index.get(a, 0)
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

N = int(input())
A = list(map(int, input().split()))
index = list(range(N))
ans = 0
for combination in combinations(index, 2):
    if A[combination[0]]+A[combination[1]] == combination[1] - combination[0]:
        ans += 1
print(ans)


Fixed submission:
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_plus_index = list(A[i]+i+1 for i in range(N))
    A_plus_index = Counter(A_plus_index)
    index_minus_A = list(i+1-A[i] for i in range(N))
    ans = 0
    for a in index_minus_A:
        ans += A_plus_index.get(a, 0)
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def combinations_with_replacement(elements, N):
    for element in elements:
        if N == 1:
            yield [element]
        else:
            for combination in combinations_with_replacement(elements, N-1):
                if element >= combination[-1]:
                    yield combination + [element]


N, M, Q = map(int, input().split())
a = [None for _ in range(Q)]
b = [None for _ in range(Q)]
c = [None for _ in range(Q)]
d = [None for _ in range(Q)]
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

ans = 0
elements = list(range(1, M+1))
for combination in combinations_with_replacement(elements, N):
    score = 0
    for i in range(Q):
        if combination[b[i]-1] - combination[a[i]-1] == c[i]:
            score += d[i]
    ans = max(score, ans)
print(ans)


Fixed submission:
import itertools
N, M, Q = map(int, input().split())
a = [None for _ in range(Q)]
b = [None for _ in range(Q)]
c = [None for _ in range(Q)]
d = [None for _ in range(Q)]
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

ans = 0
elements = list(range(1, M+1))
for combination in itertools.combinations_with_replacement(elements, N):
    score = 0
    for i in range(Q):
        if combination[b[i]-1] - combination[a[i]-1] == c[i]:
            score += d[i]
    ans = max(score, ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def combinations_with_replacement(elements, N):
    for element in elements:
        if N == 1:
            yield [element]
        else:
            for combination in combinations_with_replacement(elements, N-1):
                if element >= combination[-1]:
                    yield combination + [element]


N, M, Q = map(int, input().split())
a = [None for _ in range(Q)]
b = [None for _ in range(Q)]
c = [None for _ in range(Q)]
d = [None for _ in range(Q)]
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

ans = 0
elements = list(range(1, M+1))
for combination in combinations_with_replacement(elements, N):
    score = 0
    for i in range(Q):
        if combination[b[i]-1] - combination[a[i]-1] == c[i]:
            score += d[i]
    ans = max(score, ans)
print(ans)


Fixed submission:
import itertools
N, M, Q = map(int, input().split())
a = [None for _ in range(Q)]
b = [None for _ in range(Q)]
c = [None for _ in range(Q)]
d = [None for _ in range(Q)]
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

ans = 0
elements = list(range(1, M+1))
for combination in itertools.combinations_with_replacement(elements, N):
    score = 0
    for i in range(Q):
        if combination[b[i]-1] - combination[a[i]-1] == c[i]:
            score += d[i]
    ans = max(score, ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
def main(N=None, K=None):
    if not N:
        N = int(input())
        K = int(input())
    ans = (K-N-2)*(2*K*K-K*(N+2)-N*N-N-6)//6
    ans %= 10**9+7
    print(ans)
    return ans


if __name__ == "__main__":
    # assert main(3, 2) == 10
    # assert main(200000, 200001) == 1
    # assert main(141421, 35623) == 220280457
    main()


Fixed submission:
def main(N=None, K=None):
    if not N:
        N, K = map(int, input().split())
    ans = (K-N-2)*(2*K*K-K*(N+2)-N*N-N-6)//6
    ans %= 10**9+7
    print(ans)
    return ans


if __name__ == "__main__":
    # assert main(3, 2) == 10
    # assert main(200000, 200001) == 1
    # assert main(141421, 35623) == 220280457
    main()
Buggy python submission (verdict: Runtime Error):
from collections import Counter


def main(N=None, S=None):
    if not N or not S:
        N = int(input())
        S = int(input())
    c = Counter(S)
    ans = c["R"]*c["G"]*c["B"]
    for hop in range(1, N//2):
        for start in range(N):
            i = start
            j = start + hop
            k = start + hop*2
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1
            # print(i, j, k, ans)
    print(ans)
    return ans


if __name__ == "__main__":
    # assert main(4, "RRGB") == 1
    # assert main(39, "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB") == 1800
    main()


Fixed submission:
from collections import Counter


def main(N=None, S=None):
    if not N or not S:
        N = int(input())
        S = input()
    c = Counter(S)
    ans = c["R"]*c["G"]*c["B"]
    for hop in range(1, N):
        for start in range(N):
            i = start
            j = start + hop
            k = start + hop*2
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1
            # print(i, j, k, ans)
    print(ans)
    return ans


if __name__ == "__main__":
    # assert main(4, "RRGB") == 1
    # assert main(39, "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB") == 1800
    main()
Buggy python submission (verdict: Runtime Error):
M = 1000000007


def main(N=None, K=None):
    if not N or not K:
        N = int(input())
        K = int(input())
    ans = 0
    gcds = {}
    for X in range(K, 0, -1):
        gcds[X] = int(pow(K//X, N, M))
        n = 1
        while True:
            n += 1
            if n*X > K:
                break
            gcds[X] -= gcds[n*X]
        ans += gcds[X]*X
    ans %= M
    print(ans)
    return ans


if __name__ == "__main__":
    # assert main(3, 2) == 9
    # assert main(3, 200) == 10813692
    # assert main(100000, 100000) == 742202979
    main()


Fixed submission:
M = 1000000007


def main(N=None, K=None):
    if not N or not K:
        N, K = map(int, input().split())
    ans = 0
    gcds = {}
    for X in range(K, 0, -1):
        gcds[X] = int(pow(K//X, N, M))
        n = 1
        while True:
            n += 1
            if n*X > K:
                break
            gcds[X] -= gcds[n*X]
        ans += gcds[X]*X
    ans %= M
    print(ans)
    return ans


if __name__ == "__main__":
    # assert main(3, 2) == 9
    # assert main(3, 200) == 10813692
    # assert main(100000, 100000) == 742202979
    main()
Buggy python submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
p = map(int, input().split())
q = map(int, input().split())
r = map(int, input().split())

# X, Y, A, B, C = 1, 2, 2, 2, 1
# p = [2, 4]
# q = [5, 1]
# r = [3]

p.sort()
q.sort()
r.sort()
p = p[-X:]
q = q[-Y:]

d = []
d += p
d += q
d += r
d.sort()

print(sum(d[-X-Y:]))


Fixed submission:
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

# X, Y, A, B, C = 1, 2, 2, 2, 1
# p = [2, 4]
# q = [5, 1]
# r = [3]

p.sort()
q.sort()
r.sort()
p = p[-X:]
q = q[-Y:]

d = []
d += p
d += q
d += r
d.sort()

print(sum(d[-X-Y:]))
Buggy python submission (verdict: Time Limit Exceeded):

# coding: utf-8

# In[3]:


N,K,Q=map(int,input().split())


# In[6]:


A = []
for i in range(Q):
    A.append(int(input()))


# In[10]:


for i in range(N):
    score = K-Q + A.count(i+1)
    if score > 0:
        print("Yes")
    else:
        print("No")


Fixed submission:

# coding: utf-8

# In[11]:


N,K,Q=map(int,input().split())


# In[13]:


ans = [0] * N
for i in range(Q):
    ans[int(input())-1]+=1


# In[14]:


for i in range(N):
    score = K-Q + ans[i]
    if score > 0:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
    M, D = map(int,input().split())
    if D<22:
      print(0)
    else:
      count = 0
      for i in range(22,D+1):
        d1 = D%10
        d2 = (D-d1)//10
        if d1*d2 <= M:
          count+=1
      print(count)

Fixed submission:
M, D = map(int,input().split())
if D<22:
  print(0)
else:
  count = 0
  for i in range(22,D+1):
    d1 = i%10
    d10 = (i-d1)//10
    if d1>1 and d10>1 and d1*d10 <= M:
      count+=1
  print(count)

Buggy python submission (verdict: Runtime Error):
M, D = map(int,input())
if D<22:
  print(0)
else:
  count = 0
  for i in range(22,D+1):
    d1 = D%10
    d2 = (D-d1)//10
    if d1*d2 <= M:
      count+=1
  print(count)

Fixed submission:
M, D = map(int,input().split())
if D<22:
  print(0)
else:
  count = 0
  for i in range(22,D+1):
    d1 = i%10
    d10 = (i-d1)//10
    if d1>1 and d10>1 and d1*d10 <= M:
      count+=1
  print(count)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9 for _ in range(N)]
    dp[0] = 0
    for i in range(N):
        for j in range(1, K+1):
            if i+j < N:
                dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
    print(dp[-1])


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9 for _ in range(N)]
    dp[0] = 0
    for i in range(N):
        for j in range(1, K+1):
            if i+j < N:
                dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
    print(dp[-1])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9 for _ in N]
    dp[0] = 0
    for i in range(N):
        for j in range(1, K+1):
            if i+j < N:
                dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
    print(dp[-1])


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9 for _ in range(N)]
    dp[0] = 0
    for i in range(N):
        for j in range(1, K+1):
            if i+j < N:
                dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
    print(dp[-1])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float("inf")]*N
    dp[0] = 0
    for i in range(N):
        for j in range(1, K+1):
            if i+j < N:
                dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
    print(dp[-1])


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9 for _ in range(N)]
    dp[0] = 0
    for i in range(N):
        for j in range(1, K+1):
            if i+j < N:
                dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
    print(dp[-1])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, W = map(int, input().split())
    w = [None for _ in range(N)]
    v = [None for _ in range(N)]
    for i in range(N):
        w[i], v[i] = map(int, input().split())
    dp = [[0 for _ in range(W+1)] for _ in range(N)]
    for i in range(0, N):
        for j in range(W+1):
            if j-w[i] >= 0:
                dp[i][j] = max(dp[i-1][j-w[i]]+v[i], dp[i-1][j])
            else:
                dp[i][j] = dp[i-1][j]
    print(dp[-1][-1])


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, W = map(int, input().split())
    w = [None for _ in range(N)]
    v = [None for _ in range(N)]
    for i in range(N):
        w[i], v[i] = map(int, input().split())
    dp = [[0 for _ in range(W+1)] for _ in range(N)]
    for i in range(0, N):
        for j in range(W+1):
            if j-w[i] >= 0:
                dp[i][j] = max(dp[i-1][j-w[i]]+v[i], dp[i-1][j])
            else:
                dp[i][j] = dp[i-1][j]
    print(dp[-1][-1])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# python3だとTLE,pypy3だとAC
def main():
    N, W = map(int, input().split())
    w = [None for _ in range(N)]
    v = [None for _ in range(N)]
    for i in range(N):
        w[i], v[i] = map(int, input().split())
    MAX_V = sum(v)
    dp = [[10**9 for _ in range(MAX_V+1)] for _ in range(N)]
    dp[0][0] = 0
    for i in range(N-1):
        if i == 0:
            for sum_v in range(1, v[i]+1):
                dp[i][sum_v] = w[i]
        for sum_v in range(MAX_V+1):
            if sum_v - v[i+1] >= 0:
                dp[i+1][sum_v] = min(w[i+1] + dp[i]
                                     [sum_v-v[i+1]], dp[i][sum_v])
            else:
                dp[i+1][sum_v] = min(w[i+1], dp[i][sum_v])
    print(len(list(filter(lambda sum_v: sum_v <= W, dp[-1])))-1)


if __name__ == "__main__":
    main()


Fixed submission:
# python3だとTLE,pypy3だとAC
def main():
    N, W = map(int, input().split())
    w = [None for _ in range(N)]
    v = [None for _ in range(N)]
    for i in range(N):
        w[i], v[i] = map(int, input().split())
    MAX_V = sum(v)
    dp = [[10**9 for _ in range(MAX_V+1)] for _ in range(N)]
    dp[0][0] = 0
    for i in range(N-1):
        if i == 0:
            for sum_v in range(1, v[i]+1):
                dp[i][sum_v] = w[i]
        for sum_v in range(MAX_V+1):
            if sum_v - v[i+1] >= 0:
                dp[i+1][sum_v] = min(w[i+1] + dp[i]
                                     [sum_v-v[i+1]], dp[i][sum_v])
            else:
                dp[i+1][sum_v] = min(w[i+1], dp[i][sum_v])
    print(len(list(filter(lambda sum_v: sum_v <= W, dp[-1])))-1)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 1 
a = list(map(int,input().split()))
for i in range(n):
  ans *= a[i]
if ans > 1000000000000000000:
  print("-1")
else:
  print(ans)

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

ans = 1

if 0 in a:
    ans = 0
else:
    for i in a:
        ans *= i
        if(ans > 10**18):
            ans = -1
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 1 
a = list(map(int,input().split()))
for i in a:
  ans *= i
if ans > 10**18:
  print("-1")
else:
  print(ans)

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

ans = 1

if 0 in a:
    ans = 0
else:
    for i in a:
        ans *= i
        if(ans > 10**18):
            ans = -1
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 1 
a = list(map(int,input().split()))
for i in range(n):
  ans *= a[i]
if ans > 10**18:
  print("-1")
else:
  print(ans)

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

ans = 1

if 0 in a:
    ans = 0
else:
    for i in a:
        ans *= i
        if(ans > 10**18):
            ans = -1
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 1 
a = list(map(int,input().split()))
for i in a:
  ans *= i
if ans > 10**18:
  print("-1")
else:
  print(ans)

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

ans = 1

if 0 in a:
    ans = 0
else:
    for i in a:
        ans *= i
        if(ans > 10**18):
            ans = -1
            break
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 1 
a = list(map(int,input().split()))
for i in a:
  ans *= a[i]
if ans > 10**18:
  print("-1")
else:
  print(ans)

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

ans = 1

if 0 in a:
    ans = 0
else:
    for i in a:
        ans *= i
        if(ans > 10**18):
            ans = -1
            break
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np

from decimal import Decimal

n = int(input())
a = input().split()

ans = Decimal("1")

for i in a:
    ans *= Decimal(i)

#print(ans - Decimal("1000000000000000000"))

if(ans - Decimal("1000000000000000000") > 0):
    print(-1)
else:
    print(ans)

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

ans = 1

if 0 in a:
    ans = 0
else:
    for i in a:
        ans *= i
        if(ans > 10**18):
            ans = -1
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b = input().split()

bx = b.replace(".", "")

ans = 0
ans += int(a) * int(bx[0])
ans += int(a[:-1]) * int(bx[1])
ans += int(a[:-2]) * int(bx[2])


print(ans)

Fixed submission:
from decimal import Decimal
import math


a, b = input().split()

ax = Decimal(a)
bx = Decimal(b)

ans = ax*bx

print(math.floor(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
a = list(map(int, input().split()))

root = [1]

for i in range(n):
    t = a[root[i] - 1]
    root.append(t)
    if (t in root[:-1]):
        break
x =  root.index(root[-1])
bef = root[0:x]
#print(bef)
loop = root[x:-1]
#print(loop)
#print(root)

if (k < len(bef)):
    print(bef[k])
else:
    p = ((k - len(bef)) % len(loop))
    #print(p)
    print(loop[p])

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

root = [1]

for i in range(n):
    t = a[root[i]-1]
    if (t == 0):
        break
    a[root[i]-1] = 0
    root.append(t)
x =  root.index(root[-1])
bef = root[0:x]
#print(bef)
loop = root[x:-1]
#print(loop)
#print(root)

if (k < len(bef)):
    print(bef[k])
else:
    p = ((k - len(bef)) % len(loop))
    #print(p)
    print(loop[p])
Buggy python submission (verdict: Runtime Error):
import numpy as np

n, m = map(int, input().split())
h = np.array(list(map(int, input().split())))
nets = np.zeros((n,n))

for i in range(m):
    a,b = map(int, input().split())
    nets[a - 1][b - 1] = h[b-1]
    nets[b - 1][a - 1] = h[a-1]

ans = 0

#print(nets)

for i in range(n):
    if (h[i] >max(nets[i])):
        ans += 1

print(ans)

Fixed submission:
n, m = map(int, input().split())
h = list(map(int, input().split()))
nets = [0]*n

for _ in range(m):
    a,b = map(int, input().split())
    nets[a - 1] = max(nets[a-1], h[b-1])
    nets[b - 1] = max(nets[b-1], h[a-1])

ans = 0

#print(nets)

for i in range(n):
    if (h[i] >nets[i]):
        ans += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np

n, m = map(int, input().split())
h = np.array(list(map(int, input().split())))
nets = np.zeros((n,n))

for i in range(m):
    a,b = map(int, input().split())
    nets[a - 1][b - 1] = 1
    nets[b - 1][a - 1] = 1

ans = 0

for i in range(n):
    if (h[i] >max(h * nets[i])):
        ans += 1

print(ans)

Fixed submission:
n, m = map(int, input().split())
h = list(map(int, input().split()))
nets = [0]*n

for _ in range(m):
    a,b = map(int, input().split())
    nets[a - 1] = max(nets[a-1], h[b-1])
    nets[b - 1] = max(nets[b-1], h[a-1])

ans = 0

#print(nets)

for i in range(n):
    if (h[i] >nets[i]):
        ans += 1

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

n,m,q = map(int, input().split())
qz = [list(map(int, input().split())) for i in range(q)]

qx = []

for i in range(q):
    ma = 0
    index = 0
    for j in range(len(qz)):
        if (qz[j][2] > ma):
            ma = qz[j][2]
            index = j
    qx.append(qz[index])
    qz.pop(index)

su = [0]

def checker(af, bf):
    lt = max(af) - max(bf) + 1
    rt =[]
    for h in range(0,lt):
        amax = 0
        bf = np.array(bf)+h
        for i in range(n):
            if (af[i] != 0 and bf[i] != 0 and af[i] != bf[i]):
                break
            elif (amax > max(af[i], bf[i]) and (af[i] != 0 or bf[i] != 0)):
                break
            amax = max(amax,af[i],bf[i])
        else:
            rt.append(h)
    return rt

def adder(af, bf):
    rt = [0]*n
    for i in range(n):
        rt[i] = max(af[i], bf[i])
    return rt

ans = [[0] * n]
ans[0][qx[0][0]-1] = 1
ans[0][qx[0][1] - 1] = qx[0][2]+1
su = [qx[0][3]]

for i in range(1,q):
    a, b, c, d = map(int, qx[i])
    t = [0] * n
    t[a-1] = 1
    t[b - 1 ] = c + 1
    #print(t)
    ll = len(ans)
    for j in range(ll):
        ct = checker(ans[j], t)
        if (len(ct) != 0):
            for k in ct:
                ans.append(adder(ans[j], np.array(t)+k))
                su.append(su[j] + d)
        else:
            ans.append(t)
            su.append(d)
print(max(su))



Fixed submission:
from itertools import combinations_with_replacement

n, m, q = map(int, input().split())
qx = [list(map(int, input().split())) for i in range(q)]

ans = 0

for i in combinations_with_replacement(range(1, m + 1), n):
    s = 0
    for a, b, c, d in qx:
        s += d if (i[b-1] - i[a-1] == c) else 0
    ans = max(ans, s)

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

for i in range(1, n + 1):
    print(a.count(i))

Fixed submission:
import collections

n = int(input())
a = list(map(int, input().split()))
ax = collections.Counter(a)
for i in range(1, n + 1):
    print(ax[i])