alexjercan/bugnet huggingface dataset:
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N - 1) cin >> A[i];
  vector<int> a(N, 0);
  rep(i, N - 1) a[A[i] - 1]++;
  rep(i, N) { cout << a[i] << endl; }
}

Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < int(N); ++i)
#define rep1(i, N) for (int i = 1; i < int(N); ++i)
#define all(a) (a).begin(), (a).end()
#define print(v)                                                               \\
  {                                                                            \\
    cerr << #v << ": [ ";                                                      \\
    for (auto _ : v)                                                           \\
      cerr << _ << ", ";                                                       \\
    cerr << "]" << endl;                                                       \\
  }
#define printpair(v)                                                           \\
  {                                                                            \\
    cerr << #v << ": [ ";                                                      \\
    for (auto _ : v)                                                           \\
      cerr << "{" << _.first << "," << _.second << "}"                         \\
           << ", ";                                                            \\
    cerr << "]" << endl;                                                       \\
  }
#define dump(x) cerr << #x << ": " << x << endl;
#define bit(k) (1LL << (k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "{" << p.first << ", " << p.second << "}";
  return os;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18 + 1;
const ll MOD = (ll)1e9 + 7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N - 1) cin >> A[i];
  vec<int> a(N, 0);
  rep(i, N) a[A[i] - 1]++;
  rep(i, N) { cout << a[i] << endl; }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> num(N);

  for (int i = 1; i < N; i++) {
    int A;
    cin >> A;
    num[A - 1]++;
  }

  for (int i = 0; i < N; i++)
    cout << num[i] << endl;

  return 0;
}

Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> num(N - 1);

  for (int i = 0; i < N - 1; i++) {
    cin >> num[i];
  }

  sort(num.begin(), num.end());

  for (int i = 1; i < N; i++) {
    int sum = 0;
    for (int j = 0; j < N - 1; j++) {
      if (i == num[j])
        sum++;
    }

    cout << sum << endl;
  }

  cout << 0 << endl;

  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int INF = 1e9;
const int EPS = 1e-9;
const int SEARCH_MAX = 6e3;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> ans(N, 0);
  for (int i = 1; i < N; ++i) {
    cin >> A.at(i);
    ans.at(A.at(i) - 1)++;
  }

  for (int i = 0; i < N; ++i)
    cout << ans.at(i) << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int INF = 1e9;
