Problem:
Score : 400 points

Problem Statement

We have N+1 integers: 10^{100}, 10^{100}+1, ..., 10^{100}+N.

We will choose K or more of these integers. Find the number of possible values of the sum of the chosen numbers, modulo (10^9+7).

Constraints

1 \leq N \leq 2\times 10^5

1 \leq K \leq N+1

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of possible values of the sum, modulo (10^9+7).

Sample Input 1

3 2

Sample Output 1

10

The sum can take 10 values, as follows:

(10^{100})+(10^{100}+1)=2\times 10^{100}+1

(10^{100})+(10^{100}+2)=2\times 10^{100}+2

(10^{100})+(10^{100}+3)=(10^{100}+1)+(10^{100}+2)=2\times 10^{100}+3

(10^{100}+1)+(10^{100}+3)=2\times 10^{100}+4

(10^{100}+2)+(10^{100}+3)=2\times 10^{100}+5

(10^{100})+(10^{100}+1)+(10^{100}+2)=3\times 10^{100}+3

(10^{100})+(10^{100}+1)+(10^{100}+3)=3\times 10^{100}+4

(10^{100})+(10^{100}+2)+(10^{100}+3)=3\times 10^{100}+5

(10^{100}+1)+(10^{100}+2)+(10^{100}+3)=3\times 10^{100}+6

(10^{100})+(10^{100}+1)+(10^{100}+2)+(10^{100}+3)=4\times 10^{100}+6

Sample Input 2

200000 200001

Sample Output 2

1

We must choose all of the integers, so the sum can take just 1 value.

Sample Input 3

141421 35623

Sample Output 3

220280457

