纪念——代码首次达到近50K(更新:78.8K 2019行)

   1 #include<bits/stdc++.h>
   2 #define re register
   3 #define F(A) for(re int (A)=1;(A)<=8;++(A))
   4 using namespace std;
   5 int n,mi[10],sp[10],sa[10],kn[10],MI,SP,SA,KN;
   6 double f[110][10][10][10][10],g[10][20];
   7 double ANS,mig[10],spe[10],san[10],kno[10];
   8 char s[100],s1[100],s2[100],s3[100],s4[100];
   9 double pre[10][20],suf[10][20];
  10 void addmi(int id,int val,double p){
  11     F(i) F(j) F(k) F(l){
  12         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  13         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
  14     }
  15 }
  16 void addsp(int id,int val,double p){
  17     F(i) F(j) F(k) F(l){
  18         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  19         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
  20     }
  21 }
  22 void addsa(int id,int val,double p){
  23     F(i) F(j) F(k) F(l){
  24         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  25         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
  26     }
  27 }
  28 void addkn(int id,int val,double p){
  29     F(i) F(j) F(k) F(l){
  30         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  31         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
  32     }
  33 }
  34 void mimixd(int id,int lim,int val){
  35     F(i) F(j) F(k) F(l){
  36         re double p=pre[mi[i]][lim];
  37         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
  38         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  39         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
  40     }
  41 }
  42 void mispxd(int id,int lim,int val){
  43     F(i) F(j) F(k) F(l){
  44         re double p=pre[mi[i]][lim];
  45         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
  46         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  47         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
  48     }
  49 }
  50 void misaxd(int id,int lim,int val){
  51     F(i) F(j) F(k) F(l){
  52         re double p=pre[mi[i]][lim];
  53         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
  54         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  55         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
  56     }
  57 }
  58 void miknxd(int id,int lim,int val){
  59     F(i) F(j) F(k) F(l){
  60         re double p=pre[mi[i]][lim];
  61         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
  62         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  63         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
  64     }
  65 }
  66 void spmixd(int id,int lim,int val){
  67     F(i) F(j) F(k) F(l){
  68         re double p=pre[sp[j]][lim];
  69         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
  70         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  71         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
  72     }
  73 }
  74 void spspxd(int id,int lim,int val){
  75     F(i) F(j) F(k) F(l){
  76         re double p=pre[sp[j]][lim];
  77         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
  78         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  79         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
  80     }
  81 }
  82 void spsaxd(int id,int lim,int val){
  83     F(i) F(j) F(k) F(l){
  84         re double p=pre[sp[j]][lim];
  85         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
  86         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  87         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
  88     }
  89 }
  90 void spknxd(int id,int lim,int val){
  91     F(i) F(j) F(k) F(l){
  92         re double p=pre[sp[j]][lim];
  93         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
  94         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  95         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
  96     }
  97 }
  98 void samixd(int id,int lim,int val){
  99     F(i) F(j) F(k) F(l){
 100         re double p=pre[sa[k]][lim];
 101         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 102         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 103         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 104     }
 105 }
 106 void saspxd(int id,int lim,int val){
 107     F(i) F(j) F(k) F(l){
 108         re double p=pre[sa[k]][lim];
 109         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 110         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 111         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 112     }
 113 }
 114 void sasaxd(int id,int lim,int val){
 115     F(i) F(j) F(k) F(l){
 116         re double p=pre[sa[k]][lim];
 117         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 118         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 119         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 120     }
 121 }
 122 void saknxd(int id,int lim,int val){
 123     F(i) F(j) F(k) F(l){
 124         re double p=pre[sa[k]][lim];
 125         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 126         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 127         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 128     }
 129 }
 130 void knmixd(int id,int lim,int val){
 131     F(i) F(j) F(k) F(l){
 132         re double p=pre[kn[l]][lim];
 133         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 134         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 135         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 136     }
 137 }
 138 void knspxd(int id,int lim,int val){
 139     F(i) F(j) F(k) F(l){
 140         re double p=pre[kn[l]][lim];
 141         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 142         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 143         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 144     }
 145 }
 146 void knsaxd(int id,int lim,int val){
 147     F(i) F(j) F(k) F(l){
 148         re double p=pre[kn[l]][lim];
 149         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 150         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 151         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 152     }
 153 }
 154 void knknxd(int id,int lim,int val){
 155     F(i) F(j) F(k) F(l){
 156         re double p=pre[kn[l]][lim];
 157         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 158         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 159         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 160     }
 161 }
 162 void mimix(int id,int lim,int val){
 163     F(i) F(j) F(k) F(l){
 164         re double p=pre[mi[i]][lim-1];
 165         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 166         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 167         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 168     }
 169 }
 170 void mispx(int id,int lim,int val){
 171     F(i) F(j) F(k) F(l){
 172         re double p=pre[mi[i]][lim-1];
 173         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 174         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 175         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 176     }
 177 }
 178 void misax(int id,int lim,int val){
 179     F(i) F(j) F(k) F(l){
 180         re double p=pre[mi[i]][lim-1];
 181         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 182         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 183         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 184     }
 185 }
 186 void miknx(int id,int lim,int val){
 187     F(i) F(j) F(k) F(l){
 188         re double p=pre[mi[i]][lim-1];
 189         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 190         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 191         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 192     }
 193 }
 194 void spmix(int id,int lim,int val){
 195     F(i) F(j) F(k) F(l){
 196         re double p=pre[sp[j]][lim-1];
 197         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 198         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 199         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 200     }
 201 }
 202 void spspx(int id,int lim,int val){
 203     F(i) F(j) F(k) F(l){
 204         re double p=pre[sp[j]][lim-1];
 205         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 206         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 207         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 208     }
 209 }
 210 void spsax(int id,int lim,int val){
 211     F(i) F(j) F(k) F(l){
 212         re double p=pre[sp[j]][lim-1];
 213         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 214         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 215         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 216     }
 217 }
 218 void spknx(int id,int lim,int val){
 219     F(i) F(j) F(k) F(l){
 220         re double p=pre[sp[j]][lim-1];
 221         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 222         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 223         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 224     }
 225 }
 226 void samix(int id,int lim,int val){
 227     F(i) F(j) F(k) F(l){
 228         re double p=pre[sa[k]][lim-1];
 229         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 230         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 231         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 232     }
 233 }
 234 void saspx(int id,int lim,int val){
 235     F(i) F(j) F(k) F(l){
 236         re double p=pre[sa[k]][lim-1];
 237         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 238         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 239         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 240     }
 241 }
 242 void sasax(int id,int lim,int val){
 243     F(i) F(j) F(k) F(l){
 244         re double p=pre[sa[k]][lim-1];
 245         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 246         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 247         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 248     }
 249 }
 250 void saknx(int id,int lim,int val){
 251     F(i) F(j) F(k) F(l){
 252         re double p=pre[sa[k]][lim-1];
 253         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 254         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 255         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 256     }
 257 }
 258 void knmix(int id,int lim,int val){
 259     F(i) F(j) F(k) F(l){
 260         re double p=pre[kn[l]][lim-1];
 261         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 262         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 263         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 264     }
 265 }
 266 void knspx(int id,int lim,int val){
 267     F(i) F(j) F(k) F(l){
 268         re double p=pre[kn[l]][lim-1];
 269         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 270         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 271         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 272     }
 273 }
 274 void knsax(int id,int lim,int val){
 275     F(i) F(j) F(k) F(l){
 276         re double p=pre[kn[l]][lim-1];
 277         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 278         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 279         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 280     }
 281 }
 282 void knknx(int id,int lim,int val){
 283     F(i) F(j) F(k) F(l){
 284         re double p=pre[kn[l]][lim-1];
 285         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 286         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 287         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 288     }
 289 }
 290 void mimidd(int id,int lim,int val){
 291     F(i) F(j) F(k) F(l){
 292         re double p=suf[mi[i]][lim];
 293         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 294         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 295         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 296     }
 297 }
 298 void mispdd(int id,int lim,int val){
 299     F(i) F(j) F(k) F(l){
 300         re double p=suf[mi[i]][lim];
 301         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 302         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 303         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 304     }
 305 }
 306 void misadd(int id,int lim,int val){
 307     F(i) F(j) F(k) F(l){
 308         re double p=suf[mi[i]][lim];
 309         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 310         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 311         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 312     }
 313 }
 314 void mikndd(int id,int lim,int val){
 315     F(i) F(j) F(k) F(l){
 316         re double p=suf[mi[i]][lim];
 317         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 318         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 319         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 320     }
 321 }
 322 void spmidd(int id,int lim,int val){
 323     F(i) F(j) F(k) F(l){
 324         re double p=suf[sp[j]][lim];
 325         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 326         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 327         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 328     }
 329 }
 330 void spspdd(int id,int lim,int val){
 331     F(i) F(j) F(k) F(l){
 332         re double p=suf[sp[j]][lim];
 333         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 334         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 335         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 336     }
 337 }
 338 void spsadd(int id,int lim,int val){
 339     F(i) F(j) F(k) F(l){
 340         re double p=suf[sp[j]][lim];
 341         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 342         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 343         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 344     }
 345 }
 346 void spkndd(int id,int lim,int val){
 347     F(i) F(j) F(k) F(l){
 348         re double p=suf[sp[j]][lim];
 349         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 350         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 351         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 352     }
 353 }
 354 void samidd(int id,int lim,int val){
 355     F(i) F(j) F(k) F(l){
 356         re double p=suf[sa[k]][lim];
 357         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 358         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 359         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 360     }
 361 }
 362 void saspdd(int id,int lim,int val){
 363     F(i) F(j) F(k) F(l){
 364         re double p=suf[sa[k]][lim];
 365         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 366         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 367         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 368     }
 369 }
 370 void sasadd(int id,int lim,int val){
 371     F(i) F(j) F(k) F(l){
 372         re double p=suf[sa[k]][lim];
 373         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 374         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 375         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 376     }
 377 }
 378 void sakndd(int id,int lim,int val){
 379     F(i) F(j) F(k) F(l){
 380         re double p=suf[sa[k]][lim];
 381         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 382         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 383         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 384     }
 385 }
 386 void knmidd(int id,int lim,int val){
 387     F(i) F(j) F(k) F(l){
 388         re double p=suf[kn[l]][lim];
 389         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 390         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 391         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 392     }
 393 }
 394 void knspdd(int id,int lim,int val){
 395     F(i) F(j) F(k) F(l){
 396         re double p=suf[kn[l]][lim];
 397         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 398         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 399         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 400     }
 401 }
 402 void knsadd(int id,int lim,int val){
 403     F(i) F(j) F(k) F(l){
 404         re double p=suf[kn[l]][lim];
 405         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 406         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 407         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 408     }
 409 }
 410 void knkndd(int id,int lim,int val){
 411     F(i) F(j) F(k) F(l){
 412         re double p=suf[kn[l]][lim];
 413         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 414         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 415         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 416     }
 417 }
 418 
 419 void mimid(int id,int lim,int val){
 420     F(i) F(j) F(k) F(l){
 421         re double p=suf[mi[i]][lim+1];
 422         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 423         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 424         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 425     }
 426 }
 427 void mispd(int id,int lim,int val){
 428     F(i) F(j) F(k) F(l){
 429         re double p=suf[mi[i]][lim+1];
 430         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 431         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 432         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 433     }
 434 }
 435 void misad(int id,int lim,int val){
 436     F(i) F(j) F(k) F(l){
 437         re double p=suf[mi[i]][lim+1];
 438         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 439         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 440         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 441     }
 442 }
 443 void miknd(int id,int lim,int val){
 444     F(i) F(j) F(k) F(l){
 445         re double p=suf[mi[i]][lim+1];
 446         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 447         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 448         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 449     }
 450 }
 451 void spmid(int id,int lim,int val){
 452     F(i) F(j) F(k) F(l){
 453         re double p=suf[sp[j]][lim+1];
 454         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 455         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 456         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 457     }
 458 }
 459 void spspd(int id,int lim,int val){
 460     F(i) F(j) F(k) F(l){
 461         re double p=suf[sp[j]][lim+1];
 462         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 463         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 464         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 465     }
 466 }
 467 void spsad(int id,int lim,int val){
 468     F(i) F(j) F(k) F(l){
 469         re double p=suf[sp[j]][lim+1];
 470         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 471         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 472         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 473     }
 474 }
 475 void spknd(int id,int lim,int val){
 476     F(i) F(j) F(k) F(l){
 477         re double p=suf[sp[j]][lim+1];
 478         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 479         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 480         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 481     }
 482 }
 483 void samid(int id,int lim,int val){
 484     F(i) F(j) F(k) F(l){
 485         re double p=suf[sa[k]][lim+1];
 486         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 487         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 488         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 489     }
 490 }
 491 void saspd(int id,int lim,int val){
 492     F(i) F(j) F(k) F(l){
 493         re double p=suf[sa[k]][lim+1];
 494         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 495         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 496         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 497     }
 498 }
 499 void sasad(int id,int lim,int val){
 500     F(i) F(j) F(k) F(l){
 501         re double p=suf[sa[k]][lim+1];
 502         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 503         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 504         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 505     }
 506 }
 507 void saknd(int id,int lim,int val){
 508     F(i) F(j) F(k) F(l){
 509         re double p=suf[sa[k]][lim+1];
 510         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 511         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 512         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 513     }
 514 }
 515 void knmid(int id,int lim,int val){
 516     F(i) F(j) F(k) F(l){
 517         re double p=suf[kn[l]][lim+1];
 518         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 519         if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 520         else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 521     }
 522 }
 523 void knspd(int id,int lim,int val){
 524     F(i) F(j) F(k) F(l){
 525         re double p=suf[kn[l]][lim+1];
 526         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 527         if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 528         else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 529     }
 530 }
 531 void knsad(int id,int lim,int val){
 532     F(i) F(j) F(k) F(l){
 533         re double p=suf[kn[l]][lim+1];
 534         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 535         if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 536         else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 537     }
 538 }
 539 void knknd(int id,int lim,int val){
 540     F(i) F(j) F(k) F(l){
 541         re double p=suf[kn[l]][lim+1];
 542         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 543         if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 544         else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 545     }
 546 }
 547 void mimixdw(int id,int lim,int val){
 548     re int flag=(val<0)?-1:1;
 549     F(i) F(j) F(k) F(l){
 550         re double p=pre[mi[i]][lim];
 551         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 552         for(re int q=0;q<=16;++q){
 553             re double gl=g[abs(val)][q];
 554             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 555             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
 556         }
 557     }
 558 }
 559 void mispxdw(int id,int lim,int val){
 560     re int flag=(val<0)?-1:1;
 561     F(i) F(j) F(k) F(l){
 562         re double p=pre[mi[i]][lim];
 563         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 564         for(re int q=0;q<=16;++q){
 565             re double gl=g[abs(val)][q];
 566             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 567             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
 568         }
 569     }
 570 }
 571 void misaxdw(int id,int lim,int val){
 572     re int flag=(val<0)?-1:1;
 573     F(i) F(j) F(k) F(l){
 574         re double p=pre[mi[i]][lim];
 575         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 576         for(re int q=0;q<=16;++q){
 577             re double gl=g[abs(val)][q];
 578             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 579             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
 580         }
 581     }
 582 }
 583 void miknxdw(int id,int lim,int val){
 584     re int flag=(val<0)?-1:1;
 585     F(i) F(j) F(k) F(l){
 586         re double p=pre[mi[i]][lim];
 587         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 588         for(re int q=0;q<=16;++q){
 589             re double gl=g[abs(val)][q];
 590             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 591             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
 592         }
 593     }
 594 }
 595 void spmixdw(int id,int lim,int val){
 596     re int flag=(val<0)?-1:1;
 597     F(i) F(j) F(k) F(l){
 598         re double p=pre[sp[j]][lim];
 599         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 600         for(re int q=0;q<=16;++q){
 601             re double gl=g[abs(val)][q];
 602             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 603             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
 604         }
 605     }
 606 }
 607 void spspxdw(int id,int lim,int val){
 608     re int flag=(val<0)?-1:1;
 609     F(i) F(j) F(k) F(l){
 610         re double p=pre[sp[j]][lim];
 611         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 612         for(re int q=0;q<=16;++q){
 613             re double gl=g[abs(val)][q];
 614             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 615             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
 616         }
 617     }
 618 }
 619 void spsaxdw(int id,int lim,int val){
 620     re int flag=(val<0)?-1:1;
 621     F(i) F(j) F(k) F(l){
 622         re double p=pre[sp[j]][lim];
 623         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 624         for(re int q=0;q<=16;++q){
 625             re double gl=g[abs(val)][q];
 626             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 627             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
 628         }
 629     }
 630 }
 631 void spknxdw(int id,int lim,int val){
 632     re int flag=(val<0)?-1:1;
 633     F(i) F(j) F(k) F(l){
 634         re double p=pre[sp[j]][lim];
 635         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 636         for(re int q=0;q<=16;++q){
 637             re double gl=g[abs(val)][q];
 638             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 639             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
 640         }
 641     }
 642 }
 643 void samixdw(int id,int lim,int val){
 644     re int flag=(val<0)?-1:1;
 645     F(i) F(j) F(k) F(l){
 646         re double p=pre[sa[k]][lim];
 647         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 648         for(re int q=0;q<=16;++q){
 649             re double gl=g[abs(val)][q];
 650             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 651             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
 652         }
 653     }
 654 }
 655 void saspxdw(int id,int lim,int val){
 656     re int flag=(val<0)?-1:1;
 657     F(i) F(j) F(k) F(l){
 658         re double p=pre[sa[k]][lim];
 659         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 660         for(re int q=0;q<=16;++q){
 661             re double gl=g[abs(val)][q];
 662             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 663             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
 664         }
 665     }
 666 }
 667 void sasaxdw(int id,int lim,int val){
 668     re int flag=(val<0)?-1:1;
 669     F(i) F(j) F(k) F(l){
 670         re double p=pre[sa[k]][lim];
 671         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 672         for(re int q=0;q<=16;++q){
 673             re double gl=g[abs(val)][q];
 674             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 675             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
 676         }
 677     }
 678 }
 679 void saknxdw(int id,int lim,int val){
 680     re int flag=(val<0)?-1:1;
 681     F(i) F(j) F(k) F(l){
 682         re double p=pre[sa[k]][lim];
 683         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 684         for(re int q=0;q<=16;++q){
 685             re double gl=g[abs(val)][q];
 686             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 687             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
 688         }
 689     }
 690 }
 691 void knmixdw(int id,int lim,int val){
 692     re int flag=(val<0)?-1:1;
 693     F(i) F(j) F(k) F(l){
 694         re double p=pre[kn[l]][lim];
 695         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 696         for(re int q=0;q<=16;++q){
 697             re double gl=g[abs(val)][q];
 698             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 699             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
 700         }
 701     }
 702 }
 703 void knspxdw(int id,int lim,int val){
 704     re int flag=(val<0)?-1:1;
 705     F(i) F(j) F(k) F(l){
 706         re double p=pre[kn[l]][lim];
 707         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 708         for(re int q=0;q<=16;++q){
 709             re double gl=g[abs(val)][q];
 710             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 711             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
 712         }
 713     }
 714 }
 715 void knsaxdw(int id,int lim,int val){
 716     re int flag=(val<0)?-1:1;
 717     F(i) F(j) F(k) F(l){
 718         re double p=pre[kn[l]][lim];
 719         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 720         for(re int q=0;q<=16;++q){
 721             re double gl=g[abs(val)][q];
 722             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 723             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
 724         }
 725     }
 726 }
 727 void knknxdw(int id,int lim,int val){
 728     re int flag=(val<0)?-1:1;
 729     F(i) F(j) F(k) F(l){
 730         re double p=pre[kn[l]][lim];
 731         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 732         for(re int q=0;q<=16;++q){
 733             re double gl=g[abs(val)][q];
 734             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 735             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
 736         }
 737     }
 738 }
 739 void mimixw(int id,int lim,int val){
 740     re int flag=(val<0)?-1:1;
 741     F(i) F(j) F(k) F(l){
 742         re double p=pre[mi[i]][lim-1];
 743         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 744         for(re int q=0;q<=16;++q){
 745             re double gl=g[abs(val)][q];
 746             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 747             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
 748         }
 749     }
 750 }
 751 void mispxw(int id,int lim,int val){
 752     re int flag=(val<0)?-1:1;
 753     F(i) F(j) F(k) F(l){
 754         re double p=pre[mi[i]][lim-1];
 755         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 756         for(re int q=0;q<=16;++q){
 757             re double gl=g[abs(val)][q];
 758             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 759             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
 760         }
 761     }
 762 }
 763 void misaxw(int id,int lim,int val){
 764     re int flag=(val<0)?-1:1;
 765     F(i) F(j) F(k) F(l){
 766         re double p=pre[mi[i]][lim-1];
 767         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 768         for(re int q=0;q<=16;++q){
 769             re double gl=g[abs(val)][q];
 770             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 771             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
 772         }
 773     }
 774 }
 775 void miknxw(int id,int lim,int val){
 776     re int flag=(val<0)?-1:1;
 777     F(i) F(j) F(k) F(l){
 778         re double p=pre[mi[i]][lim-1];
 779         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 780         for(re int q=0;q<=16;++q){
 781             re double gl=g[abs(val)][q];
 782             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 783             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
 784         }
 785     }
 786 }
 787 void spmixw(int id,int lim,int val){
 788     re int flag=(val<0)?-1:1;
 789     F(i) F(j) F(k) F(l){
 790         re double p=pre[sp[j]][lim-1];
 791         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 792         for(re int q=0;q<=16;++q){
 793             re double gl=g[abs(val)][q];
 794             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 795             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
 796         }
 797     }
 798 }
 799 void spspxw(int id,int lim,int val){
 800     re int flag=(val<0)?-1:1;
 801     F(i) F(j) F(k) F(l){
 802         re double p=pre[sp[j]][lim-1];
 803         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 804         for(re int q=0;q<=16;++q){
 805             re double gl=g[abs(val)][q];
 806             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 807             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
 808         }
 809     }
 810 }
 811 void spsaxw(int id,int lim,int val){
 812     re int flag=(val<0)?-1:1;
 813     F(i) F(j) F(k) F(l){
 814         re double p=pre[sp[j]][lim-1];
 815         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 816         for(re int q=0;q<=16;++q){
 817             re double gl=g[abs(val)][q];
 818             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 819             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
 820         }
 821     }
 822 }
 823 void spknxw(int id,int lim,int val){
 824     re int flag=(val<0)?-1:1;
 825     F(i) F(j) F(k) F(l){
 826         re double p=pre[sp[j]][lim-1];
 827         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 828         for(re int q=0;q<=16;++q){
 829             re double gl=g[abs(val)][q];
 830             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 831             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
 832         }
 833     }
 834 }
 835 void samixw(int id,int lim,int val){
 836     re int flag=(val<0)?-1:1;
 837     F(i) F(j) F(k) F(l){
 838         re double p=pre[sa[k]][lim-1];
 839         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 840         for(re int q=0;q<=16;++q){
 841             re double gl=g[abs(val)][q];
 842             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 843             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
 844         }
 845     }
 846 }
 847 void saspxw(int id,int lim,int val){
 848     re int flag=(val<0)?-1:1;
 849     F(i) F(j) F(k) F(l){
 850         re double p=pre[sa[k]][lim-1];
 851         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 852         for(re int q=0;q<=16;++q){
 853             re double gl=g[abs(val)][q];
 854             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 855             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
 856         }
 857     }
 858 }
 859 void sasaxw(int id,int lim,int val){
 860     re int flag=(val<0)?-1:1;
 861     F(i) F(j) F(k) F(l){
 862         re double p=pre[sa[k]][lim-1];
 863         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 864         for(re int q=0;q<=16;++q){
 865             re double gl=g[abs(val)][q];
 866             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 867             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
 868         }
 869     }
 870 }
 871 void saknxw(int id,int lim,int val){
 872     re int flag=(val<0)?-1:1;
 873     F(i) F(j) F(k) F(l){
 874         re double p=pre[sa[k]][lim-1];
 875         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 876         for(re int q=0;q<=16;++q){
 877             re double gl=g[abs(val)][q];
 878             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 879             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
 880         }
 881     }
 882 }
 883 void knmixw(int id,int lim,int val){
 884     re int flag=(val<0)?-1:1;
 885     F(i) F(j) F(k) F(l){
 886         re double p=pre[kn[l]][lim-1];
 887         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 888         for(re int q=0;q<=16;++q){
 889             re double gl=g[abs(val)][q];
 890             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 891             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
 892         }
 893     }
 894 }
 895 void knspxw(int id,int lim,int val){
 896     re int flag=(val<0)?-1:1;
 897     F(i) F(j) F(k) F(l){
 898         re double p=pre[kn[l]][lim-1];
 899         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 900         for(re int q=0;q<=16;++q){
 901             re double gl=g[abs(val)][q];
 902             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 903             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
 904         }
 905     }
 906 }
 907 void knsaxw(int id,int lim,int val){
 908     re int flag=(val<0)?-1:1;
 909     F(i) F(j) F(k) F(l){
 910         re double p=pre[kn[l]][lim-1];
 911         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 912         for(re int q=0;q<=16;++q){
 913             re double gl=g[abs(val)][q];
 914             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 915             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
 916         }
 917     }
 918 }
 919 void knknxw(int id,int lim,int val){
 920     re int flag=(val<0)?-1:1;
 921     F(i) F(j) F(k) F(l){
 922         re double p=pre[kn[l]][lim-1];
 923         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 924         for(re int q=0;q<=16;++q){
 925             re double gl=g[abs(val)][q];
 926             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 927             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
 928         }
 929     }
 930 }
 931 void mimiddw(int id,int lim,int val){
 932     re int flag=(val<0)?-1:1;
 933     F(i) F(j) F(k) F(l){
 934         re double p=suf[mi[i]][lim];
 935         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 936         for(re int q=0;q<=16;++q){
 937             re double gl=g[abs(val)][q];
 938             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 939             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
 940         }
 941     }
 942 }
 943 void mispddw(int id,int lim,int val){
 944     re int flag=(val<0)?-1:1;
 945     F(i) F(j) F(k) F(l){
 946         re double p=suf[mi[i]][lim];
 947         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 948         for(re int q=0;q<=16;++q){
 949             re double gl=g[abs(val)][q];
 950             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 951             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
 952         }
 953     }
 954 }
 955 void misaddw(int id,int lim,int val){
 956     re int flag=(val<0)?-1:1;
 957     F(i) F(j) F(k) F(l){
 958         re double p=suf[mi[i]][lim];
 959         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 960         for(re int q=0;q<=16;++q){
 961             re double gl=g[abs(val)][q];
 962             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 963             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
 964         }
 965     }
 966 }
 967 void miknddw(int id,int lim,int val){
 968     re int flag=(val<0)?-1:1;
 969     F(i) F(j) F(k) F(l){
 970         re double p=suf[mi[i]][lim];
 971         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 972         for(re int q=0;q<=16;++q){
 973             re double gl=g[abs(val)][q];
 974             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 975             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
 976         }
 977     }
 978 }
 979 void spmiddw(int id,int lim,int val){
 980     re int flag=(val<0)?-1:1;
 981     F(i) F(j) F(k) F(l){
 982         re double p=suf[sp[j]][lim];
 983         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 984         for(re int q=0;q<=16;++q){
 985             re double gl=g[abs(val)][q];
 986             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 987             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
 988         }
 989     }
 990 }
 991 void spspddw(int id,int lim,int val){
 992     re int flag=(val<0)?-1:1;
 993     F(i) F(j) F(k) F(l){
 994         re double p=suf[sp[j]][lim];
 995         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 996         for(re int q=0;q<=16;++q){
 997             re double gl=g[abs(val)][q];
 998             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 999             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1000         }
1001     }
1002 }
1003 void spsaddw(int id,int lim,int val){
1004     re int flag=(val<0)?-1:1;
1005     F(i) F(j) F(k) F(l){
1006         re double p=suf[sp[j]][lim];
1007         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1008         for(re int q=0;q<=16;++q){
1009             re double gl=g[abs(val)][q];
1010             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1011             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1012         }
1013     }
1014 }
1015 void spknddw(int id,int lim,int val){
1016     re int flag=(val<0)?-1:1;
1017     F(i) F(j) F(k) F(l){
1018         re double p=suf[sp[j]][lim];
1019         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1020         for(re int q=0;q<=16;++q){
1021             re double gl=g[abs(val)][q];
1022             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1023             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1024         }
1025     }
1026 }
1027 void samiddw(int id,int lim,int val){
1028     re int flag=(val<0)?-1:1;
1029     F(i) F(j) F(k) F(l){
1030         re double p=suf[sa[k]][lim];
1031         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1032         for(re int q=0;q<=16;++q){
1033             re double gl=g[abs(val)][q];
1034             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1035             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1036         }
1037     }
1038 }
1039 void saspddw(int id,int lim,int val){
1040     re int flag=(val<0)?-1:1;
1041     F(i) F(j) F(k) F(l){
1042         re double p=suf[sa[k]][lim];
1043         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1044         for(re int q=0;q<=16;++q){
1045             re double gl=g[abs(val)][q];
1046             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1047             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1048         }
1049     }
1050 }
1051 void sasaddw(int id,int lim,int val){
1052     re int flag=(val<0)?-1:1;
1053     F(i) F(j) F(k) F(l){
1054         re double p=suf[sa[k]][lim];
1055         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1056         for(re int q=0;q<=16;++q){
1057             re double gl=g[abs(val)][q];
1058             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1059             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1060         }
1061     }
1062 }
1063 void saknddw(int id,int lim,int val){
1064     re int flag=(val<0)?-1:1;
1065     F(i) F(j) F(k) F(l){
1066         re double p=suf[sa[k]][lim];
1067         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1068         for(re int q=0;q<=16;++q){
1069             re double gl=g[abs(val)][q];
1070             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1071             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1072         }
1073     }
1074 }
1075 void knmiddw(int id,int lim,int val){
1076     re int flag=(val<0)?-1:1;
1077     F(i) F(j) F(k) F(l){
1078         re double p=suf[kn[l]][lim];
1079         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1080         for(re int q=0;q<=16;++q){
1081             re double gl=g[abs(val)][q];
1082             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1083             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1084         }
1085     }
1086 }
1087 void knspddw(int id,int lim,int val){
1088     re int flag=(val<0)?-1:1;
1089     F(i) F(j) F(k) F(l){
1090         re double p=suf[kn[l]][lim];
1091         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1092         for(re int q=0;q<=16;++q){
1093             re double gl=g[abs(val)][q];
1094             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1095             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1096         }
1097     }
1098 }
1099 void knsaddw(int id,int lim,int val){
1100     re int flag=(val<0)?-1:1;
1101     F(i) F(j) F(k) F(l){
1102         re double p=suf[kn[l]][lim];
1103         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1104         for(re int q=0;q<=16;++q){
1105             re double gl=g[abs(val)][q];
1106             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1107             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1108         }
1109     }
1110 }
1111 void knknddw(int id,int lim,int val){
1112     re int flag=(val<0)?-1:1;
1113     F(i) F(j) F(k) F(l){
1114         re double p=suf[kn[l]][lim];
1115         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1116         for(re int q=0;q<=16;++q){
1117             re double gl=g[abs(val)][q];
1118             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1119             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1120         }
1121     }
1122 }
1123 void mimidw(int id,int lim,int val){
1124     re int flag=(val<0)?-1:1;
1125     F(i) F(j) F(k) F(l){
1126         re double p=suf[mi[i]][lim+1];
1127         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1128         for(re int q=0;q<=16;++q){
1129             re double gl=g[abs(val)][q];
1130             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1131             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1132         }
1133     }
1134 }
1135 void mispdw(int id,int lim,int val){
1136     re int flag=(val<0)?-1:1;
1137     F(i) F(j) F(k) F(l){
1138         re double p=suf[mi[i]][lim+1];
1139         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1140         for(re int q=0;q<=16;++q){
1141             re double gl=g[abs(val)][q];
1142             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1143             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1144         }
1145     }
1146 }
1147 void misadw(int id,int lim,int val){
1148     re int flag=(val<0)?-1:1;
1149     F(i) F(j) F(k) F(l){
1150         re double p=suf[mi[i]][lim+1];
1151         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1152         for(re int q=0;q<=16;++q){
1153             re double gl=g[abs(val)][q];
1154             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1155             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1156         }
1157     }
1158 }
1159 void mikndw(int id,int lim,int val){
1160     re int flag=(val<0)?-1:1;
1161     F(i) F(j) F(k) F(l){
1162         re double p=suf[mi[i]][lim+1];
1163         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1164         for(re int q=0;q<=16;++q){
1165             re double gl=g[abs(val)][q];
1166             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1167             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1168         }
1169     }
1170 }
1171 void spmidw(int id,int lim,int val){
1172     re int flag=(val<0)?-1:1;
1173     F(i) F(j) F(k) F(l){
1174         re double p=suf[sp[j]][lim+1];
1175         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1176         for(re int q=0;q<=16;++q){
1177             re double gl=g[abs(val)][q];
1178             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1179             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1180         }
1181     }
1182 }
1183 void spspdw(int id,int lim,int val){
1184     re int flag=(val<0)?-1:1;
1185     F(i) F(j) F(k) F(l){
1186         re double p=suf[sp[j]][lim+1];
1187         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1188         for(re int q=0;q<=16;++q){
1189             re double gl=g[abs(val)][q];
1190             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1191             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1192         }
1193     }
1194 }
1195 void spsadw(int id,int lim,int val){
1196     re int flag=(val<0)?-1:1;
1197     F(i) F(j) F(k) F(l){
1198         re double p=suf[sp[j]][lim+1];
1199         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1200         for(re int q=0;q<=16;++q){
1201             re double gl=g[abs(val)][q];
1202             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1203             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1204         }
1205     }
1206 }
1207 void spkndw(int id,int lim,int val){
1208     re int flag=(val<0)?-1:1;
1209     F(i) F(j) F(k) F(l){
1210         re double p=suf[sp[j]][lim+1];
1211         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1212         for(re int q=0;q<=16;++q){
1213             re double gl=g[abs(val)][q];
1214             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1215             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1216         }
1217     }
1218 }
1219 void samidw(int id,int lim,int val){
1220     re int flag=(val<0)?-1:1;
1221     F(i) F(j) F(k) F(l){
1222         re double p=suf[sa[k]][lim+1];
1223         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1224         for(re int q=0;q<=16;++q){
1225             re double gl=g[abs(val)][q];
1226             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1227             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1228         }
1229     }
1230 }
1231 void saspdw(int id,int lim,int val){
1232     re int flag=(val<0)?-1:1;
1233     F(i) F(j) F(k) F(l){
1234         re double p=suf[sa[k]][lim+1];
1235         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1236         for(re int q=0;q<=16;++q){
1237             re double gl=g[abs(val)][q];
1238             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1239             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1240         }
1241     }
1242 }
1243 void sasadw(int id,int lim,int val){
1244     re int flag=(val<0)?-1:1;
1245     F(i) F(j) F(k) F(l){
1246         re double p=suf[sa[k]][lim+1];
1247         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1248         for(re int q=0;q<=16;++q){
1249             re double gl=g[abs(val)][q];
1250             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1251             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1252         }
1253     }
1254 }
1255 void sakndw(int id,int lim,int val){
1256     re int flag=(val<0)?-1:1;
1257     F(i) F(j) F(k) F(l){
1258         re double p=suf[sa[k]][lim+1];
1259         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1260         for(re int q=0;q<=16;++q){
1261             re double gl=g[abs(val)][q];
1262             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1263             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1264         }
1265     }
1266 }
1267 void knmidw(int id,int lim,int val){
1268     re int flag=(val<0)?-1:1;
1269     F(i) F(j) F(k) F(l){
1270         re double p=suf[kn[l]][lim+1];
1271         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1272         for(re int q=0;q<=16;++q){
1273             re double gl=g[abs(val)][q];
1274             if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1275             else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1276         }
1277     }
1278 }
1279 void knspdw(int id,int lim,int val){
1280     re int flag=(val<0)?-1:1;
1281     F(i) F(j) F(k) F(l){
1282         re double p=suf[kn[l]][lim+1];
1283         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1284         for(re int q=0;q<=16;++q){
1285             re double gl=g[abs(val)][q];
1286             if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1287             else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1288         }
1289     }
1290 }
1291 void knsadw(int id,int lim,int val){
1292     re int flag=(val<0)?-1:1;
1293     F(i) F(j) F(k) F(l){
1294         re double p=suf[kn[l]][lim+1];
1295         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1296         for(re int q=0;q<=16;++q){
1297             re double gl=g[abs(val)][q];
1298             if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1299             else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1300         }
1301     }
1302 }
1303 void knkndw(int id,int lim,int val){
1304     re int flag=(val<0)?-1:1;
1305     F(i) F(j) F(k) F(l){
1306         re double p=suf[kn[l]][lim+1];
1307         f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1308         for(re int q=0;q<=16;++q){
1309             re double gl=g[abs(val)][q];
1310             if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1311             else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1312         }
1313     }
1314 }
1315 signed main(){
1316     scanf("%s%d",s+1,&MI);F(i) mi[i]=s[i]-'0';
1317     scanf("%s%d",s+1,&SP);F(i) sp[i]=s[i]-'0';
1318     scanf("%s%d",s+1,&SA);F(i) sa[i]=s[i]-'0';
1319     scanf("%s%d",s+1,&KN);F(i) kn[i]=s[i]-'0';
1320     f[0][MI][SP][SA][KN]=1.0; 
1321     scanf("%d",&n);  g[0][0]=1.0;
1322     for(re int i=0;i<8;++i)
1323         for(re int j=0;j<=16;++j){
1324             g[i+1][j+0]+=g[i][j]*1.0/3.0;
1325             g[i+1][j+1]+=g[i][j]*1.0/3.0;
1326             g[i+1][j+2]+=g[i][j]*1.0/3.0;
1327         }
1328     for(re int i=1;i<=8;++i){
1329         pre[i][0]=g[i][0];
1330         for(re int j=1;j<=16;++j)
1331             pre[i][j]=g[i][j]+pre[i][j-1];
1332     }
1333     for(re int i=8;i>=1;--i){
1334         suf[i][17]=g[i][17];
1335         for(re int j=16;j>=0;--j)
1336             suf[i][j]=g[i][j]+suf[i][j+1];
1337     }
1338     for(re int id=1;id<=n;++id){
1339         scanf("%s%s",s1+1,s2+1);
1340         if(s2[1]=='+'||s2[1]=='-'){
1341             re int val=s2[2]-'0';
1342             if(s2[1]=='-') val=-val;
1343             if(s2[3]=='?'){
1344                 re int dat=abs(val); 
1345                 re int flag=(s2[1]=='-')?-1:1;
1346                 for(re int i=0;i<=16;++i){
1347                     if(s1[2]=='i') addmi(id,i*flag,g[dat][i]);
1348                     if(s1[2]=='p') addsp(id,i*flag,g[dat][i]);
1349                     if(s1[2]=='a') addsa(id,i*flag,g[dat][i]);
1350                     if(s1[2]=='n') addkn(id,i*flag,g[dat][i]);
1351                 }
1352             }
1353             else{
1354                 if(s1[2]=='i') addmi(id,val,1);
1355                 if(s1[2]=='p') addsp(id,val,1);
1356                 if(s1[2]=='a') addsa(id,val,1);
1357                 if(s1[2]=='n') addkn(id,val,1);
1358             }
1359             continue;
1360         }
1361         else if(s2[1]=='>'||s2[1]=='<'){
1362             re int dat;
1363             scanf("%d%s%s",&dat,s3+1,s4+1);
1364             re int val=s4[2]-'0';
1365             re int flag=(s4[1]=='-')?-1:1;
1366             if(s4[3]=='?'){
1367                 if(s2[1]=='>'&&s2[2]=='='){
1368                     if(s1[2]=='i'){
1369                         if(s3[2]=='i') mimiddw(id,dat,val*flag);
1370                         if(s3[2]=='p') mispddw(id,dat,val*flag);
1371                         if(s3[2]=='a') misaddw(id,dat,val*flag);
1372                         if(s3[2]=='n') miknddw(id,dat,val*flag);    
1373                         continue;
1374                     }
1375                     if(s1[2]=='p'){
1376                         if(s3[2]=='i') spmiddw(id,dat,val*flag);
1377                         if(s3[2]=='p') spspddw(id,dat,val*flag);
1378                         if(s3[2]=='a') spsaddw(id,dat,val*flag);
1379                         if(s3[2]=='n') spknddw(id,dat,val*flag);
1380                         continue;
1381                     }
1382                     if(s1[2]=='a'){
1383                         if(s3[2]=='i') samiddw(id,dat,val*flag);
1384                         if(s3[2]=='p') saspddw(id,dat,val*flag);
1385                         if(s3[2]=='a') sasaddw(id,dat,val*flag);
1386                         if(s3[2]=='n') saknddw(id,dat,val*flag);
1387                         continue;
1388                     }
1389                     if(s1[2]=='n'){
1390                         if(s3[2]=='i') knmiddw(id,dat,val*flag);
1391                         if(s3[2]=='p') knspddw(id,dat,val*flag);
1392                         if(s3[2]=='a') knsaddw(id,dat,val*flag);
1393                         if(s3[2]=='n') knknddw(id,dat,val*flag);
1394                         continue;
1395                     }
1396                 }
1397                 else if(s2[1]=='<'&&s2[2]=='='){
1398                     if(s1[2]=='i'){
1399                         if(s3[2]=='i') mimixdw(id,dat,val*flag);
1400                         if(s3[2]=='p') mispxdw(id,dat,val*flag);
1401                         if(s3[2]=='a') misaxdw(id,dat,val*flag);
1402                         if(s3[2]=='n') miknxdw(id,dat,val*flag);
1403                         continue;    
1404                     }
1405                     if(s1[2]=='p'){
1406                         if(s3[2]=='i') spmixdw(id,dat,val*flag);
1407                         if(s3[2]=='p') spspxdw(id,dat,val*flag);
1408                         if(s3[2]=='a') spsaxdw(id,dat,val*flag);
1409                         if(s3[2]=='n') spknxdw(id,dat,val*flag);
1410                         continue;
1411                     }
1412                     if(s1[2]=='a'){
1413                         if(s3[2]=='i') samixdw(id,dat,val*flag);
1414                         if(s3[2]=='p') saspxdw(id,dat,val*flag);
1415                         if(s3[2]=='a') sasaxdw(id,dat,val*flag);
1416                         if(s3[2]=='n') saknxdw(id,dat,val*flag);
1417                         continue;
1418                     }
1419                     if(s1[2]=='n'){
1420                         if(s3[2]=='i') knmixdw(id,dat,val*flag);
1421                         if(s3[2]=='p') knspxdw(id,dat,val*flag);
1422                         if(s3[2]=='a') knsaxdw(id,dat,val*flag);
1423                         if(s3[2]=='n') knknxdw(id,dat,val*flag);
1424                         continue;
1425                     }
1426                 }
1427                 else if(s2[1]=='>'){
1428                     if(s1[2]=='i'){
1429                         if(s3[2]=='i') mimidw(id,dat,val*flag);
1430                         if(s3[2]=='p') mispdw(id,dat,val*flag);
1431                         if(s3[2]=='a') misadw(id,dat,val*flag);
1432                         if(s3[2]=='n') mikndw(id,dat,val*flag);    
1433                         continue;
1434                     }
1435                     if(s1[2]=='p'){
1436                         if(s3[2]=='i') spmidw(id,dat,val*flag);
1437                         if(s3[2]=='p') spspdw(id,dat,val*flag);
1438                         if(s3[2]=='a') spsadw(id,dat,val*flag);
1439                         if(s3[2]=='n') spkndw(id,dat,val*flag);
1440                         continue;
1441                     }
1442                     if(s1[2]=='a'){
1443                         if(s3[2]=='i') samidw(id,dat,val*flag);
1444                         if(s3[2]=='p') saspdw(id,dat,val*flag);
1445                         if(s3[2]=='a') sasadw(id,dat,val*flag);
1446                         if(s3[2]=='n') sakndw(id,dat,val*flag);
1447                         continue;
1448                     }
1449                     if(s1[2]=='n'){
1450                         if(s3[2]=='i') knmidw(id,dat,val*flag);
1451                         if(s3[2]=='p') knspdw(id,dat,val*flag);
1452                         if(s3[2]=='a') knsadw(id,dat,val*flag);
1453                         if(s3[2]=='n') knkndw(id,dat,val*flag);
1454                         continue;
1455                     }
1456                 }
1457                 else if(s2[1]=='<'){
1458                     if(s1[2]=='i'){
1459                         if(s3[2]=='i') mimixw(id,dat,val*flag);
1460                         if(s3[2]=='p') mispxw(id,dat,val*flag);
1461                         if(s3[2]=='a') misaxw(id,dat,val*flag);
1462                         if(s3[2]=='n') miknxw(id,dat,val*flag);    
1463                         continue;
1464                     }
1465                     if(s1[2]=='p'){
1466                         if(s3[2]=='i') spmixw(id,dat,val*flag);
1467                         if(s3[2]=='p') spspxw(id,dat,val*flag);
1468                         if(s3[2]=='a') spsaxw(id,dat,val*flag);
1469                         if(s3[2]=='n') spknxw(id,dat,val*flag);
1470                         continue;
1471                     }
1472                     if(s1[2]=='a'){
1473                         if(s3[2]=='i') samixw(id,dat,val*flag);
1474                         if(s3[2]=='p') saspxw(id,dat,val*flag);
1475                         if(s3[2]=='a') sasaxw(id,dat,val*flag);
1476                         if(s3[2]=='n') saknxw(id,dat,val*flag);
1477                         continue;
1478                     }
1479                     if(s1[2]=='n'){
1480                         if(s3[2]=='i') knmixw(id,dat,val*flag);
1481                         if(s3[2]=='p') knspxw(id,dat,val*flag);
1482                         if(s3[2]=='a') knsaxw(id,dat,val*flag);
1483                         if(s3[2]=='n') knknxw(id,dat,val*flag);
1484                         continue;
1485                     }
1486                 }
1487             }
1488             else{
1489                 if(s2[1]=='>'&&s2[2]=='='){
1490                     if(s1[2]=='i'){
1491                         if(s3[2]=='i') mimidd(id,dat,val*flag);
1492                         if(s3[2]=='p') mispdd(id,dat,val*flag);
1493                         if(s3[2]=='a') misadd(id,dat,val*flag);
1494                         if(s3[2]=='n') mikndd(id,dat,val*flag);    
1495                         continue;
1496                     }
1497                     if(s1[2]=='p'){
1498                         if(s3[2]=='i') spmidd(id,dat,val*flag);
1499                         if(s3[2]=='p') spspdd(id,dat,val*flag);
1500                         if(s3[2]=='a') spsadd(id,dat,val*flag);
1501                         if(s3[2]=='n') spkndd(id,dat,val*flag);
1502                         continue;
1503                     }
1504                     if(s1[2]=='a'){
1505                         if(s3[2]=='i') samidd(id,dat,val*flag);
1506                         if(s3[2]=='p') saspdd(id,dat,val*flag);
1507                         if(s3[2]=='a') sasadd(id,dat,val*flag);
1508                         if(s3[2]=='n') sakndd(id,dat,val*flag);
1509                         continue;
1510                     }
1511                     if(s1[2]=='n'){
1512                         if(s3[2]=='i') knmidd(id,dat,val*flag);
1513                         if(s3[2]=='p') knspdd(id,dat,val*flag);
1514                         if(s3[2]=='a') knsadd(id,dat,val*flag);
1515                         if(s3[2]=='n') knkndd(id,dat,val*flag);
1516                         continue;
1517                     }
1518                 }
1519                 else if(s2[1]=='<'&&s2[2]=='='){
1520                     if(s1[2]=='i'){
1521                         if(s3[2]=='i') mimixd(id,dat,val*flag);
1522                         if(s3[2]=='p') mispxd(id,dat,val*flag);
1523                         if(s3[2]=='a') misaxd(id,dat,val*flag);
1524                         if(s3[2]=='n') miknxd(id,dat,val*flag);    
1525                         continue;
1526                     }
1527                     if(s1[2]=='p'){
1528                         if(s3[2]=='i') spmixd(id,dat,val*flag);
1529                         if(s3[2]=='p') spspxd(id,dat,val*flag);
1530                         if(s3[2]=='a') spsaxd(id,dat,val*flag);
1531                         if(s3[2]=='n') spknxd(id,dat,val*flag);
1532                         continue;
1533                     }
1534                     if(s1[2]=='a'){
1535                         if(s3[2]=='i') samixd(id,dat,val*flag);
1536                         if(s3[2]=='p') saspxd(id,dat,val*flag);
1537                         if(s3[2]=='a') sasaxd(id,dat,val*flag);
1538                         if(s3[2]=='n') saknxd(id,dat,val*flag);
1539                         continue;
1540                     }
1541                     if(s1[2]=='n'){
1542                         if(s3[2]=='i') knmixd(id,dat,val*flag);
1543                         if(s3[2]=='p') knspxd(id,dat,val*flag);
1544                         if(s3[2]=='a') knsaxd(id,dat,val*flag);
1545                         if(s3[2]=='n') knknxd(id,dat,val*flag);
1546                         continue;
1547                     }
1548                 }
1549                 else if(s2[1]=='>'){
1550                     if(s1[2]=='i'){
1551                         if(s3[2]=='i') mimid(id,dat,val*flag);
1552                         if(s3[2]=='p') mispd(id,dat,val*flag);
1553                         if(s3[2]=='a') misad(id,dat,val*flag);
1554                         if(s3[2]=='n') miknd(id,dat,val*flag);    
1555                         continue;
1556                     }
1557                     if(s1[2]=='p'){
1558                         if(s3[2]=='i') spmid(id,dat,val*flag);
1559                         if(s3[2]=='p') spspd(id,dat,val*flag);
1560                         if(s3[2]=='a') spsad(id,dat,val*flag);
1561                         if(s3[2]=='n') spknd(id,dat,val*flag);
1562                         continue;
1563                     }
1564                     if(s1[2]=='a'){
1565                         if(s3[2]=='i') samid(id,dat,val*flag);
1566                         if(s3[2]=='p') saspd(id,dat,val*flag);
1567                         if(s3[2]=='a') sasad(id,dat,val*flag);
1568                         if(s3[2]=='n') saknd(id,dat,val*flag);
1569                         continue;
1570                     }
1571                     if(s1[2]=='n'){
1572                         if(s3[2]=='i') knmid(id,dat,val*flag);
1573                         if(s3[2]=='p') knspd(id,dat,val*flag);
1574                         if(s3[2]=='a') knsad(id,dat,val*flag);
1575                         if(s3[2]=='n') knknd(id,dat,val*flag);
1576                         continue;
1577                     }
1578                 }
1579                 else if(s2[1]=='<'){
1580                     if(s1[2]=='i'){
1581                         if(s3[2]=='i') mimix(id,dat,val*flag);
1582                         if(s3[2]=='p') mispx(id,dat,val*flag);
1583                         if(s3[2]=='a') misax(id,dat,val*flag);
1584                         if(s3[2]=='n') miknx(id,dat,val*flag);    
1585                         continue;
1586                     }
1587                     if(s1[2]=='p'){
1588                         if(s3[2]=='i') spmix(id,dat,val*flag);
1589                         if(s3[2]=='p') spspx(id,dat,val*flag);
1590                         if(s3[2]=='a') spsax(id,dat,val*flag);
1591                         if(s3[2]=='n') spknx(id,dat,val*flag);
1592                         continue;
1593                     }
1594                     if(s1[2]=='a'){
1595                         if(s3[2]=='i') samix(id,dat,val*flag);
1596                         if(s3[2]=='p') saspx(id,dat,val*flag);
1597                         if(s3[2]=='a') sasax(id,dat,val*flag);
1598                         if(s3[2]=='n') saknx(id,dat,val*flag);
1599                         continue;
1600                     }
1601                     if(s1[2]=='n'){
1602                         if(s3[2]=='i') knmix(id,dat,val*flag);
1603                         if(s3[2]=='p') knspx(id,dat,val*flag);
1604                         if(s3[2]=='a') knsax(id,dat,val*flag);
1605                         if(s3[2]=='n') knknx(id,dat,val*flag);
1606                         continue;
1607                     }
1608                 }
1609             }
1610         }
1611     }
1612     printf("%.2lf\n",ANS*100.0);
1613     F(i) F(j) F(k) F(l){
1614         mig[mi[i]]+=f[n][i][j][k][l];
1615         spe[sp[j]]+=f[n][i][j][k][l];
1616         san[sa[k]]+=f[n][i][j][k][l];
1617         kno[kn[l]]+=f[n][i][j][k][l];
1618     }
1619     F(i) printf("%.2lf ",mig[i]*100.0);puts("");
1620     F(i) printf("%.2lf ",spe[i]*100.0);puts("");
1621     F(i) printf("%.2lf ",san[i]*100.0);puts("");
1622     F(i) printf("%.2lf ",kno[i]*100.0);puts("");
1623 }

 

   1 #include<bits/stdc++.h>
   2 using namespace std;
   3 int n,mi[10],sp[10],sa[10],kn[10],MI,SP,SA,KN;
   4 double f[110][10][10][10][10],g[10][20];
   5 double ANS,mig[10],spe[10],san[10],kno[10];
   6 char s[100],s1[100],s2[100],s3[100],s4[100];
   7 double pre[10][20],suf[10][20];
   8 inline void addmi(register int id,register int val,register double p){
   9     for(register int i=1;i<=8;++i)
  10     for(register int j=1;j<=8;++j)
  11         for(register int k=1;k<=8;++k)
  12         for(register int l=1;l<=8;++l){
  13             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  14             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
  15         }
  16 }
  17 inline void addsp(register int id,register int val,register double p){
  18     for(register int i=1;i<=8;++i)
  19     for(register int j=1;j<=8;++j)
  20         for(register int k=1;k<=8;++k)
  21         for(register int l=1;l<=8;++l){
  22             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  23             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
  24         }
  25 }
  26 inline void addsa(register int id,register int val,register double p){
  27     for(register int i=1;i<=8;++i)
  28     for(register int j=1;j<=8;++j)
  29         for(register int k=1;k<=8;++k)
  30         for(register int l=1;l<=8;++l){
  31             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  32             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
  33         }
  34 }
  35 inline void addkn(register int id,register int val,register double p){
  36     for(register int i=1;i<=8;++i)
  37     for(register int j=1;j<=8;++j)
  38         for(register int k=1;k<=8;++k)
  39         for(register int l=1;l<=8;++l){
  40             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  41             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
  42         }
  43 }
  44 inline void mimixd(register int id,register int lim,register int val){
  45     for(register int i=1;i<=8;++i)
  46     for(register int j=1;j<=8;++j)
  47         for(register int k=1;k<=8;++k)
  48         for(register int l=1;l<=8;++l){
  49             register double p=pre[mi[i]][lim];
  50             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
  51             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  52             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
  53         }
  54 }
  55 inline void mispxd(register int id,register int lim,register int val){
  56     for(register int i=1;i<=8;++i)
  57     for(register int j=1;j<=8;++j)
  58         for(register int k=1;k<=8;++k)
  59         for(register int l=1;l<=8;++l){
  60             register double p=pre[mi[i]][lim];
  61             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
  62             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  63             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
  64         }
  65 }
  66 inline void misaxd(register int id,register int lim,register int val){
  67     for(register int i=1;i<=8;++i)
  68     for(register int j=1;j<=8;++j)
  69         for(register int k=1;k<=8;++k)
  70         for(register int l=1;l<=8;++l){
  71             register double p=pre[mi[i]][lim];
  72             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
  73             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  74             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
  75         }
  76 }
  77 inline void miknxd(register int id,register int lim,register int val){
  78     for(register int i=1;i<=8;++i)
  79     for(register int j=1;j<=8;++j)
  80         for(register int k=1;k<=8;++k)
  81         for(register int l=1;l<=8;++l){
  82             register double p=pre[mi[i]][lim];
  83             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
  84             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  85             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
  86         }
  87 }
  88 inline void spmixd(register int id,register int lim,register int val){
  89     for(register int i=1;i<=8;++i)
  90     for(register int j=1;j<=8;++j)
  91         for(register int k=1;k<=8;++k)
  92         for(register int l=1;l<=8;++l){
  93             register double p=pre[sp[j]][lim];
  94             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
  95             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
  96             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
  97         }
  98 }
  99 inline void spspxd(register int id,register int lim,register int val){
 100     for(register int i=1;i<=8;++i)
 101     for(register int j=1;j<=8;++j)
 102         for(register int k=1;k<=8;++k)
 103         for(register int l=1;l<=8;++l){
 104             register double p=pre[sp[j]][lim];
 105             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 106             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 107             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 108         }
 109 }
 110 inline void spsaxd(register int id,register int lim,register int val){
 111     for(register int i=1;i<=8;++i)
 112     for(register int j=1;j<=8;++j)
 113         for(register int k=1;k<=8;++k)
 114         for(register int l=1;l<=8;++l){
 115             register double p=pre[sp[j]][lim];
 116             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 117             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 118             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 119         }
 120 }
 121 inline void spknxd(register int id,register int lim,register int val){
 122     for(register int i=1;i<=8;++i)
 123     for(register int j=1;j<=8;++j)
 124         for(register int k=1;k<=8;++k)
 125         for(register int l=1;l<=8;++l){
 126             register double p=pre[sp[j]][lim];
 127             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 128             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 129             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 130         }
 131 }
 132 inline void samixd(register int id,register int lim,register int val){
 133     for(register int i=1;i<=8;++i)
 134     for(register int j=1;j<=8;++j)
 135         for(register int k=1;k<=8;++k)
 136         for(register int l=1;l<=8;++l){
 137             register double p=pre[sa[k]][lim];
 138             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 139             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 140             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 141         }
 142 }
 143 inline void saspxd(register int id,register int lim,register int val){
 144     for(register int i=1;i<=8;++i)
 145     for(register int j=1;j<=8;++j)
 146         for(register int k=1;k<=8;++k)
 147         for(register int l=1;l<=8;++l){
 148             register double p=pre[sa[k]][lim];
 149             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 150             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 151             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 152         }
 153 }
 154 inline void sasaxd(register int id,register int lim,register int val){
 155     for(register int i=1;i<=8;++i)
 156     for(register int j=1;j<=8;++j)
 157         for(register int k=1;k<=8;++k)
 158         for(register int l=1;l<=8;++l){
 159             register double p=pre[sa[k]][lim];
 160             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 161             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 162             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 163         }
 164 }
 165 inline void saknxd(register int id,register int lim,register int val){
 166     for(register int i=1;i<=8;++i)
 167     for(register int j=1;j<=8;++j)
 168         for(register int k=1;k<=8;++k)
 169         for(register int l=1;l<=8;++l){
 170             register double p=pre[sa[k]][lim];
 171             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 172             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 173             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 174         }
 175 }
 176 inline void knmixd(register int id,register int lim,register int val){
 177     for(register int i=1;i<=8;++i)
 178     for(register int j=1;j<=8;++j)
 179         for(register int k=1;k<=8;++k)
 180         for(register int l=1;l<=8;++l){
 181             register double p=pre[kn[l]][lim];
 182             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 183             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 184             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 185         }
 186 }
 187 inline void knspxd(register int id,register int lim,register int val){
 188     for(register int i=1;i<=8;++i)
 189     for(register int j=1;j<=8;++j)
 190         for(register int k=1;k<=8;++k)
 191         for(register int l=1;l<=8;++l){
 192             register double p=pre[kn[l]][lim];
 193             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 194             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 195             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 196         }
 197 }
 198 inline void knsaxd(register int id,register int lim,register int val){
 199     for(register int i=1;i<=8;++i)
 200     for(register int j=1;j<=8;++j)
 201         for(register int k=1;k<=8;++k)
 202         for(register int l=1;l<=8;++l){
 203             register double p=pre[kn[l]][lim];
 204             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 205             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 206             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 207         }
 208 }
 209 inline void knknxd(register int id,register int lim,register int val){
 210     for(register int i=1;i<=8;++i)
 211     for(register int j=1;j<=8;++j)
 212         for(register int k=1;k<=8;++k)
 213         for(register int l=1;l<=8;++l){
 214             register double p=pre[kn[l]][lim];
 215             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 216             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 217             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 218         }
 219 }
 220 inline void mimix(register int id,register int lim,register int val){
 221     for(register int i=1;i<=8;++i)
 222     for(register int j=1;j<=8;++j)
 223         for(register int k=1;k<=8;++k)
 224         for(register int l=1;l<=8;++l){
 225             register double p=pre[mi[i]][lim-1];
 226             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 227             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 228             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 229         }
 230 }
 231 inline void mispx(register int id,register int lim,register int val){
 232     for(register int i=1;i<=8;++i)
 233     for(register int j=1;j<=8;++j)
 234         for(register int k=1;k<=8;++k)
 235         for(register int l=1;l<=8;++l){
 236             register double p=pre[mi[i]][lim-1];
 237             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 238             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 239             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 240         }
 241 }
 242 inline void misax(register int id,register int lim,register int val){
 243     for(register int i=1;i<=8;++i)
 244     for(register int j=1;j<=8;++j)
 245         for(register int k=1;k<=8;++k)
 246         for(register int l=1;l<=8;++l){
 247             register double p=pre[mi[i]][lim-1];
 248             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 249             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 250             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 251         }
 252 }
 253 inline void miknx(register int id,register int lim,register int val){
 254     for(register int i=1;i<=8;++i)
 255     for(register int j=1;j<=8;++j)
 256         for(register int k=1;k<=8;++k)
 257         for(register int l=1;l<=8;++l){
 258             register double p=pre[mi[i]][lim-1];
 259             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 260             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 261             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 262         }
 263 }
 264 inline void spmix(register int id,register int lim,register int val){
 265     for(register int i=1;i<=8;++i)
 266     for(register int j=1;j<=8;++j)
 267         for(register int k=1;k<=8;++k)
 268         for(register int l=1;l<=8;++l){
 269             register double p=pre[sp[j]][lim-1];
 270             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 271             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 272             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 273         }
 274 }
 275 inline void spspx(register int id,register int lim,register int val){
 276     for(register int i=1;i<=8;++i)
 277     for(register int j=1;j<=8;++j)
 278         for(register int k=1;k<=8;++k)
 279         for(register int l=1;l<=8;++l){
 280             register double p=pre[sp[j]][lim-1];
 281             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 282             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 283             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 284         }
 285 }
 286 inline void spsax(register int id,register int lim,register int val){
 287     for(register int i=1;i<=8;++i)
 288     for(register int j=1;j<=8;++j)
 289         for(register int k=1;k<=8;++k)
 290         for(register int l=1;l<=8;++l){
 291             register double p=pre[sp[j]][lim-1];
 292             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 293             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 294             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 295         }
 296 }
 297 inline void spknx(register int id,register int lim,register int val){
 298     for(register int i=1;i<=8;++i)
 299     for(register int j=1;j<=8;++j)
 300         for(register int k=1;k<=8;++k)
 301         for(register int l=1;l<=8;++l){
 302             register double p=pre[sp[j]][lim-1];
 303             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 304             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 305             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 306         }
 307 }
 308 inline void samix(register int id,register int lim,register int val){
 309     for(register int i=1;i<=8;++i)
 310     for(register int j=1;j<=8;++j)
 311         for(register int k=1;k<=8;++k)
 312         for(register int l=1;l<=8;++l){
 313             register double p=pre[sa[k]][lim-1];
 314             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 315             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 316             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 317         }
 318 }
 319 inline void saspx(register int id,register int lim,register int val){
 320     for(register int i=1;i<=8;++i)
 321     for(register int j=1;j<=8;++j)
 322         for(register int k=1;k<=8;++k)
 323         for(register int l=1;l<=8;++l){
 324             register double p=pre[sa[k]][lim-1];
 325             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 326             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 327             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 328         }
 329 }
 330 inline void sasax(register int id,register int lim,register int val){
 331     for(register int i=1;i<=8;++i)
 332     for(register int j=1;j<=8;++j)
 333         for(register int k=1;k<=8;++k)
 334         for(register int l=1;l<=8;++l){
 335             register double p=pre[sa[k]][lim-1];
 336             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 337             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 338             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 339         }
 340 }
 341 inline void saknx(register int id,register int lim,register int val){
 342     for(register int i=1;i<=8;++i)
 343     for(register int j=1;j<=8;++j)
 344         for(register int k=1;k<=8;++k)
 345         for(register int l=1;l<=8;++l){
 346             register double p=pre[sa[k]][lim-1];
 347             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 348             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 349             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 350         }
 351 }
 352 inline void knmix(register int id,register int lim,register int val){
 353     for(register int i=1;i<=8;++i)
 354     for(register int j=1;j<=8;++j)
 355         for(register int k=1;k<=8;++k)
 356         for(register int l=1;l<=8;++l){
 357             register double p=pre[kn[l]][lim-1];
 358             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 359             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 360             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 361         }
 362 }
 363 inline void knspx(register int id,register int lim,register int val){
 364     for(register int i=1;i<=8;++i)
 365     for(register int j=1;j<=8;++j)
 366         for(register int k=1;k<=8;++k)
 367         for(register int l=1;l<=8;++l){
 368             register double p=pre[kn[l]][lim-1];
 369             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 370             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 371             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 372         }
 373 }
 374 inline void knsax(register int id,register int lim,register int val){
 375     for(register int i=1;i<=8;++i)
 376     for(register int j=1;j<=8;++j)
 377         for(register int k=1;k<=8;++k)
 378         for(register int l=1;l<=8;++l){
 379             register double p=pre[kn[l]][lim-1];
 380             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 381             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 382             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 383         }
 384 }
 385 inline void knknx(register int id,register int lim,register int val){
 386     for(register int i=1;i<=8;++i)
 387     for(register int j=1;j<=8;++j)
 388         for(register int k=1;k<=8;++k)
 389         for(register int l=1;l<=8;++l){
 390             register double p=pre[kn[l]][lim-1];
 391             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 392             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 393             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 394         }
 395 }
 396 inline void mimidd(register int id,register int lim,register int val){
 397     for(register int i=1;i<=8;++i)
 398     for(register int j=1;j<=8;++j)
 399         for(register int k=1;k<=8;++k)
 400         for(register int l=1;l<=8;++l){
 401             register double p=suf[mi[i]][lim];
 402             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 403             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 404             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 405         }
 406 }
 407 inline void mispdd(register int id,register int lim,register int val){
 408     for(register int i=1;i<=8;++i)
 409     for(register int j=1;j<=8;++j)
 410         for(register int k=1;k<=8;++k)
 411         for(register int l=1;l<=8;++l){
 412             register double p=suf[mi[i]][lim];
 413             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 414             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 415             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 416         }
 417 }
 418 inline void misadd(register int id,register int lim,register int val){
 419     for(register int i=1;i<=8;++i)
 420     for(register int j=1;j<=8;++j)
 421         for(register int k=1;k<=8;++k)
 422         for(register int l=1;l<=8;++l){
 423             register double p=suf[mi[i]][lim];
 424             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 425             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 426             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 427         }
 428 }
 429 inline void mikndd(register int id,register int lim,register int val){
 430     for(register int i=1;i<=8;++i)
 431     for(register int j=1;j<=8;++j)
 432         for(register int k=1;k<=8;++k)
 433         for(register int l=1;l<=8;++l){
 434             register double p=suf[mi[i]][lim];
 435             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 436             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 437             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 438         }
 439 }
 440 inline void spmidd(register int id,register int lim,register int val){
 441     for(register int i=1;i<=8;++i)
 442     for(register int j=1;j<=8;++j)
 443         for(register int k=1;k<=8;++k)
 444         for(register int l=1;l<=8;++l){
 445             register double p=suf[sp[j]][lim];
 446             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 447             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 448             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 449         }
 450 }
 451 inline void spspdd(register int id,register int lim,register int val){
 452     for(register int i=1;i<=8;++i)
 453     for(register int j=1;j<=8;++j)
 454         for(register int k=1;k<=8;++k)
 455         for(register int l=1;l<=8;++l){
 456             register double p=suf[sp[j]][lim];
 457             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 458             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 459             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 460         }
 461 }
 462 inline void spsadd(register int id,register int lim,register int val){
 463     for(register int i=1;i<=8;++i)
 464     for(register int j=1;j<=8;++j)
 465         for(register int k=1;k<=8;++k)
 466         for(register int l=1;l<=8;++l){
 467             register double p=suf[sp[j]][lim];
 468             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 469             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 470             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 471         }
 472 }
 473 inline void spkndd(register int id,register int lim,register int val){
 474     for(register int i=1;i<=8;++i)
 475     for(register int j=1;j<=8;++j)
 476         for(register int k=1;k<=8;++k)
 477         for(register int l=1;l<=8;++l){
 478             register double p=suf[sp[j]][lim];
 479             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 480             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 481             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 482         }
 483 }
 484 inline void samidd(register int id,register int lim,register int val){
 485     for(register int i=1;i<=8;++i)
 486     for(register int j=1;j<=8;++j)
 487         for(register int k=1;k<=8;++k)
 488         for(register int l=1;l<=8;++l){
 489             register double p=suf[sa[k]][lim];
 490             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 491             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 492             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 493         }
 494 }
 495 inline void saspdd(register int id,register int lim,register int val){
 496     for(register int i=1;i<=8;++i)
 497     for(register int j=1;j<=8;++j)
 498         for(register int k=1;k<=8;++k)
 499         for(register int l=1;l<=8;++l){
 500             register double p=suf[sa[k]][lim];
 501             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 502             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 503             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 504         }
 505 }
 506 inline void sasadd(register int id,register int lim,register int val){
 507     for(register int i=1;i<=8;++i)
 508     for(register int j=1;j<=8;++j)
 509         for(register int k=1;k<=8;++k)
 510         for(register int l=1;l<=8;++l){
 511             register double p=suf[sa[k]][lim];
 512             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 513             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 514             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 515         }
 516 }
 517 inline void sakndd(register int id,register int lim,register int val){
 518     for(register int i=1;i<=8;++i)
 519     for(register int j=1;j<=8;++j)
 520         for(register int k=1;k<=8;++k)
 521         for(register int l=1;l<=8;++l){
 522             register double p=suf[sa[k]][lim];
 523             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 524             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 525             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 526         }
 527 }
 528 inline void knmidd(register int id,register int lim,register int val){
 529     for(register int i=1;i<=8;++i)
 530     for(register int j=1;j<=8;++j)
 531         for(register int k=1;k<=8;++k)
 532         for(register int l=1;l<=8;++l){
 533             register double p=suf[kn[l]][lim];
 534             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 535             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 536             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 537         }
 538 }
 539 inline void knspdd(register int id,register int lim,register int val){
 540     for(register int i=1;i<=8;++i)
 541     for(register int j=1;j<=8;++j)
 542         for(register int k=1;k<=8;++k)
 543         for(register int l=1;l<=8;++l){
 544             register double p=suf[kn[l]][lim];
 545             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 546             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 547             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 548         }
 549 }
 550 inline void knsadd(register int id,register int lim,register int val){
 551     for(register int i=1;i<=8;++i)
 552     for(register int j=1;j<=8;++j)
 553         for(register int k=1;k<=8;++k)
 554         for(register int l=1;l<=8;++l){
 555             register double p=suf[kn[l]][lim];
 556             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 557             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 558             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 559         }
 560 }
 561 inline void knkndd(register int id,register int lim,register int val){
 562     for(register int i=1;i<=8;++i)
 563     for(register int j=1;j<=8;++j)
 564         for(register int k=1;k<=8;++k)
 565         for(register int l=1;l<=8;++l){
 566             register double p=suf[kn[l]][lim];
 567             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 568             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 569             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 570         }
 571 }
 572 inline void mimid(register int id,register int lim,register int val){
 573     for(register int i=1;i<=8;++i)
 574     for(register int j=1;j<=8;++j)
 575         for(register int k=1;k<=8;++k)
 576         for(register int l=1;l<=8;++l){
 577             register double p=suf[mi[i]][lim+1];
 578             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 579             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 580             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 581         }
 582 }
 583 inline void mispd(register int id,register int lim,register int val){
 584     for(register int i=1;i<=8;++i)
 585     for(register int j=1;j<=8;++j)
 586         for(register int k=1;k<=8;++k)
 587         for(register int l=1;l<=8;++l){
 588             register double p=suf[mi[i]][lim+1];
 589             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 590             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 591             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 592         }
 593 }
 594 inline void misad(register int id,register int lim,register int val){
 595     for(register int i=1;i<=8;++i)
 596     for(register int j=1;j<=8;++j)
 597         for(register int k=1;k<=8;++k)
 598         for(register int l=1;l<=8;++l){
 599             register double p=suf[mi[i]][lim+1];
 600             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 601             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 602             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 603         }
 604 }
 605 inline void miknd(register int id,register int lim,register int val){
 606     for(register int i=1;i<=8;++i)
 607     for(register int j=1;j<=8;++j)
 608         for(register int k=1;k<=8;++k)
 609         for(register int l=1;l<=8;++l){
 610             register double p=suf[mi[i]][lim+1];
 611             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 612             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 613             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 614         }
 615 }
 616 inline void spmid(register int id,register int lim,register int val){
 617     for(register int i=1;i<=8;++i)
 618     for(register int j=1;j<=8;++j)
 619         for(register int k=1;k<=8;++k)
 620         for(register int l=1;l<=8;++l){
 621             register double p=suf[sp[j]][lim+1];
 622             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 623             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 624             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 625         }
 626 }
 627 inline void spspd(register int id,register int lim,register int val){
 628     for(register int i=1;i<=8;++i)
 629     for(register int j=1;j<=8;++j)
 630         for(register int k=1;k<=8;++k)
 631         for(register int l=1;l<=8;++l){
 632             register double p=suf[sp[j]][lim+1];
 633             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 634             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 635             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 636         }
 637 }
 638 inline void spsad(register int id,register int lim,register int val){
 639     for(register int i=1;i<=8;++i)
 640     for(register int j=1;j<=8;++j)
 641         for(register int k=1;k<=8;++k)
 642         for(register int l=1;l<=8;++l){
 643             register double p=suf[sp[j]][lim+1];
 644             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 645             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 646             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 647         }
 648 }
 649 inline void spknd(register int id,register int lim,register int val){
 650     for(register int i=1;i<=8;++i)
 651     for(register int j=1;j<=8;++j)
 652         for(register int k=1;k<=8;++k)
 653         for(register int l=1;l<=8;++l){
 654             register double p=suf[sp[j]][lim+1];
 655             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 656             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 657             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 658         }
 659 }
 660 inline void samid(register int id,register int lim,register int val){
 661     for(register int i=1;i<=8;++i)
 662     for(register int j=1;j<=8;++j)
 663         for(register int k=1;k<=8;++k)
 664         for(register int l=1;l<=8;++l){
 665             register double p=suf[sa[k]][lim+1];
 666             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 667             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 668             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 669         }
 670 }
 671 inline void saspd(register int id,register int lim,register int val){
 672     for(register int i=1;i<=8;++i)
 673     for(register int j=1;j<=8;++j)
 674         for(register int k=1;k<=8;++k)
 675         for(register int l=1;l<=8;++l){
 676             register double p=suf[sa[k]][lim+1];
 677             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 678             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 679             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 680         }
 681 }
 682 inline void sasad(register int id,register int lim,register int val){
 683     for(register int i=1;i<=8;++i)
 684     for(register int j=1;j<=8;++j)
 685         for(register int k=1;k<=8;++k)
 686         for(register int l=1;l<=8;++l){
 687             register double p=suf[sa[k]][lim+1];
 688             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 689             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 690             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 691         }
 692 }
 693 inline void saknd(register int id,register int lim,register int val){
 694     for(register int i=1;i<=8;++i)
 695     for(register int j=1;j<=8;++j)
 696         for(register int k=1;k<=8;++k)
 697         for(register int l=1;l<=8;++l){
 698             register double p=suf[sa[k]][lim+1];
 699             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 700             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 701             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 702         }
 703 }
 704 inline void knmid(register int id,register int lim,register int val){
 705     for(register int i=1;i<=8;++i)
 706     for(register int j=1;j<=8;++j)
 707         for(register int k=1;k<=8;++k)
 708         for(register int l=1;l<=8;++l){
 709             register double p=suf[kn[l]][lim+1];
 710             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 711             if(i+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 712             else f[id][min(8,i+val)][j][k][l]+=f[id-1][i][j][k][l]*p;
 713         }
 714 }
 715 inline void knspd(register int id,register int lim,register int val){
 716     for(register int i=1;i<=8;++i)
 717     for(register int j=1;j<=8;++j)
 718         for(register int k=1;k<=8;++k)
 719         for(register int l=1;l<=8;++l){
 720             register double p=suf[kn[l]][lim+1];
 721             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 722             if(j+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 723             else f[id][i][min(8,j+val)][k][l]+=f[id-1][i][j][k][l]*p;
 724         }
 725 }
 726 inline void knsad(register int id,register int lim,register int val){
 727     for(register int i=1;i<=8;++i)
 728     for(register int j=1;j<=8;++j)
 729         for(register int k=1;k<=8;++k)
 730         for(register int l=1;l<=8;++l){
 731             register double p=suf[kn[l]][lim+1];
 732             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 733             if(k+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 734             else f[id][i][j][min(8,k+val)][l]+=f[id-1][i][j][k][l]*p;
 735         }
 736 }
 737 inline void knknd(register int id,register int lim,register int val){
 738     for(register int i=1;i<=8;++i)
 739     for(register int j=1;j<=8;++j)
 740         for(register int k=1;k<=8;++k)
 741         for(register int l=1;l<=8;++l){
 742             register double p=suf[kn[l]][lim+1];
 743             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 744             if(l+val<=0) ANS+=f[id-1][i][j][k][l]*p;
 745             else f[id][i][j][k][min(8,l+val)]+=f[id-1][i][j][k][l]*p;
 746         }
 747 }
 748 inline void mimixdw(register int id,register int lim,register int val){
 749     register int flag=(val<0)?-1:1;
 750     for(register int i=1;i<=8;++i)
 751     for(register int j=1;j<=8;++j)
 752         for(register int k=1;k<=8;++k)
 753         for(register int l=1;l<=8;++l){
 754             register double p=pre[mi[i]][lim];
 755             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 756             for(register int q=0;q<=16;++q){
 757                 register double gl=g[abs(val)][q];
 758                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 759                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
 760             }
 761         }
 762 }    
 763 inline void mispxdw(register int id,register int lim,register int val){
 764     register int flag=(val<0)?-1:1;
 765     for(register int i=1;i<=8;++i)
 766     for(register int j=1;j<=8;++j)
 767         for(register int k=1;k<=8;++k)
 768         for(register int l=1;l<=8;++l){
 769             register double p=pre[mi[i]][lim];
 770             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 771             for(register int q=0;q<=16;++q){
 772                 register double gl=g[abs(val)][q];
 773                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 774                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
 775             }
 776         }
 777 }
 778 inline void misaxdw(register int id,register int lim,register int val){
 779     register int flag=(val<0)?-1:1;
 780     for(register int i=1;i<=8;++i)
 781     for(register int j=1;j<=8;++j)
 782         for(register int k=1;k<=8;++k)
 783         for(register int l=1;l<=8;++l){
 784             register double p=pre[mi[i]][lim];
 785             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 786             for(register int q=0;q<=16;++q){
 787                 register double gl=g[abs(val)][q];
 788                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 789                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
 790             }
 791         }
 792 }
 793 inline void miknxdw(register int id,register int lim,register int val){
 794     register int flag=(val<0)?-1:1;
 795     for(register int i=1;i<=8;++i)
 796     for(register int j=1;j<=8;++j)
 797         for(register int k=1;k<=8;++k)
 798         for(register int l=1;l<=8;++l){
 799             register double p=pre[mi[i]][lim];
 800             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 801             for(register int q=0;q<=16;++q){
 802                 register double gl=g[abs(val)][q];
 803                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 804                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
 805             }
 806         }
 807 }
 808 inline void spmixdw(register int id,register int lim,register int val){
 809     register int flag=(val<0)?-1:1;
 810     for(register int i=1;i<=8;++i)
 811     for(register int j=1;j<=8;++j)
 812         for(register int k=1;k<=8;++k)
 813         for(register int l=1;l<=8;++l){
 814             register double p=pre[sp[j]][lim];
 815             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 816             for(register int q=0;q<=16;++q){
 817                 register double gl=g[abs(val)][q];
 818                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 819                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
 820             }
 821         }
 822 }
 823 inline void spspxdw(register int id,register int lim,register int val){
 824     register int flag=(val<0)?-1:1;
 825     for(register int i=1;i<=8;++i)
 826     for(register int j=1;j<=8;++j)
 827         for(register int k=1;k<=8;++k)
 828         for(register int l=1;l<=8;++l){
 829             register double p=pre[sp[j]][lim];
 830             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 831             for(register int q=0;q<=16;++q){
 832                 register double gl=g[abs(val)][q];
 833                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 834                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
 835             }
 836         }
 837 }
 838 inline void spsaxdw(register int id,register int lim,register int val){
 839     register int flag=(val<0)?-1:1;
 840     for(register int i=1;i<=8;++i)
 841     for(register int j=1;j<=8;++j)
 842         for(register int k=1;k<=8;++k)
 843         for(register int l=1;l<=8;++l){
 844             register double p=pre[sp[j]][lim];
 845             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 846             for(register int q=0;q<=16;++q){
 847                 register double gl=g[abs(val)][q];
 848                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 849                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
 850             }
 851         }
 852 }
 853 inline void spknxdw(register int id,register int lim,register int val){
 854     register int flag=(val<0)?-1:1;
 855     for(register int i=1;i<=8;++i)
 856     for(register int j=1;j<=8;++j)
 857         for(register int k=1;k<=8;++k)
 858         for(register int l=1;l<=8;++l){
 859             register double p=pre[sp[j]][lim];
 860             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 861             for(register int q=0;q<=16;++q){
 862                 register double gl=g[abs(val)][q];
 863                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 864                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
 865             }
 866         }
 867 }
 868 inline void samixdw(register int id,register int lim,register int val){
 869     register int flag=(val<0)?-1:1;
 870     for(register int i=1;i<=8;++i)
 871     for(register int j=1;j<=8;++j)
 872         for(register int k=1;k<=8;++k)
 873         for(register int l=1;l<=8;++l){
 874             register double p=pre[sa[k]][lim];
 875             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 876             for(register int q=0;q<=16;++q){
 877                 register double gl=g[abs(val)][q];
 878                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 879                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
 880             }
 881         }
 882 }
 883 inline void saspxdw(register int id,register int lim,register int val){
 884     register int flag=(val<0)?-1:1;
 885     for(register int i=1;i<=8;++i)
 886     for(register int j=1;j<=8;++j)
 887         for(register int k=1;k<=8;++k)
 888         for(register int l=1;l<=8;++l){
 889             register double p=pre[sa[k]][lim];
 890             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 891             for(register int q=0;q<=16;++q){
 892                 register double gl=g[abs(val)][q];
 893                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 894                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
 895             }
 896         }
 897 }
 898 inline void sasaxdw(register int id,register int lim,register int val){
 899     register int flag=(val<0)?-1:1;
 900     for(register int i=1;i<=8;++i)
 901     for(register int j=1;j<=8;++j)
 902         for(register int k=1;k<=8;++k)
 903         for(register int l=1;l<=8;++l){
 904             register double p=pre[sa[k]][lim];
 905             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 906             for(register int q=0;q<=16;++q){
 907                 register double gl=g[abs(val)][q];
 908                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 909                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
 910             }
 911         }
 912 }
 913 inline void saknxdw(register int id,register int lim,register int val){
 914     register int flag=(val<0)?-1:1;
 915     for(register int i=1;i<=8;++i)
 916     for(register int j=1;j<=8;++j)
 917         for(register int k=1;k<=8;++k)
 918         for(register int l=1;l<=8;++l){
 919             register double p=pre[sa[k]][lim];
 920             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 921             for(register int q=0;q<=16;++q){
 922                 register double gl=g[abs(val)][q];
 923                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 924                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
 925             }
 926         }
 927 }
 928 inline void knmixdw(register int id,register int lim,register int val){
 929     register int flag=(val<0)?-1:1;
 930     for(register int i=1;i<=8;++i)
 931     for(register int j=1;j<=8;++j)
 932         for(register int k=1;k<=8;++k)
 933         for(register int l=1;l<=8;++l){
 934             register double p=pre[kn[l]][lim];
 935             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 936             for(register int q=0;q<=16;++q){
 937                 register double gl=g[abs(val)][q];
 938                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 939                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
 940             }
 941         }
 942 }
 943 inline void knspxdw(register int id,register int lim,register int val){
 944     register int flag=(val<0)?-1:1;
 945     for(register int i=1;i<=8;++i)
 946     for(register int j=1;j<=8;++j)
 947         for(register int k=1;k<=8;++k)
 948         for(register int l=1;l<=8;++l){
 949             register double p=pre[kn[l]][lim];
 950             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 951             for(register int q=0;q<=16;++q){
 952                 register double gl=g[abs(val)][q];
 953                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 954                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
 955             }
 956         }
 957 }
 958 inline void knsaxdw(register int id,register int lim,register int val){
 959     register int flag=(val<0)?-1:1;
 960     for(register int i=1;i<=8;++i)
 961     for(register int j=1;j<=8;++j)
 962         for(register int k=1;k<=8;++k)
 963         for(register int l=1;l<=8;++l){
 964             register double p=pre[kn[l]][lim];
 965             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 966             for(register int q=0;q<=16;++q){
 967                 register double gl=g[abs(val)][q];
 968                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 969                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
 970             }
 971         }
 972 }
 973 inline void knknxdw(register int id,register int lim,register int val){
 974     register int flag=(val<0)?-1:1;
 975     for(register int i=1;i<=8;++i)
 976     for(register int j=1;j<=8;++j)
 977         for(register int k=1;k<=8;++k)
 978         for(register int l=1;l<=8;++l){
 979             register double p=pre[kn[l]][lim];
 980             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 981             for(register int q=0;q<=16;++q){
 982                 register double gl=g[abs(val)][q];
 983                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 984                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
 985             }
 986         }
 987 }
 988 inline void mimixw(register int id,register int lim,register int val){
 989     register int flag=(val<0)?-1:1;
 990     for(register int i=1;i<=8;++i)
 991     for(register int j=1;j<=8;++j)
 992         for(register int k=1;k<=8;++k)
 993         for(register int l=1;l<=8;++l){
 994             register double p=pre[mi[i]][lim-1];
 995             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
 996             for(register int q=0;q<=16;++q){
 997                 register double gl=g[abs(val)][q];
 998                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
 999                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1000             }
1001         }
1002 }
1003 inline void mispxw(register int id,register int lim,register int val){
1004     register int flag=(val<0)?-1:1;
1005     for(register int i=1;i<=8;++i)
1006     for(register int j=1;j<=8;++j)
1007         for(register int k=1;k<=8;++k)
1008         for(register int l=1;l<=8;++l){
1009             register double p=pre[mi[i]][lim-1];
1010             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1011             for(register int q=0;q<=16;++q){
1012                 register double gl=g[abs(val)][q];
1013                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1014                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1015             }
1016         }
1017 }
1018 inline void misaxw(register int id,register int lim,register int val){
1019     register int flag=(val<0)?-1:1;
1020     for(register int i=1;i<=8;++i)
1021     for(register int j=1;j<=8;++j)
1022         for(register int k=1;k<=8;++k)
1023         for(register int l=1;l<=8;++l){
1024             register double p=pre[mi[i]][lim-1];
1025             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1026             for(register int q=0;q<=16;++q){
1027                 register double gl=g[abs(val)][q];
1028                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1029                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1030             }
1031         }
1032 }
1033 inline void miknxw(register int id,register int lim,register int val){
1034     register int flag=(val<0)?-1:1;
1035     for(register int i=1;i<=8;++i)
1036     for(register int j=1;j<=8;++j)
1037         for(register int k=1;k<=8;++k)
1038         for(register int l=1;l<=8;++l){
1039             register double p=pre[mi[i]][lim-1];
1040             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1041             for(register int q=0;q<=16;++q){
1042                 register double gl=g[abs(val)][q];
1043                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1044                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1045             }
1046         }
1047 }
1048 inline void spmixw(register int id,register int lim,register int val){
1049     register int flag=(val<0)?-1:1;
1050     for(register int i=1;i<=8;++i)
1051     for(register int j=1;j<=8;++j)
1052         for(register int k=1;k<=8;++k)
1053         for(register int l=1;l<=8;++l){
1054             register double p=pre[sp[j]][lim-1];
1055             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1056             for(register int q=0;q<=16;++q){
1057                 register double gl=g[abs(val)][q];
1058                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1059                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1060             }
1061         }
1062 }
1063 inline void spspxw(register int id,register int lim,register int val){
1064     register int flag=(val<0)?-1:1;
1065     for(register int i=1;i<=8;++i)
1066     for(register int j=1;j<=8;++j)
1067         for(register int k=1;k<=8;++k)
1068         for(register int l=1;l<=8;++l){
1069             register double p=pre[sp[j]][lim-1];
1070             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1071             for(register int q=0;q<=16;++q){
1072                 register double gl=g[abs(val)][q];
1073                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1074                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1075             }
1076         }
1077 }
1078 inline void spsaxw(register int id,register int lim,register int val){
1079     register int flag=(val<0)?-1:1;
1080     for(register int i=1;i<=8;++i)
1081     for(register int j=1;j<=8;++j)
1082         for(register int k=1;k<=8;++k)
1083         for(register int l=1;l<=8;++l){
1084             register double p=pre[sp[j]][lim-1];
1085             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1086             for(register int q=0;q<=16;++q){
1087                 register double gl=g[abs(val)][q];
1088                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1089                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1090             }
1091         }
1092 }
1093 inline void spknxw(register int id,register int lim,register int val){
1094     register int flag=(val<0)?-1:1;
1095     for(register int i=1;i<=8;++i)
1096     for(register int j=1;j<=8;++j)
1097         for(register int k=1;k<=8;++k)
1098         for(register int l=1;l<=8;++l){
1099             register double p=pre[sp[j]][lim-1];
1100             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1101             for(register int q=0;q<=16;++q){
1102                 register double gl=g[abs(val)][q];
1103                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1104                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1105             }
1106         }
1107 }
1108 inline void samixw(register int id,register int lim,register int val){
1109     register int flag=(val<0)?-1:1;
1110     for(register int i=1;i<=8;++i)
1111     for(register int j=1;j<=8;++j)
1112         for(register int k=1;k<=8;++k)
1113         for(register int l=1;l<=8;++l){
1114             register double p=pre[sa[k]][lim-1];
1115             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1116             for(register int q=0;q<=16;++q){
1117                 register double gl=g[abs(val)][q];
1118                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1119                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1120             }
1121         }
1122 }
1123 inline void saspxw(register int id,register int lim,register int val){
1124     register int flag=(val<0)?-1:1;
1125     for(register int i=1;i<=8;++i)
1126     for(register int j=1;j<=8;++j)
1127         for(register int k=1;k<=8;++k)
1128         for(register int l=1;l<=8;++l){
1129             register double p=pre[sa[k]][lim-1];
1130             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1131             for(register int q=0;q<=16;++q){
1132                 register double gl=g[abs(val)][q];
1133                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1134                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1135             }
1136         }
1137 }
1138 inline void sasaxw(register int id,register int lim,register int val){
1139     register int flag=(val<0)?-1:1;
1140     for(register int i=1;i<=8;++i)
1141     for(register int j=1;j<=8;++j)
1142         for(register int k=1;k<=8;++k)
1143         for(register int l=1;l<=8;++l){
1144             register double p=pre[sa[k]][lim-1];
1145             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1146             for(register int q=0;q<=16;++q){
1147                 register double gl=g[abs(val)][q];
1148                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1149                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1150             }
1151         }
1152 }
1153 inline void saknxw(register int id,register int lim,register int val){
1154     register int flag=(val<0)?-1:1;
1155     for(register int i=1;i<=8;++i)
1156     for(register int j=1;j<=8;++j)
1157         for(register int k=1;k<=8;++k)
1158         for(register int l=1;l<=8;++l){
1159             register double p=pre[sa[k]][lim-1];
1160             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1161             for(register int q=0;q<=16;++q){
1162                 register double gl=g[abs(val)][q];
1163                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1164                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1165             }
1166         }
1167 }
1168 inline void knmixw(register int id,register int lim,register int val){
1169     register int flag=(val<0)?-1:1;
1170     for(register int i=1;i<=8;++i)
1171     for(register int j=1;j<=8;++j)
1172         for(register int k=1;k<=8;++k)
1173         for(register int l=1;l<=8;++l){
1174             register double p=pre[kn[l]][lim-1];
1175             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1176             for(register int q=0;q<=16;++q){
1177                 register double gl=g[abs(val)][q];
1178                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1179                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1180             }
1181         }
1182 }
1183 inline void knspxw(register int id,register int lim,register int val){
1184     register int flag=(val<0)?-1:1;
1185     for(register int i=1;i<=8;++i)
1186     for(register int j=1;j<=8;++j)
1187         for(register int k=1;k<=8;++k)
1188         for(register int l=1;l<=8;++l){
1189             register double p=pre[kn[l]][lim-1];
1190             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1191             for(register int q=0;q<=16;++q){
1192                 register double gl=g[abs(val)][q];
1193                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1194                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1195             }
1196         }
1197 }
1198 inline void knsaxw(register int id,register int lim,register int val){
1199     register int flag=(val<0)?-1:1;
1200     for(register int i=1;i<=8;++i)
1201     for(register int j=1;j<=8;++j)
1202         for(register int k=1;k<=8;++k)
1203         for(register int l=1;l<=8;++l){
1204             register double p=pre[kn[l]][lim-1];
1205             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1206             for(register int q=0;q<=16;++q){
1207                 register double gl=g[abs(val)][q];
1208                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1209                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1210             }
1211         }
1212 }
1213 inline void knknxw(register int id,register int lim,register int val){
1214     register int flag=(val<0)?-1:1;
1215     for(register int i=1;i<=8;++i)
1216     for(register int j=1;j<=8;++j)
1217         for(register int k=1;k<=8;++k)
1218         for(register int l=1;l<=8;++l){
1219             register double p=pre[kn[l]][lim-1];
1220             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1221             for(register int q=0;q<=16;++q){
1222                 register double gl=g[abs(val)][q];
1223                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1224                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1225             }
1226         }
1227 }
1228 inline void mimiddw(register int id,register int lim,register int val){
1229     register int flag=(val<0)?-1:1;
1230     for(register int i=1;i<=8;++i)
1231     for(register int j=1;j<=8;++j)
1232         for(register int k=1;k<=8;++k)
1233         for(register int l=1;l<=8;++l){
1234             register double p=suf[mi[i]][lim];
1235             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1236             for(register int q=0;q<=16;++q){
1237                 register double gl=g[abs(val)][q];
1238                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1239                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1240             }
1241         }
1242 }
1243 inline void mispddw(register int id,register int lim,register int val){
1244     register int flag=(val<0)?-1:1;
1245     for(register int i=1;i<=8;++i)
1246     for(register int j=1;j<=8;++j)
1247         for(register int k=1;k<=8;++k)
1248         for(register int l=1;l<=8;++l){
1249             register double p=suf[mi[i]][lim];
1250             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1251             for(register int q=0;q<=16;++q){
1252                 register double gl=g[abs(val)][q];
1253                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1254                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1255             }
1256         }
1257 }
1258 inline void misaddw(register int id,register int lim,register int val){
1259     register int flag=(val<0)?-1:1;
1260     for(register int i=1;i<=8;++i)
1261     for(register int j=1;j<=8;++j)
1262         for(register int k=1;k<=8;++k)
1263         for(register int l=1;l<=8;++l){
1264             register double p=suf[mi[i]][lim];
1265             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1266             for(register int q=0;q<=16;++q){
1267                 register double gl=g[abs(val)][q];
1268                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1269                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1270             }
1271         }
1272 }
1273 inline void miknddw(register int id,register int lim,register int val){
1274     register int flag=(val<0)?-1:1;
1275     for(register int i=1;i<=8;++i)
1276     for(register int j=1;j<=8;++j)
1277         for(register int k=1;k<=8;++k)
1278         for(register int l=1;l<=8;++l){
1279             register double p=suf[mi[i]][lim];
1280             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1281             for(register int q=0;q<=16;++q){
1282                 register double gl=g[abs(val)][q];
1283                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1284                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1285             }
1286         }
1287 }
1288 inline void spmiddw(register int id,register int lim,register int val){
1289     register int flag=(val<0)?-1:1;
1290     for(register int i=1;i<=8;++i)
1291     for(register int j=1;j<=8;++j)
1292         for(register int k=1;k<=8;++k)
1293         for(register int l=1;l<=8;++l){
1294             register double p=suf[sp[j]][lim];
1295             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1296             for(register int q=0;q<=16;++q){
1297                 register double gl=g[abs(val)][q];
1298                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1299                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1300             }
1301         }
1302 }
1303 inline void spspddw(register int id,register int lim,register int val){
1304     register int flag=(val<0)?-1:1;
1305     for(register int i=1;i<=8;++i)
1306     for(register int j=1;j<=8;++j)
1307         for(register int k=1;k<=8;++k)
1308         for(register int l=1;l<=8;++l){
1309             register double p=suf[sp[j]][lim];
1310             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1311             for(register int q=0;q<=16;++q){
1312                 register double gl=g[abs(val)][q];
1313                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1314                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1315             }
1316         }
1317 }
1318 inline void spsaddw(register int id,register int lim,register int val){
1319     register int flag=(val<0)?-1:1;
1320     for(register int i=1;i<=8;++i)
1321     for(register int j=1;j<=8;++j)
1322         for(register int k=1;k<=8;++k)
1323         for(register int l=1;l<=8;++l){
1324             register double p=suf[sp[j]][lim];
1325             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1326             for(register int q=0;q<=16;++q){
1327                 register double gl=g[abs(val)][q];
1328                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1329                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1330             }
1331         }
1332 }
1333 inline void spknddw(register int id,register int lim,register int val){
1334     register int flag=(val<0)?-1:1;
1335     for(register int i=1;i<=8;++i)
1336     for(register int j=1;j<=8;++j)
1337         for(register int k=1;k<=8;++k)
1338         for(register int l=1;l<=8;++l){
1339             register double p=suf[sp[j]][lim];
1340             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1341             for(register int q=0;q<=16;++q){
1342                 register double gl=g[abs(val)][q];
1343                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1344                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1345             }
1346         }
1347 }
1348 inline void samiddw(register int id,register int lim,register int val){
1349     register int flag=(val<0)?-1:1;
1350     for(register int i=1;i<=8;++i)
1351     for(register int j=1;j<=8;++j)
1352         for(register int k=1;k<=8;++k)
1353         for(register int l=1;l<=8;++l){
1354             register double p=suf[sa[k]][lim];
1355             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1356             for(register int q=0;q<=16;++q){
1357                 register double gl=g[abs(val)][q];
1358                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1359                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1360             }
1361         }
1362 }
1363 inline void saspddw(register int id,register int lim,register int val){
1364     register int flag=(val<0)?-1:1;
1365     for(register int i=1;i<=8;++i)
1366     for(register int j=1;j<=8;++j)
1367         for(register int k=1;k<=8;++k)
1368         for(register int l=1;l<=8;++l){
1369             register double p=suf[sa[k]][lim];
1370             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1371             for(register int q=0;q<=16;++q){
1372                 register double gl=g[abs(val)][q];
1373                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1374                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1375             }
1376         }
1377 }
1378 inline void sasaddw(register int id,register int lim,register int val){
1379     register int flag=(val<0)?-1:1;
1380     for(register int i=1;i<=8;++i)
1381     for(register int j=1;j<=8;++j)
1382         for(register int k=1;k<=8;++k)
1383         for(register int l=1;l<=8;++l){
1384             register double p=suf[sa[k]][lim];
1385             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1386             for(register int q=0;q<=16;++q){
1387                 register double gl=g[abs(val)][q];
1388                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1389                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1390             }
1391         }
1392 }
1393 inline void saknddw(register int id,register int lim,register int val){
1394     register int flag=(val<0)?-1:1;
1395     for(register int i=1;i<=8;++i)
1396     for(register int j=1;j<=8;++j)
1397         for(register int k=1;k<=8;++k)
1398         for(register int l=1;l<=8;++l){
1399             register double p=suf[sa[k]][lim];
1400             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1401             for(register int q=0;q<=16;++q){
1402                 register double gl=g[abs(val)][q];
1403                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1404                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1405             }
1406         }
1407 }
1408 inline void knmiddw(register int id,register int lim,register int val){
1409     register int flag=(val<0)?-1:1;
1410     for(register int i=1;i<=8;++i)
1411     for(register int j=1;j<=8;++j)
1412         for(register int k=1;k<=8;++k)
1413         for(register int l=1;l<=8;++l){
1414             register double p=suf[kn[l]][lim];
1415             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1416             for(register int q=0;q<=16;++q){
1417                 register double gl=g[abs(val)][q];
1418                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1419                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1420             }
1421         }
1422 }
1423 inline void knspddw(register int id,register int lim,register int val){
1424     register int flag=(val<0)?-1:1;
1425     for(register int i=1;i<=8;++i)
1426     for(register int j=1;j<=8;++j)
1427         for(register int k=1;k<=8;++k)
1428         for(register int l=1;l<=8;++l){
1429             register double p=suf[kn[l]][lim];
1430             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1431             for(register int q=0;q<=16;++q){
1432                 register double gl=g[abs(val)][q];
1433                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1434                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1435             }
1436         }
1437 }
1438 inline void knsaddw(register int id,register int lim,register int val){
1439     register int flag=(val<0)?-1:1;
1440     for(register int i=1;i<=8;++i)
1441     for(register int j=1;j<=8;++j)
1442         for(register int k=1;k<=8;++k)
1443         for(register int l=1;l<=8;++l){
1444             register double p=suf[kn[l]][lim];
1445             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1446             for(register int q=0;q<=16;++q){
1447                 register double gl=g[abs(val)][q];
1448                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1449                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1450             }
1451         }
1452 }
1453 inline void knknddw(register int id,register int lim,register int val){
1454     register int flag=(val<0)?-1:1;
1455     for(register int i=1;i<=8;++i)
1456     for(register int j=1;j<=8;++j)
1457         for(register int k=1;k<=8;++k)
1458         for(register int l=1;l<=8;++l){
1459             register double p=suf[kn[l]][lim];
1460             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1461             for(register int q=0;q<=16;++q){
1462                 register double gl=g[abs(val)][q];
1463                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1464                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1465             }
1466         }
1467 }
1468 inline void mimidw(register int id,register int lim,register int val){
1469     register int flag=(val<0)?-1:1;
1470     for(register int i=1;i<=8;++i)
1471     for(register int j=1;j<=8;++j)
1472         for(register int k=1;k<=8;++k)
1473         for(register int l=1;l<=8;++l){
1474             register double p=suf[mi[i]][lim+1];
1475             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1476             for(register int q=0;q<=16;++q){
1477                 register double gl=g[abs(val)][q];
1478                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1479                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1480             }
1481         }
1482 }
1483 inline void mispdw(register int id,register int lim,register int val){
1484     register int flag=(val<0)?-1:1;
1485     for(register int i=1;i<=8;++i)
1486     for(register int j=1;j<=8;++j)
1487         for(register int k=1;k<=8;++k)
1488         for(register int l=1;l<=8;++l){
1489             register double p=suf[mi[i]][lim+1];
1490             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1491             for(register int q=0;q<=16;++q){
1492                 register double gl=g[abs(val)][q];
1493                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1494                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1495             }
1496         }
1497 }
1498 inline void misadw(register int id,register int lim,register int val){
1499     register int flag=(val<0)?-1:1;
1500     for(register int i=1;i<=8;++i)
1501     for(register int j=1;j<=8;++j)
1502         for(register int k=1;k<=8;++k)
1503         for(register int l=1;l<=8;++l){
1504             register double p=suf[mi[i]][lim+1];
1505             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1506             for(register int q=0;q<=16;++q){
1507                 register double gl=g[abs(val)][q];
1508                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1509                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1510             }
1511         }
1512 }
1513 inline void mikndw(register int id,register int lim,register int val){
1514     register int flag=(val<0)?-1:1;
1515     for(register int i=1;i<=8;++i)
1516     for(register int j=1;j<=8;++j)
1517         for(register int k=1;k<=8;++k)
1518         for(register int l=1;l<=8;++l){
1519             register double p=suf[mi[i]][lim+1];
1520             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1521             for(register int q=0;q<=16;++q){
1522                 register double gl=g[abs(val)][q];
1523                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1524                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1525             }
1526         }
1527 }
1528 inline void spmidw(register int id,register int lim,register int val){
1529     register int flag=(val<0)?-1:1;
1530     for(register int i=1;i<=8;++i)
1531     for(register int j=1;j<=8;++j)
1532         for(register int k=1;k<=8;++k)
1533         for(register int l=1;l<=8;++l){
1534             register double p=suf[sp[j]][lim+1];
1535             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1536             for(register int q=0;q<=16;++q){
1537                 register double gl=g[abs(val)][q];
1538                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1539                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1540             }
1541         }
1542 }
1543 inline void spspdw(register int id,register int lim,register int val){
1544     register int flag=(val<0)?-1:1;
1545     for(register int i=1;i<=8;++i)
1546     for(register int j=1;j<=8;++j)
1547         for(register int k=1;k<=8;++k)
1548         for(register int l=1;l<=8;++l){
1549             register double p=suf[sp[j]][lim+1];
1550             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1551             for(register int q=0;q<=16;++q){
1552                 register double gl=g[abs(val)][q];
1553                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1554                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1555             }
1556         }
1557 }
1558 inline void spsadw(register int id,register int lim,register int val){
1559     register int flag=(val<0)?-1:1;
1560     for(register int i=1;i<=8;++i)
1561     for(register int j=1;j<=8;++j)
1562         for(register int k=1;k<=8;++k)
1563         for(register int l=1;l<=8;++l){
1564             register double p=suf[sp[j]][lim+1];
1565             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1566             for(register int q=0;q<=16;++q){
1567                 register double gl=g[abs(val)][q];
1568                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1569                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1570             }
1571         }
1572 }
1573 inline void spkndw(register int id,register int lim,register int val){
1574     register int flag=(val<0)?-1:1;
1575    for(register int i=1;i<=8;++i)
1576     for(register int j=1;j<=8;++j)
1577         for(register int k=1;k<=8;++k)
1578         for(register int l=1;l<=8;++l){
1579             register double p=suf[sp[j]][lim+1];
1580             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1581             for(register int q=0;q<=16;++q){
1582                 register double gl=g[abs(val)][q];
1583                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1584                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1585             }
1586         }
1587 }
1588 inline void samidw(register int id,register int lim,register int val){
1589     register int flag=(val<0)?-1:1;
1590     for(register int i=1;i<=8;++i)
1591     for(register int j=1;j<=8;++j)
1592         for(register int k=1;k<=8;++k)
1593         for(register int l=1;l<=8;++l){
1594             register double p=suf[sa[k]][lim+1];
1595             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1596             for(register int q=0;q<=16;++q){
1597                 register double gl=g[abs(val)][q];
1598                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1599                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1600             }
1601         }
1602 }
1603 inline void saspdw(register int id,register int lim,register int val){
1604     register int flag=(val<0)?-1:1;
1605     for(register int i=1;i<=8;++i)
1606     for(register int j=1;j<=8;++j)
1607         for(register int k=1;k<=8;++k)
1608         for(register int l=1;l<=8;++l){
1609             register double p=suf[sa[k]][lim+1];
1610             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1611             for(register int q=0;q<=16;++q){
1612                 register double gl=g[abs(val)][q];
1613                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1614                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1615             }
1616         }
1617 }
1618 inline void sasadw(register int id,register int lim,register int val){
1619     register int flag=(val<0)?-1:1;
1620     for(register int i=1;i<=8;++i)
1621     for(register int j=1;j<=8;++j)
1622         for(register int k=1;k<=8;++k)
1623         for(register int l=1;l<=8;++l){
1624             register double p=suf[sa[k]][lim+1];
1625             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1626             for(register int q=0;q<=16;++q){
1627                 register double gl=g[abs(val)][q];
1628                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1629                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1630             }
1631         }
1632 }
1633 inline void sakndw(register int id,register int lim,register int val){
1634     register int flag=(val<0)?-1:1;
1635     for(register int i=1;i<=8;++i)
1636     for(register int j=1;j<=8;++j)
1637         for(register int k=1;k<=8;++k)
1638         for(register int l=1;l<=8;++l){
1639             register double p=suf[sa[k]][lim+1];
1640             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1641             for(register int q=0;q<=16;++q){
1642                 register double gl=g[abs(val)][q];
1643                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1644                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1645             }
1646         }
1647 }
1648 inline void knmidw(register int id,register int lim,register int val){
1649     register int flag=(val<0)?-1:1;
1650     for(register int i=1;i<=8;++i)
1651     for(register int j=1;j<=8;++j)
1652         for(register int k=1;k<=8;++k)
1653         for(register int l=1;l<=8;++l){
1654             register double p=suf[kn[l]][lim+1];
1655             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1656             for(register int q=0;q<=16;++q){
1657                 register double gl=g[abs(val)][q];
1658                 if(i+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1659                 else f[id][min(8,i+q*flag)][j][k][l]+=f[id-1][i][j][k][l]*p*gl;
1660             }
1661         }
1662 }
1663 inline void knspdw(register int id,register int lim,register int val){
1664     register int flag=(val<0)?-1:1;
1665     for(register int i=1;i<=8;++i)
1666     for(register int j=1;j<=8;++j)
1667         for(register int k=1;k<=8;++k)
1668         for(register int l=1;l<=8;++l){
1669             register double p=suf[kn[l]][lim+1];
1670             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1671             for(register int q=0;q<=16;++q){
1672                 register double gl=g[abs(val)][q];
1673                 if(j+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1674                 else f[id][i][min(8,j+q*flag)][k][l]+=f[id-1][i][j][k][l]*p*gl;
1675             }
1676         }
1677 }
1678 inline void knsadw(register int id,register int lim,register int val){
1679     register int flag=(val<0)?-1:1;
1680     for(register int i=1;i<=8;++i)
1681     for(register int j=1;j<=8;++j)
1682         for(register int k=1;k<=8;++k)
1683         for(register int l=1;l<=8;++l){
1684             register double p=suf[kn[l]][lim+1];
1685             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1686             for(register int q=0;q<=16;++q){
1687                 register double gl=g[abs(val)][q];
1688                 if(k+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1689                 else f[id][i][j][min(8,k+q*flag)][l]+=f[id-1][i][j][k][l]*p*gl;
1690             }
1691         }
1692 }
1693 inline void knkndw(register int id,register int lim,register int val){
1694     register int flag=(val<0)?-1:1;
1695     for(register int i=1;i<=8;++i)
1696     for(register int j=1;j<=8;++j)
1697         for(register int k=1;k<=8;++k)
1698         for(register int l=1;l<=8;++l){
1699             register double p=suf[kn[l]][lim+1];
1700             f[id][i][j][k][l]+=f[id-1][i][j][k][l]*(1-p);
1701             for(register int q=0;q<=16;++q){
1702                 register double gl=g[abs(val)][q];
1703                 if(l+q*flag<=0) ANS+=f[id-1][i][j][k][l]*p*gl;
1704                 else f[id][i][j][k][min(8,l+q*flag)]+=f[id-1][i][j][k][l]*p*gl;
1705             }
1706         }
1707 }
1708 signed main(){
1709     scanf("%s%d",s+1,&MI);for(register int i=1;i<=8;++i) mi[i]=s[i]-'0';
1710     scanf("%s%d",s+1,&SP);for(register int i=1;i<=8;++i) sp[i]=s[i]-'0';
1711     scanf("%s%d",s+1,&SA);for(register int i=1;i<=8;++i) sa[i]=s[i]-'0';
1712     scanf("%s%d",s+1,&KN);for(register int i=1;i<=8;++i) kn[i]=s[i]-'0';
1713     f[0][MI][SP][SA][KN]=1.0; 
1714     scanf("%d",&n);  g[0][0]=1.0;
1715     for(register int i=0;i<8;++i)
1716         for(register int j=0;j<=16;++j){
1717             g[i+1][j+0]+=g[i][j]*1.0/3.0;
1718             g[i+1][j+1]+=g[i][j]*1.0/3.0;
1719             g[i+1][j+2]+=g[i][j]*1.0/3.0;
1720         }
1721     for(register int i=1;i<=8;++i){
1722         pre[i][0]=g[i][0];
1723         for(register int j=1;j<=16;++j)
1724             pre[i][j]=g[i][j]+pre[i][j-1];
1725     }
1726     for(register int i=8;i>=1;--i){
1727         suf[i][17]=g[i][17];
1728         for(register int j=16;j>=0;--j)
1729             suf[i][j]=g[i][j]+suf[i][j+1];
1730     }
1731     for(register int id=1;id<=n;++id){
1732         scanf("%s%s",s1+1,s2+1);
1733         if(s2[1]=='+'||s2[1]=='-'){
1734             register int val=s2[2]-'0';
1735             if(s2[1]=='-') val=-val;
1736             if(s2[3]=='?'){
1737                 register int dat=abs(val); 
1738                 register int flag=(s2[1]=='-')?-1:1;
1739                 for(register int i=0;i<=16;++i){
1740                     if(s1[2]=='i') addmi(id,i*flag,g[dat][i]);
1741                     if(s1[2]=='p') addsp(id,i*flag,g[dat][i]);
1742                     if(s1[2]=='a') addsa(id,i*flag,g[dat][i]);
1743                     if(s1[2]=='n') addkn(id,i*flag,g[dat][i]);
1744                 }
1745             }
1746             else{
1747                 if(s1[2]=='i') addmi(id,val,1);
1748                 if(s1[2]=='p') addsp(id,val,1);
1749                 if(s1[2]=='a') addsa(id,val,1);
1750                 if(s1[2]=='n') addkn(id,val,1);
1751             }
1752             continue;
1753         }
1754         else if(s2[1]=='>'||s2[1]=='<'){
1755             register int dat;
1756             scanf("%d%s%s",&dat,s3+1,s4+1);
1757             register int val=s4[2]-'0';
1758             register int flag=(s4[1]=='-')?-1:1;
1759             if(s4[3]=='?'){
1760                 if(s2[1]=='>'&&s2[2]=='='){
1761                     if(s1[2]=='i'){
1762                         if(s3[2]=='i') mimiddw(id,dat,val*flag);
1763                         if(s3[2]=='p') mispddw(id,dat,val*flag);
1764                         if(s3[2]=='a') misaddw(id,dat,val*flag);
1765                         if(s3[2]=='n') miknddw(id,dat,val*flag);    
1766                         continue;
1767                     }
1768                     if(s1[2]=='p'){
1769                         if(s3[2]=='i') spmiddw(id,dat,val*flag);
1770                         if(s3[2]=='p') spspddw(id,dat,val*flag);
1771                         if(s3[2]=='a') spsaddw(id,dat,val*flag);
1772                         if(s3[2]=='n') spknddw(id,dat,val*flag);
1773                         continue;
1774                     }
1775                     if(s1[2]=='a'){
1776                         if(s3[2]=='i') samiddw(id,dat,val*flag);
1777                         if(s3[2]=='p') saspddw(id,dat,val*flag);
1778                         if(s3[2]=='a') sasaddw(id,dat,val*flag);
1779                         if(s3[2]=='n') saknddw(id,dat,val*flag);
1780                         continue;
1781                     }
1782                     if(s1[2]=='n'){
1783                         if(s3[2]=='i') knmiddw(id,dat,val*flag);
1784                         if(s3[2]=='p') knspddw(id,dat,val*flag);
1785                         if(s3[2]=='a') knsaddw(id,dat,val*flag);
1786                         if(s3[2]=='n') knknddw(id,dat,val*flag);
1787                         continue;
1788                     }
1789                 }
1790                 else if(s2[1]=='<'&&s2[2]=='='){
1791                     if(s1[2]=='i'){
1792                         if(s3[2]=='i') mimixdw(id,dat,val*flag);
1793                         if(s3[2]=='p') mispxdw(id,dat,val*flag);
1794                         if(s3[2]=='a') misaxdw(id,dat,val*flag);
1795                         if(s3[2]=='n') miknxdw(id,dat,val*flag);
1796                         continue;    
1797                     }
1798                     if(s1[2]=='p'){
1799                         if(s3[2]=='i') spmixdw(id,dat,val*flag);
1800                         if(s3[2]=='p') spspxdw(id,dat,val*flag);
1801                         if(s3[2]=='a') spsaxdw(id,dat,val*flag);
1802                         if(s3[2]=='n') spknxdw(id,dat,val*flag);
1803                         continue;
1804                     }
1805                     if(s1[2]=='a'){
1806                         if(s3[2]=='i') samixdw(id,dat,val*flag);
1807                         if(s3[2]=='p') saspxdw(id,dat,val*flag);
1808                         if(s3[2]=='a') sasaxdw(id,dat,val*flag);
1809                         if(s3[2]=='n') saknxdw(id,dat,val*flag);
1810                         continue;
1811                     }
1812                     if(s1[2]=='n'){
1813                         if(s3[2]=='i') knmixdw(id,dat,val*flag);
1814                         if(s3[2]=='p') knspxdw(id,dat,val*flag);
1815                         if(s3[2]=='a') knsaxdw(id,dat,val*flag);
1816                         if(s3[2]=='n') knknxdw(id,dat,val*flag);
1817                         continue;
1818                     }
1819                 }
1820                 else if(s2[1]=='>'){
1821                     if(s1[2]=='i'){
1822                         if(s3[2]=='i') mimidw(id,dat,val*flag);
1823                         if(s3[2]=='p') mispdw(id,dat,val*flag);
1824                         if(s3[2]=='a') misadw(id,dat,val*flag);
1825                         if(s3[2]=='n') mikndw(id,dat,val*flag);    
1826                         continue;
1827                     }
1828                     if(s1[2]=='p'){
1829                         if(s3[2]=='i') spmidw(id,dat,val*flag);
1830                         if(s3[2]=='p') spspdw(id,dat,val*flag);
1831                         if(s3[2]=='a') spsadw(id,dat,val*flag);
1832                         if(s3[2]=='n') spkndw(id,dat,val*flag);
1833                         continue;
1834                     }
1835                     if(s1[2]=='a'){
1836                         if(s3[2]=='i') samidw(id,dat,val*flag);
1837                         if(s3[2]=='p') saspdw(id,dat,val*flag);
1838                         if(s3[2]=='a') sasadw(id,dat,val*flag);
1839                         if(s3[2]=='n') sakndw(id,dat,val*flag);
1840                         continue;
1841                     }
1842                     if(s1[2]=='n'){
1843                         if(s3[2]=='i') knmidw(id,dat,val*flag);
1844                         if(s3[2]=='p') knspdw(id,dat,val*flag);
1845                         if(s3[2]=='a') knsadw(id,dat,val*flag);
1846                         if(s3[2]=='n') knkndw(id,dat,val*flag);
1847                         continue;
1848                     }
1849                 }
1850                 else if(s2[1]=='<'){
1851                     if(s1[2]=='i'){
1852                         if(s3[2]=='i') mimixw(id,dat,val*flag);
1853                         if(s3[2]=='p') mispxw(id,dat,val*flag);
1854                         if(s3[2]=='a') misaxw(id,dat,val*flag);
1855                         if(s3[2]=='n') miknxw(id,dat,val*flag);    
1856                         continue;
1857                     }
1858                     if(s1[2]=='p'){
1859                         if(s3[2]=='i') spmixw(id,dat,val*flag);
1860                         if(s3[2]=='p') spspxw(id,dat,val*flag);
1861                         if(s3[2]=='a') spsaxw(id,dat,val*flag);
1862                         if(s3[2]=='n') spknxw(id,dat,val*flag);
1863                         continue;
1864                     }
1865                     if(s1[2]=='a'){
1866                         if(s3[2]=='i') samixw(id,dat,val*flag);
1867                         if(s3[2]=='p') saspxw(id,dat,val*flag);
1868                         if(s3[2]=='a') sasaxw(id,dat,val*flag);
1869                         if(s3[2]=='n') saknxw(id,dat,val*flag);
1870                         continue;
1871                     }
1872                     if(s1[2]=='n'){
1873                         if(s3[2]=='i') knmixw(id,dat,val*flag);
1874                         if(s3[2]=='p') knspxw(id,dat,val*flag);
1875                         if(s3[2]=='a') knsaxw(id,dat,val*flag);
1876                         if(s3[2]=='n') knknxw(id,dat,val*flag);
1877                         continue;
1878                     }
1879                 }
1880             }
1881             else{
1882                 if(s2[1]=='>'&&s2[2]=='='){
1883                     if(s1[2]=='i'){
1884                         if(s3[2]=='i') mimidd(id,dat,val*flag);
1885                         if(s3[2]=='p') mispdd(id,dat,val*flag);
1886                         if(s3[2]=='a') misadd(id,dat,val*flag);
1887                         if(s3[2]=='n') mikndd(id,dat,val*flag);    
1888                         continue;
1889                     }
1890                     if(s1[2]=='p'){
1891                         if(s3[2]=='i') spmidd(id,dat,val*flag);
1892                         if(s3[2]=='p') spspdd(id,dat,val*flag);
1893                         if(s3[2]=='a') spsadd(id,dat,val*flag);
1894                         if(s3[2]=='n') spkndd(id,dat,val*flag);
1895                         continue;
1896                     }
1897                     if(s1[2]=='a'){
1898                         if(s3[2]=='i') samidd(id,dat,val*flag);
1899                         if(s3[2]=='p') saspdd(id,dat,val*flag);
1900                         if(s3[2]=='a') sasadd(id,dat,val*flag);
1901                         if(s3[2]=='n') sakndd(id,dat,val*flag);
1902                         continue;
1903                     }
1904                     if(s1[2]=='n'){
1905                         if(s3[2]=='i') knmidd(id,dat,val*flag);
1906                         if(s3[2]=='p') knspdd(id,dat,val*flag);
1907                         if(s3[2]=='a') knsadd(id,dat,val*flag);
1908                         if(s3[2]=='n') knkndd(id,dat,val*flag);
1909                         continue;
1910                     }
1911                 }
1912                 else if(s2[1]=='<'&&s2[2]=='='){
1913                     if(s1[2]=='i'){
1914                         if(s3[2]=='i') mimixd(id,dat,val*flag);
1915                         if(s3[2]=='p') mispxd(id,dat,val*flag);
1916                         if(s3[2]=='a') misaxd(id,dat,val*flag);
1917                         if(s3[2]=='n') miknxd(id,dat,val*flag);    
1918                         continue;
1919                     }
1920                     if(s1[2]=='p'){
1921                         if(s3[2]=='i') spmixd(id,dat,val*flag);
1922                         if(s3[2]=='p') spspxd(id,dat,val*flag);
1923                         if(s3[2]=='a') spsaxd(id,dat,val*flag);
1924                         if(s3[2]=='n') spknxd(id,dat,val*flag);
1925                         continue;
1926                     }
1927                     if(s1[2]=='a'){
1928                         if(s3[2]=='i') samixd(id,dat,val*flag);
1929                         if(s3[2]=='p') saspxd(id,dat,val*flag);
1930                         if(s3[2]=='a') sasaxd(id,dat,val*flag);
1931                         if(s3[2]=='n') saknxd(id,dat,val*flag);
1932                         continue;
1933                     }
1934                     if(s1[2]=='n'){
1935                         if(s3[2]=='i') knmixd(id,dat,val*flag);
1936                         if(s3[2]=='p') knspxd(id,dat,val*flag);
1937                         if(s3[2]=='a') knsaxd(id,dat,val*flag);
1938                         if(s3[2]=='n') knknxd(id,dat,val*flag);
1939                         continue;
1940                     }
1941                 }
1942                 else if(s2[1]=='>'){
1943                     if(s1[2]=='i'){
1944                         if(s3[2]=='i') mimid(id,dat,val*flag);
1945                         if(s3[2]=='p') mispd(id,dat,val*flag);
1946                         if(s3[2]=='a') misad(id,dat,val*flag);
1947                         if(s3[2]=='n') miknd(id,dat,val*flag);    
1948                         continue;
1949                     }
1950                     if(s1[2]=='p'){
1951                         if(s3[2]=='i') spmid(id,dat,val*flag);
1952                         if(s3[2]=='p') spspd(id,dat,val*flag);
1953                         if(s3[2]=='a') spsad(id,dat,val*flag);
1954                         if(s3[2]=='n') spknd(id,dat,val*flag);
1955                         continue;
1956                     }
1957                     if(s1[2]=='a'){
1958                         if(s3[2]=='i') samid(id,dat,val*flag);
1959                         if(s3[2]=='p') saspd(id,dat,val*flag);
1960                         if(s3[2]=='a') sasad(id,dat,val*flag);
1961                         if(s3[2]=='n') saknd(id,dat,val*flag);
1962                         continue;
1963                     }
1964                     if(s1[2]=='n'){
1965                         if(s3[2]=='i') knmid(id,dat,val*flag);
1966                         if(s3[2]=='p') knspd(id,dat,val*flag);
1967                         if(s3[2]=='a') knsad(id,dat,val*flag);
1968                         if(s3[2]=='n') knknd(id,dat,val*flag);
1969                         continue;
1970                     }
1971                 }
1972                 else if(s2[1]=='<'){
1973                     if(s1[2]=='i'){
1974                         if(s3[2]=='i') mimix(id,dat,val*flag);
1975                         if(s3[2]=='p') mispx(id,dat,val*flag);
1976                         if(s3[2]=='a') misax(id,dat,val*flag);
1977                         if(s3[2]=='n') miknx(id,dat,val*flag);    
1978                         continue;
1979                     }
1980                     if(s1[2]=='p'){
1981                         if(s3[2]=='i') spmix(id,dat,val*flag);
1982                         if(s3[2]=='p') spspx(id,dat,val*flag);
1983                         if(s3[2]=='a') spsax(id,dat,val*flag);
1984                         if(s3[2]=='n') spknx(id,dat,val*flag);
1985                         continue;
1986                     }
1987                     if(s1[2]=='a'){
1988                         if(s3[2]=='i') samix(id,dat,val*flag);
1989                         if(s3[2]=='p') saspx(id,dat,val*flag);
1990                         if(s3[2]=='a') sasax(id,dat,val*flag);
1991                         if(s3[2]=='n') saknx(id,dat,val*flag);
1992                         continue;
1993                     }
1994                     if(s1[2]=='n'){
1995                         if(s3[2]=='i') knmix(id,dat,val*flag);
1996                         if(s3[2]=='p') knspx(id,dat,val*flag);
1997                         if(s3[2]=='a') knsax(id,dat,val*flag);
1998                         if(s3[2]=='n') knknx(id,dat,val*flag);
1999                         continue;
2000                     }
2001                 }
2002             }
2003         }
2004     }
2005     printf("%.2lf\n",ANS*100.0);
2006     for(register int i=1;i<=8;++i)
2007     for(register int j=1;j<=8;++j)
2008         for(register int k=1;k<=8;++k)
2009         for(register int l=1;l<=8;++l){
2010             mig[mi[i]]+=f[n][i][j][k][l];
2011             spe[sp[j]]+=f[n][i][j][k][l];
2012             san[sa[k]]+=f[n][i][j][k][l];
2013             kno[kn[l]]+=f[n][i][j][k][l];
2014         }
2015     for(register int i=1;i<=8;++i) printf("%.2lf ",mig[i]*100.0); puts("");
2016     for(register int i=1;i<=8;++i) printf("%.2lf ",spe[i]*100.0); puts("");
2017     for(register int i=1;i<=8;++i) printf("%.2lf ",san[i]*100.0); puts("");
2018     for(register int i=1;i<=8;++i) printf("%.2lf ",kno[i]*100.0); puts("");
2019 }

 

posted @ 2019-10-26 17:13  Hzoi-lyl  阅读(547)  评论(9编辑  收藏  举报