CodeEff/ECCO huggingface dataset:
# Original solution
N = int(eval(input()))
A = input().split()

c = 1
i = 1
while i <= N-2:
	if int(A[i])-int(A[i-1]) > 0:
		if int(A[i+1])-int(A[i]) < 0:
			c += 1
			i += 2
		elif int(A[i+1])-int(A[i]) > 0:
			i += 1
		else:
			while int(A[i])-int(A[i-1]) == 0:
				i += 1
			if int(A[i])-int(A[i-1]) < 0:
				c += 1
				i += 2
	elif int(A[i])-int(A[i-1]) < 0:
		if int(A[i+1])-int(A[i]) > 0:
			c += 1
			i += 2
		else:
			while int(A[i])-int(A[i-1]) == 0:
				i += 1
			if int(A[i])-int(A[i-1]) > 0:
				c += 1
				i += 2
	else:
		i += 1

 
print(c)

# Optimized solution
N = int(eval(input()))
A = input().split()

c = 1
i = 1

while i <= N-1:
	if int(A[i])-int(A[i-1]) == 0:
		del A[i-1]
		N -= 1
	else:
		i += 1

i = 1

while i <= N-2:
	if int(A[i])-int(A[i-1]) > 0:
		if int(A[i+1])-int(A[i]) < 0:
			c += 1
			i += 2
		else:
			i += 1
	else:
		if int(A[i+1])-int(A[i]) > 0:
			c += 1
			i += 2
		else:
			i += 1
 
print(c)
# Original solution
n = eval(input())
a = list(map(int, input().split()))

b = []
for i in range(1, n):
    if a[i] - a[i-1] != 0:
        b.append(a[i] - a[i-1])
dont_mind = True
c = 1
i = 1
while i < len(b):
    prev = b[i-1]
    t = prev * b[i]
    if t >= 0:
        i += 1
        continue
    if t < 0:
        c += 1
        i += 2
        continue
    i += 1
print(c)

# Optimized solution
# coding: utf-8
# AGC 013 a 
# Here your code !
n = eval(input())
if n <= 2:
    print(1)
    exit()
    
a = list(map(int, input().split()))

c = 1

status = "n"
i = 1
while i < n:
    if status == "n":
        if a[i-1] < a[i]:
            status = "i"
        elif a[i-1] > a[i]:
            status = "d"
        i += 1
        
    elif status == "i":
        if a[i-1] <= a[i]:
            i += 1
        elif a[i-1] > a[i]:
            status = "n"
            c += 1
            i += 1
        
    elif status == "d":
        if a[i-1] < a[i]:
            status = "n"
            c += 1
            i += 1
        elif a[i-1] >= a[i]:
            i += 1
print(c)
# Original solution
# coding:utf-8

import sys
from collections import Counter


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


N = int(eval(input()))
A = inpl()

ans = 1
prev = A[0]
state = 0
for i in range(1, N):
    if state == 0:
        if A[i] > prev:
            state = 1
        elif A[i] < prev:
            state = -1

    elif state == 1:
        if A[i] < prev:
            ans += 1
            state = 0

    else:
        if A[i] > prev:
            ans += 1
            state = 0

    prev = A[i]

print(ans)


# Optimized solution
# coding:utf-8

import sys
from collections import Counter


# input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


N = int(eval(input()))
A = inpl()

ans = 1
prev = A[0]
state = 0
for i in range(1, N):
    if state == 0:
        if A[i] > prev:
            state = 1
        elif A[i] < prev:
            state = -1

    elif state == 1:
        if A[i] < prev:
            ans += 1
            state = 0

    else:
        if A[i] > prev:
            ans += 1
            state = 0

    prev = A[i]

print(ans)
# Original solution
# coding:utf-8


def inpl(): return list(map(int, input().split()))


N = int(eval(input()))
A = inpl()

ans = 1
prev = A[0]
state = 0  # 1: 増加, 0: 横ばい, -1: 減少
for i in range(1, N):
    if state == 0:
        if A[i] > prev:
            state = 1
        elif A[i] < prev:
            state = -1

    elif state == 1:
        if A[i] < prev:
            ans += 1
            state = 0

    else:
        if A[i] > prev:
            ans += 1
            state = 0

    prev = A[i]

print(ans)


