Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
"main.py" 5L, 116C written
def calc_watering_num(h, offset, left, right):
        if left > right:
                return 0
        min_h = None
        min_h_indices = []
        for i in range(left, right + 1):
                if min_h is None or min_h > h[i] - offset:
                        min_h = h[i] - offset
                        min_h_indices = [i]
                elif min_h == h[i] - offset:
                        min_h_indices.append(i)
        if len(min_h_indices) == right - left + 1:
                return min_h
        num = min_h
        prev = left
        for i in min_h_indices:
                num += calc_watering_num(h, offset + min_h, prev, i - 1)
                prev = i + 1
        num += calc_watering_num(h, offset + min_h, prev, right)
        return num


input()
h = [int(v) for v in input().split()]
print(calc_watering_num(h, 0, 0, len(h) - 1))

Fixed submission:
def calc_watering_num(h, offset, left, right):
        if left > right:
                return 0
        min_h = None
        min_h_indices = []
        for i in range(left, right + 1):
                if min_h is None or min_h > h[i] - offset:
                        min_h = h[i] - offset
                        min_h_indices = [i]
                elif min_h == h[i] - offset:
                        min_h_indices.append(i)
        if len(min_h_indices) == right - left + 1:
                return min_h
        num = min_h
        prev = left
        for i in min_h_indices:
                num += calc_watering_num(h, offset + min_h, prev, i - 1)
                prev = i + 1
        num += calc_watering_num(h, offset + min_h, prev, right)
        return num


input()
h = [int(v) for v in input().split()]
print(calc_watering_num(h, 0, 0, len(h) - 1))
Buggy python submission (verdict: Runtime Error):
def get_second(a):
	if len(a) == 1:
		return 0
	else:
		a[1][0]

n = int(input())
a = [int(v) for v in input().split()]
nums = [{}, {}]
for i, v in enumerate(a):
	if v in nums[i % 2]:
		nums[i % 2][v] += 1
	else:
		nums[i % 2][v] = 1
evens = sorted([(v, k) for k, v in nums[0].items()], reverse=True)
odds = sorted([(v, k) for k, v in nums[1].items()], reverse=True)
if evens[0][1] != odds[0][1]:
	print(n - evens[0][0] - odds[0][0])
else:
	print(n - max(evens[0][0] + get_second(odds), get_second(evens) + odds[0][0]))

Fixed submission:
def get_second(a):
	if len(a) == 1:
		return 0
	else:
		return a[1][0]

n = int(input())
a = [int(v) for v in input().split()]
nums = [{}, {}]
for i, v in enumerate(a):
	if v in nums[i % 2]:
		nums[i % 2][v] += 1
	else:
		nums[i % 2][v] = 1
evens = sorted([(v, k) for k, v in nums[0].items()], reverse=True)
odds = sorted([(v, k) for k, v in nums[1].items()], reverse=True)
if evens[0][1] != odds[0][1]:
	print(n - evens[0][0] - odds[0][0])
else:
	print(n - max(evens[0][0] + get_second(odds), get_second(evens) + odds[0][0]))
Buggy python submission (verdict: Runtime Error):
a,b,k = map(int, input().split())

q = [1]

for i in range(2,50):
  if a % i == 0 and b % i == 0:
    q.append(i)

print(q[k - 1])

Fixed submission:
a,b,k = map(int, input().split())
 
q = []
 
for i in range(1,min(a,b)+1):
  if a % i == 0 and b % i == 0:
    q.append(i)
 
print(q[-k])
Buggy python submission (verdict: Runtime Error):
import functools, math
n, a = input(), list(map(int, input().split()))
print(functools.reduce(math.gcd, a))

Fixed submission:
import functools, fractions
n, a = input(), list(map(int, input().split()))
print(functools.reduce(fractions.gcd, a))
Buggy python submission (verdict: Runtime Error):
import fraction
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fraction.gcd(x, y)

def lcm(nums):
    return reduce(lcm_base, nums, 1)

n, a = input(), list(map(int, input().split()))
l = lcm(a)
sum = 0
for aa in a:
    sum += (l-1) % aa
print(sum)


Fixed submission:
from functools import reduce
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


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

def lcm(nums):
    return reduce(lcm_base, nums, 1)

