#include <iostream>
#include <algorithm>
#include <random>
#include <ctime>
using namespace std;
const int N = 4e7;
int a[N];
int link[N];
int stack[N];
int ptr = 0;
void with_stack() {
fill_n(link, N, -1);
for (int i = 0; i < N; ++i) {
while (ptr > 0 && a[stack[ptr - 1]] <= a[i]) {
--ptr;
}
if (ptr) {
link[i] = stack[ptr - 1];
}
stack[ptr++] = i;
}
}
void without_stack() {
for (int i = 0; i < N; ++i) {
int &l = link[i];
l = i - 1;
while (l >= 0 && a[l] <= a[i]) {
l = link[l];
}
}
}
int main() {
mt19937 randint;
for (int i = 0; i < N; ++i) {
a[i] = (int)randint();
}
long long start = clock();
//with_stack();
//without_stack();
long long finish = clock();
cout << 1000 * (finish - start) / CLOCKS_PER_SEC << " ms\n";
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8cmFuZG9tPgojaW5jbHVkZSA8Y3RpbWU+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTiA9IDRlNzsKaW50IGFbTl07CmludCBsaW5rW05dOwppbnQgc3RhY2tbTl07CmludCBwdHIgPSAwOwoKdm9pZCB3aXRoX3N0YWNrKCkgewoJZmlsbF9uKGxpbmssIE4sIC0xKTsKCWZvciAoaW50IGkgPSAwOyBpIDwgTjsgKytpKSB7CgkJd2hpbGUgKHB0ciA+IDAgJiYgYVtzdGFja1twdHIgLSAxXV0gPD0gYVtpXSkgewoJCQktLXB0cjsKCQl9CgkJaWYgKHB0cikgewoJCQlsaW5rW2ldID0gc3RhY2tbcHRyIC0gMV07CgkJfQoJCXN0YWNrW3B0cisrXSA9IGk7Cgl9Cn0KCnZvaWQgd2l0aG91dF9zdGFjaygpIHsKCWZvciAoaW50IGkgPSAwOyBpIDwgTjsgKytpKSB7CgkJaW50ICZsID0gbGlua1tpXTsKCQlsID0gaSAtIDE7CgkJd2hpbGUgKGwgPj0gMCAmJiBhW2xdIDw9IGFbaV0p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