# Optimized solution
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())


def main():
    n = II()
    A = LI()

    # 1: 単調非減少，2: 単調非増加，0: 未定
    state = 0
    prev = A[0]
    res = 1
    for cur in A:
        if state:
            if state == 1 and prev > cur:
                res += 1
                state = 0
            if state == 2 and prev < cur:
                res += 1
                state = 0
        else:
            if prev < cur:
                state = 1
            if prev > cur:
                state = 2
        prev = cur

    return res


print((main()))
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))

ans = 1

#state0は未定、1は広義単調増加、2は広義単調減少
state = 0
m = A[0]

i = 1
while i <= N-1:
    if m < A[i]:
        if state == 0:
            state = 1
            m = A[i]
        elif state == 1:
            m = A[i]
        else:
            ans += 1
            state = 0
            m = A[i]
    elif m > A[i]:
        if state == 0:
            state = 2
            m = A[i]
        elif state == 1:
            ans += 1
            state = 0
            m = A[i]
        else:
            m = A[i]
    i += 1
print(ans)


# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))

ans = 1

#state0は未定、1は広義単調増加、2は広義単調減少
state = 0
m = A[0]

i = 1
while i <= N-1:
    if m < A[i]:
        if state == 0:
            state = 1
        elif state == 2:
            ans += 1
            state = 0
    elif m > A[i]:
        if state == 0:
            state = 2
        elif state == 1:
            ans += 1
            state = 0
    m = A[i]
    i += 1

print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))

ans = 1

#state0は未定、1は広義単調増加、2は広義単調減少
state = 0
m = A[0]

i = 1
while i <= N-1:
    if m < A[i]:
        if state == 0:
            state = 1
        elif state == 2:
            ans += 1
            state = 0
    elif m > A[i]:
        if state == 0:
            state = 2
        elif state == 1:
            ans += 1
            state = 0
    m = A[i]
    i += 1

print(ans)


# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
#state0は未定、1は広義単調増加、2は広義単調減少
state = 0
m = A[0]
ans = 1

for i in range(1,N):
    if m < A[i]:
        if state == 0:
            state = 1
        elif state == 2:
            ans += 1
            state = 0
    elif m > A[i]:
        if state == 0:
            state = 2
        elif state == 1:
            ans += 1
            state = 0
    m = A[i]

print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))

ans = 1
up = dn = False
for a,b in zip(A,A[1:]):
    if a < b:
        if up: continue
        up = True
        if dn:
            ans += 1
            up = dn = False
    elif a > b:
        if dn: continue
        dn = True
        if up:
            ans += 1
            up = dn = False
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
up = dn = False
ans = 1
p = A[0]
for a in A:
    if p < a:
        up = True
    elif p > a:
        dn = True
    if up and dn:
        ans += 1
        up = dn = False
    p = a
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))

ans = 0
while len(A):
    for i in range(len(A)-2):
        if (A[i+2]-A[i+1]>0)!=(A[i+1]-A[i]>0) and A[i+2]-A[i+1]!=0 and A[i+1]-A[i]!=0:
            A = A[i+2:]
            ans += 1
            break
    else:
        break

print((ans+1))

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))

ans = 1
d = 0
tmp = A[0]
for a in A[1:]:
    if d*(a-tmp) < 0:
        ans += 1
        d = 0
    else:
        d += a-tmp
    tmp = a

print(ans)
# Original solution
def upper_or_lower(i):
    if A[i] < A[i + 1]:
        return "upper"
    elif A[i] > A[i + 1]:
        return "lower"
    else:
        return upper_or_lower(i + 1)


N = int(eval(input()))
A = list(map(int, input().split()))

state = "upper"  # state が upper か lower で判定
ans = 1

# i = 0 の処理
if (len(A) > 2) and (A[0] > A[1]):
    state = "lower"

for i in range(2, N):
    if (state == "upper") and (A[i - 1] > A[i]):
        ans += 1
        if i < N - 1:
            state = upper_or_lower(i)
    elif (state == "lower") and (A[i - 1] < A[i]):
        ans += 1
        if i < N - 1:
            state = upper_or_lower(i)
    else:
        continue

print(ans)


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

change = 0  # 1, 0, -1
ans = 1

