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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include <cstdio>
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdint.h>
#include <unordered_set>
#include <algorithm>
#include <vector>
#include <functional>


using namespace std;


struct Fish
{
    int32_t iPos;
    int32_t iMass;

    bool operator<(const Fish & rhs) const
    {
        return iMass < rhs.iMass;
    }
};


struct SameFish
{
    int32_t iMassOfOne;
    int64_t iSum2Bottom;

    vector<int32_t> vPos;
};


static int32_t iN, iSameFishCnt;

static Fish aFish[500000];

static SameFish aSameFish[500000];

static char aAnswer[500002];


static void ReadData()
{
    cin >> iN;

    for (int i = 0; i < iN; ++i)
    {
        aFish[i].iPos = i;

        cin >> aFish[i].iMass;
    }
}


static inline void CloseSameFish(int iSameFish)
{
    if (iSameFish == 0)
        return;

    if (iSameFish == 1)
    {
        aSameFish[1].iSum2Bottom = aSameFish[0].iMassOfOne * aSameFish[0].vPos.size()
                                 + aSameFish[1].iMassOfOne * aSameFish[1].vPos.size();
        return;
    }

    aSameFish[iSameFish].iSum2Bottom = aSameFish[iSameFish - 1].iSum2Bottom
                                     + aSameFish[iSameFish].iMassOfOne * aSameFish[iSameFish].vPos.size();
}


static void Init()
{
    sort(aFish, aFish + iN);

    int iCurrSameFish = 0;

    aSameFish[0].iMassOfOne = aFish[0].iMass;
    aSameFish[0].vPos.push_back(aFish[0].iPos);
    aSameFish[0].iSum2Bottom = 0;

    for (int i = 1; i < iN; ++i)
    {
        if (aSameFish[iCurrSameFish].iMassOfOne == aFish[i].iMass)
        {
            aSameFish[iCurrSameFish].vPos.push_back(aFish[i].iPos);
            continue;
        }

        CloseSameFish(iCurrSameFish++);

        aSameFish[iCurrSameFish].iMassOfOne = aFish[i].iMass;
        aSameFish[iCurrSameFish].vPos.push_back(aFish[i].iPos);
    }

    CloseSameFish(iCurrSameFish);

    iSameFishCnt = iCurrSameFish + 1;
}


static void Mark(int iStart, int iEnd, char cMark)
{
    for (int i = iStart; i <= iEnd; ++i)
    {
        for (int32_t iPos : aSameFish[i].vPos)
        {
            aAnswer[iPos] = cMark;
        }
    }
}


static void Solve()
{
    if (iSameFishCnt == 1)
    {
        Mark(0, 0, 'N');
        return;
    }

    int iNotKing;

    for (int i = iSameFishCnt - 1; i > 0; --i)
    {
        if (aSameFish[i].iMassOfOne >= aSameFish[i - 1].iSum2Bottom)
        {
            iNotKing = i - 1;
            break;
        }
    }

    Mark(0, iNotKing, 'N');
    Mark(iNotKing + 1, iSameFishCnt - 1, 'T');
}


int main(int argc, char * argv[])
{
    ReadData();

    Init();

    Solve();

    aAnswer[iN] = 0;

    cout << aAnswer;

    return 0;
}