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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F(i, a, n) for (int i = a; i < n; i++)
#define mod 1000000007
#define pb push_back
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int w = 1;
  // cin>>w;
  while (w--) {
    long long n;
    cin >> n;
    vector<ll> v(n + 1, 0);
    v[0] = 1;
    v[3] = 1;
    v[4] = 1;
    v[5] = 1;
    F(i, 6, n + 1) {
      F(j, 3, i + 1) {
        if (i - j >= 0)
          v[i] = (v[i] % mod + v[i - j] % mod) % mod;
      }
    }
    cout << v[n];
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F(i, a, n) for (int i = a; i < n; i++)
#define mod 1000000007
#define pb push_back
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int w = 1;
  // cin>>w;
  while (w--) {
    long long n;
    cin >> n;
    vector<ll> v(2005, 0);
    v[0] = 1;
    v[3] = 1;
    v[4] = 1;
    v[5] = 1;
    F(i, 6, n + 1) {
      F(j, 3, i + 1) {
        if (i - j >= 0)
          v[i] = (v[i] % mod + v[i - j] % mod) % mod;
      }
    }
    cout << v[n];
  }
  return 0;
}
Problem p02555 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
int main() {
  ll n;
  cin >> n;
  ll dp[n + 1];
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  for (ll i = 4; i <= n; i++) {
    dp[i] = 1;
    for (ll j = 3; j <= i - 3; j++) {
      dp[i] += dp[j];
      dp[i] %= MOD;
    }
  }
  cout << dp[n];
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
int main() {
  ll n;
  cin >> n;
  ll dp[2001];
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  for (ll i = 4; i <= n; i++) {
    dp[i] = 1;
    for (ll j = 3; j <= i - 3; j++) {
      dp[i] += dp[j];
      dp[i] %= MOD;
    }
  }
  cout << dp[n];
}
Problem p02555 (C++)

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

typedef long long ll;
const ll m = 1e9 + 7;

int main(int argc, char **argv) {
  int S;
  std::cin >> S;

  std::vector<ll> A(S + 1, 0);

  A[3] = 1;

  for (int i = 4; i < S + 1; i++) {
    A[i] = A[i - 3] + A[i - 1];
    A[i] %= m;
  }

  std::cout << A[S] << std::endl;
}

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

typedef long long ll;
const ll m = 1e9 + 7;

int main(int argc, char **argv) {
  int S;
  std::cin >> S;

  std::vector<ll> A(2001, 0);

  A[3] = 1;

  for (int i = 4; i < S + 1; i++) {
    A[i] = A[i - 3] + A[i - 1];
    A[i] %= m;
  }

  std::cout << A[S] << std::endl;
}
Problem p02555 (C++)

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

const int mod = 1e9 + 7;
long long int dp[2005];

int main() {
  int s;
  scanf("%d", &s);
  dp[0] = 1;
  dp[1] = dp[2] = 0;
  for (int a = 0; a <= s; a++) {
    for (int b = 3; b <= s; b++) {
      (dp[a + b] += dp[a]) %= mod;
    }
  }
  printf("%lld ", dp[s]);
}


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

const int mod = 1e9 + 7;
long long int dp[2005];

int main() {
  int s;
  scanf("%d", &s);
  dp[0] = 1;
  dp[1] = dp[2] = 0;
  for (int a = 0; a <= s; a++) {
    for (int b = 3; b <= s; b++) {
      if (a + b <= s)
        (dp[a + b] += dp[a]) %= mod;
    }
  }
  printf("%lld ", dp[s]);
}
Problem p02555 (C++)

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

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

  int s;
  const int MOD = 1e9 + 7;
  cin >> s;

  vector<int> dp(s, 0);

  dp[0] = 1;
  for (int i = 3; i <= s; i++)
    for (int j = 3; j <= i; j++)
      dp[i] = (dp[i] + dp[i - j]) % MOD;

  cout << dp[s] << endl;

  return 0;
}


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

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

  int s;
  const int MOD = 1e9 + 7;
  cin >> s;

  vector<int> dp(s + 1, 0);

  dp[0] = 1;
  for (int i = 3; i <= s; i++)
    for (int j = 3; j <= i; j++)
      dp[i] = (dp[i] + dp[i - j]) % MOD;

  cout << dp[s] << endl;

  return 0;
}
Problem p02555 (C++)

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

using namespace std;

#define ll long long int

ll mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll s;
  cin >> s;
  ll dp[s + 1], cum[s + 1];
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  cum[0] = 0;
  cum[1] = 0;
  cum[2] = 0;
  cum[3] = 1;
  for (int i = 4; i <= s; i++) {
    dp[i] = (cum[i - 3] + 1) % mod;
    cum[i] = (cum[i - 1] + dp[i]) % mod;
  }

  cout << dp[s] % mod << endl;
  return 0;
}

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

using namespace std;

#define ll long long int