const int EPS = 1e-9;
const int SEARCH_MAX = 6e3;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  A.at(0) = 0; // 数えることのない番号
  for (int i = 1; i < N; ++i)
    cin >> A.at(i);

  vector<int> ans(N, 0);
  for (int i = 1; i <= N; ++i) {
    cout << count(A.begin() + i, A.end(), i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N - 1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define INF 1000000007

using ll = long long;
using namespace std;

typedef pair<int, int> P;

int main() {
  int N;
  cin >> N;
  int A[200005] = {0}, B[200005] = {0};
  rep1(i, N - 1) cin >> A[i];

  rep(i, N) B[A[i] - 1]++;

  rep(i, N) cout << B[i] << endl;
  // cout << endl;
  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N - 1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define INF 1000000007

using ll = long long;
using namespace std;

typedef pair<int, int> P;

int main() {
  int N;
  cin >> N;
  vector<int> A(N, 0), B(N, 0);
  rep1(i, N - 1) cin >> A[i];

  rep(i, N) B[A[i] - 1]++;

  rep(i, N) cout << B[i] << endl;
  // cout << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {

  long long n, x, arr[int(2e5 + 5)]{};

  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> x;
    arr[x]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << arr[i];
    if (n != 1 && i != n)
      cout << "\\n";
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, a[10001];
  cin >> n;
  for (int i = 0; i < n - 1; i++)
    cin >> a[i];
  int times = 0, count = 1;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == a[i + 1]) {
      count++;
    } else {
      cout << count << endl;
      times++;
      count = 1;
    }
  }
  int val = n - times;
  if (val >= 1) {
    while (val--)
      cout << 0 << endl;
  }
  return 0;
}
Problem p02708 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

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

  long long ans = 0;
  long long min = 0;
  for (int j = 0; j < K - 1; j++) {
    min += j;
  }
  long long max = 0;
  for (int j = N; j > N - K + 1; j--) {
    max += j;
  }

  for (int i = K; i <= N + 1; i++) {
    min += i - 1;
    max += N - i + 1;

    ans += max - min + 1;
    ans %= 1000000007;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

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

  long long ans = 0;
  for (int i = K; i <= N + 1; i++) {
    long long min = 0;
    for (int j = 0; j < i; j++) {
      min += j;
    }

    long long max = 0;
    for (int j = N; j > N - i; j--) {
      max += j;
    }

    ans += max - min + 1;
    ans %= 1000000007;
  }

  cout << ans << endl;

  return 0;
}
Problem p02708 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  long int n, k;
  long int min, max;
  long int sum = 0;
  cin >> n >> k;
  for (long int i = k; i <= n + 1; i++) {
    min = i * (i - 1) / 2;
    max = ((n - i + 1) + n) * i / 2;
    sum += max - min + 1;
    // cout << "min = " << min << " max = " << max << endl;
  }

  cout << sum % 1000000007 << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int comb(int a, int b) {
  int up = 1;
  int down = 1;
  int btmp = b;
  for (int i = 0; i < btmp; i++) {
    up *= a - i;
    down *= b - i;
  }
  return (up / down);
}

int main(void) {
  int n, k;
  int sum = 0;
  cin >> n >> k;
  if (n >= k) {
    for (int i = k; i <= (n + 1); i++) {
      // cout << "ss" << endl;
      sum += comb(n + 1, i);
      // cout << "sum(" << k << ")= " << sum << endl;
    }

    int tmp = n - 3 + 1;
    int sb = 0;
    int ad = 1;
    while ((tmp - sb) >= 0) {
      sum -= (ad * (tmp - sb));
      sb += 1;
      ad += 1;
    }

    cout << sum << endl;
  } else {
    cout << "1" << endl;
  }
  return 0;
}
Problem p02708 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define MAX_N 1
#define INF 1000000000 // 1e9
#define PI 3.14159265359
#define mod 1000000007
#define ll long long int

int main() {
  ll N, K;
  cin >> N >> K;
  ll res = 0;
  for (int i = K; i <= N + 1; i++) {
    ll temp = i * (N - i + 1) + 1;
    res += temp % mod;
    res %= mod;
  }
  cout << res << endl;
  return 0;
}


Error: 0

Fixed submission:

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

#define ll long long int
#define INF 1000000007

ll f[100001];

ll pow(ll a, ll b, ll MOD) {
  ll x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y);
      if (x > MOD)
        x %= MOD;
    }
    y = (y * y);
    if (y > MOD)
      y %= MOD;
    b /= 2;
  }
  return x;
}

