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

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

const int maxn = 510;

int n, a[maxn][maxn];
long long from[maxn][maxn], to[maxn][maxn], dp[maxn][maxn][maxn], ans;

void cmin(long long &x, long long y) { x = min(x, y); }

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j)
      if (j != i) {
        scanf("%d", &a[i][j]);
        from[i][j] = (j ? from[i][j - 1] : 0) + a[i][j];
      }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      to[i][j] = (j ? to[i][j - 1] : 0) + a[j][i];
    }
  }
  memset(dp, 0x3f, sizeof(dp));
  ans = dp[0][0][0];
  dp[0][0][0] = 0;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = 0; j <= i; ++j) {
      for (int k = 0; k <= j; ++k) {
        cmin(dp[i + 1][j][k], dp[i][j][k] +
                                  (to[i + 1][i] - (j ? to[i + 1][j - 1] : 0)) +
                                  (k ? from[i + 1][k - 1] : 0));
        cmin(dp[i + 1][i + 1][j], dp[i][j][k] + (j ? from[i + 1][j - 1] : 0));
      }
    }
  }
  for (int j = 0; j < n; ++j)
    for (int k = 0; k <= j; ++k)
      cmin(ans, dp[n - 1][j][k]);
  cout << ans << endl;
}


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

const int maxn = 500;

int n, a[maxn][maxn];
long long from[maxn][maxn], to[maxn][maxn], dp[maxn][maxn][maxn], ans;

void cmin(long long &x, long long y) { x = min(x, y); }

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j)
      if (j != i) {
        scanf("%d", &a[i][j]);
        from[i][j] = (j ? from[i][j - 1] : 0) + a[i][j];
      }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      to[i][j] = (j ? to[i][j - 1] : 0) + a[j][i];
    }
  }
  memset(dp, 0x3f, sizeof(dp));
  ans = dp[0][0][0];
  dp[0][0][0] = 0;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = 0; j <= i; ++j) {
      for (int k = 0; k <= j; ++k) {
        cmin(dp[i + 1][j][k], dp[i][j][k] +
                                  (to[i + 1][i] - (j ? to[i + 1][j - 1] : 0)) +
                                  (k ? from[i + 1][k - 1] : 0));
        cmin(dp[i + 1][i + 1][j], dp[i][j][k] + (j ? from[i + 1][j - 1] : 0));
      }
    }
  }
  for (int j = 0; j < n; ++j)
    for (int k = 0; k <= j; ++k)
      cmin(ans, dp[n - 1][j][k]);
  cout << ans << endl;
}
Problem p02969 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #include<unordered_map>
#define debug(x) (cout << "#x = " << (x) << endl)
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
// #define mid (l + r >> 1)
#define lowbit(x) (x & -x)
#define Set(x, i) memset(x, i, sizeof x)
#define R register
#define For(i, j, k) for (R int i = (j); i <= (k); ++i)
#define foR(i, j, k) for (R int i = (j); i >= (k); --i)
#define Cross(i, j, k)                                                         \
  for (R int i = (j); i; i = (k))                                              \
    using namespace std;
typedef long long ll;
using namespace std;
const ll N = 100011;
const ll Inf = 0x3f3f3f3f3f3f;

namespace IO {

#define dd ch = getchar()
inline ll read() {
  ll x = 0;
  bool f = 0;
  char dd;
  for (; !isdigit(ch); dd)
    f ^= (ch == '-');
  for (; isdigit(ch); dd)
    x = x * 10 + (ch ^ 48);
  return f ? -x : x;
}
#undef dd

inline void write(ll x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 | 48);
}

inline void wrn(ll x) {
  write(x);
  putchar(' ');
}

inline void wln(ll x) {
  write(x);
  putchar('\n');
}

inline void wlnn(ll x, ll y) {
  wrn(x);
  wln(y);
}

} // namespace IO

using namespace IO;

namespace Cesare {

int main() {
  ll a = read();
  wln(a * a * 3);
}

} // namespace Cesare

int main() { return Cesare::main(); }

/*

*/


Fixed submission:
#include <bits/stdc++.h>
// #include<unordered_map>
#define debug(x) (cout << "#x = " << (x) << endl)
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
// #define mid (l + r >> 1)
#define lowbit(x) (x & -x)
#define Set(x, i) memset(x, i, sizeof x)
#define R register
#define For(i, j, k) for (R int i = (j); i <= (k); ++i)
#define foR(i, j, k) for (R int i = (j); i >= (k); --i)
#define Cross(i, j, k)                                                         \
  for (R int i = (j); i; i = (k))                                              \
    using namespace std;
typedef long long ll;
using namespace std;
const ll N = 100011;
const ll Inf = 0x3f3f3f3f3f3f;

