Problem:
Problem Statement
Infinite Chronicle -Princess Castle-
is a simple role-playing game. 
There are $n + 1$ checkpoints, numbered $0$ through $n$, 
and for each $i = 1, 2, \ldots, n$, there is a unique one-way road running from checkpoint $i - 1$ to $i$. 
The game starts at checkpoint $0$ and ends at checkpoint $n$. 
Evil monsters will appear on the roads and the hero will have battles against them. 
You can save your game progress at any checkpoint; if you lose a battle, you can restart the game from the checkpoint where you have saved for the last time. 
At the beginning of the game, the progress is automatically saved at checkpoint $0$ with no time.
Rabbit Hanako is fond of this game and now interested in speedrunning. 
Although Hanako is an expert of the game, she cannot always win the battles because of random factors. 
For each $i$, she estimated the probability $p_i$ to win all the battles along the road from checkpoint $i - 1$ to $i$. 
Everytime she starts at checkpoint $i - 1$, after exactly one miniutes, 
she will be at checkpoint $i$ with probability $p_i$ and where she saved for the last time with probability $1 - p_i$.
What puzzles Hanako is that it also takes one minute (!) to save your progress at a checkpoint, 
so it might be a good idea to pass some checkpoints without saving in order to proceed quickly. 
The task is to compute the minimum possible expected time needed to complete the game.
Input
The input consists of multiple datasets. The number of datasets is no more than $50$. 
Each dataset has two lines: the first line contains an integer $n$ ($1 \le n \le 10^5$), representing the number of roads, 
and the second line contains $n$ numbers $p_1, p_2, \ldots, p_n$ ($0 \lt p_i \le 1$), representing the winning probabilities.
Each $p_i$ has exactly two digits after the decimal point.
The end of input is denoted as a line containing only a single zero.
Output
For each dataset, display the minimum expected time in minutes with a relative error of at most $10^{-8}$ in a line.
Sample Input
2
0.50 0.40
2
0.70 0.60
4
0.99 1.00 1.00 0.01
0
Output for the Sample Input
5.5000000000
4.0476190476
104.0101010101

Submitted solutions:

code_snippet: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100010;
double p[N],dp[N],sum[N];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF&&n)
    {
        for(int i=1;i<=n;i++) {
            scanf("%lf",&p[i]);
        }
        dp[0]=0;p[0]=1;
        for(int i=2;i<=n+1;i++)
        {
            double g1=p[i-1],g2=1.0;
            dp[i]=dp[i-1]+g2/g1+1;
            //printf("%d: %lf ",i,g2/g1);
            //printf("%d: %lf ,",i,dp[i]);
            for(int j=i-2;j>=1;j--)
            {
                g1=g1*p[j]; g2=g2*p[j]+1;
                double g=g2/g1;
                if(g>dp[i]) break;
                dp[i]=min(dp[i],dp[j]+g+1);
                //printf("%lf , ",dp[i]);
                //printf("%lf ",g);
            }
            //printf("\n");
        }
        printf("%.10lf\n",dp[n+1]-1);
    }
    return 0;
}
accuracy: 1
time_ms: 1660
memory_kb: 4892
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;

int N;
double P[1 << 19];
double dp[1 << 19];

double solve() {
    for (int i = 0; i <= N; i++) dp[i] = 1e18;
    dp[N] = 0;

    // Step 1. Enumerate Candidate
    vector<int> vec;
    vec.push_back(0);
    for (int i = 1; i <= N; i++) {
        if (P[i] < 0.999) vec.push_back(i - 1);
    }
    vec.push_back(N);
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());

    // Step 2. Dynamic Programming
    for (int i = (int)vec.size() - 1; i >= 0; i--) {
        double prob = 1.00;
        double expc = 0.00;
        for (int j = i + 1; j < min(i + 1000, (int)vec.size()); j++) {
            double val = P[vec[j - 1] + 1];
            expc += ((vec[j - 1] + 1) - vec[i]) * (prob * (1.0 - val));
            prob *= val;
            double pattern1 = (vec[j] - vec[i]) + 1.0;
            double pattern2 = expc / (1.0 - prob); if (prob > 0.999) pattern2 = 0.0;
            double total = pattern1 + pattern2 * (1.0 / prob - 1.0);
            // cout << vec[i] << " " << vec[j] << " " << pattern1 << " " << pattern2 << " " << total << endl;
            dp[vec[i]] = min(dp[vec[i]], dp[vec[j]] + total);
        }
    }

    // Step 3. Return
    return dp[0] - 1.0;
}

int main() {
    while (true) {
        cin >> N; if (N == 0) break;
        for (int i = 1; i <= N; i++) cin >> P[i];
        double ret = solve();
        printf("%.12lf\n", ret);
    }
    return 0;
}
accuracy: 1
time_ms: 7600
memory_kb: 7008
final_rank: 19

code_snippet: #line 1 "a.cpp"
// cSpell:disable
/*	author:  Kite_kuma
	created: 2022.11.22 05:33:13 */

#line 2 "SPJ-Library/template/kuma.hpp"

#line 2 "SPJ-Library/template/basic_func.hpp"

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

template <class T0, class T1, class T2>
inline bool in_range(T0 x, T1 lef, T2 rig) {
	return ((lef <= x) && (x < rig));
}

