#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } const ll MOD = 1000000007; class ModInt{ public: ll v; ModInt(ll _v = 0){ if(_v < 0) _v = (_v%MOD)+MOD; if(_v >= MOD) _v %= MOD; v = _v; } ModInt operator+(ll n){ return ModInt((v+n)%MOD); } ModInt operator-(ll n){ return ModInt((v-n+MOD)%MOD); } ModInt operator*(ll n){ if(n >= MOD) n %= MOD; return ModInt((v*n)%MOD); } ModInt operator/(ll n){ return ModInt((ModInt(n).inv()*v).v%MOD); } ModInt &operator+=(ll n){ v = (v+n)%MOD; return *this; } ModInt &operator-=(ll n){ v = (v-n+MOD)%MOD; return *this; } ModInt &operator*=(ll n){ v = (v*n+MOD)%MOD; return *this; } ModInt operator+(ModInt n){ return ModInt((v+n.v)%MOD); } ModInt operator-(ModInt n){ return ModInt((v-n.v+MOD)%MOD); } ModInt operator*(ModInt n){ return ModInt((v*n.v)%MOD); } ModInt operator/(ModInt n){ return ModInt((n.inv()*v).v%MOD); } ModInt &operator+=(ModInt n){ v = (v+n.v)%MOD; return *this; } ModInt &operator-=(ModInt n){ v = (v-n.v+MOD)%MOD; return *this; } ModInt &operator*=(ModInt n){ v = (v*n.v)%MOD; return *this; } bool operator==(ModInt n){ return v == n.v; } bool operator!=(ModInt n){ return v != n.v; } ModInt &operator=(ll n){ v = n%MOD; return *this; } ModInt inv(){ if(v == 1) return ModInt(1); else return ModInt(MOD-ModInt(MOD%v).inv().v*(MOD/v)%MOD); } }; ostream& operator<<(ostream& os, const ModInt& m){ os << m.v; return os; } istream & operator >> (istream &in, ModInt &m){ in >> m.v; return in; } ModInt pow(ModInt a, ll n) { assert(n >= 0); ModInt ans = 1; while (n > 0) { if (n&1) ans = ans*a; a = a*a; n >>= 1; } return ans; } using mint = ModInt; class AhoCorasick { public: struct Edge{ int to; char c; Edge(int to, char c): to(to), c(c) { } }; vector key_words; int n_nodes; AhoCorasick(vector key_words): key_words(key_words) { n_nodes = 1; output = {{}}; tree = {{}}; for(int i = 0; i < key_words.size(); i++) { add(i); } // build failure and output failure.resize(n_nodes); failure[0] = 0; queue que; for(Edge e: tree[0]){ que.push(e.to); failure[e.to] = 0; } while(!que.empty()){ int v = que.front(); que.pop(); for(Edge e: tree[v]){ que.push(e.to); int u = failure[v]; while(find_node(u, e.c) == -1 && u != 0) { u = failure[u]; } failure[e.to] = find_node(u, e.c); if(u == 0 && failure[e.to] == -1){ failure[e.to] = 0; } for(int i: output[failure[e.to]]) output[e.to].insert(i); } } } vector search_text(string text){ int cur = 0; vector ans(key_words.size()); for(char c: text){ while(true){ int nx = find_node(cur, c); if(cur == 0 && nx == -1){ nx = 0; } if(nx != -1) { cur = nx; break; } cur = failure[cur]; } for(int i: output[cur]) ans[i]++; } return ans; } vector> tree; vector failure; vector> output; void add(int idx){ int cur = 0; for(char c: key_words[idx]){ int nx = find_node(cur, c); if(nx == -1){ nx = add_node(cur, c); } cur = nx; } output[cur].insert(idx); } int find_node(int i, char c){ for(Edge e: tree[i]){ if(e.c == c) return e.to; } return -1; } int add_node(int from, char c){ int to = n_nodes; tree[from].push_back(Edge(to, c)); n_nodes++; output.push_back({}); tree.push_back({}); return to; } }; vector list_fib(ll l, ll r){ vector fib = {1, 2}; for(int i = 2;;i++){ ll x = fib[i-1]+fib[i-2]; if(x > r) break; fib.push_back(x); } vector ans; for(ll x: fib){ if(l <= x && x <= r) ans.push_back(x); } return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; ll l, r; cin >> n >> l >> r; auto fib = list_fib(l, r); vector key_words; for(ll x: fib) key_words.push_back(to_string(x)); auto ac = AhoCorasick(key_words); auto dp = vec2d(n+1, ac.n_nodes, mint(0)); dp[0][0] = 1; vector ok(ac.n_nodes, true); for(int i = 0; i < ac.n_nodes; i++){ if(!ac.output[i].empty()) ok[i] = false; } for(int i = 0; i < n; i++){ for(int j = 0; j < ac.n_nodes; j++){ if(!ok[j]) continue; for(int k = 0; k < 10; k++){ int cur = j; char c = '0'+k; while(true){ int nx = ac.find_node(cur, c); if(cur == 0 && nx == -1){ nx = 0; } if(nx != -1) { cur = nx; break; } cur = ac.failure[cur]; } if(!ok[cur]) continue; dp[i+1][cur] += dp[i][j]; } } } cout << accumulate(dp[n].begin(), dp[n].end(), mint(0))-1 << endl; }