Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

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

data = []
input_data = input().split()
data = [int(n) for n in input_data]
data_exp = []
for d in data:
    data_exp.append(1 + (d-1)/2)

ans = 0
for i in range(0, n-k+1, 1):
    exp_val = 0
    for j in range(k):
        exp_val += data_exp[i+j]
    ans = max(ans, exp_val)

print(ans)




### FIXED CODE ###

import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

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

data = []
input_data = input().split()
data = [int(n) for n in input_data]

data_exp = [0]
for i in range(n):
    data_exp.append(data_exp[i] + 1 + (data[i]-1)/2)

ans = 0
for i in range(n-k+1):
    tmp_ans = data_exp[i+k] - data_exp[i]
    ans = max(ans, tmp_ans)

print(ans)
### BUGGY CODE ###

N=int(input())
sum=[0]*(N+3)
ans=0
for i in range(1,N+1):
  sum[i]=sum[i-1]+i
for i in range(1,N+1):
  tmpn=N//i
  tmpsum = sum[tmpn]
  ans+=tmpsum*i
print(ans)

### FIXED CODE ###

N=int(input())
sum=[0]*(N+3)
ans=0
for i in range(1,N+1):
  sum[i]=sum[i-1]+i
for i in range(1,N+1):
  tmpn=N//i
  tmpsum = sum[tmpn]
  ans+=tmpsum*i
print(ans)
### BUGGY CODE ###

n = int(input())
s = [input() for i in range(n)]
d ={}
for key in s:
    if key in d:
        d[key] += 1
    else:
        d[key] = 1

Max = max(d.values())
max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]
max_k_list.sort()
for i in max_k_list:
    print(i)

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]
d ={}
for key in s:
    if key in d:
        d[key] += 1
    else:
        d[key] = 1
Max = max(d.values())
max_k_list = [kv[0] for kv in d.items() if kv[1] == Max]
max_k_list.sort()
for i in max_k_list:
    print(i)
### BUGGY CODE ###

# coding: utf-8

import numpy as np

N, M = map(int, input().split())

AB = [list(map(int, input().split())) for __ in range(N)]
AB.sort(key=lambda x : x[0])

ans = 0
while M > 0:
    if AB[0][1] == 0:
        AB = AB[1:]

    ans += AB[0][0]
    M -= 1

    AB[0][1] -= 1

print(ans)


### FIXED CODE ###

# coding: utf-8

# import sys
# input = sys.stdin.readline

N, M = map(int, input().split())

AB = [list(map(int, input().split())) for __ in range(N)]
AB.sort(key=lambda x : x[0])

k = 0
ans = 0
while M > 0:
    if M > AB[k][1]:
        M -= AB[k][1]
        ans += AB[k][0] * AB[k][1]
    else:
        ans += AB[k][0] * M
        break
    
    k += 1

print(ans)
### BUGGY CODE ###

N = int(input())
S = input()


ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        if S[j] == S[i]:
            continue
        for k in range(j+1, N):
            if S[k] not in [S[i], S[j]] and j-i != k-j:
                ans += 1

print(ans)

### FIXED CODE ###

N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))

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


one = A.count(1)
two = A.count(2)
three = A.count(3)

for k in range(three + 1):
    for j in range(two + three + 1 - k):
        for i in range(one + two + three + 1 -k -j):
            if i == 0 and j == 0 and k == 0:
                continue
            ret = 0
            if i > 0:
                ret += dp[i - 1][j][k] * i
            if j > 0:
                ret += dp[i + 1][j - 1][k] * j 
            if k > 0:
                ret += dp[i][j + 1][k -1] * k

            ret += N
            ret *= 1.0 / (i + j + k)
            dp[i][j][k] = ret

print(dp[one][two][three])



### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, input().split()))

    dp = [[[0.0 for k in range(N + 1)]for j in range(N + 1)]for i in range(N + 1)]


    one = A.count(1)
    two = A.count(2)
    three = A.count(3)

    for k in range(three + 1):
        for j in range(two + three + 1 - k):
            for i in range(one + two + three + 1 -k -j):
                if i == 0 and j == 0 and k == 0:
                    continue
                ret = N * 1.0
                if i > 0:
                    ret += dp[i - 1][j][k] * i
                if j > 0:
                    ret += dp[i + 1][j - 1][k] * j 
                if k > 0:
                    ret += dp[i][j + 1][k -1] * k

                dp[i][j][k] = ret / (i + j + k)

    print(dp[one][two][three])