template <class T>
inline bool chmin(T &a, T b) {
	if(a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b) {
	if(a < b) {
		a = b;
		return true;
	}
	return false;
}

void Yes(bool flag = true) { std::cout << (flag ? "Yes" : "No") << '\n'; }
void YES(bool flag = true) { std::cout << (flag ? "YES" : "NO") << '\n'; }

template <class T>
void drop(T answer) {
	std::cout << answer << '\n';
	exit(0);
}

template <class T>
void vout(std::vector<T> const &v, bool vertically = 0) {
	if(vertically) {
		for(auto const &a : v) {
			std::cout << a << '\n';
		}
		return;
	}
	for(auto it = v.begin(); it != v.end(); it++) {
		std::cout << (*it);
		if(it != v.end() - 1) {
			std::cout << ' ';
		}
	}
	std::cout << '\n';
	return;
}

inline void print() { std::cout << '\n'; }
template <class T>
inline void print(const T &x) {
	std::cout << x << '\n';
	return;
}
template <typename Head, typename... Tail>
void print(const Head &H, const Tail &... T) {
	std::cout << H << " ";
	print(T...);
}

template <class T>
void add(std::vector<T> &v, T value) {
	for(auto &a : v) a += value;
	return;
}

template <class T>
T greatest_lower_multiple(T x, T d) {
	if(d == 0) return 0;
	if(d < 0) d *= -1;
	T y = x % d;
	if(y < 0) y += d;
	return x - y;
}

template <class T>
T least_upper_multiple(T x, T d) {
	return -greatest_lower_multiple(-x, d);
}

// ceil(a / b);
template <class T>
T dup(T a, T b) {
	assert(b);
	if(b < 0) {
		a *= -1;
		b *= -1;
	}
	return least_upper_multiple(a, b) / b;
}

long long pow_ll(long long a, long long n) {
	assert(n >= 0LL);
	if(n == 0) return 1LL;
	if(a == 0) return 0LL;
	if(a == 1) return 1LL;
	if(a == -1) return (n & 1LL) ? -1LL : 1LL;
	long long res = 1;
	while(n > 1LL) {
		if(n & 1LL) res *= a;
		a *= a;
		n >>= 1;
	}
	return res * a;
}

long long modpow(long long a, long long n, long long mod) {	 // a^n mod
	assert(n >= 0 && mod);
	if(mod == 1) return 0LL;
	long long res = 1;
	a %= mod;
	while(n > 0) {
		if(n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res < 0 ? res + mod : res;
}

// return x which satisfies a * x % mod == gcd(a, mod)
// not (mod | a)
long long modinv(long long a, const long long mod) {
	long long b = mod, u = 1, v = 0;
	while(b) {
		long long t = a / b;
		a -= t * b;
		std::swap(a, b);
		u -= t * v;
		std::swap(u, v);
	}
	u %= mod;
	if(u < 0) u += mod;
	return u;
}

template <class T>
int lb(const std::vector<T> &a, const T x) {
	return (int)std::distance(a.begin(), std::lower_bound(a.begin(), a.end(), x));
}
template <class T>
int ub(const std::vector<T> &a, const T x) {
	return (int)std::distance(a.begin(), std::upper_bound(a.begin(), a.end(), x));
}
template <class T>
void unq_sort(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<int> press(const std::vector<T> &a) {
	std::vector<T> vec = a;
	unq_sort(vec);
	std::vector<int> ret;
	for(const auto &v : a) ret.push_back(lb(vec, v));
	return ret;
}
#line 1 "SPJ-Library/template/header.hpp"
#include <bits/stdc++.h>
#line 2 "SPJ-Library/template/io.hpp"

#line 4 "SPJ-Library/template/io.hpp"

#line 8 "SPJ-Library/template/debug.hpp"

#line 3 "SPJ-Library/template/constants.hpp"

constexpr int inf = 1000'000'000;
constexpr long long INF = 1'000'000'000'000'000'000LL;
constexpr int mod_1000000007 = 1000000007;
constexpr int mod_998244353 = 998244353;
const long double pi = acosl(-1.);
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
#line 10 "SPJ-Library/template/debug.hpp"

namespace viewer {

template <typename T, typename U>
void view(const std::pair<T, U> &p);

template <class T0, class T1, class T2>
void view(const std::tuple<T0, T1, T2> &p);

template <class T0, class T1, class T2, class T3>
void view(const std::tuple<T0, T1, T2, T3> &p);

void view(const long long &e);

void view(const int &e);

template <typename T>
void view(const T &e);

template <typename T>
void view(const std::set<T> &s);

template <typename T>
void view(const std::unordered_set<T> &s);

template <typename T>
void view(const std::multiset<T> &s);

template <typename T>
void view(const std::unordered_multiset<T> &s);

template <typename T>
void view(const std::vector<T> &v);

template <typename T, std::size_t ary_size>
void view(const std::array<T, ary_size> &v);

template <typename T>
void view(const std::vector<std::vector<T>> &vv);

template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v);

template <class T0, class T1, class T2>
void view(const std::vector<std::tuple<T0, T1, T2>> &v);

template <class T0, class T1, class T2, class T3>
void view(const std::vector<std::tuple<T0, T1, T2, T3>> &v);

template <typename map_type>
void view_map_container(const map_type &m);

template <typename T, typename U>
void view(const std::map<T, U> &m);

template <typename T, typename U>
void view(const std::unordered_map<T, U> &m);

template <typename container_type>
void view_container(const container_type &c, bool vertically = false) {
	typename container_type::const_iterator begin = c.begin();
	const typename container_type::const_iterator end = c.end();
	if(vertically) {
		std::cerr << "{\n";
		while(begin != end) {
			std::cerr << '\t';
			view(*(begin++));
			if(begin != end) std::cerr << ',';
			std::cerr << '\n';
		}
		std::cerr << '}';
		return;
	}
	std::cerr << "{ ";
	while(begin != end) {
		view(*(begin++));
		if(begin != end) std::cerr << ',';
		std::cerr << ' ';
	}
	std::cerr << '}';
}

template <typename T, typename U>
void view(const std::pair<T, U> &p) {
	std::cerr << '(';
	view(p.first);
	std::cerr << ", ";
	view(p.second);
	std::cerr << ')';
}

template <class T0, class T1, class T2>
void view(const std::tuple<T0, T1, T2> &p) {
	std::cerr << '(';
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ')';
}

template <class T0, class T1, class T2, class T3>
void view(const std::tuple<T0, T1, T2, T3> &p) {
	std::cerr << '(';
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ", ";
	view(std::get<3>(p));
	std::cerr << ')';
}

void view(const long long &e) {
	if(e == INF)
		std::cerr << "INF";
	else if(e == -INF)
		std::cerr << "-INF";
	else
		std::cerr << e;
}

void view(const int &e) {
	if(e == inf)
		std::cerr << "inf";
	else if(e == -inf)
		std::cerr << "-inf";
	else
		std::cerr << e;
}

template <typename T>
void view(const T &e) {
	std::cerr << e;
}

template <typename T>
void view(const std::set<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::unordered_set<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::multiset<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::unordered_multiset<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::vector<T> &v) {
	view_container(v);
}

template <typename T, std::size_t ary_size>
void view(const std::array<T, ary_size> &v) {
	view_container(v);
}

template <typename T>
void view(const std::vector<std::vector<T>> &vv) {
	view_container(vv, true);
}

template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v) {
	view_container(v, true);
}

template <class T0, class T1, class T2>
void view(const std::vector<std::tuple<T0, T1, T2>> &v) {
	view_container(v, true);
}

template <class T0, class T1, class T2, class T3>
void view(const std::vector<std::tuple<T0, T1, T2, T3>> &v) {
	view_container(v, true);
}

template <typename map_type>
void view_map_container(const map_type &m) {
	std::cerr << "{\n";
	for(typename map_type::const_iterator it = m.begin(); it != m.end(); it++) {
		std::cerr << "\t[";
		view(it->first);
		std::cerr << "] : ";
		view(it->second);
		std::cerr << '\n';
	}
	std::cerr << "}";
}

template <typename T, typename U>
void view(const std::map<T, U> &m) {
	view_map_container(m);
}

template <typename T, typename U>
void view(const std::unordered_map<T, U> &m) {
	view_map_container(m);
}

}  // namespace viewer

// when compiling : g++ foo.cpp -DLOCAL
#ifdef LOCAL
void debug_out() {}
template <typename T>
void debug_out(const T &x) {
	viewer::view(x);
}
template <typename Head, typename... Tail>
void debug_out(const Head &H, const Tail &... T) {
	viewer::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "]\n";                                       \
	} while(0)
#else
#define debug(...) (void(0))
#endif
#line 2 "SPJ-Library/template/scanner.hpp"

#line 6 "SPJ-Library/template/scanner.hpp"

namespace scanner {
template <class T>
void scan(T &a) {
	std::cin >> a;
}

template <class T, class L>
void scan(std::pair<T, L> &p) {
	scan(p.first);
	scan(p.second);
}

template <class T0, class T1, class T2>
void scan(std::tuple<T0, T1, T2> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	scan(t0);
	scan(t1);
	scan(t2);
	p = std::make_tuple(t0, t1, t2);
}

template <class T0, class T1, class T2, class T3>
void scan(std::tuple<T0, T1, T2, T3> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	T3 t3;
	scan(t0);
	scan(t1);
	scan(t2);
	scan(t3);
	p = std::make_tuple(t0, t1, t2, t3);
}

template <class T>
void scan(std::vector<T> &a) {
	for(auto &i : a) scan(i);
}

void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner
#line 7 "SPJ-Library/template/io.hpp"

#define VEC(type, name, size) \
	vector<type> name(size);  \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                     \
	vector<vector<type>> name(h, vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)        \
	string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHR(...)      \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DBL(...)        \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define TPL3(type0, type1, type2, name)   \
	std::tuple<type0, type1, type2> name; \
	scanner::INPUT(name);
#define TPL4(type0, type1, type2, type3, name)   \
	std::tuple<type0, type1, type2, type3> name; \
	scanner::INPUT(name);

template <typename T1, typename T2>
std::istream &operator>>(std::istream &is, std::pair<T1, T2> &p) {
	is >> p.first >> p.second;
	return is;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p) {
	os << p.first << ' ' << p.second;
	return os;
}

struct fast_io {
	fast_io() {
		std::ios::sync_with_stdio(false);
		std::cin.tie(nullptr);
		std::cout << std::fixed << std::setprecision(15);
		srand((unsigned)time(NULL));
	}
} fast_io_;
#line 2 "SPJ-Library/template/macros.hpp"

#define foa(s, v) for(auto &s : v)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pcnt(n) __builtin_popcountll((long long)n)

#define REPname(a, b, c, d, e, ...) e
#define rep(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int Counter_in_rep_macro = 0; Counter_in_rep_macro < (x); ++Counter_in_rep_macro)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))
#define DREPname(a, b, c, d, e, ...) e
#define drep(...) DREPname(__VA_ARGS__, DREP3, DREP2, DREP1)(__VA_ARGS__)
#define DREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define DREP2(i, l, r) for(int i = (r)-1; i >= (l); --i)
#define DREP3(i, l, r, c) for(int i = (r)-1; i >= (l); i -= (c))

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vvvi = std::vector<std::vector<std::vector<int>>>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
template <class T = ll>
using V = std::vector<T>;
template <class T = ll>
using VV = V<V<T>>;
template <class T = ll>
using VVV = V<V<V<T>>>;
template <class T = ll>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T = ll>
using pqdn = std::priority_queue<T>;
#line 7 "SPJ-Library/template/kuma.hpp"

using namespace std;
#line 6 "a.cpp"
double solve(int n) {
	vector<double> probs(n);
	foa(p, probs) cin >> p;
	vector<int> stoppable = {0};
	rep(i, 1, n) {
		if(probs[i] < 0.995) {
			stoppable.push_back(i);
		}
	}
	stoppable.push_back(n);
	int len = int(stoppable.size());
	vector<double> ans(len, INF);
	ans.front() = 0;
	debug(stoppable);
	debug(len, ans);
	rep(i, 1, len) {
		double pass_prob = 1.;
		double dash_cost = 0.;
		double& upd = ans[i];
		drep(prev, max(0, i - 20), i) {
			int jump = stoppable[prev + 1] - stoppable[prev];
			double p = probs[stoppable[prev]];
			dash_cost += pass_prob * (jump - 1);
			pass_prob /= p;
			dash_cost += pass_prob;
			if(upd < dash_cost) break;
			chmin(upd, ans[prev] + dash_cost);
			debug(i, prev, pass_prob, dash_cost);
		}
		upd += 1;
		debug(ans);
	}
	return ans.back() - 1;
}
int main() {
	int n;
	while(cin >> n && n) {
		cout << solve(n) << '\n';
	}
	return 0;
}
accuracy: 1
time_ms: 390
memory_kb: 5780
final_rank: 1

code_snippet: #line 1 "a.cpp"
// cSpell:disable
/*	author:  Kite_kuma
	created: 2022.11.22 05:33:13 */

#line 2 "SPJ-Library/template/kuma.hpp"

#line 2 "SPJ-Library/template/basic_func.hpp"

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

template <class T0, class T1, class T2>
inline bool in_range(T0 x, T1 lef, T2 rig) {
	return ((lef <= x) && (x < rig));
}

template <class T>
inline bool chmin(T &a, T b) {
	if(a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b) {
	if(a < b) {
		a = b;
		return true;
	}
	return false;
}

void Yes(bool flag = true) { std::cout << (flag ? "Yes" : "No") << '\n'; }
void YES(bool flag = true) { std::cout << (flag ? "YES" : "NO") << '\n'; }

template <class T>
void drop(T answer) {
	std::cout << answer << '\n';
	exit(0);
}

template <class T>
void vout(std::vector<T> const &v, bool vertically = 0) {
	if(vertically) {
		for(auto const &a : v) {
			std::cout << a << '\n';
		}
		return;
	}
	for(auto it = v.begin(); it != v.end(); it++) {
		std::cout << (*it);
		if(it != v.end() - 1) {
			std::cout << ' ';
		}
	}
	std::cout << '\n';
	return;
}

inline void print() { std::cout << '\n'; }
template <class T>
inline void print(const T &x) {
	std::cout << x << '\n';
	return;
}
template <typename Head, typename... Tail>
void print(const Head &H, const Tail &... T) {
	std::cout << H << " ";
	print(T...);
}

template <class T>
void add(std::vector<T> &v, T value) {
	for(auto &a : v) a += value;
	return;
}

template <class T>
T greatest_lower_multiple(T x, T d) {
	if(d == 0) return 0;
	if(d < 0) d *= -1;
	T y = x % d;
	if(y < 0) y += d;
	return x - y;
}

template <class T>
T least_upper_multiple(T x, T d) {
	return -greatest_lower_multiple(-x, d);
}

// ceil(a / b);
template <class T>
T dup(T a, T b) {
	assert(b);
	if(b < 0) {
		a *= -1;
		b *= -1;
	}
	return least_upper_multiple(a, b) / b;
}

long long pow_ll(long long a, long long n) {
	assert(n >= 0LL);
	if(n == 0) return 1LL;
	if(a == 0) return 0LL;
	if(a == 1) return 1LL;
	if(a == -1) return (n & 1LL) ? -1LL : 1LL;
	long long res = 1;
	while(n > 1LL) {
		if(n & 1LL) res *= a;
		a *= a;
		n >>= 1;
	}
	return res * a;
}

long long modpow(long long a, long long n, long long mod) {	 // a^n mod
	assert(n >= 0 && mod);
	if(mod == 1) return 0LL;
	long long res = 1;
	a %= mod;
	while(n > 0) {
		if(n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res < 0 ? res + mod : res;
}

// return x which satisfies a * x % mod == gcd(a, mod)
// not (mod | a)
long long modinv(long long a, const long long mod) {
	long long b = mod, u = 1, v = 0;
	while(b) {
		long long t = a / b;
		a -= t * b;
		std::swap(a, b);
		u -= t * v;
		std::swap(u, v);
	}
	u %= mod;
	if(u < 0) u += mod;
	return u;
}

template <class T>
int lb(const std::vector<T> &a, const T x) {
	return (int)std::distance(a.begin(), std::lower_bound(a.begin(), a.end(), x));
}
template <class T>
int ub(const std::vector<T> &a, const T x) {
	return (int)std::distance(a.begin(), std::upper_bound(a.begin(), a.end(), x));
}
template <class T>
void unq_sort(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<int> press(const std::vector<T> &a) {
	std::vector<T> vec = a;
	unq_sort(vec);
	std::vector<int> ret;
	for(const auto &v : a) ret.push_back(lb(vec, v));
	return ret;
}
#line 1 "SPJ-Library/template/header.hpp"
#include <bits/stdc++.h>
#line 2 "SPJ-Library/template/io.hpp"

#line 4 "SPJ-Library/template/io.hpp"

#line 8 "SPJ-Library/template/debug.hpp"

#line 3 "SPJ-Library/template/constants.hpp"

constexpr int inf = 1000'000'000;
constexpr long long INF = 1'000'000'000'000'000'000LL;
constexpr int mod_1000000007 = 1000000007;
constexpr int mod_998244353 = 998244353;
const long double pi = acosl(-1.);
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
#line 10 "SPJ-Library/template/debug.hpp"

namespace viewer {

template <typename T, typename U>
void view(const std::pair<T, U> &p);

template <class T0, class T1, class T2>
void view(const std::tuple<T0, T1, T2> &p);

template <class T0, class T1, class T2, class T3>
void view(const std::tuple<T0, T1, T2, T3> &p);

void view(const long long &e);

void view(const int &e);

template <typename T>
void view(const T &e);

template <typename T>
void view(const std::set<T> &s);

template <typename T>
void view(const std::unordered_set<T> &s);

template <typename T>
void view(const std::multiset<T> &s);

template <typename T>
void view(const std::unordered_multiset<T> &s);

template <typename T>
void view(const std::vector<T> &v);

template <typename T, std::size_t ary_size>
void view(const std::array<T, ary_size> &v);

template <typename T>
void view(const std::vector<std::vector<T>> &vv);

template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v);

template <class T0, class T1, class T2>
void view(const std::vector<std::tuple<T0, T1, T2>> &v);

template <class T0, class T1, class T2, class T3>
void view(const std::vector<std::tuple<T0, T1, T2, T3>> &v);

template <typename map_type>
void view_map_container(const map_type &m);

template <typename T, typename U>
void view(const std::map<T, U> &m);

template <typename T, typename U>
void view(const std::unordered_map<T, U> &m);

template <typename container_type>
void view_container(const container_type &c, bool vertically = false) {
	typename container_type::const_iterator begin = c.begin();
	const typename container_type::const_iterator end = c.end();
	if(vertically) {
		std::cerr << "{\n";
		while(begin != end) {
			std::cerr << '\t';
			view(*(begin++));
			if(begin != end) std::cerr << ',';
			std::cerr << '\n';
		}
		std::cerr << '}';
		return;
	}
	std::cerr << "{ ";
	while(begin != end) {
		view(*(begin++));
		if(begin != end) std::cerr << ',';
		std::cerr << ' ';
	}
	std::cerr << '}';
}

template <typename T, typename U>
void view(const std::pair<T, U> &p) {
	std::cerr << '(';
	view(p.first);
	std::cerr << ", ";
	view(p.second);
	std::cerr << ')';
}

template <class T0, class T1, class T2>
void view(const std::tuple<T0, T1, T2> &p) {
	std::cerr << '(';
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ')';
}

template <class T0, class T1, class T2, class T3>
void view(const std::tuple<T0, T1, T2, T3> &p) {
	std::cerr << '(';
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ", ";
	view(std::get<3>(p));
	std::cerr << ')';
}

void view(const long long &e) {
	if(e == INF)
		std::cerr << "INF";
	else if(e == -INF)
		std::cerr << "-INF";
	else
		std::cerr << e;
}

void view(const int &e) {
	if(e == inf)
		std::cerr << "inf";
	else if(e == -inf)
		std::cerr << "-inf";
	else
		std::cerr << e;
}

template <typename T>
void view(const T &e) {
	std::cerr << e;
}

template <typename T>
void view(const std::set<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::unordered_set<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::multiset<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::unordered_multiset<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::vector<T> &v) {
	view_container(v);
}

template <typename T, std::size_t ary_size>
void view(const std::array<T, ary_size> &v) {
	view_container(v);
}

template <typename T>
void view(const std::vector<std::vector<T>> &vv) {
	view_container(vv, true);
}

template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v) {
	view_container(v, true);
}

template <class T0, class T1, class T2>
void view(const std::vector<std::tuple<T0, T1, T2>> &v) {
	view_container(v, true);
}

template <class T0, class T1, class T2, class T3>
void view(const std::vector<std::tuple<T0, T1, T2, T3>> &v) {
	view_container(v, true);
}

template <typename map_type>
void view_map_container(const map_type &m) {
	std::cerr << "{\n";
	for(typename map_type::const_iterator it = m.begin(); it != m.end(); it++) {
		std::cerr << "\t[";
		view(it->first);
		std::cerr << "] : ";
		view(it->second);
		std::cerr << '\n';
	}
	std::cerr << "}";
}

template <typename T, typename U>
void view(const std::map<T, U> &m) {
	view_map_container(m);
}

template <typename T, typename U>
void view(const std::unordered_map<T, U> &m) {
	view_map_container(m);
}

}  // namespace viewer

// when compiling : g++ foo.cpp -DLOCAL
#ifdef LOCAL
void debug_out() {}
template <typename T>
void debug_out(const T &x) {
	viewer::view(x);
}
template <typename Head, typename... Tail>
void debug_out(const Head &H, const Tail &... T) {
	viewer::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "]\n";                                       \
	} while(0)
#else
#define debug(...) (void(0))
#endif
#line 2 "SPJ-Library/template/scanner.hpp"

#line 6 "SPJ-Library/template/scanner.hpp"

namespace scanner {
template <class T>
void scan(T &a) {
	std::cin >> a;
}

template <class T, class L>
void scan(std::pair<T, L> &p) {
	scan(p.first);
	scan(p.second);
}

template <class T0, class T1, class T2>
void scan(std::tuple<T0, T1, T2> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	scan(t0);
	scan(t1);
	scan(t2);
	p = std::make_tuple(t0, t1, t2);
}

template <class T0, class T1, class T2, class T3>
void scan(std::tuple<T0, T1, T2, T3> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	T3 t3;
	scan(t0);
	scan(t1);
	scan(t2);
	scan(t3);
	p = std::make_tuple(t0, t1, t2, t3);
}

template <class T>
void scan(std::vector<T> &a) {
	for(auto &i : a) scan(i);
}

void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner
#line 7 "SPJ-Library/template/io.hpp"

#define VEC(type, name, size) \
	vector<type> name(size);  \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                     \
	vector<vector<type>> name(h, vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)        \
	string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHR(...)      \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DBL(...)        \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define TPL3(type0, type1, type2, name)   \
	std::tuple<type0, type1, type2> name; \
	scanner::INPUT(name);
#define TPL4(type0, type1, type2, type3, name)   \
	std::tuple<type0, type1, type2, type3> name; \
	scanner::INPUT(name);

template <typename T1, typename T2>
std::istream &operator>>(std::istream &is, std::pair<T1, T2> &p) {
	is >> p.first >> p.second;
	return is;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p) {
	os << p.first << ' ' << p.second;
	return os;
}

struct fast_io {
	fast_io() {
		std::ios::sync_with_stdio(false);
		std::cin.tie(nullptr);
		std::cout << std::fixed << std::setprecision(15);
		srand((unsigned)time(NULL));
	}
} fast_io_;
#line 2 "SPJ-Library/template/macros.hpp"

#define foa(s, v) for(auto &s : v)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pcnt(n) __builtin_popcountll((long long)n)

#define REPname(a, b, c, d, e, ...) e
#define rep(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int Counter_in_rep_macro = 0; Counter_in_rep_macro < (x); ++Counter_in_rep_macro)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))
#define DREPname(a, b, c, d, e, ...) e
#define drep(...) DREPname(__VA_ARGS__, DREP3, DREP2, DREP1)(__VA_ARGS__)
#define DREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define DREP2(i, l, r) for(int i = (r)-1; i >= (l); --i)
#define DREP3(i, l, r, c) for(int i = (r)-1; i >= (l); i -= (c))

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vvvi = std::vector<std::vector<std::vector<int>>>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
template <class T = ll>
using V = std::vector<T>;
template <class T = ll>
using VV = V<V<T>>;
template <class T = ll>
using VVV = V<V<V<T>>>;
template <class T = ll>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T = ll>
using pqdn = std::priority_queue<T>;
#line 7 "SPJ-Library/template/kuma.hpp"

using namespace std;
#line 6 "a.cpp"
double solve(int n) {
	vector<double> probs(n);
	foa(p, probs) cin >> p;
	vector<int> stoppable = {0};
	rep(i, 1, n) {
		if(probs[i] < 0.995) {
			stoppable.push_back(i);
		}
	}
	stoppable.push_back(n);
	int len = int(stoppable.size());
	vector<double> ans(len, INF);
	ans.front() = 0;
	debug(stoppable);
	debug(len, ans);
	rep(i, 1, len) {
		double pass_prob = 1.;
		double dash_cost = 0.;
		double& upd = ans[i];
		drep(prev, 0, i) {
			int jump = stoppable[prev + 1] - stoppable[prev];
			double p = probs[stoppable[prev]];
			dash_cost += pass_prob * (jump - 1);
			pass_prob /= p;
			dash_cost += pass_prob;
			if(upd < dash_cost) break;
			chmin(upd, ans[prev] + dash_cost);
			debug(i, prev, pass_prob, dash_cost);
		}
		upd += 1;
		debug(ans);
	}
	return ans.back() - 1;
}
int main() {
	int n;
	while(cin >> n && n) {
		cout << solve(n) << '\n';
	}
	return 0;
}
accuracy: 1
time_ms: 1050
memory_kb: 5848
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=5005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        vector<double> P(N),dp(N+1,1e9);
        vector<int> use;
        for(int i=0;i<N;i++){
            cin>>P[i];
            if(P[i]!=1) use.push_back(i);
        }
        use.push_back(0);
        use.push_back(N-1);
        sort(all(use));
        use.erase(unique(all(use)),use.end());
        
        dp[0]=0;
        for(int i=0;i<N;i++){
            if(dp[i]==1e9) continue;
            int st=lower_bound(all(use),i)-use.begin();
            double now=0;
            int la=i-1;
            for(int j=st;j<min(si(use),st+50);j++){
                int aida=use[j]-la-1;
                now+=aida;
                chmin(dp[use[j]],dp[i]+now+1.0);
                now=(now+1.0)/P[use[j]];
                chmin(dp[use[j]+1],dp[i]+now+1.0);
                la=use[j];
            }
        }
        
        cout<<fixed<<setprecision(25)<<(dp[N]-1.0)<<endl;
    }
}
accuracy: 1
time_ms: 890
memory_kb: 5768
final_rank: 7

code_snippet: #pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#include<chrono>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}
template<typename T>
void cinarray(vector<T>& v) {
	rep(i, v.size())cin >> v[i];
}
template<typename T>
void coutarray(vector<T>& v) {
	rep(i, v.size()) {
		if (i > 0)cout << " "; cout << v[i];
	}
	cout << "\n";
}
ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	if (x == 0)return 0;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	int n;
	modint() :n(0) { ; }
	modint(ll m) {
		if (m < 0 || mod <= m) {
			m %= mod; if (m < 0)m += mod;
		}
		n = m;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 10;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

ll gcd(ll a, ll b) {
	a = abs(a); b = abs(b);
	if (a < b)swap(a, b);
	while (b) {
		ll r = a % b; a = b; b = r;
	}
	return a;
}
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;
const ld pi = acosl(-1.0);
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//-----------------------------------


int n;
void solve() {
	vector<ld> p(n);
	rep(i, n)cin >> p[i];
	/*{
		vector<ld> np;
		rep(i, n)if (p[i] != 1) {
			np.push_back(p[i]);
		}
		swap(p, np);
		n = p.size();
	}*/
	vector<ld> dp(n + 1,INF);
	vector<int> nex(n+1,n);
	per(i, n) {
		nex[i] = nex[i + 1];
		if (p[i] != 1)nex[i] = i;
	}
	dp[0] = 0;
	rep(i, n) {
		ld pro = 1;
		int cur = i;
		int tmp = 0;
		while (cur < n && tmp < 200) {
			tmp++;
			int to = nex[cur];
			pro += to - cur;
			chmin(dp[to], dp[i] + pro);
			if (to < n) {
				pro = pro / p[to] + 1;
				chmin(dp[to + 1], dp[i] + pro);
			}
			cur = to + 1;
		}
		/*Rep(j, i + 1, n+1) {
			pro = pro / p[j-1] + 1;
			chmin(dp[j], dp[i] + pro);
		}*/
	}
	cout << dp[n]-1 << "\n";
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	//init_f();
	//init();
	//while(true)
	//expr();
	//int t; cin >> t; rep(i, t)
	//cout << pow(100.0 / 99.0, 100) << "\n";
	//cout << pow(100.0 / 99.0, 200) << "\n";
	while(cin>>n,n)
	solve();
	return 0;
}
accuracy: 1
time_ms: 2980
memory_kb: 6612
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
int n;
double p[111111],dp[111111];
deque<int> q,qq;
struct node
{
	double s,p;
	node()
	{
		p=1.00;
		s=0.00;
	}
	node operator + (const node &u) const
	{
		node res;
		res.s=s+p*u.s;
		res.p=p*u.p;
		return res;
	}
}f[111111][22],cx,cy,nx,ny;
node cost(int l,int r)
{
	node res;
	for (int i=18;i>=0;i--)
	{
		if (r-(1<<i)+1>=l)
		{
			res=res+f[r][i];
			r-=(1<<i);
		}
	}
	return res;
}
int get_ver(int x,int y)//get the first point that dp[x]+cost(x+1,i)>=dp[y]+cost(y+1,i),x<y
{
	cx=cost(x+1,y);cy=node();
	int ans=y;
	for (int i=18;i>=0;i--)
	{
		if (ans+(1<<i)<=n)
		{
			nx=f[ans+(1<<i)][i]+cx;ny=f[ans+(1<<i)][i]+cy;
			if (dp[x]+nx.s<dp[y]+ny.s)
			{
				ans+=(1<<i);
				cx=nx;cy=ny;
			}
		}
	}
	return ans+1;
}
int main()
{
	while(scanf("%d",&n)==1)
	{
		if (!n) break;
		for (int i=1;i<=n;i++) scanf("%lf",&p[i]);
		for (int i=1;i<=n;i++) f[i][0].s=f[i][0].p=1.00/p[i];
		for (int i=1;i<=18;i++)
		{
			for (int j=(1<<i);j<=n;j++)
			{
				f[j][i]=f[j][i-1]+f[j-(1<<(i-1))][i-1];
			}
		}
		q.clear();qq.clear();
		q.push_back(0);qq.push_back(0);
		dp[0]=0.00;
		for (int i=1;i<=n;i++)
		{
			while(q.size()>1 && qq[1]<=i) 
			{
				q.pop_front();
				qq.pop_front();
			}
			dp[i]=dp[q.front()]+cost(q.front()+1,i).s+1.00;
			while(q.size()>1 && get_ver(q.back(),i)<=qq.back())
			{
				q.pop_back();qq.pop_back();
			}
			qq.push_back(get_ver(q.back(),i)); 
			q.push_back(i); 
		} 
		printf("%.10lf\n",dp[n]-1.00);
	}
	return 0;
}
accuracy: 1
time_ms: 1640
memory_kb: 42916
final_rank: 20

code_snippet: #include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
//#define T_ int
using namespace std;
//struct bit{T_ arr[1000005];int lowbit(int x){return x&(-x);}void add(int x,T_ y){for (int i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(int x){T_ s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{int l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){if (l>r) return;c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,T_ x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
//struct bit_2d{T_ a[2005][2005];int lowbit(int x){return x&(-x);}void add(int x,int y,T_ z){int i,j;for (i=x;i<=2000;i+=lowbit(i)){for (j=y;j<=2000;j+=lowbit(j)){a[i][j]+=z;}}}T_ query(int x,int y){int i,j;T_ s=0;for (i=x;i;i-=lowbit(i)){for (j=y;j;j-=lowbit(j)){s+=a[i][j];}}return s;}T_ query(int x,int y,int xx,int yy){return query(xx,yy)-query(x-1,yy)-query(xx,y-1)+query(x-1,y-1);}};
int n,m,i,j,t,qx[100005],ql,qr,len[100005];
double dp[100005],p[100005]; 
int main()
{
	while (scanf("%d",&n)&&n)
	{
		m=0;
		fz1(i,n)
		{
			scanf("%lf",&p[++m]);len[m]=1;
			if (m>1&&p[m]>0.995&&p[m-1]>0.995){
				m--;len[m]++;
			}
		}
		fz1(i,m)
		{
			double pro=1,tim=0;
			dp[i]=1e18;
			for (j=i;j>=i-100&&j>=0;j--){
				dp[i]=min(dp[i],dp[j]+tim+1);
				pro/=p[j];
				tim+=pro*len[j];
			}
		}
		printf("%.23lf\n",dp[m]-1);
	}
	return 0;
}
accuracy: 1
time_ms: 1170
memory_kb: 5160
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
double p[100010];
int pre[100010];
double dp[100010];
int n;
int main()
{
	while(scanf("%d",&n)!=EOF && n)
	{
		for(int i=1;i<=n;i++)scanf("%lf",p+i),p[i]=1.0/p[i];
		for(int i=1;i<=n;i++)
		{
			if(p[i-1]!=1.0 || p[i]!=1.0)pre[i]=i-1;
			else pre[i]=pre[i-1];
		}
		for(int i=1;i<=n;i++)
		{
			int t=i;
			double sum=0,mul=p[i];
			dp[i]=1e16;
			for(int j=1;j<=100 && t && sum<=1e14;j++)
			{
				sum+=(t-pre[t])*mul;
				t=pre[t];
				mul*=p[t];
				dp[i]=min(dp[i],dp[t]+sum+1);
			}
		}
		printf("%.10lf\n",dp[n]-1);
	}
	return 0;
}
accuracy: 1
time_ms: 620
memory_kb: 5148
final_rank: 4

code_snippet: /* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=100005;
int n,m;
db p[maxn],q[maxn],dp[maxn];
int len[maxn];

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	while(scanf("%d",&n)&&n>0){
		m=0;
		REP(i,n){
			scanf("%lf",&p[i]);
			if(m&&p[i]>0.999&&q[m]>0.999)len[m]++;
			else q[++m]=p[i],len[m]=1; 
		}
		dp[m+1]=0;
		for(int i=m;i>=1;i--){
			db cur=0;
			dp[i]=INF;
			for(int j=i;j<=i+100&&j<=m;j++){
				cur*=1/q[j];
				cur+=len[j]*(1/q[j]);
				dp[i]=min(dp[i],cur+dp[j+1]);
			}
			dp[i]++;
		}
		printf("%.10lf\n",dp[1]-1.0);
	}
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/
accuracy: 1
time_ms: 900
memory_kb: 5920
final_rank: 8

code_snippet: //by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod = 1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn = 100111;
const double mn = 1e20;

int n;
double a[maxn], dp[maxn];
struct data
{
	double prod, sum;
	data(double A=0, double B=0) : prod(A), sum(B) {}
	data operator + (const data &t) const
	{
		return data(prod*t.prod, t.sum+sum*t.prod); 
	}
}D[maxn][20];
data query_data(int l, int r)
{
	data ret(1, 0);
	for (int i=19; i>=0; i--)
	{
		if (r-(1<<i)>=l-1)
		{
			ret = D[r][i]+ret;
			r -= 1<<i;
		}
	}
	return ret;
}
int get_point(int x, int y)
{
//	cerr<<"get_point:"<<x<<","<<y<<endl;
	data dx = query_data(x+1, y), dy(1, 0);
	int pt = y;
	for (int i=19; i>=0; i--)
	{
		if (pt+(1<<i)<=n)
		{
			data ndx = dx+D[pt+(1<<i)][i];
			data ndy = dy+D[pt+(1<<i)][i];
			if (dp[x]+ndx.sum<dp[y]+ndy.sum)
			{
				pt += 1<<i;
				dx = ndx;
				dy = ndy;
			}
		}
	}
	return pt+1;
}
void solve()
{
	vector<int> v, pt;
	v.PB(0);
	int it = 0;
	for (int i=1; i<=n; i++)
	{
		while (it+1<v.size()&&i>=pt[it]) it++;
//		for (auto x : v) cerr<<x<<" "; cerr<<endl;
//		for (auto x : pt) cerr<<x<<" "; cerr<<endl;		
//		cerr<<v[it]<<"->"<<i<<endl;
		dp[i] = dp[v[it]]+query_data(v[it]+1, i).sum+1;
		while (pt.size()>0&&get_point(v.back(), i)<=pt.back()) v.pop_back(), pt.pop_back();
		it = min(it, int(v.size())-1);
		pt.PB(get_point(v.back(), i));
		v.PB(i);
	}
}
int main()
{
	while (true)
	{
		scanf("%d", &n);
		if (n==0) break;
		for (int i=1; i<=n; i++) scanf("%lf", &a[i]), a[i] = 1.0/a[i];
		for (int i=1; i<=n; i++)
		{
			D[i][0] = data(a[i], a[i]);
			for (int j=1; j<20; j++)
			{
				if (i>=(1<<j)) D[i][j] = D[i-(1<<j-1)][j-1]+D[i][j-1]; 
			}
		}
		/*
		for (int i=1; i<=n; i++)
		{
			dp[i] = 1e9;
			for (int j=i; j>=1; j--)
			{
				dp[i] = min(dp[i], dp[j-1]+query_data(j, i).sum+1);
			}
		}*/
		solve();
		printf("%.10lf\n", dp[n]-1);
	}
	return 0;
}
accuracy: 1
time_ms: 1930
memory_kb: 37132
final_rank: 18

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005

int N;
double P[NUM],dp[NUM];
int next_table[NUM];
bool is_100[NUM];

void func(){

	for(int i = 0; i < N; i++){
		scanf("%lf",&P[i]);
		is_100[i] = (P[i] == 1.0);
	}

	next_table[N-1] = N;
	for(int i = N-2; i >= 0; i--){
		if(!is_100[i+1]){

			next_table[i] = i+1;

		}else{

			next_table[i] = next_table[i+1];
		}
	}

	for(int i = 0; i < N; i++){
		dp[i] = HUGE_NUM;
	}
	dp[N] = 0;

	double E;
	int pre,next_save_point;

	for(int i = N-1; i >= 0; i--){

		next_save_point = next_table[i];
		pre = i;
		E = 0;

		for(int k = 0; k < 19; k++){

			E = (E+1)/P[pre]+(next_save_point-pre-1);

			if(next_save_point == N){

				dp[i] = min(dp[i],dp[next_save_point]+E);
				break;
			}else{

				dp[i] = min(dp[i],dp[next_save_point]+E+1);
			}

			pre = next_save_point;
			next_save_point = next_table[next_save_point];
		}
	}
	printf("%.10lf\n",dp[0]);
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 500
memory_kb: 5280
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int main(){
  while(1){
    int N;
    cin>>N;
    if(N==0)break;
    vector<double> A(N);
    rep(i,N)cin>>A[i];
    vector<int> tr;
    rep(i,N)if(A[i]!=1.0)tr.push_back(i);
    tr.push_back(N);
    vector<double> dp(N+1,INF);
    dp[N]=0;
    for(ll i=N-1;i>=0;i--){
      ll st=lower_bound(all(tr),i+1)-tr.begin();
      ll pre=i;
      double ex=0;
      for(ll j=st;j<st+20&&j<(ll)tr.size();j++){
        ll k=tr[j];
        ex=(ex+1.0)/A[pre]+(k-pre-1);
        minch(dp[i],dp[k]+ex+1.0);
        pre=k;
      }
    }
    printf("%.10f\n", dp[0]-1.0);
  }

  return 0;
}
accuracy: 1
time_ms: 1150
memory_kb: 5404
final_rank: 12

code_snippet: #include <bits/stdc++.h>

double ans[100010];

void MAIN(int n) {
    std::vector<double> prob;
    for(int i = 0; i < n; ++ i) {
        double p;
        scanf("%lf", &p);
        if(p < 0.995) {
            prob.push_back(p);
        } else if(prob.empty() || prob.back() < 0.995) {
            prob.push_back(p);
        } else {
            prob[prob.size() - 1] += 1;
        }
        ans[i] = 1e100;
    }
    n = prob.size();
    ans[n] = 0;
    for(int i = n - 1; i >= 0; -- i) {
        double now = 0;
        int upper = std::min(n, i + 50);
        for(int j = i + 1; j <= upper; ++ j) {
            if(prob[j - 1] >= 0.995) {
                now += prob[j - 1];
            } else {
                now = (now + 1) / prob[j - 1];
            }
            ans[i] = std::min(ans[i], now + ans[j] + 1);
        }
    }
    printf("%.11f\n", ans[0] - 1);
}

int main() {
    int n;
    while(scanf("%d", &n) == 1 && n > 0) {
        MAIN(n);
    }
    return 0;
}
accuracy: 1
time_ms: 720
memory_kb: 5448
final_rank: 5

code_snippet: #include <bits/stdc++.h>

double ans[100010];

void MAIN(int n) {
    std::vector<double> prob;
    for(int i = 0; i < n; ++ i) {
        double p;
        scanf("%lf", &p);
        if(p < 0.995) {
            prob.push_back(p);
        } else if(prob.empty() || prob.back() < 0.995) {
            prob.push_back(p);
        } else {
            prob[prob.size() - 1] += 1;
        }
        ans[i] = 1e100;
    }
    n = prob.size();
    ans[n] = 0;
    for(int i = n - 1; i >= 0; -- i) {
        double now = 0;
        int upper = std::min(n, i + 700);
        for(int j = i + 1; j <= upper; ++ j) {
            if(prob[j - 1] >= 0.995) {
                now += prob[j - 1];
            } else {
                now = (now + 1) / prob[j - 1];
            }
            ans[i] = std::min(ans[i], now + ans[j] + 1);
        }
    }
    printf("%.11f\n", ans[0] - 1);
}

int main() {
    int n;
    while(scanf("%d", &n) == 1 && n > 0) {
        MAIN(n);
    }
    return 0;
}
accuracy: 1
time_ms: 6520
memory_kb: 5436
final_rank: 17

code_snippet: //
//  main.cpp
//
//  Under GPLv3 license
//

// #pragma GCC diagnostic error "-std=c++14"
// #pragma GCC optimize("O3")
// #pragma comment(linker, "/STACK:1024000000,1024000000")

#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
// #include <unordered_map>
// #include <unordered_set>
#include <utility>
#include <vector>

#define pb push_back
#define pf push_front
#define mp make_pair

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int INF = (1 << 30) - 1;
const LL LINF = (1LL << 61) - 1;
const double EPS = 1e-10;
const int N = 1e5 + 1000;
const int LEN = 50;

int T;
int n;
vector<double> p;
double dp[N];

void init() {
  p.clear();
  memset(dp, 0, sizeof dp);
}

int main() {
// ios::sync_with_stdio(false);
// cin.tie(0);
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);

#ifndef ONLINE_JUDGE
  double __start_time = clock();
#endif

  // insert code heree

  while (scanf("%d", &n)) {
    if (n == 0) break;
    init();

    double buff = 0.00;
    for (int i = 0; i < n; i++) {
      double x;
      scanf("%lf", &x);
      if (x == 1.00) {
        buff += 1.00;
      } else {
        if (buff > 0) p.pb(buff), buff = 0.00;
        p.pb(x);
      }
    }

    if (buff > 0) p.pb(buff);

    n = (int)p.size();

    dp[n] = 0;
    for (int i = n - 1; i >= 0; i--) {
      dp[i] = INF;
      buff = 0;

      for (int j = i + 1; j <= n && j - i <= LEN; j++) {
        if (p[j - 1] < 1.00)
          buff = (buff + 1.00) / p[j - 1];
        else
          buff += p[j - 1];
        dp[i] = min(dp[i], buff + dp[j] + 1);
      }
    }

    printf("%.8lf\n", dp[0] - 1.00);
  }

#ifndef ONLINE_JUDGE
  cout << "LOCAL RUNNING TIME = "
       << double(((double)clock() - __start_time) / (double)CLOCKS_PER_SEC)
       << " sec" << endl;
#endif

  return 0;
}
accuracy: 1
time_ms: 970
memory_kb: 2960
final_rank: 3

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int main(){
	while(true){
		int N;
		double p[100000],dp[100001]={},inf=1e20;
		vector<int> vc;
		cin>>N;
		if(N==0) break;
		rep(i,N) cin>>p[i];
		rep(i,N) if(p[i]!=1) vc.pb(i);
		vc.pb(N);
		rep(i,N+1) dp[i]=inf;
		dp[N]=0;
		for(int i=N-1;i>=0;i--){
			int id=lower_bound(all(vc),i+1)-vc.begin();
			double ex=0;
			int pre=i;
			for(int j=id,cnt=0;j<vc.size()&&cnt<30;j++,cnt++){
				int v=vc[j];
				ex=(ex+1)/p[pre]+(v-pre-1);
				chmin(dp[i],ex+(v==N?0:1)+dp[v]);
				pre=v;
			}
		}
		printf("%.12f\n",dp[0]);
	}
}
accuracy: 1
time_ms: 1330
memory_kb: 3712
final_rank: 9

code_snippet: #include<stdio.h>
#include<algorithm>
#define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
#define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

using namespace std;
double b[110000];
double c[110000];
int w[110000];
double dp[110000];
int n;
double solve(int a){
	if(a==n)return 0;
	if(dp[a]>-0.5)return dp[a];
	double ret=999999999;
	double p=1;
	double ks=0;
	int val=0;
	for(int i=1;i<=100;i++){
		if(a+i>n)break;
		if(p<1e-9)break;
		val+=w[a+i-1];
		ks+=p*(1.0-c[a+i-1])*val;
		p*=c[a+i-1];
		ret=min(ret,solve(a+i)+(ks+p*val)/p+(a+i==n?0:1));
	}
	return dp[a]=ret;
}
int main(){
	BEGIN_STACK_EXTEND(60*1024*1024)
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++){
			scanf("%lf",b+i);
		}
		int now=0;
		for(int i=0;i<a;i++){
			if(i&&b[i]>0.999&&b[i-1]>0.999){
				w[now-1]++;
			}else{
				w[now]=1;
				c[now]=b[i];
				now++;
			}
		}
		n=now;
		for(int i=0;i<=n;i++){
			dp[i]=-1;
		}
		printf("%.12f\n",solve(0));
	//	for(int i=0;i<=n;i++)printf("%f ",dp[i]);
	//	printf("\n");
	}
	END_STACK_EXTEND
}
accuracy: 1
time_ms: 1180
memory_kb: 20032
final_rank: 16

code_snippet: #include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

void chmin(double &a, double b) { if (a > b) a = b; }



const int MAX = 100100;
const double INF = 1e10;
const double EPS = 1e-6;

int n, cn;
double p[MAX];
double cp[MAX];
int gap[MAX];

double dp[MAX];

int main() {
    while (cin >> n) {
        for (int i = 0; i < n; ++i) cin >> p[i];
        cn = 0;
        int next;
        for (int i = 0; i < n; i = next) {
            for (next = i+1; next < n; ++next)
                if ( abs(p[next] - 1.0) > EPS ) break;
            cp[cn] = p[i];
            gap[cn] = next-i-1;
            ++cn;
        }
            
        for (int i = 0; i < MAX; ++i) dp[i] = INF;
        dp[cn] = 0.0;
        for (int i = cn; i >= 0; --i) {
            double temp = 0.0;
            for (int j = i+1; j <= cn; ++j) {
                if (j - i >= 20) break;
                temp = (temp + 1.0) / cp[j-1] + gap[j-1];
                chmin(dp[i], dp[j] + temp + 1);
            }
        }
        
        printf("%.10f\n", dp[0] - 1);
    }
    
    return 0;
}
accuracy: 1
time_ms: 1080
memory_kb: 3972
final_rank: 6

code_snippet: #include <bits/stdc++.h>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

typedef long double ld; 
const ld INF = 1e+12;

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    vector<ld> p(n),p2(1,1);
    REP(i,n) cin>>p[i];
    int l = 0;
    vector<int> len;
    REP(i,n) {
      if (p[i] != 1) {
        len.push_back(l);
        p2.push_back(p[i]);
        l = 0;
      }
      ++l;
    }
    len.push_back(l);
    n = p2.size();
    vector<ld> dp(n+1,INF);
    dp[0] = 0;
    REP(i,n) {
      ld e = 0.0;
      REP(j,100) {
        if(i+j>=n)break;
        e = e + len[i+j] + (e+1) * (1-p2[i+j]) / p2[i+j];
        dp[i+j+1] = min(dp[i+j+1], dp[i] + e + 1);
      }
    }
    cout << setprecision(10) << fixed << dp[n] - 1 << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 2460
memory_kb: 8408
final_rank: 14