Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

def sieve1(n):
    isPrime = [True] * (n+1)
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2*2, n+1, 2):
        isPrime[i] = False
    for i in range(3, n+1):
        if isPrime[i]:
            for j in range(i+i, n+1, i):
                isPrime[j] = False
    return isPrime
numOfDivisors = [2] * (n+1)
numOfDivisors[1] = 1
numOfDivisors[0] = 0
isPrime = sieve1(n)
for i in range(2, n+1):
    if isPrime[i]:
        for j in range(2*i, n+1, i):
            x = j // i
            numOfDivisors[j] += numOfDivisors[x] - 1
ans = 0
for k in range(1, n+1):
    ans += numOfDivisors[k] * k
print (ans)

Fixed submission:
n = int(input())

def sieve1(n):
    isPrime = [True] * (n+1)
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2*2, n+1, 2):
        isPrime[i] = False
    for i in range(3, n+1):
        if isPrime[i]:
            for j in range(i+i, n+1, i):
                isPrime[j] = False
    return isPrime
numOfDivisors = [2] * (n+1)
numOfDivisors[1] = 1
numOfDivisors[0] = 0
isPrime = sieve1(n)
for i in range(2, n+1):
    if isPrime[i]:
        for j in range(2*i, n+1, i):
            x = j // i
            numOfDivisors[j] += numOfDivisors[x] - 1
ans = 0
for k in range(1, n+1):
    ans += numOfDivisors[k] * k
print (ans)
Buggy python submission (verdict: Runtime Error):
1000000000000000 9.99

Fixed submission:
from math import floor

