#include <iostream>
using namespace std;
int NUM_ROUNDS = 100000000;
int main() {
int tot = 0;
for(int test = 0; test <= NUM_ROUNDS; test++){
int cards = 1;
for(int round = 1;; round++){
int ncards = 0;
for(int i = 0; i < cards; i++){
if(rand() % 4 == 0){
ncards += 2;
}
}
if(ncards == 0){
tot += round;
break;
} else {
cards = ncards;
}
}
}
cout << (double)tot / NUM_ROUNDS;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IE5VTV9ST1VORFMgPSAxMDAwMDAwMDA7CgppbnQgbWFpbigpIHsKCWludCB0b3QgPSAwOwoJZm9yKGludCB0ZXN0ID0gMDsgdGVzdCA8PSBOVU1fUk9VTkRTOyB0ZXN0KyspewoJCWludCBjYXJkcyA9IDE7CgkJZm9yKGludCByb3VuZCA9IDE7OyByb3VuZCsrKXsKCQkJaW50IG5jYXJkcyA9IDA7CgkJCWZvcihpbnQgaSA9IDA7IGkgPCBjYXJkczsgaSsrKXsKCQkJCWlmKHJhbmQoKSAlIDQgPT0gMCl7CgkJCQkJbmNhcmRzICs9IDI7CgkJCQl9CgkJCX0KCQkJaWYobmNhcmRzID09IDApewoJCQkJdG90ICs9IHJvdW5kOwoJCQkJYnJlYWs7CgkJCX0gZWxzZSB7CgkJCQljYXJkcyA9IG5jYXJkczsKCQkJfQoJCX0KCX0KCWNvdXQgPDwgKGRvdWJsZSl0b3QgLyBOVU1fUk9VTkRTOwp9