stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

#define rep(i,n) for(int i = 0; i < n; i++)

using namespace std;

typedef long long ll;

typedef pair<int,int> P;

template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return 1;} return 0;}

template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return 1;} return 0;}

const long long INF = 1000000000;



ll dp[100001];



int main(void){

  int n; cin >> n;

  int h[n]; rep(i,n) cin >> h[i];

  rep(i,100001) dp[i] = INF;

  dp[0] = 0;

  for(int i = 0; i < n; i++){

    chmin(dp[i],dp[i-1]+abs(h[i] -h[i-1]));

    if(i > 1) chmin(dp[i],dp[i-2] + abs(h[i]-h[i-2]));

  }

  cout << dp[n-1] << endl;

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.8033812001357412x):
#include <bits/stdc++.h>

#define rep(i,n) for(int i = 0; i < n; i++)

using namespace std;

typedef long long ll;

typedef pair<int,int> P;



ll f[100005];



void saisho(ll h[],ll n){

  int i;

  for(i = 0; i < n; i++){

    if(i == 0){

      f[0] = 0;

    }

    else if(i == 1){

      f[1] = abs(h[1]-h[0]);

    }

    else{

      if(abs(h[i]-h[i-1]) + f[i-1] >= abs(h[i]-h[i-2]) + f[i-2]){

        f[i] = f[i-2] + abs(h[i]-h[i-2]);

      }

      else{

        f[i] = f[i-1] + abs(h[i]-h[i-1]);

      }

    }

  }

}



int main(void){

  ll n; cin >> n;

  ll h[n]; rep(i,n) cin >> h[i];

  saisho(h,n);

  cout << f[n-1] << endl;

  return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

long long int dp[1000000];

int main(void)

{

	long long int n;

	cin>>n;

	long long int a[n], i;

	for(i=0; i<n; i++)

	{

		cin>>a[i];

	}

	for(i=0; i<1000000; i++)

		dp[i]=-1;

	if(n==2)

	{

		cout<<abs(a[0]-a[1])<<endl;

		return 0;

	}

	dp[0]=a[0];

	dp[1]=abs(a[0]-a[1]);

	dp[2]=abs(a[0]-a[2]);

	for(i=3; i<n; i++)

	{

		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));

	}

	cout<<dp[n-1]<<endl;

	return 0;

	



}

// Faster C++ solution for the same problem (measured speedup: 9.392965080856492x):
#include "bits/stdc++.h"

#define ll long long int

#define pb push_back

#define mp make_pair

#define ff first

#define ss second

#define all(a) a.begin(),a.end()

using namespace std;

int main(void)

{

	ll n;

	cin>>n;

	ll a[n], i;

	for(i=0; i<n; i++)

		cin>>a[i];

	ll ans[n];

	ans[n-1] = 0;

	ans[n-2] = abs(a[n-1]-a[n-2]);

	for(i=n-3; i>=0; i--)

		ans[i] = min(ans[i+1] + abs(a[i]-a[i+1]), ans[i+2] + abs(a[i]-a[i+2]));

	cout<<ans[0]<<"\n";

}
// Slower C++ solution:
// 10/06/19 // 10:03 AM //



#include <iostream>

#include <cmath>

#include <cstring>



using namespace std;



#define MAXN 100010



int n;

int h[MAXN];

int memo[MAXN];



int funcao(int i){

    if(memo[i]>=0) return memo[i];



    if(i>=n) return 0;



    if(i==n-1)

        return memo[i] = abs(h[i]-h[i+1])+funcao(i+1);



    return memo[i] = min(abs(h[i]-h[i+1])+funcao(i+1),abs(h[i]-h[i+2]) + funcao(i+2));

}



int main(){



    memset(memo, -1, sizeof(memo));



    cin >> n;



    for(int i=1; i<=n; i++) cin >> h[i];



    cout << funcao(1) << "\n";



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.3955102746808006x):
// 14/06/19 // 02:02 AM //



#include <iostream>

#include <cmath>



using namespace std;



