Problem: Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht D mod M[i] = R[i], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.

Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo. 

Input

The first line of input contains a single integer N (1 ≤ N ≤ 16).

The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All M[i] are positive, for each i R[i] < M[i].

Output

Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4.

Examples

Input

1
2
0


Output

0.500000


Input

2
2 3
1 0


Output

0.666667

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 16;
int n;
int mod[MAXN], rem[MAXN];
int egcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  int g = egcd(b, a % b, x, y);
  swap(x, y);
  y -= x * (a / b);
  return g;
}
int mymod(int x, int mod) {
  x %= mod;
  if (x < 0) x += mod;
  return x;
}
bool combine(int &n1, int &a1, int n2, int a2) {
  int m1, m2, g = egcd(n1, n2, m1, m2);
  if (a1 % g != a2 % g) return false;
  int n3 = n1 / g * n2, a3 = mymod(a1 + m1 * (n1 / g) * (a2 - a1), n3);
  n1 = n3, a1 = a3;
  return true;
}
void run() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d", &mod[i]);
  for (int i = (0); i < (n); ++i) scanf("%d", &rem[i]);
  long long den = 20922789888000LL, num = 0;
  for (int i = (0); i < (1 << n); ++i) {
    int cmod = 1, crem = 0, cnt = 0;
    bool ok = true;
    for (int j = (0); j < (n); ++j)
      if (i & (1 << j)) {
        ++cnt;
        if (!combine(cmod, crem, mod[j], rem[j])) ok = false;
      }
    if (!ok) continue;
    if (cnt % 2 == 0)
      num += den / cmod;
    else
      num -= den / cmod;
  }
  printf("%.9lf\n", 1.0 * (den - num) / den);
}
int main() {
  run();
  return 0;
}