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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
ll gcd(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
using namespace std;
int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  rep(x, k + 1) {
    rep(y, k + 1) {
      rep(z, k + 1) {
        if (x + y + z > s)
          break;
        if (x + y + z == s)
          ans++;
      }
    }
  }
  cout << ans;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
ll gcd(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
using namespace std;
int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  rep(x, k + 1) {
    rep(y, k + 1) {
      int z = s - x - y;
      if (0 <= z && z <= k)
        ans++;
    }
  }
  cout << ans;

  return 0;
}
Problem p03835 (C++)

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

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

  int ans = 0;
  for (int i = 0; i <= K; ++i) {
    for (int j = 0; j <= K; ++j) {
      for (int k = 0; k <= K; ++k) {
        if (i + j + k == S)
          ++ans;
      }
    }
  }

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


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

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

  int ans = 0;
  for (int i = 0; i <= K; ++i) {
    for (int j = 0; j <= K; ++j) {
      int tmp = S - (i + j);
      if (0 <= tmp && tmp <= K) {
        ++ans;
      }
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int k, s;
  cin >> k >> s;
  int cnt = 0;
  rep(i, k + 1) {
    rep(j, k + 1) {
      rep(z, k + 1) {
        if (s == i + j + z)
          cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Fixed submission:
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int k, s;
  cin >> k >> s;
  int cnt = 0;
  rep(i, k + 1) {
    rep(j, k + 1) {
      if (0 <= s - i - j && k >= s - i - j)
        cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p03835 (C++)

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

int main() {
  int K, S, ans = 0;
  cin >> K >> S;
  for (int X = 0; X <= K; X++) {
    for (int Y = 0; Y <= K; Y++) {
      for (int Z = 0; X <= K; Z++) {
        if (X + Y + Z == S)
          ans++;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int K, S, ans = 0;
  cin >> K >> S;
  for (int X = 0; X <= K; X++) {
    for (int Y = 0; Y <= K; Y++) {
      if (S - X - Y >= 0 && S - X - Y <= K)
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p03835 (C++)

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

const double PI = 3.141592653589793;

int main() {
  int S, K;
  cin >> K >> S;
  int cnt = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      for (int k = 0; k <= K; k++) {
        if (i + j + k == S)
          cnt++;
      }
    }
  }

  cout << cnt << endl;
  return 0;
}


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

const double PI = 3.141592653589793;

int main() {
  int S, K;
  cin >> K >> S;
  int cnt = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      int k = S - i - j;
      if (k >= 0 && k <= K)
        cnt++;
    }
  }

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

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

int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      if (x + y > s)
        break;
      for (int z = 0; z <= k; z++) {
        if (x + y + z == s)
          ans++;
        if (x + y + z > s)
          break;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      if (s - x - y <= k && x + y <= s)
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p03835 (C++)

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

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

  int count = 0;

  for (int X = 0; X <= K; X++) {
    for (int Y = 0; Y <= K; Y++) {
      for (int Z = 0; Z <= K; Z++) {
        if (X + Y + Z == S) {
          count++;
        }
      }
    }
  }

  cout << count << endl;
}

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

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

  int count = 0;

  for (int X = 0; X <= K; X++) {
    for (int Y = 0; Y <= K; Y++) {
      int Z = S - X - Y;
      if (Z >= 0 && Z <= K) {
        count++;
      }
    }
  }

  cout << count << endl;
}
Problem p03835 (C++)

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

int main() {
  int K, S;
  cin >> K >> S;
  int cnt = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      for (int z = 0; z <= K; z++) {
        if (x + y + z == S)
          cnt++;
      }
    }
  }
  cout << cnt << endl;
}

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

int main() {
  int K, S;
  cin >> K >> S;
  int cnt = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {

      if (S - x - y >= 0 && S - x - y <= K)
        cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p03835 (C++)

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

int main() {
  int k, s, sum = 0;
  cin >> k >> s;

  for (int x = 0; x <= k; x++) {
    if (x > s)
      break;
    for (int y = 0; y <= k; y++) {
      if ((x + y) > s)
        break;
      for (int z = 0; z <= k; z++) {
        if ((x + y + z) > s)
          break;
        if ((x + y + z) == s)
          sum++;
      }
    }
  }
  cout << sum << endl;
}


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

int main() {
  int k, s, sum = 0;
  cin >> k >> s;

  for (int x = 0; x <= k; x++) {
    if (x > s)
      break;
    for (int y = 0; y <= k; y++) {
      if ((x + y) > s)
        break;
      if ((s - (x + y)) <= k)
        sum++;
    }
  }
  cout << sum << endl;
}
Problem p03835 (C++)

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for (int i = a; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

void put_double(double obj) { printf("%.12f\n", obj); };

template <typename T> std::string to_string(const T &n) {
  std::ostringstream stm;
  stm << n;
  return stm.str();
}

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() {
  int K, S;
  cin >> K >> S;

  ll ans = 0;

  rep(X, K + 1) {
    rep(Y, K + 1) {
      rep(Z, K + 1) {
        if (X + Y + Z == S)
          ans++;
      }
    }
  }
  cout << ans << endl;
}


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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for (int i = a; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

void put_double(double obj) { printf("%.12f\n", obj); };

template <typename T> std::string to_string(const T &n) {
  std::ostringstream stm;
  stm << n;
  return stm.str();
}

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() {
  int K, S;
  cin >> K >> S;

  ll ans = 0;

  rep(X, K + 1) {
    rep(Y, K + 1) {
      if (S - X - Y >= 0 && S - X - Y <= K)
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p03835 (C++)

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

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

  int cnt = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      for (int m = 0; m <= K; m++) {
        if (m + i + j == S)
          cnt++;
      }
    }
  }

  cout << cnt << endl;

  return 0;
}

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

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

  int cnt = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      int m = S - (i + j);
      if (m + i + j == S && m <= K && m >= 0)
        cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}
Problem p03835 (C++)

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(vec) for (auto &i : vec)
#define vin(vec)                                                               \
  for (auto &i : vec)                                                          \
  cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main() {
  ll k, s;
  cin >> k >> s;
  ll ans = 0;
  rep(i, 0, k + 1) rep(j, 0, k + 1) rep(l, 0, k + 1) if (i + j + l == s) ans++;
  cout << ans << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(vec) for (auto &i : vec)
#define vin(vec)                                                               \
  for (auto &i : vec)                                                          \
  cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main() {
  ll k, s;
  cin >> k >> s;
  ll ans = 0;
  rep(i, 0, k + 1) rep(j, 0, k + 1) if (s - i - j >= 0 && s - i - j <= k) ans++;
  cout << ans << endl;
}
Problem p03835 (C++)

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

int main(void) {
  int K, s;
  cin >> K >> s;
  int ans = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      for (int k = 0; k <= K; k++) {
        if (i + j + k == s)
          ans = ans + 1;
      }
    }
  }
  cout << ans;
}

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

int main(void) {
  int K, s;
  cin >> K >> s;
  int ans = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      if (s - K <= i + j && i + j <= s)
        ans = ans + 1;
    }
  }
  cout << ans;
}
Problem p03835 (C++)

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

int main(void) {
  int K, S;
  int x, y, z;
  cin >> K >> S;
  int c = 0;
  for (x = 0; x < K + 1; x++) {
    for (y = 0; y < K + 1; y++) {
      for (z = 0; z < K + 1; z++) {
        if (x + y + z == S)
          c++;
      }
    }
  }
  cout << c << endl;
}

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

int main(void) {
  int K, S;
  int x, y, z;
  cin >> K >> S;
  int c = 0;
  for (x = 0; x < K + 1; x++) {
    for (y = 0; y < x + 1; y++) {
      for (z = 0; z < y + 1; z++) {
        if (x + y + z == S) {
          if (x != y & x != z & y != z)
            c += 6;
          else if (x == y & x == z & y == z)
            c += 1;
          else
            c += 3;
        }
      }
    }
  }
  cout << c << endl;
}
Problem p03835 (C++)

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

typedef long long ll;
using namespace std;

#define F first
#define S second
#define sqr(x) x *x
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define repit(i, n) for (auto it = n.begin(); it != n.end(); ++it)

const ll mod = 1000000007;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int lcm(int a, int b) { return abs(a * b) / gcd(a, b); }

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int x, y;
  cin >> x >> y;
  int cnt = 0;
  for (int i = 0; i <= x; ++i) {
    for (int j = 0; j <= x; ++j) {
      for (int z = 0; z <= x; ++z) {
        if ((i + j + z) == y)
          cnt++;
      }
    }
  }
  cout << cnt;
}

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

typedef long long ll;
using namespace std;

#define F first
#define S second
#define sqr(x) x *x
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define repit(i, n) for (auto it = n.begin(); it != n.end(); ++it)

const ll mod = 1000000007;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int lcm(int a, int b) { return abs(a * b) / gcd(a, b); }

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int x, y;
  cin >> x >> y;
  int cnt = 0;
  for (int i = 0; i <= x; ++i) {
    for (int j = 0; j <= x; ++j) {
      int z = y - i - j;
      if (0 <= z && z <= x && (z + i + j) == y)
        cnt++;
    }
  }
  cout << cnt;
}
Problem p03835 (C++)

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

using namespace std;

// typedefリスト
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<string> vstr;

int main(void) {
  int K, S, cou;
  cou = 0;
  cin >> K >> S;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      for (int k = 0; k <= K; k++) {
        if (i + j + k == S)
          cou++;
      }
    }
  }
  cout << cou << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

// typedefリスト
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<string> vstr;

int main(void) {
  int K, S, cou;
  cou = 0;
  cin >> K >> S;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      if (i + j <= S && S - j - i <= K)
        cou++;
    }
  }
  cout << cou << endl;
}
Problem p03835 (C++)

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

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return (gcd(b, a % b));
  }
}

int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  rep(i, k + 1) {
    rep(j, k + 1) {
      rep(h, k + 1) {
        if (i + j + h == s)
          ans++;
      }
    }
  }
  cout << ans << endl;
}

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

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return (gcd(b, a % b));
  }
}

