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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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>;

typedef long long ll;
typedef long double ld;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  vector<ll> arr(n);
  ll s = 0;
  for (int z = 0; z < n; z++) {
    cin >> arr[z];
    s += arr[z];
  }
  vector<ll> pre(n);
  pre[0] = 2 * arr[0];
  pre[1] = 2 * arr[0];
  for (int z = 2; z < n - 1; z += 2) {
    pre[z] = pre[z - 2] + 2 * arr[z];
    pre[z + 1] = pre[z];
  }
  vector<ll> suff(n);
  suff[n - 1] = 2 * arr[n - 2];
  suff[n - 2] = 2 * arr[n - 2];
  for (int z = n - 3; z > 0; z -= 2) {
    suff[z] = suff[z + 2] + 2 * arr[z - 1];
    suff[z - 1] = suff[z];
  }
  vector<ll> ans(n);
  for (int z = 0; z < n; z += 2) {
    ans[z] = s;
    if (z < n - 1)
      ans[z] -= suff[z + 1];
    if (z > 0)
      ans[z] -= pre[z - 1];
    ans[z + 1] = 2 * arr[z] - ans[z];
  }
  for (ll i : ans) {
    cout << i << " ";
  }
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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>;

typedef long long ll;
typedef long double ld;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  vector<ll> arr(n);
  ll s = 0;
  for (int z = 0; z < n; z++) {
    cin >> arr[z];
    s += arr[z];
  }
  vector<ll> pre(n);
  pre[0] = 2 * arr[0];
  pre[1] = 2 * arr[0];
  for (int z = 2; z < n - 1; z += 2) {
    pre[z] = pre[z - 2] + 2 * arr[z];
    pre[z + 1] = pre[z];
  }
  vector<ll> suff(n);
  suff[n - 1] = 2 * arr[n - 2];
  suff[n - 2] = 2 * arr[n - 2];
  for (int z = n - 3; z > 0; z -= 2) {
    suff[z] = suff[z + 2] + 2 * arr[z - 1];
    suff[z - 1] = suff[z];
  }
  vector<ll> ans(n);
  for (int z = 0; z < n; z += 2) {
    ans[z] = s;
    if (z < n - 1)
      ans[z] -= suff[z + 1];
    if (z > 0)
      ans[z] -= pre[z - 1];
    if (z < n - 1)
      ans[z + 1] = 2 * arr[z] - ans[z];
  }
  for (ll i : ans) {
    cout << i << " ";
  }
  cout << endl;
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <limits>
#include <numeric>
#include <vector>

int main() {
  int N;
  std::cin >> N;

  std::vector<long long> a;
  a.reserve(N);
  long long x;
  for (int i = 0; i < N; ++i) {
    std::cin >> x;
    a.push_back(x);
  }

  const auto N_half = N / 2LL;
  const auto b_sum = std::accumulate(a.cbegin(), a.cend(), 0LL);

  std::vector<long long> b;
  b.reserve(N);

  for (int i = 0; i < N; ++i) {
    auto others = 0LL;
    for (int j = 0; j < N_half; ++j) {
      const auto idx = (i + 1 + 2 * j) % N;
      others += a[idx];
    }
    b.push_back(b_sum - 2 * others);
  }

  for (int i = 0; i < N; ++i) {
    std::cout << b[i];
    if (i < N) {
      std::cout << " ";
    } else {
      std::cout << std::endl;
    }
  }
}


Fixed submission:
#include <iostream>
#include <limits>
#include <numeric>
#include <vector>

