Ordinal Number

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

요약
폰 노이만 순서수를 중괄호와 쉼표로 표현한 문자열이 주어질 때, 그것이 나타내는 정수 n을 구한다.
난이도

보통10점 중 6점

유형
재귀, 구현, 문자열, 정렬
정답자
아직 제출이 없습니다

문제

Ordinal numbers are an extension of the set of nonnegative integers. For each nonnegative integer xx, we will establish the corresponding ordinal number f(x)f (x). The first few ordinal numbers can be defined as follows.

  • Zero corresponds to an empty set: f(0)=f(0) = {}.
  • One corresponds to the set containing the set f(0)f (0) as an element: f(1)=f(1) = {f(0)f(0)}=={{}}.
  • Two corresponds to the set containing the sets f(0)f (0) and f(1)f (1) as elements: f(2)=f(2) = {f(0),f(1)f(0), f(1)}=={{},{{}}}.
  • And so on: each positive integer kk corresponds to the set containing all the previous ordinal numbers as elements. The formula is: f(k)=f(k) = {f(0),f(1),…,f(k−1)f(0), f(1), \ldots , f(k - 1)}.

Next, we can similarly define ordinal numbers that don't correspond to integers. Alas, we won't need them in this problem.

You are given a string describing an ordinal number corresponding to a nonnegative integer nn. Find nn.

입력

The first line contains the description of an ordinal number corresponding to a certain nonnegative integer nn (0≤n≤150 \le n \le 15). It consists of the characters "{", ",", and "}".

In the description of each set, each element appears exactly once. However, as a set does not change if we change the order of elements, this order can be arbitrary.

출력

Print the integer nn corresponding to the given ordinal number.

예제4

  1. 예제 1

    입력
    {}
    
    예상 출력
    0
    
  2. 예제 2

    입력
    {{}}
    
    예상 출력
    1
    
  3. 예제 3

    입력
    {{},{{}}}
    
    예상 출력
    2
    
  4. 예제 4

    입력
    {{{}},{{{}},{}},{}}
    
    예상 출력
    3