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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main() {
  i64 N;
  cin >> N;
  i64 ans = 1;
  vector<map<i64, i64>> cnt(N + 1);
  vector<i64> memo(N + 1);
  memo[1] = 1;
  for (i64 i = 2; i <= N; i++) {
    i64 t = i;
    for (i64 j = 2; j * j <= i; j++) {
      if (i % j != 0)
        continue;
      cnt[i] = cnt[i / j];
      t = j;
      break;
    }
    cnt[i][t]++;
    memo[i] = memo[i / t] / (cnt[i][t] == 0 ? 1 : cnt[i][t]) * (cnt[i][t] + 1);
    ans += memo[i] * i;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main() {
  i64 N;
  cin >> N;
  vector<i64> cnt(N + 1);
  for (i64 i = 1; i <= N; i++)
    for (i64 j = 1; i * j <= N; j++)
      cnt[i * j]++;
  i64 ans = 0;
  for (i64 i = 1; i <= N; i++)
    ans += cnt[i] * i;
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>

#define int long long
#define rr register

#define inf 1e9
#define MAXN 10000010

using namespace std;

inline int read() {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch))
    f |= ch == '-', ch = getchar();
  while (isdigit(ch))
    s = s * 10 + (ch ^ 48), ch = getchar();
  return f ? -s : s;
}

void print(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    print(x / 10);
  putchar(x % 10 + 48);
}

int n, ans, m, k, cnt;

int a[MAXN];

inline int pri(int x) {
  for (rr int i = 1; i <= x; i++)
    for (rr int j = i; j <= x; j += i)
      a[j]++;
}

signed main() {
  n = read();
  pri(10000000);
  for (rr int i = 1; i <= n; i++)
    ans += i * a[i];
  cout << ans;
}
/*
5 4 731
80 150 80 150 1
60 90 120 149
*/

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>

#define int long long
#define rr register

#define inf 1e9
#define MAXN 10000010

using namespace std;

inline int read() {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch))
    f |= ch == '-', ch = getchar();
  while (isdigit(ch))
    s = s * 10 + (ch ^ 48), ch = getchar();
  return f ? -s : s;
}

void print(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    print(x / 10);
  putchar(x % 10 + 48);
}

int n, ans, m, k, cnt;

int a[MAXN];

inline void pri(int x) {
  for (rr int i = 1; i <= x; i++)
    for (rr int j = i; j <= x; j += i)
      a[j]++;
}

signed main() {
  n = read();
  pri(10000000);
  for (rr int i = 1; i <= n; i++)
    ans += i * a[i];
  cout << ans;
}
/*
5 4 731
80 150 80 150 1
60 90 120 149
*/
Problem p02624 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  ll s = 0;
  vector<ll> a(n);
  rep(i, n / 2) {
    rep(j, n) {
      if (i * j <= n) {
        ll x = i * j;
        a[x]++;
      }
    }
  }
  rep(i, n) { s += a[i] * i; }
  cout << s << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  ll s = 0;
  vector<ll> a(n);
  rep(i, n) {
    for (int j = i; j <= n; j += i) {
      a[j]++;
    }
  }
  rep(i, n) { s += a[i] * i; }
  cout << s << endl;
}
Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):
// time out
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  ll ans = 0;

  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= i; j++) {
      if (i % j == 0)
        ans += i;
    }
  }

  cout << ans << endl;
}

Fixed submission:
// time out
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  ll ans = 0;

  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j += i) {
      ans += j;
    }
  }

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

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

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  rep(i, n) {
    ll k = n / i;
    ans += i * k * (k + 1) / 2;
  }
  cout << ans << endl;
}

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

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  rep(i, n) {
    ll k = n / i;
    ans += i * k * (k + 1) / 2;
  }
  cout << ans << endl;
}
Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
  ll a, b, c, h, i, j, k, l, m, n, x, y;
  ll ans = 0;
  string s;
  cin >> n;

  for (a = 1; a <= n; a++) {
    ll fk = 0;
    for (i = 1; i * i <= a; i++) {
      if ((a % i) == 0) {
        fk++;
        if (a / i != i)
          fk++;
      }
    }
    // cout << "fk:" << fk << endl;
    ans += a * fk;
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
  ll a, b, c, h, i, j, k, l, m, n, x, y;
  ll ans = 0;
  string s;
  cin >> n;

  for (i = 1; i <= n; i++) {

    ans += (n - (n % i) + i) * (n / i) / 2;
  }

  cout << ans << endl;
  return 0;
}
Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define debug printf("\n<<CameHere<<\n")
#define mem(x, y) memset(x, y, sizeof(x))
#define all(qz) qz.begin(), qz.end()
#define rall(qz) qz.rbegin(), qz.rend()
#define inf LLONG_MIN
#define INF LLONG_MAX
#define mod 1000000007
#define Sqr(x) ((x) * (x))
#define ll long long
#define mk make_pair
#define pb push_back
#define pi acos(-1.0)
#define cos(a) cos(a *pi / 180)
#define sin(a) sin(a *pi / 180)
#define tan(a) tan(a *pi / 180)

