#include "bits/stdc++.h" using namespace std; #define DEBUG(x) cout<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair #define fi first #define se second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define all(c) c.begin(),c.end() const int inf = 1000000001; const ll INF = 2e18; const ll MOD = 1000000007; const ll mod = 1000000009; const double pi = 3.14159265358979323846; #define Sp(p) cout<> n; string s; rep(i, n) { char c; cin >> c; s.push_back(c); } int m; vs first; if (s[0] == '0') { m = 3; first.resize(m); first[0] = "000"; first[1] = "100"; first[2] = "111"; } else { m = 5; first.resize(m); first[0] = "001"; first[1] = "010"; first[2] = "011"; first[3] = "101"; first[4] = "110"; } ll res = 0; set st0, st1; st0.insert("100"); st0.insert("000"); st0.insert("111"); st1.insert("001"); st1.insert("010"); st1.insert("011"); st1.insert("101"); st1.insert("110"); DEBUG(s); rep(i, m) { string ans(n, '?'); ans[0] = first[i][1]; ans[1] = first[i][2]; ans[n - 1] = first[i][0]; ll temp = 1; for (int j = 1; j < n - 2; j++) { if (ans[j - 1] == '0' && ans[j] == '0') { ans[j + 1] = s[j]; } else if (ans[j - 1] == '1' && ans[j] == '0') { ans[j + 1] = s[j]; } else if (ans[j - 1] == '1' && ans[j] == '1') { ans[j + 1] = '0' + (1 - (s[j] - '0')); } else if (ans[j - 1] == '0' && ans[j] == '1') { if (s[j] == '0') { temp = 0; break; } else { ans[j + 1] = '2'; temp *= 2; } } else { ans[j + 1] = s[j]; } } ans.push_back(ans[0]); for (int j = n - 2; j <= n - 1; j++) { if (temp == 0) { continue; } if (s[j] == '0') { string a = ans.substr(j - 1, 3); if (st0.count(a)) { continue; } else if (a[0] == '2') { if (a.substr(1, 2) != "00") { if (a.substr(1, 2) == "11") { (temp *= mod_inverse(2, MOD)) %= MOD; ans[j] = '1'; } else { temp = 0; } } } else if (a[1] == '2') { if (a[0] == '0' && a[2] == '1') { temp = 0; } else { a[1] = a[2]; (temp *= mod_inverse(2, mod)) %= MOD; } } else { temp = 0; } } else { string a = ans.substr(j - 1, 3); if (st1.count(a)) { continue; } else if (a[0] == '2') { if (a.substr(1, 2) != "01" && a.substr(1, 2) != "10") { if (a.substr(1, 2) == "11") { (temp *= mod_inverse(2, MOD)) %= MOD; ans[j] = '0'; } else { temp = 0; } } } else if (a[1] == '2') { if (a[0] == '0' && a[2] == '0') { ans[j + 1] = '1'; (temp *= mod_inverse(2, MOD)) %= MOD; } else if (a[0] == '0' && a[2] == '1') { continue; } else if (a[0] == '1' && a[2] == '0') { ans[j + 1] = '1'; (temp *= mod_inverse(2, MOD)) %= MOD; } else if (a[0] == '1' && a[2] == '1') { ans[j + 1] = '0'; (temp *= mod_inverse(2, MOD)) %= MOD; } } else { temp = 0; } } } DEBUG(temp); (res += temp) % MOD; } cout << res << endl; }