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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF = 1e18 + 2;
const int MX = 103;
int N, M, k;
int arr[MX];
int can[MX];
int main() {
  scanf("%d", &N);
  scanf("%d", &M);
  for (int i = 1; i <= N; i++)
    arr[i] = 1;
  can[1] = 1;
  for (int i = 0; i < M; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    arr[a]--;
    arr[b]++;
    can[b] |= can[a];
    if (!arr[a])
      can[a] = 0;
  }
  int an = 0;
  for (int i = 1; i <= N; i++)
    an += (can[i] ? 1 : 0);
  cout << an;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF = 1e18 + 2;
const int MX = 100003;
int N, M, k;
int arr[MX];
int can[MX];
int main() {
  scanf("%d", &N);
  scanf("%d", &M);
  for (int i = 1; i <= N; i++)
    arr[i] = 1;
  can[1] = 1;
  for (int i = 0; i < M; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    arr[a]--;
    arr[b]++;
    can[b] |= can[a];
    if (!arr[a])
      can[a] = 0;
  }
  int an = 0;
  for (int i = 1; i <= N; i++)
    an += (can[i] ? 1 : 0);
  cout << an;
  return 0;
}
Problem p04034 (C++)

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

int main() {
  int n, m, x, y, box[20000];
  bool boxred[20000];

  cin >> n >> m;

  fill(box + 1, box + n + 1, 1);
  boxred[1] = true;

  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    if (boxred[x] && box[x] == 1) {
      boxred[x] = false;
      boxred[y] = true;
    } else if (boxred[x]) {
      boxred[y] = true;
    }

    box[x]--;
    box[y]++;
  }

  cout << count(boxred + 1, boxred + n + 1, true) << endl;

  return (0);
}

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

int main() {
  int n, m, x, y, box[200000];
  bool boxred[200000];

  cin >> n >> m;

  fill(box + 1, box + n + 1, 1);
  boxred[1] = true;

  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    if (boxred[x] && box[x] == 1) {
      boxred[x] = false;
      boxred[y] = true;
    } else if (boxred[x]) {
      boxred[y] = true;
    }

    box[x]--;
    box[y]++;
  }

  cout << count(boxred + 1, boxred + n + 1, true) << endl;

  return (0);
}
Problem p04034 (C++)

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

using namespace std;
typedef long long ll;
const double PI = 3.14159265;

void fastInOut();

const int N = 100005;
int cnt[N];
bool flag[N];

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.in", "r", stdin);
#endif

  fastInOut();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cnt[i] = 1;
  flag[1] = 1;
  int x, y;
  while (m--) {
    cin >> x >> y;
    cnt[x]--;
    cnt[y]++;
    if (flag[x]) {
      flag[y] = 1;
      if (cnt[x] == 0)
        flag[x] = 0;
    }
  }
  int res = 0;
  for (int i = 1; i <= n; i++)
    res += flag[i];
  cout << res;
  return 0;
}

void fastInOut() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}

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

using namespace std;
typedef long long ll;
const double PI = 3.14159265;

void fastInOut();

const int N = 100005;
int cnt[N];
bool flag[N];

int main() {

  fastInOut();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cnt[i] = 1;
  flag[1] = 1;
  int x, y;
  while (m--) {
    cin >> x >> y;
    cnt[x]--;
    cnt[y]++;
    if (flag[x]) {
      flag[y] = 1;
      if (cnt[x] == 0)
        flag[x] = 0;
    }
  }
  int res = 0;
  for (int i = 1; i <= n; i++)
    res += flag[i];
  cout << res;
  return 0;
}

