Language: C++

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define int long long

ll L, A, B, M;

typedef vector<ll> vec;
typedef vector<vec> mat;

mat mul(mat &A, mat &B) {
    mat C(A.size(), vec(B[0].size()));
    for(int i = 0; i < A.size(); i++) {
        for(int j = 0; j < B[0].size(); j++) {
            for(int k = 0; k < B.size(); k++) C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M;
        }
    }
    return C;
}

mat pow(mat A, ll n) {
    mat B(A.size(), vec(A.size()));
    for(int i = 0; i < A.size(); i++) B[i][i] = 1;
    if(n == 0) return B;
    mat C(A.size(), vec(A.size()));
    C = pow(mul(A, A), n / 2);
    if(n & 1) C = mul(C, A);
    return C;
}

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> L >> A >> B >> M;
  mat ans(3, vec(1));
  ans[0][0] = A; ans[1][0] = A; ans[2][0] = 1LL:
  ll cnt[20];
  rep1(i, 18) {
    ll MIN= pow(10, d - 1);
    if(A + B * (L - 1) < MIN) break;
    ll MAX = min(MIN * 10 - 1, A + B * (L - 1));
    cnt[i] = (MAX - A) / B + 1;
    mat A(3, vec(3)), B(3, vec(3));
    A[0][0] = 1LL; A[0][1] = 0; A[0][2] = B;
    A[1][0] = 1LL; A[1][1] = pow(10, d); A[1][2] = B;
    A[2][0] = 0; A[2][1] = 0; A[2][2] = 1LL:
    B = pow(A, cnt[i] - (i - 1 >= 0 ? cnt[i - 1] ? 1LL));
    ans = mul(B, ans);
  }
  cout << ans[0][0] << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:84:48: error: expected ';' before ':' token
   84 |   ans[0][0] = A; ans[1][0] = A; ans[2][0] = 1LL:
      |                                                ^
      |                                                ;
a.cc:87:21: error: 'd' was not declared in this scope
   87 |     ll MIN= pow(10, d - 1);
      |                     ^
a.cc:90:5: error: 'cnt' was not declared in this scope; did you mean 'int'?
   90 |     cnt[i] = (MAX - A) / B + 1;
      |     ^~~
      |     int
a.cc:92:43: error: cannot convert 'mat' {aka 'std::vector<std::vector<long long int> >'} to '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} in assignment
   92 |     A[0][0] = 1LL; A[0][1] = 0; A[0][2] = B;
      |                                           ^
      |                                           |
      |                                           mat {aka std::vector<std::vector<long long int> >}
a.cc:93:52: error: cannot convert 'mat' {aka 'std::vector<std::vector<long long int> >'} to '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} in assignment
   93 |     A[1][0] = 1LL; A[1][1] = pow(10, d); A[1][2] = B;
      |                                                    ^
      |                                                    |
      |                                                    mat {aka std::vector<std::vector<long long int> >}
a.cc:94:44: error: expected ';' before ':' token
   94 |     A[2][0] = 0; A[2][1] = 0; A[2][2] = 1LL:
      |                                            ^
      |                                            ;