Category

Similar Problems

0739. Sequence

Time limit : 1000 ms
Memory limit : 64 mb

  In a sequence of numbers a1a2a3, ... given the first term, and the rest are calculated using the formula:

ai = (ai-1)2 mod 10000.

   Find the N-th term of the sequence.

Input                 

In the first row are the numbers a1 and N, separated by a space. 0 ≤ a1 ≤ 100001 ≤ N ≤ 2000000010.

Output

Output a single number - aN.

Samples

Input

Output

1

4 3

256

2

0 2000

0

 

Tayyorladi: Azat Yusupov
Text from: e-olimp.com