void fastInOut() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}
Problem p04034 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> x;
  vector<int> y;
  vector<int> num;
  vector<int> red;
  x.resize(N + 10);
  y.resize(N + 10);
  num.resize(N + 10);
  red.resize(N + 10);
  for (int n = 0; n < N; ++n) {
    num[n] = 1;
    red[n] = 0;
  }
  red[0] = 1;
  int j = 0;
  for (int n = 0; n < M; ++n) {
    cin >> x[n] >> y[n];
    x[n] = x[n] - 1;
    y[n] = y[n] - 1;
    if (red[x[n]] == 1) {
      red[y[n]] = 1;
    }
    num[x[n]] -= 1;
    num[y[n]] += 1;
    if (num[x[n]] == 0) {
      red[x[n]] = 0;
    }
  }
  for (int k = 0; k < N; ++k) {
    if (red[k])
      ++j;
  }
  cout << j << endl;
  return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> x;
  vector<int> y;
  vector<int> num;
  vector<int> red;
  x.resize(M + 10);
  y.resize(M + 10);
  num.resize(N + 10);
  red.resize(N + 10);
  for (int n = 0; n < N; ++n) {
    num[n] = 1;
    red[n] = 0;
  }
  red[0] = 1;
  int j = 0;
  for (int n = 0; n < M; ++n) {
    cin >> x[n] >> y[n];
    x[n] = x[n] - 1;
    y[n] = y[n] - 1;
    if (red[x[n]] == 1) {
      red[y[n]] = 1;
    }
    num[x[n]] -= 1;
    num[y[n]] += 1;
    if (num[x[n]] == 0) {
      red[x[n]] = 0;
    }
  }
  for (int k = 0; k < N; ++k) {
    if (red[k])
      ++j;
  }
  cout << j << endl;
  return 0;
}
Problem p04034 (C++)

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

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

  int N, M;
  cin >> N >> M;
  vector<int> boxes(N), flags(N);
  for (int i = 0; i < N; i++)
    boxes[i] = 1;
  for (int i = 0; i < N; i++)
    flags[i] = 0;
  flags[0] = 1;

  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    bool flag = false;
    for (int i = 0; i < N; i++) {
      if (flags[i] && x == i)
        flag = true;
    }
    if (flag) {
      if (boxes[x] == 1) {
        flags[x] = 0;
        flags[y] = 1;
        boxes[x]--;
        boxes[y]++;
      } else {
        flags[y] = 1;
        boxes[x]--;
        boxes[y]++;
      }
    } else {
      boxes[x]--;
      boxes[y]++;
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += flags[i];
  }

  cout << ans << endl;

  return 0;
}

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

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

  int N, M;
  cin >> N >> M;
  vector<int> boxes(N), flags(N);
  for (int i = 0; i < N; i++)
    boxes[i] = 1;
  for (int i = 0; i < N; i++)
    flags[i] = 0;
  flags[0] = 1;

  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;

    if (flags[x]) {
      if (boxes[x] == 1) {
        flags[x] = 0;
        flags[y] = 1;
        boxes[x]--;
        boxes[y]++;
      } else {
        flags[y] = 1;
        boxes[x]--;
        boxes[y]++;
      }
    } else {
      boxes[x]--;
      boxes[y]++;
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += flags[i];
  }

  cout << ans << endl;

  return 0;
}
Problem p04034 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e18;
template <typename T> void cmax(T &a, T b) { a = max(a, b); }
template <typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(n), y(n);
  rep(i, m) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }
  vector<int> red(100005, 0), num(100005, 1);
  red[0] = 1;
  rep(i, m) {
    if (red[x[i]]) {
      red[y[i]] = 1;
    }
    num[x[i]]--;
    num[y[i]]++;
    if (num[x[i]] == 0)
      red[x[i]] = 0;
  }
  int ans = 0;
  rep(i, n) ans += red[i] == 1;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e18;
template <typename T> void cmax(T &a, T b) { a = max(a, b); }
template <typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(m), y(m);
  rep(i, m) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }
  vector<int> red(100005, 0), num(100005, 1);
  red[0] = 1;
  rep(i, m) {
    if (red[x[i]]) {
      red[y[i]] = 1;
    }
    num[x[i]]--;
    num[y[i]]++;
    if (num[x[i]] == 0)
      red[x[i]] = 0;
  }
  int ans = 0;
  rep(i, n) ans += red[i] == 1;
  cout << ans << endl;
  return 0;
}
Problem p04034 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> a(N);
  for (int i = 0; i < M; i++) {
    a[i].first = 1;
  }
  a[0].second = 1;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    a[x - 1].first--;
    a[y - 1].first++;
    if (a[x - 1].second == 1) {
      if (a[x - 1].first == 0) {
        a[x - 1].second = 0;
        a[y - 1].second = 1;
      } else if (a[x - 1].second > 0) {
        a[y - 1].second = 1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += a[i].second;
  }
  cout << ans << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> a(N);
  for (int i = 0; i < N; i++) {
    a[i].first = 1;
  }
  a[0].second = 1;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    a[x - 1].first--;
    a[y - 1].first++;
    if (a[x - 1].second == 1) {
      if (a[x - 1].first == 0) {
        a[x - 1].second = 0;
        a[y - 1].second = 1;
      } else if (a[x - 1].second > 0) {
        a[y - 1].second = 1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += a[i].second;
  }
  cout << ans << endl;
}
Problem p04034 (C++)

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

using namespace std;

typedef pair<int, int> edge;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int result[100010];
  result[1] = 1;
  int num_ball[100010];
  for (int i = 1; i <= n; i++) {
    num_ball[i] = 1;
  }
  vector<edge> edge_list(m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    edge e(x, y);
    edge_list[i] = e;
  }
  for (int i = 1; i <= m; i++) {
    int src = edge_list[i].first;
    int dst = edge_list[i].second;
    num_ball[src]--;
    num_ball[dst]++;
    if (result[src])
      result[dst] = 1;
    if (num_ball[src] == 0)
      result[src] = 0;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (result[i])
      sum++;
  }
  printf("%d\n", sum);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>

using namespace std;

typedef pair<int, int> edge;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int result[100010];
  result[1] = 1;
  int num_ball[100010];
  for (int i = 1; i <= n; i++) {
    num_ball[i] = 1;
  }
  vector<edge> edge_list(m + 1);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    edge e(x, y);
    edge_list[i] = e;
  }
  for (int i = 1; i <= m; i++) {
    int src = edge_list[i].first;
    int dst = edge_list[i].second;
    num_ball[src]--;
    num_ball[dst]++;
    if (result[src])
      result[dst] = 1;
    if (num_ball[src] == 0)
      result[src] = 0;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (result[i])
      sum++;
  }
  printf("%d\n", sum);
  return 0;
}
Problem p04034 (C++)

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

typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const long long INF = (1LL << 60);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll stringcount(string s, char c) { return count(s.cbegin(), s.cend(), c); }
bool isInteger(double x) { return floor(x) == x; }
ll ceil(const ll a, const ll b) { return ((a) + (b)-1) / b; }

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

  ll n, m;
  cin >> n >> m;
  vector<ll> cnt(n, 1);
  vector<pll> xy(n);
  for (ll i = 0; i < m; i++) {
    cin >> xy[i].first >> xy[i].second;
    xy[i].first--, xy[i].second--;
  }

  vector<bool> yes(n);
  yes[0] = true;
  for (ll i = 0; i < m; i++) {
    // cout << xy[i].first << ' ' << xy[i].second << endl;
    if (yes[xy[i].first]) {
      yes[xy[i].second] = true;
      cnt[xy[i].first]--;
      cnt[xy[i].second]++;
    } else {
      if (cnt[xy[i].second] == 0)
        yes[xy[i].second] = false;
      cnt[xy[i].first]--;
      cnt[xy[i].second]++;
    }
  }

  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    if (yes[i] && cnt[i] > 0)
      ans++;
  }

  // for(auto i : cnt) cout << i << endl;
  // for(auto i : yes) cout << i << endl;
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const long long INF = (1LL << 60);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll stringcount(string s, char c) { return count(s.cbegin(), s.cend(), c); }
bool isInteger(double x) { return floor(x) == x; }
ll ceil(const ll a, const ll b) { return ((a) + (b)-1) / b; }

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

  ll n, m;
  cin >> n >> m;
  vector<ll> cnt(n, 1);
  vector<pll> xy(m);
  for (ll i = 0; i < m; i++) {
    cin >> xy[i].first >> xy[i].second;
    xy[i].first--, xy[i].second--;
  }

  vector<bool> yes(n);
  yes[0] = true;
  for (ll i = 0; i < m; i++) {
    // cout << xy[i].first << ' ' << xy[i].second << endl;
    if (yes[xy[i].first]) {
      yes[xy[i].second] = true;
      cnt[xy[i].first]--;
      cnt[xy[i].second]++;
    } else {
      if (cnt[xy[i].second] == 0)
        yes[xy[i].second] = false;
      cnt[xy[i].first]--;
      cnt[xy[i].second]++;
    }
  }

  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    if (yes[i] && cnt[i] > 0)
      ans++;
  }

  // for(auto i : cnt) cout << i << endl;
  // for(auto i : yes) cout << i << endl;
  cout << ans << endl;
  return 0;
}
Problem p04034 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, 0), q(n, 1);
  a[0] = 1;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a[y] |= a[x];
    q[x]--;
    q[y]++;
    if (q[x] == 0)
      a[x] = 0;
  }
  cout << accumulate(a.begin(), a.end(), 0) << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, 0), q(n, 1);
  a[0] = 1;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a[y] |= a[x];
    q[x]--;
    q[y]++;
    if (q[x] == 0)
      a[x] = 0;
  }
  cout << accumulate(a.begin(), a.end(), 0) << endl;
  return 0;
}
Problem p04034 (C++)

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

int red[10001], ball[10001];

int main(void) {
  int N, M, x, y, ans = 0;
  cin.tie(0);
  ios::sync_with_stdio(false);
  red[0] = 1;
  cin >> N >> M;
  fill(ball, ball + N, 1);
  // for (int i = 0; i < N; i++) cout << red[i] << " ";
  // cout << endl;
  for (int i = 0; i < M; i++) {
    cin >> x >> y;
    if (ball[x - 1] == 1 && red[x - 1]) {
      ball[x - 1]--;
      red[x - 1] = 0;
      ball[y - 1]++;
      red[y - 1] = 1;
      // for (int i = 0; i < N; i++) cout << red[i] << " ";
      // cout << endl;
    } else if (ball[x - 1] == 1 && !red[x - 1]) {
      ball[x - 1]--;
      ball[y - 1]++;
    } else if (ball[x - 1] > 1) {
      ball[x - 1]--;
      ball[y - 1]++;
      if (red[x - 1])
        red[y - 1] = 1;
      // for (int i = 0; i < N; i++) cout << red[i] << " ";
      // cout << endl;
    }
  }
  // for (int i = 0; i < N; i++) cout << red[i] << " ";
  // cout << endl;
  ans = count(red, red + N, 1);
  cout << ans << endl;
  return 0;
}


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

int red[100001], ball[100001];

