#include <cstdlib>
#include <iostream>
using namespace std;
const int sz = 1000000;
int arr[sz];
int random(int a, int b) {
return a + rand() % (b - a + 1);
}
void quickSort(int *arr, int l, int r) {
if (l >= r) return;
int i = l, j = r;
int X = arr[random(l, r)];
while (i < j) {
while (arr[i] < X) i++;
while (arr[j] > X) j--;
if (i <= j) swap(arr[i++], arr[j--]);
}
quickSort(arr, i, r);
quickSort(arr, l, j);
}
bool check() {
for (int i=0; i<sz-1; i++){
if (arr[i] > arr[i + 1]) return false;
}
return true;
}
int main(){
for (int i=0; i<sz; i++) {
arr[i] = random(1, 1000000);
}
quickSort(arr, 0, sz - 1);
cout<<(check() ? "OK": "FAIL");
return 0;
}
CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8aW9zdHJlYW0+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IHN6ID0gMTAwMDAwMDsKaW50IGFycltzel07CgppbnQgcmFuZG9tKGludCBhLCBpbnQgYikgewogICAgcmV0dXJuIGEgKyByYW5kKCkgJSAoYiAtIGEgKyAxKTsKfQoKdm9pZCBxdWlja1NvcnQoaW50ICphcnIsIGludCBsLCBpbnQgcikgewogICAgaWYgKGwgPj0gcikgcmV0dXJuOwoKICAgIGludCBpID0gbCwgaiA9IHI7CiAgICBpbnQgWCA9IGFycltyYW5kb20obCwgcildOwoKICAgIHdoaWxlIChpIDwgaikgewogICAgICAgIHdoaWxlIChhcnJbaV0gPCBYKSBpKys7CiAgICAgICAgd2hpbGUgKGFycltqXSA+IFgpIGotLTsKICAgICAgICBpZiAoaSA8PSBqKSBzd2FwKGFycltpKytdLCBhcnJbai0tXSk7CiAgICB9CgogICAgcXVpY2tTb3J0KGFyciwgaSwgcik7CiAgICBxdWlja1NvcnQoYXJyLCBsLCBqKTsKfQoKCmJvb2wgY2hlY2soKSB7CiAgICBmb3IgKGludCBpPTA7IGk8c3otMTsgaSsrKXsKICAgICAgICBpZiAoYXJyW2ldID4gYXJyW2kgKyAxXSkgcmV0dXJuIGZhbHNlOwogICAgfQogICAgcmV0dXJuIHRydWU7Cn0KCmludCBtYWluKCl7CiAgICBmb3IgKGludCBpPTA7IGk8c3o7IGkrKykgewogICAgICAgIGFycltpXSA9IHJhbmRvbSgxLCAxMDAwMDAwKTsKICAgIH0KCiAgICBxdWlja1NvcnQoYXJyLCAwLCBzeiAtIDEpOwoKICAgIGNvdXQ8PChjaGVjaygpID8gIk9LIjogIkZBSUwiKTsKCiAgICByZXR1cm4gMDsKfQo=