#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define M 1000000007
#define ll long long int
#define F first
#define S second
#define INF (int)1000000000
const int N = 1e5 + 5;
#define maax(a,b,c) max((int)a,max((int)b,(int)c))
#define miin(a,b,c) min((int)a,min((int)b,(int)c))
#define mp make_pair
#define int long long
#define all(a) a.begin(),a.end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define inf (long long) 1e18
#define vl vector<ll>
#define sz(a) (ll)a.size()
#define mem(a,b) memset(a,b,a.size())
#define fr(i,m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define fre(i,m, n) for (int i = (int)(n); i <= (int)(m); i--)
#define rall(x) (x).rbegin(), (x).rend()
#define TIME    cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef long long LL;
typedef pair<int, int> PII;
int sollve()
{  
    
	return 0;
}
bool is_prime(int n)
{
	int g=sqrt(n);
	for(int i=2;i<=g;i++)
	{
		if(n%i==0) return true;
	}
	return false;
}
int sollvve()
{
	int n;cin>>n;
	vector<string>a(n);vector<int>b(n);map<int,int>m,nn;
	fr(i,0,n) cin>>a[i],sort(all(a[i]));
	fr(i,0,n)
	{
		string c=a[i].substr(0,1),d=a[i].substr(2,1);
		b[i]=(((c[0]-'0')*7)+((d[0]-'0')*11));
		b[i]%=100,b[i]/=10;(i%2==0)?m[b[i]]++:nn[b[i]]++;
	}
	int s=0;
	for(auto x:m)
	{
		cout<<x.S<<" ";
		s+=(x.S-1);
	}
	for(auto x:nn)
	{
		cout<<x.S<<" ";
		s+=(x.S-1);
	}
	cout<<s;
	return 0;
}
int solve()
{
	vector<int>a,b;string s;getline(cin,s);
	fr(i,0,s.size())
	{
		if(s[i]==' ') b.pb(i);
    }
    int x=stoi(s.substr(0,b[0]));a.pb(x);
    fr(i,0,b.size()-1)
    {
    	x=stoi(s.substr(b[i]+1,(b[i+1]-b[i])-1));
    	a.pb(x);
	}
	x=stoi(s.substr(b[b.size()-1]+1,((s.size()-1)-b[b.size()-1])));
	a.pb(x);
	sort(all(a));int p=0,q=0;
	for(int i=a.size()-1;i>=0;i--)
	{
		(p<q)?p+=a[i]:q+=a[i];
		//cout<<p<<" "<<q<<" "<<a[i]<<"\n";	
	}
	cout<<p+1<<" "<<q<<"\n";int pp,qq=0;
	fr(i,0,a.size())
	{
		(pp<qq)?pp+=a[i]:qq+=a[i];
	}
	cout<<pp<<" "<<qq;
	TIME;
	return 0;
}
//4 3
//0 0 2 1
//2 0 1 1
//1 4 9 14
//2 3 8 13
//3 2 7 12
//4 1 6 11
//5 5 10
//6 4 9 14
//7 3 8 13
//8 2 7 12
//9 1 6 11
//10 5 10
//11 4 9 14 
int solvve()
{
	int n;cin>>n;vector<int>a(n),b(n);
	fr(i,0,n) cin>>a[i];
	b[0]=0,b[1]=abs(a[1]-a[0]);
	fr(i,1,n)
	{
		for(int j:{i+1,i+2})
		{
			if(j<n)
			{
			  b[j]=min(b[i]+abs(a[j]-a[i]),b[i-1]+abs(a[j]-a[i-1]));
			}
		}
	}
	//for(auto x:b) cout<<x<<" ";
	cout<<b[n-1]<<"\n";
	return 0;
}
int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0);
    int t=1;
    while(t--) solvve();
    //cout<<__gcd(0,6);
	return 0;	
}
//1 2 3 4 5 10 11 3 6 16
//1 2 3 3 4 5 6 10 11 16
//319-207=112+50=172
//set-> all elements are unique and sorted ^_^


Measured memory_bytes: 4760