unittest
{
	assert( [ "1817181712114" ].parse.expand.solve == 3 );
	assert( [ "14282668646" ].parse.expand.solve == 2 );
	assert( [ "2119" ].parse.expand.solve == 0 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.map!( ( a ) => ( a - '0' ).to!( long ) ).array;
	return tuple( s );
}

const M = 2019L;

auto solve( long[] s )
{
	long[ long ] cs;
	cs[ 0 ]++;
	{
		auto r = 0L;
		foreach_reverse( i, d; s )
		{
			r = ( r + solve2( d, s.length.signed - i ) ) % M;
			cs[ r ]++;
		}
	}
	
	auto ans = 0L;
	foreach( r, c; cs )
	{
		ans += c * ( c - 1 ) / 2;
	}
	return ans;
}

long solve2( long d, long c )
{
	static rs = [ 1L ];
	if( rs.length <= c )
	{
		auto cc = rs.length.signed;
		rs.length = c + 1;
		foreach( i; cc .. rs.length.signed )
		{
			rs[ i ] = rs[ i - 1 ] * 10 % M;
		}
	}
	return ( d * rs[ c ] ) % M;
}
