#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;

typedef long long int ll;
typedef tree< ll, null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll mod = 1e9 + 7;

int main()
{
  ios_base::sync_with_stdio(false);
  cout.tie(0);cin.tie(0);

  string s;
  cin >> s;
  ll n = s.length();
  vector < vector < ll > > dp(n, vector < ll > (2019, 0));
  vector < ll > dp1(2019, 0), dp2(2019, 0);
  dp1[s[0] - '0'] = 1;
  ll ans = 0;
  for(int i = 1; i < n; i++){
    ll num = s[i] - '0';
    dp2[num] = 1;
    for(int j = 0; j < 2019; j++){
      dp2[(10 * j + num) % 2019] += dp1[j];
    }
    ans += dp2[0];
    dp1 = dp2;
    dp2.assign(2019, 0);
  }

  cout << ans << '\n';
}
