jiahuimbzuai/CoQuIR huggingface dataset:
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	N := ReadInt()
	a := ReadInts(3 * N)
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	v := 0
	for i := 0; i < N; i++ {
		v += a[i*2+1]
	}
	fmt.Println(v)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
//  [go]
package main

import (
   "bufio"
   "fmt"
   "os"
   "sort"
)

func solution(n int, a []int) int {
   sort.Ints(a)
   out := 0
   for i := n; i < 3*n; i += 2 {
        out += a[i]
   }
   return out
}

func main() {
   r := bufio.NewReader(os.Stdin)
   var n int
   fmt.Fscan(r, &n)
   a := make([]int, 3*n)
   for i := range a {
        fmt.Fscan(r, &a[i])
   }
   fmt.Println(solution(n, a))
}
//  [ruby]
N=gets.chomp.to_i
a=gets.chomp.split(" ").map!(&:to_i).sort.reverse!
n=1
m=3*N-1
sum=0
while(n<=m) do
  sum+=a[n]
  n+=2
  m-=1
end

print sum
//  [ruby]
N,*as=$<.read.split.map(&:to_i)
as.sort!

i = N
ret = 0
while i < 3*N
  ret += as[i]
  i += 2
end
puts ret
//  [ruby]
n = gets.to_i
points = gets.split.map(&:to_i).sort

ans = 0
(n...points.size).step(2) do |i|
  ans += points[i]
end

puts ans
//  [ruby]
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end


N=gets.to_i
a=get_i.sort{|x,y| y<=>x}
ans=[]
(3*N).times do|i|
    if (i+1).even?
        ans.push(a[i])
        break if ans.size==N
    end
end
puts ans.inject(:+)
//  [ruby]
N = gets.to_i
A = gets.split.map(&:to_i).sort{|a,b|b<=>a}
puts N.times.map{|i| A[2*(i+1)-1]}.inject(:+)
//  [ruby]
N = gets.to_i
ary = gets.split.map(&:to_i).sort{|a, b| b <=> a}
sum = 0
N.times do |i|
    sum += ary[i*2+1]
end
puts sum
//  [rust]
use input::*;
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

mod input {
    use super::*;
    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }
    pub fn string() -> String {
        read()
    }
    pub fn int() -> i64 {
        read()
    }
    pub fn char() -> char {
        read::<String>().pop().unwrap()
    }
    pub fn vecchar() -> Vec<char> {
        string().chars().collect()
    }
    pub fn vecint(n: i64) -> Vec<i64> {
        let mut vec = Vec::new();
        for i in 0..n {
            vec.push(int())
        }
        vec
    }
}
fn main() {
    let n = int() as usize;
    let mut a = vecint((n * 3) as i64);
    a.sort();
    a.reverse();
    let mut ans = 0;
    for i in 0..n {
        ans += a[2 * i + 1]
    }
    println!("{}", ans)
}
//  [rust]
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let n = get();
    let mut a: Vec<i64> = (0 .. 3 * n).map(|_| get()).collect();
    a.sort();
    a.reverse();
    let mut tot = 0;
    for i in 0 .. n {
        tot += a[2 * i + 1];
    }
    println!("{}", tot);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}
//  [rust]
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = (0..3 * n).map(|_| read()).collect();

    a.sort_by(|a, b| b.cmp(a));

    println!(
        "{}",
        a[..2 * n]
            .iter()
            .enumerate()
            .filter(|x| x.0 % 2 == 1)
            .map(|x| x.1)
            .sum::<i64>()
    );
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}
//  [swift]
let N=Int(readLine()!)!,a=readLine()!.characters.split(" ").map{Int(String($0))!}.sort()
print((1...N).reduce(0){$0+a[N*3-$1*2]})
//  [typescript]
const log = console.log;

const createScanFunctions = (input: string) => {
  const str = input.trim();
  const len = str.length;
  let index = 0;

  const scan = () => {
    const startIndex = index;

    while (index < len) {
      const char = str[index];

      if (char === " " || char === "\n")
        return str.substring(startIndex, index++);

      index++;
    }

    return str.substr(startIndex);
  };

  const scanInt = () => parseInt(scan());

  const scanIntArray = (length: number) => {
    const array = new Array<number>(length);
    for (let i = 0; i < length; i++) array[i] = parseInt(scan());

    return array;
  };

  return { scan, scanInt, scanIntArray };
};

// ----

const descendingSorter = (a: number, b: number) => b - a;

// ----

