// Exact relaxation for each mask/period, output native-endian IEEE float64 bounds.
// Input on stdin: N, N ciphertext, N-1 word marks, 2*29*29 log2 scores.
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stdexcept>
using std::vector;
constexpr int K=29, P=32, S=K*P;
static int md(int x){return (x%K+K)%K;}
int main(){
 int n;if(scanf("%d",&n)!=1||n<3)return 1;
 vector<int> c(n),b(n-1),f;double t[2][K][K];
 for(int i=0;i<n;i++){if(scanf("%d",&c[i])!=1)return 1;if(c[i]==0)f.push_back(i);}
 for(int &x:b)if(scanf("%d",&x)!=1)return 1;
 for(auto &m:t)for(auto &r:m)for(auto &z:r)if(scanf("%lf",&z)!=1)return 1;
 const int nf=f.size(),nl=nf/2;if(nl<1||nf>20)return 1;
 int cut=(f[nl-1]+f[nl])/2;if(cut<=f[nl-1]||cut>=f[nl]||!c[cut])return 1;
 for(int L=3;L<=16;L++){
  auto half=[&](int lo,int hi,int bits){
   vector<double> all((1<<bits)*L*S);
   for(int m=0;m<(1<<bits);m++){
    double *E=all.data()+m*L*S;vector<int> slot(hi-lo+1);int phase=0,q=0;
    for(int i=lo;i<=hi;i++){
     bool skip=false;if(c[i]==0){skip=(m>>q)&1;q++;}
     slot[i-lo]=skip?-1:phase;if(!skip)phase=(phase+1)%L;
    }
    if(q!=bits)throw std::runtime_error("mask size");
    for(int i=lo;i<hi;i++){
     int a=slot[i-lo],d=slot[i+1-lo];auto &h=t[b[i]];
     double *T=E+(a>=0?a:(d>=0?d:0))*S;
     for(int x=0;x<K;x++)for(int y=0;y<K;y++){
      int l=a<0?0:md(c[i]-x);
      int r=d<0?0:md(c[i+1]-(a>=0?y:x));
      T[x*P+y]+=h[l][r];
     }
    }
   }
   return all;
  };
  auto A=half(0,cut,nl),B=half(cut,n-1,nf-nl);
  vector<double> bounds(1<<nf);
  #pragma omp parallel for schedule(static)
  for(int m=0;m<(1<<nf);m++){
   int l=m% (1<<nl),r=m>>nl,off=(cut-__builtin_popcount((unsigned)l))%L;
   const double *a=A.data()+l*L*S,*b0=B.data()+r*L*S;
   alignas(64) double prev[P]={},next[P];
   for(int i=0;i<L;i++){
    auto u=a+i*S, v=b0+((i-off+L)%L)*S;
    std::fill(next,next+P,-1e100);
    for(int x=0;x<K;x++){
     const double px=prev[x];for(int y=0;y<K;y++)next[y]=std::max(next[y],px+(u[x*P+y]+v[x*P+y]));
    }
    std::copy(next,next+K,prev);
   }
   bounds[m]=*std::max_element(prev,prev+K)-L*std::log2(double(K));
  }
  if(fwrite(bounds.data(),sizeof(double),bounds.size(),stdout)!=bounds.size())return 1;
 }
}