#define MAXN 100010



int n;

int h[MAXN];

int memo[MAXN];



int bottom_up(){



    memo[0] = MAXN;



    for(int i=2; i<=n; i++){

        memo[i] = min(memo[i-1]+abs(h[i]-h[i-1]), memo[i-2] + abs(h[i]-h[i-2]) );

    }



    return memo[n];

}



int main(){



    cin >> n;



    for(int i=1; i<=n; i++) cin >> h[i];



    cout << bottom_up() << "\n";



    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n;

int dpt[100001];

vector<int> h;

int frog(int i){

	if(i<=1)

		return 0;

	if(dpt[i]!=-1){

			return dpt[i];

		}

	if(i>2)

		return dpt[i]=min(frog(i-1)+abs(h[i]-h[i-1]),frog(i-2)+abs(h[i]-h[i-2]));

	if(i==2){

		return dpt[i]=frog(i-1)+abs(h[i]-h[i-1]);

	}

}



int main(){

	cin>>n;

	h.push_back(0);

	int k;

	for(int i=0;i<n;i++){

		cin>>k;

		h.push_back(k);

	}

	for(int i=0;i<=100001;i++)

		dpt[i]=-1;

	cout<<frog(n);

}

// Faster C++ solution for the same problem (measured speedup: 1.403662486899097x):
#include<bits/stdc++.h>

using namespace std;

int main(){

  int n; cin>>n;

  int arr[n];

  for(int i=0;i<n;i++) cin>>arr[i];

  int ans[n]; ans[0]=0; ans[1]=abs(arr[1]-arr[0]);

  for(int i=2;i<n;i++){

    ans[i]=min(ans[i-1]+abs(arr[i]-arr[i-1]),ans[i-2]+abs(arr[i]-arr[i-2]));

  }

  cout<<ans[n-1];

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int main()

{

  int n;

  int h[100005] = {};

  int dp[100005] = {};



  cin >> n;



  for(int i=0; i<n; i++) cin >> h[i];



  dp[0] = 0;

  dp[1] = abs(h[0] - h[1]);

  for(int i=2; i<n; i++){

    dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1] , abs(h[i] - h[i-2]) + dp[i-2]);

  }

  cout << dp[n-1] << endl;

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.7836000970001913x):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()

{

  int dp[100005],h[100005];

  int n;

  cin >> n;

  for(int i=0; i<n; i++) cin >> h[i];

  

  dp[0] = 0;

  dp[1] = abs(h[1] - h[0]);



  for(int i=2; i<n; i++){

    dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1] , abs(h[i] - h[i-2]) + dp[i-2]);

  }



  cout << dp[n-1] << endl;

  return 0;

}
// Slower C++ solution:
#include <iostream>

#include <bits/c++io.h>

#include <vector>

#include <tuple>

#include <queue>

#define N 100

#define INF 1e9 + 5

using namespace std;



int solve(int k, vector<int> &c,vector<int> &dp){

    

    if(k==1){

        return 0;

    }

    if(k<1){

        return INF;

    }

    if(dp[k]) return dp[k];

    return dp[k] = min( solve(k-1,c,dp)+abs(c[k]-c[k-1]), solve(k-2,c,dp)+abs(c[k]-c[k-2]));

}





int main()

{

    int n;

    scanf("%d", &n);

    vector<int> v(n+1);

    vector<int> dp(100001,INF);

    for (int i =0;i<n;i++)

    {

        scanf("%d", &v[i]);

    }

    //재귀로 풀어봅시다. 

    //solve 는 n일 때 최소가 되는 값을 반환하는 함수라고 합시다. 

    

    // printf("%d",solve(n, v, dp));



    //선형으로 풀어봅시다.

    dp[0]=0; 

    for(int i =0;i<n;i++){

        for(auto j:{i+1,i+2}){

            dp[j] = min( dp[j], dp[i]+abs(v[j]-v[i]) );

        }

    }

    cout<<dp[n-1];

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4087359153882801x):
#include <iostream>

