Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = [int(i) for i in input().split()]


def main():
    print("Yes" if detect() else "No")


def detect():
    m = min(h)+1
    for i in range(n):
        if h[i] <= m:
            continue
        if (h[i] - min(h[i::])) > 1:
            return False
    
    return True


main()


Fixed submission:
n = int(input())
h = [int(i) for i in input().split()]


def main():
    h[0] -= 1
    print("Yes" if detect() else "No")


def detect():
    for i in range(1, n):
        if h[i] > h[i-1]:
            h[i] -= 1
        elif h[i] < h[i-1]:
            return False

    return True


main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = [int(i) for i in input().split() if i != 0]


def main():
    print("Yes" if detect() else "No")


def detect():
    m = min(h)+1
    for i in range(n):
        if h[i] <= m:
            continue
        if (h[i] - min(h[i::])) > 1:
            return False
    return True


main()


Fixed submission:
n = int(input())
h = [int(i) for i in input().split()]


def main():
    h[0] -= 1
    print("Yes" if detect() else "No")


def detect():
    for i in range(1, n):
        if h[i] > h[i-1]:
            h[i] -= 1
        elif h[i] < h[i-1]:
            return False

    return True


main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = [int(i) for i in input().split() if i != 0]


def main():
    print("Yes" if detect() else "No")


def detect():
    m = min(h)+1
    for i in range(n):
        if h[i] <= m:
            continue
        if (h[i] - min(h[i::])) > 1:
            return False
    return True


main()


Fixed submission:
n = int(input())
h = [int(i) for i in input().split()]


def main():
    h[0] -= 1
    print("Yes" if detect() else "No")


def detect():
    for i in range(1, n):
        if h[i] > h[i-1]:
            h[i] -= 1
        elif h[i] < h[i-1]:
            return False

    return True


main()

Buggy python submission (verdict: Time Limit Exceeded):
import copy

n = int(input())
h = [int(i) for i in input().split()]


def main():
    print("Yes" if detect() else "No")


def detect():
    for i in range(n):
        if (h[i] - min(h[i::])) > 1:
            return False
    return True


main()


Fixed submission:
n = int(input())
h = [int(i) for i in input().split()]


def main():
    h[0] -= 1
    print("Yes" if detect() else "No")


def detect():
    for i in range(1, n):
        if h[i] > h[i-1]:
            h[i] -= 1
        elif h[i] < h[i-1]:
            return False

    return True


main()
Buggy python submission (verdict: Runtime Error):
INF = float("inf")
n, k = map(int, input().split())
a = list(map(int, input().split()))

