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

import sys
input = sys.stdin.readline

parent_node = []

def get_parent(ind):
    global parent_node
    if ind != parent_node[ind]:
        parent_node[ind] = get_parent(parent_node[ind])
    return parent_node[ind]



def main():
    num = int(input())

    data = defaultdict(tuple)

    for i in range(num):
        x, y = map(int, input().split())
        data[i] = (x, y)

    data_sort = sorted(data.items(), key=lambda x: x[1][0])
    data_x = [ele for ele, ele2 in data_sort]
    data_sort = sorted(data.items(), key=lambda x: x[1][1])
    data_y = [ele for ele, ele2 in data_sort]

    cost_data = [0 for i in range((num - 1) * 2)]
    for i in range(len(data_x) - 1):
        a, b = data_x[i], data_x[i + 1]
        cost = abs(data[a][0] - data[b][0])
        cost_data[i] = a, b, cost
    for i in range(len(data_y) - 1):
        a, b = data_y[i], data_y[i + 1]
        cost = abs(data[a][1] - data[b][1])
        cost_data[i + len(data_x) - 1] = a, b, cost

    cost_data.sort(key=lambda x: x[2])
    global parent_node
    parent_node = [i for i in range(num)]

    ans = 0
    for i in range(len(cost_data)):
        a, b, cost = cost_data[i]
        a_parent = get_parent(a)
        b_parent = get_parent(b)
        if a_parent != b_parent:
            ans += cost
            parent_node[min(a_parent, b_parent)] = max(a_parent, b_parent)

    print(ans)





if __name__ == '__main__':
    main()


Fixed submission:
from collections import defaultdict

import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline

parent_node = []

def get_parent(ind):
    global parent_node
    if ind != parent_node[ind]:
        parent_node[ind] = get_parent(parent_node[ind])
    return parent_node[ind]



def main():
    num = int(input())

    data = defaultdict(tuple)

    for i in range(num):
        x, y = map(int, input().split())
        data[i] = (x, y)

    data_sort = sorted(data.items(), key=lambda x: x[1][0])
    data_x = [ele for ele, ele2 in data_sort]
    data_sort = sorted(data.items(), key=lambda x: x[1][1])
    data_y = [ele for ele, ele2 in data_sort]

    cost_data = [0 for i in range((num - 1) * 2)]
    for i in range(len(data_x) - 1):
        a, b = data_x[i], data_x[i + 1]
        cost = abs(data[a][0] - data[b][0])
        cost_data[i] = a, b, cost
    for i in range(len(data_y) - 1):
        a, b = data_y[i], data_y[i + 1]
        cost = abs(data[a][1] - data[b][1])
        cost_data[i + len(data_x) - 1] = a, b, cost

    cost_data.sort(key=lambda x: x[2])
    global parent_node
    parent_node = [i for i in range(num)]

    ans = 0
    for i in range(len(cost_data)):
        a, b, cost = cost_data[i]
        a_parent = get_parent(a)
        b_parent = get_parent(b)
        if a_parent != b_parent:
            ans += cost
            parent_node[min(a_parent, b_parent)] = max(a_parent, b_parent)

    print(ans)





if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):

from collections import defaultdict, Counter

def main():
    num = int(input())
    ans_dic = Counter(list(input()))
    for i in range(num - 1):
        aaa = Counter(list(input()))
        ans = defaultdict(int)
        for ele in ans_dic.keys():
            if ele in aaa.keys():
                ans[ele] += min(ans_dic[ele], aaa[ele])

    ans = sorted(ans.items(), key=lambda x: -x[1])

    for moji, kosuu in ans:
        for i in range(kosuu):
            print(moji, end='')

    print()



if __name__ == '__main__':
    main()

Fixed submission:
from collections import defaultdict, Counter

def main():
    num = int(input())
    hajime = list(input())

    ans = Counter(hajime)

    for i in range(num - 1):
        aaa = Counter(list(input()))
        ans_kari = defaultdict(int)
        for ele in ans.keys():
            if ele in aaa.keys():
                ans_kari[ele] = min(ans[ele], aaa[ele])
        ans = ans_kari

    for i in range(26):
        for j in range(ans[chr(97 + i)]):
            print(chr(97 + i), end='')

    print()



