11
22
2015
0

[Codeforces Round #325] Lizard Era: Beginning


F. Lizard Era: Beginning
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana and Worrigan. Overall the game hasn mandatory quests. To perform each of them, you need to take exactly two companions.

The attitude of each of the companions to the hero is an integer. Initially, the attitude of each of them to the hero of neutral and equal to 0. As the hero completes quests, he makes actions that change the attitude of the companions, whom he took to perform this task, in positive or negative direction.

Tell us what companions the hero needs to choose to make their attitude equal after completing all the quests. If this can be done in several ways, choose the one in which the value of resulting attitude is greatest possible.

Input

The first line contains positive integer n (1 ≤ n ≤ 25) — the number of important tasks.

Next n lines contain the descriptions of the tasks — the i-th line contains three integers li, mi, wi — the values by which the attitude of Lynn, Meliana and Worrigan respectively will change towards the hero if the hero takes them on the i-th task. All the numbers in the input are integers and do not exceed 107 in absolute value.

Output

If there is no solution, print in the first line "Impossible".

Otherwise, print n lines, two characters is each line — in the i-th line print the first letters of the companions' names that hero should take to complete the i-th task ('L' for Lynn, 'M' for Meliana, 'W' for Worrigan). Print the letters in any order, if there are multiple solutions, print any of them.

Sample test(s)
input
3
1 0 0
0 1 0
0 0 1
output
LM
MW
MW
input
7
0 8 9
5 9 -2
6 -8 -7
9 4 5
-4 -9 9
-4 5 2
-6 8 -7
output
LM
MW
LM
LW
MW
LM
LW
input
2
1 0 0
1 1 0
output
Impossible

题目大意:有n个重要任务和3个城市,每个任务对于3个城市分别有一定的贡献值(可能是负数),每完成一个任务可以选择两个城市并获得对应的贡献值。求一个选择城市的方案使得完成所有任务后对3个城市的贡献值相等。


用Meet-in-the-Middle分两半搜索,再合并状态寻找解。

代码在此。

Category: 题解 | Tags: Codeforces 搜索 | Read Count: 516

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com