CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • May Cook-Off 2013
    • May Challenge 2013
    • April Cook-Off 2013
    • April Challenge 2013
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • Campus Chapters
    • Host your Contest
    • Go for Gold
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
    • Top Contributors on Discuss
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » December Challenge 2012 » Arigeom Beats

Arigeom Beats

Problem code: ARIGEOM

  • All Submissions

All submissions for this problem are available.

Our amazing Chef recently met his best friend Joe at his place. Joe is a musician and owns a wide variety of musical instruments. He got introduced to the Arigeom beats in a music training session at Los Angeles. Arigeom beats, as the name suggests, is a combination of two series of beats. One of them has all its frequencies in arithmetic progression while the other series of beats has all its frequencies in geometric progression.

A series of beats is represented by a beat notation, which is the sequence of the frequencies at which the beats are played.

To play Arigeom beats, two digital musical instruments are played simultaneously in front of an instrument known as Sono Phone. One instrument plays the beats in arithmetic progression while the other instrument plays the beats in geometric progression. Sono Phone will capture the beats played by each of the two instruments and process them into Arigeom beats. It will merge the beats, sort the beats in ascending order, and remove duplicate beats.

For example, suppose one instruments plays the following beats notation: (2, 5, 8, 11), an arithmetic progression, while the other plays (2, 4, 8, 16), a geometric progression. The resulting Arigeom beat notation recorded by Sono Phone will be (2, 4, 5, 8, 11, 16).

Because Joe knows how to play Arigeom beats, owns the instruments, and has his friend Chef with him as well, he can't wait anymore to play the beats. Joe has an Arigeom beat notation from his music book and decides that he would play the beats in arithmetic progression while Chef will play the beats in geometric progression. The beat notation consists of N beat frequencies F1, F2, ..., FN. However, he is now confused as to which subset of the beats has to be played by Chef and which one by himself.

Help Joe and Chef figure out the subsets of beats to be played by Joe and Chef.

Input

The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. For each test case, the first line contains an integer N. The second line contains N space-separated integers F1, F2, ..., FN.

Output

For each test case, output two lines. The first line contain the beat notation to be played by Joe (in arithmetic progression). The second line contain the beat notation to be played by Chef (in geometric progression). Each beat notation must contain at least two beats. The beats in each beat notation must be sorted in ascending order.

If there are more than one possible pair of beat notations, output any one of them.

Constraints

1 ≤ T ≤ 100
2 ≤ N ≤ 10,000
1 ≤ Fi ≤ 100,000
F1 < F2 < ... < FN
It is guaranteed that at least one pair of valid beat notations exists.

Example

Input:
4
6
2 4 5 8 11 16
5
1 2 3 4 5
8
1 3 9 10 19 27 28 81
6
1 4 7 10 13 25
Output: 2 5 8 11
2 4 8 16
1 2 3 4 5
1 2 4
1 10 19 28
1 3 9 27 81
1 7 13
4 10 25

Note

In last example, the common ratio is 2.5 (non-integer) even when all the elements of geometric progression sequence are integers.


Author: ankul_iiita
Tester: laycurse
Editorial http://discuss.codechef.com/problems/ARIGEOM
Date Added: 29-08-2012
Time Limit: 0.5 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

is it like the no of ap terms

shadow9517 @ 1 Dec 2012 04:06 PM
is it like the no of ap terms and the no of gp terms should be equal or +-1 ?

@shadow9517 The numbers of

hiroto_adm @ 1 Dec 2012 04:12 PM
@shadow9517 The numbers of terms of arithmetic progression and geometric progression can be different (even don't have to +-1).

Can the F_i be negative?

venuswitharms @ 1 Dec 2012 05:12 PM
Can the F_i be negative?

@venuswitharms See

hiroto_adm @ 1 Dec 2012 05:58 PM
@venuswitharms See Constraints

can any AP/GP be empty ?

jatin_105 @ 1 Dec 2012 08:00 PM
can any AP/GP be empty ?

Is a constant sequence valid

damians @ 1 Dec 2012 10:04 PM
Is a constant sequence valid AP/GP? Like (1,1,1).

@jatin_105 See Output, then

hiroto_adm @ 2 Dec 2012 01:55 AM
@jatin_105 See Output, then both of your comment will be resolved.

@hackiftekhar The answer may

hiroto_adm @ 2 Dec 2012 01:56 AM
@hackiftekhar The answer may not be unique. Example shows one of correct outputs.

@damians AP/GP should be

hiroto_adm @ 2 Dec 2012 01:58 AM
@damians AP/GP should be strictly ascending order. Constraint sequences are not valid.

@jatin_105, Read the problem

ankul_adm @ 2 Dec 2012 02:28 AM
@jatin_105, Read the problem carefully, its mentioned in the problem.

if n=2 and given array is 2,4

ab1234 @ 2 Dec 2012 08:51 AM
if n=2 and given array is 2,4 then ap is 2,4 while gp 2,4? it means we have to print atleast 2 elements of each series such that union of these is equal to given input array?

@ab1234, yes the two series

ankul_adm @ 2 Dec 2012 02:40 PM
@ab1234, yes the two series must have atleast 2 elements and the union of the two series should give you back the input array.

@zhouyuchen, Yes you can

ankul_adm @ 3 Dec 2012 12:03 AM
@zhouyuchen, Yes you can output "3 4 5 n 1 2". "If there are more than one possible pair of beat notations, output any one of them."

can the output of this 1 4 7

sabby88 @ 4 Dec 2012 08:31 PM
can the output of this 1 4 7 10 13 25 be also AP: 1 4 7 10 13 and GP: 1 25

@sabby88, I would not

ankul_adm @ 4 Dec 2012 10:32 PM
@sabby88, I would not entertain such questions, please read the problem statement carefully and you should be able to decide based on the constraints given.

for last example 1 4 7 10 13

nagato @ 5 Dec 2012 11:55 PM
for last example 1 4 7 10 13 25 , can gp contain only 1,4 or does ap and gp together have to exhaust the given input string?

@nagato, read the problem

ankul_adm @ 6 Dec 2012 09:06 PM
@nagato, read the problem statement carefully. The two ap and gp sequences must give back the full input string on merging.

do the series have to start

javert @ 10 Dec 2012 11:46 AM
do the series have to start as low as possible, so in the 3rd example the goemetric answer given is "1 3 9 27 81" but would "3 9 27 81" be correct as well (as the 1 has been covered in the arithmetic series)

@adm are these the only

mayank_natani @ 10 Dec 2012 12:35 PM
@adm are these the only constraints to the output ?: 1. both the seq should be in ap and gp respectively. 2. both the seq should have at-least two terms. 3. both the seq should give input seq on merging. is there something like you should output longest possible ap and gp , which also fulfill the above three requirements ??

@javert and @mayank_natani,

ankul_adm @ 10 Dec 2012 03:45 PM
@javert and @mayank_natani, Did you guys miss out the statement "If there are more than one possible pair of beat notations, output any one of them." in the Output section of the problem?

for 3 4 5 6 7, would "3 4" be

n2n_ @ 11 Dec 2012 12:54 AM
for 3 4 5 6 7, would "3 4" be correct as a GP (with ratio as 4/3)?

SUCCESSFUL SUBMISSIONS


Fetching successful submissions

CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.