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

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

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

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

  cout << count << endl;
}

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

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

  ll count = 0;
  rep(i, K + 1) {
    rep(j, K + 1) {
      ll z = S - i - j;
      if (0 <= z && z <= K)
        count++;
    }
  }

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

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


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  int k, s, ans, x, y, z, count = 0;
  cin >> k >> s;
  for (x = 0; x <= k; x++) {
    for (y = 0; y <= k; y++) {
      int z = s - x - y;
      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;
  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 (x + y + z == s)
          cnt++;
      }
    }
  }

  cout << cnt << endl;
}


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

int main() {
  int k, s;
  int cnt = 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)
        cnt++;
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  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 <iostream>
using namespace std;
int main(void) {
  // Your code here!
  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) <= K && S - (X + Y) >= 0) {
        cnt++;
      }
    }
  }

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

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

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

  int ans;
  int count = 0;

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

  cout << count << endl;

  return 0;
}

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

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

  int ans;
  int count = 0;

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

  cout << count << endl;

  return 0;
}
Problem p03835 (C++)

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

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;

// container util
#define SORT(c) sort((c).begin(), (c).end())

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {

  int K, S;
  scanf("%d %d", &K, &S);

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

  printf("%d\n", ans);

  return 0;
}


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

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;

// container util
#define SORT(c) sort((c).begin(), (c).end())

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {

  int K, S;
  scanf("%d %d", &K, &S);

  int ans = 0;
  REP(x, K + 1) {
    REP(y, K + 1) {
      int z = S - (x + y);
      if (0 <= z and z <= K)
        ans++;
    }
  }

  printf("%d\n", ans);

  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;
  int X, Y, Z;
  for (X = 0; X <= K; X++) {
    for (Y = 0; Y <= K; Y++) {
      for (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 sum = X + Y;
      if (S - sum >= 0 && S - sum <= 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, count = 0;
  cin >> k >> s;
  if (s != 3 * k) {
    for (int i = k; i >= 0; i--) {
      for (int j = k; j >= 0; j--) {
        for (int l = k; l >= 0; l--) {
          // cout <<i<<j<<l<<endl;
          if (i + j + l == s) {
            count++;
          }
        }
      }
    }
  } else
    count++;
  cout << count;
}

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

int main() {
  int k, s, count = 0;
  cin >> k >> s;
  if (s != 3 * k) {
    for (int i = k; i >= 0; i--) {
      for (int j = k; j >= 0; j--) {
        // cout <<i<<j<<l<<endl;
        if (s - i - j >= 0 && s - i - j <= k) {
          count++;
        }
      }
    }
  } else
    count++;
  cout << count;
}
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 t = 0; t <= k; ++t) {
        if (i + j + t == 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 z = s - i - j;
      if (z >= 0 && z <= k) {
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}
Problem p03835 (C++)

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

using namespace std;
int main(int argc, char *argv[]) {
  int k, s, count = 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)
          count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
  int k, s, count = 0;
  ;
  cin >> k >> s;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      if (x + y <= s && s - x - y <= k)
        count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p03835 (C++)

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

int main() {
  int k, s, count = 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) {
          count++;
          break;
        }
      }
    }
  }

  cout << count << endl;
}

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

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

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

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

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

int main(void) {
  int k, s;
  int count = 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)
          count++;
      }
    }
  }

  cout << count << endl;

  return 0;
}


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

int main(void) {
  int k, s;
  int count = 0;

  cin >> k >> s;

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

  cout << count << endl;

  return 0;
}
Problem p03835 (C++)

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

#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to));
#define sort(a) sort(a.begin(), a.end())
using namespace std;

template <class T> void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

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 l = 0; l <= k; ++l) {
        if (i + j + l == s) {
          count++;
        }
      }
    }
  }

  cout << count << endl;
}

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

#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to));
#define sort(a) sort(a.begin(), a.end())
using namespace std;