#include <bits/c++io.h>

#include <vector>

#include <tuple>

#include <queue>

#define N 100

#define INF 1e9 + 5

using namespace std;



#include <iostream>

#include <bits/c++io.h>

#include <vector>

#include <tuple>

#include <queue>

#define N 100

#define INF 1e9 + 5

using namespace std;

 

int solve(int k, vector<int> &c,vector<int> &dp){

    

    if(k==1){

        return 0;

    }

    if(k<1){

        return INF;

    }

    if(dp[k]!=-1) return dp[k];

    

    return dp[k] = min( solve(k-1,c,dp)+abs(c[k]-c[k-1]), solve(k-2,c,dp)+abs(c[k]-c[k-2]));

}

//20          10

//10 30     20



int main()

{

    int n;

    scanf("%d", &n);

    vector<int> c(n+1);

    vector<int> dp(n+1,-1);

    for (int i=1;i<=n;i++){

        scanf("%d", &c[i]);

    }

    //재귀로 풀어봅시다. 

    //solve 는 n일 때 최소가 되는 값을 반환하는 함수라고 합시다. 

    dp[0]=INF;

    printf("%d",solve(n, c, dp));

    //선형으로 풀어봅시다.

    // dp[0]=0; 

    // for(int i =0;i<n;i++){

    //     for(auto j:{i+1,i+2}){

    //         dp[j] = min( dp[j], dp[i]+abs(v[j]-v[i]) );

    //     }

    // }

    // cout<<dp[n-1];



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



#define el				'\n'

#define sz(v)			((int)((v).size()))

#define all(v)          ((v).begin()),((v).end())

#define clr(v, d)		memset(v, d, sizeof(v))



double const EPS = 1e-8, PI = acos(-1);

const int N = 1e5 + 9, M = 1e5 + 9, OO = (int) 1e6 + 1;

const long long MOD = 1e9 + 7;



typedef long long ll;



void OUTPUT() {

	cout << fixed << setprecision(0);

	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

}



void READ() {

	freopen("input.txt", "r", stdin);

	//	freopen("output.txt", "w", stdout);

}

int n, heights[N], mem[N];



ll dp(int i) {

	if (i >= n)

		return OO;

	if (i == n - 1)

		return 0;

	if (mem[i] != -1)

		return mem[i];

	ll a = dp(i + 1) + abs(heights[i] - heights[i + 1]);

	ll b = dp(i + 2) + abs(heights[i] - heights[i + 2]);

//	cout << i << " " << a << " " << b << el;

	mem[i] = min(a, b);

	return mem[i];



}



int main() {

//	READ();

	OUTPUT();

	clr(mem, -1);

	cin >> n;

	for (int i = 0; i < n; ++i) {

		cin >> heights[i];

	}

	cout << dp(0);



	return 0;



}


// Faster C++ solution for the same problem (measured speedup: 1.4203624453193693x):
#include <iostream>

#include <bits/c++io.h>

#include <vector>

#include <tuple>

#include <queue>

#define N 100

#define INF 1e9 + 5

using namespace std;



#include <iostream>

#include <bits/c++io.h>

#include <vector>

#include <tuple>

#include <queue>

#define N 100

#define INF 1e9 + 5

using namespace std;

 

int solve(int k, vector<int> &c,vector<int> &dp){

    

    if(k==1){

        return 0;

    }

    if(k<1){

        return INF;

    }

    if(dp[k]!=-1) return dp[k];

    

    return dp[k] = min( solve(k-1,c,dp)+abs(c[k]-c[k-1]), solve(k-2,c,dp)+abs(c[k]-c[k-2]));

}

//20          10

//10 30     20



int main()

{

    int n;

    scanf("%d", &n);

    vector<int> c(n+1);

    vector<int> dp(n+1,-1);

    for (int i=1;i<=n;i++){

        scanf("%d", &c[i]);

    }

    //재귀로 풀어봅시다. 

    //solve 는 n일 때 최소가 되는 값을 반환하는 함수라고 합시다. 

    dp[0]=INF;

    printf("%d",solve(n, c, dp));

    //선형으로 풀어봅시다.

    // dp[0]=0; 

    // for(int i =0;i<n;i++){

    //     for(auto j:{i+1,i+2}){

    //         dp[j] = min( dp[j], dp[i]+abs(v[j]-v[i]) );

    //     }

    // }

    // cout<<dp[n-1];



    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define ld  double

#define mod 998244353

//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int n;

int arr[100000+9];

ll dp[100000][2];

ll solve(int ind , int last) {

    if (ind+1 == n) {

        return 0;

    }

    if(dp[ind][last] != -1)

        return dp[ind][last];

    ll a = 1e10;

    if (ind + 1 < n)

        a = min(a, solve(ind + 1, 0) + abs(arr[ind] - arr[ind + 1]));

    if (ind + 2 < n) {

        a = min(a, solve(ind + 2, 1) + abs(arr[ind + 2] - arr[ind]));

    }

    return dp[ind][last] = a;

}

int main() {

    cin>>n;

    for(int i = 0;i<n;i++){

        cin>>arr[i];

    }

    memset(dp,-1, sizeof(dp));

    cout<<solve(0,0);

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.600340250020531x):
#include<bits/stdc++.h>

#define ll long long

using namespace std;

int dp[100000+9];

int main(){

    int n;

    scanf("%d",&n);

    int arr[n];

    for(int i = 0;i<n;i++)

        cin>>arr[i];

    dp[0] = 0;

    dp[1] = abs(arr[1] - arr[0]);

    for(int i =2 ; i<n;i++){

        dp[i] = min(abs(arr[i]-arr[i-1]) + dp[i-1] ,abs(arr[i] - arr[i-2]) + dp[i-2] );

    }

    printf("%d",dp[n-1]);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int main(void){

    

    int N;

    int h[100000] = {};

    

    cin >> N;

    for(int i = 0; i < N; i++){

        cin >> h[i];

    }

    

    // DPの宣言と初期値を設定

    long long dp[100001];

    dp[0] = 0;

    dp[1] = abs(h[1]-h[0]);

    

    for(int i = 1; i < N-1; i++){

        int jump_One = dp[i] + abs(h[i+1] - h[i]);

        int jump_Tow = dp[i-1] + abs(h[i+1] - h[i-1]);

        dp[i+1] = min(jump_One, jump_Tow);

    }



    cout << dp[N-1] << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.3970706463132032x):
#include <bits/stdc++.h>

using namespace std;

int main(void){

    

    int N;

    cin >> N ;

    int h[100010];

    for(int i = 1; i <= N; i++){

        cin >> h[i];

    }

    

    int dp[100010];

    dp[0] = 0;

    dp[1] = abs(h[2] - h[1]);

    

    for(int i = 2; i < N; i++){

        dp[i] = min(dp[i-1] + abs(h[i+1] - h[i]), dp[i-2] + abs(h[i+1] - h[i-1]));

    }

    

    cout << dp[N-1] << endl;

    





}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int main(void){

    

    int N;

    int h[100000] = {};

    

    cin >> N;

    for(int i = 0; i < N; i++){

        cin >> h[i];

    }

    

    // DPの宣言と初期値を設定

    long long dp[100001];

    dp[0] = 0;

    dp[1] = abs(h[1]-h[0]);

    

    for(int i = 2; i < N; i++){

        dp[i] = min( dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]) );

    }



    cout << dp[N-1] << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.3972167799415305x):
#include <bits/stdc++.h>

using namespace std;

int main(void){

    

    int N;

    cin >> N ;

    int h[100010];

    for(int i = 1; i <= N; i++){

        cin >> h[i];

    }

    

    int dp[100010];

    dp[0] = 0;

    dp[1] = abs(h[2] - h[1]);

    

    for(int i = 2; i < N; i++){

        dp[i] = min(dp[i-1] + abs(h[i+1] - h[i]), dp[i-2] + abs(h[i+1] - h[i-1]));

    }

    

    cout << dp[N-1] << endl;

    





}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int main(void){

    

    int N;

    int h[100000] = {};

    

    cin >> N;

    for(int i = 0; i < N; i++){

        cin >> h[i];

    }

    

    // DPの宣言と初期値を設定

    long long dp[100001];

    dp[0] = 0;

    dp[1] = abs(h[1]-h[0]);

    

    for(int i = 1; i < N-1; i++){

        int jump_One = dp[i] + abs(h[i+1] - h[i]);

        int jump_Tow = dp[i-1] + abs(h[i+1] - h[i-1]);

        dp[i+1] = min(jump_One, jump_Tow);

    }



    cout << dp[N-1] << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.3970431121562623x):
#include <bits/stdc++.h>

using namespace std;

int main(void){

    

    int N;

    cin >> N;

    int h[100010];

    for(int i = 1; i <= N; i++){

        cin >> h[i];

    }

    

    int dp[100010];

    dp[0] = 0;

    dp[1] = abs(h[2] - h[1]);

    

    for(int i = 1; i < N; i++){

        dp[i+1] = dp[i] + abs(h[i+2] - h[i+1]);

        dp[i+1] = min(dp[i+1], dp[i-1] + abs(h[i+2] - h[i]));

    }

    

    cout << dp[N-1] << endl;

    





}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int main(void){

    

    int N;

    int h[100000] = {};

    

    cin >> N;

    for(int i = 0; i < N; i++){

        cin >> h[i];

    }

    

    // DPの宣言と初期値を設定

    long long dp[100001];

    dp[0] = 0;

    dp[1] = abs(h[1]-h[0]);

    

    for(int i = 2; i < N; i++){

        dp[i] = min( dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]) );

    }



    cout << dp[N-1] << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.3971892429045158x):
