Language: C++

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int) (n); i++)

template<int mod> struct ModInt {
	using ll = long long;
	int x;
	ModInt(ll a) {
		x = a % mod;
		if (x < 0) {
			x += mod;
		}
	}
	ModInt(int a) {
		x = a % mod;
		if (x < 0) {
			x += mod;
		}
	}
	ModInt() : x(0) {}
	inline ModInt& operator+=(const ModInt& rhs)
	{
		(*this) += rhs.x;
		return *this;
	}
	inline ModInt& operator+=(const int rhs)
	{
		x += rhs % mod;
		x %= mod;
		return *this;
	}
	inline ModInt& operator-=(const ModInt& rhs)
	{
		(*this) -= rhs.x;
		return *this;
	}
	inline ModInt& operator-=(const int rhs)
	{
		x += mod - rhs % mod;
		x %= mod;
		return *this;
	}
	inline ModInt& operator*=(const ModInt& rhs)
	{
		(*this) *= rhs.x;
		return *this;
	}
	inline ModInt& operator*=(const int rhs)
	{
		long long res = (long long) x * rhs;
		x = res % mod;
		return *this;
	}
	inline ModInt& operator/=(const ModInt& rhs)
	{
		(*this) /= rhs.x;
		return *this;
	}
	inline ModInt& operator/=(const int rhs)
	{
		long long res = modpow(rhs);
		(*this) *= res;
		return *this;
	}
	inline ModInt& operator=(const ModInt& rhs)
	{
		(*this) = rhs.x;
		return *this;
	}
	inline ModInt& operator=(const int rhs)
	{
		(*this).x = rhs % mod;
		return *this;
	}
	inline int operator==(const ModInt& rhs) const
	{
		return (*this) == rhs.x;
	}
	inline int operator==(const int rhs) const
	{
		return (*this).x == rhs % mod;
	}
	inline int operator!=(const ModInt& rhs) const
	{
		return (*this) != rhs.x;
	}
	inline int operator!=(const int rhs) const
	{
		return (*this).x != rhs % mod;
	}
	inline ModInt operator++(int unused)
	{
		ModInt res((*this).x);
		++(*this);
		return res;
	}
	inline ModInt& operator++()
	{
		(*this) += 1;
		return (*this);
	}
	inline ModInt operator--(int unused)
	{
		ModInt res((*this).x);
		--(*this);
		return res;
	}
	inline ModInt& operator--()
	{
		(*this) -= 1;
		return (*this);
	}
	inline ModInt operator+() const
	{
		return (*this);
	}
	inline ModInt operator-() const
	{
		(*this).x = mod - (*this).x
		(*this).x %= mod;
		return (*this);
	}
	int modpow(const int val, int p = mod - 2)
	{
		if (p == 0) return 1;
		if (p % 2) return (long long) val * modpow(val, p-1) % mod;
		long long t = modpow(val, p/2);
		int res = t * t % mod;
		return res;
	}
	operator int() const
	{
		return x;
	}
	friend ostream& operator<<(ostream& lhs, const ModInt& rhs)
	{
		lhs << rhs.x;
		return lhs;
	}
	friend istream& operator>>(istream& lhs, ModInt& rhs)
	{
		long long t;
		lhs >> t;
		rhs.x = t % mod;
		return lhs;
	}
	friend const ModInt operator+(const ModInt& lhs, const ModInt& rhs)  {return ModInt(lhs) += rhs;}
	friend const ModInt operator+(const ModInt& lhs, const int rhs)      {return ModInt(lhs) += rhs;}
	friend const ModInt operator+(int lhs, const ModInt& rhs)            {return ModInt(lhs) += rhs;}
	friend const ModInt operator-(const ModInt& lhs, const ModInt& rhs)  {return ModInt(lhs) -= rhs;}
	friend const ModInt operator-(const ModInt& lhs, const int rhs)      {return ModInt(lhs) -= rhs;}
	friend const ModInt operator-(int lhs, const ModInt& rhs)            {return ModInt(lhs) -= rhs;}
	friend const ModInt operator*(const ModInt& lhs, const ModInt& rhs)  {return ModInt(lhs) *= rhs;}
	friend const ModInt operator*(const ModInt& lhs, const int rhs)      {return ModInt(lhs) *= rhs;}
	friend const ModInt operator*(int lhs, const ModInt& rhs)            {return ModInt(lhs) *= rhs;}
	friend const ModInt operator/(const ModInt& lhs, const ModInt& rhs)  {return ModInt(lhs) /= rhs;}
	friend const ModInt operator/(const ModInt& lhs, const int rhs)      {return ModInt(lhs) /= rhs;}
	friend const ModInt operator/(int lhs, const ModInt& rhs)            {return ModInt(lhs) /= rhs;}
	friend const int    operator==(int lhs, const ModInt& rhs)           {return ModInt(lhs) == rhs;}
	friend const int    operator!=(int lhs, const ModInt& rhs)           {return ModInt(lhs) != rhs;}
};
using modint = ModInt<1000000007>;

vector<vector<vector<modint>>> dp;
string k;
int d;

modint dfs(int p, int s, int b)
{
  modint& res = dp[p][s][b];
  if (res != -1) return res;
  res = 0;
  rep(i, s[i-1] - '0' + 1) {
    res += dfs(p+1, (s + i) % d, i == s[i-1] - '0');
  }
  return res;
}

int main()
{
  cin >> k >> d;
  dp.resize(k.length()+1, vector<vector<modint>>(d, vector<modint>(2, -1)));
  cout << dfs(0, 0, 1) << endl;
}



Compiler output:
a.cc: In function 'modint dfs(int, int, int)':
a.cc:175:11: error: invalid types 'int[int]' for array subscript
  175 |   rep(i, s[i-1] - '0' + 1) {
      |           ^
a.cc:5:46: note: in definition of macro 'rep'
    5 | #define rep(i, n) for (int i = 0; i < (int) (n); i++)
      |                                              ^
a.cc:176:40: error: invalid types 'int[int]' for array subscript
  176 |     res += dfs(p+1, (s + i) % d, i == s[i-1] - '0');
      |                                        ^