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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define eps 1e-6
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = (n - 1); i != -1; i--)
#define snc(a, b, c) ((a) ? (b) : (c))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ins insert
#define pi acos(-1.0)
#define pb push_back
using namespace std;

char ban[8][9];
int h, w;

bool filled(vector<string> reached) {
  rep(i, h) {
    rep(j, w) {
      if (reached[i].at(j) != ban[i][j])
        return false;
    }
  }
  return true;
}

bool dfs(int x, int y, vector<string> reached) {
  if (x >= w || y >= h || y < 0 || x < 0 || ban[y][x] == '.')
    return false;
  if (ban[y][x] == '#')
    reached[y].at(x) = '#';
  if (x == w - 1 && y == h - 1) {
    if (filled(reached))
      return true;
    else
      return false;
  }
  return (dfs(x + 1, y, reached) || dfs(x, y + 1, reached));
}
int main() {
  cin >> h >> w;
  rep(i, h) cin >> ban[i];
  vector<string> reached;
  reached.resize(w, "........");
  cout << ((dfs(0, 0, reached)) ? "Possible" : "Impossible") << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define eps 1e-6
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = (n - 1); i != -1; i--)
#define snc(a, b, c) ((a) ? (b) : (c))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ins insert
#define pi acos(-1.0)
#define pb push_back
using namespace std;

char ban[8][9];
int h, w;

bool filled(vector<string> reached) {
  rep(i, h) {
    rep(j, w) {
      if (reached[i].at(j) != ban[i][j])
        return false;
    }
  }
  return true;
}

bool dfs(int x, int y, vector<string> reached) {
  if (x >= w || y >= h || y < 0 || x < 0 || ban[y][x] == '.')
    return false;
  if (ban[y][x] == '#')
    reached[y].at(x) = '#';
  if (x == w - 1 && y == h - 1) {
    if (filled(reached))
      return true;
    else
      return false;
  }
  return (dfs(x + 1, y, reached) || dfs(x, y + 1, reached));
}
int main() {
  cin >> h >> w;
  rep(i, h) cin >> ban[i];
  vector<string> reached;
  reached.resize(h, "........");
  cout << ((dfs(0, 0, reached)) ? "Possible" : "Impossible") << endl;
  return 0;
}
Problem p03937 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
ll gi() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch))
    f ^= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
char s[10][10];
int main() {
#ifdef XZZSB
  freopen("in.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
  int n = gi(), m = gi();
  for (int i = 1; i <= n; ++i)
    scanf("%s", s[i] + 1);
  int x = 1, y = 1;
  while (x < n || y < m) {
    s[x][y] = '%';
    if (s[x + 1][y] == '#')
      ++x;
    else
      ++y;
  }
  s[n][m] = '%';
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (s[i][j] == '#')
        return puts("Impossible"), 0;
  puts("Possible");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
ll gi() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch))
    f ^= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