int main() {
  int N;
  std::cin >> N;

  std::vector<long long> a;
  a.reserve(N);
  long long x;
  for (int i = 0; i < N; ++i) {
    std::cin >> x;
    a.push_back(x);
  }

  const auto N_half = N / 2LL;
  const auto b_sum = std::accumulate(a.cbegin(), a.cend(), 0LL);

  std::vector<long long> b;
  b.reserve(N);

  auto others = 0LL;
  for (int j = 0; j < N_half; ++j) {
    others += a[1 + 2 * j];
  }
  b.push_back(b_sum - 2 * others);

  for (int i = 1; i < N; ++i) {
    b.push_back(2LL * a[i - 1] - b[i - 1]);
  }

  for (int i = 0; i < N; ++i) {
    std::cout << b[i];
    if (i < N) {
      std::cout << " ";
    } else {
      std::cout << std::endl;
    }
  }
}
Problem p02984 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const ll M = 1e4 + 5;
ll a[M], ans[M];
inline ll read() {
  ll x = 0, f = 1;
  char ch = 0;
  while (!isdigit(ch))
    f = (ch == '-' ? -1 : 1), ch = getchar();
  while (isdigit(ch))
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return x * f;
}
int main() {
  ll n = read(), sum = 0, s = 0;
  for (register ll i = 1; i <= n; i++) {
    a[i] = read();
    a[i] *= 2;
    sum += a[i];
    if (i % 2)
      s += a[i];
  }
  sum = sum / 2 - s + a[n];
  ans[n] = sum;
  for (register ll i = n - 1; i >= 1; i--) {
    ans[i] = a[i] - ans[i + 1];
  }
  for (register ll i = 1; i <= n; i++) {
    printf("%lld ", ans[i]);
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const ll M = 1e5 + 5;
ll a[M], ans[M];
inline ll read() {
  ll x = 0, f = 1;
  char ch = 0;
  while (!isdigit(ch))
    f = (ch == '-' ? -1 : 1), ch = getchar();
  while (isdigit(ch))
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return x * f;
}
int main() {
  ll n = read(), sum = 0, s = 0;
  for (register ll i = 1; i <= n; i++) {
    a[i] = read();
    a[i] *= 2;
    sum += a[i];
    if (i % 2)
      s += a[i];
  }
  sum = sum / 2 - s + a[n];
  ans[n] = sum;
  for (register ll i = n - 1; i >= 1; i--) {
    ans[i] = a[i] - ans[i + 1];
  }
  for (register ll i = 1; i <= n; i++) {
    printf("%lld ", ans[i]);
  }
  return 0;
}
Problem p02984 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;

long long int a[10000];
long long arr[10000];
int main() {
  int n;
  //	scanf("%d",&n);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    //		scanf("%d",&a[i]);
    cin >> a[i];
  }
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 2 != 0) {
      sum += a[i];
    } else {
      sum -= a[i];
    }
  }
  arr[1] = sum / 2;
  //	printf("%d\n",sum);
  for (int i = 2; i <= n; i++) {
    arr[i] = a[i - 1] - arr[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    if (i == 1) {
      cout << 2 * arr[i];
      //			printf("%d",2*arr[i]);
    } else {
      cout << " " << 2 * arr[i];
      //			printf(" %d",2*arr[i]);
    }
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;

long long int a[100000000];
long long arr[100000000];
int main() {
  int n;
  //	scanf("%d",&n);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    //		scanf("%d",&a[i]);
    cin >> a[i];
  }
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 2 != 0) {
      sum += a[i];
    } else {
      sum -= a[i];
    }
  }
  arr[1] = sum / 2;
  //	printf("%d\n",sum);
  for (int i = 2; i <= n; i++) {
    arr[i] = a[i - 1] - arr[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    if (i == 1) {
      cout << 2 * arr[i];
      //			printf("%d",2*arr[i]);
    } else {
      cout << " " << 2 * arr[i];
      //			printf(" %d",2*arr[i]);
    }
  }
  return 0;
}
Problem p02984 (C++)

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

#define MAX 5

