Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, *bc = map(int, open(0).read().split())
a = [bc.pop(0) for _ in range(n)]
q = bc.pop(0)

d = {}
for x in a:
    if x in d:
        d[x] += 1
    else:
        d[x] = 1
ret = sum(a)
for i in range(0, min(q*2, len(bc)), 2):
    b = bc[i]
    c = bc[i+1]
    if b in d:
        v = d.pop(b)
        if c in d:
            d[c] += v
        else:
            d[c] = v
        ret += c * v - b * v
    #ret = sum([k * v for k, v in d.items()])
    print(ret)

Fixed submission:
n, r = open(0).read().split(maxsplit=1)
n = int(n)
*a, r = r.split(maxsplit=n)
a = list(map(int, a))
q, *bc = map(int, r.split())

d = {}
for x in a:
    if x in d:
        d[x] += 1
    else:
        d[x] = 1
ret = sum(a)
for i in range(0, min(q*2, len(bc)), 2):
    b = bc[i]
    c = bc[i+1]
    if b in d:
        v = d.pop(b)
        if c in d:
            d[c] += v
        else:
            d[c] = v
        ret += c * v - b * v
    #ret = sum([k * v for k, v in d.items()])
    print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
n, *bc = map(int, open(0).read().split())
a = [bc.pop(0) for _ in range(n)]
q = bc.pop(0)

d = {}
for x in a:
    if x in d:
        d[x] += 1
    else:
        d[x] = 1
for i in range(0, min(q*2, len(bc)), 2):
    b = bc[i]
    c = bc[i+1]
    if b in d:
        if c in d:
            d[c] += d.pop(b)
        else:
            d[c] = d.pop(b)
    ret = sum([k * v for k, v in d.items()])
    print(ret)

Fixed submission:
n, r = open(0).read().split(maxsplit=1)
n = int(n)
*a, r = r.split(maxsplit=n)
a = list(map(int, a))
q, *bc = map(int, r.split())

d = {}
for x in a:
    if x in d:
        d[x] += 1
    else:
        d[x] = 1
ret = sum(a)
for i in range(0, min(q*2, len(bc)), 2):
    b = bc[i]
    c = bc[i+1]
    if b in d:
        v = d.pop(b)
        if c in d:
            d[c] += v
        else:
            d[c] = v
        ret += c * v - b * v
    #ret = sum([k * v for k, v in d.items()])
    print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
n, *bc = map(int, open(0).read().split())
a = [bc.pop(0) for _ in range(n)]
q = bc.pop(0)

d = {}
for x in a:
    if x in d:
        d[x] += 1
    else:
        d[x] = 1
for i in range(0, min(q*2, len(bc)), 2):
    b = bc[i]
    c = bc[i+1]
    if b in d:
        if c in d:
            d[c] += d.pop(b)
        else:
            d[c] = d.pop(b)
    ret = sum([k * v for k, v in d.items()])
    print(ret)

Fixed submission:
n, r = open(0).read().split(maxsplit=1)
n = int(n)
*a, r = r.split(maxsplit=n)
a = list(map(int, a))
q, *bc = map(int, r.split())

d = {}
for x in a:
    if x in d:
        d[x] += 1
    else:
        d[x] = 1
ret = sum(a)
for i in range(0, min(q*2, len(bc)), 2):
    b = bc[i]
    c = bc[i+1]
    if b in d:
        v = d.pop(b)
        if c in d:
            d[c] += v
        else:
            d[c] = v
        ret += c * v - b * v
    #ret = sum([k * v for k, v in d.items()])
    print(ret)
Buggy python submission (verdict: Runtime Error):
import sympy


def calc():
    n, *a = map(int, open(0).read().split())
    black = set()
    r = set()
    for x in a:
        if x in r:
            black.add(x)
        r.add(x)

    r = set(a)
    count = 0
    for x in r:
        if r & black:
            continue
        if r & set(sympy.divisors(x)[:-1]):
            continue
        count += 1
    return count

print(calc())