char s[10][10];
int main() {
#ifdef XZZSB
  freopen("in.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
  int n = gi(), m = gi();
  for (int i = 1; i <= n; ++i)
    scanf("%s", s[i] + 1);
  int x = 1, y = 1;
  while ((x < n || y < m) && (x <= n && y <= m)) {
    s[x][y] = '%';
    if (s[x + 1][y] == '#')
      ++x;
    else
      ++y;
  }
  s[n][m] = '%';
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (s[i][j] == '#')
        return puts("Impossible"), 0;
  puts("Possible");
  return 0;
}
Problem p03937 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
#define tii tuple<int, int, int>
#define Priq priority_queue<int, vi, greater<int>>
#define pb push_back
#define mp make_pair
signed main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i, 0, H) cin >> S[i];
  queue<pii> Q;
  Q.push(mp(0, 0));
  vi P = {0, 1}, R = {1, 0};
  string ans = "Impossible";
  int count = 0;
  int sum = 0;
  rep(i, 0, H) {
    rep(j, 0, W) {
      if (S[i][j] == '#')
        sum++;
    }
  }
  Q.push(mp(-1, -1));
  while (Q.size() > 0) {
    int X = Q.front().first, Y = Q.front().second;
    Q.pop();
    if (X == H - 1 && Y == W - 1 && count == sum - 1) {
      ans = "Possible";
      break;
    }
    if (X == -1) {
      count++;
      Q.push(mp(-1, -1));
    } else {
      rep(i, 0, 2) {
        int A = X + P[i], B = Y + R[i];
        if (A < H && B < W) {
          if (S[A][B] == '#')
            Q.push(mp(A, B));
        }
      }
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
#define tii tuple<int, int, int>
#define Priq priority_queue<int, vi, greater<int>>
#define pb push_back
#define mp make_pair
signed main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i, 0, H) cin >> S[i];
  queue<pii> Q;
  Q.push(mp(0, 0));
  vi P = {0, 1}, R = {1, 0};
  string ans = "Impossible";
  int count = 0;
  int sum = 0;
  rep(i, 0, H) {
    rep(j, 0, W) {
      if (S[i][j] == '#')
        sum++;
    }
  }
  Q.push(mp(-1, -1));
  while (Q.size() > 1) {
    int X = Q.front().first, Y = Q.front().second;
    Q.pop();
    if (X == H - 1 && Y == W - 1 && count == sum - 1) {
      ans = "Possible";
      break;
    }
    if (X == -1) {
      count++;
      Q.push(mp(-1, -1));
    } else {
      rep(i, 0, 2) {
        int A = X + P[i], B = Y + R[i];
        if (A < H && B < W) {
          if (S[A][B] == '#')
            Q.push(mp(A, B));
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p03937 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, sum = 0;
  cin >> a >> b;
  char k[112345][112345];
  for (int i = 0; i < a; i++) {
    for (int m = 0; m < b; m++) {
      cin >> k[i][m];
      if (k[i][m] == '#')
        sum++;
    }
  }

  if (sum == a + b - 1)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, sum = 0;
  cin >> a >> b;
  char k[10][10];
  for (int i = 0; i < a; i++) {
    for (int m = 0; m < b; m++) {
      cin >> k[i][m];
      if (k[i][m] == '#')
        sum++;
    }
  }

  if (sum == a + b - 1)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
}
Problem p03938 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define vv(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int>>
#define vvl std::vector<std::vector<ll>>
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N, x;
  std::cin >> N;
  std::vector<int> A(N + 1), B(N + 1), p(N);
  for (int i = 0; i < N; i++) {
    std::cin >> x;
    p[x] = i;
  }
  for (int i = 1; i <= N; i++) {
    A[i] = i * 30000;
    B[i] = (N - i) * 30000 + p[i];
  }
  for (int i = 1; i <= N; i++)
    std::cout << A[i] << (i == N ? "\n" : " ");
  for (int i = 1; i <= N; i++)
    std::cout << B[i] << (i == N ? "\n" : " ");

  return 0;
}


Fixed submission:
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define vv(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int>>
#define vvl std::vector<std::vector<ll>>
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N, x;
  std::cin >> N;
  std::vector<int> A(N + 1), B(N + 1), p(N + 1);
  for (int i = 1; i <= N; i++) {
    std::cin >> x;
    p[x] = i;
  }
  for (int i = 1; i <= N; i++) {
    A[i] = i * 30000;
    B[i] = (N - i) * 30000 + p[i];
  }
  for (int i = 1; i <= N; i++)
    std::cout << A[i] << (i == N ? "\n" : " ");
  for (int i = 1; i <= N; i++)
    std::cout << B[i] << (i == N ? "\n" : " ");

  return 0;
}
Problem p03938 (C++)

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

signed main() {
  int N;
  cin >> N;

  vector<int> p(N);
  for (int &x : p)
    cin >> x, --x;

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

  for (int i = 0; i < N; i++) {
    a[p[i]] += i;
  }

  for (int x : a)
    cout << x << " ";
  cout << endl;

  reverse(a.begin(), a.end());
  for (int x : a)
    cout << x / N * N << " ";
  cout << endl;
}


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

signed main() {
  int N;
  cin >> N;

  vector<int> p(N);
  for (int &x : p)
    cin >> x, --x;

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

  for (int i = 0; i < N; i++) {
    a[p[i]] += i;
  }

  for (int x : a)
    cout << x << " ";
  cout << endl;

  reverse(a.begin(), a.end());
  for (int x : a)
    cout << x / N * N << " ";
  cout << endl;
}
Problem p03938 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cassert>
#include <cstdio>
using namespace std;
const int MAXN = 2e4 + 10;

int n, p[MAXN], a[MAXN], b[MAXN];
int mb;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", p + i);
    --p[i];
  }

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

  bool flag = true;
  for (int rekt = 0; flag && rekt < n; rekt++) {
    flag = false;
    for (int i = 0; i + 1 < n; i++) {
      int x = p[i], y = p[i + 1];

      if (a[x] + b[x] < a[y] + b[y])
        continue;
      int offs = a[x] + b[x] - a[y] - b[y] + 1;

      flag = true;

      for (int j = 0; j < x; j++)
        b[j] += offs;
      for (int j = x + 1; j < n; j++)
        a[j] += offs;
    }
  }

  for (int i = 0; i < n; i++)
    printf("%d ", a[i]);
  printf("\n");
  for (int i = 0; i < n; i++)
    printf("%d ", b[i]);
  printf("\n");

  return 0;
}


Fixed submission:
#include <cassert>
#include <cstdio>
using namespace std;
const int MAXN = 2e4 + 10;

int n, p[MAXN], a[MAXN], b[MAXN];
int mb;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", p + i);
    --p[i];
  }

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

  bool flag = true;
  for (int rekt = 0; flag && rekt < n; rekt++) {
    flag = false;
    for (int i = n - 2; i + 1; i--) {
      int x = p[i], y = p[i + 1];

      if (a[x] + b[x] < a[y] + b[y])
        continue;
      int offs = a[x] + b[x] - a[y] - b[y] + 1;

      flag = true;

      for (int j = 0; j < x; j++)
        b[j] += offs;
      for (int j = x + 1; j < n; j++)
        a[j] += offs;
    }
  }

  for (int i = 0; i < n; i++)
    printf("%d ", a[i]);
  printf("\n");
  for (int i = 0; i < n; i++)
    printf("%d ", b[i]);
  printf("\n");

  return 0;
}
Problem p03938 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF (1 << 30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  b[0] = 0;
  for (int i = 0; i < n; ++i) {
    int p;
    cin >> p;
    a[p - 1] = i + 1;
  }
  for (int i = 0; i < n; ++i) {
    a[i + 1] += a[i];
    b[i + 1] = -a[i];
  }
  int p = abs(*(min_element(b.begin(), b.end())) - 1);
  for (auto &k : a) {
    cout << k << " ";
  }
  cout << endl;
  for (auto &k : b) {
    cout << k + p << " ";
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define INF (1 << 30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  b[0] = 0;
  for (int i = 0; i < n; ++i) {
    int p;
    cin >> p;
    a[p - 1] = i + 1;
  }
  for (int i = 0; i < n - 1; ++i) {
    a[i + 1] += a[i];
    b[i + 1] = -a[i];
  }
  int p = abs(*(min_element(b.begin(), b.end())) - 1);
  for (auto &k : a) {
    cout << k << " ";
  }
  cout << endl;
  for (auto &k : b) {
    cout << k + p << " ";
  }
  cout << endl;
  return 0;
}
Problem p03938 (C++)

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)

int main() {
  int n, p[2005], a[2005]{}, b[2005]{};
  cin >> n;
  REP(i, n) cin >> p[i];
  REP(i, n - 1) {
    a[p[i + 1] - 1] += i + 1;
    b[p[i + 1] - 1] += i + 1;
  }
  a[0] += 1;
  REP(i, n - 1) a[i + 1] += a[i] + 1;
  b[n - 1] += 1;
  REPR(i, n - 2) b[i] += b[i + 1] + 1;
  REP(i, n) cout << a[i] << (i < n - 1 ? " " : "\n");
  REP(i, n) cout << b[i] << (i < n - 1 ? " " : "\n");
  return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)

int main() {
  int n, p[20005], a[20005]{}, b[20005]{};
  cin >> n;
  REP(i, n) cin >> p[i];
  REP(i, n - 1) {
    a[p[i + 1] - 1] += i + 1;
    b[p[i + 1] - 1] += i + 1;
  }
  a[0] += 1;
  REP(i, n - 1) a[i + 1] += a[i] + 1;
  b[n - 1] += 1;
  REPR(i, n - 2) b[i] += b[i + 1] + 1;
  REP(i, n) cout << a[i] << (i < n - 1 ? " " : "\n");
  REP(i, n) cout << b[i] << (i < n - 1 ? " " : "\n");
  return 0;
}
Problem p03938 (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 fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
// #pragma GCC optimize ("-O3")
using namespace std;
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main() {
  int N;
  cin >> N;
  vector<int> p(N);
  rep(i, 0, N) cin >> p[i];
  vector<int> r(N);
  rep(i, 0, N) r[p[i]] = i + 1;
  vector<int> A(N), B(N);
  rep(i, 0, N) {
    A[i] = 30000 * (i + 1);
    B[i] = 30000 * (N - (i + 1)) + r[i];
  }
  rep(i, 0, N) { cout << A[i] << " "; }
  cout << endl;
  rep(i, 0, N) { cout << B[i] << " "; }
  cout << endl;
}


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 fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
// #pragma GCC optimize ("-O3")
using namespace std;
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main() {
  int N;
  cin >> N;
  vector<int> p(N);
  rep(i, 0, N) cin >> p[i];
  vector<int> r(N);
  rep(i, 0, N) r[p[i] - 1] = i + 1;
  vector<int> A(N), B(N);
  rep(i, 0, N) {
    A[i] = 30000 * (i + 1);
    B[i] = 30000 * (N - (i + 1)) + r[i];
  }
  rep(i, 0, N) { cout << A[i] << " "; }
  cout << endl;
  rep(i, 0, N) { cout << B[i] << " "; }
  cout << endl;
}
Problem p03938 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;

  cin >> N;

  vector<int> p(N);
  vector<int> a(N);
  vector<int> b(N);

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

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

  for (int i = 1; i <= N; i++) {
    b[p[i]] += i;
  }

  for (int i = 1; i <= N; i++) {
    printf("%d", a[i]);
    if (i != N) {
      printf(" ");
    } else {
      printf("\n");
    }
  }

  for (int i = 1; i <= N; i++) {
    printf("%d", b[i]);
    if (i != N) {
      printf(" ");
    } else {
      printf("\n");
    }
  }

  return 0;
}


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

using namespace std;

int main() {
  int N;

  cin >> N;

  vector<int> p(N + 1);
  vector<int> a(N + 1);
  vector<int> b(N + 1);

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

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

  for (int i = 1; i <= N; i++) {
    b[p[i]] += i;
  }

  for (int i = 1; i <= N; i++) {
    printf("%d", a[i]);
    if (i != N) {
      printf(" ");
    } else {
      printf("\n");
    }
  }

  for (int i = 1; i <= N; i++) {
    printf("%d", b[i]);
    if (i != N) {
      printf(" ");
    } else {
      printf("\n");
    }
  }

  return 0;
}
Problem p03938 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
  int num, i, j;
  cin >> num;
  vector<int> d(num), a(num), b(num);
  rep(i, num) cin >> d[i];
  rep(j, num) {
    i = d[j];
    a[i] = 20001 * (i + 1);
    b[i] = 20001 * (num - i) + j;
  }
  rep(i, num - 1) cout << a[i] << " ";
  cout << a[i] << "\n";
  rep(i, num - 1) cout << b[i] << " ";
  cout << b[i] << "\n";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
  int num, i, j;
  cin >> num;
  vector<int> d(num), a(num), b(num);
  rep(i, num) cin >> d[i];
  rep(j, num) {
    i = d[j] - 1;
    a[i] = 20001 * (i + 1);
    b[i] = 20001 * (num - i) + j;
  }
  rep(i, num - 1) cout << a[i] << " ";
  cout << a[i] << "\n";
  rep(i, num - 1) cout << b[i] << " ";
  cout << b[i] << "\n";
  return 0;
}
Problem p03938 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
typedef pair<int, int> pii;
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  int temp;
  rep(i, n) {
    cin >> temp;
    p[temp] = i + 1;
  }
  rep(i, n) { cout << 30000 * (i + 1) << " "; }
  cout << endl;
  rep(i, n) { cout << 30000 * (n - i) + p[i + 1] << " "; }
  cout << endl;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