int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = i; j <= k; j++) {
      for (int h = j; h <= k; h++) {
        if (i + j + h == s) {
          if (i == j && j == h)
            ans++;
          else if (i != j && j != h && h != i)
            ans += 6;
          else
            ans += 3;
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p03835 (C++)

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

int main() {
  int k, s;
  cin >> k >> s;
  int res = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      for (int l = 0; l <= k; l++) {
        if (i + j + l == s)
          res++;
      }
    }
  }
  cout << res << endl;
}


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

int main() {
  int k, s;
  cin >> k >> s;
  int res = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      if (s - i - j >= 0 && s - i - j <= k)
        res++;
    }
  }
  cout << res << endl;
}
Problem p03835 (C++)

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

int main() {
  int count = 0;
  int k, s;
  cin >> k >> s;
  for (int i = 0; i <= k; i++) {
    if (i > s)
      break;
    for (int j = 0; j <= k; j++) {
      if (i + j > s)
        break;
      for (int r = 0; r <= k; r++) {
        if (i + j + r == s) {
          count++;
        }
      }
    }
  }
  cout << count << endl;

  return 0;
}

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

int main() {
  int count = 0;
  int k, s;
  cin >> k >> s;
  for (int i = 0; i <= k; i++) {
    if (i > s)
      break;
    for (int j = 0; j <= k; j++) {
      if (i + j > s)
        break;
      if (s - i - j <= k)
        count++;
    }
  }
  cout << count << endl;

  return 0;
}
Problem p03835 (C++)

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