int main() {
  long long N;
  cin >> N;
  long long ans[MAX];
  long long A[MAX];
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  for (int i = 1; i < N; i += 2) {
    sum -= 2 * A[i];
  }
  ans[0] = sum;
  for (int i = 1; i < N; i++) {
    ans[i] = 2 * A[i - 1] - ans[i - 1];
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}

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

#define MAX 100000

int main() {
  long long N;
  cin >> N;
  long long ans[MAX];
  long long A[MAX];
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  for (int i = 1; i < N; i += 2) {
    sum -= 2 * A[i];
  }
  ans[0] = sum;
  for (int i = 1; i < N; i++) {
    ans[i] = 2 * A[i - 1] - ans[i - 1];
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
Problem p02984 (C++)

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

int main() {
  int n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll x2 = 0;
  rep(i, n) {
    if (i % 2)
      x2 -= a[i];
    else
      x2 += a[i];
  }
  vector<int> ans(n);
  ans[0] = x2 / 2;
  rep(i, n - 1) { ans[i + 1] = a[i] - ans[i]; }
  rep(i, n) ans[i] *= 2;
  rep(i, n) printf("%d%c", ans[i], i == n - 1 ? '\n' : ' ');
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll x2 = 0;
  rep(i, n) {
    if (i % 2)
      x2 -= a[i];
    else
      x2 += a[i];
  }
  vector<int> ans(n);
  ans[0] = x2 / 2;
  rep(i, n - 1) { ans[i + 1] = a[i] - ans[i]; }
  rep(i, n) ans[i] *= 2;
  rep(i, n) printf("%d%c", ans[i], i == n - 1 ? '\n' : ' ');
  return 0;
}
Problem p02984 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
  int a;
  scanf("%d", &a);
  return a;
}

ll gli() {
  ll a;
  scanf("%lld", &a);
  return a;
}

int a[10000];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int s = 0;
  int n = gi();
  for (int i = 0; i < n; i++) {
    a[i] = gi();
    s += (i % 2 ? -1 : 1) * a[i];
  }

  printf("%d ", s);
  s /= 2;
  for (int i = 1; i < n; i++) {
    s = a[i - 1] - s;
    printf("%d%c", s * 2, (i == n - 1 ? '\n' : ' '));
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
  int a;
  scanf("%d", &a);
  return a;
}

ll gli() {
  ll a;
  scanf("%lld", &a);
  return a;
}

int a[100000];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int s = 0;
  int n = gi();
  for (int i = 0; i < n; i++) {
    a[i] = gi();
    s += (i % 2 ? -1 : 1) * a[i];
  }

  printf("%d ", s);
  s /= 2;
  for (int i = 1; i < n; i++) {
    s = a[i - 1] - s;
    printf("%d%c", s * 2, (i == n - 1 ? '\n' : ' '));
  }

  return 0;
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
//
// Created by kuroneko on 2019-07-06.
//

#include <iostream>

typedef long long ll;
using namespace std;

int main() {
  int N;
  cin >> N;
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  ll x[N];
  for (int i = 0; i < N; i++) {
    x[i] = A[i];
    for (int j = 1; j < N; j++) {
      if (j % 2 == 1)
        x[i] -= A[(i + j) % N];
      else
        x[i] += A[(i + j) % N];
    }
  }

  for (int i = 0; i < N; i++) {
    cout << x[i];
    if (i != N - 1)
      cout << ' ';
  }
  cout << endl;
  return 0;
}

Fixed submission:
//
// Created by kuroneko on 2019-07-06.
//

#include <iostream>

typedef long long ll;
using namespace std;

int main() {
  int N;
  cin >> N;
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  ll x[N];
  x[0] = A[0];
  for (int j = 1; j < N; j++) {
    if (j % 2 == 1)
      x[0] -= A[j % N];
    else
      x[0] += A[j % N];
  }

  for (int i = 0; i < N - 1; i++) {
    x[i + 1] = -x[i] + 2 * A[i];
  }

  for (int i = 0; i < N; i++) {
    cout << x[i];
    if (i != N - 1)
      cout << ' ';
  }
  cout << endl;
  return 0;
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#define ll long long
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define UNIQUE(a) unique(a.begin(), a.end())
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

const ll mod = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  vl a(n);
  REP(i, n) { cin >> a[i]; }

  ll sum = 0;
  REP(i, n) {
    sum = 0;
    REP(j, n) { sum += a[(i + j) % n] * pow(-1, j % 2); }
    cout << sum << " ";
  }
  cout << endl;
}


Fixed submission:
#define ll long long
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define UNIQUE(a) unique(a.begin(), a.end())
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

const ll mod = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  vl a(n);
  REP(i, n) { cin >> a[i]; }

  ll sum = 0;
  REP(j, n) { sum += a[j % n] * pow(-1, j % 2); }
  cout << sum << " ";

  FOR(i, 1, n) {
    sum = 2 * a[i - 1] - sum;
    cout << sum << " ";
  }
  cout << endl;
}
Problem p02984 (C++)

Buggy submission (status: Runtime Error):
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 11111111111;
const int c_mINF = -11111111111;
const int c_YET = -1;
const int c_Dx[4] = {0, 0, 1, -1};
const int c_Dy[4] = {1, -1, 0, 0};

int main() {
  int N, A[10000], X[10000];
  // 入力
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d", &A[i]);

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

  for (int i = 0; i < N / 2; i++)
    X[0] += A[2 * i] - A[2 * i + 1];
  X[0] += A[N - 1];
  X[0] /= 2;
  // printf("%d\n",X[0]);

  for (int i = 0; i < N - 1; i++) {
    X[i + 1] = A[i] - X[i];
  }
  for (int i = 0; i < N; i++)
    printf("%d ", 2 * X[i]);

  /*
                  for i in range(N - 1) :
                          X.aappend(A[i] - X[i])

                          print(X)

  */
}

/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
　　　　　　　　↓
         ＜＜提出先＞＞に注意して提出！！
*/

Fixed submission:
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 11111111111;
const int c_mINF = -11111111111;
const int c_YET = -1;
const int c_Dx[4] = {0, 0, 1, -1};
const int c_Dy[4] = {1, -1, 0, 0};

int main() {
  int N, A[100000], X[100000];
  // 入力
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d", &A[i]);

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

  for (int i = 0; i < N / 2; i++)
    X[0] += A[2 * i] - A[2 * i + 1];
  X[0] += A[N - 1];
  X[0] /= 2;
  // printf("%d\n",X[0]);

  for (int i = 0; i < N - 1; i++) {
    X[i + 1] = A[i] - X[i];
  }
  for (int i = 0; i < N; i++)
    printf("%d ", 2 * X[i]);

  /*
                  for i in range(N - 1) :
                          X.aappend(A[i] - X[i])

                          print(X)

  */
}

/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
　　　　　　　　↓
         ＜＜提出先＞＞に注意して提出！！
*/
Problem p02984 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

// bool flag = __builtin_add_overflow(a , b , &tmp);
// bool flag = __builtin_mul_overflow(a , b , &tmp);
// bool flag3= __builtin_sub_overflow(a , b , &tmp);

using namespace std;
// using namespace __gnu_cxx;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 10004, MAXM = 102, Mod = 1000000007, MAXLog = 20;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9),
      cout << fixed;

  int n;
  cin >> n;
  vector<long long> arr(n);
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    arr[i] *= 2;
    if (i & 1) {
      sum -= arr[i];
    } else {
      sum += arr[i];
    }
  }
  sum /= 2;
  cout << sum << ' ';
  for (int i = 0; i < n - 1; ++i) {
    cout << arr[i] - sum << ' ';
    sum = arr[i] - sum;
  }
  cout << '\n';

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
// #include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

