codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

342A.md (1591B)


      1 Source: https://codeforces.com/problemset/problem/342/A
      2 
      3 A. Xenia and Divisors
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*, *b*, *c* the following conditions held:
     22 
     23 * *a* < *b* < *c*;
     24 * *a* divides *b*, *b* divides *c*.
     25 
     26 Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has ![](https://espresso.codeforces.com/4de0f387b35d0865b1f96d528b2f1b06fb6f1903.png) groups of three.
     27 
     28 Help Xenia, find the required partition or else say that it doesn't exist.
     29 
     30 Input
     31 
     32 The first line contains integer *n* (3 ≤ *n* ≤ 99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
     33 
     34 It is guaranteed that *n* is divisible by 3.
     35 
     36 Output
     37 
     38 If the required partition exists, print ![](https://espresso.codeforces.com/4de0f387b35d0865b1f96d528b2f1b06fb6f1903.png) groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
     39 
     40 If there is no solution, print -1.
     41 
     42 Examples
     43 
     44 Input
     45 
     46 ```
     47 6  
     48 1 1 1 2 2 2
     49 ```
     50 
     51 Output
     52 
     53 ```
     54 -1
     55 ```
     56 
     57 Input
     58 
     59 ```
     60 6  
     61 2 2 1 1 4 6
     62 ```
     63 
     64 Output
     65 
     66 ```
     67 1 2 4  
     68 1 2 6
     69 ```