We are to count integer sequences A_1,...,A_N with each element in {0,1,...,9} such that there is at least one 0 and at least one 9. So we need total number of sequences (10^N) minus those that miss at least one of these digits. Use inclusion-exclusion: sequences with no 0: each element from 1-9 -> 9^N; sequences with no 9: similarly 9^N; sequences with neither 0 nor 9: each element from 1-8 -> 8^N. So answer = total - (no0 + no9) + (no0&no9) = 10^N - 2*9^N + 8^N.
But we must be careful: For N>=1, this formula holds. For N=0? Not needed because N>=1. But also check: when N=1, 10^1 - 29^1 + 8^1 = 10 - 18 + 8 = 0, matches example. For N=2: 100 - 281 + 64 = 100 -162 +64 = 2, matches.
So we need to compute (10^N - 2*9^N + 8^N) mod MOD = 1e9+7.
Constraints N up to 1e6, so we can compute exponentiations using fast exponent (binary exponentiation) O(log N). But N is only up to 1e6, so we could even precompute powers using loops? But 1e6 is not too big, but using exponentiation is fine. However, note that N can be large, but fast exponent works.
But wait, there might be a nuance: The sequences are of length N; we need existence of some i such that A_i = 0 and some i such that A_i = 9. They could be same i? No, because a single position cannot be both 0 and 9 simultaneously. So that's fine, we require at least one zero and at least one nine. So the formula correct.
Thus answer = (pow(10,N) - 2*pow(9,N) + pow(8,N)) % MOD, ensuring non-negative.
Implementation: read N, compute modulo. Use pow_mod function.
Edge Cases: N=1 => 0. N large, compute mod.
So answer is simple.
But the problem might be from AtCoder (maybe typical). The constraints: N up to 10^6, but they might ask to compute quickly. But fast pow O(log N) is enough. However, sometimes they might expect to compute via precomputation since N is only 1e6, but either is fine.
But check: The example with N=869121 yields 2511445, so we can verify after implementation.
We'll implement.
Implementation details:
MOD = 10**9+7
def mod_pow(a, n):
res = 1
while n > 0:
if n & 1:
res = res * a % MOD
a = a * a % MOD
n >>= 1
return res
Then compute ans = (mod_pow(10,N) - 2*mod_pow(9,N) + mod_pow(8,N)) % MOD
Make sure to add MOD before final mod to avoid negative.
Alternatively: ans = (mod_pow(10,N) - 2*mod_pow(9,N)) % MOD; ans = (ans + mod_pow(8,N)) % MOD.
Better: ans = (mod_pow(10,N) - 2*mod_pow(9,N) + mod_pow(8,N)) % MOD; if ans < 0: ans += MOD.
But Python % yields non-negative remainder, but careful: (a - b) % MOD yields positive. However if we compute directly: (pow10 - 2*pow9 + pow8) % MOD, Python's modulo will handle negative correctly, giving a result in [0, MOD). So we can just compute that.
But 2*pow9 may be large; we should compute mod.
We'll compute:
pow10 = pow(10, N, MOD) # built-in pow supports mod
pow9 = pow(9, N, MOD)
pow8 = pow(8, N, MOD)
ans = (pow10 - 2*pow9 + pow8) % MOD
print(ans)
That's it.
Time complexity O(log N). Works for N up to 1e6 (log2(1e6) ~ 20). So trivial.
But wait, maybe there's a catch: N can be up to 10^6, but that's fine. Actually they might have N up to 10^9? But constraints say 1 <= N <= 10^6. So okay.
But I recall some problems where sequences have additional constraints? Here it's just that.
Thus answer straightforward.
Now writing final solution.
We need to output as integer.
Will produce a Python solution.
Note: In Python, pow can handle large exponent with mod efficiently.
So final code:
import sys
MOD = 10**9+7
def main():
N = int(sys.stdin.readline().strip())
pow10 = pow(10, N, MOD)
pow9 = pow(9, N, MOD)
pow8 = pow(8, N, MOD)
ans = (pow10 - 2*pow9 + pow8) % MOD
print(ans)
if name == "main":
main()
That's it.
But perhaps we need to consider the possibility of overflow? In Python, fine.
Now I'll output final answer.
But wait: The problem statement says "How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?" and then conditions: 0 ≤ A_i ≤ 9; There exists some i such that A_i=0 holds; There exists some i such that A_i=9 holds. So indeed the count is as derived.
Thus answer = 10^N - 2*9^N + 8^N.
Now I'm done. ```python
import sys
MOD = 10**9 + 7
def main() -> None:
N = int(sys.stdin.readline().strip())
pow10 = pow(10, N, MOD)
pow9 = pow(9, N, MOD)
pow8 = pow(8, N, MOD)
ans = (pow10 - 2 * pow9 + pow8) % MOD
print(ans)
if name == "main":
main()