PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000014. Đếm đỉnh cách đúng K cạnh (Complete Binary Tree)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm đỉnh cách đúng K cạnh (Complete Binary Tree)

Complete Binary Tree

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Consider a binary tree indexed as an array. The root is vertex 11; vertex uu has children 2u2u and 2u+12u+1 whenever those indices do not exceed NN. Exactly vertices 1,…,N1,\ldots,N exist.

The distance between two vertices is the number of edges on the unique path between them. Given vertex XX and integer KK, count vertices vv for which dist(X,v)=Kdist(X,v)=K.

The source problem uses multiple test cases. This version accepts one set of parameters N,X,KN,X,K.

Input

  • The only line contains three integers N,X,KN,X,K.

Output

Print the number of vertices at distance exactly KK from XX.

Subtasks

  • Subtask 1 (20 points): N≤200N\le200; 1≤N≤10181\le N\le10^{18}; 1≤X≤N1\le X\le N; 0≤K≤N−10\le K\le N-1.
  • Subtask 2 (30 points): N≤107N\le10^7; 1≤N≤10181\le N\le10^{18}; 1≤X≤N1\le X\le N; 0≤K≤N−10\le K\le N-1.
  • Subtask 3 (50 points): 1≤N≤10181\le N\le10^{18}; 1≤X≤N1\le X\le N; 0≤K≤N−10\le K\le N-1.

Examples

Input

10 2 2

Output

4

Explanation

In the tree on indices 11 through 1010, vertices at distance two from vertex 22 are 3,8,9,103,8,9,10, so the answer is 44.