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

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

int ans = 0;
void cnt(int n, string s, char add) {
  int a, b, c;
  a = b = c = 0;
  s += add;

  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '3')
      a++;
    else if (s[i] == '5')
      b++;
    else if (s[i] == '7')
      c++;
  }
  if (a && b && c)
    ans++;
  int ab = stoi(s);

  if (ab * 10 + 3 <= n)
    cnt(n, s, '3');
  if (ab * 10 + 5 <= n)
    cnt(n, s, '5');
  if (ab * 10 + 7 <= n)
    cnt(n, s, '7');
}

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

  cnt(n, s, '3');
  cnt(n, s, '5');
  cnt(n, s, '7');

  cout << ans << endl;

  return 0;
}


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

int ans = 0;
void cnt(int n, string s, char add) {
  int a, b, c;
  a = b = c = 0;
  s += add;

  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '3')
      a++;
    else if (s[i] == '5')
      b++;
    else if (s[i] == '7')
      c++;
  }
  if (a && b && c)
    ans++;
  double ab = stoi(s);

  if (ab * 10 + 3 <= n)
    cnt(n, s, '3');
  if (ab * 10 + 5 <= n)
    cnt(n, s, '5');
  if (ab * 10 + 7 <= n)
    cnt(n, s, '7');
}

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

  cnt(n, s, '3');
  cnt(n, s, '5');
  cnt(n, s, '7');

  cout << ans << endl;

  return 0;
}
Problem p03212 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1e9 + 7;

int main() {

  int n;
  cin >> n;
  n = min(n, 777777753);
  int cnt = 0;

  for (int i = 357; i <= n; i++) {
    bool is_used[10] = {};
    int t = i;
    bool flag = true;
    while (t > 0) {
      int r = t % 10;
      if (r != 3 && r != 5 && r != 7) {
        flag = false;
        break;
      }
      is_used[r] = true;
      t /= 10;
    }
    if (!flag) {
      continue;
    }
    if (is_used[3] && is_used[5] && is_used[7]) {
      cnt++;
    }
    if (i == 377777775) {
      i = 533333337 - 1;
    }
  }

  cout << cnt << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1e9 + 7;

int main() {

  int n;
  cin >> n;
  n = min(n, 777777753);
  int cnt = 0;

  for (int i = 357; i <= n; i++) {
    bool is_used[10] = {};
    int t = i;
    bool flag = true;
    while (t > 0) {
      int r = t % 10;
      if (r != 3 && r != 5 && r != 7) {
        flag = false;
        break;
      }
      is_used[r] = true;
      t /= 10;
    }
    if (!flag) {
      continue;
    }
    if (is_used[3] && is_used[5] && is_used[7]) {
      cnt++;
    }
    if (i == 377777775) {
      i = 533333337 - 1;
    }
    if (i == 77777753) {
      i = 333333357 - 1;
    }
    if (i == 577777773) {
      i = 733333335 - 1;
    }
  }

  cout << cnt << endl;

  return 0;
}
Problem p03213 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

map<ll, ll> prime_decomposition(ll n) {
  map<ll, ll> mp;
  FOR(i, 2, n + 1) {
    ll t = i;
    for (ll p = 2; p * p <= t; p++) {
      if (t % p != 0)
        continue;
      ll cnt = 0;
      while (t % p == 0) {
        cnt++;
        t /= p;
      }
      mp[p] += cnt;
    }
    if (t != 1)
      mp[t] += 1;
  }

  return mp;
}

int main() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  map<ll, ll> mp = prime_decomposition(n);
  // for (auto& x : mp) {
  //   cout << x.first << " " << x.second << endl;
  // }
  ll m = SZ(mp);
  vector<vector<ll>> dp(m + 1, vector<ll>(75, 0));
  dp[0][1] = 1;
  ll i = 0;
  for (auto &x : mp) {
    FOR(j, 1, 76) {
      REP(k, x.second + 1) {
        ll nj = (k + 1) * j;
        if (nj > 75) {
          continue;
        }
        dp[i + 1][nj] += dp[i][j];
      }
    }
    i++;
  }
  // REP(i, m + 1) {
  //   REP(j, 76) {
  //     if (dp[i][j]) {
  //       DUMP(i);
  //       DUMP(j);
  //       DUMP(dp[i][j]);
  //     }
  //   }
  // }
  cout << dp[m][75] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

map<ll, ll> prime_decomposition(ll n) {
  map<ll, ll> mp;
  FOR(i, 2, n + 1) {
    ll t = i;
    for (ll p = 2; p * p <= t; p++) {
      if (t % p != 0)
        continue;
      ll cnt = 0;
      while (t % p == 0) {
        cnt++;
        t /= p;
      }
      mp[p] += cnt;
    }
    if (t != 1)
      mp[t] += 1;
  }

  return mp;
}

int main() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  map<ll, ll> mp = prime_decomposition(n);
  // for (auto& x : mp) {
  //   cout << x.first << " " << x.second << endl;
  // }
  ll m = SZ(mp);
  vector<vector<ll>> dp(m + 1, vector<ll>(76, 0));
  dp[0][1] = 1;
  ll i = 0;
  for (auto &x : mp) {
    FOR(j, 1, 76) {
      REP(k, x.second + 1) {
        ll nj = (k + 1) * j;
        if (nj > 75) {
          continue;
        }
        dp[i + 1][nj] += dp[i][j];
      }
    }
    i++;
  }
  // REP(i, m + 1) {
  //   REP(j, 76) {
  //     if (dp[i][j]) {
  //       DUMP(i);
  //       DUMP(j);
  //       DUMP(dp[i][j]);
  //     }
  //   }
  // }
  cout << dp[m][75] << endl;
}
Problem p03213 (C++)

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

