Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main() {
  int n,p; cin >> n >> p;
  mod = p;
  string s; cin >> s;
  if(p==2){
    ll is2 = 1;
    ll not2 = 0;
    FOR(i,0,s.length()-1){
      int a = (int)s[i] - '0';
      if(a%2==0) ++is2;
      else ++not2;
    }
    ll ans = 0;
    ans += max(is2 * (is2-1) / 2,0);
    ans += max(not2 * (not2-1) / 2,0);
    cout << ans << "\n";
    return 0;
  }
  if(p==5){
    map<int,ll> mp;
    ++mp[0];
    FOR(i,0,s.length()-1){
      int a = (int)s[i] - '0';
      ++mp[a%5];
    }
    ll ans = 0;
    for(auto x: mp){
      ans += x.second * (x.second-1) / 2;
    }
    cout << ans << "\n";
    return 0;
  }
  string copy = s;
  reverse(copy.begin(),copy.end());
  s = copy;
  mint mp[n+1];
  map<int,ll> m;
  mp[0] = 0;
  ++m[0];
  mint ten = 1;
  ten /= 10;
  FOR(i,1,s.length()){
    int a = (int)s[i-1] - '0';
    ten *= 10;
    // cout << ten.x << endl;
    mp[i] = ten * a + mp[i-1];
    ++m[mp[i].x];
    // cout << ten.x << " " << mp[i].x << "\n";
  }
  ll ans = 0;
  for(auto x: m){
    ans += x.second * (x.second-1) / 2;
  }
  cout << ans << "\n";


}


Compiler output:
a.cc: In function 'int main()':
a.cc:87:15: error: no matching function for call to 'max(ll, int)'
   87 |     ans += max(is2 * (is2-1) / 2,0);
      |            ~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:87:15: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   87 |     ans += max(is2 * (is2-1) / 2,0);
      |            ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:87:15: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   87 |     ans += max(is2 * (is2-1) / 2,0);
      |            ~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:88:15: error: no matching function for call to 'max(ll, int)'
   88 |     ans += max(not2 * (not2-1) / 2,0);
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:88:15: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   88 |     ans += max(not2 * (not2-1) / 2,0);
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:88:15: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   88 |     ans += max(not2 * (not2-1) / 2,0);
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~