아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Pocket Money

시간 제한1초메모리 제한256 MB

요약
+, -, 0, 미상의 날로 이루어진 문자열이 주어질 때, 잔고가 0으로 돌아오기까지 존니가 모을 수 있었던 최소 및 최대 총액을 구한다.
난이도

보통10점 중 7점

유형
그리디, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

Johnny wants to become a professional road cyclist. He has even found the perfect bike, but he does not have the funds to buy it. He asked his mother for a daily pocket money allowance, to which she agreed under some terms: the initial amount of the pocket money is 00 and then every day mother will give Johnny the current amount of pocket money and then check Johnny's grades -- if he brings more fives and sixes than the twos and ones, she will raise the pocket money by one, if less -- she will decrease it by 1, and in the remaining case the value does not change. If the value gets negative, mother will stop paying Johnny at all and he will never buy the bike.

Years later, John recalls those events with great affection. He still remembers many details: he collected exactly the bike's cost and the final amount of his pocket money was 00. One thing he cannot recall is the actual price of the bike. He even found his grade sheets, but they are old and tattered, so sometimes he cannot read what grades he got each day. Can you help John and compute the best upper and lower bounds on the price of the bike? Unfortunately, it is possible that John made some mistakes when reading the grades and it is not possible to write a correct sequence of pocket money amounts consistent with the data that John provided.

입력

The first and only line of the input contains one string of length at most 10610^6, consisting of symbols '+', '-', '0' and '_'. The characters represent changes of the pocket money in the following days: '+' means that on this day Johnny's mother raised his pocket money (by 11), '-' means that on this day she decreased it (by 11), '0' means that the pocket money amount has not changed, and '_' means that John is unable to say what happened on this particular day.

출력

You should write in the first and only line of the output two integers, separated by a single space, denoting the minimal and maximal possible price of the bike, respectively.

If the given string cannot be turned into a valid sequence of changes of the pocket money amount, then you should write a single word NIE instead (Polish for "no").

힌트

In Sample 1, the lowest bike price is achieved for the sequence "+-+-0000+-", the largest for "+++-0-0-+-".

In Sample 2, regardless of the grades in the first two days, the amount of the pocket money after the fifth day would be negative.

예제2

  1. 예제 1

    입력
    +_+-0_0_+-
    
    예상 출력
    3 13
    
  2. 예제 2

    입력
    __---_
    
    예상 출력
    NIE