template <class T> void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

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 l = s - i - j;
      if (0 <= l && l <= k) {
        count++;
      }
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef pair<int, int> P;
typedef pair<double, double> P_f;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define bitrep(bit, n) for (int bit = 0; bit <= (1 << n); bit++)
#define MAX 100100
#define MAX_N 200100
#define MAX_T 2001001
#define SENTINEL 20010010010
#define NIL -1
static const int INF = 1 << 29;
const ll INFTY = 1LL << 50;
const int MOD = 1e9 + 7;
int k, s;
int main() {
  cin >> k >> s;
  int count = 0;
  rep(x, k + 1) rep(y, k + 1) rep(z, k + 1) if (x + y + z == s) count++;
  cout << count << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef pair<int, int> P;
typedef pair<double, double> P_f;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define bitrep(bit, n) for (int bit = 0; bit <= (1 << n); bit++)
#define MAX 100100
#define MAX_N 200100
#define MAX_T 2001001
#define SENTINEL 20010010010
#define NIL -1
static const int INF = 1 << 29;
const ll INFTY = 1LL << 50;
const int MOD = 1e9 + 7;
int k, s;
int main() {
  cin >> k >> s;
  int count = 0;
  rep(x, k + 1) rep(y, k + 1) {
    int z = s - x - y;
    if (0 <= z && z <= k)
      count++;
  }

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

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

int K, S;
int count = 0;

void solve() {
  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)
          count++;
      }
    }
  }
}

int main() {
  cin >> K >> S;
  solve();
  cout << count << endl;
  return 0;
}

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

int K, S;
int count = 0;

void solve() {
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      if (0 <= S - i - j && S - i - j <= K)
        count++;
    }
  }
}

int main() {
  cin >> K >> S;
  solve();
  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 i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      for (int k = 0; k <= K; k++) {
        if (k >= 0 && (i + j + k) == 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 i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      if (0 <= S - i - j && S - i - j <= K)
        count++;
    }
  }
  cout << count << endl;
}
Problem p03835 (C++)

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

int main() {
  int K, S;
  cin >> K >> 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 <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
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++) {
      int k = S - i - j;
      if (0 <= k && k <= 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;
  cin >> K >> S;

  int count = 0;
  for (int x = 0; x < K + 1; x++) {
    for (int y = 0; y < K + 1; y++) {
      for (int z = 0; z < K + 1; 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;
typedef long long ll;

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

  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 << "\n";
}


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

using namespace std;
typedef long long ll;

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

  int k, s;
  cin >> k >> s;

  int res = 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)
        res++;
    }
  }

  cout << res << "\n";
}
Problem p03835 (C++)

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

using std::cin;
using std::cout;
using std::endl;

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) {
          break;
        }
        if (x + y + z == S) {
          ans++;
          break;
        }
      }
    }
  }

  cout << ans << endl;
}


Fixed submission:
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

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++) {
      int z = S - (x + y);
      if (z >= 0 && z <= K)
        ans++;
    }
  }

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

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

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 <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

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++) {
      int z = S - x - y;
      if (0 <= z && z <= K)
        ans++;
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define F(i, j, k) fill(i[0], i[0] + j * j, k)
#define P(p) cout << (p) << endl;
#define EXIST(s, e) ((s).find(e) != (s).end())
#define INF 1 << 25
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

int main() {
  int k, s;
  scanf("%d %d", &k, &s);
  int co = 0;

  rep(a, k + 1) {
    rep(b, k + 1) {
      rep(c, k + 1) {
        if (a + b + c == s)
          co++;
      }
    }
  }
  printf("%d\n", co);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define F(i, j, k) fill(i[0], i[0] + j * j, k)
#define P(p) cout << (p) << endl;
#define EXIST(s, e) ((s).find(e) != (s).end())
#define INF 1 << 25
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

int main() {
  int k, s;
  scanf("%d %d", &k, &s);
  int co = 0;

  rep(a, k + 1) {
    REP(b, a, k + 1) {
      REP(c, b, k + 1) {
        if (a + b + c == s) {
          if (a == b && b == c) {
            co++;
          } else if (a == b || b == c) {
            co += 3;
          } else {
            co += 6;
          }
        }
      }
    }
  }
  printf("%d\n", co);

  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++) {
      for (int z = 0; z <= k; z++) {
        if (s == x + y + z) {
          ans++;
        }
      }
    }
  }
  cout << ans;
}

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++) {
      int z = s - x - y;
      if (0 <= z && z <= k) {
        ans++;
      }
    }
  }
  cout << ans;
}
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++) {
        int A = x + y + z;
        if (A == S)
          ans++;
      }
    }
  }
  cout << ans;
}


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++) {
      int z = S - (x + y);
      if (not(0 <= z and z <= K))
        continue;
      else
        ans++;
    }
  }
  cout << ans;
}
Problem p03835 (C++)

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

