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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 10;
const ll mod = 1e9 + 7;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> pre(n + 10);
  vector<ll> suf(n + 10);
  ll sum = 0;
  for (ll i = 0; i <= n + 1; i++) {
    sum += i;
    pre[i] = sum;
  }
  sum = 0;
  for (ll i = n + 1; i >= 0; i--) {
    sum += i;
    suf[n + 2 - i] = sum;
  }
  ll ans = 0;
  for (ll i = k; i <= n + 1; i++) {
    ans += (suf[i] - pre[i] + 1ll) % mod;
    ans %= mod;
  }
  cout << ans;
  return 0;
}

Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 10;
const ll mod = 1e9 + 7;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> pre(n + 2);
  vector<ll> suf(n + 2);
  ll sum = 0;
  for (ll i = 0; i <= n + 1; i++) {
    sum += i;
    pre[i] = sum;
  }
  sum = 0;
  for (ll i = n + 1; i >= 0; i--) {
    sum += i;
    suf[n + 2 - i] = sum;
  }
  ll ans = 0;
  for (int i = k; i <= n + 1; i++) {
    ans += (suf[i] - pre[i] + 1) % mod;
    ans %= mod;
  }
  cout << ans;
  return 0;
}
Problem p02708 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t A, x, answer;
  int N, K;
  answer = 0;
  cin >> N >> K;
  for (x = K; x < N + 2; x++) {
    A = x * N + 1 - x * (x - 1);
    answer = (answer + A) % 1000000007;
  }
  cout << answer % 1000000007 << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N, K, A, x, answer;
  answer = 0;
  cin >> N >> K;
  for (x = K; x < N + 2; x++) {
    A = x * N + 1;
    for (int i = 1; i < x; i++) {
      A -= 2 * i;
    }
    answer += A;
  }
  cout << answer % 1000000007 << endl;
}
Problem p02708 (C++) — buggy submission, verdict: Runtime Error

/**
 * D - Sum of Large Numbers
 * https://atcoder.jp/contests/abc163/tasks/abc163_d
 *
 * TODO: 未完成です
 */
#include <bits/stdc++.h>
using namespace std;

long long mod = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7;

int main() {
  // 10100, 10100+1, ..., 10100+N の N+1 個の数があります。
  // この中から K 個以上の数を選ぶとき、その和としてあり得るものの個数を
  // mod(109+7) で求めてください。
  long long N, K;
  cin >> N >> K;

  long long pattern = 0;
  for (long long i = K; i <= N + 1; i++) {
    /*
    if (i == N + 1) {
        pattern += 1;
        continue;
    }*/

    // min = 0,1,2...i - 1;
    // long long min = i * (i - 1) / 2;
    // min = N,N-1...N - i + 1;
    // long long max = i * (2 * N - i + 1) / 2;

    // cout << i << " "  << min << " " << max << endl;
    //  pattern += ((i * (2 * N - i + 1) - (i * (i - 1)) / 2) + 1;
    //  pattern += ((2 * N * i - i * i + i) - (i * i - i)) / 2) + 1;
    //  pattern += (2Ni - ii + i - ii + i) / 2) + 1;
    pattern += (N - i + 1) * i + 1;
    pattern = pattern % mod;
  }

  cout << pattern << endl;
}


Error: 0

Fixed submission:

/**
 * D - Sum of Large Numbers
 * https://atcoder.jp/contests/abc163/tasks/abc163_d
 */
#include <bits/stdc++.h>
using namespace std;

int main() {
  // 10100, 10100+1, ..., 10100+N の N+1 個の数があります。
  // この中から K 個以上の数を選ぶとき、その和としてあり得るものの個数を
  // mod(109+7) で求めてください。
  int N, K;
  cin >> N >> K;

  double pattern = 0;
  for (int i = K; i < N + 1; i++) {
    // (N + 1) c (i);
    int bunshi = 1, bunbo = 1;
    for (int cnt = 0; cnt < i; cnt++) {
      bunshi *= N + 1 - cnt;
    }
    for (int cnt = 0; cnt < i; cnt++) {
      bunbo *= cnt + 1;
    }

    // cout << bunshi << ' ' << bunbo << endl;
    pattern += bunshi / bunbo;
    // この中から K 個以上の数を選ぶとき、その和としてあり得るものの個数を
    // mod(109+7) で求めてください。
    pattern = fmod(pattern, pow(10, 9) + 7);
  }

  cout << pattern << endl;
}
Problem p02708 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll bikkuri(ll n) {
  if (n <= 0) {
    return 0;
  }
  return (n + 1) * n / 2;
}