ll mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll s;
  cin >> s;
  ll dp[s + 2], cum[s + 2];
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  cum[0] = 0;
  cum[1] = 0;
  cum[2] = 0;
  cum[3] = 1;
  for (int i = 4; i <= s; i++) {
    dp[i] = (cum[i - 3] + 1) % mod;
    cum[i] = (cum[i - 1] + dp[i]) % mod;
  }

  cout << dp[s] % mod << endl;
  return 0;
}
Problem p02555 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;
const int MAXN = 20 + 5;
vector<vector<ll>> dp(MAXN, vector<ll>(MAXN, 0));

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  for (int k = 1; k < MAXN; k++) {
    dp[1][k] = k;
  }
  for (int s = 1; s < MAXN; s++) {
    dp[s][1] = 1;
  }
  for (int s = 2; s < MAXN; s++) {
    for (int k = 2; k < MAXN; k++) {
      dp[s][k] = (dp[s][k - 1] + dp[s - 1][k]) % MOD;
    }
  }
  int S;
  cin >> S;
  ll ans = 0;
  for (int i = 1; i < S; i++) {
    ans += dp[max(S - 3 * i, 0)][i];
    if (S - 3 * i == 0)
      ans += 1;
    // cout << i << " " << S - 3*i << " = " << dp[max(S - 3*i, 0)][i] << endl;
    ans %= MOD;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;
const int MAXN = 2000 + 5;
vector<vector<ll>> dp(MAXN, vector<ll>(MAXN, 0));

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  for (int k = 1; k < MAXN; k++) {
    dp[1][k] = k;
  }
  for (int s = 1; s < MAXN; s++) {
    dp[s][1] = 1;
  }
  for (int s = 2; s < MAXN; s++) {
    for (int k = 2; k < MAXN; k++) {
      dp[s][k] = (dp[s][k - 1] + dp[s - 1][k]) % MOD;
    }
  }
  int S;
  cin >> S;
  ll ans = 0;
  for (int i = 1; i < S; i++) {
    ans += dp[max(S - 3 * i, 0)][i];
    if (S - 3 * i == 0)
      ans += 1;
    // cout << i << " " << S - 3*i << " = " << dp[max(S - 3*i, 0)][i] << endl;
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02555 (C++)

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

using namespace std;

#define debug(x, y)                                                            \
  cout << (#x) << " " << (#y) << " is " << (x) << " " << (y) << endl
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i, a, b) for (i = a; i < b; i++)
#define MOD 1000000007
#define mod 998244353
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(), (x).end()

typedef vector<lld> vi;
typedef vector<vector<lld>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<lld, lld>> vpi;
typedef long long LL;

lld dp[2001][2001];

lld solve(lld n, lld l) {
  if (n < 0 || n == 1 || n == 2 || l < 0)
    return 0;
  if ((l == 0 && n != 0) || (n == 0 && l != 0))
    return dp[n][l] = 0;
  if (n == 0 && l == 0) {
    return dp[n][l] = 1;
  }
  lld c = 0;
  if (dp[n][l] != -1)
    return dp[n][l];
  for (lld i = 3; i <= n; i++) {
    c += solve(n - i, l - 1);
    c %= MOD;
  }
  return dp[n][l] = c;
}

int main() {
  fast;
  cin.tie(0);
  lld n;
  cin >> n;
  if (n == 1 || n == 2)
    cout << "0" << endl;
  else {
    memset(dp, -1, sizeof(dp));
    lld cnt = 0;
    for (lld i = 1; i <= (n / 3) + 1; i++) {
      cnt += solve(n, i);
      cnt %= MOD;
    }
    cout << cnt << endl;
  }
}


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

using namespace std;

#define debug(x, y)                                                            \
  cout << (#x) << " " << (#y) << " is " << (x) << " " << (y) << endl
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i, a, b) for (i = a; i < b; i++)
#define MOD 1000000007
#define mod 998244353
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(), (x).end()

typedef vector<lld> vi;
typedef vector<vector<lld>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<lld, lld>> vpi;
typedef long long LL;

lld dp[2001][2001];

lld solve(lld n, lld l) {
  if (n < 0 || n == 1 || n == 2 || l < 0)
    return 0;
  if ((l == 0 && n != 0) || (n == 0 && l != 0))
    return dp[n][l] = 0;
  if (n == 0 && l == 0) {
    return dp[n][l] = 1;
  }
  lld c = 0;
  if (dp[n][l] != -1)
    return dp[n][l];
  c += solve(n - 1, l);
  c %= MOD;
  c += solve(n - 3, l - 1);
  c %= MOD;
  return dp[n][l] = c;
}

int main() {
  fast;
  cin.tie(0);
  lld n;
  cin >> n;
  if (n == 1 || n == 2)
    cout << "0" << endl;
  else {
    memset(dp, -1, sizeof(dp));
    lld cnt = 0;
    for (lld i = 1; i <= (n / 3) + 1; i++) {
      cnt += solve(n, i);
      cnt %= MOD;
    }
    cout << cnt << endl;
  }
}
Problem p02555 (C++)

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

#define sync                                                                   \
  {                                                                            \
    ios_base ::sync_with_stdio(false);                                         \
    cin.tie(NULL);                                                             \
    cout.tie(NULL);                                                            \
  }
#define ll long long int
#define mod 1000000007

void solve() {
  int s;
  cin >> s;

  ll dp[s + 1];

  dp[0] = dp[1] = dp[2] = 0;

  dp[3] = 1;

  for (int i = 4; i <= s; i++) {
    dp[i] = 0;
    for (int j = i - 3; j >= 3; j--) {
      dp[i] += (dp[j]) % mod;
      dp[i] %= mod;
    }
    dp[i] = (dp[i] + 1) % mod;
  }
  cout << dp[s];
}

int main() {
  sync;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}


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

#define sync                                                                   \
  {                                                                            \
    ios_base ::sync_with_stdio(false);                                         \
    cin.tie(NULL);                                                             \
    cout.tie(NULL);                                                            \
  }
#define ll long long int
#define mod 1000000007

void solve() {
  int s;
  cin >> s;

  ll dp[s + 1];

  if (s == 1 or s == 2) {
    cout << 0;
    return;
  }

  else if (s == 3) {
    cout << 1;
    return;
  }

  dp[0] = dp[1] = dp[2] = 0;

  dp[3] = 1;

  for (int i = 4; i <= s; i++) {
    dp[i] = 0;
    for (int j = i - 3; j >= 3; j--) {
      dp[i] += (dp[j]) % mod;
      dp[i] %= mod;
    }
    dp[i] = (dp[i] + 1) % mod;
  }
  cout << dp[s];
}

int main() {
  sync;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
Problem p02555 (C++)

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

using namespace std;

#define ll long long
#define ld long double

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

ll INF = (ll)1e20;
int iINF = (int)1e20;
ll mod = (ll)1e9 + 7;

signed main() {
  ll n;
  cin >> n;
  ll dp[n + 1];
  fill(&dp[0], &dp[0] + n + 1, 0);
  dp[3] = 1;
  for (int i = 4; i <= n; ++i) {
    dp[i] = 1;
    for (int j = 3; j < i; ++j) {
      if (i - j >= 3) {
        dp[i] += dp[j];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n];
}

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

using namespace std;

#define ll long long
#define ld long double

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

ll INF = (ll)1e20;
int iINF = (int)1e20;
ll mod = (ll)1e9 + 7;

signed main() {
  ll n;
  cin >> n;
  vector<ll> dp(n + 100, 0);
  if (n < 3) {
    cout << 0;
    return 0;
  }
  dp[3] = 1;
  for (int i = 4; i <= n; ++i) {
    dp[i] = 1;
    for (int j = 3; j < i; ++j) {
      if (i - j >= 3) {
        dp[i] += dp[j];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n];
}
Problem p02555 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()

using namespace std;

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

vector<ll> dp;
ll ans = 0;
ll mod = 1e9 + 7;
int solve(int v) {
  // cout << v << endl;
  if (dp[v] > 1)
    return dp[v];

  for (int i = 3; v - i >= 0; i++)
    dp[v] = (dp[v] + solve(v - i)) % mod;

  return dp[v];
}

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

  dp.resize(n + 1, 1);
  dp[0] = 0, dp[1] = 0, dp[2] = 0, dp[3] = 1;

  cout << solve(n) % mod << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()

using namespace std;

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

vector<ll> dp;
ll ans = 0;
ll mod = 1e9 + 7;
int solve(int v) {
  // cout << v << endl;
  if (dp[v] > 1)
    return dp[v];

  for (int i = 3; v - i >= 0; i++)
    dp[v] = (dp[v] + solve(v - i)) % mod;

  return dp[v];
}

int main() {
  int n;
  cin >> n;
  if (n < 3)
    return cout << 0 << endl, 0;

  dp.resize(n + 1, 1);
  dp[0] = 0, dp[1] = 0, dp[2] = 0, dp[3] = 1;

  cout << solve(n) % mod << endl;
  return 0;
}
Problem p02555 (C++)

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

int64_t mod = 1000000007;

int64_t f(int n, vector<int64_t> &a) {
  if (a.at(n) != -1)
    return a.at(n);
  else {
    a.at(n) = (f(n - 1, a) + f(n - 3, a));
    a.at(n) %= mod;
    return a.at(n);
  }
}

int main() {
  int s;
  cin >> s;
  vector<int64_t> a(s + 1, -1);
  if (s < 3) {
    cout << 0 << endl;
    return 0;
  }
  a.at(0) = 0, a.at(1) = 0, a.at(2) = 0;
  a.at(3) = 1, a.at(4) = 1, a.at(5) = 1;
  int64_t ans;
  ans = f(s, a);
  cout << ans << endl;
}

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

int64_t mod = 1000000007;

int64_t f(int n, vector<int64_t> &a) {
  if (a.at(n) != -1)
    return a.at(n);
  else {
    a.at(n) = (f(n - 1, a) + f(n - 3, a));
    a.at(n) %= mod;
    return a.at(n);
  }
}

int main() {
  int s;
  cin >> s;
  vector<int64_t> a(s + 1, -1);
  if (s < 3) {
    cout << 0 << endl;
    return 0;
  }
  a.at(0) = 0, a.at(1) = 0, a.at(2) = 0;
  a.at(3) = 1;
  int64_t ans;
  ans = f(s, a);
  cout << ans << endl;
}
Problem p02555 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9 + 7;
ll dp[1000];
int main() {
  int s;
  cin >> s;
  dp[0] = 1;
  for (int i = 3; i <= s; i++) {
    dp[i] = dp[i - 1] + dp[i - 3];
    dp[i] %= MOD;
  }

  cout << dp[s] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9 + 7;
int dp[2050];
int main() {
  int s;
  cin >> s;
  dp[0] = 1;
  for (int i = 3; i <= s; i++) {
    dp[i] = dp[i - 1] + dp[i - 3];
    dp[i] %= MOD;
  }

  cout << dp[s] << endl;
  return 0;
}
Problem p02555 (C++)

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

int main() {
  int mod = 1e9 + 7;
  int n;
  cin >> n;
  long long int dp[n + 1];
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;
  dp[6] = 2;
  for (int i = 7; i <= n; i++)
    dp[i] = (dp[i - 3] * 2 + dp[i - 4] + dp[i - 5]) % mod;
  cout << dp[n];
  return 0;
}

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

int main() {
  int mod = 1e9 + 7;
  int n;
  cin >> n;
  long long int dp[n + 7];
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;
  dp[6] = 2;
  for (int i = 7; i <= n; i++)
    dp[i] = (dp[i - 3] * 2 + dp[i - 4] + dp[i - 5]) % mod;
  cout << dp[n];
  return 0;
}
Problem p02555 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
const int mod = 1e9 + 7;
#define all(x) x.begin(), x.end()
#define endl '\n'
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
int dp[2010];
int solve(int n) {
  if (n == 0)
    return 1;
  if (n == 1 and n == 2)
    return 0;
  if (n >= 3 and n <= 5)
    return 1;
  if (dp[n] != -1)
    return dp[n];
  int ans = 0;
  for (int i = 3; i <= n; i++) {
    if (n - i >= 0) {
      int temp = (solve(n - i)) % mod;
      ans = (ans + temp) % mod;
    }
  }
  return ans;
}
int32_t main() {
  IOS;
  int n;
  cin >> n;
  memset(dp, -1, sizeof dp);
  cout << solve(n) << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
const int mod = 1e9 + 7;
#define all(x) x.begin(), x.end()
#define endl '\n'
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
int dp[2010];
int solve(int n) {
  if (n == 0)
    return 1;
  if (n == 1 and n == 2)
    return 0;
  if (n >= 3 and n <= 5)
    return 1;
  if (dp[n] != -1)
    return dp[n];
  int ans = 0;
  for (int i = 3; i <= n; i++) {
    if (n - i >= 0) {
      int temp = (solve(n - i)) % mod;
      ans = (ans + temp) % mod;
    }
  }
  return dp[n] = ans;
}
int32_t main() {
  IOS;
  int n;
  cin >> n;
  memset(dp, -1, sizeof dp);
  cout << solve(n) << endl;
  return 0;
}
Problem p02555 (C++)

Buggy submission (status: Runtime Error):
// 177

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;
#define NUM 1000000007

int main() {
  int s;
  ll ans = 0;
  cin >> s;
  vector<vector<ll>> v(s - 2, vector<ll>(s - 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v.at(i).at(0) = 1;
  }
  for (int i = 1; i < v.size(); i++) {
    for (int j = 1; j < i + 1; j++) {
      v.at(i).at(j) = (v.at(i - 1).at(j - 1) + v.at(i - 1).at(j)) % NUM;
    }
  }
  for (int i = 1; s >= 3 * i; i++) {
    ans += v.at(s - i * 2 - 1).at(i - 1);
    ans %= NUM;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
// 177

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;
#define NUM 1000000007

int main() {
  int s;
  ll ans = 0;
  cin >> s;
  vector<vector<ll>> v(s, vector<ll>(s + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v.at(i).at(0) = 1;
  }
  for (int i = 1; i < v.size(); i++) {
    for (int j = 1; j < i + 1; j++) {
      v.at(i).at(j) = (v.at(i - 1).at(j - 1) + v.at(i - 1).at(j)) % NUM;
    }
  }
  for (int i = 1; s >= 3 * i; i++) {
    ans += v.at(s - i * 2 - 1).at(i - 1);
    ans %= NUM;
  }
  cout << ans << endl;
  return 0;
}
Problem p02555 (C++)

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

const int MOD = 1000000007;

int main() {
  ll s;
  cin >> s;
  ll dp[s + 1];              // oooo|ooooooo i番目の右に仕切り
  dp[0] = dp[1] = dp[2] = 0; // 数列なし
  dp[3] = dp[4] = dp[5] = 1; // 数列はひとつだけ(仕切りが右端)
  dp[6] = dp[3] + 1;
  // dp[7] = dp[4] + dp[3] = dp[4] + dp[6];
  // dp[8] = dp[5] + dp[4] + dp[3] = dp[5] + dp[7];
  // dp[n] = dp[n-3] + dp[n-1];
  if (s >= 7) {
    for (int i = 7; i <= s; i++) {
      dp[i] = dp[i - 3] + dp[i - 1];
      dp[i] %= MOD;
    }
  }

  cout << dp[s] << endl;
}

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

const int MOD = 1000000007;

int main() {
  ll s;
  cin >> s;
  ll dp[2001];               // oooo|ooooooo i番目の右に仕切り
  dp[0] = dp[1] = dp[2] = 0; // 数列なし
  dp[3] = dp[4] = dp[5] = 1; // 数列はひとつだけ(仕切りが右端)
  dp[6] = dp[3] + 1;
  // dp[7] = dp[4] + dp[3] = dp[4] + dp[6];
  // dp[8] = dp[5] + dp[4] + dp[3] = dp[5] + dp[7];
  // dp[n] = dp[n-3] + dp[n-1];
  if (s >= 7) {
    for (int i = 7; i <= s; i++) {
      dp[i] = dp[i - 3] + dp[i - 1];
      dp[i] %= MOD;
    }
  }

  cout << dp[s] << endl;
}
Problem p02555 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;

#define REP(a, b, c) for (ll a = b; a < (c); a++)
#define PER(a, b, c) for (ll a = b; a >= (c); a--)

inline ll ii() {
  ll x;
  cin >> x;
  return x;
}
inline string is() {
  string x;
  cin >> x;
  return x;
}
inline ld id() {
  ld x;
  cin >> x;
  return x;
}
inline void oi(ll x) { cout << x; }
inline void od(ld x) { cout << fixed << setprecision(10) << x; }
inline void os(string x) { cout << x; }
inline void oe() { cout << endl; }
inline void oie(ll x) {
  oi(x);
  oe();
}
inline void ode(ld x) {
  od(x);
  oe();
}
inline void ose(string x) {
  os(x);
  oe();
}
inline void maxin(ll &a, ll b) { a = max(a, b); }
inline void minin(ll &a, ll b) { a = min(a, b); }

ll m[1123][2123];
ll mod = 1e9 + 7;

int main() {
  ll S = ii();
  ll ret = 0;
  m[0][0] = 1;
  REP(i, 0, 667) {
    REP(k, 0, S) {
      if (m[i][k] == 0)
        continue;
      for (ll j = 3; k + j <= S; j++) {
        if (k + j == S) {
          ret += m[i][k];
          ret %= mod;
        } else {
          m[i + 1][k + j] += m[i][k];
          m[i + 1][k + j] %= mod;
        }
      }
    }
  }
  oie(ret);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;

#define REP(a, b, c) for (ll a = b; a < (c); a++)
#define PER(a, b, c) for (ll a = b; a >= (c); a--)

inline ll ii() {
  ll x;
  cin >> x;
  return x;
}
inline string is() {
  string x;
  cin >> x;
  return x;
}
inline ld id() {
  ld x;
  cin >> x;
  return x;
}
inline void oi(ll x) { cout << x; }
inline void od(ld x) { cout << fixed << setprecision(10) << x; }
inline void os(string x) { cout << x; }
inline void oe() { cout << endl; }
inline void oie(ll x) {
  oi(x);
  oe();
}
inline void ode(ld x) {
  od(x);
  oe();
}
inline void ose(string x) {
  os(x);
  oe();
}
inline void maxin(ll &a, ll b) { a = max(a, b); }
inline void minin(ll &a, ll b) { a = min(a, b); }

ll m[1123][2123];
ll mod = 1e9 + 7;

int main() {
  ll S = ii();
  ll ret = 0;
  m[0][0] = 1;
  REP(i, 0, 667) {
    ll s = 0;
    REP(k, 0, S - 3 + 1) {
      s += m[i][k];
      if (k + 3 == S) {
        ret += s;
        ret %= mod;
      } else {
        m[i + 1][k + 3] += s;
        m[i + 1][k + 3] %= mod;
      }
    }
  }
  oie(ret);

  return 0;
}
Problem p02555 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
// #define _GLIBCXX_DEBUG

const int mod = 1000000007;

int a(vector<int> &dp, int S) {
  if (S <= 2)
    return 0;
  if (S <= 5)
    return 1;
  if (dp[S] >= 0)
    return dp[S];
  int ans = 0;
  for (int i = 3; i < S; i++) {
    ans += a(dp, S - i);
    ans %= mod;
  }
  ans++;
  dp[S] = ans;
  return ans;
}

signed main() {
  int S;
  cin >> S;
  vector<int> dp(S + 1, -1);

  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;

  cout << a(dp, S) << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
// #define _GLIBCXX_DEBUG

const int mod = 1000000007;

int a(vector<int> &dp, int S) {
  if (S <= 2)
    return 0;
  if (S <= 5)
    return 1;
  if (dp[S] >= 0)
    return dp[S];
  int ans = 0;
  for (int i = 3; i < S; i++) {
    ans += a(dp, S - i);
    ans %= mod;
  }
  ans++;
  dp[S] = ans;
  return ans;
}

signed main() {
  int S;
  cin >> S;
  vector<int> dp(S + 1, -1);

  if (S <= 2) {
    cout << 0 << endl;
    return 0;
  }
  if (S <= 5) {
    cout << 1 << endl;
    return 0;
  }

  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;

  cout << a(dp, S) << endl;
}
Problem p02555 (Python)

Buggy submission (status: Runtime Error):
S = int(input())
MOD = 10**9 + 7
A = [0] * (S + 1)
A[0] = 1
A[1] = 0
A[2] = 0

cumsum = 1
for i in range(3, len(A)):
    A[i] = cumsum
    cumsum += A[i - 2]
    cumsum %= MOD
print(A[-1])


Fixed submission:
S = int(input())
if S == 1:
    print(0)
    exit()
MOD = 10**9 + 7
A = [0] * (S + 1)
A[0] = 1
A[1] = 0
A[2] = 0

cumsum = 1
for i in range(3, len(A)):
    A[i] = cumsum
    cumsum += A[i - 2]
    cumsum %= MOD
print(A[-1])
Problem p02555 (C++)

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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 100005
#define MOD 1000000007
#define fast                                                                   \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pi 3.14159265358979323846
#define Q                                                                      \
  ll _;                                                                        \
  cin >> _;                                                                    \
  while (_--)
#define endl "\n"
#define flush fflush(stdout);

int main() {

  fast

      ll i,
      j, n;
  cin >> n;
  ll dp[n + 1];
  for (i = 0; i <= n; i++) {
    dp[i] = 0;
  }
  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;

  for (i = 6; i <= n; i++) {
    for (j = 0; j <= i - 3; j++) {
      dp[i] = (dp[j] % MOD) + (dp[i] % MOD);
      dp[i] = dp[i] % MOD;
    }
  }
  ll ans = dp[n] % MOD;
  cout << ans % MOD << endl;
}

//    cout << fixed << setprecision(12);


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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 100005
#define MOD 1000000007
#define fast                                                                   \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pi 3.14159265358979323846
#define Q                                                                      \
  ll _;                                                                        \
  cin >> _;                                                                    \
  while (_--)
#define endl "\n"
#define flush fflush(stdout);

int main() {

  fast

      ll i,
      j, n;
  cin >> n;
  ll dp[2001];
  for (i = 0; i <= n; i++) {
    dp[i] = 0;
  }
  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;

  for (i = 6; i <= n; i++) {
    for (j = 0; j <= i - 3; j++) {
      dp[i] = (dp[j] % MOD) + (dp[i] % MOD);
      dp[i] = dp[i] % MOD;
    }
  }
  ll ans = dp[n] % MOD;
  cout << ans % MOD << endl;
}

//    cout << fixed << setprecision(12);
Problem p02555 (Python)

Buggy submission (status: Runtime Error):
S = int(input())

if S < 3:
    print(0)
    exit()

x = [0] * (S + 1)
x[3] = x[4] = x[5] = 1
for i in range(6, S + 1):
    x[i] += 1
    for j in range(3, i - 3 + 1):
        x[i] += x[i - j]

print(x[S] % (10**9 + 7))


Fixed submission:
S = int(input())

if S < 3:
    print(0)
    exit()

if S < 6:
    print(1)
    exit()

x = [0] * (S + 1)
x[3] = x[4] = x[5] = 1
for i in range(6, S + 1):
    x[i] += 1
    for j in range(3, i - 3 + 1):
        x[i] += x[i - j]

print(x[S] % (10**9 + 7))
Problem p02555 (C++)

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

struct listnode {
  int val;
  listnode *next;
};
vector<int> func(vector<int> a, vector<int> l, int sum) {
  vector<int> k, val;
  for (int i = 0; i < l.size(); i++)
    if (l[i] == 0) {
      k.push_back(i);
      val.push_back(a[i]);
    }
  if (sum < 0)
    return a;
  else {
    sort(val.rbegin(), val.rend());
    for (int i = 0; i < k.size(); i++)
      a[k[i]] = val[i];
  }
  return a;
}

int32_t main() {
  int m = 1000000007;

  int n;
  cin >> n;
  int dp[2001];
  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;
  dp[6] = 2;
  dp[7] = 3;
  for (int i = 8; i <= n + 1; i++)
    dp[i] = (dp[i - 3] + dp[i - 1]) % m;
  cout << dp[n] % m << endl;
  return 0;
}

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

struct listnode {
  int val;
  listnode *next;
};
vector<int> func(vector<int> a, vector<int> l, int sum) {
  vector<int> k, val;
  for (int i = 0; i < l.size(); i++)
    if (l[i] == 0) {
      k.push_back(i);
      val.push_back(a[i]);
    }
  if (sum < 0)
    return a;
  else {
    sort(val.rbegin(), val.rend());
    for (int i = 0; i < k.size(); i++)
      a[k[i]] = val[i];
  }
  return a;
}

int32_t main() {
  int m = 1000000007;

  int n;
  cin >> n;
  int dp[2001];
  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;
  dp[6] = 2;
  dp[7] = 3;
  for (int i = 8; i < n + 1; i++)
    dp[i] = (dp[i - 3] + dp[i - 1]) % m;
  cout << dp[n] % m << endl;
  return 0;
}
Problem p02555 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
const int mod = 1e9 + 7;
ll c[2010][2010];
void init(int n) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      if (!j)
        c[i][j] = 1;
      else
        c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0), cin.tie(0);
  int s;
  cin >> s;
  init(2005);
  ll ans = 0;
  for (int i = 1; i * 2 <= s; i++) {
    ans = (ans + c[s - 2 * i - 1][i - 1]) % mod;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
const int mod = 1e9 + 7;
ll c[2010][2010];
void init(int n) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      if (!j)
        c[i][j] = 1;
      else
        c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0), cin.tie(0);
  int s;
  cin >> s;
  init(2005);
  ll ans = 0;
  for (int i = 1; i * 2 <= s - 1; i++) {
    ans = (ans + c[s - 2 * i - 1][i - 1]) % mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02556 (C++)

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

int main(void) {
  static double p[100000][2];
  double min[32], max[32];
  int n;
  int i, j, k;
  double dat;
  double ans;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    for (j = 0; j < 2; j++) {
      scanf("%lf", &p[i][j]);
    }
  }

  ans = 0;
  for (i = 0; i < 1 << 2; i++) {
    for (j = 0; j < n; j++) {
      dat = 0;
      for (k = 0; k < 2; k++) {
        if ((i >> k) & 1) {
          dat += p[j][k];
        } else {
          dat -= p[j][k];
        }
      }
      if (j == 0) {
        min[i] = max[i] = dat;
      } else {
        if (dat < min[i]) {
          min[i] = dat;
        }
        if (dat > max[i]) {
          max[i] = dat;
        }
      }
    }
    ans = ans > max[i] - min[i] ? ans : max[i] - min[i];
  }

  printf("%.0f\n", ans);

  return (0);
}

Fixed submission:
#include <stdio.h>

int main(void) {
  static double p[220000][2];
  double min[32], max[32];
  int n;
  int i, j, k;
  double dat;
  double ans;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    for (j = 0; j < 2; j++) {
      scanf("%lf", &p[i][j]);
    }
  }

  ans = 0;
  for (i = 0; i < 1 << 2; i++) {
    for (j = 0; j < n; j++) {
      dat = 0;
      for (k = 0; k < 2; k++) {
        if ((i >> k) & 1) {
          dat += p[j][k];
        } else {
          dat -= p[j][k];
        }
      }
      if (j == 0) {
        min[i] = max[i] = dat;
      } else {
        if (dat < min[i]) {
          min[i] = dat;
        }
        if (dat > max[i]) {
          max[i] = dat;
        }
      }
    }
    ans = ans > max[i] - min[i] ? ans : max[i] - min[i];
  }

  printf("%.0f\n", ans);

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v1, v2;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v1.push_back(x + y);
    v2.push_back(x - y);
  }
  sort(v1.begin(), v2.end());
  sort(v2.begin(), v2.end());
  cout << max(v1[n - 1] - v1[0], v2[n - 1] - v2[0]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v1, v2;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v1.push_back(x + y);
    v2.push_back(x - y);
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  cout << max(v1[n - 1] - v1[0], v2[n - 1] - v2[0]);
  return 0;
}
Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define inf 1e200
typedef long long ll;
ll a[100001][2];
ll n;
ll GetManhattan(ll p[][2], ll n, ll dem) {
  ll ans = 0, Min, Max;
  ll i, j, k;
  for (i = 0; i < (1 << (dem)); i++) { // 用二进制形式遍历所有可能的运算情况
    Min = inf, Max = -inf;
    for (j = 0; j < n; j++) { // 遍历每一个点
      ll sum = 0;
      for (k = 0; k < 2; k++) { // 因为是五维的，所以有4个运算符
        // 提取当前运算符
        ll t = i & 1 << k; // 1为+，0为-
        if (t)
          sum += p[j][k];
        else
          sum -= p[j][k];
      }
      if (sum > Max)
        Max = sum;
      if (sum < Min)
        Min = sum;
    }
    if (Max - Min > ans)
      ans = Max - Min;
  }
  return ans;
}
#pragma warning(disable : 4996)
int main() {
  scanf("%d", &n);
  {
    for (ll i = 0; i < n; i++)
      for (ll j = 0; j < 2; j++)
        scanf("%lld", &a[i][j]);
    ll ans = GetManhattan(a, n, 2);
    printf("%lld\n", ans);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define inf 1e200
typedef long long ll;
ll a[200003][2];
ll n;
ll GetManhattan(ll p[][2], ll n, ll dem) {
  ll ans = 0, Min, Max;
  ll i, j, k;
  for (i = 0; i < (1 << (dem)); i++) { // 用二进制形式遍历所有可能的运算情况
    Min = inf, Max = -inf;
    for (j = 0; j < n; j++) { // 遍历每一个点
      ll sum = 0;
      for (k = 0; k < 2; k++) { // 因为是五维的，所以有4个运算符
        // 提取当前运算符
        ll t = i & 1 << k; // 1为+，0为-
        if (t)
          sum += p[j][k];
        else
          sum -= p[j][k];
      }
      if (sum > Max)
        Max = sum;
      if (sum < Min)
        Min = sum;
    }
    if (Max - Min > ans)
      ans = Max - Min;
  }
  return ans;
}
#pragma warning(disable : 4996)
int main() {
  scanf("%d", &n);
  {
    for (ll i = 0; i < n; i++)
      for (ll j = 0; j < 2; j++)
        scanf("%lld", &a[i][j]);
    ll ans = GetManhattan(a, n, 2);
    printf("%lld\n", ans);
  }
  return 0;
}
Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include <map>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define N 60060
#define ll long long
using namespace std;

map<ll, int> mp[33];
typedef map<ll, int>::iterator iter;
int seq[N][5];
int n, m;
void del(int pos, int val) {
  iter t1 = mp[pos].find(val);
  t1->second--;
  if (t1->second == 0)
    mp[pos].erase(t1);
  return;
}
int mm;
int myabs(int x) { return x < 0 ? -x : x; }
ll get_ans() {
  ll res = 0;
  for (int i = 0; i < mm; i++) {
    iter l = mp[i].begin();
    iter r = mp[i].end();
    r--;
    ll tmp = myabs((l->first) - (r->first));
    if (tmp > res)
      res = tmp;
  }
  return res;
}
void dfs(int deep, int val, int root, int pos, int id) {
  if (deep >= m) {
    if (id == 0) {
      mp[root][val]++;
    } else {
      del(root, val);
    }
    return;
  }
  dfs(deep + 1, val + seq[pos][deep], root * 2, pos, id);
  dfs(deep + 1, val - seq[pos][deep], root * 2 + 1, pos, id);
  return;
}
signed main() {
  scanf("%d", &n);
  m = 2;
  mm = 1 << m;
  for (int i = 0; i < mm; i++)
    mp[i].clear();

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++)
      scanf("%d", &seq[i][j]);
    dfs(0, 0, 0, i, 0);
    //  puts("d");
  }
  printf("%lld\n", get_ans());
}

Fixed submission:
#include <map>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define N 200060
#define ll long long
using namespace std;

map<ll, int> mp[33];
typedef map<ll, int>::iterator iter;
int seq[N][5];
int n, m;
void del(int pos, int val) {
  iter t1 = mp[pos].find(val);
  t1->second--;
  if (t1->second == 0)
    mp[pos].erase(t1);
  return;
}
int mm;
int myabs(int x) { return x < 0 ? -x : x; }
ll get_ans() {
  ll res = 0;
  for (int i = 0; i < mm; i++) {
    iter l = mp[i].begin();
    iter r = mp[i].end();
    r--;
    ll tmp = myabs((l->first) - (r->first));
    if (tmp > res)
      res = tmp;
  }
  return res;
}
void dfs(int deep, int val, int root, int pos, int id) {
  if (deep >= m) {
    if (id == 0) {
      mp[root][val]++;
    } else {
      del(root, val);
    }
    return;
  }
  dfs(deep + 1, val + seq[pos][deep], root * 2, pos, id);
  dfs(deep + 1, val - seq[pos][deep], root * 2 + 1, pos, id);
  return;
}
signed main() {
  scanf("%d", &n);
  m = 2;
  mm = 1 << m;
  for (int i = 0; i < mm; i++)
    mp[i].clear();

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++)
      scanf("%d", &seq[i][j]);
    dfs(0, 0, 0, i, 0);
    //  puts("d");
  }
  printf("%lld\n", get_ans());
}
Problem p02556 (C++)

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

using namespace std;
const int M = 2e4 + 5;
int a[M], b[M];
int n, ans = 0;
int main() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    a[i] = x + y;
    b[i] = y - x;
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  ans = max(a[n] - a[1], b[n] - b[1]);
  printf("%d\n", ans);
  return 0;
}

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

using namespace std;
const int M = 2e5 + 5;
int a[M], b[M];
int n, ans = 0;
int main() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    a[i] = x + y;
    b[i] = y - x;
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  ans = max(a[n] - a[1], b[n] - b[1]);
  printf("%d\n", ans);
  return 0;
}
Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
using namespace std;

const int N = (int)(1e5 + 500);

int x[N], y[N];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

#ifndef _LOCAL
#endif // _LOCAL

  int n;
  int mx1, mx2, mx3, mx4;

  mx1 = mx2 = mx3 = mx4 = -2e9;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
    mx1 = max(mx1, -x[i] - y[i]);
    mx2 = max(mx2, -x[i] + y[i]);
    mx3 = max(mx3, x[i] - y[i]);
    mx4 = max(mx4, x[i] + y[i]);
  }

  int ans = -2e9;
  for (int i = 0; i < n; ++i) {
    ans = max(ans, x[i] + y[i] + mx1);
    ans = max(ans, x[i] - y[i] + mx2);
    ans = max(ans, -x[i] + y[i] + mx3);
    ans = max(ans, -x[i] - y[i] + mx4);
  }

  cout << ans << "\n";

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
using namespace std;

const int N = (int)(2e5 + 500);

int x[N], y[N];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

#ifndef _LOCAL
#endif // _LOCAL

  int n;
  int mx1, mx2, mx3, mx4;

  mx1 = mx2 = mx3 = mx4 = -2e9;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
    mx1 = max(mx1, -x[i] - y[i]);
    mx2 = max(mx2, -x[i] + y[i]);
    mx3 = max(mx3, x[i] - y[i]);
    mx4 = max(mx4, x[i] + y[i]);
  }

  int ans = -2e9;
  for (int i = 0; i < n; ++i) {
    ans = max(ans, x[i] + y[i] + mx1);
    ans = max(ans, x[i] - y[i] + mx2);
    ans = max(ans, -x[i] + y[i] + mx3);
    ans = max(ans, -x[i] - y[i] + mx4);
  }

  cout << ans << "\n";

  return 0;
}
Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define re register
#define ls (o << 1)
#define rs (o << 1 | 1)
#define pb push_back
const double PI = acos(-1.0);
const int M = 1e5 + 7;
/*
int head[M],cnt=1;
void init(int n){cnt=1;for(int i=0;i<=n;i++)head[i]=0;}
struct EDGE{int to,nxt,w;}ee[M*2];
void add(int x,int y,int
w){ee[++cnt].nxt=head[x],ee[cnt].w=w,ee[cnt].to=y,head[x]=cnt;}
*/
int x[M], y[M];
int p[4][M];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i];
    p[0][i] = x[i] + y[i];
    p[1][i] = -x[i] + y[i];
    p[2][i] = x[i] - y[i];
    p[3][i] = -x[i] - y[i];
  }
  for (int i = 0; i < 4; i++)
    sort(p[i] + 1, p[i] + 1 + n);
  int mx = 0;
  for (int i = 0; i < 4; i++) {
    mx = max(mx, p[i][n] - p[i][1]);
    // cout<<i<<"  "<<p[i][n]<<"  "<<p[i][1]<<endl;
  }
  cout << mx << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define re register
#define ls (o << 1)
#define rs (o << 1 | 1)
#define pb push_back
const double PI = acos(-1.0);
const int M = 2e5 + 7;
/*
int head[M],cnt=1;
void init(int n){cnt=1;for(int i=0;i<=n;i++)head[i]=0;}
struct EDGE{int to,nxt,w;}ee[M*2];
void add(int x,int y,int
w){ee[++cnt].nxt=head[x],ee[cnt].w=w,ee[cnt].to=y,head[x]=cnt;}
*/
int x[M], y[M];
int p[4][M];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i];
    p[0][i] = x[i] + y[i];
    p[1][i] = -x[i] + y[i];
    p[2][i] = x[i] - y[i];
    p[3][i] = -x[i] - y[i];
  }
  for (int i = 0; i < 4; i++)
    sort(p[i] + 1, p[i] + 1 + n);
  int mx = 0;
  for (int i = 0; i < 4; i++) {
    mx = max(mx, p[i][n] - p[i][1]);
    // cout<<i<<"  "<<p[i][n]<<"  "<<p[i][1]<<endl;
  }
  cout << mx << endl;
  return 0;
}
Problem p02556 (C++)

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

// mannhattan distance => 45 degree rotation
// max( abs(x1-x2) + abs(y1-y2) )
// abs(x1-x2) = max( x1-x2, x2-x1)
// =>  max( abs(x1-x2) + abs(y1-y2) ) = max( x1-x2+y1-y2, x1-x2+y2-y1,
// x2-x1+y1-y2, x2-x1+y2-y1 ) X = x+y, Y = x-y max( abs(x1-x2) + abs(y1-y2) ) =
// max( X1-X2, Y1-Y2, Y2-Y1, X2-X1 ) = max( abs(X1-X2), abs(Y1-Y2) ) //

int main() {
  int N;
  cin >> N;
  vector<int> x45(N), y45(N);
  rep(i, N) {
    int x, y;
    cin >> x >> y;
    x45[i] = x + y;
    y45[i] = x - y;
  }
  sort(x45.begin(), x45.end());
  sort(x45.begin(), y45.end());
  cout << max(abs(x45[N - 1] - x45[0]), abs(y45[N - 1] - y45[0]));
  return 0;
}

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

// mannhattan distance => 45 degree rotation
// max( abs(x1-x2) + abs(y1-y2) )
// abs(x1-x2) = max( x1-x2, x2-x1)
// =>  max( abs(x1-x2) + abs(y1-y2) ) = max( x1-x2+y1-y2, x1-x2+y2-y1,
// x2-x1+y1-y2, x2-x1+y2-y1 ) X = x+y, Y = x-y max( abs(x1-x2) + abs(y1-y2) ) =
// max( X1-X2, Y1-Y2, Y2-Y1, X2-X1 ) = max( abs(X1-X2), abs(Y1-Y2) ) //

int main() {
  int N;
  cin >> N;
  vector<int> x45(N), y45(N);
  rep(i, N) {
    int x, y;
    cin >> x >> y;
    x45[i] = x + y;
    y45[i] = x - y;
  }
  sort(x45.begin(), x45.end());
  sort(y45.begin(), y45.end());
  cout << max(abs(x45[N - 1] - x45[0]), abs(y45[N - 1] - y45[0]));
  return 0;
}
Problem p02556 (C++)

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

#define rep(ver, n) rep2(ver, 0, n)
#define rep2(ver, m, n) for (int ver = m; ver < (n); ver++)
#define loop while (true)
#define dup(x, y) (((x) + (y)-1) / (y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr << #x << ": " << x << "\n"
#define debug2(x, y)                                                           \
  std::cerr << #x << ": " << x << ", " << #y << ": " << y << "\n"
#define debug3(x, y, z)                                                        \
  std::cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z        \
            << ": " << z << "\n"

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

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

ll n, x[30000] = {}, y[300000] = {}, sum1[300000] = {}, sum2[300000] = {};

int main() {
  scanf("%d", &n);
  rep(i, n) {
    int tx, ty;
    scanf("%d %d", &tx, &ty);
    x[i] = tx;
    y[i] = ty;
    sum1[i] = tx + ty;
    sum2[i] = tx - ty;
  }

  sort(sum1, sum1 + n);
  sort(sum2, sum2 + n);
  cout << max(abs(sum1[n - 1] - sum1[0]), abs(sum2[n - 1] - sum2[0]));

  return 0;
}


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

#define rep(ver, n) rep2(ver, 0, n)
#define rep2(ver, m, n) for (int ver = m; ver < (n); ver++)
#define loop while (true)
#define dup(x, y) (((x) + (y)-1) / (y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr << #x << ": " << x << "\n"
#define debug2(x, y)                                                           \
  std::cerr << #x << ": " << x << ", " << #y << ": " << y << "\n"
#define debug3(x, y, z)                                                        \
  std::cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z        \
            << ": " << z << "\n"

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

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

ll n, x[300000] = {}, y[300000] = {}, sum1[300000] = {}, sum2[300000] = {};

int main() {
  scanf("%d", &n);
  rep(i, n) {
    int tx, ty;
    scanf("%d %d", &tx, &ty);
    x[i] = tx;
    y[i] = ty;
    sum1[i] = tx + ty;
    sum2[i] = tx - ty;
  }

  sort(sum1, sum1 + n);
  sort(sum2, sum2 + n);
  cout << max(abs(sum1[n - 1] - sum1[0]), abs(sum2[n - 1] - sum2[0]));

  return 0;
}