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



using namespace std;



main () {

  string s; cin >> s;

  int n = s.size();

  int r = 0;

  int p = 0;

  int ans = 0;

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

    if (s[i] == 'g') {

      if (p + 1 <= r) {

        ans++;

        p++;

      } else r++;

    } else {

      if (p + 1 <= r) {

        p++;

      } else {

        r++;

        ans--;

      }

    }

  }

  cout << ans;

}


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

#include<cmath>

#include<algorithm>

#include<cstring>



using namespace std;



char orin[100005];



int main(void)

{

	int grades = 0, ok = 0;

	scanf("%s", orin);

	for (int i = 0; orin[i]; ++i)

	{

		if (orin[i] == 'g')

		{

			if (ok)

			{

				++grades;

				--ok;

			}

			else

				++ok;

		}

		else

		{

			if (ok)

				--ok;

			else

			{

				--grades;

				++ok;

			}

		}

	}

	printf("%d", grades);

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



using namespace std;

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

#define REP(i,a,b) REPP(i,a,b,1)

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

#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) REP(i,0,(int)a-1)

#define FORD(i,a) REV(i,(int)a-1,0)

#define PB push_back

#define POB pop_back

#define MP make_pair

#define FI first

#define SE second

typedef long long ll;

typedef unsigned long long ull;

typedef pair < int , int > pii;

typedef vector < int > vi;

typedef vector < pii > vii;

typedef vector < ll > vl;



const double EPS = 1e-9;

const double PI = acos(-1);

const int INF = 1e9;

const ll MOD = 1e9 + 7;



ll addMod(ll a, ll b){

	return (a+b) % MOD;

}



ll mulMod(ll a, ll b){

	return (a*b) % MOD;

}



/////////////////////////////////////////////////////////



const int N = 1e5;



string str;



int solve(){

	int cnt = 0, cnt2 = 1, ret = 0;

	if(str[0] == 'p') ret++;

	REP(i,1,str.length()-1){

		if(str[i] == 'p'){

			if(cnt+1 <= cnt2){

				cnt++;

			}

			else{

				cnt2++;

				ret--;

			}

		}

		else{

			if(cnt+1 <= cnt2){

				cnt++;

				ret++;

			}

			else cnt2++;

		}

//		printf("cnt %d, cnt2 %d -> %d\n",cnt,cnt2,ret);

	}

	return ret;

}



int main(){

	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> str;

	cout << solve() << endl;

	return 0;

}

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

#include<cmath>

#include<algorithm>

#include<cstring>



using namespace std;



char orin[100005];



int main(void)

{

	int grades = 0, ok = 0;

	scanf("%s", orin);

	for (int i = 0; orin[i]; ++i)

	{

		if (orin[i] == 'g')

		{

			if (ok)

			{

				++grades;

				--ok;

			}

			else

				++ok;

		}

		else

		{

			if (ok)

				--ok;

			else

			{

				--grades;

				++ok;

			}

		}

	}

	printf("%d", grades);

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

using namespace std;

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



int main(void){

	string s;

	cin>>s;

	int N=(int)s.size(),cnt=0;

	rep(i,N){

		if(i<=(N-1)/2){

			if(s[i]=='p')cnt--;

		}else if(s[i]=='g')cnt++;

	}

	cout<<cnt<<endl;

	return 0;

}


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

int main(void){

	char c;

	int p=0;

	while((c=getchar())!='\n'){

		if(c=='g')p++;

		else p--;

	}

	printf("%d\n",p/2);

	return 0;

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



using namespace std;



const int INF = 1 << 30;



int main()

{

  int N;

  string S;



  cin >> S;





  int sz[100001] = {}, sz2[100001] = {};

  for(int i = (int) S.size() - 1; i >= 0; i--) {

    sz[i] = sz[i + 1];

    if(S[i] == 'g') ++sz[i];

    else --sz[i];

  }



  int goo = 0, ret = -INF;

  int lost = 0;

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

    if(S[i] == 'g') ++goo;

    else if(S[i] == 'p' && goo == 0) ++lost;

    else --goo;

    ret = max(ret, -lost + min(goo, sz[i + 1]));

  }

  cout << ret << endl;

}

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



using namespace std;





int main() {

  string S;

  cin >> S;



  // グーのとき: 貯金が出来る

  // グーのとき: 貯金を使って利益を得る

  // パーのとき: 貯金が出来る

  // パーのとき: 貯金を使って利益を得る



  int ret = 0;

  for(auto &p : S) ret -= p == 'p';

  cout << ret + S.size() / 2 << endl;

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

using namespace std;



int main () {

	string s;

	int cnt = 0;

	cin >> s;

	for (int i = 0; i < s.length(); i++){

        if (i % 2 == 0){

            if (s[i] == 'p'){

                cnt--;

            }

        }

        else{

            if (s[i] == 'g'){

                cnt++;

            }

        }

	}

	cout << cnt;

}


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

#include<stdlib.h>

#include<string.h>

typedef long long ll;

char str[100005];

int main(void)

{

	int p = 0, r = 0;

	scanf("%s", str);

	int len = strlen(str);

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

		str[i] == 'p' ? p++ : r++;

	int max = len / 2;

	max = max > p ? max - p : 0;

	printf("%d\n", max);

	return 0;

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

using namespace std;



using VS = vector<string>;    using LL = long long;

using VI = vector<int>;       using VVI = vector<VI>;

using PII = pair<int, int>;   using PLL = pair<LL, LL>;

using VL = vector<LL>;        using VVL = vector<VL>;



#define ALL(a)  begin((a)),end((a))

#define RALL(a) (a).rbegin(), (a).rend()

#define PB push_back

#define EB emplace_back

#define MP make_pair

#define SZ(a) int((a).size())

#define SORT(c) sort(ALL((c)))

#define RSORT(c) sort(RALL((c)))

#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)

#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)

#define debug(x) cerr << #x << ": " << x << endl

const int INF = 1e9;                          const LL LINF = 1e16;

const LL MOD = 1000000007;                    const double PI = acos(-1.0);

int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };



/* -----  2018/02/14  Problem: 062_arc_b / Link: https://arc062.contest.atcoder.jp/tasks/arc062_b?lang=en  ----- */

/* ------問題------



シカのAtCoDeerくんは友達のTopCoDeerくんとあるゲームをして対戦しています。 

このゲームは N ターンからなります。各ターンではそれぞれのプレイヤーはじゃんけんのグーかパーを出します。

ただし、各プレイヤーは次の条件を満たす必要があります。

(※) 各ターンの後で、(今までにパーを出した回数)≦(今までにグーを出した回数)　を満たす



このゲームでの各プレイヤーの得点は、(勝ったターンの数) − (負けたターンの数) です。

AtCoDeerくんは特殊能力を持っているので、ゲームが始まる前にTopCoDeerくんの出す N ターンの手を全て知ることが出来ました。

AtCoDeerくんの各ターンでの手を決めて、AtCoDeerくんの得点を最大化してください。 TopCoDeerくんの出す手の情報は文字列 s で与えられます。

s の i(1≦i≦N) 文字目が gのときは i ターン目でTopCoDeerくんがグーを出すことを、 pのときはパーを出すことを表します。



-----問題ここまで----- */

/* -----解説等-----







----解説ここまで---- */



LL N;



LL ans = 0LL;



int main() {

	cin.tie(0);

	ios_base::sync_with_stdio(false);



	string S;

	cin >>S;

	ans = SZ(S) / 2;

	FOR(i, 0, SZ(S)) {

		if (S[i] == 'p')

			ans--;

	}





	cout << ans << "\n";



	return 0;

}


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

#include<stdlib.h>

#include<string.h>

typedef long long ll;

char str[100005];

int main(void)

{

	int p = 0, r = 0;

	scanf("%s", str);

	int len = strlen(str);

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

		str[i] == 'p' ? p++ : r++;

	int max = len / 2;

	max = max > p ? max - p : 0;

	printf("%d\n", max);

	return 0;

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

#include<cstring>

#include<string>

#include<cstdio>

using namespace std;

int main(){

	string s;

	cin>>s;

	int g=0,p=0;

	int res=0;

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

		if(g==p){

			g++;

			if(s[i]=='p'){

				res--;

			}

		}

		else if(g>p){

			if(s[i]=='g'){

				p++;

				res++;

			}

			else{

				p++;

			}

		}

	}



	cout<<res<<endl;

	return 0;

}

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

#include<stdlib.h>

#include<string.h>

typedef long long ll;

char str[100005];

int main(void)

{

	int p = 0, r = 0;

	scanf("%s", str);

	int len = strlen(str);

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

		str[i] == 'p' ? p++ : r++;

	int max = len / 2;

	max = max > p ? max - p : 0;

	printf("%d\n", max);

	return 0;

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

using namespace std;



int main () {

	string s;

	int cnt = 0;

	cin >> s;

	for (int i = 0; i < s.length(); i++){

        if (i % 2 == 0){

            if (s[i] == 'p'){

                cnt--;

            }

        }

        else{

            if (s[i] == 'g'){

                cnt++;

            }

        }

	}

	cout << cnt;

}


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

#include<cstring>

using namespace std;

char a[100008];

int main()

{

	scanf("%s",a);

	int t=strlen(a);

	int sum=0;

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

	{

	if(a[i]=='p')

	sum++;	

	}

	printf("%d\n",t/2-sum);

	

	

	

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

using namespace std;



using VS = vector<string>;    using LL = long long;

using VI = vector<int>;       using VVI = vector<VI>;

using PII = pair<int, int>;   using PLL = pair<LL, LL>;

using VL = vector<LL>;        using VVL = vector<VL>;



#define ALL(a)  begin((a)),end((a))

#define RALL(a) (a).rbegin(), (a).rend()

#define PB push_back

#define EB emplace_back

#define MP make_pair

#define SZ(a) int((a).size())

#define SORT(c) sort(ALL((c)))

#define RSORT(c) sort(RALL((c)))

#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)

#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)

#define debug(x) cerr << #x << ": " << x << endl

const int INF = 1e9;                          const LL LINF = 1e16;

const LL MOD = 1000000007;                    const double PI = acos(-1.0);

int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };



/* -----  2018/02/14  Problem: 062_arc_b / Link: https://arc062.contest.atcoder.jp/tasks/arc062_b?lang=en  ----- */

/* ------問題------



シカのAtCoDeerくんは友達のTopCoDeerくんとあるゲームをして対戦しています。 

このゲームは N ターンからなります。各ターンではそれぞれのプレイヤーはじゃんけんのグーかパーを出します。

ただし、各プレイヤーは次の条件を満たす必要があります。

(※) 各ターンの後で、(今までにパーを出した回数)≦(今までにグーを出した回数)　を満たす



このゲームでの各プレイヤーの得点は、(勝ったターンの数) − (負けたターンの数) です。

AtCoDeerくんは特殊能力を持っているので、ゲームが始まる前にTopCoDeerくんの出す N ターンの手を全て知ることが出来ました。

AtCoDeerくんの各ターンでの手を決めて、AtCoDeerくんの得点を最大化してください。 TopCoDeerくんの出す手の情報は文字列 s で与えられます。

s の i(1≦i≦N) 文字目が gのときは i ターン目でTopCoDeerくんがグーを出すことを、 pのときはパーを出すことを表します。



-----問題ここまで----- */

/* -----解説等-----







----解説ここまで---- */



LL N;



LL ans = 0LL;



int main() {

	cin.tie(0);

	ios_base::sync_with_stdio(false);



	string S;

	cin >>S;

	ans = SZ(S) / 2;

	FOR(i, 0, SZ(S)) {

		if (S[i] == 'p')

			ans--;

	}





	cout << ans << "\n";



	return 0;

}


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

#include<cstring>

using namespace std;

char a[100008];

int main()

{

	scanf("%s",a);

	int t=strlen(a);

	int sum=0;

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

	{

	if(a[i]=='p')

	sum++;	

	}

	printf("%d\n",t/2-sum);

	

	

	

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

#include<cstring>

#include<string>

#include<cstdio>

using namespace std;

int main(){

	string s;

	cin>>s;

	int g=0,p=0;

	int res=0;

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

		if(g==p){

			g++;

			if(s[i]=='p'){

				res--;

			}

		}

		else if(g>p){

			if(s[i]=='g'){

				p++;

				res++;

			}

			else{

				p++;

			}

		}

	}



	cout<<res<<endl;

	return 0;

}

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

#include<cstring>

using namespace std;

char a[100008];

int main()

{

	scanf("%s",a);

	int t=strlen(a);

	int sum=0;

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

	{

	if(a[i]=='p')

	sum++;	

	}

	printf("%d\n",t/2-sum);

	

	

	

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

using namespace std;

int a[200005], price[200005];

int main()

{

    int n, tot = 0;

    cin >> n;

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

    {

        cin >> a[i];

    }

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

    {

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

    }

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

    {

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

        cout << price[i] << endl;

    }

}

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

#include <cstdlib>



using namespace std;



const int N = 111111;



int a[N];

long long pre[N];

long long suf[N];



int main() {

  int n;

  scanf("%d", &n);

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

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

  }

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

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

  }

  for (int i = n; i > 0; --i) {

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

  }

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

    printf("%lld\n", pre[i - 1] + abs(a[i - 1] - a[i + 1]) + suf[i + 1]);

  }

  return 0; 

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



using namespace std;



int main()

{

    int n;

    cin>>n;

    long long int arr[n+2],dp[n+2];

    memset(dp,0,sizeof(dp));

    arr[0]=0;

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

        cin>>arr[i];

        if(i==1)

            dp[i]=abs(arr[i]);

        else

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

    }



    dp[0]=0;

    arr[0]=0;

    arr[n+1]=0;

    dp[n+1]=abs(arr[n]);

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

        dp[i]+=dp[i-1];

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

    {

        long long int pre=0,ans=dp[n+1];

        ans-=abs(arr[i]-arr[i-1]);

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

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

        cout<<ans<<endl;

    }

    return 0;

}


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

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN int(1e5)

int n,tot;

int poi[MAXN+5];

int main()

{

    //freopen("in.txt","r",stdin);

    scanf("%d",&n);

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

        scanf("%d",&poi[i]),tot+=abs(poi[i-1]-poi[i]);

    tot+=abs(poi[n]);

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

    {

        int ans=tot;

        if(i==n)

            ans=ans-abs(poi[n])-abs(poi[n-1]-poi[n])+abs(poi[n-1]);

        else

            ans=ans-abs(poi[i-1]-poi[i])-abs(poi[i]-poi[i+1])+abs(poi[i-1]-poi[i+1]);

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

    }

    return 0;

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

using namespace std;

#define faster_io ios_base::sync_with_stdio(0);

#define ll long long



int main()

{

    faster_io;



    int n,i,j,k,temp=0,sum=0,sum1;

    cin>>n;

    int a[n+5],b[n+5];

    a[0]=0;

    a[n+1]=0;

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

        cin>>a[i];

        b[i]=abs(temp-a[i]);

        temp=a[i];

        sum+=b[i];

    }



    b[i]=abs(a[n]-0);

    sum+=b[i];

    sum1=sum;



    for(i=0,j=1;j<=n;i++,j++){

        sum-=(b[j]+b[j+1]);

        sum+=(abs(a[j-1]-a[j+1]));

        cout<<sum<<endl;

        sum=sum1;

    }



    return 0;

}






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

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN int(1e5)

int n,tot;

int poi[MAXN+5];

int main()

{

    //freopen("in.txt","r",stdin);

    scanf("%d",&n);

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

        scanf("%d",&poi[i]),tot+=abs(poi[i-1]-poi[i]);

    tot+=abs(poi[n]);

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

    {

        int ans=tot;

        if(i==n)

            ans=ans-abs(poi[n])-abs(poi[n-1]-poi[n])+abs(poi[n-1]);

        else

            ans=ans-abs(poi[i-1]-poi[i])-abs(poi[i]-poi[i+1])+abs(poi[i-1]-poi[i+1]);

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

    }

    return 0;

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

#include<stdlib.h>

using namespace std;

int main()

{

    int n;

    cin>>n;

    int ar[n+2];

    long long sum=0;

    ar[0]=0;

    ar[n+1]=0;

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

    {

        cin>>ar[i];

        sum+=abs(ar[i]-ar[i-1]);

    }

    sum+=abs(0-ar[n]);

    //cout<<sum<<endl;

    long long res=0;

    long long res1=0;

    long long tem=sum;

    for(int j=1;j<=n;j++)

    {

        sum=tem;

        res+=abs(ar[j]-ar[j-1])+abs(ar[j+1]-ar[j]);

        //cout<<"abs(ar[j]-ar[j-1])="<<abs(ar[j]-ar[j-1])<<"   abs(ar[j+1]-ar[j])="<<abs(ar[j+1]-ar[j])<<endl;

        res1+=abs(ar[j+1]-ar[j-1]);

        //cout<<"res="<<res<<" res1="<<res1<<endl;

        sum-=res;

        sum+=res1;



        cout<<sum<<endl;

        sum=0;

        res=0;

        res1=0;

    }







    return 0;

}


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

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN int(1e5)

int n,tot;

int poi[MAXN+5];

int main()

{

    //freopen("in.txt","r",stdin);

    scanf("%d",&n);

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

        scanf("%d",&poi[i]),tot+=abs(poi[i-1]-poi[i]);

    tot+=abs(poi[n]);

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

    {

        int ans=tot;

        if(i==n)

            ans=ans-abs(poi[n])-abs(poi[n-1]-poi[n])+abs(poi[n-1]);

        else

            ans=ans-abs(poi[i-1]-poi[i])-abs(poi[i]-poi[i+1])+abs(poi[i-1]-poi[i+1]);

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

    }

    return 0;

}
// Slower C++ solution:


#include<bits/stdc++.h>

#define optimize  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long int

#define pb push_back



using namespace std;



int main()

{

    optimize;



   ll s=0;

   int n;



   cin>>n;



   int a[n];

   cin>>a[0];

   s = abs(0-a[0]);

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

      cin>>a[i];



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



   }



   s = s + abs(0-a[n-1]);

   ll ss = s;

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

    ss  = s;

    if(i==0){

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

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

        cout<<ss<<endl;



    }

    else if(i==n-1){

        ss = ss - abs(a[i-1]-a[i]) - abs(a[i]-0);

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

        cout<<ss<<endl;

    }

    else{

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

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

        cout<<ss<<endl;

    }

   }



}




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

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN int(1e5)

int n,tot;

int poi[MAXN+5];

int main()

{

    //freopen("in.txt","r",stdin);

    scanf("%d",&n);

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

        scanf("%d",&poi[i]),tot+=abs(poi[i-1]-poi[i]);

    tot+=abs(poi[n]);

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

    {

        int ans=tot;

        if(i==n)

            ans=ans-abs(poi[n])-abs(poi[n-1]-poi[n])+abs(poi[n-1]);

        else

            ans=ans-abs(poi[i-1]-poi[i])-abs(poi[i]-poi[i+1])+abs(poi[i-1]-poi[i+1]);

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

    }

    return 0;

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

#define ll long long

using namespace std;



const int M = 1e5 + 7;

int a[M];



int main()

{

    int n;

    scanf("%d", &n);

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

        scanf("%d",a + i);

    }



    ll s = 0;

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

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

        //cout << s << endl;

    }



    s += abs(a[n]);



    //cout << s << endl;



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

        ll sub = 0, add = 0;

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

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

        add += abs(a[i - 2] - a[i]);

        printf("%lld\n", s - sub + add);

    }

    //cout << " s = "<< s << endl;

    ll sub = 0, add = 0;

    sub += abs(a[n - 1] - a[n]);

    sub += abs(a[n]);

    add += abs(a[n - 1]);



    //cout << sub << ' ' << add << endl;



    printf("%lld\n",s - sub + add);



    return 0;

}


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

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN int(1e5)