void primes(long N, vector<long> &p) {
  long i = 2;
  while (N != 1) {
    if (0 == N % i) {
      N /= i;
      p.at(i)++;
    } else
      i++;
  }
  return;
}

long comb(long N, long P) {
  long S = 1;
  for (long i = 1; i <= P; i++) {
    S *= N;
    S /= i;
    N--;
  }
  return S;
}
/*
long    perm(long N, long P) {
        long S=1;
        for (long i=1; i<=P; i++) {
                S *= N;
                N--;
        }
        return S;
}
*/
long NofP(long N, vector<long> &p) {
  N--;
  long S = 0;
  for (long i = 0; i < p.size(); i++) {
    if (p.at(i) >= N)
      S++;
  }
  return S;
}

int main() {
  long N = 100;
  cin >> N;
  vector<long> p(N, 0);
  for (long i = 2; i <= N; i++) {
    primes(i, p);
  }
  long S = 0;
  S += comb(NofP(75, p), 1);
  S += comb(NofP(25, p), 1) * comb(NofP(3, p) - 1, 1);
  S += comb(NofP(15, p), 1) * comb(NofP(5, p) - 1, 1);
  S += comb(NofP(5, p), 2) * comb(NofP(3, p) - 2, 1);
  cout << S << endl;
  return 0;
}

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

void primes(long N, vector<long> &p) {
  long i = 2;
  while (N != 1) {
    if (0 == N % i) {
      N /= i;
      p.at(i)++;
    } else
      i++;
  }
  return;
}

long comb(long N, long P) {
  long S = 1;
  for (long i = 1; i <= P; i++) {
    S *= N;
    S /= i;
    N--;
  }
  return S;
}
/*
long    perm(long N, long P) {
        long S=1;
        for (long i=1; i<=P; i++) {
                S *= N;
                N--;
        }
        return S;
}
*/
long NofP(long N, vector<long> &p) {
  N--;
  long S = 0;
  for (long i = 0; i < p.size(); i++) {
    if (p.at(i) >= N)
      S++;
  }
  return S;
}

int main() {
  long N = 100;
  cin >> N;
  vector<long> p(N + 1, 0);
  for (long i = 2; i <= N; i++) {
    primes(i, p);
  }
  long S = 0;
  S += comb(NofP(75, p), 1);
  S += comb(NofP(25, p), 1) * comb(NofP(3, p) - 1, 1);
  S += comb(NofP(15, p), 1) * comb(NofP(5, p) - 1, 1);
  S += comb(NofP(5, p), 2) * comb(NofP(3, p) - 2, 1);
  cout << S << endl;
  return 0;
}
Problem p03213 (C++)

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

long kaijo(long n) {
  long ret = 1;
  for (int i = 1; i <= n; i++) {
    ret *= i;
  }
  return ret;
}

long com(long n, long r) {
  long ans = kaijo(n) / kaijo(r) / kaijo(n - r);
  return ans;
}

int main() {
  int N;

  cin >> N;
  vector<long> a(N);

  if (N <= 9) {
    cout << 0 << endl;
    return 0;
  }

  for (int i = 2; i <= N; i++) {
    int m = i;
    for (int j = 2; j <= sqrt(i); j++) {
      while (m % j == 0) {
        a[j]++;
        m /= j;
      }
    }
    if (m > 1)
      a[m]++;
  }
  for (int i = 1; i <= N; i++) {
    // cout<<a[i]<<endl;
  }
  int f4 = 0, f2 = 0, f74 = 0, f24 = 0, f14 = 0;
  for (int i = 0; i <= N; i++) {
    if (a[i] >= 74)
      f74++;
    if (a[i] >= 24)
      f24++;
    if (a[i] >= 14)
      f14++;
    if (a[i] >= 4)
      f4++;
    if (a[i] < 4 && a[i] >= 2)
      f2++;
  }

  long ans = 0;

  // 1*75
  ans += f74;

  // 3*25
  ans += f24 * (f4 + f2 - 1);

  // 5*15
  ans += f14 * (f4 - 1);

  // 3*5*5
  if (f4 >= 3)
    ans += f4 * com(f4 - 1, 2);
  ans += f2 * com(f4, 2);

  cout << ans << endl;
}


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

long kaijo(long n) {
  long ret = 1;
  for (int i = 1; i <= n; i++) {
    ret *= i;
  }
  return ret;
}

long com(long n, long r) {
  long ans = kaijo(n) / kaijo(r) / kaijo(n - r);
  return ans;
}

int main() {
  int N;

  cin >> N;
  vector<long> a(100);

  if (N <= 9) {
    cout << 0 << endl;
    return 0;
  }

  for (int i = 2; i <= N; i++) {
    int m = i;
    for (int j = 2; j <= sqrt(i); j++) {
      while (m % j == 0) {
        a[j]++;
        m /= j;
      }
    }
    if (m > 1)
      a[m]++;
  }
  for (int i = 1; i <= N; i++) {
    // cout<<a[i]<<endl;
  }
  int f4 = 0, f2 = 0, f74 = 0, f24 = 0, f14 = 0;
  for (int i = 0; i <= N; i++) {
    if (a[i] >= 74)
      f74++;
    if (a[i] >= 24)
      f24++;
    if (a[i] >= 14)
      f14++;
    if (a[i] >= 4)
      f4++;
    if (a[i] < 4 && a[i] >= 2)
      f2++;
  }

  long ans = 0;

  // 1*75
  ans += f74;

  // 3*25
  ans += f24 * (f4 + f2 - 1);

  // 5*15
  ans += f14 * (f4 - 1);

  // 3*5*5
  if (f4 >= 3)
    ans += f4 * com(f4 - 1, 2);
  ans += f2 * com(f4, 2);

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

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

using namespace std;
using ll = long long;

map<int, int> Map;
template <class T> void fact(T n) {
  for (T i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      Map[i]++;
      n /= i;
    }
  }
  if (n == 1)
    return;
  Map[n]++;
}

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    fact(i);
  int res = 0;
  vector<int> num;
  for (auto i : Map)
    num.push_back(i.second);
  int m = num.size();

  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      for (int k = 0; k < m; k++) {
        if (i == k || j == k)
          continue;
        if (num[i] >= 4 && num[j] >= 4 && num[k] >= 2)
          res++;
      }
    }
  }

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (i == j)
        continue;
      if (num[i] >= 14 && num[j] >= 4)
        res++;
    }
  }

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (i == j)
        continue;
      if (num[i] >= 24 && num[j] >= 2)
        res++;
    }
  }
  if (num.front() >= 74)
    res++;

  cout << res << endl;
}

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

