Language: C++

#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>
#include<stack>
#include<string>
#include<iomanip>
#include<algorithm>
#include<functional>
#include<cstring>
#include<utility>
#include<math.h>
using namespace std;


/**** Type Define ****/

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;

/**** Const List   ****/

const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, -1, 0, 1};
const ll NCK_MAX = 510000;
/**** General Functions ****/
ll ketawa(ll n){
  ll a=0;
  while(n!=0){
    a+=n%10;
    n/=10;
  }
  return a;
}
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return (t% M)*(t % M)%M;
    }
    return (N * RepeatSquaring(N, P-1, M))%M;
}
bool IsPrime(ll a){//order root a
  if(a==1)return false;
  for(int i=2;i*i<=a;i++){
    if(a%i==0&&a!=i){
      return false;
    }
  }
  return true;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b){
    return a  / gcd(a, b)*b;
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
  if (b == 0) {
    x = 1, y = 0; return a;
  }
  ll q = a/b, g = extgcd(b, a - q*b, x, y);
  ll z = x - q * y;
  x = y;
  y = z;
  return g;
}

ll invmod (ll a, ll m) { // a^-1 mod m
  ll x, y;
  extgcd(a, m, x, y);
  x %= m;
  if (x < 0) x += m;
  return x;
}

ll *fac, *finv, *inv;

void nCk_init(ll mod) {
  fac = new ll[NCK_MAX];
  finv = new ll[NCK_MAX];
  inv = new ll[NCK_MAX];
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < NCK_MAX; i++) {
    fac[i] = fac[i-1] * i % mod;
    inv[i] = mod - inv[mod%i] * (mod / i) % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}

ll nCk(ll n, ll k, ll mod) {
  if (fac == NULL) nCk_init(mod);
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

ll lmin(ll a, ll b) { return a > b ? b : a; };

ll lmax(ll a, ll b) { return a > b ? a : b; };

ll lsum(ll a, ll b) { return a + b; };

/**** Zip ****/

template <typename T>
class Zip {
  vector<T> d;
  bool flag;
public:
  Zip() {
    flag = false;
  }
  void add(T x) {
    d.push_back(x);
    flag = true;
  }
  ll getNum(T x) { // T need to have operator < !!
    if (flag) {
      sort(d.begin(), d.end());
      d.erase(unique(d.begin(), d.end()), d.end());
      flag = false;
    }
    return lower_bound(d.begin(), d.end(), x) - d.begin();
  }
  ll size() {
    if (flag) {
      sort(d.begin(), d.end());
      d.erase(unique(d.begin(), d.end()), d.end());
      flag = false;
    }
    return (ll)d.size();
  }
};

/**** Union Find ****/

class UnionFind {
  vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
  void init(ll n) {
    par.resize(n, 1); rank.resize(n, 0);
  }
  ll getSize(ll x) {
    return par[find(x)];
  }
  ll find(ll x) {
    if (par[x] > 0) return x;
    return -(par[x] = -find(-par[x]));
  }
  void merge(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[y] += par[x];
      par[x] = -y;
    } else {
      par[x] += par[y];
      par[y] = -x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool isSame(ll x, ll y) {
    return find(x) == find(y);
  }
};

/**** Segment Tree ****/
class SegmentTree {
public:
  vector<pair<double, double>> node;//node[0]は使用しない
  ll n;//データの個数(nodeの最下層には何個並んでいるか)
  pair<double, double> initial_value;//初期値
public:
  void Init(ll n_,pair<double, double> initial_value_){
    n=1;
    while(n<n_)n*=2;
    node.resize(2*n);
    for(ll i=0;i<2*n;i++){
      node[i]=initial_value_;
    }
    initial_value=initial_value_;
  }
  void Update(ll k,pair<double, double> a){
    //node[k]をaにする
    //それに従って先祖も変わっていく
    k+=n;
    node[k]=a;
    while(k>1){
      k=k/2;
      node[k]=pair<double, double>(node[k*2].first*node[k*2+1].first,node[k*2].second*node[k*2+1].first+node[k*2+1].second);
    }
  }
  /*void Watch(){
    for(ll i=0;i<2*n;i++){
      cout<<node[i]<<endl;
    }
  }*/
  double Query(){//[a,b)
    return node[1].first+node[1].second;
  }
};


/**** LIS ****/
ll lis(ll* a, ll n, ll* dp) {
  fill(dp, dp + n, INF);//INFを代入
  for (ll i = 0; i < n; i++) *lower_bound(dp, dp + n, a[i]) = a[i];
  return (ll)(lower_bound(dp, dp + n, INF) - dp);
}


/**** main function ****/
string s,t={};
ll h,w,n,m;
double dp[1000][1000];
ll ans;
vector<ll> vec;
ll zenbu;
int main(){
    cin>>n;
    vec.push_back(0);
    for(ll i=0;i<n;i++){
      cin>>m;
      vec.push_back(m);
    }
    vec.push_back(0);
    for(ll i=0;i<n+1;i++){
      zenbu+=labs(vec[i+1]-vec[i]);
    }
    for(ll i=1;i<=n;i++){
      if(vec[i-1]<=vec[i]&&vec[i+1]<=vec[i]){
        cout<<zenbu-lmin(vec[i]-vec[i+1],vec[i]-vec[i-1])*2<<endl;
      }else if(vec[i-1]>=vec[i]&&vec[i+1]>=vec[i]){
        cout<<zenbu-lmin(vec[i-1]-vec[i],vec[i+1]-vec[i])*2<<endl;
      }else{
        cout<<zenbu<<endl;
      }
    }

}
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>
#include<stack>
#include<string>
#include<iomanip>
#include<algorithm>
#include<functional>
#include<cstring>
#include<utility>
#include<math.h>
using namespace std;


/**** Type Define ****/

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;

/**** Const List   ****/

const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, -1, 0, 1};
const ll NCK_MAX = 510000;
/**** General Functions ****/
ll ketawa(ll n){
  ll a=0;
  while(n!=0){
    a+=n%10;
    n/=10;
  }
  return a;
}
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return (t% M)*(t % M)%M;
    }
    return (N * RepeatSquaring(N, P-1, M))%M;
}
bool IsPrime(ll a){//order root a
  if(a==1)return false;
  for(int i=2;i*i<=a;i++){
    if(a%i==0&&a!=i){
      return false;
    }
  }
  return true;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b){
    return a  / gcd(a, b)*b;
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
  if (b == 0) {
    x = 1, y = 0; return a;
  }
  ll q = a/b, g = extgcd(b, a - q*b, x, y);
  ll z = x - q * y;
  x = y;
  y = z;
  return g;
}