// bool flag = __builtin_add_overflow(a , b , &tmp);
// bool flag = __builtin_mul_overflow(a , b , &tmp);
// bool flag3= __builtin_sub_overflow(a , b , &tmp);

using namespace std;
// using namespace __gnu_cxx;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 10004, MAXM = 102, Mod = 1000000007, MAXLog = 20;

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9),
      cout << fixed;

  int n;
  cin >> n;
  vector<long long> arr(n);
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    arr[i] *= 2;
    if (i & 1) {
      sum -= arr[i];
    } else {
      sum += arr[i];
    }
  }
  sum /= 2;
  cout << sum << ' ';
  for (int i = 0; i < n - 1; ++i) {
    cout << arr[i] - sum << ' ';
    sum = arr[i] - sum;
  }
  cout << '\n';

  return 0;
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

const int m = 1000000007;

int main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  ll sum = 0;
  rep(i, n) sum += a[i];
  int m = (n - 1) / 2;
  rep(i, n) {
    ll sum2 = 0;
    int k = i + 1;
    rep(j, m) {
      if (k >= n)
        k -= n;
      sum2 += a[k];
      k += 2;
    }
    sum2 *= 2;
    cout << sum - sum2 << "\n";
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

const int m = 1000000007;

int main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  ll sum = 0;
  rep(i, n) sum += a[i];
  int m = (n - 1) / 2;
  for (int i = 1; i < n; i += 2) {
    sum -= a[i] * 2;
  }
  sum /= 2;
  cout << sum * 2 << "\n";
  for (int i = 0; i < n - 1; i++) {
    sum = (a[i] - sum);
    cout << sum * 2 << "\n";
  }

  return 0;
}
Problem p02984 (C++)

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

long long n;
vector<long long> a, ans;

void solve();

int main() {
  cin >> n;
  a.resize(n);
  ans.assign(n, 0);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  solve();
  for (int i = 0; i < n; ++i) {
    if (i != 0)
      cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

void solve() {
  long long sum = 0;
  for (int i = 0; i < n; ++i)
    if (i % 2)
      sum -= a[i];
    else
      sum += a[i];
  ans[0] = sum;
  for (int i = 0; i < n; ++i) {
    ans[i + 1] = (a[i] - ans[i] / 2) * 2;
  }
}


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

long long n;
vector<long long> a, ans;

void solve();

int main() {
  cin >> n;
  a.resize(n);
  ans.assign(n, 0);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  solve();
  for (int i = 0; i < n; ++i) {
    if (i != 0)
      cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

void solve() {
  long long sum = 0;
  for (int i = 0; i < n; ++i)
    if (i % 2)
      sum -= a[i];
    else
      sum += a[i];
  ans[0] = sum;
  for (int i = 0; i < n; ++i) {
    ans[(i + 1) % n] = (a[i] - ans[i] / 2) * 2;
  }
}
Problem p02984 (C++)

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

int main() {
  int n;
  ll a_sum = 0;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, n) {
    cin >> a[i];
    a_sum += a[i];
  }
  rep(i, n) {
    if (i == 0) {
      for (int j = i + 1; j < n; j += 2) {
        a_sum -= 2 * a[j];
      }
      b[0] = a_sum;
    }
    b[i + 1] = 2 * a[i] - b[i];
    cout << b[i];
    if (i < n - 1) {
      cout << " ";
    }
  }
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long mod = 2019;
using namespace std;
using ll = long long;

int main() {
  int n;
  ll a_sum = 0;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, n) {
    cin >> a[i];
    a_sum += a[i];
  }
  rep(i, n) {
    if (i == 0) {
      for (int j = i + 1; j < n; j += 2) {
        a_sum -= 2 * a[j];
      }
      b[0] = a_sum;
    }
    if (i < n - 1) {
      b[i + 1] = 2 * a[i] - b[i];
    }
    cout << b[i];
    if (i < n - 1) {
      cout << " ";
    }
  }
  cout << endl;
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N), B(N);
  ll sum = 0;
  rep(i, N) {
    cin >> A[i];
    sum += A[i];
  }
  rep(i, N) {
    B[i] = sum;
    int sub = i + 1;
    rep(j, N / 2) {
      B[i] -= 2 * A[sub % N];
      sub += 2;
    }
  }

  rep(i, N) cout << B[i] << ' ';
  cout << endl;
}

Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N), B(N);
  ll sum = 0;
  rep(i, N) {
    cin >> A[i];
    sum += A[i];
  }

  B[0] = sum;
  for (int i = 1; i < N; i += 2)
    B[0] -= 2 * A[i];

  for (int i = 1; i < N; i++) {
    B[i] = 2 * A[i - 1] - B[i - 1];
  }

  rep(i, N) cout << B[i] << ' ';
  cout << endl;
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define inf 2147483647
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rr read()
#define ll long long
#define repb(i, a, b) for (int i = a; i <= b; i++)
#define CloseIo ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 1e5 + 5;
ll a[N] = {0};
int main() {
  ll n;
  CloseIo;
  cin >> n;
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) {
    ll ans = 0;
    ll flag = 1;
    rep(j, 0, n) {
      ans += (a[((i + j) % n)] * flag);
      flag = -flag;
    }
    printf("%lld%s", ans, i == n - 1 ? "" : " ");
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define inf 2147483647
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rr read()
#define ll long long
#define repb(i, a, b) for (int i = a; i <= b; i++)
#define CloseIo ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 1e5 + 5;
ll a[N] = {0};
int main() {
  ll n;
  CloseIo;
  cin >> n;
  rep(i, 0, n) cin >> a[i];

  ll ans = 0;
  ll flag = 1;
  rep(j, 0, n) {
    ans += (a[j] * flag);
    flag = -flag;
  }
  vector<ll> v;
  v.push_back(ans);
  for (int i = 0; i < n - 1; i++) {
    ans = 2 * a[i] - ans;
    // printf("%lld",ans);
    v.push_back(ans);
  }
  for (int i = 0; i < v.size(); i++) {
    printf("%lld%s", v[i], i == v.size() - 1 ? "" : " ");
  }
}
Problem p02984 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  vector<int64_t> x(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int64_t sum = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      sum += A[i];
    } else {
      sum -= A[i];
    }
  }
  x[0] = sum;
  for (int i = 1; i < N; i--) {
    x[i] = A[i - 1] * 2 - x[i - 1];
  }
  for (int i = 0; i < N - 1; i++) {
    cout << x[i] << " ";
  }
  cout << x[N - 1] << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  vector<int64_t> x(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int64_t sum = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      sum += A[i];
    } else {
      sum -= A[i];
    }
  }
  x[0] = sum;
  for (int i = 1; i < N; i++) {
    x[i] = A[i - 1] * 2 - x[i - 1];
  }
  for (int i = 0; i < N - 1; i++) {
    cout << x[i] << " ";
  }
  cout << x[N - 1] << endl;
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define INF (1LL << 60)

