Language: C++

#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define getsize(x) ((long long)(x).size())
#define srt(x) sort((x).begin(), (x).end())
#define rsrt(x) sort((x).rbegin(), (x).rend())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vc = vector<char>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
template<class T>void print(T x) { cout << '\n' << "== " << x << " ==" << '\n'; }
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>void precise(T x) { cout << setprecision(21) << x << '\n'; }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long double doublepi = M_PI * 2.0;
const long double halfpi = M_PI / 2.0;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long MOD = 1e9 + 7;

int main()
{
    ll N, K;
    cin >> N >> K;
    vll nums(N+1);
    rep(i, 0, N+1) {
        nums[i] = i;
    }
    vll acc(N+2, 0);
    rep(i, 0, N+1) {
        acc[i+1] = (acc[i] + nums[i]) % MOD;
    }

    ll sm = 0;
    rep(i, K, N+2) {
        ll left = (acc[i] - acc[0]) % MOD;
        ll right = (acc[N+1] - acc[N+1-i]) % MOD;
        if (right < 0) right += MOD;
         cout << acc[N+1-i] << ' ' << acc[N+1] << endl;
        ll ans = (right - left + 1) % MOD;
        if (ans < 0) ans += MOD;
        sm = (sm + ans) % MOD;
    }
    cout << sm << endl;
}
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define getsize(x) ((long long)(x).size())
#define srt(x) sort((x).begin(), (x).end())
#define rsrt(x) sort((x).rbegin(), (x).rend())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vc = vector<char>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
template<class T>void print(T x) { cout << '\n' << "== " << x << " ==" << '\n'; }
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>void precise(T x) { cout << setprecision(21) << x << '\n'; }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long double doublepi = M_PI * 2.0;
const long double halfpi = M_PI / 2.0;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long MOD = 1e9 + 7;

int main()
{
    ll N, K;
    cin >> N >> K;
    vll nums(N+1);
    rep(i, 0, N+1) {
        nums[i] = i;
    }
    vll acc(N+2, 0);
    rep(i, 0, N+1) {
        acc[i+1] = (acc[i] + nums[i]) % MOD;
    }

    ll sm = 0;
    rep(i, K, N+2) {
        ll left = (acc[i] - acc[0]) % MOD;
        ll right = (acc[N+1] - acc[N+1-i]) % MOD;
        if (right < 0) right += MOD;
         cout << acc[N+1-i] << ' ' << acc[N+1] << endl;
        ll ans = (right - left + 1) % MOD;
        if (ans < 0) ans += MOD;
        sm = (sm + ans) % MOD;
    }
    cout << sm << endl;
}


Compiler output:
a.cc:74:23: error: redefinition of 'template<class T> void print(T)'
   74 | template<class T>void print(T x) { cout << '\n' << "== " << x << " ==" << '\n'; }
      |                       ^~~~~
a.cc:17:23: note: 'template<class T> void print(T)' previously declared here
   17 | template<class T>void print(T x) { cout << '\n' << "== " << x << " ==" << '\n'; }
      |                       ^~~~~
a.cc:75:23: error: redefinition of 'template<class T> void print1d(T, ll)'
   75 | template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
      |                       ^~~~~~~
a.cc:18:23: note: 'template<class T> void print1d(T, ll)' previously declared here
   18 | template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
      |                       ^~~~~~~
a.cc:76:23: error: redefinition of 'template<class T> void print2d(T, ll, ll)'
   76 | template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
      |                       ^~~~~~~
a.cc:19:23: note: 'template<class T> void print2d(T, ll, ll)' previously declared here
   19 | template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
      |                       ^~~~~~~
a.cc:77:23: error: redefinition of 'template<class T> void precise(T)'
   77 | template<class T>void precise(T x) { cout << setprecision(21) << x << '\n'; }
      |                       ^~~~~~~
a.cc:20:23: note: 'template<class T> void precise(T)' previously declared here
   20 | template<class T>void precise(T x) { cout << setprecision(21) << x << '\n'; }
      |                       ^~~~~~~
a.cc:78:23: error: redefinition of 'template<class T> bool chmax(T&, const T&)'
   78 | template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
      |                       ^~~~~
a.cc:21:23: note: 'template<class T> bool chmax(T&, const T&)' previously declared here
   21 | template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
      |                       ^~~~~
a.cc:79:23: error: redefinition of 'template<class T> bool chmin(T&, const T&)'
   79 | template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
      |                       ^~~~~
a.cc:22:23: note: 'template<class T> bool chmin(T&, const T&)' previously declared here
   22 | template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
      |                       ^~~~~
a.cc:80:29: error: redefinition of 'template<class T, class U> T rem(T, U)'
   80 | template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
      |                             ^~~
a.cc:23:29: note: 'template<class T, class U> T rem(T, U)' previously declared here
   23 | template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
      |                             ^~~
a.cc:81:21: error: redefinition of 'template<class T> ld deg2rad(T)'
   81 | template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
      |                     ^~~~~~~
a.cc:24:21: note: 'template<class T> ld deg2rad(T)' previously declared here
   24 | template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
      |                     ^~~~~~~
a.cc:82:21: error: redefinition of 'template<class T> ld rad2deg(T)'
   82 | template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
      |                     ^~~~~~~
a.cc:25:21: note: 'template<class T> ld rad2deg(T)' previously declared here
   25 | template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
      |                     ^~~~~~~
a.cc:83:19: error: redefinition of 'const long double pi'
   83 | const long double pi = M_PI;
      |                   ^~
a.cc:26:19: note: 'const long double pi' previously defined here
   26 | const long double pi = M_PI;
      |                   ^~
a.cc:84:19: error: redefinition of 'const long double doublepi'
   84 | const long double doublepi = M_PI * 2.0;
      |                   ^~~~~~~~
a.cc:27:19: note: 'const long double doublepi' previously defined here
   27 | const long double doublepi = M_PI * 2.0;
      |                   ^~~~~~~~
a.cc:85:19: error: redefinition of 'const long double halfpi'
   85 | const long double halfpi = M_PI / 2.0;
      |                   ^~~~~~
a.cc:28:19: note: 'const long double halfpi' previously defined here
   28 | const long double halfpi = M_PI / 2.0;
      |                   ^~~~~~
a.cc:86:17: error: redefinition of 'const long long int big'
   86 | const long long big = 1LL << 50;
      |                 ^~~
a.cc:29:17: note: 'const long long int big' previously defined here
   29 | const long long big = 1LL << 50;
      |                 ^~~
a.cc:87:17: error: redefinition of 'const long long int inf'
   87 | const long long inf = 1LL << 60;
      |                 ^~~
a.cc:30:17: note: 'const long long int inf' previously defined here
   30 | const long long inf = 1LL << 60;
      |                 ^~~
a.cc:88:17: error: redefinition of 'const long long int MOD'
   88 | const long long MOD = 1e9 + 7;
      |                 ^~~
a.cc:31:17: note: 'const long long int MOD' previously defined here
   31 | const long long MOD = 1e9 + 7;
      |                 ^~~
a.cc:90:5: error: redefinition of 'int main()'
   90 | int main()
      |     ^~~~
a.cc:33:5: note: 'int main()' previously defined here
   33 | int main()
      |     ^~~~