if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial



def union_r(node):
    global road_union
    if road_union[node] != node:
        road_union[node] = union_r(road_union[node])
    return road_union[node]

def union_t(node):
    global train_union
    if train_union[node] != node:
        train_union[node] = union_t(train_union[node])
    return train_union[node]


road_union, train_union = [], []


def main():
    node_num, road_num, train_num = map(int, input().split())

    global road_union
    road_union = [i for i in range(node_num + 1)]
    for i in range(road_num):
        a, b = map(int, input().split())
        parent_a = union_r(a)
        parent_b = union_r(b)
        road_union[min(parent_a, parent_b)] = max(parent_a, parent_b)
        # print(road_union)

    global train_union
    train_union = [i for i in range(node_num + 1)]
    for i in range(train_num):
        a, b = map(int, input().split())
        parent_a = union_t(a)
        parent_b = union_t(b)
        train_union[min(parent_a, parent_b)] = max(parent_a, parent_b)

    # print(train_union, road_union)

    ryouhou = [0 for i in range(node_num + 1)]
    for i in range(1, node_num + 1):
        parent_r = union_r(i)
        parent_t = union_t(i)
        ryouhou[i] = (parent_r, parent_t)

    # print(train_union, road_union, 'uuu')

    count_d = Counter(ryouhou)

    for i in range(1, node_num + 1):
        now_flg = ryouhou[i]
        print(count_d[now_flg], end=' ')
    print()





if __name__ == '__main__':
    main()

Fixed submission:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial



def main():
    if input() in ['a', 'e', 'i', 'o', 'u']:
        print('vowel')
    else:
        print('consonant')






if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):

def main():
    data = input()

    while 'ST' in data:
        data = data.replace('ST', '')
    print(len(data))




if __name__ == '__main__':
    main()

Fixed submission:

def main():
    data  = list(input())

    ans = len(data)
    count_s = 0
    for i in range(len(data)):
        if data[i] == 'S':
            count_s += 1
        else:
            if count_s > 0:
                count_s -= 1
                ans -= 2

    print(ans)




if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




def main():
    s = list(input())
    num = int(input())

    for i in range(len(s)):
        now_ind = ord(s[i])
        if now_ind + num > 122:
            num -= 123 - now_ind
            s[i] = 'a'

    last_ind = ord(s[-1])
    if last_ind + num <= 122:
        last_ind += num
    else:
        last_ind = last_ind + num - 27
    s[-1] = chr(last_ind)

    print(''.join(s))



if __name__ == '__main__':
    main()



Fixed submission:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




def main():
    s = list(input())
    num = int(input())

    for i in range(len(s)):
        now_ind = ord(s[i])
        if now_ind == 97:
            continue
        if now_ind + num > 122:
            num -= 123 - now_ind
            s[i] = 'a'

    last_ind = ord(s[-1]) - 97
    last_ind = (last_ind + num) % 26 + 97
    s[-1] = chr(last_ind)

    print(''.join(s))



if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from  collections import Counter

def main():
    num, avg = map(int, input().split())
    data = list(map(int, input().split()))

    dp = [[[0 for i in range(max(num, avg) * max(data) + 1)] for j in range(num + 1)] for k in range(num + 1)]
    dp[0][0][0] = 1

    for i in range(1, num + 1):
        now_card = data[i - 1]
        for j in range(num + 1):
            for k in range(max(num, avg) * max(data) + 1):
                # print(i, j, k)
                dp[i][j][k] += dp[i - 1][j][k]
                if k - now_card >= 0 and j - 1 >= 0:
                    dp[i][j][k] += dp[i - 1][j - 1][k - now_card]
        # print(dp[i][j])

    ans = 0
    for i in range(1, num + 1):
        ans += dp[num][i][i * avg]
    print(ans)





if __name__ == '__main__':
    main()


Fixed submission:
from  collections import Counter