#define REP(i, m, n) for (ll(i) = (m), i##_len = (n); (i) < (i##_len); ++(i))
#define FORR(i, v) for (auto(i) : v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define pb push_back

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  ll S = 0;
  REP(i, 0, N) S += A[i];

  ll T;
  REP(i, 0, N) {
    T = 0;
    if (i % 2 == 0) {
      for (ll j = 0; j <= i - 2; j += 2)
        T += A[j];
      for (ll j = i + 1; j <= N - 2; j += 2)
        T += A[j];
    } else {
      for (ll j = 1; j <= i - 2; j += 2)
        T += A[j];
      for (ll j = i + 1; j <= N - 1; j += 2)
        T += A[j];
    }
    _PS(S - T * 2);
  }

  return 0;
}

/*



*/

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

using namespace std;
using ll = long long;

#define INF (1LL << 60)

#define REP(i, m, n) for (ll(i) = (m), i##_len = (n); (i) < (i##_len); ++(i))
#define FORR(i, v) for (auto(i) : v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define pb push_back

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  ll S = 0;
  REP(i, 0, N) S += A[i];

  ll T = 0;
  for (ll i = 1; i <= N - 2; i += 2)
    T += A[i];
  ll x = S - T * 2;
  _PS(x);
  REP(i, 1, N) {
    x = 2 * A[i - 1] - x;
    _PS(x);
  }

  return 0;
}

/*



*/
Problem p02984 (Python)

Buggy submission (status: Runtime Error):
import sys
import numpy as np


def input():
    return sys.stdin.readline().rstrip()


def main():
    n = int(input())
    a = [int(e) for e in input().split()]
    va = np.array(a)
    m = np.identity(n, dtype=int)
    for i in range(n):
        if i < n - 1:
            m[i][i + 1] = 1
        else:
            m[i][0] = 1
    vx = np.linalg.solve(m, va).astype(np.int) * 2
    print(*vx)


main()


Fixed submission:
import sys
import numpy as np


def input():
    return sys.stdin.readline().rstrip()


def main():
    n = int(input())
    a = [int(e) for e in input().split()]
    x = [0 for _ in range(n)]
    x[0] = sum(a) - (sum(a[1:n:2]) * 2)
    for i in range(2, n, 2):
        x[i] = x[i - 2] + ((a[i - 1] - a[i - 2]) * 2)
    x[1] = sum(a) - (sum(a[2:n:2]) * 2)
    for i in range(3, n, 2):
        x[i] = x[i - 2] + ((a[i - 1] - a[i - 2]) * 2)
    print(*x)


main()
Problem p02984 (Python)