n, a = input(), list(map(int, input().split()))
l = lcm(a)
sum = 0
for aa in a:
    sum += (l-1) % aa
print(sum)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(nums):
    return reduce(lcm_base, nums, 1)

n, a = input(), list(map(int, input().split()))
l = lcm(a)
sum = 0
for aa in a:
    sum += (l-1) % aa
print(sum)


Fixed submission:
from functools import reduce
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


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

def lcm(nums):
    return reduce(lcm_base, nums, 1)

n, a = input(), list(map(int, input().split()))
l = lcm(a)
sum = 0
for aa in a:
    sum += (l-1) % aa
print(sum)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(nums):
    return reduce(lcm_base, nums, 1)

n, a = input(), list(map(int, input().split()))
l = lcm(a)
sum = 0
for aa in a:
    sum += (l-1) % aa
print(sum)


Fixed submission:
from functools import reduce
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


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

def lcm(nums):
    return reduce(lcm_base, nums, 1)

n, a = input(), list(map(int, input().split()))
l = lcm(a)
sum = 0
for aa in a:
    sum += (l-1) % aa
print(sum)
Buggy python submission (verdict: Runtime Error):
a = input()
print(a if a % 2 == 0 else a * 2)

Fixed submission:
a = input()
print(a if a % 2 == 0 else a * 2)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N, K = list(map(int, input().split()))
count = 0
for i in range(K, N+1):
    count += N - i
for i in range(K+1, N+1):
    for j in range(1, i):
        if i % j >= K:
            count += 1
print(count)

Fixed submission:
N, K = list(map(int, input().split()))
count = 0
if K == 0:
    print(N*N)
    exit()
for i in range(1, N+1):
    count += int(N/i) * max(i-K, 0) + max(N - int(N/i)*i + 1 - K, 0)
print(count)
Buggy python submission (verdict: Runtime Error):
print(input()/3)

Fixed submission:
print(int(int(input())/3))
Buggy python submission (verdict: Runtime Error):
N = int(input())
txys = [list(map(int, input().split())) for _ in range(N) ]
txys.insert(0, [0, 0, 0])
 
for i in range(N):
    dt = txys[i+1][0] - txys[i][0]
    dist = abs(txys[i][1] - txys[i+1][1]) + abs(txys[i][2] - txys[i+1][2])
    if dt % 2 != dist % 2 or dist > dt:
        print("No")
        exit()
print("Yes")


Fixed submission:
a, b = map(int, input().split())
print("Even" if a * b % 2 == 0 else "Odd")

Buggy python submission (verdict: Runtime Error):
print("Even" if int(input()) * int(input()) % 2 == 0 else "odd")