typedef pair<int, int> pii;
int main() {
  int n;
  cin >> n;
  vector<int> p(n + 2);
  int temp;
  rep(i, n) {
    cin >> temp;
    p[temp] = i + 1;
  }
  rep(i, n) { cout << 30000 * (i + 1) << " "; }
  cout << endl;
  rep(i, n) { cout << 30000 * (n - i) + p[i + 1] << " "; }
  cout << endl;
}
Problem p03938 (C++)

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

#define fi first
#define se second
#define show(x)                                                                \
  cerr << #x << "="                                                            \
       << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int n;
int p[2001];
int a[2001], b[2001];

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.txt", "r", stdin);
  // stream2 = freopen("out.txt", "w", stdout);
  if (stream1 == NULL)
    return 0;
    // if (stream2 == NULL) return 0;:w
#endif
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  for (int i = 1; i <= n; i++) {
    a[i - 1] = n * i;
  }
  for (int i = 0; i < n; i++) {
    b[i] = a[n - i - 1];
  }
  for (int i = 0; i < n; i++) {
    a[p[i]] += i;
  }
  for (int i = 0; i < n; i++) {
    if (i != n - 1)
      cout << a[i] << " ";
    else
      cout << a[i] << endl;
  }
  for (int i = 0; i < n; i++) {
    if (i != n - 1)
      cout << b[i] << " ";
    else
      cout << b[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 << "="                                                            \
       << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int n;
int p[20001];
int a[20001], b[20001];

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.txt", "r", stdin);
  // stream2 = freopen("out.txt", "w", stdout);
  if (stream1 == NULL)
    return 0;
    // if (stream2 == NULL) return 0;:w
#endif
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  for (int i = 1; i <= n; i++) {
    a[i - 1] = n * i;
  }
  for (int i = 0; i < n; i++) {
    b[i] = a[n - i - 1];
  }
  for (int i = 0; i < n; i++) {
    a[p[i]] += i;
  }
  for (int i = 0; i < n; i++) {
    if (i != n - 1)
      cout << a[i] << " ";
    else
      cout << a[i] << endl;
  }
  for (int i = 0; i < n; i++) {
    if (i != n - 1)
      cout << b[i] << " ";
    else
      cout << b[i] << endl;
  }
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  // fclose(stream2);
#endif
  return 0;
}
Problem p03938 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);

mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

const int M = 5;
int A[M];
int B[M];

int main() {
  fastIO;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    A[i] = M * i;
    B[i] = M * (n - i + 1);
  }
  int p;
  for (int i = 1; i <= n; i++) {
    cin >> p;
    A[p] += i;
  }
  for (int i = 1; i <= n; i++)
    cout << A[i] << " ";
  cout << "\n";
  for (int i = 1; i <= n; i++)
    cout << B[i] << " ";
  return 0;
}

Fixed submission:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);

mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

const int M = 25000;
int A[M];
int B[M];

int main() {
  fastIO;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    A[i] = M * i;
    B[i] = M * (n - i + 1);
  }
  int p;
  for (int i = 1; i <= n; i++) {
    cin >> p;
    A[p] += i;
  }
  for (int i = 1; i <= n; i++)
    cout << A[i] << " ";
  cout << "\n";
  for (int i = 1; i <= n; i++)
    cout << B[i] << " ";
  return 0;
}
Problem p03938 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  vector<int> a(n), b(n), r(n);
  rep(i, n) {
    a[i] = 30000 * (i + 1);
    b[i] = 30000 * (n - i);
    r[p[i]] = i + 1;
  }
  rep(i, n) {
    if (i != 0)
      cout << " ";
    cout << a[i];
  }
  cout << endl;
  rep(i, n) {
    if (i != 0)
      cout << " ";
    cout << b[i] + r[i];
  }
  cout << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  vector<int> a(n), b(n), r(n);
  rep(i, n) {
    a[i] = 30000 * (i + 1);
    b[i] = 30000 * (n - i);
    r[p[i] - 1] = i + 1;
  }
  rep(i, n) {
    if (i != 0)
      cout << " ";
    cout << a[i];
  }
  cout << endl;
  rep(i, n) {
    if (i != 0)
      cout << " ";
    cout << b[i] + r[i];
  }
  cout << endl;
}
Problem p03938 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define MAX 20000
int p[MAX];
pair<int, int> d[MAX];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  for (int i = 1; i <= n; ++i) {
    d[i].first = i * n;
    d[i].second = n * n - i * n + n;
  }
  for (int i = 0; i < n; ++i) {
    d[p[i]].first += i + 1;
  }
  for (int i = 1; i <= n; ++i) {
    if (i != 1)
      cout << " ";
    cout << d[i].first;
  }
  cout << endl;
  for (int i = 1; i <= n; ++i) {
    if (i != 1)
      cout << " ";
    cout << d[i].second;
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define MAX 20001
int p[MAX];
pair<int, int> d[MAX];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  for (int i = 1; i <= n; ++i) {
    d[i].first = i * n;
    d[i].second = n * n - i * n + n;
  }
  for (int i = 0; i < n; ++i) {
    d[p[i]].first += i + 1;
  }
  for (int i = 1; i <= n; ++i) {
    if (i != 1)
      cout << " ";
    cout << d[i].first;
  }
  cout << endl;
  for (int i = 1; i <= n; ++i) {
    if (i != 1)
      cout << " ";
    cout << d[i].second;
  }
  cout << endl;
  return 0;
}
Problem p03938 (C++)

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