namespace IO {

#define dd ch = getchar()
inline ll read() {
  ll x = 0;
  bool f = 0;
  char dd;
  for (; !isdigit(ch); dd)
    f ^= (ch == '-');
  for (; isdigit(ch); dd)
    x = x * 10 + (ch ^ 48);
  return f ? -x : x;
}
#undef dd

inline void write(ll x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 | 48);
}

inline void wrn(ll x) {
  write(x);
  putchar(' ');
}

inline void wln(ll x) {
  write(x);
  putchar('\n');
}

inline void wlnn(ll x, ll y) {
  wrn(x);
  wln(y);
}

} // namespace IO

using namespace IO;

namespace Cesare {

int main() {
  ll a = read();
  return wln(a * a * 3), 0;
}

} // namespace Cesare

int main() { return Cesare::main(); }

/*

*/
Problem p02969 (C++)

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

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define int long long int
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  IOS int n;
  cin >> n;
  cout << 3 * (n * n) << '\n';
  return 0;
}


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

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define int long long int
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

int32_t main() {

  IOS int n;
  cin >> n;
  cout << 3 * (n * n) << '\n';
  return 0;
}
Problem p02969 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
int main(void) {
  int r;
  std::cin >> r;
  std::cout << 3 * (r * r);

  return true;
}

Fixed submission:
#include <iostream>
int main(void) {
  int r;
  std::cin >> r;
  std::cout << 3 * (r * r);

  return 0;
}
Problem p02969 (C++)

Buggy submission (status: Runtime Error):
/**akshaykumar99**/

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

#define F first
#define S second
#define pp pop_back()
#define pu(x) push_back(x)
#define eb(x) emplace_back(x)
#define mp(a, b) make_pair(a, b)
#define all(v) v.begin(), v.end()
#define f(i, x, n) for (i = x; i < n; i++)
#define rall(v) v.rbegin(), v.rend()

const int MOD = 1e9 + 7, INF = INT_MAX;
const long long LINF = LLONG_MAX;

typedef long long ll;
typedef long double ld;
typedef vector<int> ivc;
typedef pair<int, int> ipr;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int r;
  cin >> r;
  ll z = r * r * 3;
  cout << z << endl;
}

Fixed submission:
/**akshaykumar99**/

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

#define F first
#define S second
#define pp pop_back()
#define pu(x) push_back(x)
#define eb(x) emplace_back(x)
#define mp(a, b) make_pair(a, b)
#define all(v) v.begin(), v.end()
#define f(i, x, n) for (i = x; i < n; i++)
#define rall(v) v.rbegin(), v.rend()

const int MOD = 1e9 + 7, INF = INT_MAX;
const long long LINF = LLONG_MAX;

typedef long long ll;
typedef long double ld;
typedef vector<int> ivc;
typedef pair<int, int> ipr;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int r;
  cin >> r;
  ll z = r * r * 3;
  cout << z << endl;
}
Problem p02969 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265
#define ll long long
#define vi vector<int>
#define pb push_back
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 100000000
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mk(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define ff first
#define ss second
#define re return
// #define endl "\n"
#define max2(x, y) (x > y) ? x : y
#define min2(x, y) (x < y) ? x : y
#define mid(s, e) (s + (e - s) / 2)
#define mini INT_MIN
#define maxo INT_MAX
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define read(a, n)                                                             \
  for (int i = 0; i < n; i++)                                                  \
  cin >> a[i]
#define show(a, n)                                                             \
  for (int i = 0; i < n; i++)                                                  \
    cout << a[i] << ' ';                                                       \
  cout << endl
#define en cout << "\n";

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  cout << 3 * n * n << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265
#define ll long long
#define vi vector<int>
#define pb push_back
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 100000000
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mk(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define ff first
#define ss second
#define re return
// #define endl "\n"
#define max2(x, y) (x > y) ? x : y
#define min2(x, y) (x < y) ? x : y
#define mid(s, e) (s + (e - s) / 2)
#define mini INT_MIN
#define maxo INT_MAX
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define read(a, n)                                                             \
  for (int i = 0; i < n; i++)                                                  \
  cin >> a[i]
#define show(a, n)                                                             \
  for (int i = 0; i < n; i++)                                                  \
    cout << a[i] << ' ';                                                       \
  cout << endl
#define en cout << "\n";

int main() {
  // #ifndef ONLINE_JUDGE
  //  freopen("input.txt","r",stdin);
  //  freopen("output.txt","w",stdout);
  // #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  cout << 3 * n * n << endl;
}
Problem p02969 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int i;
  cin >> i;
  cout << i << endl;
  return i * i * 3;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int i;
  cin >> i;
  cout << 3 * i * i << endl;
  // return 0;
};
Problem p02969 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF INT_MAX
#define endl '\n'
#define ll long long int
#define N 1000005
using namespace std;

inline int redi() {
  int ret = 0, f = 0;
  char ch = getchar_unlocked();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = 1;
    ch = getchar_unlocked();
  }
  while (isdigit(ch)) {
    ret = ret * 10 + ch - 48;
    ch = getchar_unlocked();
  }
  return f ? -ret : ret;
}
inline void print(int x) {
  if (x < 0) {
    putchar_unlocked('-');
    x = -x;
  }
  int y = 10, len = 1;
  while (y <= x) {
    y *= 10;
    len++;
  }
  while (len--) {
    y /= 10;
    putchar_unlocked(x / y + 48);
    x %= y;
  }
}

