#include <bits/stdc++.h>
using namespace std;
int process() {
int previous_result = -1;
int tosses = 0;
while(true) {
int x = rand() % 2;
++tosses;
if(previous_result == 1 && x == 1) {
return tosses;
}
previous_result = x;
}
}
int main() {
const int tries = 8000000;
double sum = 0;
for(int rep = 0; rep < tries; ++rep) {
sum += process();
}
printf("%lf\n", sum / tries); // average value
}
// N tries -> precision 1/sqrt(N)
// 10^6 -> precision 0.001
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgcHJvY2VzcygpIHsKCWludCBwcmV2aW91c19yZXN1bHQgPSAtMTsKCWludCB0b3NzZXMgPSAwOwoJd2hpbGUodHJ1ZSkgewoJCWludCB4ID0gcmFuZCgpICUgMjsKCQkrK3Rvc3NlczsKCQlpZihwcmV2aW91c19yZXN1bHQgPT0gMSAmJiB4ID09IDEpIHsKCQkJcmV0dXJuIHRvc3NlczsKCQl9CgkJcHJldmlvdXNfcmVzdWx0ID0geDsKCX0KfQoKaW50IG1haW4oKSB7Cgljb25zdCBpbnQgdHJpZXMgPSA4MDAwMDAwOwoJZG91YmxlIHN1bSA9IDA7Cglmb3IoaW50IHJlcCA9IDA7IHJlcCA8IHRyaWVzOyArK3JlcCkgewoJCXN1bSArPSBwcm9jZXNzKCk7Cgl9CglwcmludGYoIiVsZlxuIiwgc3VtIC8gdHJpZXMpOyAvLyBhdmVyYWdlIHZhbHVlCn0KCi8vIE4gdHJpZXMgLT4gcHJlY2lzaW9uIDEvc3FydChOKQovLyAxMF42IC0+IHByZWNpc2lvbiAwLjAwMQ==