prithivMLmods/Coder-Stat huggingface dataset:
Problem p03265 (Python)

Buggy submission (status: Runtime Error):
x1, y1, x2, y2 = map(int, input().split())
x = x1 - x2
y = y1 - y2
point3 = [x2 + y, y2 - x]
point4 = [x1 + y, y1 - x]
print(*[*point3, *point4], sep=" ")


Fixed submission:
x1, y1, x2, y2 = map(int, input().split())
x = x1 - x2
y = y1 - y2
point3 = [x2 + y, y2 - x]
point4 = [x1 + y, y1 - x]
print(*[point3[0], point3[1], point4[0], point4[1]], sep=" ")
Problem p03265 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
  int x[5], y[5], xx, yy;
  scanf("%d %d %d %d", &x[1], y[1], x[2], y[2]);
  xx = x[2] - x[1];
  xx = abs(xx);
  yy = y[2] - y[1];
  yy = abs(yy);

  if (x[1] >= x[2] && y[1] >= y[2]) {
    x[3] = x[2] + yy;
    y[3] = y[2] - xx;
    x[4] = x[3] + xx;
    y[4] = y[3] + yy;
  } else if (x[1] <= x[2] && y[1] <= y[2]) {
    x[3] = x[2] - yy;
    y[3] = y[2] + xx;
    x[4] = x[3] - xx;
    y[4] = y[3] - yy;
  } else if (x[1] <= x[2] && y[1] >= y[2]) {
    x[3] = x[2] + yy;
    y[3] = y[2] + xx;
    x[4] = x[3] - xx;
    y[4] = y[3] + yy;
  } else if (x[1] >= x[2] && y[1] <= y[2]) {
    x[3] = x[2] - yy;
    y[3] = y[2] - xx;
    x[4] = x[3] + xx;
    y[4] = y[3] - yy;
  }
  printf("%d %d %d %d\n", x[3], y[3], x[4], y[4]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
  int x[5], y[5], xx, yy;
  scanf("%d %d %d %d", &x[1], &y[1], &x[2], &y[2]);
  xx = x[2] - x[1];
  xx = abs(xx);
  yy = y[2] - y[1];
  yy = abs(yy);

  if (x[1] >= x[2] && y[1] >= y[2]) {
    x[3] = x[2] + yy;
    y[3] = y[2] - xx;
    x[4] = x[3] + xx;
    y[4] = y[3] + yy;
  } else if (x[1] <= x[2] && y[1] <= y[2]) {
    x[3] = x[2] - yy;
    y[3] = y[2] + xx;
    x[4] = x[3] - xx;
    y[4] = y[3] - yy;
  } else if (x[1] <= x[2] && y[1] >= y[2]) {
    x[3] = x[2] + yy;
    y[3] = y[2] + xx;
    x[4] = x[3] - xx;
    y[4] = y[3] + yy;
  } else if (x[1] >= x[2] && y[1] <= y[2]) {
    x[3] = x[2] - yy;
    y[3] = y[2] - xx;
    x[4] = x[3] + xx;
    y[4] = y[3] - yy;
  }
  printf("%d %d %d %d\n", x[3], y[3], x[4], y[4]);
  return 0;
}
Problem p03265 (C++)

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

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

int main() {
  int n, x;
  cin >> n >> x;
  int m[n], MIN = 1000000000;
  rep(i, n) {
    cin >> m[i];
    x -= m[i];
    MIN = min(MIN, m[i]);
  }
  int count = 0;
  while (x >= MIN) {
    count++;
    x -= MIN;
  }
  cout << n + count << endl;
  return 0;
}


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

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int x = c - a, y = d - b;

  cout << c - y << " " << d + x << " " << a - y << " " << b + x << endl;

  return 0;
}
Problem p03265 (Python)

Buggy submission (status: Runtime Error):
import numpy as np

x_1, y_1, x_2, y_2 = map(int, input().split())

P_1 = np.array([x_1, y_1])
P_2 = np.array([x_2, y_2])
vec_12 = P_2 - P_1
vec_13 = np.array([-vec_12[1], vec_12[0]])
P_3 = P_1 + vec_13
P_4 = P_2 + vec_13
print(P_3[0], P_3[1], P_4[1], P_4[2])


Fixed submission:
import numpy as np

x_1, y_1, x_2, y_2 = map(int, input().split())

P_1 = np.array([x_1, y_1])
P_2 = np.array([x_2, y_2])
vec_12 = P_2 - P_1
vec_13 = np.array([-vec_12[1], vec_12[0]])
P_3 = P_1 + vec_13
P_4 = P_2 + vec_13
print(P_4[0], P_4[1], P_3[0], P_3[1])
Problem p03265 (Python)

