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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout << #x << "=" << x
#define nl cout << "\n"
#define frn(i, n) for (int i = 0; i < n; i++)
#define fr(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define trav(x, c) for (auto &x : c)
using namespace std;
const int mod = 1e9 + 7;
int toint(string s) {
  int ans = 0;
  for (char x : s)
    ans = ans * 10 + (x - '0');
  return ans;
}

int lcs(string a, string b) {
  int n = a.size(), m = b.size();
  int dp[2][m + 1];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i == 0 || j == 0)
        dp[i % 2][j] = 0;
      else {
        if (a[i - 1] == b[j - 1])
          dp[i % 2][j] = 1 + dp[1 - i % 2][j - 1];
        else
          dp[i % 2][j] = max(dp[i % 2][j - 1], dp[1 - i % 2][j]);
      }
    }
  }
  return dp[n % 2][m];
}

int sum(int x) {
  int s = 0;
  while (x) {
    s += x % 10;
    x /= 10;
  }
  return s;
}

bool equal(string s) {
  for (int i = 0, j = s.size() / 2; j < s.size(); i++, j++) {
    if (s[i] != s[j])
      return false;
  }
  return true;
}

ll fact(int n) {
  ll ans = 1;
  fr(i, 2, n + 1) ans = (ans * i) % mod;
  return ans;
}

int main() {
  int k, s;
  cin >> k >> s;
  int n = 2550 * 2550;
  vector<int> left(n), right(n);
  frn(a, k + 1) {
    frn(b, k + 1) { left[a + b]++; }
  }
  frn(c, k + 1) { right[s - c]++; }
  int ans = 0;
  frn(i, left.size()) { ans += left[i] * right[i]; }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout << #x << "=" << x
#define nl cout << "\n"
#define frn(i, n) for (int i = 0; i < n; i++)
#define fr(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define trav(x, c) for (auto &x : c)
using namespace std;
const int mod = 1e9 + 7;
int toint(string s) {
  int ans = 0;
  for (char x : s)
    ans = ans * 10 + (x - '0');
  return ans;
}

int lcs(string a, string b) {
  int n = a.size(), m = b.size();
  int dp[2][m + 1];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i == 0 || j == 0)
        dp[i % 2][j] = 0;
      else {
        if (a[i - 1] == b[j - 1])
          dp[i % 2][j] = 1 + dp[1 - i % 2][j - 1];
        else
          dp[i % 2][j] = max(dp[i % 2][j - 1], dp[1 - i % 2][j]);
      }
    }
  }
  return dp[n % 2][m];
}

int sum(int x) {
  int s = 0;
  while (x) {
    s += x % 10;
    x /= 10;
  }
  return s;
}

bool equal(string s) {
  for (int i = 0, j = s.size() / 2; j < s.size(); i++, j++) {
    if (s[i] != s[j])
      return false;
  }
  return true;
}

ll fact(int n) {
  ll ans = 1;
  fr(i, 2, n + 1) ans = (ans * i) % mod;
  return ans;
}

int main() {
  int k, s;
  cin >> k >> s;
  int n = 2550 * 2550;
  vector<int> left(n), right(n);
  frn(a, k + 1) {
    frn(b, k + 1) { left[a + b]++; }
  }
  frn(c, k + 1) {
    if (s >= c)
      right[s - c]++;
  }
  int ans = 0;
  frn(i, left.size()) { ans += left[i] * right[i]; }
  cout << ans;
}
Problem p03835 (C++)

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

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


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

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

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

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

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

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;
}
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;
using ll = long long;
// using P = pair<int,int>;
// pow(x,n)
// cout << fixed << setprecision(桁数);

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


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

