9161: Grayscale Confusion

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述


Sometimes, you may want to print a color image in grayscale mode, either because you want to save ink or your printer can only do so. However, when you do that, you may encounter a problem: some colors that are distinct in the color image may become indistinguishable in the grayscale image. This is the information loss caused by the grayscale conversion.

Of course, a good conversion from RGB (Red, Green, Blue) to Grayscale is not unique. Here, we define a property that a good conversion must satisfy: if a color (r,g,b)(r, g, b)(r,g,b) is strictly less than (r′,g′,b′)(r', g', b')(r,g,b): r<r′,g<g′,b<b′r < r', g < g', b < b'r<r,g<g,b<b, then the conversion fff must hold that f(r,g,b)<f(r′,g′,b′)f(r, g, b) < f(r', g', b')f(r,g,b)<f(r,g,b). It means that the strict partial order on color space should be preserved.

Xiao Fan is given an RGB image and you want to convert it to a grayscale image. However, Xiao Fan also want to confuse Xiao Shi by intentionally mapping two specified colors to the same grayscale value, while keeping the order of the colors. Can you help Xiao Fan to find a good conversion that confuses two given colors from nnn given colors?

输入格式


The first line of input contains an integer n (2≤n≤1000)n~(2 \leq n \leq 1\,000)n (2n1000), representing the number of distinct colors in the RGB image.
The next nnn lines of input each contain three integers ri,gi,bi (0≤ri,gi,bi≤255)r_i, g_i, b_i~ (0 \leq r_i, g_i, b_i \leq 255)ri,gi,bi (0ri,gi,bi255), representing the red, green and blue components of a color cic_ici.
The two colors that should be confused is the first two colors, c1c_1c1 and c2c_2c2.

输出格式


If it's impossible to do so, print -1\texttt{-1}-1 in one line.
Otherwise, output nnn lines, each containing an integer\textbf{integer}integer wi(0≤wi≤255)w_i (0 \leq w_i \leq 255)wi(0wi255), representing the grayscale value of the corresponding color f(ri,gi,bi)=wif(r_i, g_i, b_i) = w_if(ri,gi,bi)=wi in your solution. If there are multiple solutions, print any of them.

输入样例 复制

3
0 0 0
2 2 2
1 1 1

输出样例 复制

-1

分类标签