CF 208B
void solve() {
vector<int> st;
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
// reverse order
int ans = 0;
for (int i = 1; i <= n; ++i) {
while (st.size() && a[st.back()] < a[i]) st.pop_back();
if (st.size()) {
ans = max(ans, a[st.back()] ^ a[i]);
}
st.push_back(i);
}
// non-reverse order
for (int i = n; i >= 1; --i) {
while (st.size() && a[st.back()] < a[i]) st.pop_back();
if (st.size()) {
ans = max(ans, a[st.back()] ^ a[i]);
}
st.push_back(i);
}
cout << ans << '\n';
return;
}
CF 1394A