inline void init() {
  ll n;
  cin >> n;
  cout << 3 * n * n << endl;
}

inline void solve() {}

int main() {
  freopen("input.in", "r", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  init();
  solve();
  cout << flush;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define INF INT_MAX
#define endl '\n'
#define ll long long int
#define N 1000005
using namespace std;

inline int redi() {
  int ret = 0, f = 0;
  char ch = getchar_unlocked();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = 1;
    ch = getchar_unlocked();
  }
  while (isdigit(ch)) {
    ret = ret * 10 + ch - 48;
    ch = getchar_unlocked();
  }
  return f ? -ret : ret;
}
inline void print(int x) {
  if (x < 0) {
    putchar_unlocked('-');
    x = -x;
  }
  int y = 10, len = 1;
  while (y <= x) {
    y *= 10;
    len++;
  }
  while (len--) {
    y /= 10;
    putchar_unlocked(x / y + 48);
    x %= y;
  }
}

inline void init() {
  ll n;
  cin >> n;
  cout << 3 * n * n << endl;
}

inline void solve() {}

int main() {
  // freopen("input.in","r",stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  init();
  solve();
  cout << flush;

  return 0;
}
Problem p02969 (C++)

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

#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define SUBL                                                                   \
  freopen("/home/ajinkya/Desktop/input.txt", "r", stdin);                      \
  freopen("/home/ajinkya/Desktop/output.txt", "w", stdout);
#define ll long long
#define ull unsigned long long
#define FI(i, a, n) for (int i = a; i <= n; i++)
#define RFI(i, n, a) for (int i = n; i >= a; i--)
#define FLL(i, a, n) for (ll i = a; i <= n; i++)
#define RFLL(i, n, a) for (ll i = n; i >= a; i--)
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(), v.end()
#define pll pair<ll, ll>
#define pi pair<int, int>
#define GCD(a, b) __gcd(a, b)
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define debug(x) cout << x << endl
#define MOD 1000000007
#define INF LLONG_MAX
#define PI 3.14159265359
using namespace std;

int main() {
  fastio SUBL ll a;
  cin >> a;
  cout << 3 * a * a;
  return 0;
}

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

#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define SUBL                                                                   \
  freopen("/home/ajinkya/Desktop/input.txt", "r", stdin);                      \
  freopen("/home/ajinkya/Desktop/output.txt", "w", stdout);
#define ll long long
#define ull unsigned long long
#define FI(i, a, n) for (int i = a; i <= n; i++)
#define RFI(i, n, a) for (int i = n; i >= a; i--)
#define FLL(i, a, n) for (ll i = a; i <= n; i++)
#define RFLL(i, n, a) for (ll i = n; i >= a; i--)
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(), v.end()
#define pll pair<ll, ll>
#define pi pair<int, int>
#define GCD(a, b) __gcd(a, b)
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define debug(x) cout << x << endl
#define MOD 1000000007
#define INF LLONG_MAX
#define PI 3.14159265359
using namespace std;

int main() {
  fastio
      // SUBL
      ll a;
  cin >> a;
  cout << 3 * a * a;
  return 0;
}
Problem p02969 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back

#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
using namespace std;
signed main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  speed int r;
  cin >> r;
  cout << (3 * r * r);
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back

#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
using namespace std;
signed main() {
  speed int r;
  cin >> r;
  cout << (3 * r * r);
}
Problem p02969 (Python)

Buggy submission (status: Runtime Error):
r = input()
s = 3 * (r**2)
print(s)


Fixed submission:
r = int(input())
s = 3 * (r**2)
print(s)
Problem p02969 (Python)

Buggy submission (status: Runtime Error):
r = input()
print(3 * r * r)


Fixed submission:
r = int(input())
print(3 * r * r)
Problem p02969 (C++)

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

int main() {
  int a;
  cin >> a;
  a *= 3 * a;
  cout << a << endl;
  return a;
}


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

int main() {
  int a;
  cin >> a;
  a *= 3 * a;
  cout << a << endl;
  return 0;
}
Problem p02970 (C++)

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

int main() {
  int n, d;
  cin >> n >> d;

  int ans = n / (2 * d + 1);
  if (n % (ans * (2 * d + 1)) != 0) {
    ans++;
  }
  cout << ans << endl;
}

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

int main() {
  int n, d;
  cin >> n >> d;

  int a = 2 * d + 1;
  int ans = n / a;
  if (ans * a != n) {
    ans++;
  }
  cout << ans << endl;
}
Problem p02970 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
#define rg register
#define LL long long
#define __space putchar(' ')
#define __endl putchar('\n')
template <typename qwq> inline void read(qwq &x) {
  x = 0;
  rg LL f = 1;
  rg char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  x *= f;
}
template <typename qaq> inline void print(qaq x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9)
    print(x / 10);
  putchar(x % 10 + '0');
}
int n, d;
int main() {
  read(n), read(d);
  rg int tmp = n / (2 * d + 1);
  if (!(n % (tmp * (2 * d + 1))))
    print(tmp);
  else
    print(tmp + 1);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
#define rg register
#define LL long long
#define __space putchar(' ')
#define __endl putchar('\n')
template <typename qwq> inline void read(qwq &x) {
  x = 0;
  rg LL f = 1;
  rg char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  x *= f;
}
template <typename qaq> inline void print(qaq x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9)
    print(x / 10);
  putchar(x % 10 + '0');
}
int n, d;
int main() {
  read(n), read(d);
  rg int tmp = n / (2 * d + 1);
  if (!tmp)
    print(1);
  else if (!(n % (tmp * (2 * d + 1))))
    print(tmp);
  else
    print(tmp + 1);
  return 0;
}
Problem p02970 (C++)

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

