QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100

#554. Prophecy

统计

JSOI is a kingdom with a long history. Recently, archaeologists discovered an ancient prophecy in a tomb. Although the conclusion part is incomplete, the derivation process remains intact. The prophecy concerns the date of the world's destruction, and King JS has entrusted the important task of deciphering the prophecy to the Minister of Culture, JYY.

The prophecy consists of three parts: Heaven, Earth, and Man:

The first part, "Heaven," comes from the revelations of the gods to the ancient JSOI prophets. It consists of $N$ elements, represented by 32-bit unsigned integers, denoted as $a_1$ to $a_n$.

The second part, "Earth," comes from the observations of the world by the ancient JSOI people. It consists of $N$ elements, represented by 32-bit unsigned integers, denoted as $b_1$ to $b_n$.

The third part, "Man," comes from the JSOI people's belief regarding the date the world will be destroyed, represented by a 64-bit unsigned integer, denoted as $t$.

The derivation process for the prophecy $f$ is as follows:

$$f(x) = \begin{cases} a_x, & x \le N \\ \bigoplus_{i=1}^{n} (f(x-i) \land b_i), & x > N \end{cases}$$

Where $\land$ denotes the bitwise AND operation, and $\bigoplus$ denotes the bitwise XOR operation. Now, JYY wants to find the value of $f(t)$.

Input

The first line contains a positive integer $N$. The second line contains $N$ unsigned integers $a_i$. The third line contains $N$ unsigned integers $b_i$. The fourth line contains an integer $t$.

Output

Output a single integer, the value of $f(t)$.

Constraints

  • For 10% of the data, $t \le 1000$;
  • For another 20% of the data, $N \le 100$;
  • For 100% of the data, $1 \le N \le 1000$, $t \le 10^{18}$.

Examples

Input 1

3
10 20 30
7 19 13
5

Output 1

16

Input 2

5
2345678901 1001001001 3333333333 3141592653 1234567890
2147483648 2147483647 4294967295 4294967294 3434343434
100

Output 2

1067078691

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.