int main() {
  int k, s;
  cin >> k >> s;
  int cnt = 0;
  for (int x = 0; x <= k; ++x) {
    for (int y = 0; y <= s - x && y <= k; ++y) {
      int z = s - x - y;
      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 K, S;
  cin >> K >> S;
  int counter = 0;
  for (int X = 0; X <= K & X <= S; X++) {
    for (int Y = 0; Y <= K & Y <= S - X; Y++) {
      for (int Z = 0; Z <= K & Z <= S - X - Y; Z++) {
        if (X + Y + Z == 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 <= S; X++) {
    for (int Y = 0; Y <= K & Y <= S - X; Y++) {
      if (S - X - Y <= K)
        counter++;
    }
  }
  cout << counter << 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 + 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 + 1; x++) {
    for (int y = 0; y < k + 1; y++) {
      int z;
      z = s - x - y;
      if (0 <= z && z <= k)
        count++;
    }
  }
  cout << count << endl;
}
Problem p03835 (C++)

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

#define MOD 1000000007
typedef unsigned long long ull;

int k, s;

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


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

#define MOD 1000000007
typedef unsigned long long ull;

int k, s;

int main() {
  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;
}
Problem p03835 (C++)

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

#define INF (1 << 31) // INT_MAX/2
#define MOD 1000000007

using ll = long long;
using ull = unsigned long long;

int main(int argc, char *argv[]) {
  int K, S;
  std::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 (i + j + k == S) {
          count++;
        }
      }
    }
  }

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

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

#define INF (1 << 31) // INT_MAX/2
#define MOD 1000000007

using ll = long long;
using ull = unsigned long long;

int main(int argc, char *argv[]) {
  int K, S;
  std::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 ((0 <= z) && (z <= K)) {
        count++;
      }
    }
  }

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

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

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

  return 0;
}


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

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

  int ans = 0;
  for (int i = 0; i <= K; ++i) {
    for (int j = 0; j <= i; ++j) {
      for (int k = 0; k <= j; ++k) {
        if (i + j + k == S) {
          if (i != j && j != k && k != i) {
            ans += 6;
          } else if ((i == j && j != k) || (j == k && j != i) ||
                     (k == i && i != j)) {
            ans += 3;
          } else {
            ans++;
          }
        }
      }
    }
  }

  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 i = 0; i <= K; ++i) {
    for (int j = 0; j <= K; ++j) {
      ans += (S - i - j <= K && S - i - j >= 0);
    }
  }

  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 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 (0 <= z && 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;
  long long ans = 0;
  scanf("%d%d", &K, &S);
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      for (int z = 0; z <= K && x + y + z <= S; z++) {
        if (x + y + z == S)
          ans++;
      }
    }
  }
  printf("%lld\n", ans);
}

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

int main() {
  int K, S;
  long long ans = 0;
  scanf("%d%d", &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++;
    }
  }
  printf("%lld\n", ans);
}
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 <= k && z >= 0) {
        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, ans = 0;
  cin >> K >> S;
  REP(i, K) REP(y, K) REP(j, K) if (i + y + j == S) ans++;
  cout << ans << endl;
}

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, ans = 0;
  cin >> K >> S;
  REP(i, K) REP(y, K) if (0 <= (S - i - y) && (S - i - y) <= K) ans++;
  cout << ans << endl;
}
Problem p03835 (C++)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  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;
  return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int K, S, count = 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)
        ++count;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p03835 (C++)

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int ans, mi1, mi2, mi3;
int main() {
  int k, s;
  cin >> k >> s;
  mi1 = min(s, k);
  for (int i = mi1; i >= 0; i--) {
    mi2 = min(s - i, k);
    for (int j = mi2; j >= 0; j--) {
      mi3 = min(s - i - j, k);
      for (int l = mi3; l >= 0; l--) {
        if (i + j + l == s) {
          ans++;
        }
        if (i + j + l < s) {
          break;
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF INT_MAX;
typedef long long ll;
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)
          ans++;
      }
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF INT_MAX;
typedef long long ll;
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++) {
      if (s - i - j <= k && s - i - j >= 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 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 += 1;
        }
      }
    }
  }
  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 += 1;
      }
    }
  }
  cout << ans << 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++) {
    if (i > s)
      break;
    for (int j = 0; j <= k; j++) {
      if (i + j > s)
        break;
      for (int l = 0; l <= k; l++) {
        if (i + j + l > s)
          break;
        if (i + j + l == s) {
          count++;
          break;
        }
      }
    }
  }
  cout << count << endl;
}


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

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  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 l = 0; l <= k; l++) {
        if (i + j + l == s) {
          ans++;
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int k, s;
  cin >> k >> s;
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      if ((i + j) > s)
        break;
      if (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;
#define rep(i, n) for (int i = 0; i < (n); i++)

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

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

int main() {
  int k, s;
  cin >> k >> s;
  int cnt = 0;
  rep(x, k + 1) rep(y, k + 1) {
    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 <cmath>
#include <stdio.h>
using namespace std;

int main() {
  int k, s;
  scanf("%d", &k);
  scanf("%d", &s);
  int res = 0;
  if (3 * k == s) {
    printf("%d\n", 1);
    return 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)
          res++;
      }
    }
  }
  printf("%d\n", res);
}


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

int main() {
  int k, s;
  scanf("%d", &k);
  scanf("%d", &s);
  int res = 0;
  if (3 * k == s) {
    printf("%d\n", 1);
    return 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)
        res++;
    }
  }
  printf("%d\n", res);
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int k, s;
  cin >> k >> s;
  int cnt;
  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;
  return 0;
}

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i, a, b) for (ll i = (a), __last_##i = (b); i < __last_##i; i++)
#define RFOR(i, a, b) for (ll i = (b)-1, __last_##i = (a); i >= __last_##i; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, v.size()) {
    if (i)
      os << " ";
    os << v[i];
  }
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
  REP(i, v.size()) {
    if (i)
      os << endl;
    os << v[i];
  }
  return os;
}