ll pow(ll c, ll d) { return d == 0 ?: c * pow(c, d - 1); }
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return ((a * b) / gcd(a, b)); }
/*---------AL ASAD NUR RIYAD------------*/
#define mx 20000009
ll ar[mx + 100];

void fn() {
  for (ll i = 2; i <= mx / 2; i++) {
    for (ll j = i * 2; j <= mx; j += i) {
      ar[j]++;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  fn();
  ll n;
  cin >> n;
  ll cnt = 1;
  for (ll i = 2; i <= n; i++) {
    cnt += (i * (ar[i] + 2));
  }
  cout << cnt << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define debug printf("\n<<CameHere<<\n")
#define mem(x, y) memset(x, y, sizeof(x))
#define all(qz) qz.begin(), qz.end()
#define rall(qz) qz.rbegin(), qz.rend()
#define inf LLONG_MIN
#define INF LLONG_MAX
#define mod 1000000007
#define Sqr(x) ((x) * (x))
#define ll long long
#define mk make_pair
#define pb push_back
#define pi acos(-1.0)
#define cos(a) cos(a *pi / 180)
#define sin(a) sin(a *pi / 180)
#define tan(a) tan(a *pi / 180)

ll pow(ll c, ll d) { return d == 0 ?: c * pow(c, d - 1); }
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return ((a * b) / gcd(a, b)); }
/*---------AL ASAD NUR RIYAD------------*/
#define mx 10000009
ll ar[mx + 100];

void fn() {
  for (ll i = 2; i <= mx / 2; i++) {
    for (ll j = i * 2; j <= mx; j += i) {
      ar[j]++;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  fn();
  ll n;
  cin >> n;
  ll cnt = 1;
  for (ll i = 2; i <= n; i++) {
    cnt += (i * (ar[i] + 2));
  }
  cout << cnt << endl;
  return 0;
}
Problem p02624 (C++)

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

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
typedef pair<int, int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9 + 7;
const int vx[6] = {0, 1, 0, -1, 1, -1};
const int vy[6] = {1, 0, -1, 0, 1, 1};

ll f(ll a) {
  ll rep = 0;
  for (ll i = 1; i <= a / 2; ++i) {
    if (a % i == 0) {
      rep++;
    }
  }
  return rep + 1;
}

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

  ll n;
  cin >> n;
  ll ans = 0;
  vector<ll> dp(200000000, 2);
  dp[0] = 0;
  dp[1] = 1;
  rep(i, n / 2 + 1) {
    if (i == 0 || i == 1)
      continue;
    for (ll j = i + i; j <= n; j += i) {
      dp[j]++;
    }
  }
  rep(i, n + 1) { ans += i * dp[i]; }
  cout << ans << endl;

  cout << endl;
  return 0;
}


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

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
typedef pair<int, int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9 + 7;
const int vx[6] = {0, 1, 0, -1, 1, -1};
const int vy[6] = {1, 0, -1, 0, 1, 1};

ll f(ll a) {
  ll rep = 0;
  for (ll i = 1; i <= a / 2; ++i) {
    if (a % i == 0) {
      rep++;
    }
  }
  return rep + 1;
}

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

  ll n;
  cin >> n;
  ll ans = 0;
  vector<ll> dp(20000000, 2);
  dp[0] = 0;
  dp[1] = 1;
  rep(i, n / 2 + 1) {
    if (i == 0 || i == 1)
      continue;
    for (ll j = i + i; j <= n; j += i) {
      dp[j]++;
    }
  }
  rep(i, n + 1) { ans += i * dp[i]; }
  cout << ans << endl;

  cout << endl;
  return 0;
}
Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define arep(a, i, n) for (int i = (a); i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define cinf(x, n)                                                             \
  for (int i = 0; i < (n); i++)                                                \
    cin >> x[i];
#define coutf(x, n)                                                            \
  for (int i = 0; i < (n); i++)                                                \
    cout << x[i] << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll a[10000001];

int main() {
  ll n;
  cin >> n;
  ull sum = 0;
  for (ll i = 1; i < n + 1; i++) {
    for (ll j = i; j < n + 1; j *= i) {
      a[j]++;
    }
  }
  arep(1, i, n + 1) { sum += i * a[i]; }
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define arep(a, i, n) for (int i = (a); i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define cinf(x, n)                                                             \
  for (int i = 0; i < (n); i++)                                                \
    cin >> x[i];
#define coutf(x, n)                                                            \
  for (int i = 0; i < (n); i++)                                                \
    cout << x[i] << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll a[10000001];

int main() {
  ll n;
  cin >> n;
  ull sum = 0;
  for (ll i = 1; i < n + 1; i++) {
    for (ll j = i; j < n + 1; j += i) {
      a[j]++;
    }
  }
  arep(1, i, n + 1) { sum += i * a[i]; }
  cout << sum << endl;
}
Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <vector>
#define MOD 1000000007
typedef long long int lli;
using namespace std;
int f(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt += 2;
    }
  }
  return cnt;
}
int main() {
  int n;
  cin >> n;
  lli ans = 0;
  for (int k = 1; k <= n; k++) {
    lli g = (lli)f(k);
    ans += (k * f(k));
  }
  cout << ans << "\n";
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <vector>
#define MOD 1000000007
typedef long long int lli;
using namespace std;
int f(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt += 2;
    }
  }
  return cnt;
}
int main() {
  int n;
  cin >> n;
  lli ans = 0;
  int dp[n + 1];
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      dp[j]++;
    }
    ans += ((lli)dp[i] * i);
  }
  cout << ans << "\n";
  return 0;
}
Problem p02624 (C++)

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i, n) for (ll i = 0; i < (ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int, int>, int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

// 最大公約数
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}

// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

// 約数の全列挙
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  cout << fixed << setprecision(15);
  ll N;
  cin >> N;

  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    vector<ll> P = divisor(i);

    ans += i * P.size();
  }
  cout << ans << endl;
  return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i, n) for (ll i = 0; i < (ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int, int>, int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

// 最大公約数
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}

// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

// 約数の全列挙
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  cout << fixed << setprecision(15);
  ll N;
  cin >> N;

  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ll k = N / i;
    ans += i * k * (k + 1) / 2;
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++)

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