Buggy submission (status: Time Limit Exceeded):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    x_sum = sum(a) // 2
    x = [0] * n
    for i in range(n):
        tmp = x_sum
        idx = (i + 1) % n
        for _ in range((n - 1) // 2):
            tmp -= a[idx]
            idx += 2
            idx %= n
        x[i] = 2 * tmp
    print(*x)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    x_sum = sum(a) // 2
    x = [0] * n
    tmp = x_sum
    idx = 1
    for _ in range((n - 1) // 2):
        tmp -= a[idx]
        idx += 2
        idx %= n
    x[0] = 2 * tmp
    for i in range(n - 1):
        x[i + 1] = 2 * (a[i] - x[i] // 2)
    print(*x)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
Problem p02984 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = sum(a) / 2
p = int((n - 1) / 2)

x = []

for i in range(n):
    t = b
    for j in range(p):
        t -= a[(2 * j + i + 1) % n]
    x.append(t * 2)

for i in range(n):
    print(int(x[i]), end=" ")


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = sum(a) / 2
p = int((n - 1) / 2)

x = []

t = b
for j in range(p):
    t -= a[2 * j + 1]
x.append(t * 2)

for i in range(n - 1):
    t = a[i] - x[i] / 2
    x.append(t * 2)

for i in range(n):
    print(int(x[i]), end=" ")
Problem p02984 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3
n = int(input())
a = [int(x) for x in input().split()]

ans = [sum(a[(i + j) % n] * (-1) ** (j % 2) for j in range(n)) for i in range(n)]

print(" ".join(str(x) for x in ans))


Fixed submission:
#!/usr/bin/env python3
n = int(input())
a = [int(x) for x in input().split()]

v = sum(a[i] * (-1) ** (i % 2) for i in range(n))

ans = [0] * n

for i in range(n):
    ans[i] = v
    v = -v + 2 * a[i]

print(" ".join(str(x) for x in ans))
Problem p02984 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = []
    for i in range(N):
        s = 0
        for j, a in enumerate(A):
            s += a * (1 if (((j - i) % N) % 2 == 0) else -1)
        ans.append(str(s))
    return ans


def main():
    print(" ".join(solve()))


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = []
    s = 0
    for j, a in enumerate(A):
        s += a * (1 if ((j % N) % 2 == 0) else -1)
    ans.append(str(s))
    for i in range(1, N):
        s = -s + 2 * A[i - 1]
        ans.append(str(s))
    return ans


def main():
    print(" ".join(solve()))


if __name__ == "__main__":
    main()
Problem p02984 (Python)

Buggy submission (status: Time Limit Exceeded):
from collections import deque

n = int(input())
A = list(map(int, input().split()))

sum_even = sum(A[::2])
sum_odd = sum(A[1::2]) + A[0]
ANS = A[:]
A = deque(A)
minus = False
for _ in range(n - 1):
    A.rotate(-1)
    for i in range(n):
        if minus:
            ANS[i] -= A[i]
        else:
            ANS[i] += A[i]
    minus = not minus
ANS = deque(ANS)
ANS.rotate()
print(*ANS)


Fixed submission:
from collections import deque

n = int(input())
A = list(map(int, input().split()))

B = [0] * n
B[0] = A[0]
B[1] = A[1]
for i in range(2, n):
    B[i] = B[i - 2] + A[i]

ANS = [0] * n
for i in range(n):
    ans = 0
    if i % 2 == 0:
        ans += B[-1] - B[-2]
    else:
        ans += B[-2] - B[-1]

    if i - 2 >= 0:
        ans -= B[i - 2] * 2

    if i - 1 >= 0:
        ans += B[i - 1] * 2

    ANS[i] = ans

print(*ANS)
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
typedef pair<int, int> P;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

  int n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];

  ll l = -1, r = 2e9;
  while (1) {
    long double mid = (l + r) / 2;
    long double b[n];
    long long memo[n];
    rep(i, n) b[i] = 0;
    b[n - 1] += mid / 2;
    b[0] += mid / 2;
    memo[0] = mid;
    rep(i, n - 1) {
      long double rain = (long double)a[i] - b[i];
      b[i] += rain;
      b[i + 1] += rain;
      memo[i + 1] = rain * 2;
    }
    if (a[n - 1] == b[n - 1]) {
      rep(i, n) {
        if (i == n - 1)
          cout << memo[i] << endl;
        else
          cout << memo[i] << " ";
      }
      return 0;
    } else if (a[n - 1] > b[n - 1]) {
      l = mid;
    } else {
      r = mid;
    }
  }

  return 0;
}

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
typedef pair<int, int> P;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

  int n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];

  ll l = -1LL, r = (ll)2e9 + (ll)10;
  while (1) {
    long double mid = (l + r) / 2;
    long double b[n];
    long long memo[n];
    rep(i, n) b[i] = 0;
    b[n - 1] += mid / 2;
    b[0] += mid / 2;
    memo[0] = mid;
    rep(i, n - 1) {
      long double rain = (long double)a[i] - b[i];
      b[i] += rain;
      b[i + 1] += rain;
      memo[i + 1] = rain * 2;
    }
    if (a[n - 1] == b[n - 1]) {
      rep(i, n) {
        if (i == n - 1)
          cout << memo[i] << endl;
        else
          cout << memo[i] << " ";
      }
      return 0;
    } else if (a[n - 1] > b[n - 1]) {
      l = mid;
    } else {
      r = mid;
    }
  }

  return 0;
}
Problem p02984 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;
  long long int a[10000], s = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i % 2 == 0)
      s += a[i];
    else
      s -= a[i];
  }
  cout << s;
  s = s / 2;
  for (int i = 0; i < n - 1; i++) {
    s = a[i] - s;
    cout << " " << 2 * s;
  }
  cout << endl;
}

Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;
  long long int a[100002], s = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i % 2 == 0)
      s += a[i];
    else
      s -= a[i];
  }
  cout << s;
  s = s / 2;
  for (int i = 0; i < n - 1; i++) {
    s = a[i] - s;
    cout << " " << 2 * s;
  }
  cout << endl;
}
Problem p02984 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int N, A[100000];
  int i, j;
  long S = 0, ans;
  long long sum[200000];
  for (i = 0; i < 200000; i++)
    sum[i] = 0;
  cin >> N;
  for (i = 0; i < N; i++)
    cin >> A[i];
  for (i = 0; i < 2 * N; i++) {
    sum[i + 1] = sum[i] + A[(2 * i + 1) % N];
  }
  S = sum[N] / 2;
  for (i = 0; i < N; i++) {
    ans = S - sum[i * (N / 2 + 1) % N + N / 2] + sum[i * (N / 2 + 1) % N];
    cout << ans * 2 << endl;
  }
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int N, A[100000];
  long i, j;
  long S = 0, ans;
  long long sum[200000];
  for (i = 0; i < 200000; i++)
    sum[i] = 0;
  cin >> N;
  for (i = 0; i < N; i++)
    cin >> A[i];
  for (i = 0; i < 2 * N; i++) {
    sum[i + 1] = sum[i] + A[(2 * i + 1) % N];
  }
  S = sum[N] / 2;
  for (i = 0; i < N; i++) {
    ans = S - sum[i * (N / 2 + 1) % N + N / 2] + sum[i * (N / 2 + 1) % N];
    cout << ans * 2 << endl;
  }
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
#include <vector>

