1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
/* -----------------------
Autor: Tomasz Boguslawski
-------------------------- */
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<sstream>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include <fstream>
#include<math.h>

#define FOR(x, b, e) for(long x = b; x <= (e); x++)
#define FORD(x, b, e) for(long x = b; x >= (e); x--)
#define VAR(v, n) __typeof(n) v = (n)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define DEBUG if (debug)
#define MIN(a,b) ((a>b)?b:a)
#define MAX(a,b) ((a>b)?a:b)
#define LL long long

using namespace std;

LL barr;
LL a[501000];
vector<LL> b(501000);
LL s[501000];
LL n;
LL smallest, largest;

bool X(LL k)
{
    return k>=barr;
}

bool isKing(LL k)
{
    // k - indeks w wektorze "b"
    LL weight = b[k];
    FOR(i,0,n-1) if (i!=k)
    {
        if (b[i]<weight)
        {
            weight+=b[i];
            if (weight>largest) return true;
        }
        else
        {
            return false;
        }
    }
}

LL findSmallest(LL low, LL high)
{
    if (high-low > 5)
    {
        LL mid = (high+low)/2;
        if (isKing(mid)) return findSmallest(low, mid);
        else return findSmallest(mid+1, high);
    }
    else
    {
        FOR(i,low,high) if (isKing(i)) return i;
        return -1;
    }
}

/// MAIN
int main(int argc, char* argv[])
{
    // magic formula, which makes streams work faster:
	ios_base::sync_with_stdio(0);

    cin >> n;
    FOR(i,1,n) { cin >> a[i]; b[i-1]=a[i]; };
    sort(b.begin(), b.begin()+n);
    s[0]=0; FOR(i,1,n) s[i]=s[i-1]+b[i-1];
    //FOR(i,1,n) cout << a[i] << " "; cout << "\n";
    //FOR(i,1,n) cout << b[i-1] << " "; cout << "\n";
    //FOR(i,1,n) cout << s[i] << " "; cout << "\n";
    smallest=b[0]; largest=b[n-1];
    //FOR(i,1,n) cout << isKing(i-1) << " "; cout << "\n";
    LL smallestKingNr = findSmallest(0,n-1);
    LL smallestKing=-1; if (smallestKingNr!=-1) smallestKing=b[smallestKingNr];
    //cout << smallestKing << "\n";

    if (smallestKing==-1) FOR(i,1,n) cout << 'N';
    else FOR(i,1,n) if (a[i]>=smallestKing) cout << 'T'; else cout << 'N';
    cout << "\n";
    return 0;
};