#define int long long
#define endl "\n"
#define pb push_back
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define IN freopen("input.txt", "r", stdin);
#define OUT freopen("output.txt", "w", stdout);

const int N = 2e5 + 5;
const double pi = 3.141592653589793238;

int32_t main() {
  IOS;
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i % j == 0)
        cnt += i;
    }
  }
  cout << cnt << endl;
}


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

#define int long long
#define endl "\n"
#define pb push_back
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define IN freopen("input.txt", "r", stdin);
#define OUT freopen("output.txt", "w", stdout);

const int N = 2e5 + 5;
const double pi = 3.141592653589793238;

int32_t main() {
  IOS;
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    int num = n / i;
    cnt += i * (num + 1) * num / 2;
  }
  cout << cnt << endl;
}
Problem p02624 (C++)

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

using namespace std;
struct _ {
  ios_base::Init i;
  _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }
} _;

vector<long long> spf(1e7 + 1, 0);

int main() {

  long long n;
  cin >> n;

  iota(spf.begin(), spf.begin() + n, 0);

  for (long long i = 2; i * i <= n; i++) {
    for (long long j = i * i; j <= n; j += i)
      spf[j] = min(spf[j], i);
  }

  long long ans = 0;

  for (long long i = 1; i <= n; i++) {
    long long x = i, cnt = 1;
    while (x != 1) {
      long long pfac = spf[x], temp = 0;
      while (x % pfac == 0)
        x /= pfac, temp++;
      cnt *= (temp + 1);
    }
    ans += (i * cnt);
  }

  cout << ans;

  return 0;
}

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

using namespace std;
struct _ {
  ios_base::Init i;
  _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }
} _;

vector<long long> spf(1e7 + 1, 0);

