unittest
{
	assert( [ "4", "10 30 40 20" ].parse.expand.solve == 30 );
	assert( [ "2", "10 10" ].parse.expand.solve == 0 );
	assert( [ "6", "30 10 60 10 60 50" ].parse.expand.solve == 40 );
}



import std.algorithm;
import std.conv;
import std.math;
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 );
	input.popFront;
	auto hs = input.front.split.to!( long[] );
	return tuple( hs );
}

auto solve( long[] hs )
{
	auto dp = new long[ hs.length ];
	
	foreach( i; 0 .. hs.length )
	{
		for( auto ia = i + 1; ia < hs.length && ia <= i + 2; ia++ )
		{
			auto d = dp[ i ] + ( hs[ i ] - hs[ ia ] ).abs;
			if( dp[ ia ] == 0 ) dp[ ia ] = d;
			else                dp[ ia ] = min( d, dp[ ia ] );		// 一つ前で計算した値と比較して小さいほうを取る
		}
	}
	
	return dp[ hs.length - 1 ];
}