for i in range(N-1):
    if A[i+1] - A[i] > 0:
        if change == 0:
            change = 1
        elif change == -1:
            ans += 1
            change = 0
        else:
            continue
    elif A[i+1] - A[i] < 0:
        if change == 0:
            change = -1
        elif change == 1:
            ans += 1
            change = 0
        else:
            continue

print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

if n <= 2:
    print((1))
    exit()

dec, inc = False, False
cnt = 1

for i in range(n-1):
    if a[i+1] - a[i] < 0:
        dec = True
    elif a[i+1] - a[i] > 0:
        inc = True

    if dec and inc:
        cnt += 1
        dec, inc = False, False

print(cnt)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

ans = 1
up = None

for x, y in zip(a, a[1:]):
    if x < y:
        if up is None:
            up = True
        elif not up:
            ans += 1
            up = None
    elif x > y:
        if up is None:
            up = False
        elif up:
            ans += 1
            up = None
print(ans)
# Original solution
def main():
    N = int(eval(input()))
    A = [int(a) for a in input().split()]
    
    idx = 0
    ans = 0
    for i in range(len(A)):
        if idx + 1 > len(A) - 1 :
            break

        m = ""
        if A[idx] < A[idx + 1]:
            m = "+"
        elif A[idx] > A[idx + 1]:
            m = "-"
        else:
            find = False
            for j in range(idx, len(A)-1):
                if A[j] < A[j + 1]:
                    m = "+"
                    find = True
                    break
                elif A[j] > A[j + 1]:
                    m = "-"
                    find = True
                    break
            if find == False:
                print((ans + 1))
                exit()

        for j in range(idx, len(A) - 1):
            if m == "+":
                if A[j] <= A[j + 1]:
                    pass
                else:
                    idx = j + 1
                    ans += 1
                    break
            elif m == "-":
                if A[j] >= A[j + 1]:
                    pass
                else:
                    idx = j + 1
                    ans += 1
                    break

    print((ans + 1))

if __name__ == "__main__":
    main()

# Optimized solution
def main():
    N = int(eval(input()))
    A = [int(a) for a in input().split()]

    idx = 0
    ans = 0
    for i in range(len(A)):
        if idx + 1 > len(A) - 1 :
            break

        m = ""
        if A[idx] < A[idx + 1]:
            m = "+"
        elif A[idx] > A[idx + 1]:
            m = "-"
        else:
            find = False
            for j in range(idx, len(A)-1):
                if A[j] < A[j + 1]:
                    m = "+"
                    find = True
                    idx = j
                    break
                elif A[j] > A[j + 1]:
                    m = "-"
                    find = True
                    idx = j
                    break
            if find == False:
                print((ans + 1))
                exit()

        for j in range(idx, len(A) - 1):
            if m == "+":
                if A[j] <= A[j + 1]:
                    idx = j + 1
                else:
                    idx = j + 1
                    ans += 1
                    break
            elif m == "-":
                if A[j] >= A[j + 1]:
                    idx = j + 1
                else:
                    idx = j + 1
                    ans += 1
                    break

    print((ans + 1))

if __name__ == "__main__":
    main()
# Original solution
import sys

read= sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 1000000007
sys.setrecursionlimit(10**7)

#N,*A = map(int,read().split())
N = int(eval(input()))
A = list(map(int,input().split()))

State = 0
res = 1

for i in range(1,N):
    if A[i] > A[i-1]:
        X = 1
    elif A[i] == A[i-1]:
        X = 0
    else :
        X = -1

    #前と同じ状態の時
    if X == State:
        continue
    
    if  State == 0:
        State = X

    if X != State  and  X != 0:
        res += 1
        State = 0

print(res)

# Optimized solution
import sys

read= sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 1000000007
sys.setrecursionlimit(10**7)

#N,*A = map(int,read().split())
N = int(eval(input()))
A = list(map(int,input().split()))

#現在作ってる数列の種類を記録
# 単調増加：1
# 単調減少 ：-1
# 初期値:0
State = 0

#答え入れる
res = 1

