package main import . "fmt" import . "strings" import . "math/big" func main() { var h,w int Scan(&h,&w) ss:=make([]string,h) for i:=range ss { var s string Scan(&s) s=ReplaceAll(s,".","a") s=ReplaceAll(s,"#",".") ss[i]=ReplaceAll(s,"a","#") } var x,y int for i,s:=range ss { var t string Scan(&t) if s!=t { x++ } if ss[h-1-i]!=t { y++ } } if x>0&&y>0 { Println(-1) } else if x==0&&y>0 { Println("3.5317401904617327") } else { var e,f,z *Rat e,f,z=NewRat(2,1),NewRat(1,1),NewRat(0,1) for i:=0;i<1000;i++ { e.Mul(e,NewRat(2,1)) if i%2==0 &&x>0{ continue } z.Add(z,new(Rat).Mul(NewRat(int64(i+1),1), new(Rat).Mul(f,new(Rat).Sub(NewRat(1,1),e)))) f.Mul(f,e) } Println(z.FloatString(12)) } }