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

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template <class _T> static void getval(_T &a) { std::cin >> a; }
template <class _T> static void getval(_T &a, _T &b) { std::cin >> a >> b; }
template <class _T> static void getval(_T &a, _T &b, _T &c) {
  std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
  if (a < (_T)0) {
    a *= (_T)-1;
  }
  return a;
}
template <class _T> static void tp_swap(_T &right, _T &left) {
  //	usage:  tp_swap<type name>(a, b);
  _T tmp = right;
  right = left;
  left = tmp;
}

static void C();

int main() {
  C();
  fflush(stdout);
  return 0;
}

static void C() {
  int N, M;
  getval(N, M);

  LLONG K;
  getval(K);

  std::vector<LLONG> sumAi(N + 1, 0), sumBi(M + 1, 0);
  for (int i = 1; i <= N; i++) {
    LLONG ai;
    getval(ai);
    sumAi[i] = sumAi[i - 1] + ai;
  }
  for (int i = 1; i <= M; i++) {
    LLONG bi;
    getval(bi);
    sumBi[i] = sumBi[i - 1] + bi;
  }

  int bookMax = 0, cnt = 0;
  for (int b = M; b >= 0; b--) {
    for (int a = 0; a <= N; a++) {
      if (sumAi[a] + sumBi[b] <= K) {
        bookMax = std::max(bookMax, b + a);
      }
    }
  }
  printf("%d\n", bookMax);
}


Fixed submission:

#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template <class _T> static void getval(_T &a) { std::cin >> a; }
template <class _T> static void getval(_T &a, _T &b) { std::cin >> a >> b; }
template <class _T> static void getval(_T &a, _T &b, _T &c) {
  std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
  if (a < (_T)0) {
    a *= (_T)-1;
  }
  return a;
}
template <class _T> static void tp_swap(_T &right, _T &left) {
  //	usage:  tp_swap<type name>(a, b);
  _T tmp = right;
  right = left;
  left = tmp;
}

static void C();

int main() {
  C();
  fflush(stdout);
  return 0;
}

static void C() {
  int N, M;
  getval(N, M);

  LLONG K;
  getval(K);

  std::vector<LLONG> sumAi(N + 1, 0), sumBi(M + 1, 0);
  for (int i = 1; i <= N; i++) {
    LLONG ai;
    getval(ai);
    sumAi[i] = sumAi[i - 1] + ai;
  }
  for (int i = 1; i <= M; i++) {
    LLONG bi;
    getval(bi);
    sumBi[i] = sumBi[i - 1] + bi;
  }

  int bookMax = 0, bIdx = M;
  for (int a = 0; a <= N; a++) {
    if (sumAi[a] <= K) {
      bookMax = std::max(bookMax, a);
    }
    while (bIdx) {
      if (sumAi[a] + sumBi[bIdx] <= K) {
        bookMax = std::max(bookMax, bIdx + a);
        break;
      } else {
        bIdx--;
      }
    }
  }
  printf("%d\n", bookMax);
}
Problem p02623 (C++)

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

int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  long long k;
  std::cin >> n >> m >> k;
  std::vector<long long> a(n + 1), b(m + 1);
  for (int i = 1; i <= n; i++) {
    std::cin >> a[i];
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    std::cin >> b[i];
    b[i] += b[i - 1];
  }
  int c = 0;
  for (int i = 0; i <= n && a[i] <= k; i++) {
    int j = std::lower_bound(b.begin(), b.end(), k - a[i]) - b.begin();
    if (j > m)
      j = m;
    if (b[j] > k - a[j])
      j--;
    if (j < 0)
      j = 0;
    c = std::max(c, i + j);
  }
  std::cout << c << '\n';
  return 0;
}


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

int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  long long k;
  std::cin >> n >> m >> k;
  std::vector<long long> a(n + 1), b(m + 1);
  for (int i = 1; i <= n; i++) {
    std::cin >> a[i];
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    std::cin >> b[i];
    b[i] += b[i - 1];
  }
  int i = 0, j = 0;
  while (i <= n && a[i] <= k)
    i++;
  i--;
  while (j <= m && a[i] + b[j] <= k)
    j++;
  j--;
  int c = i + j;
  while (i > 0) {
    i--;
    while (j <= m && a[i] + b[j] <= k)
      j++;
    j--;
    c = std::max(c, i + j);
  }
  std::cout << c << '\n';
  return 0;
}
Problem p02623 (C++)

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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  ll time = 0;
  ll book_b = 0;
  ll book_a = 0;
  ll books = 0;
  for (ll i = 0; i < n and time + a[i] <= k; i++) {
    time += a[i];
    book_a = i + 1;
  }
  for (ll i = book_a - 1; i >= -1; i--) {
    for (ll j = book_b; j < m and time + b[j] <= k; j++) {
      time += b[j];
      book_b = j + 1;
    }
    books = max(books, book_a + book_b);
    if (book_a != 0) {
      time -= a[i];
      book_a--;
    }
  }
  cout << books << endl;
  return 0;
}

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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n), b(m);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  ll time = 0;
  ll book_b = 0;
  ll book_a = 0;
  ll books = 0;
  for (ll i = 0; i < n and time + a[i] <= k; i++) {
    time += a[i];
    book_a = i + 1;
  }
  for (ll i = book_a - 1; i >= -1; i--) {
    for (ll j = book_b; j < m and time + b[j] <= k; j++) {
      time += b[j];
      book_b = j + 1;
    }
    books = max(books, book_a + book_b);
    if (book_a != 0) {
      time -= a[i];
      book_a--;
    }
  }
  cout << books << endl;
  return 0;
}
Problem p02623 (C++)

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

