unittest
{
	assert( [ "2 0", "1 3" ].parse.expand.solve == 2 );
	assert( [ "1 1", "50" ].parse.expand.solve == 0 );
	assert( [ "3 0", "1 1 1" ].parse.expand.solve == 4 );
	assert( [ "45 1", "17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 66 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26" ].parse.expand.solve == 17592186044416 );
}



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

auto solve( long p, long[] as )
{
	return dfs( as )[ p ];
}

long[ 2 ] dfs( long[] as )
{
	static long[ 2 ][ long[] ] memo;
	
	if( as !in memo )
	{
		auto k = as.idup;
		auto p = as[ 0 ] % 2;
		if( as.length == 1 )
		{
			if( p == 0 ) memo[ k ] = [ 2L, 0L ];		// 食べない→0枚(偶数)、食べる→a枚(偶数)
			else         memo[ k ] = [ 1L, 1L ];		// 食べない→0枚(偶数)、食べる→a枚(奇数)
		}
		else
		{
			auto r = dfs( as[ 1 .. $ ] );
			if( p == 0 ) memo[ k ] = [ r[ 0 ] + r[ 0 ], r[ 1 ] + r[ 1 ] ];		// 食べない→r枚(偶奇引継)、食べる→a+r枚(偶奇引継)
			else         memo[ k ] = [ r[ 0 ] + r[ 1 ], r[ 1 ] + r[ 0 ] ];		// 食べない→r枚(偶奇引継)、食べる→a+r枚(偶奇反転)
		}
	}
	return memo[ as ];
}