A, B = input().split()
A = int(A)
B = float(B)
B = round(B*100)
print (A*B // 100)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = input()
q = int(input())
S = [c for c in s]
deque = deque(S)
reversed = 0
for i in range(q):
    line = input()
    if line[0] == '1':
        reversed = reversed ^ 1
    else:
        op, f, c = line.split()
        f = int(f)
        if reversed == 0:
            if f == 1:
                deque.appendleft(c)
            else:
                deque.append(c)
        else:
            if f == 1:
                deque.append(c)
            else:
                deque.appendleft(c)
if reversed == 0:
    deque.reverse()
result = ""
for i in range(len(deque)):
    result += deque.pop()
print(result)

Fixed submission:
from collections import deque
s = input()
q = int(input())
S = [c for c in s]
deque = deque(S)
reversed = 0
for i in range(q):
    line = input()
    if line[0] == '1':
        reversed = reversed ^ 1
    else:
        op, f, c = line.split()
        f = int(f)
        if reversed == 0:
            if f == 1:
                deque.appendleft(c)
            else:
                deque.append(c)
        else:
            if f == 1:
                deque.append(c)
            else:
                deque.appendleft(c)
if reversed:
    deque.reverse()
result = "".join(deque)
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
adjMat = [[-1]*n for i in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        adjMat[i][x-1] = y
ans = 0
for i in range(1 << (n)):
    #print (bin(i))
    success = True
    for j in range(n):
        if i & 2**j:
            for k in range(n):
                if k == j:
                    continue
                if  i & 2**k == 0 and adjMat[j][k] == 1:
                    success = False
                if i & 2**k > 0 and adjMat[k][j] == 0:
                    success = False
                #print (j, k, adjMat[j][k], adjMat[k][j], success)
        if not success:
            break
    if success:
        i2 = i
        c = 0
        while i2 > 0:
            c += i2 & 1
            i2 //= 2
        ans = max(c, ans)
print (ans) 

Fixed submission:
n = int(input())
adjMat = [[-1]*n for i in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        adjMat[i][x-1] = y
ans = 0
for i in range(1 << (n)):
    #print (bin(i))
    success = True
    for j in range(n):
        if i & 2**j:
            for k in range(n):
                if k == j:
                    continue
                if  i & 2**k == 0 and adjMat[j][k] == 1:
                    success = False
                if i & 2**k > 0 and adjMat[k][j] == 0:
                    success = False
                #print (j, k, adjMat[j][k], adjMat[k][j], success)
        if not success:
            break
    if success:
        i2 = i
        c = 0
        while i2 > 0:
            c += i2 & 1
            i2 //= 2
        ans = max(c, ans)
print (ans)
Buggy python submission (verdict: Runtime Error):
from math import sqrt
from functools import reduce
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

def lcm(a, b):
    return a*b//gcd(a, b)
n = int(input())
n2 = n
pfs = []
isP = True
i = 2
while i <= int(sqrt(n)):
    while n % i == 0:
        pfs.append(i)
        n //= i
        isP = False
    i += 1
pfs.append(n)
"print (pfs)
if isP:
    ans =  (n2-1)
elif len(pfs) > 2:
    l = reduce(lcm, pfs)
    ans = l-1 + n2//l-1
else:
    ans = pfs[-1]-1 + n2//pfs[-1]-1
print (ans)

Fixed submission:
from math import sqrt
n = int(input())
minSoFar = 10**12+1

for a in range(1, int(sqrt(n))+1):
    if n % a == 0:
        b = n // a
        minSoFar = min(minSoFar, a+b-2)
print(minSoFar)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, raw_input().split())
A = [int(raw_input()) for i in range(m)]
def solve(n, A):
  dp = [0] * (n + 1)
  ai = 0
  if ai < len(A) and A[ai] == 1:
    dp[1] = -1
    ai += 1
  else:
    dp[1] = 1
  if ai < len(A) and A[ai] == 2:
    dp[2] = -1
    ai += 1
  elif dp[1] != -1:
    dp[2] = 2
  else:
    dp[2] = 1
  for i in range(3, n + 1):
    if ai < len(A) and A[ai] == i:
      dp[i] = -1
      ai += 1
      continue
    if dp[i-2] != -1:
      dp[i] = dp[i-2] 
    if dp[i-1] != -1:
      dp[i] += dp[i-1]
  return dp[n] % (10**9+7)
print solve(n, A)

Fixed submission:
n, m = map(int, raw_input().split())

def solve(n, m):
    dp = [0] * (n + 1)
    ai = 0
    a = -1
    dp[0] = 1
    if ai < m:
        a = int(raw_input())
    if a == 1:
        ai += 1
        if ai < m:
            a = int(raw_input())
        dp[1] = -1
    else:
        dp[1] = 1

    for i in range(2, n+1):
        if i == a:
            ai += 1
            if ai < m:
                a = int(raw_input())
            dp[i] = -1
        else:
            if dp[i-2] != -1:
                dp[i] = dp[i-2]
            if dp[i-1] != -1:
                dp[i] += dp[i-1]
    return dp[n] % (10**9+7)
print solve(n, m)
Buggy python submission (verdict: Runtime Error):
n = int(raw_input)
restaurants = []
for i in range(n):
    line = raw_input().split()
    restaurants.append((line[0], int(line[1]), i+1))
restaurants.sort(key=lambda x: (x[0], x[1]))
for i in range(n):
    print resutaurants[i][2]

Fixed submission:
n = int(raw_input())
restaurants = []
for i in range(n):
    line = raw_input().split()
    restaurants.append((line[0], int(line[1]), i+1))
restaurants.sort(key=lambda x: (x[0], -x[1]))
for i in range(n):
    print restaurants[i][2]
Buggy python submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())
V = map(int, raw_input().split())
achievable = 0
for i in range(1, k+1):
    #print "i=" + str(i)
    for l in range(-1, i):
        #print "l=" + str(l)
        candid = 0
        kr = k - i
        subV = V[0:l+1]
        negatives = [x for x in subV if x < 0]
        #print "kr=" + str(kr)
        if l == -1:
            pass
        else:
            candid += sum(subV)
            #print subV
        for r in range(n-1, n-i+l, -1):
            if l >= r:
                break
            candid += V[r]
            #print V[r]
            if V[r] < 0:
                negatives.append(V[r])
        negatives.sort(reverse=True)
        while len(negatives) > 0 and kr > 0:
            candid -= negatives.pop()
            kr -= 1
        achievable = max(achievable, candid)
print achievablen, k = map(int, raw_input().split())
V = map(int, raw_input().split())
achievable = 0
for i in range(1, k+1):
    #print "i=" + str(i)
    for l in range(-1, i):
        #print "l=" + str(l)
        candid = 0
        kr = k - i
        subV = V[0:l+1]
        negatives = [x for x in subV if x < 0]
        #print "kr=" + str(kr)
        if l == -1:
            pass
        else:
            candid += sum(subV)
            #print subV
        for r in range(n-1, n-i+l, -1):
            if l >= r:
                break
            candid += V[r]
            #print V[r]
            if V[r] < 0:
                negatives.append(V[r])
        negatives.sort(reverse=True)
        while len(negatives) > 0 and kr > 0:
            candid -= negatives.pop()
            kr -= 1
        achievable = max(achievable, candid)
print achievable

Fixed submission:
n, k = map(int, raw_input().split())
V = map(int, raw_input().split())
achievable = 0
for i in range(1, k+1):
    #print "i=" + str(i)
    for l in range(-1, i):
        if l > n :
            break
        #print "l=" + str(l)
        candid = 0
        fail = False
        kr = k - i
        subV = V[0:l+1]
        negatives = [x for x in subV if x < 0]
        #print "kr=" + str(kr)
        if l == -1:
            pass
        else:
            candid += sum(subV)
            #print subV
        for r in range(n-1, n-i+l, -1):
            if l >= r:
                fail = True
                break
            candid += V[r]
            #print V[r]
            if V[r] < 0:
                negatives.append(V[r])
        if fail:
            continue
        negatives.sort(reverse=True)
        while len(negatives) > 0 and kr > 0:
            candid -= negatives.pop()
            kr -= 1
        achievable = max(achievable, candid)
print achievable
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
x, y, z, k = map(int, raw_input().split())
A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_input().split())
AB = []
for (a, b) in product(A, B):
    AB.append(a+b)