int main() {
  ll N, K;
  cin >> N >> K;
  ll sum = 0;
  for (int k = K; k <= N + 1; k++) {
    sum += (bikkuri(N) - bikkuri(N - k) - bikkuri(k - 1) + 1);
    // cout << k << " : " << bikkuri(N) - bikkuri(N - k) - bikkuri(k - 1) + 1 <<
    // endl;
    sum = sum % (1000000000 + 7);
  }
  cout << sum << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

int main() {
  ll N, K;
  cin >> N >> K;
  ll sum = 0;
  for (int k = K; k <= N + 1; k++) {
    sum += (bikkuri(N) - bikkuri(N - k) - bikkuri(k - 1) + 1);
    // cout << k << " : " << bikkuri(N) - bikkuri(N - k) - bikkuri(k - 1) + 1 <<
    // endl;
    sum = sum % (1000000000 + 7);
  }
  cout << sum << endl;
}
Problem p02708 (C++) — buggy submission, verdict: Runtime Error

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

const int mod = 1000000007;

ll sum(ll l, ll r) { return (l + r) / 2 * (r - l + 1); }

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

  ll ans = 0;
  ;

  for (int i = k; i <= n + 1; i++) {
    ll l = sum(0, i - 1);
    ll r = sum(n - i + 1, n);
    ans += r - l + 1;
  }
  cout << ans % mod << endl;
}

Error: WA

Fixed submission:

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

int solve(int n) {
  if (n == 1 || n == 0)
    return 1;
  return n * solve(n - 1);
}

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

  // ans = ((n+1)!/k!) + ((n+1)!/(k+1)!) + ... + (n+1)!/(n+1)!
  int N = solve(n + 1);
  ll ans = 0;
  for (int i = k; i <= n + 1; i++) {
    ans += N / solve(i) / solve(n + 1 - i);
  }

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define P pair<int, int>
using ll = int64_t;
using namespace std;
#define ketasuu(n) fixed << setprecision(n)
#define btoe(p) p.begin(), p.end()
#define etob(p) p.rbegin(), p.rend()

const ll mod = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> m(10000000);
  ll s = 0, e = 0, a = 0, b = n;
  rep(i, n + 2) {
    s += a;
    a++;
    e += b;
    b--;
    m[i + 1] = e - s + 1;
  }
  ll ans = 0;
  for (int i = k; i < n + 2; ++i) {
    ans += m[i];
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Error: -6
malloc(): corrupted top size


Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define P pair<int, int>
using ll = int64_t;
using namespace std;
#define ketasuu(n) fixed << setprecision(n)
#define btoe(p) p.begin(), p.end()
#define etob(p) p.rbegin(), p.rend()

const ll mod = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> m(n + 2);
  ll s = 0, e = 0, a = 0, b = n;
  rep(i, n + 2) {
    s += a;
    a++;
    e += b;
    b--;
    m[i + 1] = e - s + 1;
  }
  ll ans = 0;
  for (int i = k; i < n + 2; ++i) {
    ans += m[i];
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02708 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> pf(n + 2);
  ll sum = 0;
  for (int i = 0; i <= n; i++) {
    sum += i;
    pf[i + 1] = sum;
  }
  ll ans = 0;
  for (int i = k; i <= n + 1; i++) {
    ll low = pf[i];
    ll high = pf[n + 1] - pf[n + 1 - i];
    ans = (ans + (high - low + 1)) % mod;
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
ll dp(int n, int k) {
  ll table[n + 1][k + 1];
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0 || j == i)
        table[i][j] = 1;
      else
        table[i][j] = (table[i - 1][j] % mod + table[i - 1][j - 1] % mod) % mod;
    }
  }
  return table[n][k];
}

