prithivMLmods/Coder-Stat huggingface dataset:
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int N;
  cin >> N;
  int a[110];
  for (int i = 0; i < N; i++)
    cin >> a[i];

  // 全部訪れる場合の金額sum
  int sum = 0;
  sum = abs(a[0]);
  for (int i = 0; i < N - 1; i++) {
    sum += abs(a[i + 1] - a[i]);
  }
  sum += abs(a[N - 1]);

  // iを訪れない
  int sum2;
  // i=1のとき
  sum2 = sum - abs(a[1] - a[0]) - abs(a[0]) + abs(a[1]);
  cout << sum2 << '\n';
  // i=2,3,4...
  for (int i = 1; i < N - 1; i++) {
    sum2 = sum - abs(a[i + 1] - a[i]) - abs(a[i] - a[i - 1]) +
           abs(a[i + 1] - a[i - 1]);
    cout << sum2 << '\n';
  }
  // i=N
  sum2 = sum - abs(a[N - 1]) - abs(a[N - 1] - a[N - 2]) + abs(a[N - 2]);
  cout << sum2 << '\n';
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int N;
  cin >> N;
  int a[100100];
  for (int i = 0; i < N; i++)
    cin >> a[i];

  // 全部訪れる場合の金額sum
  int sum = 0;
  sum = abs(a[0]);
  for (int i = 0; i < N - 1; i++) {
    sum += abs(a[i + 1] - a[i]);
  }
  sum += abs(a[N - 1]);

  // iを訪れない
  int sum2;
  // i=1のとき
  sum2 = sum - abs(a[1] - a[0]) - abs(a[0]) + abs(a[1]);
  cout << sum2 << '\n';
  // i=2,3,4...
  for (int i = 1; i < N - 1; i++) {
    sum2 = sum - abs(a[i + 1] - a[i]) - abs(a[i] - a[i - 1]) +
           abs(a[i + 1] - a[i - 1]);
    cout << sum2 << '\n';
  }
  // i=N
  sum2 = sum - abs(a[N - 1]) - abs(a[N - 1] - a[N - 2]) + abs(a[N - 2]);
  cout << sum2 << '\n';
  return 0;
}
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
const int MAXN = 5; // 1000005; change
int xAxis[MAXN];
int diffs[MAXN];
vector<int> trip;

