Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=[]
b=[]
for i in range(n):
    ia,ib=map(int,input().split())
    a.append(ia)
    b.append(ib)
dp={0:0}
for i in range(n):
    dp2={}
    for key,val in dp.items():
        dp2[key]=val
    for key,val in dp.items():
        nk=(key|a[i])
        if nk<=k:
            if nk in dp:
                dp2[nk]=max(dp2[nk],val+b[i])
            else:
                dp2[nk]=val+b[i]
    for key,val in dp2.items():
        dp[key]=val
ret=0
for val in dp.values():
    ret=max(ret,val)
print(ret)

Fixed submission:
n,k=map(int,input().split())
a=[]
b=[]
for i in range(n):
    ia,ib=map(int,input().split())
    a.append(ia)
    b.append(ib)
bit=0
while k>=(1<<bit):
    bit+=1
ret=0
for i in range(n):
    if k==k|a[i]:
        ret+=b[i]
for i in range(bit):
    if k&(1<<i):
        mask=((1<<bit)-1)^((1<<(i+1))-1)
        ok=(k&mask)|((1<<i)-1)
        tmp=0
        for j in range(n):
            if ok==ok|a[j]:
                tmp+=b[j]
        ret=max(ret,tmp)
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from fractions import Fraction
mod = 998244353
n = int(input())
p = [list(map(int, input().split())) for i in range(n)]
pow2 = [2**i % mod for i in range(n + 1)]
used = [[False] * n for i in range(n)]
ret = (pow2[n] - 1 - n - n * (n - 1) / 2) % mod
for i in range(n):
    for j in range(i):
        if used[i][j]:
            continue
        inline = [i, j]
        for k in range(n):
            if k == i or k == j:
                continue
            if (p[i][1] - p[k][1]) * (p[j][0] - p[k][0]) == (p[j][1] - p[k][1]) * (p[i][0] - p[k][0]):
                inline.append(k)
        for k in range(len(inline)):
            for l in range(len(inline)):
                used[inline[k]][inline[l]] = True
        v = len(inline)
        ret = (ret + mod - pow2[v] + 1 + v + v * (v - 1) // 2) % mod
print(int(ret))


Fixed submission:
import math
mod = 998244353
n = int(input())
p = [list(map(int, input().split())) for i in range(n)]
pow2 = [1]
for i in range(n):
    pow2.append(pow2[-1] * 2 % mod)
used = [[False] * n for i in range(n)]
ret = (pow2[n] - 1 - n - n * (n - 1) / 2) % mod
for i in range(n):
    for j in range(i):
        if used[i][j]:
            continue
        inline = [i, j]
        for k in range(n):
            if k == i or k == j:
                continue
            if (p[i][1] - p[k][1]) * (p[j][0] - p[k][0]) == (p[j][1] - p[k][1]) * (p[i][0] - p[k][0]):
                inline.append(k)
        for k in range(len(inline)):
            for l in range(len(inline)):
                used[inline[k]][inline[l]] = True
        v = len(inline)
        ret = (ret + mod - pow2[v] + 1 + v + v * (v - 1) // 2) % mod
print(int(ret))
Buggy python submission (verdict: Runtime Error):
s=input()
def solve(decided, left, idx):
    if idx==len(s):
        return decided+left
    # 手前に+を入れる
    ret1 = solve(decided+left,int(s[idx]),idx+1)
    # 入れない
    ret2 = solve(decided, left*10int(s[idx]), idx+1)
    return ret1+ret2
print(solve(0,int(s[0]),1))

Fixed submission:
s=input()
def solve(decided, left, idx):
    if idx==len(s):
        return decided+left
    # 手前に+を入れる
    ret1 = solve(decided+left,int(s[idx]),idx+1)
    # 入れない
    ret2 = solve(decided, left*10+int(s[idx]), idx+1)
    return ret1+ret2
# 最初の文字の左側には+は入れる必要が無いので1から
print(solve(0,int(s[0]),1))
Buggy python submission (verdict: Runtime Error):
from sys import stdin

N, K, S = [int(x) for x in stdin.readline().rstrip().split()]

ans = [S] * K
n = (N - K) // (S - 1)
ans.extend([S + 1] * (N - K))

print(*ans)


Fixed submission:
from sys import stdin

N, K, S = [int(x) for x in stdin.readline().rstrip().split()]
    
ans = [S] * K
if S == 10 ** 9:
    ans.extend([1] * (N - K))
else:
    ans.extend([S + 1] * (N - K))

print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import heapq

N, M = [int(x) for x in stdin.readline().rstrip().split()]
B = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)]