using namespace std;

int main(void) {
  int n, d;
  cin >> n >> d;

  cout << n / (2 * d + 1) + (n % (2 * d + 1) == 0 ? 0 : 1) << endl;
  return 1;
}

Fixed submission:
#include <iostream>

using namespace std;

int main(void) {
  int n, d;
  cin >> n >> d;

  cout << n / (2 * d + 1) + (n % (2 * d + 1) == 0 ? 0 : 1) << endl;
  return 0;
}
Problem p02970 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, d;
  cin >> n >> d;
  int count = 0;
  int tree[20];
  for (int i = 0; i < n; i++) {
    tree[i] = 0;
  }

  for (int i = 0; i < n; i++) {
    if (tree[i] == 0) {
      for (int j = i; j <= i + 2 * d; j++) {
        tree[j] = 1;
      }
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, d;
  cin >> n >> d;
  int count = 0;
  int tree[100];
  for (int i = 0; i < n; i++) {
    tree[i] = 0;
  }

  for (int i = 0; i < n; i++) {
    if (tree[i] == 0) {
      for (int j = i; j <= i + 2 * d; j++) {
        tree[j] = 1;
      }
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02970 (C++)

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

#define REPI(i, n) for (int i = 0; i < n; i++)
#define REPJ(j, n) for (int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

  int n, d, ans = 0;
  cin >> n >> d;
  d = 2 * d + 1;
  for (; n > 0; ans++)
    d -= n;
  cout << ans;
}


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

#define REPI(i, n) for (int i = 0; i < n; i++)
#define REPJ(j, n) for (int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

  int n, d, ans = 0;
  cin >> n >> d;
  d = 2 * d + 1;
  for (; n > 0; ans++)
    n -= d;
  cout << ans;
}
Problem p02970 (C++)

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

using namespace std;

typedef long long ll;

int main() {
  int n;
  cin >> n;
  int d;
  cin >> d;
  d = d * 2;
  d++;
  d = n / d;
  if (n % d != 0)
    d++;
  cout << d << endl;
}


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

using namespace std;

typedef long long ll;

int main() {
  int n;
  cin >> n;
  int d;
  cin >> d;
  d = d * 2;
  d++;
  // cout<<d<<endl;
  int u = n / d;
  if (u == 0)
    u++;
  else {
    if (n % d != 0)
      u++;
  }
  cout << u << endl;
}
Problem p02970 (C++)

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

int main() {
  int n, d, c = 0;
  cin >> n >> d;
  vector<int> v;
  int a = (d + 1);
  while (a <= n) {
    c++;
    v.push_back(a);
    a += (2 * d + 1);
  }

  if ((n - (*(v.end() - 1))) > d)
    c++;
  cout << c;
}

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

int main() {
  int n, d, c = 0;
  cin >> n >> d;
  vector<int> v;
  int a = (d + 1);
  while (a <= n) {
    c++;
    v.push_back(a);
    a += (2 * d + 1);
  }
  if (c == 0) {
    cout << "1";
    return 0;
  }

  if ((n - (*(v.end() - 1))) > d)
    c++;
  cout << c;
}
Problem p02970 (C++)

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

int main() {
  int N, D;
  cin >> N >> D;
  int i = 1;
  int look = 0;
  while (1) {
    look += 2 * D + 1;
    if (look >= N) {
      return i;
    }
    i++;
  }
  cout << i << endl;
}


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

int main() {
  int N, D;
  cin >> N >> D;
  int i = 1;
  int look = 0;
  while (1) {
    look += 2 * D + 1;
    if (look >= N) {
      break;
    }
    i++;
  }
  cout << i << endl;
}
Problem p02970 (C++)

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

int main() {
  long long n, m, sum = 0, mod = 2019;
  cin >> n, m;

  cout << n / (2 * m) + 1 << endl;
}

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

int main() {
  long long n, m, sum = 0, mod = 2019;
  cin >> n >> m;
  if (n % (2 * m + 1) == 0)
    cout << n / (2 * m + 1) << endl;
  else
    cout << n / (2 * m + 1) + 1 << endl;
}
Problem p02970 (C++)

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

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define int long long int
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  IOS int n, d;
  cin >> n >> d;
  int ans = ceil((1.0 * n) / (2 * d + 1));
  cout << ans;
  return 0;
}


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

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define int long long int
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

int32_t main() {

  IOS int n, d;
  cin >> n >> d;
  int ans = ceil((1.0 * n) / (2 * d + 1));
  cout << ans;
  return 0;
}
Problem p02970 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back

#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
using namespace std;
signed main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  speed int n, d;
  cin >> n >> d;
  int q = (2 * d + 1);
  if ((n % q) == 0) {
    cout << (n / q);
  } else {
    cout << (n / q) + 1;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back

#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
using namespace std;
signed main() {
  speed int n, d;
  cin >> n >> d;
  int q = (2 * d + 1);
  if ((n % q) == 0) {
    cout << (n / q);
  } else {
    cout << (n / q) + 1;
  }
}
Problem p02970 (Python)

Buggy submission (status: Runtime Error):
n, d = map(int, input())
print(-(-n // (1 + d * 2)))


Fixed submission:
n, d = map(int, input().split())
print(-(-n // (1 + d * 2)))
Problem p02971 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vll vector<ll>
#define vii vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define matrix vector<vll>
#define all(v) v.begin(), v.end()
#define PQ priority_queue
using namespace std;
ll pow(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res *= a;
    b /= 2;
    a *= a;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vii v(n);
  multiset<int> ml;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    ml.insert(v[i]);
  }
  for (int i = 0; i < n; i++) {
    ml.erase(v[i]);
    auto it = ml.rbegin();
    cout << *it << "\n";
    ml.insert(v[i]);
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vll vector<ll>
#define vii vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define matrix vector<vll>
#define all(v) v.begin(), v.end()
#define PQ priority_queue
using namespace std;
ll pow(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res *= a;
    b /= 2;
    a *= a;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vii v(n);
  multiset<int> ml;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    ml.insert(v[i]);
  }
  for (int i = 0; i < n; i++) {
    ml.erase(ml.find(v[i]));
    auto it = ml.rbegin();
    cout << *it << "\n";
    ml.insert(v[i]);
  }

  return 0;
}
Problem p02971 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = long long int;

int main() {
  int N;
  cin >> N;
  vi vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  for (int i = 0; i < N; i++) {
    vi v = vec;
    v[i] = -1;
    sort(v.begin(), v.end());
    cout << v[N - 1] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = long long int;

int main() {
  int N;
  cin >> N;
  vi vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  vi v = vec;
  int num = v.size();
  sort(v.begin(), v.end());
  bool r = true;
  if (v[N - 1] == v[N - 2]) {
    r = false;
  }
  vi res(0);
  res.push_back(v[0]);
  for (int i = 1; i < num; i++) {
    if (v[i] != v[i - 1]) {
      res.push_back(v[i]);
    }
  }
  ll k = v[N - 1];
  ll g = res.size();
  if (r == true) {
    for (auto x : vec) {
      if (x == k) {
        cout << res[g - 2] << endl;
      } else {
        cout << res[g - 1] << endl;
      }
    }
  } else {
    for (auto x : vec) {
      cout << res[g - 1] << endl;
    }
  }
}
Problem p02971 (C++)

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

using namespace std;

const int N = 20000;

int main() {
  int n, array[N], max_value1 = -1, max_value2 = -1, max_index = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> array[i];
  }

  for (int i = 0; i < n; i++) {
    if (max_value1 < array[i]) {
      max_value1 = array[i];
      max_index = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == max_index)
      continue;
    if (max_value2 < array[i]) {
      max_value2 = array[i];
    }
  }

  for (int i = 0; i < n; i++) {
    if (i != max_index)
      cout << max_value1 << endl;
    else
      cout << max_value2 << endl;
  }
}

Fixed submission:
#include <iostream>

using namespace std;

const int N = 200000;

int main() {
  int n, array[N], max_value1 = -1, max_value2 = -1, max_index = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> array[i];
  }

  for (int i = 0; i < n; i++) {
    if (max_value1 < array[i]) {
      max_value1 = array[i];
      max_index = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == max_index)
      continue;
    if (max_value2 < array[i]) {
      max_value2 = array[i];
    }
  }

  for (int i = 0; i < n; i++) {
    if (i != max_index)
      cout << max_value1 << endl;
    else
      cout << max_value2 << endl;
  }
}
Problem p02971 (C++)

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

int main() {
  int n;
  cin >> n;
  int max = 0, max_second = 0;
  vector<int> data(n);
  vector<int> dp(200001);
  for (int i = 0; i < n; i++) {
    cin >> data.at(i);
    dp.at(data.at(i))++;
    if (max < data.at(i))
      max = data.at(i);
  }

  for (int i = max - 1;; i--) {
    if (dp.at(i) > 0) {
      max_second = i;
      break;
    }
  }

  if (dp.at(max) > 1) {
    for (int i = 0; i < n; i++) {
      cout << max << endl;
    }
    return 0;
  }

  for (int i = 0; i < n; i++) {
    if (data.at(i) == max) {
      cout << max_second << endl;
    } else {
      cout << max << endl;
    }
  }
}

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

int main() {
  int n;
  cin >> n;
  int max = 0, max_second = 0;
  vector<int> data(n);
  vector<int> dp(200001);
  for (int i = 0; i < n; i++) {
    cin >> data.at(i);
    dp.at(data.at(i))++;
    if (max < data.at(i))
      max = data.at(i);
  }

  for (int i = max - 1; i >= 0; i--) {
    if (dp.at(i) > 0) {
      max_second = i;
      break;
    }
  }

  if (dp.at(max) > 1) {
    for (int i = 0; i < n; i++) {
      cout << max << endl;
    }
    return 0;
  }

  for (int i = 0; i < n; i++) {
    if (data.at(i) == max) {
      cout << max_second << endl;
    } else {
      cout << max << endl;
    }
  }
}
Problem p02971 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int MAX = 0, MAXi;

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);

    if (a.at(i) > MAX) {
      MAX = a.at(i);
      MAXi = i;
    }
  }

  for (int i = 0; i < N; i++) {
    if (i == MAXi) {
      int MAX2 = 0;
      for (int j = 0; i < N; j++) {
        if (j != i)
          MAX2 = max(MAX2, a.at(j));
      }
      cout << MAX2 << endl;
    } else {
      cout << MAX << endl;
    }
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int MAX = 0, MAXi;

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);

    if (a.at(i) > MAX) {
      MAX = a.at(i);
      MAXi = i;
    }
  }

  for (int i = 0; i < N; i++) {
    if (i == MAXi) {
      int MAX2 = 0;
      for (int j = 0; j < N; j++) {
        if (j != i)
          MAX2 = max(MAX2, a.at(j));
      }
      cout << MAX2 << endl;
    } else {
      cout << MAX << endl;
    }
  }
}
Problem p02971 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long ulint;
const int mod = 2019;

int main() {
  int n;
  cin >> n;
  int a[n];
  int maxall = 0;
  int maxnum = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (maxall <= a[i]) {
      maxall = a[i];
      maxnum = i;
    }
    // maxall = max(maxall, a[i]);
  }
  // i == 除外
  for (int i = 0; i < n; i++) {
    int maxtmp = 0;
    if (i < maxnum) {
      cout << maxall << endl;
      continue;
    }

    for (int j = 0; j < n; j++) {
      if (i != j && maxall == a[j]) {
        maxtmp = maxall;
        break;
      }
      if (i != j) {
        maxtmp = max(maxtmp, a[j]);
      }
    }
    cout << maxtmp << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long ulint;
const int mod = 2019;

int main() {
  int n;
  cin >> n;
  int a[n];
  int maxall = 0;
  int maxnum = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (maxall <= a[i]) {
      maxall = a[i];
      maxnum = i;
    }
    // maxall = max(maxall, a[i]);
  }
  // i == 除外
  for (int i = 0; i < n; i++) {
    int maxtmp = 0;
    if (i != maxnum) {
      cout << maxall << endl;
      continue;
    }

    for (int j = 0; j < n; j++) {
      if (i != j && maxall == a[j]) {
        maxtmp = maxall;
        break;
      }
      if (i != j) {
        maxtmp = max(maxtmp, a[j]);
      }
    }
    cout << maxtmp << endl;
  }

  return 0;
}
Problem p02971 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
const int N = 1e5 + 5;
int a[N];
int main() {
  int n, i, max1 = 0, max2 = 0, p;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] > max1) {
      max1 = a[i];
      p = i;
    }
  }

  for (i = 1; i <= n; i++)
    if (i != p && a[i] > max2)
      max2 = a[i];

  for (i = 1; i <= n; i++)
    if (i != p)
      cout << max1 << endl;
    else
      cout << max2 << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