int main(void) {
  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;
  return 0;
}

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

int main(void) {
  int K, S, ans = 0;
  cin >> K >> S;
  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>
#include <iostream>

using namespace std;

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

  int cnt = 0;
  for (int i = 0; i <= k; i++) {
    if (i > k)
      break;
    for (int j = 0; j <= k; j++) {
      if (j > k)
        break;
      for (int l = 0; l <= k; l++) {
        if (l > k)
          break;

        if (i + j + l == s)
          cnt++;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}

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

using namespace std;

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

  int cnt = 0;
  for (int i = 0; i <= k; i++) {
    if (i > k)
      break;
    for (int j = 0; j <= k; j++) {
      if (j > k)
        break;
      int z = s - i - j;
      if (0 <= z && z <= 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, count = 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)
          count++;
      }
    }
  }
  cout << count << endl;
}


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

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int count = 0;
  for (int q = 0; q <= a; q++) {
    for (int w = 0; w <= a; w++) {
      for (int e = 0; e <= a; e++) {
        if (q + w + e == b)
          count++;
      }
    }
  }
  cout << count << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int count = 0;
  for (int q = 0; q <= a; q++) {
    for (int w = 0; w <= a; w++) {
      if (b - q - w <= a && 0 <= b - q - w)
        count++;
    }
  }
  cout << count << endl;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
typedef long long ll;
using namespace std;

int main() {
  int K, S;
  cin >> K >> S;
  int x, y, z;
  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;
      }
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
typedef long long ll;
using namespace std;

int main() {
  int K, S;
  cin >> K >> S;
  int x, y, z;
  int ans = 0;

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

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

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n); // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define sz(a) int((a).size())
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repe(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define vsort(v) sort((v).begin(), (v).end())

// code
// ------------------------------------------------
int main() {

  int k, s;
  cin >> k >> s;

  int n = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      for (int z = 0; z <= k; z++) {
        int sum = x + y + z;
        if (sum == s)
          n++;
      }
    }
  }

  cout << n;

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n) {
  int s = 0;
  while (n) {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

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

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n); // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define sz(a) int((a).size())
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repe(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define vsort(v) sort((v).begin(), (v).end())

// code
// ------------------------------------------------
int main() {

  int k, s;
  cin >> k >> s;

  int n = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      int z = s - x - y;
      if ((0 <= z) && (z <= k)) {
        n++;
      }
    }
  }

  cout << n;

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n) {
  int s = 0;
  while (n) {
    s += n % 10;
    n = n / 10;
  }
  return s;
}
Problem p03835 (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++)
int main() {
  int K, S;
  cin >> K >> S;
  int count = 0;
  rep(i, K + 1) {
    rep(j, K + 1) {
      rep(k, K + 1) {
        if (i + j + k == S) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int K, S;
  cin >> K >> S;
  int count = 0;
  rep(i, K + 1) {
    rep(j, K + 1) {
      if (0 <= S - i - j && S - i - j <= 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, x = 0, y = 0, z = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      for (int k = 0; k <= K; k++) {
        int tmp = i + j + k;
        if (tmp == 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, z = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      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 <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <typeinfo>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  int K, S;
  cin >> K >> S;

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

  cout << cnt << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <typeinfo>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  int K, S;
  cin >> K >> S;

  int cnt = 0;
  for (int x = 0; x <= min(S, K); ++x) {
    for (int y = 0; y <= min(S - x, K); ++y) {
      int z = S - x - y;
      if (0 <= z and z <= 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(void) {
  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; z <= k; z++) {
        if (x + y + z == s)
          ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

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

int main() {
  int k, s;
  int 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 += 1;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int k, s;
  int 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 (0 <= z && z <= k)
        ans += 1;
    }
  }
  cout << ans << endl;
}
Problem p03835 (C++)

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

using namespace std;

int main() {

  int64_t K, S;
  cin >> K >> S;

  int64_t ans = 0;
  for (int64_t i = 0; i <= K; i++)
    for (int64_t j = 0; j <= K; j++)
      for (int64_t k = 0; k <= K; k++)
        if (i + j + k == S)
          ans++;

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main() {

  int64_t K, S;
  cin >> K >> S;

  int64_t ans = 0;
  for (int64_t i = 0; i <= K; i++)
    for (int64_t j = 0; j <= K; j++)
      if (S - i - j <= K && S - i - j >= 0)
        ans++;

  cout << ans << endl;

  return 0;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define print(x) cout << (x) << endl;
int main() {
  int K, S, count = 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)
          count++;
      }
    }
  }
  cout << count << endl;
}

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

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

int main() {
  long k, s;
  cin >> k >> s;
  long 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)
          break;
        else if (i + j + l == s) {
          ++cnt;
        }
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


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

int main() {
  long k, s;
  cin >> k >> s;
  long cnt = 0;
  for (int i = 0; i <= k; ++i) {
    for (int j = 0; j <= k; ++j) {
      long l = s - i - j;
      if (l <= k && l >= 0 && i + j + l == s) {
        ++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++) {
      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 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;
}
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 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 <bits/stdc++.h>
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++) {
      if (s - i - j >= 0 && s - i - j <= k) {
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}
Problem p03835 (C++)

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

#define Bye return 0
#define ll long long

void solve() {
  int k, s;
  cin >> k >> s;
  int cont = 0;
  for (int i = 0; i <= k; i++)
    for (int j = 0; j <= k; j++)
      for (int x = 0; x <= k; x++)
        cont += (i + j + x == s);

  cout << cont << endl;
}

int main() {
  solve();
  Bye;
}

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

#define Bye return 0
#define ll long long

void solve() {
  int k, s;
  cin >> k >> s;
  int cont = 0;
  for (int x = 0; x <= k; x++)
    for (int y = 0; y <= k; y++) {
      int z = s - x - y;
      cont += (z >= 0 && z <= k);
    }

  cout << cont << endl;
}

int main() {
  solve();
  Bye;
}
Problem p03835 (C++)

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

int main() {
  int k, s, cnt = 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)
          cnt++;
      }
    }
  }
  cout << cnt << endl;
}

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

int main() {
  int k, s, cnt = 0;
  ;
  cin >> k >> s;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      if (0 <= s - i - j && s - i - j <= 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, count;
  cin >> k >> s;
  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;
}

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

int main() {
  int k, s, count;
  cin >> k >> s;
  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>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define ci(n) cin >> n
#define co(n) cout << n << endl
using namespace std;

int main() {
  long a, b, c = 0;
  cin >> a >> b;
  rep(i, 0, a + 1) {
    rep(j, 0, a + 1) {
      rep(k, 0, a + 1) {
        if (i + j + k == b) {
          c++;
          break;
        }
      }
    }
  }
  co(c);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define ci(n) cin >> n
#define co(n) cout << n << endl
using namespace std;

int main() {
  long a, b, c = 0;
  cin >> a >> b;
  rep(i, 0, a + 1) {
    rep(j, 0, a + 1) {
      if (0 <= b - i - j && b - i - j <= a)
        c++;
    }
  }
  co(c);

  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 a = 0;
  for (int h = 0; h <= K; h++) {
    for (int i = 0; i <= K; i++) {
      for (int j = 0; j <= K; j++) {
        if (S == h + i + j)
          a++;
        else if (S < h + i + j)
          break;
      }
    }
  }
  cout << a << endl;
}


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

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(), x.end())
#define ALL(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main() {

  int K, S;

  cin >> K >> S;

  ll ct = 0;

  rep(i, K + 1) {
    rep(j, K + 1) {
      rep(k, K + 1) { ct += (i + j + k == S); }
    }
  }

  cout << ct << "\n";
}
//-----------------------------------
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Fixed submission:
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(), x.end())
#define ALL(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main() {

  int K, S;

  cin >> K >> S;

  ll ct = 0;

  rep(i, K + 1) {
    rep(j, K + 1) { ct += (i + j <= S and i + j >= S - K); }
  }

  cout << ct << "\n";
}
//-----------------------------------
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using vi = vector<int>;
using vs = vector<string>;
using gi = greater<int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define soao(c) sort((c).begin(), (c).end())       // 昇順
#define sodo(c) sort((c).begin(), (c).end(), gi()) // 降順
#define rev(c) reverse((c).begin(), (c).end())

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;
using lli = long long int;
using vi = vector<int>;
using vs = vector<string>;
using gi = greater<int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define soao(c) sort((c).begin(), (c).end())       // 昇順
#define sodo(c) sort((c).begin(), (c).end(), gi()) // 降順
#define rev(c) reverse((c).begin(), (c).end())

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 <iostream>
using namespace std;
long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w,
    x, y, z;
int main() {
  cin >> k >> s;
  for (i = 0; i <= k; i++) {
    for (j = 0; j <= k; j++) {
      for (a = 0; a <= k; a++) {
        if (i + j + a == s) {
          z++;
        }
      }
    }
  }
  cout << z << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w,
    x, y, z;
int main() {
  cin >> k >> s;
  for (i = 0; i <= k; i++) {
    for (j = 0; j <= k; j++) {
      if ((s - i - j <= k) && (s - i - j >= 0)) {
        z++;
      }
    }
  }
  cout << z << endl;
  return 0;
}
Problem p03835 (C++)

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

int main() {
  int K, S;
  scanf("%d%d", &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++;
      }
    }
  }

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

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

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

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

  printf("%d", ans);
  return 0;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n)                                                              \
  ;                                                                            \
  for (int i = 0; i < (n); i++)
#define chmin(a, b)                                                            \
  if ((a) > (b))                                                               \
    (a) = (b);
#define chmax(a, b)                                                            \
  if ((a) < (b))                                                               \
    (a) = (b);
#define vi vector<int>
int gcd(int a, int b) { /*a>=0,b>=0,￢(a=b=0)*/
  while (min(a, b) > 0) {
    if (a < b)
      swap(a, b);
    a = a % b;
  }
  return max(a, b);
}
int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int MOD = 1e9 + 7;
const int INF = 1e18 + 10;

/*----------------------------------------------*/

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n)                                                              \
  ;                                                                            \
  for (int i = 0; i < (n); i++)
#define chmin(a, b)                                                            \
  if ((a) > (b))                                                               \
    (a) = (b);
#define chmax(a, b)                                                            \
  if ((a) < (b))                                                               \
    (a) = (b);
#define vi vector<int>
int gcd(int a, int b) { /*a>=0,b>=0,￢(a=b=0)*/
  while (min(a, b) > 0) {
    if (a < b)
      swap(a, b);
    a = a % b;
  }
  return max(a, b);
}
int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int MOD = 1e9 + 7;
const int INF = 1e18 + 10;

/*----------------------------------------------*/

signed main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  rep(i, k + 1) {
    FOR(j, i, k) {
      FOR(l, j, k) {
        if (i + j + l == s) {
          if (i == j && j == l)
            ans++;
          else if (i == j || j == l || l == i)
            ans += 3;
          else
            ans += 6;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03835 (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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;

int main() {
  int K, S;
  cin >> K >> S;
  int cnt;
  for (int x = K; x >= 0; x--) {
    if (x + 2 * K < S) {
      break;
    }
    for (int y = K; y >= 0; y--) {
      if (x + y + K < S || x + y > S) {
      } else {
        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;
  cin >> K >> S;

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

  cout << counter << endl;
}

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

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

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

  cout << counter << endl;
}