Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from sys import setrecursionlimit

setrecursionlimit(10**10)

def dfs(v):
    flag = True

    for nxt in edge[v]:
        if l[v] == l[nxt]:
            return False
        elif l[v] + l[nxt] == 1:
            continue
        else:
            l[nxt] = 1 - l[v]
            cnt[1-l[v]] += 1
            flag &= dfs(nxt)
    
    return flag
        

n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

l = [-1] * n
l[0] = 0
cnt = [1, 0]

if dfs(0):
    print(cnt[0] * cnt[1] - m)
else:
    print(n * (n - 1) // 2 - m)

Fixed submission:
from sys import setrecursionlimit

setrecursionlimit(10**6)

def dfs(v):
    flag = True

    for nxt in edge[v]:
        if l[v] == l[nxt]:
            return False
        elif l[v] + l[nxt] == 1:
            continue
        else:
            l[nxt] = 1 - l[v]
            cnt[1-l[v]] += 1
            flag &= dfs(nxt)
    
    return flag
        

n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

l = [-1] * n
l[0] = 0
cnt = [1, 0]

if dfs(0):
    print(cnt[0] * cnt[1] - m)
else:
    print(n * (n - 1) // 2 - m)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

l = []
d = dict()
for v in a:
    if v not in d:
        d[v] = 1
    else:
        d[v] += 1
        
    if d[v] == 2:
        l.append(v)

l.sort()
print(l[-1] * l[-2])

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

l = []
d = dict()
for v in a:
    if v not in d:
        d[v] = 1
    else:
        d[v] += 1
        
    if d[v] == 2 or d[v] == 4:
        l.append(v)

if len(l) < 2:
    print(0)
else:
    l.sort()
    print(l[-1] * l[-2])
Buggy python submission (verdict: Runtime Error):
def dfs(v, p, d):
    dist[v] = d
    for c, cost in edge[v]:
        if c == p:
            continue
        dfs(c, v, d + cost)


n = int(input())

edge = [[] for _ in range(n)]
for _ in range(n-1):
    a, b, c = map(int, input().split())
    edge[a-1].append([b-1, c])
    edge[b-1].append([a-1, c])

q, k = map(int, input().split())

dist = [0] * n
dfs(k-1, -1, 0)

res = [0] * q
for i in range(q):
    x, y = map(int, input().split())
    res[i] = dist[x-1] + dist[y-1]

for v in res:
    print(v)

Fixed submission:
from heapq import heappush, heappop

def dijkstra(s):
    '''
    始点sから各頂点への最短距離を求める
    '''
    d = [float("inf")] * n
    d[s] = 0
    used = [False] * n
    used[s] = True
    edgelist = []

    for e in edge[s]:
        heappush(edgelist, e)

    while edgelist:
        cost, v = heappop(edgelist)
        if used[v]:
            continue
        d[v] = cost
        used[v] = True
        for e in edge[v]:
            if not used[e[1]]:
                heappush(edgelist, [e[0] + d[v], e[1]])

    return d


n = int(input())

edge = [[] for _ in range(n)]
for _ in range(n-1):
    a, b, c = map(int, input().split())
    edge[a-1].append([c, b-1])
    edge[b-1].append([c, a-1])

q, k = map(int, input().split())

dist = dijkstra(k-1)

res = [0] * q
for i in range(q):
    x, y = map(int, input().split())
    res[i] = dist[x-1] + dist[y-1]

for v in res:
    print(v)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit
from fractions import gcd

def segfunc(x, y):
    '''
    問題に応じて返り値を設定
    '''
    return gcd(x, y)


def init(a):
    '''
    配列aで初期化
    '''
    for i in range(n):
        seg[i+num-1] = a[i]    
    for i in range(num-2, -1, -1) :
        seg[i] = segfunc(seg[2*i+1], seg[2*i+2])


def query(p, q):
    '''
    [p, q)についてsegfuncを適用したものを返す
    '''
    if q <= p:
        return ide_ele
    
    p += num - 1
    q += num - 2
    res = ide_ele

    while q - p > 1:
        if p & 1 == 0:
            res = segfunc(res, seg[p])
        if q & 1 == 1:
            res = segfunc(res, seg[q])
            q -= 1
        p = p // 2
        q = (q - 1) // 2
    
    if p == q:
        res = segfunc(res, seg[p])
    else:
        res = segfunc(res, segfunc(seg[p], seg[q]))
    
    return res


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

if k > max(a):
    print('IMPOSSIBLE')
    exit()

num = (2 ** len(bin(n - 1)) - 2)
ide_ele = 0
seg = [ide_ele] * 2 * num

init(a)

if k % query(0, n) == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Fixed submission:
from sys import exit
from math import gcd

def segfunc(x, y):
    '''
    問題に応じて返り値を設定
    '''
    return gcd(x, y)


def init(a):
    '''
    配列aで初期化
    '''
    for i in range(n):
        seg[i+num-1] = a[i]    
    for i in range(num-2, -1, -1) :
        seg[i] = segfunc(seg[2*i+1], seg[2*i+2])


def query(p, q):
    '''
    [p, q)についてsegfuncを適用したものを返す
    '''
    if q <= p:
        return ide_ele
    
    p += num - 1
    q += num - 2
    res = ide_ele

    while q - p > 1:
        if p & 1 == 0:
            res = segfunc(res, seg[p])
        if q & 1 == 1:
            res = segfunc(res, seg[q])
            q -= 1
        p = p // 2
        q = (q - 1) // 2
    
    if p == q:
        res = segfunc(res, seg[p])
    else:
        res = segfunc(res, segfunc(seg[p], seg[q]))
    
    return res


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

if k > max(a):
    print('IMPOSSIBLE')
    exit()

num = (2 ** len(bin(n - 1)) - 2)
ide_ele = 0
seg = [ide_ele] * 2 * num

init(a)

if k % query(0, n) == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

q = int(input())

m = {}

for i in range(100000):
  m[i] = 0

for e in a:
  m[e] += 1
  
ans = sum(a)

for i in range(q):
  b,q = map(int,input().split())
  diff = (q-b) * m[b]
  
  m[q] += m[b]
  m[b] = 0
  
  ans += diff
  print(ans)
  

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

q = int(input())

m = {}

for i in range(1000000):
  m[i] = 0

for e in a:
  m[e] += 1
  
ans = sum(a)

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

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
x = 1
if 0 in a:
  print(0)
  exit()
for e in a:
  x *= e
  if x > 10**18:
    print(-1)
    exit()
print(x)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
b = 100*b
print((a*b)//100)

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

print((a*b)//100)
Buggy python submission (verdict: Runtime Error):
import math

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

def gcd(x,y):
    return x if y == 0 else gcd(y,x%y)

def lcm(x,y):
    return (x*y)//gcd(x,y)

now_lcm = a[0]
for i in range(n-1):
    now_lcm = lcm(now_lcm,a[i+1])

mod = 1e9+7
ans = 0
for e in a:
    ans = ((ans%mod) + ((now_lcm//e)%mod))%mod

print(int(ans))


Fixed submission:
import math

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

def gcd(x,y):
    return x if y == 0 else gcd(y,x%y)

def lcm(x,y):
    return (x*y)//gcd(x,y)

now_lcm = a[0]
for i in range(n):
    now_lcm = lcm(now_lcm,a[i])

ans = 0
for e in a:
    ans += now_lcm//e

print(int(ans%(10**9+7)))
Buggy python submission (verdict: Runtime Error):
def gcd(x,y):
  return x if y=0 else gcd(y,x%y)

def lcm(x,y):
  return (x*y)/gcd(x,y)

a,b = map(int,input().split())

print(lcm(a,b))

Fixed submission:
def gcd(x,y):
  return x if y==0 else gcd(y,x%y)

def lcm(x,y):
  return (x*y)//gcd(x,y)

a,b = map(int,input().split())

print(lcm(a,b))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

n /= 2
if s[:n] == s[n:]:
  print("Yes")
else:
  print("No")


Fixed submission:
n = int(input())
s = input()

n //= 2
if s[:n] == s[n:]:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

n /= 2;
if s[:n] == s[n:]:
  print("Yes")
else:
  print("No")

Fixed submission:
n = int(input())
s = input()

n //= 2
if s[:n] == s[n:]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())

d = n//2
print((n-d)/d)

Fixed submission:
n = int(input())

d = n//2
print((n-d)/n)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

b = []
for i,e in enumerate(a):
  b.append(e,i+1)
  
sort(b)

for i,t in enumerate(b):
  if i == n-1:
    print(t[0])
  else:
    print(t[0],end=' ')

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

b = []
for i,e in enumerate(a):
  b.append((e,i+1))
  
b.sort()

for i,t in enumerate(b):
  if i == n-1:
    print(t[1])
  else:
    print(t[1],end=' ')

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

b = []
for i,e in enumerate(a):
  b.append(e,i+1)
  
sort(b)

print(' '.join(b))

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

b = []
for i,e in enumerate(a):
  b.append((e,i+1))
  
b.sort()

for i,t in enumerate(b):
  if i == n-1:
    print(t[1])
  else:
    print(t[1],end=' ')
Buggy python submission (verdict: Runtime Error):
s = input()
li = ["Sunny","Cloudy","Rainy"]
id = 0

if s == "Sunny":
  id = 1
elif s == "Cloudy:
  id = 2
else:
  id = 0
  
print(li[id])

Fixed submission:
s = input()
li = ["Sunny","Cloudy","Rainy"]
id = 0

if s == "Sunny":
  id = 1
elif s == "Cloudy":
  id = 2
else:
  id = 0
  
print(li[id])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 0

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

print(ans)


Fixed submission:
n = int(input())

print((n*(n-1))//2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
arr = list(map(int,input().split()))

arr.sort()

prev = arr[0]

for i in range(n-1)
  prev = (prev+arr[i+1])/2
  
print(prev)



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

arr.sort()

prev = arr[0]

for i in range(n-1):
  prev = (prev+arr[i+1])/2
  
print(prev)
Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
graph = [[] for i in range(n)]
for i in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  graph[a].append(b)
  graph[b].append(a)

weight = [0 for i in range(n)]
for i in range(q):
  p,x = map(int,input().split())
  weight[p-1] = x

st = [0]
visit = [false for i in range(n)]
while not len(st) == 0:
  now = st.pop()
  visit[now] = true
  for e in graph[now]:
    if visit[e]:
      continue
    weight[e] += weight[e]
    st.push(e)
    
print(' '.join(map(str,weight)))

Fixed submission:
n,q = map(int,input().split())
graph = [[] for i in range(n)]
for i in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  graph[a].append(b)
  graph[b].append(a)

weight = [0 for i in range(n)]
for i in range(q):
  p,x = map(int,input().split())
  weight[p-1] += x

st = [0]
visit = [False for i in range(n)]
while not len(st) == 0:
  now = st.pop()
  visit[now] = True
  for e in graph[now]:
    if visit[e]:
      continue
    weight[e] += weight[now]
    st.append(e)
    
print(' '.join(map(str,weight)))
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
print(a+b if b%a == 0 else b-a)

Fixed submission:
s = input()
m = int(s[5:7])

if m >= 5:
    print("TBD")
else:
    print("Heisei")
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
a = list(map(int,input().split()))

s = [0]*(n+1)

for i,e in enumerate(a):
    s[i+1] = s[i] + e

ans = 0
for i in range(1,n+1):
    sl = sorted(s[:i])
    l = bisect.bisect_left(sl,s[i])
    r = bisect.bisect_right(sl,s[i])

    ans += r-l

print(ans)


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

s = [0]*(n+1)

for i,e in enumerate(a):
    s[i+1] = s[i] + e

def comb(n,m):
    return math.factorial(n)//math.factorial(m)//math.factorial(n-m)

ans = 0
s = sorted(s)

l = 0
r = 0
#print(s)
while l < n+1:
    while r < n+1  and s[l] == s[r]:
        #print(r,s[r])
        r += 1

    if r-l >= 2:
        ans += comb(r-l,2)
    l = r

print(ans)

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

s = [0]*(n+1)

for i,e in enumerate(a):
    s[i+1] = s[i] + e

ans = 0
for i in range(1,n+1):
    sl = sorted(s[:i])
    l = bisect.bisect_left(sl,s[i])
    r = bisect.bisect_right(sl,s[i])

    ans += r-l

print(ans)


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

s = [0]*(n+1)

for i,e in enumerate(a):
    s[i+1] = s[i] + e

def comb(n,m):
    return math.factorial(n)//math.factorial(m)//math.factorial(n-m)

ans = 0
s = sorted(s)

l = 0
r = 0
#print(s)
while l < n+1:
    while r < n+1  and s[l] == s[r]:
        #print(r,s[r])
        r += 1

    if r-l >= 2:
        ans += comb(r-l,2)
    l = r

print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
n = len(s)
p = 0
for e in s:
  if e == 'p':
    p += 1
print(s//2 - p)

Fixed submission:
s = input()
n = len(s)
p = 0
for e in s:
  if e == 'p':
    p += 1
print(n//2 - p)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())

print((a+b)*h//2)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())

print((a+b)*c//2)
Buggy python submission (verdict: Runtime Error):
class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod
        self.fac = [1 for i in range(self.n + 1)]
        self.finv = [1 for i in range(self.n + 1)]
        for i in range(2, self.n+1):
            self.fac[i] = (self.fac[i - 1] * i) % self.mod
            self.finv[i] = (self.finv[i-1] * pow(i, -1, self.mod)) % self.mod

    def comb(self, n, m):
        return self.fac[n] * (self.finv[n-m] * self.finv[m] % self.mod) % self.mod
def iparse():
    return list(map(int, input().split()))

if __name__ == "__main__":
    n, a = iparse()
    x = iparse()

    dp = [[[0 for i in range(sum(x) + 10)] for j in range(n + 10)] \
        for k in range(n + 10)]
    dp[0][0][0] = 1
    for i in range(n):
        for j in range(n + 1):
            for k in range(sum(x) + 1):
                if j >= 1 and k - x[i] >= 0:
                    dp[i + 1][j][k] = dp[i][j][k] + dp[i][j - 1][k - x[i]]
                else:
                    dp[i+1][j][k] = dp[i][j][k]
    ans = 0
    for i in range(n):
        ans += dp[n][i + 1][(i+1)*a]
    print(ans)
    


Fixed submission:
class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod
        self.fac = [1 for i in range(self.n + 1)]
        self.finv = [1 for i in range(self.n + 1)]
        for i in range(2, self.n+1):
            self.fac[i] = (self.fac[i - 1] * i) % self.mod
            self.finv[i] = (self.finv[i-1] * pow(i, -1, self.mod)) % self.mod

    def comb(self, n, m):
        return self.fac[n] * (self.finv[n-m] * self.finv[m] % self.mod) % self.mod
def iparse():
    return list(map(int, input().split()))

if __name__ == "__main__":
    n, a = iparse()
    x = iparse()

    dp = [[[0 for i in range(sum(x) + 10)] for j in range(n + 10)] \
        for k in range(n + 10)]
    dp[0][0][0] = 1
    for i in range(n):
        for j in range(n + 1):
            for k in range(sum(x) + 1):
                if j >= 1 and k - x[i] >= 0:
                    dp[i + 1][j][k] = dp[i][j][k] + dp[i][j - 1][k - x[i]]
                else:
                    dp[i+1][j][k] = dp[i][j][k]
    ans = 0
    for i in range(n):
        if (i + 1) * a >= sum(x) + 10:
            break
        ans += dp[n][i + 1][(i+1)*a]
    print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
st = []
for e in s:
  if e == 'B' and len(st) != 0:
    st.pop()
  else:
    st.append(int(e))
print(''.join(map(str,st)))


Fixed submission:
s = input()
st = []
for e in s:
  if e == 'B':
    if len(st) != 0:
      st.pop()
  else:
    st.append(int(e))
print(''.join(map(str,st)))

Buggy python submission (verdict: Runtime Error):
s = input()
st = []
for e in s:
  if e == B and len(st) != 0:
    st.pop()
  else:
    st.append(int(e))
print(''.join(map(str,st)))

Fixed submission:
s = input()
st = []
for e in s:
  if e == 'B':
    if len(st) != 0:
      st.pop()
  else:
    st.append(int(e))
print(''.join(map(str,st)))
Buggy python submission (verdict: Time Limit Exceeded):

import queue

n,m=map(int,input().split())

G=[[] for i in range(n)]

for _ in range(m):
 y,yy=map(int,input().split())
 y-=1
 yy-=1
 G[y].append(yy)
 G[yy].append(y)

q=queue.Queue()

vis=[0]*n
mae=[-1]*n

q.put([0,0])
while q.empty()==False:
 r=q.get()
 if vis[r[0]]==1:
  continue
 vis[r[0]]=1
 mae[r[0]]=r[1]
 for v in G[r[0]]:
  q.put([v,r[0]])

print("Yes")
for i in range(1,n):
 print(mae[i]+1)

Fixed submission:

import queue

n,m=map(int,input().split())

G=[[] for i in range(n)]

for _ in range(m):
 y,yy=map(int,input().split())
 y-=1
 yy-=1
 G[y].append(yy)
 G[yy].append(y)

q=queue.Queue()

vis=[0]*n
mae=[-1]*n

q.put([0,0])
while q.empty()==False:
 r=q.get()
 if vis[r[0]]==1:
  continue
 vis[r[0]]=1
 mae[r[0]]=r[1]
 for v in G[r[0]]:
  if vis[v]==0:
   q.put([v,r[0]])

print("Yes")
for i in range(1,n):
 print(mae[i]+1)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
input = stdin.readline

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

ls = []
s = set([])

a = X
s.add(a)
ls.append(a)

while True:
    a = pow(a, 2, M)

    if a in s:
        ind = ls.index(a)
        break
    elif len(ls) == N:
        break
    else:
        s.add(a)
        ls.append(a)

new_ls = ls[ind:len(ls)]

ans = sum(ls)

if len(new_ls) != 0:
    ans += sum(new_ls) * (max(0, (N - len(ls))) // len(new_ls))

    tmp = max(0, (N - len(ls))) % len(new_ls)

    if tmp != 0:
        for i in range(tmp):
            ans += new_ls[i % len(new_ls)]

print(ans)


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

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

ls = []
s = set([])

a = X
s.add(a)
ls.append(a)
ind = -1
new_ls = []

while True:
    a = pow(a, 2, M)

    if a in s:
        ind = ls.index(a)
        break
    elif len(ls) == N:
        break
    else:
        s.add(a)
        ls.append(a)

if ind != -1:
    new_ls = ls[ind:len(ls)]

ans = sum(ls)

if len(new_ls) != 0:
    ans += sum(new_ls) * (max(0, (N - len(ls))) // len(new_ls))

    tmp = max(0, (N - len(ls))) % len(new_ls)

    if tmp != 0:
        for i in range(tmp):
            ans += new_ls[i % len(new_ls)]

print(ans)

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

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

ls = []
s = set([])

a = X
s.add(a)
ls.append(a)

while True:
    a = pow(a, 2, M)

    if a in s:
        ind = ls.index(a)
        break
    elif len(ls) == N:
        break
    else:
        s.add(a)
        ls.append(a)

new_ls = ls[ind:len(ls)]

ans = sum(new_ls) * (max(0, (N - len(ls))) // len(new_ls)) + sum(ls)

tmp = max(0, (N - len(ls))) % len(new_ls)

if tmp != 0:
    for i in range(tmp):
        ans += new_ls[i % len(new_ls)]

print(ans)


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

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

ls = []
s = set([])

a = X
s.add(a)
ls.append(a)
ind = -1
new_ls = []

while True:
    a = pow(a, 2, M)

    if a in s:
        ind = ls.index(a)
        break
    elif len(ls) == N:
        break
    else:
        s.add(a)
        ls.append(a)

if ind != -1:
    new_ls = ls[ind:len(ls)]

ans = sum(ls)

if len(new_ls) != 0:
    ans += sum(new_ls) * (max(0, (N - len(ls))) // len(new_ls))

    tmp = max(0, (N - len(ls))) % len(new_ls)

    if tmp != 0:
        for i in range(tmp):
            ans += new_ls[i % len(new_ls)]

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

setrecursionlimit(10 ** 8)

S = int(input())

A = [-1] * (S + 1)
mod = 10 ** 9 + 7

for i in range(3):
    A[i] = 0

for i in range(3, 6):
    A[i] = 1


def dfs(n):
    if A[n] != -1:
        return A[n]
    else:
        A[n] = (dfs(n - 3) + dfs(n - 1)) % mod
        return A[n]


print(dfs(S))


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

S = int(input())

A = [-1] * (2001)
mod = 10 ** 9 + 7

for i in range(3):
    A[i] = 0

for i in range(3, 6):
    A[i] = 1


def dfs(n):
    if A[n] != -1:
        return A[n]
    else:
        A[n] = (dfs(n - 3) + dfs(n - 1)) % mod
        return A[n]


print(dfs(S))

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

S = int(input())

A = [-1] * (S + 1)
mod = 10 ** 9 + 7

for i in range(3):
    A[i] = 0

for i in range(3, 6):
    A[i] = 1


def dfs(n):
    if A[n] != -1:
        return A[n]
    else:
        A[n] = (dfs(n - 3) + dfs(n - 1)) % mod
        return A[n]


print(dfs(S))


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

S = int(input())

A = [-1] * (2001)
mod = 10 ** 9 + 7

for i in range(3):
    A[i] = 0

for i in range(3, 6):
    A[i] = 1


def dfs(n):
    if A[n] != -1:
        return A[n]
    else:
        A[n] = (dfs(n - 3) + dfs(n - 1)) % mod
        return A[n]


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

X, K, D = map(int, input().split())

m = X % D
l = X // D

if l > K:
    print(abs(abs(X) - D * K))
else:
    if (K - l) % 2 == 0:
        print(m)
        exit(1)
    else:
        print(D - m)


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

X, K, D = map(int, input().split())

X = abs(X)

m = X % D
l = X // D

if l > K:
    print(abs(X) - D * K)
else:
    if (K - l) % 2 == 0:
        print(m)
    else:
        print(D - m)

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

X, K, D = map(int, input().split())

m = X % D
l = X // D

if l > K:
    print(abs(abs(X) - D * K))
    exit(1)
else:
    if (K - l) % 2 == 0:
        print(m)
    else:
        print(D - m)


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

X, K, D = map(int, input().split())

X = abs(X)

m = X % D
l = X // D

if l > K:
    print(abs(X) - D * K)
else:
    if (K - l) % 2 == 0:
        print(m)
    else:
        print(D - m)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
input = stdin.readline

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

ans_ls = []
tmp = 1

for i in range(K):
    tmp *= A[i]

ans_ls.append(tmp)

for i in range(K, N):
    tmp //= A[i - K]
    tmp *= A[i]
    ans_ls.append(tmp)

for i in range(len(ans_ls) - 1):
    if ans_ls[i + 1] <= ans_ls[i]:
        print("No")
    else:
        print("Yes")


Fixed submission:
from sys import stdin
from collections import deque
input = stdin.readline

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

q = deque([])

for i in range(K):
    q.append(A[i])

for i in range(K, N):
    tmp = q.popleft()
    if A[i] <= tmp:
        print("No")
    else:
        print("Yes")
    q.append(A[i])
Buggy python submission (verdict: Runtime Error):
from sys import stdin
input = stdin.readline

N = int(input())
A = list(map(int, input().split()))
Q = int(input())

ls = [0] * 10 ** 5

for a in A:
    ls[a] += 1

s = sum(A)

for _ in range(Q):
    B, C = map(int, input().split())
    s += ls[B] * (C - B)
    ls[B], ls[C] = 0, ls[B] + ls[C]
    print(s)


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

N = int(input())
A = list(map(int, input().split()))
Q = int(input())

ls = [0] * 10 ** 6

for a in A:
    ls[a] += 1

s = sum(A)

for _ in range(Q):
    B, C = map(int, input().split())
    s += ls[B] * (C - B)
    ls[C] += ls[B]
    ls[B] = 0
    print(s)