main()
### BUGGY CODE ###

from itertools import combinations

n = int(input())
lst = list(map(int, input().split()))

comb = combinations(lst, 2)
res = 0
for i in comb:
  res += i[0] * i[1]
print(res % ((10**9)+7))

### FIXED CODE ###

n = int(input())
lst = list(map(int, input().split()))

ans = 0
summ = sum(lst)
summ_sq = summ**2
for i in range(n):
    ans += lst[i]**2

res = (summ_sq-ans)//2
print(res % ((10**9)+7))
### BUGGY CODE ###

import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)


n, m = map(int, input().split())
A = list(map(int, input().split()))


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


total = Counter()
two_count = None
for a in A:
    primes = Counter(prime_factorize(a))
    if not two_count:
        two_count = primes[2]
    elif two_count != primes[2]:
        print(0)
        exit()

    for k, v in primes.items():
        total[k] = max(total[k], primes[k])

ans = 1
for k, v in total.items():
    ans *= pow(k, v)
# print(ans)

print((m - ans//2)//ans + 1)


### FIXED CODE ###

import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
# import math
from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)


n, m = map(int, input().split())
A = list(map(int, input().split()))


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


def lcm_list(numbers):
    x = 1
    for i in range(n):
        x = lcm_base(x, numbers[i])
        if x > 2*m:
            print(0)
            exit()

    return x


def count_two(x):
    count = 0
    while x%2 == 0:
        count += 1
        x //= 2
    return count


two_count = count_two(A[0])
for a in A[1:]:
    if two_count != count_two(a):
        print(0)
        exit()

LCM = lcm_list(A)
# print(LCM)
print((m - LCM//2)//LCM + 1)
### BUGGY CODE ###

n,m = map(int,input().split())
ans = 0
flag = True
tmp = int(m/n)
for i in range(1,tmp+1):
    if m%i == 0:
        if ans < i:
            ans = i
print(ans)

### FIXED CODE ###

import numpy as np

n,m = map(int,input().split())
ans = 0
tmp = int(m/n)
for i in range(1,int(np.sqrt(m)+1)):
    if m%i == 0:
        if (ans < i) and(i <= tmp):
            ans = i
        tmp2 = m//i
        if (ans < tmp2) and(tmp2 <= tmp):
            ans = tmp2
print(ans)
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    s = input()
    q = int(input())
    reverse = False
    
    for _ in range(q):
        query = list(input().split())
        if query[0] == '1':
            if reverse:
                reverse = False
            else:
                reverse = True
        else:
            if reverse:
                if query[1] == '1':
                    s = s + query[2]
                else:
                    s = query[2] + s
            else:
                if query[1] == '1':
                    s = query[2] + s
                else:
                    s = s + query[2]
    
    if reverse:
        print(s[::-1])
    else:
        print(s)
        
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()

def main():
    s = deque(input())
    q = int(input())
    reverse = False
    
    for _ in range(q):
        query = list(input().split())
        if query[0] == '1':
            reverse ^= True
        else:
            if reverse:
                if query[1] == '1':
                    s.append(query[2])
                else:
                    s.appendleft(query[2])
            else:
                if query[1] == '1':
                    s.appendleft(query[2])
                else:
                    s.append(query[2])
                    
    s = ''.join(s)
    if reverse:
        s = s[::-1]
    print(s)
        
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n,k = map(int, input().split())
a = list(map(int, input().split()))

root = [1]

for i in range(n):
    t = a[root[i] - 1]
    root.append(t)
    if (t in root[:-1]):
        break
x =  root.index(root[-1])
bef = root[0:x]
#print(bef)
loop = root[x:-1]
#print(loop)
#print(root)

if (k < len(bef)):
    print(bef[k])
else:
    p = ((k - len(bef)) % len(loop))
    #print(p)
    print(loop[p])

### FIXED CODE ###

n,k = map(int, input().split())
a = list(map(int, input().split()))

root = [1]

for i in range(n):
    t = a[root[i]-1]
    if (t == 0):
        break
    a[root[i]-1] = 0
    root.append(t)
x =  root.index(root[-1])
bef = root[0:x]
#print(bef)
loop = root[x:-1]
#print(loop)
#print(root)

if (k < len(bef)):
    print(bef[k])
else:
    p = ((k - len(bef)) % len(loop))
    #print(p)
    print(loop[p])
### BUGGY CODE ###

LIMIT = 10000000
 
isPrime = [True for _ in range(LIMIT)]

isPrime[0] = isPrime[1] = False
 
for i in range(2, int(LIMIT ** 0.5)+1):
  if isPrime[i]:
    for j in range(i * i, LIMIT, i):
      isPrime[j] = False
 
try:
    while True:
        n = int(input())
        count = 0
        for i in range(n+1):
            if isPrime[i]:
                count += 1
        print(count)
except EOFError:
  pass

### FIXED CODE ###

import sys
ifprime = [1]*(1000000)
ifprime[0] = ifprime[1] = 0
a = 2
while a < 1000000:
  if ifprime[a]:
    b = a*a
    while b < 1000000:
      ifprime[b] = 0
      b += a
  a += 1
for n in sys.stdin:
  print sum(ifprime[:int(n)+1])
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
Query = [list(input().split()) for i in range(Q)]


# 番兵を設置
S = 'x' + S + 'x'

# 左から何番目のゴーレムまで消えるか二分探索
ok, ng = 0, N + 1
while abs(ok - ng) > 1:
    m = (ok + ng) // 2
    x = (ok + ng) // 2

    for t, d in Query:
        if S[x] != t:
            continue

        if d == 'R':
            x += 1
        if d == 'L':
            x -= 1

        if x == 0:
            ok = m
            break
    else:
        ng = m
Left_ans = ok

# 右から何番目のゴーレムまで消えるか二分探索
ok, ng = N + 1, 0
while abs(ok - ng) > 1:
    m = (ok + ng) // 2
    x = (ok + ng) // 2

    for t, d in Query:
        if S[x] != t:
            continue

        if d == 'R':
            x += 1
        if d == 'L':
            x -= 1

        if x == N + 1:
            ok = m
            break
    else:
        ng = m
Right_ans = ok

print(N - min(N, Left_ans + (N + 1 - Right_ans)))


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
Query = [list(input().split()) for i in range(Q)]


# 番兵を設置
S = 'x' + S + 'x'

# 左から何番目のゴーレムまで消えるか二分探索
ok, ng = 0, N + 1
while abs(ok - ng) > 1:
    m = (ok + ng) // 2
    x = (ok + ng) // 2

    for t, d in Query:
        if S[x] != t:
            continue

        if d == 'R':
            x += 1
        if d == 'L':
            x -= 1

        if x == 0:
            ok = m
            break
    else:
        ng = m
Left_ans = ok

# 右から何番目のゴーレムまで消えるか二分探索
ok, ng = N + 1, 0
while abs(ok - ng) > 1:
    m = (ok + ng) // 2
    x = (ok + ng) // 2

    for t, d in Query:
        if S[x] != t:
            continue

        if d == 'R':
            x += 1
        if d == 'L':
            x -= 1

        if x == N + 1:
            ok = m
            break
    else:
        ng = m
Right_ans = ok

print(N - min(N, Left_ans + (N + 1 - Right_ans)))
### BUGGY CODE ###


def main():
    h, w = map(int, input().split())
    s = [list(input()) for i in range(h)]

    white, black = [], []
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                black.append([i, j])
            else:
                white.append([i, j])

    ans = 0
    for bx, by in black:
        for wx, wy in white:

            queue = [[bx, by]]
            visited = [[False for i in range(w + 1)] for j in range(h+1)]
            while len(queue) != 0:
                p = queue.pop(0)
                visited[p[0]][p[1]] = True
                if p[0] == wx and p[1] == wy:
                    ans += 1
                    break
                for x, y in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
                    nx = p[0] + x
                    ny = p[1] + y
                    if nx < 0 or ny < 0 or nx >= h or ny >= w or visited[nx][ny] == True:
                        continue
                    #print(nx, ny, s)
                    if (((nx+ny) % 2) == ((bx+by) % 2) and s[nx][ny] == ".") or (((nx+ny) % 2) != ((bx+by) % 2) and s[nx][ny] == "#"):
                        continue
                    queue.append([nx, ny])

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    
    h, w = map(int, input().split())
    s = [list(input()) for i in range(h)]
    start = []
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#": 
                start.append([i,j])

    ans = [0,0]
    vis = [[-1 for i in range(w)] for j in range(h)]
    def f(x, y, pre):
        vis[x][y] = 1
        if s[x][y] == "#":
            ans[0] += 1
        else:
            ans[1] +=1
        for i, j in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
            nx = i + x
            ny = j + y
            if nx >= 0 and ny >= 0 and nx < h and ny < w and vis[nx][ny] == -1:
                if pre == "B" and s[nx][ny] == ".":
                    f(nx,ny,"W")
                elif pre == "W" and s[nx][ny] == "#":
                    f(nx, ny, "B")
                
    
    ret = 0
    for i, j in start:
        if vis[i][j] == -1:
            f(i, j, "B")
        ret += ans[0] * ans[1]
        ans[0] = ans[1] = 0
    print(ret)
        

if __name__ == '__main__':
    main()
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    b.append(a[i])
    b = b[::-1]
print(*b)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
if len(a)%2 == 0:
    b = a[::-2]+a[::2]
else:
    b = a[::-2]+a[1::2]
    
print(*b)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 9)

N = int(input())
E = [tuple(map(int,input().split())) for _ in range(N-1)]
#print(E)
V = [set() for _ in range(N+1)]
for a,b in E:
  V[a].add(b)
  V[b].add(a)
#print(V)
maxc = 0
for v in V:
  maxc = max(maxc,len(v))
#print(maxc)
CE = {}
for e in E:
  CE[e] = 0
#print(CE)

def dfs(u,t,c):
  CU = set()
  if t > 0:
    CE[(min(u,t),max(u,t))] = c
    CU.add(c)
  for v in V[u]:
    if CE[(min(u,v),max(u,v))] != 0:
      CU.add(CE[(min(u,v),max(u,v))])
  CC = set(range(1,maxc+1))-CU
  for v in V[u]:
    if CE[(min(u,v),max(u,v))] == 0:
      dfs(v,u,CC.pop())

dfs(1,0,1)
print(maxc)
for e in E:
  print(CE[e])


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 9)

N = int(input())
E = [tuple(map(int,input().split())) for _ in range(N-1)]
#print(E)
V = [set() for _ in range(N+1)]
for a,b in E:
  V[a].add(b)
  V[b].add(a)
#print(V)
maxc = 0
for v in V:
  maxc = max(maxc,len(v))
#print(maxc)
CE = {}
for e in E:
  CE[e] = 0
#print(CE)

def dfs(u,t,c):
  if t > 0:
    CE[(min(u,t),max(u,t))] = c
  cc = c+1
  if cc > maxc:
    cc = 1
  for v in V[u]:
    if CE[(min(u,v),max(u,v))] == 0:
      dfs(v,u,cc)
      cc += 1
      if cc > maxc:
        cc = 1

dfs(1,0,1)
print(maxc)
for e in E:
  print(CE[e])
### BUGGY CODE ###

N = int(input())
arr = [list(map(int,input().split())) for i in range(N)]
arr = sorted(arr, key=lambda x: x[0])
F = [True]*N
P = [0]*N
for i in range(N):
  P[i] = [arr[i][0]-arr[i][1], arr[i][0]+arr[i][1]]
for i in range(N):
  for j in range(i+1,N):
    if F[i]:
      if P[i][1] > P[j][0]:
        F[j] = False
      elif P[i][1] <= P[j][0]:
        break
print(F.count(True))


### FIXED CODE ###

N = int(input())
arr = [list(map(int,input().split())) for i in range(N)]
arr = sorted(arr, key=lambda x: x[0])
F = [True]*N
P = [0]*N
for i in range(N):
  P[i] = [arr[i][0]-arr[i][1], arr[i][0]+arr[i][1]]
P = sorted(P,key=lambda x:x[1])
ind = 0
for i in range(1,N):
  if P[i][0] < P[ind][1]:
    F[i] = False
  else:
    ind = i
print(F.count(True))
### BUGGY CODE ###

s = input()
n = int(input())
c = 0
for _ in range(n):
  lst = [i for i in input().split()]
  if lst[0] == '1':
    if c == 1:
      s, tmp = tmp, s
      #print(s)
      #print(tmp)
    else:
      tmp = s
      s = s[::-1]
      c = 1
      #print(s)
      #print(tmp)
  elif lst[0] == '2':
    c = 0
    if lst[1] == '1':
      s = lst[2] + s
    elif lst[1] == '2':
      s = s + lst[2]
print(s)

### FIXED CODE ###

s = input()
n = int(input())
c = 0
left_l = ['', '']
right_l = ['', '']
s_l = [s, s[::-1]]
for _ in range(n):
  lst = [i for i in input().split()]
  if lst[0] == '1':
    if c == 1:
      s_l[0], s_l[1] = s_l[1], s_l[0]
      #print(s)
    else:
      s_l = [right_l[1] + s_l[1] + left_l[1], left_l[0] + s_l[0] + right_l[0]]
      left_l[0], left_l[1] = '', ''
      right_l[0], right_l[1] = '', ''
      c = 1
      #print(s)
  elif lst[0] == '2':
    c = 0
    if lst[1] == '1':
      left_l[0] = lst[2] + left_l[0]
      left_l[1] = left_l[1] + lst[2]
    elif lst[1] == '2':
      right_l[0] = right_l[0] + lst[2]
      right_l[1] = lst[2] + right_l[1]
w = left_l[0] + s_l[0] + right_l[0]
print(w)
### BUGGY CODE ###

def main():
	n, k = map(int, input().split())
	*a, = map(int, input().split())
	*f, = map(int, input().split())
	a.sort()
	f.sort(reverse=1)
	prod = [(y, x * y) for x, y in zip(a, f)]
	l = -1
	r = 10 ** 12
	while r - l > 1:
		m = (l + r) // 2
		s = sum(max(0, 0 - (m - p) // y) for y, p in prod)
		if s <= k:
			r = m
		else:
			l = m
	print(r)


if __name__ == "__main__":
	main()

### FIXED CODE ###

def main():
	n, k = map(int, input().split())
	*a, = map(int, input().split())
	*f, = map(int, input().split())
	a.sort()
	f.sort(reverse=1)
	prod = [(y, x * y) for x, y in zip(a, f)]
	l = -1
	r = 10 ** 12
	while r - l > 1:
		m = (l + r) // 2
		s = sum(max(0, 0 - (m - p) // y) for y, p in prod)
		if s <= k:
			r = m
		else:
			l = m
	print(r)


if __name__ == "__main__":
	main()
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
 
ans = []
for i in range(n):
  if i%2 ==0:
    ans.append(a[i])
  else:
    ans.insert(0,a[i])
 
print(str(ans).replace("[","").replace("]","").replace(",","") if n%2 ==0 else str(ans[::-1]).replace("[","").replace("]","").replace(",","") )

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))

ans=[0]*n
for i in range(n):
  if i%2 ==0:
    ans[n//2+i//2]=a[i]
  else:
    ans[n//2-i//2-1]=a[i]

print(str(ans).replace("[","").replace("]","").replace(",","") if n%2 ==0 else str(ans[::-1]).replace("[","").replace("]","").replace(",","") )
### BUGGY CODE ###

S = input()
Q = int(input())
flag_reversed = False
ret = S
front_ones = []
back_ones = []
for _ in range(Q):
    temp = input()
    if (len(temp) == 1):
        flag_reversed = not flag_reversed
    else:
        T, F, C = [x for x in temp.split(" ")]
        F = int(F)
        add_begin = True
        if (F == 2):
            add_begin = False
        if (flag_reversed):
            add_begin = not add_begin
        if (add_begin):
            front_ones.insert(0, C)
        else:
            back_ones.append(C)

ret = ''.join(front_ones) + ret + ''.join(back_ones)

if (flag_reversed):
    ret = ''.join(reversed(ret))
print(ret)



### FIXED CODE ###

from collections import deque

S = input()
Q = int(input())
flag_reversed = False
ret = deque(S)

for _ in range(Q):
    temp = input()
    if (len(temp) < 2):
        flag_reversed = not flag_reversed
    else:
        T, F, C = [x for x in temp.split(" ")]
        F = int(F)
        add_begin = True
        if (F == 2):
            add_begin = False
        if (flag_reversed):
            add_begin = not add_begin
        if (add_begin):
            ret.appendleft(C)
        else:
            ret.append(C)

ret = ''.join(ret)

if (flag_reversed):
    ret = ''.join(reversed(ret))
print(ret)
### BUGGY CODE ###

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 CODE ###

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