def main():
    num, avg = map(int, input().split())
    data = list(map(int, input().split()))

    dp = [[[0 for i in range(6000)] for j in range(num + 1)] for k in range(num + 1)]
    dp[0][0][0] = 1

    for i in range(1, num + 1):
        now_card = data[i - 1]
        for j in range(num + 1):
            for k in range(6000):
                # print(i, j, k)
                dp[i][j][k] += dp[i - 1][j][k]
                if k - now_card >= 0 and j - 1 >= 0:
                    dp[i][j][k] += dp[i - 1][j - 1][k - now_card]
        # print(dp[i][j])

    ans = 0
    for i in range(1, num + 1):
        ans += dp[num][i][i * avg]
    print(ans)





if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):

from  collections import Counter

def main():
    num, avg = map(int, input().split())
    data = list(map(int, input().split()))

    dp = [[[0 for i in range(num * max(data) + 1)] for j in range(num + 1)] for k in range(num + 1)]
    dp[0][0][0] = 1

    for i in range(1, num + 1):
        now_card = data[i - 1]
        for j in range(num + 1):
            for k in range(num * max(data) + 1):
                # print(i, j, k)
                dp[i][j][k] += dp[i - 1][j][k]
                if k - now_card >= 0 and j - 1 >= 0:
                    dp[i][j][k] += dp[i - 1][j - 1][k - now_card]
        # print(dp[i][j])

    ans = 0
    for i in range(1, num + 1):
        ans += dp[num][i][i * avg]
    print(ans)





if __name__ == '__main__':
    main()

Fixed submission:
from  collections import Counter

def main():
    num, avg = map(int, input().split())
    data = list(map(int, input().split()))

    dp = [[[0 for i in range(6000)] for j in range(num + 1)] for k in range(num + 1)]
    dp[0][0][0] = 1

    for i in range(1, num + 1):
        now_card = data[i - 1]
        for j in range(num + 1):
            for k in range(6000):
                # print(i, j, k)
                dp[i][j][k] += dp[i - 1][j][k]
                if k - now_card >= 0 and j - 1 >= 0:
                    dp[i][j][k] += dp[i - 1][j - 1][k - now_card]
        # print(dp[i][j])

    ans = 0
    for i in range(1, num + 1):
        ans += dp[num][i][i * avg]
    print(ans)





if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):

import sys


def check(num, s, b):
    sum_keta = 0
    while num > 0:
        sum_keta += num % b
        num //= b
    if sum_keta == s:
        return 1
    else:
        return 0


def main():
    num = int(input())
    s = int(input())

    if num == s:
        print(num + 1)
        sys.exit()

    for b in range(2, int(num ** 0.5) + 2):
        if check(num, s, b):
            print(b)
            sys.exit()

    for p in range(1, int(num ** 0.5) + 2):
        b = (num - s) // p + 1
        if check(num, s, b):
            print(b)
            sys.exit()

    print(-1)






if __name__ == '__main__':
    main()

Fixed submission:

import sys


def check(num, s, b):
    sum_keta = 0
    while num > 0:
        sum_keta += num % b
        num //= b
    if sum_keta == s:
        return 1
    else:
        return 0


def main():
    num = int(input())
    s = int(input())

    if num < s:
        print(-1)
        sys.exit()

    if num == s:
        print(num + 1)
        sys.exit()

    if num == 1:
        print(-1)
        sys.exit()

    for b in range(2, int(num ** 0.5) + 2):
        if check(num, s, b):
            print(b)
            sys.exit()

    for p in range(1, int(num ** 0.5) + 2)[::-1]:
        b = (num - s) // p + 1
        if b <= 1:
            continue
        if check(num, s, b):
            print(b)
            sys.exit()

    print(-1)






if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N = input()
if (N[-1] == str(3)):
    print('bon')
elif(int(N[-1]) == 0 or int(N[-1]) == 1 or int(N[-1]) == 6 or int(N[-1]) == 8 ):
    print('pon')
else:
    print('hon')

Fixed submission:
S = input()
T = input()
if(T[0:len(T)-1] == S):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
A += list(map(int,input().split()))
S = 0
k = 0