int main() {
  // freopen("in","r",stdin);

  int Npoints, partial_value = 0;

  cin >> Npoints;

  for (int i = 1; i <= Npoints; ++i) {
    int value;
    cin >> value;
    xAxis[i] = value;
  }

  for (int i = 1; i < Npoints; ++i) {
    diffs[i - 1] = abs(xAxis[i] - xAxis[i + 1]);
    partial_value += abs(xAxis[i] - xAxis[i + 1]);
  }

  // ignoring the trip to ith point

  for (int i = 1; i <= Npoints; i++) {
    int ans = partial_value;

    if (i != 1 && i != Npoints) {
      ans -= diffs[i - 2];
      ans -= diffs[i - 1];

      ans += abs(xAxis[i - 1] - xAxis[i + 1]);
      ans += abs(xAxis[1]);
      ans += abs(xAxis[Npoints]);
      cout << ans << endl;
    } else {
      if (i == 1) {
        ans -= diffs[0];
        ans += abs(xAxis[i + 1]);
        ans += abs(xAxis[Npoints]);
        cout << ans << endl;
      } else if (i == Npoints) {
        ans -= diffs[i - 2];
        ans += abs(xAxis[i - 1]);
        ans += abs(xAxis[1]);
        cout << ans << endl;
      }
    }

    //        cout << ans << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
const int MAXN = 1000005; // 1000005; change
int xAxis[MAXN];
int diffs[MAXN];
vector<int> trip;

int main() {
  // freopen("in","r",stdin);

  int Npoints, partial_value = 0;

  cin >> Npoints;

  for (int i = 1; i <= Npoints; ++i) {
    int value;
    cin >> value;
    xAxis[i] = value;
  }

  for (int i = 1; i < Npoints; ++i) {
    diffs[i - 1] = abs(xAxis[i] - xAxis[i + 1]);
    partial_value += abs(xAxis[i] - xAxis[i + 1]);
  }

  // ignoring the trip to ith point

  for (int i = 1; i <= Npoints; i++) {
    int ans = partial_value;

    if (i != 1 && i != Npoints) {
      ans -= diffs[i - 2];
      ans -= diffs[i - 1];

      ans += abs(xAxis[i - 1] - xAxis[i + 1]);
      ans += abs(xAxis[1]);
      ans += abs(xAxis[Npoints]);
      cout << ans << endl;
    } else {
      if (i == 1) {
        ans -= diffs[0];
        ans += abs(xAxis[i + 1]);
        ans += abs(xAxis[Npoints]);
        cout << ans << endl;
      } else if (i == Npoints) {
        ans -= diffs[i - 2];
        ans += abs(xAxis[i - 1]);
        ans += abs(xAxis[1]);
        cout << ans << endl;
      }
    }

    //        cout << ans << endl;
  }
}
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  int a[10000] = {};

  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }

  int s = 0;
  for (int i = 0; i <= N; i++) {
    s += abs(a[i] - a[i + 1]);
  }

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    ans = s - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) +
          abs(a[i - 1] - a[i + 1]);
    cout << ans << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  int a[100000] = {};

  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }

  int s = 0;
  for (int i = 0; i <= N; i++) {
    s += abs(a[i] - a[i + 1]);
  }

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    ans = s - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) +
          abs(a[i - 1] - a[i + 1]);
    cout << ans << endl;
  }
}
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define r(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int main(void) {
  int n;
  ll sum = 0;
  ll a[10010] = {};
  ll b[10010] = {};

  cin >> n;
  for (int j = 1; j <= n; j++) {
    cin >> a[j];
    sum += llabs(a[j] - a[j - 1]);
    b[j] = llabs(a[j] - a[j - 1]);
  }
  sum += llabs(a[n + 1] - a[n]);
  b[n + 1] = llabs(a[n + 1] - a[n]);

  for (int i = 1; i <= n; i++) {
    ll ans = sum;
    ans -= (b[i] + b[i + 1]);
    ans += llabs(a[i + 1] - a[i - 1]);
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define r(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int main(void) {
  int n;
  ll sum = 0;
  ll a[100010] = {};
  ll b[100010] = {};

  cin >> n;
  for (int j = 1; j <= n; j++) {
    cin >> a[j];
    sum += llabs(a[j] - a[j - 1]);
    b[j] = llabs(a[j] - a[j - 1]);
  }
  sum += llabs(a[n + 1] - a[n]);
  b[n + 1] = llabs(a[n + 1] - a[n]);

  for (int i = 1; i <= n; i++) {
    ll ans = sum;
    ans -= (b[i] + b[i + 1]);
    ans += llabs(a[i + 1] - a[i - 1]);
    cout << ans << endl;
  }
  return 0;
}
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;

int main() {
  ll n, l;
  cin >> n;
  vector<ll> a(n + 2);
  a[0] = 0;
  a[n + 1] = 0;
  ll sum = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> l;
    a[i] = l;
  }
  vector<ll> d(n);
  for (ll i = 1; i <= n + 1; i++) {
    d[i] = abs(a[i] - a[i - 1]);
    sum += d[i];
  }
  for (int i = 1; i <= n; i++) {
    cout << sum - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) +
                abs(a[i - 1] - a[i + 1])
         << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;

int main() {
  ll n, l;
  cin >> n;
  vector<ll> a(n + 2);
  a[0] = 0;
  a[n + 1] = 0;
  ll sum = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> l;
    a[i] = l;
  }
  vector<ll> d(n + 1);
  for (ll i = 1; i <= n + 1; i++) {
    d[i] = abs(a[i] - a[i - 1]);
    sum += d[i];
  }
  for (int i = 1; i <= n; i++) {
    cout << sum - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) +
                abs(a[i - 1] - a[i + 1])
         << endl;
  }
  return 0;
}
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define int long long

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

signed main() {
  int N;
  int A[11000];
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  int sum = 0;
  for (int i = 1; i <= N; i++) {
    sum += abs(A[i] - A[i - 1]);
  }
  sum += abs(A[N]);
  for (int i = 1; i <= N; i++) {
    cout << sum - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) +
                abs(A[i + 1] - A[i - 1])
         << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define int long long

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

signed main() {
  int N;
  int A[110000];
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  int sum = 0;
  for (int i = 1; i <= N; i++) {
    sum += abs(A[i] - A[i - 1]);
  }
  sum += abs(A[N]);
  for (int i = 1; i <= N; i++) {
    cout << sum - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) +
                abs(A[i + 1] - A[i - 1])
         << endl;
  }
  return 0;
}
Problem p03401 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int n;
const int INF = 2000000005;

int mp2[100005] = {0};
int main() {
  for (int i = 0; i < 100005; i++) {

    mp2[i] = INF;
  }
  mp2[0] = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> mp2[i];
  }
  mp2[n + 1] = 0;
  for (int j = 1; j <= n; j++) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (i != j && i + 1 != j) {
        ans += abs(mp2[i + 1] - mp2[i]);
      } else if (i + 1 == j) {
        ans += abs(mp2[i + 2] - mp2[i]);
        i++;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int n;
const int INF = 2000000005;

int mp2[100005] = {0};
int main() {
  for (int i = 0; i < 100005; i++) {

    mp2[i] = INF;
  }
  mp2[0] = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> mp2[i];
  }
  mp2[n + 1] = 0;
  int yo = 0;
  for (int i = 0; i <= n; i++) {
    yo += abs(mp2[i + 1] - mp2[i]);
  }

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

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

    ans += abs(mp2[i - 1] - mp2[i + 1]);
    cout << ans << endl;
  }

  return 0;
}
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)

// dpテーブルをローカルで宣言したらセグフォになった...
ll a[10010], sa[10010];

