UVa 11111 Generalized Matrioshkas: Stack

Source: Internet
Author: User
Tags time limit

11111-generalized Matrioshkas

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=103&page=show_ problem&problem=2052

Vladimir worked for years making matrioshkas, those nesting the dolls that certainly represent truly Russian. A Matrioshka is a doll it opened in the two halves, so this one finds the another doll. Then This doll May is opened to find another one inside it. This can is repeated several times, till a final doll-that cannot is Opened-is reached.

Recently, Vladimir realized that's idea of nesting dolls might is generalized to nesting toys. Indeed, he has designed toys, contain toys but in a more general sense. One of these toys May is opened in two halves and it could have more than one toy inside it. That's the new feature that's Vladimir wants to introduce in its new line of toys.

The Vladimir has developed a notation to describe how nesting toys is should. A toy is represented with a positive integer and according to its size. More precisely:if when opening the toy represented Bym we find the toys represented by N1, N2, ..., nr, it must be true t HATN1 +n2 + ... +nr <m. And if, we say that toymcontains directly the Toysn1,n2,..., Nr. It should is clear that toys, may contained to the TOYSN1,N2,..., nr are not considered as directly contained In the Toym.

A generalized Matrioshka is denoted with a non-empty sequence of non zero integers of the form:

A1 A2 ... an

such that toy k are represented in the sequence with two integers-k andk, and the negative one occurring in the sequence F Irst that the positive one.

For example, the sequence

-9-7-2 2-3-2-1 1 2 3 7 9

Represents a generalized Matrioshka conformed by six toys, namely, 1, 2 (twice), 3, 7 and 9. Note that Toy 7 contains directly toys2 And3. Note that "the" the toy2 occurs left to the second one and that second copy contains directly a toy1. It would be wrong to understand the first-2 and the Last2 should is paired.

On the other hand, the following sequences does not describe generalized Matrioshkas:

-9-7-2 2-3-1-2 2 1 3 7 9

Because toy 2 is bigger than toy 1 and cannot being allocated inside it.

-9-7-2 2-3-2-1 1 2 3 7-2 2-9

Because 7 and 2 May is allocated together inside9.

-9-7-2 2-3-1-2 3 2 1 7 9

Because there is a nesting problem within toy 3.

Your problem is to write a program to help Vladimir telling good designs from bad ones.

Input

The input file contains several test cases, each one of them in a separate line. Each test case is a sequence of non zero integers, and one with a absolute value less than107.

Output

Output texts for each of the input case are presented in the same order this input is read.

For each test case the answer must is a line of the form:-) matrioshka!

If the design describes a generalized Matrioshka. In the answer should is the form

:-( Try again.

Sample Input

-9-7-2 2-3 -2-1 1 2 3 7 9
-9-7-2 2-3 -1-2 2 1 3 7 9
-9-7-2 2-3 -1-2 3 2 1 7 9
-100-50-6 6 50-100
-100-50-6 6
-10-5-2 2 5-4-3 3 4-9-5-
2 2 5-4-3 3 4-9

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.