#include <bits/stdc++.h>

using namespace std;

int main(void){

    

    int N;

    cin >> N;

    int h[100010];

    for(int i = 1; i <= N; i++){

        cin >> h[i];

    }

    

    int dp[100010];

    dp[0] = 0;

    dp[1] = abs(h[2] - h[1]);

    

    for(int i = 1; i < N; i++){

        dp[i+1] = dp[i] + abs(h[i+2] - h[i+1]);

        dp[i+1] = min(dp[i+1], dp[i-1] + abs(h[i+2] - h[i]));

    }

    

    cout << dp[N-1] << endl;

    





}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

 

typedef long long ll;

typedef pair<int, int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

 

template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}

template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}



const int NM = 1e5+10;

const ll INF = 1LL << 60;

ll h[NM];

ll dp[NM];



int main() {

    int N; cin >> N;

    rep(i, N) {

        cin >> h[i];

    }

    rep(i, NM) dp[i] = INF;

    dp[0] = 0;

    for(int i=0; i<N; i++) {

       dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]));

       if(i+2 < N){

            dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]));

       }

    }

    cout << dp[N-1] << endl;



}

// Faster C++ solution for the same problem (measured speedup: 1.7656579415832714x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<int, int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

#define all(x) (x).begin(),(x).end()

template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}