int main() {
  ll n;
  cin >> n;
  ll res = 0;
  a[0] = 0;
  a[n + 1] = 0;
  rep(i, n + 1) {
    if (i > 0) {
      cin >> a[i];
    }
  }
  rep(i, n + 1) {
    sa[i] = abs(a[i + 1] - a[i]);
    res += sa[i];
  }
  rep(i, n + 1) {
    if (i > 0) {
      ll ans = 0;
      ans = res + abs(a[i + 1] - a[i - 1]) - abs(a[i] - a[i - 1]) -
            abs(a[i + 1] - a[i]);
      cout << ans << endl;
    }
    // i番目がi-1,i+1番目に対して
    // 左、間、右にあるかで場合分けすれば良い。
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)

// dpテーブルをローカルで宣言したらセグフォになった...
ll a[100010], sa[100010];

int main() {
  ll n;
  cin >> n;
  ll res = 0;
  a[0] = 0;
  a[n + 1] = 0;
  rep(i, n + 1) {
    if (i > 0) {
      cin >> a[i];
    }
  }
  rep(i, n + 1) {
    sa[i] = abs(a[i + 1] - a[i]);
    res += sa[i];
  }
  rep(i, n + 1) {
    if (i > 0) {
      ll ans = 0;
      ans = res + abs(a[i + 1] - a[i - 1]) - abs(a[i] - a[i - 1]) -
            abs(a[i + 1] - a[i]);
      cout << ans << endl;
    }
    // i番目がi-1,i+1番目に対して
    // 左、間、右にあるかで場合分けすれば良い。
  }
}
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int abs(int a) { return a > 0 ? a : -a; }
int n, map[10001], sum[100001], money[10001];
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n + 1; i++) {
    if (i <= n)
      scanf("%d", &map[i]);
    money[i] = abs(map[i] - map[i - 1]);
    // printf("%d ",money[i]);
    sum[i] = sum[i - 1] + money[i];
  }
  // puts("");
  for (int i = 1; i <= n; i++) {
    printf("%d\n",
           sum[n + 1] - money[i] - money[i + 1] + abs(map[i + 1] - map[i - 1]));
    // printf("%d %d %d
    // %d\n",sum[n+1],money[i],money[i+1],abs(map[i+1]-map[i-1]));
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
int abs(int a) { return a > 0 ? a : -a; }
int n, map[100001], sum[100001], money[100001];
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n + 1; i++) {
    if (i <= n)
      scanf("%d", &map[i]);
    money[i] = abs(map[i] - map[i - 1]);
    // printf("%d ",money[i]);
    sum[i] = sum[i - 1] + money[i];
  }
  // puts("");
  for (int i = 1; i <= n; i++) {
    printf("%d\n",
           sum[n + 1] - money[i] - money[i + 1] + abs(map[i + 1] - map[i - 1]));
    // printf("%d %d %d
    // %d\n",sum[n+1],money[i],money[i+1],abs(map[i+1]-map[i-1]));
  }
  return 0;
}
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N = 0;
  long long zahyo[10005];
  long long kingaku[10005];
  long long print = 0;
  long long tmp = 0;
  long long sum = 0, ans = 0;
  cin >> N;

  zahyo[0] = 0;
  zahyo[N + 1] = 0;

  for (int i = 1; i <= N; i++) {
    cin >> zahyo[i];
    kingaku[i] = abs(zahyo[i] - zahyo[i - 1]);
    ans += kingaku[i];
  }
  kingaku[N + 1] = abs(zahyo[N]);
  ans += kingaku[N + 1];

  for (int i = 1; i <= N; i++) {
    print =
        ans - kingaku[i] - kingaku[i + 1] + abs(zahyo[i + 1] - zahyo[i - 1]);

    cout << print << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N = 0;
  long long zahyo[100005];
  long long kingaku[100005];
  long long print = 0;
  long long tmp = 0;
  long long sum = 0, ans = 0;
  cin >> N;

  zahyo[0] = 0;
  zahyo[N + 1] = 0;

  for (int i = 1; i <= N; i++) {
    cin >> zahyo[i];
    kingaku[i] = abs(zahyo[i] - zahyo[i - 1]);
    ans += kingaku[i];
  }
  kingaku[N + 1] = abs(zahyo[N]);
  ans += kingaku[N + 1];

  for (int i = 1; i <= N; i++) {
    print =
        ans - kingaku[i] - kingaku[i + 1] + abs(zahyo[i + 1] - zahyo[i - 1]);

    cout << print << endl;
  }
}
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll pref[10100];
ll suff[10100];
ll ara[10100];
int main() {
  ll n, d, rem;
  cin >> n;
  // int ara[n+10];
  ara[n + 1] = 0;
  ara[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> ara[i];
  }
  for (int i = 1; i <= n; i++) {
    pref[i] = pref[i - 1] + abs(ara[i] - ara[i - 1]);
  }

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

    suff[i] = suff[i + 1] + abs(ara[i] - ara[i + 1]);
  }

  for (int i = 1; i <= n; i++) {
    ll lft = pref[i - 1], rgt = suff[i + 1], mid = abs(ara[i - 1] - ara[i + 1]);
    // cout << pref[i-1] << endl;
    cout << lft + rgt + mid << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll pref[101000];
ll suff[101000];
ll ara[101000];
int main() {
  ll n, d, rem;
  cin >> n;
  // int ara[n+10];
  ara[n + 1] = 0;
  ara[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> ara[i];
  }
  for (int i = 1; i <= n; i++) {
    pref[i] = pref[i - 1] + abs(ara[i] - ara[i - 1]);
  }

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

    suff[i] = suff[i + 1] + abs(ara[i] - ara[i + 1]);
  }

  for (int i = 1; i <= n; i++) {
    ll lft = pref[i - 1], rgt = suff[i + 1], mid = abs(ara[i - 1] - ara[i + 1]);
    // cout << pref[i-1] << endl;
    cout << lft + rgt + mid << endl;
  }
}
Problem p03402 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
const long long mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int ddx[4] = {1, 1, -1, -1};
const int ddy[4] = {1, -1, -1, 1};
//////////////////////////////////

int main() {
  int a, b;
  cin >> a >> b;
  a--;
  b--;
  vector<string> s(100, string(100, '#'));
  for (int i = 50; i <= 100; i++) {
    s[i] = string(100, '.');
  }

  for (int i = 0; i < 49; i += 2) {
    for (int j = 0; j < 100; j += 2) {
      if (a == 0)
        break;
      s[i][j] = '.';
      a--;
    }
  }
  for (int i = 51; i < 100; i += 2) {
    for (int j = 0; j < 100; j += 2) {
      if (b == 0)
        break;
      s[i][j] = '#';
      b--;
    }
  }
  cout << s.size() << " " << s[0].size() << endl;
  for (int i = 0; i < 100; i++)
    cout << s[i] << endl;

  return 0;
}