def get_divisors(num):
    f_divs, l_divs = [], []
    for i in range(1, int(num**0.5)+1):
        if not num % i:
            f_divs.append(i)
            if i != num // i:
                l_divs.append(num // i)
    return f_divs + l_divs[::-1]

s = sum(a)
divs = get_divisors(s)
ans = 1

def evl(d):
    if d == 1: return True
    m = d*n*2
    rem = [x % d for x in a]
    dp = [[INF] * (m+d*2+10) for _ in range(n+1)]
    mid = m // 2
    dp[0][mid] = 0
    for i in range(n):
        for j in range(m):
            if rem[i] == 0:
                dp[i+1][j] = min(dp[i+1][j], dp[i][j])
                continue
            dp[i+1][j-rem[i]] = min(dp[i+1][j-rem[i]], dp[i][j]+rem[i])
            dp[i+1][j+d-rem[i]] = min(dp[i+1][j+d-rem[i]], dp[i][j]+(d-rem[i]))
    return dp[n][mid] // 2 <= k

l, r = -1, len(divs)

while r-l > 1:
    x = (r+l) // 2
    if evl(divs[x]): l = x
    else: r = x

print(divs[l])


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

def get_divisors(num):
    f_divs, l_divs = [], []
    for i in range(1, int(num**0.5)+1):
        if not num % i:
            f_divs.append(i)
            if i != num // i:
                l_divs.append(num // i)
    return f_divs + l_divs[::-1]

divs = get_divisors(sum(a))
ans = 1

def evl(d):
    rem = [x % d for x in a]
    rem.sort()
    s = sum(rem)
    c = 0
    for i, x in enumerate(rem):
        c += x
        if c == d*(n-i-1) - (s-c):
            return c <= k
    return False

for d in divs[::-1]:
    if evl(d):
        print(d)
        break
Buggy python submission (verdict: Runtime Error):
from math import factorial

n, k = map(int, input().split())
w = n - k

def c(a, b):
    return int(factorial(a) / (factorial(a-b) * factorial(b)))

for i in range(1, k+1):
    print((c(k-1, i-1) * c(w+1, i)) % (10**9 + 7))



Fixed submission:
from math import factorial

n, k = map(int, input().split())
r = n - k

def c(a, b):
    if a < b: return 0
    return factorial(a) // (factorial(a-b) * factorial(b))

for i in range(1, k+1):
    print((c(k-1, i-1) * c(r+1, i)) % (10**9 + 7))
Buggy python submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())

def main():
    cd = c * d / math.gcd(c, d)
    print(b - a - (f(c) + f(d) - f(cd)) + 1)

def f(x):
    return math.floor((b - x * math.ceil(a / x)) / x) + 1

main()

Fixed submission:
from fractions import gcd

a, b, c, d = map(int, input().split())
a -= 1

def main():
    cd = c * d // gcd(c, d)
    print(b - a - f(c) - f(d) + f(cd))

def f(x):
    return b // x - a // x

main()
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
v = []
for i in range(n):
    for j in range(n):
        if i == j: continue
        x, y = xy[j]
        px, py = xy[i]
        v.append((x-px, y-py))
num = Counter(v).most_common(1)[0][1]
print(n - num)


Fixed submission:
from collections import Counter
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
v = []
for i in range(n):
    for j in range(n):
        if i == j: continue
        x, y = xy[j]
        px, py = xy[i]
        v.append((x-px, y-py))
num = Counter(v).most_common(1)[0][1] if v else 0
print(n - num)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
a.append(n+1)
seq = [a[0]]

for i in range(m):
    d = a[i+1] - a[i] - 1
    if d == 0:
        print(0)
        sys.exit()
    seq.append(d)

memo = [-1] * 10**5
def fib(i):
    if i == 0: return 0
    elif i == 1: return 1
    elif memo[i] != -1: return memo[i]
    else:
        memo[i] = fib(i-1) + fib(i-2)
        return memo[i]

ans = 1
for s in seq:
    ans *= fib(s)
print(ans % 1000000007)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)

n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
a.append(n+1)
seq = [a[0]]

for i in range(m):
    d = a[i+1] - a[i] - 1
    if d == 0:
        print(0)
        sys.exit()
    seq.append(d)

memo = [-1] * (10**5 + 7)
def fib(i):
    if i == 0: return 0
    elif i == 1: return 1
    elif memo[i] != -1: return memo[i]
    else:
        memo[i] = fib(i-1) + fib(i-2)
        return memo[i]

ans = 1
for s in seq:
    ans *= fib(s)
