There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones…
- User
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat. Input
The single line of input contains one integer n (0 ≤ n ≤ 109).
Output
Print single integer — the last digit of 1378n.
Examples
Input
1
Output
8
Input
2
Output
4
Note
In the first example, last digit of 13781 = 1378 is 8.
In the second example, last digit of 13782 = 1378·1378 = 1898884 is 4.
Assistant
We are asked: Given n, print the last digit of 1378^n. That is compute (1378^n) mod 10.
Given that 1378 mod 10 = 8. So we need 8^n mod 10. The last digit of powers of 8 repeats with period 4: 8^1=8, 8^2=64->4, 8^3=512->2, 8^4=4096->6, 8^5=32768->8, ... cycle length 4: 8,4,2,6. For n=0, 8^0=1, last digit 1. But careful: The problem says n is integer, 0 ≤ n ≤ 10^9. For n=0, 1378^0 = 1, last digit 1. So we need to handle that.
Thus answer: if n==0: 1 else: compute exponent mod 4: let r = n mod 4. If r==0 -> last digit 6; r==1 -> 8; r==2 -> 4; r==3 -> 2.
We can also treat n=0 as special: because 0 mod 4 =0 but 8^0=1, not 6. So handle separately.
Alternatively, we can compute pow(1378, n, 10) using modular exponentiation, but given n up to 1e9 it's fine, but easiest is pattern.
Thus solution: read n; if n==0: print(1) else: d = [6,8,4,2]; index = n % 4; print(d[index])? Wait careful: For n mod 4 = 0 (and n>0) gives 6. For n mod 4 = 1 gives 8, 2 gives 4, 3 gives 2. So mapping: r=1->8,2->4,3->2,0->6. So d = [6,8,4,2] indexing by r where r from 0 to 3. So d[r] gives correct for n>0. For n=0, r=0 but we want 1. So we can if n==0: print(1) else: print(d[n%4]).
Alternatively, we could compute pow(8, n, 10) with pow built-in and handle n=0 automatically because pow(8,0,10)=1. So we could just compute pow(8, n, 10). That's simplest and safe. But note: 8^n mod 10 can be computed using pow(8,n,10). In Python, pow(8,n,10) works for n up to large numbers because it uses modular exponentiation. So we can do: print(pow(8,n,10)). That automatically returns 1 for n=0. That is the easiest.
But careful: The problem states n up to 1e9, pow(8,n,10) works quickly.
Thus solution: read n, compute result = pow(8, n, 10), output result.
But wait: Is 1378 mod 10 = 8 always? Yes. Because (1378 mod 10) = 8. Then (1378^n mod 10) = (8^n mod 10). So it's correct.
Edge cases: n=0 -> 1. Works.
Now, the problem: It says print single integer — the last digit. That is exactly mod 10.
Now, examples: n=1 -> pow(8,1,10)=8; n=2 -> pow(8,2,10)=64%10=4. Good.
Thus the code is trivial.
I will produce a solution in Python.
Implementation: import sys def main(): n = int(sys.stdin.readline().strip()) ans = pow(8, n, 10) print(ans)
Or if using input().
That's it.
But note: Could also compute 1378^n mod 10 directly: pow(1378, n, 10). But since 1378 is larger, but pow handles it. pow(1378, n, 10) also works because 1378 % 10 = 8, so it's equivalent. But either way.
Thus solution.
Now the answer: We'll just output.
But as per problem statement, "Please help, although it's a naive cheat." So it's a simple problem.
I'll produce final solution.
But I need to provide reasoning: We note that last digit depends only on base mod 10, and we compute exponent cyclicity. Provide explanation.
Thus final. ```python
import sys
def main() -> None: data = sys.stdin.readline().strip() if not data: return n = int(data) # last digit of 1378^n = last digit of 8^n ans = pow(8, n, 10) print(ans)
if name == "main": main()