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.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO.Pipes;
using System.Runtime;
 
namespace Csharponly
{
    class Program
    {
        static public void Main()
        {
            int[] NK = Arrayint();
 
            string ans = Team(NK[0] + 1, NK[1]);
			
          	long a = long.Parse(ans);
          	long b = a%1000000007;
            Console.WriteLine(b);
 
        }
 
 
        static string Team(int a, int b)
        {
            string ans = "1";
            for (int i = b; i < a; i++)
            {
 
                ans = Tasu(Tasu(ans ,Kakeru((a - i).ToString(),i.ToString())),"1");
 				//Console.WriteLine(ans);
            }
            return ans;
        }
 
        //b*(b+1)*(b*2)* *a
        static int Warunum(int aa, int bb)
        {
            int cc = 1;
            for (int i = bb; i < aa; i++)
            {
                cc = cc * i;
            }
            return cc;
        }
 
        static string Kakeru(string a1, string b1)
        {
            int anum = a1.Length;
            int bnum = b1.Length;
            int[] a = Array(a1);
            int[] b = Array(b1);
 
            int[] kakeruans = new int[anum + bnum];
            for(int i = 0; i < anum; i++)
            {
                for(int j = 0; j < bnum; j++)
                {
                    kakeruans[i + j] += a[i] * b[j];
                }
            }
            for(int i = 0; i < kakeruans.Length; i++)
            {
                if(kakeruans[i] >= 10)
                {
                    kakeruans[i + 1] += kakeruans[i] / 10;
                    kakeruans[i] = kakeruans[i] % 10;
                }
            }
            string kakerustring = "";
            for (int i = 0; i < kakeruans.Length - 1; i++)
            {
                kakerustring = kakeruans[i].ToString() + kakerustring;
            }
            if (kakeruans[kakeruans.Length - 1] != 0)
            {
                kakerustring = kakeruans[kakeruans.Length - 1].ToString() + kakerustring;
            }
 
            return kakerustring;
        }
 
        static string Tasu(string a1, string b1)
        {
            int anum = a1.Length;
            int bnum = b1.Length;
            int[] a = Array(a1);
            int[] b = Array(b1);
 
            string tasustring = "";
            if (anum < bnum)
            {
                int[] tasuans = new int[bnum + 1];
                for (int i = 0; i < anum; i++)
                {
                    tasuans[i] = a[i] + b[i];
                }
                for(int i = anum; i < bnum; i++)
                {
                    tasuans[i] = b[i];
                }
                for(int i = 0; i < tasuans.Length; i++)
                {
                    if(tasuans[i] >= 10)
                    {
                        tasuans[i] -= 10;
                        tasuans[i + 1]++; 
                    }
                }
                for (int i = 0; i < tasuans.Length - 1; i++)
                {
                    tasustring = tasuans[i].ToString() + tasustring;
                }
                if(tasuans[tasuans.Length - 1] != 0)
                {
                    tasustring = tasuans[tasuans.Length - 1].ToString() + tasustring;
                }
            }
            else
            {
                int[] tasuans = new int[anum + 1];
                for (int i = 0; i < bnum; i++)
                {
                    tasuans[i] = a[i] + b[i];
                }
                for (int i = bnum; i < anum; i++)
                {
                    tasuans[i] = a[i];
                }
                for (int i = 0; i < tasuans.Length; i++)
                {
                    if (tasuans[i] >= 10)
                    {
                        tasuans[i] -= 10;
                        tasuans[i + 1]++;
                    }
                }
                for (int i = 0; i < tasuans.Length - 1 ; i++)
                {
                    tasustring = tasuans[i].ToString() + tasustring;
                }
                if (tasuans[tasuans.Length - 1] != 0)
                {
                    tasustring = tasuans[tasuans.Length - 1].ToString() + tasustring;
                }               
            }
            return tasustring;
        }
 
        static int[] Array(string A)
        {
            int[] a = new int[A.Length];
            string num;
            for (int i = 0; i < A.Length; i++)
            {
                num = A.Substring(i, 1);
                a[A.Length - i - 1] = int.Parse(num);
            }
 
            return a;
        }
 
        //一つの文字列を受け渡す
        static string Onestring()
        {
            return Console.ReadLine();
        }
 
        //複数の文字列を配列で受け渡す
        //文字列と文字列の間は" "で区切る
        static string[] Arraystring()
        {
            return Console.ReadLine().Split(' ');
        }
 
        //一つの数字を受け渡す
        static int Oneint()
        {
            return int.Parse(Console.ReadLine());
        }
 
        //複数の数字を配列で受け渡す
        //数字と数字の間は" "で区切る
        static int[] Arrayint()
        {
            String[] input_line = Console.ReadLine().Split(' ');
            int[] input_num = new int[input_line.Length];
            for (int i = 0; i < input_line.Length; i++)
            {
                input_num[i] = int.Parse(input_line[i]);
            }
            return input_num;
        }
    }
}