// EOF


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
const long long mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int ddx[4] = {1, 1, -1, -1};
const int ddy[4] = {1, -1, -1, 1};
//////////////////////////////////

int main() {
  int a, b;
  cin >> a >> b;
  a--;
  b--;
  vector<string> s(100, string(100, '#'));
  for (int i = 50; i < 100; i++) {
    s[i] = string(100, '.');
  }

  for (int i = 0; i < 49; i += 2) {
    for (int j = 0; j < 100; j += 2) {
      if (a == 0)
        break;
      s[i][j] = '.';
      a--;
    }
  }
  for (int i = 51; i < 100; i += 2) {
    for (int j = 0; j < 100; j += 2) {
      if (b == 0)
        break;
      s[i][j] = '#';
      b--;
    }
  }
  cout << s.size() << " " << s[0].size() << endl;
  for (int i = 0; i < 100; i++)
    cout << s[i] << endl;

  return 0;
}

// EOF
Problem p03402 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll a, b;
char res[100][100];

int main() {
  cin >> a >> b;
  for (ll i = 0; i < 100; i++) {
    for (ll j = 0; j < 100; j++) {
      if (i < 50)
        res[i][j] = '.';
      else
        res[i][j] = '#';
    }
  }
  ll countb = 0;
  for (ll i = 0; i < 50; i += 2) {
    for (ll j = 0; j < 100; j += 2) {
      if (countb == b - 1)
        break;
      res[i][j] = '#';
      countb++;
    }
    if (countb == b - 1)
      break;
  }
  ll counta = 0;
  for (ll i = 99; i >= 50; i += 2) {
    for (ll j = 0; j < 100; j += 2) {
      if (counta == a - 1)
        break;
      res[i][j] = '.';
      counta++;
    }
    if (counta == a - 1)
      break;
  }
  cout << 100 << " " << 100 << endl;
  for (ll i = 0; i < 100; i++) {
    for (ll j = 0; j < 100; j++) {
      cout << res[i][j];
    }
    cout << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll a, b;
char res[100][100];

int main() {
  cin >> a >> b;
  for (ll i = 0; i < 100; i++) {
    for (ll j = 0; j < 100; j++) {
      if (i < 50)
        res[i][j] = '.';
      else
        res[i][j] = '#';
    }
  }
  ll countb = 0;
  for (ll i = 0; i < 50; i += 2) {
    for (ll j = 0; j < 100; j += 2) {
      if (countb == b - 1)
        break;
      res[i][j] = '#';
      countb++;
    }
    if (countb == b - 1)
      break;
  }
  ll counta = 0;
  for (ll i = 99; i >= 50; i -= 2) {
    for (ll j = 0; j < 100; j += 2) {
      if (counta == a - 1)
        break;
      res[i][j] = '.';
      counta++;
    }
    if (counta == a - 1)
      break;
  }
  cout << 100 << " " << 100 << endl;
  for (ll i = 0; i < 100; i++) {
    for (ll j = 0; j < 100; j++) {
      cout << res[i][j];
    }
    cout << endl;
  }
}
Problem p03402 (Python)

Buggy submission (status: Runtime Error):
a = int(input())
b = int(input())
ans = []
for i in range(50):
    ans.append(["."] * 100)
for i in range(50):
    ans.append(["#"] * 100)

i = 0
b -= 1
while b > 0:
    for j in range(0, 100, 2):
        ans[i][j] = "#"
        b -= 1
        if b == 0:
            break
    i += 2

i = 60
a -= 1
while a > 0:
    for j in range(0, 100, 2):
        ans[i][j] = "."
        a -= 1
        if a == 0:
            break
    i += 2
print(100, 100)
for i in range(100):
    print("".join(ans[i]))


Fixed submission:
a, b = map(int, input().split())
ans = []
for i in range(50):
    ans.append(["."] * 100)
for i in range(50):
    ans.append(["#"] * 100)

i = 0
b -= 1
while b > 0:
    for j in range(0, 100, 2):
        ans[i][j] = "#"
        b -= 1
        if b == 0:
            break
    i += 2

i = 60
a -= 1
while a > 0:
    for j in range(0, 100, 2):
        ans[i][j] = "."
        a -= 1
        if a == 0:
            break
    i += 2
print(100, 100)
for i in range(100):
    print("".join(ans[i]))
Problem p03402 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll;
char mp[50][101], m, n;
void fill_mp(int num, int x, char ch) {
  for (int i = x;; i += 2) {
    for (int j = 0; j < 100; j += 2) {
      if (num == 0)
        return;
      mp[i][j] = ch;
      num--;
    }
  }
}
int main() {
  while (~scanf("%d%d", &m, &n)) {
    for (int i = 0; i < 25; i++) {
      memset(mp[i], '#', sizeof(mp[i]));
    }
    for (int i = 25; i < 50; i++) {
      memset(mp[i], '.', sizeof(mp[i]));
    }
    for (int i = 0; i < 50; i++)
      mp[i][100] = 0;
    m--, n--;
    fill_mp(m, 0, '.'), fill_mp(n, 26, '#');
    printf("50 100\n");
    for (int i = 0; i < 50; i++)
      printf("%s\n", mp[i]);
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll;
char mp[50][101];
int m, n;
void fill_mp(int num, int x, char ch) {
  for (int i = x;; i += 2) {
    for (int j = 0; j < 100; j += 2) {
      if (num == 0)
        return;
      mp[i][j] = ch;
      num--;
    }
  }
}
int main() {
  while (~scanf("%d%d", &m, &n)) {
    for (int i = 0; i < 25; i++) {
      memset(mp[i], '#', sizeof(mp[i]));
    }
    for (int i = 25; i < 50; i++) {
      memset(mp[i], '.', sizeof(mp[i]));
    }
    for (int i = 0; i < 50; i++)
      mp[i][100] = 0;
    m--, n--;
    fill_mp(m, 0, '.'), fill_mp(n, 26, '#');
    printf("50 100\n");
    for (int i = 0; i < 50; i++)
      printf("%s\n", mp[i]);
  }
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 5, 0), s(n + 5, 0), t(n + 5, 0), u(n + 5, 0);
  REP(i, n) cin >> a[i + 1];
  for (int i = 0; i <= n; ++i)
    s[i] = abs(a[i + 1] - a[i]);
  for (int i = 0; i <= n; ++i)
    t[i + 1] = t[i] + s[i];
  for (int i = n; i >= 0; --i)
    u[i - 1] = u[i] + s[i];
  for (int i = 1; i <= n; ++i)
    cout << t[i - 1] + u[i] + abs(a[i + 1] - a[i - 1]) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 5, 0), s(n + 5, 0), t(n + 5, 0), u(n + 5, 0);
  REP(i, n) cin >> a[i + 1];
  for (int i = 0; i <= n; ++i)
    s[i] = abs(a[i + 1] - a[i]);
  for (int i = 0; i <= n; ++i)
    t[i + 1] = t[i] + s[i];
  for (int i = n; i > 0; --i)
    u[i - 1] = u[i] + s[i];
  for (int i = 1; i <= n; ++i)
    cout << t[i - 1] + u[i] + abs(a[i + 1] - a[i - 1]) << endl;
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;

const int MXN = 500;
int arr[MXN];

int co(int a, int b) { return abs(arr[a] - arr[b]); }

int main() {

  int n;
  cin >> n;

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

  int tc = 0;
  for (int i = 0; i <= n; i++) {
    tc += co(i, i + 1);
  }

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

    int br = co(skip - 1, skip + 1);
    int at = co(skip - 1, skip) + co(skip, skip + 1);
    cout << tc - at + br << endl;
  }
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;

const int MXN = 100005;
int arr[MXN];

int co(int a, int b) { return abs(arr[a] - arr[b]); }

int main() {

  int n;
  cin >> n;

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

  int tc = 0;
  for (int i = 0; i <= n; i++) {
    tc += co(i, i + 1);
  }

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

    int br = co(skip - 1, skip + 1);
    int at = co(skip - 1, skip) + co(skip, skip + 1);
    cout << tc - at + br << endl;
  }
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rrep(i, a, b) for (int i = a; i >= b; --i)
#define yesno(flag)                                                            \
  if (flag)                                                                    \
    cout << "Yes" << endl;                                                     \
  else                                                                         \
    cout << "No" << endl;
using namespace std;
typedef long long ll;
const int INF = 1000000000LL;
const ll r197 = 1000000007;
typedef pair<int, int> P;
typedef pair<int, P> Pa;

int main() {
  int n;
  int a[10005];
  cin >> n;
  a[0] = 0;
  a[n + 1] = 0;
  int ans = 0;
  rep(i, 1, n + 1) {
    cin >> a[i];
    ans += abs(a[i] - a[i - 1]);
  }
  ans += abs(a[n]);

  rep(i, 1, n + 1) {
    int t = ans;
    ans -= abs(a[i] - a[i - 1]);
    ans -= abs(a[i + 1] - a[i]);
    ans += abs(a[i + 1] - a[i - 1]);
    cout << ans << endl;
    ans = t;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rrep(i, a, b) for (int i = a; i >= b; --i)
#define yesno(flag)                                                            \
  if (flag)                                                                    \
    cout << "Yes" << endl;                                                     \
  else                                                                         \
    cout << "No" << endl;
using namespace std;
typedef long long ll;
const int INF = 1000000000LL;
const ll r197 = 1000000007;
typedef pair<int, int> P;
typedef pair<int, P> Pa;

int main() {
  int n;
  int a[100005];
  cin >> n;
  a[0] = 0;
  a[n + 1] = 0;
  int ans = 0;
  rep(i, 1, n + 1) {
    cin >> a[i];
    ans += abs(a[i] - a[i - 1]);
  }
  ans += abs(a[n]);

  rep(i, 1, n + 1) {
    int t = ans;
    ans -= abs(a[i] - a[i - 1]);
    ans -= abs(a[i + 1] - a[i]);
    ans += abs(a[i + 1] - a[i - 1]);
    cout << ans << endl;
    ans = t;
  }

  return 0;
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000 + 10;
int a[maxn];
int n;
int main() {
  scanf("%d", &n);
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sum += abs(a[i] - a[i - 1]);
  }
  sum += abs(a[n]);
  for (int i = 1; i <= n; ++i) {
    printf("%d\n", sum - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) +
                       abs(a[i + 1] - a[i - 1]));
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int a[maxn];
int n;
int main() {
  scanf("%d", &n);
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sum += abs(a[i] - a[i - 1]);
  }
  sum += abs(a[n]);
  for (int i = 1; i <= n; ++i) {
    printf("%d\n", sum - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) +
                       abs(a[i + 1] - a[i - 1]));
  }
  return 0;
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
/*
problem's name:
statue:
writer:Patrick_y
*/
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define mp make_pair
typedef long long ll;
using namespace std;
const int INF = 20050208;
/*------------main part------------*/

int poi[1000];
int tot;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> poi[i];
  }
  tot += abs(poi[0]);
  for (int i = 1; i < n; i++) {
    tot += abs(poi[i] - poi[i - 1]);
  }
  tot += abs(poi[n - 1]);
  for (int i = 0; i < n; i++) {
    int tmp = tot;
    if (i == 0) {
      tot -= abs(poi[i]);
      tot -= abs(poi[i + 1] - poi[i]);
      tot += abs(poi[i + 1]);
    } else if (i == n - 1) {
      tot -= abs(poi[i - 1] - poi[i]);
      tot -= abs(poi[i]);
      tot += abs(poi[i - 1]);
    } else {
      tot -= abs(poi[i - 1] - poi[i]);
      tot -= abs(poi[i + 1] - poi[i]);
      tot += abs(poi[i + 1] - poi[i - 1]);
    }
    cout << tot << endl;
    tot = tmp;
  }
  return 0;
}


Fixed submission:
/*
problem's name:
statue:
writer:Patrick_y
*/
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define mp make_pair
typedef long long ll;
using namespace std;
const int INF = 20050208;
/*------------main part------------*/

int poi[100005];
int tot;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> poi[i];
  }
  tot += abs(poi[0]);
  for (int i = 1; i < n; i++) {
    tot += abs(poi[i] - poi[i - 1]);
  }
  tot += abs(poi[n - 1]);
  for (int i = 0; i < n; i++) {
    int tmp = tot;
    if (i == 0) {
      tot -= abs(poi[i]);
      tot -= abs(poi[i + 1] - poi[i]);
      tot += abs(poi[i + 1]);
    } else if (i == n - 1) {
      tot -= abs(poi[i - 1] - poi[i]);
      tot -= abs(poi[i]);
      tot += abs(poi[i - 1]);
    } else {
      tot -= abs(poi[i - 1] - poi[i]);
      tot -= abs(poi[i + 1] - poi[i]);
      tot += abs(poi[i + 1] - poi[i - 1]);
    }
    cout << tot << endl;
    tot = tmp;
  }
  return 0;
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
// #include <iomanip>
#include <string>
// #include <algorithm>
// #include <utility>
// #include <stack>
// #include <queue>
// #include <tuple>
// #include <set>
// #include <map>
// #include <unordered_map>
// #include <vector>
// #include <functional>
// #include <bitset>
// #include <cmath>
using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
#define MOD 1000000007

lint mabs(lint a) { return a < 0 ? (-a) : a; }
int main() {
  int A[5002], B[5002], C[5002];
  A[0] = 0;
  int N;
  lint sum = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    B[i] = mabs(A[i - 1] - A[i]);
    sum += B[i];
    if (i >= 2)
      C[i - 1] = B[i - 1] + B[i] - mabs(A[i - 2] - A[i]);
  }
  A[N + 1] = 0;
  B[N + 1] = mabs(A[N] - A[0]);
  sum += B[N + 1];
  C[N] = B[N] + B[N + 1] - mabs(A[N - 1] - A[N + 1]);

  for (int i = 1; i <= N; i++) {
    cout << (sum - C[i]) << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
// #include <iomanip>
#include <string>
// #include <algorithm>
// #include <utility>
// #include <stack>
// #include <queue>
// #include <tuple>
// #include <set>
// #include <map>
// #include <unordered_map>
// #include <vector>
// #include <functional>
// #include <bitset>
// #include <cmath>
using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
#define MOD 1000000007

lint mabs(lint a) { return a < 0 ? (-a) : a; }
int main() {
  int A[100002], B[100002], C[100002];
  A[0] = 0;
  int N;
  lint sum = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    B[i] = mabs(A[i - 1] - A[i]);
    sum += B[i];
    if (i >= 2)
      C[i - 1] = B[i - 1] + B[i] - mabs(A[i - 2] - A[i]);
  }
  A[N + 1] = 0;
  B[N + 1] = mabs(A[N] - A[0]);
  sum += B[N + 1];
  C[N] = B[N] + B[N + 1] - mabs(A[N - 1] - A[N + 1]);

  for (int i = 1; i <= N; i++) {
    cout << (sum - C[i]) << endl;
  }
  return 0;
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr << #x << "=" << x << "\n"
typedef long long ll;
using namespace std;

// const ll MOD=(ll)1e9+7;
// const ll inf=(ll)1e14;
const int dy[] = {1, 0, -1};
const int dx[] = {1, 0, -1};
int n, m, h, w;
string s;
ll a[100001], b[100001];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  // FILE *stream2;
  stream1 = freopen("in", "r", stdin);
  // stream2=freopen("out","w",stdout);
  if (stream1 == NULL)
    return 0;
    // if(stream2==NULL)return 0;
#endif
  cin >> n;
  ll pre = 0;
  a[0] = 0;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += abs(pre - a[i]);
    pre = a[i];
  }
  sum += abs(pre - 0);
  a[n + 1] = 0;
  for (int i = 0; i < n + 1; i++) {
    b[i] = abs(a[i + 1] - a[i]);
  }
  for (int i = 0; i < n; i++) {
    cout << sum - b[i] - b[i + 1] + abs(a[i + 2] - a[i]) << endl;
  }
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  // fclose(stream2);
#endif
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr << #x << "=" << x << "\n"
typedef long long ll;
using namespace std;

// const ll MOD=(ll)1e9+7;
// const ll inf=(ll)1e14;
const int dy[] = {1, 0, -1};
const int dx[] = {1, 0, -1};
int n, m, h, w;
string s;
ll a[100011], b[100011];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  // FILE *stream2;
  stream1 = freopen("in", "r", stdin);
  // stream2=freopen("out","w",stdout);
  if (stream1 == NULL)
    return 0;
    // if(stream2==NULL)return 0;
#endif
  cin >> n;
  ll pre = 0;
  a[0] = 0;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += abs(pre - a[i]);
    pre = a[i];
  }
  sum += abs(pre - 0);
  a[n + 1] = 0;
  for (int i = 0; i < n + 1; i++) {
    b[i] = abs(a[i + 1] - a[i]);
  }
  for (int i = 0; i < n; i++) {
    cout << sum - b[i] - b[i + 1] + abs(a[i + 2] - a[i]) << endl;
  }
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  // fclose(stream2);
#endif
  return 0;
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;
#define int long long

signed main() {
  ios_base::sync_with_stdio(false);

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

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

  for (int i = 1; i < n - 1; ++i) {
    cout << ans - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) +
                abs(a[i - 1] - a[i + 1])
         << '\n';
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;
#define int long long

signed main() {
  ios_base::sync_with_stdio(false);

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

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

  for (int i = 1; i < n - 1; ++i) {
    cout << ans - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) +
                abs(a[i - 1] - a[i + 1])
         << '\n';
  }

  return 0;
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int ddx[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
bool debug = false;

/*---------------------------------------------------*/

int main() {
  int n;
  int a[50005];
  ll sum = 0;
  cin >> n;
  a[0] = 0;
  REP(i, 1, n + 1) cin >> a[i];
  a[n + 1] = 0;
  REP(i, 1, n + 2) {
    sum += abs(a[i - 1] - a[i]);
    // cout<<abs(a[i-1]-a[i])<<endl;
  }
  REP(i, 1, n + 1) {
    cout << (sum - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) +
             abs(a[i - 1] - a[i + 1]))
         << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int ddx[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
bool debug = false;

/*---------------------------------------------------*/

int main() {
  int n;
  int a[100010] = {0};
  ll sum = 0;
  cin >> n;
  a[0] = 0;
  REP(i, 1, n + 1) cin >> a[i];
  a[n + 1] = 0;
  REP(i, 1, n + 2) {
    sum += abs(a[i - 1] - a[i]);
    // cout<<abs(a[i-1]-a[i])<<endl;
  }
  REP(i, 1, n + 1) {
    cout << (sum - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) +
             abs(a[i - 1] - a[i + 1]))
         << endl;
  }
  return 0;
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int sum = 0;
  int a[5010];
  a[0] = 0;
  a[N + 1] = 0;
  rep(i, N) cin >> a[i + 1];
  rep(i, N + 1) { sum += abs(a[i + 1] - a[i]); }
  rep(i, N) {
    cout << sum - abs(a[i + 1] - a[i]) - abs(a[i + 2] - a[i + 1]) +
                abs(a[i + 2] - a[i])
         << endl;
  }

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int sum = 0;
  int a[105010];
  a[0] = 0;
  a[N + 1] = 0;
  rep(i, N) cin >> a[i + 1];
  rep(i, N + 1) { sum += abs(a[i + 1] - a[i]); }
  rep(i, N) {
    cout << sum - abs(a[i + 1] - a[i]) - abs(a[i + 2] - a[i + 1]) +
                abs(a[i + 2] - a[i])
         << endl;
  }

  return 0;
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
int main() {
  ll n;
  cin >> n;
  vector<ll> a;
  ll cost[5140];
  a.pb(0);
  for (int i = 0; i < n; i++) {
    ll x;
    cin >> x;
    a.pb(x);
  }
  a.pb(0);
  ll sum = 0;
  for (int i = 1; i <= n + 1; i++) {
    cost[i] = abs(a[i] - a[i - 1]);
    sum += cost[i];
  }
  for (int i = 1; i <= n; i++) {
    if ((a[i - 1] <= a[i] && a[i] <= a[i + 1]) ||
        (a[i - 1] >= a[i] && a[i] >= a[i + 1])) {
      cout << sum << endl;
    } else if ((a[i - 1] <= a[i + 1] && a[i + 1] <= a[i]) ||
               (a[i - 1] >= a[i + 1] && a[i + 1] >= a[i])) {
      cout << sum - 2 * cost[i + 1] << endl;
    } else {
      cout << sum - 2 * cost[i] << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
int main() {
  ll n;
  cin >> n;
  vector<ll> a;
  ll cost[114514];
  a.pb(0);
  for (int i = 0; i < n; i++) {
    ll x;
    cin >> x;
    a.pb(x);
  }
  a.pb(0);
  ll sum = 0;
  for (int i = 1; i <= n + 1; i++) {
    cost[i] = abs(a[i] - a[i - 1]);
    sum += cost[i];
  }
  for (int i = 1; i <= n; i++) {
    if ((a[i - 1] <= a[i] && a[i] <= a[i + 1]) ||
        (a[i - 1] >= a[i] && a[i] >= a[i + 1])) {
      cout << sum << endl;
    } else if ((a[i - 1] <= a[i + 1] && a[i + 1] <= a[i]) ||
               (a[i - 1] >= a[i + 1] && a[i + 1] >= a[i])) {
      cout << sum - 2 * cost[i + 1] << endl;
    } else {
      cout << sum - 2 * cost[i] << endl;
    }
  }
  return 0;
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i, a, b) for (register sign i = (sign)a; i <= (sign)b; ++i)
#define Fordown(i, a, b) for (register sign i = (sign)a; i >= (sign)b; --i)
bool cmax(sign &a, sign b) { return (a < b) ? a = b, 1 : 0; }
bool cmin(sign &a, sign b) { return (a > b) ? a = b, 1 : 0; }
template <typename T> T read() {
  T ans = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-')
    ch = getchar();
  if (ch == '-')
    f = -1, ch = getchar();
  while (isdigit(ch))
    ans = (ans << 3) + (ans << 1) + (ch - '0'), ch = getchar();
  return ans * f;
}
template <typename T> void write(T x, char y) {
  if (x == 0) {
    putchar('0');
    putchar(y);
    return;
  }
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  static char wr[20];
  int top = 0;
  for (; x; x /= 10)
    wr[++top] = x % 10 + '0';
  while (top)
    putchar(wr[top--]);
  putchar(y);
}
void file() {
#ifndef ONLINE_JUDGE
  freopen("c.in", "r", stdin);
  freopen("c.out", "w", stdout);
#endif
}
const int N = 100 + 5;
int n, a[N];
ll sum[N];
void input() {
  n = read<int>();
  For(i, 1, n) a[i] = read<int>();
}
void work() {
  ll ans, res = 0;
  For(i, 1, n + 1) res += abs(a[i] - a[i - 1]);
  For(i, 1, n) {
    ans = res - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) +
          abs(a[i + 1] - a[i - 1]);
    write(ans, '\n');
  }
}
int main() {

  input();
  work();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i, a, b) for (register sign i = (sign)a; i <= (sign)b; ++i)
#define Fordown(i, a, b) for (register sign i = (sign)a; i >= (sign)b; --i)
bool cmax(sign &a, sign b) { return (a < b) ? a = b, 1 : 0; }
bool cmin(sign &a, sign b) { return (a > b) ? a = b, 1 : 0; }
template <typename T> T read() {
  T ans = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-')
    ch = getchar();
  if (ch == '-')
    f = -1, ch = getchar();
  while (isdigit(ch))
    ans = (ans << 3) + (ans << 1) + (ch - '0'), ch = getchar();
  return ans * f;
}
template <typename T> void write(T x, char y) {
  if (x == 0) {
    putchar('0');
    putchar(y);
    return;
  }
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  static char wr[20];
  int top = 0;
  for (; x; x /= 10)
    wr[++top] = x % 10 + '0';
  while (top)
    putchar(wr[top--]);
  putchar(y);
}
void file() {
#ifndef ONLINE_JUDGE
  freopen("c.in", "r", stdin);
  freopen("c.out", "w", stdout);
#endif
}
const int N = 1e5 + 5;
int n, a[N];
ll sum[N];
void input() {
  n = read<int>();
  For(i, 1, n) a[i] = read<int>();
}
void work() {
  ll ans, res = 0;
  For(i, 1, n + 1) res += abs(a[i] - a[i - 1]);
  For(i, 1, n) {
    ans = res - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) +
          abs(a[i + 1] - a[i - 1]);
    write(ans, '\n');
  }
}
int main() {

  input();
  work();
  return 0;
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;

  vector<int> a(n + 2);
  for (int i = 0; i < n; i++) {
    cin >> a[i + 1];
  }
  a[0] = a[n + 1] = 0;

  vector<int> b(n);
  for (int i = 1; i < n + 2; i++) {
    b[i] = abs(a[i] - a[i - 1]);
  }

  for (int i = 1; i < n + 2; i++) {
    b[i] += b[i - 1];
  }

  for (int i = 0; i < n; i++) {
    cout << b[i] + abs(a[i] - a[i + 2]) + (b[n + 1] - b[i + 2]) << '\n';
  }
  cout << flush;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;

  vector<int> a(n + 2);
  for (int i = 0; i < n; i++) {
    cin >> a[i + 1];
  }
  a[0] = a[n + 1] = 0;

  vector<int> b(n + 2);
  for (int i = 1; i < n + 2; i++) {
    b[i] = abs(a[i] - a[i - 1]);
  }

  for (int i = 1; i < n + 2; i++) {
    b[i] += b[i - 1];
  }

  for (int i = 0; i < n; i++) {
    cout << b[i] + abs(a[i] - a[i + 2]) + (b[n + 1] - b[i + 2]) << '\n';
  }
  cout << flush;

  return 0;
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

ll a[10003];
ll b[10003];
int main() {
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (ll i = 1; i <= n + 1; i++) {
    b[i] = abs(a[i] - a[i - 1]) + b[i - 1];
  }
  ll sum = b[n + 1];
  for (ll i = 0; i < n; i++) {
    ll now = sum + abs(a[i + 2] - a[i]);
    now -= b[i + 2] - b[i];
    cout << now << endl;
  }
  // your code goes here
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

ll a[100003];
ll b[100003];
int main() {
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (ll i = 1; i <= n + 1; i++) {
    b[i] = abs(a[i] - a[i - 1]) + b[i - 1];
  }
  ll sum = b[n + 1];
  for (ll i = 0; i < n; i++) {
    ll now = sum + abs(a[i + 2] - a[i]);
    now -= b[i + 2] - b[i];
    cout << now << endl;
  }
  // your code goes here
  return 0;
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int f(int x) { return x < 0 ? -x : x; }

int a[5001], sum[5001];

int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + f(a[i] - a[i - 1]);
  }
  for (i = 1; i < n; i++)
    printf("%d\n",
           f(a[n]) + sum[n] + f(a[i + 1] - a[i - 1]) - sum[i + 1] + sum[i - 1]);
  printf("%d\n", sum[n - 1] + f(a[n - 1]));
}

Fixed submission:
#include <stdio.h>

int f(int x) { return x < 0 ? -x : x; }

int a[500001], sum[500001];

int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + f(a[i] - a[i - 1]);
  }
  for (i = 1; i < n; i++)
    printf("%d\n",
           f(a[n]) + sum[n] + f(a[i + 1] - a[i - 1]) - sum[i + 1] + sum[i - 1]);
  printf("%d\n", sum[n - 1] + f(a[n - 1]));
}