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;
const double PI = 4.0 * atan(1);
struct point {
  int x, y;
  point(int _x, int _y) {
    x = _x;
    y = _y;
  }
  point() {
    x = 0;
    y = 0;
  }
};
long double dist(point a, point b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
bool check(int n, vector<long long int> arr) {
  for (int i = 0; i < n - 1; i++) {
    if (arr[i] > arr[i + 1]) return 0;
  }
  return 1;
}
long long int gcd(long long int a, long long int b) {
  for (;;) {
    if (a == 0) return b;
    b %= a;
    if (b == 0) return a;
    a %= b;
  }
}
long long int lcm(long long int a, long long int b) {
  long long int temp = gcd(a, b);
  return temp ? (a / temp * b) : 0;
}
long long int choose(int n, int k) {
  if (k == 0) return 1;
  return (n * choose(n - 1, k - 1)) / k;
}
const int MAX = 500;
int multi(int x, int res[], int res_size) {
  int carry = 0;
  for (int i = 0; i < res_size; i++) {
    int prod = res[i] * x + carry;
    res[i] = prod % 10;
    carry = prod / 10;
  }
  while (carry) {
    res[res_size] = carry % 10;
    carry = carry / 10;
    res_size++;
  }
  return res_size;
}
void fact(int n) {
  int res[MAX];
  res[0] = 1;
  int res_size = 1;
  for (int x = 2; x <= n; x++) res_size = multi(x, res, res_size);
  for (int i = res_size - 1; i >= 0; i--) cout << res[i];
}
long double delta(int a, int b, int c) { return b * b - 4 * a * c; }
unsigned long long int mul_mod(unsigned long long int a,
                               unsigned long long int b,
                               unsigned long long int m) {
  long double x;
  unsigned long long int c;
  long long int r;
  if (a >= m) a %= m;
  if (b >= m) b %= m;
  x = a;
  c = x * b / m;
  r = (long long int)(a * b - c * m) % (long long int)m;
  return r < 0 ? r + m : r;
}
char s1[100005], s2[100005], s3[100005];
bool sim[100005] = {0};
bool check(char grid1[2][2], char grid2[2][2]) {
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      if (grid1[i][j] != grid2[i][j]) return false;
    }
  }
  return true;
}
int n, m;
bool check(int a, int b) { return a >= 0 && a < n && b >= 0 && b < m; }
long long int power(int n) {
  long long int temp = 1;
  for (int i = 0; i < n; i++) {
    temp *= 2;
  }
  return temp;
}
int main() {
  int n;
  cin >> n;
  int m[16], r[16];
  int tlcm = 1;
  for (int i = 0; i < n; i++) {
    cin >> m[i];
    tlcm = lcm(tlcm, m[i]);
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }
  for (int i = 0; i < tlcm; i++) {
    for (int j = 0; j < n; j++) {
      if (i % m[j] == r[j]) {
        count++;
        break;
      }
    }
  }
  printf("%f", (float)count / (float)tlcm);
  return 0;
}