/* -*- coding: utf-8 -*- * * 1417.cc: No.1417 100の倍数かつ正整数(2) - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_L = 10000; const int MOD = 1000000007; const int d2s[] = { 0, 0, 1, 0, 2, 0, 1, 0, 2, 0 }; const int d5s[] = { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }; /* typedef */ typedef long long ll; /* global variables */ char s[MAX_L + 4]; int dp[MAX_L + 1][3][3]; /* subroutines */ inline void addmod(int &a, int b) { a = (a + b) % MOD; } inline int pmod(int a, int b) { return (ll)a * b % MOD; } void seti(int i, int j2, int j5, int d0, int maxk) { for (int k = 1; k < maxk; k++) addmod(dp[i][min(2, j2 + d2s[k])][min(2, j5 + d5s[k])], d0); } /* main */ int main() { scanf("%s", s); int l = strlen(s); int s0 = s[0] - '0'; seti(1, 0, 0, 1, s0); int cj2 = d2s[s0], cj5 = d5s[s0]; bool z = false; for (int i = 1; i < l; i++) { for (int j2 = 0; j2 <= 2; j2++) for (int j5 = 0; j5 <= 2; j5++) { int d0 = dp[i][j2][j5]; if (d0 > 0) seti(i + 1, j2, j5, d0, 10); } seti(i + 1, 0, 0, 1, 10); int si = s[i] - '0'; if (si == 0) z = true; if (! z) { seti(i + 1, cj2, cj5, 1, si); cj2 = min(2, cj2 + d2s[si]); cj5 = min(2, cj5 + d5s[si]); } } if (! z && cj2 == 2 && cj5 == 2) addmod(dp[l][2][2], 1); printf("%d\n", dp[l][2][2]); return 0; }