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
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <set>
#include <unordered_map>
using namespace std;


int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  int n;
  unordered_map<int64_t, int64_t> weight_to_count;
  cin >> n;
  vector<int64_t> weights(n);
  int64_t temp;
  for (int i = 0; i < n; ++i) {
    cin >> temp;
    weights[i] = temp;
  }
  vector<int64_t> remember = weights;
  std::sort(weights.begin(), weights.end());

  int64_t last_seg_sum = weights[0];
  vector<int64_t> cons_sums;
  int64_t last_w = weights[0];
  vector<int64_t> diff_vals(1, last_w);

  for (int i = 1; i < n; ++i) {
    if (weights[i] != last_w) {
      cons_sums.push_back(last_seg_sum);
      last_seg_sum = 0;
      last_w = weights[i];
      diff_vals.push_back(last_w);
    }
    last_seg_sum += weights[i];
  }
    cons_sums.push_back(last_seg_sum);
  for (int i = 1; i <= cons_sums.size(); ++i){
    cons_sums[i] += cons_sums[i - 1];
  }

  if (diff_vals.size() == 1) {
    for (int i = 0; i < n; ++i) {
      cout << 'N';
    }
    return 0;
  }
//  for (int i = 0; i < diff_vals.size(); ++i) {
//    cout << diff_vals[i] << " -- " << cons_sums[i]  << '\n';
//  }

  int len = cons_sums.size();
  int64_t act_max = diff_vals[diff_vals.size() - 1];
  for (int i = len - 1; i > 0; --i) {
    if (cons_sums[i]> act_max) {
      act_max = diff_vals[i];
    }
  }

  char resp;
  for (int i = 0; i < n; ++i) {
    resp = remember[i] >= act_max ? 'T' : 'N';
    cout << resp;
  }
  return 0;
}