Nimber Sequence

아직 제출이 없습니다시간 제한1초메모리 제한256 MB

문제

Given are Nimbers a_1,a_2,,a_K1a\_1, a\_2, \ldots, a\_{K-1}, b_1,b_2,,b_5b\_1, b\_2, \ldots, b\_5, and c_1,c_2,,c_5c\_1, c\_2, \ldots, c\_5.

Let a_n=(_i=15a_nib_i)(_i=15a_nK+ic_i)\displaystyle a\_n = \left(\bigoplus\_{i = 1}^{5} a\_{n - i} \otimes b\_i \right) \oplus \left(\bigoplus\_{i = 1}^{5} a\_{n - K + i} \otimes c\_i \right) for all nKn \ge K.

Find the value of a_ma\_m.

입력

The first line of input contains two positive integers KK and mm (6K1056 \le K \le 10^5, 1m10181 \le m \le 10^{18}).

The second line contains K1K - 1 non-negative integers a_1,a_2,,a_K1a\_1, a\_2, \ldots, a\_{K - 1} (0a_i<2320 \le a\_i < 2^{32}).

The third line contains five non-negative integers b_1,b_2,,b_5b\_1, b\_2, \ldots, b\_5 (0b_i<2320 \le b\_i < 2^{32}).

The fourth line contains five non-negative integers c_1,c_2,,c_5c\_1, c\_2, \ldots, c\_5 (0c_i<2320 \le c\_i < 2^{32}).

출력

Output a single line with a single integer: the value of a_ma\_m.

힌트

Nimbers are non-negative integers associated with Nim games. For the purposes of this problem, two operations are necessary:

  • "\large\oplus" is the Nim sum: ab=mex(ab0a<aab0b<b)\displaystyle a \oplus b = \mathrm{mex}\left( \\{a' \oplus b \mid 0 \le a' < a\\} \cup \\{a \oplus b' \mid 0 \le b' < b\\} \right),
  • "\large\otimes" is the Nim product: ab=mex((ab)(ab)(ab)0a<a,,0b<b)\displaystyle a \otimes b = \mathrm{mex}\left( \\{(a' \otimes b) \oplus (a \otimes b') \oplus (a' \otimes b') \mid 0 \le a' < a, \\, 0 \le b' < b \\} \right).

Here, mex(S)\mathrm{mex}(S) represents the smallest non-negative integer d∉Sd \not\in S.