template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

const ll INF = 1LL << 60;



//dp_a

int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n;cin>>n;

    vector<int> h(n+2, 0);

    rep(i,n){

        cin>>h[i];

    }

    vector<ll> dp(n+2, INF);

    dp[0]=0;

    for(int i=0;i<n;i++){

        chmin(dp[i+1], dp[i]+abs(h[i+1]-h[i]));

        chmin(dp[i+2], dp[i]+abs(h[i+2]-h[i]));

    }

    cout<<dp[n-1]<<endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define REP(i, a, b) for(int i = (a); i <= (b); i++)

#define PER(i, a, b) for(int i = (a); i >= (b); i--)

#define rep(i, a, b) for(int i = (a); i < (b); i++)

#define debug(x) cerr << #x << " = " << x << endl;

#define SET(c, v) memset(c, v, sizeof c)

#define pi 3.14159265358979323846264338

#define all(S) (S).begin(), (S).end()

#define INF 0x3f3f3f3f

#define mod 1000000007

#define pf push_front

#define pb push_back

#define mk make_pair

#define MAX 100000

#define MA1 10000



#define S second

#define F first

typedef long long ll;

typedef long double lf;

typedef pair<int, int> ii;

typedef pair<int, ii> pii;

typedef unsigned long long int ull;