int n,tot;

int poi[MAXN+5];

int main()

{

    //freopen("in.txt","r",stdin);

    scanf("%d",&n);

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

        scanf("%d",&poi[i]),tot+=abs(poi[i-1]-poi[i]);

    tot+=abs(poi[n]);

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

    {

        int ans=tot;

        if(i==n)

            ans=ans-abs(poi[n])-abs(poi[n-1]-poi[n])+abs(poi[n-1]);

        else

            ans=ans-abs(poi[i-1]-poi[i])-abs(poi[i]-poi[i+1])+abs(poi[i-1]-poi[i+1]);

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

    }

    return 0;

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

#include<vector>

using namespace std;



int main() {

	int n;

	int v[100010] = { 0 };

	cin >> n;

	int s[100010];

	int t[100010] = { 0 };

	int sum = 0;

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

		cin >> v[i];

		s[i - 1] = abs(v[i] - v[i - 1]);

		if (i > 1)t[i - 1] = abs(v[i] - v[i - 2]);

		sum += s[i - 1];

	}

	s[n] = abs(0 - v[n]);

	sum += s[n];

	t[n] = abs(0 - v[n - 1]);

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

		cout << sum - (s[i] + s[i + 1]) + t[i + 1] << endl;

	}

}

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

using namespace std;