using namespace std;
const int N = 2e3 + 10;
int a[N], b[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    a[i] = i * n, b[i] = (n - i + 1) * n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[x] += i - 1;
  }
  for (int i = 1; i <= n; i++)
    cout << a[i] << " ";
  cout << "\n";
  for (int i = 1; i <= n; i++)
    cout << b[i] << " ";
  cout << "\n";

  return 0;
}


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

using namespace std;
const int N = 2e4 + 10;
int a[N], b[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    a[i] = i * n, b[i] = (n - i + 1) * n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[x] += i - 1;
  }
  for (int i = 1; i <= n; i++)
    cout << a[i] << " ";
  cout << "\n";
  for (int i = 1; i <= n; i++)
    cout << b[i] << " ";
  cout << "\n";

  return 0;
}
Problem p03938 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = 101, base = 20009;
inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}
int N, a[MAXN], b[MAXN];
int main() {
  N = read();
  for (int i = 1; i <= N; i++)
    a[i] = base * i;
  for (int i = 1; i <= N; i++)
    b[i] = base * (N - i + 1);
  for (int i = 1; i <= N; i++) {
    int x = read();
    a[x] -= (N - i + 1);
  }
  for (int i = 1; i <= N; i++)
    printf("%d ", a[i]);
  puts("");
  for (int i = 1; i <= N; i++)
    printf("%d ", b[i]);
  return 0;
}
/*
1
2 21
*/


Fixed submission:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = 20001, base = 20009;
inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}
int N, a[MAXN], b[MAXN];
int main() {
  N = read();
  for (int i = 1; i <= N; i++)
    a[i] = base * i;
  for (int i = 1; i <= N; i++)
    b[i] = base * (N - i + 1);
  for (int i = 1; i <= N; i++) {
    int x = read();
    a[x] -= (N - i + 1);
  }
  for (int i = 1; i <= N; i++)
    printf("%d ", a[i]);
  puts("");
  for (int i = 1; i <= N; i++)
    printf("%d ", b[i]);
  return 0;
}
/*
1
2 21
*/
Problem p03939 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define N 200005

using namespace std;

inline int input() {
  int x;
  char ch;
  while (!isdigit(ch = getchar()))
    ;
  for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48))
    ;
  return x;
}

long double n, d, x, ans;

int main() {
#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  n = input(), x = input(), d = input();

  while (n) {
    ans += (x * 2 + (n * 2 - 1) * d) / 2;
    x = ((n * 2 + 2) * x + d * 5) / n / 2;
    d = (n * 2 + 4) * d / n / 2;
    --n;
  }

  printf("%Lf\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define N 200005

using namespace std;

inline int input() {
  int x;
  char ch;
  while (!isdigit(ch = getchar()))
    ;
  for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48))
    ;
  return x;
}

long double n, d, x, ans;

int main() {
  n = input(), x = input(), d = input();

  while (n) {
    ans += (x * 2 + (n * 2 - 1) * d) / 2;
    x = ((n * 2 + 2) * x + d * 5) / n / 2;
    d = (n * 2 + 4) * d / n / 2;
    --n;
  }

  printf("%Lf\n", ans);
  return 0;
}
Problem p03939 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

