Problem:
Problem I: 11224111122411
腕が引っかかって抜けない。
机の裏に転がり込んでしまったものを拾おうとして、懐中電灯代わりに携帯の画面で照らしながら腕を挿し込んでみたが、うっかり何かに引っかかって抜けなくなってしまった。無理に動かすと痛い。
どうしよう。どうすれば脱出できるのだろう。大声で助けを呼ぶか。恥ずかしいので却下したいが、独力で脱出するのは難しそうだ。いや、声の届く範囲には誰もいなかったはずだ。焦る気持ちを押さえて辺りを見渡す。あのパソコンに手が届けばメールで助けを呼べるのだが、あいにく遠すぎる。やはり偶然誰かが通りかかるのを待つしかないのか。
いや待て、メールを送る機械ならあるじゃないか。手の届くところというよりも、既にこの手の中に。深く伸ばした手の先の画面はぼやけてよく見えないが、長年使っている携帯だ。画面が見えなくてもメールぐらいは送れるはずだ。
慎重に、頭の中に画面を描きながらボタンを押す。指の感触だけを頼りに、タイプミスだけはしないように、数字キーを何度も押してメッセージを打ち込む。漢字変換はしない、平仮名でもきっと伝わるはずだ。つくづくタッチパネルが主流のスマートフォンに乗り換えていなくてよかったと思う。
深呼吸をして、送信ボタンに指をかける。しばらくして、携帯が軽く震えた。送信完了の合図だ。溜息。しばらくすれば友人が助けに来るに違いない。
友人は賢いので適切に解釈してくれると思うのだが、今送ったメッセージは、本当に送りたかったメッセージとは違うものになっているかもしれない。この携帯の文字入力メソッドは広く使われているものと同じで、例えば「あ」行の平仮名を入力するのに "1" のボタンを使う。 "1" は「あ」を、 "11" は「い」を、以下同様に "11111" が「お」を表す。平仮名はループする、つまり "111111" もまた「あ」となる。「か」行は "2" 、「さ」行は "3" 、 ... を使い、同じボタンを続けて押したときの挙動は "1" の例と同様である。
ただし、この文字入力メソッドにはちょっと厄介な挙動がある。数字ボタンを押した後しばらく操作しないでいると、平仮名への変換が強制的に行われてしまうのだ。つまり、３回続けて "1" を押せば 「う」 になるが、時間を置いて３回 "1" を押すと「あああ」になる。別の例をあげると、 "111111" と押したとき、その押す間隔によって入力された文字列は「あ」にも「ああああああ」にもなる。"111111111111"は「い」かもしれないし、「ええいああ」かもしれないし、１２個の「あ」になるかもしれない。なお、違う数字ボタンを押したときにも平仮名への変換はおこなわれるので、 "12345" は「あかさたな」という文字列にしかなりえない。
さて、慎重にタイプしたので間違ったボタンを押したつもりはないのだが、適切な間隔でボタンを押せた自信はない。本当に送りたかったメッセージとは違うものを送ってしまった可能性は大いにあるのだ。さて、送られたかもしれない文字列の数は何通りだろうか。ああ、これは友人が助けに来るまでの暇つぶしにいいかもしれない。遅くても５時間以内に助けに来てくれるだろう。それまでに解けるといいのだけど。
Input
入力は複数のケースからなる。
各ケースは以下のフォーマットで与えられる。
string
入力の終わりは,入力が"#"からなる行によって与えられる
string
は0から9の間の数字を最大100,000個含む。
string
の長さが10,000を越える入力は50個を超えない。
テストケースのファイルサイズは5MB以下であることが保証される。
またテストケースの数は100を超えない。
各数字キーで入力可能な文字は以下の表のとおりである。
数字
入力可能な文字
1
あいうえお
2
かきくけこ
3
さしすせそ
4
たちつてと
5
なにぬねの
6
はひふへほ
7
まみむめも
8
やゆよ
9
らりるれろ
0
わをん
Output
文章の解釈の仕方を100000007で割った余りを1行に出力せよ。
Sample input
1
11
111111
111111111111
12345
11111111119999999999
11111111113333333333
11111111118888888888
11111111112222222222111111111
11111111110000000000444444444
11224111122411
888888888888999999999999888888888888999999999999999999
666666666666666777333333333338888888888
1111114444441111111444499999931111111222222222222888111111115555
#
Sample output
1
2
32
1856
1
230400
230400
156480
56217600
38181120
128
26681431
61684293
40046720
The University of Aizu Programming Contest 2011 Summer
原案: Tomoya Sakai
問題文: Takashi Tayama

Submitted solutions:

code_snippet: #pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace::std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
// random_device rd;
// mt19937 mt(rd());
// #include <boost/numeric/interval.hpp>
// #include <boost/numeric/interval/io.hpp>
// #include <boost/intrusive/rbtree.hpp>
// #include <boost/geometry.hpp>
// #include <boost/geometry/geometries/linestring.hpp>
// #include <boost/geometry/geometries/polygon.hpp>
// #include <boost/geometry/geometries/point_xy.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cfloat;
// typedef mp::cpp_int cint;

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
template<typename T=long long>using pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T=long long>using pqueue =__gnu_pbds::priority_queue<T, less<T>,rc_binomial_heap_tag>;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
typedef vector<pair<lint,lint>> pvec;
typedef vector<vector<pair<lint,lint>>> pmat;
typedef vector<vector<vector<pair<lint,lint>>>> pmat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
//#define PI 3.141592653589793
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"");if(i>INF/2)cout<<"INF";else cout<<i;f=1;}cout<<"\n";}while(0)
#define output2(v) for(auto j:v)output(j);
#define _output(v) do{bool f=0;rep(i,v.size()){cout<<(f?" ":"");if(v[i]>INF/2)cout<<"INF";else cout<<v[i];f=1;}cout<<"\n";}while(0)
#define _output2(v) rep(j,v.size()){_output(v[j]);}
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define SUM(v) accumulate(all(v),0LL)
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define LINF 9223372036854775807
#define MOD 100000007
#define endl "\n"
template<typename T=lint>T in(){return *istream_iterator<T>(cin);}
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
template<typename T=lint>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<typename T=lint>inline T add(T a,T b){return a+b;}
template<typename T=lint>inline T minq(T a,T b){return min(a,b);}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};

