unittest
{
	assert( [ "5", "1", "2", "1", "2", "2" ].parse.expand.solve == 3 );
	assert( [ "6", "4", "2", "5", "4", "2", "4" ].parse.expand.solve == 5 );
	assert( [ "7", "1", "3", "1", "2", "3", "3", "2" ].parse.expand.solve == 5 );
}



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 n = input.front.to!( long );
	auto cs = new long[ n ];
	foreach( ref c; cs )
	{
		input.popFront;
		c = input.front.to!( long );
	}
	return tuple( cs );
}

auto solve( long[] cs )
{
	long[][ long ] pss;
	auto pc = 0L;
	auto dp = new long[ 1 + cs.length ];
	dp[ 0 ] = 1;
	foreach( i, c; cs )
	{
		dp[ i + 1 ] = dp[ i ];
		if( pc == c ) continue;
		
		if( c in pss )
		{
			foreach( p; pss[ c ] )
			{
				dp[ i + 1 ] += dp[ p ];
			}
		}
		pss[ c ] ~= i;
		pc = c;
	}
	return dp[ $ - 1 ];
}
