#include <cstdlib>
#include <iostream>
using namespace std;
const int sz = 1000000;
const int maxNumber = 10000;
int arr[sz];
int counting[maxNumber + 1];
void countingSort(int *arr, int l, int r) {
for (int value=0; value<=maxNumber; value++) counting[value] = 0;
for (int i=l; i<=r; i++) counting[arr[i]]++;
for (int value=0; value<=maxNumber; value++) {
while (counting[value]) {
arr[l++] = value;
counting[value]--;
}
}
}
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] = rand() % maxNumber;
}
countingSort(arr, 0, sz - 1);
cout<<(check() ? "OK": "FAIL");
return 0;
}
CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8aW9zdHJlYW0+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IHN6ID0gMTAwMDAwMDsKY29uc3QgaW50IG1heE51bWJlciA9IDEwMDAwOwoKaW50IGFycltzel07CmludCBjb3VudGluZ1ttYXhOdW1iZXIgKyAxXTsKCnZvaWQgY291bnRpbmdTb3J0KGludCAqYXJyLCBpbnQgbCwgaW50IHIpIHsKICAgIGZvciAoaW50IHZhbHVlPTA7IHZhbHVlPD1tYXhOdW1iZXI7IHZhbHVlKyspIGNvdW50aW5nW3ZhbHVlXSA9IDA7CgogICAgZm9yIChpbnQgaT1sOyBpPD1yOyBpKyspIGNvdW50aW5nW2FycltpXV0rKzsKCiAgICBmb3IgKGludCB2YWx1ZT0wOyB2YWx1ZTw9bWF4TnVtYmVyOyB2YWx1ZSsrKSB7CiAgICAgICAgd2hpbGUgKGNvdW50aW5nW3ZhbHVlXSkgewogICAgICAgICAgICBhcnJbbCsrXSA9IHZhbHVlOwogICAgICAgICAgICBjb3VudGluZ1t2YWx1ZV0tLTsKICAgICAgICB9CiAgICB9Cn0KCmJvb2wgY2hlY2soKSB7CiAgICBmb3IgKGludCBpPTA7IGk8c3otMTsgaSsrKXsKICAgICAgICBpZiAoYXJyW2ldID4gYXJyW2kgKyAxXSkgcmV0dXJuIGZhbHNlOwogICAgfQogICAgcmV0dXJuIHRydWU7Cn0KCmludCBtYWluKCl7CiAgICBmb3IgKGludCBpPTA7IGk8c3o7IGkrKykgewogICAgICAgIGFycltpXSA9IHJhbmQoKSAlIG1heE51bWJlcjsKICAgIH0KCiAgICBjb3VudGluZ1NvcnQoYXJyLCAwLCBzeiAtIDEpOwoKICAgIGNvdXQ8PChjaGVjaygpID8gIk9LIjogIkZBSUwiKTsKCiAgICByZXR1cm4gMDsKfQo=