#include #include #include #include #include #include #include #include #include template struct PatternsMatching { struct Node { std::array nxt; int fail; bool matched; explicit Node() : fail(0), matched(false) { nxt.fill(-1); } }; std::vector nodes; std::function enc; explicit PatternsMatching(T base) { nodes.emplace_back(); enc = [=](T c) { return c - base; }; } template void add(const Container& s) { int pos = 0; for (T ci : s) { int c = enc(ci); int npos = nodes[pos].nxt[c]; if (npos == -1) { npos = nodes.size(); nodes[pos].nxt[c] = npos; nodes.emplace_back(); } pos = npos; } nodes[pos].matched = true; } void build() { std::queue que; for (int& pos : nodes[0].nxt) { if (pos == -1) { pos = 0; } else { que.push(pos); } } while (!que.empty()) { int pos = que.front(); que.pop(); for (int c = 0; c < K; ++c) { int npos = nodes[pos].nxt[c]; if (npos == -1) continue; int p = nodes[pos].fail; while (nodes[p].nxt[c] == -1) p = nodes[p].fail; int fpos = next(nodes[pos].fail, c); nodes[npos].fail = fpos; if (nodes[fpos].matched) nodes[npos].matched = true; que.push(npos); } } } int next(int pos, int c) const { while (nodes[pos].nxt[c] == -1) pos = nodes[pos].fail; return nodes[pos].nxt[c]; } // (id, end of matching) template std::vector> matching(const Container& s) const { std::vector> ret; int pos = 0; for (int i = 0; i < (int)s.size(); ++i) { pos = next(pos, enc(s[i])); for (auto id : nodes[pos].ids) { ret.emplace_back(id, i + 1); } } return ret; } Node& operator[](int pos) { return nodes[pos]; } Node operator[](int pos) const { return nodes[pos]; } }; using lint = long long; using mint = atcoder::modint1000000007; void solve() { int n; lint l, r; std::cin >> n >> l >> r; PatternsMatching<10, char> pm('0'); { lint a = 1, b = 1; while (a <= r) { if (l <= a && a <= r) pm.add(std::to_string(a)); lint s = a + b; b = a; a = s; } } pm.build(); int m = pm.nodes.size(); std::vector dp(m, 0); dp[0] = 1; auto ndp = dp; while (n--) { std::fill(ndp.begin(), ndp.end(), 0); for (int i = 0; i < m; ++i) { for (int d = 0; d < 10; ++d) { int j = pm.next(i, d); if (pm.nodes[j].matched) continue; ndp[j] += dp[i]; } } std::swap(dp, ndp); } std::cout << (std::accumulate(dp.begin(), dp.end(), mint(0)) - 1).val() << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }