#include <iostream>
#include <algorithm>
#include <functional>
bool PlanA() { return true; }
bool PlanB() { return true; }
bool PlanC() { return false; }
bool Error() { return true; }
int main() {
using namespace std;
function<bool()> steps[] = { PlanA, PlanB, PlanC, Error,
[](){ return false; } /* sentinal */ };
auto failed_at = begin(steps);
while( (*failed_at++)() )
;
cout << "failed at: " << distance( begin(steps), failed_at ) << endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KIApib29sIFBsYW5BKCkgeyByZXR1cm4gdHJ1ZTsgfQpib29sIFBsYW5CKCkgeyByZXR1cm4gdHJ1ZTsgfQpib29sIFBsYW5DKCkgeyByZXR1cm4gZmFsc2U7IH0KYm9vbCBFcnJvcigpIHsgcmV0dXJuIHRydWU7IH0KIAppbnQgbWFpbigpIHsKICAgIAogICAgdXNpbmcgbmFtZXNwYWNlIHN0ZDsKICAgIAogICAgZnVuY3Rpb248Ym9vbCgpPiBzdGVwc1tdID0geyBQbGFuQSwgUGxhbkIsIFBsYW5DLCBFcnJvciwgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFtdKCl7IHJldHVybiBmYWxzZTsgfSAvKiBzZW50aW5hbCAqLyB9OwogICAgYXV0byBmYWlsZWRfYXQgPSBiZWdpbihzdGVwcyk7CiAgICB3aGlsZSggKCpmYWlsZWRfYXQrKykoKSApCiAgICAgICAgOwogICAgICAgIAogICAgY291dCA8PCAiZmFpbGVkIGF0OiAiIDw8IGRpc3RhbmNlKCBiZWdpbihzdGVwcyksIGZhaWxlZF9hdCApIDw8IGVuZGw7Cn0=