Problem p02554 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

const long long int MOD = pow(10, 9) + 7;

int main(void) {

  int N;
  cin >> N;
  long long int a = 1, b = 1, c = 1, ans;
  for (int i = 0; i < N; i++) {
    a *= 10;
    a %= MOD;
    b *= 8;
    b %= MOD;
    c *= 9;
    c %= MOD;
  }
  ans = (a + b - 2 * c) % MOD;
  if (ans < 0)
    ans += MOD;
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define LL long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define vil vector<pil>
#define vli vector<pli>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define TN typename
#define all(v) v.begin(), v.end()
#define fill(a, b) memset(a, b, sizeof(a))
#define endl '\\n'
#define Int in()
#define Long Lin()
#define policy_set                                                             \\
  tree<int, null_type, less<int>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>
#define policy_multiset                                                        \\
  tree<int, null_type, less_equal<int>, rb_tree_tag,                           \\
       tree_order_statistics_node_update>

template <TN T> T gcd(T a, T b) { return !b ? a : gcd(b, a % b); }
template <TN T> T lcm(T a, T b) { return a * (b / gcd(a, b)); }
template <TN T> inline void smin(T &a, T b) { a = a < b ? a : b; }
template <TN T> inline void smax(T &a, T b) { a = a > b ? a : b; }

#define error(args...)                                                         \\
  {                                                                            \\
    string _s = #args;                                                         \\
    replace(_s.begin(), _s.end(), ',', ' ');                                   \\
    stringstream _ss(_s);                                                      \\
    istream_iterator<string> _it(_ss);                                         \\
    err(_it, args);                                                            \\
  }
void err(istream_iterator<string> it) { cout << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}

inline int in() {
  int n;
  scanf("%d", &n);
  return n;
}
inline ll Lin() {
  ll n;
  scanf("%lld", &n);
  return n;
}
inline double Din() {
  double n;
  scanf("%lf", &n);
  return n;
}

const int mod = (int)1e9 + 7;
const ll Mod = (ll)1e9 + 7;

inline int add(int a, int b) {
  a += b;
  return a >= mod ? a - mod : a;
}
inline int sub(int a, int b) {
  a -= b;
  return a < 0 ? a + mod : a;
}
inline int mul(int a, int b) { return (ll)a * b % mod; }

const int inf = (int)2e9 + 5;
const ll Inf = (ll)1e18 + 5;
const int N = 2e5 + 5;

int solve() {
  ll n;
  cin >> n;
  ll a = 1, b = 1, c = 1;
  for (int i = 0; i < n; i++) {
    a *= 10;
    a %= Mod;
    b *= 8;
    b %= Mod;
    c *= 9;
    c %= Mod;
  }
  ll ans = (a + b - 2 * c) % Mod;
  cout << ans << endl;
}

int main() {
  // ios_base::sync_with_stdio(false); cin.tie(NULL);
  int test = 1, tc = 0;
  // scanf("%d", &test);
  // cin >> test;
  while (test--) {
    // printf("Case %d: ", ++tc);
    solve();
  }
  return 0;
}