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
#include <iostream>
#include <vector>
#include <map>
#include <set>

using weight_t = uint32_t;
using order_t = std::vector<weight_t>;
using stat_t = std::map<weight_t, uint32_t>;

struct sum_t
{
	order_t order;
	stat_t stat;
	stat_t stat2;

	void add_sum(weight_t w)
	{
		order.emplace_back(w);
		if (stat.find(w) == stat.end())
		{
			stat.emplace(std::make_pair(w, 1));
		}
		else
		{
			stat[w] += 1;
		}	
	}
	
	friend std::istream& operator>>(std::istream& in, sum_t& s)
	{
		uint32_t size;
		in >> size;
		s.order.reserve(size);
		for (;size > 0; --size)
		{
			weight_t w;
			in >> w;
			s.add_sum(w);
		}
		return in;
	}

	void process(std::ostream& out)
	{
		auto it = stat.begin();
		weight_t sums_sum = 0;
		while (it != stat.end())
		{
			sums_sum += it->second * it->first;
			stat2.emplace(it->first, sums_sum);
			++it;
		}
	}

	weight_t get_cut_point()
	{
		auto rit = stat2.rbegin();
		weight_t prev = rit->first;
		++rit;
		for (; rit != stat2.rend(); ++rit)
		{
			if (rit->second < prev)
			{
				return rit->first;
			}
		}
		if (stat2.size() > 1)
		{
			return stat2.begin()->first;
		}
		else
		{
			return 0;
		}
	}

	void print_stat(std::ostream& out, stat_t const& st) const
	{
		for(auto it = st.begin(); it != st.end(); ++it)
		{
			out << "[" << it->first << "] -> ";
			out << it->second << "\n"; 
		}
	}
	
	void print_stats(std::ostream& out) const
	{
		out << "stat:\n";
		print_stat(out, stat);
		out << "stat2:\n";
		print_stat(out, stat2);
	}

	friend std::ostream& operator<<(std::ostream& out, sum_t const& s)
	{
		s.print_stats(out);
		return out;
	}
	
	void print_result(std::ostream& out, weight_t cp)
	{
		for(auto const& e : order)
		{
			out << (e <= cp ? "N" : "T");
		}
		out << std::endl;
	}
};

uint32_t solution(std::istream& input, std::ostream& out)
{
	uint32_t result = 0;
	sum_t sum;
	input >> sum;
	sum.process(out);
	weight_t cp = sum.get_cut_point();
//	out << sum;
	sum.print_result(out, cp);
	return result;
}

#ifndef TEST
int main(int argc, char* argv[])
{
	solution(std::cin, std::cout);
	return 0;
}
#endif