Problem p03403 (C++)

Buggy submission (status: Time Limit Exceeded):
// Traveling Plan

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, x, y) for (ll i = x; i < y; i++)
#define irep(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n, a)                                                           \
  ll n;                                                                        \
  cin >> n;                                                                    \
  vector<ll> a(n);                                                             \
  rep(i, 0, n) cin >> a[i]
#define nxvarep(n, x, a)                                                       \
  ll n, x;                                                                     \
  cin >> n >> x;                                                               \
  vector<ll> a(n);                                                             \
  rep(i, 0, n) cin >> a[i]
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a / __gcd(a, b) * b)
#define range(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n", a)
template <class T> inline bool chmin(T &a, T b, bool f) {
  if (f == 1) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
  } else if (f == 0) {
    if (a < b) {
      a = b;
      return true;
    }
    return false;
  }
  return false;
}
typedef pair<ll, string> p;
const int inf = 2147483647;         // 2*10^9
const ll INF = 9223372036854775807; // 9*10^18

int main() {
  nvarep(n, a);
  rep(i, 0, n) {
    ll c = 0, ans = 0;
    rep(j, 0, n) {
      if (i == j)
        continue;
      ans += abs(a[j] - c);
      c = a[j];
    }
    ans += abs(c - 0);
    cout << ans << nnn;
  }
  return 0;
}

Fixed submission:
// Traveling Plan

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, x, y) for (ll i = x; i < y; i++)
#define irep(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n, a)                                                           \
  ll n;                                                                        \
  cin >> n;                                                                    \
  vector<ll> a(n);                                                             \
  rep(i, 0, n) cin >> a[i]
#define nxvarep(n, x, a)                                                       \
  ll n, x;                                                                     \
  cin >> n >> x;                                                               \
  vector<ll> a(n);                                                             \
  rep(i, 0, n) cin >> a[i]
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a / __gcd(a, b) * b)
#define range(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n", a)
template <class T> inline bool chmin(T &a, T b, bool f) {
  if (f == 1) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
  } else if (f == 0) {
    if (a < b) {
      a = b;
      return true;
    }
    return false;
  }
  return false;
}
typedef pair<ll, string> p;
const int inf = 2147483647;         // 2*10^9
const ll INF = 9223372036854775807; // 9*10^18

int main() {
  nvarep(n, a);
  a.insert(a.begin(), 0LL);
  a.pb(0LL);
  ll goke = 0;
  rep(i, 1, n + 2) { goke += abs(a[i] - a[i - 1]); }
  rep(i, 1, n + 1) {
    ll ans = goke - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) +
             abs(a[i - 1] - a[i + 1]);
    cout << ans << nnn;
  }
  return 0;
}