int main() {

  long long n;
  cin >> n;

  iota(spf.begin(), spf.begin() + n + 1, 0);

  for (long long i = 2; i * i <= n; i++) {
    for (long long j = i * i; j <= n; j += i)
      spf[j] = min(spf[j], i);
  }

  long long ans = 0;

  for (long long i = 1; i <= n; i++) {
    long long x = i, cnt = 1;
    while (x != 1) {
      long long pfac = spf[x], temp = 0;
      while (x % pfac == 0)
        x /= pfac, temp++;
      cnt *= (temp + 1);
    }
    ans += (i * cnt);
  }

  cout << ans;

  return 0;
}
Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> P;
#define mp(x, y) make_pair(x, y)

typedef queue<int> qi;
typedef queue<string> qs;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = (a); i <= (b); i++)
#define repm(i, n) for (int i = n; i >= 0; i--)

#define all(v) v.begin(), v.end()
// sort( all(v) )　などと使える

ll f(ll x) {
  ll cnt = 0;

  for (ll i = 1; i * i <= x; i++) {
    if (x % i == 0)
      cnt++;
    if (x % i == 0 && i * i != x)
      cnt++;
  }

  return cnt;
}

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

  ll ans = 0;

  // cout << f(n) << endl;

  for (ll k = 1; k <= n; k++) {
    ans += k * f(k);
  }

  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> P;
#define mp(x, y) make_pair(x, y)

typedef queue<int> qi;
typedef queue<string> qs;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = (a); i <= (b); i++)
#define repm(i, n) for (int i = n; i >= 0; i--)

#define all(v) v.begin(), v.end()
// sort( all(v) )　などと使える

ll f(ll x) {
  ll cnt = 0;

  for (ll i = 1; i * i <= x; i++) {
    if (x % i == 0)
      cnt++;
    if (x % i == 0 && i * i != x)
      cnt++;
  }

  return cnt;
}

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

  ll ans = 0;

  // cout << f(n) << endl;

  for (ll j = 1; j <= n; j++) {
    // jの倍数はqコあるよ
    ll q = n / j;
    // jの倍数 * jはj + 2 * j + ・・・ + q * j
    //  = q * (q + 1) / 2 * j
    ans += j * q * (q + 1) / 2;
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define endl '\n'
#define pi 2 * acos(0.0)
#define pb(a) push_back(a)
#define db double
#define ld long double
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define inf 1000000000000000001
#define sqr(x) (x) * (x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a / gcd(a, b)) * b)
#define debug(x) cerr << #x << " = " << (x) << endl
#define all(x) (x).begin(), (x).end()
#define unsyncIO                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)

using namespace std;

int main() {
  // freopen("/home/taalpatar_shepai/Documents/my_codes/out.txt", "w", stdout);
  unsyncIO;
  ll n, ans = 0;
  cin >> n;
  for (ll j = 1; j <= n; j++) {
    for (ll i = 1; i <= n; i++) {
      if (i % j == 0)
        ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define endl '\n'
#define pi 2 * acos(0.0)
#define pb(a) push_back(a)
#define db double
#define ld long double
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define inf 1000000000000000001
#define sqr(x) (x) * (x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a / gcd(a, b)) * b)
#define debug(x) cerr << #x << " = " << (x) << endl
#define all(x) (x).begin(), (x).end()
#define unsyncIO                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)

using namespace std;

int main() {
  // freopen("/home/taalpatar_shepai/Documents/my_codes/out.txt", "w", stdout);
  unsyncIO;
  ll n, ans = 0;
  cin >> n;
  for (ll j = 1; j <= n; j++) {
    ll t = n / j;
    ans += t * (t + 1) / 2 * j;
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  ll a = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      if (i % j == 0)
        a += i;
    }
  }
  cout << a;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  ll a = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = i; j <= n; j += i) {
      a += j;
    }
  }
  cout << a;
}
Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  long long int n, i, j, s = 0, sum = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= i; j++) {
      if (i % j == 0)
        s++;
    }
    sum += (s * i);
    s = 0;
  }
  cout << sum;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long long int n, i, j, s = 0, sum = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j = j + i)
      sum += j;
  }
  cout << sum;
}
Problem p02624 (C++)

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

int main() {
  ll n;
  cin >> n;
  map<ll, int> mp;
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; j = j + i) {
      mp[j]++;
    }
    ans += i * mp[i];
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  ll n;
  cin >> n;
  // map<ll,int> mp;
  vector<ll> mp(n + 1, 0);
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; j = j + i) {
      mp[j]++;
    }
    ans += i * mp[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<ll> p(n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n / i; j++) {
      p[i * j - 14]++;
    }
  }
  ll ans = 0;
  rep(i, n) { ans += (i + 1) * p[i]; }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<ll> p(n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n / i; j++) {
      p[i * j - 1]++;
    }
  }
  ll ans = 0;
  rep(i, n) { ans += (i + 1) * p[i]; }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define ll long long