int main(void) {
  int N, M, x, y, ans = 0;
  cin.tie(0);
  ios::sync_with_stdio(false);
  red[0] = 1;
  cin >> N >> M;
  fill(ball, ball + N, 1);
  // for (int i = 0; i < N; i++) cout << red[i] << " ";
  // cout << endl;
  for (int i = 0; i < M; i++) {
    cin >> x >> y;
    if (ball[x - 1] == 1 && red[x - 1]) {
      ball[x - 1]--;
      red[x - 1] = 0;
      ball[y - 1]++;
      red[y - 1] = 1;
      // for (int i = 0; i < N; i++) cout << red[i] << " ";
      // cout << endl;
    } else if (ball[x - 1] == 1 && !red[x - 1]) {
      ball[x - 1]--;
      ball[y - 1]++;
    } else if (ball[x - 1] > 1) {
      ball[x - 1]--;
      ball[y - 1]++;
      if (red[x - 1])
        red[y - 1] = 1;
      // for (int i = 0; i < N; i++) cout << red[i] << " ";
      // cout << endl;
    }
  }
  // for (int i = 0; i < N; i++) cout << red[i] << " ";
  // cout << endl;
  ans = count(red, red + N, 1);
  cout << ans << endl;
  return 0;
}
Problem p04034 (C++)

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

using namespace std;

int main() {
  int n = 0, m = 0;
  cin >> n >> m;
  vector<int> cnt(n, 1);
  vector<bool> red(n, false);
  red.at(0) = true;
  int x = 0, y = 0;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    x--;
    y--;
    cnt.at(x)--;
    cnt.at(y)++;
    if (red.at(x)) {
      red.at(y) = true;
    }
    if (cnt.at(x) == 0) {
      red.at(x) = false;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (red.at(i))
      ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
  int n = 0, m = 0;
  cin >> n >> m;
  vector<int> cnt(n, 1);
  vector<bool> red(n, false);
  red.at(0) = true;
  int x = 0, y = 0;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    x--;
    y--;
    cnt.at(x)--;
    cnt.at(y)++;
    if (red.at(x)) {
      red.at(y) = true;
    }
    if (cnt.at(x) == 0) {
      red.at(x) = false;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (red.at(i))
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p04034 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
struct P {
  // string r;
  int x, y, z;

  bool operator<(const P &a) const {
    // if(y!=a.y)
    // return y>a.y;
    return x > a.x;
    //        return z>a.z;
  }
};

vector<P> v[5555];
// bitset<4001000> b;
int a, c, i, b, k, d, n, m,
    e; // dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[15555];
int o[15400];
int dx[10] = {0, 1, 0, -1}, dy[10] = {1, 0, -1, 0},
    dz[10] = {0, 0, 0, 0, 1, -1};

long long x, y, z, mod = 1000000007;
P u[111111];
double j[111];

stack<int> s;
queue<P> q;
//'1'==49;
//'A'==65;
//'a'==97;
// unordered_
map<int, int> p;
// list<int> l;
string r;
// char r[333][333];

bool as(P a, P b) {
  if (a.x != b.x)
    return a.x < b.x;
  return a.y > b.y;
}

int main() {
  scanf("%d %d", &a, &b);
  for (int t = 1; t <= a; o[t] = 1, t++)
    ;
  l[1] = 1;
  for (int t = 1; t <= b; t++) {
    scanf("%d %d", &n, &m);
    o[n]--;
    o[m]++;
    if (l[n])
      l[m] = 1;
    if (!o[n])
      l[n] = 0;
  }
  for (int t = 1; t <= a; k += l[t], t++)
    ;
  printf("%d ", k);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
struct P {
  // string r;
  int x, y, z;

  bool operator<(const P &a) const {
    // if(y!=a.y)
    // return y>a.y;
    return x > a.x;
    //        return z>a.z;
  }
};

vector<P> v[5555];
// bitset<4001000> b;
int a, c, i, b, k, d, n, m,
    e; // dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[115555];
int o[115400];
int dx[10] = {0, 1, 0, -1}, dy[10] = {1, 0, -1, 0},
    dz[10] = {0, 0, 0, 0, 1, -1};

long long x, y, z, mod = 1000000007;
P u[111111];
double j[111];

stack<int> s;
queue<P> q;
//'1'==49;
//'A'==65;
//'a'==97;
// unordered_
map<int, int> p;
// list<int> l;
string r;
// char r[333][333];

bool as(P a, P b) {
  if (a.x != b.x)
    return a.x < b.x;
  return a.y > b.y;
}

int main() {
  scanf("%d %d", &a, &b);
  for (int t = 1; t <= a; o[t] = 1, t++)
    ;
  l[1] = 1;
  for (int t = 1; t <= b; t++) {
    scanf("%d %d", &n, &m);
    o[n]--;
    o[m]++;
    if (l[n])
      l[m] = 1;
    if (!o[n])
      l[n] = 0;
  }
  for (int t = 1; t <= a; k += l[t], t++)
    ;
  printf("%d ", k);
}
Problem p04034 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, k, n) for (int i = (k); i < (n); ++i)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

inline ll add(ll x, ll y) { return (x + y) % MOD; }
inline ll mul(ll x, ll y) { return (x * y) % MOD; }
inline ll sub(ll x, ll y) {
  ll res = x - y;
  if (res < 0)
    res += MOD;
  return res;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> cnt(N, 1);
  vector<bool> red(N, false);
  red[0] = true;
  REP(i, N) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    cnt[x]--, cnt[y]++;
    if (red[x] && cnt[x] < 1) {
      red[x] = false;
      red[y] = true;
    } else if (red[x] && cnt[x] >= 1) {
      red[y] = true;
    }
  }
  int ans = 0;
  REP(i, N) if (red[i]) ans++;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, k, n) for (int i = (k); i < (n); ++i)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

inline ll add(ll x, ll y) { return (x + y) % MOD; }
inline ll mul(ll x, ll y) { return (x * y) % MOD; }
inline ll sub(ll x, ll y) {
  ll res = x - y;
  if (res < 0)
    res += MOD;
  return res;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> cnt(N, 1);
  vector<bool> red(N, false);
  red[0] = true;
  REP(i, M) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    cnt[x]--, cnt[y]++;
    if (red[x] && cnt[x] < 1) {
      red[x] = false;
      red[y] = true;
    } else if (red[x] && cnt[x] >= 1) {
      red[y] = true;
    }
  }
  int ans = 0;
  REP(i, N) if (red[i]) ans++;
  cout << ans << endl;
  return 0;
}
Problem p04034 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> red(n, 0), cnt(n, 1);
  red[0] = 1;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    if (red[x] == 1) {
      if (cnt[x] == 1)
        red[x] = 0;
      red[y] = 1;
    }
    cnt[x]--;
    cnt[y]++;
  }

  int ans = 0;
  for (int i = 0; i < n; i++)
    ans += red[i];

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> red(n, 0), cnt(n, 1);
  red[0] = 1;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    if (red[x] == 1) {
      if (cnt[x] == 1)
        red[x] = 0;
      red[y] = 1;
    }
    cnt[x]--;
    cnt[y]++;
  }

  int ans = 0;
  for (int i = 0; i < n; i++)
    ans += red[i];

  cout << ans << endl;
}
Problem p04034 (C++)

