Mountain Bike Trail

시간 제한8초메모리 제한2048 MB

요약
오르막 라이더들의 외침 순서가 주어질 때 가능한 그룹 수의 최솟값과 최댓값을 구한다.
난이도

보통10점 중 6점

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

문제

When riding on a singletrack mountain bike trail, the courtesy is for riders going downhill to yield to riders going uphill. Often, the uphill riders will let the downhill rider know about how many riders are behind them in their group so the downhill rider knows what to watch for. For example, if there are five riders in a group, the first one may say "4 back", the second may say "3 back", repeating this pattern until the last rider says "just me."

You have been volunteering for the local mountain bike trail maintenance club and have been put in charge of collecting statistics on the number of groups riding up your favorite trail. To do so, you decided the most fun way would be to ride down the trail and use a tape recorder to record what everyone says as you let them by, and use a computer program to do the counting.

Due to the fact that some riders fall really far behind from their group, the groups may not be in order. Additionally, some members of the group may have gotten really tired and decided to wait at the bottom of the trail, so not every group will end with "just me."

입력

The first line of input contains a single integer NN (0≤N≤1060 \le N \le 10^6), indicating the number of riders you passed as you biked down the trail.

The next NN lines contain either:

  • The text "just me", indicating the rider was the last rider in a group.
  • Or, an integer mm (1≤m<1061 \le m < 10^6), indicating the number of riders in the same group who are behind the uphill rider, followed by the string "back".

You may assume that all riders are completely knowledgeable of the current number of riders behind themselves in their group, and will always correctly answer the number of riders in their group behind themselves. Likewise, riders will never disappear on the trail. If a rider says "4 back" then the next rider in their group (if one is on the trail) will not say anything but "3 back".

출력

Output two integers on the same line, separated by a space. The first integer represents the minimum number of groups you may have seen on the trail, and the second integer represents the maximum number of groups you may have seen on the trail.

예제2

  1. 예제 1

    입력
    5
    4 back
    3 back
    2 back
    1 back
    just me
    
    예상 출력
    1 5
    
  2. 예제 2

    입력
    12
    2 back
    4 back
    3 back
    2 back
    4 back
    3 back
    2 back
    1 back
    1 back
    1 back
    just me
    just me
    
    예상 출력
    3 12