for i in range(1,N):
    
    #A[i]はA[i-1]と比べたときの大小を記録

    #X に現在の状態を記録
    # 増加：1
    # 減少 ：-1
    # 同じ値:0
    if A[i] > A[i-1]: #大きくなった時
        X = 1 
    elif A[i] == A[i-1]: #等しい時
        X = 0
    else :# それ以外(小さくなった時)
        X = -1

    #現在の状態と作っている数列の状態が同じとき
    if X == State:
        continue
    
    #配列の種類が0の時(どちらにもなりえる)
    if  State == 0: 
        State = X #Stateが決定されるため、更新

    #現在の状態と作っている数列の状態が違い、現在の状態が0出ないとき
    if X != State  and  X != 0: 
        res += 1 
        State = 0 #数列を初期化

print(res)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))+[0]
a=[a[i] for i in range(n) if a[i]!=a[i+1]]
s=0
while a:
  n=len(a)
  if n==1:
    a=[]
  else:
    d=a[0]-a[1]>0
    for i in range(n-1):
      if d==(a[i]-a[i+1]<0):
        a=a[i+1:]
        break
    else:
      a=[]
  s+=1
print(s)


# Optimized solution
n = int(eval(input()))
ans = 1
a, b = False, False
x = list(map(int, input().split()))
for i in range(1, n):
    if x[i] > x[i - 1]:
        a = True
    if x[i] < x[i - 1]:
        b = True
    if a and b:
        a, b = False, False
        ans += 1
print(ans)
# Original solution
N = int(eval(input()))
cnt = 0
L = list(map(int,input().split()))
while True:
    try: 
        if L[0] <L[1]>L[2] or L[0] > L[1] <L[2]:
            a0=L.pop(0)
            a1=L.pop(0)
            cnt += 1

        else:
            L.pop(0)
    except:
        break
print((1+cnt))


# Optimized solution
N = int(eval(input()))
cnt = 0
tmp = ''
M = list(map(int,input().split()))
L = []
for x in M:
    if x == tmp:
        pass
    else:
        L.append(x)
    tmp = x
    

    
while True:
    try: 
        if L[0] <L[1]>L[2] or L[0] > L[1] <L[2]:
            a0=L.pop(0)
            a1=L.pop(0)
            cnt += 1
        else:
            L.pop(0)
    except:
        break
#    print(L)
print((1+cnt))
# Original solution
def main():
    n = int(eval(input()))
    A = list(map(int, input().split()))

    res = 0
    i = 1

    while i < len(A) - 1:
        if (A[i - 1] < A[i] and A[i] > A[i + 1]) or (A[i - 1] > A[i] and A[i] < A[i + 1]):
            res += 1
            A = A[i + 1:]
            i = 1
        else:
            i += 1
    
    print((res + 1))

if __name__ == '__main__':
    main()

# Optimized solution
def main():
    n = int(eval(input()))
    A = list(map(int, input().split()))

    res = 1
    inc = 0
    dec = 0

    for i in range(n - 1):
        if A[i] < A[i+1]:
            inc += 1
        elif A[i] > A[i+1]:
            dec += 1
        
        if inc and dec:
            res += 1
            inc, dec = 0, 0
    
    print(res)

if __name__ == '__main__':
    main()
# Original solution
#!/usr/bin/env python

n = int(eval(input()))
a = list(map(int, input().split()))
d = [0 for _ in range(n-1)]
for i in range(n-1):
    d[i] = a[i+1]-a[i]

ans = 1 
flg = [False, False]

for i in range(n-1):
    if d[i] > 0:
        flg[0] = True
    elif d[i] < 0:
        flg[1] = True

    if flg[0] == flg[1] == True:
        ans += 1
        flg = [False, False]

print(ans)


# Optimized solution
#!/usr/bin/env python

n = int(eval(input()))
a = list(map(int, input().split()))
d = [0 for _ in range(n-1)]
for i in range(n-1):
    d[i] = a[i+1]-a[i]

# print(d)
ans = 1 
state = 'flat'
for i in range(n-1):
    if i == 0:
        if d[i] > 0:
            state = 'up'    
        elif d[i] < 0:
            state = 'down'

    else:
        if d[i] > 0:
            if state == 'flat':
                state = 'up'
            elif state == 'down':
                state = 'flat'
                ans += 1

        elif d[i] < 0:
            if state == 'flat':
                state = 'down'
            elif state == 'up':
                state = 'flat'
                ans += 1