using namespace std;
using ll = long long;

map<int, int> Map;
template <class T> void fact(T n) {
  for (T i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      Map[i]++;
      n /= i;
    }
  }
  if (n == 1)
    return;
  Map[n]++;
}

int main() {
  int n;
  cin >> n;
  if (n < 10) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++)
    fact(i);
  int res = 0;
  vector<int> num;
  for (auto i : Map)
    num.push_back(i.second);
  int m = num.size();

  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      for (int k = 0; k < m; k++) {
        if (i == k || j == k)
          continue;
        if (num[i] >= 4 && num[j] >= 4 && num[k] >= 2)
          res++;
      }
    }
  }

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (i == j)
        continue;
      if (num[i] >= 14 && num[j] >= 4)
        res++;
    }
  }

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (i == j)
        continue;
      if (num[i] >= 24 && num[j] >= 2)
        res++;
    }
  }
  if (num.front() >= 74)
    res++;

  cout << res << endl;
}
Problem p03213 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 2; i <= n; ++i) {
    int tmp = i;
    for (int j = 2; j * j <= i; ++j) {
      while (1) {
        if (tmp % j != 0)
          break;
        ++mp[j];
        tmp /= j;
      }
    }
    // cout << i << " " << tmp << endl;
    if (tmp != 1)
      ++mp[tmp];
  }
  // for (auto p : mp) {
  //     cout << p.first << " " << p.second << endl;
  // }
  vector<int> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 1; i <= 100; ++i) {
    if (mp[i] != 0) {
      for (int j = 75; j >= 1; --j) {
        for (int x = 1; x <= mp[i]; ++x) {
          if (j * (x + 1) <= 75) {
            dp[j * (x + 1)] += dp[j];
          }
        }
      }
    }
  }
  cout << dp[75] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 2; i <= n; ++i) {
    int tmp = i;
    for (int j = 2; j * j <= i; ++j) {
      while (1) {
        if (tmp % j != 0)
          break;
        ++mp[j];
        tmp /= j;
      }
    }
    // cout << i << " " << tmp << endl;
    if (tmp != 1)
      ++mp[tmp];
  }
  // for (auto p : mp) {
  //     cout << p.first << " " << p.second << endl;
  // }
  vector<int> dp(76, 0);
  dp[1] = 1;
  for (int i = 1; i <= 100; ++i) {
    if (mp[i] != 0) {
      for (int j = 75; j >= 1; --j) {
        for (int x = 1; x <= mp[i]; ++x) {
          if (j * (x + 1) <= 75) {
            dp[j * (x + 1)] += dp[j];
          }
        }
      }
    }
  }
  cout << dp[75] << endl;
  return 0;
}
Problem p03213 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef unsigned long long LL;
typedef pair<int, int> P;
const LL mod = 1000000007;
const LL LINF = 1LL << 62;
const LL INF = 1 << 17;

vector<LL> fact;
vector<LL> inver(200001);

LL combi(int n, int r) {
  if (n < r || n < 0 || r < 0)
    return 0;
  return fact[n] % mod * inver[n - r] % mod * inver[r] % mod;
}

LL hcombi(int n, int r) { return combi(n + r - 1, r); }

LL fpow(LL a, LL n) {
  LL x = 1;
  while (n > 0) {
    if (n & 1) {
      x = x * a % mod;
    }
    a = a * a % mod;
    n >>= 1;
  }
  return x;
}

void set_combi() {
  LL s = 1;
  fact.push_back(1);
  for (int i = 1; i <= 200000; i++) {
    s *= i;
    s %= mod;
    fact.push_back(s);
  }
  inver[200000] = fpow(fact[200000], mod - 2);
  for (int i = 199999; i >= 0; i--) {
    inver[i] = inver[i + 1] * (i + 1) % mod;
  }
}

LL dp[101][1000];