int main() {
  ll k, x, y, z, s;
  ll count = 0;
  cin >> k >> s;

  rep(x, k + 1) rep(y, k + 1) rep(z, k + 1) {
    if (x + y + z == s)
      count++;
  }
  cout << count << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i, a, b) for (ll i = (a), __last_##i = (b); i < __last_##i; i++)
#define RFOR(i, a, b) for (ll i = (b)-1, __last_##i = (a); i >= __last_##i; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, v.size()) {
    if (i)
      os << " ";
    os << v[i];
  }
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
  REP(i, v.size()) {
    if (i)
      os << endl;
    os << v[i];
  }
  return os;
}

int main() {
  ll k, x, y, z, s;
  ll count = 0;
  cin >> k >> s;
  rep(x, k + 1) rep(y, k + 1) {
    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 main() {
  int K, S;
  int counter = 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) {
          counter++;
        }
      }
    }
  }

  cout << counter << endl;

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int K, S;
  int counter = 0;
  cin >> K >> S;

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

  cout << counter << endl;

  return 0;
}
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 > s || j + l > s || i + l > s)
          continue;
        if (s == i + j + l)
          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++) {
      int l = s - i - j;
      if (0 <= l && l <= k)
        cnt++;
    }
  cout << cnt << endl;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;

#define MOD 998244353

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

