Harryxun/stf_run huggingface dataset:
N, K = map(int, input().split())

S = input()

b = 0
p1 = 0
p2 = 0
for i in range(N):
    if i == 0:
        if S[i] == S[i+1]:
            b += 1
        if S[i] == "L":
            p1 += 1
        else:
            if S[i] == "R" and S[i+1] == "L":
                p2 += 1
    elif 0 < i < N-1:
        if S[i] == S[i+1]:
            b += 1
        if S[i] == "R" and S[i+1] == "L":
            p2 += 1
    elif i == N-1:
        if S[i] == "R":
            p1 += 1

#print(b)
if K <= p2:
    b += 2*K
else:
    b += 2*K
    K -= p2
    b += max(p1, K)

print(min(N-1,b))

### FIXED CODE ###


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

ans = 0
for x,y in zip(S, S[1:]):
    if x == y: #同じ方向を見ているとき
        ans += 1
#最大K回まで操作をして、そのたびに幸福な人が二人増える。全員同じ方向を向くとN-1
ans = N-1 if ans+2*K >= N-1 else ans+2*K
print(ans)
while True:
    N = int(input())
    if N==0:break
    dataset = input()
    mens = ["" for _ in range(N)]
    i = 0
    p = ""
    while dataset:
        if i == N: i = 0
        card, dataset = dataset[0], dataset[1:]
        if card == "M":
            mens[i] += card
        elif card == "S":
            p += card + mens[i]
            mens[i] = ""
        else:
            mens[i] += card + p
            p = ""
        i += 1
    print(*[v for v in sorted(len(m) for m in mens)], len(p))

### FIXED CODE ###

while True:
    N = int(input())
    if N==0:break
    dataset = input()
    mens = ["" for _ in range(N)]
    i = 0
    p = ""
    while dataset:
        if i == N: i = 0
        card, dataset = dataset[0], dataset[1:]
        if card == "M":
            mens[i] += card
        elif card == "S":
            p += card + mens[i]
            mens[i] = ""
        else:
            mens[i] += card + p
            p = ""
        i += 1
    print(' '.join(map(str, sorted([len(m) for m in mens]))), len(p))
# coding: utf-8

n = int(input())
words = {}
ans = 0

for i in range(n):
  t = ''.join(sorted(input()))
  if t in words:
    ans += words[t]
    words[t] += 1
  else:
    words[t] += 1
    
print(ans)

### FIXED CODE ###

# coding: utf-8

n = int(input())
words = {}
ans = 0

for i in range(n):
  t = ''.join(sorted(input()))
  if t in words:
    ans += words[t]
    words[t] += 1
  else:
    words[t] = 1
    
print(ans)
L, R = map(int, input().split())
import numpy as np
LL = L%2019
RR = R%2019
min = 2019


for i in range(LL, RR+1):
    for j in range(i+1, RR+1):
        if (i*j)%2019 < min:
            min= (i*j)%2019

        if (i*j)%2019 == 0:
            min = 0
            break
    else:
        continue
    break
        

print(min)

### FIXED CODE ###

import sys
import fractions
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

a,b,c = MAP()
print(min(a*b,c))
def make(x):
    x = bin(x)[2:]
    while len(x) < len(S) - 1:
        x = "0" + x
    return list(x)

S = input()
a = pow(2, len(S) - 1)
b = []

for i in range(0, a):
    b.append(make(i))

i = 0
j = 0
key = int(S[0])
snum = 1
ans = 0
for i in b:
    snum = 1
    key = int(S[0])
    for j in i:
        if j == "0":
            key *= 10
            key += int(S[snum])
        elif j == "1":
            ans += key
            key = int(S[snum])
        #print(i, j, key)
        snum += 1
    ans += key
print(ans)


### FIXED CODE ###

def make(x):
    x = bin(x)[2:]
    while len(x) < len(S) - 1:
        x = "0" + x
    return list(x)

S = input()
a = pow(2, len(S) - 1)
b = []

for i in range(0, a):
    b.append(make(i))

