Sphere Online Judge

Computer geeks! Show off your skills and claim the job of your dreams! RecruitCoders.com

SPOJ Problem Set (classical)

1713. Funny scales

Problem code: SCALE

Kinh_Can has a set of precious weights P1, P2, ..., PN in which the mass of the ith weight is Pi = 3i-1, and a balance with 2 scales. On a nice day, Kinh_Can decided to show off his set of precious weights to his friends, and said that he can put them in equilibrium with any weight as long as its mass is not more than the mass of the sum of his weights. At first, his friends didn't believe, but after many trials they realized that Kinh_Can was right. In addition, while putting a thing whose mass is X on a scale, Kinh_Can could put right away the weights added on the 2 scales to keep their blance without any trial. With a random weight X (X is a natural number, X ≠ 0). Your task is to put weights on scales in order to keep the 2 scales' balance like Kinh_Can. The first scale initially weights X, and the second one weights 0.

Input

Input has exactly one line consisting 2 numbers, the first is N and the second is X.

Output

  • If there is no solution, you should write -1
  • If there is at least one solution for the problem, you should write exactly 2 lines:
    • The first line contains some numbers descripting the indices of the weights in the first disc
    • The second line contains some numbers description the indices of the weights in the second disc
    • Note: One of 2 lines can be blank

Constraints

  • 1 ≤ N ≤ 20
  • 1 ≤ X ≤ 2000000000

Example

Input 1:
10 2

Output 1:
1
2

Input 2:
10 5

Output 2:
1 2
3


Added by:Unknown
Date:2007-07-29
Time limit:1s
Source limit:50000B
Languages:All except: ERL JS PERL 6
Resource:Classical

hide comments
2012-04-18 15:48:10 manish sharma
can there be more than 1 solution
2011-07-28 05:21:24 cprocoder
Very nice problem
2011-04-30 11:31:04 Sigma Kappa
The numbers should be output in increasing order.
2011-01-25 12:22:05 Harish
can someone post the tricky test cases for this problem ? with all cases I find that mine is working but I get WA
SPOJ System © 2012 Sphere Research Labs | Projekty informatyczne i aplikacje na zamówienie. All Rights Reserved.