#define FAST_IO                                                                \
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
const int N = 2 * (1e5 + 1);
const int INF = 1e9 + 5;
const long long MOD = 1e9 + 7;

int32_t main() {
  FAST_IO;
  int k, s;
  cin >> k >> s;
  int c = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      for (int x = 0; x <= k; x++) {
        if ((i + j + x) == s)
          c++;
      }
    }
  }
  cout << c;
  return 0;
}


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

#define FAST_IO                                                                \
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
const int N = 2 * (1e5 + 1);
const int INF = 1e9 + 5;
const long long MOD = 1e9 + 7;

int32_t main() {
  FAST_IO;
  int k, s;
  cin >> k >> s;
  int c = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      // for (int x = 0; x <= k; x++) {
      int z = s - i - j;
      if (z >= 0 && z <= k)
        c++;
      //}
    }
  }
  cout << c;
  return 0;
}
Problem p03835 (C++)

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

int main() {
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for (int x = 0; x <= K; ++x) {
    for (int y = 0; y <= K; ++y) {
      for (int z = 0; z <= K; ++z) {
        if (x + y + z == S) {
          ans++;
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for (int x = 0; x <= K; ++x) {
    for (int y = 0; y <= K; ++y) {
      if (S - x - y <= K && S - x - y >= 0)
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03835 (C++)

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

int main() {
  int k, s;
  cin >> k >> s;
  int cou = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      for (int f = 0; f <= k; f++) {
        if (i + j + f == s) {
          cou++;
        }
      }
    }
  }
  cout << cou << endl;
}


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

int main() {
  int k, s;
  cin >> k >> s;
  int cou = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      if (s - i - j >= 0 && s - i - j <= k) {
        cou++;
      }
    }
  }
  cout << cou << endl;
}
Problem p03835 (C++)

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

int main() {
  int k, s, i, j, w;
  cin >> k >> s;
  int x, y, z, num = 0;
  for (i = 0; i <= k; i++) {
    x = i;
    for (j = 0; j <= k; j++) {
      y = j;
      for (w = 0; w <= k; w++) {
        z = w;
        if (x + y + z == s) {
          num++;
        }
      }
    }
  }
  cout << num;
}


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

int main() {
  int k, s, i, j, w;
  cin >> k >> s;
  int x, y, z, num = 0;
  for (i = 0; i <= k; i++) {
    x = i;
    for (j = 0; j <= k; j++) {
      y = j;
      z = s - x - y;
      if (z >= 0 && z <= k) {
        num++;
      }
    }
  }
  cout << num;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int k, s, x, y, z, i = 0;
  cin >> k >> s;
  for (x = 0; x <= k; x++) {
    for (y = 0; y <= k; y++) {
      for (z = 0; z <= k; z++) {
        if (x + y + z == s)
          i++;
      }
    }
  }
  cout << i << endl;
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int k, s, x, y, z, i = 0;
  cin >> k >> s;
  for (x = 0; x <= k; x++) {
    for (y = 0; y <= k; y++) {
      z = s - x - y;
      if (z >= 0 && z <= k)
        i++;
    }
  }
  cout << i << endl;
  return 0;
}
Problem p03835 (C++)

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

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

  int count = 0;

  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      for (int z = 0; z <= K; z++) {
        if (x + y + z == S)
          count++;
      }
    }
  }
  cout << count << endl;
}


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

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

  int count = 0;

  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int z = S - x - y;
      if (z < 0)
        break;
      if (z <= K)
        count++;
    }
  }
  cout << count << endl;
}
Problem p03835 (C++)

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

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

