#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);
}