graph = [[10 ** 15] * N for _ in range(N)]
for i in range(1, N):
    graph[i][i - 1] = 0
for m in B:
    graph[m[0] - 1][m[1] - 1] = m[2]

d = [(0, 0)]
distance = [10 ** 15] * N
distance[0] = 0
color = ['white'] * N
heapq.heapify(d)

while len(d) > 0:
    temp, u = heapq.heappop(d)
    color[u] = 'black'
    if distance[u] < temp:
        continue
    for v in range(N):
        if color[v] != 'black':
            if distance[u] + graph[u][v] < distance[v]:
                distance[v] = distance[u] + graph[u][v]
                color[v] = 'gray'
                heapq.heappush(d, (distance[v], v))

if distance[N - 1] == 10 ** 15:
    print(-1)
else:
    print(distance[N - 1])

Fixed submission:
from sys import stdin
import heapq

N, M = [int(x) for x in stdin.readline().rstrip().split()]
B = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)]

graph = [[] for _ in range(N)]
for i in range(1, N):
    graph[i].append((0, i - 1))
for m in B:
    graph[m[0] - 1].append((m[2], m[1] - 1))

d = [(0, 0)]
distance = [10 ** 15] * N
distance[0] = 0
color = ['white'] * N
heapq.heapify(d)

while len(d) > 0:
    temp, u = heapq.heappop(d)
    color[u] = 'black'
    if distance[u] < temp:
        continue
    for v in graph[u]:
        if color[v[1]] != 'black':
            if distance[u] + v[0] < distance[v[1]]:
                distance[v[1]] = distance[u] + v[0]
                color[v[1]] = 'gray'
                heapq.heappush(d, (distance[v[1]], v[1]))

if distance[N - 1] == 10 ** 15:
    print(-1)
else:
    print(distance[N - 1])
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import math

a, b, x = [int(x) for x in stdin.readline().rstrip().split()]

if 2 * x >= (a ** 2) * b:
    v = (a ** 2) * b - x
    c = (2 * v) / (a ** 2)
    print(90 - math.atan(a / c) * 180 / math.pi)
else:
    c = 2 * x / (a * b)
    print(math.atan(b / c) * 180 / math.pi)


Fixed submission:
from sys import stdin
import math

a, b, x = [int(x) for x in stdin.readline().rstrip().split()]

if x == (a ** 2) * b:
    print(0)
    exit()
if 2 * x >= (a ** 2) * b:
    v = (a ** 2) * b - x
    c = (2 * v) / (a ** 2)
    print(90 - math.atan(a / c) * 180 / math.pi)
else:
    c = 2 * x / (a * b)
    print(math.atan(b / c) * 180 / math.pi)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

N = int(stdin.readline().rstrip())
L = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
L.sort()

for i in range(2, N):
    for j in range(1, i):
        for k in range(j):
            if L[j] + L[k] > L[i]:
                ans += 1

print(ans)


Fixed submission:
from sys import stdin
import bisect

N = int(stdin.readline().rstrip())
L = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
L.sort()
for i in range(1, N):
    for j in range(i):
        ans += max(bisect.bisect_left(L, L[i] + L[j]) - i - 1, 0)

print(ans)
Buggy python submission (verdict: Runtime Error):
K = int(stdin.readline().rstrip())
ans_odd = 0
ans_even = 0
changed_odd = [False] * len(S)
changed_even = [False] * len(S)

