#include <bits/stdc++.h>
using namespace std;
int ternarySearch(int l, int r, int key, vector<int> ar)
{
if (r >= l) {
int mid1 = l + (r - l) / 3;
int mid2 = r - (r - l) / 3;
if (ar[mid1] == key) {
return mid1;
}
if (ar[mid2] == key) {
return mid2;
}
if (key < ar[mid1]) {
return ternarySearch(l, mid1 - 1, key, ar);
}
else if (key > ar[mid2]) {
return ternarySearch(mid2 + 1, r, key, ar);
}
else {
return ternarySearch(mid1 + 1, mid2 - 1, key, ar);
}
}
return -1;
}
int main()
{
int n; cin >> n;
vector<int> a(n);
for(int i=0; i<n; i++){
cin >> a[i];
}
cout << ternarySearch(0, n-1, 5, a);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgdGVybmFyeVNlYXJjaChpbnQgbCwgaW50IHIsIGludCBrZXksIHZlY3RvcjxpbnQ+IGFyKQp7CiAgICBpZiAociA+PSBsKSB7CiAgICAgICAgaW50IG1pZDEgPSBsICsgKHIgLSBsKSAvIDM7CiAgICAgICAgaW50IG1pZDIgPSByIC0gKHIgLSBsKSAvIDM7CiAgICAgICAgaWYgKGFyW21pZDFdID09IGtleSkgewogICAgICAgICAgICByZXR1cm4gbWlkMTsKICAgICAgICB9CiAgICAgICAgaWYgKGFyW21pZDJdID09IGtleSkgewogICAgICAgICAgICByZXR1cm4gbWlkMjsKICAgICAgICB9CiAgICAgICAgaWYgKGtleSA8IGFyW21pZDFdKSB7CiAgICAgICAgICAgIHJldHVybiB0ZXJuYXJ5U2VhcmNoKGwsIG1pZDEgLSAxLCBrZXksIGFyKTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAoa2V5ID4gYXJbbWlkMl0pIHsKICAgICAgICAgICAgcmV0dXJuIHRlcm5hcnlTZWFyY2gobWlkMiArIDEsIHIsIGtleSwgYXIpOwogICAgICAgIH0KICAgICAgICBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIHRlcm5hcnlTZWFyY2gobWlkMSArIDEsIG1pZDIgLSAxLCBrZXksIGFyKTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gLTE7Cn0KaW50IG1haW4oKQp7CiAgICBpbnQgbjsgY2luID4+IG47CiAgICB2ZWN0b3I8aW50PiBhKG4pOwogICAgZm9yKGludCBpPTA7IGk8bjsgaSsrKXsKICAgICAgICBjaW4gPj4gYVtpXTsKICAgIH0KICAgIGNvdXQgPDwgdGVybmFyeVNlYXJjaCgwLCBuLTEsIDUsIGEpOwp9Cg==