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

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

using namespace std;

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


Fixed submission:
#include <cmath>
#include <iomanip>
#include <iostream>

using namespace std;

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI = 3.141592653589793238463;
const int INF = 1000000007;

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

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

int solve(int k, int s) {
  int res = 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) {
          res++;
        }
      }
    }
  }
  return res;
}

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

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

  cout << solve(k, s) << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI = 3.141592653589793238463;
const int INF = 1000000007;

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

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

int solve(int k, int s) {
  int res = 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++;
      }
    }
  }
  return res;
}

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

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

  cout << solve(k, 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; i++) {
    for (int j = 0; j <= k; j++) {
      for (int p = 0; p <= k; p++) {
        if (i + j + p == 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 (0 <= s - i - j && 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;

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

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

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

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

int main(void) {
  int K, S, i, j, k, res = 0;
  scanf("%d%d", &K, &S);
  for (i = 0; i <= K; i++) {
    for (j = 0; j <= K; j++) {
      for (k = 0; k <= K; k++) {
        if (i + j + k == S) {
          res++;
        }
      }
    }
  }
  printf("%d", res);
  return 0;
}

Fixed submission:
#include <stdio.h>

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

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

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

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(6);
  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 or z > k)
        continue;
      cerr << x << y << z << endl;
      ans++;
    }
  }

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

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(6);
  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 or z > k)
        continue;
      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 = 0, S = 0;
  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 = 0, S = 0;
  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 and 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;
  int z;
  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++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {
  int k, s;
  int z;
  cin >> k >> s;
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      z = s - i - j;
      if (z <= k && 0 <= z) {
        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 cnt = 0;
  int K, S;
  cin >> K >> S;
  for (size_t i = 0; i <= K; i++) {
    for (size_t j = 0; j <= K; j++) {
      for (size_t k = 0; k <= K; k++) {
        int total = i + j + k;
        if (total == S) {
          cnt++;
          break;
        } else if (total > S)
          break;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

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

  int ans = 0;
  for (int i = 0; i <= S; i++) { // iはX
    for (int j = 0; j <= S; j++) {
      for (int k = 0; k <= S; k++) { // kはZ
        if (i + j + k == S && i <= K && j <= K && k <= K) {
          ans++;
        } else {
          continue;
        }
      }
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.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++) {   // iはX
    for (int j = 0; j <= K; j++) { // 三つ目の変数ZはS - i - j
      int z = S - (i + j);
      if (i + j + z == S && i <= K && j <= K && 0 <= z && z <= K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p03835 (C++)

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

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

  return 0;
}


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

int main() {
  long long k, s, cnt = 0;
  cin >> k >> s;
  for (long long i = 0; i <= k; i++) {
    for (long long j = 0; j <= k; j++) {
      if (s - i - j >= 0 and s - i - j <= k)
        cnt++;
    }
  }
  cout << cnt << 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++)
#define ll long long
#define INF 10000000
#define int long long
using namespace std;
signed main() {
  int k, s;
  int cnt = 0;
  cin >> k >> s;
  rep(i, k + 1) {
    rep(j, k + 1) {
      rep(l, k + 1) {
        if (i + j + l == s)
          cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define INF 10000000
#define int long long
using namespace std;
signed main() {
  int k, s;
  int 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 (i + j + l == s && l >= 0 && l <= 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 num, Max;
  int count = 0;
  cin >> num >> Max;
  for (int i = 0; i <= num; i++) {
    for (int j = 0; j <= num; j++) {
      for (int k = 0; k <= num; k++) {
        if (i + j + k == Max) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}

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

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int k, s;
  cin >> k >> s;
  ll ans = 0;
  for (int i = 0; i <= k; i++)
    for (int j = 0; j <= k; j++)
      for (int k2 = 0; k2 <= k; k++)
        if (i + j + k2 == s)
          ans++;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int k, s;
  cin >> k >> s;
  ll ans = 0;
  for (int i = 0; i <= k; i++)
    for (int j = 0; j <= k; j++) {
      int y = s - i - j;
      if (y <= k && y >= 0)
        ans++;
    }
  cout << ans << endl;
  return 0;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(), v.end()

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(), v.end()

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++) {
      int z = s - x - y;
      if (0 <= z && z <= k) {
        counter++;
      }
    }
  }
  cout << counter << endl;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  int K, S;
  int X, Y, Z;
  int res;
  cin >> K >> S;
  for (X = 0; X <= K; X++) {
    for (Y = 0; Y <= K; Y++) {
      for (Z = 0; Z <= K; Z++) {
        if (X + Y + Z == S) {
          res++;
        }
      }
    }
  }

  cout << res << endl;

  return 0;
}


Fixed submission:
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  int K, S;
  int X, Y, Z;
  int res;
  cin >> K >> S;
  for (X = 0; X <= K; X++) {
    for (Y = 0; Y <= K; Y++) {
      Z = S - X - Y;
      if (0 <= Z && Z <= K)
        res++;
    }
  }

  cout << res << endl;

  return 0;
}
Problem p03835 (Python)

Buggy submission (status: Time Limit Exceeded):
k, s = map(int, input().split())

ans = 0
for x in range(k + 1):
    for y in range(min(k + 1, s - x + 1)):
        for z in range(min(k + 1, s - x - y + 1)):
            if x + y + z == s:
                ans += 1

print(ans)


Fixed submission:
k, s = map(int, input().split())

ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        if 0 <= s - x - y <= k:
            ans += 1

print(ans)
Problem p03835 (C++)

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

using namespace std;

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

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

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

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

int main(int argc, const char *argv[]) {
  int n, s;
  cin >> n >> s;

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

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

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(int argc, const char *argv[]) {
  int n, s;
  cin >> n >> s;

  int ans = 0;
  for (int x = 0; x <= n; x++) {
    for (int y = 0; y <= n; y++) {
      int z = s - (x + y);

      if (0 <= z && z <= n) {
        ans++;
      }
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
K, S = map(int, input().split())
ans = 0
for x in range(K + 1):
    for y in range(K + 1):
        for z in range(K + 1):
            # print(x, y, z)
            if x + y + z == S:
                ans += 1
print(ans)


Fixed submission:
K, S = map(int, input().split())
ans = 0
for x in range(K + 1):
    for y in range(K + 1):
        ans += 1 if 0 <= S - x - y <= K else 0
print(ans)
Problem p03835 (Python)

Buggy submission (status: Time Limit Exceeded):
# -*- coding: utf-8 -*-
K, S = map(int, input().split())
cnt = 0

for X in range(K + 1):
    for Y in range(K + 1):
        for Z in range(K + 1):
            if X + Y + Z == S:
                cnt += 1
print(cnt)


Fixed submission:
# -*- coding: utf-8 -*-
K, S = map(int, input().split())
cnt = 0

for X in range(K + 1):
    for Y in range(K + 1):
        Z = S - X - Y
        if 0 <= Z <= K:
            cnt += 1

print(cnt)
Problem p03835 (Python)

Buggy submission (status: Time Limit Exceeded):
K, S = map(int, input().split())

counter = 0
for x in range(K + 1):
    for y in range(K + 1):
        for z in range(K + 1):
            if S == x + y + z:
                counter += 1
print(counter)


Fixed submission:
K, S = map(int, input().split())

counter = 0
for x in range(K + 1):
    for y in range(K + 1):
        z = S - x - y
        if 0 <= z and z <= K:
            counter += 1
print(counter)
Problem p03835 (Python)

Buggy submission (status: Time Limit Exceeded):
# https://atcoder.jp/contests/abc051/tasks/abc051_b

# n n,
K, S = map(int, input().split())

# initialize
ans = 0

# logic: 全探索: 基本形
for i in range(K + 1):
    if i + K + 1 + K + 1 < S:
        continue
    for j in range(K + 1):
        if i + j + K + 1 < S:
            continue
        if 0 <= S - i - j <= K:
            ans += 1

print(ans)


Fixed submission:
k, s = map(int, input().split())
count = 0
for a in range(k + 1):
    for b in range(k + 1):
        if 0 <= s - a - b <= k:
            count += 1
print(count)
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a, b, c = 0, x = 0, y = 0, z = 0, e;
  cin >> a >> b;
  for (int h = x; h <= a; h++) {
    for (int k = y; k <= a; k++) {
      for (int i = z; i <= a; i++) {
        if (h + k + i == b) {
          c++;
        }
      }
    }
  }
  cout << c << "\n";
  cin >> e;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a, b, c = 0, x = 0, y = 0, z = 0, e;
  cin >> a >> b;
  for (int h = x; h <= a; h++) {
    for (int k = y; k <= a; k++) {
      if (b - (h + k) >= 0 && b - (h + k) <= a) {
        c++;
      }
    }
  }
  cout << c << "\n";
  cin >> e;
}
Problem p03835 (C++)

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

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

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

  cout << ret << endl;
  return 0;
}

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

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

  int ret = 0;
  REP(i, K + 1) REP(j, K + 1) {
    int k = S - (i + j);
    if (0 <= k && k <= K)
      ++ret;
  }

  cout << ret << 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 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 (0 <= S - (i + j) && S - (i + j) <= K) {
        count++;
      }
    }
  }
  cout << count << endl;
}
Problem p03835 (C++)

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

int main() {
  int K, S;
  int Max = 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++) {
        int total = x + y + z;
        if (total == S) {
          Max++;
        }
      }
    }
  }
  cout << Max << endl;
}

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

int main() {
  int K, S;
  int Max = 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 && K >= z) {
        Max++;
      }
    }
  }
  cout << Max << endl;
}
Problem p03835 (C++)

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

using namespace std;

int main() {
  int K, S, ans = 0;
  cin >> K;
  cin >> 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 <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
// #include <bits/stdc++.h>

using namespace std;

int main() {
  int K, S, ans = 0;
  cin >> K;
  cin >> 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>
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++) {
      int a = 0;
      a = s - i - j;
      if (0 <= a && a <= 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;
  int i, j, k;
  long long 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 <iostream>

using namespace std;

int main() {
  int K, S;
  int i, j, k;
  long long ans = 0;
  cin >> K >> S;

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

  cout << ans << endl;

  return 0;
}
Problem p03835 (C++)

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

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

  printf("%d", count);
}

Fixed submission:
#include <stdio.h>

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

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

  printf("%d", count);
}
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 all(x) (x).begin(), (x).end()
#define INF 10000000
using ll = long long;

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>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define INF 10000000
using ll = long long;

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 += 1;
    }
  }
  cout << ans << endl;
}
Problem p03835 (C++)

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

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

  int count = 0;

  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      for (int p = 0; p <= k; p++) {
        int sum = i + j + p;
        if (sum == s) {
          count++;
        }
      }
    }
  }
  cout << count;
  cout << endl;
}


Fixed submission:
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

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

  int count = 0;

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ARB                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define bp __builtin_popcount
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
const int maxn = 1e5 + 5;
const double EPS = 1e-14;

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


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ARB                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define bp __builtin_popcount
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
const int maxn = 1e5 + 5;
const double EPS = 1e-14;

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 z = s - i - j;
      if (z >= 0 && z <= k)
        cnt++;
    }
  }
  cout << cnt;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int K;
  int S;
  cin >> K >> S;
  int total = 0;
  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 (S == i + j + k) {
          count++;
          break;
        }
      }
    }
  }
  cout << count << endl;
}

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define lld long long int
#define DBG1(vari1) cerr << #vari1 << " = " << (vari1) << endl;
#define DBG2(vari1, vari2)                                                     \
  cerr << #vari1 << " = " << (vari1) << " " << #vari2 << " = " << (vari2)      \
       << endl;