Buggy submission (status: Runtime Error):
// https://atcoder.jp/contests/agc002/tasks/agc002_b

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> v(m + 1, 1); // 各箱にあるボースの数
  set<int> st; // 赤いボールがある可能性のある箱番号
  // 赤いボールは1番にあり
  st.insert(1);

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[x]--;
    v[y]++;
    if (st.count(x) == 1) {
      if (v[x] == 0) {
        st.erase(x);
      }
      st.insert(y);
    }
  }

  cout << st.size() << endl;

  return 0;
}

Fixed submission:
// https://atcoder.jp/contests/agc002/tasks/agc002_b

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> v(n + 1, 1); // 各箱にあるボースの数
  set<int> st; // 赤いボールがある可能性のある箱番号
  // 赤いボールは1番にあり
  st.insert(1);

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[x]--;
    v[y]++;
    if (st.count(x) == 1) {
      if (v[x] == 0) {
        st.erase(x);
      }
      st.insert(y);
    }
  }

  cout << st.size() << endl;

  return 0;
}
Problem p04034 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, s, n) for (int i = s; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF (ll)1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T> ostream &operator<<(std::ostream &o, const vector<T> &v) {
  rep(i, v.size()) { o << (i > 0 ? " " : "") << v[i]; }
  return o;
}

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

class CompareDist {
public:
  bool operator()(pair<int, int> n1, pair<int, int> n2) {
    return (n1.fs != n2.fs ? n1.fs < n2.fs : n1.sc < n2.sc);
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  vi box(n, 1), x(n), y(n);
  vector<bool> b(n, false);
  b[0] = true;
  rep(i, m) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }
  rep(i, m) {
    box[x[i]]--;
    box[y[i]]++;
    if (b[x[i]])
      b[y[i]] = true;
    if (box[x[i]] == 0)
      b[x[i]] = false;
  }
  int ans = 0;
  rep(i, n) {
    if (b[i])
      ans++;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, s, n) for (int i = s; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF (ll)1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T> ostream &operator<<(std::ostream &o, const vector<T> &v) {
  rep(i, v.size()) { o << (i > 0 ? " " : "") << v[i]; }
  return o;
}

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

class CompareDist {
public:
  bool operator()(pair<int, int> n1, pair<int, int> n2) {
    return (n1.fs != n2.fs ? n1.fs < n2.fs : n1.sc < n2.sc);
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  vi box(n, 1), x(m), y(m);
  vector<bool> b(n, false);
  b[0] = true;
  rep(i, m) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }
  rep(i, m) {
    box[x[i]]--;
    box[y[i]]++;
    if (b[x[i]])
      b[y[i]] = true;
    if (box[x[i]] == 0)
      b[x[i]] = false;
  }
  int ans = 0;
  rep(i, n) {
    if (b[i])
      ans++;
  }
  cout << ans << endl;
}
Problem p04035 (C++)

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

using namespace std;

typedef long long ll;

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

  int n;
  cin >> n;
  ll l;
  cin >> l;
  std::vector<ll> v(n);
  ll idx;
  bool flag = false;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < n - 1; i++) {
    if (v[i] + v[i + 1] >= l) {
      idx = i;
      flag = true;
      break;
    }
  }
  if (flag) {
    cout << "Possible" << endl;
    for (int i = 0; i < idx; i++) {
      cout << i + 1 << endl;
    }
    for (int i = n - 2; i > idx; i++) {
      cout << i + 1 << endl;
    }
    cout << idx + 1 << endl;
  } else
    cout << "Impossible" << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

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

  int n;
  cin >> n;
  ll l;
  cin >> l;
  std::vector<ll> v(n);
  ll idx;
  bool flag = false;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < n - 1; i++) {
    if (v[i] + v[i + 1] >= l) {
      idx = i;
      flag = true;
      break;
    }
  }
  if (flag) {
    cout << "Possible" << endl;
    for (int i = 0; i < idx; i++) {
      cout << i + 1 << endl;
    }
    for (int i = n - 2; i > idx; i--) {
      cout << i + 1 << endl;
    }
    cout << idx + 1 << endl;
  } else
    cout << "Impossible" << endl;
  return 0;
}
Problem p04035 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll n, a, b, k;
  in2(n, k);
  vector<ll> c(n);
  rep(i, n) in(c[i]);
  bool h = false;
  rep(i, n - 1) {
    if (c[i] + c[i + 1] >= k) {
      a = i;
      h = true;
    }
  }
  if (!h) {
    out("Impossible");
    memi;
  }
  out("Possible");
  memi;
  rep(i, a) {
    out(i + 1);
    memi;
  }
  b = n - 2;
  while (b >= a) {
    out(b + 1);
    memi;
    b--;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll n, a, b, k;
  in2(n, k);
  vector<ll> c(n);
  rep(i, n) in(c[i]);
  bool h = false;
  rep(i, n - 1) {
    if (c[i] + c[i + 1] >= k) {
      a = i;
      h = true;
    }
  }
  if (!h) {
    out("Impossible");
    memi;
    return 0;
  }
  out("Possible");
  memi;
  rep(i, a) {
    out(i + 1);
    memi;
  }
  b = n - 2;
  while (b >= a) {
    out(b + 1);
    memi;
    b--;
  }
}
Problem p04035 (C++)

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