Fixed submission:
a, b = map(int, input().split())
print("Even" if a * b % 2 == 0 else "Odd")
Buggy python submission (verdict: Time Limit Exceeded):
N, Y = list(map(int, input().split()))
Y //= 1000
for x in range(0, Y+1):
    for y in range(0, Y//5+1):
        z = N-x-y
        if (9*x + 4*y) == Y-N and z >= 0:
            print(x, y, N-x-y)
            exit()
print(-1, -1, -1)


Fixed submission:
N, Y = list(map(int, input().split()))
Y //= 1000
for x in range(0, Y//10+1):
    for y in range(0, (Y-10*x)//5+1):
        z = N-x-y
        if (9*x + 4*y) == Y-N and z >= 0:
            print(x, y, N-x-y)
            exit()
print(-1, -1, -1)
Buggy python submission (verdict: Runtime Error):
import math
N, H = list(map(int, input().split()))
maxA = 0
n = 0
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    maxA = max(maxA, ta)
    b.append(tb)

b = list(filter(lambda x: x > maxA, b))
b.sort()

while H > 0 and b:
    H -= b.pop()
    n += 1

print(n + max(H-1, -1) // a + 1 )

Fixed submission:
N, H = list(map(int, input().split()))
maxA = 0
n = 0
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    maxA = max(maxA, ta)
    b.append(tb)

b = list(filter(lambda x: x > maxA, b))
b.sort()

while H > 0 and b:
    H -= b.pop()
    n += 1

print(n + max(H-1, -1) // maxA + 1 )

Buggy python submission (verdict: Runtime Error):
import math
N, H = list(map(int, input().split()))
a = []
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    a.append(ta)
    b.append(tb)

b = list(filter(lambda x: x > max(a), b))
b.sort()
slashNum = math.ceil( (H - sum(b)) / max(a) )

dmg = slashNum * max(a)
for i in range(N):
    dmg += b[-i]
    if dmg >= H:
        print(slashNum + i + 1)
        exit()

Fixed submission:
N, H = list(map(int, input().split()))
maxA = 0
n = 0
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    maxA = max(maxA, ta)
    b.append(tb)

b = list(filter(lambda x: x > maxA, b))
b.sort()

while H > 0 and b:
    H -= b.pop()
    n += 1

print(n + max(H-1, -1) // maxA + 1 )

Buggy python submission (verdict: Runtime Error):
import math
N, H = list(map(int, input().split()))
a = []
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    a.append(ta)
    b.append(tb)

b = list(filter(lambda x: x > max(a), b))
b.sort()
b.reverse()
slashNum = math.ceil( (H - sum(b)) / max(a) )

dmg = slashNum * max(a)
for i in range(N):
    dmg += b[i]
    if dmg >= H:
        print(slashNum + i + 1)
        exit()

Fixed submission:
N, H = list(map(int, input().split()))
maxA = 0
n = 0
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    maxA = max(maxA, ta)
    b.append(tb)

b = list(filter(lambda x: x > maxA, b))
b.sort()

while H > 0 and b:
    H -= b.pop()
    n += 1

print(n + max(H-1, -1) // maxA + 1 )

Buggy python submission (verdict: Runtime Error):
import math
N, H = list(map(int, input().split()))
a = []
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    a.append(ta)
    b.append(tb)

b = list(filter(lambda x: x > max(a), b))
b.sort()
b.reverse()
slashNum = math.ceil( (H - sum(b)) / max(a) )

dmg = slashNum * max(a)
for i in range(N):
    dmg += b[i]
    if dmg >= H:
        print(slashNum + i + 1)
        break

Fixed submission:
N, H = list(map(int, input().split()))
maxA = 0
n = 0
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    maxA = max(maxA, ta)
    b.append(tb)

b = list(filter(lambda x: x > maxA, b))
b.sort()

while H > 0 and b:
    H -= b.pop()
    n += 1

print(n + max(H-1, -1) // maxA + 1 )
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

def _main():
    text = input()
    count = 0

    while True:
        new_text = text.replace('01', '')
        new_text = new_text.replace('10', '')

        if text == new_text:
            break
        else:
            count += len(text) - len(new_text)
            text = new_text

    print(count)



if __name__ == '__main__':
    _main()

Fixed submission:
# coding: utf-8

def _main():
    text = input()

    zero_count = text.count('0')
    one_count = len(text) - zero_count

    ans = min(zero_count, one_count) * 2

    print(ans)



if __name__ == '__main__':
    _main()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

import re

def _main():
    text = input()
    count = 0

    while True:
        new_text = re.sub(r'01|10', '', text)

        if text == new_text:
            break
        else:
            count += len(text) - len(new_text)
            text = new_text

    print(count)



if __name__ == '__main__':
    _main()

Fixed submission:
# coding: utf-8

def _main():
    text = input()

    zero_count = text.count('0')
    one_count = len(text) - zero_count

    ans = min(zero_count, one_count) * 2

    print(ans)



if __name__ == '__main__':
    _main()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

import re

def _main():
    text = input()
    count = 0

    while True:
        new_text = re.sub(r'01|10', '', text, 1)

        if text == new_text:
            break
        else:
            count += 2
            text = new_text

    print(count)



if __name__ == '__main__':
    _main()

Fixed submission:
# coding: utf-8

def _main():
    text = input()

    zero_count = text.count('0')
    one_count = len(text) - zero_count

    ans = min(zero_count, one_count) * 2

    print(ans)



if __name__ == '__main__':
    _main()
Buggy python submission (verdict: Runtime Error):
# coding: utf-8

import sys

def _main():
    # args = sys.argv[1:]
    # args = [int(arg) for arg in args]
    datelist = sys.argv[1].split('/')
    year, month, day = [int(i) for i in datelist]

    if year< 2019:
        print('Heisei')
    elif year == 2019:
        if month<4:
            print('Heisei')
        elif month == 4:
            if day <= 30:
                print('Heisei')
            else:
                print('TBD')
        else:
            print('TBD')
    else:
        print('TBD')

if __name__ == '__main__':
    _main()

Fixed submission:
# coding: utf-8

import sys

def _main():
    # args = sys.argv[1:]
    # args = [int(arg) for arg in args]
    text = input()
    datelist = text.split('/')
    year, month, day = [int(i) for i in datelist]

    if year< 2019:
        print('Heisei')
    elif year == 2019:
        if month<4:
            print('Heisei')
        elif month == 4:
            if day <= 30:
                print('Heisei')
            else:
                print('TBD')
        else:
            print('TBD')
    else:
        print('TBD')

if __name__ == '__main__':
    _main()
Buggy python submission (verdict: Runtime Error):
print(input().count())

Fixed submission:
print(input().count('2'))
Buggy python submission (verdict: Runtime Error):
a,b = input().split(' ')
if (a*b) % 2 == 1:
    print('Odd')
else:
    print('Even')

Fixed submission:
a,b = input().split(' ')
a = int(a)
b = int(b)
if (a*b)%2 == 0:
  print('Even')
else:
  print('Odd')

Buggy python submission (verdict: Runtime Error):
a,b = input().split(' ')
if (a*b)%2 == 0:
  print('Even')
else:
  print('Odd')

Fixed submission:
a,b = input().split(' ')
a = int(a)
b = int(b)
if (a*b)%2 == 0:
  print('Even')
else:
  print('Odd')
Buggy python submission (verdict: Runtime Error):
,b,c = input().split()
print('YES') if a[-1] == b[0] and b[-1] == c[0] else print('NO')

Fixed submission:
a,b,c = input().split()
print('YES') if a[-1] == b[0] and b[-1] == c[0] else print('NO')
Buggy python submission (verdict: Runtime Error):
print([x[0].upper() for x in input().split()].join())

Fixed submission:
print(''.join([x[0].upper() for x in input().split()]))
Buggy python submission (verdict: Runtime Error):
w,a,b = [int(x) for x in input().split()]
print(abs(b-w-(b-a+w))) if a+w <= b else print(0)


Fixed submission:
a,b = input().split()
print('H') if a == b else print('D')

Buggy python submission (verdict: Runtime Error):
a,b = input.split()
print('H') if a == b else print('D')

Fixed submission:
a,b = input().split()
print('H') if a == b else print('D')
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
print(math.factorical(n) % (10**9 + 7))


Fixed submission:
import math
n = int(input())
print(math.factorial(n) % (10**9 + 7))

Buggy python submission (verdict: Runtime Error):
import math
n = gets.to_i
print(math.factorical(n) % (10**9 + 7))


Fixed submission:
import math
n = int(input())
print(math.factorial(n) % (10**9 + 7))
Buggy python submission (verdict: Runtime Error):
a,b = [int(x) for x in input().split()]
j = [2,3,4,5,6,7,8,9,10,11,12,13,1]
if j.index(a) > j.rindex(b):
  print('Alice')
elif j.index(a) < j.index(b):
  print('Bob')
else:
  print('Draw')


Fixed submission:
a,b = [int(x) for x in input().split()]
j = [2,3,4,5,6,7,8,9,10,11,12,13,1]
if j.index(a) > j.index(b):
  print('Alice')
elif j.index(a) < j.index(b):
  print('Bob')
else:
  print('Draw')

Buggy python submission (verdict: Runtime Error):
j = [2,3,4,5,6,7,8,9,10,11,12,13,1]
a,b = [int(x) for x in input().split()]
if j.index(a) > j.rindex(b):
  print('Alice')
elif j.index(a) < j.index(b):
  print('Bob')
else:
  print('Draw')


Fixed submission:
a,b = [int(x) for x in input().split()]
j = [2,3,4,5,6,7,8,9,10,11,12,13,1]
if j.index(a) > j.index(b):
  print('Alice')
elif j.index(a) < j.index(b):
  print('Bob')
else:
  print('Draw')

Buggy python submission (verdict: Runtime Error):
j = [2,3,4,5,6,7,8,9,10,11,12,13,1]
a,b = [int(x) for x in input().split()]
if j.index(a) > j.rindex(b):
  print('Alice')
elif j.rindex(a) < j.rindex(b):
  print('Bob')
else:
  print('Draw')


Fixed submission:
a,b = [int(x) for x in input().split()]
j = [2,3,4,5,6,7,8,9,10,11,12,13,1]
if j.index(a) > j.index(b):
  print('Alice')
elif j.index(a) < j.index(b):
  print('Bob')
else:
  print('Draw')

Buggy python submission (verdict: Runtime Error):
j = [2,3,4,5,6,7,8,9,10,11,12,13,1]
a,b = [int(x) for x in input().split()]
if j.rindex(a) < j.rindex(b):
  print('Alice')
elif j.rindex(a) > j.rindex(b):
  print('Bob')
else:
  print('Draw')

Fixed submission:
a,b = [int(x) for x in input().split()]
j = [2,3,4,5,6,7,8,9,10,11,12,13,1]
if j.index(a) > j.index(b):
  print('Alice')
elif j.index(a) < j.index(b):
  print('Bob')
else:
  print('Draw')
Buggy python submission (verdict: Runtime Error):
a = input()
print(len(a[a.index('A'):a.rindex('Z')+1]))

Fixed submission:
a = int(input())
print('ARC') if a>=1200 else print('ABC')
Buggy python submission (verdict: Runtime Error):
a = input()
b = a[a.index('A'):a.rindex('z')+1]

Fixed submission:
a = input()
print(len(a[a.index('A'):a.rindex('Z')+1]))
Buggy python submission (verdict: Runtime Error):
input()
tmp = x = 0
for a in input():
  x += int(a.replace('I','1').replace('D','-1'))
  if tmp < x:
    tmp = x

print(max([0,tmp]))


Fixed submission:
a,b,c,d = [int(x) for x in input().split()]
print(a*b) if (a*b) >= (c*d) else print(c*d)

Buggy python submission (verdict: Runtime Error):
input()
tmp = x = 0
for a in input():
  x += int(a.replace('I','1').replace('D','-1'))
  if tmp < x:
    tmp = x

print(max([,tmp]))


Fixed submission:
a,b,c,d = [int(x) for x in input().split()]
print(a*b) if (a*b) >= (c*d) else print(c*d)

Buggy python submission (verdict: Runtime Error):
a,b,c,d = [int(x) for x in input().sprit()]
print(a*b) if (a*b) >= (c*d) else print(c*d)


Fixed submission:
a,b,c,d = [int(x) for x in input().split()]
print(a*b) if (a*b) >= (c*d) else print(c*d)

Buggy python submission (verdict: Runtime Error):
a,b,c,d = [int(x) for x in input.sprit()]
print(a*b) if (a*b) >= (c*d) else print(c*d)


Fixed submission:
a,b,c,d = [int(x) for x in input().split()]
print(a*b) if (a*b) >= (c*d) else print(c*d)

Buggy python submission (verdict: Runtime Error):
a,b,c,d = [int(x) for x in input.split()]
print(a*b) if (a*b) >= (c*d) else print(c*d)

Fixed submission:
a,b,c,d = [int(x) for x in input().split()]
print(a*b) if (a*b) >= (c*d) else print(c*d)
Buggy python submission (verdict: Runtime Error):
k,s = [int(x) for x in input().split()]
a = 0
n = 0
while a <= k:
  b = 0
  while b <= k:
    z = s-a-b
    if 0<=z and z <= k:
      n += 1
    b += 1
  a += 1
print(n)


Fixed submission:
print(input().replace(',',' '))

Buggy python submission (verdict: Runtime Error):
k,s = [int(x) for x in input().split()]
ans = 0
for x in range(k+1):
    for y in range(x, k+1):
        z = s - x - y
        if x <= y <= z <= k:
            ans += [ None, 1, 3, 6 ][ len(set([ x, y, z ])) ]

Fixed submission:
print(input().replace(',',' '))

Buggy python submission (verdict: Runtime Error):
k,s = input().split()
a = 0
n = 0
while a <= k:
  b = 0
  while b <= k:
    c = 0
    while c <= k:
      if (a+b+c) == s:
        n += 1
      c += 1
    b += 1
  a += 1
print(n)


Fixed submission:
print(input().replace(',',' '))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
for _ in range(m):
  t = a
  b,c = [int(x) for x in input().split()]
  t[b-1] = c
  print(sum(a))


Fixed submission:
a,o,b = input().split()
print(int(a) + int(o+b))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]
m = int(input())
for _ in range(m):
  b,c = [int(x) for x in input.split()]
  a[b-1] = c
  print(sum(a))


Fixed submission:
a,o,b = input().split()
print(int(a) + int(o+b))

Buggy python submission (verdict: Runtime Error):
a,o,b = input().split()
print(a + int(o+b))

Fixed submission:
a,o,b = input().split()
print(int(a) + int(o+b))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [input() for _ in range(n)]
m = int(input())
for _ in range(m):
  b,c = [int(x) for x in input.split()]
  a[b-1] = c
  print(sum(a))

Fixed submission:
from copy import deepcopy
n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
for _ in range(m):
  t = deepcopy(a)
  b,c = [int(x) for x in input().split()]
  t[b-1] = c
  print(sum(t))

Buggy python submission (verdict: Runtime Error):
n = input()
a = [input() for _ in range(n)]
m = input()
for _ in range(m):
  b,c = [int(x) for x in input.split()]
  a[b-1] = c
  print(sum(a))

Fixed submission:
from copy import deepcopy
n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
for _ in range(m):
  t = deepcopy(a)
  b,c = [int(x) for x in input().split()]
  t[b-1] = c
  print(sum(t))
Buggy python submission (verdict: Time Limit Exceeded):
S=raw_input()
A=[s for s in S]

while True:
    A_new=[]
    i=0
    while i<len(A):
        if i<len(A)-1:
            if A[i]!=A[i+1]:
                i+=2
            else:
                A_new.append(A[i])
                i+=1
        else:
            A_new.append(A[i])
            i+=1
    if A==A_new:
        break
    else:
        A=A_new[:]
print len(S)-len(A)

Fixed submission:
S=raw_input()
A=[]
Ans=0
for i in range(len(S)):
    if len(A)>0:
        if A[-1]!=S[i]:
            A.pop()
            Ans+=2
        else:
            A.append(S[i])
    else:
        A.append(S[i])

print Ans
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,raw_input().split())
A=map(int,raw_input().split())

import collections
D = collections.defaultdict(int)

for a in A:
    a2=format(a, 'b')
    for i,a20 in enumerate(a2[::-1]):
        D[i]+=int(a20)


K2=format(K, 'b')
K2=K2.zfill(max(D)+1)


Ans=0
x=0
n=len(K2)

for i in range(n):
    if x!=0:
        Ans+=(2**(n-i-1))*max(D[n-i-1],N-D[n-i-1])
    else:
        if K2[i]=="0":
            Ans+=(2**(n-i-1))*D[n-i-1]
        else:
            if D[n-i-1]>N-D[n-i-1]:
                Ans+=(2**(n-i-1))*D[n-i-1]
                x=1
            else:
                Ans+=(2**(n-i-1))*(N-D[n-i-1])
print Ans

Fixed submission:
N,K=map(int,raw_input().split())
A=map(int,raw_input().split())

import collections
D = collections.defaultdict(int)

for a in A:
    a2=format(a, 'b')
    for i,a20 in enumerate(a2[::-1]):
        if a20=="1":
            D[i]+=1


K2=format(K, 'b')
K2=K2.zfill(max(D)+1)


Ans=0
n=len(K2)

for i in range(n):
    if K2[i]=="0":
        Ans+=(2**(n-i-1))*D[n-i-1]
    else:
        if D[n-i-1]>N-D[n-i-1]:
            Ans+=(2**(n-i-1))*D[n-i-1]
            break
        else:
            Ans+=(2**(n-i-1))*(N-D[n-i-1])
    
if i<n-1:
    Ans+=sum((2**(n-j-1))*max(D[n-j-1],N-D[n-j-1]) for j in range(i+1,n))

print Ans