print(ans % 1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

bc = [x + y for y in c for x in b]
bc.sort()
bcl = len(bc)

def bs_l(f, high, low=0):
    l, r = low-1, high+1
    while r - l > 1:
        x = (l + r) // 2
        if f(x): l = x
        else: r = x
    return l

def detect(s):
    cnt = 0
    for x in a:
        t = max(0, s-x)
        cnt += bcl - bisect_left(bc, t)
    return cnt >= k

res = bs_l(detect, 10**10+1)
ans = []
for x in a:
    t = max(0, res-x)
    for i in range(bcl-1, bisect_left(bc, t)-1, -1):
        ans.append(x + bc[i])

ans.sort(reverse=True)
print(*ans[:k], sep="\n")


Fixed submission:
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
bc = [x + y for y in c for x in b]
bc.sort(reverse=True)
ans = [x + y for y in a for x in bc[:k]]
ans.sort(reverse=True)
print(*ans[:k], sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = list(input())
ac = {i+1 for i in range(n-1) if s[i] + s[i+1] == "AC"}
for _ in range(q):
    l, r = map(int, input().split())
    lr = set(range(l, r))
    print(len(ac & lr))


Fixed submission:
n, q = map(int, input().split())
s = input()

ac = [0] * n
for i in range(1, n):
    ac[i] = ac[i-1] + int(s[i-1:i+1] == "AC")

for _ in range(q):
    l, r = map(int, input().split())
    print(ac[r-1] - ac[l-1])
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):
    res = float("inf")
    for j in range(1, min(i, k)+1):
        res = min(res, abs(h[i] - h[i-j]) + dp[i-j])
    dp[i] = res

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):
    res = float("inf")
    for j in range(1, min(i, k)+1):
        res = min(res, abs(h[i] - h[i-j]) + dp[i-j])
    dp[i] = res

print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
from fractions import gcd

n, m = map(int, input().split())
s = input()
t = input()
l = n * m // gcd(n, m)
x = [""] * l

