unittest
{
	assert( [ "7 7" ].parse.expand.solve == 2 );
	assert( [ "6 0" ].parse.expand.solve == 2 );
	assert( [ "18 10" ].parse.expand.solve == 7 );
	assert( [ "100 8" ].parse.expand.solve == 45 );
	
	assert( [ "2 7" ].parse.expand.solve == 0 );		// 追加ケース
}



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 nk = input.front.split.to!( long[] );
	return tuple( nk[ 0 ], nk[ 1 ] );
}

auto solve( long n, long k )
{
debug writefln( "\nsolve( %s )", n );
	if( n <= 2 ) return 0L;
	
	const M = 11L;
	
	auto cs = new long[ M ];
	auto t = ( 1 + 2 + 3 + 8 + 9 + 10 + 15 + 16 + 17 ) % M;
	foreach( y, ref c; cs )
	{
		foreach( x; 0L .. 5L )
		{
			if( t % M == k ) c++;
			t = ( t + 9 ) % M;
		}
		t = ( t + 27 ) % M;
	}
	
	auto ans = 0L;
	auto d = 1 + ( n - 2 ) / M;
	auto r = ( n - 2 ) % M;
	foreach( y, c; cs )
	{
		if( y < r ) ans += c * d;
		else        ans += c * ( d - 1 );
	}
debug writefln( "ans = %s", ans );
	return ans;
}