using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i += 1)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define repv(arr) for (auto it = arr[i].begin(); it != arr[i].end(); it++)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define ssortA(arr) stable_sort(arr.begin(), arr.end())
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)
#define pb push_back
#define ll long long
#define LCM(a, b) boost::math::lcm(a, b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  ll k;
  cin >> n >> m >> k;
  vl arr(n + 1), b(m + 1);
  rep(i, 1, n + 1) { cin >> arr[i]; }
  rep(i, 1, m + 1) { cin >> b[i]; }
  int max = 0;

  vl prea(n + 1, 0), preb(m + 1, 0);
  rep(i, 1, n + 1) { prea[i] += prea[i - 1] + arr[i]; }
  rep(i, 1, n + 1) { preb[i] += b[i] + preb[i - 1]; }
  int i = 1, j = n;
  while (1) {
    if (j < 0 || i > m) {
      break;
    } else {
      if (prea[j] + preb[i] <= k) {
        if (i + j > max)
          max = i + j;
        i++;
      } else {
        j--;
      }
    }
  }
  cout << max << endl;
}


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

using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i += 1)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define repv(arr) for (auto it = arr[i].begin(); it != arr[i].end(); it++)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define ssortA(arr) stable_sort(arr.begin(), arr.end())
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)
#define pb push_back
#define ll long long
#define LCM(a, b) boost::math::lcm(a, b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  ll k;
  cin >> n >> m >> k;
  vl arr(n + 1), b(m + 1);
  rep(i, 1, n + 1) { cin >> arr[i]; }
  rep(i, 1, m + 1) { cin >> b[i]; }
  int max = 0;

  vl prea(n + 1, 0), preb(m + 1, 0);
  rep(i, 1, n + 1) { prea[i] += prea[i - 1] + arr[i]; }
  rep(i, 1, m + 1) { preb[i] += preb[i - 1] + b[i]; }
  int i = 0, j = n;
  while (1) {
    if (j < 0 || i > m) {
      break;
    } else {
      if (prea[j] + preb[i] <= k) {
        if (i + j > max)
          max = i + j;
        i++;
      } else {
        j--;
      }
    }
  }
  cout << max << endl;
}
Problem p02623 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, n) for (int i = 1; i <= (n); ++i)
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Sort2(x) sort((x).begin(), (x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>; // グラフ型

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> b(m);
  rep(i, m) cin >> b[i];

  vector<ll> sa(n + 1);
  rep(i, n) { sa[i + 1] = a[i] + sa[i]; }
  vector<ll> sb(m + 1);
  rep(i, m) { sb[i + 1] = a[i] + sb[i]; }

  int ans = 0;

  rep(i, n + 1) {
    ll k2 = k - sa[i];
    if (k2 < 0)
      continue;
    auto c = upper_bound(sb.begin(), sb.end(), k2);
    int j = distance(sb.begin(), c);
    ans = max(ans, i + j - 1);
  }

  cout << ans << endl;
}

/*
sb = 0,1,5,7,8,9
5 = 3
4 = 2
0 = 1
*/

/*
g++ b.cpp
./a.out

oj d https://atcoder.jp/contests/abc172/tasks/abc172_c
oj t
*/


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, n) for (int i = 1; i <= (n); ++i)
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Sort2(x) sort((x).begin(), (x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>; // グラフ型

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> b(m);
  rep(i, m) cin >> b[i];

  vector<ll> sa(n + 1);
  rep(i, n) { sa[i + 1] = a[i] + sa[i]; }
  vector<ll> sb(m + 1);
  rep(i, m) { sb[i + 1] = b[i] + sb[i]; }

  int ans = 0;

  rep(i, n + 1) {
    ll k2 = k - sa[i];
    if (k2 < 0)
      continue;
    auto c = upper_bound(sb.begin(), sb.end(), k2);
    int j = distance(sb.begin(), c);
    ans = max(ans, i + j - 1);
  }

  cout << ans << endl;
}

/*
sb = 0,1,5,7,8,9
5 = 3
4 = 2
0 = 1
*/

/*
g++ b.cpp
./a.out

oj d https://atcoder.jp/contests/abc172/tasks/abc172_c
oj t
*/
Problem p02623 (C++)

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

int main() {
  long long n, m, k;
  std::cin >> n >> m >> k;
  // long long  a[n+1], b[m+1];
  std::vector<long long> a{n + 1}, b{m + 1};
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i < n + 1; i++)
    std::cin >> a[i];
  for (int i = 1; i < m + 1; i++)
    std::cin >> b[i];

  for (int i = 1; i < n + 1; i++)
    a[i] += a[i - 1];
  for (int i = 1; i < m + 1; i++)
    b[i] += b[i - 1];

  long long ans = 0, r = m;
  for (int i = 0; i < n + 1; i++) {
    if (a[i] > k)
      break;
    while (a[i] + b[r] > k)
      r--;
    ans = std::max({ans, i + r});
  }

  std::cout << ans;

  return 0;
}


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

