---
# System prepended metadata

title: Untitled

---

## 競技プロゼミ
## 2022/1/24

### 2
```python=

#yagi
N, K = map(int, input().split())

tree_list = [int(input()) for i in range(N)]
tree_list = sorted(tree_list)

h_min=10**10
# 10^10
diff_h = 0

for i in range(N-K+1):
    diff_h = tree_list[i+K-1]-tree_list[i]
    if diff_h<h_min:
        h_min = diff_h
        
print(h_min)

# tsssubotani
n,k = map(int,input().split())
h = list(int(input())for _ in range(n))
h.sort()
ans = []
for i in range(n-k+1):
    x = h[i+k-1]-h[i]
    ans.append(x)
print(min(ans)) 


# yoshie
N,K = map(int,input().split())
h = sorted(list(int(input())for _ in range(N)))
ans = 10**10
for i in range(N-K+1):ans = min(ans,h[i+K-1]-h[i])
print(ans)
    
```



### 3
```python=


#tsubotani
from statistics import median
a,b,c = map(int,input().split())
if a*b*c%2==0:
    print(0)
else:
    l=[a,b,c]
    print(min(l)*median(l))

# yoshie
l = sorted(list(map(int,input().split())))
if a*b*c%2==0:print(0)
else:print(l[0]*l[1])

```



## 4

f(A, x) := レベルAバーガーの下からx番目まででパティが何枚あるか
（xは0-indexed）

patty[A] := レベルAバーガーに含まれるパティの数
tot[A] := レベルAバーガーの層数

```python=
#tsubotani
n,x = map(int,input().split())

# P=1 , B=0
b = [""]*51
b[0] = "1"

def l_burger(l):
    if b[l]!="":
        return b[l]
    x = "0"+l_burger(l-1)+"1"+l_burger(l-1)+"0"
    b[l] =x
    return 


n_burger = list(l_burger(n))
ans = 0
for i in range(x):
    ans += int(n_burger[i])

print(ans)







# sino
N,X = map(int,input().split())
patty_cnt = [0]*51
patty_cnt[0] = 1
tot = 

for i in range(1,N+1):
    patty_cnt[i] =patty_cnt[0]*2+1
print(b[N][:X].count("P"))



def levelup(X,N):
    if N==0 and X!=0:
        return 1
    if X==0:
        return 0
    elif X<2**(N+1)-1:
        return levelup(X-1,N-1)
    elif X<2**(N+2)-3:
        return 2**N - 1 + levelup(X-2**(N+1)+1,N-1) + 1
    elif X==2**(N+2)-3:
        return 2**(N+1) - 1

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

print(levelup(X,N))



```