Harryxun/stf_run huggingface dataset:
import sys
input = sys.stdin.readline
from collections import defaultdict

class Unionfind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [1]*n
    
    def root(self, x):
        p = x
        
        while not self.par[p]<0:
            p = self.par[p]
        
        while x!=p:
            tmp = x
            x = self.par[x]
            self.par[tmp] = p
        
        return p
    
    def unite(self, x, y):
        rx, ry = self.root(x), self.root(y)
        
        if rx==ry: return False
        
        if self.rank[rx]<self.rank[ry]:
            rx, ry = ry, rx
        
        self.par[rx] += self.par[ry]
        self.par[ry] = rx
    
        if self.rank[rx]==self.rank[ry]:
            self.rank[rx] += 1
    
    def is_same(self, x, y):
        return self.root(x)==self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

N, M = map(int, input().split())
a = list(map(int, input().split()))
uf = Unionfind(N)

for _ in range(M):
    x, y = map(int, input().split())
    uf.unite(x, y)

d = defaultdict(list)
rs = set()

for i in range(N):
    r = uf.root(i)
    rs.add(r)
    d[r].append(a[i])

if len(rs)==1:
    print(0)
    exit()

if 2*(len(rs)-1)>N:
    print('Impossible')
    exit()
    
ans = 0

for k in d.keys():
    d[k].sort()
    ans += d[0]

l = []

for v in d.values():
    l += v[1:]

l.sort()
ans += sum(l[:len(rs)-2])

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict

class Unionfind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [1]*n
    
    def root(self, x):
        p = x
        
        while not self.par[p]<0:
            p = self.par[p]
        
        while x!=p:
            tmp = x
            x = self.par[x]
            self.par[tmp] = p
        
        return p
    
    def unite(self, x, y):
        rx, ry = self.root(x), self.root(y)
        
        if rx==ry: return False
        
        if self.rank[rx]<self.rank[ry]:
            rx, ry = ry, rx
        
        self.par[rx] += self.par[ry]
        self.par[ry] = rx
    
        if self.rank[rx]==self.rank[ry]:
            self.rank[rx] += 1
    
    def is_same(self, x, y):
        return self.root(x)==self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

N, M = map(int, input().split())
a = list(map(int, input().split()))
uf = Unionfind(N)

for _ in range(M):
    x, y = map(int, input().split())
    uf.unite(x, y)

d = defaultdict(list)
rs = set()

for i in range(N):
    r = uf.root(i)
    rs.add(r)
    d[r].append(a[i])

if len(rs)==1:
    print(0)
    exit()

if 2*(len(rs)-1)>N:
    print('Impossible')
    exit()
    
ans = 0

for k in d.keys():
    d[k].sort()
    ans += d[k][0]

l = []

for v in d.values():
    l += v[1:]

l.sort()
ans += sum(l[:len(rs)-2])

print(ans)
n = input()

if n == ABC:
    print("ARC")
else:
    print("ABC")

### FIXED CODE ###


n = input()

if n == "ABC":
    print("ARC")
else:
    print("ABC")
#C問題
N,M = map(int,input().split())
K = []
S = []
for i in range(M):
    ks =list(map(int,input().split()))
    ss = []
    kk = ks[0]
    K.append(kk)
    for j in range(kk):
        ss.append(ks[j+1])
    
    S.append(ss)
P = list(map(int,input().split()))
Bit = 2**N
ans = 0
for i in range(Bit):
    b = bin(i)
    b = b.lstrip("0b")
    lenb = len(b)
    j = 0
    for j in range(N-lenb):
        b = "0"+b
        
    sw = []
    j = 0

    for j in range(M):
        if b[j] == "1":
            sw.append(1)
        else:
            sw.append(0)
    
    j = 0
    flag = 0
    for j in range(M):
        cond = P[j]
        now = 0
        for k in range(K[j]):
            now+=sw[S[j][k]-1]
            
        if now%2 == cond:
            pass
        else:
            flag = 1
            break
            
    if flag == 0:
        ans+=1
    
print(ans)

### FIXED CODE ###

