1. Abridged problem statement
Given an integer N (1 ≤ N ≤ 10^6), count how many N-digit positive integers x (i.e. with no leading zeros) satisfy that the last nine digits of x² are exactly 987654321. Output that count in decimal.

2. Detailed editorial

Goal: count N-digit x such that
  x² ≡ 987654321 (mod 10^9).

Let S = 987654321 and D = 10^9. We proceed in two steps:

A) Find all 9-digit suffixes y (0 ≤ y < D) with y² ≡ S (mod D).
   - By experiment or by Hensel/CRT, one finds exactly 8 distinct residues y₁…y₈ modulo 10^9 satisfying yᵢ² ≡ S.
   - Hence there are 8 possible choices for the last nine digits of x.

B) Count how many full N-digit numbers extend each such suffix.
   - If N < 9, no N-digit number even has nine digits, so answer = 0.
   - If N = 9, x must equal one of the 8 valid suffixes, but leading digit cannot be zero. Checking shows all 8 are indeed 9-digit (not starting with zero), so answer = 8.
   - If N > 9, write x = P·10^9 + y with suffix y one of the 8 roots.
     • The prefix P has length L = N−9 digits, and its first digit is 1…9 (no leading zero).
     • Number of choices for P is 9·10^(L−1) = 9·10^(N−10).
     • Total = (number of suffixes) ⋅ (number of prefixes) = 8 ⋅ 9 ⋅ 10^(N−10) = 72⋅10^(N−10).

Implementation runs in O(1) time per test by just handling cases N<9, N=9, N>9 (printing "72" plus the trailing zeros for the big-number case).

3. C++ Solution
```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n;

void read() { cin >> n; }

void solve() {
    // A square ending in ...987654321 must end in 9, so its root ends in 3 or
    // 7. Checking modulo 10^9 shows exactly two roots mod 10^9 give that
    // suffix, so squares end in 987654321 only for roots of at least 9 digits.
    // For n < 9 there are none; for n == 9 there are 8 (the two residues times
    // the choices of leading digit that keep it a 9-digit number); for n > 9
    // each extra digit multiplies the count by 10, giving 72 followed by
    // (n - 10) zeros.

    if(n < 9) {
        cout << 0 << '\n';
    } else if(n == 9) {
        cout << 8 << '\n';
    } else {
        cout << 72;
        n -= 10;
        while(n--) {
            cout << 0;
        }
        cout << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}
```

4. Python Solution
```python
import sys
def main():
    data = sys.stdin.read().strip()
    if not data:
        return
    n = int(data)

    # Case 1: fewer than 9 digits → no solution
    if n < 9:
        print(0)
        return

    # Case 2: exactly 9 digits → exactly 8 valid suffixes, all 9-digit
    if n == 9:
        print(8)
        return

    # Case 3: n >= 10
    # Total = 8 suffixes × (9·10^(n−10) prefixes) = 72 · 10^(n−10)
    # We print '72' followed by (n−10) zeros to form that decimal number.
    zeros = n - 10
    sys.stdout.write('72' + '0' * zeros + '\n')

if __name__ == '__main__':
    main()
```

5. Compressed editorial

- We need x² ≡ 987654321 mod 10^9.
- Exactly 8 residues mod 10^9 satisfy this.
- For N < 9: 0. For N = 9: 8.
- For N > 9: choose one of 8 suffixes and a nonzero-leading prefix of length N−9: 9·10^(N−10) ways ⇒ total = 8·9·10^(N−10) = 72·10^(N−10).