AB.sort(reverse=True)
C.sort(reverse=True)
ABC = []
for i in range(min(k+1, len(AB))):
    for j in range(len(C)):
        ABC.append(AB[i]+C[j])
ABC.sort(reverse=True)
for i in range(min(k, len(ABC))):
    print ABC[i]


Fixed submission:
from itertools import product
x, y, z, k = map(int, raw_input().split())
A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_input().split())
AB = []
for (a, b) in product(A, B):
    AB.append(a+b)
AB.sort(reverse=True)
C.sort(reverse=True)
ABC = []
for i in range(min(k+1, len(AB))):
    for j in range(len(C)):
        ABC.append(AB[i]+C[j])
ABC.sort(reverse=True)
for i in range(min(k, len(ABC))):
    print ABC[i]
Buggy python submission (verdict: Runtime Error):
from heapq import heapify, heappop, heappush, nsmallest
n, m = map(int, raw_input().split())
X = map(int, raw_input().split())
X.sort()
heap = []
for i in range(1, m):
    diff = X[i] - X[i-1]
    if len(heap) >= n - 1 and nsmallest(1, heap)[0][0] < diff:
        heappop(heap)
        heappush(heap, (diff, X[i-1], X[i]))
    elif len(heap) < n - 1:
        heappush(heap, (diff, X[i-1], X[i]))
    else:
        continue
heap.sort(key=lambda X : X[1])
cp = X[0]
move = 0
for j in range(len(heap)):
    diff, left, right = heap[j]
    move += left - cp
    cp = right
move += (X[-1] - cp)
print move

Fixed submission:
from heapq import heapify, heappop, heappush, nsmallest
n, m = map(int, raw_input().split())
X = map(int, raw_input().split())
X.sort()
if m == 1:
    print 0
    exit()
elif n == 1:
    print X[-1] - X[0]
    exit()
heap = []
heapify(heap)
for i in range(1, m):
    diff = X[i] - X[i-1]
    if len(heap) >= n - 1 and heap[0][0] < diff:
        heappop(heap)
        heappush(heap, (diff, X[i-1], X[i]))
    elif len(heap) < n - 1:
        heappush(heap, (diff, X[i-1], X[i]))
    else:
        continue
heap.sort(key=lambda X : X[1])
cp = X[0]
move = 0
for j in range(len(heap)):
    diff, left, right = heap[j]
    move += left - cp
    cp = right
move += (X[-1] - cp)
print move
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input())
candidOdd = 0
candidEven = 0
candidEven2 = 0
for i in range(1, n+1):
    if k % 2 == 1:
        if i % k == 0:
            candidOdd += 1
    else:
        if i % k == 0:
            candidEven += 1
        elif i % k == (k/2):
            candidEven2 += 1
print(candidOdd**3 + candidEven**3 + candidEven2**3)

Fixed submission:
n, k = map(int, input().split())
candidOdd = 0
candidEven = 0
candidEven2 = 0
for i in range(1, n+1):
    if k % 2 == 1:
        if i % k == 0:
            candidOdd += 1
    else:
        if i % k == 0:
            candidEven += 1
        elif i % k == (k/2):
            candidEven2 += 1
print(candidOdd**3 + candidEven**3 + candidEven2**3)
Buggy python submission (verdict: Runtime Error):
from math import ceil
n = int(input())
arr = list(map(int, input().split()))
B = []
for i in range(n):
    B.append(arr[i] - (i+1))