#define DBG3(vari1, vari2, vari3)                                              \
  cerr << #vari1 << " = " << (vari1) << " " << #vari2 << " = " << (vari2)      \
       << " " << #vari3 << " = " << (vari3) << endl;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  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 w = 0; w <= k; w++) {
        if ((i + j + w) == s)
          c++;
      }
  cout << c;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define lld long long int
#define DBG1(vari1) cerr << #vari1 << " = " << (vari1) << endl;
#define DBG2(vari1, vari2)                                                     \
  cerr << #vari1 << " = " << (vari1) << " " << #vari2 << " = " << (vari2)      \
       << endl;
#define DBG3(vari1, vari2, vari3)                                              \
  cerr << #vari1 << " = " << (vari1) << " " << #vari2 << " = " << (vari2)      \
       << " " << #vari3 << " = " << (vari3) << endl;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  int k, s;
  cin >> k >> s;
  int c = 0;
  for (int i = 0; i <= k; i++)
    for (int j = 0; j <= k; j++) {
      int q = s - i - j;
      if (q >= 0 && q <= k)
        c++;
    }
  cout << c;
}
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++)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)

#define All(x) (x).begin(), (x).end()
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

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

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

using namespace std;

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

#define All(x) (x).begin(), (x).end()
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

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

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

