跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F1430. Replace To Make Regular Bracket Sequence

    ID: 1436 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>数据结构表达式解析数学字符串基础难度共享题库Codeforces英文题面题目来源题面语言

Replace To Make Regular Bracket Sequence

题目描述

C. Replace To Make Regular Bracket Sequence
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.

The following definition of a regular bracket sequence is well-known, so you can be familiar with it.

Let's define a regular bracket sequence (RBS). Empty string is RBS. Let s1 and s2 be a RBS then the strings <s1>s2, {s1}s2, [s1]s2, (s1)s2 are also RBS.

For example the string "[[(){}]<>]" is RBS, but the strings "[)()" and "][()()" are not.

Determine the least number of replaces to make the string s RBS.

Input

The only line contains a non empty string s, consisting of only opening and closing brackets of four kinds. The length of s does not exceed 106.

Output

If it's impossible to get RBS from s print Impossible.

Otherwise print the least number of replaces needed to get RBS from s.

Examples
Input
[<}){}
Output
2
Input
{()}[]
Output
0
Input
]]
Output
Impossible

题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 936 题。保留原作者与原赛事署名。