int v[MAX], pd[MAX], N;



int solve(int i) {

	int &ans = pd[i];

	if(i == N-1) return 0;

	if(i >= N) return 1 << 30;

	if(ans != -1) return ans;

	return ans = min(solve(i+1) + abs(v[i] - v[i+1]), solve(i+2) + abs(v[i] - v[i+2]));

}



int main(int argc, char** argv) {

	scanf("%d", &N);

	rep(i, 0, N) scanf("%d", &v[i]);

	memset(pd, -1, sizeof pd);

	printf("%d\n", solve(0));

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.4012403074631918x):
#include <bits/stdc++.h>

using namespace std;

 

#define REP(i, a, b) for(int i = (a); i <= (b); i++)

#define PER(i, a, b) for(int i = (a); i >= (b); i--)

#define rep(i, a, b) for(int i = (a); i < (b); i++)

#define all(S) (S).begin(), (S).end()

#define pf push_front

#define pb push_back

#define mk make_pair

#define S second

#define F first

typedef long long ll;

typedef long double lf;

typedef pair<int, int> ii;

const int MAX = 1e5+5;

int N, a[MAX];

ll pd[MAX];



ll solve() {

	pd[2] = abs(a[2] - a[1]);

	REP(i, 3, N) {

		pd[i] = pd[i-1]+abs(a[i]-a[i-1]);

		pd[i] = min(pd[i], pd[i-2]+abs(a[i]-a[i-2]));

	}

	return pd[N];

}