using ll = long long;

const int mod = 1e9 + 7;

const int inf = (1 << 30) - 1;

const ll infll = (1LL << 61) - 1;



#include <bits/stdc++.h>

using namespace std;



string to_string(string s)

{

    return '"' + s + '"';

}



string to_string(const char *s)

{

    return to_string((string)s);

}



string to_string(bool b)

{

    return (b ? "true" : "false");

}



template <typename A, typename B>

string to_string(pair<A, B> p)

{

    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";

}



template <typename A>

string to_string(A v)

{

    bool first = true;

    string res = "{";

    for (const auto &x : v)

    {

        if (!first)

        {

            res += ", ";

        }

        first = false;

        res += to_string(x);

    }

    res += "}";

    return res;

}



void debug_out() { cerr << endl; }



template <typename Head, typename... Tail>

void debug_out(Head H, Tail... T)

{

    cerr << " " << to_string(H);

    debug_out(T...);

}



ll N, ans = infll, sum;



int main()

{

    cin >> N;

    vector<ll> A(N + 2), cnt;

    A[0] = 0;

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

    {

        cin >> A[i];

        sum += abs(A[i] - A[i -1]);

    }

    sum += abs(A[N + 1] - A[N]);

    A[N + 1] = 0;

    cnt.push_back(A[0]);

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

    {

        cout << sum - abs(A[i - 1] - A[i]) - abs(A[i + 1] - A[i]) + abs(A[i - 1] - A[i + 1]) << endl;

    }

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

using namespace std;



#define justinlaiorz ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N = 1e5 + 2;

int n, a[N], pre[N], suf[N];



inline int abs(int a){

	return a < 0 ? -a : a;

}

int main(){

	justinlaiorz

	cin >> n;

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

	for(int i = 1; i <= n; ++i) pre[i] = pre[i-1] + abs(a[i] - a[i-1]);

	for(int i = n; i >= 1; --i) suf[i] = suf[i+1] + abs(a[i] - a[i+1]);

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

		cout << pre[i-1] + suf[i+1] + abs(a[i-1] - a[i+1]) << '\n';

	}

	return 0;

}

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

int n, a[100002], pre[100002], suf[100002];

int abs(int a){ return a < 0 ? -a : a;}

int main(){

	scanf("%d", &n);

	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]), pre[i] = pre[i-1] + abs(a[i] - a[i-1]);

	for(int i = n; i >= 1; --i) suf[i] = suf[i+1] + abs(a[i] - a[i+1]);

	for(int i = 1; i <= n; ++i) printf("%d\n", pre[i-1] + suf[i+1] + abs(a[i-1] - a[i+1]));

}