print(ans)
# Original solution
MOD=(10**9)+7
n,k=list(map(int,input().split()))
ans=0
for i in range(k,n+2):
    min_start=0
    min_end=min_start+i-1
    max_end=n
    max_start=n-i+1
    min_sum=(min_end-min_start+1)*(min_end+min_start)//2
    max_sum=(max_end-max_start+1)*(max_end+max_start)//2
#    print(i,min_start,min_end,min_sum,max_start,max_end,max_sum,max_sum-min_sum+1)
    ans+=max_sum-min_sum+1
    ans=ans%MOD
print((ans%MOD))

# Optimized solution
n,k=list(map(int,input().split()))
MOD=(10**9)+7

ans=0
for i in range(k,n+2):
    min_sum=i*(i-1)//2
    max_sum=i*(n+(n-i+1))//2
#    print(i,min_sum,max_sum,max_sum-min_sum+1)
    ans=(ans+(max_sum-min_sum+1))%MOD
print(ans)
# Original solution
n, k = list(map(int, input().split()))
print((sum(i * (n - i + 1) + 1 for i in range(k, n + 2))%(10**9 + 7)))


# Optimized solution
n, k = list(map(int, input().split()))
f = lambda i: (n + 1) * i * (i - 1) // 2 - i * (i - 1) * (2 * i - 1) // 6 
print(((n - k + 2 + f(n + 2) - f(k)) % (10**9 + 7)))
# Original solution
n,k=list(map(int,input().split()))
ans=0
mod=10**9+7
l=[i for i in range(n+1)]
mi=sum(l[:k])
ma=sum(l[n+1-k:])
ans=(ans+(ma-mi+1))%(10**9+7)
for i in range(k+1,n+2):
    mi+=l[i-1]
    ma+=l[-i]
    ans=(ans+(ma-mi+1))%(10**9+7)
print(ans)

# Optimized solution
n,k=list(map(int,input().split()))
ans=0
mod=10**9+7
l=[i for i in range(n+1)]
mi=sum(l[:k])
ma=sum(l[n+1-k:])
ans=(ans+ma-mi+1)%mod
for i in range(k+1,n+2):
    mi+=l[i-1]
    ma+=l[-i]
    ans=(ans+ma-mi+1)%mod
print(ans)
# Original solution
N, K = list(map(int, input().split()))

counter = 0
for i in range(K, N+2):
    smallest = (i-1) * i // 2
    largest = ((2 * N + 1) - i) * i // 2
    counter += (largest - smallest + 1)
    counter %= (10 ** 9 + 7)

print(counter)

# Optimized solution
N, K = list(map(int, input().split()))

MOD = 10 ** 9 + 7

counter = 0
for k in range(K, N+2):
	counter += (N-k+1) * k + 1
	counter %= MOD

print(counter)
# Original solution
MOD = 10 ** 9 + 7

n,k = list(map(int,input().split()))

ans = 0
for i in range(k,n+2):
    i %= MOD
    add = -i**2 + i*(n+1) + 1
    add %= MOD
    ans += add

ans %= MOD
print(ans)



# Optimized solution
MOD = 10 ** 9 + 7

n,k = list(map(int,input().split()))

ans = 0
for i in range(k,n+2):
    add = -i**2 + i*(n+1) + 1
    add %= MOD
    ans += add

ans %= MOD
print(ans)
# Original solution
MOD=10**9+7
N,K=list(map(int,input().split()))
ans=0
for k in range(K,N+2):
  ans+=(N-k+1)*k+1
  ans%=MOD
print(ans)

# Optimized solution
MOD=10**9+7

N,K=list(map(int,input().split()))
ans=0
ans+=N-K+2
ans+=(N+1)*(N+1+K)*(N-K+2)//2
ans%=MOD
ans-=(N+1)*(N+2)*(2*N+3)//6
ans%=MOD
ans+=K*(K-1)*(2*K-1)//6
ans%=MOD
print(ans)
# Original solution
N, K = list(map(int, input().split()))
MOD = 10 ** 9 + 7

LOW, HIGH = 0, N
ans = 0

if 1 >= K:
    ans += (HIGH - LOW + 1)

for i in range(2, N + 2):
    LOW += i - 1
    HIGH += N - i + 1
    LOW %= MOD
    HIGH %= MOD
    if i >= K:
        ans += (HIGH - LOW + 1)
        ans %= MOD