#C問題
N,M = map(int,input().split())
K = []
S = []
for i in range(M):
    ks =list(map(int,input().split()))
    ss = []
    kk = ks[0]
    K.append(kk)
    for j in range(kk):
        ss.append(ks[j+1])
    
    S.append(ss)
P = list(map(int,input().split()))
Bit = 2**N
ans = 0
for i in range(Bit):
    b = bin(i)
    b = b.lstrip("0b")
    lenb = len(b)
    j = 0
    for j in range(N-lenb):
        b = "0"+b
        
    sw = []
    j = 0

    for j in range(N):
        if b[j] == "1":
            sw.append(1)
        else:
            sw.append(0)
    
    j = 0
    flag = 0
    for j in range(M):
        cond = P[j]
        now = 0
        for k in range(K[j]):
            now+=sw[S[j][k]-1]
            
        if now%2 == cond:
            pass
        else:
            flag = 1
            break
            
    if flag == 0:
        ans+=1
    
print(ans)
n, q = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n-1)]
PX = [list(map(int, input().split())) for _ in range(q)]

stack = [[] for _ in range(n+1)]
stack[0].append(1)
for i in range(n-1):
	stack[AB[i][0]].append(AB[i][1])

ans = [0] * n
def dfs(cur, num):
	ans[cur-1] += num
	if len(stack[cur]) <= 0:
		return
	for c in stack[cur]:
		dfs(c, num)

for px in PX:
	dfs(px[0], px[1])