B.sort()
b1 = B[n//2]
b2 = B[int(ceil(n/2))]
ans1, ans2 = 0, 0
for i in range(n):
    ans1 += abs(arr[i]-(b1+i+1))
    ans2 += abs(arr[i]-(b2+i+1))
print (min(ans1, ans2))

Fixed submission:
from math import ceil
n = int(input())
arr = list(map(int, input().split()))
B = []
for i in range(n):
    B.append(arr[i] - (i+1))
B.sort()
b1 = B[n//2]
b2 = B[n//2]
if n > 1:
	b2 = B[int(ceil(n/2))]
ans1, ans2 = 0, 0
for i in range(n):
    ans1 += abs(arr[i]-(b1+i+1))
    ans2 += abs(arr[i]-(b2+i+1))
print (min(ans1, ans2))
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2000)
h, w = map(int, raw_input().split())
s = [[c for c in raw_input()] for i in range(h)]
def isValid(i, j):
    if i < 0 or i >= h or j < 0 or j >= w:
        return False
    return True
    
def dfs(s, i, j):
    if not isValid(i, j) or s[i][j] == "0" or s[i][j] == ".":
        return 0
    if s[i][j] == "#":
        s[i][j] = "0"
        a = dfs(s, i+1, j)
        b = dfs(s, i-1, j)
        c = dfs(s, i, j+1)
        d = dfs(s, i, j-1)
        return 1 + a + b + c + d

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            ccs = dfs(s, i, j)
            #print ccs
            if ccs == 1:
                print "No"
                exit()
print "Yes"

Fixed submission:
import sys
sys.setrecursionlimit(3000)
h, w = map(int, raw_input().split())
s = [[c for c in raw_input()] for i in range(h)]
def isValid(i, j):
    if i < 0 or i >= h or j < 0 or j >= w:
        return False
    return True
    
def dfs(s, i, j):
    if not isValid(i, j) or s[i][j] == "0" or s[i][j] == ".":
        return 0
    if s[i][j] == "#":
        s[i][j] = "0"
        a = dfs(s, i+1, j)
        b = dfs(s, i-1, j)
        c = dfs(s, i, j+1)
        d = dfs(s, i, j-1)
        return 1 + a + b + c + d

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            ccs = dfs(s, i, j)
            #print ccs
            if ccs == 1:
                print "No"
                exit()
print "Yes"

Buggy python submission (verdict: Runtime Error):
h, w = map(int, raw_input().split())
s = [[c for c in raw_input()] for i in range(h)]
def isValid(i, j):
    if i < 0 or i >= h or j < 0 or j >= w:
        return False
    return True
    
def dfs(s, i, j):
    if not isValid(i, j) or s[i][j] == "0" or s[i][j] == ".":
        return 0
    if s[i][j] == "#":
        s[i][j] = "0"
        a = dfs(s, i+1, j)
        b = dfs(s, i-1, j)
        c = dfs(s, i, j+1)
        d = dfs(s, i, j-1)
        return 1 + a + b + c + d

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            ccs = dfs(s, i, j)
            #print ccs
            if ccs == 1:
                print "No"
                exit()
print "Yes"

Fixed submission:
import sys
sys.setrecursionlimit(3000)
h, w = map(int, raw_input().split())
s = [[c for c in raw_input()] for i in range(h)]
def isValid(i, j):
    if i < 0 or i >= h or j < 0 or j >= w:
        return False
    return True
    
def dfs(s, i, j):
    if not isValid(i, j) or s[i][j] == "0" or s[i][j] == ".":
        return 0
    if s[i][j] == "#":
        s[i][j] = "0"
        a = dfs(s, i+1, j)
        b = dfs(s, i-1, j)
        c = dfs(s, i, j+1)
        d = dfs(s, i, j-1)
        return 1 + a + b + c + d

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            ccs = dfs(s, i, j)
            #print ccs
            if ccs == 1:
                print "No"
                exit()
print "Yes"
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
arr = []
for i in range(n-1):
    arr.append(tuple(map(int, input().split())))

for i in range(n-1):
    c1, s1, f1 = arr[i]
    ct = s1+c1
    for j in range(i+1, n-1):
        c2, s2, f2 = arr[j]
        while ct > s2:
            s2 += f2
        ct = s2 + c2
    print (ct)
print (0)

Fixed submission:
n = int(input())
arr = []
for i in range(n-1):
    arr.append(tuple(map(int, input().split())))

for i in range(n-1):
    c1, s1, f1 = arr[i]
    ct = s1+c1
    for j in range(i+1, n-1):
        c2, s2, f2 = arr[j]
        while ct > s2:
            s2 += f2
        ct = s2 + c2
    print (ct)
print (0)
Buggy python submission (verdict: Runtime Error):
s = raw_input()
length = len(s)

T = []
for i in range(length-1):
    if s[i] != s[i+1]:
    	T.append(max(i+1, length-(i+1)))
print min(T)

Fixed submission:
s = raw_input()
length = len(s)
if length == 1:
    print 1
    exit()
T = []
for i in range(length-1):
    if s[i] != s[i+1]:
    	T.append(max(i+1, length-(i+1)))
if len(T) == 0:
    print length
else:
    print min(T)

Buggy python submission (verdict: Runtime Error):
s = raw_input()
length = len(s)

T = []
for i in range(length-1):
    if s[i] != s[i+1]:
    	T.append(max(i+1, length-(i+1)))
print min(T)

Fixed submission:
s = raw_input()
length = len(s)
if length == 1:
    print 1
    exit()
T = []
for i in range(length-1):
    if s[i] != s[i+1]:
    	T.append(max(i+1, length-(i+1)))
if len(T) == 0:
    print length
else:
    print min(T)
Buggy python submission (verdict: Runtime Error):
n = int(input())

F = []
P = []
for i in range(n):
    F.append(list(map(int, input().split())))
for i in range(n):
    P.append(list(map(int, input().split())))
ans = -10**9
for i in range(1, 1 << (10)):
    C = [0]*11
    for j in range(10):
        if i & 2**j:
            for k in range(n):
                if F[k][j]:
                    C[k] += 1
    current = 0
    for k in range(n):
        current += P[k][C[k]]
    ans = max(current, ans)
print (ans)

Fixed submission:
n = int(input())

F = []
P = []
for i in range(n):
    F.append(list(map(int, input().split())))
for i in range(n):
    P.append(list(map(int, input().split())))
ans = -10**9
for i in range(1, 1 << (10)):
    C = [0]*n
    for j in range(10):
        if i & 2**j:
            for k in range(n):
                if F[k][j]:
                    C[k] += 1
    current = 0
    for k in range(n):
        current += P[k][C[k]]
    ans = max(current, ans)
print (ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
arr = list(map(int, input().split()))
ans = 0
for i in range(n):
    if arr[i] == i + 1:
        ans += 1
        arr[i+1], arr[i] = arr[i], arr[i+1]
if arr[n-1] == n:
    ans += 1
print (ans)   

Fixed submission:
n = int(input())
arr = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if arr[i] == i + 1:
        ans += 1
        arr[i+1], arr[i] = arr[i], arr[i+1]
if arr[n-1] == n:
    ans += 1
print (ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
arr = list(map(int, input().split()))
ans = 0
for i in range(n):
    if arr[i] == i + 1:
        ans += 1
        arr[i+1], arr[i] = arr[i], arr[i+1]
print (ans)   

Fixed submission:
n = int(input())
arr = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if arr[i] == i + 1:
        ans += 1
        arr[i+1], arr[i] = arr[i], arr[i+1]
if arr[n-1] == n:
    ans += 1
print (ans)
Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue
n, m = map(int, input().split())
adj = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)
def bfs():
    queue = Queue()
    queue.put((1, 0))
    visited = [False]*(n+1)
    while not queue.empty():
        u, step = queue.get()
        if u == n and step == 2:
            print ("POSSIBLE")
            return
        for a in adj[u]:
            if step + 1 <= 2:
                queue.put((a, step+1))
    print ("IMPOSSIBLE")
    return
bfs()

Fixed submission:
from queue import Queue
n, m = map(int, input().split())
adj = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)
def bfs():
    queue = Queue()
    queue.put(1)
    distance = [10**6]*(n+1)
    distance[1] = 0
    while not queue.empty():
        u = queue.get()
        if u == n and distance[u] == 2:
            print ("POSSIBLE")
            return
        for a in adj[u]:
            if distance[u] + 1 <= 2 and distance[a] > distance[u] + 1:
                distance[a] = distance[u] + 1
                queue.put(a)
    print ("IMPOSSIBLE")
    return
bfs()

Buggy python submission (verdict: Runtime Error):
4 3
1 4
4 5
2 3

Fixed submission:
from queue import Queue
n, m = map(int, input().split())
adj = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)
def bfs():
    queue = Queue()
    queue.put(1)
    distance = [10**6]*(n+1)
    distance[1] = 0
    while not queue.empty():
        u = queue.get()
        if u == n and distance[u] == 2:
            print ("POSSIBLE")
            return
        for a in adj[u]:
            if distance[u] + 1 <= 2 and distance[a] > distance[u] + 1:
                distance[a] = distance[u] + 1
                queue.put(a)
    print ("IMPOSSIBLE")
    return
bfs()