int main() {

  int k, s;
  cin >> k;
  cin >> s;
  int ans = 0;

  for (int a = 0; a <= k; ++a) {
    for (int b = 0; b <= k; ++b) {
      for (int c = 0; c <= k; ++c) {
        if (a + b + c == s) {
          ans++;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <cmath>
#include <fstream>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

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

int main() {

  int k, s;
  cin >> k;
  cin >> s;
  int ans = 0;

  for (int a = 0; a <= k; ++a) {
    for (int b = 0; b <= k; ++b) {
      int c = s - a - b;
      if (0 <= c && c <= k) {
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define CLEAR(v) memset(v, 0, sizeof(v))
#define MP(a, b) make_pair((a), (b))
#define ABS(a) ((a) > 0 ? (a) : -(a))
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)

int main() {
  int k, s;
  cin >> k >> s;
  int cnt = 0;
  int mi = min(k, s);
  for (int i = 0; i <= mi; i++) {
    int mj = min(k, s - i);
    for (int j = 0; j <= mj; j++) {
      int mk = min(k, s - i - j);
      for (int k = 0; k <= mk; k++) {
        if (i + j + k == s) {
          cnt++;
          // cout << i <<", "<<j<<", "<<k<<endl;
        }
      }
    }
  }
  cout << cnt << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define CLEAR(v) memset(v, 0, sizeof(v))
#define MP(a, b) make_pair((a), (b))
#define ABS(a) ((a) > 0 ? (a) : -(a))
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)

int main() {
  int k, s;
  cin >> k >> s;
  int cnt = 0;
  int mi = min(k, s);
  for (int i = 0; i <= mi; i++) {
    int mj = min(k, s - i);
    for (int j = 0; j <= mj; j++) {
      int z = s - i - j;
      if (0 <= z && z <= k) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}
Problem p03835 (C++)

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

int main() {
  int n, s, cnt = 0;
  cin >> n >> s;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= n; k++) {
        if (i + j + k == s)
          cnt++;
        else if (i + j + k > s)
          break;
      }
    }
  }
  cout << cnt;
}


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

int main() {
  int n, s, cnt = 0;
  cin >> n >> s;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      int sum = i + j;
      if (n >= s - sum and s - sum >= 0)
        cnt++;
    }
  }
  cout << cnt;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stack>
#include <vector>

using namespace std;
#define n_max 1000

int main() {
  int S, K;
  int cnt = 0;

  cin >> K >> S;

  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      for (int z = 0; z <= K; z++) {
        if (S == (x + y + z)) {
          cnt++;
        }
      }
    }
  }

  cout << cnt << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stack>
#include <vector>

using namespace std;
#define n_max 1000

int main() {
  int S, K;
  int cnt = 0;

  cin >> K >> S;

  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int z = S - x - y;
      if (0 <= z && z <= K) {
        cnt++;
      }
    }
  }

  cout << cnt << endl;

  return 0;
}
Problem p03835 (C++)

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

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

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

  int res = 0;
  rep(i, K + 1) {
    rep(j, K + 1) {
      rep(k, K + 1) {
        if (i + j + k == S)
          res++;
      }
    }
  }

  cout << res << endl;
  return 0;
}


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

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

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

  int res = 0;
  rep(i, K + 1) {
    rep(j, K + 1) {
      if (i + j > S)
        break;
      if (S - i - j <= K)
        res++;
    }
  }

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

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

int main() {
  int k, s, sum = 0;
  cin >> k >> s;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      for (int z = 0; z <= k; z++) {
        if (x + y + z == s) {
          sum++;
        }
      }
    }
  }
  cout << sum << endl;
}


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