int main() {
  long long n, m, k;
  std::cin >> n >> m >> k;
  // long long  a[n+1], b[m+1];
  std::vector<long long> a(n + 1), b(m + 1);
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i < n + 1; i++)
    std::cin >> a[i];
  for (int i = 1; i < m + 1; i++)
    std::cin >> b[i];

  for (int i = 1; i < n + 1; i++)
    a[i] += a[i - 1];
  for (int i = 1; i < m + 1; i++)
    b[i] += b[i - 1];

  long long ans = 0, r = m;
  for (int i = 0; i < n + 1; i++) {
    if (a[i] > k)
      break;
    while (a[i] + b[r] > k)
      r--;
    ans = std::max({ans, i + r});
  }

  std::cout << ans;

  return 0;
}
Problem p02623 (C++)

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

#undef int
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
#define int long long int
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    int n, m, k;
    cin >> n >> m >> k;
    int crr[n], drr[n];
    for (int i = 0; i < n; i++) {
      cin >> crr[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> drr[i];
    }
    int s = 0;
    int i, j;
    for (i = 0; i < n; i++) {
      if (s + crr[i] <= k)
        s += crr[i];
      else
        break;
    }
    int z = i - 1;
    for (j = 0; j < m; j++) {
      if (s + drr[j] <= k)
        s += drr[j];
      else
        break;
    }
    int x = j;
    int ans = 0;
    ans = max(ans, z + x + 1);
    while (z >= 0) {
      if (x >= m)
        break;
      if (z < 0)
        break;
      s = s - crr[z];
      z--;
      ans = max(ans, z + x + 1);
      if (x >= m)
        break;
      while (s + drr[x] <= k) {
        if (x >= m)
          break;
        s += drr[x];
        x++;
        ans = max(ans, z + x + 1);
        if (x >= m)
          break;
      }
    }
    ans = max(ans, z + x + 1);
    cout << ans << endl;
  }
  return 0;
}

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

#undef int
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
#define int long long int
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    int n, m, k;
    cin >> n >> m >> k;
    int crr[n], drr[m];
    for (int i = 0; i < n; i++) {
      cin >> crr[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> drr[i];
    }
    int s = 0;
    int i, j;
    for (i = 0; i < n; i++) {
      if (s + crr[i] <= k)
        s += crr[i];
      else
        break;
    }
    int z = i - 1;
    for (j = 0; j < m; j++) {
      if (s + drr[j] <= k)
        s += drr[j];
      else
        break;
    }
    int x = j;
    int ans = 0;
    ans = max(ans, z + x + 1);
    while (z >= 0) {
      if (x >= m)
        break;
      if (z < 0)
        break;
      s = s - crr[z];
      z--;
      ans = max(ans, z + x + 1);
      if (x >= m)
        break;
      while (s + drr[x] <= k) {
        if (x >= m)
          break;
        s += drr[x];
        x++;
        ans = max(ans, z + x + 1);
        if (x >= m)
          break;
      }
    }
    ans = max(ans, z + x + 1);
    cout << ans << endl;
  }
  return 0;
}
Problem p02623 (C++)

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

  int n, m;
  cin >> n >> m;
  ll k;
  cin >> k;
  vector<ll> a(n + 1), b(n + 1);
  for (int i = 0; i < n; i++) {
    ll t;
    cin >> t;
    a[i + 1] = a[i] + t;
  }
  for (int i = 0; i < m; i++) {
    ll t;
    cin >> t;
    b[i + 1] = b[i] + t;
  }

  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (a[i] > k)
      break;
    int l = 0, r = m + 1;
    while (r - l > 1) {
      int mid = (l + r) / 2;
      if (a[i] + b[mid] <= k)
        l = mid;
      else
        r = mid;
    }
    ans = max(ans, i + l);
  }
  cout << ans << endl;

  return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

  int n, m;
  cin >> n >> m;
  ll k;
  cin >> k;
  vector<ll> a(n + 1), b(m + 1);
  for (int i = 0; i < n; i++) {
    ll t;
    cin >> t;
    a[i + 1] = a[i] + t;
  }
  for (int i = 0; i < m; i++) {
    ll t;
    cin >> t;
    b[i + 1] = b[i] + t;
  }

  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (a[i] > k)
      break;
    int l = 0, r = m + 1;
    while (r - l > 1) {
      int mid = (l + r) / 2;
      if (a[i] + b[mid] <= k)
        l = mid;
      else
        r = mid;
    }
    ans = max(ans, i + l);
  }
  cout << ans << endl;

  return 0;
}
Problem p02623 (C++)

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX{200010};
const ll MOD{1000000007}, oo{1LL << 62};

