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

Buggy submission (status: Runtime Error):
/**
 *    created: 01.07.2020 21:04:51
 **/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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;
}
const int MOD = 1000000007;
// const int MOD = 998244353;
const long double pi = acos(-1.0);
const int INF = 1LL << 60;

signed main() {

  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int a, b;
  int cnt = 0;
  for (int i = a; i <= b; i++) {
    string s = to_string(i);
    if (s[0] == s[4] && s[1] == s[3])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
/**
 *    created: 01.07.2020 21:04:51
 **/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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;
}
const int MOD = 1000000007;
// const int MOD = 998244353;
const long double pi = acos(-1.0);
const int INF = 1LL << 60;

signed main() {

  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int a, b;
  cin >> a >> b;
  int cnt = 0;
  for (int i = a; i <= b; i++) {
    string s = to_string(i);
    if (s[0] == s[4] && s[1] == s[3])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p03416 (C++)

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //    ll x;
  //    x=1ll << 59;
  //    ll y=(1ll << 59) - 1ll;
  //    cout<<((double)(x)==(double)(x-1))<<endl;
  char a[5], b, c, d;
  ll x, y, s = 0;
  cin >> x >> y;
  for (int i = x; i <= y; i++) {
    sprintf(a, "%d", i);
    if (a[0] == a[4] && a[1] == a[3])
      s++;
  }
  cout << s << endl;
}


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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //    ll x;
  //    x=1ll << 59;
  //    ll y=(1ll << 59) - 1ll;
  //    cout<<((double)(x)==(double)(x-1))<<endl;
  char a[6], b, c, d;
  ll x, y, s = 0;
  cin >> x >> y;
  for (int i = x; i <= y; i++) {
    sprintf(a, "%d", i);
    if (a[0] == a[4] && a[1] == a[3])
      s++;
  }
  cout << s << endl;
}
Problem p03416 (C++)

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

int main() {
  int a, b, c;
  cin >> a >> b;
  c = 0;
  for (int i = a; i = b; i++) {
    if (!(i % 100 - i / 1000))
      c++;
  }
  cout << c << endl;
}

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

int main() {
  int a, b, c;
  cin >> a >> b;
  c = 0;
  for (int i = a; i <= b; i++) {
    if (i / 10000 == i % 10 && i / 10 % 10 == i / 1000 % 10)
      c++;
  }
  cout << c << endl;
}
Problem p03416 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << endl;
#define CFYN(n) cout << ((n) ? "YES" : "NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

int main(void) {
  IOS int a, b;
  cin >> a >> b;
  int ans = 0;
  FOR(i, a, b + 1) {
    string s = to_string(i);
    bool b = true;
    FOR(j, 1, 3) if (s[2 - i] = !s[2 + i]) b = false;
    if (b)
      ans++;
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << endl;
#define CFYN(n) cout << ((n) ? "YES" : "NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

int main(void) {
  IOS int a, b;
  cin >> a >> b;
  int ans = 0;
  FOR(i, a, b + 1) {
    string s = to_string(i);
    bool b = true;
    FOR(j, 1, 3) if (s[2 - j] != s[2 + j]) b = false;
    if (b)
      ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p03416 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int a, b, s;
  cin >> a >> b;
  int i = 0;
  for (s = a; i <= b; s++) {
    int t = s % 10, u = s / 10000, p = s / 10 % 10, q = s / 1000 % 10;
    if (t == u && p == q)
      i++;
  }
  cout << i << endl;
}


Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int a, b, s;
  cin >> a >> b;
  int i = 0;
  for (s = a; s <= b; s++) {
    int t = s % 10, u = s / 10000, p = s / 10 % 10, q = s / 1000 % 10;
    if (t == u && p == q)
      i++;
  }
  cout << i << endl;
}
Problem p03416 (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++)
#define ll long long int

int main(void) {
  ll A, B;
  cin >> A >> B;
  int x1, x2, y1, y2, sum = 0;

  while (A <= B) {
    /*
    //1
    x1 = A % 10;
    //5
    x2 = A / 10000;
    //2
    y1 = A % 10000 / 1000;
    //4
    y2 = A % 100 / 10;
    */
    if (A % 10 != 0 && A % 10 == A / 10000 &&
        A % 10000 / 1000 == A % 100 / 10) {
      sum++;
    }
  }

  cout << sum << endl;
}

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

int main(void) {
  ll A, B;
  cin >> A >> B;
  int x1, x2, y1, y2, sum = 0;

  while (A <= B) {
    /*
    //1
    x1 = A % 10;
    //5
    x2 = A / 10000;
    //2
    y1 = A % 10000 / 1000;
    //4
    y2 = A % 100 / 10;
    */
    if (A % 10 != 0 && A % 10 == A / 10000 &&
        A % 10000 / 1000 == A % 100 / 10) {
      sum++;
    }

    A++;
  }

  cout << sum << endl;
}
Problem p03416 (C++)

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

int main() {
  int a, b;
  cin >> a >> b;
  vector<int> x(5);
  int ans = 0;
  for (int i = a; i <= b; i++) {
    for (int j = 0; j < 5; j++) {
      x[j] = i % 10;
      i /= 10;
    }
    if (x[0] == x[4] && x[1] == x[3]) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  vector<int> x(5);
  int ans = 0;
  for (int i = a; i <= b; i++) {
    x[0] = i % 10;
    x[1] = i / 10 % 10;
    x[2] = i / 100 % 10;
    x[3] = i / 1000 % 10;
    x[4] = i / 10000 % 10;
    if (x[0] == x[4] && x[1] == x[3]) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03416 (C++)

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

using namespace std;
int N, K;

int main() {
  cin >> N >> K;
  int ans = 0;
  for (int i = N; i <= K; i++) {
    int a = i % 10;
    i /= 10;
    int b = i % 10;
    i /= 100;
    int c = i % 10;
    i /= 10;
    int d = i % 10;
    if (a == d && b == c) {
      ans++;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
int N, K;

int main() {
  cin >> N >> K;
  int ans = 0;
  for (int j = N; j <= K; j++) {
    int i = j;
    int a = i % 10;
    i /= 10;
    int b = i % 10;
    i /= 100;
    int c = i % 10;
    i /= 10;
    int d = i % 10;
    if (a == d && b == c) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03416 (C++)

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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i, a, b) for (int i = a; i < b; i++)
#define ren(i, a, b) for (int i = a; i >= b; i--)

#define ll long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi vector<int>
#define pii pair<int, int>
#define piii pair<pair<int, int>, int>
#define all(v) v.begin(), v.end()

int mod = 1000000007;
const int N = 1005;

// gcd
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
bool pal(int x) {

  deque<int> q;
  while (x > 0) {
    int r = x % 10;
    q.push_back(r);
  }
  while (q.size() > 1) {
    int a = q.front();
    int b = q.back();
    q.pop_back();
    q.pop_front();
    if (a != b)
      return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int a, b;
  cin >> a >> b;
  int ans = 0;
  for (int i = a; i <= b; i++) {
    if (pal(i))
      ans++;
  }
  cout << ans << endl;
  return 0;
}


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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i, a, b) for (int i = a; i < b; i++)
#define ren(i, a, b) for (int i = a; i >= b; i--)

#define ll long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi vector<int>
#define pii pair<int, int>
#define piii pair<pair<int, int>, int>
#define all(v) v.begin(), v.end()

int mod = 1000000007;
const int N = 1005;

// gcd
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
bool pal(int x) {

  deque<int> q;
  while (x > 0) {
    int r = x % 10;
    q.push_back(r);

    x /= 10;
  }
  while (q.size() > 1) {
    int a = q.front();
    int b = q.back();
    q.pop_back();
    q.pop_front();
    if (a != b)
      return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int a, b;
  cin >> a >> b;
  int ans = 0;
  for (int i = a; i <= b; i++) {
    if (pal(i))
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03416 (C++)

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

int main() {
  int a, b;
  string n;
  cin >> a >> b;

  int cnt = 0;
  for (int i = a; i <= b; ++i) {
    if (n.at(0) == n.at(4) && n.at(1) == n.at(3)) {
      ++cnt;
    }
  }
  cout << cnt << endl;
}


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

int main() {
  int a, b;
  string n;
  cin >> a >> b;

  int cnt = 0;
  for (int i = a; i <= b; ++i) {
    n = to_string(i);
    if (n.at(0) == n.at(4) && n.at(1) == n.at(3)) {
      ++cnt;
    }
  }
  cout << cnt << endl;
}
Problem p03416 (C++)

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

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  for (int x = A; x <= B; x++) {
    int x1, x2, x3, x4, x5;
    x1 = x % 10;
    x /= 10;
    x2 = x % 10;
    x /= 10;
    x3 = x % 10;
    x /= 10;
    x4 = x % 10;
    x /= 10;
    x5 = x;
    if (x1 == x5 && x2 == x4)
      ans++;
  }
  cout << ans << endl;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  for (int a = 1; a < 10; a++) {
    for (int b = 0; b < 10; b++) {
      for (int c = 0; c < 10; c++) {
        int s = a * 10001 + b * 1010 + c * 100;
        if (A <= s && s <= B)
          ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p03416 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, sum = 0;
  string N;
  cin >> A >> B;
  for (int i = 0; i < B - A + 1; i++) {
    N = A + i;
    if (N.at(0) == N.at(4) && N.at(1) == N.at(3)) {
      sum++;
    }
  }
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, sum = 0;
  string N;
  cin >> A >> B;
  for (int i = 0; i < B - A + 1; i++) {
    N = std::to_string(A + i);
    if (N.at(0) == N.at(4) && N.at(1) == N.at(3)) {
      sum++;
    }
  }
  cout << sum << endl;
}
Problem p03416 (C++)

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

using namespace std;

int main() {
  int a, b, ans = 0, s, s2, l, l2;

  scanf("%d %d", &a, &b);

  for (int i = a; i <= b; i++) {
    l = i % 10;
    i /= 10;
    l2 = i % 10;
    i /= 100l;
    s2 = i % 10;
    i /= 10;
    s = i % 10;

    if (s == l && s2 == l2) {
      ans++;
    }
  }

  printf("%d", ans);
}

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

using namespace std;

int main() {
  int a, b, ans = 0, s, s2, l, l2;

  scanf("%d %d", &a, &b);

  for (int i = a; i <= b; i++) {
    l = i % 10;
    l2 = i / 10 % 10;
    s2 = i / 1000 % 10;
    s = i / 10000 % 10;

    if (s == l && s2 == l2) {
      ans++;
    }
  }

  printf("%d", ans);
}
Problem p03416 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  for (int i = A; i <= B; i++) {
    string S = to_string(i);
    int n = S.size();
    bool b = true;
    for (int j = 0; j < n / 2; j++) {
      if (S.at(j) != S.at(n - i - 1)) {
        b = false;
        break;
      }
    }
    if (b)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  for (int i = A; i <= B; i++) {
    string S = to_string(i);
    int n = S.size();
    bool b = true;
    for (int j = 0; j < n / 2; j++) {
      if (S.at(j) != S.at(n - j - 1)) {
        b = false;
        break;
      }
    }
    if (b)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03417 (C++)

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> v(n, vector<ll>(m));
  ll sum = (n - 2) * (m - 2);
  if (n == 1 && m == 1) {
    cout << 1 << endl;
    return 0;
  } else if (n == 1 || m == 1) {
    cout << max(n, m) - 2 << endl;
    return 0;
  } else {
    cout << sum << endl;
  }
}

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

int main() {
  ll n, m;
  cin >> n >> m;
  ll sum = (n - 2) * (m - 2);
  if (n == 1 && m == 1) {
    cout << 1 << endl;
    return 0;
  } else if (n == 1 || m == 1) {
    cout << max(n, m) - 2 << endl;
    return 0;
  } else {
    cout << sum << endl;
  }
}
Problem p03417 (C++)

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

using namespace std;

long long n, m, ans;

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int s = 0;
      if (i - 1 > 0 && j - 1 > 0)
        s++;
      if (i - 1 > 0)
        s++;
      if (i - 1 > 0 && j + 1 <= m)
        s++;
      if (j - 1 > 0)
        s++;
      if (j + 1 <= m)
        s++;
      if (i + 1 <= n && j - 1 > 0)
        s++;
      if (i + 1 <= n)
        s++;
      if (i + 1 <= n && j + 1 <= m)
        s++;
      if (s % 2 == 0)
        ans++;
    }
  cout << ans;
}

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

using namespace std;

long long n, m, ans;

int main() {
  cin >> n >> m;
  if (n == 1 && m == 1)
    cout << 1;
  else if (n == 1)
    cout << m - 2;
  else if (m == 1)
    cout << n - 2;
  else if (n == 2 || m == 2)
    cout << 0;
  else
    cout << n * m - 2 * n - 2 * m + 4;
}
Problem p03417 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int int64_t
#define ALL(a) (a).begin(), (a).end()
signed main() {
  int N, M;
  cin >> N >> M;
  vector<bitset<1000000002>> A(M + 2);
  REP(i, 1, M) {
    REP(j, 1, N) {
      A[i - 1].flip(j - 1);
      A[i - 1].flip(j);
      A[i - 1].flip(j + 1);
      A[i].flip(j - 1);
      A[i].flip(j);
      A[i].flip(j + 1);
      A[i + 1].flip(j - 1);
      A[i + 1].flip(j);
      A[i + 1].flip(j + 1);
    }
  }
  int ans = 0;
  REP(i, 1, M) {
    A[i].reset(0);
    A[i].reset(N + 1);
    ans += A[i].count();
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int int64_t
#define ALL(a) (a).begin(), (a).end()
signed main() {
  int N, M;
  cin >> N >> M;
  int X = N - 2, Y = M - 2;
  if (X < 0)
    X = 1;
  if (Y < 0)
    Y = 1;
  cout << X * Y << endl;
}
Problem p03417 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, m;
ll direction[8][2] = {{1, 0},  {0, 1},   {0, -1}, {-1, 0},
                      {-1, 1}, {-1, -1}, {1, -1}, {1, 1}};
bool valid(ll a, ll b) {
  if (a >= 1 && a <= n && b >= 1 && b <= m)
    return true;
  else
    return false;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //    ll x;
  //    x=1ll << 59;
  //    ll y=(1ll << 59) - 1ll;
  //    cout<<((double)(x)==(double)(x-1))<<endl;
  ll x = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ll s = 1;
      for (int k = 0; k < 8; k++) {
        ll a = i + direction[k][0];
        ll b = j + direction[k][1];

        if (valid(a, b))
          s++;
      }
      if (s & 1)
        x++;
    }
  }
  cout << x;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, m;
ll direction[8][2] = {{1, 0},  {0, 1},   {0, -1}, {-1, 0},
                      {-1, 1}, {-1, -1}, {1, -1}, {1, 1}};
bool valid(ll a, ll b) {
  if (a >= 1 && a <= n && b >= 1 && b <= m)
    return true;
  else
    return false;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //    ll x;
  //    x=1ll << 59;
  //    ll y=(1ll << 59) - 1ll;
  //    cout<<((double)(x)==(double)(x-1))<<endl;
  ll x = 0;
  cin >> n >> m;
  ll c = n, d = m;
  n = min(c, d);
  m = max(c, d);
  if (n == 1 && m == 1)
    cout << 1 << endl;
  else if (n == 1)
    cout << m - 2 << endl;
  else
    cout << (ll)((ll)(n * m) - (ll)(2ll * n) - (ll)(2ll * m) + 4ll) << endl;
}
Problem p03417 (C++)

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<vi> vec(n + 2, vi(m + 2, 0));
  rep(i, n) rep(j, m) rep(k, 3) rep(l, 3) vec[i + k - 1][j + l - 1]++;
  ll ans = 0;
  rep(i, n) rep(j, m) if (vec[i + 1][j + 1] % 2 == 1) ans++;
  cout << ans << endl;
  return 0;
}

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

int main() {
  ll n, m;
  cin >> n >> m;
  if (n == 1 && m == 1)
    cout << 1 << endl;
  else if (n == 1)
    cout << m - 2 << endl;
  else if (m == 1)
    cout << n - 2 << endl;
  else
    cout << (n - 2) * (m - 2) << endl;
  return 0;
}
Problem p03417 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
int rev(int a) {
  int p = 0;
  while (a != 0) {
    p += a % 10;
    p *= 10;
    a /= 10;
  }
  return p / 10;
}
bool pallin(int a) {
  if (a == rev(a))
    return true;
  else
    return false;
}
int32_t main() {
  int a, b;
  cin >> a >> b;
  if (a <= 3 || b <= 3) {
    int arr[5][5];
    for (int i = 0; i < 5; ++i)
      for (int j = 0; j < 5; ++j)
        arr[i][j] = -1;
    for (int i = 1; i <= a; ++i)
      for (int j = 1; j <= b; ++j)
        arr[i][j] = 1;
    for (int i = 1; i <= a; ++i)
      for (int j = 1; j <= b; ++j) {
        int l1, l2;
        l1 = i - 1;
        l2 = j - 1;
        for (int ii = 0; ii < 3; ++ii)
          for (int jj = 0; jj < 3; ++jj)
            if (arr[ii + l1][jj + l2] != -1)
              arr[ii + l1][jj + l2] = 1 - arr[ii + l1][jj + l2];
      }
    int z = 0;
    for (int i = 0; i < 5; ++i)
      for (int j = 0; j < 5; ++j)
        if (arr[i][j] == 0)
          z++;
    cout << z;
  } else {
    int ans = a * b;
    ans -= 2 * a;
    ans -= 2 * (b - 2);
    cout << ans;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
int rev(int a) {
  int p = 0;
  while (a != 0) {
    p += a % 10;
    p *= 10;
    a /= 10;
  }
  return p / 10;
}
bool pallin(int a) {
  if (a == rev(a))
    return true;
  else
    return false;
}
int32_t main() {
  int a, b;
  cin >> a >> b;
  if (a == 1 || b == 1) {
    if (a == 1 && b == 1)
      cout << "1"; // mistaken first time
    else
      cout << a + b - 3;
  } else {
    int ans = a * b;
    ans -= 2 * a;
    ans -= 2 * (b - 2);
    cout << ans;
  }
  return 0;
}
Problem p03417 (C++)

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<vector<int>> v(n, vector<int>(m, 0));
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m; j++) {
      v.at(i).at(j) ? v.at(i).at(j) = 0 : v.at(i).at(j) = 1;
      if (j - 1 >= 0) {
        v.at(i).at(j - 1) ? v.at(i).at(j - 1) = 0 : v.at(i).at(j - 1) = 1;
      }
      if (j + 1 < m) {
        v.at(i).at(j + 1) ? v.at(i).at(j + 1) = 0 : v.at(i).at(j + 1) = 1;
      }

      if (i - 1 >= 0) {
        v.at(i - 1).at(j) ? v.at(i - 1).at(j) = 0 : v.at(i - 1).at(j) = 1;
        if (j - 1 >= 0) {
          v.at(i - 1).at(j - 1) ? v.at(i - 1).at(j - 1) = 0
                                : v.at(i - 1).at(j - 1) = 1;
        }
        if (j + 1 < m) {
          v.at(i - 1).at(j + 1) ? v.at(i - 1).at(j + 1) = 0
                                : v.at(i - 1).at(j + 1) = 1;
        }
      }

      if (i + 1 < n) {
        v.at(i + 1).at(j) ? v.at(i + 1).at(j) = 0 : v.at(i + 1).at(j) = 1;
        if (j - 1 >= 0) {
          v.at(i + 1).at(j - 1) ? v.at(i + 1).at(j - 1) = 0
                                : v.at(i + 1).at(j - 1) = 1;
        }
        if (j + 1 < m) {
          v.at(i + 1).at(j + 1) ? v.at(i + 1).at(j + 1) = 0
                                : v.at(i + 1).at(j + 1) = 1;
        }
      }
    }
  }
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m; j++) {
      if (v.at(i).at(j) == 1) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}


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

int main() {
  ll n, m;
  cin >> n >> m;
  cout << abs((n - 2) * (m - 2)) << endl;
}
Problem p03417 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> matrix;
  matrix.resize(N + 10);
  for (ll i = 0; i <= N + 1; i++) {
    matrix[i].resize(M + 10);
    for (ll j = 0; j <= M + 1; j++) {
      matrix[i][j] = 0;
    }
  }

  for (ll i = 1; i <= N; i++) {
    for (ll j = 1; j <= M; j++) {
      matrix[i - 1][j - 1] += 1;
      matrix[i - 1][j] += 1;
      matrix[i - 1][j + 1] += 1;
      matrix[i][j - 1] += 1;
      matrix[i][j] += 1;
      matrix[i][j + 1] += 1;
      matrix[i + 1][j - 1] += 1;
      matrix[i + 1][j] += 1;
      matrix[i + 1][j + 1] += 1;
    }
  }
  ll count = 0;
  for (ll i = 1; i <= N; i++) {
    for (ll j = 1; j <= M; j++) {
      // cout << A[i][j] << endl;
      if (matrix[i][j] % 2 == 1)
        ++count;
    }
  }
  cout << count << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll N, M;
  cin >> N >> M;
  if (N == 1 && M == 1)
    cout << N << endl;
  else if (N == 1 || M == 1)
    cout << max(N, M) - 2 << endl;
  else
    cout << (N - 2) * (M - 2) << endl;
  return 0;
}
Problem p03418 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

int N, K;

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

  ll count = 0;
  FOR(left, K, N) {
    int over = left == 0 ? 0 : N - left;
    count += over;
    if (left * 2 >= N)
      continue;

    int x = N - left;
    FOR(i, left + 1, x + 1) { count += x / i; }
  }
  printf("%lld\n", count);
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

int N, K;

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

  ll count = 0;
  FOR(b, 1, N + 1) {
    int p = N / b;
    int r = N % b;
    int a_count = p * max(0, b - K) + max(0, r - K + 1);
    count += a_count;
  }
  if (K == 0) {
    int zero_a_count = N;
    count -= zero_a_count;
  }
  printf("%lld\n", count);
}
Problem p03418 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f

int main() {
  long long n, k;
  scanf("%lld%lld", &n, &k);
  if (k == 0) {
    printf("%lld\n", n * n);
  } else {
    long long sum = (n - k) * (n - k + 1) >> 1;
    for (int b = k + 1; b <= n; ++b) {
      for (int p = k; p <= b - 1; ++p) { // 枚举余数
        int t = (n - p) / b;
        if (t == 0) {
          break;
        }
        sum = sum + t;
      }
    }
    printf("%lld\n", sum);
  }
  // system("pause");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f

int main() {
  long long n, k;
  scanf("%lld%lld", &n, &k);
  if (k == 0) {
    printf("%lld\n", n * n);
  } else {
    long long sum = (n - k) * (n - k + 1) >> 1;
    for (int b = k + 1; b <= n; ++b) {
      for (int p = k; p <= b - 1; ++p) { // 枚举余数
        int t = (n - p) / b;
        if (t == 0) {
          break;
        }
        int li = n - t * b;
        li = min(li, b - 1);
        sum = sum + t * (li - p + 1);
        p = li;
      }
    }
    printf("%lld\n", sum);
  }
  // system("pause");
  return 0;
}
Problem p03418 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
template <class T, class U> inline void chmin(T &t, U f) {
  if (t > f)
    t = f;
}
template <class T, class U> inline void chmax(T &t, U f) {
  if (t < f)
    t = f;
}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX / 3
#define MAX_N 1000
ll n, k, i, j;
void solve() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  if (k == 0) {
    cout << n * n << endl;
    return;
  }
  ll ans = 0;
  repl(i, k + 1, n + 1) {
    ans += i - k;
    repl(j, k, i) ans += (n - j) / i;
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
template <class T, class U> inline void chmin(T &t, U f) {
  if (t > f)
    t = f;
}
template <class T, class U> inline void chmax(T &t, U f) {
  if (t < f)
    t = f;
}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX / 3
#define MAX_N 1000
ll n, k, i, j;
void solve() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  if (k == 0) {
    cout << n * n << endl;
    return;
  }
  ll ans = 0;
  repl(i, 1, n + 1) {
    ll m = n / i;
    ll r = n % i;
    ans += (m * MAX(0, i - k) + MAX(0, r - k + 1));
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
Problem p03418 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
ll n, k;
ll ans;

int main() {
  cin >> n >> k;
  if (!k)
    ans = n * n;
  else {
    ans += (1 + n - k) * (n - k) / 2;
    for (ll b = k + 1; b <= n; b++) { // 被模的数
      for (ll r = k; r < b; r++) {    // 枚举余数
        ll tmp = (n - r) / b;
        if (!tmp)
          break;
        int dd = min(r, b - 1);
        ans += tmp * (dd - r + 1);
        r = dd;
      }
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
ll n, k;
ll ans;

int main() {
  cin >> n >> k;
  if (!k)
    ans = n * n;
  else {
    ans += (1 + n - k) * (n - k) / 2;
    for (ll b = k + 1; b <= n; b++) { // 被模的数
      for (ll r = k; r < b; r++) {    // 枚举余数
        ll tmp = (n - r) / b;
        if (!tmp)
          break;
        ll dd = n - tmp * b;
        dd = min(dd, b - 1);
        ans += tmp * (dd - r + 1);
        r = dd;
      }
    }
  }
  cout << ans << endl;
}
Problem p03418 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  int count = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      if (i % j >= K)
        count++;
    }
  }
  cout << count << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  long long count = 0;
  int base;
  for (int i = K + 1; i <= N; i++) {
    count += ((N / i) * (i - K));
    if (N % i) {
      if (K == 0) {
        count += N % i;
      } else {
        count += max(0, (N % i - K + 1));
      }
    }
  }
  cout << count << endl;
}
Problem p03418 (C++)

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

int main() {
  long long n, k;
  cin >> n >> k;
  if (k == 0) {
    cout << n * n;
    return 0;
  }
  long long ans = 0;
  for (long long i = k + 1; i <= n; i++) {
    int ans_i = k;
    while (ans_i <= n) {
      for (int j = 0; j < i - k; j++) {
        if (j + ans_i <= n) {
          ans++;
        }
        // cout << j+ans_i << ' ' << i << endl;
      }
      ans_i += i;
    }
  }
  cout << ans;
}


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

int main() {
  long long n, k;
  cin >> n >> k;
  if (k == 0) {
    cout << n * n;
    return 0;
  }
  long long ans = 0;
  for (long long i = k + 1; i <= n; i++) {
    long long j = (n - k + i) / i;
    int x = (k + i * (j - 1) + i - k - 1 - n);
    ans += (i - k) * j - max(0, x);
  }
  cout << ans;
}
Problem p03418 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  long long ans = 0;
  for (int b = K + 1; b <= N; b++) {
    for (int k = K; k < b; k++) {
      ans += (N - k) / b;
      if (k != 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  long long ans = 0;
  for (int b = K + 1; b <= N; b++) {
    ans += (b - K) * (N / b);
    ans += max(0, N % b + 1 - K);
    if (K == 0) {
      ans--;
    }
  }
  cout << ans << endl;
}
Problem p03418 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
using namespace std;
const int MaxN = 1e5 / 2;

int main() {
  long long n, k, a, b, sum;
  long long ans;
  while (~scanf("%lld %lld", &n, &k)) {
    ans = 0;
    if (k == 0)
      ans = n * n;
    else {
      for (int i = k; i <= n; i++) {
        ans = ans + n - i;
        sum = i - i / 2;
        if (sum > k)
          ans += sum - k;
        for (int j = k + 1; j <= i / 2; j++) {
          if (i % j >= k) {
            ans++;
          }
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
using namespace std;
const int MaxN = 1e5 / 2;

int main() {
  long long n, k, a, b, sum;
  long long ans;
  while (~scanf("%lld %lld", &n, &k)) {
    ans = 0;
    if (k == 0)
      ans = n * n;
    else {
      /*	for(int i = k;i <= n;i++)
              {
                      ans = ans + n - i;
                      sum = i-i/2;
                      if(sum > k) ans += sum-k;
                      sum = i/2-i/3;
                      for(int j = k+1;j <= i/2;j++)
                      {
                              if(i%j>=k)
                              {
                                      ans++;
                              }
                      }
              }*/
      for (int i = k + 1; i <= n; i++) {
        ans += n / i * (i - k);
        sum = n % i - k + 1;
        if (sum > 0)
          ans += sum;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
Problem p03418 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <complex>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }
  for (ll i = k + 1; i <= n; k++) {
    ans += (i - k) * (n / i);
    ans += max((ll)0, (n % i) - (k - 1));
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <complex>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }
  for (ll i = k + 1; i <= n; i++) {
    ans += (i - k) * (n / i);
    ans += max((ll)0, (n % i) - (k - 1));
  }
  cout << ans << endl;

  return 0;
}
Problem p03418 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

int n, k;

void input() { cin >> n >> k; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  input();
  ll ans = 0;
  for (int b = k + 1; b <= n; ++b) {
    for (int a = k; a <= b; ++a) {
      if (a == 0)
        continue;
      if (a % b >= k)
        ans += 1 + (n - a) / b;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

int n, k;

void input() { cin >> n >> k; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  input();
  ll ans = 0;
  for (int b = 1; b <= n; ++b) {
    int p = n / b;
    int r = n % b;
    ans += p * max(0, b - k) + max(0, r - k + 1);
    ans -= max(0, 1 - k);
  }
  cout << ans << endl;
  return 0;
}
Problem p03418 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define IO                                                                     \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
int n, k;
int main() {
  IO;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  int n, k;
  cin >> n >> k;
  if (k == 0) {
    cout << 1ll * n * n;
    return 0;
  }
  ll res = 0;
  for (int b = k + 1; b <= n; b++) {
    int p = n / b;
    int r = n % b;
    res += 1ll * p * max(0, b - k) + 1ll * max(0, r - k + 1);
  }
  cout << res;
  return 0;
}


Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define IO                                                                     \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
int n, k;
int main() {
  IO;

  int n, k;
  cin >> n >> k;
  if (k == 0) {
    cout << 1ll * n * n;
    return 0;
  }
  ll res = 0;
  for (int b = k + 1; b <= n; b++) {
    int p = n / b;
    int r = n % b;
    res += 1ll * p * max(0, b - k) + 1ll * max(0, r - k + 1);
  }
  cout << res;
  return 0;
}
Problem p03418 (C++)

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

using namespace std;

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

  if (K == 0) {
    cout << 1LL * N * N << endl;
    return 0;
  }
  long long ans = 0LL;

  for (int b = K + 1; b <= N; ++b) {
    for (int a = 0; a <= N; ++a) {
      if (a % b == 0) {
        a += K - 1;
      } else {
        ans++;
      }
    }
  }

  cout << ans << endl;
}

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

using namespace std;

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

  if (K == 0) {
    cout << 1LL * N * N << endl;
    return 0;
  }
  long long ans = 0LL;

  for (int b = K + 1; b <= N; ++b) {
    ans += (N / b) * (b - K);
    if (N % b >= K) {
      ans += N % b + 1 - K;
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
using namespace std;
int N, K;
long long ans = 0;
int main() {
#ifdef LOACL
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  scanf("%d %d", &N, &K);
  for (int b = K + 1; b <= N; b++) {
    for (int a = 1; a <= N; a++)
      if (a % b >= K)
        ans++;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
int N, K;
long long ans = 0;
int main() {
#ifdef LOACL
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  scanf("%d %d", &N, &K);
  if (K == 0)
    ans = 1ll * N * N;
  else {
    for (int b = K + 1; b <= N; b++) {
      int x1 = b - K;
      int x2 = N / b;
      int k = N - x2 * b;
      if (k >= K)
        ans += k - K + 1;
      ans += x1 * x2;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03418 (C++)

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

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

  if (k == 0) {
    cout << 1ll * n * n;
    return 0;
  }

  ll count = 0;
  for (int b = k + 1; b <= n; b++) {
    int start = -1;
    int c = 0, ck = 0;
    int a;
    for (a = k; a <= n; a++) {
      if (start == -1) {
        start = a % b;
      } else if (start == a % b) {
        break;
      }
      c++;
      if (a % b >= k) {
        ck++;
      }
    }
    count += 1ll * (a - k + 1) * ck / c;
    for (; a <= n; a++) {
      if (a % b >= k) {
        count++;
      }
    }
  }
  cout << count;
  return 0;
}

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

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

  if (k == 0) {
    cout << 1ll * n * n;
    return 0;
  }

  ll count = 0;
  for (int b = k + 1; b <= n; b++) {
    count += max(0, (b - k) * (n / b));
    count += max(0, n % b - k + 1);
  }
  cout << count;
  return 0;
}
Problem p03418 (C++)

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

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

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

int main() {
  int N, K;
  cin >> N >> K;
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    int q = N / i;
    ans += (long long)q * max(0, i - K);
    ans += (long long)max(0, N - q * i - K + 1);
  }
  if (K == 0) {
    ans = (long long)N * N;
  }
  cout << ans << endl;
}
Problem p03418 (C++)

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

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

  int cnt = 0;
  for (int i = 1; i <= N; i++) {
    // i >= K -> ok
    if (i < K)
      continue;
    // j > i -> ok
    cnt += N - i;
    // abs(i-j)>=K
    for (int j = K; j < i; j++)
      if (i % j >= K)
        cnt++;
  }
  cout << cnt << endl;

  return 0;
}


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

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

  if (!K)
    return cout << 1LL * N * N << endl, 0;

  long long cnt = 0;
  for (int b = 1; b <= N; b++) {
    cnt += 1LL * N / b * max(0, b - K) + max(0, N % b - K + 1);
  }
  cout << cnt << endl;

  return 0;
}
Problem p03418 (C++)

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

typedef long long ll;

using namespace std;

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

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

typedef long long ll;

using namespace std;

int main() {
  int N, K, i, j;
  cin >> N >> K;
  ll ans = 0;
  for (int b = 1; b <= N; b++) {
    if (b > K) {
      ans += (N / b) * (b - K);
      int tmp = (N / b) * b;

      int last_num = N - tmp;

      if (last_num - K >= 0) {
        if (K == 0) {
          ans += last_num - K;
        } else {
          ans += last_num - K + 1;
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p03418 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
typedef vector<int> vi;
#define inf 1000000000
const int max_N = 1e5 + 10;
int n, k, tmp3;
ll ans = 0;
int main() {
  cin >> n >> k;
  if (k == 0) {
    cout << (ll)n * n << endl;
    return 0;
  }
  ans = (ll)n * n;
  ans -= (ll)n * k;
  for (int i = k + 1; i <= n; i++) {
    int tmp2 = n / i;
    ans -= (tmp2 * k);
    for (int j = 1 + tmp2 * i; j <= n; j++) {
      if (j % i < k)
        ans--;
      else if (j % i >= k)
        break;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
typedef vector<int> vi;
#define inf 1000000000
const int max_N = 1e5 + 10;
int n, k, tmp3;
ll ans = 0;
int main() {
  cin >> n >> k;
  if (k == 0) {
    cout << (ll)n * n << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    int p = n / i;
    int anum = p * max(0, i - k);
    int r = n - p * i;
    int rest = max(0, r - k + 1);
    ans += anum + rest;
  }
  cout << ans << endl;
  return 0;
}
Problem p03418 (C++)

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int ans = 0;
  for (long long int i = k + 1; i <= n; i++) {
    if (k == 0) {
      ans += n / i;
      long long int mod = min((n + i - 1) % i + 1, i - 1);
      if (i > 1)
        ans +=
            (((n + i - 1) / i) * mod + (((n + i - 1) / i - 1) * (i - mod - 1)));
    } else {
      int mod = min((n + i - k) % i + 1, i - k);
      ans +=
          ((n + i - k) / i) * (mod) + (((n + i - k) / i - 1) * (i - k - mod));
    }
  }
  cout << ans << endl;
}