Fixed submission:
n, *a = map(int, open(0).read().split())           
a.sort()                                           
s = set()                                          
checked = set()                                    
dup = set()                                        
count = 0                                          
for x in a:                                        
    if x in s:                                     
        if x in checked:                           
            dup.add(x)                             
        continue                                   
    count += 1                                     
    checked.add(x)                                 
    for i in range(1, 10**6 // x + 1):             
        s.add(x * i)                               
                                                   
print(count - len(dup))
Buggy python submission (verdict: Runtime Error):
import sys
import math                                               
a,b = [float(x) for x in sys.stdin.readline().split(" ")]
c = str(a * b).split(".")[0]                              
print(c)                                                  

Fixed submission:
import sys
def calc():                                             
    _ = int(sys.stdin.readline())                       
    xs = [int(x) for x in sys.stdin.readline().split(" ")]
    for x in xs:                                          
        if x == 0:                                        
            return 0                                      
    r = 1                                                 
    m = 10 ** 18                                          
    for x in xs:                                          
        r *= x                                            
        if r > m:                                         
            return -1                                     
    return r                                              
                                                          
print(calc())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
_ = int(sys.stdin.readline().strip())                 
xs = [int(x) for x in sys.stdin.readline().split(" ")]
r = 1                                                 
for x in xs:                                          
    r *= x                                            
if r > 10 ** 18:                                      
    print("-1")                                       
else:                                                 
    print(r)                                          

Fixed submission:
import sys
def calc():                                             
    _ = int(sys.stdin.readline())                       
    xs = [int(x) for x in sys.stdin.readline().split(" ")]
    for x in xs:                                          
        if x == 0:                                        
            return 0                                      
    r = 1                                                 
    m = 10 ** 18                                          
    for x in xs:                                          
        r *= x                                            
        if r > m:                                         
            return -1                                     
    return r                                              
                                                          
print(calc())
Buggy python submission (verdict: Runtime Error):
import sys                       
a = sys.stdin.readline().rstrip()
b = sys.stdin.readline().rstrip()
if a == b[:-1]:                  
  print "Yes"                    
else:                            
  print "No"                     
                                 

Fixed submission:
import sys                       
a = sys.stdin.readline().rstrip()
b = sys.stdin.readline().rstrip()
if a == b[:-1]:                  
  print("Yes")                   
else:                            
  print("No")

Buggy python submission (verdict: Runtime Error):
import sys
a = sys.stdin.readline()
b = sys.stdin.readline()
if a == b[:-1]:
  print "Yes"
else:
  print "No"

Fixed submission:
import sys                       
a = sys.stdin.readline().rstrip()
b = sys.stdin.readline().rstrip()
if a == b[:-1]:                  
  print("Yes")                   
else:                            
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N, S = open(0).read().split()
N = int(N)
ans = set()
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            ans.add(S[i] + S[j] + S[k])
print(len(ans))


Fixed submission:
N, S = open(0).read().split()
S = list(map(int, list(S)))
N = int(N)

cnt = 0
for i in range(0, 10):
        for j in range(0, 10):
            for k in range(0, 10):
                try:
                    n = S.index(i)
                    m = S[n+1:].index(j)
                    o = S[n+m+2:].index(k)
                    cnt += 1
                except ValueError:
                    pass
print(cnt)
Buggy python submission (verdict: Runtime Error):
import sys
import math

def lcm(a, b):
  return (a * b) // math.gcd(a, b)


a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
e = b - a + 1
f = int(b / c) - int((a - 1) / c)
g = int(b / d) - int((a - 1) / d)
cd = lcm(c, d)
h = int(b / cd) - int((a - 1) / cd)
n = e - f - g + h
print(n)


Fixed submission:
import sys
import math

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

def lcm(a, b):
  return (a * b) // gcd(a, b)

  
a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
e = b - a + 1
if c == d:
  fgh = (b // c) - ((a - 1) // c)
  n = e - fgh
  print(n) 
else:
  f = (b // c) - ((a - 1) // c)
  g = (b // d) - ((a - 1) // d)
  cd = lcm(c, d) 
  h = (b // cd) - ((a - 1) // cd)
  n = e - f - g + h
  print(n)

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

def lcm(a, b):
  return (a * b) // math.gcd(a, b)


a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
e = b - a + 1
f = int(b / c) - int((a - 1) / c)
g = int(b / d) - int((a - 1) / d)
cd = lcm(c, d)
h = int(b / cd) - int((a - 1) / cd)
n = e - f - g + h
print(n)


Fixed submission:
import sys
import math

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

def lcm(a, b):
  return (a * b) // gcd(a, b)

  
a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
e = b - a + 1
if c == d:
  fgh = (b // c) - ((a - 1) // c)
  n = e - fgh
  print(n) 
else:
  f = (b // c) - ((a - 1) // c)
  g = (b // d) - ((a - 1) // d)
  cd = lcm(c, d) 
  h = (b // cd) - ((a - 1) // cd)
  n = e - f - g + h
  print(n)

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

a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
e = b - a + 1
f = int(b / c) - int((a - 1) / c)
g = int(b / d) - int((a - 1) / d)
cd = math.lcm(c, d)
h = int(b / cd) - int((a - 1) / cd)
n = e - f - g + h
print(n)


Fixed submission:
import sys
import math

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

def lcm(a, b):
  return (a * b) // gcd(a, b)

  
a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
e = b - a + 1
if c == d:
  fgh = (b // c) - ((a - 1) // c)
  n = e - fgh
  print(n) 
else:
  f = (b // c) - ((a - 1) // c)
  g = (b // d) - ((a - 1) // d)
  cd = lcm(c, d) 
  h = (b // cd) - ((a - 1) // cd)
  n = e - f - g + h
  print(n)
Buggy python submission (verdict: Runtime Error):
N,S = open(0).read().split()
N=int(N)
S=list(S)

def calc():
    group = [] if S[0] == '.' else [0]
    n = 0
    mark = S[0]
    for s in S:
        if s == mark:
            n += 1
        else:
            mark = s
            group.append(n)
            n = 1
    if n > 0:
        group.append(n)
    if S[-1] == '#':
        group.pop()

    cnt = 0
    i = 1
    j = len(group) - 1
    while i <= j:
        l = group[i]
        r = group[j]
        if l < r:
            cnt += l
            i += 2
        else:
            cnt += r
            j -= 2
    return cnt

all_w = sum([1 if s == '#' else 0 for s in S])
all_b = sum([1 if s == '.' else 0 for s in S])
lwrb = calc()
print(min(all_w, all_b, lwrb)

Fixed submission:
N,S = open(0).read().split()
N=int(N)
S=[s == "." for s in list(S)]

w = sum([1 if s else 0 for s in S])
b = 0
m = w + b
for s in S:
    if s:
        w -= 1
    else:
        b += 1
    m = min(m, w + b)
print(m)
Buggy python submission (verdict: Runtime Error):
n, k, *hs = [int(x) for x in open(0).read().split()]
dp = [0] * n
for i in range(1, n):
    v = 10000
    for j in range(max(0, i - k), i):
        v = min(v, dp[j] + abs(hs[i] - hs[j]))
    dp[i] = v
print(dp[n-1])

Fixed submission:
def delta(a, b):                                 
    return abs(a - b)                            
                                                 
n, *hs = [int(x) for x in open(0).read().split()]
l = len(hs)                                      
delta = lambda a, b: abs(hs[a] - hs[b])          
dp = [0, delta(1, 0)]                            
for i in range(2, l):                            
    dp.append(min(                               
        dp[i - 1] + delta(i, i - 1),             
        dp[i - 2] + delta(i, i - 2)))            
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n, k, *hs = [int(x) for x in open(0).read().split()]
dp = [0] * n                                        
for i in range(1, n):                               
    v = 10000                                       
    for j in range(max(0, i - k), i):               
        v = min(v, dp[j] + abs(hs[i] - hs[j]))      
    dp[i] = v                                       
print(dp[n-1])                                      

Fixed submission:
def delta(a, b):                                 
    return abs(a - b)                            
                                                 
n, *hs = [int(x) for x in open(0).read().split()]
l = len(hs)                                      
delta = lambda a, b: abs(hs[a] - hs[b])          
dp = [0, delta(1, 0)]                            
for i in range(2, l):                            
    dp.append(min(                               
        dp[i - 1] + delta(i, i - 1),             
        dp[i - 2] + delta(i, i - 2)))            
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n, k, *hs = [int(x) for x in open(0).read().split()]
dp = [0] * n                                        
for i in range(1, n):                               
    v = 10000                                       
    for j in range(max(0, i - k), i):               
        v = min(v, dp[j] + abs(hs[i] - hs[j]))      
    dp[i] = v                                       
print(dp[n-1])                                      

Fixed submission:
def delta(a, b):                                 
    return abs(a - b)                            
                                                 
n, *hs = [int(x) for x in open(0).read().split()]
l = len(hs)                                      
delta = lambda a, b: abs(hs[a] - hs[b])          
dp = [0, delta(1, 0)]                            
for i in range(2, l):                            
    dp.append(min(                               
        dp[i - 1] + delta(i, i - 1),             
        dp[i - 2] + delta(i, i - 2)))            
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, k, *hs = [int(x) for x in open(0).read().split()]                           
dp = [float("inf")] * n                                                        
dp[0] = 0                                                                      
for i in range(1, n):                                                          
    dp[i] = min([dp[j] + abs(hs[i] - hs[j]) for j in range(max(0, i - k), i)]) 
print(dp[n-1])                                                                 


Fixed submission:
def main():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j, i)])
    print(dp[n-1])

main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k, *hs = [int(x) for x in open(0).read().split()]           
l = len(hs)                                                    
delta = lambda a, b: abs(hs[a] - hs[b])                        
dp = [0]                                                       
for i in range(1, l):                                          
    cs = [dp[j] + delta(i, j) for j in range(max(0, i - k), i)]
    v = min(cs)                                                
    dp.append(v)                                               
print(dp[-1])                                                  

Fixed submission:
def main():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j, i)])
    print(dp[n-1])

main()

Buggy python submission (verdict: Runtime Error):
 n, k, *hs = [int(x) for x in open(0).read().split()]            
 l = len(hs)                                                     
 delta = lambda a, b: abs(hs[a] - hs[b])                         
 dp = [0]                                                        
 for i in range(1, l):                                           
     cs = [dp[j] + delta(i, j) for j in range(max(0, i - k), i)] 
     v = min(cs)                                                 
     dp.append(v)                                                
 print(dp[-1])                                                   

Fixed submission:
def main():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j, i)])
    print(dp[n-1])

main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, W, *wv = map(int, open(0).read().split())
    dp = [-1] * (W + 1)
    dp[0] = 0
    for i in range(n):
        w = wv[i * 2]
        v = wv[i * 2 + 1]
        for j in range(W - w, -1, -1):
            if dp[j] == -1:
                continue
            dp[j + w] = max(dp[j] + v, dp[j + w])
        #print(dp)
    print(max(dp))

main()

Fixed submission:
from numpy import zeros, maximum            
                                            
n, W, *wv = map(int, open(0).read().split())
t = zeros(W+1, int)                         
for i in range(n):                          
    w = wv[i * 2]                           
    v = wv[i * 2 + 1]                       
    t[w:] = maximum(t[w:], t[:-w]+v)        
print(t[-1])

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, W, *wv = map(int, open(0).read().split())
    dp = [0] * (W + 1)
    for i in range(n):
        w = wv[i * 2]
        v = wv[i * 2 + 1]
        for j in range(W, w - 1, -1):
            dp[j] = max(dp[j], dp[j - w] + v)
    print(dp[W])

main()

Fixed submission:
from numpy import zeros, maximum            
                                            
n, W, *wv = map(int, open(0).read().split())
t = zeros(W+1, int)                         
for i in range(n):                          
    w = wv[i * 2]                           
    v = wv[i * 2 + 1]                       
    t[w:] = maximum(t[w:], t[:-w]+v)        
print(t[-1])

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, W, *wv = map(int, open(0).read().split())
    dp = [[0] * (W + 1) for _ in range(n + 1)]
    for i in range(n):
        w = wv[i * 2]
        v = wv[i * 2 + 1]
        for j in range(0, w):
            dp[i + 1][j] = dp[i][j]
        for j in range(w, W + 1):
            dp[i + 1][j] = max(dp[i][j], dp[i][j - w] + v)
    print(dp[-1][W])

main()

Fixed submission:
from numpy import zeros, maximum            
                                            
n, W, *wv = map(int, open(0).read().split())
t = zeros(W+1, int)                         
for i in range(n):                          
    w = wv[i * 2]                           
    v = wv[i * 2 + 1]                       
    t[w:] = maximum(t[w:], t[:-w]+v)        
print(t[-1])
Buggy python submission (verdict: Runtime Error):
from itertools import permutations
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
m = [set() for _ in range(1, 9)]
for a, b in AB:
    m[a].add(b)
    m[b].add(a)

def main():
    ans = []
    def traverse(n, visits):
        visits = visits | set([n])
        if len(visits) == N:
            ans.append(1)
            return
        for c in m[n] - visits:
            traverse(c, visits)
    traverse(1, set())
    return len(ans)

print(main())

Fixed submission:
from itertools import permutations
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
m = [set() for _ in range(27)]
for a, b in AB:
    m[a].add(b)
    m[b].add(a)

def main():
    ans = []
    def traverse(n, visits):
        visits = visits | set([n])
        if len(visits) == N:
            ans.append(1)
            return
        for c in m[n] - visits:
            traverse(c, visits)
    traverse(1, set())
    return len(ans)

print(main())
Buggy python submission (verdict: Runtime Error):
s, t = map(input().split())
a, b = map(int, input().split())
u = input()
print(a-1,b if s==u else a,b-1)

Fixed submission:
s, t = input().split()
a, b = map(int, input().split())
u = input()
if s==u:
    print(a-1,b)
else:
    print(a,b-1)
Buggy python submission (verdict: Runtime Error):
K, X = map(int, input())
print("Yes" if 500*K>=X else "No")

Fixed submission:
K, X = map(int, input().split())
print("Yes" if 500*K>=X else "No")
Buggy python submission (verdict: Runtime Error):
a, b = int(input())
print(a*b if a<=9 and b<=9 else -1)

Fixed submission:
a, b = map(int, input().split())
print(a*b if a<=9 and b<=9 else -1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = [int(input()) for i in range(N)]
print("Yes" if max(L) < sum(L)-max(L) else "No")

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
print("Yes" if max(L) < sum(L)-max(L) else "No")
Buggy python submission (verdict: Runtime Error):
N = input()
print("ABC" if N<=999 else "ABD")

Fixed submission:
N = int(input())
print("ABC" if N<=999 else "ABD")

Buggy python submission (verdict: Runtime Error):
N = map(int, input().split())
print("ABC" if N<=999 else "ABD")

Fixed submission:
N = int(input())
print("ABC" if N<=999 else "ABD")
Buggy python submission (verdict: Runtime Error):
A, B = map(input().split())
print(max(A+B, A-B, A*B))

Fixed submission:
A, B = map(int, input().split())
print(max(A+B, A-B, A*B))
Buggy python submission (verdict: Runtime Error):
N = int(input())
print("YES" if N[0]==N[-1] else "NO")

Fixed submission:
N = input()
print("Yes" if N[0]==N[-1] else "No")
Buggy python submission (verdict: Runtime Error):
n=input()
if s[2]==s[3] and s[4]==s[5]:
  print("Yes")
else:
  print("No")
  

Fixed submission:
s=input()
if s[2]==s[3] and s[4]==s[5]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
  if(a[i]>=k):
    cnt+=1
    
print(cnt)  

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
  if(a[i]>=k):
    cnt+=1
    
print(cnt)
Buggy python submission (verdict: Runtime Error):
h,w,k=map(int,input().split())
c=[input() for _ in range(h)]
count=0
for H in range(h<<1):
  for W in range(W<<1):
    b=0
    for i in range(h):
      for j in range(w):
        if (H >> i) & 1 == 0 and (W >> j) & 1 == 0 and c[i][j] == "#":
          b+=1
    if b==k:
      count+=1
print(count)

Fixed submission:
h,w,k=map(int,input().split())
c=[input() for _ in range(h)]
count=0
for H in range(1<<h):
  for W in range(1<<w):
    b=0
    for i in range(h):
      for j in range(w):
        if (H >> i) & 1 == 0 and (W >> j) & 1 == 0 and c[i][j] == "#":
          b+=1
    if b==k:
      count+=1
print(count)

Buggy python submission (verdict: Runtime Error):
h,w,k=map(int,input().split())
c=[input() for _ in range(h)]
count=0
for H in range(h<<1):
  for W in range(W<<1):
    b=0
    for i in range(h):
      for j in range(w):
        if (W >> i) & 1 == 0 and (H >> j) & 1 == 0 and c[i][j] == "#":
          b+=1
    if b==k:
      count+=1
print(count)

Fixed submission:
h,w,k=map(int,input().split())
c=[input() for _ in range(h)]
count=0
for H in range(1<<h):
  for W in range(1<<w):
    b=0
    for i in range(h):
      for j in range(w):
        if (H >> i) & 1 == 0 and (W >> j) & 1 == 0 and c[i][j] == "#":
          b+=1
    if b==k:
      count+=1
print(count)