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 );
}

auto solve( long[] s )
{
	// dp[ i桁目 ][ 余り ] = 存在する
	auto dp = new bool[ long ][ 1 + s.length ];
	foreach( i, d; s )
	{
		dp[ i + 1 ][ d ] = 1;
		foreach( j; dp[ i ].keys )
		{
			 dp[ i + 1 ][ ( j * 10 + d ) % 2019 ] = 1;
		}
	}
	
	auto ans = 0L;
	foreach( dpp; dp )
	{
		if( 0 in dpp ) ans++;
	}
	return ans;
}