ll solve(ll N, ll M, ll K, const vector<ll> &xs, const vector<ll> &ys) {
  ll ans = 0, sum = 0, a = 0, b = 0, c = 0;

  while (a < N and (sum + xs[a] <= K)) {
    ++c;
    sum += xs[a++];
  }

  while (b < M and (sum + ys[b] <= K)) {
    sum += ys[b++];
    ++c;
  }

  ans = c;
  --a;

  while (a >= 0) {
    sum -= xs[a--];
    --c;

    while (b < M and (sum + xs[b] <= K)) {
      sum += ys[b++];
      ++c;
    }

    ans = max(ans, c);
  }

  return ans;
}

int main() {
  ios::sync_with_stdio(false);

  ll N, M, K;
  cin >> N >> M >> K;

  vector<ll> xs(N), ys(M);

  for (int i = 0; i < N; ++i)
    cin >> xs[i];

  for (int i = 0; i < M; ++i)
    cin >> ys[i];

  auto ans = max(solve(N, M, K, xs, ys), solve(M, N, K, ys, xs));

  cout << ans << '\n';

  return 0;
}


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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX{200010};
const ll MOD{1000000007}, oo{1LL << 62};

ll solve(ll N, ll M, ll K, const vector<ll> &xs, const vector<ll> &ys) {
  ll ans = 0, sum = 0, a = 0, b = 0, c = 0;

  while (a < N and (sum + xs[a] <= K)) {
    ++c;
    sum += xs[a++];
  }

  while (b < M and (sum + ys[b] <= K)) {
    sum += ys[b++];
    ++c;
  }

  ans = c;
  --a;

  while (a >= 0) {
    sum -= xs[a--];
    --c;

    while (b < M and (sum + ys[b] <= K)) {
      sum += ys[b++];
      ++c;
    }

    ans = max(ans, c);
  }

  return ans;
}

int main() {
  ios::sync_with_stdio(false);

  ll N, M, K;
  cin >> N >> M >> K;

  vector<ll> xs(N), ys(M);

  for (int i = 0; i < N; ++i)
    cin >> xs[i];

  for (int i = 0; i < M; ++i)
    cin >> ys[i];

  auto ans = max(solve(N, M, K, xs, ys), solve(M, N, K, ys, xs));

  cout << ans << '\n';

  return 0;
}
Problem p02623 (C++)

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

int main() {
  int N, M, K;
  long long sum = 0;
  cin >> N >> M >> K;
  vector<int> A(N), B(M);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int j = 0; j < N; j++) {
    cin >> B.at(j);
    sum += B.at(j);
  }
  int ans = 0;
  int j = M;
  for (int i = 0; i < N + 1; i++) {
    while (j > 0 && sum > K) {
      j--;
      sum -= B.at(j);
    }
    if (sum > K) {
      break;
    }
    ans = max(ans, i + j);
    if (i == N) {
      break;
    }
    sum += A.at(i);
  }
  cout << ans << endl;
}


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

int main() {
  int N, M, K;
  long long sum = 0;
  cin >> N >> M >> K;
  vector<int> A(N), B(M);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int j = 0; j < M; j++) {
    cin >> B.at(j);
    sum += B.at(j);
  }
  int ans = 0;
  int j = M;
  for (int i = 0; i < N + 1; i++) {
    while (j > 0 && sum > K) {
      j--;
      sum -= B.at(j);
    }
    if (sum > K) {
      break;
    }
    ans = max(ans, i + j);
    if (i == N) {
      break;
    }
    sum += A.at(i);
  }
  cout << ans << endl;
}
Problem p02623 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;
const double PI = 3.14159265358979323846;
const int NMAX = 100005;
using namespace std;

int main() {
  ll n, m, k;

  cin >> n >> m >> k;
  ll suma[n + 1], sumb[m + 1];
  vector<ll> a(n), b(m);
  suma[0] = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    suma[i + 1] = suma[i] + a[i];
  }
  sumb[0] = 0;
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    sumb[i + 1] = sumb[i] + b[i];
  }

  int j = m;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    ll d = suma[i];
    if (d > k)
      break;
    for (j = m; j >= 0; j--) {
      if (d + sumb[j] <= k)
        break;
    }
    ans = max(ans, i + j);
  }

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;
const double PI = 3.14159265358979323846;
const int NMAX = 100005;
using namespace std;

