Problem:
Beautiful Sequence
Alice is spending his time on an independent study to apply to the Nationwide Mathematics Contest. This year’s theme is "Beautiful Sequence." As Alice is interested in the working of computers, she wants to create a beautiful sequence using only 0 and 1. She defines a "Beautiful" sequence of length $N$ that consists only of 0 and 1 if it includes $M$ successive array of 1s as its sub-sequence.
Using his skills in programming, Alice decided to calculate how many "Beautiful sequences" she can generate and compile a report on it.
Make a program to evaluate the possible number of "Beautiful sequences" given the sequence length $N$ and sub-sequence length $M$ that consists solely of 1. As the answer can be extremely large, divide it by $1,000,000,007 (= 10^9 + 7)$ and output the remainder.
Input
The input is given in the following format.
$N$ $M$
The input line provides the length of sequence $N$ ($1 \leq N \leq 10^5$) and the length $M$ ($1 \leq M \leq N$) of the array that solely consists of 1s.
Output
Output the number of Beautiful sequences in a line.
Sample Input 1
4 3
Sample Output 1
3
The sequences with length 4 that include 1s in successive array of length 3 are: 0111, 1110 and 1111.
Sample Input 2
4 2
Sample Output 2
8
The sequences with length 4 that include 1s in successive array of length 2 are: 0011, 0110, 0111, 1011, 1100, 1101, 1110 and 1111.

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
ll fast_power(ll a , ll p) {
    if(p == 0)return 1;
    ll res = fast_power(a , p / 2);
    res = res * res % mod;
    if(p & 1)res = a % mod * res % mod;
    return res;
}
const int N = 1e5 + 1;
ll dp[N];
signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n , m;cin>>n>>m;
    for(int i = 0;i <= m;i++) {
        dp[i] = fast_power(2ll , i);
    }
    dp[m] -= 1;
    dp[m] = (dp[m] + mod) % mod;
    for(int i = m + 1;i <= n;i++) {
        dp[i] = 2 * dp[i - 1] - dp[i - 1 - m];
        dp[i] %= mod;
        dp[i] = (dp[i] + mod) % mod;
    }
    cout<<(fast_power(2ll , n) - dp[n] + mod) % mod<<'\n';
}
accuracy: 1
time_ms: 10
memory_kb: 4016
final_rank: 2

code_snippet: #include"bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define int long long
typedef long long ll;
typedef vector<ll> vi;
typedef pair<int,int> P;
constexpr ll mod = 1000000007;

struct segtree{
	vi node,lazy;
	int N;
	void init(int _){
		N=1;
		while(N<_)N*=2;
		node.resize(2*N);
		lazy.resize(2*N);
	}
	void eval(int k,int l,int r){
		if(!lazy[k])return;
		node[k]+=lazy[k]*(r-l)%mod;
		node[k]%=mod;
		if(k<N-1){
			lazy[2*k+1]+=lazy[k];
			lazy[2*k+1]%=mod;
			lazy[2*k+2]+=lazy[k];
			lazy[2*k+2]%=mod;
		}
		lazy[k]=0;
	}	
	void upd(int a,int b,int x,int k,int l,int r){
		eval(k,l,r);
		if(r<=a||b<=l)return;
		if(a<=l&&r<=b){
			lazy[k]+=x;
			lazy[k]%=mod;
			eval(k,l,r);return;
		}
		upd(a,b,x,k*2+1,l,(l+r)/2);
		upd(a,b,x,k*2+2,(l+r)/2,r);
		node[k]=node[k*2+1]+node[k*2+2];
		node[k]%=mod;
	}
	ll calc(int a,int b,int k,int l,int r){
		eval(k,l,r);
		if(r<=a||b<=l)return 0;
		if(a<=l&&r<=b)return node[k];
		ll vl=calc(a,b,k*2+1,l,(l+r)/2);
		ll vr=calc(a,b,k*2+2,(l+r)/2,r);
		return (vl+vr)%mod;
	}
	void add(int l,int r,int x){
		upd(l,r,x,0,0,N);
	}
	ll get(int l,int r){
		return calc(l,r,0,0,N);
	}
};

ll modpow(ll a,ll x){
	ll res=1;
	while(x){
		if(x&1)res=res*a%mod;
		a=a*a%mod;
		x>>=1;
	}
	return res;
}