Buggy submission (status: Runtime Error):
def main():
    x1, y1, x2, y2 = map(int, input().split())

    ans = editorial(x1, y1, x2, y2)
    assert ans == twi(x1, y1, x2, y2)
    print(*ans)


def twi(x1, y1, x2, y2):
    """
    https://twitter.com/akensho/status/1035924165205716992
    https://twitter.com/hogeover30/status/1035903937830764545
    """
    import math

    cos90 = int(math.cos(math.pi / 2))
    sin90 = int(math.cos(math.pi / 2))

    x = x2 - x1
    y = y2 - y1
    x4 = x * cos90 - y * sin90 + x1
    y4 = x * sin90 + y * cos90 + y1

    x = x1 - x4
    y = y1 - y4
    x3 = x * cos90 - y * sin90 + x4
    y3 = x * sin90 + y * cos90 + y4

    return x3, y3, x4, y4


def editorial(x1, y1, x2, y2):
    x = x2 - x1
    y = y2 - y1

    x3 = x2 - y
    y3 = y2 + x
    x4 = x1 - y
    y4 = y1 + x

    return x3, y3, x4, y4


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    x1, y1, x2, y2 = map(int, input().split())

    ans = editorial(x1, y1, x2, y2)
    # assert ans == twi(x1, y1, x2, y2)
    print(*ans)


def twi(x1, y1, x2, y2):
    """
    https://twitter.com/akensho/status/1035924165205716992
    https://twitter.com/hogeover30/status/1035903937830764545
    """
    import math

    cos90 = int(math.cos(math.pi / 2))
    sin90 = int(math.cos(math.pi / 2))

    x = x2 - x1
    y = y2 - y1
    x4 = x * cos90 - y * sin90 + x1
    y4 = x * sin90 + y * cos90 + y1

    x = x1 - x4
    y = y1 - y4
    x3 = x * cos90 - y * sin90 + x4
    y3 = x * sin90 + y * cos90 + y4

    return x3, y3, x4, y4


def editorial(x1, y1, x2, y2):
    x = x2 - x1
    y = y2 - y1

    x3 = x2 - y
    y3 = y2 + x
    x4 = x1 - y
    y4 = y1 + x

    return x3, y3, x4, y4


if __name__ == "__main__":
    main()
Problem p03266 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define lint long long
#define REP(i, x, n) for (lint i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (lint i = n - 1; i >= 0; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main() {
  lint n, k;
  cin >> n >> k;
  lint zero = n / k;
  lint half = n / (k / 2) - zero;
  lint ans = zero * zero * zero + (half * half * half) * (k % 2 == 0);
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define lint long long
#define REP(i, x, n) for (lint i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (lint i = n - 1; i >= 0; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main() {
  lint n, k;
  cin >> n >> k;
  lint zero = n / k;
  lint ans = pow(zero, 3);
  if (k % 2 == 0) {
    lint half = n / (k / 2) - zero;
    ans += pow(half, 3);
  }
  cout << ans << endl;
  return 0;
}
Problem p03266 (C++)

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int main() {
  ll n, k;
  cin >> n >> k;
  V<ll> sum(n);
  for (int i = 1; i <= n; i++)
    sum[i % k]++;
  ll ans = 0;
  for (int a = 0; a < k; a++) {
    ll b = (k - a) % k;
    ll c = (k - a) % k;
    if ((b + c) % k != 0)
      continue;
    ans += sum[a] * sum[b] * sum[c];
  }
  cout << ans << endl;
}


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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int main() {
  ll n, k;
  cin >> n >> k;
  V<ll> sum(k);
  for (int i = 1; i <= n; i++)
    sum[i % k]++;
  ll ans = 0;
  for (int a = 0; a < k; a++) {
    ll b = (k - a) % k;
    ll c = (k - a) % k;
    if ((b + c) % k != 0)
      continue;
    ans += sum[a] * sum[b] * sum[c];
  }
  cout << ans << endl;
}
Problem p03266 (C++)

Buggy submission (status: Time Limit Exceeded):
//
// Created by Takaaki Hirano on 2018/09/01.
//
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <unordered_map>
#include <vector>

using namespace std;
int N, K;
long long ans = 0;

void solve() {
  unordered_map<long long, long long> mp;
  for (int i = 1; i <= N; ++i) {
    mp[i % K] = mp[i % K] + 1;
  }
  for (auto mppair : mp) {
    for (auto mppari2 : mp) {
      if ((mppair.first + mppari2.first) % K == 0) {
        for (auto mppair3 : mp) {
          if ((mppair.first + mppair3.first) % K == 0 &&
              (mppari2.first + mppair3.first) % K == 0) {
            ans += mppair.second * mppari2.second * mppair3.second;
          }
        }
      }
    }
  }

  printf("%lli\n", ans);
}