int main(int argc, char ** argv) {

	scanf("%d", &N);

	REP(i, 1, N) scanf("%d", &a[i]);

	printf("%I64d\n", solve());

	return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <cstdlib>

#include <algorithm>

#include <vector>

#define repi(i,a,b) for(int i=(a);i<(b);++i)

#define rep(i,a) repi(i,0,a)

#define all(a) (a).begin(), (a).end()



using ll = long long;



ll N;

ll A[100010];

std::vector<ll> ma, minus;

ll S;



int main()

{

  scanf( "%lld", &N );



  rep( i, N )

  {

    scanf( "%lld", A+i );



    if( A[i] >= 0 )

      ma.push_back( A[i] );

    

    if( A[i] < 0 )

      minus.push_back( -A[i] );



    S += llabs(A[i]);

  }



  std::sort( all(ma) );

  std::sort( all(minus) );



  ll ans = 0;



  if( minus.size() & 1 )

  {

    if( !minus.empty() ) rep( i, minus.size()-1 )

      ans += minus[i+1];



    if( !ma.empty() && !minus.empty() )

    {

      if( ma[0] < minus[0] )

      {

        ans += minus[0];

        ans -= ma[0];

      }

      else

      {

        ans -= minus[0];

        ans += ma[0];

      }

    }

    else

    {

      if( !ma.empty() )

        ans += ma[0];

      if( !minus.empty() )

        ans -= minus[0];

    }



    if( !ma.empty() ) rep( i, ma.size()-1 )

      ans += ma[i+1];

  }

  else

    ans = S;



  printf( "%lld\n", ans );



  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.791150807334704x):
#include <cstdio>

#include <algorithm>

#define repi(i,a,b) for(int i=(a);i<(b);++i)

#define rep(i,a) repi(i,0,a)

#define all(a) (a).begin(), (a).end()



using ll = long long;



ll N;

ll A[100010];

ll dp[100010][2];



int main()

{

  scanf( "%lld", &N );

  rep( i, N )

    scanf( "%lld", A+i );



  dp[0][0] = A[0], dp[0][1] = -A[0];



  rep( i, N )

  {

    dp[i+1][0] = std::max( dp[i][0]+A[i+1], dp[i][1]-A[i+1] );

    dp[i+1][1] = std::max( dp[i][0]-A[i+1], dp[i][1]+A[i+1] );

  }



  printf( "%lld\n", dp[N-1][0] );



  return 0;

}
// Slower C++ solution:
//   _/                _/                 _/_/_/   _/

//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/

// _/     _/    _/   _/     _/    _/  _/_/_/     _/

//_/     _/    _/   _/     _/    _/  _/    _/   _/

// _/_/   _/_/       _/_/   _/_/      _/_/     _/

#include<iostream>

#include<algorithm>

#include<cmath>

#include<iomanip>

#include<set>

#include<map>

#include<queue>

#include<vector>

using namespace std;

typedef long long ll;

const int MOD=1e9+7;

const double pi=3.14159265358979323846;

const int inf=1e9;

const ll INF=5e18;

typedef pair<int,int> P;

int main() {

  cin.tie(0),cout.tie(0);

  ios::sync_with_stdio(false);

  ll n,a[100005]={},ans=0,cnt=0,x=INF;

  cin >> n;

  for(int i=0; i<n; i++) {

    cin >> a[i];

    if(a[i]<0) {

      cnt++;

    }

    ans+=abs(a[i]);

    x=min(x,abs(a[i]));

  }

  cout << (cnt%2?ans-=2*x:ans) << endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.7998699185539087x):
//   _/                _/                 _/_/_/   _/

//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/

// _/     _/    _/   _/     _/    _/  _/_/_/     _/

//_/     _/    _/   _/     _/    _/  _/    _/   _/

// _/_/   _/_/       _/_/   _/_/      _/_/     _/

#include<iostream>

#include<algorithm>

#include<cmath>

#include<iomanip>

#include<set>

#include<map>

#include<queue>

#include<vector>

#include<random>

using namespace std;

typedef long long ll;

const int MOD=1e9+7;

const double pi=3.14159265358979323846;

const int inf=1e9;

const ll INF=1e18;

int main() {

  cin.tie(0),cout.tie(0);

  ios::sync_with_stdio(false);

  ll n,a,ans=0,cnt=0,x=inf;

  cin >> n;

  for(int i=0; i<n; i++) {

    cin >> a;

    if(a<0) {

      cnt++;

    }

    ans+=abs(a);

    x=min(x,abs(a));

  }

  cout << (cnt%2?ans-=x*2:ans) << endl;

 }
// Slower C++ solution:
#include<bits/stdc++.h>



using namespace std;

#define PROBLEM "E"

#define MAX 100010



int main(){



	#ifdef DBG

	freopen("problem" PROBLEM ".in", "r", stdin);

	freopen("problem" PROBLEM ".out", "w", stdout);

	#endif



	int N;



	cin >> N;

	long long int a[MAX];

	memset(a, 0, sizeof(a));

	int count = 0;



	for(int i = 0 ; i < N ; i++){



		cin >> a[i];

		if(a[i] < 0)

			count++;

	}



	transform(a, a+N, a, [](long long i){



		return abs(i);

	});



	int tmp = *std::min_element(a, a+N);



	if(count % 2 == 0)

		cout << accumulate(a, a+N, (long long)0) << endl;

	else

		cout << accumulate(a, a + N, (long long)0) - 2*tmp << endl;



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.7856421934584181x):
#include <iostream>

#include <vector>

#include <math.h>

using namespace std;

int main() {

    long long n,num;

    cin>>n;

    vector<long long>v;

    for(int i=0;i<n;i++){

        cin>>num;

        v.push_back(num);

    }

    long long mi = 1000000;

    int minus = 0;

    long long sum = 0;

    for(int i=0;i<v.size();i++){

        if(v[i]<0)minus++;

        mi = min(abs(v[i]),mi);

        sum += abs(v[i]);

    }

    if(minus % 2 == 1){

        sum -= 2 * mi;

        

    }

    cout<<sum<<endl;

}