segtree S1,S2;
signed main(){
	ll n,m;cin>>n>>m;m--;
	S1.init(n+2);
	S2.init(n+2);
	S1.add(0,1,1);
	S2.add(0,1,1);
	for(int i=1;i<=n;i++){
		S2.add(i,n+1,S1.get(i-1,i));
		S1.add(i,min(i+m,n+1),S2.get(i-1,i));
	}

	ll ans=modpow(2,n);
	ans-=S1.get(n,n+1);
	ans-=S2.get(n,n+1);
	ans+=mod*2;
	ans%=mod;
	cout<<ans<<endl;
}
accuracy: 1
time_ms: 90
memory_kb: 11236
final_rank: 7

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef vector<int> vint;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define mod llint(1e9+7)

int power(int a, int b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, b / 2);
	tmp *= tmp;
	tmp %= mod;
	if (b % 2 == 1) {
		tmp *= (llint)a;
		tmp %= mod;
	}
	return tmp;
}

int main() {
	int n, m;
	cin >> n >> m;
	vint dp(n + 1);
	dp[m] = 1;
	for (int i = m; i < n; i++) {
		(dp[i + 1] = dp[i] * 2) %= mod;
		(dp[i + 1] += power(2, i - m)) %= mod;
		(dp[i + 1] -= dp[i - m]) %= mod;
	}
	while (dp[n] < 0)dp[n] += mod;
	cout << dp[n] << endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3600
final_rank: 1

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1   INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

struct SegTree{
    ll sz;
    vector<ll> dat;
    SegTree(ll n){
        sz = 1;
        while (sz < n) sz *= 2;
        dat.resize(2 * sz - 1, 0);
    }
    void update(ll a, ll x){
        a += sz - 1;
        dat[a] = x;
        while(a > 0){
            a = (a - 1) / 2;
            dat[a] = dat[a * 2 + 1] + dat[a * 2 + 2];
        }
        
    }
    ll query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1){
        if (r < 0) r = sz;
        if (r <= a or b <= l) return 0;
        if (a <= l and r <= b) return dat[k];
        ll q1, q2;
        q1 = query(a, b, k * 2 + 1, l, (l + r) / 2);
        q2 = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return q1 + q2;
    }
};

SegTree tree(110000);
ll n, m, dp[110000];
int main(){
    cin >> n >> m;
    tree.update(0, 1);
    REPO(i, n + 1){
        tree.update(i, tree.query(max(0ll, i - m), i) % MOD) ;
        //cout << i - m << endl;
        //cout << tree.query(i, i + 1) << endl;
    }
    ll a = 1;
    REP(i, n){
        a *= 2;
        a %= MOD;
    }
    cout << (a - tree.query(n + 1, n + 2) + MOD * 2) % MOD << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4784
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define elif else if
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

template<int modulo> struct ModInt {
    int x;

    ModInt() : x(0) {}
    ModInt(ll y) : x(y >= 0 ? y % modulo : (modulo - (-y) % modulo) % modulo) {}

    ModInt& operator+=(const ModInt& p) {
        if ((x += p.x) >= modulo) x -= modulo;
        return *this;
    }
    ModInt& operator-=(const ModInt& p) {
        if ((x += modulo - p.x) >= modulo) x -= modulo;
        return *this;
    }
    ModInt& operator*=(const ModInt& p) {
        x = (int)(1LL * x * p.x % modulo);
        return *this;
    }
    ModInt& operator/=(const ModInt& p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt& p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt& p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt& p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt& p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt& p) const { return x == p.x; }
    bool operator!=(const ModInt& p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = modulo, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    ModInt pow(ll e) {
        ll a = 1, p = x;
        while (e > 0) {
            if (e % 2 == 0) {
                p = (p * p) % modulo;
                e /= 2;
            }
            else {
                a = (a * p) % modulo;
                e--;
            }
        }
        return ModInt(a);
    }

    friend ostream& operator<<(ostream& os, const ModInt<modulo>& p) {
        return os << p.x;
    }
    friend istream& operator>>(istream& is, ModInt<modulo>& a) {
        ll x;
        is >> x;
        a = ModInt<modulo>(x);
        return (is);
    }
};
using modint = ModInt<mod>;

template<class Op> class SegmentTree {
	using T = typename Op::T;
	int len, n;
	vector<T> dat;
    T unit = Op::unit;
public:
	SegmentTree(const int _n) : n(_n) {
		for (len = 1; len < n; len <<= 1);
		dat.resize(len << 1, unit);
	}
	SegmentTree(const vector<T>& v) : n(v.size()) {
		for (len = 1; len < n; len <<= 1);
		dat.resize(len << 1, unit);
		for (int i = 0; i < n; ++i)dat[i + len] = v[i];
		for (int i = len - 1; 0 < i; --i)
			dat[i] = Op::merge(dat[i << 1], dat[i << 1 | 1]);
	}
	inline void update(int idx, const T a) {
		idx += len;
		dat[idx] = Op::update(dat[idx], a);
		for (idx >>= 1; 0 < idx; idx >>= 1)
			dat[idx] = Op::merge(dat[idx << 1], dat[idx << 1 | 1]);
	}
	inline T value(int l, int r) {
		T vl = unit, vr = unit;
		for (l += len, r += len; l < r; l >>= 1, r >>= 1) {
			if (l & 1)vl = Op::merge(vl, dat[l++]);
			if (r & 1)vr = Op::merge(dat[--r], vr);
		}
		return Op::merge(vl, vr);
	}
	inline T operator[](int idx) { return dat[idx + len]; }
};
template<class Type> struct modintSumAddUpdate {
	using T = Type;
    const static T unit = 0;
    inline static T merge(T vl, T vr) { return (vl + vr) % mod; }
    inline static T update(T vl, T vr) { return (vl + vr) % mod; }
};

int main() {
    init();

    int n, m; cin >> n >> m;
    vector<SegmentTree<modintSumAddUpdate<ll>>> dp(2, n + 2);
    dp[0].update(0, 1);
    eFOR(i, 1, n + 1) {
        if (m + 1 <= i)dp[1].update(i, dp[0].value(0, i - m));
        dp[0].update(i, dp[0].value(max(0, i - m), i));
        dp[1].update(i, dp[1].value(0, i));
    }
    print(dp[1][n + 1]);

    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 8988
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define elif else if
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

template<int modulo> struct ModInt {
    int x;

    ModInt() : x(0) {}
    ModInt(ll y) : x(y >= 0 ? y % modulo : (modulo - (-y) % modulo) % modulo) {}

    ModInt& operator+=(const ModInt& p) {
        if ((x += p.x) >= modulo) x -= modulo;
        return *this;
    }
    ModInt& operator-=(const ModInt& p) {
        if ((x += modulo - p.x) >= modulo) x -= modulo;
        return *this;
    }
    ModInt& operator*=(const ModInt& p) {
        x = (int)(1LL * x * p.x % modulo);
        return *this;
    }
    ModInt& operator/=(const ModInt& p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt& p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt& p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt& p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt& p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt& p) const { return x == p.x; }
    bool operator!=(const ModInt& p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = modulo, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    ModInt pow(ll e) {
        ll a = 1, p = x;
        while (e > 0) {
            if (e % 2 == 0) {
                p = (p * p) % modulo;
                e /= 2;
            }
            else {
                a = (a * p) % modulo;
                e--;
            }
        }
        return ModInt(a);
    }

    friend ostream& operator<<(ostream& os, const ModInt<modulo>& p) {
        return os << p.x;
    }
    friend istream& operator>>(istream& is, ModInt<modulo>& a) {
        ll x;
        is >> x;
        a = ModInt<modulo>(x);
        return (is);
    }
};
using modint = ModInt<mod>;

template<class Op> class SegmentTree {
	using T = typename Op::T;
	int len, n;
	vector<T> dat;
    T unit = Op::unit;
public:
	SegmentTree(const int _n) : n(_n) {
		for (len = 1; len < n; len <<= 1);
		dat.resize(len << 1, unit);
	}
	SegmentTree(const vector<T>& v) : n(v.size()) {
		for (len = 1; len < n; len <<= 1);
		dat.resize(len << 1, unit);
		for (int i = 0; i < n; ++i)dat[i + len] = v[i];
		for (int i = len - 1; 0 < i; --i)
			dat[i] = Op::merge(dat[i << 1], dat[i << 1 | 1]);
	}
	inline void update(int idx, const T a) {
		idx += len;
		dat[idx] = Op::update(dat[idx], a);
		for (idx >>= 1; 0 < idx; idx >>= 1)
			dat[idx] = Op::merge(dat[idx << 1], dat[idx << 1 | 1]);
	}
	inline T value(int l, int r) {
		T vl = unit, vr = unit;
		for (l += len, r += len; l < r; l >>= 1, r >>= 1) {
			if (l & 1)vl = Op::merge(vl, dat[l++]);
			if (r & 1)vr = Op::merge(dat[--r], vr);
		}
		return Op::merge(vl, vr);
	}
	inline T operator[](int idx) { return dat[idx + len]; }
};
template<class Type> struct modintSumAddUpdate {
	using T = Type;
    const static T unit = 0;
    inline static T merge(T vl, T vr) { return (vl + vr) % mod; }
    inline static T update(T vl, T vr) { return (vl + vr) % mod; }
};

int main() {
    init();

    int n, m; cin >> n >> m;
    vector<SegmentTree<modintSumAddUpdate<ll>>> dp;
    dp.emplace_back(n + 2);
    dp.emplace_back(n + 2);
    dp[0].update(0, 1);
    eFOR(i, 1, n + 1) {
        if (m + 1 <= i)dp[1].update(i, dp[0].value(0, i - m));
        dp[0].update(i, dp[0].value(max(0, i - m), i));
        dp[1].update(i, dp[1].value(0, i));
    }
    print(dp[1][n + 1]);

    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 7056
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define elif else if
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

template<int modulo> struct ModInt {
    int x;

    ModInt() : x(0) {}
    ModInt(ll y) : x(y >= 0 ? y % modulo : (modulo - (-y) % modulo) % modulo) {}

    ModInt& operator+=(const ModInt& p) {
        if ((x += p.x) >= modulo) x -= modulo;
        return *this;
    }
    ModInt& operator-=(const ModInt& p) {
        if ((x += modulo - p.x) >= modulo) x -= modulo;
        return *this;
    }
    ModInt& operator*=(const ModInt& p) {
        x = (int)(1LL * x * p.x % modulo);
        return *this;
    }
    ModInt& operator/=(const ModInt& p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt& p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt& p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt& p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt& p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt& p) const { return x == p.x; }
    bool operator!=(const ModInt& p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = modulo, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    ModInt pow(ll e) {
        ll a = 1, p = x;
        while (e > 0) {
            if (e % 2 == 0) {
                p = (p * p) % modulo;
                e /= 2;
            }
            else {
                a = (a * p) % modulo;
                e--;
            }
        }
        return ModInt(a);
    }

    friend ostream& operator<<(ostream& os, const ModInt<modulo>& p) {
        return os << p.x;
    }
    friend istream& operator>>(istream& is, ModInt<modulo>& a) {
        ll x;
        is >> x;
        a = ModInt<modulo>(x);
        return (is);
    }
};
using modint = ModInt<mod>;

template<class Op> class SegmentTree {
	using T = typename Op::T;
	int len, n;
	vector<T> dat;
    T unit = Op::unit;
public:
	SegmentTree(const int _n) : n(_n) {
		for (len = 1; len < n; len <<= 1);
		dat.resize(len << 1, unit);
	}
	SegmentTree(const vector<T>& v) : n(v.size()) {
		for (len = 1; len < n; len <<= 1);
		dat.resize(len << 1, unit);
		for (int i = 0; i < n; ++i)dat[i + len] = v[i];
		for (int i = len - 1; 0 < i; --i)
			dat[i] = Op::merge(dat[i << 1], dat[i << 1 | 1]);
	}
	inline void update(int idx, const T a) {
		idx += len;
		dat[idx] = Op::update(dat[idx], a);
		for (idx >>= 1; 0 < idx; idx >>= 1)
			dat[idx] = Op::merge(dat[idx << 1], dat[idx << 1 | 1]);
	}
	inline T value(int l, int r) {
		T vl = unit, vr = unit;
		for (l += len, r += len; l < r; l >>= 1, r >>= 1) {
			if (l & 1)vl = Op::merge(vl, dat[l++]);
			if (r & 1)vr = Op::merge(dat[--r], vr);
		}
		return Op::merge(vl, vr);
	}
	inline T operator[](int idx) { return dat[idx + len]; }
};
template<class Type> struct modintSumAddUpdate {
	using T = Type;
    const static T unit = 0;
    inline static T merge(T vl, T vr) { return (vl + vr) % mod; }
    inline static T update(T vl, T vr) { return (vl + vr) % mod; }
};

int main() {
    init();

    int n, m; cin >> n >> m;
    vector<SegmentTree<modintSumAddUpdate<ll>>> dp;
    dp.emplace_back(n + 2);
    dp.emplace_back(n + 2);
    dp[0].update(0, 1);
    eFOR(i, 1, n + 1) {
        if (m + 1 <= i)dp[1].update(i, dp[0].value(0, i - m));
        dp[0].update(i, dp[0].value(i - m, i));
        dp[1].update(i, dp[1].value(0, i));
    }
    print(dp[1][n + 1]);

    return 0;
}
accuracy: 0.8
time_ms: 30
memory_kb: 7080
final_rank: 8

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll dp0[100005]={0};
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll ret=pow(x,y/2);
  ret*=ret;
  ret%=mod;
  if(y%2==1) ret*=x;
  return ret%mod;
}
const ll g2=pow(2,mod-2);
struct segtree{
private:
  vector<ll> node,lazy;
  ll siz;
public:
  segtree(int n){
    siz=1;
    while(siz<=n) siz*=2;
    node.resize(siz*2,0);
    lazy.resize(siz*2,0);
  }
  void eval(ll pos){
    node[pos]+=lazy[pos];
    node[pos]%=mod;
    if(pos<siz-1) {
      lazy[pos*2+1]+=lazy[pos]/2;
      lazy[pos*2+2]+=lazy[pos]/2;
    //  lazy[pos*2+1]%=mod;
    //  lazy[pos*2+2]%=mod;
    }
    lazy[pos]=0;
  }
  void add_q(ll a,ll b,ll x,ll l,ll r,ll pos){
    eval(pos);
    if(b<=l||r<=a) return;
    if(a<=l&&r<=b){
      lazy[pos]+=(x*(r-l));
      eval(pos);
      return;
    }
    ll mid=(l+r)/2;
    add_q(a,b,x,l,mid,pos*2+1);
    add_q(a,b,x,mid,r,pos*2+2);
    node[pos]=(node[pos*2+1]+node[pos*2+2])%mod;
  }
  ll sum_q(ll a,ll b,ll l,ll r,ll pos){
    if(b<=l||r<=a) return 0;
    eval(pos);
    if(a<=l&&r<=b){
      return node[pos]%mod;
    }
    ll mid=(l+r)/2;
    return (sum_q(a,b,l,mid,pos*2+1)+sum_q(a,b,mid,r,pos*2+2))%mod;
  }
  void add(ll a,ll b,ll x){
    add_q(max((ll)0,a),min(b,siz),x,0,siz,0);
  }
  ll sum(ll a,ll b){
    return sum_q(max((ll)0,a),min(b,siz),0,siz,0);
  }
  void debug(){
    cout<<"Node:"<<endl;
    ll t=2;
    for(int i=2;i<=siz*2;i++) {
      cout<<node[i-2]<<" ";
      if(i==t){
        t*=2;
        cout<<endl;
      }
    }
    cout<<"Lazy:"<<endl;
    t=2;
    for(int i=2;i<=siz*2;i++){
      cout<<lazy[i-2]<<" ";
      if(i==t){
        t*=2;
        cout<<endl;
      }
    }
  }
};
int main(){
  ll n,m;
  cin>>n>>m;
  segtree dp1=segtree(n+3);
  dp0[0]=1;
  for(int i=0;i<n;i++){
    dp1.add(i+1,min(n+1,i+m),dp0[i]);
    dp0[i+1]=dp0[i]+dp1.sum(i,i+1);
    dp0[i+1]%=mod;
  }
/*  for(int i=0;i<=n;i++) cout<<dp0[i]<<" ";
  cout<<endl;
  for(int i=0;i<=n;i++) cout<<dp1.sum(i,i+1)<<" ";
  cout<<endl;*/
  ll ans=pow(2,n);
  //cout<<ans<<endl;
  ans-=(dp0[n]+dp1.sum(n,n+1));
  if(ans<0){
    ll t=(0-ans)/mod;
    ans+=(t+1)*mod;
  }
  cout<<ans%mod<<endl;
}
accuracy: 1
time_ms: 60
memory_kb: 7860
final_rank: 6