int main() {
  // INPUT
  ll N = 0;
  cin >> N;

  // SOURCE
  ll ans = 0;
  for (ll i = 1; i < N + 1; ++i) {
    for (ll j = 1; j <= i; ++j) {
      if (i % j == 0)
        ans += i;
    }
  }

  // OUTPUT
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define ll long long
int main() {
  // INPUT
  ll N = 0;
  cin >> N;

  // SOURCE
  ll ans = 0;
  for (ll i = 1; i < N + 1; ++i) {
    ll Y = N / i;
    ans += (Y * (Y + 1) * i) / 2;
  }

  // OUTPUT
  cout << ans << endl;

  return 0;
}
Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
using namespace std;

#define ll long long
int n;

int main() {
  scanf("%d", &n);

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll sum = 0;
    for (int j = 1; j <= i; j++)
      if (i % j == 0)
        sum++;
    ans += 1ll * i * sum;
  }

  printf("%lld", ans);
  return 0;
}

Fixed submission:
#include <cstdio>
using namespace std;

#define ll long long
int n;

int main() {
  scanf("%d", &n);

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll x = n / i;
    ans += x * (x + 1) / 2 * i;
  }

  printf("%lld", ans);
  return 0;
}
Problem p02624 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

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

  ll n;
  cin >> n;
  ll res = 0;
  for (int i = 1; i <= n; i++) {
    ll x = n / x;
    res += (x + 1) * i / 2;
  }
  cout << res << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

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

  ll n;
  cin >> n;
  ll res = 0;
  for (ll i = 1; i <= n; i++) {
    ll x = n / i;
    res += x * (x + 1) * i / 2;
  }
  cout << res << endl;
  return 0;
}
Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):
// prepared by dumb
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define dl double
#define llu unsigned long long int
#define scll(x) scanf("%lld", &x)
#define scdl(x) scanf("%lf", &x)
#define scull(x) scanf("%llu", &x)
#define scch(x) scanf(" %c", &x)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define ppb() pop_back()
#define ppf() pop_front()
#define Pi acos(-1.0)
#define INF 1000000000000000000
#define mod 1000000007
#define ff first
#define ss second
#define mpr make_pair
#define debug(x) cout << x << '\n';
// sin((x*pi)/180.0)[x in degree]
// sin(x)[x in radian]
// asin(x)[radian]
//(asin(x)*180)/pi[degree]
// or(|)//and(&)//xor(^)//not(~)
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll a, b, c, d, e, f = 0, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x,
                    y, z;
  ll cnt = 0, ans = 0, l1, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = 0;
  ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm;
  string str, str1, str2;

  scll(n);
  unordered_map<ll, ll> coun;
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j += i)
      coun[j]++;
  }

  for (i = 1; i <= n; i++)
    ans += i * coun[i];
  cout << ans;

  return 0;
}