bool primeNumber(ll n) {
  if (n < 2)
    return false;
  else {
    for (ll i = 2; i * i <= n; i++) {
      if (n % i == 0)
        return false;
    }
    return true;
  }
}

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

  for (ll i = 0; i <= k; i++) {
    for (ll j = 0; j <= k; j++) {
      for (ll h = 0; h <= k; h++) {
        if (i + j + h == s)
          ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;

#define MOD 998244353

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

bool primeNumber(ll n) {
  if (n < 2)
    return false;
  else {
    for (ll i = 2; i * i <= n; i++) {
      if (n % i == 0)
        return false;
    }
    return true;
  }
}

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

  for (ll i = 0; i <= k; i++) {
    for (ll j = i; j <= k; j++) {
      for (ll h = j; h <= k; h++) {
        if (i + j + h == s) {
          if (i == j && j == h) {
            ans++;
          } else if (i == j || j == h || i == h) {
            ans += 3;
          } else {
            ans += 6;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03835 (C++)

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

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

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

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

  for (int i = 0; i <= k; ++i) {
    for (int j = 0; j <= k; ++j) {
      ll t = s - i - j;
      if (0 <= t and t <= k) {
        ans += 1;
      }
    }
  }
  cout << ans << endl;
}
Problem p03835 (C++)

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

int main(void) {
  int k;
  int s;
  scanf("%d", &k);
  scanf("%d", &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);
}


Fixed submission:
#include <stdio.h>

int main(void) {
  int k;
  int s;
  scanf("%d", &k);
  scanf("%d", &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 <= k && z >= 0)
        ans++;
    }
  }
  printf("%d", ans);
}
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 + 1; i++) {
    for (int j = 0; j < K + 1; j++) {
      for (int k = 0; k < K + 1; k++) {
        if (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 + 1; i++) {
    for (int j = 0; j < K + 1; j++) {
      if ((S - i - j <= K) && (S - i - j >= 0)) {
        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 n = 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)
          n++;
      }
    }
  }
  cout << n << endl;
  return 0;
}


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

int main() {
  int k, s;
  cin >> k >> s;
  int n = 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)n++;
      // }
      int z = s - i - j;
      if (0 <= z && z <= k) {
        n++;
      }
    }
  }
  cout << n << endl;
  return 0;
}
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;
  int x = 0, y = 0, z = 0;
  for (x = 0; x <= k; x++) {
    for (y = 0; y <= k; y++) {
      for (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, cnt = 0;
  cin >> k >> s;
  int x = 0, y = 0, z = 0;
  for (x = 0; x <= k; x++) {
    for (y = 0; y <= k; y++) {
      z = s - x - y;
      if ((0 <= z) && (z <= k)) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}
Problem p03835 (C++)

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

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int K, S;
  cin >> K >> S;
  int ret = 0;
  for (int i = 0; K >= i; i++) {
    for (int j = 0; K >= j; j++) {
      if (i + j <= S && i + j + K >= S) {
        ret++;
      }
    }
  }
  cout << ret << 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 N = 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)
          N++;
      }
    }
  }
  cout << N << endl;
}

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

int main() {
  int K, S;
  cin >> K >> S;
  int N = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      if (i + j <= S && i + j + K >= S)
        N++;
    }
  }
  cout << N << endl;
}
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 l = 0; l <= k; l++) {
        if (i + j + l == s) {
          ++ans;
        }
      }
    }
  }
  cout << ans << "\n";
}


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 (i + j <= s && s - i - j <= k) {
        ++ans;
      }
    }
  }
  cout << ans << "\n";
}
Problem p03835 (C++)

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

int main() {
  int k, s, answer = 0;

  cin >> k >> s;

  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) {
          answer++;
        }
      }
    }
  }

  cout << answer << endl;
}


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

int main() {
  int k, s, answer = 0;

  cin >> k >> s;

  for (int x = 0; x < k + 1; x++) {
    for (int y = 0; y < k + 1; y++) {
      if (s <= x + y + k && s >= x + y) {
        answer++;
      }
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <string>
// #include<string>
// #include<sstream>
using namespace std;
int main() {
  int k, s;
  scanf("%d%d", &k, &s);
  int i, j, b, sum = 0;
  for (i = 0; i <= k; i++) {
    for (j = 0; j <= k && j <= s - i; j++) {
      for (b = 0; b <= k && b <= s - i - j; b++) {
        if (i + j + b == s)
          sum++;
      }
    }
  }
  printf("%d\n", sum);
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <string>
// #include<string>
// #include<sstream>
using namespace std;
int main() {
  int k, s;
  scanf("%d%d", &k, &s);
  int i, j, b, sum = 0;
  for (i = 0; i <= k; i++) {
    for (j = 0; j <= k && j <= s - i; j++) {
      if (s - i - j <= k)
        sum++;
    }
  }
  printf("%d\n", sum);
}
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 i = 0; i <= k; ++i) {
    for (int j = 0; j <= k && i + j <= s; ++j) {
      for (int l = 0; l <= k && i + j + l <= s; ++l) {
        ans += (i + j + l == s ? 1 : 0);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
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 && i + j <= s; ++j) {
      if (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() {
  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++;
          break;
        }
      }
    }
  }
  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) {
        continue;
      } else if (x + y <= S) {
        count++;
      } else {
        break;
      }
    }
  }
  cout << count << endl;
}
Problem p03835 (C++)

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