for i in range(0, l, l//n):
    x[i] = s[i*n//l]

for i in range(0, l, l//m):
    if x[i]:
        if x[i] != t[i*m//l]:
            print(-1)
            break
    else: x[i] = t[i*m//l]
else: print(l)


Fixed submission:
from fractions import gcd

n, m = map(int, input().split())
s = input()
t = input()
g = gcd(n, m)
l = n * m // g

for i in range(g):
    if s[i*n//g] != t[i*m//g]:
        print(-1)
        break
else: print(l)

Buggy python submission (verdict: Runtime Error):
from fractions import gcd

n, m = map(int, input().split())
s = input()
t = input()
l = n * m // gcd(n, m)
x = [""] * l

for i in range(n):
    x[i*l//n] = s[i]

for i in range(m):
    index = i*l//m
    if x[index]:
        if x[index] != t[i]:
            print(-1)
            break
    else: x[index] = t[i]
else: print(l)


Fixed submission:
from fractions import gcd

n, m = map(int, input().split())
s = input()
t = input()
g = gcd(n, m)
l = n * m // g

for i in range(g):
    if s[i*n//g] != t[i*m//g]:
        print(-1)
        break
else: print(l)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [tuple(map(int, input().split())) for _ in range(n-1)]
s.append((0, 0, 0))

for i in range(n):
    sec = s[i][0] + s[i][1]
    for j in range(i+1, n-1):
        c = s[j][1]
        while True:
            if c >= sec:
                sec = c
                break
            c += s[j][2]
        sec += s[j][0]
    print(sec)


Fixed submission:
from math import ceil

n = int(input())
s = [tuple(map(int, input().split())) for _ in range(n-1)]
s.append((0, 0, 0))

for i in range(n):
    sec = s[i][0] + s[i][1]
    for j in range(i+1, n-1):
        if sec < s[j][1]: sec = s[j][1]
        else: sec = s[j][2] * ceil(sec / s[j][2])
        sec += s[j][0]
    print(sec)
Buggy python submission (verdict: Runtime Error):
n = int(input())

def get_divisors(num):
    f_divs, l_divs = [], []
    for i in range(1, int(num**0.5)+1):
        if not num % i:
            f_divs.append(i)
            if i != num // i:
                l_divs.append(num // i)
    return f_divs[-1], l_divs[-1]

print(max(*map(lambda x: len(str(x)), get_divisors(n))))


Fixed submission:
n = int(input())

def get_divisors(num):
    f_divs, l_divs = [], []
    for i in range(1, int(num**0.5)+1):
        if not num % i:
            f_divs.append(i)
            l_divs.append(num // i)
    return f_divs, l_divs

div1, div2 = get_divisors(n)
ans = float("inf")
for i in range(len(div1)):
    ans = min(ans, max(len(str(div1[i])), len(str(div2[i]))))
print(ans)
Buggy python submission (verdict: Runtime Error):
s = [ord(x) - ord("a") for x in input()]
k = int(input())

for i in range(len(s)):
    if s[i] == 0: continue
    r = 26 - s[i]
    if r <= k:
        k -= r
        s[i] = 0

s[-1] += k
print("".join([chr(x + ord("a")) for x in s]))


Fixed submission:
s = [ord(x) - ord("a") for x in input()]
k = int(input())

for i in range(len(s)):
    if s[i] == 0: continue
    r = 26 - s[i]
    if r <= k:
        k -= r
        s[i] = 0

s[-1] = (s[-1] + k) % 26
print("".join([chr(x + ord("a")) for x in s]))
Buggy python submission (verdict: Time Limit Exceeded):
n, m, s, t = map(int, input().split())
s-=1
t-=1
G = [[] for i in range(n)]
for i in range(m):
    u,v,a,b=map(int,input().split())
    G[u-1].append((v-1,a,b))
    G[v-1].append((u-1,a,b))

V=10**15
ans=[0]*n
from heapq import heappush,heappop
def dijkstra(u,k):
    D=[10**18]*n
    q=[(u,0)]
    D[u]=0
    while q:
        u,d=heappop(q)
        if D[u]<d: continue
        for v ,a ,b in G[u]:
            w=b if k else a
            if d + w < D[v]:
                D[v]=d+w
                heappush(q,(v,d+w))
    return D
D1=dijkstra(s,0)
D2=dijkstra(t,1)
tmp=1e18
for i in reversed(range(n)):
    tmp=min(tmp,D1[i]+D2[i])
    ans[i]=10**15-tmp
print(*ans,sep="\n")



Fixed submission:
n, m, s, t = map(int, input().split())
s-=1
t-=1
G = [[] for i in range(n)]
for i in range(m):
    u,v,a,b=map(int,input().split())
    G[u-1].append((v-1,a,b))
    G[v-1].append((u-1,a,b))

V=10**15
ans=[0]*n
from heapq import heappush,heappop
def dijkstra(u,k):
    D=[10**18]*n
    q=[(0,u)]
    D[u]=0
    while q:
        d,u=heappop(q)
        if D[u]<d: continue
        for v ,a ,b in G[u]:
            w=b if k else a
            if d + w < D[v]:
                D[v]=d+w
                heappush(q,(d+w,v))
    return D
D1=dijkstra(s,0)
D2=dijkstra(t,1)
tmp=1e18
for i in reversed(range(n)):
    tmp=min(tmp,D1[i]+D2[i])
    ans[i]=10**15-tmp
print(*ans,sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
n, m, s, t = map(int, input().split())
s-=1
t-=1
G = [[] for i in range(n)]
for i in range(m):
    u,v,a,b=map(int,input().split())
    G[u-1].append((v-1,a,b))
    G[v-1].append((u-1,a,b))

V=10**15
ans=[0]*n
from heapq import heappush,heappop
def dijkstra(u,k):
    D=[10**18]*n
    q=[(u,0)]
    D[u]=0
    while q:
        u,d=heappop(q)
        if D[u]<d: continue
        for v ,a ,b in G[u]:
            w=b if k else a
            if d + w < D[v]:
                D[v]=d+w
                heappush(q,(v,d+w))
    return D
D1=dijkstra(s,0)
D2=dijkstra(t,1)
tmp=1e18
for i in reversed(range(n)):
    tmp=min(tmp,D1[i]+D2[i])
    ans[i]=10**15-tmp
print(*ans,sep="\n")



Fixed submission:
n, m, s, t = map(int, input().split())
s-=1
t-=1
G = [[] for i in range(n)]
for i in range(m):
    u,v,a,b=map(int,input().split())
    G[u-1].append((v-1,a,b))
    G[v-1].append((u-1,a,b))

V=10**15
ans=[0]*n
from heapq import heappush,heappop
def dijkstra(u,k):
    D=[10**18]*n
    q=[(0,u)]
    D[u]=0
    while q:
        d,u=heappop(q)
        if D[u]<d: continue
        for v ,a ,b in G[u]:
            w=b if k else a
            if d + w < D[v]:
                D[v]=d+w
                heappush(q,(d+w,v))
    return D
D1=dijkstra(s,0)
D2=dijkstra(t,1)
tmp=1e18
for i in reversed(range(n)):
    tmp=min(tmp,D1[i]+D2[i])
    ans[i]=10**15-tmp
print(*ans,sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7

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

ans = 0

for i in range(n-1):
    ans += a[i] * sum(a[i+1:])
    ans %= MOD

print(ans)


Fixed submission:
MOD = 10**9 + 7

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

s = sum(a)
ans = 0

for i in range(n-1):
    s -= a[i]
    ans += a[i] * s
    ans %= MOD

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7

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

ans = 0

for i in range(n-1):
    for j in range(i+1, n):
        ans += a[i] * a[j]
        ans %= MOD

print(ans)


Fixed submission:
MOD = 10**9 + 7

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

s = sum(a)
ans = 0

for i in range(n-1):
    s -= a[i]
    ans += a[i] * s
    ans %= MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

s = 0

for i in range(len(str(n))):
    s += n % 10
    n //= 10
    s %= 9

print('Yes' if s == 0 else 'No')


Fixed submission:
n = int(input())

print('Yes' if n % 9 == 0 else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

ans = 1000
buy = -1
for bit in range(2 ** n):
    money = 1000
    stock = 0
    for i in range(n):
        if (bit >> i) & 1:
            buy = i
            stock += money // A[i]
            money -= A[i] * (money // A[i])
        else:
            if buy == -1:
                continue
            elif A[buy] < A[i]:
                money += stock * A[i]
                stock = 0
    money += stock * A[-1]
    if money > ans:
        ans = money

print(ans)


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

money = 1000
stock = 0

for i in range(n-1):
    if A[i] < A[i+1]:
        tmp = money // A[i]
        stock += tmp
        money -= tmp * A[i]
    if A[i] > A[i+1]:
        money += stock * A[i]
        stock = 0
money += stock * A[-1]
print(money)

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

ans = 1000
for bit in range(2 ** n):
    money = 1000
    stock = 0
    for i in range(n):
        if (bit >> i) & 1:
            stock += money // A[i]
            money -= A[i] * (money // A[i])
        else:
            money += stock * A[i]
            stock = 0
    if money > ans:
        ans = money

print(ans)


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

money = 1000
stock = 0

for i in range(n-1):
    if A[i] < A[i+1]:
        tmp = money // A[i]
        stock += tmp
        money -= tmp * A[i]
    if A[i] > A[i+1]:
        money += stock * A[i]
        stock = 0
money += stock * A[-1]
print(money)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

def prime_factorize(n):
    prime_factor_list = []
    while n%2 == 0:
        prime_factor_list.append(2)
        n //= 2
    f = 3
    while f*f <= n:
        if n%f == 0:
            prime_factor_list.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        prime_factor_list.append(n)
    
    prime_factor = collections.Counter(prime_factor_list)

    return prime_factor

def yakusuu(n):
    c = prime_factorize(n)
    res = 1
    for i in c.values():
        res *= (i + 1)
    
    return res

n = int(input())

ans = 0

for i in range(1, n+1):
    y = yakusuu(i)
    ans += i * y

print(ans)


Fixed submission:
n = int(input())

def s(n):
    return n * (n + 1) // 2

ans = 0

for i in range(1, n+1):
    tmp = n // i
    ans += i * s(tmp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


def prime_factrize(n):
    prime_list = primes(n)
    s = int(math.sqrt(n)) + 1
    l = [0]*s
    for x in prime_list:
        if x**2 > n:
            break
        while n % x == 0:
            n // x
            l[x] += 1
    
    return l

def yakusuu(n):
    l = prime_factrize(n)
    res = 1

    for i in l:
        res *= (i + 1)

    return res

n = int(input())

ans = 0

for i in range(1, n+1):
    y = yakusuu(i)
    ans += i * y

print(ans)


Fixed submission:
n = int(input())

def s(n):
    return n * (n + 1) // 2

ans = 0

for i in range(1, n+1):
    tmp = n // i
    ans += i * s(tmp)

print(ans)

Buggy python submission (verdict: Runtime Error):
import sympy

n = int(input())

ans = 0

for i in range(1, n+1):
    c = sympy.divisor_count(i)
    ans += i * c

print(ans)


Fixed submission:
n = int(input())

def s(n):
    return n * (n + 1) // 2

ans = 0

for i in range(1, n+1):
    tmp = n // i
    ans += i * s(tmp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

def prime_factorize(n):
    prime_factor_list = []
    while n%2 == 0:
        prime_factor_list.append(2)
        n //= 2
    f = 3
    while f*f <= n:
        if n%f == 0:
            prime_factor_list.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        prime_factor_list.append(n)
    
    prime_factor = collections.Counter(prime_factor_list)

    return prime_factor

def yakusuu(n):
    c = prime_factorize(n)
    res = 1
    for i in c.values():
        res *= (i + 1)
    
    return res

n = int(input())

ans = 0

for i in range(1, n+1):
    y = yakusuu(i)
    ans += i * y

print(ans)


Fixed submission:
n = int(input())

def s(n):
    return n * (n + 1) // 2

ans = 0

for i in range(1, n+1):
    tmp = n // i
    ans += i * s(tmp)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = list(map(int, input().split()) for _ in range(q))

num = [0]*(10**5 + 1)
for i in range(10**5 + 1):
    num[i] = a.count(i)

s = sum(a)

for b, c in bc:
    s += (c - b)*num[b]
    num[c] += num[b]
    num[b] = 0

    print(s)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = list(map(int, input().split()) for _ in range(q))

s = sum(a)

num = [0]*(10**5 + 1)
for x in a:
    num[x] += 1

for b, c in bc:
    s += (c - b)*num[b]
    num[c] += num[b]
    num[b] = 0

    print(s)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
q = int(input())

s = sum(a)

num = [0]*10**5

for i in range(10**5):
    num[i] = a.count(i)

for i in range(q):
    b, c = map(int, input().split())
    d = (c-b) * num[b]
    num[c] += num[b]
    num[b] = 0
    s += d
    print(s)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = list(map(int, input().split()) for _ in range(q))

s = sum(a)

num = [0]*(10**5 + 1)
for x in a:
    num[x] += 1

for b, c in bc:
    s += (c - b)*num[b]
    num[c] += num[b]
    num[b] = 0

    print(s)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
h=list(map(int,input().split()))
a=[]
b=[]
for i in range(m):
    a.append(int(input())
    b.append(int(input())

l=[]
for i in range(m):
    l.append(max(a[i],b[i]))

li=[]
for i in l:
    if i in a and a[index(i)] > b[index(i)]:
        li.append(i)
    elif i in b and a[index(i)] < b[index(i)]:
        li.append(i)

for i in range(1,n+1):
    if i not in a and i not in b:
        li.append(i)
 print(lem(li))

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

for i in range(m):
    a,b=map(int,input().split())
    if h[a-1] < h[b-1]:
        ans[a-1] = 1
    elif h[a-1] > h[b-1]:
        ans[b-1] += 1
    else:
        ans[a-1] += 1
        ans[b-1] += 1

print(ans.count(0))
Buggy python submission (verdict: Time Limit Exceeded):
import math
a,b,n=map(int,input().split())
ans=0
for x in range(n+1):
    y = math.floor(a*x/b) - a* math.floor(x/b)
    ans=max(ans,y)

print(ans)

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

if n<b:
    print(math.floor(a*n/b))
else:
    print(math.floor(a*(b-1)/b))