int main() {
  int k, s, sum = 0;
  cin >> k >> s;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      if (k >= s - x - y && s - x - y >= 0) {
        sum++;
      }
    }
  }
  cout << sum << endl;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int K, S, sunadatyan = 0;
  cin >> K >> S;
  for (int i = 0; i <= K; i++) {
    for (int ii = 0; ii <= K; ii++) {
      for (int iii = 0; iii <= K; iii++) {
        if (i + ii + iii == S) {
          sunadatyan = sunadatyan + 1;
        }
      }
    }
  }
  cout << sunadatyan << endl;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int K, S, sunadatyan = 0;
  cin >> K >> S;
  for (int X = 0; X <= K; X++) {
    for (int Y = 0; Y <= K; Y++) {
      int Z = S - (X + Y);
      if (X + Y + Z == S && Z <= K && 0 <= Z) {
        sunadatyan = sunadatyan + 1;
      }
    }
  }
  cout << sunadatyan << endl;
}
Problem p03835 (C++)

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

int main() {
  int k, s, ans = 0;
  cin >> k >> s;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      for (int l = 0; l <= k; l++) {
        if (i + j + l != s)
          continue;
        else
          ans++;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int k, s, ans = 0;
  cin >> k >> s;
  int x = k, y = k, z = k;
  for (int i = k; i >= 0; i--) {
    for (int j = k; j >= 0; j--) {
      if (i + j > s || s - i - j > k)
        continue;
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03835 (C++)

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

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

int main() {
  // int n;
  // cin >> n;
  // int a[n];
  // sort(a, a + n);
  // int len = 0;
  // for (int i = 0; i < n; i++) cin >> a[i];
  // for (int i = 0; i < n; i++) {
  //     for (int j = i + 1; j < n; j++) {
  //         for (int k = j + 1; k < n; k++) {
  //             if (a[i] + a[j] > a[k]) len = max(len, a[i] + a[j] + a[k]);
  //         }
  //     }
  // }
  // cout << len << endl;

  // int n;
  // cin >> n;
  // int x[n], y[n];
  // double dist = 0.0;
  // for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
  // for (int i = 0; i < n; i++) {
  //     for (int j = i + 1; j < n; j++) {
  //         dist = max(dist, sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j],
  //         2)));
  //     }
  // }
  // cout << dist << endl;

  int k, s;
  cin >> k >> s;
  int count = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      for (int z = 0; z <= k; z++) {
        if (x + y + z == s)
          count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}

Fixed submission:
#include <math.h>

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

int main() {
  // int n;
  // cin >> n;
  // int a[n];
  // sort(a, a + n);
  // int len = 0;
  // for (int i = 0; i < n; i++) cin >> a[i];
  // for (int i = 0; i < n; i++) {
  //     for (int j = i + 1; j < n; j++) {
  //         for (int k = j + 1; k < n; k++) {
  //             if (a[i] + a[j] > a[k]) len = max(len, a[i] + a[j] + a[k]);
  //         }
  //     }
  // }
  // cout << len << endl;

  // int n;
  // cin >> n;
  // int x[n], y[n];
  // double dist = 0.0;
  // for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
  // for (int i = 0; i < n; i++) {
  //     for (int j = i + 1; j < n; j++) {
  //         dist = max(dist, sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j],
  //         2)));
  //     }
  // }
  // cout << dist << endl;

  int k, s;
  cin >> k >> s;
  int count = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      int z = s - x - y;
      if (z >= 0 && z <= k)
        count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p03835 (C++)

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

int main() {
  int K, S, ans = 0;
  cin >> K >> S;
  for (int i = 0; i <= K; ++i) {
    for (int j = 0; j <= K; ++j) {
      for (int k = 0; k <= K; ++k) {
        if (i + j + k == S) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int K, S, ans = 0;
  cin >> K >> S;
  for (int i = 0; i <= K; ++i) {
    for (int j = 0; j <= K; ++j) {
      int z = S - i - j;
      if (z >= 0 && z <= K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int K, S;
  cin >> K >> S;
  int X, Y, Z;
  int ans = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      for (int k = 0; k <= K; k++) {
        X = i;
        Y = j;
        Z = k;
        if ((X + Y + Z) == S) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int K, S;
  cin >> K >> S;
  int X, Y, Z;
  int ans = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      if (((S - i - j) >= 0) && ((S - i - j) <= K)) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p03835 (C++)

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

using namespace std;
int main(void) {
  int k, s;

  cin >> k >> s;

  int count = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      for (int l = 0; l <= k; l++) {
        if (i + j + l == s) {
          count++;
        }
      }
    }
  }

  cout << count << endl;

  return 0;
}

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

using namespace std;
int main(void) {
  int k, s;

  cin >> k >> s;

  int count = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      int z = s - i - j;
      if (0 <= z && z <= k) {
        count++;
      }
    }
  }

  cout << count << endl;

  return 0;
}
Problem p03835 (C++)

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

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

  int count = 0;

  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      for (int z = 0; z <= K; z++) {
        if (x + y + z == S)
          count++;
      }
    }
  }

  cout << count << endl;
}

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

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

  int count = 0;

  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      if ((S - x - y <= K) && (S - x - y >= 0))
        count++;
    }
  }

  cout << count << endl;
}
Problem p03835 (C++)

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

int main() {
  int s, k, ans = 0;
  cin >> k >> s;

  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      for (int z = 0; z <= k; z++) {
        if (x + y + z == s)
          ans++;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int s, k, ans = 0;
  cin >> k >> s;

  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      int z = s - (x + y);
      if ((z <= k) && (z >= 0))
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p03835 (C++)

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()

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

  int K, S;
  cin >> K >> S;
  ll ans = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      for (int k = 0; k <= K; k++) {
        if (i + j + k == S)
          ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()

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

  int K, S;
  cin >> K >> S;
  ll ans = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      if (0 <= S - i - j && S - i - j <= K)
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03835 (C++)

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

int main(void) {
  int K, S;
  cin >> K >> S;

  int count = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      for (int z = 0; z <= K; z++) {
        if (x + y + z == S)
          count++;
      }
    }
  }

  cout << count << endl;
}

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

int main(void) {
  int K, S;
  cin >> K >> S;

  int count = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      if (S - (x + y) >= 0 && S - (x + y) <= K)
        count++;
    }
  }

  cout << count << endl;
}
Problem p03835 (C++)

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

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

  int count = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      for (int u = 0; u <= k; u++) {
        if (i + j + u == s)
          count++;
      }
    }
  }

  cout << count << endl;

  return 0;
}

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

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

  int count = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      int u = s - i - j;
      if (0 <= u && u <= k)
        count++;
    }
  }

  cout << count << endl;

  return 0;
}
Problem p03835 (C++)

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