using namespace std;

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

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

using namespace std;

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

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

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

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

  int cnt = 0;

  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      for (int m = 0; m <= k; m++) {
        if (i + j + m == s)
          cnt++;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}

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

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

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

  int cnt = 0;

  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      int m = s - i - j;
      if (0 <= m && m <= k) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}
Problem p03835 (C++)

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

using namespace std;

int main() {
  int K, S;

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

  cout << count;
}

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

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

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

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

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

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

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

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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
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 <iostream>
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 (s - i - j <= k && s - i - j >= 0)
        cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p03835 (C++)

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

#define int long long
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);

signed main() {
  IOS;

  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;

  return 0;
}


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

#define int long long
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);

signed main() {
  IOS;

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

  return 0;
}
Problem p03835 (C++)

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

int main() {

  int K, S;
  cin >> K >> S;

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

  cout << c << endl;

  return 0;
}

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

int main() {

  int K, S;
  cin >> K >> S;

  int c = 0;

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

  cout << c << endl;

  return 0;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
平面上に N 個の点があり、それぞれ 0 から N−1 までの番号が付けられており、
それぞれの点について x 座標と y 座標が与えられています。
その N 点のうち 2
点を選び結んで得られる線分のうち、最も長くなる線分の長さを求めてください。
*/
#include <iomanip>
#include <iostream>
#include <math.h>
using namespace std;

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

  int res = 0;
  for (int i = 0; i <= K; ++i) {
    for (int k = 0; k <= K; ++k) {
      for (int l = 0; l <= K; ++l) {
        if (i + k + l == S)
          ++res;
      }
    }
  }
  cout << res << endl;
}