int N, d, x;
double D[100010];

void solve() {
  scanf("%d%d%d", &N, &d, &x);
  D[1] = 1;
  for (int i = 2; i <= N; i++) {
    D[i] = D[i - 1] + 1.0 / i;
  }
  double d2 = d + (N - 0.5) * x, ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += d2 * 0.5 * (D[i] + D[N + 1 - i]);
  }
  printf("%.12f\n", ans);
}

int main() {
  int Tc = 1; // scanf("%d\n", &Tc);
  for (int tc = 1; tc <= Tc; tc++) {
    solve();
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

int N, d, x;
double D[200010];

void solve() {
  scanf("%d%d%d", &N, &d, &x);
  D[1] = 1;
  for (int i = 2; i <= N; i++) {
    D[i] = D[i - 1] + 1.0 / i;
  }
  double d2 = d + (N - 0.5) * x, ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += d2 * 0.5 * (D[i] + D[N + 1 - i]);
  }
  printf("%.12f\n", ans);
}

int main() {
  int Tc = 1; // scanf("%d\n", &Tc);
  for (int tc = 1; tc <= Tc; tc++) {
    solve();
  }
  return 0;
}
Problem p03939 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using std::cin;
using std::cout;
typedef long long ll;
const int Maxn = 2e5 + 5;
typedef double arr[Maxn];
// ll Add(ll x, ll y) { return (x += y) >= Mod ? x - Mod : (x < 0 ? x + Mod :
// x); }
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
inline ll read() {
  rg ll res = 0, sign = 1;
  rg char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      sign = -1;
    ch = getchar();
  }
  do {
    res = (res << 3) + (res << 1) + (ch ^ 48);
    ch = getchar();
  } while (isdigit(ch));
  return res * sign;
}
int n;
arr a;
double d, ans;
int main() {
  cin >> n >> a[1] >> d;
  n <<= 1;
  a[n] = a[1] + d * (n - 1);
  while (n > 0) {
    ans += (a[1] + a[n]) / 2;
    a[1] += (2 * a[1] + 5 * d) / n;
    a[n - 2] = a[n] - 2 * d;
    a[n - 2] += (2 * a[n - 2] + (2 * n - 1) * d) / n;
    d += 4 * d / n;
    n -= 2;
  }
  printf("%.10f\n", ans);
  return 0;
}
/*


1 2 3 4 5 6
9 15 21

x-2 x-1 x x+1 x+2

<=x x->x+2
x+1 x->xx+1x+2

x/n*2d+1/n*(2a+3d)
[2a+(3+2x)d]/n

a+[2a+(3+2x)d]/n
d+(2d+2d)/n
d+4d/n

n/2*2d+1/n*(3x+3d)
*/


Fixed submission:
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using std::cin;
using std::cout;
typedef long long ll;
const int Maxn = 4e5 + 5;
typedef double arr[Maxn];
// ll Add(ll x, ll y) { return (x += y) >= Mod ? x - Mod : (x < 0 ? x + Mod :
// x); }
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
inline ll read() {
  rg ll res = 0, sign = 1;
  rg char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      sign = -1;
    ch = getchar();
  }
  do {
    res = (res << 3) + (res << 1) + (ch ^ 48);
    ch = getchar();
  } while (isdigit(ch));
  return res * sign;
}
int n;
arr a;
double d, ans;
int main() {
  cin >> n >> a[1] >> d;
  n <<= 1;
  a[n] = a[1] + d * (n - 1);
  while (n > 0) {
    ans += (a[1] + a[n]) / 2;
    a[1] += (2 * a[1] + 5 * d) / n;
    a[n - 2] = a[n] - 2 * d;
    a[n - 2] += (2 * a[n - 2] + (2 * n - 1) * d) / n;
    d += 4 * d / n;
    n -= 2;
  }
  printf("%.10f\n", ans);
  return 0;
}
/*


1 2 3 4 5 6
9 15 21

x-2 x-1 x x+1 x+2

<=x x->x+2
x+1 x->xx+1x+2

x/n*2d+1/n*(2a+3d)
[2a+(3+2x)d]/n

a+[2a+(3+2x)d]/n
d+(2d+2d)/n
d+4d/n

n/2*2d+1/n*(3x+3d)
*/
Problem p03939 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <ctype.h>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef tuple<int, int, int> t3;

const int MX = 1 << 17;
const int MM = 1000000007;

double D[MX];

int main() {
  int N, d, x;
  scanf("%d%d%d", &N, &d, &x);
  double t = 1;
  D[1] = 1;
  for (int i = 2; i <= N; i++)
    D[i] = D[i - 1] + 1.0 / i * D[i - 1] + 1;
  printf("%.10lf\n", D[N] * (2 * d + (2 * N - 1) * x) / 2.0);
}


Fixed submission:
#include <algorithm>
#include <assert.h>
#include <ctype.h>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef tuple<int, int, int> t3;