Fixed submission:
// prepared by dumb
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define dl double
#define llu unsigned long long int
#define scll(x) scanf("%lld", &x)
#define scdl(x) scanf("%lf", &x)
#define scull(x) scanf("%llu", &x)
#define scch(x) scanf(" %c", &x)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define ppb() pop_back()
#define ppf() pop_front()
#define Pi acos(-1.0)
#define INF 1000000000000000000
#define mod 1000000007
#define ff first
#define ss second
#define mpr make_pair
#define debug(x) cout << x << '\n';
// sin((x*pi)/180.0)[x in degree]
// sin(x)[x in radian]
// asin(x)[radian]
//(asin(x)*180)/pi[degree]
// or(|)//and(&)//xor(^)//not(~)
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll a, b, c, d, e, f = 0, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x,
                    y, z;
  ll cnt = 0, ans = 0, l1, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = 0;
  ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm;
  string str, str1, str2;

  scll(n);
  vector<ll> coun(n + 1, 0);
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j += i)
      coun[j]++;
  }

  for (i = 1; i <= n; i++)
    ans += i * coun[i];
  cout << ans;

  return 0;
}
Problem p02624 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main(void) {
  long long N;
  cin >> N;

  long long ans = 0;

  for (int X = 0; X < N; X++) {
    long long Y = N / X;
    long long G = Y * (Y + 1) * X / 2;
    ans += G;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  long long N;
  cin >> N;

  long long ans = 0;

  for (int X = 1; X <= N; X++) {
    long long Y = N / X;
    long long G = Y * (Y + 1) * X / 2;
    ans += G;
  }

  cout << ans << endl;

  return 0;
}
Problem p02625 (C++)

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

using namespace std;

typedef long long ll;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

ll MOD = 1e9 + 7;

const ll max_n = 505050;
ll fact[max_n];
bool fact_inited = false;

ll powmod(ll a, ll b) {
  if (b == 0)
    return 1;
  if (b % 2 == 1)
    return a * powmod(a, b - 1) % MOD;

  ll d = powmod(a, b / 2) % MOD;
  return d * d % MOD;
}

ll init_fact() {
  fact[0] = 1;
  fact[1] = 1;

  for (ll i = 2; i < max_n; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }

  fact_inited = true;
}

ll comb(ll n, ll k) {
  if (!fact_inited)
    init_fact();

  ll ret = fact[n];
  ret *= powmod(fact[k], MOD - 2);
  ret %= MOD;
  ret *= powmod(fact[n - k], MOD - 2);
  ret %= MOD;
  return ret;

  // X^(-1) = X^(p-2) (mod p) (Fermat's little theorem)
}

ll perm(ll n, ll k) {
  if (!fact_inited)
    init_fact();

  ll ret = fact[n];
  ret *= powmod(fact[n - k], MOD - 2);
  ret %= MOD;
  return ret;
}

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

  ll n, m;
  cin >> n >> m;

  ll ans = perm(m, n) * perm(m, n);
  ans %= MOD;

  ll s = -1;
  for (int x = 1; x <= n; x++) {
    ll t = perm(m, n) * comb(n, x) % MOD * perm(m - x, n - x) % MOD;
    t %= MOD;
    t *= s;
    ans += MOD + t;
    ans %= MOD;

    s *= -1;
  }

  cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

ll MOD = 1e9 + 7;

const ll max_n = 505050;
ll fact[max_n];
bool fact_inited = false;

ll powmod(ll a, ll b) {
  if (b == 0)
    return 1;
  if (b % 2 == 1)
    return a * powmod(a, b - 1) % MOD;

  ll d = powmod(a, b / 2) % MOD;
  return d * d % MOD;
}

void init_fact() {
  fact[0] = 1;
  fact[1] = 1;

  for (ll i = 2; i < max_n; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }

  fact_inited = true;
}

ll comb(ll n, ll k) {
  if (!fact_inited)
    init_fact();

  ll ret = fact[n];
  ret *= powmod(fact[k], MOD - 2);
  ret %= MOD;
  ret *= powmod(fact[n - k], MOD - 2);
  ret %= MOD;
  return ret;

  // X^(-1) = X^(p-2) (mod p) (Fermat's little theorem)
}

ll perm(ll n, ll k) {
  if (!fact_inited)
    init_fact();

  ll ret = fact[n];
  ret *= powmod(fact[n - k], MOD - 2);
  ret %= MOD;
  return ret;
}

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

  ll n, m;
  cin >> n >> m;

  ll ans = perm(m, n) * perm(m, n);
  ans %= MOD;

  ll s = -1;
  for (int x = 1; x <= n; x++) {
    ll t = perm(m, n) * comb(n, x) % MOD * perm(m - x, n - x) % MOD;
    t %= MOD;
    t *= s;
    ans += MOD + t;
    ans %= MOD;

    s *= -1;
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
/* run this program using the console pauser or add your own getch,
 * system("pause") or input loop */
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define ll long long
#define sc(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
const ll mod = 1e9 + 7;
ll ad(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll jc[720005];
ll ap(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll ksm(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b % 2 == 1)
      res = ap(res, a);
    a = ap(a, a);
    b /= 2;
  }
  return res;
}
ll C(ll a, ll b) {
  return ap(jc[a], ap(ksm(jc[b], mod - 2), ksm(jc[a - b], mod - 2)));
}
ll f[720005];
ll g[720005];
int main(int argc, char **argv) {
  ll n, m;
  sl(n);
  sl(m);
  jc[0] = 1;
  rep(i, 1, m + m) { jc[i] = ap(jc[i - 1], i); }
  ll ans = 0;
  rep(i, 0, n) // 最少有i个相等
  {
    g[i] = ap(ap(ap(C(n, i), C(m, i)), ap(C(m - i, (n - i)), C(m - i, n - i))),
              ap(jc[i], ap(jc[n - i], jc[n - i])));
    //	cout<<g[i]<<" "<<ap(C(m,2*(n-i)),(jc[2*(n-i)]))<<endl;
    ans = ad(ans, ((i) % 2 == 0) ? g[i] : mod - g[i]);
  }

  cout << ans;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
/* run this program using the console pauser or add your own getch,
 * system("pause") or input loop */
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define ll long long
#define sc(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
const ll mod = 1e9 + 7;
ll ad(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll jc[720005];
ll ap(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll ksm(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b % 2 == 1)
      res = ap(res, a);
    a = ap(a, a);
    b /= 2;
  }
  return res;
}
ll C(ll a, ll b) {
  return ap(jc[a], ap(ksm(jc[b], mod - 2), ksm(jc[a - b], mod - 2)));
}
ll f[720005];
ll g[720005];
int main(int argc, char **argv) {
  ll n, m;
  sl(n);
  sl(m);
  jc[0] = 1;
  rep(i, 1, m) { jc[i] = ap(jc[i - 1], i); }
  ll ans = 0;
  rep(i, 0, n) // 最少有i个相等
  {
    g[i] = ap(ap(ap(C(n, i), C(m, i)), ap(C(m - i, (n - i)), C(m - i, n - i))),
              ap(jc[i], ap(jc[n - i], jc[n - i])));
    //	cout<<g[i]<<" "<<ap(C(m,2*(n-i)),(jc[2*(n-i)]))<<endl;
    ans = ad(ans, ((i) % 2 == 0) ? g[i] : mod - g[i]);
  }

  cout << ans;
  return 0;
}
Problem p02626 (C++)

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

int main() {
  int N;
  cin >> N;
  ull x, A1, A2;
  cin >> A1;
  cin >> A2;
  x = 0;
  for (int i = 3; i <= N; i++) {
    ull a;
    cin >> a;
    x ^= a;
  }
  set<pair<ull, ull>> S; // (z+b,b)
  S.insert(pair<ull, ull>(1, 1));
  while (S.size() > 0) {
    pair<ull, ull> p = *S.begin();
    S.erase(S.begin());
    ull z = p.first - p.second;
    ull b = p.second;
    //		cout << "check (" << z << "," << b << ")" << endl;
    if (((A1 - z) ^ (A2 + z)) == x) {
      cout << z << endl;
      return (0);
    }
    if ((((A1 - z) & (b * 2 - 1)) ^ ((A2 + z) & (b * 2 - 1))) ==
        (x & (b * 2 - 1))) {
      if (p.first + p.second < A1) {
        S.insert(pair<ull, ull>(z + b * 2, b * 2));
        //				cout << "insert (" << z + b * 2 << "," << b *
        //2 << ")" << endl;
        S.insert(pair<ull, ull>(z + b + b, b));
        //				cout << "insert (" << z + b + b * 2 << "," <<
        //b * 2 << ")" << endl;
      }
    }
  }
  cout << -1 << endl;
  return (0);
}


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

int main() {
  int N;
  cin >> N;
  ull x, A1, A2;
  cin >> A1;
  cin >> A2;
  x = 0;
  for (int i = 3; i <= N; i++) {
    ull a;
    cin >> a;
    x ^= a;
  }
  set<pair<ull, ull>> S; // (z+b,b)
  S.insert(pair<ull, ull>(1, 1));
  while (S.size() > 0) {
    pair<ull, ull> p = *S.begin();
    S.erase(S.begin());
    ull z = p.first - p.second;
    ull b = p.second;
    //		cout << "check (" << z << "," << b << ")" << endl;
    if (((A1 - z) ^ (A2 + z)) == x) {
      cout << z << endl;
      return (0);
    }
    if ((((A1 - z) & (b * 2 - 1)) ^ ((A2 + z) & (b * 2 - 1))) ==
        (x & (b * 2 - 1))) {
      if (p.first + p.second < A1) {
        S.insert(pair<ull, ull>(z + b * 2, b * 2));
        //				cout << "insert (" << z + b * 2 << "," << b *
        //2 << ")" << endl;
        if (((A1 - z) & b) == 0 || ((A2 + z) & b) == b) {
          S.insert(pair<ull, ull>(z + b + b * 2, b * 2));
          //				cout << "insert (" << z + b + b * 2 << "," << b * 2
          //<< ")" << endl;
        }
      }
    }
  }
  cout << -1 << endl;
  return (0);
}
Problem p02626 (C++)

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------

int N;
ll A[303];

void solve() {
  int i, j, k, l, r, x, y;
  string s;

  cin >> N;
  FOR(i, N) cin >> A[i];
  ll xo = 0;
  for (i = 2; i < N; i++)
    xo ^= A[i];

  vector<int> cand;
  FOR(i, 1 << 20) if (i < A[0]) {
    ll v = (A[0] - i) ^ (A[1] + i) ^ xo;
    if ((v & ((1 << 20) - 1)) == 0)
      cand.push_back(i);
  }

  ll mi = 1LL << 50;
  FORR(c, cand) {
    for (ll a = c; a < A[0]; a += 1 << 20) {
      ll v = (A[0] - a) ^ (A[1] + a) ^ xo;
      if (v == 0)
        mi = min(mi, a);
    }
  }

  if (mi == 1LL << 50)
    mi = -1;
  cout << mi << endl;
}

int main(int argc, char **argv) {
  string s;
  int i;
  if (argc == 1)
    ios::sync_with_stdio(false), cin.tie(0);
  FOR(i, argc - 1) s += argv[i + 1], s += '\n';
  FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------

int N;
ll A[303];

void solve() {
  int i, j, k, l, r, x, y;
  string s;

  cin >> N;
  FOR(i, N) cin >> A[i];
  ll xo = 0;
  for (i = 2; i < N; i++)
    xo ^= A[i];

  vector<int> cand;
  FOR(i, 1 << 20) if (i < A[0]) {
    ll v = (A[0] - i) ^ (A[1] + i) ^ xo;
    if ((v & ((1 << 20) - 1)) == 0)
      cand.push_back(i);
  }

  ll mi = 1LL << 50;
  FORR(c, cand) {
    for (ll a = c; a < min(mi, A[0]); a += 1 << 20) {
      ll v = (A[0] - a) ^ (A[1] + a) ^ xo;
      if (v == 0)
        mi = min(mi, a);
    }
  }

  if (mi == 1LL << 50)
    mi = -1;
  cout << mi << endl;
}

int main(int argc, char **argv) {
  string s;
  int i;
  if (argc == 1)
    ios::sync_with_stdio(false), cin.tie(0);
  FOR(i, argc - 1) s += argv[i + 1], s += '\n';
  FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
Problem p02627 (Python)

Buggy submission (status: Runtime Error):
s = input()
if s.isuper():
    print("A")
else:
    print("a")


Fixed submission:
s = input()
if s.isupper():
    print("A")
else:
    print("a")
Problem p02627 (Python)

Buggy submission (status: Runtime Error):
a = input()
if ord(a) >= "a" and ord(a) <= "z":
    print("a")
else:
    print("A")


Fixed submission:
a = input()
if ord(a) >= ord("a") and ord(a) <= ord("z"):
    print("a")
else:
    print("A")
Problem p02627 (Python)

Buggy submission (status: Runtime Error):
s = int(input())
if s == s.lower():
    print("a")
else:
    print("A")


Fixed submission:
s = input()
if s == s.lower():
    print("a")
else:
    print("A")
Problem p02627 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define SCANF(i)                                                               \
  int i;                                                                       \
  scanf("%d", &i)
typedef long long ll;
using namespace std;
using P = pair<int, int>;
const long long INF = 1LL << 60;
const int IINF = 100000000;
const int MOD = (int)1e9 + 7;
// 約数列挙
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  // sort(ret.begin(), ret.end()); // 昇順に並べる
  return ret;
}
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, -1, 0, 1};

signed main() {
  char t;
  cin >> t;
  for (char c = 'a'; c <= 'z'; c++) {
    if (c == t) {
      cout << 'a' << endl;
      return 1;
    }
  }
  cout << 'A' << endl;
} // https://atcoder.jp/contests/abc171/tasks/abc171_a

Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define SCANF(i)                                                               \
  int i;                                                                       \
  scanf("%d", &i)
typedef long long ll;
using namespace std;
using P = pair<int, int>;
const long long INF = 1LL << 60;
const int IINF = 100000000;
const int MOD = (int)1e9 + 7;
// 約数列挙
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  // sort(ret.begin(), ret.end()); // 昇順に並べる
  return ret;
}
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, -1, 0, 1};

signed main() {
  char t;
  cin >> t;
  for (char c = 'a'; c <= 'z'; c++) {
    if (c == t) {
      cout << 'a' << endl;
      return 0;
    }
  }
  cout << 'A' << endl;
} // https://atcoder.jp/contests/abc171/tasks/abc171_a