Problem:
Problem F:
UTF-8
UTF-8はマルチバイト文字を符号化する手法の一つである。
文字は計算機上ではバイト列として扱われる。英語だけであればラテンアルファベットおよび数字、記号を合わせても 1byteで表現できるが、残念ながら世界中で利用されている文字を1byteで表現することはできないため、複数のバイトを用いて文字を表す必要がある。
ここで例えば"あ"という文字に12354(0x3042)という2バイト列を割り当てたとき、そのままバイト列を並べると0x30,0x42と2文字なのか0x3042で1文字なのかが区別がつかない。
このため、マルチバイト文字符号化方式のUTF-8では始めの1バイト目で続くバイト列の長さが分かるようにすることにより、この問題を克服している。具体的なビットパターンは以下のようになる。
バイト長
ビットパターン
1
0xxxxxxx
2
110yyyyx 10xxxxxx
3
1110yyyy 10yxxxxx 10xxxxxx
4
11110yyy 10yyxxxx 10xxxxxx 10xxxxxx
ここでxは0/1の任意のビットとする。またyも0/1の任意のビットとなるがどれか一つは1である必要がある。また全ての文字は1,2,3,4バイト文字のいずれかであるとする。
ここでyのビットが少なくとも一つは1であるという制約は以下のような理由による。 例えば'/'(0x2f)をバイト列にエンコードする際に0x2fと1バイトで符号化するないしは0xc0 0xafと2バイトで符号化する方法の二つがあるが、このような曖昧性を許すとセキュリティ上の脅威のもととなる可能性があるためである。
以上の話を聞いたあなたはUTF-8がどの程度の自由度があるのかが気になった。具体的には与えられたバイト列の一部のビットが不明な時にUTF-8として可能なバイト列の組み合わせがどの程度あるかということである。
このとき可能なバイト列の組み合わせの個数を求め、1,000,000で割った余りを出力せよ。
Input
N
b
1
b
2
...
b
N
Nはバイト列の個数, b
i
はバイト列である。
1 ≤ N ≤ 1000 を満たしている。 b
i
は記号{0/1/x}が8個並んでいる。xはビットが不明であることを示している。
Output
可能なバイト列の組み合わせの個数を1,000,000で割った余りを出力せよ。
Notes on Test Cases
上記入力形式で複数のデータセットが与えられます。各データセットに対して上記出力形式で出力を行うプログラムを作成して下さい。
N が 0 のとき入力の終わりを示します。
Sample Input
1
xxxxxxxx
3
11100000
10x00000
10111111
3
11100000
10000000
10111111
4
xxxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxx
0
Output for Sample Input
128
1
0
778240

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define F first
#define S second

int calc1(string s){
	if(s[0]=='1')return 0;
	int x=1;
	r(i,7){
		if(s[i+1]=='x')x*=2;
	}
	return x;
}

int calc2(string s){
	int y=0;
	string p="110yyyyx10xxxxxx";
	r(i,16){
		if(p[i]=='y'&&(s[i]=='1'||s[i]=='x')) y=1;
		if(isdigit(p[i])&&isdigit(s[i])&&p[i]!=s[i])return 0;
	}
	if( !y )return 0;
	int dp[33][2]={};
	dp[0][0]=1;
	r(i,16){
		r(j,2){
			if(isdigit(p[i])){
				dp[i+1][j] += dp[i][j];
			}
			if(p[i]=='x'){
				int x=(isdigit(s[i])?1:2);
				dp[i+1][j] += dp[i][j]*x;
			}
			if(p[i]=='y'){
				if(s[i]=='1'){
					dp[i+1][1] += dp[i][j];
				}
				if(s[i]=='0'){
					dp[i+1][j] += dp[i][j];
				}
				if(s[i]=='x'){
					dp[i+1][1] += dp[i][j];
					dp[i+1][j] += dp[i][j];
				}
			}
			dp[i+1][j] %= 1000000;
		}
	}
	return dp[16][1];
}

int calc3(string s){
	int y=0;
	string p="1110yyyy10yxxxxx10xxxxxx";
	r(i,24){
		if(p[i]=='y'&&(s[i]=='1'||s[i]=='x')) y=1;
		//cout<<i<<endl;
		if(isdigit(p[i])&&isdigit(s[i])&&p[i]!=s[i])return 0;
	}
	//cout<<y<<endl;
	if( !y )return 0;
	int dp[33][2]={};
	dp[0][0]=1;
	r(i,24){
		r(j,2){
			if(isdigit(p[i])){
				dp[i+1][j] += dp[i][j];
			}
			if(p[i]=='x'){
				int x=(isdigit(s[i])?1:2);
				dp[i+1][j] += dp[i][j]*x;
			}
			if(p[i]=='y'){
				if(s[i]=='1'){
					dp[i+1][1] += dp[i][j];
				}
				if(s[i]=='0'){
					dp[i+1][j] += dp[i][j];
				}
				if(s[i]=='x'){
					dp[i+1][1] += dp[i][j];
					dp[i+1][j] += dp[i][j];
				}
			}
			dp[i+1][j] %= 1000000;
		}
	}
	return dp[24][1];
}

int calc4(string s){
	int y=0;
	string p="11110yyy10yyxxxx10xxxxxx10xxxxxx";
	r(i,32){
		if(p[i]=='y'&&(s[i]=='1'||s[i]=='x')) y=1;
		if(isdigit(p[i])&&isdigit(s[i])&&p[i]!=s[i])return 0;
	}
	if( !y )return 0;
	int dp[33][2]={};
	dp[0][0]=1;
	r(i,32){
		r(j,2){
			if(isdigit(p[i])){
				dp[i+1][j] += dp[i][j];
			}
			if(p[i]=='x'){
				int x=(isdigit(s[i])?1:2);
				dp[i+1][j] += dp[i][j]*x;
			}
			if(p[i]=='y'){
				if(s[i]=='1'){
					dp[i+1][1] += dp[i][j];
				}
				if(s[i]=='0'){
					dp[i+1][j] += dp[i][j];
				}
				if(s[i]=='x'){
					dp[i+1][1] += dp[i][j];
					dp[i+1][j] += dp[i][j];
				}
			}
			dp[i+1][j] %= 1000000;
		}
	}
	return dp[32][1];
}

int n;
string s[1111];
int dp[1111];