i = 0
j = 0
key = int(S[0])
snum = 1
ans = 0
if len(S) != 1:
    for i in b:
        snum = 1
        key = int(S[0])
        for j in i:
            if j == "0":
                key *= 10
                key += int(S[snum])
            elif j == "1":
                ans += key
                key = int(S[snum])
            #print(i, j, key)
            snum += 1
        ans += key
    print(ans)
else:
    print(S)
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

ans=0
for i in range(N):
  ans+=B[A[i]]
  if(i>=1):
    if(A[i]==A[i-1]+1):
      ans+=C[i-1]
      
print(ans)
  

### FIXED CODE ###

import math

def resolve():
    N=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    C=list(map(int,input().split()))


    ans=0
    for i in range(N):
        ans+=B[A[i]-1]
        if(i>=1):
            if(A[i]==A[i-1]+1):
                ans+=C[A[i-1]-1]
        
    print(ans)
  

resolve()
#ABC116D-VariousSushi.py

from sys import stdin
from numpy import sum

input = stdin.readline

N, K = [int(n) for n in input().split()]
INPUT = [[None for i in range(2)] for j in range(N)]
List1, List2 = [], []
kind1 = []
flag1 = 0

for i in range(N):
    INPUT[i][0], INPUT[i][1] = [int(m) for m in input().split()]

INPUT = sorted(INPUT, key = lambda x: x[1], reverse=True)

for i in range(N):
    if INPUT[i][0] not in kind1:
            List1.append([INPUT[i][1], 1])
            kind1.append(INPUT[i][0])
    else: List1.append([INPUT[i][1], 0])

List2 = List1[K:]
if List2 != []:
    List2.sort(key =lambda x : (x[1],x[0]))
    del List1[K:]
    lenList2 = len(List2)
else: lenList2 = 0

List1 = sorted(List1, key = lambda x : (x[1], x[0]), reverse=True)

sum = sum(List1, axis = 0)

Score = sum[0] + sum[1]**2
Test = Score
kindnumber = sum[1]

for i in range(lenList2):
    if List2[-1][1] == 0 or List1[-1] == 1:
        break
    Test = Test - List1.pop()[0] + List2.pop()[0] + 2 * kindnumber + 1
    kindnumber = kindnumber + 1
    if Test >= Score:
        Score = Test
    i = i - 1

print(int(Score))


### FIXED CODE ###

#ABC116D-VariousSushi.py

from sys import stdin
#from numpy import sum

input = stdin.readline

N, K = list(map(int, input().split()))
List1= []
kind = set()
point1, point2 = 0, 0

INPUT = [tuple(map(int, input().split())) for _ in range(N)]

INPUT.sort(key = lambda x: -x[1])

for ti, di in INPUT[:K]:
    point1 += di
    if ti in kind:
        List1.append(di)
    kind.add(ti)

point2 = len(kind)

Score = point1 + point2**2
Test = Score

List1POP = List1.pop

for ti, di in INPUT[K:]:
    if 0 >= len(List1):
        break
    if ti in kind:
        continue
    Test = Test - List1POP() + di + 2 * point2 + 1
    point2 += 1
    kind.add(ti)
    Score = max(Score, Test)

print(Score)
n,q=map(int, input().split())
S=input()
lr=[list(map(int, input().split())) for _ in range(q)]
t=[0]*(n+1)
for i in range(n):
    #i桁目までに登場するACを計算する
    t[i+1]=t[i]+(1 if s[i:i+2] == "AC" else 0)
for i in range(q):
    l,r=lr[i][0]-1,lr[i][1]-1
    print(t[r-1]-t[l-1])

### FIXED CODE ###

n,q=map(int, input().split())
S=input()
lr=[list(map(int, input().split())) for _ in range(q)]
t=[0]*(n+1)
for i in range(n):
    #i桁目までに登場するACを計算する
    t[i+1]=t[i]+(1 if S[i:i+2] == "AC" else 0)