function Main(input: string): void {
  const { scanInt, scanIntArray } = createScanFunctions(input);
  const n = scanInt();
  const a = scanIntArray(3 * n);

  a.sort(descendingSorter);

  let totalStrength = 0;
  const len = 2 * n;

  for (let i = 1; i < len; i += 2) {
    totalStrength += a[i];
  }

  log(totalStrength);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [python]
import numpy as np

N = int(input())
lst = np.array(list(map(int, input().split())))

cnt = 1
flag = True
for i in range(1, N):
    mount = lst[i]
    flag = True
    for j in range(0, i):
        if lst[j] > mount:
            flag = False
            break
    if flag == True:
        cnt = cnt + 1
print(cnt)
//  [python]
import numpy as np
from collections import defaultdict
from collections import Counter
from collections import OrderedDict
#key = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
N = int(input())
#H = (int(i) for i in input().split())
#H = (int(input().split()))
H=list(map(int, input().split()))  #リスト入力
#print(H)
cnt = 0
for i, h in enumerate(H):
    if i == 0:
        max_h = H[0]
        cnt += 1
        continue
    else:
        if max_h <= h:
            cnt += 1
            max_h = h
print(cnt)
//  [python]
import numpy as np
n=int(input())  #数値入力
h=list(map(int, input().split()))  #リスト入力
count = 0
high = h[0]
for i in range(n):
    if h[i] >= high:
        count += 1
        high = h[i]

print(count)
//  [java]
import java.util.*;

public class Main {
        public static void main(String[] args){
            Scanner sc =new Scanner(System.in);
            int n = sc.nextInt();
            int[] h = new int[n];
            for(int i=0;i<n;i++){
                h[i] = sc.nextInt();
            }
            int max = h[0];
            int sum = 1;
            for(int j=1;j<n;j++){
                if(h[j]>=max){
                    sum++;
                    max=h[j];
                }
            }
            System.out.println(sum);
            for(long k = 0;k<100000000;k++){
                sum=sum*2;
                sum=sum/2;
            }
        }

        }
//  [java]
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextLine();//not use
		String input = sc.nextLine();
		int listI[] = splitStringToArrayOfInt(input);
		int count = 1;
		for(int i = 1 ; i < listI.length ; i++) {
			for(int j = 0 ; j < i ; j++) {
				if(listI[j] <= listI[i] && j == (i-1)) {
					count++;
				}else if(listI[i] < listI[j]) {
					break;
				}
			}
		}
		System.out.println(count);
	}
	
	private static int[] splitStringToArrayOfInt(String input) {
		return Arrays.stream(input.split(" ")).filter(s -> !s.isEmpty()).mapToInt(Integer::parseInt).toArray();
	}
}
//  [java]
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.function.Consumer;

import static java.util.stream.Collectors.toList;

public class Main {
    private static final Scanner scanner = new Scanner(System.in);
    private static final Consumer<List<String>> consumer = solve();

    public static void main(String[] args) {
        consumer.accept(readInput());
    }

    private static List<String> readInput() {
        final List<String> lineList = new ArrayList<>();
        while (scanner.hasNextLine()) {
            lineList.add(scanner.nextLine());
        }
        return lineList;
    }

    private static Consumer<List<String>> solve() {
        return args -> {
            final List<Long> numList = Arrays.stream(args.get(1).split(" ")).map(Long::valueOf).collect(toList());
            Long max = 0L;
            Long ans = 0L;
            for (int i = 0; i < numList.size(); i++) {
                if (numList.get(i) >= max) {
                    max = numList.get(i);
                    ans++;
                }
            }
            System.out.println(ans);
        };
    }

}
//  [cpp]
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

int main(){
    int a,r=0,l=0,ans=0;
    cin>>a;
    vector<int>c(100000000);
    vector<int>d(100000000);
    for(int i=0;i<a;i++){
        cin>>c[i];
        if(r<=c[i]){
            r=c[i];
            d[i]++;
        }
    
    }
    for(int i=0;i<a;i++){
        if(d[i]!=0){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}
//  [cpp]
#include<bits/stdc++.h>

using namespace std;
using ll = long long;


int main()
{
    int n;
    cin >> n;
    vector<int> a(100000000);
    for(int i = 0; i < n; i++)cin >> a[i];

    int cnt = 0;
    for(int i = 0; i < n; i++){
        bool res = true;
        for(int j = i - 1; j >= 0; j--) {
            if(a[i] < a[j])res = false;
        }
        cnt += res;
    }
    cout << cnt << endl;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const int mod=1e9+7;

struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};

mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}

void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}