if len(S) == 1:
    print(K // 2)
    exit()

for i in range(1, len(S)):
    if S[i] == S[i - 1] and not changed_odd[i - 1]:
        ans_odd += 1
        changed_odd[i] = True

if S[0] == S[len(S) - 1] and not changed_odd[len(S) - 1]:
    ans_odd += 1
    changed_even[0] = True

for i in range(1, len(S)):
    if S[i] == S[i - 1] and not changed_even[i - 1]:
        ans_even += 1
        changed_even[i] = True

if K % 2 == 0:
    print((ans_odd + ans_even) * (K // 2))
else:
    print((ans_odd + ans_even) * (K // 2) + ans_even)


Fixed submission:
from sys import stdin

S = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())
ans_odd = 0
ans_even = 0
changed_odd = [False] * len(S)
changed_even = [False] * len(S)

if len(S) == 1:
    print(K // 2)
    exit()

cnt = 1
ans = 0
begin = 0
end = 0

start = 0
for i in range(1, len(S)):
    if S[i - 1] != S[i]:
        if start == 0:
            begin += cnt
        else:
            if cnt >= 2:
                ans += cnt // 2
        cnt = 1
        start = i
    else:
        cnt += 1
    if i == len(S) - 1:
        if start == 0:
            print((cnt * K) // 2)
            exit()
        end += cnt
        break

if S[0] != S[-1]:
    print(ans * K + (begin // 2) * K + (end // 2) * K)
else:
    print(ans * K + begin // 2 + end // 2 + ((begin + end) // 2) * (K - 1))
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import fractions

A, B = [int(x) for x in stdin.readline().rstrip().split()]
gcd = fractions.gcd(A, B)

x = 2
ans = 1
g = 1

while gcd > 1:
    if gcd % x == 0:
        gcd //= x
        if g != x:
            ans += 1
        g = x
    else:
        x += 1

print(ans)


Fixed submission:
from sys import stdin
import fractions

A, B = [int(x) for x in stdin.readline().rstrip().split()]
gcd = fractions.gcd(A, B)
C = []
y = 1
while y ** 2 <= gcd:
    if gcd % y == 0:
        if y >= 2:
            C.append(y)
        if y ** 2 != gcd:
            C.append(gcd // y)
    y += 1

ans = 1
g = 1
C.sort()
for c in C:
    while gcd % c == 0:
        gcd //= c
        if g != c:
            ans += 1
        g = c

print(ans)

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

A, B = [int(x) for x in stdin.readline().rstrip().split()]
gcd = math.gcd(A, B)

x = 2
ans = 1
g = 1

while gcd > 1:
    if gcd % x == 0:
        gcd //= x
        if g != x:
            ans += 1
        g = x
    else:
        x += 1

print(ans)


Fixed submission:
from sys import stdin
import fractions

A, B = [int(x) for x in stdin.readline().rstrip().split()]
gcd = fractions.gcd(A, B)
C = []
y = 1
while y ** 2 <= gcd:
    if gcd % y == 0:
        if y >= 2:
            C.append(y)
        if y ** 2 != gcd:
            C.append(gcd // y)
    y += 1

ans = 1
g = 1
C.sort()
for c in C:
    while gcd % c == 0:
        gcd //= c
        if g != c:
            ans += 1
        g = c

print(ans)
Buggy python submission (verdict: Runtime Error):
from sys import stdin

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()
dp = [[0] * (N + 1) for _ in range(N + 1)]
res = 0

for i in range(N - 1, -1, -1):
    for j in range(N - 1, i, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1, dp[i][j]
        res = max(res, min(j - i, dp[i][j]))

print(res)


Fixed submission:
from sys import stdin

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()
dp = [[0] * (N + 1) for _ in range(N + 1)]
res = 0

for i in range(N - 1, -1, -1):
    for j in range(N - 1, i, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1
        res = max(res, min(j - i, dp[i][j]))

print(res)
Buggy python submission (verdict: Runtime Error):
N = int(stdin.readline().rstrip())
H = [int(x) for x in stdin.readline().rstrip().split()]
cnt = 0

if N == 1:
    print('Yes')
    exit()

if N == 2:
    if H[0] - H[1] > 1:
        print('No')
        exit()
    else:
        print('Yes')
        exit()

for i in range(1, N):
    if H[i - 1] - H[i] > 1:
        print('No')
        exit()
    elif H[i - 1] - H[i] == 1:
        if cnt > 0:
            print('No')
            exit()
        H[i] -= 1
        cnt += 1

print('Yes')


Fixed submission:
from sys import stdin, exit

N = int(stdin.readline().rstrip())
H = [int(x) for x in stdin.readline().rstrip().split()]
drop = 0

if N == 1:
    print('Yes')
    exit()

if N == 2:
    if H[0] - H[1] > 1:
        print('No')
        exit()
    else:
        print('Yes')
        exit()

for i in range(N - 2, -1, -1):
    if H[i] - H[i + 1] > 1:
        print('No')
        exit()
    if H[i] - H[i + 1] == 1:
        H[i] -= 1
print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

N = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]

ans = []
for k in reversed(range(1, N + 1)):
    if k == 1:
        if len(ans) % 2 != a[k - 1]:
            ans.append(k)
        continue
    t = N // k
    cnt = 0
    for i in range(1, t + 1):
        if i * k in ans:
            cnt += 1
    if cnt % 2 != a[k - 1]:
        ans.append(k)

x = len(ans)
print(x)
if x >= 0:
    print(*ans)


Fixed submission:
from sys import stdin

N = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]

ans = []
for k in reversed(range(1, N + 1)):
    if a[k - 1] == 1:
        ans.append(k)
        tmp = 1
        while tmp * tmp <= k:
            if k % tmp == 0:
                a[tmp - 1] ^= 1
                if tmp != k // tmp:
                    a[k // tmp - 1] ^= 1
            tmp += 1

x = len(ans)
print(x)
if x >= 0:
    print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

N = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]

ans = []
for k in reversed(range(1, N + 1)):
    t = N // k
    cnt = 0
    for i in range(1, t + 1):
        if i * k in ans:
            cnt += 1
    if cnt % 2 != a[k - 1]:
        ans.append(k)

x = len(ans)
print(x)
if x >= 0:
    print(*ans)


Fixed submission:
from sys import stdin

N = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]

ans = []
for k in reversed(range(1, N + 1)):
    if a[k - 1] == 1:
        ans.append(k)
        tmp = 1
        while tmp * tmp <= k:
            if k % tmp == 0:
                a[tmp - 1] ^= 1
                if tmp != k // tmp:
                    a[k // tmp - 1] ^= 1
            tmp += 1

x = len(ans)
print(x)
if x >= 0:
    print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import bisect

N = int(stdin.readline().rstrip())
A = [int(stdin.readline().rstrip()) for _ in range(N)]

colors = [10 ** 10]
for i in range(N):
    bi = bisect.bisect_left(colors, A[i])
    bir = bisect.bisect_right(colors, A[i])
    if bir == len(A):
        colors[len(A) - 1] = A[i]
    elif bi == 0:
        bisect.insort_left(colors, A[i])
    else:
        colors[bi - 1] = A[i]

print(len(colors) - 1)


Fixed submission:
from sys import stdin
import bisect
from collections import deque

N = int(stdin.readline().rstrip())
A = [int(stdin.readline().rstrip()) for _ in range(N)]

colors = deque([10 ** 10])
for i in range(N):
    bi = bisect.bisect_left(colors, A[i])
    bir = bisect.bisect_right(colors, A[i])
    if bir == len(A):
        colors[len(A) - 1] = A[i]
    elif bi == 0:
        colors.appendleft(A[i])
    else:
        colors[bi - 1] = A[i]

print(len(colors) - 1)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import math

A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]


def div(n, x, y):
    lcs = int(x * y / math.gcd(x, y))
    return n - int(n // x) - int(n // y) + int(n // lcs)


print(div(B, C, D) - div(A - 1, C, D))


Fixed submission:
from sys import stdin
import fractions

A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]


def div(n, x, y):
    lcs = int(x * y / fractions.gcd(x, y))
    return n - int(n // x) - int(n // y) + int(n // lcs)


print(div(B, C, D) - div(A - 1, C, D))
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin, exit

N = int(stdin.readline().rstrip())
work = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]

work.sort(key=lambda x: x[1])
time = 0
for k in range(N):
    if time + work[0][0] > work[0][1]:
        print('No')
        exit()
    time += work.pop(0)[0]
print('Yes')


Fixed submission:
from sys import stdin, exit

N = int(stdin.readline().rstrip())
work = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]

work.sort(key=lambda x: x[1])
time = 0
for k in range(N):
    if time + work[k][0] > work[k][1]:
        print('No')
        exit()
    time += work[k][0]
print('Yes')
Buggy python submission (verdict: Runtime Error):
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(stdin.readline().rstrip()) for _ in range(M)]
fib = [1, 1]
for k in range(N):
    fib.append((fib[-1] + fib[-2]) % 1000000007)
ans = fib[a[0] - 1]
for l in range(M - 1):
    if a[l + 1] - a[l] == 1:
        print(0)
        exit()
    ans = ans * fib[a[l + 1] - a[l] - 2]
ans = ans * fib[N - a[-1] - 1]
print(ans % 1000000007)


Fixed submission:
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(stdin.readline().rstrip()) for _ in range(M)]
fib = [1, 1]
for k in range(N):
    fib.append((fib[-1] + fib[-2]) % 1000000007)
if M == 0:
    print(fib[N])
    exit()
ans = fib[a[0] - 1]
for l in range(M - 1):
    if a[l + 1] - a[l] == 1:
        print(0)
        exit()
    ans = ans * fib[a[l + 1] - a[l] - 2]
ans = ans * fib[N - a[-1] - 1]
print(ans % 1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

L = stdin.readline().rstrip()
inf = 10 ** 9 + 7
ones = 3
if L[-1] == '0':
    ans = 1
else:
    ans = 3

if len(L) == 1:
    print(ans)
    exit()

for i in range(2, len(L) + 1):
    if L[-i] == '1':
        ans = (ones + 2 * ans) % inf
    ones *= 3

print(ans)


Fixed submission:
from sys import stdin

L = stdin.readline().rstrip()
inf = 10 ** 9 + 7
ones = 3
if L[-1] == '0':
    ans = 1
else:
    ans = 3

if len(L) == 1:
    print(ans)
    exit()

for i in range(2, len(L) + 1):
    if L[-i] == '1':
        ans = (ones + 2 * ans) % inf
    ones = (3 * ones) % inf

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
from collections import deque

N = int(stdin.readline().rstrip())
b = [int(x) for x in stdin.readline().rstrip().split()]
ans = deque([])

while N > 0:
    index = N - 1
    while index >= 0:
        if b[index] == index + 1:
            ans.appendleft(b[index])
            b1 = b[:index]
            b2 = b[index + 1:]
            b = b1 + b2
            N -= 1
            break
        index -= 1

print(*ans)


Fixed submission:
from sys import stdin, exit
from collections import deque

N = int(stdin.readline().rstrip())
b = [int(x) for x in stdin.readline().rstrip().split()]
ans = deque([])

while N > 0:
    index = N - 1
    while index >= 0:
        if b[index] == index + 1:
            ans.appendleft(b[index])
            b1 = b[:index]
            b2 = b[index + 1:]
            b = b1 + b2
            N -= 1
            break
        index -= 1
        if index == -1:
            print(-1)
            exit()

print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
from collections import deque

N = int(stdin.readline().rstrip())
b = [int(x) for x in stdin.readline().rstrip().split()]
ans = deque([])

while len(b) > 0:
    index = len(b) - 1
    while index >= 0:
        if b[index] == index + 1:
            c = b.pop(index)
            ans.appendleft(c)
            break
        index -= 1

print(*ans)


Fixed submission:
from sys import stdin, exit
from collections import deque

N = int(stdin.readline().rstrip())
b = [int(x) for x in stdin.readline().rstrip().split()]
ans = deque([])

while N > 0:
    index = N - 1
    while index >= 0:
        if b[index] == index + 1:
            ans.appendleft(b[index])
            b1 = b[:index]
            b2 = b[index + 1:]
            b = b1 + b2
            N -= 1
            break
        index -= 1
        if index == -1:
            print(-1)
            exit()

print(*ans)
Buggy python submission (verdict: Runtime Error):
N, A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
l = [int(stdin.readline().rstrip()) for _ in range(N)]


def solve(m, a, b, c):
    if m == N:
        if a == 0 or b == 0 or c == 0:
            return 10 ** 7
        else:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
    return min(solve(m + 1, a, b, c), solve(m + 1, a + l[m], b, c) + 10,
               solve(m + 1, a, b + l[m], c) + 10, solve(m + 1, a, b, c + l[m]) + 10)


print(solve(0, 0, 0, 0))

Fixed submission:
from sys import stdin

# ABC
# N = int(stdin.readline().rstrip())


def dfs(x):
    ret = 0
    if int(x) > N:
        return ret
    if '7' in x and '5' in x and '3' in x:
        ret += 1
    for k in '753':
        ret += dfs(x + k)
    return ret


# print(dfs('0'))

# ABC119 C - Synthetic Kadomatsu
N, A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
l = [int(stdin.readline().rstrip()) for _ in range(N)]


def solve(m, a, b, c):
    if m == N:
        if a == 0 or b == 0 or c == 0:
            return 10 ** 7
        else:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
    return min(solve(m + 1, a, b, c), solve(m + 1, a + l[m], b, c) + 10,
               solve(m + 1, a, b + l[m], c) + 10, solve(m + 1, a, b, c + l[m]) + 10)


print(solve(0, 0, 0, 0))
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import math
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
ans = A[0]
for k in range(N)[1:]:
    ans = math.gcd(ans, A[k])
print(ans)


Fixed submission:
from sys import stdin
import fractions
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
ans = A[0]
for k in range(N)[1:]:
    ans = fractions.gcd(ans, A[k])
print(ans)
Buggy python submission (verdict: Runtime Error):
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]


def to_bin(n):
    return bin(n)[2:]


if K == 0:
    ans = 0
    for a in A:
        ans += K ^ a
    print(ans)
    exit()

cnt = [0] * len(to_bin(K))
for a in A:
    b = to_bin(a)
    while len(b) < len(cnt):
        b = '0' + b
    b = b[::-1]
    for i in range(len(b)):
        if b[i] == '1':
            cnt[i] += 1

ans = 0
for j in range(len(cnt)):
    ans += max(cnt[j], N - cnt[j]) * (2 ** j)

print(ans)

Fixed submission:
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]


def to_bin(n):
    return bin(n)[2:]


cnt = [0] * 40
for a in A:
    b = to_bin(a)
    b = b[::-1]
    for i in range(len(b)):
        if b[i] == '1':
            cnt[i] += 1

ans = 0
cnt.reverse()
k_str = to_bin(K)
while len(k_str) < 40:
    k_str = '0' + k_str

for j in range(len(cnt)):
    if k_str[j] == '1':
        tmp_ans = 0
        for k in range(len(cnt)):
            power = 39 - k
            if k <= j - 1:
                if k_str[k] == '0':
                    tmp_ans += cnt[k] * (2 ** power)
                else:
                    tmp_ans += (N - cnt[k]) * (2 ** power)
            elif k == j:
                tmp_ans += cnt[k] * (2 ** power)
            else:
                tmp_ans += max(cnt[k], N - cnt[k]) * (2 ** power)
        ans = max(ans, tmp_ans)
tmp_ans = 0
for k in range(len(cnt)):
    power = 39 - k
    if k_str[k] == '0':
        tmp_ans += cnt[k] * (2 ** power)
    else:
        tmp_ans += (N - cnt[k]) * (2 ** power)
ans = max(ans, tmp_ans)
print(ans)