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

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

Space Alignment

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

요약
공백과 탭으로 들여쓰기 된 코드 줄들이 주어질 때, 모든 줄이 일정한 들여쓰기를 따르도록 하는 탭 너비의 최솟값을 구하고, 불가능하면 -1을 출력한다.
난이도

보통10점 중 5점

유형
수학, 정수론, 구현
정답자
아직 제출이 없습니다

문제

You are collaborating with a few other programmers on a coding project. To your horror, you discover that some people have been using tabs to indent code while other people have been using spaces to indent code within the same file. Apparently these people didn't notice that anything was amiss when they did so.

You wish to replace the tabs with spaces so that the file has consistent indenting. Consistent indenting means that for every line at a nesting depth of kk, k≥0k \ge 0, the first non-whitespace character in the line should be preceded by exactly k⋅ik \cdot i spaces, where i>0i>0.

Is it possible to replace each tabs with a fixed number of spaces to repair the file and have consistent indenting?

입력

The first line of input contains a single integer nn (2≤n≤1002 \le n \le 100), which is the number of lines of code.

Each of the next nn lines contains a string, consisting of a sequence of the characters 's' (representing a space) and/or 't' (representing a tab), followed by a single '\{' or '\}'. Each line will have at most 1,0001\\,000 characters.

The first line is guaranteed to be a single '\{', the last line is guaranteed to be a single '\}', and the braces throughout the data are guaranteed to match; that is, looking at only those characters as a single string, it is always possible to repeatedly remove a substring "\{\}" until you are left with the empty string.

출력

Output a single integer, which is the smallest number of spaces greater than zero to replace each tab with and achieve consistent indentation, or −1-1 if it isn't possible.

예제1

  1. 예제 1

    입력
    10
    {
    ss{
    sts{
    tt}
    t}
    t{
    ss}
    }
    {
    }
    
    예상 출력
    2