int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );

  int n;cin>>n;
  vi h(n);
  rep(i,n)cin>>h[i];

  int ans=0;
  int max=0;
  rep(i,n){
    if(max<h[i])max=h[i];
    if(h[i]>=max)ans++;
  }
  cout<<ans<<endl;

  return 0;
}
//  [c]
#include<stdio.h>
int main()
{
int n,ans,i;
  scanf("%d",&n);
  ans=1;
  int h[n],max[n];
  for(i=0;i<n;++i)
  {
  scanf("%d",&h[i]);
  }
  max[0]=h[0];
  for(i=0;i<n-1;++i)
  {
  if(max[i]<=h[i+1]) {max[i+1]=h[i+1];
                    ans++;
                    }
  else max[i+1]=max[i];
  }
  printf("%d",ans);
return 0;
}
//  [c]
#include<stdio.h>

int main()
{
    int N,i,j,count=1, max;
    scanf("%d", &N);
    int H[N];
    for(i=0; i<N;i++)
    scanf("%d", &H[i]);

    max = H[0];

    for(j=1; j<N; j++)
    {
        if(H[j]>=max)
        {
            max = H[j];
            count++;
        }
    }
    printf("%d\n", count);

    return 0;

}
//  [c]
#include<stdio.h>
int main(void){
	int n,h,i,max,cnt=1;
	scanf("%d %d",&n,&h);
	max=h;
	for(i=1;i<n;i++){
		scanf("%d",&h);
		if(max<=h){
			cnt++;
			max=h;
		}
	}
	printf("%d",cnt);
	return 0;
}
//  [javascript]
"use strict"

function Main(input) {
  input = input.split('\n');
  let N = parseInt(input.shift());
  let array = input.shift().split(' ').map(x => x-0);
  let result = 0;
  let max = 0;
  for (let i=0;i<N;i++){
    let tmp = array[i];
    if (tmp >= max) {
      max = tmp;
      result++;
    }
  }
  console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
'use strict'
function main(input) {
  input = input.trim().split('\n')
  let max = 0
  let count = 0
  input[1].split(' ').forEach(height => {
    if (Number(height) >= max) {
      count++;
      max = Number(height)
    }
  })
  console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
'use strict';

function Main(input) {
  const H = input.split("\n")[1].split(" ").map(x => Number(x))
  
  let height = 0
  let ans = 0

  for (let h of H) {
    if (h >= height) {
      ans++
      height = h
    }
  }

  console.log(ans)  
};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
//  [go]
package main

import "fmt"

func main() {
	// Code for B - Great Ocean View
	var N int
	fmt.Scanf("%d", &N)

	H := make([]int, N)
	var answer int
	var max int = 0
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &H[i])
		if max <= H[i] {
			answer++
			max = H[i]
		}
	}
	fmt.Println(answer)
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var n int

	fmt.Scan(&n)

	var m int = 0
	var cnt int = 0
	
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		if x >= m {
			cnt++
			m = x
		}
	}

	fmt.Print(cnt)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	h := iSScan(n)
	mx := h[0]
	ans := 1
	for i := 1; i < n; i++ {
		if h[i] >= mx {
			mx = h[i]
			ans++
		}
	}
	fmt.Println(ans)
}
//  [ruby]
n=gets.to_i
s=gets.split.map &:to_i
max=0
ans=0
s.each do |i|
  if i>=max
    max=i
    ans+=1
  end
end
puts ans
//  [ruby]
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]

ans = 0
max = 0
for i in 1..N do
  if lines[1][i-1] >= max then
    ans += 1
    max = lines[1][i-1]
  end
end
  
puts ans
//  [ruby]
n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)
cnt = 1
max = arr[0]
1.upto(arr.length-1) do |i|
	if arr[i] >= max 
		cnt += 1
		max = arr[i]
	end
end
puts cnt
//  [rust]
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::iter::Iterator;
use std::collections::*;
use std::cmp::*;
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }
  
  #[allow(unused_macros)]
  macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
    n: usize,
    mut h: [i64; n],
    }

    let mut maxh = h[0];
    let mut cnt = 0;
    for i in 1..n {
      if h[i] >= maxh {
        cnt +=1;
        maxh = h[i];
      }
    }
     println!("{}", cnt + 1);
}
//  [rust]
use proconio::input;