for i in range(q):
    l,r=lr[i][0]-1,lr[i][1]-1
    print(t[r]-t[l])
N,K = map(int, input().split())
A = list(map(int, input().split()))
print((N-1+K-1-1)//(K-1))

### FIXED CODE ###

S=input()
print(S.count("+")-S.count("-"))
from sys import stdin
input = stdin.readline

X, K, D = map(int, input().split())

m = X % D
l = X // D

if l > K:
    print(abs(abs(X) - D * K))
    exit(1)
else:
    if (K - l) % 2 == 0:
        print(m)
    else:
        print(D - m)


### FIXED CODE ###

from sys import stdin
input = stdin.readline

X, K, D = map(int, input().split())

X = abs(X)

m = X % D
l = X // D

if l > K:
    print(abs(X) - D * K)
else:
    if (K - l) % 2 == 0:
        print(m)
    else:
        print(D - m)
N,D=map(int,input().split())
cnt=0
for idx in range(N):
  X,Y=map(int,input().split())
  if X**2+Y**2<=D**2:
    cnt=cnt+1
print(cnt)


### FIXED CODE ###

X = int(input())
if X >= 30:
  print('Yes')
else:
  print('No')
n=int(input())
a=list(map(int,input().split()))
a.sort()
f=[1]*(2*10**5+10)
from collections import Counter
c=Counter(a)
ans=0
for ai in a:
  if c[ai]==1 and f[ai]==1:ans+=1
  for i in range(ai,2*10**5,ai):
    f[i]=0
print(ans)



### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a.sort()
from collections import Counter
c=Counter(a)
f=[1]*(10**6+1)
ans=0
for ai in a:  
  if c[ai]==1 and f[ai]==1:ans+=1
  if f[ai]==1:
    for i in range(ai,10**6+1,ai):
      f[i]=0
print(ans)
N = int(input())
A = list(map(int,input().split()))
r = ""
for i in range(N):
  r+= str(A.index(i+1)+1)
  r+= " "
print(r)


### FIXED CODE ###

N = int(input())
print( 1 - int(N/2) / N )
while True:

### FIXED CODE ###

import sys
def N(n):
    return (n+1)*(n+2)*(n+3)/6
for n in sys.stdin:
    n = int(n)
    if n > 2000:
        n = 4000 - n
    if n < 1001:
        print N(n)
    else:
        m = n - 1000
        print N(n) - (N(2*m) - m - 1)/2
a=int(input())
b=int(input())
print a*b ,a*2+b*2

### FIXED CODE ###

h,w=map(int,raw_input().split())
print("%d %d"%(h*w,h*2+w*2))
a = input()
b = input()

q = a/b
r = a%b
q_f = float(a)/float(b)

print q,r, q_f

### FIXED CODE ###

a,b = map(float, raw_input().split())

if b > 10**6:
  f = 0.0
else:
  f = a/b

d = int(a/b)
r = int(a%b)


print d, r, f
a=int(input())
b=list(map(int, input().split()))
print(max(a)-min(b))

### FIXED CODE ###

a=int(input())
b=list(map(int, input().split()))
print(max(b)-min(b))
N,X = map(int,input().split())
L = list(map(int,input().split()))
D = 0
i = 0
count = 0
while D<=X:
    count += 1
    D += L[i]
    i += 1
print(count)


### FIXED CODE ###

N,X = map(int,input().split())
L = list(map(int,input().split()))

pos = 0
cnt = 1

for l in L:
    pos += l
    if pos <= X:
        cnt += 1
    else:
        break
print(cnt)
N=int(input())
b=[]
L=[]
b=input().split()
M=[]
for i in range(N):
    L.append(int(b[i]))
L.sort()
L.reverse()
#print(L)
x=0
y=0
p=0
index=0
for i in range(N-2):
    x=L.pop(0)
    for j in range(N-2-i):
        y=L.pop(0)
        for k in range(N-2-i-j):
#            print('i,j,k :'+str(i)+str(j)+str(k)+':'+str(x)+str(y)+str(L[k]))
            if x<y+L[k]:
                index+=1
            else:
                break
        M.append(y)
    L=M+L
    M.clear()
print(index)


### FIXED CODE ###

A,B = map(int,input().split())
if A>=B*2:
    print(A-B*2)
else:
    print(0)
n = int(input())

ans = 0
for j in range(1,n+1):
  	count = 1
	for i in range(n//2):
    	if n % i == 0:
      		count += 1
        if count >= 8:
          ans +=1
print(ans)

            

### FIXED CODE ###

n = int(input())
a = n//2
ans = 0
for j in range(1,n+1):
    count = 0
    for i in range(1,j+1):
        if j % i == 0:
            count += 1
        if count >= 8 and j % 2 == 1:
            ans +=1
print(ans)
import itertools
n, m = map(int, input().split())
path = [[False] * n for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    path[b][a] = True
ans = 0
for i itertools.permutations(range(n), n):
    if i[0] == 0:
        for j in range(n):
            if j == n - 1:
                ans += 1
                break
            if not path[i[j]][i[j+1]]:
                break
print(ans)


### FIXED CODE ###

import itertools
n, m = map(int, input().split())
path = [[False] * n for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    path[b][a] = True
ans = 0
for i in itertools.permutations(range(n), n):
    if i[0] == 0:
        for j in range(n):
            if j == n - 1:
                ans += 1
                break
            if not path[i[j]][i[j+1]]:
                break
print(ans)
def solve():
    A, B, C, D = list(map(int, input().split()))
    ans = min(B,D) - max(A,C)
    if ans < 0:
        ans = 0
    print(ans)
    
solve()

### FIXED CODE ###

N = input()

if N[0] == N[2]:
    print('Yes')
else:
    print('No')
from collections import defaultdict
n,m,s,t=map(int, input().split())
s-=1
t-=1
yen={}
snk={}
adj=defaultdict(list)
for _ in range(m):
    u,v,a,b=map(int, input().split())
    u-=1    
    v-=1    
    adj[u].append(v)
    adj[v].append(u)
    yen[(u,v)]=a
    yen[(v,u)]=a
    snk[(u,v)]=b
    snk[(v,u)]=b

d=[float('inf')]*n
d[s]=0
prev={}
q=list(range(n))
while q!=[]:
    md=float('inf')    
    for qi in q:
        md=min(md,d[qi])
    u=q.pop(q.index(d.index(md)))
    for v in adj[u]:
        if d[v]>d[u]+yen[(u,v)]:
            d[v]=d[u]+yen[(u,v)]
            prev[v]=u
# tr=t
# while tr!=s:
#     print(tr,'->')
#     tr=prev[tr]
# print(s)
dr=[float('inf')]*n
dr[t]=0
prevr={}
qr=list(range(n))
while qr!=[]:
    md=float('inf')    
    for qi in qr:
        md=min(md,dr[qi])
    u=qr.pop(qr.index(dr.index(md)))
    for v in adj[u]:
        if dr[v]>dr[u]+snk[(u,v)]:
            dr[v]=dr[u]+snk[(u,v)]
            prevr[v]=u
while d!=[]:
    ans=float('inf')
    for y,s in zip(d,dr):
        ans=min(ans, y+s)
        if ans==y+s:
            ai=d.index(y)
    print(10**15-ans)
    del d[0]
    del dr[0]


### FIXED CODE ###

from collections import defaultdict
import heapq
n,m,s,t=map(int, input().split())
s-=1
t-=1
yen={}
snk={}
adj=defaultdict(list)
for _ in range(m):
    u,v,a,b=map(int, input().split())
    u-=1    
    v-=1    
    adj[u].append(v)
    adj[v].append(u)
    yen[(u,v)]=a
    yen[(v,u)]=a
    snk[(u,v)]=b
    snk[(v,u)]=b

def dijkstra(s, t, cost):
    q=[]
    d=[float('inf')]*n
    d[s]=0
    heapq.heappush(q, (d[s], s))
    prev={}
    while q!=[]:
        du, u=heapq.heappop(q)
        for v in adj[u]:
            if d[v]>du+cost[(u,v)]:
                d[v]=du+cost[(u,v)]
                prev[v]=u
                
                heapq.heappush(q, (d[v], v))
    return d

d1=dijkstra(s, t, yen)
d2=dijkstra(t, s, snk)
snuke=[]
for d1i, d2i in zip(d1,d2):
    snuke.append(d1i+d2i)
ans=[]
mins=float('inf')
for si in reversed(snuke):
    if si<mins:
        ans.append(si)
        mins=si
    else:
        ans.append(mins)
ans.reverse()
for ai in ans:
    print(10**15-ai)
a, b = int(input().split())
item = list()
item.append(a+b)
item.append(a-b)
item.append(a*b)
print(max(item))

### FIXED CODE ###

a, b = map(int, input().split())
item = list()
item.append(a+b)
item.append(a-b)
item.append(a*b)
print(max(item))
a = int(input())
b = int(input())
c = a*b
 
 
if c % 2==0:
  print("even")
elif c % 2==1:
  print("odd")
  

### FIXED CODE ###

a,b=map(int,input().split())
if (a*b) % 2:
  print("Odd")
else:
  print("Even")
import math
A, B = map(int, input()split())
print(math.floor(A*B))

### FIXED CODE ###

from decimal import Decimal
import math
A, B = input().split()
A = Decimal(A)
B = Decimal(B)
ans = A*B
print(math.floor(ans))
X = input()
ans = []
for x in X:
    if x == "S":
        ans.append(x)
        else:
            if len(ans) != 0:
                if ans [-1] == "S":
                    ans.pop()
                else:
                    ans.append(x)
            else:
                ans.append(x)
print(len(ans)) 




### FIXED CODE ###


X = str(input())
ans = []
for x in X:
    if x == 'S':
        ans.append(x)
    else:
        if len(ans) != 0:
            if ans[-1] == 'S':
                ans.pop()
            else:
                ans.append(x)
        else:
            ans.append(x)
print(len(ans))
A, B, h, m = map(int, input().split())

inport math

c = abs(h * 30 - m * 6 + m * 0.5)

print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(c))))

### FIXED CODE ###

import math

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

c = abs(h * 30 - m * 6 + m * 0.5)

print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(c))))
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
rep = sorted([tuple(map(int, input().split())) for i in range(m)], key= lambda x: -x[1])
rep_n = min(n, sum(ri[0] for ri in rep))
i = 0
for b, c in rep:
    for _ in range(b):
        if a[i] < c:
            a[i] = c
            i += 1
        if i >= n:
            break
print(sum(a))

### FIXED CODE ###

n, m = map(int, input().split())
cards = sorted(list(map(int, input().split())))
ope = [list(map(int, input().split())) for i in range(m)]
ope.sort(key=lambda x: x[1], reverse=True)
i, j, k = 0, 0, 0
while i < n and j < m and cards[i] < ope[j][1]:
    cards[i] = ope[j][1]
    i += 1
    k += 1
    if k >= ope[j][0]:
        j += 1
        k = 0
print(sum(cards))
a, b, c = input().split()

if a == b and a != c:
  print('Yes')
elif b == c and b != a:
  print('Yes')
elif c == a and c != b:
  print('Yes')
else:
  print('No)

### FIXED CODE ###

a, b, c = input().split()
 
if a == b and a != c:
  print('Yes')
elif b == c and b != a:
  print('Yes')
elif c == a and c != b:
  print('Yes')
else:
  print('No')
n = int(input())
a = input().split()
m = 1
for i in range(n):
    m = m * a[i]
    if m = 0:
        break
    

if m > 10**18:
    print("-1")
else:
    print(m)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
m = 1
for i in range(n):
    if a[i] == 0:
        m = 0
        print("0")

if m == 1:
    for j in range(n):
        m = m * a[j]
        if m > 10**18:
            break
    if m > 10**18:
        print("-1")
    else:
        print(m)
N, T = map(int, input().split())
cost = []
time = []
for i in range(N):
    c, t = map(int, input().split())
    if t <= T:
        cost.append(c)
        time.append(t)
min_time_index = time.index(min(time))
print(cost[min_time_index])

### FIXED CODE ###

N, T = map(int, input().split())
cost = []
time = []
for i in range(N):
    c, t = map(int, input().split())
    if t <= T:
        cost.append(c)
        time.append(t)
if len(time) == 0:
    print("TLE")
else:
    #min_time_index = time.index(min(time))
    #print(cost[min_time_index])
    print(min(cost))
while 1:
	su = 0
	stack = []
	try:
		raw = raw_input().split()
	except:
		pass
	else:
		for s in raw:
			if s == "-":
				stack.append(stack.pop(-2) - stack.pop())
			elif s == "+":
				stack.append(stack.pop(-2) + stack.pop())
			elif s == "/":
				stack.append(stack.pop(-2) / stack.pop())
			elif s == "*":
				stack.append(stack.pop(-2) * stack.pop())
			elif s == "%":
				stack.append(stack.pop(-2) % stack.pop())
			else:
				stack.append(int(s))
	
		print "%.6" % stack[0]

### FIXED CODE ###

while 1:
	try:
		stack = []
		for s in raw_input().split():
			if s == "-":
				stack.append(stack.pop(-2) - stack.pop())
			elif s == "+":
				stack.append(stack.pop(-2) + stack.pop())
			elif s == "/":
				stack.append(stack.pop(-2) / stack.pop())
			elif s == "*":
				stack.append(stack.pop(-2) * stack.pop())
			else:
				stack.append(float(s))
	
		print "%.6f" % (stack[0])
	except:
		break
N, K = map(int,input().split())
S = list(input())

def eval(N,S):
    total=0
    for i in range(1,N):
        if S[i]==S[i-1]:total+=1
    return total

for k in range(K):
    j=[]
    for i in range(1, N):
        if S[i-1]!=S[i]:
            j.append(i)
            if len(j)==2:break
    if len(j)==1:j.append(N)
    if S[j[0]]=='R':
        S[j[0]:j[1]]=['L']*(j[1]-j[0])
    else:S[j[0]:j[1]]=['R']*(j[1]-j[0])
    print(S)  
print(eval(N,S))
  


### FIXED CODE ###

import sys
from collections import deque

input = sys.stdin.readline

N, K = map(int,input().split())
S = list(input())

sq = deque(S)
lst=[]
j=0

for i in range(K):
    j=0
    if not sq:break
    sq_1st = sq.popleft()
    sq_2nd = sq_1st
    lst.append(sq_1st)

    while sq:
        sq_3rd = sq.popleft()
        if sq_2nd!=sq_3rd:
            j+=1
            sq_2nd=sq_3rd
            if j==2:
                sq.appendleft(sq_3rd)
                break
        lst.append(sq_1st)

lst+=list(sq)             

def eval(N,S):
    total=0
    for i in range(1,N):
        if S[i]==S[i-1]:total+=1
    return total
  
print(eval(N,lst))
a, b, c, d = map(int, input().split())

ab = [a, b]
cd = [c, d]

print(min(ab) + min(cd))


### FIXED CODE ###

a, b, c, d = [int(input()) for _ in range(4)]

print(min(a, b) + min(c, d))
from sys import stdin

H, W = [int(x) for x in stdin.readline().rstrip().split()]
A = [stdin.readline().rstrip() for _ in range(H)]
B = [[A[x][y] for x in range(H)] for y in range(W)]
queue = []

for k in range(H):
    for l in range(W):
        if A[k][l] == '#':
            queue.append((k, l, 0))


while len(queue) > 0:
    h, w, t = queue.pop(0)
    if h > 0:
        if B[h - 1][w] == '.':
            B[h - 1][w] = '#'
            queue.append((h - 1, w, t + 1))
    if h < H - 1:
        if B[h + 1][w] == '.':
            B[h + 1][w] = '#'
            queue.append((h + 1, w, t + 1))
    if w > 0:
        if B[h][w - 1] == '.':
            B[h][w - 1] = '#'
            queue.append((h, w - 1, t + 1))
    if w < W - 1:
        if B[h][w + 1] == '.':
            B[h][w + 1] = '#'
            queue.append((h, w + 1, t + 1))
    if len(queue) == 0:
        print(t)



### FIXED CODE ###

from sys import stdin
from collections import deque

H, W = [int(x) for x in stdin.readline().rstrip().split()]
B = [list(stdin.readline().rstrip()) for _ in range(H)]

q = deque([])

for k in range(H):
    for l in range(W):
        if B[k][l] == '#':
            q.append((k, l, 0))

while len(q) > 0:
    h, w, t = q.popleft()
    if h > 0:
        if B[h - 1][w] == '.':
            B[h - 1][w] = '#'
            q.append((h - 1, w, t + 1))
    if h < H - 1:
        if B[h + 1][w] == '.':
            B[h + 1][w] = '#'
            q.append((h + 1, w, t + 1))
    if w > 0:
        if B[h][w - 1] == '.':
            B[h][w - 1] = '#'
            q.append((h, w - 1, t + 1))
    if w < W - 1:
        if B[h][w + 1] == '.':
            B[h][w + 1] = '#'
            q.append((h, w + 1, t + 1))
    if len(q) == 0:
        print(t)
a, b, c, d = map(int, input().split())

print(max([(a*c), (a*d), (b*c), (b*d)]))

### FIXED CODE ###

num = int(input())
if num == 1:
	print(0)
elif num == 0:
    print(1)
import math

if __name__ == '__main__':
    N, K = list(map(int, input().split()))
    integer_value = []
    for i in range(N):
        integer, value = list(map(int, input().split()))
        integer_value.append((integer, value))
    r = int(math.log(K, 2))
    max_value = 0
    for i in range(r + 1):
        # print((K >> i) & 0b1)
        if not ((K >> i) & 0b1):
            continue

        tmp_sum = 0

        mask = 1
        for j in range(i):
            mask = (mask << 1) + 1
        Ki = (K | mask) - 2 ** i

        for tmp_int, tmp_val in integer_value:
            if Ki | tmp_int == Ki:
                tmp_sum += tmp_val

        # print(str(tmp_sum) + " " + str(i))
        if max_value < tmp_sum:
            max_value = tmp_sum

    # K の場合
    K_val = 0
    for tmp_int, tmp_val in integer_value:
        if K | tmp_int == K:
            K_val += tmp_val
    # print("max_val" + str(max_value))
    # print("K_val" + str(K_val))
    if K_val < max_value:
        print(max_value)
    else:
        print(K_val)


### FIXED CODE ###

import math

if __name__ == '__main__':
    N, K = list(map(int, input().split()))
    integer_value = []
    for i in range(N):
        integer, value = list(map(int, input().split()))
        integer_value.append((integer, value))
    if K == 0:
        r = 0
    else:
        r = int(math.log(K, 2))
    max_value = 0
    for i in range(r + 1):
        # print((K >> i) & 0b1)
        if not ((K >> i) & 0b1):
            continue

        tmp_sum = 0

        mask = 1
        for j in range(i):
            mask = (mask << 1) + 1
        Ki = (K | mask) - 2 ** i

        for tmp_int, tmp_val in integer_value:
            if Ki | tmp_int == Ki:
                tmp_sum += tmp_val

        # print(str(tmp_sum) + " " + str(i))
        if max_value < tmp_sum:
            max_value = tmp_sum

    # K の場合
    K_val = 0
    for tmp_int, tmp_val in integer_value:
        if K | tmp_int == K:
            K_val += tmp_val
    # print("max_val" + str(max_value))
    # print("K_val" + str(K_val))
    if K_val < max_value:
        print(max_value)
    else:
        print(K_val)