int main() {
  LL N;
  cin >> N;
  vector<LL> v(101, 0);
  for (int i = 2; i <= N; i++) {
    int t = i;
    for (int j = 2; j <= N; j++) {
      while (t % j == 0) {
        v[j]++;
        t /= j;
      }
    }
  }
  dp[0][1] = 1;
  for (int i = 0; i <= N; i++) {
    for (int j = 1; j < 75; j++) {
      for (int k = 0; k <= v[i]; k++) {
        if (j * (k + 1) <= 75)
          dp[i + 1][j * (k + 1)] += dp[i][j];
      }
    }
  }
  LL ans = 0;
  for (int i = 0; i <= N; i++) {
    ans += dp[i][75];
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef unsigned long long LL;
typedef pair<int, int> P;
const LL mod = 1000000007;
const LL LINF = 1LL << 62;
const LL INF = 1 << 17;

LL dp[101][1000];

int main() {
  LL N;
  cin >> N;
  vector<LL> v(101, 0);
  for (int i = 2; i <= N; i++) {
    int t = i;
    for (int j = 2; j <= N; j++) {
      while (t % j == 0) {
        v[j]++;
        t /= j;
      }
    }
  }
  dp[0][1] = 1;
  for (int i = 0; i <= N; i++) {
    for (int j = 1; j < 75; j++) {
      for (int k = 0; k <= v[i]; k++) {
        if (j * (k + 1) <= 75)
          dp[i + 1][j * (k + 1)] += dp[i][j];
      }
    }
  }
  LL ans = 0;
  for (int i = 0; i <= N; i++) {
    ans += dp[i][75];
  }
  cout << ans << endl;
  return 0;
}
Problem p03213 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> d(76, 0);
  for (int i = 2; i <= n; i++) {
    int X = i;
    for (int div = 2; div <= i; div++) {
      int cnt = 0;
      while (X % div == 0) {
        cnt++;
        X /= div;
      }
      d[div] += cnt;
    }
  }
  int d2 = 0, d4 = 0, d14 = 0, d24 = 0, d74 = 0;
  for (int i = 0; i < 76; i++) {
    if (d[i] >= 2)
      d2++;
    if (d[i] >= 4)
      d4++;
    if (d[i] >= 14)
      d14++;
    if (d[i] >= 24)
      d24++;
    if (d[i] >= 74)
      d74++;
  }
  int ans = 0;
  ans += max(0, d74);
  ans += max(0, d24 * (d2 - 1));
  ans += max(0, d14 * (d4 - 1));
  ans += max(0, d4 * (d4 - 1) * (d2 - 2) / 2);
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(101, 0);
  for (int i = 2; i <= n; i++) {
    int X = i;
    for (int div = 2; div <= i; div++) {
      int cnt = 0;
      while (X % div == 0) {
        cnt++;
        X /= div;
      }
      d[div] += cnt;
    }
  }
  int d2 = 0, d4 = 0, d14 = 0, d24 = 0, d74 = 0;
  for (int i = 0; i < 76; i++) {
    if (d[i] >= 2)
      d2++;
    if (d[i] >= 4)
      d4++;
    if (d[i] >= 14)
      d14++;
    if (d[i] >= 24)
      d24++;
    if (d[i] >= 74)
      d74++;
  }
  int ans = 0;
  ans += max(0, d74);
  ans += max(0, d24 * (d2 - 1));
  ans += max(0, d14 * (d4 - 1));
  ans += max(0, d4 * (d4 - 1) * (d2 - 2) / 2);
  cout << ans << endl;
}
Problem p03213 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef unsigned long long LL;
typedef pair<int, int> P;
const LL mod = 1000000007;
const LL LINF = 1LL << 62;
const LL INF = 1 << 17;

LL dp[101][100];

int main() {
  LL N;
  cin >> N;
  vector<LL> v(101, 0);
  for (int i = 2; i <= N; i++) {
    int t = i;
    for (int j = 2; j <= N; j++) {
      while (t % j == 0) {
        v[j]++;
        t /= j;
      }
    }
  }
  dp[0][1] = 1;
  for (int i = 0; i <= N; i++) {
    for (int j = 1; j <= 75; j++) {
      for (int k = 0; k <= v[i]; k++) {
        if (j * (k + 1) <= 75)
          dp[i + 1][j * (k + 1)] += dp[i][j];
      }
    }
  }
  cout << dp[N + 1][75] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef unsigned long long LL;
typedef pair<int, int> P;
const LL mod = 1000000007;
const LL LINF = 1LL << 62;
const LL INF = 1 << 17;

LL dp[102][100];

int main() {
  LL N;
  cin >> N;
  vector<LL> v(101, 0);
  for (int i = 2; i <= N; i++) {
    int t = i;
    for (int j = 2; j <= N; j++) {
      while (t % j == 0) {
        v[j]++;
        t /= j;
      }
    }
  }
  dp[0][1] = 1;
  for (int i = 0; i <= N; i++) {
    for (int j = 1; j <= 75; j++) {
      for (int k = 0; k <= v[i]; k++) {
        if (j * (k + 1) <= 75)
          dp[i + 1][j * (k + 1)] += dp[i][j];
      }
    }
  }
  cout << dp[N + 1][75] << endl;
  return 0;
}
Problem p03214 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<double> v(n);
  for (auto &e : v)
    cin >> e;
  double ave = 0;
  for (auto &e : v)
    ave += e;
  ave = ave / n;
  int argi = 0;
  for (int i = 0; i < n; ++i) {
    if (abs(v[i] - ave) < abs(v[argi] - ave))
      i = argi;
  }
  cout << argi << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<double> v(n);
  for (auto &e : v)
    cin >> e;
  double ave = 0;
  for (auto &e : v)
    ave += e;
  ave = ave / n;
  int argi = 0;
  for (int i = 0; i < n; ++i) {
    if (abs(v[i] - ave) < abs(v[argi] - ave))
      argi = i;
  }
  cout << argi << endl;
}
Problem p03215 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
#define debug prllf
#else
#define debug(...)
#endif
const ll maxn = 105;
ll b[maxn];
vector<ll> v;
int main() {
  ll n, k;
  cin >> n >> k;
  for (ll i = 0; i < n; ++i) {
    cin >> b[i];
  }
  for (ll i = 0; i < n; ++i) {
    ll now = 0;
    for (ll k = i; k < n; ++k) {
      now += b[k];
      v.push_back(now);
    }
  }
  ll ans = 0;
  for (ll i = 40; i >= 0; --i) {
    ll now = ans | (1ll << i);
    ll ret = 0;
    for (ll j : v) {
      if ((j & now) == now) {
        ret++;
      }
    }
    if (ret >= k) {
      ans |= (1ll << i);
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
#define debug prllf
#else
#define debug(...)
#endif
const ll maxn = 1005;
ll b[maxn];
vector<ll> v;
int main() {
  ll n, k;
  cin >> n >> k;
  for (ll i = 0; i < n; ++i) {
    cin >> b[i];
  }
  for (ll i = 0; i < n; ++i) {
    ll now = 0;
    for (ll k = i; k < n; ++k) {
      now += b[k];
      v.push_back(now);
    }
  }
  ll ans = 0;
  for (ll i = 40; i >= 0; --i) {
    ll now = ans | (1ll << i);
    ll ret = 0;
    for (ll j : v) {
      if ((j & now) == now) {
        ret++;
      }
    }
    if (ret >= k) {
      ans |= (1ll << i);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03215 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repd(i, a, b) for (int i = a; i >= b; --i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define rvc(i, S) for (int i = 0; i < (int)S.size(); ++i)

#define pb push_back
#define fi first
#define se second
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define maxn 100020
#define ll long long
#define int long long
#define N 8000020
using namespace std;

int n, k;
int a[maxn];
int sum[maxn];
int cnt = 0;
int num[maxn];
bool tmp[maxn];
bool used[maxn];
signed main() {
  cin >> n >> k;
  rep(i, 1, n) {
    scanf("%lld", &a[i]);
    sum[i] += sum[i - 1] + a[i];
  }
  rep(i, 1, n) rep(j, i, n) num[++cnt] = sum[j] - sum[i - 1];
  ll ans = 0;
  rep(i, 1, cnt) used[i] = 1;
  repd(i, 60, 0) {
    ll tot = 0;
    rep(j, 1, cnt) {
      if ((num[j] & (1ll << i)) && (used[j]))
        tot++;
    }
    if (tot >= k) {
      ans += (1ll << i);
      rep(j, 1, cnt) if (!(num[j] & (1ll << i))) used[j] = 0;
    }
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repd(i, a, b) for (int i = a; i >= b; --i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define rvc(i, S) for (int i = 0; i < (int)S.size(); ++i)

#define pb push_back
#define fi first
#define se second
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define maxn 1000020
#define ll long long
#define int long long
#define N 8000020
using namespace std;

int n, k;
int a[maxn];
int sum[maxn];
int cnt = 0;
int num[maxn];
bool tmp[maxn];
bool used[maxn];
signed main() {
  cin >> n >> k;
  rep(i, 1, n) {
    scanf("%lld", &a[i]);
    sum[i] += sum[i - 1] + a[i];
  }
  rep(i, 1, n) rep(j, i, n) num[++cnt] = sum[j] - sum[i - 1];
  ll ans = 0;
  rep(i, 1, cnt) used[i] = 1;
  repd(i, 60, 0) {
    ll tot = 0;
    rep(j, 1, cnt) {
      if ((num[j] & (1ll << i)) && (used[j]))
        tot++;
    }
    if (tot >= k) {
      ans += (1ll << i);
      rep(j, 1, cnt) if (!(num[j] & (1ll << i))) used[j] = 0;
    }
  }
  cout << ans;
  return 0;
}
Problem p03215 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#define ll long long
using namespace std;
ll a[1010], sum[100010];
int n, m, cnt = 0;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++) {
    ll tot = 0;
    for (int j = i; j <= n; j++)
      tot += a[j], sum[++cnt] = tot;
  }
  ll ans = 0;
  for (int j = 44; j >= 0; j--) {
    int num = 0;
    for (int i = 1; i <= cnt; i++)
      if ((sum[i] >> j) & 1)
        num++;
    if (num >= m) {
      ans |= (1ll << j);
      for (int i = 1; i <= cnt; i++)
        if (!((sum[i] >> j) & 1))
          sum[i] = 0;
    }
  }
  printf("%lld", ans);
  return 0;
}


Fixed submission:
#include <cstdio>
#define ll long long
using namespace std;
ll a[1010], sum[1000010];
int n, m, cnt = 0;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++) {
    ll tot = 0;
    for (int j = i; j <= n; j++)
      tot += a[j], sum[++cnt] = tot;
  }
  ll ans = 0;
  for (int j = 44; j >= 0; j--) {
    int num = 0;
    for (int i = 1; i <= cnt; i++)
      if ((sum[i] >> j) & 1)
        num++;
    if (num >= m) {
      ans |= (1ll << j);
      for (int i = 1; i <= cnt; i++)
        if (!((sum[i] >> j) & 1))
          sum[i] = 0;
    }
  }
  printf("%lld", ans);
  return 0;
}
Problem p03215 (C++)

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

#define maxn 1010
typedef long long ll;
int a[maxn];
ll s[maxn];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i)
    scanf("%d", a + i);
  int t = 0;
  for (int i = 1; i <= n; ++i) {
    ll sum = 0;
    for (int j = i; j <= n; ++j)
      sum += a[j], s[++t] = sum;
  }
  ll ans = 0;
  for (int i = 40; ~i; --i) {
    int cnt = 0;
    for (int j = 1; j <= t; ++j)
      if (s[j] & (1ll << i))
        ++cnt;
    if (cnt >= k) {
      int nt = 0;
      for (int j = 1; j <= t; ++j)
        if (s[j] & (1ll << i))
          s[++nt] = s[j];
      t = nt;
      ans |= 1ll << i;
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <cstdio>

#define maxn 1010
typedef long long ll;
int a[maxn];
ll s[maxn * maxn];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i)
    scanf("%d", a + i);
  int t = 0;
  for (int i = 1; i <= n; ++i) {
    ll sum = 0;
    for (int j = i; j <= n; ++j)
      sum += a[j], s[++t] = sum;
  }
  ll ans = 0;
  for (int i = 40; ~i; --i) {
    int cnt = 0;
    for (int j = 1; j <= t; ++j)
      if (s[j] & (1ll << i))
        ++cnt;
    if (cnt >= k) {
      int nt = 0;
      for (int j = 1; j <= t; ++j)
        if (s[j] & (1ll << i))
          s[++nt] = s[j];
      t = nt;
      ans |= 1ll << i;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03215 (C++)

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

void judge(vector<ll> &p2, int exp, int K, ll ans) {
  // cout << exp << " " << ans << endl;
  vector<ll> p;
  if (exp == 0) {
    cout << ans << endl;
  }
  int x = 0;
  int tmp = 0;
  rep(j, p2.size()) {
    if (p2[j] % (1ll << exp) >= (1ll << exp - 1)) {
      tmp++;
      p.push_back(p2[j]);
    }
  }
  if (K <= tmp)
    judge(p, exp - 1, K, ans + (1ll << exp - 1));
  else
    judge(p2, exp - 1, K, ans);
}

int main() {
  cin.sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];
  vector<ll> p;
  rep(i, N) {
    ll tmp = 0;
    rep(j, N) {
      tmp += a[i + j];
      p.push_back(tmp);
      if (i + j == N - 1)
        break;
    }
  }
  judge(p, 40, K, 0);

  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

void judge(vector<ll> &p2, int exp, int K, ll ans) {
  // cout << exp << " " << ans << endl;
  vector<ll> p;
  if (exp == 0) {
    cout << ans << endl;
    return;
  }
  int x = 0;
  int tmp = 0;
  rep(j, p2.size()) {
    if (p2[j] % (1ll << exp) >= (1ll << exp - 1)) {
      tmp++;
      p.push_back(p2[j]);
    }
  }
  if (K <= tmp)
    judge(p, exp - 1, K, ans + (1ll << exp - 1));
  else
    judge(p2, exp - 1, K, ans);
}

int main() {
  cin.sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];
  vector<ll> p;
  rep(i, N) {
    ll tmp = 0;
    rep(j, N) {
      tmp += a[i + j];
      p.push_back(tmp);
      if (i + j == N - 1)
        break;
    }
  }
  judge(p, 40, K, 0);

  return 0;
}
Problem p03215 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, t) for (int i = (s); i < (t); ++i)
#define per(i, s, t) for (int i = ((t)-1); i >= s; --i)
#define repb(i, s, t) for (int i = (s); i <= (t); ++i)
#define lepb(i, s, t) for (int i = (s); i >= (t); --i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
#define mst(a, b) memset(a, b, sizeof(a))
#define dd(x) cout << #x << '=' << x << ' '
#define de(x) cout << #x << '=' << x << '\n'
#define fi first
#define se second
#define sq(x) ((x) * (x))
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;

const int inf = 0x3f3f3f3f;
const ll inff = 4557430888798830399ll;
const db eps = 1e-10;
const db pi = acos(-1.0);
const ll mod = 1e9 + 7;

#define maxn 1003
int a[maxn];
ll p[2][maxn * maxn];

int main() {
  //	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int n, k, z, c, cnt, dnt;
  ll t, s;
  scanf("%d%d", &n, &k);
  repb(i, 1, n) scanf("%d", a + i);
  cnt = 0;
  repb(i, 1, n) {
    t = 0;
    repb(j, i, n) p[0][cnt++] = (t += a[j]);
  }
  for (z = 1, s = 0; (z << 1) <= p[0][n - 1]; z <<= 1)
    ;
  for (int o = 0; z; z >>= 1, o ^= 1, cnt = dnt) {
    dnt = 0;
    c = 0;
    rep(i, 0, cnt) if (p[o][i] & z) p[o ^ 1][dnt++] = p[o][i], c += 1;
    if (c < k) {
      rep(i, 0, cnt) if (!(p[o][i] & z)) p[o ^ 1][dnt++] = p[o][i];
    } else
      s |= z;
  }
  printf("%lld\n", s);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, t) for (int i = (s); i < (t); ++i)
#define per(i, s, t) for (int i = ((t)-1); i >= s; --i)
#define repb(i, s, t) for (int i = (s); i <= (t); ++i)
#define lepb(i, s, t) for (int i = (s); i >= (t); --i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
#define mst(a, b) memset(a, b, sizeof(a))
#define dd(x) cout << #x << '=' << x << ' '
#define de(x) cout << #x << '=' << x << '\n'
#define fi first
#define se second
#define sq(x) ((x) * (x))
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;

const int inf = 0x3f3f3f3f;
const ll inff = 4557430888798830399ll;
const db eps = 1e-10;
const db pi = acos(-1.0);
const ll mod = 1e9 + 7;

#define maxn 1003
int a[maxn];
ll p[2][maxn * maxn];

int main() {
  //	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int n, k, c, cnt, dnt;
  ll z, t, s;
  scanf("%d%d", &n, &k);
  repb(i, 1, n) scanf("%d", a + i);
  cnt = 0;
  repb(i, 1, n) {
    t = 0;
    repb(j, i, n) p[0][cnt++] = (t += a[j]);
  }
  for (z = 1, s = 0; (z << 1) <= p[0][n - 1]; z <<= 1)
    ;
  for (int o = 0; z; z >>= 1, o ^= 1, cnt = dnt) {
    dnt = 0;
    c = 0;
    rep(i, 0, cnt) if (p[o][i] & z) p[o ^ 1][dnt++] = p[o][i], c += 1;
    if (c < k) {
      rep(i, 0, cnt) if (!(p[o][i] & z)) p[o ^ 1][dnt++] = p[o][i];
    } else
      s |= z;
  }
  printf("%lld\n", s);
}
Problem p03215 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  int N, K;
  cin >> N >> K;

  vector<int> a(N);
  vector<int> sum(N);
  REP(i, N) {
    cin >> a[i];
    sum[i + 1] = sum[i] + a[i];
  }

  vector<int> v;
  REP(l, N) {
    FOR(r, l + 1, N) { v.push_back(sum[r] - sum[l]); }
  }

  int ans = 0;
  REV(i, 50, 0) {
    int tmp = ans | (1LL << i);

    int k = 0;
    REP(j, v.size()) {
      if ((v[j] & tmp) == tmp) {
        k++;
      }
    }
    if (k >= K) {
      ans = tmp;
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  int N, K;
  cin >> N >> K;

  vector<int> a(N);
  vector<int> sum(N + 1);
  REP(i, N) {
    cin >> a[i];
    sum[i + 1] = sum[i] + a[i];
  }

  vector<int> v;
  REP(l, N) {
    FOR(r, l + 1, N) { v.push_back(sum[r] - sum[l]); }
  }

  int ans = 0;
  REV(i, 50, 0) {
    int tmp = ans | (1LL << i);

    int k = 0;
    REP(j, v.size()) {
      if ((v[j] & tmp) == tmp) {
        k++;
      }
    }
    if (k >= K) {
      ans = tmp;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03215 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
using namespace std;
typedef long long int LL;
LL sum[1005];
LL t[100005];
bool con[100005]; // concern

int main() {
  LL n, m, p;
  int i, j, k;
  LL s = 0;
  LL a, b;
  memset(con, true, sizeof(con));
  cin >> n >> m;
  p = n * (n + 1) / 2;
  for (i = 0; i < n; i++) {
    cin >> a;
    sum[i + 1] = sum[i] + a;
  }
  for (i = 0, k = 0; i < n; i++) {
    for (j = i; j < n; j++) {
      t[k++] = sum[j + 1] - sum[i];
    }
  }
  for (i = 40; i >= 0; i--) {
    a = (LL)1 << i;
    for (j = 0, k = 0; j < p; j++) {
      if (con[j] && (t[j] & a)) {
        k++;
      }
    }
    if (k >= m) {
      s += a;
      for (j = 0; j < p; j++) {
        if ((t[j] & a) == 0)
          con[j] = false;
      }
    }
  }
  cout << s << endl;
}


Fixed submission:
#include <cstring>
#include <iostream>
using namespace std;
typedef long long int LL;
LL sum[1005];
LL t[1000005];
bool con[1000005]; // concern

int main() {
  LL n, m, p;
  int i, j, k;
  LL s = 0;
  LL a, b;
  memset(con, true, sizeof(con));
  cin >> n >> m;
  p = n * (n + 1) / 2;
  for (i = 0; i < n; i++) {
    cin >> a;
    sum[i + 1] = sum[i] + a;
  }
  for (i = 0, k = 0; i < n; i++) {
    for (j = i; j < n; j++) {
      t[k++] = sum[j + 1] - sum[i];
    }
  }
  for (i = 40; i >= 0; i--) {
    a = (LL)1 << i;
    for (j = 0, k = 0; j < p; j++) {
      if (con[j] && (t[j] & a)) {
        k++;
      }
    }
    if (k >= m) {
      s += a;
      for (j = 0; j < p; j++) {
        if ((t[j] & a) == 0)
          con[j] = false;
      }
    }
  }
  cout << s << endl;
}
Problem p03215 (C++)

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

using namespace std;

unsigned long sums[500050];

void solve() {
  int N, K;
  cin >> N >> K;
  vector<unsigned long> imos(N + 1);
  for (int i = 0; i < N; i++) {
    long a;
    cin >> a;
    imos[i + 1] = a + imos[i];
  }

  unsigned long ans = 0;

  for (int l = 0; l < N; l++)
    for (int r = l + 1; r <= N; r++) {
      sums[N * l + r - l] = imos[r] - imos[l];
    }

  unsigned long b = 1ULL << 60;

  while (b > 0) {
    int cnt = 0;
    for (auto s : sums) {
      cnt += ((ans + b) & s) == ans + b;
    }
    if (cnt >= K)
      ans += b;
    b >>= 1;
  }

  cout << ans << endl;
}

int main() {
  solve();
  // cout << "yui(*-v・)yui" << endl;
  return 0;
}


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

using namespace std;

unsigned long sums[5000050];

void solve() {
  int N, K;
  cin >> N >> K;
  vector<unsigned long> imos(N + 1);
  for (int i = 0; i < N; i++) {
    long a;
    cin >> a;
    imos[i + 1] = a + imos[i];
  }

  unsigned long ans = 0;

  for (int l = 0; l < N; l++)
    for (int r = l + 1; r <= N; r++) {
      sums[N * l + r - l] = imos[r] - imos[l];
    }

  unsigned long b = 1ULL << 60;

  while (b > 0) {
    int cnt = 0;
    for (auto s : sums) {
      cnt += ((ans + b) & s) == ans + b;
    }
    if (cnt >= K)
      ans += b;
    b >>= 1;
  }

  cout << ans << endl;
}

int main() {
  solve();
  // cout << "yui(*-v・)yui" << endl;
  return 0;
}
Problem p03216 (C++)

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

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(0);
  int n, q;
  string s;
  cin >> n >> s >> q;
  for (int i = 0; i < n; ++i)
    s = s + "*";
  n *= 2;
  vector<ll> prefM(n), prefC(n);
  for (int i = 0; i < n; ++i) {
    prefM[i] = 0;
    if (s[i] == 'M')
      ++prefM[i];
    if (i - 1 >= 0)
      prefM[i] += prefM[i - 1];
  }
  for (int i = 0; i < n; ++i) {
    prefC[i] = 0;
    if (s[i] == 'C')
      ++prefC[i];
    if (i - 1 >= 0)
      prefC[i] += prefC[i - 1];
  }
  for (int i = 0; i < q; ++i) {
    int k;
    cin >> k;
    --k;
    ll odp = 0;
    vector<ll> ilMC(n);
    ilMC[0] = 0;
    for (int j = 0; j < k - 1; ++j)
      if (s[j] == 'M')
        ilMC[0] += prefC[k - 1] - prefC[j];
    for (int j = 1; j + k - 1 < n; ++j) {
      if (s[j] == '*')
        break;
      ilMC[j] = ilMC[j - 1];
      if (s[j - 1] == 'M')
        ilMC[j] -= prefC[j + k - 2] - prefC[j - 1];
      if (s[j + k - 1] == 'C')
        ilMC[j] += prefM[j + k - 2] - prefM[j - 1];
    }
    ++k;
    for (int j = 0; j + k - 1 < n; ++j) {
      if (s[j] == '*')
        break;
      if (s[j] == 'D')
        odp += ilMC[j + 1];
    }
    cout << odp << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(0);
  int n, q;
  string s;
  cin >> n >> s >> q;
  string g(n, '*');
  s = s + g;
  n *= 2;
  vector<ll> prefM(n), prefC(n);
  for (int i = 0; i < n; ++i) {
    prefM[i] = 0;
    if (s[i] == 'M')
      ++prefM[i];
    if (i - 1 >= 0)
      prefM[i] += prefM[i - 1];
  }
  for (int i = 0; i < n; ++i) {
    prefC[i] = 0;
    if (s[i] == 'C')
      ++prefC[i];
    if (i - 1 >= 0)
      prefC[i] += prefC[i - 1];
  }
  for (int i = 0; i < q; ++i) {
    int k;
    cin >> k;
    --k;
    ll odp = 0;
    vector<ll> ilMC(n);
    ilMC[0] = 0;
    for (int j = 0; j < k - 1; ++j)
      if (s[j] == 'M')
        ilMC[0] += prefC[k - 1] - prefC[j];
    for (int j = 1; j + k - 1 < n; ++j) {
      if (s[j] == '*')
        break;
      ilMC[j] = ilMC[j - 1];
      if (s[j - 1] == 'M')
        ilMC[j] -= prefC[j + k - 2] - prefC[j - 1];
      if (s[j + k - 1] == 'C')
        ilMC[j] += prefM[j + k - 2] - prefM[j - 1];
    }
    ++k;
    for (int j = 0; j + k - 1 < n; ++j) {
      if (s[j] == '*')
        break;
      if (s[j] == 'D')
        odp += ilMC[j + 1];
    }
    cout << odp << endl;
  }
  return 0;
}
Problem p03216 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

lin n;
string s;
lin q;

void solve(lin k) {
  queue<lin> d;
  queue<lin> m;
  lin ad = 0;
  lin res = 0;

  rep(i, s.length()) {
    if (d.size() > 0) {
      if (i - d.front() >= k) {
        d.pop();
        ad -= m.size();

        if (d.size() > 0) {
          while (m.size() >= 0 && d.front() > m.front()) {
            m.pop();
          }
        } else {
          while (m.size() > 0) {
            m.pop();
          }
        }
      }
    }

    if (s[i] == 'D') {
      d.push(i);
    } else if (s[i] == 'M') {
      if (d.size() > 0) {
        m.push(i);
        ad += d.size();
      }
    } else if (s[i] == 'C') {
      res += ad;
    }
  }

  cout << res << endl;
}

int main(void) {
  lin k[76];

  cin >> n >> s >> q;
  rep(i, q) {
    cin >> k[i];
    solve(k[i]);
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

lin n;
string s;
lin q;

void solve(lin k) {
  queue<lin> d;
  queue<lin> m;
  lin ad = 0;
  lin res = 0;

  rep(i, s.length()) {
    if (d.size() > 0) {
      if (i - d.front() >= k) {
        d.pop();
        ad -= m.size();

        if (d.size() > 0) {
          while (m.size() > 0 && d.front() > m.front()) {
            m.pop();
          }
        } else {
          while (m.size() > 0) {
            m.pop();
          }
        }
      }
    }

    if (s[i] == 'D') {
      d.push(i);
    } else if (s[i] == 'M') {
      if (d.size() > 0) {
        m.push(i);
        ad += d.size();
      }
    } else if (s[i] == 'C') {
      res += ad;
    }
  }

  cout << res << endl;
}

int main(void) {
  lin k[76];

  cin >> n >> s >> q;
  rep(i, q) {
    cin >> k[i];
    solve(k[i]);
  }

  return 0;
}
Problem p03216 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int, int>;
// 参考: http://kmjp.hatenablog.jp/entry/2018/11/26/0900
ll m[123456];
ll c[123456];
ll mc[123456];
int main() {
  int n;
  string s;
  int q;
  cin >> n >> s >> q;
  rep(i, n) {
    if (s[i] == 'M')
      m[i]++;
    if (s[i] == 'C')
      c[i]++;
  }
  rep(i, n) {
    m[i + 1] += m[i];
    c[i + 1] += c[i];
  }
  rep(i, n) {
    if (s[i] == 'C') {
      mc[i] = m[i];
    }
  }
  rep(i, n) { mc[i + 1] += mc[i]; }
  while (q--) {
    int k;
    cin >> k;
    k--;
    ll ans = 0;
    rep(i, n) {
      if (s[i] == 'D') {
        int pos = min(n, i + k);
        ans += mc[pos] - mc[i] - m[i] * (c[pos] - c[i]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int, int>;
// 参考: http://kmjp.hatenablog.jp/entry/2018/11/26/0900
ll m[1234567];
ll c[1234567];
ll mc[1234567];
int main() {
  int n;
  string s;
  int q;
  cin >> n >> s >> q;
  rep(i, n) {
    if (s[i] == 'M')
      m[i]++;
    if (s[i] == 'C')
      c[i]++;
  }
  rep(i, n) {
    m[i + 1] += m[i];
    c[i + 1] += c[i];
  }
  rep(i, n) {
    if (s[i] == 'C') {
      mc[i] = m[i];
    }
  }
  rep(i, n) { mc[i + 1] += mc[i]; }
  while (q--) {
    int k;
    cin >> k;
    k--;
    ll ans = 0;
    rep(i, n) {
      if (s[i] == 'D') {
        int pos = min(n, i + k);
        ans += mc[pos] - mc[i] - m[i] * (c[pos] - c[i]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}