int main() {
  ll n, m, k;

  cin >> n >> m >> k;
  ll suma[n + 1], sumb[m + 1];
  vector<ll> a(n), b(m);
  suma[0] = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    suma[i + 1] = suma[i] + a[i];
  }
  sumb[0] = 0;
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    sumb[i + 1] = sumb[i] + b[i];
  }

  int j = m;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    ll d = suma[i];
    if (d > k)
      break;
    for (j; j >= 0; j--) {
      if (d + sumb[j] <= k)
        break;
    }
    ans = max(ans, i + j);
  }

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

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

using namespace std;

long long inf = 1000000007;

int main() {
  long long n;
  cin >> n;
  long long ans = 0;

  for (long long i = 1; i <= n; i++) {
    long long pre = i;
    long long num = i;

    for (long long j = 2; j <= num; j++) {
      long long cnt = 0;
      while (num % j == 0) {
        num /= j;
        cnt++;
      }
      pre *= cnt + 1;
    }

    ans += pre;
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

long long inf = 1000000007;

int main() {
  long long n;
  cin >> n;
  long long ans = 0;

  for (long long i = 1; i <= n; i++) {
    long long y = n / i;
    ans += y * (1 + y) / 2 * i;
  }

  cout << ans << endl;

  return 0;
}
Problem p02624 (C++)

Buggy submission (status: Runtime Error):

// Problem : D - Sum of Divisors
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_d
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

int n;
ll a[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  ll res = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = i; j <= n; j += i) {
      a[j]++;
    }
  }
  for (int i = 2; i <= n; ++i) {
    res += (a[i] + 1) * i;
  }
  cout << res << endl;
  return 0;
}


Fixed submission:

// Problem : D - Sum of Divisors
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_d
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e7 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

int n;
ll a[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  ll res = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = i; j <= n; j += i) {
      a[j]++;
    }
  }
  for (int i = 2; i <= n; ++i) {
    res += (a[i] + 1) * i;
  }
  cout << res << endl;
  return 0;
}
Problem p02624 (C++)

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

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define sz(a) (int)((a).size())
#define NoType ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
// find_by_order(x) -> returns an iterator to the element at a given position
// order_of_key(x) -> returns the position of a given element

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;

const int mod = (int)1e9 + 7;
const int MAXN = 2e5 + 12;
// indexed_set s;

int n;

int main() {

  NoType;

  cin >> n;
  int m[n + 1];
  for (int i = 1; i <= 10000000; i++)
    m[i] = 0;

  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      m[j]++;
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += (i * m[i]);
  }

  cout << ans;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define sz(a) (int)((a).size())
#define NoType ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
// find_by_order(x) -> returns an iterator to the element at a given position
// order_of_key(x) -> returns the position of a given element

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;

const int mod = (int)1e9 + 7;
const int MAXN = 2e5 + 12;
// indexed_set s;

int n;

int main() {

  NoType;

  cin >> n;
  ll m[n + 1] = {0};

  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      m[j]++;
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += (i * m[i]);
  }

  cout << ans;

  return 0;
}
Problem p02624 (C++)

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm = 1000000000;
ll MM = mm + 7;
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.141592653589793

int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  for (ll i = 1; i <= n; i++) {
    ll cnt = 0;
    for (ll j = 1; j <= sqrt(i); j++) {
      if (i % j == 0) {
        if (j == sqrt(i)) {
          cnt++;
        } else {
          cnt += 2;
        }
      }
    }
    sum += i * cnt;
  }
  cout << sum << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm = 1000000000;
ll MM = mm + 7;
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.141592653589793

int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  for (ll i = 1; i <= n; i++) {
    ll m = n / i;
    sum += i * (1 + m) * m / 2;
  }
  cout << sum << endl;
}
Problem p02624 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int _max = 1e7 + 10;
const int mod = 1e9 + 7;
typedef long long ll;

ll a[_max];

int init() {

  for (int i = 1; i <= _max; i++) {
    int begin = i;
    while (1) {
      if (begin > _max) {
        break;
      }
      a[begin]++;
      begin = begin + i;
    }
  }
}

