Language: C++

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

#include <iomanip>

#include <algorithm>

#include <vector>

#include <stack>

#include <queue>

#include <cmath>

#include <set>

#include <map>

#include <string>

#include <numeric>

#include <cstdio>

#include <cstdlib>

#include <ctime>

#include <iterator>

using namespace std;


const int INF = 10000000;

typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for (int i = 0; i < (a); i++)

//char maze[100][101];

ll n, m;

int sx, sy;

int gx, gy;

int qqq;

//各座標までの最短距離

int d[100][100];


//移動方向のベクトル

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

int ans = 0;
pair<int, int> red[101], blue[101];
//ll a[200000], b[20000];

//ユークリッドの互除法
ll gcd(ll x, ll y) {
	if (x < y) swap(x, y);
	if (y == 0) return x;
	return gcd(y, x%y);
}

//エラトステネスの篩 prime(n)[k]で1~nまで探索して(k+1)番目の素数を出力
vector <int> erstlist;
void prime(int n) {
	vector<int> erst;
	for (int i = 0; i < n; ++i) erst.PB(i);
	erst[0] = erst[1] = 0;
	for (int dx = 2; dx*dx <= n; dx++) {
		if (erst[dx] == NULL) continue;
		for (int i = dx * 2; i < n; i += dx) erst[i] = NULL;
	}

	for (auto i : erst) if (i) erstlist.PB(i);

	return;
}

int isPrime(int x) {
	int i;
	if (x < 2) return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0) return 0;
	return 1;
}

int v_find(std::vector<int> vec, int number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	if (itr!=vec.end()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

int ok = 1000; //解が存在する値
int ng = -1;   //解が存在しない値

ll BIG = 10000000000;

ll POW(ll a, ll b) {
	if (b == 0) return 1;
	return (a*POW(a, b - 1)) % BIG;
}

int Kaijou(int a) {
	if (a < 2) return 1;
	return a * Kaijou(a - 1);
}


ll aa[51];

int main() {
	cin >> n;
	int a[100000] = { 0 };
	rep(i, n) cin >> a[i];
	int sum = 0;
	int pass[100001] = { 0 };
	pass[0] = abs(a[0]);
	sum = pass[0];
	rep(i, n) {
		if (i) {
			pass[i] = abs(a[i] - a[i - 1]);
			sum += pass[i];
		}
	}
	pass[n] = abs(a[n - 1]);
	sum += pass[n];
	if (0 <= (a[0])*(a[1] - a[0])) cout << sum << endl;
	else cout << sum - 2*pass[0]<<endl;
	for (int i = 1; i < n - 1;++i) {
		if (0 <= (a[i]-a[i-1])*(a[i + 1] - a[i])) cout << sum << endl;
		else cout << sum - 2*pass[i] << endl;
	}
	if (n > 2)if (0 > (a[n - 1] - a[n - 2])*(a[n - 2] - a[n - 3])) {
		cout << sum - 2 * pass[n] << endl;
		return 0;
	}
	if(0<= (a[n-1]-a[n-2])*(0 - a[n-1])) cout << sum << endl;
	else cout << sum -2*pass[n-1] << endl;
	c	return 0;
}


Compiler output:
a.cc: In function 'void prime(int)':
a.cc:80:33: warning: NULL used in arithmetic [-Wpointer-arith]
   80 |                 if (erst[dx] == NULL) continue;
      |                                 ^~~~
a.cc:81:64: warning: converting to non-pointer type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} from NULL [-Wconversion-null]
   81 |                 for (int i = dx * 2; i < n; i += dx) erst[i] = NULL;
      |                                                                ^~~~
a.cc: In function 'int main()':
a.cc:155:9: error: 'c' was not declared in this scope
  155 |         c       return 0;
      |         ^