Fixed submission:
/*
平面上に N 個の点があり、それぞれ 0 から N−1 までの番号が付けられており、
それぞれの点について x 座標と y 座標が与えられています。
その N 点のうち 2
点を選び結んで得られる線分のうち、最も長くなる線分の長さを求めてください。
*/
#include <iomanip>
#include <iostream>
#include <math.h>
using namespace std;

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

  int res = 0;
  for (int i = 0; i <= K; ++i) {
    for (int k = 0; k <= K; ++k) {
      if (i + k <= S & S - i - k <= K)
        ++res;
    }
  }
  cout << res << 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++;
      }
    }
  }

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

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

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

int main() {
  int k, s;
  int x, y, z;

  std::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) {
        counter = (x + y + z == s) ? counter + 1 : counter;
      }
    }
  }

  std::cout << counter;
}


Fixed submission:
#include <iostream>

int main() {
  int k, s;
  int x, y, z;

  std::cin >> k >> s;
  int counter = 0;
  for (int x = 0; x <= k; ++x) {
    for (int y = 0; y <= k; ++y) {
      counter = (s - x - y <= k && s - x - y >= 0) ? counter + 1 : counter;
    }
  }

  std::cout << counter;
}
Problem p03835 (C++)

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define rrep(i, n) RFOR(i, n, 0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

  int k, s;
  cin >> k >> s;
  ll dp[s + 1][3];
  // dp[i][j] := 変数を i+1個使いjを作るときの組み合わせ数

  rep(i, s + 1) rep(j, 3) dp[i][j] = 0LL;
  rep(i, k + 1) dp[i][0] = 1LL;

  rep(j, 2) {
    rep(i, s + 1) {
      rep(l, k + 1) {
        if (i - l >= 0)
          dp[i][j + 1] += dp[i - l][j];
      }
    }
  }

  // rep(i, s+1) rep(j, 3) cout << dp[i][j] << (j == 2 ? "\n" : " ");
  cout << dp[s][2] << endl;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define rrep(i, n) RFOR(i, n, 0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

  int k, s;
  cin >> k >> s;
  ll dp[8000][3];
  // dp[i][j] := 変数を j+1個使いiを作るときの組み合わせ数

  rep(i, s + 1) rep(j, 3) dp[i][j] = 0LL;
  rep(i, k + 1) dp[i][0] = 1LL;

  rep(j, 2) {
    rep(i, s + 1) {
      rep(l, k + 1) {
        if (i - l >= 0)
          dp[i][j + 1] += dp[i - l][j];
      }
    }
  }

  // rep(i, s+1) rep(j, 3) cout << dp[i][j] << (j == 2 ? "\n" : " ");
  cout << dp[s][2] << endl;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
//     for(int i=0; i<N;i++){
//     }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void) {
  int K, S;
  cin >> K >> S;
  int cnt = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      for (int k = 0; k <= K; k++) {
        if ((i + j + k) == S)
          cnt++;
      }
    }
  }

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


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
//     for(int i=0; i<N;i++){
//     }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void) {
  int K, S;
  cin >> K >> S;
  int cnt = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      int s = S - i - j;
      if (s <= K && s >= 0)
        cnt++;
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int k, s, ans = 0;
  cin >> k >> s;
  for (int 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 <iostream>
using namespace std;
int main() {
  int k, s, ans = 0;
  cin >> k >> s;
  for (int j = 0; j <= k; j++) {
    for (int l = 0; l <= k; l++) {
      if (j + l <= s && s - (j + l) <= k)
        ans++;
    }
  }
  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 X, Y, Z, cnt = 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 <iostream>
using namespace std;

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

  int X, Y, Z, cnt = 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 <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 l = 0; l <= K; l++)
        S == i + j + l ? ans++ : 0;
  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++) {
      int z = S - i - j;
      0 <= z &&z <= K ? ans++ : 0;
    }
  cout << ans << endl;
}