QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#17974. XOR Graph

統計

An XOR graph with $N$ vertices is defined as follows.

  • The graph has $N$ vertices numbered from $0$ to $N-1$.
  • For each vertex $i$, there are directed edges from vertex $i$ to vertex $i \oplus t$ and vertex $(i \oplus t) + 1$.
  • However, if the destination vertex exceeds $N-1$, the edge does not exist.

Here, $\oplus$ denotes the bitwise XOR operation.

Given the number of vertices $N$, the starting vertex $x$, the destination vertex $y$, and a non-negative integer $t$, find the minimum number of edges needed to move from vertex $x$ to vertex $y$.

Input

The first line of input contains four space-separated integers $N$, $x$, $y$, and $t$. ($2 \leq N \leq 10^{18}$; $0 \leq x, y < N$; $x \neq y$; $0 \leq t < 2^{20}$)

Output

Print the minimum number of edges needed to move from vertex $x$ to vertex $y$. If no such path exists, print $-1$ instead.

Examples

Input 1

4 2 3 2

Output 1

2

Input 2

10 7 9 6

Output 2

-1

Input 3

165321961421 998244353 5029393147 98207

Output 3

8242633

Note

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.