#define mp make_pair
#define pb push_back
#define pf push_front
#define pbp pop_back
#define pfp pop_front
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define ios_base ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define open(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout)
#define F first
#define S second

using namespace std;

typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7;
const int N = 1e5 + 123;
const int inf = 1e9 + 123;
const long long INF = 1e18;
const double eps = 1e-5;

int n, l, a[N];
ll p[N];
int main() {
  ios_base cin >> n >> l;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    p[i] = a[i] + p[i - 1];
  }
  int start = 0;
  vector<int> v;
  int c = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] + a[i + 1] >= l)
      c = i;
  }
  if (c == 0)
    return cout << "Impossible", 0;
  cout << "Possible" << endl;
  for (int i = 1; i < c; i++) {
    cout << i << endl;
  }
  for (int i = n - 1; i > c; i++) {
    cout << i << endl;
  }
  cout << c << endl;
  return 0;
}


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

#define mp make_pair
#define pb push_back
#define pf push_front
#define pbp pop_back
#define pfp pop_front
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define ios_base ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define open(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout)
#define F first
#define S second

using namespace std;

typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7;
const int N = 1e5 + 123;
const int inf = 1e9 + 123;
const long long INF = 1e18;
const double eps = 1e-5;

int n, l, a[N];
ll p[N];
int main() {
  ios_base cin >> n >> l;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    p[i] = a[i] + p[i - 1];
  }
  int start = 0;
  vector<int> v;
  int c = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] + a[i + 1] >= l)
      c = i;
  }
  if (c == 0)
    return cout << "Impossible", 0;
  cout << "Possible" << endl;
  for (int i = 1; i < c; i++) {
    cout << i << endl;
  }
  for (int i = n - 1; i > c; i--) {
    cout << i << endl;
  }
  cout << c << endl;
  return 0;
}
Problem p04035 (C++)

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

using namespace std;

int a[100010];

int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  int n, l;
  scanf("%d%d", &n, &l);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int j = 0;
  for (int i = 1; i < n; i++)
    if (a[i] + a[i + 1] >= l)
      j = i;
  if (!j) {
    puts("Impossible");
    return 0;
  }
  puts("Possible");
  for (int i = 1; i < j; i++)
    printf("%d\n", i);
  for (int i = n - 1; i > j; i--)
    printf("%d\n", i);
  printf("%d\n", j);
  return 0;
}


Fixed submission:
#include <cstdio>

using namespace std;

int a[100010];

int main() {
  int n, l;
  scanf("%d%d", &n, &l);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int j = 0;
  for (int i = 1; i < n; i++)
    if (a[i] + a[i + 1] >= l)
      j = i;
  if (!j) {
    puts("Impossible");
    return 0;
  }
  puts("Possible");
  for (int i = 1; i < j; i++)
    printf("%d\n", i);
  for (int i = n - 1; i > j; i--)
    printf("%d\n", i);
  printf("%d\n", j);
  return 0;
}
Problem p04035 (C++)

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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL << 60)

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

