Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):


oo = 1000000000 + 5

def main():
    n, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    
    dp = [oo for _ in range(n)]
    dp[0] = 0
    for i in range(n):
        for j in range(i + 1, i + k + 1):
            if j < n:
                dp[j] = min(dp[j], dp[i] + fabs(a[i] - a[j]))
                
    print(int(dp[n - 1]))

main()

Fixed submission:
def main():
  import sys
  input = sys.stdin.readline
  n, k = map(int, input().split())
  arr = list(map(int, input().split()))
  dp = [1000000000] * n
  dp[0] = 0
  for i in range(1, n):
    for j in range(max(0, i - k), i):
      dp[i] = min(dp[i], dp[j] + abs(arr[i] - arr[j]))
  print(dp[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  import sys
  input = sys.stdin.readline
  n, k = map(int, input().split())
  arr = list(map(int, input().split()))
  dp = [1000000000] * n
  dp[0] = 0
  for i in range(1, n):
    for j in range(max(0, i - k), i):
      dp[i] = min(dp[i], dp[j] + abs(arr[i] - arr[j]))
  print(dp[-1])
main()  

Fixed submission:
def main():
  import sys
  input = sys.stdin.readline
  n, k = map(int, input().split())
  arr = list(map(int, input().split()))
  dp = [1000000000] * n
  dp[0] = 0
  for i in range(1, n):
    for j in range(max(0, i - k), i):
      dp[i] = min(dp[i], dp[j] + abs(arr[i] - arr[j]))
  print(dp[-1])
main()

Buggy python submission (verdict: Runtime Error):
def main():
  import sys
  input = sys.stdin.readline
  n, k = map(int, input().split())
  arr = list(map(int, input().split()))
  dp = [1000000000] * n
  dp[0] = 0
  for i in range(1, n):
    for j in range(max(0, i - k), i):
    dp[i] = min(dp[i], dp[j] + abs(arr[i] - arr[j]))
  print(dp[-1])
main()  

Fixed submission:
def main():
  import sys
  input = sys.stdin.readline
  n, k = map(int, input().split())
  arr = list(map(int, input().split()))
  dp = [1000000000] * n
  dp[0] = 0
  for i in range(1, n):
    for j in range(max(0, i - k), i):
      dp[i] = min(dp[i], dp[j] + abs(arr[i] - arr[j]))
  print(dp[-1])
main()
Buggy python submission (verdict: Runtime Error):
S = input()
w = int(input())
l = len(S)
ret = ""
if S % w:
  for i in range(1 + S // w):
    ret += S[i * w]
else:
  for i in range(S // w):
    ret += S[i * w]
print(ret)

Fixed submission:
S = input()
w = int(input())
l = len(S)
ret = ""
if l % w:
  for i in range(1 + l // w):
    ret += S[i * w]
else:
  for i in range(l // w):
    ret += S[i * w]
print(ret)
Buggy python submission (verdict: Runtime Error):
def main():
	N = int(input())
	A = list(map(int, input().split()))
	s = sum(A)
	def ano_helper(BCDE):
		BCDE = BCDE + [s - sum(BCDE)]
		BCDE.sort()
		return abs(BCDE[-1] - BCDE[0])
	def helper(BCDEs, inds):
		if len(BCDEs[0]) == 4:
			return BCDEs
		ret_BCDEs = []
		ret_inds = []
		for candidate in range(len(BCDEs)):
			BCDE = BCDEs[candidate]
			ind = inds[candidate]
			ave = sum(A[ind:]) / (5 - len(BCDE))
			temp = 0
			while temp + A[ind] < ave:
				temp += A[ind]
				ind += 1
				if ind == N:
					break
			ret_BCDEs.append(BCDE + [temp])
			ret_inds.append(ind)
			if ind < N:
				ret_BCDEs.append(BCDE + [temp + A[ind]])
				ret_inds.append(ind + 1)
		return helper(ret_BCDEs, ret_inds)
	print(sorted([ano_helper(i[1:]) for i in helper([[0]], [0])])[0])
	return 0
	#BCDE = []
	#ind = 0
	#su = []
	#tempBCDE = [[]]
	#while len(BCDE[-1]) < 4:
	#	temp = 0
	#	ret = []
	#	while temp < (s - su) / (4 - len(BCDE)):
	#		te = A[ind]
	#		temp += te
	#		ret.append(te)
	#		su += te
	#		ind += 1
	#	tempBCDE.append(ret)
	#print(BCDE)
main()

Fixed submission:
def main():
	N = int(input())
	if N % 2:
		print(2 * N)
	else:
		print(N)
	return 0
main()

Buggy python submission (verdict: Runtime Error):
def main():
	N = int(input())
	seq = list(map(int, input().split()))
	seq = [seq[i] - i - 1 for i in range(N)]
	def helper(b):
		return sum([abs(seq[i] - b) for i in range(N)])
	ave = sum(seq) // N
	print(min(helper(ave), helper(ave + 1)))
	return 0
main()

Fixed submission:
def main():
	N = int(input())
	if N % 2:
		print(2 * N)
	else:
		print(N)
	return 0
main()

Buggy python submission (verdict: Runtime Error):
def main():
	N = int(input())
	seq = list(map(int, input().split()))
	maks = 0
	for i in range(0, N):
		for j in range(i, N):
			maks = max(abs(seq[j] - seq[i]), maks)
	print(maks)
	return 0
main()

Fixed submission:
def main():
	N = int(input())
	if N % 2:
		print(2 * N)
	else:
		print(N)
	return 0
main()
Buggy python submission (verdict: Runtime Error):
def main():
	N = int(input())
	seq = list(map(int, input().split()))
	maks = 0
	for i in range(1, N):
		maks = max(seq[i] - seq[i - 1])
	print(maks)
	return 0
main()

Fixed submission:
def main():
	N = int(input())
	seq = list(map(int, input().split()))
	maks = 0
	for i in range(0, N):
		for j in range(i, N):
			maks = max(abs(seq[j] - seq[i]), maks)
	print(maks)
	return 0
main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
	N = int(input())
	seq = list(map(int, input().split()))
	seq = [seq[i] - i - 1 for i in range(N)]
	def helper(b):
		return sum([abs(seq[i] - b) for i in range(N)])
	temp = []
	for i in range(N):
		temp.append(helper(seq[i]))
	print(min(temp))
	return 0
main()

Fixed submission:
def main():
	N = int(input())
	seq = list(map(int, input().split()))
	seq = [seq[i] - i - 1 for i in range(N)]
	se = sorted(list(set(seq)))
	def helper(b):
		return sum([abs(seq[i] - b) for i in range(N)])
	L = 0
	R = len(se)
	while True:
		ind = (L + R) // 2
		temp = helper(se[ind])
		if helper(se[ind - 1]) > temp and temp > helper(se[ind + 1]):
			L = ind
		elif helper(se[ind - 1]) < temp:
			R = ind
		else:
			print(temp)
			return 0
main()
Buggy python submission (verdict: Runtime Error):
print(4 - 2 * S.count("c"))

Fixed submission:
def main():
    S = input()
    c = S.count("-")
    print(4 - 2 * c)
    return 0
main()
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    if (N / (N % 9)) % 1 == 0:
        print("Yes")
    else:
        print("No")
    return 0
main()


Fixed submission:
def main():
    def dig_sum(x):
        return sum(list(map(int, [i for i in str(x)])))
    N = int(input())
    if (N / dig_sum(N)) % 1 == 0:
        print("Yes")
    else:
        print("No")
    return 0
main()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    a, b, k = map(int, input().split())
    for i in range(a, b+1):
        if i < a+k or b-k < i:
            print(i)
resolve()

Fixed submission:
def resolve():
    a, b, k = map(int, input().split())
    if a+k-1 >= b-k+1:
        for i in range(a, b+1):
            print(i)
    else:
        for i in range(a, a+k):
            print(i)
        for i in range(b-k+1, b+1):
            print(i)
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    a, b = map(int, input().split())

    ans = str()

    if a > b:
        ans = "GREATER"
    elif a < b:
        ans = "LESS"
    else:
        ans = "EQUAL"

    print(ans)
resolve()

Fixed submission:
def resolve():
    a = int(input())
    b = int(input())

    ans = str()

    if a > b:
        ans = "GREATER"
    elif a < b:
        ans = "LESS"
    else:
        ans = "EQUAL"

    print(ans)
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
[n, m] = [int(num) for num in input().split()];
a = [];
b = [];
for i in range(m):
	[t1, t2] = [int(num) for num in input().split()];
	a.append(t1);
	b.append(t2);
	
start = [];
end = [];
for i in range(m):
	if a[i] == 1:
		start.append(b[i]);
	if b[i] == n:
		end.append(a[i]);

flag = False;		
for i in range(1, n + 1):
	if (i in start) & (i in end):
		flag = True;
		
if (flag):
	print('POSSIBLE');
else:
	print('IMPOSSIBLE');

Fixed submission:
[n, m] = [int(num) for num in input().split()];
a = [];
b = [];

for i in range(m):
	[t1, t2] = [int(num) for num in input().split()];
	a.append(t1);
	b.append(t2);

start = [];
end = [];
for i in range(n):
	start.append(False);
	end.append(False);
	
for i in range(m):
	if a[i] == 1:
		start[b[i]] = True;
	elif b[i] == n:
		end[a[i]] = True;
		
flag = False;
for i in range(n):
	if start[i] & end[i]:
		flag = True;
		
if flag:
	print('POSSIBLE');
else:
	print('IMPOSSIBLE');
Buggy python submission (verdict: Runtime Error):
s = raw_input().rstrip()
t = s
s = s[::-1]
s = s.replace("b", "d")
s = s.replace("p", "q")
s = s.replace("d", "b")
s = s.replace("q", "p")
print s == t * "YES" or "NO"

Fixed submission:
s = raw_input().rstrip()
t = s
s = s[::-1]
s = s.replace("b", "t")
s = s.replace("p", "s")
s = s.replace("d", "b")
s = s.replace("q", "p")
s = s.replace("t", "d")
s = s.replace("s", "q")
print ((s == t) * "Yes") or "No"
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, raw_input().split())

s = 3*c

print a,b,s-a-b
print s-(c+s-(s-a-b+s-a-c)),c,s-(s-a-b+s-a-c)
print a+b-c,s-b-c,s-a-c

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

s = 3*c

print a,b,s-a-b
print s-(c+s-(s-a-b+s-a-c)),c,s-(s-a-b+s-a-c)
print a+b-c,s-b-c,s-a-c

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, raw_input())

s = 3*c

print a,b,s-a-b
print s-(c+s-(s-a-b+s-a-c)),c,s-(s-a-b+s-a-c)
print a+b-c,s-b-c,s-a-c

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

s = 3*c

print a,b,s-a-b
print s-(c+s-(s-a-b+s-a-c)),c,s-(s-a-b+s-a-c)
print a+b-c,s-b-c,s-a-c
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int, raw_input().split())

x = abs(c-a)
y = abs(d-b)

if x == 0 or y == 0:
	print 0
	return

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

e = gcd(x,y)
x /= e
y /= e

print (x+y-1) * e

Fixed submission:
a,b,c,d = map(int, raw_input().split())

x = abs(c-a)
y = abs(d-b)

if x == 0 or y == 0:
	print 0
	import sys
	sys.exit(0)

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

e = gcd(x,y)
x /= e
y /= e

print (x+y-1) * e
Buggy python submission (verdict: Runtime Error):
a = input()
print(a ^ 2)

Fixed submission:
a=int(input())
print(a * a)

Buggy python submission (verdict: Runtime Error):
import sys
r = sys.argv[1]
print(int(r) ** 2)


Fixed submission:
r = input()
print(int(r) ** 2)

Buggy python submission (verdict: Runtime Error):
print(r ** 2)

Fixed submission:
r = input()
print(int(r) ** 2)

Buggy python submission (verdict: Runtime Error):
import sys
print(int(sys.argv[1]) ** 2)

Fixed submission:
r = input()
print(int(r) ** 2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
if N % 2 > 0 or S != S[:int(N/2)] + S[:int(N/2)]:
    exit("No")
exit("Yes")

Fixed submission:
N = int(input())
S = input()
if N % 2 > 0 or S != S[:int(N/2)] + S[:int(N/2)]:
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
if N % 2 > 0 or S != S[:int(N/2)] + S[:int(N/2)6]:
    exit("No")
exit("Yes")

Fixed submission:
N = int(input())
S = input()
if N % 2 > 0 or S != S[:int(N/2)] + S[:int(N/2)]:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
r = input()
result = int(r*r)
print(result)

Fixed submission:
r = input()
r = int(r)
result = r**2
print(result)

Buggy python submission (verdict: Runtime Error):
r = input()
print(r*r)

Fixed submission:
r = input()
r = int(r)
result = r**2
print(result)
Buggy python submission (verdict: Runtime Error):
import math
a,b,x = map(int,input().split())
if x >= (b*a**2)/2:
    print(90-math.degrees(math.atan(a**3/(2*(b*a**2-x)))))
else:
    print(90-math.degrees(math.atan(2*x/(a*b**2))))

Fixed submission:
import math
a,b,x = map(int,input().split())
if b*a**2 == x:
    print("0")
elif x >= (b*a**2)/2:
    print(90-math.degrees(math.atan(a**3/(2*(b*a**2-x)))))
else:
    print(90-math.degrees(math.atan(2*x/(a*b**2))))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
for i in range(1,n):
    ans += i
print(ans)

Fixed submission:
def summention(n):
    return n*(n+1)//2

n = int(input())
print(summention(n-1))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = [0 for i in range(n+1)]
a.reverse()
a.insert(0,0)
counter = 0
for i in range(1,n+1): #a[i]を見ている
    temp = 0
    for k in range(n+1-i,n+1): #b[k]を見ている
        if k % (n+1-i) == 0:
            temp += b[k]
    if temp%2 != a[i]:
        b[n+1-i] = 1
        counter += 1
print(counter)
for i in range(1,n+1):
    if b[i] == 1:
        if counter != 1:
            print(i,end= " ")
        else:
            print(i)
        counter -= 1


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = [0 for i in range(n+1)]
a.reverse()
a.insert(0,0)
counter = 0
for i in range(1,n+1): #a[i]を見ている
    temp = 0
    t = 1
    while (n+1-i)*t <= n:
        temp += b[(n+1-i)*t]
        t += 1
    if temp%2 != a[i]:
        b[n+1-i] = 1
        counter += 1
print(counter)
for i in range(1,n+1):
    if b[i] == 1:
        if counter != 1:
            print(i,end= " ")
        else:
            print(i)
        counter -= 1
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for i in range(n):
    temp = int(input())
    a.append(temp)
a.reverse()
b = [a[0]]
counter = 1
for i in range(1,n):
    temp = False
    for k in range(counter):
        if a[i] < b[k]:
            b[k] = a[i]
            temp = True
            break
    if temp == False:
        b.append(a[i])
        counter += 1
print(counter)

Fixed submission:
import bisect
n = int(input())
a = []
for i in range(n):
    temp = int(input())
    a.append(temp)
a.reverse()
b = [a[0]]
counter = 1
for i in range(1,n):
    if a[i] >= b[-1]:
        counter += 1
        b.append(a[i])
    else:
        ind = bisect.bisect_right(b,a[i])
        b[ind] = a[i]
print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
comb = [[0 for i in range(2001)] for k in range(2001)] #comb[i][j] = iCj
mod = int(1e9+7)
for i in range(1,2001):
    comb[i][0] = 1
    comb[i][1] = i
for i in range(2,2001):
    for j in range(2,2001):
        comb[i][j] = comb[i-1][j] + comb[i-1][j-1]
        comb[i][j] %= mod

n,k = map(int,input().split())
for i in range(1,k+1):
    print(comb[n-k+1][i]*comb[k-1][i-1]%mod)

Fixed submission:
mod = int(1e9+7)
stair = [1]
for i in range(1,2001):
    stair.append(stair[i-1]*i)
def comb(stair,n,r):
    return (stair[n]//(stair[n-r]*stair[r]))%mod

n,k = map(int,input().split())
for i in range(1,k+1):
    ans = comb(stair,n-k+1,i) * comb(stair,k-1,i-1)
    print(ans%mod)
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
lcm = int(c*d/math.gcd(c,d))

print((b-a+1) - ((b//c-(a-1)//c) + (b//d-(a-1)//d) - (b//lcm-(a-1)//lcm)))

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

a,b,c,d = map(int,input().split())
lcm = int(c*d/gcd(c,d))

total = b-a+1
totalc = b//c-(a-1)//c
totald = b//d-(a-1)//d
totalcd = b//lcm-(a-1)//lcm
print(total - (totalc + totald - totalcd))
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = sum(a)
card = []
for i in range(m):
    b,c = map(int,input().split())
    card.append([b,c])

card.sort(key = lambda x: x[1])
card.reverse()
mini = a[0]
i = 0
now = 0 #aの参照インデックス
plus = 0
while i < m and mini < card[i][1]:
    while card[i][0] > 0 and now < n and card[i][1] > a[now]:
        plus += card[i][1]-a[now]
        card[i][0] -= 1
        now += 1
    if now < n and card[i][1] < a[now]:
        mini = card[i][1]
    else:
        mini = a[now]
    i += 1
print(ans+plus)

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = sum(a)
card = []
for i in range(m):
    b,c = map(int,input().split())
    card.append([b,c])

card.sort(key = lambda x: x[1])
card.reverse()
mini = a[0]
i = 0
now = 0 #aの参照インデックス
plus = 0
while i < m and mini < card[i][1]:
    while card[i][0] > 0 and now < n and card[i][1] > a[now]:
        plus += card[i][1]-a[now]
        card[i][0] -= 1
        now += 1
    if now == n:
        now -= 1
        if card[i][1] < a[now]:
            mini = card[i][1]
        else:
            mini = a[now]
        break
    else:
        if card[i][1] < a[now]:
            mini = card[i][1]
        else:
            mini = a[now]
    i += 1
print(ans+plus)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = sum(a)
card = []
for i in range(m):
    b,c = map(int,input().split())
    card.append([b,c])

card.sort(key = lambda x: x[1])
card.reverse()
mini = a[0]
i = 0
now = 0 #aの参照インデックス
plus = 0
while i < m and mini < card[i][1]:
    while card[i][0] > 0 and now < n and card[i][1] > a[now]:
        plus += card[i][1]-a[now]
        card[i][0] -= 1
        now += 1
    if card[i][1] < a[now]:
        mini = card[i][1]
    else:
        mini = a[now]
    i += 1
print(ans+plus)

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = sum(a)
card = []
for i in range(m):
    b,c = map(int,input().split())
    card.append([b,c])

card.sort(key = lambda x: x[1])
card.reverse()
mini = a[0]
i = 0
now = 0 #aの参照インデックス
plus = 0
while i < m and mini < card[i][1]:
    while card[i][0] > 0 and now < n and card[i][1] > a[now]:
        plus += card[i][1]-a[now]
        card[i][0] -= 1
        now += 1
    if now == n:
        now -= 1
        if card[i][1] < a[now]:
            mini = card[i][1]
        else:
            mini = a[now]
        break
    else:
        if card[i][1] < a[now]:
            mini = card[i][1]
        else:
            mini = a[now]
    i += 1
print(ans+plus)
Buggy python submission (verdict: Runtime Error):
import math
n,k = map(int,input().split())
twos = [1]
i = 0
while 2*twos[i] <= 10**5:
    twos.append(twos[i]*2)
    i += 1

ans = 0
for i in range(1,n+1):
    temp = 0
    while twos[temp] * i <= k-1:
        temp += 1
    ans += 1/n * 1/twos[temp]
print(ans)

Fixed submission:
import math
n,k = map(int,input().split())
twos = [1]
i = 0
while 2*twos[i] <= 10**5:
    twos.append(twos[i]*2)
    i += 1
twos.append(twos[-1]*2)

ans = 0
for i in range(1,n+1):
    temp = 0
    while twos[temp] * i <= k-1:
        temp += 1
    ans += 1/n * 1/twos[temp]
print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools
x,y,z,t = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans = []
for i in range(x):
    for k in range(y):
        ans.append(a[i]+b[k])
ans.sort()
ans.reverse()
if x*y > t:
    ans = ans[0:t]
out = []
for i in range(len(ans)):
    for k in range(z):
        out.append(ans[i]+c[k])
out.sort()
out.reverse()
for i in range(t):
    print(out[i])

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if e-a <= k:
    print("Yay!")
else:
    print(":(")
Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
s = list(input())
cum = [0 for i in range(n+1)]
i = 0
while i < n:
    if s[i] == "A" and s[i+1] == "C":
        cum[i+1] = cum[i]
        cum[i+2] = 1+cum[i+1]
        i += 2
    else:
        cum[i+1] = cum[i]
        i += 1

for i in range(q):
    l,r = map(int,input().split())
    print(cum[r]-cum[l])

Fixed submission:
n,q = map(int,input().split())
s = list(input())
cum = [0 for i in range(n+1)]
i = 0
while i < n:
    if i < n-1 and s[i] == "A" and s[i+1] == "C":
        cum[i+1] = cum[i]
        cum[i+2] = 1+cum[i+1]
        i += 2
    else:
        cum[i+1] = cum[i]
        i += 1

for i in range(q):
    l,r = map(int,input().split())
    print(cum[r]-cum[l])
Buggy python submission (verdict: Runtime Error):
def div(a,b):
    return [a//b,a-(a//b)*b]

def func(n,twos): #f(1,n)
    small = twos[0]
    l = len(bin(n))-2
    n += 1
    num = [0 for i in range(l)]
    for i in range(l):
        if i == 0:
            if div(n,4)[1] == 0 or div(n,4)[1] == 1:
                
                num[i] = 0
            else:
                num[i] = 1
        else:
            if (div(n,twos[i])[1] - twos[i]//2) <= 0 or (div(n,twos[i])[1] - twos[i]//2)%2 == 0:
                num[i] = 0
            else:
                num[i] = 1
    num.reverse()
    return num

def decode(ans,twos):
    val = 0
    ans.reverse()
    twos.insert(0,1)
    for i in range(len(ans)):
        val += ans[i]*twos[i]
    twos.pop(0)
    return val

a,b = map(int,input().split())
twos = [2]
i = 0
while twos[i]*2 <= 1e12:
    twos.append(twos[i]*2)
    i += 1
ans1 = func(a-1,twos)
ans2 = func(b,twos)

for i in range(len(ans2)-len(ans1)):
    ans1.insert(0,0)

print(decode(ans2,twos) ^ decode(ans1,twos))

Fixed submission:
def f(n):
    if n%2 == 0:
        return (n//2)%2 ^ n
    else:
        return ((n+1)//2)%2

a,b = map(int,input().split())
print(f(a-1)^f(b))
Buggy python submission (verdict: Time Limit Exceeded):
import collections
n,p = map(int,input().split())

if n >= 40 or p == 1:
    print("1")
else:
    s = 0
    fact = {}
    while s == 0:
        for i in range(2,p+1):
            if p%i == 0:
                p = p//i
                if p == 1:
                    s = 1
                if i not in fact:
                    fact[i] = 1
                else:
                    fact[i] += 1
                break
    ans = 1
    for i in fact:
        if fact[i] >= n:
            ans = ans*i**(fact[i]//n)
    print(ans)

Fixed submission:
import time

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

if n >= 40 or p == 1:
    print("1")
elif n == 1:
    print(p)
else:
    s = 0
    fact = {}
    start = time.time()
    check = False
    while s == 0:
        for i in range(2,p+1):
            now = time.time()
            if now > start+1.9:
                s = 1
                check = True
                break
            if p%i == 0:
                p = p//i
                if p == 1:
                    s = 1
                if i not in fact:
                    fact[i] = 1
                else:
                    fact[i] += 1
                break
    ans = 1
    for i in fact:
        if fact[i] >= n:
            ans = ans*i**(fact[i]//n)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
n,p = map(int,input().split())

if n >= 40 or p == 1:
    print("1")
else:
    s = 0
    fact = []
    while s == 0:
        for i in range(2,p+1):
            if p%i == 0:
                p = p//i
                if p == 1:
                    s = 1
                fact.append(i)
                break
    c = collections.Counter(fact)
    ans = 1
    for i in c:
        if c[i] >= n:
            ans = ans*i**(c[i]//n)
    print(ans)

Fixed submission:
import time

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

if n >= 40 or p == 1:
    print("1")
elif n == 1:
    print(p)
else:
    s = 0
    fact = {}
    start = time.time()
    check = False
    while s == 0:
        for i in range(2,p+1):
            now = time.time()
            if now > start+1.9:
                s = 1
                check = True
                break
            if p%i == 0:
                p = p//i
                if p == 1:
                    s = 1
                if i not in fact:
                    fact[i] = 1
                else:
                    fact[i] += 1
                break
    ans = 1
    for i in fact:
        if fact[i] >= n:
            ans = ans*i**(fact[i]//n)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
s = list(input())
n = len(s)
check = True
counter = 0
while check:
    temp = False
    for i in range(n-1):
        if s[i] == "B" and s[i+1] == "W":
            s[i] = "W"
            s[i+1] = "B"
            counter += 1
            temp = True
    if temp == False:
        check = False
print(counter)

Fixed submission:
s = list(input())
b = 0
ans = 0
for i in range(len(s)):
    if s[i] == "B":
        b += 1
    else:
        ans += b
print(ans)