Num = 0
Dum = 0
Gum = 0

for i in range(N-1):
    Num = i
    for j in range(Num+1):
        Dum += A[j]
    Gum += Dum * A[Num + 1]
    Dum = 0

print(Gum % 1000000007)


Fixed submission:
N = int(input())
A = []
A += list(map(int,input().split()))
S = 0
k = 0

Dum = 0
Gum = 0

for i in range(0, N-1):
    Dum += A[i]
    Gum += Dum * A[i+1]

print(Gum % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
A += list(map(int,input().split()))
S = 0
k = 0

B = A[1:N]   # A1を除外

C = []

Num = 0
Dum = 0
Gum = 0

for i in range(N-1):
    Num = i
    for j in range(Num+1):
        Dum += A[j]
    C.append(Dum)
    Dum = 0

for k in range(N-1):
    Gum += B[k] * C[k]

print(Gum % 1000000007)

Fixed submission:
N = int(input())
A = []
A += list(map(int,input().split()))
S = 0
k = 0

Dum = 0
Gum = 0

for i in range(0, N-1):
    Dum += A[i]
    Gum += Dum * A[i+1]

print(Gum % 1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
N = 0

for i in range(K):
    N += 7*(10**i)
    if N % K == 0:
        print(i+1)
        exit()

print(-1)

Fixed submission:
K = int(input())

t = 7
for i in range(K):
    if t % K == 0:
        print(i + 1)
        break
    t = (t * 10 + 7) % K
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
import bisect

X, N = map(int, input().split())
P = set(map(int, input().split()))

A = {i for i in range(1,101)}

S = list(A - P)

T = bisect.bisect_left(S, X)

if T == 0:
    print(S[0])
elif X - S[T-1] > S[T] - X:
    print(S[T])
else:
    print(S[T-1])


Fixed submission:
import bisect

X, N = map(int, input().split())
P = set(map(int, input().split()))

A = {i for i in range(102)}

S = list(A - P)

T = bisect.bisect_left(S, X)

if T == 0:
    print(S[0])
elif X - S[T-1] > S[T] - X:
    print(S[T])
else:
    print(S[T-1])
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

N, M = map(int, input().split())
F = defaultdict(list)

max_size = 0


for _ in range(M):

    A, B = map(int, input().split())

    if B not in F[A]:
        F[A].append(B)
    if A not in F[B]:
        F[B].append(A)

def dfs(i):
    vis.append(i)
    size = 0
    for j in F[i]:
        if j not in vis:
            size += dfs(j)
    return size + 1


vis = list()

ret = 0

for i in range(N):
    if i+1 not in vis:
        size = dfs(i+1)
        if size > ret:
            ret = size

print('{}'.format(ret))




Fixed submission:
class UnionFind():
    def __init__(self, N):
        self.N = N
        self.par = [n for n in range(N)]
        self.rank = [1] * N
        
    def find(self, u):
        if self.par[u] == u:
            return u
        else:
            return self.find(self.par[u])
    
    def union(self, u, v):

        pu = self.find(u)
        pv = self.find(v)

        if pu == pv: 
            return

        if self.rank[pu] < self.rank[pv]:
            self.par[pu] = pv
            self.rank[pv] += self.rank[pu]

        else: # self.rank[pu] > self.rank[pv]
            self.par[pv] = pu
            self.rank[pu] += self.rank[pv]
 
N, M = map(int, input().split())
UF = UnionFind(N)
for _ in range(M):
    A, B = map(int, input().split())
    A, B = A-1, B-1
    UF.union(A, B)


ret = 0

for n in range(N):
    ret = max(ret, UF.rank[n])

print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
S = [s for s in S]
Q = int(input())

flip = False

for q in range(0, Q):
    qi = list(input().split())

    if len(qi) == 1:
        flip = not flip
    else: # len(qi) == 3
        Fi, Ci = int(qi[1]), qi[2]
        
        if Fi == 1: # front 
            if not flip:
                S.insert(0, Ci)
            else: # flip == True
                S.append(Ci)
        else:
            if not flip:
                S.append(Ci)
            else:
                S.insert(0, Ci)

S = "".join(S)

print( S if not flip else S[::-1])


Fixed submission:
S = str(input())
Q = int(input())

flip = False

head = ""
tail = ""

for q in range(Q):
    Ti = input()
    if Ti == '1':
        flip = not flip
    else:
        _, Fi, Ci = map(str, Ti.split())
        Fi = int(Fi)

        if (Fi^flip)&1:
            head += Ci
        else:
            tail += Ci

S = head[::-1] + S + tail
print( S if not flip else S[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
Q = int(input())

for q in range(0, Q):
    qi = list(input().split())

    if len(qi) == 1:
        S = S[::-1]
    else: # len(qi) == 3
        Fi, Ci = int(qi[1]), qi[2]

        if Fi == 1: # front
            S = Ci + S
        else: # Fi == 2, end
            S = S + Ci

print(S)


Fixed submission:
S = str(input())
Q = int(input())

flip = False

head = ""
tail = ""

for q in range(Q):
    Ti = input()
    if Ti == '1':
        flip = not flip
    else:
        _, Fi, Ci = map(str, Ti.split())
        Fi = int(Fi)

        if (Fi^flip)&1:
            head += Ci
        else:
            tail += Ci

S = head[::-1] + S + tail
print( S if not flip else S[::-1])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

P = list()
for m in range(M):
    n, rst = input().split()
    n = int(n)
    P.append( (n, rst) )


ck = [False for _ in range(N+1)]

ret_cor, ret_pen = 0, 0

for n, rst in P:
    if rst == 'AC':
        if not ck[n]:
            ck[n] = True
            ret_cor += 1

    else: # rst == 'WA'
        if not ck[n]:
            ret_pen += 1

print(ret_cor, ret_pen)


Fixed submission:
l = input()

print(chr(ord(l)+1))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

ret = 0

for i in range(N):
    if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
        ret += 1

print(ret)


Fixed submission:
N = int(input())
S = input()

ret = 0

for i in range(0, N-2):
    if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
        ret += 1

print(ret)
Buggy python submission (verdict: Runtime Error):
N, K = raw_input().split()
N, K = int(N), int(K)

R, S, P = raw_input().split()
R, S, P = int(R), int(S), int(P) 

T = raw_input()

his = list()
ret = 0

for i in range(N):
    if T[i] == 'r':
        if i-K >= 0 and his[i-K] == 'p':
            if i+K <= N and T[i+K] == 's':
                his.append('s')
            else:
                his.append('r')
        else:
            ret += P
            his.append('p')

    elif T[i] == 's':
        if i-K >= 0 and his[i-K] == 'r':
            if i+K <= N and T[i+K] == 'p':
                his.append('p')
            else:
                his.append('s')
        else:
            ret += R
            his.append('r')

    else: # T[i] == 'p'
        if i-K >= 0 and his[i-K] == 's':
            if i+K <= N and T[i+K] == 'r':
                his.append('r')
            else:
                his.append('p')
        else:
            ret += S
            his.append('s')
    
print '{}'.format(ret)
    
        


Fixed submission:
# D - Prediction and Restriction
# https://atcoder.jp/contests/abc149/tasks/abc149_d


N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

def opt(seg):
    # dp[STEP][R/P/S]
    dp = [ [-1, -1, -1] for _ in range(len(seg))]

    dp[0][0] = (R if seg[0] == 's' else 0)
    dp[0][1] = (P if seg[0] == 'r' else 0)
    dp[0][2] = (S if seg[0] == 'p' else 0)

    for i in range(1, len(seg)):
        dp[i][0] = (R if seg[i] == 's' else 0) + max(dp[i-1][1], dp[i-1][2])
        dp[i][1] = (P if seg[i] == 'r' else 0) + max(dp[i-1][0], dp[i-1][2])
        dp[i][2] = (S if seg[i] == 'p' else 0) + max(dp[i-1][0], dp[i-1][1])

    return max(dp[-1])

segs = list()

for K_idx in range(K):
    segs.append( T[K_idx::K] )

print('{}'.format(sum(map(opt, segs))))
Buggy python submission (verdict: Runtime Error):
A, B = map(int, raw_input().split())

s = 1 + 2 + 3
print '{}'.format(s-A-B)


Fixed submission:
A = int(input())
B = int(input())
s = 1 + 2 + 3
print '{}'.format(s-A-B)

Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

s = 1 + 2 + 3
print('{}'.format(s-A-B))


Fixed submission:
A = int(input())
B = int(input())
s = 1 + 2 + 3
print '{}'.format(s-A-B)
Buggy python submission (verdict: Runtime Error):
# Five Dishes
# https://atcoder.jp/contests/abc123/tasks/abc123_b

NUM_DISHES = 5
tt = 0
itvs = list()

for i in range(NUM_DISHES):
    st = int(input())
    tt += st
    if st % 10 == 0:
        itvs.append(0)
    else:
        itvs.append(10 - serve_time % 10)

itvs.sort()

for interval in range(len(itvs) - 1):
    tt += itvs[interval]

print "{}".format(tt)


Fixed submission:
# TODO B - Five Dishes
# https://atcoder.jp/contests/abc123/tasks/abc123_b

NUM_DISHES = 5
intervals = list()

total_time = 0
for i in range(NUM_DISHES):
    serve_time = int(input())
    total_time += serve_time

    if serve_time % 10 == 0:
        intervals.append(0)
    else:
        intervals.append(10 - serve_time % 10)

intervals.sort()

for interval in range(len(intervals) - 1):
    total_time += intervals[interval]

print "{:d}".format(total_time)

Buggy python submission (verdict: Runtime Error):
# Five Dishes
# https://atcoder.jp/contests/abc123/tasks/abc123_b

NUM_DISHES = 5
tt = 0
itvs = list()

for i in range(NUM_DISHES):
    st = int(input())
    tt += st
    if st % 10 == 0:
        itvs.append(0)
    else:
        itvs.append(10 - serve_time % 10)

itvs.sort()

for interval in range(len(itvs) - 1):
    tt += itvs[interval]

print "{}".format(tt)


Fixed submission:
# TODO B - Five Dishes
# https://atcoder.jp/contests/abc123/tasks/abc123_b

NUM_DISHES = 5
intervals = list()

total_time = 0
for i in range(NUM_DISHES):
    serve_time = int(input())
    total_time += serve_time

    if serve_time % 10 == 0:
        intervals.append(0)
    else:
        intervals.append(10 - serve_time % 10)

intervals.sort()

for interval in range(len(intervals) - 1):
    total_time += intervals[interval]

print "{:d}".format(total_time)
Buggy python submission (verdict: Runtime Error):
# D - XOR World
# https://atcoder.jp/contests/abc121/tasks/abc121_d

def two2ten(two):
    base = 1
    ten = 0
    for i in two:
        ten += i*base
        base *= 2
    return ten

def ten2two(ten):
    two = list()
    while ten > 0:
        two.append(ten%2)
        ten /= 2
    return two

def find_first_1(two):
    for two_id in range(len(two)):
        if two[two_id] == 1:
            return two_id

A, B = map(int, raw_input().split())
b = ten2two(B)
pos1 = find_first_1(b)
ret = [0]*len(b)
t = B - A + 1

while t > 0:
    for b_id in range(len(b)):
        ret[b_id] += b[b_id]

    b[pos1] = 0
    for b_id in range(0, pos1):
        b[b_id] = 1

    pos1 = find_first_1(b)
    t -= 1

for ret_id in range(len(ret)):
    ret[ret_id] %= 2

print '{}'.format(two2ten(ret))


Fixed submission:
# D - XOR World
# https://atcoder.jp/contests/abc121/tasks/abc121_d


def xor_from0(n):
    if n % 4 == 0:
        return n
    elif n % 4 == 1:
        return 1
    elif n % 4 == 2:
        return n+1
    else: # n % 4 == 3
        return 0

A, B = map(int, raw_input().split())
print '{}'.format(xor_from0(A-1) ^ xor_from0(B))