fn main() {
  input! {
    n: i32,
    h: [i32; n],
  }
  
  let mut max: i32 = 0;
  let mut cnt: i32 = 0;
  
  for _h in h {
    if _h >= max {
      max = _h;
      cnt += 1;
    }
  }
  
  println!("{}", cnt);
}
//  [rust]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        h: [usize; n]
    };

    let mut base = h[0];
    let mut count = 1;

    for i in 1..n {
        let x = h[i];
        if base <= x {
            count += 1;
            base = x;
        }
    }

    println!("{}", count);
}
//  [swift]
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    func count() -> Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
}
extension Array where Element: Comparable {
    func max() -> Element! {
        return self.maxElement()
    }
    func min() -> Element! {
        return self.minElement()
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let N = readInt()!
let H = readIntSplit(by: " ")
var h = [0]
var ans = 0
for i in 0..<N {
    if H[i] >= h.max()! {
        ans += 1
    }
    h += [H[i]]
}
print(ans)
//  [swift]
let _=readLine()!,H=readLine()!.characters.split(" ").map{Int(String($0))!};
var h=0,a=0;
for i in H{
  if i>=h{
    a++;
    h=i
  }
};
print(a)
//  [swift]
var _=readLine(),H=readLine()!.characters.split(" ").map{Int(String($0))!},h=0,a=0;for i in H{if i>=h{a++;h=i}};print(a)
//  [typescript]
namespace Coder {
  class Scanner {
    private buffer: string = '';
    private stdinQueue: any = [];

    constructor() {
      process.stdin.resume();
      process.stdin.setEncoding('utf8');
      process.stdin.on(
        'data',
        (chunk): void => {
          this.buffer += chunk;
          while (this.stdinQueue.length > 0) {
            const i = this.buffer.indexOf('\n');
            if (i < 0) {
              break;
            }
            let line = this.buffer.substr(0, i);
            if (line.endsWith('\r')) {
              line = line.slice(0, -1);
            }
            this.buffer = this.buffer.substr(i + 1);
            this.stdinQueue.shift()(line);
          }
        },
      );
    }
    public getLine(): Promise<string> {
      return new Promise((resolve, reject) => {
        const i = this.buffer.indexOf('\n');
        if (i >= 0 && this.stdinQueue.length === 0) {
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          resolve(line);
        } else {
          this.stdinQueue.push(resolve);
        }
      });
    }

    public close(): void {
      process.stdin.pause();
    }
  }

  async function solve() {
    const sc = new Scanner();
    const N: number = +(await sc.getLine());
    const H: number[] = (await sc.getLine()).split(' ').map((x) => +x);
    let max = H[0];
    let ans = 1;
    for (let i = 1; i < N; i += 1) {
      if (H[i] >= max) {
        ans += 1;
      }
      max = Math.max(max, H[i]);
    }
    console.log(ans);
    sc.close();
  }

  solve();
}
//  [typescript]
import * as fs from 'fs';

namespace AtCoder {
    export interface Paramable {
        readonly args: string[][];
    }

    export interface Task {
        main(this: Task): void;
    }
}

namespace AtCoder.abc001 {
    export class TaskA implements AtCoder.Task, AtCoder.Paramable {
        public constructor(public readonly args: string[][]) {
        }

        public main(this: TaskA): void {
            const n: number = parseInt(this.args[0][0], 10);
            const h: number[] = this.args[1].map(Number);
            const wk: number[] = this.args[1].map(Number);
            const target: any = [];
            let ans: number = 0;
            h.forEach(x => {
                target.push(wk.shift());
                const max = Math.max(...target);
                if (x >= max) ans++;
            });
            console.log(ans);
        }
    }

    const args: string[][] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(r => r.split(' '));
    const task: AtCoder.Task = new TaskA(args);
    task.main();
}
//  [typescript]
function readInt(str) {
  return parseInt(str, 10);
}
function Main(raw: string) {
  const input = raw.split("\n");
  const [N]=input[0].split(" ").map(readInt);
  const H=input[1].split(" ").map(readInt);
  let count=0;
  let cur=0;
  for(let i=0;i<N;i++){
    if(cur<=H[i]){
      count++;
      cur=H[i];
    }
  }
  //出力
  console.log("%d", count);
}

//DO NOT EDIT
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [python]
N,K = map(int,input().split())
print(int(round((N*N*N/6 + N*N/2 + 4*N/3 + K*K*K/3 - K*K - K/3 - N*K*K/2 + N*K/2 + 2))) % (10**9 + 7))
//  [python]
n,k=map(int,input().split())
print((n*(n+1)*(n+2)//6-(3*n-2*k+4)*(k-1)*k//6-k+n+2)%(10**9+7))
//  [python]
N,k=map(int,input().split())
print(((2+N-k)*(6+N+N**2+2*k+k*N-k**2*2)//6)%(10**9+7))
//  [python]
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, K: int):
    import itertools
    import numpy as np
    candidate = 0
    ls = list(range(0, N+1))
    ls_cumsum = np.cumsum(ls)
    ls_cumsum_re = np.cumsum(ls[::-1])
    for k in range(K, N+1):
        ls_min, ls_max = ls_cumsum[k-1], ls_cumsum_re[k-1]
        candidate += ls_max - ls_min + 1
    print((candidate+1) % MOD)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()
//  [python]
#D
from collections import deque
N,K = map(int,input().split())
numbers = [i for i in range(0,N+1)]
large  = deque([N])
small = deque([0])
for i in range(1,N+1):
    large.append(large[-1]+numbers[-i-1])
    small.append(small[-1]+numbers[i])

mod = 10**9+7

ans = 1
for i in range(K,N+1):
    ans += (large[i-1] - small[i-1] + 1)%mod
print(ans%mod)
//  [python]
mod = 10**9 + 7
n, k = map(int, input().split())

f = {0:0}
s = {0:0}

for i in range(1, 10**6):
    f[i] = (f[i-1] + i) % mod
    s[i] = (s[i-1] + pow(i, 2, mod)) % mod


def solve(n, k):
    ans = (n+1) * ((f[n+1]-f[k-1])%mod) % mod
    sub = (s[n+1] - s[k-1]) % mod
    ans = (ans - sub) % mod
    ans = (ans + n-k+2) % mod

    return ans

ans = solve(n, k)
print(ans)
//  [java]
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static HashMap<Long,Long>map = new HashMap<>();
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int K = nextInt();

		long ans =0;
		long min=0;
		long max=0;
		for(long i=0;i<=N;i++){

			min+=i;
			max+=N-i;
			if(i+1>=K){
				long n=max-min+1;
				ans=(ans+n)%MOD;
			}
		}
		System.out.println(ans);
	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}
//  [java]
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	final long MOD=(long)1e9+7;
	
	long pow(long a,long n) {
		return n==0?1:(pow(a*a%MOD,n/2)*(n%2==1?a:1))%MOD;
	}
	
	long inv(long a) {
		return pow(a,MOD-2);
	}
	
	long mul(long...a) {
		long r=1;
		for (long v:a) r=r*v%MOD;
		return r;
	}
	
	long add(long...a) {
		long r=0;
		for (long v:a) r=(r+v)%MOD;
		return r;
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		int N=sc.nextInt();
		int K=sc.nextInt();
		// 0,1,..,N
		long ans=0;
		for (long num=K;num<=N+1;++num) {
			long min=mul(num,num-1,inv(2));
			long max=mul(num,N+(N-(num-1)),inv(2));
			long add=(max-min+1)%MOD;
			add=(add+MOD)%MOD;
			ans=add(ans,add);
		}
		System.out.println(ans);
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}




class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
//  [java]
import java.util.*;
import java.io.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                PrintWriter ou = new PrintWriter(System.out);
                int n = Integer.parseInt(sc.next());
                int k = Integer.parseInt(sc.next());
                sc.close();
                long yono = 0;
                for(int i = k ; i <= n + 1 ; i++){
                        yono += i * (long)(n - i + 1) + 1;
                        yono %= 1000000007;
                }
                ou.print(yono + "\n");
                ou.flush();
        }
}
//  [cpp]
/*
* @Author: Kabid
* @Date:   2020-04-19 17:59:10
*/

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define in(x)  scanf("%d", &x);
#define ins(x)  scanf("%s", &x);
#define out(x) printf("%d", x);
#define lin puts("");
#define _ putchar(' ');

int main(){
	int c=0,j;
	long long  n,m,s1=0,s2=0,i,s=0;
	scanf("%lli %lli",&n,&m);
	long long k=ceil(pow(10,9))+7;
	for(i=m;i<=n;i++){
		/**for(j=0,c=1;c<=i;j++,c++){
			s1+=j;
			 
		}**/
		//out(s1) lin
		/**for(j=n,c=1;c<=i;j--,c++){
			s2+=j;
			
		}**/
		//out(s2) lin
		s1=((i-1)*(i))/2;
		s2=((n-i)*i+(i*(i+1))/2);
		//printf("s1=%d s2=%d s=%d\n",s1,s2,s);

		s+=(s2-s1+1);
		//printf("s1=%d s2=%d s=%d\n",s1,s2,s);
		s1=0;
		s2=0;
	}
	s++;

	printf("%lli",s%k);
	
	

	

	
    return 0;
}
//  [cpp]
#import<ios>
long n,k,a;main(){for(scanf("%d%d",&n,&k);k<n+2;)a+=1-(k+~n)*k++;printf("%d",a%=n=1e9+7);}
//  [cpp]
#include <stdio.h>
#define M 1000000007

int main()
{		
	int n, i, k;
	int d, x;
	long long s = 1;
		
	scanf("%d%d", &n, &k);
	for(d = n + 1, x = n, i = 1; i <= n; i++){
		if(i >= k) s += d;
		d += (x -= 2);
		if(d >= M) d -= M;
		if(d < 0) d += M;
	}
	printf("%lld\n", s %= M);
			
	return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, K;
  IN(N,K);

  ll ans = 0;
  FOR(k,K,N+2){
    ll tmp = N*k - k*(k-1) + 1;
    debug_print(k, tmp);
    ans += tmp;
    ans %= MOD;
  }

  OUT(ans);

  return 0;
}
//  [cpp]
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
#include <cmath>
#include <queue>
#include <string.h>

const int MOD = 1000000007;

int main(int argc, char *argv[])
{
	int n,k;

	cin>>n>>k;

	ll ret=0;
	for (ll i=k;i<=n+1;i++)
	{
		ll a=i*(i-1)/2;
		ll b=i*(n+n-i+1)/2;

		cerr<<i<<" "<<a<<" "<<b<<endl;
		ret=(ret+(b-a+1))%MOD;
	}
	cout<<ret<<endl;

	return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
//桁数指定　cout << fixed << setprecision(2)
typedef long long  ll;
const double pi=3.1415926535;
const ll  mod=1000000007;
int main() {
  ll n,k;
  ll ans=0;
  cin>>n>>k;
  for(int i=k;i<=n+1;i++){
    ll min=(0+i)*(i+1)/2;  /*  +k*10^100  */
    ll max=i*(n+1-i)+min;
    ans+=(max-min)+1;
    if(ans>=mod)ans%=mod;
    cerr<<"LOOP"<<i<<":"<<max-min+1<<endl;
  }
  cout<<ans;
}
//  [c]
#include<stdio.h>
#define LIMIT 1000000007

int main(void)
{
	long n,k,i,j;
	long sum=0,min=0,max=0;
	int flag=1;

	scanf("%ld %ld",&n,&k);

	for(i=k;i<=n+1;i++){
		if(flag){
			for(j=0;j<i;j++){
				min+=j;
			}
			for(j=n;j>n-i;j--){
				max+=j;
			}
			flag=0;
		}
		else{
			min+=i-1;
			max+=n-i+1;
		}
		sum+=max-min+1;
	}
	sum=sum%LIMIT;

	printf("%ld\n",sum);
	return 0;
}
//  [c]
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main(void) {
	long long int n, k, i;
	long long int num = 0;
	scanf("%lld %lld", &n, &k);
	for (i = k; i < n + 2; i++) {
		num = num + (i * (n - i + 1) + 1);
	}
	printf("%lld",num%(1000000007));
	return 0;
}
//  [c]
#include <stdio.h>

long calc(long max, long count) {
  return (max - count + 1) * count + 1;
}

int main(void) {
  int n, k;
  
  scanf("%d %d", &n, &k);
  if(k > n) {
    printf("1\n");
    return 0;
  }
  long ret = 0;
  for(int i = k;i <= n + 1;i++) {
    ret += calc(n, i);
  }
  ret %= 1000000007;
  printf("%ld\n", ret);
  return 0;
}
//  [c]
#include<stdio.h>
#define MODN (1000000007)

static inline long mdml(long a,long b){
    long long res = (long long)a * b;
    return res % MODN;
}

static inline long mdsub(long lhs,long rhs){
    long res = lhs - rhs;
    if(res < 0)res += MODN;
    return res;
}

static inline long mdadd(long lhs,long rhs){
    return (lhs + rhs) % MODN;
}

static inline long mdpow(long num,long ind){
    unsigned long cnt = ind;
    long res = 1;  
    while(cnt){
        if(cnt & 1ul)res = mdml(res,num);
        num = mdml(num,num);
        cnt >>= 1;
    }
    return res;
}

static inline long mddiv(long rhs,long lhs){
    return mdml(rhs,mdpow(lhs,MODN - 2));
}

int main(void){
    register int i;
    int n,k;
    scanf("%d %d",&n,&k);
    int kd_sel = n + 2 - k;
    long cnt[kd_sel];
    for(i = 0;i < kd_sel;i++){
        int nsel = k + i;
        cnt[i] = mdadd( mdsub( mddiv( mdml( mdsub( mdml( 2 , n) , nsel-1) , nsel) , 2) , mddiv( mdml(nsel-1 , nsel) , 2)) , 1);
    }
    long ans = 0;
    for(i = 0;i < kd_sel;i++)ans = mdadd(ans,cnt[i]);
    printf("%ld",ans);
}
//  [c]
#include <stdio.h>

#define MOD_BY 1000000007

int add(int a, int b) {
	return a + b - (a + b >= MOD_BY ? MOD_BY : 0);
}

int sub(int a, int b) {
	return b == 0 ? a : add(a, MOD_BY - b);
}

int mul(int a, int b) {
	int r = 0;
	while (b > 0) {
		if (b & 1) r = add(r, a);
		a = add(a, a);
		b >>= 1;
	}
	return r;
}

int pou(int a, int b) {
	int r = 1;
	while (b > 0) {
		if (b & 1) r = mul(r, a);
		a = mul(a, a);
		b >>= 1;
	}
	return r;
}

int inv(int a) {
	return pou(a, MOD_BY - 2);
}

int d2;

/*
https://www.kwansei.ac.jp/hs/z90010/sugakua/suuretu/tousasum/tousasum.htm

Sn = n(a+l) / 2
*/
int wa(int a, int l) {
	int n = l - a + 1;
	return mul(mul(n, add(a, l)), d2);
}

int main(void) {
	int N, K;
	int m;
	int kotae = 0;
	d2 = inv(2);
	if (scanf("%d%d", &N, &K) != 2) return 1;
	for (m = K; m <= N + 1; m++) {
		int sita, ue;
		/* 一番下m個 */
		sita = wa(0, m - 1);
		/* 一番上m個 */
		ue = wa(N - m + 1, N);

		kotae = add(kotae, add(sub(ue, sita), 1));
	}
	printf("%d\n", kotae);
	return 0;
}

/*

m個選ぶ時、一番下m個～一番上m個まで全て1個ずつ動かして作れる

*/
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

// ll dp[]
#define MAXF 510000

ll fac[MAXF], finv[MAXF], inv[MAXF];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAXF; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ll n, K;
  ll a, b;
  ll sum=0;

  scanf("%lld%lld", &n, &K) ;

  COMinit();

  for (ll i = K; i <= n+1; i++)
  {
      a = i*(i-1)/2;
      b = i*(2*n-i+1) /2;
      sum = (sum + (b-a+1)) % MOD;
  }

  printf("%lld", sum);
  
  

  return 0;
}
//  [javascript]
"use strict"
function main(arg) {
    var tmp = arg.trim().split("\n")[0].split(" ").map(Number)
    var N = tmp[0]
    var K = tmp[1]
    var counter = 0
    for (let i = K; i <= N + 1; i++) {
        var min = 0
        var max = 0
        min = sumStep(i - 1)
        max = sumStep(N) - sumStep(N -i)
        counter += (max-min) + 1
        counter %= 1000000007
    }
    console.log(counter)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function sumStep(n) {
    return (n * (n + 1))/2
}
//  [javascript]
function main(input) {
  let n,k = 0;
  [n, k] = input[0].trim().split(" ").map(i => parseInt(i));

  let sum = 0;

  function　sum1toN(n) {
    return n*(n+1)/2;
  }

  for(let i=k;i<=n+1;i++){
    const min = sum1toN(i-1);
    const max = sum1toN(n) - sum1toN(n-i);
    sum = (sum+(max-min+1))%(10**9+7);
  }
  console.log(sum);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));
//  [javascript]
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
var mod = 1e9+7;

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var n = next();
  var k = next();
  var ans = 0, l = 0, r = 0;
  for(var i = 1; i < k; i++){
    l += i-1;
    r += n-i+1;
  }
  for(; i <= n+1; i++){
    l += i-1;
    r += n-i+1;
    ans += r-l+1;
    ans %= mod;
  }
  return ans;
}
//  [javascript]
function Main(input){
  input = input.split(" ").map(Number);
  var sum = 0;
  for(var i=input[1];i<=input[0]+1;i++){
      var n = ((input[0]-i+1+input[0])*i/2)-(i*(i-1)/2)+1;
      sum += n;
      sum %=1000000007;
  }
  console.log(sum)
  }Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
//  [javascript]
const main = (input) => {
  const mod = 10**9 + 7
  const [n, k] = input.trim().split(' ').map(Number)
  

  let ans = 0

  for (let i=k; i<=n+1; i++) {
    const s_sum = (i-1) * i / 2

    const b_f = n - i + 1

    const b_sum = (b_f + n) * i / 2

    ans += b_sum - s_sum + 1
  }

  return console.log((ans % mod + mod) % mod)
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [javascript]
const main = (input) => {
  const args = input.split(' ').map(Number)
  const [n, k] = args
  if (n + 1 - k === 0) {
    console.log(1)
    return
  }
  const sums = [0]
  for (let i = 0; i < n + 1; i++) {
    sums.push(i + sums[i])
  }
  const sum = Array(n + 2 - k).fill(0).map((_, i) => {
    const min = sums[i + k] - sums[0]
    const max = sums[n + 1] - sums[n + 1 - i - k]
    return max - min + 1
  }).reduce((p, c) => p + c)
  console.log(sum % (10 ** 9 + 7))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [go]
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

const (
	maxBufsize = 1000000
)

func inputs(lines int) []string {
	var strSlice []string

	rdr := bufio.NewReaderSize(os.Stdin, maxBufsize)

	for i := 0; i < lines; i++ {

		line := ReadLine(rdr)
		strSlice = append(strSlice, line)

	}

	return strSlice
}

// ReadLine is to read long line
func ReadLine(rdr *bufio.Reader) string {
	buf := make([]byte, 0, maxBufsize)
	for {
		l, p, e := rdr.ReadLine()

		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}

	return string(buf)
}

func modpow(a, n, mod int64) int64 {
	r := int64(1)

	for {
		if (n & 1) == 1 {
			r = (r * a) % mod
		}
		n = n >> 1
		a = (a * a) % mod
		if n <= 0 {
			break
		}
	}

	return r
}

func calcsmall(k int) int {
	return (k - 1) * k / 2
}

func calclarge(k, n int) int {
	return (2*n - k + 1) * k / 2
}

func sumscount(N, K int) int {
	sums := 0
	for i := K; i <= (N + 1); i++ {
		small := calcsmall(i)
		large := calclarge(i, N)

		cnt := large - small + 1
		sums += cnt
	}
	return sums
}

func main() {
	lines := inputs(1)

	tmp := strings.Split(lines[0], " ")
	N, _ := strconv.Atoi(tmp[0])
	K, _ := strconv.Atoi(tmp[1])
	MOD := int64(math.Pow10(9) + 7)

	ans := int64(sumscount(N, K)) % MOD
	fmt.Println(ans)

}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

const initBufSize, maxBufSize = 10000, 1000000

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInts(n int) []int {
	res := make([]int, n)
	for i := range res {
		res[i] = nextInt()
	}
	return res
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func abs(n int) int {
	return int(math.Abs(float64(n)))
}

func pow(r, n int) int {
	return int(math.Pow(float64(r), float64(n)))
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initBufSize), maxBufSize)
	n := nextInt()
	k := nextInt()
	sum := 0
	for i := 1; i <= n; i++ {
		sum += i
	}
	//N+1個選ぶ時の最大値と最小値
	max, min := sum, sum
	//選ぶ数を1つずつ減らしながら和の最大値と最小値を求める
	i := n + 1
	maxCalc := 0
	minCalc := n
	ans := 0
	for i >= k {
		//最大値はK⇒N+1の順に減少
		//最小値はN+1⇒Kの順に減少
		if i < n+1 {
			max -= maxCalc
			min -= minCalc
			maxCalc++
			minCalc--
		}
		//fmt.Println("i:", i, "max:", max, "min:", min)
		temp := 0
		temp = max - min + 1
		ans += temp % (1000000000 + 7)
		i--
	}
	fmt.Println(ans % (1000000000 + 7))
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var nk string
	if sc.Scan() {
		nk = sc.Text()
	}

	nkArr := strings.Split(nk, " ")

	n, _ := strconv.Atoi(nkArr[0])
	k, _ := strconv.Atoi(nkArr[1])

	sum := 0
	for i := k; i <= n+1; i++ {
		min := (i - 1) * i / 2
		max := (2*n - i + 1) * i / 2

		sum += (max - min + 1)
	}

	ans := sum % 1000000007

	fmt.Print(ans)
}