print(*ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
n, q = map(int, input().split())
 
stack = [[] for _ in range(n)]
for i in range(n-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  stack[a].append(b)
  stack[b].append(a)
ans = [0] * n
for i in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
def dfs(cur, par):
    for c in stack[cur]:
      if c == par:
        continue
      ans[c] += ans[cur] 
      dfs(c, cur)
dfs(0, -1)
print(*ans)
for i in range(3000):
    a, b = map(int, input().split())
    
    if a == b == 0
        break
    elif a < b:
        print(a, b)
    else
        print(b, a)
    
    
    


### FIXED CODE ###

for i in range(3000):
    a, b = map(int, input().split())
    
    if a == b == 0:
        break
    elif a < b:
        print(a, b)
    else:
        print(b, a)
N=int(input())
A = list(map(int, input().split()))

big = max(A)
small = min(A)
print(int(big - small))


### FIXED CODE ###

N = int(input())
if N % 2 == 0:
    ans = N
else:
    ans = N * 2
print(ans)
n=int(input())
t0=0
x0=0
y0=0
for i in range(n):
  t,x,y=[int(i) for i in input().split()]
  if (t-t0-(abs(x-x0)+abs(y-y0)))%2 == 1 or t-t0<(abs(x-x0)+abs(y-y0)):
    print('No')
    break
  t0,x0,y0=t,x,
else:
  print('Yes')
  

### FIXED CODE ###

n=int(input())
t0=0
x0=0
y0=0
for i in range(n):
  t,x,y=[int(i) for i in input().split()]
  if (t-t0-(abs(x-x0)+abs(y-y0)))%2 == 1 or t-t0<(abs(x-x0)+abs(y-y0)):
    print('No')
    break
  t0,x0,y0=t,x,y
else:
  print('Yes')
n = int(input())
a = [int(input()) for i in range(n)]
on = 1
count = 0
on_li = [1]
while True:
    on = a[on-1]
    if on in on_li:
        print(-1)
        exit()
    on_li.append(on)
    print(on_li)
    count += 1
    if on == 2:
        print(count)
        exit()

### FIXED CODE ###

n=int(input())
a=[int(input()) for i in range(n)]

c,s=1,a[0]

while s!=2 and c<n:
    c,s=c+1,a[s-1]

print(c if c<n else -1)
data = int(input())
list = sorted(data)

print("{a} {b} {c}").format(a=list[0], b=list[1], c=list[2])

### FIXED CODE ###

num = list(map(int, input().split()))
num.sort()
print(num[0], num[1], num[2])
# これは, u749194f さんの改造です。
# オリジナルではございません。
# https://atcoder.jp/contests/abc162/submissions/11825963
n = int(input())
s = input()
flag = True
if len(set(s))<=2:
    print(0)
    flag = False
if flag:
    r = [i+1 for i in range(n) if s[i]=='R']
    b = [i+1 for i in range(n) if s[i]=='B']
    g = [i+1 for i in range(n) if s[i]=='G']
    minus = 0
    def cnt_cmb(a, b, c):
        cnt = 0
        for i in a:
            for j in b:
                if (i+j)/2 in c:
                    cnt += 1
        return cnt
    minus += cnt_cmb(r, b, g)
    minus += cnt_cmb(b, g, r)
    minus += cnt_cmb(g, r, b)
    print(len(r)*len(b)*len(g)-minus)

### FIXED CODE ###

print(["No","Yes"]["7" in input()])
n=int(input())
*l,=map(int,input().split())
v=0
for i in range(n-1):
  if l[i]==i+1:
    l[i],l[i+1]=l[i+1],l[i]
    v+=1
if l[N-1]==N:
  l[N-2],l[N-1]=l[N-1],l[N-2]
  v+=1
    
print(v)

### FIXED CODE ###

n=int(input())
*l,=map(int,input().split())
v=0
for i in range(n-1):
  if l[i]==i+1:
    l[i],l[i+1]=l[i+1],l[i]
    v+=1
if l[n-1]==n:
  l[n-2],l[n-1]=l[n-1],l[n-2]
  v+=1
    
print(v)
from collections import deque

def copyDeque(d):
    x = deque()
    for i in d:
        x.append(i)
    return x

def cndP(w):
    if len(w)>1:
        x = w.pop()
        cndP(copyDeque(w))
        w.append(x)
        s = 0
        while(len(w)>0):
            s += w.pop()
            st.add(s)
    else:
        st.add(w[0])
        
def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = copyDeque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = deque()

for i in range(n):
    w.append(int(input()))
    
st = set()
cndP(copyDeque(w))

sorted_st = sorted(st)
for i in sorted_st:
    if pIsAccptbl(w,k,i):
        print(i)
        break

### FIXED CODE ###

from collections import deque

def isPa(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp

n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
    w.append(int(input()))
    
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)

if k == 1:
    print(mean)
else:
    minP = mean
    maxP = maxinp
    while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP or minP == maxP):
            print(maxP)
            break
n = int(input())
arr = list(int,input().split())
arr = arr[::2]
def odd(n) : return (n%2==1)
lst = filter(odd,arr)
print(len(lst))

### FIXED CODE ###

n = int(input())
arr = list(map(int,input().split()))
def odd(n) : return (n%2==1)
lst = list(filter(odd,arr[0:n:2]))
print(len(lst))
def f(y,x,c0):
  global A
  c=A[y][x]
  if c==" " or c!=c0:
    return 0
  else:
    A[y][x]=" "
    for i,j in [[0,-1],[0,1],[-1,0],[1,0]]:
      f(y+i,x+j,c0)
    return 1

while 1:
  H,W=map(int,raw_input().split())
  if H==W==0: break
  A=[[[] for _ in range(W+2)] for _ in range(H+2)]
  for i in range(H+2):
    if i==0 or i==H+1:
      for j in range(W+2): A[i][j]=" "
    else:
      s=raw_input().rstrip()
      for j in range(1,W+1): A[i][j]=s[j]
  for e in A: print e
  c=0
  for i in range(1,H+1):
    for j in range(1,W+1):
      c+=f(i,j,A[i][j])
  print c

### FIXED CODE ###

def f(y,x,a):
  M.append([y,x])
  while M:
    y,x=M.pop()
    if A[y][x]==a:
      A[y][x]=' '
      for i,j in [[0,-1],[-1,0],[0,1],[1,0]]: M.append([y+i,x+j])
  return 1

M=[]
while 1:
  H,W=map(int,raw_input().split())
  if H==W==0: break
  A=[list(' '*(W+2)) for _ in range(H+2)]
  for i in range(H): A[i+1][1:W+1]=list(raw_input())
  c=0
  for i in range(1,H+1):
    for j in range(1,W+1):
      a=A[i][j]
      if a!=' ': c+=f(i,j,a)
  print c
A,B=map(int,input().split())
if (B==1 and A!=1) or B>A:
  print("Bob")
elif (A==1 and B!=1) or B<A:
  print("Alice")
elif A==B:
  print(Draw)

### FIXED CODE ###

A,B=map(int,input().split())
if (B==1 and A!=1) or(A!=1 and B>A):
  print("Bob")
elif (A==1 and B!=1) or B<A:
  print("Alice")
elif A==B:
  print("Draw")
S=input()
w=int(input())
n=len(S)
T=""
for i in range (0,n+1,w):
  T+=S[i]
print(T)

### FIXED CODE ###

S=input()
w=int(input())
n=len(S)
T=""
for i in range (0,n,w):
  T+=S[i]
print(T)
import sys

K = int(input())
S = input()
sentence = list(S)
sentencelong = len(sentence)

if K < sentencelong:
  print(sentence[:K] + '...')
elif K > sentencelong:
  print(S)
  
else:
  sys.exit()
  

### FIXED CODE ###

K=int(input())
S=input()

if len(S) > K:
  S = S[:K] + "..."
  
print(S)
n, m = input()
A = []
b = []
c = 0
  
for i in range(n):
   A += [map(int, raw_input().split())]

for j in range(m):
   b += [input()]
   
for i in range(n):
   for j in range(m):
      c += A[i][j] * b[j]
   print c

### FIXED CODE ###

n, m = map(int, raw_input().split())
A = []
b = []
    
for i in range(0, n):
   A += [map(int, raw_input().split())]
  
for j in range(0, m):
   b += [input()]
     
for i in range(0, n):
   c = 0
   for j in range(0, m):
      c += A[i][j] * b[j]
   print c
s,t,u = map(str,input().spilt())

print(s[0].upper()+t[0].upper()+u[0].upper())


### FIXED CODE ###

s,t,u = input().split()

print(s[0].upper()+t[0].upper()+u[0].upper())
# import math
# import bisect
import numpy as np
import itertools
# import copy
import sys

input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    cmb = list(itertools.combinations([i for i in range(1, n)], k-1))
    ans = INF

    for ele in cmb:
        prc = 0
        prev = a[0]
        for idx in ele:
            cur = a[idx]
            if cur - prev <= 0:
                prc += prev - cur + 1
                cur = prev + 1
            prev = cur
        ans = min(ans, prc)

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# import math
# import bisect
#import numpy as np
import itertools
import copy
import sys

input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    cmb = list(itertools.combinations([i for i in range(1, n)], k-1))
    ans = INF

    if k > 1:
            for ele in cmb:
                prc = 0
                prev = a[0]
                acp = copy.copy(a)
                for idx in ele:
                    if acp[idx] - prev <= 0:
                        prc += prev - acp[idx] + 1
                        acp[idx] = prev + 1
                    prev = acp[idx]
                cnt = 1
                mh = acp[0]
                for i in range(1, n):
                    if mh < acp[i]:
                        cnt += 1
                        mh = acp[i]
                if cnt >= k:
                    ans = min(ans, prc)
    else:
        ans = 0

    print(ans)


if __name__ == '__main__':
    main()
m, n = list(map(int, input().split(" ")))
a_list = list(map(int, input().split(" "))).sort(reverse=True)
if m == 0:
    print('Yes')
else:
    if a_list[m-1] >= sum(a_list) / (4 * m):
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

n, m = list(map(int, input().split(" ")))
a_list = sorted(list(map(int, input().split(" "))), reverse=True)
if m == 0:
    print('Yes')
else:
    if a_list[m-1] >= sum(a_list) / (4 * m):
        print('Yes')
    else:
        print('No')
A, B = map(int, input().split())
result = 0
def calc(A, B, N):
    if N >= B:
        return A
    A = A ^ (N + 1)
    return calc(A, B, N + 1)
print(calc(A, B, A))


### FIXED CODE ###

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

def calc(n):
    mod = n % 4
    if mod == 0:
        return n
    elif mod == 1:
        return n ^ (n-1) 
    elif mod == 2:
        return n ^ 1
    elif mod == 3:
        return 0
a = calc(A - 1)
b = calc(B)

print(a ^ b)
import math

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

mod = 998244353

fac = [0] * N
finv = [0] * N
inv = [0] * N

fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, N):
    fac[i] = fac[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod

def com(n, k):
    global fac, finv, mod
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod

ans = pow(M, N, mod)
for L in range(K + 1, N):
    result = (M * pow(M - 1, N - L - 1, mod) * com(N - 1, N - L - 1)) % mod
    ans -= result

print(ans % mod)


### FIXED CODE ###

import math

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

if N == 1:
    print(M)
    exit(0)

mod = 998244353

fac = [0] * N
finv = [0] * N
inv = [0] * N

fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, N):
    fac[i] = fac[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod

def com(n, k):
    global fac, finv, mod
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod

ans = pow(M, N, mod)
for L in range(K + 1, N):
    result = (M * pow(M - 1, N - L - 1, mod) * com(N - 1, N - L - 1)) % mod
    ans -= result

print(ans % mod)
N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for i in range(0,2*N,2) :
    ans += L[i]
print(ans)


### FIXED CODE ###

N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
answer = 0
for i in range(len(L)) :
    if i % 2 == 0 :
        answer += L[i]
print(answer)
def dfs(s):
	global x, G
	for t, d in G[s]:
		if x[t] is None:
			x[t] = x[s] + d
			if not dfs(t):
				return False
		else:
			if x[t] != x[s] + d:
				return False
	return True

N,M = map(int,input().split())
x = [None] * N
G = [[] for _ in range(N)]
for _ in range(M):
	L, R, D = map(int,input().split())
	G[L-1].append([R-1,D])
	G[R-1].append([L-1,-D])
print(G)
res = True
for i in range(N):
	if x[i] is None:
		x[i] = 0
		res &= dfs(i)

print("Yes" if res == True else "No")

### FIXED CODE ###

import sys
sys.setrecursionlimit(200002)

def dfs(s):
	global x, G
	for t, d in G[s]:
		if x[t] is None:
			x[t] = x[s] + d
			if not dfs(t):
				return False
		else:
			if x[t] != x[s] + d:
				return False
	return True

N,M = map(int,input().split())
x = [None] * N
G = [[] for _ in range(N)]
for _ in range(M):
	L, R, D = map(int,input().split())
	G[L-1].append([R-1,D])
	G[R-1].append([L-1,-D])

res = True
for i in range(N):
	if x[i] is None:
		x[i] = 0
		res &= dfs(i)

print("Yes" if res == True else "No")
N, Y = map(int, input().split())
ans = 0
found = False
for i in range(N):
    for j in range(N):
        k = N - i - j
        is_sum = i * 10_000 + j * 5_000 + k * 1_000 == Y
        if is_sum:
            print(i, j, k)
            found = True
            break
    if found:
        break
        # for k in range(N):
        #     if i * 10_000 + j * 5_000 + k * 1_000 == Y and i + j + k == N:
        #         print(i, j, k)
        #         found = True
if not found:
    print("-1 -1 -1")


### FIXED CODE ###

N, Y = map(int, input().split())
ans = 0
found = False

Y //= 1000

T = 0
for i in range(Y // 10 + 1):
    for j in range((Y - i * 10) // 5 + 1):
        T += 1
        x = Y - i * 10 - j * 5
        if x < 0:
            break
        if i + j + x == N:
            print(i, j, x)
            found = True
            break
    if found:
        break
if not found:
    print("-1 -1 -1")
n = int(input())
for i in range(1,11):
    if n <= pow(26,i):
        d = i
        break
    n = n - pow(26,i)
d = d - 1 
n = n - 1
ans =''
for i in range(d):
    tmp = divmod(n,pow(26,d-i))
    ans = ans+ chr(97+tmp[0])
    n = tmp[1]
print(ans + chr(97+n))

### FIXED CODE ###

n = int(input())
for i in range(1,12):
    if n <= pow(26,i):
        d = i
        break
    n = n - pow(26,i)
d = d - 1 
n = n - 1
ans =''
for i in range(d):
    tmp = divmod(n,pow(26,d-i))
    ans = ans+ chr(97+tmp[0])
    n = tmp[1]
print(ans + chr(97+n))
n, q = map(int, input().split())
s = list(input())
lr = [list(map(int, input().split())) for _ in range(q)]

cntli = []
for i in range(q):
    si = s[lr[i][0]-1:lr[i][1]]
    si2 = [n for n in si if n in ("A","C")]
    cnt = 0
    for j in range(len(si)-1):
        if si2[j] == "A":
            if si2[j+1] == "C":
                cnt += 1
    else:
        cntli.append(cnt)

for p in cntli:
    print(p)

### FIXED CODE ###

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

t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)

for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
n = int(input))
print(" ".join(list(map(int, input().split()))[::-1]))


### FIXED CODE ###

input()
print(" ".join(input().split()[::-1]))
n = int(input())
An = list(map(int, input().split()))

j = 100000000000000000

ans = 1


for i in range(n):
    ans = ans * An[i]

if ans <= j:
    print(ans)
    quit()
else :
    print('-1')
    quit()

### FIXED CODE ###

a,b=map(int,input().replace('.', '').split())
print(a*b//100)
N, X = map(int, input().split())


def f(n):
    # レベルnの総数
    if n == 0:
        return 1
    else:
        return 2 * f(n - 1) + 3


def g(n):
    # レベルnのpの数
    if n == 0:
        return 1
    else:
        return 2 * g(n - 1) + 1


def dfs(n, x):
    # 総数
    m = f(n)
    # 真ん中
    a = (m + 1) // 2

    if x == a:
        return g(n - 1) + 1
    elif x == 1:
        return 0
    elif x < a:
        return dfs(n - 1, x - 1)
    elif x >= a:
        return g(n - 1) + 1 + dfs(n - 1, x - a)
    elif x == m:
        return 2 * g(n - 1) + 1


ans = dfs(N, X)
print(ans)


### FIXED CODE ###

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


def f(n):
    # レベルnの総数
    if n == 0:
        return 1
    else:
        return 2 * f(n - 1) + 3


def g(n):
    # レベルnのpの数
    if n == 0:
        return 1
    else:
        return 2 * g(n - 1) + 1


def dfs(n, x):
    # 総数
    m = f(n)
    # 真ん中
    a = (m + 1) // 2

    if n == 0:
        return 1
    elif x == 1:
        return 0
    elif x < a:
        return dfs(n - 1, x - 1)
    elif x == a:
        return g(n - 1) + 1
    elif x >= a:
        return g(n - 1) + 1 + dfs(n - 1, x - a)
    elif x == m:
        return 2 * g(n - 1) + 1


ans = dfs(N, X)
print(ans)
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[int(inpui())-1])

### FIXED CODE ###

a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[int(input())-1])
S, T = map(str, input().split())
list_S = list(S)
list_T = list(T)
count = 0
for i in range(3):
    if list_S(i) == list_T(i):
        count += 1
print(count)

### FIXED CODE ###

S = list(input())
T = list(input())

count = 0
for i in range(3):
    if S[i] == T[i]:
        count += 1
print(count)
line = raw_input()
a = line.split(" ")
s = a[0] * a[1]
len = 2 * (a[0] + a[1])
print str(s) + " " + str(len)

### FIXED CODE ###

line = raw_input()
lis = line.split()
a = int(lis[0])
b = int(lis[1])
s = a * b
len = 2 * (a + b)
print str(s) + " " + str(len)
from sys import stdin

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

arr =[]

arr.append(a+b)
arr.append(a-b)
arr.append(a*b)

print(arr.max())

### FIXED CODE ###

from sys import stdin
 
a,b = [int(x) for x in stdin.readline().rstrip().split()]
 
arr =[]
 
arr.append(a+b)
arr.append(a-b)
arr.append(a*b)
 
print(max(arr))