stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

using namespace std;



const int MAX_N = 1e5;

vector<vector<int> > graph(MAX_N + 1);

vector<bool> searched(MAX_N + 1, false);



void dfs(int f) {

    for (int a : graph[f]) {

        if (!searched[a]) {

            searched[a] = true;

            dfs(a);

        }

    }

}



int main() {

    int N, M; cin >> N >> M;

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

        int x, y, z; cin >> x >> y >> z;

        graph[x].push_back(y);

        graph[y].push_back(x);

    }

    int ans = 0;

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

        if (!searched[i]) {

            searched[i] = true;

            dfs(i);

            ans++;

        }

    }

    cout << ans << endl;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <set>

using namespace std;



struct UnionFind {

    vector<int> parents;

    UnionFind(int N) : parents(N+1) {

        for (int i = 0; i < N+1; i++) parents[i] = i;

    }

    int root(int x) {

        if (parents[x] == x) {

            return x;

        } else {

            parents[x] = root(parents[x]);

            return parents[x];

        }

    }

    void unite(int x, int y) {

        int rx = root(x);

        int ry = root(y);

        if (rx != ry) {

            parents[rx] = ry;

        }

    }

    bool same(int x, int y) {

        int rx = root(x);

        int ry = root(y);

        return rx == ry;

    }

};



int main() {

    int N, M; cin >> N >> M;

    UnionFind tree(N);

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

        int x, y, z; cin >> x >> y >> z;

        tree.unite(x, y);

    }

    set<int> roots;

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

        roots.insert(tree.root(i));

    }

    cout << roots.size() << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//#pragma GCC target("avx2")

//#pragma GCC optimize("O3")

   

//#include <x86intrin.h>

#include <bits/stdc++.h>   

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

 

using namespace __gnu_pbds;

using namespace std;



template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

     

#define F first

#define S second           

#define lb lower_bound               

#define ub upper_bound

#define pb push_back

#define pf push_front    

#define ppb pop_back

#define mp make_pair                                     

#define bpp __builtin_popcountll                                                                                        

#define sqr(x) ((x) * (x)) 

#define al 0x3F3F3F3F

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

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

#define in insert

#define ppf pop_front

#define endl '\n'

//#define int long long

 

typedef unsigned long long ull;

typedef long long ll;

typedef long double ld;

typedef pair <int, int> pii;

 

const int mod = (int)1e9 + 7;

const int N = (int)3e5 + 123;

const ll inf = (ll)1e18 + 1;



const double pi = acos (-1.0);

const double eps = 1e-7;                  

const int dx[] = {0, 0, 1, 0, -1};

const int dy[] = {0, 1, 0, -1, 0};



int n, m, x[N], y[N], z[N], ans;

vector <int> g[N];

bool used[N];



void dfs (int v) {

   used[v] = 1;

   for (auto to : g[v])

      if (!used[to])

         dfs (to);

}



inline void boost () {                    

   ios_base :: sync_with_stdio (NULL);

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

}                                                     



inline void Solve () {

   cin >> n >> m;

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

      cin >> x[i] >> y[i] >> z[i];

      g[x[i]].pb (y[i]);

      g[y[i]].pb (x[i]);

   }

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

      if (!used[i])

         dfs (i), ans ++;

   cout << ans;

}



main () {                                       

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

// freopen (".out", "w", stdout);              

   boost ();

   int tt = 1;

   //cin >> tt;   

   while (tt --) {

      Solve ();

   }                                               

   return 0;      

}

                          

// Optimized solution to the same problem (faster):
/*|In The Name Of Allah|*/



#include <bits/stdc++.h>



using namespace std;



const int N = 2e5+5;



int n;

int m;

bool mark[N];

int parent[N];



int getP(int u){

    if(parent[u] == u)

        return u;

    return parent[u] = getP(parent[u]);

}



void join(int u , int v){

    u = getP(u);

    v = getP(v);

    parent[u] = v;

}



int main(){

    scanf("%d%d" , &n , &m);

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

        parent[i] = i;

    }

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

        int u , v , w;

        scanf("%d%d%d" , &u , &v , &w);

        join(u , v);

    }

    int cnt = 0;

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

        if(mark[getP(i)])

            continue;

        cnt++;

        mark[getP(i)] = 1;

    }

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

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#pragma GCC optimize(3,"Ofast","inline")

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

const int N=1e5+5;

const int M=1e6+5;

const int INF=0x3f3f3f3f;

const ull sed=31;

const ll mod=1e9+7;

const double eps=1e-9;

typedef pair<int,int>P;

typedef pair<double,double>Pd;



int n,m,ans;

bool vis[N];

vector<int>E[N];



void dfs(int x)

{

    if(vis[x]) return ;

    vis[x]=true;

    for(int i=0;i<E[x].size();i++) dfs(E[x][i]);

}

int main()