/* Modular Multiplicative Inverse
 Using Euler's Theorem
 a^(phi(m)) = 1 (mod m)
 a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD) { return pow(n, MOD - 2, MOD); }

ll C(ll n, ll r, ll MOD) {

  return (f[n] *
          ((InverseEuler(f[r], MOD) * InverseEuler(f[n - r], MOD)) % MOD)) %
         MOD;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  f[0] = 1;
  for (int i = 1; i <= 100000; i++)
    f[i] = (f[i - 1] * i) % INF;

  //	cout << C(10000,2,INF) << endl;

  int n;
  cin >> n;

  int k;
  cin >> k;
  ll sum = 0;
  for (int i = 2; i <= n; i++) {
    sum = sum + C(n + 1, i, INF);
    sum = sum % INF;
  }
  cout << sum % INF << "\\n";

  return 0;
}
Problem p02708 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main() {
  ll n, k;
  cin >> n >> k;
  ll i, ans = 0, j, mod = 1e9 + 7;
  for (i = k; i <= n + 1; i++) {
    ll sum = 0, sum1 = 0;
    sum = i * (i - 1) / 2;
    sum1 = i * (n + n - i + 1) / 2;
    ans += sum1 - sum + 1;
    ans %= mod;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main() {
  ll n, k;
  cin >> n >> k;
  ll i, ans = 0, j, mod = 1e9 + 7;
  for (i = k; i <= n + 1; i++) {
    ll sum = 0, sum1 = 0;
    for (j = 0; j < i; j++) {
      sum += j;
      sum1 += n - j;
    }
    ans += sum1 - sum + 1;
    ans %= mod;
  }
  cout << ans;
}
Problem p02708 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define sort(A) sort(A.begin(), A.end())
#define reverse(A) reverse(A.begin(), A.end());
#define vecmin(A) *min_element(A.begin(), A.end());
#define vecmax(A) *max_element(A.begin(), A.end());
typedef long long ll;

ll f(ll n, ll k) { return -k * k + k + n * k + 1; }

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for (ll i = k; i <= n + 1; i++) {
    ans += f(n, i);
    ans %= 1000000007;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define sort(A) sort(A.begin(), A.end())
#define reverse(A) reverse(A.begin(), A.end());
#define vecmin(A) *min_element(A.begin(), A.end());
#define vecmax(A) *max_element(A.begin(), A.end());
typedef long long ll;

ll sum(ll n) {
  ll ans = 0;
  for (ll i = 1; i <= n; i++)
    ans += i;
  return ans;
}

ll f(ll n, ll k) {
  ll left = sum(n) - sum(n - k);
  ll right = sum(k - 1);
  return left - right + 1;
}

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for (ll i = k; i <= n + 1; i++) {
    ans += f(n, i);
    ans %= 1000000007;
  }
  cout << ans << endl;
}
Problem p02708 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

const long long MOD = 1000000007;

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

  vector<long long> ascSums(N + 1, 0LL);
  vector<long long> descSums(N + 1, 0LL);
  ascSums[0] = 0;
  descSums[0] = N;
  for (long long i = 1; i < N + 1; ++i) {
    ascSums[i] = ascSums[i - 1] + i;
    descSums[i] = descSums[i - 1] + (N - i);
    ascSums[i] %= MOD;
    descSums[i] %= MOD;
  }

  long long patterns = 0;
  for (long long k = K; k <= N + 1; ++k) {
    patterns += descSums[k - 1] - ascSums[k - 1] + 1;
    patterns %= MOD;
  }
  if (patterns < 0) {
    patterns += MOD;
  }
  cout << patterns << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

const long long MOD = 1000000007;

long long numOfSumPatterns(long long N, long long k) {
  long long minSum = 0;
  long long maxSum = 0;
  for (int i = 0; i < k; ++i) {
    minSum += i;
    maxSum += N - i;
  }
  long long n = maxSum - (minSum - 1);
  // long long n = 1;
  //// N C (k-1)
  // for (long long i = 0; i < k - 1ll; ++i) {
  //     n *= (N - i);
  //     if (n > MOD) {
  //         n = n % MOD;
  //     }
  // }
  // for (long long i = 1LL; i <= k - 1LL; ++i) {
  //     n /= i;
  // }

  // n += N - k + 1;
  return n;
}

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

  long long patterns = 0;
  for (long long k = K; k <= N + 1; ++k) {
    patterns += numOfSumPatterns(N, k);
    if (patterns > MOD) {
      patterns = patterns % MOD;
    }
  }
  cout << patterns << endl;
  return 0;
}
Problem p02708 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
const int INF = 0x7fffffff;
const int MOD = 1000000007;
using lll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
  lll ii, jj, kk;
  vector<int> ret;
  int n, k;

  cin >> n >> k;

  lll minNum, maxNum;
  lll sum = 0;
  lll cnt;
  for (ii = k; ii <= n + 1; ii++) {

    minNum = 0;
    maxNum = 0;

    // for(jj=0,cnt=0;jj<ii;jj++,cnt++){
    //   minNum += cnt;
    //   maxNum += (n-cnt);
    // }
    minNum = (ii * (ii - 1)) / 2;
    maxNum = n * ii - minNum;
    // cout << "maxNum:" << maxNum << "minNum:" << minNum << endl;

    sum = (sum + maxNum - minNum + 1) % MOD;
  }

  cout << sum << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
const int INF = 0x7fffffff;
const int MOD = 1000000007;
using lll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
  lll ii, jj, kk;
  vector<int> ret;
  int n, k;

  cin >> n >> k;

  lll minNum, maxNum;
  lll sum = 0;
  lll cnt;
  for (ii = k; ii <= n + 1; ii++) {

    minNum = 0;
    maxNum = 0;

    for (jj = 0, cnt = 0; jj < ii; jj++, cnt++) {
      minNum += cnt;
      maxNum += (n - cnt);
    }

    // cout << "maxNum:" << maxNum << "minNum:" << minNum << endl;

    sum = (sum + maxNum - minNum + 1) % MOD;
  }

  cout << sum << endl;

  return 0;
}
Problem p02708 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define MAXN 200005
#define MOD 1000000007
using namespace std;

long long n, k, prefix[MAXN], suffix[MAXN], ans[MAXN];

int main() {
  cin >> n >> k;
  suffix[1] = n;
  for (long long i = 2; i <= n; i++) {
    prefix[i] = prefix[i - 1] + i - 1;
    suffix[i] = suffix[i - 1] + n - i + 1;
    prefix[i] %= MOD;
    suffix[i] %= MOD;
  }
  ans[n + 1] = 1;
  for (long long i = n; i >= 1; i--) {
    ans[i] = ans[i + 1] + suffix[i] - prefix[i] + 1;
    ans[i] = (ans[i] + MOD) % MOD;
  }
  cout << ans[k] << "\\n";
}

Error: 0

Fixed submission:

#include <iostream>
#define MAXN 100005
#define MOD 1000000007
using namespace std;

long long n, k, prefix[MAXN], suffix[MAXN], ans[MAXN];

int main() {
  cin >> n >> k;
  suffix[1] = n;
  for (long long i = 2; i <= n; i++) {
    prefix[i] = prefix[i - 1] + i - 1;
    suffix[i] = suffix[i - 1] + n - i + 1;
    prefix[i] %= MOD;
    suffix[i] %= MOD;
  }
  ans[n + 1] = 1;
  // for (int i=0; i<=n; i++) {
  // 	cout << prefix[i] << ' ' << suffix[i] << "\\n";
  // }
  for (long long i = n; i >= 1; i--) {
    ans[i] = ans[i + 1] + suffix[i] - prefix[i] + 1;
    ans[i] %= MOD;
  }
  cout << ans[k] << "\\n";
}
Problem p02708 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define ST_ARR_LEN(array) (sizeof(array) / sizeof(*array))

using namespace std;

using ll = long long;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;
typedef vector<int> IntVector;
typedef list<int> IntList;

typedef struct S {
  int a;
  int b;
} Object;

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

  ll sum = 0;
  ll min, max;
  for (long long i = K; i <= N; i++) {
    if (i == 1) {
      min = 0;
    } else if (i == 2) {
      min = 1;
    } else {
      min = i * (i - 1) / 2;
    }
    max = i * (2 * N - i + 1) / 2;
    sum += (max - min + 1);
    sum = sum % 1000000007;
  }
  sum++;

  cout << sum << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define ST_ARR_LEN(array) (sizeof(array) / sizeof(*array))

using namespace std;

using ll = long long;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;
typedef vector<int> IntVector;
typedef list<int> IntList;

typedef struct S {
  int a;
  int b;
} Object;

ll factorial(ll n) {
  ll fac = 1;
  while (n > 0) {
    fac *= n;
    n--;
  }
  return fac;
}
ll permutation(ll n, ll k) {
  if (k == 0)
    return 1;
  ll per = n;
  for (int i = 1; i < k; i++) {
    per *= (n - i);
  }
  return per;
}
ll combination(ll n, ll k) {
  if (n - k < k)
    k = n - k;
  ll com = (permutation(n, k)) / (factorial(k));
  return com;
}

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

  ll c;
  ll sum = 0;
  for (int i = K; i <= N; i++) {
    c = combination(N + 1, i);
    sum += c - ((N * (N + 1) / 2) - (i * (2 * N - i + 1) / 2));
  }
  sum++;

  cout << sum << endl;
}
Problem p02708 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#define P 1000000000 + 7
typedef long long int lli;
using namespace std;

int main(void) {
  lli n, k;
  lli min, max;

  cin >> n >> k;
  lli sum = 0;
  for (lli i = k; i <= n + 1; i++) {
    min = (2 * 0 + (i - 1) * 1) * i / 2;
    max = (2 * n + (i - 1) * -1) * i / 2;
    // cout<<"min="<<min<<" max="<<max<<endl;

    sum += max - min + 1;
    sum %= P;
  }
  cout << sum << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#define P 1000000000 + 7
typedef long long int lli;
using namespace std;

void yespr() { cout << "Yes\\n" << endl; }
void nopr() { cout << "No\\n" << endl; }
lli comb(lli n, lli r) {
  vector<vector<long long>> v(n + 1, vector<long long>(n + 1, 0));
  for (lli i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (lli j = 1; j < v.size(); j++) {
    for (lli k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v[n][r];
}

int main(void) {
  lli n, k;

  cin >> n >> k;
  lli sum = 0;
  for (lli i = k; i <= n; i++) {
    sum += comb(n + 1, i);
    sum %= P;
  }
  if (k > n)
    cout << 1 << endl;
  else
    cout << sum << endl;
  return 0;
}
Problem p02708 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h> //ABC 163_d
#define ll long long
using namespace std;
ll n, ans, k;
const ll mod = 1e9 + 7;
int main() {
  cin >> n >> k;
  for (ll i = k; i <= n + 1; i++) {
    ll l = (0 + i - 1) * i / 2;
    ll r = (n - i + 1 + n) * i / 2;
    ans = (ans + r - l + 1) % mod;
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h> //ABC 162_d
#define ll long long
using namespace std;
string t;
int s[4][4005], a[4005];
long long ans, n;
int main() {
  cin >> n >> t;
  for (int i = 1; i <= n; i++) {
    if (t[i - 1] == 'R')
      a[i] = 0;
    if (t[i - 1] == 'G')
      a[i] = 1;
    if (t[i - 1] == 'B')
      a[i] = 2;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 2; j++)
      s[j][i] = s[j][i - 1];
    s[a[i]][i] = s[a[i]][i - 1] + 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (a[i] == a[j])
        continue;
      ans += s[3 - a[i] - a[j]][n] - s[3 - a[i] - a[j]][j];
      if (2 * j - i <= n && a[2 * j - i] == 3 - a[i] - a[j])
        ans++;
    }
  }
  cout << ans;
  return 0;
}
Problem p02708 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long n, k;
  cin >> n >> k;
  const int MOD = 1000000007;
  long long add;
  long long sum = 0;

  for (long long i = k; i <= n + 1; i++) {
    long long minsum = i * (i - 1) / 2;
    long long maxsum = i * ((2 * n) - i + 1) / 2;
    add = maxsum - minsum + 1;
    sum = (sum + add) % MOD;
  }
  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

  for (int i = k; i <= n + 1; i++) {
    long long minsum = 0;
    long long maxsum = 0;
    for (int j = 0; j < i; j++) {
      minsum += j;
      maxsum += n - j;
    }
    sum += maxsum - minsum + 1;
  }
  long long result = fmod(sum, 1000000007);
  cout << result << endl;
  return 0;
}