class mint {
  using u64 = std::uint_fast64_t;
    public:
    u64 a;
    constexpr mint(const u64 x = 0) noexcept : a(x % MOD) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr mint operator+(const mint rhs) const noexcept {
        return mint(*this) += rhs;
    }
    constexpr mint operator-(const mint rhs) const noexcept {
        return mint(*this) -= rhs;
    }
    constexpr mint operator*(const mint rhs) const noexcept {
        return mint(*this) *= rhs;
    }
    constexpr mint operator/(const mint rhs) const noexcept {
        return mint(*this) /= rhs;
    }
    constexpr mint &operator+=(const mint rhs) noexcept {
        a += rhs.a;
        if (a >= MOD) {
            a -= MOD;
        }
        return *this;
    }
    constexpr mint &operator-=(const mint rhs) noexcept {
        if (a < rhs.a) {
            a += MOD;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr mint &operator*=(const mint rhs) noexcept {
        a = a * rhs.a % MOD;
        return *this;
    }
    constexpr mint operator++(int n) const noexcept {
        return mint(*this) +=1;
    }
    constexpr mint operator--(int n) const noexcept {
        return mint(*this) -=1;
    }
    constexpr mint &operator/=(mint rhs) noexcept {
        u64 exp = MOD - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};
ostream& operator<<(ostream& lhs, const mint& rhs) noexcept {
    lhs << rhs.a;
    return lhs;
}
istream& operator>>(istream& lhs, const mint& rhs) noexcept {
    lhs >> rhs.a;
    return lhs;
}
inline mint pow(mint m,lint n){
    if(n==0)return 1;
    else if(n%2==0){
        mint x=pow(m,n/2);
        return x*x;
    }else{
        return m*pow(m,n-1);
    }
}
inline mint fact(lint a){
    return a?fact(a-1)*a:1;
}
class Comb{
    public:
    vector<lint> fac,ifac;
    Comb(){
        fac.resize(300001);
        ifac.resize(300001);
        fac[0] = 1;
        ifac[0] = 1;
        rep(i,300000){
            fac[i+1] = fac[i]*(i+1) % MOD;
            ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD;
        }
    }
    lint mpow(lint x, lint n){
        lint ans = 1;
        while(n != 0){
            if(n&1) ans = ans*x % MOD;
            x = x*x % MOD;
            n = n >> 1;
        }
        return ans;
    }
    lint comb(lint a, lint b){
        if(a == 0 && b == 0)return 1;
        if(a < b || a < 0)return 0;
        lint tmp = ifac[a-b]* ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};
Comb c;
mint f(lint n,lint m){
    vector<vector<mint>> dp(n+1,vector<mint>(m,0));
    dp[0][0]=0;
    dp[1][0]=1;
    repi(i,2,n+1)rep(j,m){
        dp[i][0]+=dp[i-1][j];
        if(j!=0)dp[i][j]=dp[i-1][j-1];
    }
    mint res=0;
    for(lint i=0;n-i*m>=0;i++)rep(j,m){
        res+=dp[n-i*m][j];
    }
    return res;
}
int main(){
    while(1){
        string s;
        cin>>s;
        if(s=="#")break;
        lint cnt=1;
        mint ans=1;
        rep(i,s.size()-1){
            if(s[i]==s[i+1])cnt++;
            else {
                lint m=5;
                if(s[i]=='8'||s[i]=='0')m=3;
                ans*=f(cnt,m);
                cnt=1;
            }
        }
        lint m=5;
        if(s[s.size()-1]=='8'||s[s.size()-1]=='0')m=3;
        ans*=f(cnt,m);
        cout<<ans<<endl;
    }
}
accuracy: 1
time_ms: 240
memory_kb: 17964
final_rank: 16

code_snippet: #include <bits/stdc++.h>
#define MOD (long long)(1e8 + 7)
using namespace std;

string s;

long long solve();
long long calc(long long len, long long msize);

int main() {
  while(1) {
    cin >> s;
    if(s == "#") break;
    cout << solve() << endl;
  }
  return 0;
}

long long solve() {
  long long ans = 1, ssize = s.size();
  for(int i = 0; i < ssize; ++i) {
    char now = s[i];
    long long cnt = 0, nowsize = 3;
    if(now != '0' && now != '8') nowsize += 2;
    while(i < ssize && s[i] == now) ++i, ++cnt;
    (ans *= calc(cnt, nowsize)) %= MOD;
    --i;
  }
  return ans;
}

long long calc(long long len, long long msize) {
  long long ans = 0;
  vector<long long> dp;
  dp.assign(msize, 0);
  dp[len % msize] = 1;
  for(int i = 0; i < len; ++i) {
    long long sum = 0;
    for(int j = 0; j < msize; ++j) (sum += dp[j]) %= MOD;
    if((len - 1 - i) % msize == 0) (ans += sum) %= MOD;
    dp[(len - 1 - i) % msize] = sum;
  }
  return ans;
}
accuracy: 1
time_ms: 120
memory_kb: 3272
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 100000007

const ll M=100000;
ll dp5[100001],dp3[100001];

ll calc(bool is5, ll len){
  ll res=0;
  if(is5){
    repl(l,1,len+1){
      if((len-l)%5==0){
        (res+=dp5[l])%=mod;
      }
    }
  }else{
    repl(l,1,len+1){
      if((len-l)%3==0){
        (res+=dp3[l])%=mod;
      }
    }
  }
  return res;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  dp5[0]=1;
  repl(i,1,M+1){
    repl(j,1,5+1){
      if(i-j>=0)(dp5[i]+=dp5[i-j])%=mod;
    }
  }
  dp3[0]=1;
  repl(i,1,M+1){
    repl(j,1,3+1){
      if(i-j>=0)(dp3[i]+=dp3[i-j])%=mod;
    }
  }

  while(1){
    string S;
    cin>>S;
    if(S=="#")break;
    ll N=S.size();
    ll res=1;
    ll i=0;
    while(i<N){
      ll j=i;
      while(j<N&&S[i]==S[j]){
        j++;
      }
      if(S[i]=='8'||S[i]=='0') (res*=calc(false,j-i))%=mod;
      else (res*=calc(true,j-i))%=mod;
      i=j;
    }
    cout<<res<<endl;
  }

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5016
final_rank: 4

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
using namespace std;
typedef long long int ll;

ll mod=1e8+7;
ll dp[100100];
ll dp1[100100];

int main(){
	for(int i=1;i<=6;i++){
		dp[i]=pow(2,i-1);
	}
	for(int i=7;i<=100000;i++){
		(dp[i]+=dp[i-1]+dp[i-2]+dp[i-3]+dp[i-4]+dp[i-5]+1)%=mod;
	}
	for(int i=1;i<=4;i++){
		dp1[i]=pow(2,i-1);
	}
	for(int i=5;i<=100000;i++){
		(dp1[i]+=dp1[i-1]+dp1[i-2]+dp1[i-3]+1)%=mod;
	}
	while(1){
		string s; cin >> s;
		if(s=="#")break;
		int n=s.size();
		ll ans=1;
		for(int i=0;i<n;i++){
			char c=s[i];
			int cnt=0;
			while(i<n&&s[i]==c){
				i++;
				cnt++;
			}
			i--;
			if(c=='8'||c=='0')(ans*=dp1[cnt])%=mod;
			else (ans*=dp[cnt])%=mod;
		}
		cout << ans << endl;
	}
}
accuracy: 1
time_ms: 70
memory_kb: 5040
final_rank: 8

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

template<ll MOD = 1000000007>
class ModInt {
    ll n;
    static ModInt pow(ModInt x, ll p) {
        if (p == 0) {
            return 1;
        } else if (p % 2) {
            return x * pow(x, p - 1);
        } else {
            auto t = ModInt::pow(x, p / 2);
            return t * t;
        }
    }
    ModInt reverse() const {
        return ModInt::pow(*this, MOD - 2);
    }

public:
    ModInt()
        : n(0) {}
    ModInt(ll _n)
        : n(_n % MOD) {}
    ModInt operator+=(const ModInt &m) {
        n += m.n;
        if (n >= MOD) {
            n -= MOD;
        }
        return *this;
    }
    ModInt operator-=(const ModInt &m) {
        n -= m.n;
        if (n < 0) {
            n += MOD;
        }
        return *this;
    }
    ModInt operator*=(const ModInt &m) {
        n *= m.n;
        if (n >= MOD) {
            n %= MOD;
        }
        return *this;
    }
    ModInt operator/=(const ModInt &m) {
        return n = (m.reverse() * n).n;
    }

    ModInt operator+=(const ll l) {
        return (*this) += ModInt(l);
    }
    ModInt operator-=(const ll l) {
        return (*this) -= ModInt(l);
    }
    ModInt operator*=(const ll l) {
        return (*this) *= ModInt(l);
    }
    ModInt operator/=(const ll l) {
        return (*this) /= ModInt(l);
    }
    ModInt operator+(const ModInt &m) {
        auto t = *this;
        return t += m;
    }
    ModInt operator-(const ModInt &m) {
        auto t = *this;
        return t -= m;
    }
    ModInt operator*(const ModInt &m) {
        auto t = *this;
        return t *= m;
    }
    ModInt operator/(const ModInt &m) {
        auto t = *this;
        return t /= m;
    }
    ModInt operator+(const ll l) {
        auto t = *this;
        return t += l;
    }
    ModInt operator-(const ll l) {
        auto t = *this;
        return t -= l;
    }
    ModInt operator*(const ll l) {
        auto t = *this;
        return t *= l;
    }
    ModInt operator/(const ll l) {
        auto t = *this;
        return t /= l;
    }
    ModInt operator=(const ll l) {
        n = l % MOD;
        if (n < 0) {
            n += MOD;
        }
        return *this;
    }
    friend ostream &operator<<(ostream &out, const ModInt &m) {
        out << m.n;
        return out;
    }
    friend istream &operator>>(istream &in, ModInt &m) {
        ll l;
        in >> l;
        m = l;
        return in;
    }
};

using mint = ModInt<100000007>;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int size = 100010;
    vector<mint> dp1(size + 1, 1), dp2(size + 1, 1);
    REP(i, 1, size + 1) {
        REP(j, 1, 6) {
            if (i - j > 0) {
                dp1[i] += dp1[i - j];
            }
        }
        REP(j, 1, 4) {
            if (i - j > 0) {
                dp2[i] += dp2[i - j];
            }
        }
    }

    string s;
    while (cin >> s, s != "#") {
        mint ans = 1;
        s += "#";
        int prev = 0;
        REP(i, 1, s.size()) {
            if (s[i - 1] != s[i]) {
                if (s[prev] == '8' || s[prev] == '0') {
                    ans *= dp2[i - prev];
                } else {
                    ans *= dp1[i - prev];
                }
                prev = i;
            }
        }
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4760
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 100000007;

const int N = 100010;
ll x[N], y[N];

int main(){
    x[0] = 1;
    rep(i,N){
        for(int j=1; j<=5; ++j)if(i+j<N) (x[i+j] += x[i]) %= mod;
        if(i-5>0) (x[i] += x[i-5]) %= mod;
    }
    y[0] = 1;
    rep(i,N){
        for(int j=1; j<=3; ++j)if(i+j<N) (y[i+j] += y[i]) %= mod;
        if(i-3>0) (y[i] += y[i-3]) %= mod;
    }

    string s;
    while(cin >>s,(s!="#")){
        int n = s.size();

        ll ans = 1;
        int i = 0;
        while(i<n){
            int nx = i;
            while(nx<n && s[nx]==s[i]) ++nx;

            int w = nx-i;
            if(s[i]=='8' || s[i]=='0') (ans *= y[w]) %= mod;
            else (ans *= x[w]) %= mod;

            i = nx;
        }

        cout << ans << "\n";
    }
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 4896
final_rank: 9

code_snippet: #define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e8 + 7;

int main(){
	
	while(true){
		string str;
		cin >> str;
		char pre = str[0];
		
		if(pre == '#'){
			break;
		}
		
		str += " ";
		
		int cnt = 0;
		
		vector<P> v;
		
		for(int i = 0; i < str.size(); i++){
			if(str[i] == pre){
				cnt += 1;
			}else{
				if(pre == '8' || pre == '0'){
					v.push_back(make_pair(cnt, 3));
				}else{
					v.push_back(make_pair(cnt, 5));
				}
				cnt = 1;
			}
			pre = str[i];
		}
		
		long long int ans = 1;
		
		for(int i = 0; i < v.size(); i++){
			int num = v[i].first;
			int tp = v[i].second;
			long long int S = 0;
			long long int DP[5] = {1};
			
			for(int j = 1; j <= num + 1; j++){
				if((num - j) % tp == 0){
					for(int k = 0; k < tp; k++){
						S += DP[k];
						S %= MOD;
					}
				}
				long long int DP2[5] = {};
				for(int k = 0; k < tp; k++){
					DP2[0] += DP[k];
					DP2[0] %= MOD;
				}
				for(int k = 1; k < tp; k++){
					DP2[k] = DP[k - 1];
					DP2[k] %= MOD;
				}
				swap(DP, DP2);
			}
			ans *= S;
			ans %= MOD;
		}
		
		cout << ans << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 350
memory_kb: 3288
final_rank: 15

code_snippet: #define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e8 + 7;

int main(){
	
	while(true){
		string str;
		cin >> str;
		char pre = str[0];
		
		if(pre == '#'){
			break;
		}
		
		str += " ";
		
		int cnt = 0;
		
		vector<P> v;
		
		for(int i = 0; i < str.size(); i++){
			if(str[i] == pre){
				cnt += 1;
			}else{
				if(pre == '8' || pre == '0'){
					v.push_back(make_pair(cnt, 3));
				}else{
					v.push_back(make_pair(cnt, 5));
				}
				cnt = 1;
			}
			pre = str[i];
		}
		
		long long int ans = 1;
		
		for(int i = 0; i < v.size(); i++){
			int num = v[i].first;
			int tp = v[i].second;
			long long int S = 0;
			long long int DP[5] = {1};
			
			for(int j = 1; j <= num + 1; j++){
				if((num - j) % tp == 0){
					for(int k = 0; k < tp; k++){
						S += DP[k];
						S %= MOD;
					}
				}
				long long int DP2[5] = {};
				for(int k = 0; k < tp; k++){
					DP2[0] += DP[k];
				}
				for(int k = 1; k < tp; k++){
					DP2[k] = DP[k - 1];
				}
				swap(DP, DP2);
			}
			ans *= S;
			ans %= MOD;
		}
		
		cout << ans << endl;
	}
	return 0;
}
accuracy: 0.3333333333333333
time_ms: 120
memory_kb: 3316
final_rank: 20

code_snippet: #include <stdio.h>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100000007

ll dp_5[100001],dp_3[100001];
char buf[100001];


void func(){

	ll ans = 1;
	int left = 0,right;

	while(buf[left] != '\0'){
		for(right = left; buf[right] != '\0' && buf[right] == buf[left]; right++);
		right--;

		if(buf[left] == '8' || buf[left] == '0'){
			ans *= dp_3[right-left+1];
			ans %= NUM;
		}else{
			ans *= dp_5[right-left+1];
			ans %= NUM;
		}
		left = right+1;
	}

	printf("%lld\n",ans%NUM);
}

int main(){

	for(int length = 1; length <= 6; length++){
		dp_5[length] = pow(2,length-1);
	}
	for(int length = 7; length <= 100000; length++){
		dp_5[length] = (1+dp_5[length-1]+dp_5[length-2]+dp_5[length-3]+dp_5[length-4]+dp_5[length-5])%NUM;
	}

	for(int length = 1; length <= 4; length++){
		dp_3[length] = pow(2,length-1);
	}
	for(int length = 5; length <= 100000; length++){
		dp_3[length] = (1+dp_3[length-1]+dp_3[length-2]+dp_3[length-3])%NUM;
	}

	while(true){
		scanf("%s",buf);
		if(buf[0] == '#')break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5048
final_rank: 5

code_snippet: #include "bits/stdc++.h"
using namespace std;


const int mod = 100000007;
struct Mod {
public:
	int num;
	Mod() : Mod(0) { ; }
	Mod(long long int n) : num((n % mod + mod) % mod) {
		static_assert(mod<INT_MAX / 2, "mod is too big, please make num 'long long int' from 'int'");
	}
	Mod(int n) : Mod(static_cast<long long int>(n)) { ; }
	operator int() { return num; }
};

Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator+(const Mod a, const long long int  b) { return b + a; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; }
Mod operator*(const Mod a, const long long int b) { return Mod(b)*a; }
Mod operator*(const Mod a, const int b) { return Mod(b)*a; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator*=(Mod& a, const long long int &b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod mod_pow(const Mod a, const long long  int n) {
	if (n == 0) return Mod(1);
	Mod res = mod_pow((a * a), (n / 2));
	if (n % 2) res = res * a;
	return res;
}
Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
	assert(b.num != 0);
	return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) {
	return Mod(a) / b;
}
Mod operator/=(Mod &a, const Mod b) {
	return a = a / b;
}

#define MAX_MOD_N 1024000

Mod fact[MAX_MOD_N], factinv[MAX_MOD_N];
void init(const int amax = MAX_MOD_N) {
	fact[0] = Mod(1); factinv[0] = 1;
	for (int i = 0; i < amax - 1; ++i) {
		fact[i + 1] = fact[i] * Mod(i + 1);
		factinv[i + 1] = factinv[i] / Mod(i + 1);
	}
}
Mod comb(const int a, const int b) {
	return fact[a] * factinv[b] * factinv[a - b];
}

int main() {
	vector<vector<Mod>>dp5(2e5, vector<Mod>(5));
	dp5[1][0] = 1;
	for (int i = 1; i < 1e5 + 3; ++i) {
		for (int j = 0; j < 5; ++j) {
			dp5[i + 1][0] += dp5[i][j];
			if (j != 4) {
				dp5[i + 1][j + 1] += dp5[i][j];
			}
		}
	}
	vector<vector<Mod>>dp3(2e5, vector<Mod>(3));
	dp3[1][0] = 1;
	for (int i = 1; i < 1e5 + 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			dp3[i + 1][0] += dp3[i][j];
			if (j != 2) {
				dp3[i + 1][j + 1] += dp3[i][j];
			}
		}
	}
	vector<Mod>sums3(2e5), sums5(2e5);
	sums3[0] = 0;
	sums5[0] = 0;
	for (int i = 0; i < 1e5 + 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			sums3[i] += dp3[i][j];
		}
		for (int j = 0; j < 5; ++j) {
			sums5[i] += dp5[i][j];
		}
		if (i >= 3)sums3[i + 1] += sums3[i - 2];
		if (i >= 5)sums5[i + 1] += sums5[i - 4];
	}
	while (1) {
		string st; cin >> st;
		if (st == "#")break;
		else {
			vector<pair<int,int>>nums;
			char pre = ' ';
			int num = 0;
			for (int i = 0; i < st.size(); ++i) {
				char c(st[i]);
				if (!num || (pre == c)) {
					num++;
				}
				else {
					
					nums.emplace_back(pre,num);
					num = 1;
				}
				pre = c;
			}
			nums.emplace_back(pre,num);
			Mod ans = 1;
			for (auto n : nums) {
				if (n.first == '0' || n.first == '8') {
					ans *= sums3[n.second];
				}
				else {
					ans *= sums5[n.second];
				}
			}
			cout << ans << endl;
			
		}
	}

	
	return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 34592
final_rank: 17

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

ll dp[6][100001]; //dp[pos][buffered char][hidden or not]

const static ll MOD = 100000007;

int main(){
  string text;

  memset(dp,0,sizeof(dp));
  dp[3][0] = 0;
  dp[3][1] = 1;
  dp[3][2] = 2;

  dp[5][0] = 0;
  dp[5][1] = 1;
  dp[5][2] = 2;
  dp[5][3] = 4;
  dp[5][4] = 8;

  for(int text_i = 0; text_i < 100000; text_i++){
    dp[3][text_i + 3] += 1;
    for(int offset = 0; offset <= 2; offset++){
      dp[3][text_i + 3] += dp[3][text_i + offset];
      dp[3][text_i + 3] %= MOD;
    }

    dp[5][text_i + 5] += 1;
    for(int offset = 0; offset <= 4; offset++){
      dp[5][text_i + 5] += dp[5][text_i + offset];
      dp[5][text_i + 5] %= MOD;
    }
  }

  while(cin >> text){
    if(text == "#") break;

    ll res = 1;
    int length = 1;
    for(int text_i = 0; text_i + 1 < text.size(); text_i++){
      if(text[text_i] == text[text_i + 1]){
        length++;
      }
      else{
        if(text[text_i] == '8' || text[text_i] == '0'){
          res = (res * dp[3][length]) % MOD;
          res %= MOD;
        }
        else{
          res = (res * dp[5][length]) % MOD;
          res %= MOD;
        }
        length = 1;
      }
    }

    if(length > 0){
      if(text[text.size() - 1] == '8' || text[text.size() - 1] == '0'){
        res = (res * dp[3][length]) % MOD;
        res %= MOD;
      }
      else{
        res = (res * dp[5][length]) % MOD;
        res %= MOD;
      }
    }
    printf("%lld\n",res % MOD);
  }
}
accuracy: 1
time_ms: 100
memory_kb: 6024
final_rank: 12

code_snippet: #include<stdio.h>
#include<algorithm>
using namespace std;
long long mod=100000007;
char str[110000];
long long dp1[110000];
long long dp2[110000];
int main(){
	dp1[0]=dp2[0]=1;
	for(int i=0;i<101000;i++){
		for(int j=1;j<=5;j++)dp1[i+j]=(dp1[i+j]+dp1[i])%mod;
		for(int j=1;j<=3;j++)dp2[i+j]=(dp2[i+j]+dp2[i])%mod;
	}
	for(int i=4;i<101000;i++){
		if(i-5>0)dp1[i]=(dp1[i]+dp1[i-5])%mod;
		dp2[i]=(dp2[i]+dp2[i-3])%mod;
	}
	while(1){
		scanf("%s",str);
		if(str[0]=='#')return 0;
		long long ret=1;
		int val=0;
		int now=str[0]-'0';
		for(int i=0;str[i];i++){
			if(now!=str[i]-'0'){
				if(now==8||now==0)ret=ret*dp2[val]%mod;
				else ret=ret*dp1[val]%mod;
				now=str[i]-'0';
				val=1;
			}else val++;
		}
		if(now==8||now==0)ret=ret*dp2[val]%mod;
		else ret=ret*dp1[val]%mod;
		printf("%lld\n",ret);
	}
}
accuracy: 1
time_ms: 30
memory_kb: 2644
final_rank: 2

code_snippet: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define M 100000007
#define N 100000

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

char str[N+1];
int dp1[N+1], dp2[N+1];

int main(){
  dp1[1] = 1; dp1[2] = 2; dp1[3] = 4; dp1[4] = 8; dp1[5] = 16;
  REP(i, 6, N+1){
    dp1[i] = 1;
    REP(j, 1, 6) dp1[i] = (dp1[i] + dp1[i-j])%M;
  }

  dp2[1] = 1; dp2[2] = 2; dp2[3] = 4;
  REP(i, 4, N+2){
    dp2[i] = 1;
   REP(j, 1, 4) dp2[i] = (dp2[i] + dp2[i-j])%M;
  }

  while(scanf("%s", str) && str[0] != '#'){
    int c = 0;
    ll res = 1;
    char now = str[0];
    rep(i, strlen(str)){
      if(str[i] == now) c++;
      else{
	//	printf("%d\n", c);
	if(now == '1' || now == '2' || now == '3' || now == '4' || now == '5' || now == '6' || 
	   now == '7' || now == '9') res = (res * dp1[c])%M;
	else res = (res * dp2[c])%M;
	c = 1;
	now = str[i];
      }
    }
    //    printf("%d\n", c);
    if(now == '8' || now == '0') res = (res * dp2[c])%M;
    else res = (res * dp1[c])%M;

    printf("%lld\n", res);
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 2012
final_rank: 1

code_snippet: #include <iostream>
#include <string.h>
#include <string>

using namespace std;

#define MOD 100000007

void solve()
{
	int dp1[100001], dp2[100001];
	memset(dp1,0,sizeof(dp1));
	memset(dp2,0,sizeof(dp2));
	dp1[1] = 1; dp1[2] = 2; dp1[3] = 4; dp1[4] = 8; dp1[5] = 16;
	dp2[1] = 1; dp2[2] = 2; dp2[3] = 4;
	
	for(int i = 6; i < 100001; ++i)
	{
		dp1[i] = (1 + dp1[i - 1] % MOD + dp1[i - 2] % MOD + dp1[i - 3] % MOD + dp1[i - 4] % MOD + dp1[i - 5] % MOD) % MOD;
	}
	for(int i = 4; i < 100001; ++i)
	{
		dp2[i] = (1 + dp2[i - 1] % MOD + dp2[i - 2] % MOD + dp2[i - 3] % MOD) % MOD;
	}
	
	string str;
	while(cin >> str)
	{
		if(str == "#")
		{
			break;
		}
		long long ret = 1;
		char c;
		c = str[0];
		int num;
		num = 1;
		if(str.size() == 1)
		{
			cout << 1 << endl;
		}
		else
		{
			for(int i = 1; i < str.size(); ++i)
			{
				if(str[i] == c)
				{
					++num;
				}
				else
				{
					if(c == '0' || c == '8')
					{
						ret = ((long long)ret * dp2[num]) % MOD;
					}
					else
					{
						ret = ((long long)ret * dp1[num]) % MOD;
					}
					c = str[i];
					num = 1;
				}
			}
			if(c == '0' || c == '8')
			{
				ret = ((long long)ret * dp2[num]) % MOD;
			}
			else
			{
				ret = ((long long)ret * dp1[num]) % MOD;
			}
			cout << ret << endl;
		}
	}
}

int main(void)
{
	solve();
	return(0);
}
accuracy: 1
time_ms: 100
memory_kb: 2112
final_rank: 7

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define MOD (100000007LL)

using namespace std;

typedef unsigned long long ull;
typedef pair<int,int> ii;

string message;

typedef long long ll;
/*
ll my_pow(ll a,ll e)
{
  return !e?1:
    (e%2?(a*my_pow(a,e-1))%MOD:(my_pow(a*a,e/2))%MOD);
}

void calc(ull &v,char c,int pw)
{
  if(pw == 0)return;
  if(c == '8' || c == '0')
    {
      if(pw == 3)v = ((v * 2LL)%MOD - 1 ) % MOD;
      else if(pw > 3)v = ((v * 2LL)%MOD - my_pow(2LL,(pw-4))) % MOD;
      else      v = (v * 2LL) % MOD;
    }
  else
    {
      if(pw > 5)v = ((v * 2LL)%MOD - my_pow(2LL,pw-6) ) % MOD;
      else      v = (v * 2LL) % MOD;
    }
}
void compute()
{
  ull ans = 1;
  ull value = 1;
  char cur = message[0];
  int seq = -1;
  rep(i,message.size())
    {
      seq++;
      calc(value,message[i],seq);
      if((i+1 < message.size() && cur != message[i+1]) || i == message.size()-1)
	{
	  ans = ( ans * value ) % MOD;
	  value = 1;
	  seq = -1; 
	  if(i != message.size()-1)cur = message[i+1];
	  continue;
	}
    }
  cout << ans << endl;
}
*/

void compute()
{
  vector<ii> vec;
  char cur = message[0];
  int cnt = 0,max_length = 0;
  rep(i,message.size())
    {
      cnt++;
      if((i+1<message.size() && cur != message[i+1]) || i == message.size()-1)
	{
	  vec.push_back(ii(cur-'0',cnt));
	  max_length = max(max_length,cnt);
	  cnt = 0;
	  cur = message[i+1];
	}
    }

  max_length++;
  ull dp[2][max_length];//dp[0] : 3, dp[1] : 5
  rep(i,3)dp[0][i] = (ull)pow(2.0,i);
  rep(i,6)dp[1][i] = (ull)pow(2.0,i);

  REP(i,3,max_length)dp[0][i] = (((dp[0][i-1] + dp[0][i-2]) % MOD + dp[0][i-3]) % MOD + 1ULL) % MOD;
  REP(i,6,max_length)dp[1][i] = (((((dp[1][i-1] + dp[1][i-2])%MOD + dp[1][i-3])%MOD + dp[1][i-4])%MOD + dp[1][i-5])%MOD + 1ULL) % MOD;

  ull ans = 1;
  rep(i,vec.size())
    {
      int type = ((vec[i].first == 8 || vec[i].first == 0)?0:1);
      ans = ( ans * dp[type][vec[i].second-1] ) % MOD;
    }

  cout << ans << endl;

}

int main()
{
  while(cin >> message,message != "#")
    {
      compute();

    }
  return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 2880
final_rank: 14

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define MOD (100000007LL)

using namespace std;

typedef unsigned long long ull;
typedef pair<int,int> ii;

string message;

typedef long long ll;
/*
ll my_pow(ll a,ll e)
{
  return !e?1:
    (e%2?(a*my_pow(a,e-1))%MOD:(my_pow(a*a,e/2))%MOD);
}

void calc(ull &v,char c,int pw)
{
  if(pw == 0)return;
  if(c == '8' || c == '0')
    {
      if(pw == 3)v = ((v * 2LL)%MOD - 1 ) % MOD;
      else if(pw > 3)v = ((v * 2LL)%MOD - my_pow(2LL,(pw-4))) % MOD;
      else      v = (v * 2LL) % MOD;
    }
  else
    {
      if(pw > 5)v = ((v * 2LL)%MOD - my_pow(2LL,pw-6) ) % MOD;
      else      v = (v * 2LL) % MOD;
    }
}
void compute()
{
  ull ans = 1;
  ull value = 1;
  char cur = message[0];
  int seq = -1;
  rep(i,message.size())
    {
      seq++;
      calc(value,message[i],seq);
      if((i+1 < message.size() && cur != message[i+1]) || i == message.size()-1)
	{
	  ans = ( ans * value ) % MOD;
	  value = 1;
	  seq = -1; 
	  if(i != message.size()-1)cur = message[i+1];
	  continue;
	}
    }
  cout << ans << endl;
}
*/

void compute()
{
  vector<ii> vec;
  char cur = message[0];
  int cnt = 0,max_length = 0;
  rep(i,message.size())
    {
      cnt++;
      if((i+1<message.size() && cur != message[i+1]) || i == message.size()-1)
	{
	  vec.push_back(ii(cur-'0',cnt));
	  max_length = max(max_length,cnt);
	  cnt = 0;
	  cur = message[i+1];
	}
    }

  max_length++;
  ull dp[2][max_length];//dp[0] : 3, dp[1] : 5
  rep(i,3)dp[0][i] = (ull)pow(2.0,i);
  rep(i,6)dp[1][i] = (ull)pow(2.0,i);

  REP(i,3,max_length)dp[0][i] = dp[0][i-1] + dp[0][i-2] + dp[0][i-3] + 1;
  REP(i,6,max_length)dp[1][i] = dp[1][i-1] + dp[1][i-2] + dp[1][i-3] + dp[1][i-4] + dp[1][i-5] + 1;

  ull ans = 1;
  rep(i,vec.size())
    {
      int type = ((vec[i].first == 8 || vec[i].first == 0)?0:1);
      ans = ( ans * dp[type][vec[i].second-1] ) % MOD;
    }

  cout << ans << endl;

}

int main()
{
  while(cin >> message,message != "#")
    {
      compute();

    }
  return 0;
}
accuracy: 0.3333333333333333
time_ms: 100
memory_kb: 2876
final_rank: 19

code_snippet: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 100000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int MAX = 100000;
void fill_dp(int dp[MAX + 1], int len){
  int dp_[MAX + 1][6] = {};
  dp_[1][0] = 1;
  for(int i = 1; i < MAX; i++){
    for(int j = 0; j < len; j++){
      dp_[i + 1][0] = (dp_[i + 1][0] + dp_[i][j]) % MOD;
      dp_[i + 1][j + 1] = (dp_[i + 1][j + 1] + dp_[i][j]) % MOD;
    }
  }
  for(int i = 1; i <= MAX; i++){
    for(int j = 0; j < len; j++){
      dp[i] = (dp[i] + dp_[i][j]) % MOD;
    }
  }
  for(int i = len; i <= MAX; i++){
    dp[i] = (dp[i] + dp[i - len]) % MOD;
  }
}

int main(){
  int dp3[MAX + 1] = {};
  int dp5[MAX + 1] = {};
  fill_dp(dp3, 3);
  fill_dp(dp5, 5);
  string s;
  while(cin >> s && s != "#"){
    int N = s.size();
    s += "#";
    int cur = 1;
    int ans = 1;
    REP(i, N){
      if(s[i] != s[i + 1]){
        if(s[i] == '8' || s[i] == '0'){
          ans = ((ll)ans * dp3[cur]) % MOD;
        }else{
          ans = ((ll)ans * dp5[cur]) % MOD;
        }
        cur = 1;
      }else{
        cur ++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 4452
final_rank: 13

code_snippet: #include<stdio.h>
#include<iostream>
#include<string.h>

long long int memo5[100001][6];
long long int memo3[100001][4];
long long int perm5[100001],perm3[100001];
long long int mod=100000007;


int main(){
	memset(memo5,0,sizeof(memo5));
	memset(memo3,0,sizeof(memo3));
	memo5[1][1]=1;
	memo3[1][1]=1;
	perm5[1]=perm3[1]=1;
	for(int n=2;n<=100000;n++){
		int i=n-1;
		memo5[n][1]=(memo5[i][1]+memo5[i][2]+memo5[i][3]+memo5[i][4]+memo5[i][5]+(n%5==1))%mod;
		memo5[n][2]=memo5[i][1];
		memo5[n][3]=memo5[i][2];
		memo5[n][4]=memo5[i][3];
		memo5[n][5]=memo5[i][4];
		perm5[n]=(memo5[n][1]+memo5[n][2]+memo5[n][3]+memo5[n][4]+memo5[n][5])%mod;
		
		memo3[n][1]=(memo3[i][1]+memo3[i][2]+memo3[i][3]+(n%3==1))%mod;
		memo3[n][2]=memo3[i][1];
		memo3[n][3]=memo3[i][2];
		perm3[n]=(memo3[n][1]+memo3[n][2]+memo3[n][3])%mod;
	}
	
	char text[100001];
	while(1){
		scanf("%s",text);
		if(text[0]=='#')break;
		int count=0;
		char c=text[0];
		long long int ans=1;
		for(int i=0;i<strlen(text)+1;i++){
			if(text[i]==c){
				count++;
			}else{
				if(c=='8'||c=='0')ans=(ans*perm3[count])%mod;
				else ans=(ans*perm5[count])%mod;
				c=text[i];
				count=1;
			}
			
		}
		std::cout<<ans<<"\n";
	}
}
accuracy: 1
time_ms: 10
memory_kb: 10632
final_rank: 6

code_snippet: #include<stdio.h>
#include<iostream>
#include<string.h>

long long int memo5[100001][6];
long long int memo3[100001][4];
long long int perm5[100001],perm3[100001];
long long int mod=100000007;


int main(){
	memset(memo5,0,sizeof(memo5));
	memset(memo3,0,sizeof(memo3));
	memo5[1][1]=1;
	memo3[1][1]=1;
	perm5[1]=perm3[1]=1;
	for(int n=2;n<=100000;n++){
		int i=n-1;
		memo5[n][1]=(memo5[i][1]+memo5[i][2]+memo5[i][3]+memo5[i][4]+memo5[i][5]+(n%5==1))%mod;
		memo5[n][2]=memo5[i][1];
		memo5[n][3]=memo5[i][2];
		memo5[n][4]=memo5[i][3];
		memo5[n][5]=memo5[i][4];
		perm5[n]=(memo5[n][1]+memo5[n][2]+memo5[n][3]+memo5[n][4]+memo5[n][5])%mod;
		
		memo3[n][1]=memo3[i][1]+memo3[i][2]+memo3[i][3]+(n%3==1);
		memo3[n][2]=memo3[i][1];
		memo3[n][3]=memo3[i][2];
		perm3[n]=(memo3[n][1]+memo3[n][2]+memo3[n][3])%mod;
	}
	
	char text[100001];
	while(1){
		scanf("%s",text);
		if(text[0]=='#')break;
		int count=0;
		char c=text[0];
		long long int ans=1;
		for(int i=0;i<strlen(text)+1;i++){
			if(text[i]==c){
				count++;
			}else{
				if(c=='8'||c=='0')ans=(ans*perm3[count])%mod;
				else ans=(ans*perm5[count])%mod;
				c=text[i];
				count=1;
			}
			
		}
		std::cout<<ans<<"\n";
	}
}
accuracy: 0.3333333333333333
time_ms: 10
memory_kb: 10632
final_rank: 18

code_snippet: //34
#include<iostream>

using namespace std;

const int M=100000007;

int main(){
  int nnl[2][100001]={{}};
  int nlp[2][100001]={{}};
  for(int i=0;i<2;i++){
    int s=3+i*2;
    nnl[i][0]=nlp[i][0]=1;
    for(int j=1;j<=100000;j++){
      for(int k=1;k<=s;k++){
	if(j-k<0)break;
	nnl[i][j]=(nnl[i][j]+nnl[i][j-k])%M;
      }
      nlp[i][j]=(nnl[i][j]+((j-s<1)?0:nlp[i][j-s]))%M;
    }
  }
  for(char c;cin>>c,c!='#';){
    char p=0;
    int cc=0;
    long long a=1;
    for(;;cin.get(c)){
      if(c==p){
	cc++;
      }else{
	a=(a*nlp[p!='8'&&p!='0'][cc])%M;
	p=c;
	cc=1;
      }
      if(c=='\n')break;
    }
    cout<<a<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 2712
final_rank: 10