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 ];
	
	dp[ 0 ] = 0L;
	dp[ 1 ] = ( hs[ 0 ] - hs[ 1 ] ).abs;
	foreach( i; 2 .. dp.length )
	{
		auto p2 = dp[ i - 2 ] + ( hs[ i - 2 ] - hs[ i ] ).abs;		// 2つ前から跳んできたときの累積コスト
		auto p1 = dp[ i - 1 ] + ( hs[ i - 1 ] - hs[ i ] ).abs;		// 1つ前から跳んできたときの累積コスト
		dp[ i ] = min( p2, p1 );
	}
	
	return dp[ $ - 1 ];
}