int main() {
  cin >> N >> K;
  solve();
  return 0;
}


Fixed submission:
//
// Created by Takaaki Hirano on 2018/09/01.
//
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <unordered_map>
#include <vector>

using namespace std;
int N, K;
long long ans = 0;

void solve() {
  unordered_map<long long, long long> mp;
  // あまりを保持しておく
  for (int i = 1; i <= N; ++i)
    mp[i % K]++;

  // 全てのaに対して
  for (int a = 1; a <= N; ++a) {
    // aに対するb, cのあまり（等しくなる）
    int b = (K - a % K) % K;
    int c = (K - a % K) % K;

    // 場合の数を数えるためにあまりの場合の数を求める．
    if ((b + c) % K == 0)
      ans += mp[b] * mp[c];
  }

  printf("%lli\n", ans);
}

int main() {
  cin >> N >> K;
  solve();
  return 0;
}
Problem p03266 (C++)

Buggy submission (status: Runtime Error):
/*
 * atcoder/abc108_2nd/c.cpp
 */

// C++ 14
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring> // memset
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for (int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

/*
 * aを決める
 * a % K = 0の場合)  a + b, a + cよりb % K, c % Kである必要がある
 * a % K != 0の場合) b = K - a, c = K - a
 */
int N, K;
int counter[100100] = {0};
void solve() {
  cin >> N >> K;
  loop(a, 1, N + 1) { counter[a % K]++; }

  ll count = 0;
  loop(a, 0, K) {
    int bK = ((K - a) + K) % K;
    int cK = ((K - a) + K) % K;
    count += ((bK + cK) % K == 0) * counter[a] * counter[bK] * counter[cK];
  }
  cout << count << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Fixed submission:
/*
 * atcoder/abc108_2nd/c.cpp
 */

// C++ 14
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring> // memset
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for (int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

/*
 * aを決める
 * a % K = 0の場合)  a + b, a + cよりb % K, c % Kである必要がある
 * a % K != 0の場合) b = K - a, c = K - a
 */
int N, K;
ll counter[200100] = {0};
void solve() {
  cin >> N >> K;
  loop(a, 1, N + 1) { counter[a % K]++; }

  ll count = 0;
  loop(a, 0, K) {
    int bK = ((K - a) + K) % K;
    int cK = ((K - a) + K) % K;
    count += ((bK + cK) % K == 0) * counter[a] * counter[bK] * counter[cK];
  }
  cout << count << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}
Problem p03266 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define int long long
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> pint;

signed main() {
  int N, K;
  cin >> N >> K;

  int ans = 0;
  for (int a = 1; a <= N; a++)
    for (int b = 1; b <= N; b++)
      for (int c = 1; c <= N; c++) {
        if ((a + b) % K == 0 and (b + c) % K == 0 and (c + a) % K == 0)
          ans++;
      }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define int long long
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> pint;

signed main() {
  int N, K;
  cin >> N >> K;

  int ans = (N / K) * (N / K) * (N / K);
  if (K % 2 == 0) {
    ans += ((N + K / 2) / K) * ((N + K / 2) / K) * ((N + K / 2) / K);
  }
  cout << ans << endl;
}
Problem p03266 (C++)

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

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, k;
  int t;
  cin >> n >> k;
  long long sum = 0;
  for (int i = 1; i <= k; i++) {
    int j = k - (i % k);
    long long b = (n - j + k) / k;
    for (t = k - (i % k); t <= n; t += k)
      if ((t + j) % k == 0) {
        long long d = (n - t + k) / k;
        sum += b * d;
        break;
      }
  }
  sum *= (n / k);
  for (int i = 1; i <= n % k; i++) {
    int j = k - (i % k);
    long long b = (n - j + k) / k;
    for (t = k - (i % k); t <= n; t += k)
      if ((t + j) % k == 0) {
        long long d = (n - t + k) / k;
        sum += b * d;
        break;
      }
  }
  cout << sum << endl;
}
Problem p03266 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  int M = 2 * N / K;
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= M; j++) {
      for (int k = 1; k < i + j; k++) {
        int n, m, l;
        n = i - j + k;
        m = i + j - k;
        l = -i + j + k;
        if ((n > 0) && (m > 0) && (l > 0) && (n <= M) && (m <= M) && (l <= M) &&
            ((K * n) % 2 == 0) && ((K * m) % 2 == 0) && ((K * l) % 2 == 0)) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  long ans;
  if (K % 2 == 1) {
    long a = N / K;
    ans = a * a * a;
  } else {
    long a = N / K;
    long b = (N + K / 2) / K;
    ans = a * a * a + b * b * b;
  }
  cout << ans << endl;
  return 0;
}
Problem p03266 (C++)

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N, K;
  cin >> N >> K;
  ll ans = 0;
  for (int k = K; k <= 2 * N; k += K) {
    dump(k, ans);
    for (int a = 1; a < k; a++) {
      int b = k - a;
      if (a < 0 || N < a)
        continue;
      if (b < 0 || N < b)
        continue;
      for (int i = K; i <= 2 * N; i += K) {
        int c = i - a;
        if (0 < c && c <= N && (b + c) % K == 0) {
          dump(k, a, b, c);
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N, K;
  cin >> N >> K;
  ll ans = 0;
  if (K % 2 == 1) {
    int cnt = N / K;
    ans += (ll)cnt * cnt * cnt;
  } else {
    int cnt = N / K;
    ans += (ll)cnt * cnt * cnt;
    int cnt2 = (N + K / 2) / K;
    ans += (ll)cnt2 * cnt2 * cnt2;
    dump(cnt, cnt2);
  }
  cout << ans << endl;
  return 0;
}
Problem p03266 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  if (k == 1) {
    ans = n * n * n;
    cout << ans << endl;
    return 0;
  }
  for (ll i = 1; i <= n; i++) {
    ll j;
    ll ibai = i / k;
    j = k - (i - k * ibai);
    ll l = k - j;
    if (l == 0)
      l += k;
    while (j <= n) {
      ll copy = n - l;
      if ((i + l) % k != 0)
        break;
      ll cnt = copy / k + 1;
      ans += cnt;
      j += k;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  if (k == 1) {
    ans = n * n * n;
    cout << ans << endl;
    return 0;
  }
  for (ll i = 1; i <= n; i++) {
    ll j;
    ll ibai = i / k;
    j = k - (i - k * ibai);
    ll l = k - j;
    if (l == 0)
      l += k;
    ll lcopy = n - l;
    if ((i + l) % k != 0)
      continue;
    ll lcnt = lcopy / k + 1;
    ll jcopy = n - j;
    ll jcnt = jcopy / k + 1;
    ans += lcnt * jcnt;
  }
  cout << ans << endl;
}
Problem p03266 (C++)

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n, k;
  cin >> n >> k;
  ll ans = 0;
  for (int a = 1; a <= n; ++a) {
    int b_mod = k - a % k;
    for (int b = b_mod; b <= n; b += k) {
      int c_mod = k - b % k;
      if (c_mod != b_mod)
        continue;
      for (int c = c_mod; c <= n; c += k) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n, k;
  cin >> n >> k;
  ll ans = 0;
  for (int a = 1; a <= n; ++a) {
    int mod = (k - a % k) % k;
    if ((2 * mod) % k != 0)
      continue;
    ll comb = (n - mod) / k;
    if (mod != 0)
      comb++;
    ans += comb * comb;
  }
  cout << ans << endl;
  return 0;
}
Problem p03266 (C++)

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

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>

#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

#define all(v) v.begin(), v.end()

#define sortAl(v) sort(all(v))
#define sortAlr(v)                                                             \
  sort(v.begin(), v.end());                                                    \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)

template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  ll n, k;
  cin >> n >> k;

  ll a[20000] = {};
  rep(i, k) {
    a[i] = n / k;
    if (i != 0 && i <= n % k) {
      a[i]++;
    }
  }

  ll ans = a[0] * a[0] * a[0];
  if (k % 2 == 0) {
    ans += a[k / 2] * a[k / 2] * a[k / 2];
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>

#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

#define all(v) v.begin(), v.end()

#define sortAl(v) sort(all(v))
#define sortAlr(v)                                                             \
  sort(v.begin(), v.end());                                                    \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)

template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  ll n, k;
  cin >> n >> k;

  ll a[200000] = {};
  rep(i, k) {
    a[i] = n / k;
    if (i != 0 && i <= n % k) {
      a[i]++;
    }
  }

  ll ans = a[0] * a[0] * a[0];
  if (k % 2 == 0) {
    ans += a[k / 2] * a[k / 2] * a[k / 2];
  }

  cout << ans << endl;

  return 0;
}
Problem p03266 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n, K;
  while (cin >> n >> K) {
    int sum = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = K - i % K; j <= n; j = j + K) {
        for (int k = K - i % K; k <= n; k = k + K) {
          if ((j + k) % K == 0) {
            sum++;
          }
        }
      }
    }
    cout << sum << endl;
  }
  return 0;
}


Fixed submission:
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n, K;
  while (cin >> n >> K) {
    long long sum = 0;
    long long t = 0;
    if (K & 1) {
      t = n / K;
      sum += t * t * t;
    } else {
      t = n / K;
      sum += t * t * t;
      t = (n + K / 2) / K;
      sum += t * t * t;
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p03266 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  int n, K;
  cin >> n >> K;
  int ans = 0;
  vector<pair<int, pair<int, int>>> P;
  for (int z = K; z <= n * 2; z += K) {
    for (int i = 1; i < z, i <= n; i++) {
      int j = z - i;
      // cout << "i:" << i << " j:" << j << endl;
      if (j == 0)
        break;
      if (j > n)
        continue;
      else {
        int k = K - (i % K);
        if ((j + k) % K == 0) {
          ans++;
          // cout << "z:" << z << " i:" << i << " j:" << j << " k:" << k <<
          // endl;
          ans += ((n - k) / K);
          P.push_back(make_pair(i, make_pair(j, k)));
        }
      }
    }
  }

  // cout << "DEBUG" << endl;
  // for (int i = 0; i < P.size(); i++) {
  // 	cout << P[i].first << " " << P[i].second.first << " " <<
  // P[i].second.second << endl;
  // }

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

Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  int n, K;
  cin >> n >> K;
  int ans = 0;
  vector<pair<int, pair<int, int>>> P;
  for (int i = 1; i <= n; i++) {
    int j = K - (i % K);
    // cout << "i:" << i << " j:" << j << endl;
    if (j == 0)
      break;
    if (j > n)
      continue;
    else {
      int k = K - (i % K);
      if ((j + k) % K == 0) {
        // cout << "i:" << i << " j:" << j << " k:" << k << endl;
        ans += ((n - k) / K + 1) * ((n - j) / K + 1);
        // P.push_back(make_pair(i, make_pair(j, k)));
      }
    }
  }

  // cout << "DEBUG" << endl;
  // for (int i = 0; i < P.size(); i++) {
  // 	cout << P[i].first << " " << P[i].second.first << " " <<
  // P[i].second.second << endl;
  // }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, num, n) for (int i = num, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> mod_num(N, 0);
  REP(i, 1, N + 1) mod_num[i % K]++;

  ll ans = 0;
  rep(i, K) {
    ll a = i;
    ll b = (K - a) % K;
    ll c = (K - a) % K;

    if ((b + c) % K == 0) {
      ans += mod_num[a] * mod_num[b] * mod_num[c];
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, num, n) for (int i = num, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> mod_num(K, 0);
  REP(i, 1, N + 1) mod_num[i % K]++;

  ll ans = 0;
  rep(i, K) {
    ll a = i;
    ll b = (K - a) % K;
    ll c = (K - a) % K;

    if ((b + c) % K == 0) {
      ans += mod_num[a] * mod_num[b] * mod_num[c];
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03266 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

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

  vector<ll> num(N + 1, 0);
  ll ans = 0;
  FOR(i, 1, N + 1) { num[i % K]++; }
  REP(a, K) {
    if ((a + a) % K == 0) {
      ans += num[a] * num[a] * num[a];
    }
  }

  cout << ans << "\n";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

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

  vector<ll> num(K + 1, 0);
  ll ans = 0;
  FOR(i, 1, N + 1) { num[i % K]++; }
  REP(a, K) {
    if ((a + a) % K == 0) {
      ans += num[a] * num[a] * num[a];
    }
  }

  cout << ans << "\n";

  return 0;
}
Problem p03266 (C++)

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

using namespace std;

#define Rep(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()

#define ll long long

int main() {
  int N, K, ans = 0;
  cin >> N >> K;
  Rep(i, 1, N + 1) Rep(j, 1, N + 1) Rep(k, 1, N + 1) {
    if ((i + j) % K == 0 && (j + k) % K == 0 && (k + i) % K == 0) {
      ans++;
    }
  }

  cout << ans << endl;
}


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

using namespace std;

#define Rep(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()

#define ll long long

int main() {
  int n, k;
  cin >> n >> k;
  int count = 0;
  Rep(i, 1, n + 1) if (i % k == 0) count++;
  ll ans = pow(count, 3);
  count = 0;
  if (k % 2 == 0)
    Rep(i, 1, n + 1) if (i % k == k / 2) count++;
  ans += pow(count, 3);

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main() {
  long long N, K;
  cin >> N >> K;
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    int j = i;
    while (j > K) {
      j -= K;
    }
    if ((2 * j) % K == 0) {
      ans += (((-j + K) % K + N) / K) * (((-j + K) % K + N) / K);
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  long long N, K;
  cin >> N >> K;
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    int j = i % K;
    if ((2 * j) % K == 0) {
      ans += (((-j + K) % K + N) / K) * (((-j + K) % K + N) / K);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03268 (C++)

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> m(n, 0);
  for (ll i = 1; i <= n; ++i)
    m[i % k]++;
  ll ans = 0;
  rep(i, k) {
    ll b = (k - i) % k;
    ll c = (k - i) % k;
    if ((b + c) % k != 0)
      continue;
    ans += m[i] * m[b] * m[c];
  }
  cout << ans << endl;
  return 0;
}

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> m(k, 0);
  for (ll i = 1; i <= n; ++i)
    m[i % k]++;
  ll ans = 0;
  rep(i, k) {
    ll b = (k - i) % k;
    ll c = (k - i) % k;
    if ((b + c) % k != 0)
      continue;
    ans += m[i] * m[b] * m[c];
  }
  cout << ans << endl;
  return 0;
}
Problem p03268 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      f = -1;
  for (; isdigit(ch); ch = getchar())
    x = (x << 3) + (x << 1) + (ch ^ 48);
  return x * f;
}
const int maxn = 2e5 + 10;
int n, k;
int main() {
#ifndef ONLINE_JUDGE
  freopen("c.in", "r", stdin);
  freopen("c.out", "w", stdout);
#endif
  n = read(), k = read();
  int d = n / k, f = k / 2;
  ll ans = 1ll * d * d * d;
  if (!(k & 1)) {
    d = 0;
    while (f <= n)
      ++d, f += k;
    ans += 1ll * d * d * d;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      f = -1;
  for (; isdigit(ch); ch = getchar())
    x = (x << 3) + (x << 1) + (ch ^ 48);
  return x * f;
}
const int maxn = 2e5 + 10;
int n, k;
int main() {
  n = read(), k = read();
  int d = n / k, f = k / 2;
  ll ans = 1ll * d * d * d;
  if (!(k & 1)) {
    d = 0;
    while (f <= n)
      ++d, f += k;
    ans += 1ll * d * d * d;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03268 (Python)

Buggy submission (status: Runtime Error):
n, k = map(int, input().split())
print((n // k) ** 3 + (~k & 1) * (n // (k // 2) - n // k) ** 3)


Fixed submission:
n, k = map(int, input().split())
print((n // k) ** 3 + (~k & 1) * (n // -(-k // 2) - n // k) ** 3)
Problem p03268 (C++)

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

using namespace std;

typedef long long ll;
typedef vector<ll> v_ll;
typedef vector<vector<ll>> vv_ll;
typedef vector<pair<ll, ll>> vp_ll;
typedef pair<ll, ll> p_ll;

ll N, K;
int main() {
  cin >> N >> K;
  ll X = (N / (K / 2) + 1) / 2;
  ll Y = N / K;
  if (K % 2 == 0)
    cout << X * X * X + Y * Y * Y << endl;
  else
    cout << Y * Y * Y << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> v_ll;
typedef vector<vector<ll>> vv_ll;
typedef vector<pair<ll, ll>> vp_ll;
typedef pair<ll, ll> p_ll;

ll N, K;
int main() {
  cin >> N >> K;
  if (K == 1) {
    cout << N * N * N << endl;
    return 0;
  }
  ll X = (N / (K / 2) + 1) / 2;
  ll Y = N / K;
  if (K % 2 == 0)
    cout << X * X * X + Y * Y * Y << endl;
  else
    cout << Y * Y * Y << endl;
  return 0;
}
Problem p03268 (C++)

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

using namespace std;
typedef long long ll;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  ll n, k;
  cin >> n >> k;

  vector<ll> mods(min(k, n), 0);

  for (auto mod = 0; mod <= min(k, n); mod++) {
    mods[mod] = mod == 0 ? (n - mod) / k : (n - mod) / k + 1;
  }

  ll cnt = mods[0] * mods[0] * mods[0];
  if (k % 2 == 0 && k / 2 <= n) {
    cnt += mods[k / 2] * mods[k / 2] * mods[k / 2];
  }

  cout << cnt << endl;

  return 0;
}


Fixed submission:
#include "iostream"
#include "vector"

using namespace std;
typedef long long ll;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  ll n, k;
  cin >> n >> k;

  vector<ll> mods(min(k, n) + 1, 0);

  for (auto mod = 0; mod <= min(k, n); mod++) {
    mods[mod] = mod == 0 ? (n - mod) / k : (n - mod) / k + 1;
  }

  ll cnt = mods[0] * mods[0] * mods[0];
  if (k % 2 == 0 && k / 2 <= n) {
    cnt += mods[k / 2] * mods[k / 2] * mods[k / 2];
  }

  cout << cnt << endl;

  return 0;
}
Problem p03268 (C++)

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> num(n, 0);
  for (int i = 1; i <= n; i++)
    num[i % k]++;
  ll ans = 0;
  rep(i, k) {
    int a, b, c;
    a = i;
    b = (k - a) % k;
    c = (k - a) % k;
    if ((b + c) % k != 0)
      continue;
    ans += num[a] * num[b] * num[c];
  }
  cout << ans << endl;
}


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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> num(k, 0);
  for (int i = 1; i <= n; i++)
    num[i % k]++;
  ll ans = 0;
  rep(i, k) {
    int a, b, c;
    a = i;
    b = (k - a) % k;
    c = (k - a) % k;
    if ((b + c) % k != 0)
      continue;
    ans += num[a] * num[b] * num[c];
  }
  cout << ans << endl;
}
Problem p03268 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for (ll i = a; i < n; i++)
#define pb push_back
#define mp make_pair

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
const ll power = 49999;

ll n, k;
ll res;
ll m[200007];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  /*
  #ifndef ONLINE_JUDGE
          freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
  #endif
  */

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  cin >> n >> k;
  forn(i, 1, n + 1) { m[i % k]++; }
  forn(i, 0, k) {
    ll a = m[i];
    if ((i + i) % k == 0)
      res += a * a * a;
  }
  cout << res;
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for (ll i = a; i < n; i++)
#define pb push_back
#define mp make_pair

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
const ll power = 49999;

ll n, k;
ll res;
ll m[200007];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  /*
  #ifndef ONLINE_JUDGE
          freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
  #endif
  */

  cin >> n >> k;
  forn(i, 1, n + 1) { m[i % k]++; }
  forn(i, 0, k) {
    ll a = m[i];
    if ((i + i) % k == 0)
      res += a * a * a;
  }
  cout << res;
  return 0;
}
Problem p03268 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
ID: anonymo14
TASK: wormhole
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i, a, b) for (int i = a; i <= b; i++)

#define MOD 1000000007

void solve(int test_case) {
  int n, k;
  cin >> n >> k;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = k - (i % k); j <= n; j += k) {
      if (j == 0)
        continue;
      for (int m = k - (j % k); m <= n; m += k) {
        if (m == 0)
          continue;
        // if((i+m)%k==0&&(j+m)%k==0)ans++;
        if ((i + m) % k == 0)
          ans++;
      }
    }
  }
  cout << ans;
}

int main() {

  ////// FILE BASED IO////
  // freopen("wormhole.in", "r", stdin);
  // freopen("wormhole.out", "w", stdout);
  ///////////////

  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  // cin>>t;
  REP(i, 1, t) { solve(i); }
  return 0;
}


Fixed submission:
/*
ID: anonymo14
TASK: wormhole
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i, a, b) for (int i = a; i <= b; i++)

#define MOD 1000000007

void solve(int test_case) {
  int n, k;
  cin >> n >> k;
  ll ans = 0;
  if (k & 1) {
    ans = pow(n / k, 3);
  } else {
    ans = pow(n / k, 3);
    int cnt = 0;
    for (int i = k / 2; i <= n; i += k)
      cnt++;
    ans += pow(cnt, 3);
  }
  cout << ans;
}

int main() {

  ////// FILE BASED IO////
  // freopen("wormhole.in", "r", stdin);
  // freopen("wormhole.out", "w", stdout);
  ///////////////

  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  // cin>>t;
  REP(i, 1, t) { solve(i); }
  return 0;
}
Problem p03268 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<int, int> pii;
int n, K, tot;
int add;
int main() {
  cin >> n >> K;
  if (K % 2 == 0)
    add = K / 2;
  else
    add = K;
  // for(int i=add;i<=n;i+=add)
  // 	for(int j=add;j<=n;j+=add)
  // 		if((i+j)%K==0)
  // 			for(int k=add;k<=n;k+=add)
  // 				if((i+k)%K==0&&(j+k)%K==0)tot++;
  for (int i = add; i <= n; i += add)
    for (int j = i; j <= n; j += add)
      if ((i + j) % K == 0)
        for (int k = j; k <= n; k += add)
          if ((i + k) % K == 0 && (j + k) % K == 0) {
            if (i == j) {
              if (j == k)
                tot++;
              else
                tot += 3;
            } else if (j == k) {
              tot += 3;
            } else
              tot += 6;
          }
  cout << tot << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<int, int> pii;
int n, K, tot;
int add;
int main() {
  cin >> n >> K;
  if (K % 2 != 0) {
    int t = n / K;
    cout << 1LL * t * t * t << endl;
    return 0;
  } else {
    // if(n%K==0){
    // 	int x=n/K;
    // 	cout<<x*x*x*2<<endl;
    // }else{
    int x = n / K, y = (n + K / 2) / K;
    cout << 1LL * x * x * x + 1LL * y * y * y << endl;
    // }
  }
  return 0;
}
Problem p03268 (C++)

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

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

  vector<int> num(n, 0);

  for (int i = 1; i <= n; i++)
    num[i % k]++;
  long res = 0;
  for (int a = 0; a < k; a++) {
    int b = (k - a) % k;
    int c = (k - a) % k;
    if ((b + c) % k != 0)
      continue;
    res += num[a] * num[b] * num[c];
  }

  cout << res << endl;

  return 0;
}

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

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

  vector<long long> num(k, 0);

  for (int i = 1; i <= n; i++)
    num[i % k]++;
  long res = 0;
  for (int a = 0; a < k; a++) {
    int b = (k - a) % k;
    int c = (k - a) % k;
    if ((b + c) % k != 0)
      continue;
    res += num[a] * num[b] * num[c];
  }

  cout << res << endl;

  return 0;
}
Problem p03268 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i > b; i--)
#define vint vector<int>
#define vvint vector<vint>
#define ct(a) cout << a << endl
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

ll N, K, ans;

int main() {
  cin >> N >> K;

  FOR(i, 1, N + 1) {
    if (i * 2 % K != 0)
      continue;
    int mod = K - i % K;
    ll cur = 0;
    while (K * cur + mod <= N) {
      cur++;
    }
    ans += cur * cur;
  }

  ct(ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i > b; i--)
#define vint vector<int>
#define vvint vector<vint>
#define ct(a) cout << a << endl
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

ll N, K, ans;

int main() {
  cin >> N >> K;

  FOR(i, 1, N + 1) {
    if (i * 2 % K != 0)
      continue;
    ll mod = 0;
    if (i % K != 0)
      mod = K - i % K;
    ll cur = (N + mod) / K;
    ans += cur * cur;
  }

  ct(ans);
  return 0;
}
Problem p03268 (C++)

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

using namespace std;

#define int long long int
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define se second
#define fi first

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

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

inline int add(int x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
  return x;
}
inline int sub(int x, int y) {
  x -= y;
  if (x < 0)
    x += mod;
  return x;
}
inline int mul(int x, int y) { return ((x % mod) * (y % mod)) % mod; }
inline int power(int a, int b) {
  int x = 1;
  while (b) {
    if (b & 1)
      x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a) { return power(a, mod - 2); }

#undef int
int main() {
#define int long long int
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int n, k;
  cin >> n >> k;
  int x = 0, y = 0;
  for (int i = 1; i <= n; i++) {
    if (i % k == 0)
      x++;
    if (i % k == (k / 2))
      y++;
  }
  if (k & 1)
    cout << (x * x * x) << endl;
  else
    cout << (x * x * x + y * y * y) << endl;

  return 0;
}


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

using namespace std;

#define int long long int
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define se second
#define fi first

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

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

inline int add(int x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
  return x;
}
inline int sub(int x, int y) {
  x -= y;
  if (x < 0)
    x += mod;
  return x;
}
inline int mul(int x, int y) { return ((x % mod) * (y % mod)) % mod; }
inline int power(int a, int b) {
  int x = 1;
  while (b) {
    if (b & 1)
      x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a) { return power(a, mod - 2); }

#undef int
int main() {
#define int long long int

  int n, k;
  cin >> n >> k;
  int x = 0, y = 0;
  for (int i = 1; i <= n; i++) {
    if (i % k == 0)
      x++;
    if (i % k == (k / 2))
      y++;
  }
  if (k & 1)
    cout << (x * x * x) << endl;
  else
    cout << (x * x * x + y * y * y) << endl;

  return 0;
}
Problem p03268 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
long long n, k, ans, c[100005];
int main() {
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    c[i] = n / k;
    if (i >= 1 && i <= n % k)
      c[i]++;
  }
  for (int i = 0; i < k; i++) {
    if (2 * i % k == 0)
      ans += c[i] * c[i] * c[(k - i) % k];
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
long long n, k, ans, c[200005];
int main() {
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    c[i] = n / k;
    if (i >= 1 && i <= n % k)
      c[i]++;
  }
  for (int i = 0; i < k; i++) {
    if (2 * i % k == 0)
      ans += c[i] * c[i] * c[(k - i) % k];
  }
  cout << ans;
  return 0;
}