typedef long long int lli;
typedef long long ll;
typedef long double ld;

int main() {
  int t = 1;
  // cin>>t;
  while (t--) {
    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 p = 0; p <= k; p++) {
          if (i + j + p == s) {
            c++;
          }
        }
      }
    }
    cout << c;
  }
}

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

typedef long long int lli;
typedef long long ll;
typedef long double ld;

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

Buggy submission (status: Time Limit Exceeded):
// ABC051A - Sum of Three Integers

#include <bits/stdc++.h>
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:
// ABC051A - Sum of Three Integers

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

  cout << ans << endl;

  return 0;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <stdio.h>
#define FOR(i, a, b) for (long long int i = (a); i < (b); i++)
#define REP(i, N) FOR(i, 0, N)
#define debug(x) cout << #x << " = " << x << endl;

using namespace std;

int main(void) {

  int K, sum;
  cin >> K >> sum;
  int ans = 0;
  if (K > sum) {
    REP(i, K + 1) {
      if (i > sum)
        break;
      REP(j, K + 1 - i) {
        if (j > sum)
          break;
        REP(k, K + 1 - j) {
          if (k > sum)
            break;
          if (i + j + k == sum) {
            ans++;
            break;
          }
        }
      }
    }
  } else {
    REP(i, K + 1) {
      if (sum - i > 2 * K)
        continue;
      REP(j, K + 1) {
        if (sum - (i + j) > K)
          continue;
        REP(k, K + 1) {
          if (i + j + k == sum) {
            ans++;
            break;
          }
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <iostream>
#include <stdio.h>
#define FOR(i, a, b) for (long long int i = (a); i < (b); i++)
#define REP(i, N) FOR(i, 0, N)
#define debug(x) cout << #x << " = " << x << endl;

using namespace std;

int main(void) {

  int K, sum;
  cin >> K >> sum;
  int ans = 0;
  REP(i, K + 1) {
    REP(j, K + 1) {
      int s = sum - i - j;
      if (0 <= s && s <= K) {
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}
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 ans = 0;
  rep(i, k + 1) {
    rep(j, k + 1) {
      if (j > s - i)
        continue;
      rep(l, k + 1) {
        if (l > s - i - j)
          continue;
        if (s == i + j + l)
          ans++;
      }
    }
  }
  cout << ans << endl;
}


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 ans = 0;
  rep(i, k + 1) {
    rep(j, k + 1) {
      if (0 <= s - i - j && s - i - j <= 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 int;

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;
}

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

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 (0 <= z && z <= K) {
        count++;
      }
    }
  }
  cout << count;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
using namespace std;
// とりまイントとダブルが入り乱れるときは
// とりまどちらかに統一しよう。

int max(int x, int y) {
  if (x > y)
    return x;
  return y;
}

int min(int x, int y) {
  if (x < y)
    return x;
  return y;
}

int main() {
  int k, s;
  cin >> k >> s;
  int res = 0;
  bool judge = false;
  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)
          res++;
      }
    }
  }
  cout << res << endl;
}


Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;
// とりまイントとダブルが入り乱れるときは
// とりまどちらかに統一しよう。

int max(int x, int y) {
  if (x > y)
    return x;
  return y;
}

int min(int x, int y) {
  if (x < y)
    return x;
  return y;
}

int main() {
  int k, s;
  cin >> k >> s;
  int res = 0;
  bool judge = false;
  for (int x = 0; x <= k; ++x) {
    for (int y = 0; y <= k; ++y) {
      int z = s - x - y; // 合計
      if (0 <= z && z <= k)
        res++;
    }
  }
  cout << res << endl;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int i, j, k, p, n, ans = 0;
  cin >> k >> n;
  for (i = 0; i <= k; i++) {
    for (j = 0; j <= k; j++) {
      for (p = 0; p <= k; p++) {
        if (i + j + p == n)
          ans++;
      }
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <iostream>
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 ij = s - i - j;
      if (ij <= k && ij >= 0)
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  int x, y, z;
  int s, k;
  cin >> k >> s;
  int sum = 0;
  for (x = 0; x <= k; x++) {
    for (y = 0; y <= k; y++) {
      for (z = 0; z <= k; z++) {
        if (x + y + z == s) {
          sum++;
        }
      }
    }
  }
  cout << sum;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  int x, y, z;
  int s, k;
  cin >> k >> s;
  int sum = 0;
  for (x = 0; x <= k; x++) {
    for (y = 0; y <= k; y++) {
      z = s - x - y;
      if (z >= 0 && z <= k) {
        sum++;
      }
    }
  }
  cout << sum;
  return 0;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
typedef long long ll;
typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7,
          around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const ld PI = abs(acos(-1));
int n, m;

int main() {
  cin >> n >> m;

  ll s = 0;
  REP(i, 0, n + 1) {
    REP(j, 0, n + 1) {
      REP(k, 0, n + 1) {
        if (i + j + k == m)
          s++;
      }
    }
  }

  cout << s << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
typedef long long ll;
typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7,
          around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const ld PI = abs(acos(-1));
int n, m;

int main() {
  cin >> n >> m;

  ll s = 0;
  REP(i, 0, n + 1) {
    REP(j, 0, n + 1) {
      if (0 <= m - i - j and m - i - j <= n)
        s++;
    }
  }

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

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

using namespace std;
#define FOR(i, n) for (i = 0; i <= n; ++i)
#define DEBG(s) cout << s << endl;
int i, j, a, b, c;

int main(void) {
  int k, s, cnt = 0;
  cin >> k >> s;
  FOR(a, k) {
    FOR(b, k) {
      FOR(c, k) {
        if (a + b + c == s)
          cnt++;
      }
    }
  }
  cout << cnt;

  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;
#define FOR(i, n) for (i = 0; i <= n; ++i)
#define DEBG(s) cout << s << endl;
int i, j, a, b, c;

int main(void) {
  int k, s, cnt = 0;
  cin >> k >> s;
  FOR(i, k) {
    FOR(j, k) {
      int jdg = s - i - j;
      if (0 <= jdg && jdg <= k)
        cnt++;
    }
  }
  cout << cnt;

  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;
  if (3 * k == s) {
    cout << 1 << endl;
  } else {
    for (int x = k; x >= 0; x--) {
      for (int y = k; y >= 0; y--) {
        for (int z = k; z >= 0; z--) {
          if (x + y + z < s)
            break;
          if (x + y + z == s)
            count++;
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int k, s, count = 0;
  cin >> k >> s;
  if (3 * k == s) {
    cout << 1 << endl;
  } else {
    for (int x = 0; x <= k; x++) {
      for (int y = 0; y <= k; y++) {
        if (x + y + k >= s && s - x - y >= 0) {
          // cout<<x<<" "<<y<<" "<<s-x-y<<endl;
          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 argc, char **argv) {
  int K, S;
  cin >> K >> S;
  int ret = 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)
          ret++;
      }
    }
  }
  cout << ret << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  int K, S;
  cin >> K >> S;
  int ret = 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) {
        ret++;
      }
    }
  }
  cout << ret << endl;
  return 0;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); ++i) // a ≦ i < b
#define Rrep(i, a, b)                                                          \
  for (int i = (a); i >= (b); --i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(), (a).end()

int main() {
  int K, S;
  cin >> K >> S;
  int counter = 0;

  rep(x, 0, K + 1) {
    rep(y, 0, K + 1) {
      rep(z, 0, K + 1) {
        if (x + y + z == S)
          ++counter;
      }
    }
  }
  cout << counter << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); ++i) // a ≦ i < b
#define Rrep(i, a, b)                                                          \
  for (int i = (a); i >= (b); --i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(), (a).end()

int main() {
  int K, S;
  cin >> K >> S;
  int counter = 0;

  rep(x, 0, K + 1) {
    rep(y, 0, K + 1) {
      int z = S - x - y;
      if (0 <= z && z <= K)
        ++counter;
    }
  }
  cout << counter << 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 ans = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K + 1; i++) {
      if (S - K <= i + j) {
        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 i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      if (i + j <= S && i + j >= S - K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}