int main() {
  init();
  int n;
  cin >> n;
  ll he = 0;
  for (int i = 1; i <= n; i++) {
    he = he + a[i] * i;
  }
  cout << he << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int _max = 1e7 + 10;
const int mod = 1e9 + 7;
typedef long long ll;

ll a[_max];

void init() {

  for (int i = 1; i <= _max; i++) {
    int begin = i;
    while (1) {
      if (begin > _max) {
        break;
      }
      a[begin]++;
      begin = begin + i;
    }
  }
}

int main() {
  init();
  int n;
  cin >> n;
  ll he = 0;
  for (int i = 1; i <= n; i++) {
    he = he + a[i] * i;
  }
  cout << he << endl;
  return 0;
}
Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define SPEED                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pll pair<int, int>
#define ppll pair<pll, pll>
#define mod 1000000007
unsigned int bp(int n) // built_in_pop_count //
{
  unsigned int count = 0;
  while (n) {
    n &= (n - 1);
    count++;
  }
  return count;
}
int countDivisors(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;

      else
        cnt = cnt + 2;
    }
  }
  return cnt;
}
int32_t main() {
  SPEED;
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += i * countDivisors(i);
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define SPEED                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pll pair<int, int>
#define ppll pair<pll, pll>
#define mod 1000000007
unsigned int bp(int n) // built_in_pop_count //
{
  unsigned int count = 0;
  while (n) {
    n &= (n - 1);
    count++;
  }
  return count;
}
int countDivisors(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;

      else
        cnt = cnt + 2;
    }
  }
  return cnt;
}
int32_t main() {
  SPEED;
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += (i * (n / i) * (1 + n / i)) / 2;
  }
  cout << ans;
}
Problem p02624 (C++)

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

using namespace std;
using ll = long long;

class Osa_k {
private:
  int n;
  vector<int> factor;

public:
  // O(NloglogN)
  Osa_k(int _n) : n(_n) {
    factor.assign(n, 0);
    iota(factor.begin(), factor.end(), 0);
    for (int i = 2; i * i < n; i++) {
      if (factor[i] < i)
        continue;
      for (int j = i * i; j < n; j += i) {
        if (factor[j] == j)
          factor[j] = i;
      }
    }
  }

  // O(logV)
  map<int, int> sieve(int v) {
    map<int, int> ret;
    while (v != factor[v]) {
      ret[factor[v]]++;
      v /= factor[v];
    }
    if (v != 1)
      ret[v]++;
    return ret;
  }

  vector<int> divisor(int v) {}

  // O(N)
  vector<int> get_list() {
    vector<int> prime;
    for (int i = 2; i < n; i++)
      if (factor[i] == i)
        prime.emplace_back(i);
    return prime;
  }

  // O(1)
  bool is_prime(int v) {
    if (v <= 1)
      return false;
    return (factor[v] == v);
  }

} fact(1000001);

int main() {
  int n;
  cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    auto v = fact.sieve(i);
    ll ans = 1;
    for (auto j : v)
      ans *= j.second + 1;
    sum += ans * i;
  }
  cout << sum << endl;
}

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

using namespace std;
using ll = long long;

class Osa_k {
private:
  int n;
  vector<int> factor;

public:
  // O(NloglogN)
  Osa_k(int _n) : n(_n) {
    factor.assign(n, 0);
    iota(factor.begin(), factor.end(), 0);
    for (int i = 2; i * i < n; i++) {
      if (factor[i] < i)
        continue;
      for (int j = i * i; j < n; j += i) {
        if (factor[j] == j)
          factor[j] = i;
      }
    }
  }

  // O(logV)
  map<int, int> sieve(int v) {
    map<int, int> ret;
    while (v != factor[v]) {
      ret[factor[v]]++;
      v /= factor[v];
    }
    if (v != 1)
      ret[v]++;
    return ret;
  }

  vector<int> divisor(int v) {}

  // O(N)
  vector<int> get_list() {
    vector<int> prime;
    for (int i = 2; i < n; i++)
      if (factor[i] == i)
        prime.emplace_back(i);
    return prime;
  }

  // O(1)
  bool is_prime(int v) {
    if (v <= 1)
      return false;
    return (factor[v] == v);
  }

} fact(10000001);

