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
#include <cstdio>
#include <cstdlib>

typedef long long int lli;
const int NN = 500500;
int s[NN];
int orig[NN];

int find_min(int *s, int N) {
  lli sum = 0;
  int eater = 0;
  int eaten = 0;

  for (int prev = s[0]; s[eaten] == prev; sum += prev) {
    if (++eaten == N) {
      return 1000111222;
    }
  }
  
  while (eaten < N) {
    eater = eaten;
    sum += s[eater];
    eaten = eater + 1;

    for (; eaten < N && sum > s[eaten]; ++eaten) {
      sum += s[eaten];
    }
  }
  return s[eater];
}

int main() {
  int N;

  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &orig[i]);
    s[i] = orig[i];
  }
  qsort(s, N, sizeof(int), [](const void *a, const void *b) { return *((int *)a) - *((int *)b); });

  int min = find_min(s, N);

  for (int i = 0; i < N; ++i) {
    printf("%c", (orig[i] >= min) ? 'T' : 'N');
  }
  printf("\n");

  return 0;
}