ll invmod (ll a, ll m) { // a^-1 mod m
  ll x, y;
  extgcd(a, m, x, y);
  x %= m;
  if (x < 0) x += m;
  return x;
}

ll *fac, *finv, *inv;

void nCk_init(ll mod) {
  fac = new ll[NCK_MAX];
  finv = new ll[NCK_MAX];
  inv = new ll[NCK_MAX];
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < NCK_MAX; i++) {
    fac[i] = fac[i-1] * i % mod;
    inv[i] = mod - inv[mod%i] * (mod / i) % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}

ll nCk(ll n, ll k, ll mod) {
  if (fac == NULL) nCk_init(mod);
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

ll lmin(ll a, ll b) { return a > b ? b : a; };

ll lmax(ll a, ll b) { return a > b ? a : b; };

ll lsum(ll a, ll b) { return a + b; };

/**** Zip ****/

template <typename T>
class Zip {
  vector<T> d;
  bool flag;
public:
  Zip() {
    flag = false;
  }
  void add(T x) {
    d.push_back(x);
    flag = true;
  }
  ll getNum(T x) { // T need to have operator < !!
    if (flag) {
      sort(d.begin(), d.end());
      d.erase(unique(d.begin(), d.end()), d.end());
      flag = false;
    }
    return lower_bound(d.begin(), d.end(), x) - d.begin();
  }
  ll size() {
    if (flag) {
      sort(d.begin(), d.end());
      d.erase(unique(d.begin(), d.end()), d.end());
      flag = false;
    }
    return (ll)d.size();
  }
};

/**** Union Find ****/

class UnionFind {
  vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
  void init(ll n) {
    par.resize(n, 1); rank.resize(n, 0);
  }
  ll getSize(ll x) {
    return par[find(x)];
  }
  ll find(ll x) {
    if (par[x] > 0) return x;
    return -(par[x] = -find(-par[x]));
  }
  void merge(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[y] += par[x];
      par[x] = -y;
    } else {
      par[x] += par[y];
      par[y] = -x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool isSame(ll x, ll y) {
    return find(x) == find(y);
  }
};

/**** Segment Tree ****/
class SegmentTree {
public:
  vector<pair<double, double>> node;//node[0]は使用しない
  ll n;//データの個数(nodeの最下層には何個並んでいるか)
  pair<double, double> initial_value;//初期値
public:
  void Init(ll n_,pair<double, double> initial_value_){
    n=1;
    while(n<n_)n*=2;
    node.resize(2*n);
    for(ll i=0;i<2*n;i++){
      node[i]=initial_value_;
    }
    initial_value=initial_value_;
  }
  void Update(ll k,pair<double, double> a){
    //node[k]をaにする
    //それに従って先祖も変わっていく
    k+=n;
    node[k]=a;
    while(k>1){
      k=k/2;
      node[k]=pair<double, double>(node[k*2].first*node[k*2+1].first,node[k*2].second*node[k*2+1].first+node[k*2+1].second);
    }
  }
  /*void Watch(){
    for(ll i=0;i<2*n;i++){
      cout<<node[i]<<endl;
    }
  }*/
  double Query(){//[a,b)
    return node[1].first+node[1].second;
  }
};


/**** LIS ****/
ll lis(ll* a, ll n, ll* dp) {
  fill(dp, dp + n, INF);//INFを代入
  for (ll i = 0; i < n; i++) *lower_bound(dp, dp + n, a[i]) = a[i];
  return (ll)(lower_bound(dp, dp + n, INF) - dp);
}


/**** main function ****/
string s,t={};
ll h,w,n,m;
double dp[1000][1000];
ll ans;
vector<ll> vec;
ll zenbu;
int main(){
    cin>>n;
    vec.push_back(0);
    for(ll i=0;i<n;i++){
      cin>>m;
      vec.push_back(m);
    }
    vec.push_back(0);
    for(ll i=0;i<n+1;i++){
      zenbu+=labs(vec[i+1]-vec[i]);
    }
    for(ll i=1;i<=n;i++){
      if(vec[i-1]<=vec[i]&&vec[i+1]<=vec[i]){
        cout<<zenbu-lmin(vec[i]-vec[i+1],vec[i]-vec[i-1])*2<<endl;
      }else if(vec[i-1]>=vec[i]&&vec[i+1]>=vec[i]){
        cout<<zenbu-lmin(vec[i-1]-vec[i],vec[i+1]-vec[i])*2<<endl;
      }else{
        cout<<zenbu<<endl;
      }
    }

}


Compiler output:
a.cc:277:10: error: redefinition of 'const ll INF'
  277 | const ll INF = 1LL << 60;
      |          ^~~
a.cc:26:10: note: 'const ll INF' previously defined here
   26 | const ll INF = 1LL << 60;
      |          ^~~
a.cc:278:10: error: redefinition of 'const ll mod'
  278 | const ll mod = 1000000007;
      |          ^~~
a.cc:27:10: note: 'const ll mod' previously defined here
   27 | const ll mod = 1000000007;
      |          ^~~
a.cc:279:10: error: redefinition of 'const ll dx [4]'
  279 | const ll dx[4] = {1, 0, -1, 0};
      |          ^~
a.cc:28:10: note: 'const ll dx [4]' previously defined here
   28 | const ll dx[4] = {1, 0, -1, 0};
      |          ^~
a.cc:280:10: error: redefinition of 'const ll dy [4]'
  280 | const ll dy[4] = {0, -1, 0, 1};
      |          ^~
a.cc:29:10: note: 'const ll dy [4]' previously defined here
   29 | const ll dy[4] = {0, -1, 0, 1};
      |          ^~
a.cc:281:10: error: redefinition of 'const ll NCK_MAX'
  281 | const ll NCK_MAX = 510000;
      |          ^~~~~~~
a.cc:30:10: note: 'const ll NCK_MAX' previously defined here
   30 | const ll NCK_MAX = 510000;
      |          ^~~~~~~
a.cc:283:4: error: redefinition of 'll ketawa(ll)'
  283 | ll ketawa(ll n){
      |    ^~~~~~
a.cc:32:4: note: 'll ketawa(ll)' previously defined here
   32 | ll ketawa(ll n){
      |    ^~~~~~
a.cc:291:4: error: redefinition of 'll RepeatSquaring(ll, ll, ll)'
  291 | ll RepeatSquaring(ll N, ll P, ll M){
      |    ^~~~~~~~~~~~~~
a.cc:40:4: note: 'll RepeatSquaring(ll, ll, ll)' previously defined here
   40 | ll RepeatSquaring(ll N, ll P, ll M){
      |    ^~~~~~~~~~~~~~
a.cc:299:6: error: redefinition of 'bool IsPrime(ll)'
  299 | bool IsPrime(ll a){//order root a
      |      ^~~~~~~
a.cc:48:6: note: 'bool IsPrime(ll)' previously defined here
   48 | bool IsPrime(ll a){//order root a
      |      ^~~~~~~
a.cc:308:4: error: redefinition of 'll gcd(ll, ll)'
  308 | ll gcd(ll a, ll b) {
      |    ^~~
a.cc:57:4: note: 'll gcd(ll, ll)' previously defined here
   57 | ll gcd(ll a, ll b) {
      |    ^~~
a.cc:312:4: error: redefinition of 'll lcm(ll, ll)'
  312 | ll lcm(ll a, ll b){
      |    ^~~
a.cc:61:4: note: 'll lcm(ll, ll)' previously defined here
   61 | ll lcm(ll a, ll b){
      |    ^~~
a.cc:316:4: error: redefinition of 'll extgcd(ll, ll, ll&, ll&)'
  316 | ll extgcd(ll a, ll b, ll& x, ll& y) {
      |    ^~~~~~
a.cc:65:4: note: 'll extgcd(ll, ll, ll&, ll&)' previously defined here
   65 | ll extgcd(ll a, ll b, ll& x, ll& y) {
      |    ^~~~~~
a.cc:327:4: error: redefinition of 'll invmod(ll, ll)'
  327 | ll invmod (ll a, ll m) { // a^-1 mod m
      |    ^~~~~~
a.cc:76:4: note: 'll invmod(ll, ll)' previously defined here
   76 | ll invmod (ll a, ll m) { // a^-1 mod m
      |    ^~~~~~
a.cc:335:5: error: redefinition of 'll* fac'
  335 | ll *fac, *finv, *inv;
      |     ^~~
a.cc:84:5: note: 'll* fac' previously declared here
   84 | ll *fac, *finv, *inv;
      |     ^~~
a.cc:335:11: error: redefinition of 'll* finv'
  335 | ll *fac, *finv, *inv;
      |           ^~~~
a.cc:84:11: note: 'll* finv' previously declared here
   84 | ll *fac, *finv, *inv;
      |           ^~~~
a.cc:335:18: error: redefinition of 'll* inv'
  335 | ll *fac, *finv, *inv;
      |                  ^~~
a.cc:84:18: note: 'll* inv' previously declared here
   84 | ll *fac, *finv, *inv;
      |                  ^~~
a.cc:337:6: error: redefinition of 'void nCk_init(ll)'
  337 | void nCk_init(ll mod) {
      |      ^~~~~~~~
a.cc:86:6: note: 'void nCk_init(ll)' previously defined here
   86 | void nCk_init(ll mod) {
      |      ^~~~~~~~
a.cc:351:4: error: redefinition of 'll nCk(ll, ll, ll)'
  351 | ll nCk(ll n, ll k, ll mod) {
      |    ^~~
a.cc:100:4: note: 'll nCk(ll, ll, ll)' previously defined here
  100 | ll nCk(ll n, ll k, ll mod) {
      |    ^~~
a.cc:358:4: error: redefinition of 'll lmin(ll, ll)'
  358 | ll lmin(ll a, ll b) { return a > b ? b : a; };
      |    ^~~~
a.cc:107:4: note: 'll lmin(ll, ll)' previously defined here
  107 | ll lmin(ll a, ll b) { return a > b ? b : a; };
      |    ^~~~
a.cc:360:4: error: redefinition of 'll lmax(ll, ll)'
  360 | ll lmax(ll a, ll b) { return a > b ? a : b; };
      |    ^~~~
a.cc:109:4: note: 'll lmax(ll, ll)' previously defined here
  109 | ll lmax(ll a, ll b) { return a > b ? a : b; };
      |    ^~~~
a.cc:362:4: error: redefinition of 'll lsum(ll, ll)'
  362 | ll lsum(ll a, ll b) { return a + b; };
      |    ^~~~
a.cc:111:4: note: 'll lsum(ll, ll)' previously defined here
  111 | ll lsum(ll a, ll b) { return a + b; };
      |    ^~~~
a.cc:367:7: error: redefinition of 'class Zip<T>'
  367 | class Zip {
      |       ^~~
a.cc:116:7: note: previous definition of 'class Zip<T>'
  116 | class Zip {
      |       ^~~
a.cc:398:7: error: redefinition of 'class UnionFind'
  398 | class UnionFind {
      |       ^~~~~~~~~
a.cc:147:7: note: previous definition of 'class UnionFind'
  147 | class UnionFind {
      |       ^~~~~~~~~
a.cc:430:7: error: redefinition of 'class SegmentTree'
  430 | class SegmentTree {
      |       ^~~~~~~~~~~
a.cc:179:7: note: previous definition of 'class SegmentTree'
  179 | class SegmentTree {
      |       ^~~~~~~~~~~
a.cc:467:4: error: redefinition of 'll lis(ll*, ll, ll*)'
  467 | ll lis(ll* a, ll n, ll* dp) {
      |    ^~~
a.cc:216:4: note: 'll lis(ll*, ll, ll*)' previously defined here
  216 | ll lis(ll* a, ll n, ll* dp) {
      |    ^~~
a.cc:475:8: error: redefinition of 'std::string s'
  475 | string s,t={};
      |        ^
a.cc:224:8: note: 'std::string s' previously declared here
  224 | string s,t={};
      |        ^
a.cc:475:10: error: redefinition of 'std::string t'
  475 | string s,t={};
      |          ^
a.cc:224:10: note: 'std::string t' previously declared here
  224 | string s,t={};
      |          ^
a.cc:476:4: error: redefinition of 'll h'
  476 | ll h,w,n,m;
      |    ^
a.cc:225:4: note: 'll h' previously declared here
  225 | ll h,w,n,m;
      |    ^
a.cc:476:6: error: redefinition of 'll w'
  476 | ll h,w,n,m;
      |      ^
a.cc:225:6: note: 'll w' previously declared here
  225 | ll h,w,n,m;
      |      ^
a.cc:476:8: error: redefinition of 'll n'
  476 | ll h,w,n,m;
      |        ^
a.cc:225:8: note: 'll n' previously declared here
  225 | ll h,w,n,m;
      |        ^
a.cc:476:10: error: redefinition of 'll m'
  476 | ll h,w,n,m;
      |          ^
a.cc:225:10: note: 'll m' previously declared here
  225 | ll h,w,n,m;
      |          ^
a.cc:477:8: error: redefinition of 'double dp [1000][1000]'
  477 | double dp[1000][1000];
      |        ^~
a.cc:226:8: note: 'double dp [1000][1000]' previously declared here
  226 | double dp[1000][1000];
      |        ^~
a.cc:478:4: error: redefinition of 'll ans'
  478 | ll ans;
      |    ^~~
a.cc:227:4: note: 'll ans' previously declared here
  227 | ll ans;
      |    ^~~
a.cc:479:12: error: redefinition of 'std::vector<long long int> vec'
  479 | vector<ll> vec;
      |            ^~~
a.cc:228:12: note: 'std::vector<long long int> vec' previously declared here
  228 | vector<ll> vec;
      |            ^~~
a.cc:480:4: error: redefinition of 'll zenbu'
  480 | ll zenbu;
      |    ^~~~~
a.cc:229:4: note: 'll zenbu' previously declared here
  229 | ll zenbu;
      |    ^~~~~
a.cc:481:5: error: redefinition of 'int main()'
  481 | int main(){
      |     ^~~~
a.cc:230:5: note: 'int main()' previously defined here
  230 | int main(){
      |     ^~~~