#include // Aho-Corasick algorithm // Complexity: // - add_keyword(): O(|str|) // - build_aho_corasick(): O(\sum_i |str_i|) template struct Trie { std::vector> child; std::vector fail; std::vector node_info; int root; Trie() : child(1), fail(1), node_info(1), root(0) {} void add_keyword(const std::string &str, T info) { int now = 0; for (auto c : str) { if (child[now].count(c) == 0) { child[now][c] = fail.size(); child.emplace_back(); fail.emplace_back(root); node_info.emplace_back(0); } now = child[now][c]; } node_info[now] += info; } void build_aho_corasick() { std::queue q; for (auto pa : child[root]) q.push(pa.second); while (!q.empty()) { int s = q.front(); q.pop(); for (auto pa : child[s]) { int t = fail[s]; while (t and child[t].count(pa.first) == 0) t = fail[t]; int u = (child[t].count(pa.first) ? child[t][pa.first] : root); fail[pa.second] = u; node_info[pa.second] += node_info[u]; q.push(pa.second); } } } }; using namespace std; using lint = long long; struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i struct ModInt { using lint = long long; int val; constexpr ModInt() : val(0) {} constexpr ModInt &_setval(lint v) { val = (v >= mod ? v - mod : v); return *this; } constexpr ModInt(lint v) { _setval(v % mod + mod); } explicit operator bool() const { return val != 0; } constexpr ModInt operator+(const ModInt &x) const { return ModInt()._setval((lint)val + x.val); } constexpr ModInt operator-(const ModInt &x) const { return ModInt()._setval((lint)val - x.val + mod); } constexpr ModInt operator*(const ModInt &x) const { return ModInt()._setval((lint)val * x.val % mod); } constexpr ModInt operator/(const ModInt &x) const { return ModInt()._setval((lint)val * x.inv() % mod); } constexpr ModInt operator-() const { return ModInt()._setval(mod - val); } constexpr ModInt &operator+=(const ModInt &x) { return *this = *this + x; } constexpr ModInt &operator-=(const ModInt &x) { return *this = *this - x; } constexpr ModInt &operator*=(const ModInt &x) { return *this = *this * x; } constexpr ModInt &operator/=(const ModInt &x) { return *this = *this / x; } friend constexpr ModInt operator+(lint a, const ModInt &x) { return ModInt()._setval(a % mod + x.val); } friend constexpr ModInt operator-(lint a, const ModInt &x) { return ModInt()._setval(a % mod - x.val + mod); } friend constexpr ModInt operator*(lint a, const ModInt &x) { return ModInt()._setval(a % mod * x.val % mod); } friend constexpr ModInt operator/(lint a, const ModInt &x) { return ModInt()._setval(a % mod * x.inv() % mod); } constexpr bool operator==(const ModInt &x) const { return val == x.val; } constexpr bool operator!=(const ModInt &x) const { return val != x.val; } bool operator<(const ModInt &x) const { return val < x.val; } // To use std::map friend std::istream &operator>>(std::istream &is, ModInt &x) { lint t; is >> t; x = ModInt(t); return is; } friend std::ostream &operator<<(std::ostream &os, const ModInt &x) { os << x.val; return os; } constexpr lint power(lint n) const { lint ans = 1, tmp = this->val; while (n) { if (n & 1) ans = ans * tmp % mod; tmp = tmp * tmp % mod; n /= 2; } return ans; } constexpr lint inv() const { return this->power(mod - 2); } }; using mint = ModInt<1000000007>; int main() { int N; lint L, R; cin >> N >> L >> R; vector fibs; { lint f1 = 1, f2 = 0; while (true) { lint fnew = f1 + f2; if (fnew >= L and fnew <= R) { fibs.emplace_back(fnew); } else if (fnew > R) break; f2 = f1; f1 = fnew; } } Trie aho; for (auto v : fibs) { aho.add_keyword(to_string(v), 1); } aho.build_aho_corasick(); const int V = aho.fail.size(); vector> to(V, vector(10)); const vector &bad = aho.node_info; REP(i, V) { REP(d, 10) { int now = i; while (now != 0 and aho.child[now].count('0' + d) == 0) { now = aho.fail[now]; } if (aho.child[now].count('0' + d)) { to[i][d] = aho.child[now]['0' + d]; } } } vector dp(V); dp[0] = 1; REP(_, N) { vector nxt(V); REP(i, V) for (auto j : to[i]) { if (!bad[j]) nxt[j] += dp[i]; } dp = nxt; } cout << accumulate(dp.begin(), dp.end(), mint(0)) - 1 << '\n'; }