{

    scanf("%d%d",&n,&m);

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

    {

        int x,y,z;

        scanf("%d%d%d",&x,&y,&z);

        E[x].push_back(y);

        E[y].push_back(x);

    }

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

    {

        if(vis[i]) continue;

        ans++;

        dfs(i);

    }

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

    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;

using ii = pair<int, int>;



class UFDS

{

private:

    std::vector<int> size, ps;

    int count;



public:

    UFDS(int N) : size(N + 1, 1), ps(N + 1), count(N)

    {

        std::iota(ps.begin(), ps.end(), 0);

    }



    int find_set(int x) 

    {

        return x == ps[x] ? x : (ps[x] = find_set(ps[x]));

    }



    bool same_set(int x, int y)

    {

        return find_set(x) == find_set(y);        

    }



    void union_set(int x, int y)

    {

        if (same_set(x, y))

            return;



        int p = find_set(x);

        int q = find_set(y);



        if (size[p] < size[q])

            std::swap(p, q);



        ps[q] = p;

        size[p] += size[q];

        --count;

    }



    int get_count() const { return count; }

};



int solve(int N, const vector<ii>& es)

{

    UFDS ufds(N);



    for (auto p : es)

    {

        auto x = p.first, y = p.second;



        ufds.union_set(x, y);

    }



    return ufds.get_count();

}



int main()

{

    ios::sync_with_stdio(false);



    int N, M;

    cin >> N >> M;



    vector<ii> es(M);



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

    {

        int x, y, z;

        cin >> x >> y >> z;



        es.push_back(ii(x, y));

    }



    cout << solve(N, es) << endl;



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



typedef long long int lli;



int n, m, par[100001];



int root(int x) {

    if (par[x] == x) {

        return x;

    }

    else {

        return par[x] = root(par[x]);

    }

}



void unite(int x, int y) {

    x = root(x);

    y = root(y);

    if (x == y) return;



    par[x] = y;

}



int main() {

    int x, y, z;



    for (int i=0; i<100001; i++) par[i] = i;



    cin >> n >> m;

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

        cin >> x >> y >> z;

        unite(x, y);

    }



    int ans = 0;

    vector<bool> used(100001, false);

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

        int idx = root(i);

        if (!used[idx]) {

            ans++;

            used[idx] = true;

        }

    }



    cout << ans << endl;



    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;



typedef long long int lli;



class UnionFind {

private:

    vector<int> data;



public:

    UnionFind(int size) : data(size, -1) { }

    

    int root(int x) {

        return (data[x] < 0) ? x : data[x] = root(data[x]);

    }



    bool unite(int x, int y) {

        x = root(x);

        y = root(y);

        

        if (x != y) {

            if (data[y] < data[x]) swap(x, y);

            data[x] += data[y];

            data[y] = x;

        }

        return x != y;

    }



    bool find(int x, int y) {

        return root(x) == root(y);

    }



    int size(int x) {

        return -data[root(x)];

    }

};



int main() {

    int n, m, x, y, z;



    cin >> n >> m;

    

    UnionFind uf(n+1);

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

        cin >> x >> y >> z;

        uf.unite(x, y);

    }



    int ans = 0;

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

        if (uf.root(i) == i) ans++;

    }



    cout << ans << endl;



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<vector>

#include<string>

#include<cmath>

#include<algorithm>

#include <numeric>

#include<map>

#include<unordered_map>

#include <queue>

 

using namespace std;

using ll=long long;

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

#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)

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

 

bool used[100010] = {false};

vector<vector<ll>> g(100010);



void dfs(ll pos){

    used[pos] = true;

    rep(i, g[pos].size()){

        if(!used[g[pos][i]])dfs(g[pos][i]);

    }

}

int main(){

    ll n, m;

    cin >> n >> m;

    rep(i, m){

        ll x, y, z;

        cin >> x >> y >> z;

        g[x].push_back(y);

        g[y].push_back(x);

    }

    ll ans = 0;

    rep(i, n){

        if(!used[i+1]){

            ans++;

            dfs(i+1);

        }

    }

    cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

 

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

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

 

using namespace std;

using ll  = long long;

using pll = pair<ll, ll>;

using pdd = pair<double, double>;

 

const ll MOD  = 1e9+7;

const ll LINF = 1LL << 60;

const int INF = 1e9 + 7;



int mvx[] = {1, 0, 0, -1};

int mvy[] = {0, 1, -1, 0};



//union find

struct UnionFind {

    vector<ll> parent;

    vector<ll> usize;

 

    UnionFind(int n) : parent(n), usize(n, 1LL){

        rep(i, n)parent[i]=i;

    }

    

    int root(int x){

        if(parent[x] == x) return x;

        else return parent[x] = root(parent[x]);

    }

    

    bool issame(int x, int y){

        return root(x) == root(y);

    }

    

    bool merge(int x, int y) {

        x = root(x);

        y = root(y);

 

        if(x == y)return false;

 

        if(parent[x] > parent[y]) swap(x, y);



        usize[x] += usize[y];

        parent[y] = x;

 

        return true;

    }

    

    int size(int x) {

        return usize[root(x)];

    }

};



int main(){

    ll n, m;

    cin >> n >> m;



    UnionFind uf(n);



    rep(i, m){

        int x, y, z;

        cin >> x >> y >> z;

        x--, y--;



        uf.merge(x, y);

    }



    set<ll> ans;

    rep(i, n){

        ans.insert(uf.root(i));

    }



    cout << ans.size() << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

    }

}

// Optimized solution to the same problem (faster):
#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; 

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}






// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem: