This page is still under construction.

Parts of this page are still being built. What you see may change.

Breaking the Equations

Time limit1sMemory limit128 MB

Summary
Pick twelve values from the given set that satisfy the six addition equations and form the lexicographically smallest tuple.
Level

Medium6 of 10

Topics
Hash map, Brute force, Sorting, Backtracking
Solved
No attempts yet

Problem

You are given a set A={a1,a2,a3,…,an}A = \{a_1, a_2, a_3, \dots, a_n\}. Every element of AA is an integer that is at least 0.

Consider these six equations.

  • c1=x1+x2c_1 = x_1 + x_2
  • x4=x3+x1x_4 = x_3 + x_1
  • x5=x6+x7x_5 = x_6 + x_7
  • x11=x8+x9x_{11} = x_8 + x_9
  • x6=x2+x10x_6 = x_2 + x_{10}
  • x12=x9+c2x_{12} = x_9 + c_2

c1c_1 and c2c_2 are integer constants. Given c1c_1 and c2c_2, write a program that solves the equations, that is, find all twelve values x1x_1 through x12x_{12}. Every xix_i must be an element of AA. Two different xix_i may take the same value. Only inputs whose equations can be solved are given.

Input

The first line contains nn, c1c_1, and c2c_2. Each of the next nn lines contains one aia_i. 12≤n≤7,00012 \le n \le 7{,}000, and each aia_i is a 32-bit integer.

Output

Print 12 lines in total: x1x_1 on the first line, x2x_2 on the second, and so on down to x12x_{12} on the twelfth.

If more than one solution exists, compare the tuples (x1,x2,…,x12)(x_1, x_2, \dots, x_{12}) position by position from the front and print only the lexicographically smallest one.

Examples2

  1. Example 1

    Input
    16 100 -30
    100
    70
    30
    10
    80
    42
    53
    95
    17
    35
    52
    12
    5
    77
    89
    1000
    
    Expected output
    70
    30
    10
    80
    52
    35
    17
    10
    42
    5
    52
    12
    
  2. Example 2

    Input
    12 5 -1
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    Expected output
    1
    4
    1
    2
    6
    5
    1
    1
    2
    1
    3
    1