#define lli long long
#define all(i) i.begin(), i.end()
#define rall(i) i.rbegin(), i.rend()
#define rep0(i, j) for (int i = 0; i < j; i++)
#define rep1(i, j) for (int i = 1; i <= j; i++)
#define rep0d(i, j) for (int i = j - 1; i >= 0; i--)
#define MAX 1000000007
int a[2001][2001];
using namespace std;

int main() {
  lli n;
  cin >> n;
  vector<lli> vec(n), ans(n + 1);
  rep0(i, n) cin >> vec[i];
  lli temp;
  ans[0] = temp = min(vec[0], vec[n - 1]) / 2;
  while (1) {
    int i = 0;
    for (; i < n && ans[i] >= 0; i++) {
      ans[i + 1] = vec[i] - ans[i];
    }
    temp /= 2;
    if (ans[0] == ans[n])
      break;
    if (ans[0] > ans[n] || i % 2 == 1)
      ans[0] = ans[0] + temp;
    else
      ans[0] = ans[0] - temp + 1;
  }
  rep0(i, n) cout << ans[i] * 2 << '\n';
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
#include <vector>

#define lli long long
#define all(i) i.begin(), i.end()
#define rall(i) i.rbegin(), i.rend()
#define rep0(i, j) for (int i = 0; i < j; i++)
#define rep1(i, j) for (int i = 1; i <= j; i++)
#define rep0d(i, j) for (int i = j - 1; i >= 0; i--)
#define MAX 1000000007
int a[2001][2001];
using namespace std;

int main() {
  lli n;
  cin >> n;
  vector<lli> vec(n), ans(n + 1);
  rep0(i, n) cin >> vec[i];
  lli temp;
  ans[0] = temp = min(vec[0], vec[n - 1]) / 2;

  int i = 0;
  for (; i < n; i++) {
    ans[i + 1] = vec[i] - ans[i];
  }
  ans[0] = (ans[0] + ans[n]) / 2;

  for (int i = 0; i < n; i++) {
    ans[i + 1] = vec[i] - ans[i];
  }
  rep0(i, n) cout << ans[i] * 2 << '\n';
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  vector<int> A;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.push_back(a);
  }

  for (int i = 0; i < N; i++) {
    int a = 0;
    int p = 1;
    for (int j = 0; j < N; j++) {
      a += A[i + j < N ? i + j : i + j - N] * p;
      p *= -1;
    }
    cout << a << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  vector<int> A;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.push_back(a);
  }

  int a = 0;
  int p = 1;
  for (int j = 0; j < N; j++) {
    a += A[j] * p;
    p *= -1;
  }
  cout << a << endl;

  for (int j = 0; j < N - 1; j++) {
    a = 2 * (A[j] - a / 2);
    cout << a << endl;
  }
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(void) {
  int n;
  cin >> n;
  int dam[n + 1];
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    dam[i] = x;
  }
  int ans[n + 1];
  for (int i = 1; i <= n; i++) {
    ans[i] = 0;
  }
  vector<int> num;
  int c = 0;
  c = dam[1];
  while (c) {
    num.push_back(2 * c);
    c--;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += dam[i];
  }
  int first = n - 1;
  while (first) {
    sum -= 2 * dam[first];
    first -= 2;
  }
  ans[1] = sum;

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

  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }

  return 0;
}


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