int main() {
  int n, k;
  cin >> n >> k;
  ll ans = dp(n + 1, k);
  cout << ans;
  return 0;
}
Problem p02708 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
#define MOD 1000000007

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

  ll n, k;
  cin >> n >> k;
  vector<int> dp = {};
  dp.resize(n, 0);

  // 累積和
  for (auto i = 0; i < n + 1; i++) {
    if (i != 0) {
      dp[i] = (dp[i - 1] + i) % MOD;
    }
  }

  ll total = 0;
  for (ll i = k; i < n + 1; i++) {
    ll max = dp[n] - dp[n - i];
    ll min = dp[i - 1];
    ll val = max - min + 1;

    total += val;
    total %= MOD;
  }

  if (total < 0)
    total += MOD;

  total += 1;
  total %= MOD;
  cout << total << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
#define MOD 1000000007

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> dp = {};
  dp.resize(n, 0);

  // 累積和
  for (auto i = 0; i < n + 1; i++) {
    if (i != 0) {
      dp[i] = (dp[i - 1] + i) % MOD;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define print(a) cout << a << endl;
#define printVec(v)                                                            \\
  printf("{");                                                                 \\
  for (const auto &i : v) {                                                    \\
    std::cout << i << ", ";                                                    \\
  }                                                                            \\
  printf("}\\n");
inline int newline() {
  putchar('\\n');
  return 0;
}

int main() {
  ll n, k;
  cin >> n >> k;

  ll result = 0;

  erep3(i, k, n + 1) {
    ll min = i * (0 + i - 1) / 2;
    ll max = i * (n - i + 1 + n) / 2;

    result += max - min + 1;
  }

  print(result % 1000000007);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define print(a) cout << a << endl;
#define printVec(v)                                                            \\
  printf("{");                                                                 \\
  for (const auto &i : v) {                                                    \\
    std::cout << i << ", ";                                                    \\
  }                                                                            \\
  printf("}\\n");
inline int newline() {
  putchar('\\n');
  return 0;
}

int main() {
  ll n, k;
  cin >> n >> k;

  ll result = 0;

  rep3(i, k, n + 2) {
    ll min = 0;
    ll max = 0;

    for (int j = 0; j < i; ++j) {
      min += j;
    }

    for (int j = n; j > n - i; --j) {
      max += j;
    }

    result += max - min + 1;
  }

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

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP1(i, n) for (ll i = 1; i <= (ll)(n); i++)

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

ll lcm(int a, int b) { return a * b / gcd(a, b); }

ll power(ll a, ll n) {
  if (n == 0)
    return 1;
  ll p = power(a, n / 2);
  p = (p * p);
  if (n % 2)
    return (p * a);
  else
    return p;
}

int main() {
  ios_base::sync_with_stdio(false); // for fast I/O operation
  cin.tie(NULL);

  ll mod = 1000000007;

  ll n, k;
  cin >> n >> k;
  ll c = 0;

  ll s[n + 1];
  s[0] = 0;
  REP(i, n) { s[i + 1] = s[i] + i + 1; }

  for (int i = k; i <= n + 1; i++) {
    ll min = 0;
    min = s[i - 1] - s[0];
    ll max = 0;
    if (i != n + 1) {
      max = s[n] - s[n - i];
    } else {
      max = s[n];
    }
    c += max - min + 1;
    c = c % mod;
  }
  cout << c << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP1(i, n) for (ll i = 1; i <= (ll)(n); i++)

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

ll lcm(int a, int b) { return a * b / gcd(a, b); }

ll power(ll a, ll n) {
  if (n == 0)
    return 1;
  ll p = power(a, n / 2);
  p = (p * p);
  if (n % 2)
    return (p * a);
  else
    return p;
}

int main() {
  ios_base::sync_with_stdio(false); // for fast I/O operation
  cin.tie(NULL);

  ll mod = 1000000007;

  ll n, k;
  cin >> n >> k;
  ll c = 0;
  for (int i = k; i <= n + 1; i++) {
    ll min = 0;
    for (ll j = 0; j < i; j++) {
      min += j;
    }
    ll max = 0;
    for (ll j = n - i + 1; j <= n; j++) {
      max += j;
    }
    c += max - min + 1;
    c = c % mod;
  }
  cout << c << endl;
}
Problem p02708 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
constexpr int mo = 1e9 + 7;
constexpr int inf = 1 << 30;
constexpr ll infl = 1ll << 60;
constexpr ll mo2 = 998244353;
const double PAI = acos(-1);
constexpr long double eps = 1e-9;

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

  ll n, k;
  cin >> n >> k;

  ll ret = 0;
  for (ll i = k; i <= n + 1; ++i) {
    ll mi = (i - 1) * i / 2;
    ll ma = (n + (n - i + 1)) * i / 2;
    (ret += ma - mi + 1) %= mo;
  }
  cout << ret << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
constexpr int mo = 1e9 + 7;
constexpr int inf = 1 << 30;
constexpr ll infl = 1ll << 60;
constexpr ll mo2 = 998244353;

ll comb(ll N_, ll C_) {
  const int NUM_ = 2000001;
  static ll fact[NUM_ + 1], factr[NUM_ + 1], inv[NUM_ + 1];
  if (fact[0] == 0) {
    inv[1] = fact[0] = factr[0] = 1;
    for (int i = 2; i <= NUM_; ++i)
      inv[i] = inv[mo % i] * (mo - mo / i) % mo;
    for (int i = 1; i <= NUM_; ++i)
      fact[i] = fact[i - 1] * i % mo, factr[i] = factr[i - 1] * inv[i] % mo;
  }
  if (C_ < 0 || C_ > N_)
    return 0;
  return factr[C_] * fact[N_] % mo * factr[N_ - C_] % mo;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

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

#include <bits/stdc++.h>
#define ll long long
const int N = 1e9 + 7;
using namespace std;
ll n, k, ans, ans1, ans2, a, b;
int main() {
  cin >> n >> k;
  for (a = 1; a <= k - 1; a++)
    ans1 += a;
  for (b = n; b >= n + 1 - k; b--)
    ans2 += b;
  ans += ans2 - ans1 + 1;
  ans %= N;
  for (int i = k + 1; i <= n + 1; i++) {
    ans1 += a;
    a++;
    ans2 += b;
    b--;
    ans += (ans2 - ans1 + 1);
    ans %= N;
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

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

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

long long comb(long long n, long long k) {
  long long ans = 1;
  if (k > n - k)
    k = n - k;
  long long p = (long long)pow(10, 9) + 7;
  for (int i = 0; i < k; i++) {
    ans *= n - i;
    ans = ans % p;
  }
  for (int i = 0; i < k; i++) {
    ans = ans / (k - i);
  }
  return ans;
}
int main() {
  long long n, k;
  cin >> n >> k;
  long long ans = 0;
  for (long long i = k; i <= n + 1; i++) {
    long long min = 0, max = 0;
    min = (i * (i - 1)) / 2;
    max = ((2 * n - i + 1) * i) / 2;
    ans += max - min + 1;
  }
  ans = ans % ((long long)pow(10, 9) + 7);
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

long long comb(long long n, long long k) {
  long long ans = 1;
  if (k > n - k)
    k = n - k;
  long long p = (long long)pow(10, 9) + 7;
  for (int i = 0; i < k; i++) {
    ans *= n - i;
    ans = ans % p;
  }
  for (int i = 0; i < k; i++) {
    ans = ans / (k - i);
  }
  return ans;
}
int main() {
  long long n, k;
  cin >> n >> k;
  long long ans = 0;
  for (int i = k; i <= n + 1; i++) {
    long long min = 0, max = 0;
    for (int j = 0; j < i; j++) {
      min += j;
      max += n - j;
    }
    ans += max - min + 1;
  }
  ans = ans % ((long long)pow(10, 9) + 7);
  cout << ans << endl;
  return 0;
}
Problem p02708 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
/****** define constant end ********/
/****** define variable start ******/
ll n, k;
/******* define variable end *******/
int solve() {
  cin >> n >> k;
  vl ma(n + 5);
  vl mi(n + 5);
  ll ans = 0;
  for (ll i = k; i <= n + 1; i++) {
    mi[i] = i * (i - 1) / 2;
    ma[i] = n * (n + 1) / 2 - (n + 1 - i) * (n - i) / 2;
    ans += ma[i] - mi[i] + 1;
    ans %= MOD;
  }
  cout << ans % MOD << endl;
  return 0;
}

int main() {
  // clock_t start = clock();
  cout << std::fixed << std::setprecision(10);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int end_solve = solve();
  /*
  clock_t end = clock();
  const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
  1000.0; printf("time %lf[ms]\\n", time);
  */

  return end_solve;
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
/****** define constant end ********/
/****** define variable start ******/
ll n, k;
/******* define variable end *******/
int solve() {
  cin >> n >> k;
  vl ma(n);
  vl mi(n);
  ll ans = 0;
  for (ll i = k; i <= n + 1; i++) {
    mi[i] = i * (i - 1) / 2;
    ma[i] = n * (n + 1) / 2 - (n + 1 - i) * (n - i) / 2;
    ans += ma[i] - mi[i] + 1;
    ans %= MOD;
  }
  cout << ans % MOD << endl;
  return 0;
}

int main() {
  // clock_t start = clock();
  cout << std::fixed << std::setprecision(10);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int end_solve = solve();
  /*
  clock_t end = clock();
  const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
  1000.0; printf("time %lf[ms]\\n", time);
  */

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

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

int main() {

  long N;
  long K;
  cin >> N >> K;

  long ans = 0;

  vector<long> bb(N + 2);
  vector<long> aa(N + 2);
  aa.at(0) = 0;
  bb.at(0) = 0;
  for (int i = 1; i < N + 2; i++) {
    bb.at(i) = bb.at(i - 1) + (i - 1);
  }

  for (int i = 1; i < N + 2; i++) {
    aa.at(i) = aa.at(i - 1) + N - (i - 1);
  }
  for (int j = K; j < N + 2; j++) {

    ans = ans + 1 + aa.at(j) - bb.at(j);

    ans = ans % 1000000007;
  }

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

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)


Fixed submission:

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

int main() {

  long N;
  long K;
  cin >> N >> K;

  long ans = 0;

  vector<long> bb(N + 1);
  vector<long> aa(N + 1);
  aa.at(0) = 0;
  bb.at(0) = 0;
  for (int i = 1; i < N + 2; i++) {
    bb.at(i) = bb.at(i - 1) + (i - 1);
  }

  for (int i = 1; i < N + 2; i++) {
    aa.at(i) = aa.at(i - 1) + N - (i - 1);
  }
  for (int j = K; j < N + 2; j++) {

    ans = ans + 1 + aa.at(j) - bb.at(j);

    ans = ans % 1000000007;
  }

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

#include <iostream>
using namespace std;
int main() {
  long long int N, k, i, j, ans = 0;
  cin >> N >> k;
  long long int start_value = 0;
  long long int end_value = 0;
  for (j = 0; j < k; j++) {
    start_value += j;
    end_value += N - j;
  }
  ans += end_value - start_value + 1;
  start_value += k;
  end_value = end_value + N - k;
  // ans=ans%1000000007;
  // cout<<start_value<<endl;
  // cout<<end_value<<endl;

  for (i = k + 1; i <= N + 1; i++) {
    ans += end_value - start_value + 1;
    ans = ans % 1000000007;
    start_value = start_value + i;
    end_value = end_value + N - i;

    // cout<<start_value<<endl;
    // cout<<end_value<<endl;
    // cout<<ans<<endl;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long int N, k, i, j, ans = 0;
  cin >> N >> k;

  for (i = k; i <= N + 1; i++) {
    long long int start_value = 0;
    long long int end_value = 0;
    for (j = 0; j < i; j++) {
      start_value += j;
      end_value += N - j;
    }
    ans += end_value - start_value + 1;
    ans = ans % 1000000007;
  }

  cout << ans << 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 c = 0;
  for (long long kk = k; kk <= n + 1; kk++) {
    c = (kk * (n + 1 - kk) + 1 + c) % (1000000007);
  }
  cout << c << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  long long c = 0;
  for (int kk = k; kk <= n + 1; kk++) {
    long long b = 1;
    for (int i = 0; i < kk; i++)
      b += (n - 2 * i) % (1000000007);
    c = (b + c) % (1000000007);
  }
  cout << c << endl;
  return 0;
}