Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

int main( void ){
	// initialize();
	string S; cin >> S;
	int N = S.size();
	int prev[ 2019 ] = {};
	ll ans = 0;

	prev[ ( int )( S[ 0 ] - '0' ) ] = 1;
	rep( i, 1, N ){
		int num = ( int )( S[ i ] - '0' );
		int now[ 2019 ] = {};
		rep( j, 0, 2019 ){
			if(prev[ j ] != 0){
				int temp = prev[ j ];
				now[ ( j * 10 + num ) % 2019 ] = temp;
			}
		}
		now[ num ]++;
		ans += now[ 0 ];
		rep( i, 0, 2019 ){
			prev[ i ] = now[ i ];
		}
	}
	cout << ans << endl;
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

int main( void ){
	// initialize();
	string S; cin >> S;
	int N = S.size();
	int prev[ 2019 ] = {};
	ll ans = 0;

	prev[ ( int )( S[ 0 ] - '0' ) ] = 1;
	rep( i, 1, N ){
		int num = ( int )( S[ i ] - '0' );
		int now[ 2019 ] = {};
		rep( j, 0, 2019 ){
			if(prev[ j ] != 0){
				int temp = prev[ j ];
				now[ ( j * 10 + num ) % 2019 ] = temp;
			}
		}
		now[ num ]++;
		ans += now[ 0 ];
		rep( i, 0, 2019 ){
			prev[ i ] = now[ i ];
		}
	}
	cout << ans << endl;
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Compiler output:
a.cc:111:10: error: redefinition of 'const ll INF'
  111 | const ll INF = 1LL << 60;
      |          ^~~
a.cc:17:10: note: 'const ll INF' previously defined here
   17 | const ll INF = 1LL << 60;
      |          ^~~
a.cc:112:11: error: redefinition of 'const int k_mod'
  112 | const int k_mod = 1e9 + 7;
      |           ^~~~~
a.cc:18:11: note: 'const int k_mod' previously defined here
   18 | const int k_mod = 1e9 + 7;
      |           ^~~~~
a.cc:113:42: error: redefinition of 'struct P<T, K>'
  113 | template <typename T, typename K> struct P {
      |                                          ^
a.cc:19:42: note: previous definition of 'struct P<T, K>'
   19 | template <typename T, typename K> struct P {
      |                                          ^
a.cc:119:3: error: conflicting declaration 'typedef struct edge edge'
  119 | } edge;
      |   ^~~~
a.cc:25:3: note: previous declaration as 'typedef struct edge edge'
   25 | } edge;
      |   ^~~~
a.cc:121:5: error: redefinition of 'int main()'
  121 | int main( void ){
      |     ^~~~
a.cc:27:5: note: 'int main()' previously defined here
   27 | int main( void ){
      |     ^~~~
a.cc:147:25: error: redefinition of 'template<class T> bool chmax(T&, T)'
  147 | template <class T> bool chmax( T& a, T b ) {
      |                         ^~~~~
a.cc:53:25: note: 'template<class T> bool chmax(T&, T)' previously declared here
   53 | template <class T> bool chmax( T& a, T b ) {
      |                         ^~~~~
a.cc:153:25: error: redefinition of 'template<class T> bool chmin(T&, T)'
  153 | template <class T> bool chmin( T& a, T b ) {
      |                         ^~~~~
a.cc:59:25: note: 'template<class T> bool chmin(T&, T)' previously declared here
   59 | template <class T> bool chmin( T& a, T b ) {
      |                         ^~~~~
a.cc:159:6: error: redefinition of 'int* eratosthenes(int)'
  159 | int* eratosthenes( int N ){
      |      ^~~~~~~~~~~~
a.cc:65:6: note: 'int* eratosthenes(int)' previously defined here
   65 | int* eratosthenes( int N ){
      |      ^~~~~~~~~~~~
a.cc:177:6: error: redefinition of 'bool bit_search(int, int)'
  177 | bool bit_search( int pattern, int N ){
      |      ^~~~~~~~~~
a.cc:83:6: note: 'bool bit_search(int, int)' previously defined here
   83 | bool bit_search( int pattern, int N ){
      |      ^~~~~~~~~~
a.cc:186:6: error: redefinition of 'void initialize()'
  186 | void initialize( void ){
      |      ^~~~~~~~~~
a.cc:92:6: note: 'void initialize()' previously defined here
   92 | void initialize( void ){
      |      ^~~~~~~~~~