int main(void) {
  int n;
  cin >> n;
  int dam[n + 1];
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    dam[i] = x;
  }
  int ans[n + 1];
  for (int i = 1; i <= n; i++) {
    ans[i] = 0;
  }

  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += dam[i];
  }
  int first = n - 1;
  while (first) {
    sum -= 2 * dam[first];
    first -= 2;
  }
  ans[1] = sum;

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

  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }

  return 0;
}
Problem p02984 (C++)

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i, n) for (int i = 0, i##_cond = (n); i < i##_cond; ++i)
#define FOR(i, a, b) for (int i = (a), i##_cond = (b); i < i##_cond; ++i)
#define ROF(i, a, b)                                                           \
  for (int i = (a)-1, i##_cond = (b); i >= i##_cond; --i) // ROF(i,n,0)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend() // sortで降順
#define pb push_back
#define eb emplace_back
#define fst first
#define snd second
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
constexpr ll inf = 1ll << 61;
constexpr ll mod = 1e9 + 7;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> T add(const T &a, const T &b) { return (a + b) % mod; }

signed main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  int sum = accumulate(all(a), 0);
  vi ans(n);
  for (int i = 0; i < n - 1; i += 2) {
    sum -= 2 * a[i];
  }
  dump(sum);
  ans[n - 1] = sum;
  ROF(i, n - 1, 0) { ans[i] = 2 * (a[i] - ans[i + 1] / 2); }
  assert(ans[0] + ans[n - 1] == a[n - 1] * 2);
  dump(ans);
  cout << ans[0];
  FOR(i, 1, n) cout << " " << ans[i];
  cout << endl;
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i, n) for (int i = 0, i##_cond = (n); i < i##_cond; ++i)
#define FOR(i, a, b) for (int i = (a), i##_cond = (b); i < i##_cond; ++i)
#define ROF(i, a, b)                                                           \
  for (int i = (a)-1, i##_cond = (b); i >= i##_cond; --i) // ROF(i,n,0)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend() // sortで降順
#define pb push_back
#define eb emplace_back
#define fst first
#define snd second
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
constexpr ll inf = 1ll << 61;
constexpr ll mod = 1e9 + 7;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> T add(const T &a, const T &b) { return (a + b) % mod; }

signed main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  int sum = accumulate(all(a), 0ll);
  vi ans(n);
  for (int i = 0; i < n - 1; i += 2) {
    sum -= 2 * a[i];
  }
  dump(sum);
  ans[n - 1] = sum;
  ROF(i, n - 1, 0) { ans[i] = 2 * (a[i] - ans[i + 1] / 2); }
  assert(ans[0] + ans[n - 1] == a[n - 1] * 2);
  dump(ans);
  cout << ans[0];
  FOR(i, 1, n) cout << " " << ans[i];
  cout << endl;
}
Problem p02984 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 2e3 + 5;
const ll p = 998244353;
ll a[maxn], b[maxn];

int main() {
  ios::sync_with_stdio(false);

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

  ll sum = 0, f = 1;
  for (int i = 1; i <= n; i++) {
    sum += f * a[i];
    f *= -1;
  }
  b[1] = sum;

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

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 2e6 + 5;
const ll p = 998244353;
ll a[maxn], b[maxn];

int main() {
  ios::sync_with_stdio(false);

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

  ll sum = 0, f = 1;
  for (int i = 1; i <= n; i++) {
    sum += f * a[i];
    f *= -1;
  }
  b[1] = sum;

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

  for (int i = 1; i <= n; i++) {
    cout << b[i] << " ";
  }
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

const int nax = 1e5;

int d[nax];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
  }
  for (int i = 0; i < n; ++i) {
    long long ai = 0;
    for (int c = 0, p = i; c < n; ++c) {
      if (c & 1)
        ai -= d[p];
      else
        ai += d[p];
      ++p;
      p %= n;
    }
    cout << ai << " ";
  }
  cout << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

const int nax = 1e5;

int d[nax];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
  }
  long long ai = 0;
  for (int c = 0; c < n; ++c) {
    if (c & 1)
      ai -= d[c];
    else
      ai += d[c];
  }
  cout << ai << " ";
  for (int i = 1; i < n; ++i) {
    cout << 2 * d[i - 1] - ai << " ";
    ai = 2 * d[i - 1] - ai;
  }
  cout << "\n";
  return 0;
}