const int N = 2e5 + 5;
int a[N];
int main() {
  int n, i, max1 = 0, max2 = 0, p;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] > max1) {
      max1 = a[i];
      p = i;
    }
  }

  for (i = 1; i <= n; i++)
    if (i != p && a[i] > max2)
      max2 = a[i];

  for (i = 1; i <= n; i++)
    if (i != p)
      cout << max1 << endl;
    else
      cout << max2 << endl;
  return 0;
}
Problem p02971 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int N, A[200000], sA[200000];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sA[i] = A[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (sA[i] < sA[j]) {
        int tmp = sA[i];
        sA[i] = sA[j];
        sA[j] = tmp;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    int j = 0;
    if (A[i] == sA[0])
      cout << sA[1] << endl;
    else
      cout << sA[j] << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int N, A[200000], sA[200000];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sA[i] = A[i];
  }
  sort(sA, sA + N, greater<int>());
  for (int i = 0; i < N; i++) {
    int j = 0;
    if (A[i] == sA[0])
      cout << sA[1] << endl;
    else
      cout << sA[j] << endl;
  }
  return 0;
}
Problem p02971 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 100010, Mod = 998244353;
const double pi = acos(-1.0);
typedef long long int ll;
typedef pair<int, int> pii;
int n, a[N], b[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i], b[i] = a[i];
  sort(b + 1, b + n + 1);
  int mx = b[n], mx2 = b[n - 1];
  for (int i = 1; i <= n; i++)
    if (a[i] != mx)
      cout << mx << endl;
    else
      cout << mx2 << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 200010, Mod = 998244353;