int main() {
  int n;
  cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    auto v = fact.sieve(i);
    ll ans = 1;
    for (auto j : v)
      ans *= j.second + 1;
    sum += ans * i;
  }
  cout << sum << endl;
}
Problem p02624 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_one(i, n) for (int i = 1; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  int prime[n + 1];
  rep(i, n + 1) prime[i] = 0;
  for (int i = 2; i * i < n + 1; i++) {
    for (int j = i; j < n + 1; j += i) {
      if (prime[j] == 0)
        prime[j] = j / i;
    }
  }
  map<int, int> div[n + 1];
  for (int i = 2; i < n + 1; i++) {
    if (prime[i] == 0)
      div[i][i] = 1;
    else {
      int tmp = i / prime[i];
      div[i] = div[prime[i]];
      div[i][tmp] += 1;
    }
  }
  ll ans = 1;
  for (int i = 2; i < n + 1; i++) {
    int div_count = 1;
    for (auto itr = div[i].begin(); itr != div[i].end(); itr++) {
      // cout << "key=" << itr->first << " value=" << itr->second << endl;
      div_count *= itr->second + 1;
    }
    ans += i * div_count;
    // cout << "i=" << i << " div_count="<< div_count << endl << endl;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_one(i, n) for (int i = 1; i < n; i++)
using namespace std;
typedef long long ll;

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

Buggy submission (status: Time Limit Exceeded):
n = int(input())
ans = 0
for i in range(1, n + 1):
    for j in range(i, n + 1, i):
        ans += j
print(ans)


Fixed submission:
n = int(input())
ans = 0
for i in range(1, int(n**0.5) + 1):
    k = n // i
    ans += i * k * (k + 1) // 2
    if i != k:
        l = n // (i + 1)
        ans += i * (i + 1) * (k + l + 1) * (k - l) // 4
print(ans)
Problem p02624 (Python)

Buggy submission (status: Time Limit Exceeded):
def main():
    num = int(input())
    ans = 0

    for div in range(1, num + 1):
        for i in range(div, num + 1):
            if i % div == 0:
                ans += i

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    num = int(input())
    ans = 0

    for divisor in range(1, num + 1):
        quotient = num // divisor
        ans += (quotient + 1) * quotient * divisor // 2

    print(ans)


if __name__ == "__main__":
    main()
Problem p02624 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
# 愚直にやると約数の個数テーブルをO(NlogN)
print(sum(i * j for i in range(1, n + 1) for j in range(1, n // i + 1)))


Fixed submission:
n = int(input())

ans = 0
for a in range(1, n + 1):
    num = n // a
    ans += num * (num + 1) // 2 * a
print(ans)
Problem p02624 (Python)

Buggy submission (status: Time Limit Exceeded):
from numba import njit
import numpy as np


@njit("i8(i8)")
def solve(n):
    ans = 1
    res = np.ones(n + 1, dtype=np.int64)
    for i in range(2, n + 1):
        res[i::i] += 1
        res[i] *= i
        ans += res[i]
    return ans


N = int(input())
print(solve(N))


Fixed submission:
from numba import njit
import numpy as np


@njit("i8(i8)")
def solve(n):
    ans = 1
    res = np.ones(n + 1, dtype=np.int64)
    for i in range(2, n + 1):
        for j in range(i, n + 1, i):
            res[j] += 1
        ans += i * res[i]
    return ans


N = int(input())
print(solve(N))
Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
#define yn                                                                     \
  { puts("Yes"); }                                                             \
  else {                                                                       \
    puts("No");                                                                \
  }
#define MAX_N 10000005

ll f[MAX_N] = {};
int main() {
  ll n;
  cin >> n;

  ll ans = 0;
  srep(i, 1, n + 1) {
    int ii = i;
    while (ii <= n) {
      ans += ii;
      // f[ii]++;
      // ii += i;
    }
  }

  /*
  srep(i,1,n+1){
      ll ii = i;
      ans += f[i] * ii;
  }
  */
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
#define yn                                                                     \
  { puts("Yes"); }                                                             \
  else {                                                                       \
    puts("No");                                                                \
  }
#define MAX_N 10000005

ll f[MAX_N] = {};
int main() {
  ll n;
  cin >> n;

  ll ans = 0;
  srep(i, 1, n + 1) {
    int ii = i;
    while (ii <= n) {
      ans += ii;
      // f[ii]++;
      ii += i;
    }
  }

  /*
  srep(i,1,n+1){
      ll ii = i;
      ans += f[i] * ii;
  }
  */
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<ll> v(1e9);
  for (int i = 1; i <= N; ++i) {
    for (int j = i; j <= N; j += i) {
      v[j]++;
    }
  }
  ll ans = 0;
  for (int i = 1; i <= N; ++i) {
    ans += i * (v[i]);
  }
  cout << ans << endl;
}


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

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = -1; i < (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = unsigned long long;

const ll MA = 10000000;

ll to[MA];

int main() {

  ll n;
  cin >> n;
  ll ans = 1;

  for (ll i = 2; i <= n; i++) {
    ll j = i;
    while (j + i <= n * 2) {
      to[j] += 1;
      j += i;
    }
    ans += i * (to[i] + 1);
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = -1; i < (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = unsigned long long;

const ll MA = 10000000;

ll to[MA];

int main() {

  ll n;
  cin >> n;
  ll ans = 1;

  for (ll i = 2; i <= n; i++) {
    ll j = i;
    while (j <= n) {
      to[j] += 1;
      j += i;
    }
    ans += i * (to[i] + 1);
  }

  cout << ans << endl;

  return 0;
}
Problem p02624 (C++)

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

using namespace std;
typedef long long llong;

#define MAX

int main() {
  int N;

  llong ans = 0;
  scanf("%lld", &N);

  for (llong x = 1; x <= N; x++) {
    llong n = N / x;
    ans += n * (2 * x + (n - 1) * x) / 2;
  }

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

Fixed submission:
#include <stdio.h>

using namespace std;
typedef long long llong;

#define MAX

int main() {
  llong N;

  llong ans = 0;
  scanf("%lld", &N);

  for (llong x = 1; x <= N; x++) {
    llong n = N / x;
    ans += n * (2 * x + (n - 1) * x) / 2;
  }

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

Buggy submission (status: Runtime Error):
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
#define INF ((1 << 30) - 1 + (1 << 30))
#define INFLL (1LL << 60)
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); ++i)
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;
}

int main() {
  const int sz = 1e6;
  vector<int> bkt(sz + 1, 2);
  bkt[0] = 0;
  bkt[1] = 1;
  for (int i = 2; i <= sz / 2; ++i) {
    for (int j = i * 2; j < sz + 1; j += i) {
      ++bkt[j];
    }
  }
  int N;
  cin >> N;
  ll ans = 0;
  rep(i, N + 1) { ans += (ll)i * bkt[i]; }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
#define INF ((1 << 30) - 1 + (1 << 30))
#define INFLL (1LL << 60)
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); ++i)
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;
}

int main() {
  const int sz = 1e7;
  vector<int> bkt(sz + 1, 2);
  bkt[0] = 0;
  bkt[1] = 1;
  for (int i = 2; i <= sz / 2; ++i) {
    for (int j = i * 2; j < sz + 1; j += i) {
      ++bkt[j];
    }
  }
  int N;
  cin >> N;
  ll ans = 0;
  rep(i, N + 1) { ans += (ll)i * bkt[i]; }
  cout << ans << endl;
  return 0;
}
Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#define ll long long

using namespace std;

int main() {
  int N;
  cin >> N;
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = i; i <= N; j += i) {
      ans += j;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#define ll long long

using namespace std;

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;
  return 0;
}
Problem p02624 (C++)

Buggy submission (status: Time Limit Exceeded):
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define PI 2 * acos(0.0)
#define maxn 10000005

int32_t main() {
  io;
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    int di = 0;
    for (int j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        di++;
        if (j != i / j)
          di++;
      }
    }
    ans += 1LL * i * di;
  }
  cout << ans;
  return 0;
}

Fixed submission:
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define PI 2 * acos(0.0)
#define maxn 10000005

int32_t main() {
  io;
  int n;
  cin >> n;
  ll ans = 0;
  vi din(n + 1, 1);
  for (int i = 2; i <= n; i++)
    for (int j = i; j <= n; j += i)
      din[j]++;
  for (int i = 1; i <= n; i++)
    ans += 1LL * i * din[i];
  cout << ans;
  return 0;
}
Problem p02624 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
ll pass() {
  ll k = 0, s = 0;
  int n;
  cin >> n;
  vector<int> a(n + 1, 0);

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j += i) {
      a[j]++;
    }
  }

  for (int i = 1; i <= n; i++) {
    s += (i * (ll)a[i]);
    ;
  }

  cout << s << endl;
}
int main() {
  ll n, m, k = 0, s = 0, l = 0, t = 0;
  pass();
}


Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
void pass() {
  ll k = 0, s = 0;
  int n;
  cin >> n;
  vector<int> a(n + 1, 0);

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j += i) {
      a[j]++;
    }
  }

  for (int i = 1; i <= n; i++) {
    s += (i * (ll)a[i]);
    ;
  }

  cout << s << endl;
}
int main() {
  ll n, m, k = 0, s = 0, l = 0, t = 0;
  pass();
}
Problem p02624 (Python)

Buggy submission (status: Time Limit Exceeded):
import numpy as np
from numba import njit

n = int(input())


@njit
def f(n):
    cnt = np.zeros(n + 1, np.int32)
    for i in range(1, n + 1):
        cnt[i::i] += 1

    return (cnt * np.arange(n + 1)).sum()


ans = f(n)
print(ans)


Fixed submission:
import numpy as np
from numba import njit

n = int(input())


@njit
def f(n):
    cnt = np.zeros(n + 1, np.int16)
    for i in range(1, n + 1):
        cnt[i::i] += 1

    return (cnt * np.arange(n + 1)).sum()


ans = f(n)
print(ans)
Problem p02624 (C++)

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

#define ll long long

int main() {

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

  return 0;
}

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

#define ll long long

int main() {

  int N;
  cin >> N;
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ll c = N / i;
    ans += c * (c + 1) / 2 * i;
  }
  cout << ans;

  return 0;
}
Problem p02624 (C++)

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

int main() {
  ll N;
  cin >> N;
  ll x = 0;
  vector<ll> div(10000000000, 0);

  for (ll i = 1; i <= N; i++) {
    for (ll j = 1; i * j <= N; j++) {
      div[i * j]++;
    }
  }

  for (ll k = 1; k <= N; k++) {
    x += k * div[k];
  }
  cout << x << endl;
}

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

int main() {
  ll N;
  cin >> N;
  ll x = 0;
  vector<ll> div(10000000, 0);

  for (ll i = 1; i <= N; i++) {
    for (ll j = 1; i * j <= N; j++) {
      div[i * j]++;
    }
  }

  for (ll k = 1; k <= N; k++) {
    x += k * div[k];
  }
  cout << x << endl;
}