print(ans)


# Optimized solution
N, K = list(map(int, input().split()))
MOD = 10 ** 9 + 7

low, high = 0, 0
ans = 0
for i in range(1, N + 2):
    low += i - 1
    high += N - i + 1

    if i >= K:
        ans += (high - low + 1)
        ans %= MOD

print(ans)
# Original solution
n,k = [int(i) for i in input().split()]
mod = 10**9+7
chk = 0
ans = 0
for i in range(n+1):
  chk += (n + i*n +1 -(i+1)*i)%mod
  chk %= mod
for i in range(k-1):
  ans += (n + i*n +1 -(i+1)*i)%mod
  ans %= mod
print(((chk-ans)%mod)) 

# Optimized solution
n,k=list(map(int,input().split()));mod=10**9+7;print(((n*(n+1)*(n+2)//6-k*(k-1)*(3*n-2*k+4)//6+n-k+2)%mod))
# Original solution
# D - Sum of Large Numbers
from itertools import accumulate


def main():
    N, K = list(map(int, input().split()))
    cumsum_left = tuple(accumulate(list(range(N + 1))))
    cumsum_right = tuple(accumulate(reversed(list(range(N + 1)))))
    total = 0
    MOD = 10 ** 9 + 7
    for l, r in zip(cumsum_left[K - 1 :], cumsum_right[K - 1 :]):
        total += r - l + 1
        total %= MOD
    print(total)


if __name__ == "__main__":
    main()


# Optimized solution
# D - Sum of Large Numbers
from itertools import accumulate


def main():
    N, K = list(map(int, input().split()))
    MOD = 10 ** 9 + 7
    cumsum_left = tuple(accumulate(list(range(N + 1))))
    cumsum_right = tuple(accumulate(reversed(list(range(N + 1)))))
    total = sum(r - l + 1 for l, r in zip(cumsum_left[K - 1 :], cumsum_right[K - 1 :]))
    total %= MOD
    print(total)


if __name__ == "__main__":
    main()
# Original solution
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

ans = 0
for i in range(K, N + 2):
    B = N * (N + 1) // 2 - (N - i) * (N - i + 1) // 2
    A = (i - 1) * i // 2
    ans += (B - A + 1)
print((ans % mod))

# Optimized solution
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

ans = 0
for k in range(K, N + 2):
    # k個足してできる最大の整数
    # 大きい順にk個選べばよい
    # N + (N - 1) + ... + (N - k + 1)
    # = (0+1+...+N) - (0+1+...+(N-k)) = B
    B = N * (N + 1) // 2 - (N - k) * (N - k + 1) // 2
    # 最小の整数は小さい順にk個選べばよい
    # 0 + 1 + ... + (k-1)
    A = (k - 1) * k // 2
    # k個足してできる整数の数
    ans += (B - A + 1)
print((ans % mod))
# Original solution
N,K=list(map(int,input().split()))
ans=0


for i in range(K,N+2):
    mini=i*(i-1)//2
    maxi=i*N-mini
    ans=ans+(maxi-mini+1)
print((ans%(10**9+7)))


# Optimized solution
N,K=list(map(int,input().split()))

M=N+1

A=-M*(M+1)*(2*M+1)//6+(N+1)*M*(M+1)//2+M

M=K-1

B=-M*(M+1)*(2*M+1)//6+(N+1)*M*(M+1)//2+M


print(((A-B)%(10**9+7)))
# Original solution
def LI():return list(map(int,input().split()))
n,k=LI()
mod=10**9+7
ans=0
for kk in range(k,n+1+1):
    tmp=n*kk-(kk-1)*kk+1
    ans+=(tmp%mod)
print((ans%mod))

# Optimized solution
n,k=list(map(int,input().split()));print(((k-n-2)*(2*k*k-k*n-2*k-n*n-n-6)//6%(10**9+7)))
# Original solution
n,k=list(map(int,input().split()))
a=0
for i in range(k,n+2):
  a=(a+i*(n-i+1)+1)%(10**9+7)
print(a)

# Optimized solution
n,k=list(map(int,input().split()));print((sum(1+i*(n-i+1)for i in range(k,n+2))%(10**9+7)))