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

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

Port Robot

시간 제한10초메모리 제한1024 MB

요약
소문자는 저장, 대문자는 꺼내기를 나타내는 로그가 주어질 때, 꺼내기가 항상 맨 위 컨테이너를 대상으로 하고 마지막에 창고가 비는지 판정한다.
난이도

보통10점 중 4점

유형
스택, 문자열, 시뮬레이션
정답자
아직 제출이 없습니다

문제

You are developing a robot that helps in storing containers that have arrived at ports before sending them to ships. These robots are responsible for handling these containers using limited space. Specifically, the space can fit multiple containers one over the other, but not side by side, as depicted in the figure.

While operating, the robot performs two actions:

  1. Putting a container in storage.
  2. Taking a container from storage.

There are 26 types of containers in this port, each one characterized by a letter of the Latin alphabet. Each time an action is performed, the robot logs the type of the container in lowercase when storing a container and in uppercase when taking a container from storage. Your task is to check if the logs produced by a robot indicate stable operation. In stable operation, the logged containers of action type 2 exist in storage and are in the uppermost position. Moreover, in stable operation, we always end with empty storage.

As an example, consider a scenario in which the robot produces the log: 'cdDC'. Here, we have a stable operation of the robot, as the robot initially places 'c' and then 'd' (indicating that 'd' is in the upper position). The robot then takes the first 'd' out and, finally, takes out 'c'. On the other hand, an unstable operation would result from the log: 'cdCD', since the robot cannot take 'c' before taking out 'd'.

입력

The first line contains the length of the log generated by the robot. The second line contains the extracted log of the robot operation.

출력

A single number 0 if the log indicate wrong operation and 1 if the operation is stable.

예제2

  1. 예제 1

    입력
    8
    DdaacCAA
    
    예상 출력
    0
    
  2. 예제 2

    입력
    14
    aabcdDCBdDAbBA
    
    예상 출력
    1