const int MX = 1 << 18;
const int MM = 1000000007;

double D[MX];

int main() {
  int N, d, x;
  scanf("%d%d%d", &N, &d, &x);
  double t = 1;
  D[1] = 1;
  for (int i = 2; i <= N; i++)
    D[i] = D[i - 1] + 1.0 / i * D[i - 1] + 1;
  printf("%.10lf\n", D[N] * (2 * d + (2 * N - 1) * x) / 2.0);
}
Problem p03939 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD 1000000007LL
#define eps 1e-10
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int n;
ll x;
ll d[200005];
ll a[100005];
ll sum[100005];

int main(void) {
  scanf("%d%lld%lld", &n, &d[0], &x);
  for (int i = 1; i < n * 2; i++) {
    d[i] = d[i - 1] + x;
  }
  for (int i = 0; i < n; i++) {
    a[i] = d[i * 2] + d[i * 2 + 1];
  }
  for (int i = 0; i < n; i++) {
    sum[i + 1] = sum[i] + a[i];
  }
  long double res = sum[n] * 0.5;
  for (int i = 1; i < n; i++) {
    res += (sum[n] - sum[i]) * 0.25 / (i + 1);
    res += (sum[n - i] - sum[0]) * 0.25 / (i + 1);
  }
  printf("%.9f\n", (double)res);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD 1000000007LL
#define eps 1e-10
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int n;
ll x;
ll d[400005];
ll a[200005];
ll sum[200005];

int main(void) {
  scanf("%d%lld%lld", &n, &d[0], &x);
  for (int i = 1; i < n * 2; i++) {
    d[i] = d[i - 1] + x;
  }
  for (int i = 0; i < n; i++) {
    a[i] = d[i * 2] + d[i * 2 + 1];
  }
  for (int i = 0; i < n; i++) {
    sum[i + 1] = sum[i] + a[i];
  }
  long double res = sum[n] * 0.5;
  for (int i = 1; i < n; i++) {
    res += (sum[n] - sum[i]) * 0.25 / (i + 1);
    res += (sum[n - i] - sum[0]) * 0.25 / (i + 1);
  }
  printf("%.9f\n", (double)res);
  return 0;
}
Problem p03939 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 200005;
int n, d[N], x, i, j, k;
long double s[N], w, ans;
int main() {
  scanf("%d%d%d", &n, &d[1], &x);
  for (i = 2; i <= 2 * n; ++i)
    d[i] = d[i - 1] + x;
  for (i = 1, j = 0; i < 2 * n; i += 2, ++j) {
    k = d[i] + d[i + 1];
    s[1] += 2 * k;
    s[min(j, n - j - 1) + 2] -= k;
    s[max(j, n - j - 1) + 2] -= k;
  }
  /*for(i=2;i<=2*n+1;i+=2)
  {
          w=d[i-1];
          for(j=i-1,k=1;j>1;j-=2,++k)
                  w+=1.0*(d[j-2]+d[j-1])/(k+1)/2;
          w+=d[i];
          for(j=i+1,k=1;j<2*n+1;j+=2,++k)
                  w+=1.0*(d[j]+d[j+1])/(k+1)/2;
          ans+=w/2;
  }*/
  for (i = 1; i <= n; ++i) {
    s[i] += s[i - 1];
    ans += (long double)s[i] / (long double)i;
  }
  printf("%.15Lf", ans / (long double)4);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 500005;
int n, d[N], x, i, j, k;
long double s[N], w, ans;
int main() {
  scanf("%d%d%d", &n, &d[1], &x);
  for (i = 2; i <= 2 * n; ++i)
    d[i] = d[i - 1] + x;
  for (i = 1, j = 0; i < 2 * n; i += 2, ++j) {
    k = d[i] + d[i + 1];
    s[1] += 2 * k;
    s[min(j, n - j - 1) + 2] -= k;
    s[max(j, n - j - 1) + 2] -= k;
  }
  /*for(i=2;i<=2*n+1;i+=2)
  {
          w=d[i-1];
          for(j=i-1,k=1;j>1;j-=2,++k)
                  w+=1.0*(d[j-2]+d[j-1])/(k+1)/2;
          w+=d[i];
          for(j=i+1,k=1;j<2*n+1;j+=2,++k)
                  w+=1.0*(d[j]+d[j+1])/(k+1)/2;
          ans+=w/2;
  }*/
  for (i = 1; i <= n; ++i) {
    s[i] += s[i - 1];
    ans += (long double)s[i] / (long double)i;
  }
  printf("%.15Lf", ans / (long double)4);
  return 0;
}
Problem p03940 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define maxn 100005
typedef long long LL;
int n, x[maxn], T, E;
LL f[maxn], ans;

int main() {
  scanf("%d%d%d", &n, &E, &T);
  for (int i = 1; i <= n; i++)
    scanf("%d", x + i);
  for (int i = 1; i <= n; i++)
    f[i] = 1e16;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= i; j++)
      f[i] = min(f[i], f[j - 1] + max(T, (x[i] - x[j]) * 2));
  ans = E + f[n];
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define maxn 100005
typedef long long LL;
int n, x[maxn], T, E;
LL f[maxn], ans;

int main() {
  scanf("%d%d%d", &n, &E, &T);
  for (int i = 1; i <= n; i++)
    scanf("%d", x + i);
  for (int i = 1; i <= n; i++)
    f[i] = 1e16;
  /*    for (int i=1;i<=n;i++)
          for (int j=1;j<=i;j++)
              f[i]=min(f[i],f[j-1]+max(T,(x[i]-x[j])*2));*/
  int p = 1;
  LL t = 1e16;
  ;
  for (int i = 1; i <= n; i++) {
    while ((x[i] - x[p]) * 2 > T && p <= i) {
      t = min(t, f[p - 1] - 2 * x[p]);
      p++;
    }
    f[i] = min(f[i], min(f[p - 1] + T, t + 2 * x[i]));
  }
  ans = E + f[n];
  printf("%lld\n", ans);
  return 0;
}
Problem p03940 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#define lol(i, n) for (ll i = 0; i < n; i++)
#define mod 1000000007
#define chmin(a, b) a = min(a, b);
typedef long long ll;

using namespace std;
#define N 2010
ll n, d[N], t, e;
ll BN(ll key) {
  ll l = -1, r = n, m = (l + r) / 2;
  for (; l < r - 1; m = (l + r) / 2) {
    if (d[m + 1] * 2 < key)
      l = m;
    else
      r = m;
  }
  return l;
}
ll f[N], g[N];
int main() {
  cin >> n >> e >> t;
  d[0] = 0;
  lol(i, n) cin >> d[i + 1];
  lol(i, N) f[i] = 1e18;
  f[0] = 0, g[0] = -2 * d[1];
  for (ll i = 1; i <= n; i++) {
    ll surf = BN(d[i] * 2 - t);
    ll res = 1e17;
    if (surf + 1 < i)
      chmin(res, f[surf + 1] + t);
    if (~surf)
      chmin(res, g[surf] + 2 * d[i]);
    f[i] = res;
    g[i] = min(g[i - 1], f[i] - 2 * d[i + 1]);
  }
  cout << f[n] + e << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#define lol(i, n) for (ll i = 0; i < n; i++)
#define mod 1000000007
#define chmin(a, b) a = min(a, b);
typedef long long ll;

using namespace std;
#define N 200010
ll n, d[N], t, e;
ll BN(ll key) {
  ll l = -1, r = n, m = (l + r) / 2;
  for (; l < r - 1; m = (l + r) / 2) {
    if (d[m + 1] * 2 < key)
      l = m;
    else
      r = m;
  }
  return l;
}
ll f[N], g[N];
int main() {
  cin >> n >> e >> t;
  d[0] = 0;
  lol(i, n) cin >> d[i + 1];
  lol(i, N) f[i] = 1e18;
  f[0] = 0, g[0] = -2 * d[1];
  for (ll i = 1; i <= n; i++) {
    ll surf = BN(d[i] * 2 - t);
    ll res = 1e17;
    if (surf + 1 < i)
      chmin(res, f[surf + 1] + t);
    if (~surf)
      chmin(res, g[surf] + 2 * d[i]);
    f[i] = res;
    g[i] = min(g[i - 1], f[i] - 2 * d[i + 1]);
  }
  cout << f[n] + e << endl;
  return 0;
}
Problem p03940 (Python)

Buggy submission (status: Time Limit Exceeded):
n, e, t = map(int, input().split())
x = list(map(int, input().split()))
dp = [0] + [float("inf")] * n
for i in range(n):
    ndp = dp.copy()
    for j in range(i, n):
        ndp[j + 1] = min(dp[j + 1], dp[i] + max(t, 2 * (x[j] - x[i])))
    dp = ndp
print(e + dp[-1])


Fixed submission:
import sys
from bisect import bisect, bisect_left


class BinaryIndexedTree:
    def __init__(self, n):
        self.size = n
        self.INF = 10**18
        self.tree = [self.INF] * (n + 1)

    def get_min(self, i):
        s = self.INF
        while i > 0:
            s = min(s, self.tree[i])
            i -= i & -i
        return s

    def update(self, i, x):
        while i <= self.size:
            if self.tree[i] <= x:
                break
            self.tree[i] = x
            i += i & -i


def solve(n, e, t, xxx):
    if n == 1:
        return e + t

    dp1 = [0] * (n + 1)
    dp2 = BinaryIndexedTree(n + 1)
    dp2.update(1, -xxx[0] * 2)

    for i in range(n):
        x = xxx[i]
        j = bisect_left(xxx, x - t // 2, hi=i)
        ex_time = dp1[j] + t
        if j > 0:
            ex_time = min(ex_time, x * 2 + dp2.get_min(j))
        dp1[i + 1] = ex_time
        if i < n - 1:
            dp2.update(i + 2, ex_time - xxx[i + 1] * 2)

    return e + dp1[-1]


n, e, t, *xxx = map(int, sys.stdin.buffer.read().split())
print(solve(n, e, t, xxx))