#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;


int main() {
    str S;
    cin>>S;
    ll n=S.size();
    reverse(all(S));
    vel data(2019);
    ll ans=0,tot=0,x=1;
    rep0(i,n){
       tot+=(S[i]-'0')*x;
       tot%=2019;
       if(data[tot]==0&&tot==0){data[tot]++;}
       if((S[i]-'0')!=0){data[tot]++;}
       x*=10;
       x%=2019;
    }
    rep0(i,2019){
        ll q=data[i];
        if(data[i]!=0){cout<<i<<" "<<data[i]<<endl;}
        ans+=q*(q-1)/2;
    }
    cout<<ans<<endl;
}