const double pi = acos(-1.0);
typedef long long int ll;
typedef pair<int, int> pii;
int n, a[N], b[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i], b[i] = a[i];
  sort(b + 1, b + n + 1);
  int mx = b[n], mx2 = b[n - 1];
  for (int i = 1; i <= n; i++)
    if (a[i] != mx)
      cout << mx << endl;
    else
      cout << mx2 << endl;
  return 0;
}
Problem p02971 (C++)

Buggy submission (status: Runtime Error):
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void) { return; }
template <typename First, typename... Rest>
void ci(First &first, Rest &...rest) {
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void) {
  cout << "\n";
  return;
}
template <typename First, typename... Rest> void co(First first, Rest... rest) {
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define gcd __gcd
#define lcm(n, m) n *m / gcd(n, m)
#define np next_permutation
#define repi(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size())
#define each(i, n) for (auto &&i : n)
#define so(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数

int main() {
  int N;
  ci(N);
  ve<int> A(N), B(N);
  rep(i, N) {
    ci(A.at(i));
    B.at(i) = A.at(i);
  }
  so(B);
  rep(i, N) {
    int a = 0;
    if (B.at(N - 1) == A.at(i)) {
      a = B.at(N);
    } else {
      a = B.at(N - 1);
    }
    co(a);
  }
}

Fixed submission:
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void) { return; }
template <typename First, typename... Rest>
void ci(First &first, Rest &...rest) {
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void) {
  cout << "\n";
  return;
}
template <typename First, typename... Rest> void co(First first, Rest... rest) {
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define gcd __gcd
#define lcm(n, m) n *m / gcd(n, m)
#define np next_permutation
#define repi(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size())
#define each(i, n) for (auto &&i : n)
#define so(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数

int main() {
  int N;
  ci(N);
  ve<int> A(N), B(N);
  rep(i, N) {
    ci(A.at(i));
    B.at(i) = A.at(i);
  }
  so(B);
  rep(i, N) {
    int a = 0;
    if (B.at(N - 1) == A.at(i)) {
      a = B.at(N - 2);
    } else {
      a = B.at(N - 1);
    }
    co(a);
  }
}
Problem p02971 (C++)

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

int main() {
  int n, a[20005];
  pair<int, int> p[20005];
  cin >> n;
  int max1 = -1, max2 = -1, ind1, ind2;
  for (int i = 0; i < n; i++) {

    cin >> a[i];
    p[i] = make_pair(a[i], i);
  }
  sort(p, p + n);
  max1 = p[n - 1].first;
  max2 = p[n - 2].first;
  ind1 = p[n - 1].second;
  ind2 = p[n - 2].second;
  for (int i = 0; i < n; i++) {
    if (a[i] == max1 && i == ind1)
      cout << max2 << endl;
    else
      cout << max1 << endl;
  }
}


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

int main() {
  int n, a[200005];
  pair<int, int> p[200005];
  cin >> n;
  int max1 = -1, max2 = -1, ind1, ind2;
  for (int i = 0; i < n; i++) {

    cin >> a[i];
    p[i] = make_pair(a[i], i);
  }
  sort(p, p + n);
  max1 = p[n - 1].first;
  max2 = p[n - 2].first;
  ind1 = p[n - 1].second;
  ind2 = p[n - 2].second;
  for (int i = 0; i < n; i++) {
    if (a[i] == max1 && i == ind1)
      cout << max2 << endl;
    else
      cout << max1 << endl;
  }
}
Problem p02971 (C++)

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

int main(int argc, char *argv[]) {
  unsigned int N;
  std::cin >> N;
  std::vector<unsigned int> A(N);
  for (auto &a : A) {
    std::cin >> a;
  }
  unsigned int a;
  for (int i = 0; i < N; ++i) {
    a = A[i];
    A.erase(A.begin() + i);
    std::cout << *std::max_element(A.begin(), A.end()) << std::endl;
    A.insert(A.begin() + i, a);
  }
  return 0;
}

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

int main(int argc, char *argv[]) {
  unsigned int N;
  std::cin >> N;
  std::vector<unsigned int> A(N);
  for (auto &a : A) {
    std::cin >> a;
  }

  auto globalMaxIter = std::max_element(A.begin(), A.end());
  unsigned int globalMax = *globalMaxIter;
  A.erase(globalMaxIter);
  unsigned int secondMax = *std::max_element(A.begin(), A.end());
  A.insert(globalMaxIter, globalMax);
  for (auto &a : A) {
    std::cout << (a == globalMax ? secondMax : globalMax) << std::endl;
  }
  return 0;
}
Problem p02971 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string, int>;
const double PI = acos(-1);

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);

  rep(i, n) {
    vector<int> b = a;
    b.at(i) = -1;
    cout << *max_element(b.begin(), b.end()) << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string, int>;
const double PI = acos(-1);

int main() {
  int n;
  cin >> n;
  vector<int> b(n);
  rep(i, n) cin >> b.at(i);
  vector<int> a = b;
  sort(a.begin(), a.end());
  if (a.at(n - 1) == a.at(n - 2)) {
    rep(i, n) cout << a.at(n - 1) << endl;
  } else {
    rep(i, n) {
      if (b.at(i) == a.at(n - 1))
        cout << a.at(n - 2) << endl;
      else
        cout << a.at(n - 1) << endl;
    }
  }
}
Problem p02971 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cinttypes>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
static const long k10E7 = 1000000007;

int main() {
  long n;
  cin >> n;

  vector<long> an(n);
  for (long &a : an) {
    cin >> a;
  }

  for (long i = 0; i < n; i++) {
    const long ai = an[i];
    an[i] = 0;
    cout << *max_element(an.begin(), an.end()) << endl;
    an[i] = ai;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cinttypes>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
static const long k10E7 = 1000000007;

int main() {
  long n;
  cin >> n;

  vector<long> an(n);
  for (long &a : an) {
    cin >> a;
  }

  auto first_max_it = max_element(an.begin(), an.end());
  size_t first_max_index = distance(an.begin(), first_max_it);

  const long ai_tmp = an[first_max_index];
  an[first_max_index] = 0;
  auto second_max_it = max_element(an.begin(), an.end());
  size_t second_max_index = distance(an.begin(), second_max_it);
  an[first_max_index] = ai_tmp;

  for (size_t i = 0; i < (size_t)n; i++) {
    if (i == first_max_index) {
      cout << an[second_max_index] << endl;
    } else {
      cout << an[first_max_index] << endl;
    }
  }

  return 0;
}
Problem p02971 (C++)

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

using namespace std;

#define INF 1000000007
#define LINF 1000000000000000007

typedef long long i64;
typedef pair<i64, i64> P;

int n, a[101010];

int main() {
  cin >> n;
  i64 ans = 0, ans2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (ans < a[i]) {
      ans2 = ans;
      ans = a[i];
    } else if (ans2 < a[i]) {
      ans2 = a[i];
    }
  }

  for (int i = 0; i < n; i++) {
    if (a[i] == ans) {
      cout << ans2 << endl;
    } else
      cout << ans << endl;
  }

  return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF 1000000000000000007

typedef long long i64;
typedef pair<i64, i64> P;

int n, a[202020];

int main() {
  cin >> n;
  i64 ans = 0, ans2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (ans < a[i]) {
      ans2 = ans;
      ans = a[i];
    } else if (ans2 < a[i]) {
      ans2 = a[i];
    }
  }

  for (int i = 0; i < n; i++) {
    if (a[i] == ans) {
      cout << ans2 << endl;
    } else
      cout << ans << endl;
  }

  return 0;
}
Problem p02971 (C++)

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

using namespace std;
int main() {
  int n, i, ar[i];
  cin >> n;
  int max = 0, smax = 0;

  for (i = 0; i < n; i++) {
    cin >> ar[i];
    if (max < ar[i]) {
      smax = max;
      max = ar[i];
    } else if (ar[i] >= smax) {
      smax = ar[i];
    }
  }
  for (i = 0; i < n; i++) {
    if (ar[i] == max) {
      cout << smax << "\n";
    } else {
      cout << max << "\n";
    }
  }
  return 0;
}

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

using namespace std;
int main() {
  int n, i, ar[200005];
  cin >> n;
  int max = 0, smax = 0;

  for (i = 0; i < n; i++) {
    cin >> ar[i];
    if (max < ar[i]) {
      smax = max;
      max = ar[i];
    } else if (ar[i] >= smax) {
      smax = ar[i];
    }
  }
  for (i = 0; i < n; i++) {
    if (ar[i] == max) {
      cout << smax << "\n";
    } else {
      cout << max << "\n";
    }
  }
  return 0;
}