int N, L;
int a[123456];

signed main() {

  cin >> N >> L;
  rep(i, N) { cin >> a[i]; }
  int t = -1;
  rep(i, N - 1) {
    if (a[i] + a[i + 1] >= L) {
      t = i;
      break;
    }
  }
  if (t == -1) {
    cout << "Impossible" << endl;
  } else {
    cout << "Possible" << endl;
    for (int i = 0; i < t; i++)
      cout << i + 1 << endl;
    for (int i = N - 2; i >= t; i++)
      cout << i + 1 << endl;
  }

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL << 60)

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

int N, L;
int a[123456];

signed main() {

  cin >> N >> L;
  rep(i, N) { cin >> a[i]; }
  int t = -1;
  rep(i, N - 1) {
    if (a[i] + a[i + 1] >= L) {
      t = i;
      break;
    }
  }
  if (t == -1) {
    cout << "Impossible" << endl;
  } else {
    cout << "Possible" << endl;
    for (int i = 0; i < t; i++)
      cout << i + 1 << endl;
    for (int i = N - 2; i >= t; i--)
      cout << i + 1 << endl;
  }

  return 0;
}
Problem p04035 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
template <typename T> void fin(T a) {
  cout << a << endl;
  exit(0);
}
#define int long long

signed main() {
  int n, l;
  cin >> n >> l;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  int a = -1;
  for (int i = 1; i < n; i++)
    if (v[i] + v[i - 1] >= l)
      a = i;
  if (a < 0)
    fin("Impossible");
  cout << "Possible" << endl;
  for (int i = 1; i < a; i++)
    cout << i << endl;
  for (int i = n - 1; i >= a; i++)
    cout << i << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
template <typename T> void fin(T a) {
  cout << a << endl;
  exit(0);
}
#define int long long

signed main() {
  int n, l;
  cin >> n >> l;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  int a = -1;
  for (int i = 1; i < n; i++)
    if (v[i] + v[i - 1] >= l)
      a = i;
  if (a < 0)
    fin("Impossible");
  cout << "Possible" << endl;
  for (int i = 1; i < a; i++)
    cout << i << endl;
  for (int i = n - 1; i >= a; i--)
    cout << i << endl;
}
Problem p04035 (C++)

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

int main() {
  int n, l;
  bool f = false;
  cin >> n >> l;
  int k, j;
  vector<int> a(n);
  vector<int> co(n - 1);
  cin >> a.at(0);
  for (int i = 1; i < n; i++) {
    cin >> a.at(i);
    if (a.at(i - 1) + a.at(i) >= l) {
      f = true;
      k = i;
    }
  }
  if (f) {
    for (int i = 1; i < k; i++) {
      co.at(i - 1) = i;
      j = i;
    }
    for (int i = n - 1; i >= k; i--, j++) {
      co.at(j) = i;
    }
    cout << "Possible" << endl;
    for (int i = 0; i < n - 1; i++) {
      cout << co.at(i) << endl;
    }
  } else {
    cout << "Impossible" << endl;
  }
}

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

int main() {
  int n, l;
  bool f = false;
  cin >> n >> l;
  int k = 1, j = 0;
  vector<int> a(n);
  vector<int> co(n - 1);
  cin >> a.at(0);
  for (int i = 1; i < n; i++) {
    cin >> a.at(i);
    if (a.at(i - 1) + a.at(i) >= l) {
      f = true;
      k = i;
    }
  }
  if (f) {
    for (int i = 1; i < k; i++) {
      co.at(i - 1) = i;
      j = i;
    }
    for (int i = n - 1; i >= k; i--, j++) {
      co.at(j) = i;
    }
    cout << "Possible" << endl;
    for (int i = 0; i < n - 1; i++) {
      cout << co.at(i) << endl;
    }
  } else {
    cout << "Impossible" << endl;
  }
}
Problem p04035 (C++)

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

#define FOR(i, init, a) for (int i = init; i < a; i++)
#define rep(i, a) FOR(i, 0, a)
#define rrep(i, a) for (int i = a; i >= 0; i--)
#define rep1(i, a) for (int i = 1; i <= a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a, b) cout << a << " " << b << endl;
#define cout3(a, b, c) cout << a << " " << b << " " << c << endl;
#define cout4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a, n) memset(a, n, sizeof(a))
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

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

  ll N, L, nums[1009];

  cin >> N >> L;
  rep(i, N) cin >> nums[i];

  ll mx = 0, best;
  rep(i, N - 1) {
    if (mx < nums[i] + nums[i + 1]) {
      mx = nums[i] + nums[i + 1];
      best = i;
    }
  }

  if (mx < L) {
    cout1("Impossible");
  } else {
    cout1("Possible");
    rep(i, best) { cout1(i + 1); }
    for (int i = N - 1; i > best; i--) {
      cout1(i);
    }
  }
}

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

