#include using namespace std; using ll = long long; using pii = pair; using pll = pair; using vi = vector; using vl = vector; #define rep3(i, a, b, c) for (ll i = (a); i < (b); i += (c)) #define rep2(i, a, b) rep3(i, a, b, 1) #define rep1(i, n) rep2(i, 0, n) #define rep0(n) rep1(aaaaa, n) #define ov4(a, b, c, d, name, ...) name #define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__) #define per(i, a, b) for (ll i = (a) - 1; i >= (b); i--) #define fore(e, v) for (auto&& e : v) #define all(a) begin(a), end(a) #define sz(a) (int)(size(a)) #define lb(v, x) (lower_bound(all(v), x) - begin(v)) #define eb emplace_back template bool chmin(T& a, const S& b) { return a > b ? a = b, 1 : 0; } template bool chmax(T& a, const S& b) { return a < b ? a = b, 1 : 0; } const int INF = 1e9 + 100; const ll INFL = 3e18 + 100; #define i128 __int128_t struct _ { _() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); } } __; using mat=array, 8>; const int MOD=1000000007; mat matmul(mat a,mat b){ mat ret; rep(i,8)rep(j,8)ret[i][j]=0; rep(k,8){ rep(i,8){ rep(j,8){ ret[i][j]=(ret[i][j]+a[i][k]*b[k][j])%MOD; } } } return ret; } mat matpow(mat a,ll n){ mat ret,t=a; rep(i,8)rep(j,8)ret[i][j]=0; rep(i,8)ret[i][i]=1; while(n>0){ if(n%2)ret=matmul(ret, t); t=matmul(t, t); n/=2; } return ret; } int main(){ string T; ll K; cin>>T>>K; mat add0,add1; rep(i,8)rep(j,8)add0[i][j]=add1[i][j]=0; rep(i,8)add0[i][i]=1; add0[3][0]+=1; add0[6][0]+=1; add0[3][1]+=1; add0[4][1]+=1; add0[6][1]+=1; add0[3][2]+=1; add0[4][2]+=2; add0[5][2]+=1; add0[6][2]+=1; add0[3][7]+=1; add0[4][7]+=2; add0[5][7]+=1; add0[6][7]+=1; rep(i,8)add1[i][i]=1; add1[0][3]+=1; add1[6][3]+=1; add1[0][4]+=1; add1[1][4]+=1; add1[6][4]+=1; add1[0][5]+=1; add1[1][5]+=2; add1[2][5]+=1; add1[6][5]+=1; add1[0][7]+=1; add1[1][7]+=2; add1[2][7]+=1; add1[6][7]+=1; mat base; rep(i,8)rep(j,8)base[i][j]=0; rep(i,8)base[i][i]=1; fore(i,T){ if(i=='0')base=matmul(base, add0); else base=matmul(base, add1); } mat vp=matpow(base, K); cout<