int main(int argc, char const *argv[]) {
  int s, k, cnt = 0;
  std::cin >> k >> s;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      for (int l = 0; l <= k; l++) {
        int ans = i + j + l;
        if (ans == s)
          cnt++;
      }
    }
  }

  std::cout << cnt << endl;
  return 0;
}


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

int main(int argc, char const *argv[]) {
  int s, k, cnt = 0;
  std::cin >> k >> s;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {

      int l = s - i - j;
      if (l >= 0 && l <= k)
        cnt++;
    }
  }

  std::cout << cnt << endl;
  return 0;
}
Problem p03835 (C++)

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

#define FOR(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define eFOR(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define SORT(i) sort((i).begin(), (i).end())
#define INF 1000000000

int main() {

  int k, s, ans = 0;
  cin >> k >> s;

  eFOR(x, k) {
    eFOR(y, k) {
      eFOR(z, k) {
        if (x + y + z == s)
          ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define eFOR(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define SORT(i) sort((i).begin(), (i).end())
#define INF 1000000000

int main() {

  int k, s, ans = 0;
  cin >> k >> s;

  eFOR(x, k) {
    eFOR(y, k) {
      if (s - x - y >= 0 && s - x - y <= k)
        ans++;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03835 (C++)

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

int main() {
  using namespace std;
  int k, x, y, z, s, sum;
  int counter = 0;

  cin >> k >> s;
  for (x = 0; x <= k; x++) {
    for (y = 0; y <= k; y++) {
      for (z = 0; z <= k; z++) {
        if (x + y + z == s) {
          counter++;
        }
      }
    }
  }
  cout << counter;
}

Fixed submission:
#include <iostream>

int main() {
  using namespace std;
  int k, x, y, z, s, sum;
  int counter = 0;

  cin >> k >> s;
  for (x = 0; x <= k; x++) {
    for (y = 0; y <= k; y++) {
      if (s - x - y <= k &&
          s - x - y >=
              0) { // for文で回すのが基本だが、それだと計算量が多すぎる。この条件式は少しトリッキーだが理解できるはず
                   // if(s - x - y <= k){
                   // x + y + z = sを満たす
                   // z = s - x - y
                   // 0 <= z <= k
                   // 0 <= s - x- y <= k
        // cout << x << " " << y << endl;
        counter++;
      }
    }
  }
  cout << counter;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, end) rep2(i, 0, (end))
#define rep2(i, beg, end) for (int i = (beg); i < (end); i++)
#define all(cont) begin(cont), end(cont)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll, ll> pii;
typedef pair<ll, string> pis;
typedef pair<string, ll> psi;

string gets(bool skipnewline);

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k, s;
  cin >> k >> s;
  int count = 0;
  int maxv = min(k + 1, s + 1);
  rep2(x, 0, maxv) {
    rep2(y, x, maxv) {
      int t = s - x - y;
      rep2(z, y, maxv) {
        if (z > t)
          break;
        if (z == t) {
          int k;
          if ((x != y) && (y != z))
            k = 6;
          else if ((x == y) && (y == z))
            k = 1;
          else
            k = 3;
          count += k;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}

string gets(bool skipToNextline) {
  if (skipToNextline)
    gets(false);
  const int LINE_MAX = 1024;
  char buf[LINE_MAX];
  cin.getline(buf, sizeof(buf));
  return buf;
}


Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, end) rep2(i, 0, (end))
#define rep2(i, beg, end) for (int i = (beg); i < (end); i++)
#define all(cont) begin(cont), end(cont)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll, ll> pii;
typedef pair<ll, string> pis;
typedef pair<string, ll> psi;

string gets(bool skipnewline);

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k, s;
  cin >> k >> s;
  int count = 0;
  rep2(x, 0, min(k + 1, s + 1)) {
    const int t = s - x;
    rep2(y, x, min(k + 1, t + 1)) {
      const int u = t - y;
      rep2(z, y, min(k + 1, u + 1)) {
        if (z == u) {
          int k;
          if ((x != y) && (y != z))
            k = 6;
          else if ((x == y) && (y == z))
            k = 1;
          else
            k = 3;
          count += k;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}

string gets(bool skipToNextline) {
  if (skipToNextline)
    gets(false);
  const int LINE_MAX = 1024;
  char buf[LINE_MAX];
  cin.getline(buf, sizeof(buf));
  return buf;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
/**
 *  author: mahfuzz
 *  created: 08.12.2019
 **/

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define debug(x) cout << #x << ':' << x << "\n";
//~ const double pi = 2*acos(0.0);
//~ const long long mod = 1e9+7;
//~ const int max_n = 1e6+5;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);

  int k, s;
  cin >> k >> s;
  int cnt = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      for (int l = 0; l <= k; l++) {
        if (i + j + l == s)
          cnt++;
      }
    }
  }

  cout << cnt << "\n";

  return 0;
}


Fixed submission:
/**
 *  author: mahfuzz
 *  created: 08.12.2019
 **/

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define debug(x) cout << #x << ':' << x << "\n";
//~ const double pi = 2*acos(0.0);
//~ const long long mod = 1e9+7;
//~ const int max_n = 1e6+5;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);

  int k, s;
  cin >> k >> s;
  int cnt = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      int z = s - i - j;
      if (z >= 0 && z <= k)
        cnt++;
    }
  }

  cout << cnt << "\n";

  return 0;
}
Problem p03835 (C++)

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

int main() {
  int k, s;
  cin >> k >> s;
  int count = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      for (int z = 0; z <= k; z++) {
        if (x + y + z == s)
          count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}

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

int main() {
  int k, s;
  cin >> k >> s;
  int count = 0;
  for (int x = 0; x <= k; x++) {
    if (x > s)
      continue;
    int ypz = s - x;
    if (ypz < k)
      count += (ypz + 1);
    else if (ypz >= k && ypz <= 2 * k)
      count += (k - (ypz - k) + 1);
    else
      count += 0;
  }
  cout << count << endl;
  return 0;
}
Problem p03835 (C++)

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, s, ans = 0;
  cin >> k >> s;
  for (int i = 0; i <= k; i++) {
    for (int m = 0; m <= k; m++) {
      if (s - i - m <= k && 0 <= s - i - m)
        ans++;
    }
  }
  cout << ans << endl;
}