#define FOR(i, init, a) for (int i = init; i < a; i++)
#define rep(i, a) FOR(i, 0, a)
#define rrep(i, a) for (int i = a; i >= 0; i--)
#define rep1(i, a) for (int i = 1; i <= a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a, b) cout << a << " " << b << endl;
#define cout3(a, b, c) cout << a << " " << b << " " << c << endl;
#define cout4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a, n) memset(a, n, sizeof(a))
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

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

  ll N, L, nums[100009];

  cin >> N >> L;
  rep(i, N) cin >> nums[i];

  ll mx = 0, best;
  rep(i, N - 1) {
    if (mx < nums[i] + nums[i + 1]) {
      mx = nums[i] + nums[i + 1];
      best = i;
    }
  }

  if (mx < L) {
    cout1("Impossible");
  } else {
    cout1("Possible");
    rep(i, best) { cout1(i + 1); }
    for (int i = N - 1; i > best; i--) {
      cout1(i);
    }
  }
}
Problem p04035 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int s, n, m;
int a[300000];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  int mx = -1;
  int nm = 0;
  for (int i = 1; i < n; i++)
    if (a[i] + a[i + 1] > mx) {
      mx = a[i] + a[i + 1];
      nm = i;
    }
  if (mx < m)
    cout << "Impossible\n";
  else {
    cout << "Possible\n";
    for (int i = 1; i < nm; i++)
      cout << i << "\n";
    for (int i = n - 1; i >= nm + 1; i++)
      cout << i << "\n";
    cout << nm << "\n";
  }
  return 0;
}


Fixed submission:
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int s, n, m;
int a[300000];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  int mx = -1;
  int nm = 0;
  for (int i = 1; i < n; i++)
    if (a[i] + a[i + 1] > mx) {
      mx = a[i] + a[i + 1];
      nm = i;
    }
  if (mx < m)
    cout << "Impossible\n";
  else {
    cout << "Possible\n";
    for (int i = 1; i < nm; i++)
      cout << i << "\n";
    for (int i = n - 1; i >= nm + 1; i--)
      cout << i << "\n";
    cout << nm << "\n";
  }
  return 0;
}
Problem p04035 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define itn int
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; i--)
#define all(vec) vec.begin(), vec.end()
#define sortt(vec) sort((vec).begin(), (vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const int inf = 2e9;
const ll lnf = 9e18;

int main() {
  itn n, l;
  cin >> n >> l;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int it = -1;
  rep(i, n - 1) {
    if (a[i] + a[i + 1] >= l) {
      it = i;
    }
  }
  if (it == -1) {
    cout << "Impossible" << endl;
    return 0;
  }
  cout << "Possible" << endl;
  rep(i, it) cout << i + 1 << endl;
  for (int i = n - 2; i >= it + 1; i++)
    cout << i + 1 << endl;
  cout << it + 1 << endl;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define itn int
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; i--)
#define all(vec) vec.begin(), vec.end()
#define sortt(vec) sort((vec).begin(), (vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const int inf = 2e9;
const ll lnf = 9e18;

int main() {
  itn n, l;
  cin >> n >> l;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int it = -1;
  rep(i, n - 1) {
    if (a[i] + a[i + 1] >= l) {
      it = i;
    }
  }
  if (it == -1) {
    cout << "Impossible" << endl;
    return 0;
  }
  cout << "Possible" << endl;
  rep(i, it) cout << i + 1 << endl;
  for (int i = n - 2; i >= it + 1; i--)
    cout << i + 1 << endl;
  cout << it + 1 << endl;
}
Problem p04035 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <typeinfo>
#include <vector>

#define DIV 1000000007

using namespace std;

long long N, L;
long long a[100005];

int main() {
  cin >> N >> L;
  long long maxcomb = -1;
  long long maxidx = -1;

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

  for (int i = 0; i < N - 1; i++) {
    if (maxcomb < a[i] + a[i + 1]) {
      maxidx = i;
      maxcomb = a[i] + a[i + 1];
    }
  }
  if (maxcomb < L) {
    cout << "Impossible" << endl;
    return 0;
  }

  cout << "Possible" << endl;
  for (int i = 0; i < N - 1; i++) {
    return 1;
    if (i != maxidx) {
      cout << i + 1 << endl;
    }
  }
  cout << maxidx + 1 << endl;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <typeinfo>
#include <vector>

#define DIV 1000000007

using namespace std;

long long N, L;
long long a[100005];

int main() {
  cin >> N >> L;
  long long maxcomb = -1;
  long long maxidx = -1;

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

  for (int i = 0; i < N - 1; i++) {
    if (maxcomb < a[i] + a[i + 1]) {
      maxidx = i;
      maxcomb = a[i] + a[i + 1];
    }
  }
  if (maxcomb < L) {
    cout << "Impossible" << endl;
    return 0;
  }

  cout << "Possible" << endl;
  for (int i = 0; i < maxidx; i++) {
    cout << i + 1 << endl;
  }
  for (int i = N - 2; i > maxidx; i--) {
    cout << i + 1 << endl;
  }
  cout << maxidx + 1 << endl;
}