<PREV Problem:
NEXT>
Solved by 66 users: ...
 < 
 < 
 < 
 < 
 < 
 < 
 < 
 < 
 < 
 < 

Brackets III

Time limit = 1 second

Memory limit = 64 Mb

You are given a string consisting of the brackets "<",">"; "(",")"; "{","}"; "[","]". The problem is to find the number of substrings that are the regular brackets sequence (RBS).

The definition of RBS: RBS + RBS = RBS, <RBS> = RBS, (RBS) = RBS, [RBS] = RBS, (RBS) = RBS.

Examples of RBS: (), ([]), <>()[](<>){{}}, <{{{}}()}>.

Input A string consisting of characters "(","[","{","<",">","}","]",")". The length of the line does not exceed 106 characters.

Output Number of substrings that are RBS.

Input#1
}<>(){)(<})[]
Output#1
4

Input#2
((><))>{<>}[[])
Output#2
3

Author:
Egor Malyshev
28 april 2009

<PREV | Problem set | Search related messages | NEXT>


© acm.mipt DevGroup
The page was generated in 210ms

SW soft NIX
ID = 54.162.181.75