signed main(){
	while(cin>>n,n){
		r(i,n)cin>>s[i];
		memset(dp,0,sizeof(dp));
		dp[0] = 1;
		for(int i=0;i<n;i++){
			if( i+1 <= n ){
				int x = calc1(s[i]);
				dp[i+1] += dp[i]*x;
				dp[i+1] %= 1000000;
			}
			if( i+2 <= n ){
				int x = calc2(s[i]+s[i+1]);
				dp[i+2] += dp[i]*x;
				dp[i+2] %= 1000000;
			}
			if( i+3 <= n ){
				int x = calc3(s[i]+s[i+1]+s[i+2]);
				//cout<<x<<endl;
				dp[i+3] += dp[i]*x;
				dp[i+3] %= 1000000;
			}
			if( i+4 <= n ){
				int x = calc4(s[i]+s[i+1]+s[i+2]+s[i+3]);
				dp[i+4] += dp[i]*x;
				dp[i+4] %= 1000000;
			}
		}
		cout<<dp[n]<<endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3144
final_rank: 13

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

const Int MOD = 1e6;
const Int MAX = 1024;
Int n;
Int dp[5][4][2][MAX];
string ss[MAX];

Int check(Int v,string s){
  for(Int i=0;i<8;i++){
    if((s[i]!='x')&&((s[i]-'0')!=(v&1))) return 0;
    v>>=1;
  }
  return 1;
}

Int rf[5][4],mc[5][4],ms[5][4];
Int match(Int a,Int b,Int l){
  return (a>>(8-l))==(b>>(8-l));
}

Int dfs(Int len,Int i,Int y,Int p){
  if(p==n) return (len==1&&i==0&&y==1);
  Int &res=dp[len][i][y][p];
  if(~res) return res;
  res=0;

  for(Int bit=0;bit<256;bit++){
    if(!check(bit,ss[p])) continue;
    if(!match(bit,rf[len][i],mc[len][i])) continue;
    if(i+1==len){
      if(y){
        for(Int nxt=1;nxt<=4;nxt++){
          Int ni=0;
          Int ny=(nxt==1);
          Int np=p+1;
          res+=dfs(nxt,ni,ny,np);
          res%=MOD;
        }
      }
    }else{
      Int ni=i+1;
      Int ny=y||(ms[len][i]&bit);
      Int np=p+1;
      res+=dfs(len,ni,ny,np);
      res%=MOD;
    }
  }
  return res;
}

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

  rf[1][0]=0b00000000;

  rf[2][0]=0b11000000;
  rf[2][1]=0b10000000;

  rf[3][0]=0b11100000;
  rf[3][1]=0b10000000;
  rf[3][2]=0b10000000;

  rf[4][0]=0b11110000;
  rf[4][1]=0b10000000;
  rf[4][2]=0b10000000;
  rf[4][3]=0b10000000;

  mc[1][0]=1;

  mc[2][0]=3;
  mc[2][1]=2;

  mc[3][0]=4;
  mc[3][1]=2;
  mc[3][2]=2;

  mc[4][0]=5;
  mc[4][1]=2;
  mc[4][2]=2;
  mc[4][3]=2;

  ms[1][0]=0b00000000;

  ms[2][0]=0b00011110;
  ms[2][1]=0b00000000;

  ms[3][0]=0b00001111;
  ms[3][1]=0b00100000;
  ms[3][2]=0b00000000;

  ms[4][0]=0b00000111;
  ms[4][1]=0b00110000;
  ms[4][2]=0b00000000;
  ms[4][3]=0b00000000;

  while(cin>>n,n){
    memset(dp,-1,sizeof(dp));
    for(Int i=0;i<n;i++){
      cin>>ss[i];
      reverse(ss[i].begin(),ss[i].end());
    }
    Int ans=0;
    for(Int len=1;len<=4;len++){
      ans+=dfs(len,0,(len==1),0);
      ans%=MOD;
    }
    cout<<ans<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 1030
memory_kb: 3632
final_rank: 20

code_snippet: #include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e6)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
#define PI (acos(-1))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}
LL exp(int a, int b){
    LL res = 1;
    LL sum = a;
    while(b){
        if(b&1)res = (res * sum) % MOD;
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}
int N;
vector<string> bytes;
vector<int> dp;
LL count(string a, string b){
    bool check=false;
    for(auto i:b)if(i=='y'){
        check=true;
        break;
    }
    if(check){
        bool flag = false;
        int xc = 0;
        int yc = 0;
        REP(i, a.size()){
            if(b[i]=='1'){
                if(a[i]=='0')return 0;
            }
            if(b[i]=='0'){
                if(a[i]=='1')return 0;
            }
            if(b[i]=='x'){
                if(a[i]=='x')++xc;
            }
            if(b[i]=='y'){
                if(a[i]=='1')flag=true;
                if(a[i]=='x')++yc;
            }
        }
        if(flag){
            return exp(2, xc + yc);
        }else{
            if(yc==0)return 0;
            return (exp(2, yc) - 1) * exp(2, xc);
        }
    }else{
        int count = 0;
        REP(i, a.size()){
            if(b[i]=='x'){
                if(a[i]=='x')++count;
            }else{
                if((a[i]!='x') and (a[i] != b[i]))return 0;
            }
        }
        return exp(2, count);
    }
} 

LL func(int place){
    if(place == N){
        return 1;
    }
    if(dp[place]>=0)return dp[place];
    LL res = (LL)func(place+1) * count(bytes[place], "0xxxxxxx");
    res %= MOD;
    if(place+2 <= N){
        res += (LL)func(place+2) * count(bytes[place]+bytes[place+1], "110yyyyx10xxxxxx");
        res %= MOD;
    }
    if(place+3 <= N){
        string str="";
        for(int i=0;i<3;++i)str += bytes[place+i];
        res += (LL)func(place+3) * count(str, "1110yyyy10yxxxxx10xxxxxx");
        res %= MOD;
    }
    if(place+4 <= N){
        string str="";
        for(int i=0;i<4;++i)str += bytes[place+i];
        res += (LL)func(place+4) * count(str, "11110yyy10yyxxxx10xxxxxx10xxxxxx");
        res %= MOD;
    }
    return dp[place] = res;
}

int main(){
    while(cin >> N && N){
        bytes = vector<string>(N);
        for(auto &i:bytes)cin >> i;
        dp = vector<int>(N, -1);
        cout << func(0) << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3288
final_rank: 14

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

const Int MOD = 1e6;
const Int MAX = 1024;
Int n;
Int dp[5][4][2][MAX];
string ss[MAX];

Int check(Int v,string s){
  for(Int i=0;i<8;i++){
    if((s[i]!='x')&&((s[i]-'0')!=(v&1))) return 0;
    v>>=1;
  }
  return 1;
}

Int rf[5][4],mc[5][4],ms[5][4];
Int match(Int a,Int b,Int l){
  return (a>>(8-l))==(b>>(8-l));
}

Int dfs(Int len,Int i,Int y,Int p){
  if(p==n) return (len==1&&i==0&&y==1);
  Int &res=dp[len][i][y][p];
  if(~res) return res;
  res=0;
  
  for(Int bit=0;bit<256;bit++){
    if(!check(bit,ss[p])) continue;
    if(!match(bit,rf[len][i],mc[len][i])) continue;
    if(i+1==len){
      if(y){
        for(Int nxt=1;nxt<=4;nxt++){
          Int ni=0;
          Int ny=(nxt==1);
          Int np=p+1;
          res+=dfs(nxt,ni,ny,np);
          res%=MOD;
        }
      }
    }else{
      Int ni=i+1;
      Int ny=y||(ms[len][i]&bit);
      Int np=p+1;
      res+=dfs(len,ni,ny,np);
      res%=MOD;
    }
  }
  return res;
}

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

  rf[1][0]=0b00000000;
  
  rf[2][0]=0b11000000;
  rf[2][1]=0b10000000;

  rf[3][0]=0b11100000;
  rf[3][1]=0b10000000;
  rf[3][2]=0b10000000;

  rf[4][0]=0b11110000;
  rf[4][1]=0b10000000;
  rf[4][2]=0b10000000;
  rf[4][3]=0b10000000;
  
  mc[1][0]=1;
  
  mc[2][0]=3;
  mc[2][1]=2;

  mc[3][0]=4;
  mc[3][1]=2;
  mc[3][2]=2;

  mc[4][0]=5;
  mc[4][1]=2;
  mc[4][2]=2;
  mc[4][3]=2;
  
  ms[1][0]=0b00000000;
  
  ms[2][0]=0b00011110;
  ms[2][1]=0b00000000;

  ms[3][0]=0b00001111;
  ms[3][1]=0b00100000;
  ms[3][2]=0b00000000;

  ms[4][0]=0b00000111;
  ms[4][1]=0b00110000;
  ms[4][2]=0b00000000;
  ms[4][3]=0b00000000;
  
  while(cin>>n,n){
    memset(dp,-1,sizeof(dp));
    for(Int i=0;i<n;i++){
      cin>>ss[i];
      reverse(ss[i].begin(),ss[i].end());
    }
    Int ans=0;
    for(Int len=1;len<=4;len++){
      ans+=dfs(len,0,(len==1),0);
      ans%=MOD;
    }
    cout<<ans<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 1030
memory_kb: 3588
final_rank: 19

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;



const int mod = 1000000;
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 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) {
	assert(b.num != 0);
	return Mod(a) * inv(b);
}
Mod operator/=(Mod &a, const Mod b) {
	assert(b.num != 0);
	return a = a * inv(b);
}

#define MAX_MOD_N 1024000

Mod fact[MAX_MOD_N], factinv[MAX_MOD_N];
void init() {
	fact[0] = Mod(1); factinv[0] = 1;
	for (int i = 0; i < MAX_MOD_N - 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() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		Mod dp[1001][7][2];
		for (int i = 0; i < 1001; ++i) {
			for (int j = 0; j < 7; ++j) {
				for (int k = 0; k < 2; ++k) {
					dp[i][j][k] = 0;
				}
			}
		}
		dp[0][0][0] = 1;
		for (int i = 0; i < N; ++i) {
			string st; cin >> st; 
			for (int b = 0; b < 256; ++b) {
				bitset<8>bs(b);
				bool ok = true;
				for (int n = 0; n < 8; ++n) {
					if (st[n] == '0'&&bs[7-n] == 1)ok = false;
					if (st[n] == '1'&&bs[7-n] == 0)ok = false;
				}
				if (!ok)continue;
				for (int j = 0; j < 7; ++j) {
					for (int k = 0; k< 2; ++k) {
						bool valid = true;
						switch (j)
						{
						case 0:
							if (!((b ^ 0b00000000) & 0b10000000)) {
								dp[i + 1][0][0] += dp[i][j][k];
							}
							if (!((b ^ 0b11000000) & 0b11100000)) {
								if (b & 0b00011110) {
									dp[i + 1][1][1] += dp[i][j][k];
								}
							}
							if (!((b ^ 0b11100000) & 0b11110000)) {
								if (b & 0b00001111) {
									dp[i + 1][2][1] += dp[i][j][k];
								}
								else {
									dp[i + 1][2][0] += dp[i][j][k];
								}
							}
							if (!((b ^ 0b11110000) & 0b11111000)) {
								if (b & 0b00000111) {
									dp[i + 1][4][1] += dp[i][j][k];
								}
								else {
									dp[i + 1][4][0] += dp[i][j][k];
								}
							}
							break;
						case 1:
							if (!((b ^ 0b10000000) & 0b11000000)) {
								dp[i + 1][0][0] += dp[i][j][k];
							}
							break;
						case 2:
							if (!((b ^ 0b10000000) & 0b11000000)) {
								if (k || (b & 0b00100000)) {
									dp[i + 1][3][1] += dp[i][j][k];
								}
							}
							break;
						case 3:
							if (!((b ^ 0b10000000) & 0b11000000)) {
								dp[i + 1][0][0] += dp[i][j][k];
							}
							break;
						case 4:
							if (!((b ^ 0b10000000) & 0b11000000)) {
								if (k || (b & 0b00110000)) {
									dp[i + 1][5][1] += dp[i][j][k];
								}
							}
							break;
						case 5:
							if (!((b ^ 0b10000000) & 0b11000000)) {
								dp[i + 1][6][1] += dp[i][j][k];
							}
							break;
						case 6:
							if (!((b ^ 0b10000000) & 0b11000000)) {
								dp[i + 1][0][0] += dp[i][j][k];
							}
							break;
						}
					}
				}
			}
		}
		Mod ans = dp[N][0][0];
		cout << ans << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 11212
final_rank: 18

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>

enum { PATTERN_1, PATTERN_2, PATTERN_3, PATTERN_4 };
typedef size_t variation_t;


bool can_match(
    const std::string &str, size_t offset, size_t size,
    const std::string &query)
{
    for (int i = 0; i < size; ++i)
        if (str.at(offset + i) != 'x' and
            str.at(offset + i) != query.at(i))
            return false;

    return true;
}


bool all_zero(const std::string &byte, size_t offset, size_t size)
{
    for (int i = offset; i < offset + size; ++i)
        if (byte.at(i) != '0')
            return false;
    return true;
}


variation_t variation(const std::string &byte, size_t offset, size_t size)
{
    size_t count(0);
    
    for (size_t i = offset; i < offset + size; ++i)
        if (byte.at(i) == 'x')
            ++count;
    
    return (variation_t)(std::pow(2.0, (double)count)) % 1000000;
}


bool can_be_pattern_of(
    int pattern, std::vector<std::string> &input, size_t offset)
{
#define getbyte(i) input.at(offset + i)
    switch (pattern)
    {
    case PATTERN_1:
        if (input.size() - offset >= 1)
        {
            char c = getbyte(0).at(0);
            return (c == '0') or (c == 'x');
        }
        
    case PATTERN_2:
        if (input.size() - offset >= 2)
        {
            return
                can_match(getbyte(0), 0, 3, "110")
                and can_match(getbyte(1), 0, 2, "10")
                and not all_zero(getbyte(0), 3, 4);
        }
        break;
        
    case PATTERN_3:
        if (input.size() - offset >= 3)
        {
            return
                can_match(getbyte(0), 0, 4, "1110")
                and can_match(getbyte(1), 0, 2, "10")
                and can_match(getbyte(2), 0, 2, "10")
                and (not all_zero(getbyte(0), 4, 4) or
                     not all_zero(getbyte(1), 2, 1));
        }
        
    case PATTERN_4:
        if (input.size() - offset >= 4)
        {
            return
                can_match(getbyte(0), 0, 5, "11110")
                and can_match(getbyte(1), 0, 2, "10")
                and can_match(getbyte(2), 0, 2, "10")
                and can_match(getbyte(3), 0, 2, "10")
                and (not all_zero(getbyte(0), 5, 3) or
                     not all_zero(getbyte(1), 2, 2));
        }
    }
    
    return false;
#undef getbyte
}


variation_t count(
    std::vector<std::string> &input, size_t offset,
    std::map<size_t, variation_t> *memo)
{
    if (offset >= input.size()) return 1;

    std::map<size_t, variation_t>::iterator found = memo->find(offset);
    if (found != memo->end())
        return found->second;
    
#define getbyte(i) input.at(offset + i)
    variation_t out(0);

    if (can_be_pattern_of(PATTERN_1, input, offset))
    {
        variation_t var_x = variation(getbyte(0), 1, 7);
        out += var_x * count(input, offset + 1, memo);
        out %= 1000000;
    }
    
    if (can_be_pattern_of(PATTERN_2, input, offset))
    {
        variation_t var_x =
            variation(getbyte(0), 7, 1) *
            variation(getbyte(1), 2, 6);

        variation_t var_y = variation(getbyte(0), 3, 4);
        if (getbyte(0).substr(3, 4).find('1') == std::string::npos)
            --var_y;
                
        out += var_x * var_y * count(input, offset + 2, memo);
        out %= 1000000;
    }
    
    if (can_be_pattern_of(PATTERN_3, input, offset))
    {
        variation_t var_x =
            variation(getbyte(1), 3, 5) *
            variation(getbyte(2), 2, 6);

        variation_t var_y =
            variation(getbyte(0), 4, 4) *
            variation(getbyte(1), 2, 1);
        if (getbyte(0).substr(4, 4).find('1') == std::string::npos
            and getbyte(1).at(2) != '1')
            --var_y;
                
        out += var_x * var_y * count(input, offset + 3, memo);
        out %= 1000000;
    }
    
    if (can_be_pattern_of(PATTERN_4, input, offset))
    {
        variation_t var_x =
            variation(getbyte(1), 4, 4) *
            variation(getbyte(2), 2, 6) *
            variation(getbyte(3), 2, 6);

        variation_t var_y =
            variation(getbyte(0), 5, 3) *
            variation(getbyte(1), 2, 2);
        if (getbyte(0).substr(5, 3).find('1') == std::string::npos
            and getbyte(1).substr(2, 2).find('1') == std::string::npos)
            --var_y;
                
        out += var_x * var_y * count(input, offset + 4, memo);
        out %= 1000000;
    }

    (*memo)[offset] = out; // MEMORIZE
        
    return out;
#undef getbyte
}


int main()
{
    while (true)
    {
        int n;
        std::cin >> n;

        if (n == 0) break;

        std::vector<std::string> input;
        for (int i = 0; i < n; ++i)
        {
            input.push_back(std::string());
            std::cin >> input.back();
        }

        std::map<size_t, variation_t> memo;
        std::cout << count(input, 0, &memo) << std::endl;
    }
    
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1576
final_rank: 10

code_snippet: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const long long MOD = 1000000LL;

/* typedef */

typedef long long ll;
typedef unsigned char uchar;

/* global variables */

int n;
uchar bytes[MAX_N], masks[MAX_N];
ll dp[MAX_N + 1];
int bcs[256];

/* subroutines */

void str2bits(string str, uchar& byte, uchar& mask) {
  byte = mask = 0;
  for (int i = 7, b = 1; i >= 0; i--, b <<= 1) {
    if (str[i] == 'x') mask |= b;
    else if (str[i] == '1') byte |= b;
  }
}

int bcount(uchar bits) {
  int count = 0;
  for (; bits > 0; bits >>= 1)
    if (bits & 1) count++;
  return count;
}

ll utf8_1(int i) {
  if (i > n - 1 ||
      (bytes[i] & 0x80) != 0) return 0LL;
  uchar m0 = masks[i] & 0x7f;
  return (1LL << bcs[m0]);
}

ll utf8_2(int i) {
  if (i > n - 2 ||
      (bytes[i] & 0xe0) != (0xc0 & ~masks[i]) ||
      (bytes[i + 1] & 0xc0) != (0x80 & ~masks[i + 1])) return 0LL;

  int ybc = bcs[bytes[i] & 0x1e];
  int ymc = bcs[masks[i] & 0x1e];
  if (ybc == 0 && ymc == 0) return 0LL;

  ll yn = 1LL << ymc;
  if (ybc == 0) yn--;
  
  uchar m0 = masks[i] & 0x01;
  uchar m1 = masks[i + 1] & 0x3f;
  return yn * (1LL << (bcs[m0] + bcs[m1]));
}

ll utf8_3(int i) {
  if (i > n - 3 ||
      (bytes[i] & 0xf0) != (0xe0 & ~masks[i]) ||
      (bytes[i + 1] & 0xc0) != (0x80 & ~masks[i + 1]) ||
      (bytes[i + 2] & 0xc0) != (0x80 & ~masks[i + 2])) return 0LL;

  int ybc = bcs[bytes[i] & 0x0f] + bcs[bytes[i + 1] & 0x20];
  int ymc = bcs[masks[i] & 0x0f] + bcs[masks[i + 1] & 0x20];
  if (ybc == 0 && ymc == 0) return 0LL;

  ll yn = 1LL << ymc;
  if (ybc == 0) yn--;
  
  uchar m1 = masks[i + 1] & 0x1f;
  uchar m2 = masks[i + 2] & 0x3f;
  return yn * (1LL << (bcs[m1] + bcs[m2]));
}

ll utf8_4(int i) {
  if (i > n - 4 ||
      (bytes[i] & 0xf8) != (0xf0 & ~masks[i]) ||
      (bytes[i + 1] & 0xc0) != (0x80 & ~masks[i + 1]) ||
      (bytes[i + 2] & 0xc0) != (0x80 & ~masks[i + 2]) ||
      (bytes[i + 3] & 0xc0) != (0x80 & ~masks[i + 3])) return 0LL;

  int ybc = bcs[bytes[i] & 0x07] + bcs[bytes[i + 1] & 0x30];
  int ymc = bcs[masks[i] & 0x07] + bcs[masks[i + 1] & 0x30];
  if (ybc == 0 && ymc == 0) return 0LL;

  ll yn = 1LL << ymc;
  if (ybc == 0) yn--;
  
  uchar m1 = masks[i + 1] & 0x0f;
  uchar m2 = masks[i + 2] & 0x3f;
  uchar m3 = masks[i + 3] & 0x3f;
  return yn * (1LL << (bcs[m1] + bcs[m2] + bcs[m3]));
}

/* main */

int main() {
  for (int b = 0; b < 256; b++) bcs[b] = bcount((uchar)b);

  for (;;) {
    cin >> n;
    if (n == 0) break;

    for (int i = 0; i < n; i++) {
      string str;
      cin >> str;
      str2bits(str, bytes[i], masks[i]);
      //cout << str; printf("=%x/%x\n", bytes[i], masks[i]);
    }

    memset(dp, 0, sizeof(dp));
    dp[n] = 1LL;

    for (int i = n - 1; i >= 0; i--) {
      dp[i] = (dp[i] + utf8_1(i) * dp[i + 1]) % MOD;
      if (i < n - 1) dp[i] = (dp[i] + utf8_2(i) * dp[i + 2]) % MOD;
      if (i < n - 2) dp[i] = (dp[i] + utf8_3(i) * dp[i + 3]) % MOD;
      if (i < n - 3) dp[i] = (dp[i] + utf8_4(i) * dp[i + 4]) % MOD;
    }

    cout << dp[0] << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1220
final_rank: 1

code_snippet: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef long long int Int;
const int L = 8;
const Int MOD = 1000000;

void countXY(Int ys, Int yt, Int xs, Int xt, Int &x, Int &y, string &s){
  if(ys != -1) FOR(i, ys, yt) if(s[i] == 'x') ++y;
  if(xs != -1) FOR(i, xs, xt) if(s[i] == 'x') ++x;
}

Int countPattern(Int x, Int y, string s){
  bool t = 1;
  REP(i, s.length()) if(s[i] == '1') t = 0;
  Int a = 1, b = 1;
  REP(i, x) a = (a * 2 % MOD);
  REP(j, y) b = (b * 2 % MOD);
  if(t) b = (b - 1 + MOD) % MOD;
  return (a % MOD) * (b % MOD) % MOD;
}

bool check(string s){
  bool f = 0;
  REP(i, s.length()){
    if(s[i] == 'x') return 1;
    if(s[i] == '1') f = 1;
  }
  return f;
}

bool check_pref(string &s, string tar){
  REP(i, tar.length()) if(s[i] != 'x' && s[i] != tar[i]) return 0;
  return 1;
}

int main() {
  Int N;
  while(cin >>N && N){
    vector<string> v(N);
    REP(i, N) cin >>v[i];
    vector<Int> dp(N + 1, 0);
    dp[0] = 1;
    REP(i, N){
      if(check_pref(v[i], "0")){
        Int x = 0, y = 0;
        countXY(-1, -1, 1, L, x, y, v[i]);
        dp[i + 1] = ((dp[i] * countPattern(x, y, "1") % MOD) + dp[i + 1]) % MOD;
      }
      if(i + 1 < N && check_pref(v[i], "110") && check_pref(v[i + 1], "10") && check(v[i].substr(3, 4))){
        Int x = 0, y = 0;
        countXY(3, L - 1, L - 1, L, x, y, v[i]);
        countXY(-1, -1, 2, L, x, y, v[i + 1]);
        dp[i + 2] = ((dp[i] * countPattern(x, y, v[i].substr(3, 4)) % MOD) + dp[i + 2]) % MOD;
      }
      if(i + 2 < N && check_pref(v[i], "1110") && check_pref(v[i + 1], "10") && check_pref(v[i + 2], "10") && check(v[i].substr(4, 4) + v[i + 1].substr(2, 1))){
        Int x = 0, y = 0;
        countXY(4, L, -1, -1, x, y, v[i]);
        countXY(2, 3, 3, L, x, y, v[i + 1]);
        countXY(-1, -1, 2, L, x, y, v[i + 2]);
        dp[i + 3] = ((dp[i] * countPattern(x, y, v[i].substr(4, 4) + v[i + 1].substr(2, 1)) % MOD) + dp[i + 3]) % MOD;
      }
      if(i + 3 < N && check_pref(v[i], "11110") && check_pref(v[i + 1], "10") && check_pref(v[i + 2], "10") && check_pref(v[i + 3], "10") && check(v[i].substr(5, 3) + v[i + 1].substr(2, 2))){
        Int x = 0, y = 0;
        countXY(5, L, -1, -1, x, y, v[i]);
        countXY(2, 4, 4, L, x, y, v[i + 1]);
        countXY(-1, -1, 2, L, x, y, v[i + 2]);
        countXY(-1, -1, 2, L, x, y, v[i + 3]);
        dp[i + 4] = ((dp[i] * countPattern(x, y, v[i].substr(5, 3) + v[i + 1].substr(2, 2)) % MOD) + dp[i + 4]) % MOD;
      }
    }
    cout <<dp[N] <<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 1276
final_rank: 8

code_snippet: #include<stdio.h>
#include<algorithm>
using namespace std;
char str[1100][10];
int mod=1000000;
int dp[1100][5][5];
int t[12];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%s",str[i]);
		for(int i=0;i<1100;i++)for(int j=0;j<5;j++)for(int k=0;k<5;k++)
			dp[i][j][k]=0;
		dp[a][0][0]=1;
		for(int i=a-1;i>=0;i--){
			for(int j=0;j<12;j++)t[j]=0;
			for(int j=0;j<256;j++){
				bool ok=true;
				for(int k=0;k<8;k++){
					if((j&(1<<k))&&str[i][k]=='0')ok=false;
					if(!(j&(1<<k))&&str[i][k]=='1')ok=false;
				}
				if(ok){
					if(j%2==0)t[0]++;
					else if(j%4==1){
						if(j&4)t[1]++;
						else if(j&8)t[2]++;
						else t[3]++;
					}else if(j%8==3){
						if(j&120)t[4]++;
					}else if(j%16==7){
						if(j&240)t[5]++;
						else t[6]++;
					}else if(j%32==15){
						if(j&224)t[7]++;
						else t[8]++;
					}
				}
			}
		//	for(int j=0;j<9;j++)printf("%d ",t[j]);printf("\n");
			dp[i][0][0]=(dp[i+1][0][0]*t[0]+(dp[i+1][1][0])*t[4]+
			dp[i+1][2][0]*t[5]+dp[i+1][2][1]*(t[5]+t[6])+dp[i+1][3][0]*t[7]+dp[i+1][3][1]*(t[7]+t[8]))%mod;
			dp[i][1][0]=(dp[i+1][0][0]*(t[1]+t[2]+t[3]))%mod;
			dp[i][2][0]=(dp[i+1][1][0]*(t[2]+t[3]))%mod;
			dp[i][2][1]=(dp[i+1][1][0]*t[1])%mod;
			dp[i][3][0]=((dp[i+1][2][0]+dp[i+1][2][1])*t[3])%mod;
			dp[i][3][1]=((dp[i+1][2][0]+dp[i+1][2][1])*(t[1]+t[2]))%mod;
		}
		printf("%d\n",dp[0][0][0]);
	}
}
accuracy: 1
time_ms: 60
memory_kb: 1148
final_rank: 9

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define REP(i, s, e) for ( int i = s; i <= e; i++ )  

string b;
string p[4] = {"0xxxxxxx","110yyyyx10xxxxxx","1110yyyy10yxxxxx10xxxxxx","11110yyy10yyxxxx10xxxxxx10xxxxxx"};

int dp[8010][4][33][2];
int dfs(int x,int pat,int pos,int done){
	int &res = dp[x][pat][pos][done];
	if( res != -1 ) return res;
	int ans = 0;
	if( pos == p[pat].size() ){
		if( !done ) return 0;
		if( x == b.size() ) return 1;
		ans += dfs(x,0,0,1);
		ans += dfs(x,1,0,0);
		ans += dfs(x,2,0,0);
		ans += dfs(x,3,0,0);
		ans %= 1000000;
		return ans;
	}
	if( x == b.size() ) return 0;
	for(int num = '0' ; num <= '1' ; num++){
		if( b[x] != 'x' && b[x] != num ) continue;
		int nextDone = done;
		if( p[pat][pos] == 'y' && num == '1' ) nextDone = 1;
		if( p[pat][pos] != 'x' && p[pat][pos] != 'y' && p[pat][pos] != num ) continue;
		ans += dfs(x+1,pat,pos+1,nextDone);
	}
	ans %= 1000000;
	return res = ans;
}
int main(){
	int N;
	while(cin >> N && N){
		memset(dp,-1,sizeof(dp));
		b = "";
		for(int i = 0 ; i < N ; i++){
			string s;
			cin >> s;
			b += s;
		}
		int ans = 0;
		ans += dfs(0,0,0,1);
		ans += dfs(0,1,0,0);
		ans += dfs(0,2,0,0);
		ans += dfs(0,3,0,0);
		ans %= 1000000;
		cout << ans << endl;
	}
	
}
accuracy: 1
time_ms: 50
memory_kb: 10340
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
string pat[4] = {"0xxxxxxx","110yyyyx10xxxxxx","1110yyyy10yxxxxx10xxxxxx","11110yyy10yyxxxx10xxxxxx10xxxxxx"};
int N;
map< pair< int , bool > , int > used;
vector< string > data;
int rec2( int idx, const string& str, const string& patan, bool y_flag){
  if(idx == str.size()){
    return y_flag;
  }
  int ret = 0;
  if(used.find( make_pair( idx, y_flag)) != used.end()) return used[make_pair( idx, y_flag)];
  if(isdigit(str[idx])){
    if(isdigit(patan[idx])){
      if(str[idx] != patan[idx]) return 0;
      else ret = rec2( idx + 1,  str, patan, y_flag);
    } else {
      ret = rec2( idx + 1, str, patan, y_flag|(str[idx]=='1'&&patan[idx]=='y'));
    }
  } else {
    if(isdigit(patan[idx])){
      ret = rec2( idx + 1, str, patan, y_flag);
    } else {
      ret = rec2( idx + 1, str, patan, y_flag|(patan[idx]=='y')) + rec2( idx + 1, str, patan, y_flag);
    }
  }
  return used[make_pair( idx, y_flag)] = ret % 1000000;
}
int rec( int idx, const string& str, const string& patan, bool y_flag){
  used.clear();
  return rec2( idx, str, patan, y_flag);
}
int main(){
  long long dp[1001] = {};
  while(cin >> N, N){
    for(int i = 0; i < N; i++){
      string s;
      cin >> s;
      data.push_back(s);
    }
    for(int i = 0; i < N; i++){
      if(i == 0){
        dp[i] = rec( 0, data[0], pat[0], true);
        dp[i] %= 1000000;
      } else if(i == 1){
        dp[i] = dp[0] * rec( 0, data[i], pat[0], true);
        dp[i] %= 1000000;
        dp[i] += rec( 0, data[0] + data[1], pat[1], false);
        dp[i] %= 1000000;
      } else if(i == 2){
        dp[i] = dp[1] * rec( 0, data[2], pat[0], true);
        dp[i] %= 1000000;
        dp[i] += dp[0] * rec( 0, data[1] + data[2], pat[1], false);
        dp[i] %= 1000000;
        dp[i] += rec( 0, data[0] + data[1] + data[2], pat[2], false);
        dp[i] %= 1000000;
      } else if(i == 3){
        dp[i] = dp[2] * rec( 0, data[3], pat[0], true);
        dp[i] %= 1000000;
        dp[i] += dp[1] * rec( 0, data[2] + data[3], pat[1], false);
        dp[i] %= 1000000;
        dp[i] += dp[0] * rec( 0, data[1] + data[2] + data[3], pat[2], false);
        dp[i] %= 1000000;
        dp[i] += rec( 0, data[0] + data[1] + data[2] + data[3], pat[3], false);
        dp[i] %= 1000000;
      } else {
        dp[i] = dp[i - 1] * rec( 0, data[i], pat[0], true);
        dp[i] %= 1000000;
        dp[i] += dp[i - 2] * rec( 0, data[i - 1] + data[i], pat[1], false);
        dp[i] %= 1000000;
        dp[i] += dp[i - 3] * rec( 0, data[i - 2] + data[i - 1] + data[i], pat[2], false);
        dp[i] %= 1000000;
        dp[i] += dp[i - 4] * rec( 0, data[i - 3] + data[i - 2] + data[i - 1] + data[i], pat[3], false);
        dp[i] %= 1000000;
      }
    }
    cout << dp[N - 1] << endl;

    data.clear();
  }
}
accuracy: 1
time_ms: 80
memory_kb: 1280
final_rank: 11

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

using namespace std;

int main(){
  for(int N;cin>>N,N;){
    string b[1000];
    for(int i=0;i<N;i++){
      cin>>b[i];
    }
    int dp[1001]={1};
    for(int i=0;i<N;i++){
      vector<string> bp[4]={
	{"0xxxxxxx"},
	{"110yyyyx","10xxxxxx"},
	{"1110yyyy","10yxxxxx","10xxxxxx"},
	{"11110yyy","10yyxxxx","10xxxxxx","10xxxxxx"}
      };
      for(int j=0;j<4;j++){
	if(N-i<bp[j].size())continue;
	bool f=false;
	int x=0,y=0;
	bool yz=false;
	for(int k=0;k<bp[j].size();k++){
	  for(int l=0;l<8;l++){
	    if(bp[j][k][l]=='0'||bp[j][k][l]=='1'){
	      f|=b[i+k][l]==(bp[j][k][l]^'0'^'1');
	    }else if(bp[j][k][l]=='y'){
	      y+=b[i+k][l]=='x';
	      yz|=b[i+k][l]=='1';
	    }else{
	      x+=b[i+k][l]=='x';
	    }
	  }
	}
	if(!f){
	  long long yf=(j==0)?1:(1LL<<y)-!yz;
	  const int M=1000000;
	  dp[i+bp[j].size()]=(dp[i+bp[j].size()]+(yf<<x)%M*dp[i])%M;
	}
      }
    }
    cout<<dp[N]<<endl;
  }
}
accuracy: 1
time_ms: 30
memory_kb: 1272
final_rank: 7

code_snippet: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

typedef long long lli;

const lli MOD = 1000000;
int n;
string str[1000];
vector<string> pat[4];

void init(){
  for(int i=0;i<4;i++) pat[i].clear();
  pat[0].push_back("0xxxxxxx");

  pat[1].push_back("110yyyyx");
  pat[1].push_back("10xxxxxx");

  pat[2].push_back("1110yyyy");
  pat[2].push_back("10yxxxxx");
  pat[2].push_back("10xxxxxx");

  pat[3].push_back("11110yyy");
  pat[3].push_back("10yyxxxx");
  pat[3].push_back("10xxxxxx");
  pat[3].push_back("10xxxxxx");
}

void solve(){
  lli dp[1001][4][4][8][2];
  for(int i=0;i<n;i++) for(int j=0;j<4;j++) for(int k=0;k<4;k++) for(int l2=0;l2<8;l2++) for(int l=0;l<2;l++) dp[i][j][k][l2][l] = 0;

  for(int i=0;i<n;i++){
    for(int j=0;j<4;j++){
      if(pat[j][0][0] == '1' && str[i][0] != '0' || pat[j][0][0] == '0' && str[i][0] != '1'){
        int pos = pat[j][0][0] == '0';
        if(i == 0) dp[i][j][0][0][pos] = 1;
        else{
          for(int k=0;k<4;k++) dp[i][j][0][0][pos] = (dp[i][j][0][0][pos] + dp[i-1][k][k][7][1]) % MOD;

          for(int k=0;k<j;k++)
            for(int l=0;l<2;l++)
              dp[i][j][k+1][0][l] = (dp[i][j][k+1][0][l] + dp[i-1][j][k][7][l]) % MOD;
        }
      }
    }

    for(int j=0;j<4;j++){
      for(int k=0;k<=j;k++){
        for(int l=1;l<8;l++){
          for(int l2=0;l2<2;l2++){
            if(pat[j][k][l] == '1' && str[i][l] != '0' || pat[j][k][l] == '0' && str[i][l] != '1') dp[i][j][k][l][l2] = (dp[i][j][k][l][l2] + dp[i][j][k][l-1][l2]) % MOD;
            if(pat[j][k][l] == 'y'){
              if(str[i][l] == '0' || str[i][l] == 'x') dp[i][j][k][l][l2] = (dp[i][j][k][l][l2] + dp[i][j][k][l-1][l2]) % MOD;
              if(str[i][l] == '1' || str[i][l] == 'x') dp[i][j][k][l][1] = (dp[i][j][k][l][1] + dp[i][j][k][l-1][l2]) % MOD;
            }
            if(pat[j][k][l] == 'x'){
              if(str[i][l] == 'x') dp[i][j][k][l][l2] = (dp[i][j][k][l][l2] + dp[i][j][k][l-1][l2] * 2) % MOD;
              else dp[i][j][k][l][l2] = (dp[i][j][k][l][l2] + dp[i][j][k][l-1][l2]) % MOD;
            }
          }
        }
      }
    }
  }

  lli ans = 0;
  for(int i=0;i<4;i++) ans = (ans + dp[n-1][i][i][7][1]) % MOD;
  cout << ans << endl;

}

int main(){
  init();
  while(cin >> n && n){
    for(int i=0;i<n;i++) cin >> str[i];
    solve();
  }
}
accuracy: 1
time_ms: 40
memory_kb: 3268
final_rank: 15

code_snippet: #include <iostream>
#include <algorithm>
#include <string>
 
using namespace std;
 
typedef long long lli;
 
const lli N = 1000;
const lli M = 1000000;
 
lli n, dp[N+1], t[17];
string data[N];
string pat[4][4] = {
  {"0xxxxxxx", "", "", ""},
  {"110yyyyx", "10xxxxxx", "", ""},
  {"1110yyyy", "10yxxxxx", "10xxxxxx", ""},
  {"11110yyy", "10yyxxxx", "10xxxxxx", "10xxxxxx"},
};
 
main(){
  t[0] = 1;
  for(lli i=1;i<17;i++) t[i] = (t[i-1] * 2) % M;
  while(cin >> n && n){
    for(lli i=0;i<n;i++) cin >> data[i];
    fill(dp, dp+n+1, 0);
    dp[0] = 1;
    for(lli i=0;i<n;i++){
      for(lli j=0;j<4&&i+j<n;j++){
        bool f = true;
        int f_y = 0;
        if(j == 0) f_y = true;
        lli cnt[2] = {0, 0};
        for(lli k=0;k<=j;k++){
          for(lli l=0;l<8;l++){
            if(data[i+k][l] != 'x' && pat[j][k][l] != 'x' && pat[j][k][l] != 'y' && data[i+k][l] != pat[j][k][l]){
f = false;
            }
            if(data[i+k][l] == '1' && pat[j][k][l] == 'y') f_y = 2;
            if(data[i+k][l] == 'x'){
              if(pat[j][k][l] == 'x') cnt[0]++;
              if(pat[j][k][l] == 'y'){
                cnt[1]++;
                f_y = max(f_y, 1);
              }
            }
          }
        }
        if(!f_y) f = false;
        if(f){
          lli val = t[cnt[0]];
          if(cnt[1]){
            if(f_y == 2) val = (val * t[cnt[1]]) % M;
            else val = (val * ((t[cnt[1]] - 1 + M) % M)) % M;
          }
          dp[i+j+1] = (dp[i+j+1] + dp[i] * val) % M;
        }
      }
    }
    cout << dp[n] << endl;
  }
}
accuracy: 1
time_ms: 20
memory_kb: 1272
final_rank: 2

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

using namespace std;

typedef long long lli;

const lli N = 1000;
const lli M = 1000000;

lli n, dp[N+1], t[1001];
string data[N];
string pat[4][4] = {
  {"0xxxxxxx", "", "", ""},
  {"110yyyyx", "10xxxxxx", "", ""},
  {"1110yyyy", "10yxxxxx", "10xxxxxx", ""},
  {"11110yyy", "10yyxxxx", "10xxxxxx", "10xxxxxx"},
};

main(){
  t[0] = 1;
  for(lli i=1;i<1001;i++) t[i] = (t[i-1] * 2) % M;
  while(cin >> n && n){
    for(lli i=0;i<n;i++) cin >> data[i];
    fill(dp, dp+n+1, 0);
    dp[0] = 1;
    for(lli i=0;i<n;i++){
      for(lli j=0;j<4&&i+j<n;j++){
        bool f = true;
        bool f_y = false;
        bool f_y2 = false;
        if(j == 0) f_y = true;
        lli cnt[2] = {0, 0};
        for(lli k=0;k<=j;k++){
          for(lli l=0;l<8;l++){
            if(data[i+k][l] != 'x' && pat[j][k][l] != 'x' && pat[j][k][l] != 'y' && data[i+k][l] != pat[j][k][l]){
              //cout << "# " << j << ' ' << k << ' ' << l << endl;
f = false;
            }
            if(data[i+k][l] == '1' && pat[j][k][l] == 'y') f_y = f_y2 = true;
            if(data[i+k][l] == 'x'){
              if(pat[j][k][l] == 'x') cnt[0]++;
              if(pat[j][k][l] == 'y'){
                cnt[1]++;
                f_y = true;
              }
            }
          }
        }
        //cout << i << ' ' << j << ' ' << f << endl;
        if(!f_y) f = false;
        if(f){
          lli val = t[cnt[0]];;
          //cout << cnt[0] << ' ' << cnt[1] << endl;
          if(cnt[1]){
            if(f_y2) val = (val * t[cnt[1]]) % M;
            else val = (val * ((t[cnt[1]] - 1 + M) % M)) % M;
          }
          //cout << val << endl;
          dp[i+j+1] = (dp[i+j+1] + dp[i] * val) % M;
        }
      }
    }
    cout << dp[n] << endl;
  }
}
accuracy: 1
time_ms: 20
memory_kb: 1280
final_rank: 3

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,a0,1,0};
 
const int tx[] = {0,1,1,0};
const int ty[] = {0,0,1,1};
 
static const double EPS = 1e-8;
 
ll mypow(ll x,int power){
    ll res = 1;
    while(power>0){
        if(power & 1) res *= x;
        x *= x;
        power >>= 1;
    }
    return res;
}
 
void init_format(vector<vector<string> >& bit_format){
    bit_format.resize(4);
 
    bit_format[0].push_back("0xxxxxxx");
 
    bit_format[1].push_back("110yyyyx");
    bit_format[1].push_back("10xxxxxx");
 
    bit_format[2].push_back("1110yyyy");
    bit_format[2].push_back("10yxxxxx");
    bit_format[2].push_back("10xxxxxx");
 
    bit_format[3].push_back("11110yyy");
    bit_format[3].push_back("10yyxxxx");
    bit_format[3].push_back("10xxxxxx");
    bit_format[3].push_back("10xxxxxx");
}
 
ll CountPatterns(int start,int last,const vector<vector<string> >& bit_format,const vector<string>& bits,int len){
    bool isok = true;
 
    int x_num = 0;
    int y_num = 0;
    int y1_num = 0;
    int y0_num = 0;
 
    for(int i=start,k=0;i<bits.size() && i <= last && k< bit_format[len-1].size();i++,k++){
 
        for(int j=0;j<bits[i].size() && j< bit_format[len-1][k].size();j++){
 
            if(bits[i][j]=='x'){
                if(bit_format[len-1][k][j] == 'x'){
                    x_num++;
                }
 
                else if(bit_format[len-1][k][j] == 'y'){
                    y_num++;
                }
            }
 
            else if(bits[i][j]=='1'){
                if(bit_format[len-1][k][j] =='0'){
                    isok = false;
                }
 
                else if(bit_format[len-1][k][j] == 'y'){
                    y1_num++;
                }
                else{
                    continue;
                }
            }
            else if(bits[i][j] == '0'){
                if(bit_format[len-1][k][j] =='1'){
                    isok = false;
                }
                else if(bit_format[len-1][k][j] == 'y'){
                    y0_num++;
                }
            }
        }
    }
 
    if(y_num==0 && y1_num==0 && y0_num > 0) isok = false;
 
    ll x_patterns = mypow(2,x_num);
    ll y_patterns = 1;
 
    if(y1_num > 0){
        y_patterns = mypow(2,y_num);
    }
    else{
        y_patterns = mypow(2,y_num)-1;
    }
 
    if(y_patterns == 0) y_patterns = 1;
    if(!isok) return 0;
 
    x_patterns %= 1000000;
    y_patterns %= 1000000;
 
    return x_patterns*y_patterns % 1000000LL;
}
 
ll dp[1001];
 
int main(){
    vector<vector<string> > bit_format;
    init_format(bit_format);
 
    int N;
    while(cin >> N){
        if(N==0) break;
 
        string line;
        vector<string> bits;
        for(int i=0;i<N;i++){
            string line;
            cin >> line;
            bits.push_back(line);
        }
 
         
        memset(dp,0,sizeof(dp));
        for(int start=0;start<N ;start++){
            for(int len = 4; len >=1; len--){
                if(start-len+1 < 0) continue;
                ll patterns = CountPatterns(start-len+1,start,bit_format,bits,len); 
                dp[start] += patterns * (start-len >=0 ? dp[start-len] : 1);
                dp[start] %= 1000000LL;
            }
        }
        printf("%ld\n",dp[N-1]%1000000LL);
    }
}
accuracy: 1
time_ms: 20
memory_kb: 1284
final_rank: 4

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,a0,1,0};

const int tx[] = {0,1,1,0};
const int ty[] = {0,0,1,1};

static const double EPS = 1e-8;

ll mypow(ll x,int power){
	ll res = 1;
	while(power>0){
		if(power & 1) res *= x;
		x *= x;
		power >>= 1;
	}
	return res;
}

void init_format(vector<vector<string> >& bit_format){
	bit_format.resize(4);

	bit_format[0].push_back("0xxxxxxx");

	bit_format[1].push_back("110yyyyx");
	bit_format[1].push_back("10xxxxxx");

	bit_format[2].push_back("1110yyyy");
	bit_format[2].push_back("10yxxxxx");
	bit_format[2].push_back("10xxxxxx");

	bit_format[3].push_back("11110yyy");
	bit_format[3].push_back("10yyxxxx");
	bit_format[3].push_back("10xxxxxx");
	bit_format[3].push_back("10xxxxxx");
}

ll CountPatterns(int start,int last,const vector<vector<string> >& bit_format,const vector<string>& bits,int len){
	bool isok = true;

	int x_num = 0;
	int y_num = 0;
	int y1_num = 0;
	int y0_num = 0;

	for(int i=start,k=0;i<bits.size() && i <= last && k< bit_format[len-1].size();i++,k++){

		for(int j=0;j<bits[i].size() && j< bit_format[len-1][k].size();j++){

			if(bits[i][j]=='x'){
				if(bit_format[len-1][k][j] == 'x'){
					x_num++;
				}

				else if(bit_format[len-1][k][j] == 'y'){
					y_num++;
				}
			}

			else if(bits[i][j]=='1'){
				if(bit_format[len-1][k][j] =='0'){
					isok = false;
				}

				else if(bit_format[len-1][k][j] == 'y'){
					y1_num++;
				}
				else{
					continue;
				}
			}
			else if(bits[i][j] == '0'){
				if(bit_format[len-1][k][j] =='1'){
					isok = false;
				}
				else if(bit_format[len-1][k][j] == 'y'){
					y0_num++;
				}
			}
		}
	}

	if(y_num==0 && y1_num==0 && y0_num > 0) isok = false;

	ll x_patterns = mypow(2,x_num);
	ll y_patterns = 1;

	if(y1_num > 0){
		y_patterns = mypow(2,y_num);
	}
	else{
		y_patterns = mypow(2,y_num)-1;
	}

	if(y_patterns == 0) y_patterns = 1;
	if(!isok) return 0;

	x_patterns %= 1000000;
	y_patterns %= 1000000;

	return x_patterns*y_patterns % 1000000LL;
}

ll dp[1001];

int main(){
	vector<vector<string> > bit_format;
	init_format(bit_format);

	int N;
	while(cin >> N){
		if(N==0) break;

		string line;
		vector<string> bits;
		for(int i=0;i<N;i++){
			string line;
			cin >> line;
			bits.push_back(line);
		}

		
		memset(dp,0,sizeof(dp));
		for(int start=0;start<N ;start++){
			for(int len = 4; len >=1; len--){
				if(start-len+1 < 0) continue;
				ll patterns = CountPatterns(start-len+1,start,bit_format,bits,len);	
				dp[start] += patterns * (start-len >=0 ? dp[start-len] : 1);
				dp[start] %= 1000000LL;
			}
		}
		printf("%ld\n",dp[N-1]%1000000LL);
	}
}
accuracy: 1
time_ms: 20
memory_kb: 1284
final_rank: 4

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,a0,1,0};

const int tx[] = {0,1,1,0};
const int ty[] = {0,0,1,1};

static const double EPS = 1e-8;

ll mypow(ll x,int power){
	ll res = 1;
	while(power>0){
		if(power & 1) res *= x;
		x *= x;
		power >>= 1;
	}
	return res;
}

void init_format(vector<vector<string> >& bit_format){
	bit_format.resize(4);

	bit_format[0].push_back("0xxxxxxx");

	bit_format[1].push_back("110yyyyx");
	bit_format[1].push_back("10xxxxxx");

	bit_format[2].push_back("1110yyyy");
	bit_format[2].push_back("10yxxxxx");
	bit_format[2].push_back("10xxxxxx");

	bit_format[3].push_back("11110yyy");
	bit_format[3].push_back("10yyxxxx");
	bit_format[3].push_back("10xxxxxx");
	bit_format[3].push_back("10xxxxxx");
}

ll CountPatterns(int start,int last,const vector<vector<string> >& bit_format,const vector<string>& bits,int len){
	bool isok = true;

	int x_num = 0;
	int y_num = 0;
	int y1_num = 0;
	int y0_num = 0;

	for(int i=start,k=0;i<bits.size() && i <= last && k< bit_format[len-1].size();i++,k++){

		for(int j=0;j<bits[i].size() && j< bit_format[len-1][k].size();j++){

			if(bits[i][j]=='x'){
				if(bit_format[len-1][k][j] == 'x'){
					x_num++;
				}

				else if(bit_format[len-1][k][j] == 'y'){
					y_num++;
				}
			}

			else if(bits[i][j]=='1'){
				if(bit_format[len-1][k][j] =='0'){
					isok = false;
				}

				else if(bit_format[len-1][k][j] == 'y'){
					y1_num++;
				}
				else{
					continue;
				}
			}
			else if(bits[i][j] == '0'){
				if(bit_format[len-1][k][j] =='1'){
					isok = false;
				}
				else if(bit_format[len-1][k][j] == 'y'){
					y0_num++;
				}
			}
		}
	}

	if(y_num==0 && y1_num==0 && y0_num > 0) isok = false;

	int x_patterns = mypow(2,x_num);
	int y_patterns = 1;

	if(y1_num > 0){
		y_patterns = mypow(2,y_num);
	}
	else{
		y_patterns = mypow(2,y_num)-1;
	}

	if(y_patterns == 0) y_patterns = 1;
	if(!isok) return 0;

	x_patterns %= 1000000;
	y_patterns %= 1000000;

	return x_patterns*y_patterns % 1000000LL;
}

ll dp[1001];

int main(){
	vector<vector<string> > bit_format;
	init_format(bit_format);

	int N;
	while(cin >> N){
		if(N==0) break;

		string line;
		vector<string> bits;
		for(int i=0;i<N;i++){
			string line;
			cin >> line;
			bits.push_back(line);
		}

		
		memset(dp,0,sizeof(dp));
		for(int start=0;start<N ;start++){
			for(int len = 4; len >=1; len--){
				if(start-len+1 < 0) continue;
				ll patterns = CountPatterns(start-len+1,start,bit_format,bits,len);	
				dp[start] += patterns * (start-len >=0 ? dp[start-len] : 1);
				dp[start] %= 1000000LL;
				//printf("start-len+1:%d start:%d \n",start-len+1,start);
			}
		}

		//for(int i=0;i<N;i++){
		//	for(int j=i+1;j<N;j++){
		//		for(int k=i;k+1<=j;k++){
		//			dp[i][j] += (dp[i][k]%1000000LL) * (dp[k+1][j]%1000000LL);
		//		}
		//	}
		//}

		printf("%ld\n",dp[N-1]%1000000LL);
	}
}
accuracy: 1
time_ms: 20
memory_kb: 1284
final_rank: 4

code_snippet: #include<stdio.h>
#include<set>
#include<string>
#include<iostream>
#include<string.h>
std::set<std::string> patterns[5][4],patternsAllY0[5][4];//yがめんどくさいのでｙの全パタンを最初に決定しておく

long long int mod=1000000;

void createCheckPattern(std::string str,int p,int no1,int no2,int yCount,bool hitY){
	if(p==8){
		if(yCount==0&&hitY==true)patternsAllY0[no1][no2].insert(str);
		else patterns[no1][no2].insert(str);
		return ;
	}
	
	char c=str[p];
	if(c=='x'||c=='y'){
		str[p]='0';
		bool hit=(c=='y');
		createCheckPattern(str,p+1,no1,no2,yCount,hitY||hit);
		str[p]='1';
		createCheckPattern(str,p+1,no1,no2,yCount+hit,hitY||hit);
		str[p]=c;
	}else{
		createCheckPattern(str,p+1,no1,no2,yCount,hitY);
	}
}

void patternSet(){
	createCheckPattern("0xxxxxxx",0,1,0,0,false);//1バイト
	
	createCheckPattern("110yyyyx",0,2,0,0,false);//2バイト1つめ文字
	createCheckPattern("10xxxxxx",0,2,1,0,false);//２バイト２つ目
	
	createCheckPattern("1110yyyy",0,3,0,0,false);//３バイト１つ目
	createCheckPattern("10yxxxxx",0,3,1,0,false);//３バイト2つ目
	createCheckPattern("10xxxxxx",0,3,2,0,false);//３バイト3つ目
	
	createCheckPattern("11110yyy",0,4,0,0,false);//4バイト１つ目
	createCheckPattern("10yyxxxx",0,4,1,0,false);//4バイト2つ目
	createCheckPattern("10xxxxxx",0,4,2,0,false);//4バイト3つ目
	createCheckPattern("10xxxxxx",0,4,3,0,false);//4バイト4つ目
	/*for(int i=1;i<=4;i++){
		for(int j=0;j<i;j++)printf("(%d %d %d)",patterns[i][j].size(),i,j);
		printf("\n");
		for(int j=0;j<i;j++)printf("(%d %d %d)",patternsAllY0[i][j].size(),i,j);
		printf("\n\n");
	}*/
}

void saiki(std::string& str,int p,int no1,int no2,long long int &re1,long long int& re2){
	if(p==0)re1=re2=0;
	if(p==8){
		if(patterns[no1][no2].find(str)!=patterns[no1][no2].end())re1++;
		else if(patternsAllY0[no1][no2].find(str)!=patternsAllY0[no1][no2].end())re2++;
	}else{
		if(str[p]=='x'){
			str[p]='0';
			saiki(str,p+1,no1,no2,re1,re2);
			str[p]='1';
			saiki(str,p+1,no1,no2,re1,re2);
			str[p]='x';
		}else{
			saiki(str,p+1,no1,no2,re1,re2);
		}
	}
}

void calc(int n){
	std::string strs[1002];
	for(int i=0;i<n;i++){
		std::cin>>strs[i];
	}
	long long int memo[1010]={1,0};

	for(int i=0;i<n;i++){
		if(i+4<=n){
			long long int ts[2][4];
			memset(ts,0,sizeof(ts));
			saiki(strs[i+0],0,4,0,ts[0][0],ts[1][0]);
			saiki(strs[i+1],0,4,1,ts[0][1],ts[1][1]);
			saiki(strs[i+2],0,4,2,ts[0][2],ts[1][2]);
			saiki(strs[i+3],0,4,3,ts[0][3],ts[1][3]);
			long long int t=0;
			for(int s=0;s<2;s++){
				for(int j=0;j<2;j++){
					for(int k=0;k<2;k++){
						for(int L=0;L<2;L++){
							t+=ts[s][0]*ts[j][1]*ts[k][2]*ts[L][3];
						}
					}
				}
			}
			t-=ts[1][0]*ts[1][1]*ts[0][2]*ts[0][3];
			t%=mod;
			memo[i+4]=(memo[i+4]+memo[i]*t)%mod;
		}
		if(i+3<=n){
			long long int ts[2][4];
			memset(ts,0,sizeof(ts));
			saiki(strs[i+0],0,3,0,ts[0][0],ts[1][0]);
			saiki(strs[i+1],0,3,1,ts[0][1],ts[1][1]);
			saiki(strs[i+2],0,3,2,ts[0][2],ts[1][2]);
			long long int t=0;
			for(int s=0;s<2;s++){
				for(int j=0;j<2;j++){
					for(int k=0;k<2;k++){
						t+=ts[s][0]*ts[j][1]*ts[k][2];
					}
				}
			}
			t-=ts[1][0]*ts[1][1]*ts[0][2];
			t%=mod;
			memo[i+3]=(memo[i+3]+memo[i]*t)%mod;
		}
		if(i+2<=n){
			long long int ts[2][4];
			memset(ts,0,sizeof(ts));
			saiki(strs[i+0],0,2,0,ts[0][0],ts[1][0]);
			saiki(strs[i+1],0,2,1,ts[0][1],ts[1][1]);
			long long int t=0;
			for(int s=0;s<2;s++){
				for(int j=0;j<2;j++){
					t+=ts[s][0]*ts[j][1];
				}
			}
			t-=ts[1][0]*ts[0][1];
			t%=mod;
			memo[i+2]=(memo[i+2]+memo[i]*t)%mod;
		}
		if(i+1<=n){
			long long int ts[2][4];
			memset(ts,0,sizeof(ts));
			long long int t=0;
			saiki(strs[i],0,1,0,ts[0][0],ts[1][0]);
			memo[i+1]=(memo[i+1]+memo[i]*ts[0][0])%mod;
		}
	}
	std::cout<<memo[n]%mod<<"\n";
}

int main(){
	int n;
	patternSet();
	char text[1000][10];
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		calc(n);
	}
}
accuracy: 1
time_ms: 750
memory_kb: 1364
final_rank: 16

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 = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll memo[1001];
int calc(int idx, vector<string>& v){
  int N = v.size();
  if(idx == N) return 1;
  if(memo[idx] != -1) return memo[idx];
  ll &res = memo[idx];
  res = 0;
  string s;
  string mask[4] = {
    "0xxxxxxx",
    "110yyyyx10xxxxxx",
    "1110yyyy10yxxxxx10xxxxxx",
    "11110yyy10yyxxxx10xxxxxx10xxxxxx"
  };
  for(int l = 0; l < 4; l++){
    if(idx + l == N) return res;
    s += v[idx + l];
    bool y_judge[256] = {};
    bool ok = true;
    REP(i, mask[l].size()) {
      if(mask[l][i] == 'y'){
        y_judge[s[i]] = true;
      }
      if(mask[l][i] == '0' && s[i] == '1') ok = false;
      if(mask[l][i] == '1' && s[i] == '0') ok = false;
    }
    if(l >= 1 && !y_judge['x'] && !y_judge['1']) ok = false;
    if(!ok) continue;
    ll cnt1 = 1, cnt2 = 1;
    REP(i, mask[l].size()){
      if(mask[l][i] == 'y' && s[i] == 'x') cnt1 <<= 1;
      if(mask[l][i] == 'x' && s[i] == 'x') cnt2 <<= 1;
    }
    if(l >= 1 && !y_judge['1']) cnt1--;
    res += cnt1 * cnt2 * calc(idx + 1 + l, v);
    res %= 1000000;
  }
  return res;
}
int main(){
  int N;
  while(cin>>N && N){
    vector<string> v(N);
    REP(i, N) cin>>v[i];
    memset(memo, -1, sizeof(memo));
    cout<<calc(0, v)<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1992
final_rank: 12