Harryxun/stf_run huggingface dataset:
S = list(input())
K = int(input())
length = []
tl = 1
x = 0
ans = 0
J = True
same = 1
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    same += 1
if same == len(S):
  J = False
S.append('end')
if S[0] != S[len(S)] and J:
  for i in range(len(S)):
    if S[i] == S[i+1]:
      tl += 1
    else:
      length.append(tl)
      tl = 1
  for i in range(len(length)):
    x += length[i]//2
  ans += x*K
  print(ans)
elif not J:
  ans = (len(S)-1)*K//2
  print(ans)
else:
  for i in range(len(S)):
    if S[i] == S[i+1]:
      tl += 1
    else:
      length.append(tl)
      tl = 1
  ans += ((length[0]+length[len(length)])*(K-1)//2) + length[0]//2 + length[length]//2
  length[0] = 0
  length[len(length)] = 0
  for i in range(len(length)):
    x += length[i]//2
  ans += x*K
  print(ans)
  


### FIXED CODE ###

S = list(input())
R = int(input())
lengths = []
same = False
All = False
odd = False
sl = 1
Sum = 0
if S[0] == S[len(S)-1]:
  same = True
S.append('0')
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    sl += 1
  else:
    lengths.append(sl)
    sl = 1
if len(lengths) == 1:
  All = True
if lengths[0]%2 == 1 and lengths[len(lengths)-1]%2 == 1:
  odd = True
if same:
  if All:
    Sum += (lengths[0]*R)//2
  else:
    temp = lengths[0]
    lengths[0] = 0
    lengths[len(lengths)-1] += temp
    if odd:
      for l in range(len(lengths)):
        Sum += (lengths[l]//2)*R
      Sum -= 1
    else:
      for g in range(len(lengths)):
        Sum += (lengths[g]//2)*R
else:
  for j in range(len(lengths)):
    Sum += (lengths[j]//2)*R
print(Sum)
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i+1
b = sorted(a)
center1 = b[n//2+1]
center2 = b[n//2]
buf1 = 0
buf2 = 0
for i in range(n):
    buf1 += abs(b[i]-center1)
    buf2 += abs(b[i]-center2)
print(int(min(buf1, buf2)))


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i+1
b = sorted(a)
center1 = b[n//2]
center2 = 0
if not n == 1:
    center2 = b[n//2+1]
buf1 = 0
buf2 = 0
for i in range(n):
    buf1 += abs(b[i]-center1)
    buf2 += abs(b[i]-center2)
print(int(min(buf1, buf2)))
n, q = map(int, input().split())

graph = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].append(b)
    # print(a, b)

nodes = [0 for _ in range(n + 1)]
for i in range(q):
    p, x = map(int, input().split())
    nodes[p] += x

# print(nodes)
result = [0 for _ in range(n + 1)]
def dfs(i=1, cost=nodes[1]):
    result[i] = cost
    for sub in graph[i]:
        dfs(sub, cost + nodes[sub])
dfs()
print(*result[1:])


### FIXED CODE ###

from collections import deque
n, q = map(int, input().split())

graph = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)
    # print(a, b)

nodes = [0 for _ in range(n + 1)]
for i in range(q):
    p, x = map(int, input().split())
    nodes[p] += x

# print(nodes)
result = [0 for _ in range(n + 1)]

# que = [(1, nodes[1])]
que = deque([(1, nodes[1])])

visited = [False] * (n + 1)
while que:
    i, cost = que.popleft()
    if visited[i]:
        continue
    result[i] = cost
    visited[i] = True
    for sub in graph[i]:
        que.append((sub, cost + nodes[sub]))
print(*result[1:])
N, M, K = map(int, input().split())
if M == 1:
    0/0

def power_func(a, n, p):
    bi = str(format(n,"b"))#2進表現に
    if n == 0:
        return 1
    if a == 0:
        return 0
    res = 1
    for i in range(len(bi)):
        res = (res*res) % p
        if bi[i] == "1":
            res = (res*a) % p
    return res

P = 998244353
inv_t = [0] + [1]
for i in range(2, max(M,K)+2):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

ans = (M * power_func(M-1, N-1, P))%P
curr = ans
for k in range(K):
    curr = (curr*(N-k-1)*inv_t[k+1]*inv_t[M-1]) % P
    ans += curr
    ans %= P

print(ans)

### FIXED CODE ###

import sys
N, M, K = map(int, input().split())

if M == 1 :
    if K == N-1:
        print(1)
    else:
        print(0)
    sys.exit()

def power_func(a, n, p):
    bi = str(format(n,"b"))#2進表現に
    if a == 0:
        return 0
    res = 1
    for i in range(len(bi)):
        res = (res*res) % p
        if bi[i] == "1":
            res = (res*a) % p
    return res

P = 998244353
inv_t = [0] + [1]
for i in range(2, max(M,K)+2):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

ans = (M * power_func(M-1, N-1, P))%P
curr = ans
for k in range(K):
    curr = (curr*(N-k-1)*inv_t[k+1]*inv_t[M-1]) % P
    ans += curr
    ans %= P

print(ans)
X = int(input())

import math
#----エラトステネスの篩--------
def get_primenumber(number):
    prime_list = []
    #2からnumberまでの数字をsearch_listに入れる
    search_list = list(range(2,number+1))
    while True:
      #search_listの先頭の値が√nの値を超えたら処理終了
      if search_list[0] > math.sqrt(number):
        #prime_listにsearch_listを結合
        prime_list.extend(search_list)
        break
      else:
        #search_listの先頭をprime_listに入れる
        head_num = search_list[0]
        prime_list.append(head_num)
        #search_listの先頭をpopする
        search_list.pop(0)
        #head_numの倍数を取り除く
        search_list = [num for num in search_list if num % head_num != 0]
    return prime_list
  
  num_list = get_primenumber(10**5+1)
  
  import sys

for i in range(len(num_list)):
    if X <= num_list[i]:
        print(num_list[i])
        sys.exit()

### FIXED CODE ###

X = int(input())

import math
import sys

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while True:
    if is_prime(X) == True:
        print(X)
        sys.exit()
    X+=1
import math

a, b, c = [[j for j in input().split()] for i in range(3)]
print(a[0] + b[1] + c[2])

### FIXED CODE ###

import math

a = input()
b = input()
c = input()
print(a[0] + b[1] + c[2])
import sys
N = int(input())

on = 0
for i in range(1<<N):
  a = int(sys.stdin.read(1))
  if bin(i).count("1") == 1 and not a:
    on |= i
  if not a ^ bool(i & on):
    print("Impossible")
    break
else:
  raise ValueError

### FIXED CODE ###

import sys
from heapq import *

def first_1(x):
  if x:
    i = 0
    while x & 1 == 0:
      x >>= 1
      i += 1
    return i

def sep_single(s):
  if s:
    r = 1 << (s.bit_length()-1)
    i = s.bit_length()-1
    while s:
      if r & s:
        yield -i, r
        s ^= r
      r >>= 1
      i -= 1

def prepare_to_right(g, x):
  x0, y0 = g[-1]
  if x0 < x and y0:
    y0 = 0
    g.append((x0, 0))
  while x0 < x:
    x0 += 1
    g.append((x0, 0))

def prepare_to_left(g, x):
  x0, y0 = g[-1]
  if x+1 < x0 and y0:
    y0 = 0
    g.append((x0, 0))
  while x+1 < x0:
    x0 -= 1
    g.append((x0, 0))

def append_to_right(g, x, y):
  prepare_to_right(g, x)
  x0, y0 = g[-1]
  if y != y0:
    g.append((x, y))
  g.append((x+1, y))

def subloop_tp_group(g):
  x = 0
  while g&1 == 0:
    g >>= 1
    x += 1
  loop = [(x+1, 0)]
  tail = [(x, 0), (x, 1), (x+1, 1)]
  g >>= 1
  x += 1
  while g:
    while g&1==0:
      g >>= 1
      x += 1
    prepare_to_right(loop, x)
    prepare_to_right(tail, x)
    rev = reversed(loop)
    append_to_right(loop, x, 1)
    loop.append((x+1, 0))
    loop.extend(rev)
    loop.extend(tail)
    append_to_right(loop, x, 0)
    append_to_right(tail, x, 1)
    g >>= 1
    x += 1
  loop.extend(reversed(tail))
  return loop

N = int(input())

single = 0
tpg = []
for i in range(1<<N):
  a = int(sys.stdin.read(1))
  if bin(i).count("1") == 1:
    if a == 0:
      single |= i
  else:
    b = i & single
    if i and b | a == 0 and all(p & i != p for n, p in tpg):
      heappush(tpg, (-first_1(i), i))
    elif i | a == 0 or a and (b or any(p & i == p for n, p in tpg)):
      print("Impossible")
      break
else:
  print("Possible")
  loop = []
  for n, g in merge(sep_single(single), nsmallest(len(tpg),tpg)):
    subloop = subloop_tp_group(g)
    if loop:
      prepare_to_left(loop, subloop[0][0])
      if loop[-1] == subloop[0]:
        loop.pop()
    loop.extend(subloop)
  
  if not loop:
    loop.append((0, 0))
  prepare_to_right(loop, loop[0][0])
  
  print(len(loop)-1)
  for p in loop:
    print(*p)
A, P = map(int, input(' '))
print((3*A+P)//2)

### FIXED CODE ###

A, P = map(int, input().split(' '))
print((3*A+P)//2)
n, k = map(int, input().split())
p = list(map(int, input().split()))
ans = []
for i in range(1, n-k+1,2):
    ans.append(sum(p[(i):(k+i)]))
ans2 = []
for i in range(0, n-k+1,2):
    ans2.append(sum(p[(i):(k+i)]))
ans1 = max(ans)
ans2 = max(ans2)
print((k+max([ans1, ans2]))/2)

### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
tmp = sum(p[:k])
ans = [tmp]
if n == k:
    ans_mae = ans[0]
    print((ans_mae+k)/2)
else:
    for i in range(1,n-k+1):
        tmp = tmp - p[i-1] + p[i+k-1]
        ans.append(tmp)
    print((max(ans)+k)/2)
x = input().split()[1]
ans = 0
 
a = input().split()
a.sort()
 
for i in len(a):
  if a[i] > x:
    print(ans)
    break
  else:
    x-=a[i]
    ans+=1
print(ans)

### FIXED CODE ###

line = input().split()
N = int(line[0])
x = int(line[1])
ans = 0

a = input().split()
a = [int(i) for i in a]
a.sort()

for i in range(N):
    if a[i] > x:
        print(ans)
        break
    else:
        x -= a[i]
        if i != (N - 1):
            ans += 1
        else:
            if x == 0:
                ans += 1
            print(ans)
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
li = rl()
print(max(li) - min(li)









### FIXED CODE ###

import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
li = rl()
print(max(li) - min(li))
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(input())

#white = ".", black = "#"
def search(x, y, color):
    global ans
    if color == ".":
        for m in [1, -1]:
            if 0 <= x+m <= H-1:
                if S[x+m][y] == "#" and not dp[x+m][y]:
                    dp[x+m][y] = True
                    color = "#"
                    search(x+m, y, color)
        for n in [1, -1]:
            if 0 <= y+n <= W-1:
                if S[x][y+n] == "#" and not dp[x][y+n]:
                    dp[x][y+n] = True
                    color = "#"
                    search(x, y+n, color)

    else:
        for m in [1, -1]:
            if 0 <= x+m <= H-1:
                if S[x+m][y] == "." and not dp[x+m][y]:
                    ans += 1
                    dp[x+m][y] = True
                    color = "."
                    search(x+m, y, color)

        for n in [1, -1]:
            if 0 <= y+n <= W-1:
                if S[x][y+n] == "." and not dp[x][y+n]:
                    ans += 1
                    dp[x][y+n] = True
                    color = "."
                    search(x, y+n, color)


ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            dp = [[False] * W for a in range(H)]
            dp[i][j] = True
            search(i, j, "#")

print(ans)


### FIXED CODE ###

N = int(input())
H = int(input())
W = int(input())
print((N - H + 1)*(N - W + 1))
def beforeTax(n):
  li = int(n // 1.08)
  if int(li * 1.08) == n:
    print(li)
  if int((li + 1) * 1.08) == n:
    print(li + 1)
  print(':(')
 
if __name__ == "__main__":
  import sys
  in_str = ''
  for line in sys.stdin:
    in_str += line
  n = [int(_) for _ in in_str.split()]
  print(int(beforeTax(n)))

### FIXED CODE ###

def beforeTax(n):
  li = int(n // 1.08)
  if int(li * 1.08) == n:
    print(li)
  elif int((li + 1) * 1.08) == n:
    print(li + 1)
  else:
  	print(':(')
 
if __name__ == "__main__":
  import sys
  in_str = ''
  for line in sys.stdin:
    in_str += line
  n = [int(_) for _ in in_str.split()][0]
  beforeTax(n)
rint(3*int(input())**2)

### FIXED CODE ###

print(3*int(input())**2)
H ,N = [int(i) for i in input().split()]
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split(' ')])
 
MAX = 0
for a, b in AB:
    MAX = a if MAX < a else MAX
 
DP = [10**10] * (H+MAX)
DP[0] = 0
for i in range(H):
    for a,b in AB:
        if DP[i] != 10**10:
            DP[i+a] = min(DP[i+a],DP[i] + b)
 
print(min(DP[H:]))
H ,N = [int(i) for i in input().split()]
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split(' ')])

MAX = 0
for a, b in AB:
    MAX = a if MAX < a else MAX

DP = [10**10] * (H+MAX)
DP[0] = 0
for i in range(H):
    for a,b in AB:
        if DP[i] != 10**10:
            DP[i+a] = min(DP[i+a],DP[i] + b)

print(min(DP[H:]))
提出情報

### FIXED CODE ###

H ,N = [int(i) for i in input().split()]
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split(' ')])
 
MAX = 0
for a, b in AB:
    MAX = a if MAX < a else MAX
 
DP = [10**10] * (H+MAX)
DP[0] = 0
for i in range(H):
    for a,b in AB:
        if DP[i] != 10**10:
            DP[i+a] = min(DP[i+a],DP[i] + b)
 
print(min(DP[H:]))
def main():
    import sys
    input = sys.stdin.readline
    N, T = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(N)]
    ab.sort(key=lambda x: x[1])
    dp = [-1 for i in range(T*2 + 1)]
    dp[0] = 0
    for a, b in ab:
        for i in range(T*2 + 1, 0, -1):
            if i - a >= 0:
                if dp[i-a] >= 0 and i - a < T:
                    dp[i] = max(dp[i], dp[i-a] + b)
    for i in range(1, T*2+1):
        dp[i] = max(dp[i], dp[i-1])
    ans = dp[-1]

    # print(dp)
    print(ans)


main()


### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    N, T = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(N)]
    ab.sort(key=lambda x: (x[0], x[1]))
    dp = [-1 for i in range(T*2 + 1)]
    dp[0] = 0
    for a, b in ab:
        for i in range(T*2, 0, -1):
            if i >= a:
                if dp[i-a] >= 0 and i - a < T:
                    dp[i] = max(dp[i], dp[i-a] + b)

    for i in range(1, T*2+1):
        dp[i] = max(dp[i], dp[i-1])
    ans = dp[-1]

    ab.sort(key=lambda x: x[1])
    tmp = ab.pop()
    dp = [-1 for i in range(T)]
    dp[0] = 0
    for a, b in ab:
        for i in range(T-1, 0, -1):
            if i >= a:
                if dp[i-a] >= 0:
                    dp[i] = max(dp[i], dp[i-a] + b)

    for i in range(1, T):
        dp[i] = max(dp[i], dp[i-1])
    ans = max(ans, tmp[1] + dp[-1])

    # print(dp)
    print(ans)


main()
import numpy as np


def solve(n, aaa):
    if aaa[0] > 0:
        return -1
    if any(a1 - a0 > 1 for a0, a1 in zip(aaa, aaa[1:])):
        return -1
    ans = 0
    aaa.reverse()

    while any(aaa):
        new = [0] * (len(aaa) - 1)
        a1 = aaa[0]
        ap = 0
        for i, a0 in enumerate(aaa[1:]):
            if a1 == 0:
                a1 = a0
                continue
            ans += 1
            if a1 - a0 < 1:
                new[i] = ap = max(a1 - 1, ap)
            else:
                new[i] = ap
            a1 = a0
            if ap:
                ap -= 1
        aaa = np.trim_zeros(new)
        if a1:
            ans += 1
    return ans


n = int(input())
aaa = list(map(int, (input() for _ in range(n))))
print(solve(n, aaa))


### FIXED CODE ###

def solve(n, aaa):
    if aaa[0] > 0:
        return -1
    if any(a1 - a0 > 1 for a0, a1 in zip(aaa, aaa[1:])):
        return -1
    ans = 0
    a0 = 0

    for a1 in aaa[1:]:
        if a1 - a0 != 1:
            ans += a0
        a0 = a1

    return ans + a0


n = int(input())
aaa = list(map(int, (input() for _ in range(n))))
print(solve(n, aaa))
int_a, int_b, int_k = map(int, input().split())

ar = list(range(int_a, int_b + 1))

minset = set(range(int_a, int_a + int_k))
maxset = set(range(int_b - int_k + 1, int_b + 1))

result = list(minset | maxset)
result.sort()
for i in result:
    if int_a <= i <= int_b:
        print(i)



### FIXED CODE ###

int_a, int_b, int_k = map(int, input().split())

minset = set(range(int_a, int_a + int_k))
maxset = set(range(int_b - int_k + 1, int_b + 1))

result = list(minset | maxset)
result.sort()
for i in result:
    if int_a <= i <= int_b:
        print(i)
n=int(input())
import numpy
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

pri_fact=prime_factorize(n)

def prod(x):
    kotae=1
    for i in x:
        kotae*=i
    return kotae

ans=10**12
for i in range(len(pri_fact)):
    ans=min((prod(pri_fact[0:i])-1)+(prod(pri_fact[i:])-1),ans)

print(int(ans))


### FIXED CODE ###

n=int(input())

ans=10**12
d=2
while d<=n**(1/2):
    if n%d==0:
        ans=min(ans,d+n//d-2)
    d+=1
if ans==10**12:
    print(n-1)
    exit()
print(ans)
import math

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

a=(n[0]-1)//n[2]
b=(n[0]-1)//n[3]
c=(n[0]-1)//(n[2]*n[3]/math.gcd(n[2],n[3]))

d=n[1]//n[2]
e=n[1]//n[3]
f=n[1]//(n[2]*n[3]/math.gcd(n[2],n[3]))

print((n[1]-d-e+f)-((n[0]-1)-a-b+c))

### FIXED CODE ###

import fractions

a,b,c,d=map(int, input().split())

a-=1

buf_1=a-(a//c+a//d)+a//((c*d)//fractions.gcd(c,d))
buf_2=b-(b//c+b//d)+b//((c*d)//fractions.gcd(c,d))

print(buf_2-buf_1)
def main():
    S = list(input())

    N = len(S)

    if (S[0] == 0) or (S[-1] == 0):
        print (-1)
        return 0

    lst = []
    for i in range((N - 1) // 2):
        if S[i] != S[N - 2 - i]:
            print (-1)
            return 0
        if S[i] == '1':
            lst.append(i + 1)
    if N % 2 == 0 and S[N//2 - 1] == '1':
        lst.append(N//2)
    # print (lst)

    if lst[-1] * 2 != N:
        center = lst[-1] + 1
        for x in range(lst[-1] * 2 + 2, N + 1):
            print (center, x)

        before = 1
        n = lst[-1] * 2 + 2
        for tmp in lst[1:]:
            print (before, tmp)
            print (n - before, n - tmp)
            for x in range(tmp - before - 1):
                print (before + 1 + x, tmp)
                print (n - (before + 1 + x), n - tmp)
            before = tmp
        print (tmp, center)
        print (n - tmp, center)

    if lst[-1] * 2 == N:
        before = 1
        n = lst[-1] * 2 + 1
        for tmp in lst[1:]:
            print (before, tmp)
            print (n - before, n - tmp)
            for x in range(tmp - before - 1):
                print (before + 1 + x, tmp)
                print (n - (before + 1 + x), n - tmp)
            before = tmp
        print (tmp, n - tmp)

if __name__ == '__main__':
    main()

### FIXED CODE ###

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

    N = len(S)

    if (S[0] == '0') or (S[-1] == '1'):
        print (-1)
        return 0

    lst = []
    for i in range((N - 1) // 2):
        if S[i] != S[N - 2 - i]:
            print (-1)
            return 0
        if S[i] == '1':
            lst.append(i + 1)
    if N % 2 == 0 and S[N//2 - 1] == '1':
        lst.append(N//2)
    # print (lst)

    if lst[-1] * 2 != N:
        center = lst[-1] + 1
        for x in range(lst[-1] * 2 + 2, N + 1):
            print (center, x)

        before = 1
        n = lst[-1] * 2 + 2
        tmp = 1
        for tmp in lst[1:]:
            print (before, tmp)
            print (n - before, n - tmp)
            for x in range(tmp - before - 1):
                print (before + 1 + x, tmp)
                print (n - (before + 1 + x), n - tmp)
            before = tmp
        print (tmp, center)
        print (n - tmp, center)

    if lst[-1] * 2 == N:
        before = 1
        n = lst[-1] * 2 + 1
        tmp = 1
        for tmp in lst[1:]:
            print (before, tmp)
            print (n - before, n - tmp)
            for x in range(tmp - before - 1):
                print (before + 1 + x, tmp)
                print (n - (before + 1 + x), n - tmp)
            before = tmp
        print (tmp, n - tmp)

if __name__ == '__main__':
    main()
N, K = map(int, input().split())
A = [tuple(int(x) for x in input().split()) for _ in range(N)]
A = [(a, b) for a, b in A if a <= K]
# print(A)
L = K.bit_length()
ans = 0
for i in reversed(range(L)):
    bit = (1 << i) & K
    if bit != 1:
        # print(bit, ':', i)
        cand = 0
        bor = 0
        for a, b in A:
            if ((a >> i) & 1) == 0:
                # print(a, (a >> i) & 1)
                cand += b
                bor ^= a
        ans = max(ans, cand)
        assert(bor <= K)
print(ans)


### FIXED CODE ###

N, K = map(int, input().split())
A = [tuple(int(x) for x in input().split()) for _ in range(N)]
A = [(a, b) for a, b in A if a <= K]
L = K.bit_length()
ans = sum(b for a, b in A if (a | K) <= K)
for i in reversed(range(L)):
    bit = (1 << i) & K
    if bit != 1:
        cand = 0
        bor = 0
        tmp_K = K & ~(1 << i) | ((1 << i) - 1)
        ans = max(ans, sum(b for a, b in A if (a | tmp_K) <= K))
print(ans)
N=int(input())
S=input()
cnt1 = 0
cnt2 = 0
for idx,s in enumerate(S):
    if s == "#" and idx < N-1:
        cnt1+=1
    if s=="." and N!=0:
        cnt2+=1
if cnt1 < cnt2:
    print(cnt1)
else:
    print(cnt2)



### FIXED CODE ###

X= [int(i) for i in input().split()]
if (X[0] > X[2] and X[1] < X[2]) or (X[0] < X[2] and X[1] > X[2]) :
    print("Yes")
else:
    print("No")
import sys
n=int(input())
a=map(int,input().split())
ans=1
for i in range(n):
  ans*=a[i]
  if ans>10**18:
    print(-1)
    sys.exit()
print(ans)

### FIXED CODE ###

#!/usr/bin/env python3
import sys
n=int(input())
a=list(map(int,input().split()))
ans=1
 
for i in range(n):
    if a[i]==0:
        print(0)
        sys.exit()

for i in range(n):
    ans*=a[i]
    if ans>10**18:
        print(-1)
        sys.exit()
 
print(ans)
from sys import stdin
ans = 'No'
n,m,k = map(int,stdin.readline().split())
for i in xrange(n+1):
 for j in xrange(m+1):
  if i*m - b*j==k:
   ans = 'Yes'
print ans

### FIXED CODE ###

from sys import stdin
s = stdin.readline().strip()
ans = 'No'
if s.startswith('YAKI'):
 ans = 'Yes'
print ans
from unittest import TestCase, main
from A import func

class test(TestCase):
  def test_with_valid_params(self):
    test_patterns = [
      ("apple","apples"),
      ("bus","buses"),
      ("box","boxs")
    ]

    for S,result in test_patterns:
      with self.subTest(S=S):
        self.assertEqual(func(S),result)

if __name__ == "__main__":
  main()

### FIXED CODE ###

def func(S):
  if S[-1] == "s":
    return S+"es"
  else:
    return S+"s"


if __name__ == "__main__":
    S = input()
    print(func(S))
N, X = map(int, raw_input().split())

def func(lv, id):
    sz = 4 * 2 ** lv - 3
    num = 2 * 2 ** lv - 1
    mid = (sz + 1) / 2
    if lv == 0:
        return 1
    if id == 1:
        return 0
    if id == mid:
        return (num - 1) / 2 + 1
    if id == sz:
        return num
    if 1 < id < mid:
        return func(lv - 1, id - 1)
    if mid < id < sz:
        return func(lv - 1, id - (sz - 3) / 2) + num / 2

print func(N, X)

### FIXED CODE ###

#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, X = map(int, raw_input().split())

sz = [1] * (N + 1)
num = [1] * (N + 1)

for i in range(N):
    sz[i + 1] = sz[i] * 2 + 3
    num[i + 1] = num[i] * 2 + 1

def func(lv, id):
    mid = (sz[lv] + 1) / 2
    if lv == 0:
        return 1
    if id == 1:
        return 0
    if id == mid:
        return (num[lv] - 1) / 2 + 1
    if id == sz[lv]:
        return num[lv]
    if 1 < id < mid:
        return func(lv - 1, id - 1)
    if mid < id < sz[lv]:
        return func(lv - 1, id - sz[lv - 1] - 2) + num[lv - 1] + 1

print func(N, X)
a, b = map(int, input())
if a <= b:
  print(a)
else:
  print(a-1)

### FIXED CODE ###

a, b = map(int, input().split())
if a <= b:
  print(a)
else:
  print(a-1)