Solution in C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            input_iter = LazyLoadAllLines();
            //------------------------------------------------//
            //var n = Read<long>();
            //var s = Read();
            //var als = Read<long>(n);
            //var sls = Read(n);
            //List<List<long>> abls = new List<List<long>>();
            //List<long> cls = new List<long>();
            /*List<long> edgeNum = Enumerable.Repeat(0L, (int)n).ToList();
            for (int i = 0; i < n - 1; ++i)
            {
                abls.Add(Read<long>(2));
                abls[i].Add(i);
                abls[i].Add(-1);
                --abls[i][0];
                --abls[i][1];
                //cls.Add(Read<long>());
                ++edgeNum[(int)abls[i][0]];
                ++edgeNum[(int)abls[i][1]];
            }*/

            //als.Sort((l, r) => (r - l));
            //sls.Sort(StringComparer.OrdinalIgnoreCase);

            // DP?Graph?
            // int -> long

            var n = Read<long>();
            var k = Read<long>();

            var elemNum = n + 1;
            LongMod num = new LongMod(0);
            for (long i = k; i <= elemNum; i++)
            {
                 num += (elemNum - i) * i + 1;
            }
            

            Console.WriteLine(num);
        }

        static IEnumerator<string> input_iter;

        static IEnumerator<string> LazyLoadAllLines(bool doSplit = true)
        {
            string line;
            if (doSplit)
            {
                do
                {
                    line = Console.ReadLine();
                    foreach (var s in line.Split(' '))
                        yield return s;
                } while (line != null);
            }
            else
            {
                do
                {
                    line = Console.ReadLine();
                    yield return line;
                } while (line != null);
            }
        }
        // single 1 elem.
        static _T Read<_T>() where _T : struct
        {
            input_iter.MoveNext();
            return (_T)Convert.ChangeType(input_iter.Current, typeof(_T));
        }
        static string Read()
        {
            input_iter.MoveNext();
            return input_iter.Current;
        }
        // single n-elems.
        static List<_T> Read<_T>(long num) where _T : struct
        {
            List<_T> res = new List<_T>();
            for (long i = 0; i < num; ++i)
            {
                input_iter.MoveNext();
                res.Add((_T)Convert.ChangeType(input_iter.Current, typeof(_T)));
            }
            return res;
        }
        static List<string> Read(long num)
        {
            List<string> res = new List<string>();
            for (long i = 0; i < num; ++i)
            {
                input_iter.MoveNext();
                res.Add(input_iter.Current);
            }
            return res;
        }
        // multiple(single type) n-elems. (Range, Edge etc.)
        static List<List<_T>> Read<_T>(long elemNum, long typeNum, bool toSort = false) where _T : struct
        {
            List<List<_T>> res = new List<List<_T>>();
            for (int i = 0; i < elemNum; ++i)
            {
                var elem = Read<_T>(typeNum);
                if (toSort) elem.Sort();
                res.Add(elem);
            }
            return res;
        }
        // multiple(multiple type) n-elems.
        static List<(_T1, _T2)> Read<_T1, _T2>(long num) where _T1 : struct where _T2 : struct
        {
            List<(_T1, _T2)> res = new List<(_T1, _T2)>();
            for (int i = 0; i < num; ++i)
            {
                res.Add((Read<_T1>(), Read<_T2>()));
            }
            return res;
        }

        static void Swap<_T>(ref _T l, ref _T r)
        {
            _T temp = l;
            l = r;
            r = temp;
        }

        public class PriorityQueue<T> : IEnumerable<T>
        {
            private readonly List<T> _data = new List<T>();
            private readonly IComparer<T> _comparer;
            private readonly bool _isDescending;

            public PriorityQueue(IComparer<T> comparer, bool isDescending = true)
            {
                _comparer = comparer;
                _isDescending = isDescending;
            }

            public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
                : this(Comparer<T>.Create(comparison), isDescending)
            {
            }

            public PriorityQueue(bool isDescending = true)
                : this(Comparer<T>.Default, isDescending)
            {
            }

            public void Enqueue(T item)
            {
                _data.Add(item);
                var childIndex = _data.Count - 1;
                while (childIndex > 0)
                {
                    var parentIndex = (childIndex - 1) / 2;
                    if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
                        break;
                    Swap(childIndex, parentIndex);
                    childIndex = parentIndex;
                }
            }

            public T Dequeue()
            {
                var lastIndex = _data.Count - 1;
                var firstItem = _data[0];
                _data[0] = _data[lastIndex];
                _data.RemoveAt(lastIndex--);
                var parentIndex = 0;
                while (true)
                {
                    var childIndex = parentIndex * 2 + 1;
                    if (childIndex > lastIndex)
                        break;
                    var rightChild = childIndex + 1;
                    if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0)
                        childIndex = rightChild;
                    if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
                        break;
                    Swap(parentIndex, childIndex);
                    parentIndex = childIndex;
                }
                return firstItem;
            }

            public T Peek()
            {
                return _data[0];
            }

            public void Clear()
            {
                _data.Clear();
            }

            private void Swap(int a, int b)
            {
                var tmp = _data[a];
                _data[a] = _data[b];
                _data[b] = tmp;
            }

            private int Compare(T a, T b)
            {
                return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
            }

            public int Count => _data.Count;

            public IEnumerator<T> GetEnumerator()
            {
                return _data.GetEnumerator();
            }

            IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
        }

        public class LongMod
        {
            public long value { get; private set; }
            public long mod { get; private set; }

            public LongMod(long v, long m = 1000000007L) { value = v; mod = m; }

            public static implicit operator long(LongMod v) { return v.value; }

            public static bool operator ==(LongMod l, LongMod r) { return (l.value == r.value && l.mod == r.mod); }
            public static bool operator !=(LongMod l, LongMod r) { return !(l == r); }
            public static bool operator >(LongMod l, LongMod r) { return (l.value > r.value && l.mod == r.mod); }
            public static bool operator <(LongMod l, LongMod r) { return !(l > r) && !(l == r); }
            public static bool operator >=(LongMod l, LongMod r) { return !(l < r); }
            public static bool operator <=(LongMod l, LongMod r) { return !(l > r); }

            public static LongMod operator +(LongMod l, LongMod r) { return new LongMod((l.value + r.value) % l.mod, l.mod); }
            public static LongMod operator +(LongMod l, long r) { return new LongMod((l.value + r) % l.mod, l.mod); }
            public static LongMod operator -(LongMod l, LongMod r) { return new LongMod((l.value + l.mod - r.value) % l.mod, l.mod); }
            public static LongMod operator -(LongMod l, long r) { return new LongMod((l.value + l.mod - r) % l.mod, l.mod); }
            public static LongMod operator *(LongMod l, LongMod r) { return new LongMod(((l.value % l.mod) * (r.value % l.mod)) % l.mod, l.mod); }
            public static LongMod operator *(LongMod l, long r) { return new LongMod(((l.value % l.mod) * (r % l.mod)) % l.mod, l.mod); }
            public static LongMod operator /(LongMod l, LongMod r) { return new LongMod(l * r.Invert()); }
            public static LongMod operator /(LongMod l, long r) { return new LongMod(l * new LongMod(r, l.mod).Invert()); }
            public static LongMod operator %(LongMod l, LongMod r) { return new LongMod(l.value % r.value, r.value); }
            public static LongMod operator %(LongMod l, long r) { return new LongMod(l.value % r, r); }

            public LongMod Invert()
            {
                // 逆元 (1/x) : 存在条件 = valueとmodが互いに素
                // memo : mod = 10^9+7(素数)の時, value != 0ならok.
                long a = value, b = mod, u = 1, v = 0;
                while (b > 0)
                {
                    long t = a / b;
                    a -= t * b; Swap(ref a, ref b);
                    u -= t * v; Swap(ref u, ref v);
                }
                u %= mod;
                if (u < 0) u += mod;
                return new LongMod(u, mod);
            }

            public LongMod Power(long exp)
            {
                // べき乗
                long a = value, res = 1;
                while (exp > 0)
                {
                    if ((exp & 1) > 0) res = res * a % mod;
                    a = a * a % mod;
                    exp >>= 1;
                }
                return new LongMod(res, mod);
            }

            public LongMod Factorial()
            {
                // 階乗
                LongMod res = new LongMod(1L, mod);
                for (long i = value; i > 0; --i) res *= i;
                return res;
            }
        }
    }
}