#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<iostream>
char a[1000005*2];
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
int main(void)
{
    int n,i,k,p,q,m,j,l;
    while(scanf("%s",a)!=EOF)
    {
        map<char,int>my;
        my['<']=1;
        my['>']=5;
        my['{']=2;
        my['}']=6;
        my['(']=3;
        my[')']=7;
        my['[']=4;
        my[']']=8;
        stack<int>st;
        int l=strlen(a);
        if(l%2!=0)
        {
            printf("Impossible\n");
        }
        else
        {

            {
               int cnt=0;int vv=0;
                for(i=0; i<l;i++)
                {
                    if(my[a[i]]<=4)
                    {
                        st.push(my[a[i]]);
                    }
                    else
                    {
                        if(st.empty())
                        {vv=1;
                            break;
                        }
                        else
                        {
                            int cc=st.top();

                            if(my[a[i]]-cc!=4)
                            {
                                cnt++;
                            }
                            st.pop();
                        }
                    }

                }if(vv==0)
                printf("%d\n",cnt);
                else printf("Impossible\n");
            }
        }
    }
    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<iostream>
char a[1000005*2];
#include<map>
using namespace std;
typedef long long ll;
int main(void)
{
    int n,i,k,p,q,m,j,l;
    while(scanf("%s",a)!=EOF)
    {
        map<char,int>my;
        my['<']=1;
        my['>']=5;
        my['{']=2;
        my['}']=6;
        my['(']=3;
        my[')']=7;
        my['[']=4;
        my[']']=8;
        int l=strlen(a);
        if(l%2!=0)
        {
            printf("Impossible\n");
        }
        else
        {
            int cnt=0;
            int cnt2=0;
            for(i=0; i<l; i++)
            {

                if(a[i]=='<'||a[i]=='('||a[i]=='{'||a[i]=='[')
                {
                    cnt++;
                }
                else
                {
                    cnt--;
                }
                if(cnt<0)
                    break;

            }
            if(i!=l)
            {
                printf("Impossible\n");
            }
            else
            {
                 cnt=0;
                for(i=1; i<l;)
                {
                    if(my[a[i]]>4)
                    {
                        int vv=i-1;
                        for(j=i; my[a[j]]>4; j++)
                        {
                            if(my[a[j]]-my[a[vv]]!=4)
                            {
                                cnt++;
                            }
                            vv--;

                        }
                        i=j;
                    }
                    else i++;

                }
                printf("%d\n",cnt);
            }
        }
    }
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

bool compare(char a, char b)
{
    return a=='('&&b==')' || a=='['&&b==']' || a=='<'&&b=='>' || a=='{'&&b=='}';
}

bool compare1(char a, char b)
{
    return (a=='(' || a=='[' || a=='<' || a=='{') && (b==')' || b==']' || b=='>' || b=='}');
}

int main()
{
    string s;
    cin >> s;
    if(s.size()%2)
    {
        cout << "Impossible" << endl;
        return 0;
    }
    vector<char> c, c1;
    for(int i=0; i<s.size(); i++)
    {
        if(c.size()==0)
        {
            c.push_back(s[i]);
            continue;
        }
        if(compare(c[c.size()-1], s[i]))
        {
            c.pop_back();
            continue;
        }
        c.push_back(s[i]);
    }
    for(int i=0; i<c.size(); i++)
    {
        if(c1.size()==0)
        {
            c1.push_back(c[i]);
            continue;
        }
        if(compare1(c1[c1.size()-1], c[i]))
        {
            c1.pop_back();
            continue;
        }
        c1.push_back(c[i]);
    }
    if(c1.size()==0)
        cout << c.size()/2 << endl;
    else
        cout << "Impossible" << endl;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

bool compare(char a, char b)
{
    return a=='('&&b==')' || a=='['&&b==']' || a=='<'&&b=='>' || a=='{'&&b=='}';
}

bool compare1(char a, char b)
{
    return (a=='(' || a=='[' || a=='<' || a=='{') && (b==')' || b==']' || b=='>' || b=='}');
}

int countl(string s)
{
    int res=0;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]=='(' || s[i]=='[' || s[i]=='<' || s[i]=='{')
            res++;
    }
    return res;
}

int count2(string s)
{
    int res=0;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]==')' || s[i]==']' || s[i]=='>' || s[i]=='}')
            res++;
    }
    return res;
}

int main()
{
    int n=0, left, right;
    string s;
    cin >> s;
    left=countl(s);
    right=count2(s);

    if( s.size()%2 || right!=left)
    {
        cout << "Impossible" << endl;
        return 0;
    }
    vector<char> c, c1;
    for(int i=0; i<s.size(); i++)
    {
        if(c.size()==0)
        {
            c.push_back(s[i]);
            continue;
        }
        if(compare(c[c.size()-1], s[i]))
        {
            c.pop_back();
            continue;
        }
        if(compare1(c[c.size()-1], s[i]))
        {
            c.pop_back();
            n++;
            continue;
        }
        c.push_back(s[i]);
    }
    if(c.size())
    {
        cout << "Impossible" << endl;
        return 0;
    }
    cout << n << endl;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

bool compare(char a, char b)
{
    return a=='('&&b==')' || a=='['&&b==']' || a=='<'&&b=='>' || a=='{'&&b=='}';
}

bool compare1(char a, char b)
{
    return (a=='(' || a=='[' || a=='<' || a=='{') && (b==')' || b==']' || b=='>' || b=='}');
}

int countl(string s)
{
    int res=0;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]=='(' || s[i]=='[' || s[i]=='<' || s[i]=='{')
            res++;
    }
    return res;
}

int count2(string s)
{
    int res=0;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]==')' || s[i]==']' || s[i]=='>' || s[i]=='}')
            res++;
    }
    return res;
}

int main()
{
    int n=0, left, right;
    string s;
    cin >> s;
    left=countl(s);
    right=count2(s);

    if(s.size()%2 || right!=left)
    {
        cout << "Impossible" << endl;
        return 0;
    }
    vector<char> c, c1;
    for(int i=0; i<s.size(); i++)
    {
        if(c.size()==0)
        {
            c.push_back(s[i]);
            continue;
        }
        if(compare(c[c.size()-1], s[i]))
        {
            c.pop_back();
            continue;
        }
        if(compare1(c[c.size()-1], s[i]))
        {
            c.pop_back();
            n++;
            continue;
        }
        c.push_back(s[i]);
    }
    cout << n << endl;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

bool compare(char a, char b)
{
    return a=='('&&b==')' || a=='['&&b==']' || a=='<'&&b=='>' || a=='{'&&b=='}';
}

int main()
{
    string s;
    cin >> s;
    if(s.size()<4 || s.size()%2)
    {
        cout << "Impossible" << endl;
        return 0;
    }
    vector<char> c;
    for(int i=0; i<s.size(); i++)
    {
        if(c.size()==0)
        {
            c.push_back(s[i]);
            continue;
        }
        if(compare(c[c.size()-1], s[i]))
        {
            c.pop_back();
            continue;
        }
        c.push_back(s[i]);
    }
    cout << c.size()/2 << endl;
    return 0;
}


#include <iostream>
#include <string>
#include <map>

using namespace std;

typedef struct Lista{
	char ca;
	struct Lista *prox;
}lista;

typedef struct Pilha{
	lista *topo;
}pilha;

pilha *cria(){
	pilha *p = (pilha*)malloc(sizeof(pilha));
	p->topo = NULL;
	return p;
}

void push(pilha *p, char c){

	lista *no = (lista*)malloc(sizeof(lista));
	no->ca = c;
	no->prox = p->topo;
	p->topo = no;
}

void pop(pilha *p){
	lista *aux = p->topo;
	p->topo = p->topo->prox;
	free(aux);
}

int size(pilha *p){
	int count=0;

	if(p==NULL) return count;

	for(lista *l = p->topo; l !=NULL; l = l->prox){
		count++;
	}
	return count;
}

void print(pilha *stk){

	for(lista *l = stk->topo; l !=NULL; l = l->prox){
		cout << "Imprimindo pilha " << l->ca << endl;
	}
}

int main(){

	pilha *stk;
	int c=0;
	string s;
	int tam;

	map <char, char> rel;

	rel['}'] = '{';
	rel['>'] = '<';
	rel[']'] = '[';
	rel[')'] = '(';

	stk = cria();

	cin >> s;

	for(unsigned i=0; i<s.size(); i++){

		if(s[i] == '(' || s[i] == '[' || s[i] == '{' || s[i] == '<') {
			push(stk, s[i]);
		}
		else{

			if((tam = size(stk))==0) {
				cout<< "Impossible";
				return 0;
			}

			if(rel[s[i]]== (stk->topo->ca)) pop(stk);

			else{
				pop(stk);
				c++;
			}
		}

	}

	if((tam =size(stk))==0) cout << c;

	else cout << "Impossible";

	return 0;
}

// 1535327485610


#include <bits/stdc++.h>

using namespace std;

stack<char> pilha;
map<char,char> expc;
bool imp;

int main(){
    int res=0;
    string s;

    cin >> s;

    expc[')'] = '(';
    expc['}'] = '{';
    expc['>'] = '<';
    expc[']'] = '[';

    for (int i=0;i<s.size();i++){
        if (s[i]=='['||s[i]=='<'||s[i]=='('||s[i]=='{')
            pilha.push(s[i]);

        else if (!pilha.empty()){
            if (expc[s[i]]!=pilha.top()){
                res++;
                pilha.pop();
            }

            else
                pilha.pop();
        }

        else
            imp = true;

    }

    if (!imp && pilha.empty())
        printf("%d\n", res);
    else
        printf("Impossible\n");

    return 0;
}

// 1481813717614


#include <iostream>
using namespace std;

typedef struct {
  int topo;
  int item [1000000];
} PILHA;
PILHA p;

void coloca(char valor){
    p.topo++;
    p.item[p.topo]=valor;
}

char tira(){
    p.topo--;
    return p.item[p.topo+1];
}

char mostra(){
    return p.item[p.topo];
}
void tira_semretorno(){
    p.topo--;
}
int tamanho(){
    return p.topo;
}

int main()
{
    int resposta=0;
    p.topo=0;
    string entrada;
    cin>>entrada;
    for(int i=0;i<entrada.size();i++){
        if(entrada[i] == '{' || entrada[i] == '[' || entrada[i] == '<' || entrada[i] == '(')coloca(entrada[i]);
        else {
            if(p.topo == 0){
                cout<<"Impossible";
                return 0;
            }
            else{
                switch(entrada[i]){
                case '}':
                    if(mostra() == '{')tira_semretorno();
                    else{
                        tira_semretorno();
                        resposta++;
                    }
                    break;
                case ']':
                    if(mostra() == '[')tira_semretorno();
                    else{
                        tira_semretorno();
                        resposta++;
                    }
                    break;

                case ')':
                    if(mostra() == '(')tira_semretorno();
                    else{
                        tira_semretorno();
                        resposta++;
                    }
                    break;

                case '>':
                    if(mostra() == '<')tira_semretorno();
                    else{
                        tira_semretorno();
                        resposta++;
                    }
                    break;
                }
            }

        }

    }
    if(p.topo==0){
        cout << resposta;

    }
    else{
        cout << "Impossible";
    }
    return 0;
}

// 1535391746259


#include <iostream>
#include <string>
#include <map>
using namespace std;

class RBS
{
public:
    void checkRBS(string brackets);
    bool checkPossibility(string brackets);
    int replace(string brackets);

private:
    map<char,int> availability;
    int notRBS = 0;
};

void RBS::checkRBS(std::string brackets)
{

    for(auto type: brackets)
        availability[type] = 0;
    for(auto type: brackets){
        availability[type]++;
        if(type == '>'&& availability['<']==0)
            notRBS++;
        if(type == ')'&& availability['(']==0)
            notRBS++;
        if(type == '}'&& availability['{']==0)
            notRBS++;
        if(type == ']'&& availability['[']==0)
            notRBS++;
    }

}

bool RBS::checkPossibility(std::string brackets)
{
    int possibility = 0;

    for(auto type: brackets){
        if(type == '<'|| type == '['|| type == '{'|| type == '(')
            possibility++;
        if(type == '>'|| type == ']'|| type == '}'|| type == ')'){
            if (possibility == 0)
                return false;
            else
                possibility--;
        }
    }
    return true;
}

int RBS::replace(std::string brackets)
{
    if (notRBS%2!=0)
        return -1;
    else
        return notRBS;
}

int main(){
    RBS rbs;
    int result = -1;
    string brackets;
    getline(cin,brackets);
    if(rbs.checkPossibility(brackets)){
        rbs.checkRBS(brackets);
        result = rbs.replace(brackets);
    }
    if (result == -1)   cout << "Impossible"<< endl;
    else                cout << result      << endl;
}
// 1534969674498


#include<iostream>
#include <cstdio>

using namespace std;
const int ms = 1e6;
//variaveis globais
string pilha;
int head=-1, turn=0;
//funcoes
int check_list(string s, int str){
    int i, direita=0, esquerda=0;
    if(str==0){
        return 2;
    }
    else if(s[0]=='}'||s[0]==']'||s[0]=='>'||s[0]==')'){
        return 0;
    }
    else if(s[str-1]=='{'||s[str-1]=='['||s[str-1]=='<'||s[str-1]=='('){
        return 0;
    }
    for(i=0;i<str;i++){
        if(s[i]=='}'||s[i]==']'||s[i]=='>'||s[i]==')'){
            esquerda++;
        }
        else{
            direita++;
        }
    }
    if(direita==esquerda){
        return 1;
    }
    else{
        return 0;
    }
}

void add_pilha(string s, int i){
    head++;
    pilha[head] =  s[i];
    //cout << pilha[head];
}

void couple(string s, int i){
    if(pilha[head]=='{' and s[i]!='}'){
        //cout <<"\n  " << "O PROBLEMA ESTA NO {}    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else if(pilha[head]=='(' and s[i]!=')'){
        //cout <<"\n  " << "O PROBLEMA ESTA NO ()    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else if(pilha[head]=='<' and s[i]!='>'){
      //  cout <<"\n  " << "O PROBLEMA ESTA NO <>    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else if(pilha[head]=='[' and s[i]!=']'){
    //    cout <<"\n  " << "O PROBLEMA ESTA NO []    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else{
        head--;
    }
}

int main() {
    int i, str;
    int key = 1;
    string s;
    cin >> s;
    str = s.size();
    pilha.resize(ms);
    key = check_list(s, str);
    if(key==0){
        cout << "Impossible\n";
    }
    else if(key==2){
        cout << "0\n";
    }
    else{
        for(i=0;i<str;i++){
            if(s[i]=='{' or s[i]=='[' or s[i]=='<' or s[i]=='('){
                add_pilha(s, i);
            }
            else{
                couple(s, i);
            }
        }

        cout << turn;
    }
    return 0;
}

// 1534971218973


#include <iostream>
#include <string>

using namespace std;

class STACK{

    private:
        struct node{
            char s;
            node *next;
        };
        node *top = NULL;

    public:
        char push(char s){
            node *newest = new node;
            newest->s = s;

            if(top==NULL){
                newest->next = NULL;
                top = newest;
            }
            else{
                node* aux = top->next;
                top->next = newest;
                top->next->next = aux;

                int aux2;
                aux2=top->s;
                top->s=top->next->s;
                top->next->s=aux2;
            }

        }
        char pull(){
            if(top!=NULL)
                top=top->next;
        }
        char pop(){
            if(top!=NULL)
                return top->s;
        }
        int empty(){
            if(top==NULL)
                return 1;
            else
                return 0;
        }

};

int main(){

    STACK opening_brackets;
    STACK closing_brackets;
    STACK another_opening_brackets;
    STACK another_closing_brackets;

    string STRING;

    cin>>STRING;

    int i, c=1, ob=0, cb=0, k=0;

    for(i=0;i<STRING.size();i++){

        if(STRING[i]=='<' || STRING[i]=='{' || STRING[i]=='[' || STRING[i]=='('){
            ob++;
            opening_brackets.push(STRING[i]);
        }
        else{
            cb++;
            closing_brackets.push(STRING[i]);
            if((opening_brackets.pop()=='(' && closing_brackets.pop()==')') ||
                (opening_brackets.pop()=='{' && closing_brackets.pop()=='}') ||
                (opening_brackets.pop()=='<' && closing_brackets.pop()=='>') ||
                (opening_brackets.pop()=='[' && closing_brackets.pop()==']')){
                opening_brackets.pull();
                closing_brackets.pull();
            }
            else if( !((opening_brackets.pop()=='(' && another_closing_brackets.pop()==')') ||
                (opening_brackets.pop()=='{' && another_closing_brackets.pop()=='}') ||
                (opening_brackets.pop()=='<' && another_closing_brackets.pop()=='>') ||
                (opening_brackets.pop()=='[' && another_closing_brackets.pop()==']')) ){
                k++;
                opening_brackets.pull();
                closing_brackets.pull();
            }
        }

        if(cb>ob)
            c=0;
    }

    if(c==0 || STRING.size()%2>0 || cb!=ob)
        cout<<"Impossible";
    else
        cout<<k;

    return 0;

}

// 1535399504981


#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <map>

using namespace std;

typedef struct Lista{
	char ca;
	struct Lista *prox;
}lista;

typedef struct Pilha{
	lista *topo;
}pilha;

pilha *cria(){
	pilha *p = (pilha*)malloc(sizeof(pilha));
	p->topo = NULL;
	return p;
}

void push(pilha *p, char c){

	lista *no = (lista*)malloc(sizeof(lista));
	no->ca = c;
	no->prox = p->topo;
	p->topo = no;
}

void pop(pilha *p){
	lista *aux = p->topo;
	p->topo = p->topo->prox;
	free(aux);
}

int size(pilha *p){
	int count=0;

	if(p==NULL) return count;

	for(lista *l = p->topo; l !=NULL; l = l->prox){
		count++;
	}
	return count;
}

void print(pilha *stk){

	for(lista *l = stk->topo; l !=NULL; l = l->prox){
		cout << "Imprimindo pilha " << l->ca << endl;
	}
}

int main(){

	pilha *stk;
	int c=0;
	string s;
	int tam;

	map <char, char> rel;

	rel['}'] = '{';
	rel['>'] = '<';
	rel[']'] = '[';
	rel[')'] = '(';

	stk = cria();

	cin >> s;

	for(unsigned i=0; i<s.size(); i++){

		if(s[i] == '(' || s[i] == '[' || s[i] == '{' || s[i] == '<') {
			push(stk, s[i]);
		}
		else{

			if((tam = size(stk))==0) {
				cout<< "Impossible";
				return 0;
			}

			if(rel[s[i]]== (stk->topo->ca)) pop(stk);

			else{
				pop(stk);
				c++;
			}
		}

	}

	if((tam =size(stk))==0) cout << c;

	else cout << "Impossible";

	return 0;
}

// 1535328386496


#include <cstdio>
#include <iostream>

using namespace std;

int main() {
    int troca=0;
    int i=0;
    char c[100];
    while(cin>>c[i]){
        if(c[i]==')'){
            if(i==0){
                cout << "impossible" << endl;
                return 0;
            }
            else if(c[i-1]=='('){
                i=i - 2;
            }
            else if(c[i-1]=='['){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='{'){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='<'){
                i = i-2;
                troca++;
            }

        }
        else if(c[i]==']'){
            if(i==0){
                cout << "impossible" << endl;
                return 0;
            }
            else if(c[i-1]=='('){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='['){
                i = i-2;
            }
            else if(c[i-1]=='{'){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='<'){
                i = i-2;
                troca++;
            }

        }
        else if(c[i]=='}'){
            if(i==0){
                cout << "impossible" << endl;
                return 0;
            }
            else if(c[i-1]=='('){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='['){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='{'){
                i = i-2;
            }
            else if(c[i-1]=='<'){
                i = i-2;
                troca++;
            }

        }
        else if(c[i]=='>'){
            if(i==0){
                cout << "impossible" << endl;
                return 0;
            }
            else if(c[i-1]=='('){
                i=i - 2;
                troca++;
            }
            else if(c[i-1]=='['){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='{'){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='<'){
                i = i-2;

            }
        }

        i++;
    }
    if(i>0){
        cout <<"impossible" << endl;

    }
    else {
        cout << troca << endl;
    }
	return 0;
}
// 1535291644469


#include<bits/stdc++.h>
using namespace std;

const int MAX = 1000005;

int main() {
    char s[MAX];
    int topo = 0, ch = 0;
    char pilha[MAX];
    scanf(" %s", s);

    for (int i = 0; s[i] != 0; i++) {
        if (s[i] == '[' || s[i] == '(' || s[i] == '{' || s[i] == '<')
            pilha[topo] = s[i], topo++;
        else {
            if (topo == 0) {
                printf("Impossible\n");
                return 0;
            }
            if (s[i] == ']' && pilha[topo - 1] != '[') ch++;
            else if (s[i] == ')' && pilha[topo - 1] != '(') ch++;
            else if (s[i] == '}' && pilha[topo - 1] != '{') ch++;
            else if (s[i] == '>' && pilha[topo - 1] != '<') ch++;
            topo--;
        }
    }
    if (topo != 0) printf("Impossible\n");
    else printf("%d\n", ch);
}

// 1478631453460


#include<iostream>
#include <cstdio>

using namespace std;
const int ms = 1000001;
//variaveis globais
char pilha[ms];
int head=-1, turn=0;
//funcoes
int check_list(string& s, int str){
    int i, direita=0, esquerda=0;
    if(str==0){
        return 2;
    }
    else if(s[0]=='}'||s[0]==']'||s[0]=='>'||s[0]==')'){
        return 0;
    }
    else if(s[str-1]=='{'||s[str-1]=='['||s[str-1]=='<'||s[str-1]=='('){
        return 0;
    }
    for(i=0;i<str;i++){
        if(s[i]=='}'||s[i]==']'||s[i]=='>'||s[i]==')'){
            esquerda++;
        }
        else{
            direita++;
        }
    }
    if(direita==esquerda){
        return 1;
    }
    else{
        return 0;
    }
}

void add_pilha(string& s, int i){
    head++;
    pilha[head] =  s[i];
    //cout << pilha[head];
}

void couple(string& s, int i){
    if(pilha[head]=='{' and s[i]!='}'){
        //cout <<"\n  " << "O PROBLEMA ESTA NO {}    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else if(pilha[head]=='(' and s[i]!=')'){
        //cout <<"\n  " << "O PROBLEMA ESTA NO ()    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else if(pilha[head]=='<' and s[i]!='>'){
      //  cout <<"\n  " << "O PROBLEMA ESTA NO <>    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else if(pilha[head]=='[' and s[i]!=']'){
    //    cout <<"\n  " << "O PROBLEMA ESTA NO []    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else{
        head--;
    }
}

int main() {
    int i, str;
    int key = 1, ok=1;
    string s;
    cin >> s;
    str = s.size();
    key = check_list(s, str);
    if(key==0){
        cout << "Impossible\n";
    }
    else if(key==2){
        cout << "0\n";
    }
    else{
        for(i=0;i<str;i++){
            if(s[i]=='{' or s[i]=='[' or s[i]=='<' or s[i]=='('){
                add_pilha(s, i);
            }
            else{
            	if(head<0){
            		cout << "Impossible";
            		ok=0;
            		break;
            	}
                couple(s, i);
            }
        }
        if(ok==1){
        	cout << turn;
        }
    }
    return 0;
}

// 1535124446556


#include<iostream>
#include<string>

using namespace std;

bool E_par(int d){
	// verifica se a string tem tamanho impar
	if(d%2==0)
		return true;
	else
		return false;

}

bool E_valido(char d1, char d){
	//Verifica se a string nao começa com a um fechamento e/ou termina com uma abertura
	if(d =='['||d=='<'||d=='{'||d=='('){
		return false;
	}else if (d1==']'||d1=='>'||d1=='}'||d1==')'){
		return false;
	}else
	   return true;

}

bool E_Abertura(char caractere){
	if (caractere=='['||caractere=='<'||caractere=='('||caractere=='{'){
		return true;
	}
}

int main(){
	char aberturas [1000000];
	int flag=0, trocas = 0;
	int i=0;
	int j=0;
	string frase;

	cin>>frase;

	if(E_par(frase.size())){
		if(E_valido(frase[0],frase[frase.size()-1])){

	   		for (i=0; i<frase.size() && flag==0;i++){
	   			if (frase[i]=='['||frase[i]=='<'||frase[i]=='('||frase[i]=='{'){

					aberturas[j]=frase[i];
					j++;

			   }else{

				   	if(j>0){
				   		if ((aberturas[j-1] == '[' && frase[i]==']' )||(aberturas[j-1]=='<' && frase[i]=='>' )||(aberturas[j-1]=='(' && frase[i]==')' )||(aberturas[j-1]=='{' && frase[i]=='}' )){

						   }else{
					   			trocas++;
					   		}
					   		aberturas[j]=0;
					   		j--;
					}else{
						flag=1;
					}
			   }
		}
		}else{

			flag=1;

		}

	}else{

		flag=1;
	}

	if(flag==1 || j>0){
		cout<<"Impossible";
	}else if(flag == 0){
		cout<<trocas;
	}

	return 0;
}

// 1534977046030


#include <iostream>
#include <string>
using namespace std;
int count2 = 0;
void crack(string str){
    int lenght= 0, begin = 0, count1 = 0, size = str.size();
    int sizeh = size / 2;
    //cout << str << endl;
    for(int i = 0; i < str.size(); i++){
        lenght ++;
        //cout << begin << lenght << endl;
        if( str[i] == '<' || str[i] == '(' || str[i] == '{' || str[i] == '[' )
            count1++;
        if( str[i] == '>' || str[i] == ')' || str[i] == '}' || str[i] == ']' )
            count1--;
        if(count1 == 0){
            //cout << "DEBUG DEBUG" << endl;
            if(size == 2){
                if(str[0] == '('  && str[1] != ')'){
                count2 ++;
                //cout << "DEBUG 1" << endl;
                }
                if(str[0] == '{'  && str[1] != '}'){
                count2 ++;
                //cout << "DEBUG 2" << endl;
                }
                if(str[0] == '['  && str[1] != ']'){
                count2 ++;
                //cout << "DEBUG 3" << endl;
                }
                if(str[0] == '<'  && str[1] != '>'){
                count2 ++;
                //cout << "DEBUG 4" << endl;
                }
            }else{
                if(str[begin] == '('  && str[ begin + lenght - 1] != ')'){
                count2 ++;
                //cout << "DEBUG 5" << endl;
                }
                if(str[begin] == '{'  && str[ begin + lenght - 1] != '}'){
                count2 ++;
                //cout << "DEBUG 6" << endl;
                }
                if(str[begin] == '['  && str[ begin + lenght - 1] != ']'){
                count2 ++;
                //cout << "DEBUG 7" << endl;
                }
                if(str[begin] == '<'  && str[ begin + lenght - 1] != '>'){
                count2 ++;
                //cout << "DEBUG 8" << endl;
                }
            }
            string str1 = str.substr(begin + 1, lenght - 2);
            //cout << str1 << endl;
            if(size != 2){
            crack(str1);
            }

            begin = i + 1;
            lenght = 0;
        }
    }
}
int main(){
    string str;
    int size_str, count = 0, total = 0;
    int kind[8] = {0,0,0,0,0,0,0,0};
    int status[8] = {0,0,0,0,0,0,0,0};
    cin >> str;

    size_str= str.size();
    if(str[0] == '>' || str[0] == ')' || str[0] == '}' || str[0] == ']'){
        cout << "Impossible" << endl;
        return 0;
    }
    if(str[size_str - 1] == '<' || str[size_str - 1] == '(' || str[size_str - 1] == '{' || str[size_str - 1] == '['){
        cout << "Impossible" << endl;
        return 0;
    }
    for(int i = 0; i < size_str; i++){
        if( str[i] == '<' || str[i] == '(' || str[i] == '{' || str[i] == '[' ){
            count++;
        }
        if( str[i] == '>' || str[i] == ')' || str[i] == '}' || str[i] == ']' ){
            count--;
        }
        if( count < 0 ){
            cout << "Impossible" << endl;
            return 0;
        }
    }
    if( count != 0 ){
            cout << "Impossible" << endl;
            return 0;
    }
    crack(str);

    cout << count2 << endl;
    return 0;
}
// 1535511119123


#include <iostream>
#include <string>

using namespace std;

int main() {

    string S;
    string P;
    int count = 0, i;
    int A = 0, F = 0;
    int X = 0;
    bool Possible = true;

    cin >> S;

    for (i = 0; i < S.size(); i++) {
        if (S[i] == '(' || S[i] == '[' || S[i] == '{' || S[i] == '<') {
            count++;
            P[count] = S[i];
            A++;
        }
        else {
            if (count <= 0) {
                Possible = false;
                break;
            }
            if ((S[i] == ')' && P[count] == '(') || (S[i] == ']' && P[count] == '[') || (S[i] == '}' && P[count] == '{') || (S[i] == '>' && P[count] == '<')) {
                count--;
                F++;
            }
            else {
                X++;
                count--;
                F++;
            }
        }
    }

    if (A != F) {
        Possible = false;
    }

    if (Possible == true) {
        cout << X << endl;
    }
    else {
        cout << "Impossible" << endl;
    }

    return 0;
}
// 1535473750061


#include <iostream>
#include <string>
using namespace std;

struct Node{
    char val;
    struct Node *pont;
};
typedef struct Node node;

node *adicionar_lista(char x, node *head);
void observar_lista(node *head);
node *remocao_lista(node *head);

int main(){
    string rbs;
    int long i=0, j=0, a=0, b=0, c=0, d=0, e=0;
    node *parantes_esquerdo = new node;
    parantes_esquerdo->pont = NULL;
    parantes_esquerdo->val = 'x';

    node *parantes_direito = new node;
    parantes_direito->pont = NULL;
    parantes_direito->val = 'x';

    node *chaves_esquerdo = new node;
    chaves_esquerdo->pont = NULL;
    chaves_esquerdo->val = 'x';

    node *chaves_direito = new node;
    chaves_direito->pont = NULL;
    chaves_direito->val = 'x';

    node *cochetes_esquerdo = new node;
    cochetes_esquerdo->pont = NULL;
    cochetes_esquerdo->val = 'x';

    node *cochetes_direito = new node;
    cochetes_direito->pont = NULL;
    cochetes_direito->val = 'x';

    node *menor_esquerdo = new node;
    menor_esquerdo->pont = NULL;
    menor_esquerdo->val = 'x';

    node *menor_direito = new node;
    menor_direito->pont = NULL;
    menor_direito->val = 'x';

	getline(cin, rbs); //pegou todos caracteres;
	j = rbs.size();

    for(i=0; i<j; i++){
        if(rbs[i] == '<'){
            menor_esquerdo = adicionar_lista(rbs[i], menor_esquerdo );
            a++;
        } else if(rbs[i] == '>'){
            menor_direito = adicionar_lista(rbs[i], menor_direito);
            a--;
        }else if(rbs[i] == '('){
            parantes_esquerdo = adicionar_lista(rbs[i], parantes_esquerdo );
            b++;
        } else if(rbs[i] == ')'){
            parantes_direito = adicionar_lista(rbs[i], parantes_direito);
            b--;
        } else if(rbs[i] == '{'){
            chaves_esquerdo = adicionar_lista(rbs[i], chaves_esquerdo );
            c++;
        } else if(rbs[i] == '}'){
            chaves_direito = adicionar_lista(rbs[i], chaves_direito);
            c--;
        }else if(rbs[i] == '['){
            cochetes_esquerdo = adicionar_lista(rbs[i], cochetes_esquerdo );
            d++;
        } else if(rbs[i] == ']'){
            cochetes_direito = adicionar_lista(rbs[i], cochetes_direito);
            d--;
        }
    }

    if((a+b+c+d) != 0){
    	cout << "Impossible" << endl;
    	return 0;
    }else if(a > 0){ e += a;}
    	  if(b > 0){ e += b;}
    	  if(c > 0){ e += c;}
    	  if(d > 0){ e += d;}

    cout << e << endl;

    while(parantes_esquerdo->pont != NULL){
    	parantes_esquerdo = remocao_lista(parantes_esquerdo);
    }

    while(parantes_direito->pont != NULL){
    	parantes_direito = remocao_lista(parantes_direito);
    }

    while(menor_esquerdo->pont != NULL){
    	menor_esquerdo = remocao_lista(menor_esquerdo);
    }

    while(menor_direito->pont != NULL){
    	menor_direito = remocao_lista(menor_direito);
    }

    while(chaves_esquerdo->pont != NULL){
    	chaves_esquerdo = remocao_lista(chaves_esquerdo);
    }

    while(chaves_direito->pont != NULL){
    	chaves_direito = remocao_lista(chaves_direito);
    }

    while(cochetes_esquerdo->pont != NULL){
    	cochetes_esquerdo = remocao_lista(cochetes_esquerdo);
    }

    while(cochetes_direito->pont != NULL){
    	cochetes_direito = remocao_lista(cochetes_direito);
    }

    delete parantes_esquerdo;
    delete parantes_direito;
    delete chaves_esquerdo;
    delete chaves_direito;
    delete cochetes_esquerdo;
    delete cochetes_direito;
    delete menor_esquerdo;
    delete menor_direito;

    return 0;
}

node *adicionar_lista(char x, node *head){
    node *novo = new node;
    novo->pont = head;
    novo->val = x;

    return novo;
}

void observar_lista(node *head){
    if(head == '\0'){
        cout << "error, lista vazia" << endl;
    } else while(head->pont != NULL){
        cout << head->val << " ";
        head = head->pont;
    }
    cout << endl;
}

node *remocao_lista(node *head){
    node *auxiliar;
    if(head->pont == NULL){ //tentando apagar nada;
        return head;
    } else{
        auxiliar = head->pont;
        delete head;
        return auxiliar;
    }
}
// 1534986823655


#include<iostream>
#include<string>

using namespace std;

bool E_par(int d){
	// verifica se a string tem tamanho impar
	if(d%2==0)
		return true;
	else
		return false;

}

bool E_valido(char d1, char d){
	//Verifica se a string nao começa com a um fechamento e/ou termina com uma abertura
	if(d =='['||d=='<'||d=='{'||d=='('){
		return false;
	}else if (d1==']'||d1=='>'||d1=='}'||d1==')'){
		return false;
	}else
	   return true;

}

int main(){
	int flag=0, trocas = 0;
	int i=0;
	int j=0;
	string frase;

	cin>>frase;

	if(E_par(frase.size())){

		if(E_valido(frase[0],frase[frase.size()-1])){

			   for(i=(frase.size()-1); i>=0 && flag == 0; i--){
				  //procura a abertura mais proxima do fim da string
				   if(frase[i]=='[' || frase[i] =='<'|| frase[i] =='{'|| frase[i] =='('){
					  //achamos uma abertura
					   flag = 1;
					  //Procura o fechamento da abertura acima encontrada
					   for(j=i; j<frase.size() && flag == 1; j++){

						   if(frase[j]==']'|| frase[j] =='>'|| frase[j] =='}'|| frase[j] ==')'){
                               //achamos o fechamento
					    		flag=0;

					    		//procurando trocas
								if((frase[i] == '[' && frase[j] == ']') || (frase[i] == '{' && frase[j] == '}') || (frase[i] == '<' && frase[j] == '>')|| (frase[i] == '(' && frase[j] == ')')){

								}else{
									//computando o número de trocas
									trocas++;
								}
								//indisponibiliza a posição j para próxima contagem de fechamento
								frase[j]=0;
						   }

					   }

				   }

			   }

		}else{

			flag=1;

		}

	}else{

		flag=1;
	}

	if(flag==1){
		cout<<"Impossible";
	}else if(flag == 0){
		cout<<trocas;
	}

	return 0;
}
// 1534887542976


#include <iostream>
#include <string>

using namespace std;

class STACK{

	private:
		struct node{
			char s;
			node *next;
		};
    	node *top = NULL;

	public:
		char push(char s){
			node *newest = new node;
			newest->s = s;

			if(top==NULL){
				newest->next = NULL;
				top = newest;
			}
			else{
				node* aux = top->next;
				top->next = newest;
				top->next->next = aux;

				int aux2;
				aux2=top->s;
				top->s=top->next->s;
				top->next->s=aux2;
			}

		}
		char pull(){
			if(top!=NULL)
				top=top->next;
		}
		char pop(){
			if(top!=NULL)
				return top->s;
		}
		int empty(){
			if(top==NULL)
				return 1;
			else
				return 0;
		}

};

int main(){

	STACK opening_brackets;
	STACK closing_brackets;
	STACK another_opening_brackets;
	STACK another_closing_brackets;

	string STRING;

	cin>>STRING;

	int i, c=1, ob=0, cb=0;

	for(i=0;i<STRING.size();i++){

		if(STRING[i]=='<' || STRING[i]=='{' || STRING[i]=='[' || STRING[i]=='('){
			ob++;
			opening_brackets.push(STRING[i]);
		}
		else{
			cb++;
			closing_brackets.push(STRING[i]);
		}

		if(cb>ob)
			c=0;
	}

	if(c==0 || STRING.size()%2>0)
		cout<<"IMPOSSIBLE";
	else{
		c=0;
		for(i=0;i<STRING.size()/2;i++){
			if( (opening_brackets.pop()=='(' && closing_brackets.pop()==')') ||
			    (opening_brackets.pop()=='{' && closing_brackets.pop()=='}') ||
			    (opening_brackets.pop()=='<' && closing_brackets.pop()=='>') ||
			    (opening_brackets.pop()=='[' && closing_brackets.pop()==']') ){
                c++;
				opening_brackets.pull();
				closing_brackets.pull();
			}
		}
		for(i=0;i<(STRING.size()/2)-c;i++){
		    another_closing_brackets.push(closing_brackets.pop());
		    closing_brackets.pull();
		}

		int k=0;
		for(i=0;i<(STRING.size()/2)-c;i++){
		    if( !((opening_brackets.pop()=='(' && another_closing_brackets.pop()==')') ||
			    (opening_brackets.pop()=='{' && another_closing_brackets.pop()=='}') ||
			    (opening_brackets.pop()=='<' && another_closing_brackets.pop()=='>') ||
			    (opening_brackets.pop()=='[' && another_closing_brackets.pop()==']')) ){

		        k++;
		    }
		}

		cout<<k;
	}

	return 0;

}
// 1535140723037


#include <iostream>
#include <string>
using namespace std;
#define ptrnull NULL

struct Node{
    char val;
    struct Node *pont;
};
typedef struct Node node;

node *adicionar_lista(char x, node *head);
void observar_lista(node *head);
char remocao_lista(node *head);
char procurar_ultimo(node *head);

int main(){
    string rbs;

    int controle = 0, contador = 0;
    int long i, j;
    char p, q;

    node *left = new node;
    node *last = left;
    left->pont = NULL;
    left->val = 'x';

    getline(cin,rbs); //pegando caracteres;
    j = rbs.size();

    for(i=0; i < j; i++) {
        p = rbs[i];

        if(p == '<' || p == '{' || p == '[' || p == '('){
            adicionar_lista(p, last);

        }else{
            if(left->pont == NULL){ //Exemplo: ][ ;
                controle = 1;
                break;
            }else{
                q = remocao_lista(left);
                    if(p == ')' && q == '('){
                        //faz nada;
                    }else{

                        if(p == '>' && q == '<'){
                            //faz nada;
                        }else{

                            if(p == ']' && q == '['){
                               //faz nada;
                            }else{

                                if(p == '}' && q == '{'){
                                    //faz nada;
                                }else contador++;

                            }
                        }
                    }

            }
        }

    }

    if(controle == 1 || left->pont != NULL){
        cout << "Impossible" << endl;
    }else {
        cout << contador << endl;
    }

    delete left;
    return 0;

}

node *adicionar_lista(char x, node *head){ //adicionando no final normalmente;
    node *novo = new node;
    novo->pont = NULL;
    novo->val = x;

    while(head->pont != NULL){
        head = head->pont;
    }

    head->pont = novo;
}

void observar_lista(node *head){
    node *cursor = head;

    if(cursor == NULL){
        cout << "error, lista vazia" << endl;
    } else while(cursor->pont != NULL){
        cout << cursor->val << '-';
        cursor = cursor->pont;
    }

    cout << cursor->val << endl;;
}

char remocao_lista(node *head) {
    node *cursor = head;
    node *auxiliar;
    char sinal;

    if(cursor->pont == NULL){//Proximo NO eh vazio;
        cout << "Sem nada para remover" << endl;
        return cursor->val;

    }else{
        if(cursor->pont->pont == NULL){
            sinal = cursor->pont->val;
            cursor = cursor->pont;
            head->pont = NULL;

            delete cursor;
            return sinal;
        }else{

            while(cursor->pont->pont != NULL){//Procurando o final, e apontando p/ o anterior dele;
                cursor = cursor->pont;
            }

            sinal = cursor->pont->val; //Recebendo valor dele;
            auxiliar = cursor->pont; //Auxiliar recebe a posicao que devera deletar;
            cursor->pont = cursor->pont->pont; //fazendo apontar para o NULL;
            delete auxiliar;

            return sinal;
        }
    }
}

char procurar_ultimo(node *head){
    node *cursor = head;

    while(cursor->pont != NULL){
        cursor = cursor->pont;
    }

    return cursor->val;
}
// 1535394737494


#include <cstdio>
#include <iostream>
#define X 1000000
using namespace std;
typedef struct{
      int cima;
      int porra[X] ;
}pilha;
void chamaEla(pilha &foda){
    foda.cima = -1;
}
void colocar(pilha &foda, char &C){
    foda.porra[++foda.cima]=C;
}
int tirar(pilha &foda){

    return (foda.porra[foda.cima--]) ;
}

int main() {
    pilha foda;

    chamaEla(foda);

    char aux,C;
    int x;
    int i,j,cont=0;
    string meu;
    cin >> meu;
    C=meu[0];
    x=meu.size();
    if(C==')' or C==']'or C=='}' or C=='>'){
        printf("Impossible");
        return 0;
    }
    if(meu[x-1]=='(' or meu[x-1]=='[' or meu[x-1]=='{' or meu[x-1]=='<'){
        printf("Impossible");
        return 0;
    }
    if((x)%2!=0){
        printf("Impossible");
        return 0;
    }
    colocar(foda,C);
    x=meu.size();
    for(i=1;i<x;i++){
        if(meu[i]=='(' or meu[i]=='[' or meu[i]=='{' or meu[i]=='<' ){
            C=meu[i];
            colocar(foda,C);
        }
        else if(meu[i]==')'){
            C=tirar(foda);
            if(C=='('){
            }
            else{
                cont++;
            }
        }
       else if(meu[i]==']'){
            C=tirar(foda);
            if(C=='['){
            }
            else{
                cont++;
            }
        }
        else if(meu[i]=='>'){
            C=tirar(foda);
            if(C=='<'){
            }
            else{
                cont++;
            }
        }
        else if(meu[i]=='}'){
            C=tirar(foda);
            if(C=='{'){
            }
            else{
                cont++;
            }
        }
    }
    cout << cont;

	return 0;
}
// 1534970508686


#include <cstdio>
#include <iostream>

using namespace std;

int main() {
    int troca=0;
    int i=0;
    char c[1000005];
    while(cin>>c[i]){
        if(c[i]==')'){
            if(i==0){
                cout << "Impossible"<<endl ;
                return 0;
            }
            else if(c[i-1]=='('){
                i=i - 2;
            }
            else if(c[i-1]=='['){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='{'){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='<'){
                i = i-2;
                troca++;
            }

        }
        else if(c[i]==']'){
            if(i==0){
                cout << "Impossible" <<endl ;
                return 0;
            }
            else if(c[i-1]=='('){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='['){
                i = i-2;
            }
            else if(c[i-1]=='{'){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='<'){
                i = i-2;
                troca++;
            }

        }
        else if(c[i]=='}'){
            if(i==0){
                cout << "Impossible" << endl;
                return 0;
            }
            else if(c[i-1]=='('){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='['){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='{'){
                i = i-2;
            }
            else if(c[i-1]=='<'){
                i = i-2;
                troca++;
            }

        }
        else if(c[i]=='>'){
            if(i==0){
                cout << "Impossible" << endl;
                return 0;
            }
            else if(c[i-1]=='('){
                i=i - 2;
                troca++;
            }
            else if(c[i-1]=='['){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='{'){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='<'){
                i = i-2;

            }
        }

        i++;
    }
    if(i>0){
        cout <<"Impossible" <<endl;

    }
    else {
        cout << troca << endl;
    }
	return 0;
}
// 1535309982751


#include <iostream>
#include <string>
using namespace std;

int count2 = 0;
void crack(string str){
    int lenght= 0, begin = 0, count1 = 0, size = str.size();

    for(int i = 0; i < str.size(); i++){
        lenght ++;

        if( str[i] == '<' || str[i] == '(' || str[i] == '{' || str[i] == '[' )
            count1++;
        if( str[i] == '>' || str[i] == ')' || str[i] == '}' || str[i] == ']' )
            count1--;
        if(count1 == 0){
            string str1 = str.substr(begin + 1, lenght - 2);
            if(size == 2){
                if(str[0] == '('  && str[1] != ')'){
                count2 ++;

                }
                if(str[0] == '{'  && str[1] != '}'){
                count2 ++;

                }
                if(str[0] == '['  && str[1] != ']'){
                count2 ++;

                }
                if(str[0] == '<'  && str[1] != '>'){
                count2 ++;

                }
            }else{
                int aux = begin + lenght - 1;
                if(str[begin] == '('  && str[ aux] != ')'){
                count2 ++;

                }
                if(str[begin] == '{'  && str[ aux] != '}'){
                count2 ++;

                }
                if(str[begin] == '['  && str[ aux] != ']'){
                count2 ++;

                }
                if(str[begin] == '<'  && str[ aux] != '>'){
                count2 ++;

                }
                crack(str1);
            }
            begin = i + 1;
            lenght = 0;
        }
    }
}
int main(){
    string str;
    int size_str, count = 0, total = 0;
    int kind[8] = {0,0,0,0,0,0,0,0};
    int status[8] = {0,0,0,0,0,0,0,0};
    cin >> str;

    size_str= str.size();
    if(str[0] == '>' || str[0] == ')' || str[0] == '}' || str[0] == ']'){
        cout << "Impossible" << endl;
        return 0;
    }
    if(str[size_str - 1] == '<' || str[size_str - 1] == '(' || str[size_str - 1] == '{' || str[size_str - 1] == '['){
        cout << "Impossible" << endl;
        return 0;
    }
    for(int i = 0; i < size_str; i++){
        if( str[i] == '<' || str[i] == '(' || str[i] == '{' || str[i] == '[' ){
            count++;
        }
        if( str[i] == '>' || str[i] == ')' || str[i] == '}' || str[i] == ']' ){
            count--;
        }
        if( count < 0 ){
            cout << "Impossible" << endl;
            return 0;
        }
    }
    if( count != 0 ){
            cout << "Impossible" << endl;
            return 0;
    }

    crack(str);

    cout << count2 << endl;
    return 0;
}
// 1535511694559


#include <iostream>
#include <string>
using namespace std;
#define ptrnull NULL

struct Node{
    char val;
    struct Node *pont;
};
typedef struct Node node;

void adicionar_lista(char x, node *head);
void observar_lista(node *head);
char remocao_lista(node *head);

int main(){
    string rbs;
    int possibilidade = 1;
    int long i, j;
    char p, q;

    node *left = new node;
    node *right = new node;
    node *left2 = new node;

    left->pont = NULL; right->pont = NULL; left2->pont = NULL;
    left->val = 'x';   right->val = 'y'; left2->val = 'z';
    getline(cin,rbs); //pegando caracteres;
    j = rbs.size();

    for(i=0; i < j; i++) {
        p = rbs[i];

        if(p == '<' || p == '{' || p == '[' || p == '('){
            adicionar_lista(p, left);
            adicionar_lista(p, left2);
        }else {
            adicionar_lista(p, right);
            if(left->pont == NULL){
                possibilidade = 0;
                break;
            }else p = remocao_lista(left); /********/
        }

    }

    int long r[5]; r[0]= 0; r[1]= 0; r[2]= 0; r[3]= 0;
    while(left2->pont != NULL){
        p = remocao_lista(left2);

        if(p == '<'){ r[0]++;}
        if(p == '{'){ r[1]++;}
        if(p == '['){ r[2]++;}
        if(p == '('){ r[3]++;}

    }

    while(left->pont != NULL){
        p = remocao_lista(left);
    }

    while(right->pont != NULL){
        p = remocao_lista(right);

        if(p == '>'){ r[0]--;}
        if(p == '}'){ r[1]--;}
        if(p == ']'){ r[2]--;}
        if(p == ')'){ r[3]--;}
    }

    r[4] = 0;
    if(r[0] > 0) {r[4] += r[0];}
    if(r[1] > 0) {r[4] += r[1];}
    if(r[2] > 0) {r[4] += r[2];}
    if(r[3] > 0) {r[4] += r[3];}

    if(possibilidade == 0 || (r[0] + r[1] + r[2] + r[3]) != 0){
        cout << "Impossible" << endl;

        delete left;
        delete left2;
        delete right;

    }else{

    cout << r[4] << endl;

    delete left;
    delete right;
    delete left2;

    return 0;
    }

}

void adicionar_lista(char x, node *head){
    node *novo = new node;
    novo->pont = NULL;
    novo->val = x;

    node *cursor = head; //assim nao perderei o head;

    while(cursor->pont != NULL){
        cursor = cursor->pont;
    }
    cursor->pont = novo;
}

void observar_lista(node *head){
    node *cursor = head;

    if(cursor == NULL){
        cout << "error, lista vazia" << endl;
    } else while(cursor->pont != NULL){
        cout << cursor->val << '-';
        cursor = cursor->pont;
    }

    cout << cursor->val << endl;;
}

char remocao_lista(node *head) {
    node *cursor = head;
    char sinal;

    if(cursor->pont == NULL){//Proximo NO eh vazio
        cout << "Sem nada para remover" << endl;
        return head->val;
    }

    cursor = cursor->pont;
    sinal = cursor->val;

    head->pont = cursor->pont; //apontando para o prx cara que eu deletei;
    delete cursor;
    return sinal;

}
// 1535138594323


#include <iostream>
#include <string>

using namespace std;

void push(int stack[], int &top, int val){
	top++;
	stack[top]= val;
}

void pop(int stack[], int &top){
	top--;
}

int main(){

int strSize, top=0,balance=0,xchg=0;
string line;

cin>>line;

strSize = line.length();

if(strSize%2 != 0){
	cout<<"Impossible"<<endl;
	return 0;
}

int stack[strSize];

for(int i=0;i<strSize;i++){

	if(line[i] == '<' || line[i] == '{' || line[i] == '[' || line[i] == '('){
		balance++;
		push(stack,top,line[i]);
	}

		while(line[i] == '>' || line[i] == '}' || line[i] == ']' || line[i] == ')'){

			if(top != 0 && stack[top] == '<' && line[i] != '>'){
				xchg++;
				pop(stack,top);
				balance--;

				break;
			}
			if(top != 0 && stack[top] == '<' && line[i] == '>'){
				pop(stack,top);
				balance--;

				break;
			}

				if(top != 0 && stack[top] == '{' && line[i] != '}'){
				xchg++;

				pop(stack,top);
				balance--;
				break;
			}
			 if(top != 0 && stack[top] == '{' && line[i] == '}'){
				pop(stack,top);
				balance--;

				break;
			}

				if(top != 0 && stack[top] == '(' && line[i] != ')'){
				xchg++;
				pop(stack,top);
				balance--;

				break;
			}
			 if(top != 0 && stack[top] == '(' && line[i] == ')'){
				pop(stack,top);
				balance--;

				break;
			}

				if(top != 0 && stack[top] == '[' && line[i] != ']'){
				xchg++;

				pop(stack,top);
				balance--;
				break;
			}
			if(top != 0 && stack[top] == '[' && line[i] == ']'){
				pop(stack,top);
				balance--;
				break;
			}
			balance--;
			if(balance < 0){
				cout<<"Impossible"<<endl;
				return 0;
			}
			break;
		}

}

if(balance == 0){
	cout<<xchg<<endl;
}
else{
	cout<<"Impossible"<<endl;
}

	return 0;
}
// 1535469825100


#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
    int a = 0, f = 0, i =0;
    string inp;
    char l;
    int tab[4][2] = {0};
    cin >> inp;
    i = 0;
    while(inp[i] != '\0'){
        l = inp[i];
        switch(l){
            case '{':
                a++;
                tab[0][0]++;
                break;
            case '[':
                a++;
                tab[1][0]++;
                break;
            case '(':
                a++;
                tab[2][0]++;
                break;
            case '<':
                a++;
                tab[3][0]++;
                break;

            case '}':
                f++;
                tab[0][1]++;
                break;
            case ']':
                f++;
                tab[1][1]++;
                break;
            case ')':
                f++;
                tab[2][1]++;
                break;
            case '>':
                f++;
                tab[3][1]++;
                break;
        }
        i++;
    }
    if(f != a){
        puts("Impossible");
        return 0;
    }
    int soma = 0, tmp;
    for(i = 0; i < 4; i++){
        if(tab[i][0] != tab[i][1]){
            tmp = tab[i][0] - tab[i][1];
            if(tmp < 0){
               tmp *= (-1);
            }
            soma += tmp;
        }
    }
    soma /=2;
    cout << soma;
    return 0;
}
// 1534783072008


#include <cstdio>
#include <iostream>

using namespace std;

int main() {
    int troca=0;
    int i=0;
    char c[1000005];
    while(cin>>c[i]){
        if(c[i]==')'){
            if(i==0){
                cout << "Impossible"<<endl ;
                return 0;
            }
            else if(c[i-1]=='('){
                i=i - 2;
            }
            else if(c[i-1]=='['){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='{'){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='<'){
                i = i-2;
                troca++;
            }

        }
        else if(c[i]==']'){
            if(i==0){
                cout << "Impossible" <<endl ;
                return 0;
            }
            else if(c[i-1]=='('){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='['){
                i = i-2;
            }
            else if(c[i-1]=='{'){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='<'){
                i = i-2;
                troca++;
            }

        }
        else if(c[i]=='}'){
            if(i==0){
                cout << "Impossible" << endl;
                return 0;
            }
            else if(c[i-1]=='('){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='['){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='{'){
                i = i-2;
            }
            else if(c[i-1]=='<'){
                i = i-2;
                troca++;
            }

        }
        else if(c[i]=='>'){
            if(i==0){
                cout << "Impossible" << endl;
                return 0;
            }
            else if(c[i-1]=='('){
                i=i - 2;
                troca++;
            }
            else if(c[i-1]=='['){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='{'){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='<'){
                i = i-2;

            }
        }

        i++;
    }
    if(i>0){
        cout <<"Impossible" <<endl;

    }
    else {
        cout << troca << endl;
    }
	return 0;
}
// 1535313620382


#include<stdio.h>
#include<string.h>
class Pilha{
    public:
    int tamanho;
    char vector[1000010];
    Pilha(){
        tamanho=0;
    }
    void push(char data){
        vector[tamanho++]=data;
    }
    int pop(){
        return vector[--tamanho];
    }
};
int main(){
    int count=0;
    char parenteses[1000001],temp;
    scanf("%s",parenteses);
    Pilha stack;
    bool cond;
    int tam=strlen(parenteses);
    if(parenteses[0]==')'||parenteses[0]==']'||parenteses[0]=='}'||parenteses[0]=='>'){
        printf("Impossible");
        return 0;
    }
    if(parenteses[tam-1]=='('||parenteses[tam-1]=='['||parenteses[tam-1]=='{'||parenteses[tam-1]=='<'){
        printf("Impossible");
        return 0;
    }
    for(int i=0;i<tam;i++){
        if(parenteses[i]=='('||parenteses[i]=='['||parenteses[i]=='{'||parenteses[i]=='<'){
            stack.push(parenteses[i]);
        }
        else if(stack.tamanho>0){
            temp=stack.pop();
            cond=temp=='('&&parenteses[i]!=')'||temp=='['&&parenteses[i]!=']';
            cond=cond||temp=='<'&&parenteses[i]!='>'||temp=='{'&&parenteses[i]!='}';
            if(cond){
                count++;
            }
        }
        else{
        printf("Impossible");
            return 0;
        }
    }
    if(stack.tamanho>0){
        printf("Impossible");
        return 0;
    }
    printf("%d",count);

}
// 1534820667415


#include <iostream>
#include <string>

using namespace std;

int main() {

    string S;
    string P;
    int count = 0, i;
    int A = 0, F = 0; //QTD DE ABERTOS E DE FECHADOS
    int X = 0; //QTD DAS TROCAS QUE TERÃO QUE SER FEITAS
    bool Possible = true;

    cin >> S;

    for (i = 0; i < S.size(); i++) {
        if (S[i] == '(' || S[i] == '[' || S[i] == '{' || S[i] == '<') {
            count++;
            P[count] = S[i];
            A++;
        }
        else {
            if (count <= 0) { //OU É <= ?????
                Possible = false;
                break;
            }
            if ((S[i] == ')' && P[count] == '(') || (S[i] == ']' && P[count] == '[') || (S[i] == '}' && P[count] == '{') || (S[i] == '>' && P[count] == '<')) {
                count--;
                F++;
            }
            else {
                X++;
                count--;
                F++;
            }
        }
    }

    if (A != F) {
        Possible = false;
    }

    if (Possible == true) {
        cout << X;
    }
    else {
        cout << "Impossible";
    }

    return 0;
}
// 1535473643191


#include <cstdio>
#include <cstring>
#include <stack>

int main()
{
	char str[1000001];

	scanf("%s", str);
	int m = strlen(str);
	std::stack<char> stack;
	bool possible = true;
	int replaces = 0;

	for (int j = 0; j < m; j++)
	{
		// printf("j = %d\n", j);
		if (str[j] == '(' || str[j] == '[' || str[j] == '{' || str[j] == '<')
			stack.push(str[j]);
		else
		{
			char match;
			switch (str[j])
			{
				case ')':
					match = '(';
					break;
				case ']':
					match = '[';
					break;
				case '}':
					match = '{';
					break;
				case '>':
					match = '<';
					break;
			}

			if (stack.empty())
			{
				possible = false;
				break;
			}
			else if (stack.top() == match)
				stack.pop();
			else
			{
				replaces++;
				stack.pop();
			}
		}
	}

	if (!stack.empty())
		possible = false;

	if (possible)
		printf("%d\n", replaces);
	else
		printf("Impossible\n");

	return 0;
}
// 1478633780983


#include <iostream>
#include <string>
using namespace std;
#define ptrnull NULL

char q;

struct Node{
    char val;
    struct Node *pont;
};
typedef struct Node node;

node *adicionar_lista(char x, node *head);
node *remocao_lista(node *head);

int main(){
    string rbs;

    int controle = 0, contador = 0;
    int long i, j;
    char p;

    node *left = new node;
    left->pont = NULL;
    left->val = 'x';

    getline(cin,rbs); //pegando caracteres;
    j = rbs.size();

    for(i=0; i < j; i++) {
        p = rbs[i];

        if(p == '<' || p == '{' || p == '[' || p == '('){
            left = adicionar_lista(p, left);

        }else{
            if(left->pont == NULL){ //Exemplo: ][ ;
                controle = 1;
                break;
            }else{
                left = remocao_lista(left);
                    if(p == ')' && q == '('){
                        //faz nada;
                    }else{

                        if(p == '>' && q == '<'){
                            //faz nada;
                        }else{

                            if(p == ']' && q == '['){
                               //faz nada;
                            }else{

                                if(p == '}' && q == '{'){
                                    //faz nada;
                                }else contador++;

                            }
                        }
                    }

            }
        }

    }

    if(controle == 1 || left->pont != NULL){
        cout << "Impossible" << endl;
    }else {
        cout << contador << endl;
    }

    delete left;
    return 0;
}

node *adicionar_lista(char x, node *head){ //adicionando no final normalmente;
    node *novo = new node;
    novo->pont = head;
    novo->val = x;

    return novo;
}

node *remocao_lista(node *head){
    node *auxiliar;

    if(head->val == 'x'){ //tentando apagar nada;
        return head;
    } else{
        auxiliar = head->pont;
        q = head->val;

        delete head;
        return auxiliar;
    }
}

// 1535413041763


#include<iostream>
#include <cstdio>

using namespace std;
//variaveis globais
string pilha;
int turn=0;
//funcoes
bool check_list(string s, int str){
    int i, direita=0, esquerda=0;
    if(s[0]=='}'||s[0]==']'||s[0]=='>'||s[0]==')'){
        return false;
    }
    else if(s[str-1]=='{'||s[str-1]=='['||s[str-1]=='<'||s[str-1]=='('){
        return false;
    }
    for(i=0;i<str;i++){
        if(s[i]=='}'||s[i]==']'||s[i]=='>'||s[i]==')'){
            esquerda++;
        }
        else{
            direita++;
        }
    }
    if(direita==esquerda){
        return true;
    }
    else{
        return false;
    }
}

void add_pilha(string s, int i, int* head){
    (*head)++;
    pilha[*head] =  s[i];
    //cout << pilha[*head];
}

void couple(string s, int i, int* head){
    if(pilha[*head]=='{' and s[i]!='}'){
        //cout <<"\n  " << "O PROBLEMA ESTA NO {}    " << s[i] <<"  " << pilha[*head] << endl;
        turn++;
        (*head)--;
    }
    else if(pilha[*head]=='(' and s[i]!=')'){
       // cout <<"\n  " << "O PROBLEMA ESTA NO ()    " << s[i] <<"  " << pilha[*head] << endl;
        turn++;
        (*head)--;
    }
    else if(pilha[*head]=='<' and s[i]!='>'){
        //cout <<"\n  " << "O PROBLEMA ESTA NO <>    " << s[i] <<"  " << pilha[*head] << endl;
        turn++;
        (*head)--;
    }
    else if(pilha[*head]=='[' and s[i]!=']'){
        //cout <<"\n  " << "O PROBLEMA ESTA NO []    " << s[i] <<"  " << pilha[*head] << endl;
        turn++;
        (*head)--;
    }
    else{
        (*head)--;
    }
}

int main() {
	int i, str, rola=-1;
    bool key = true;
    int *head = &rola;
    string s;
    cin >> s;
    str = s.size();
    key = check_list(s, str);
    if(key==false){
        cout << "Impossible";
    }
    else{
        for(i=0;i<str;i++){
            if(s[i]=='{' or s[i]=='[' or s[i]=='<' or s[i]=='('){
                add_pilha(s, i, head);
            }
            else{
                couple(s, i, head);
            }
        }
        cout << turn;
    }
    return 0;
}
// 1534966830627


#include<iostream>
#include<string>
using namespace std;

typedef struct node{
	char c;
	struct node *prox;
} Node;

Node *head = NULL;

void push(char c);
void pop();
int isempty();
int is_left_side(char c);
int is_equal(char c, char d);

int main(){
	string str;
	int qt_op = 0;

	cin >> str;

	for(int x = 0; x < str.length(); x++){
		if(is_left_side(str[x])){ // verifica se é do lado esquerdo ([, (, {, <)
			push(str[x]); // dá push (adiciona na pilha)
		}else{
			if(isempty()){ // caso n seja e a pilha esteja vazia, encerra e manda impossible
				cout << "Impossible";
				return 0;
			}else{
				if(!is_equal(head->c, str[x])){ // caso n seja igual (<>, {}, (), [], soma em qt_op)
					qt_op++;
				}
				pop(); // dá pop (tira o topo da pilha)
			}
		}
	}

	if(!isempty()){ // caso apos o fim da operação a pilha continuar com algum elemento, dá Impossible
		cout << "Impossible";
		return 0;
	}else{ // caso não, retorna a quantia de operações
		cout << qt_op;
	}
}

int is_left_side(char c){
	if(c == '[' || c == '<' || c == '{' || c == '('){
		return 1;
	}
	return 0;
}

int is_equal(char c, char d){
	if(abs(c-d) != 2 && abs(c-d) != 1){
		return 0;
	}
	return 1;
}

int isempty(){
	if(head == NULL){ // se o topo da pilha estiver apontando pra null, n tem nenhum elemento nela
		return 1;
	}
	return 0;
}

void pop(){
	if(head != NULL){
		head = head->prox; // aponta pra o proximo
	}else{
		head = NULL;
	}
}

void push(char c){
	Node *node = (Node*) malloc(sizeof(Node)); // alocação dinâmica pra o prx. nó
	if(node != NULL){ // caso tenha conseguido alocar
		node->c = c;
		node->prox = head;
		head = node;
	}
}
// 1534819147366


#include<iostream>
#include <cstdio>

using namespace std;
//variaveis globais
string pilha;
int head=-1, turn=0;
//funcoes
bool check_list(string s, int str){
    int i, direita=0, esquerda=0;
    if(s[0]=='}'||s[0]==']'||s[0]=='>'||s[0]==')'){
        return false;
    }
    else if(s[str-1]=='{'||s[str-1]=='['||s[str-1]=='<'||s[str-1]=='('){
        return false;
    }
    for(i=0;i<str;i++){
        if(s[i]=='}'||s[i]==']'||s[i]=='>'||s[i]==')'){
            esquerda++;
        }
        else{
            direita++;
        }
    }
    if(direita==esquerda){
        return true;
    }
    else{
        return false;
    }
}

void add_pilha(string s, int i){
    head++;
    pilha[head] =  s[i];
    //cout << pilha[head];
}

void couple(string s, int i){
    if(pilha[head]=='{' and s[i]!='}'){
        //cout <<"\n  " << "O PROBLEMA ESTA NO {}    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else if(pilha[head]=='(' and s[i]!=')'){
        //cout <<"\n  " << "O PROBLEMA ESTA NO ()    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else if(pilha[head]=='<' and s[i]!='>'){
      //  cout <<"\n  " << "O PROBLEMA ESTA NO <>    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else if(pilha[head]=='[' and s[i]!=']'){
    //    cout <<"\n  " << "O PROBLEMA ESTA NO []    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else{
        head--;
    }
}

int main() {
	int i, str;
    bool key = true;
    string s;
    cin >> s;
    str = s.size();
    key = check_list(s, str);
    if(key==false){
        cout << "Impossible";
    }
    else{
        for(i=0;i<str;i++){
            if(s[i]=='{' or s[i]=='[' or s[i]=='<' or s[i]=='('){
                add_pilha(s, i);
            }
            else{
                couple(s, i);
            }
        }
        cout << turn;
    }
    return 0;
}
// 1534967285415


#include <cstdio>
#include <iostream>
#define X 1000000
using namespace std;
typedef struct{
      int cima;
      int porra[X] ;
}pilha;
void chamaEla(pilha &foda){
    foda.cima = -1;
}
void colocar(pilha &foda, char &C){
    foda.porra[++foda.cima]=C;
}
int tirar(pilha &foda){

    return (foda.porra[foda.cima--]) ;
}

int main() {
    pilha foda;

    chamaEla(foda);

    char aux,C;
    int x;
    int i,j,cont=0,cont1=1,cont2=0;
    string meu;
    cin >> meu;
    C=meu[0];
    x=meu.size();
    if(C==')' or C==']'or C=='}' or C=='>'){
        printf("Impossible");
        return 0;
    }
    if(meu[x-1]=='(' or meu[x-1]=='[' or meu[x-1]=='{' or meu[x-1]=='<'){
        printf("Impossible");
        return 0;
    }
    if((x)%2!=0){
        printf("Impossible");
        return 0;
    }
    colocar(foda,C);
    x=meu.size();
    for(i=1;i<x;i++){
        if(meu[i]=='(' or meu[i]=='[' or meu[i]=='{' or meu[i]=='<' ){
            cont1++;
            C=meu[i];
            colocar(foda,C);
        }
        else if(meu[i]==')'){
            cont2++;
            C=tirar(foda);
            if(C=='('){
            }
            else{
                cont++;
            }
        }
       else if(meu[i]==']'){
            cont2++;
            C=tirar(foda);
            if(C=='['){
            }
            else{
                cont++;
            }
        }
        else if(meu[i]=='>'){
            cont2++;
            C=tirar(foda);
            if(C=='<'){
            }
            else{
                cont++;
            }
        }
        else if(meu[i]=='}'){
            cont2++;
            C=tirar(foda);
            if(C=='{'){
            }
            else{
                cont++;
            }
        }
    }
    if(cont1!=cont2){
        printf("Impossible");
        return 0;
    }
    cout << cont;

	return 0;
}
// 1534971197173


#include<iostream>
#include <cstdio>

using namespace std;
const int ms = 1000001;
//variaveis globais
char pilha[ms];
int head=-1, turn=0;
//funcoes
int check_list(string s, int str){
    int i, direita=0, esquerda=0;
    if(str==0){
        return 2;
    }
    else if(s[0]=='}'||s[0]==']'||s[0]=='>'||s[0]==')'){
        return 0;
    }
    else if(s[str-1]=='{'||s[str-1]=='['||s[str-1]=='<'||s[str-1]=='('){
        return 0;
    }
    for(i=0;i<str;i++){
        if(s[i]=='}'||s[i]==']'||s[i]=='>'||s[i]==')'){
            esquerda++;
        }
        else{
            direita++;
        }
    }
    if(direita==esquerda){
        return 1;
    }
    else{
        return 0;
    }
}

void add_pilha(string s, int i){
    head++;
    pilha[head] =  s[i];
    //cout << pilha[head];
}

void couple(string s, int i){
    if(pilha[head]=='{' and s[i]!='}'){
        //cout <<"\n  " << "O PROBLEMA ESTA NO {}    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else if(pilha[head]=='(' and s[i]!=')'){
        //cout <<"\n  " << "O PROBLEMA ESTA NO ()    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else if(pilha[head]=='<' and s[i]!='>'){
      //  cout <<"\n  " << "O PROBLEMA ESTA NO <>    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else if(pilha[head]=='[' and s[i]!=']'){
    //    cout <<"\n  " << "O PROBLEMA ESTA NO []    " << s[i] <<"  " << pilha[head] << endl;
        turn++;
        head--;
    }
    else{
        head--;
    }
}

int main() {
    int i, str;
    int key = 1, ok=1;
    string s;
    cin >> s;
    str = s.size();
    key = check_list(s, str);
    if(key==0){
        cout << "Impossible\n";
    }
    else if(key==2){
        cout << "0\n";
    }
    else{
        for(i=0;i<str;i++){
            if(s[i]=='{' or s[i]=='[' or s[i]=='<' or s[i]=='('){
                add_pilha(s, i);
            }
            else{
            	if(head<0){
            		cout << "Impossible";
            		ok=0;
            		break;
            	}
                couple(s, i);
            }
        }
        if(ok==1){
        	cout << turn;
        }
    }
    return 0;
}

// 1535075138047


#include <cstdio>
#include <iostream>

using namespace std;

int main() {
    int troca=0;
    int i=0;
    char c[100];
    while(cin>>c[i]){
        if(c[i]==')'){
            if(i==0){
                cout << "Impossible"<<endl ;
                return 0;
            }
            else if(c[i-1]=='('){
                i=i - 2;
            }
            else if(c[i-1]=='['){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='{'){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='<'){
                i = i-2;
                troca++;
            }

        }
        else if(c[i]==']'){
            if(i==0){
                cout << "Impossible" <<endl ;
                return 0;
            }
            else if(c[i-1]=='('){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='['){
                i = i-2;
            }
            else if(c[i-1]=='{'){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='<'){
                i = i-2;
                troca++;
            }

        }
        else if(c[i]=='}'){
            if(i==0){
                cout << "Impossible" << endl;
                return 0;
            }
            else if(c[i-1]=='('){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='['){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='{'){
                i = i-2;
            }
            else if(c[i-1]=='<'){
                i = i-2;
                troca++;
            }

        }
        else if(c[i]=='>'){
            if(i==0){
                cout << "Impossible" << endl;
                return 0;
            }
            else if(c[i-1]=='('){
                i=i - 2;
                troca++;
            }
            else if(c[i-1]=='['){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='{'){
                i = i-2;
                troca++;
            }
            else if(c[i-1]=='<'){
                i = i-2;

            }
        }

        i++;
    }
    if(i>0){
        cout <<"Impossible" <<endl;

    }
    else {
        cout << troca << endl;
    }
	return 0;
}
// 1535294619789


#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <map>

using namespace std;

typedef struct Lista{
	char ca;
	struct Lista *prox;
}lista;

typedef struct Pilha{
	lista *topo;
}pilha;

pilha *cria(){
	pilha *p = (pilha*)malloc(sizeof(pilha));
	p->topo = NULL;
	return p;
}

void push(pilha *p, char c){

	lista *no = (lista*)malloc(sizeof(lista));
	no->ca = c;
	no->prox = p->topo;
	p->topo = no;
}

void pop(pilha *p){
	lista *aux = p->topo;
	p->topo = p->topo->prox;
	free(aux);
}

int size(pilha *p){
	int i, count=0;

	if(p==NULL) return count;

	for(lista *l = p->topo; l !=NULL; l = l->prox){
		count++;
	}
	return count;
}

void print(pilha *stk){

	for(lista *l = stk->topo; l !=NULL; l = l->prox){
		cout << "Imprimindo pilha " << l->ca << endl;
	}
}

int main(){

	pilha *stk;
	int i, c=0;
	string s;
	int tam;

	map <char, char> rel;

	rel['}'] = '{';
	rel['>'] = '<';
	rel[']'] = '[';
	rel[')'] = '(';

	stk = cria();

	cin >> s;

	for(i=0; i<s.size(); i++){

		if(s[i] == '(' || s[i] == '[' || s[i] == '{' || s[i] == '<') {
			push(stk, s[i]);
		}
		else{

			if((tam = size(stk))==0) {
				cout<< "Impossible";
				return 0;
			}

			if(rel[s[i]]== (stk->topo->ca)) pop(stk);

			else{
				pop(stk);
				c++;
			}
		}

	}

	if((tam =size(stk))==0) cout << c;

	else cout << "Impossible";

	return 0;
}
// 1535327696077


#include <iostream>
#include <string>
using namespace std;
int count2 = 0;
void crack(string str){
    int lenght= 0, begin = 0, count1 = 0, size = str.size();
    int sizeh = size / 2;

    for(int i = 0; i < str.size(); i++){
        lenght ++;

        if( str[i] == '<' || str[i] == '(' || str[i] == '{' || str[i] == '[' )
            count1++;
        if( str[i] == '>' || str[i] == ')' || str[i] == '}' || str[i] == ']' )
            count1--;
        if(count1 == 0){

            if(size == 2){
                if(str[0] == '('  && str[1] != ')'){
                count2 ++;

                }
                if(str[0] == '{'  && str[1] != '}'){
                count2 ++;

                }
                if(str[0] == '['  && str[1] != ']'){
                count2 ++;

                }
                if(str[0] == '<'  && str[1] != '>'){
                count2 ++;

                }
            }else{
                int aux = begin + lenght - 1;
                if(str[begin] == '('  && str[ aux] != ')'){
                count2 ++;

                }
                if(str[begin] == '{'  && str[ aux] != '}'){
                count2 ++;

                }
                if(str[begin] == '['  && str[ aux] != ']'){
                count2 ++;

                }
                if(str[begin] == '<'  && str[ aux] != '>'){
                count2 ++;

                }
            }
            string str1 = str.substr(begin + 1, lenght - 2);

            if(size != 2){
            crack(str1);
            }

            begin = i + 1;
            lenght = 0;
        }
    }
}
int main(){
    string str;
    int size_str, count = 0, total = 0;
    int kind[8] = {0,0,0,0,0,0,0,0};
    int status[8] = {0,0,0,0,0,0,0,0};
    cin >> str;

    size_str= str.size();
    if(str[0] == '>' || str[0] == ')' || str[0] == '}' || str[0] == ']'){
        cout << "Impossible" << endl;
        return 0;
    }
    if(str[size_str - 1] == '<' || str[size_str - 1] == '(' || str[size_str - 1] == '{' || str[size_str - 1] == '['){
        cout << "Impossible" << endl;
        return 0;
    }
    for(int i = 0; i < size_str; i++){
        if( str[i] == '<' || str[i] == '(' || str[i] == '{' || str[i] == '[' ){
            count++;
        }
        if( str[i] == '>' || str[i] == ')' || str[i] == '}' || str[i] == ']' ){
            count--;
        }
        if( count < 0 ){
            cout << "Impossible" << endl;
            return 0;
        }
    }
    if( count != 0 ){
            cout << "Impossible" << endl;
            return 0;
    }
    crack(str);

    cout << count2 << endl;
    return 0;
}
// 1535511261278


#include <bits/stdc++.h>

using namespace std;

stack<char> pilha;
map<char,char> expc;
bool imp;

int main(){
    int res=0;
    string s;

    cin >> s;

    expc[')'] = '(';
    expc['}'] = '{';
    expc['>'] = '<';
    expc[']'] = '[';

    for (int i=0;i<s.size();i++){
        if (s[i]=='['||s[i]=='<'||s[i]=='('||s[i]=='{')
            pilha.push(s[i]);

        else if (!pilha.empty()){
            if (expc[s[i]]!=pilha.top()){
                //cout << expc[s[i]] << " " << s[i] << endl;
                res++;
                if(!pilha.empty())
                    pilha.pop();
            }

            else
                if(!pilha.empty())
                    pilha.pop();
        }

        else
            imp = true;

    }

    if (!imp)
        printf("%d\n", res);
    else
        printf("Impossible\n");

    return 0;
}

// 1481813117781


#include<iostream>
#include<string>
#include<stack>
#include<cmath>
using namespace std;
int main()
{
	stack <char> M;
	int sum=0;
	int flag=1;
	string s;
	cin>>s;
	int len=s.length();
	if(s[0]=='}'||s[0]==')'||s[0]==']'||s[0]=='>')
	{
		cout<<"Impossible"<<endl;
	}
	else
	{
		for(int i=0;i<len;i++)
		{
			if(s[i]=='{'||s[i]=='('||s[i]=='['||s[i]=='<')
			{
				M.push (s[i]);
			}
			else
			{
				if(M.empty())
				{
					flag=0;
					break;
				}
				else
				{
					if(s[i]=='}' && M.top()=='{')
					{
						M.pop();
					}
					else if(s[i]==')' && M.top()=='(')
					{
						M.pop();
					}
					else if(s[i]=='>' && M.top()=='<')
					{
						M.pop();
					}
					else if(s[i]==']' && M.top()=='[')
					{
						M.pop();
					}
					else
					{
						M.pop();
						sum++;
					}
				}
			}
		}
		if(M.empty()&&flag)
		{
			cout<<sum<<endl;
		}
		else
		{
			cout<<"Impossible"<<endl;
		}
	}
	return 0;
}


#include<iostream>
#include<string>
#include<stack>
#include<cmath>
using namespace std;
int main()
{
	stack <char> M;
	int sum=0;
	string s;
	cin>>s;
	int len=s.length()-1;
	if(s[0]=='}'||s[0]==')'||s[0]==']'||s[0]=='>')
	{
		cout<<"Impossible"<<endl;
	}
	//else if(s[len]=='{'||s[len]=='('||s[len]=='['||s[len]=='<')
	//{
		//cout<<"Impossible"<<endl;
	//}
	else
	{
		for(int i=0;i<s.length();i++)
		{
			if(s[i]=='{'||s[i]=='('||s[i]=='['||s[i]=='<')
			{
				M.push (s[i]);
			}
			else
			{
				if(s[i]=='}'&&M.top()=='{')
				{
					M.pop();
				}
				else if(s[i]==')'&&M.top()=='(')
				{
					M.pop();
				}
				else if(s[i]=='>'&&M.top()=='<')
				{
					M.pop();
				}
				else if(s[i]==']'&&M.top()=='[')
				{
					M.pop();
				}
				else
				{
					M.pop();
					sum++;
				}
			}
		}
		if(M.empty())
		{
			cout<<sum<<endl;
		}
		else
		{
			cout<<"Impossible"<<endl;
		}
	}
	return 0;
}


#include<iostream>
#include<string>
#include<stack>
#include<cmath>
using namespace std;
int main()
{
	stack <char> M;
	int sum=0;
	string s;
	cin>>s;
	int len=s.length()-1;
	if(s[0]=='}'||s[0]==')'||s[0]==']'||s[0]=='>')
	{
		cout<<"Impossible"<<endl;
	}
	//else if(s[len]=='{'||s[len]=='('||s[len]=='['||s[len]=='<')
	//{
		//cout<<"Impossible"<<endl;
	//}
	else
	{
		for(int i=0;i<s.length();i++)
		{
			if(s[i]=='{'||s[i]=='('||s[i]=='['||s[i]=='<')
			{
				M.push (s[i]);
			}
			else
			{
				if(s[i]=='}'&&M.top()=='{')
				{
					M.pop();
				}
				else if(s[i]==')'&&M.top()=='(')
				{
					M.pop();
				}
				else if(s[i]=='>'&&M.top()=='<')
				{
					M.pop();
				}
				else if(s[i]==']'&&M.top()=='[')
				{
					M.pop();
				}
				else
				{
					M.pop();
					sum++;
				}
			}
			if(M.empty())
			{
				cout<<sum<<endl;
			}
			else
			{
				cout<<"Impossible"<<endl;
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

string cad;

int main(){
	cin>>cad;

	queue<int> q[5];

	for(int i=0;cad[i];i++){
		if(cad[i]=='(')	q[0].push(i);
		else if(cad[i]=='{') q[1].push(i);
		else if(cad[i]=='[') q[2].push(i);
		else if(cad[i]=='<') q[3].push(i);

		if(cad[i]==')' && !q[0].empty()){
			int id = q[0].front();
			q[0].pop();
			cad[id] = cad[i] = '-';
		}
		else if(cad[i]=='}' && !q[1].empty()){
			int id = q[1].front();
			q[1].pop();
			cad[id] = cad[i] = '-';
		}
		else if(cad[i]==']' && !q[2].empty()){
			int id = q[2].front();
			q[2].pop();
			cad[id] = cad[i] = '-';
		}
		else if(cad[i]=='>' && !q[3].empty()){
			int id = q[3].front();
			q[3].pop();
			cad[id] = cad[i] = '-';
		}
	}

	int a = 0 , b = 0;
	for(int i=0;cad[i];i++)
		if(cad[i]=='(' || cad[i]=='[' || cad[i]=='{' || cad[i]=='<') a++;
		else if(cad[i]!='-') b++;

	if(a==b) printf("%d\n",a);
	else printf("Impossible\n");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

string cad;

char Inversa(char a){
	if(a=='{') return '}';
	if(a=='[') return ']';
	if(a=='<') return '>';
	return ')';
}

int main(){
	cin>>cad;

	stack<char> q;
	int cont = 0;

	for(int i=0;cad[i];i++){
		if(cad[i]=='(')	q.push(i);
		else if(cad[i]=='{') q.push(i);
		else if(cad[i]=='[') q.push(i);
		else if(cad[i]=='<') q.push(i);
		else if(!q.empty()){
			if(Inversa(cad[q.top()])!=cad[i]) cont++;
			int id = q.top();
			q.pop();
			cad[id] = cad[i] = '-';
		}
	}

	int a = 0 , b = 0;
	for(int i=0;cad[i];i++)
		if(cad[i]=='(' || cad[i]=='[' || cad[i]=='{' || cad[i]=='<') a++;
		else if(cad[i]!='-') b++;

	if(!a && !b) printf("%d\n",cont);
	else printf("Impossible\n");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

string cad;

char Inversa(char a){
	if(a=='{') return '}';
	if(a=='[') return ']';
	if(a=='<') return '>';
	return ')';
}

int main(){
	cin>>cad;

	stack<char> q;

	for(int i=0;cad[i];i++){
		if(cad[i]=='(')	q.push(i);
		else if(cad[i]=='{') q.push(i);
		else if(cad[i]=='[') q.push(i);
		else if(cad[i]=='<') q.push(i);
		else if(!q.empty()){
			if(Inversa(cad[q.top()])!=cad[i])
				while(!q.empty()) q.pop();
			else{
				int id = q.top();
				q.pop();
				cad[id] = cad[i] = '-';
			}
		}
	}

	int a = 0 , b = 0;
	for(int i=0;cad[i];i++)
		if(cad[i]=='(' || cad[i]=='[' || cad[i]=='{' || cad[i]=='<') a++;
		else if(cad[i]!='-') b++;

	if(a==b) printf("%d\n",a);
	else printf("Impossible\n");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

string cad;

char Inversa(char a){
	if(a=='{') return '}';
	if(a=='[') return ']';
	if(a=='<') return '>';
	return ')';
}

int main(){
	cin>>cad;

	stack<char> q;

	for(int i=0;cad[i];i++){
		if(cad[i]=='(')	q.push(i);
		else if(cad[i]=='{') q.push(i);
		else if(cad[i]=='[') q.push(i);
		else if(cad[i]=='<') q.push(i);
		else if(!q.empty() && Inversa(cad[q.top()])==cad[i]){
			int id = q.top();
			q.pop();
			cad[id] = cad[i] = '-';
		}
	}

	int a = 0 , b = 0;
	for(int i=0;cad[i];i++)
		if(cad[i]=='(' || cad[i]=='[' || cad[i]=='{' || cad[i]=='<') a++;
		else if(cad[i]!='-') b++;

	if(a==b) printf("%d\n",a);
	else printf("Impossible\n");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1000005;

string cad;

char Inversa(char a){
	if(a=='{') return '}';
	if(a=='[') return ']';
	if(a=='<') return '>';
	return ')';
}

int q[MAXN];

int main(){
	cin>>cad;

	int cont = 0;
	int piv = 0;

	for(int i=0;cad[i];i++){
		if(cad[i]=='(')	q[piv++] = i;
		else if(cad[i]=='{') q[piv++] = i;
		else if(cad[i]=='[') q[piv++] = i;
		else if(cad[i]=='<') q[piv++] = i;
		else if(piv){
			if(Inversa(cad[q[piv-1]])!=cad[i]) cont++;
			int id = q[--piv];
			cad[id] = cad[i] = '-';
		}
	}

	int a = 0 , b = 0;
	for(int i=0;cad[i];i++)
		if(cad[i]=='(' || cad[i]=='[' || cad[i]=='{' || cad[i]=='<') a++;
		else if(cad[i]!='-') b++;

	if(!a && !b) printf("%d\n",cont);
	else printf("Impossible\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int rsp=0;
int contrarios(char a, char b){
    int uittty;
if(a=='<' and b=='>'){return 0;}
if(a=='(' and b==')'){return 0;}
if(a=='[' and b==']'){return 0;}
if(a=='{' and b=='}'){return 0;}
rsp++;
}
int tipo(char a){
    if(a=='{' or a=='[' or a=='<' or a=='('){return 1;}
    return 0;
}
int main(){
stack<char>pila;
string p;
cin>>p;
for(int i=0;i<p.length();i++){
    if(tipo(p[i])==1){pila.push(p[i]);}
    else{if(pila.size()==0){cout<<"Impossible"<<endl;return 0;}
    contrarios(pila.top(),p[i]);pila.pop();}
}
if(pila.size()==0){cout<<rsp<<endl;}
else{cout<<"Impossible"<<endl;return 0;}
}


#include<bits/stdc++.h>
using namespace std;
int rsp=0;
int resta(int a,int b){
if(a>b){return a-b;}else{return b-a;}
}
int contrarios(char a,char b){
if(a=='<' and b=='>'){return 1;}
else if(a=='{' and b=='}'){return 1;}
else if(a=='[' and b==']'){return 1;}
else if(a=='(' and b==')'){return 1;}
else{rsp++;return 0;}
}
int puertas(char a){
if(a=='{' or a=='<' or a=='[' or a=='('){return 1;}
return 0;
}
int main(){
string p;
cin>>p;
int x=0;
int y=0;
while(p[p.length()-1]!='?'){
    while(puertas(p[x])==1 or p[x]=='?'){x++;if(x>=p.length()){cout<<"Impossible"<<endl;return 0;}}
    if(puertas(p[x])==0){
        y=x-1;
        if(y<0){cout<<"Impossible"<<endl;return 0;}
        while(puertas(p[y])==0 or p[y]=='?'){y--;if(y<0){cout<<"Impossible"<<endl;return 0;}}
    }
    contrarios(p[y],p[x]);
    p[x]='?';
    p[y]='?';
    x++;
}
cout<<rsp<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int resta(int a,int b){
if(a>b){return a-b;}else{return b-a;}
}
int contrarios(char a,char b){
if((a=='{' or a=='<') and (b=='}' or b=='>')){return 1;}
else if((a=='[' or a=='(') and (b==']' or b==')')){return 1;}
else{return 0;}
}
int puertas(char a){
if(a=='{' or a=='<' or a=='[' or a=='('){return 1;}
return 0;
}
int main(){
string p;
cin>>p;
int x=0;
int y=0;
int s1=0,s2=0,s3=0,s4=0;
for(int i=0;i<p.length();i++){
    if(p[i]=='{'){s1++;}
    if(p[i]=='['){s2++;}
    if(p[i]=='}'){s3++;}
    if(p[i]==']'){s4++;}
}
while(p[p.length()-1]!='?'){
    while(puertas(p[x])==1 or p[x]=='?'){x++;if(x>=p.length()){cout<<"Impossible"<<endl;return 0;}}
    if(puertas(p[x])==0){
        y=x-1;
        if(y<0){cout<<"Impossible"<<endl;return 0;}
        while(puertas(p[y])==0 or p[y]=='?'){y--;if(y<0){cout<<"Impossible"<<endl;return 0;}}
    }
    if(contrarios(p[y],p[x])==1){
    p[x]='?';
    p[y]='?';
    x++;}
    else{cout<<"Impossible"<<endl;return 0;}
}
cout<<resta(s1,s3)+resta(s2,s4)<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int rsp=0;
int contrarios(char a, char b){
if(a=='<' and b=='>'){return 0;}
if(a=='(' and b==')'){return 0;}
if(a=='[' and b==']'){return 0;}
if(a=='{' and b=='}'){return 0;}
rsp++;
}
int tipo(char a){
    if(a=='{' or a=='[' or a=='<' or a=='('){return 1;}
    return 0;
}
int main(){
stack<char>pila;
string p;
cin>>p;
for(int i=0;i<p.length();i++){
    if(tipo(p[i])==1){pila.push(p[i]);}
    else{if(pila.size()==0){cout<<"Impossible"<<endl;return 0;}
    contrarios(pila.top(),p[i]);pila.pop();}
}
if(pila.size()==0){cout<<rsp<<endl;}
else{cout<<"Impossible"<<endl;return 0;}
}


#include<bits/stdc++.h>
using namespace std;
int rsp=0;
int contrarios(char a, char b){
if(a=='<' and b=='>'){return 0;}
if(a=='(' and b==')'){return 0;}
if(a=='[' and b==']'){return 0;}
if(a=='{' and b=='}'){return 0;}
rsp++;
}
int tipo(char a){
    if(a=='{' or a=='[' or a=='<' or a=='('){return 1;}
    return 0;
}
int main(){
stack<char>pila;
string p;
cin>>p;
for(int i=0;i<p.length();i++){
    if(tipo(p[i])==1){pila.push(p[i]);}
    else{if(pila.size()==0 and i!=p.length()-1){cout<<"Impossible"<<endl;return 0;}
    contrarios(pila.top(),p[i]);pila.pop();}
}
if(pila.size()==0){cout<<rsp<<endl;}
else{cout<<"Impossible"<<endl;return 0;}
}


#include<bits/stdc++.h>

#define ll long long
#define p(a) printf("%d\n",a)
#define s(a) scanf("%d",&a)
#define sll(a) scanf("%lld",&a)
#define rep(a,b,c) for(int c=a ; c<=b ; ++c)
#define pii pair<int , int>
#define vi vector<int>
#define vs vector<string>
#define pb push_back
#define vi_it vector<int> :: iterator
#define vs_it vector<string> :: iterator
#define mp(a,b) make_pair(a,b)
#define INF INT_MAX
#define inf INT_MIN
#define ff first
#define ss second
#define mset(a,val) memset(a,val,sizeof a)
#define ALL(a) a.begin(),a.end()

using namespace std;

bool open(char c)
{
	return (c=='<' || c=='(' || c=='{' || c=='[');
}

bool ispair(char o ,char c)
{
	if( o=='(' && c==')')
		return true;

	if( o=='[' && c==']')
		return true;

	if( o=='{' && c=='}')
		return true;

	if( o=='<' && c=='>')
		return true;

	return false;
}
int main()
{

	// freopen("in.txt" ,"r" , stdin);
	// freopen("out.txt","w",stdout);

	string s ; cin >> s ;
	bool flag = false ;

	stack < char > st;

	if(s.length() == 0)
	{
		cout << 0 << endl;
		return 0;
	}

	if(!open(s[0]))
		flag = true;
	st.push(s[0]);

	ll int res = 0;
	int i=1;

	while(!flag && i<s.length())
	{
		if(open(s[i]))
			st.push(s[i]);
		else{
			if(st.empty())
				flag = true;
			if(open(st.top()))
			{
				if(!ispair(st.top() , s[i]))
					res++;
				st.pop();
			}
		}
		i++;

	}
	if(!s.empty())
		flag = true;
	if(flag)
		cout << "Impossible" << endl;
	else
		cout << res << endl;
	//cout<< "Done in " << clock() / CLOCKS_PER_SEC <<"sec"<< endl;
	return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define p(a) printf("%d\n",a)
#define s(a) scanf("%d",&a)
#define sll(a) scanf("%lld",&a)
#define rep(a,b,c) for(int c=a ; c<=b ; ++c)
#define pii pair<int , int>
#define vi vector<int>
#define vs vector<string>
#define pb push_back
#define vi_it vector<int> :: iterator
#define vs_it vector<string> :: iterator
#define mp(a,b) make_pair(a,b)
#define INF INT_MAX
#define inf INT_MIN
#define ff first
#define ss second
#define mset(a,val) memset(a,val,sizeof a)
#define ALL(a) a.begin(),a.end()

using namespace std;

bool open(char c)
{
	return (c=='<' || c=='(' || c=='{' || c=='[');
}

bool ispair(char o ,char c)
{
	if( o=='(' && c==')')
		return true;

	if( o=='[' && c==']')
		return true;

	if( o=='{' && c=='}')
		return true;

	if( o=='<' && c=='>')
		return true;

	return false;
}
int main()
{

	// freopen("in.txt" ,"r" , stdin);
	// freopen("out.txt","w",stdout);

	string s ; cin >> s ;
	bool flag = false ;

	stack < char > st;

	if(s.length() == 0)
	{
		cout << 0 << endl;
		return 0;
	}

	if(!open(s[0]))
		flag = true;
	st.push(s[0]);

	ll int res = 0;
	int i=1;

	while(!flag && i<s.length())
	{
		if(open(s[i]))
			st.push(s[i]);
		else{
			if(st.empty())
				flag = true;
			if(open(st.top()))
			{
				if(!ispair(st.top() , s[i]))
					res++;
				st.pop();
			}
		}
		i++;

	}
	if(s.empty())
		flag = true;
	if(flag)
		cout << "Impossible" << endl;
	else
		cout << res << endl;
	//cout<< "Done in " << clock() / CLOCKS_PER_SEC <<"sec"<< endl;
	return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define p(a) printf("%d\n",a)
#define s(a) scanf("%d",&a)
#define sll(a) scanf("%lld",&a)
#define rep(a,b,c) for(int c=a ; c<=b ; ++c)
#define pii pair<int , int>
#define vi vector<int>
#define vs vector<string>
#define pb push_back
#define vi_it vector<int> :: iterator
#define vs_it vector<string> :: iterator
#define mp(a,b) make_pair(a,b)
#define INF INT_MAX
#define inf INT_MIN
#define ff first
#define ss second
#define mset(a,val) memset(a,val,sizeof a)
#define ALL(a) a.begin(),a.end()

using namespace std;

bool open(char c)
{
	return (c=='<' || c=='(' || c=='{' || c=='[');
}

bool ispair(char o ,char c)
{
	if( o=='(' && c==')')
		return true;

	if( o=='[' && c==']')
		return true;

	if( o=='{' && c=='}')
		return true;

	if( o=='<' && c=='>')
		return true;

	return false;
}
int main()
{

	// freopen("in.txt" ,"r" , stdin);
	// freopen("out.txt","w",stdout);

	string s ; cin >> s ;
	bool flag = false ;

	stack < char > st;

	if(s.length() == 0)
	{
		cout << 0 << endl;
		return 0;
	}

	if(!open(s[0]))
		flag = true;
	st.push(s[0]);

	ll int res = 0;
	int i=1;

	while(!flag && i<s.length())
	{
		if(open(s[i]))
			st.push(s[i]);
		else{
			if(st.empty())
				flag = true;
			if(open(st.top()))
			{
				if(!ispair(st.top() , s[i]))
					res++;
				st.pop();
			}
		}
		i++;

	}
	if(!st.empty())
		flag = true;
	if(flag)
		cout << "Impossible" << endl;
	else
		cout << res << endl;
	//cout<< "Done in " << clock() / CLOCKS_PER_SEC <<"sec"<< endl;
	return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define p(a) printf("%d\n",a)
#define s(a) scanf("%d",&a)
#define sll(a) scanf("%lld",&a)
#define rep(a,b,c) for(int c=a ; c<=b ; ++c)
#define pii pair<int , int>
#define vi vector<int>
#define vs vector<string>
#define pb push_back
#define vi_it vector<int> :: iterator
#define vs_it vector<string> :: iterator
#define mp(a,b) make_pair(a,b)
#define INF INT_MAX
#define inf INT_MIN
#define ff first
#define ss second
#define mset(a,val) memset(a,val,sizeof a)
#define ALL(a) a.begin(),a.end()

using namespace std;

bool open(char c)
{
	return (c=='<' || c=='(' || c=='{' || c=='[');
}

bool ispair(char o ,char c)
{
	if( o=='(' && c==')')
		return true;

	if( o=='[' && c==']')
		return true;

	if( o=='{' && c=='}')
		return true;

	if( o=='<' && c=='>')
		return true;

	return false;
}
int main()
{

	// freopen("in.txt" ,"r" , stdin);
	// freopen("out.txt","w",stdout);

	string s ; cin >> s ;
	bool flag = false ;

	stack < char > st;

	if(s.length() == 0)
	{
		cout << 0 << endl;
		return 0;
	}

	if(!open(s[0]))
		flag = true;
	st.push(s[0]);

	ll int res = 0;
	int i=1;

	while(!flag && i<s.length())
	{
		if(open(s[i]))
			st.push(s[i]);
		else{
			if(st.empty())
				flag = true;
		else	if(open(st.top()))
			{
				if(!ispair(st.top() , s[i]))
					res++;
				st.pop();
			}
		}
		i++;

	}
	if(!st.empty())
		flag = true;
	if(flag)
		cout << "Impossible" << endl;
	else
		cout << res << endl;
	//cout<< "Done in " << clock() / CLOCKS_PER_SEC <<"sec"<< endl;
	return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define p(a) printf("%d\n",a)
#define s(a) scanf("%d",&a)
#define sll(a) scanf("%lld",&a)
#define rep(a,b,c) for(int c=a ; c<=b ; ++c)
#define pii pair<int , int>
#define vi vector<int>
#define vs vector<string>
#define pb push_back
#define vi_it vector<int> :: iterator
#define vs_it vector<string> :: iterator
#define mp(a,b) make_pair(a,b)
#define INF INT_MAX
#define inf INT_MIN
#define ff first
#define ss second
#define mset(a,val) memset(a,val,sizeof a)
#define ALL(a) a.begin(),a.end()

using namespace std;

bool open(char c)
{
	return (c=='<' || c=='(' || c=='{' || c=='[');
}

bool ispair(char o ,char c)
{
	if( o=='(' && c==')')
		return true;

	if( o=='[' && c==']')
		return true;

	if( o=='{' && c=='}')
		return true;

	if( o=='<' && c=='>')
		return true;

	return false;
}
int main()
{

	// freopen("in.txt" ,"r" , stdin);
	// freopen("out.txt","w",stdout);

	string s ; cin >> s ;
	bool flag = false ;

	stack < char > st;

	if(s.length() == 0)
	{
		cout << 0 << endl;
		return 0;
	}

	if(!open(s[0]))
		flag = true;
	st.push(s[0]);

	ll int res = 0;
	int i=1;

	while(!flag && i<s.length())
	{
		if(open(s[i]))
			st.push(s[i]);
		else{
			if(st.empty())
				cout << i << endl,flag = true;
			if(open(st.top()))
			{
				if(!ispair(st.top() , s[i]))
					res++;
				st.pop();
			}
		}
		i++;

	}
	if(s.empty())
		flag = true;
	if(flag)
		cout << "Impossible" << endl;
	else
		cout << res << endl;
	//cout<< "Done in " << clock() / CLOCKS_PER_SEC <<"sec"<< endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <stack>
using namespace std;
void planA(char *a,int n)
{
	stack<char> s;
	int total=0,i;
	for (i=0;i<n;i++)
	{
		if (a[i]=='<' || a[i]=='{'  ||  a[i]=='[' || a[i]=='(')
		{
			s.push(a[i]);
		}
		else
		{
			if (s.empty())
			{
				cout<<"Impossible"<<endl;
				return;
			}
			else
			{
				switch(a[i])
				{
					case '>':
						if (s.top()!='<')total++;
						break;
					case  '}':
						if (s.top()!='{')total++;
						break;
					case  ')':
						if (s.top()!='(')total++;
						break;
					case  ']':
						if (s.top()!='[')total++;
						break;
				}
				s.pop();
			}
		}
	}
	if (s.empty())
		cout<<total<<endl;
	else
		cout<<"Impossible"<<endl;
}
int main()
{
	int n;
	char a[1000020];
	while (cin>>a)
	{
		n=strlen(a);
		planA(a,n);
	}
  return 0;
}


#include <iostream>
#include <cstring>
#include <stack>
using namespace std;
void planA(char *a,int n)
{
	stack<char> s;
	int total=0,i;
	for (i=0;i<n;i++)
	{
		if (a[i]=='<' || a[i]=='{'  ||  a[i]=='[' || a[i]=='(')
		{
			s.push(a[i]);
		}
		else
		{
			if (s.empty())
			{
				cout<<"Impossible"<<endl;
				return;
			}
			else
			{
				switch(a[i])
				{
					case '>':
						if (s.top()!='<')total++;
						break;
					case  '}':
						if (s.top()!='{')total++;
						break;
					case  ')':
						if (s.top()!='(')total++;
						break;
					case  ']':
						if (s.top()!='[')total++;
						break;
				}
				s.pop();
			}
		}
	}
	if (s.empty())
		cout<<total<<endl;
	else
		cout<<"Impossible"<<endl;
}
int main()
{
	int n;
	char a[1000020];
	while (cin>>a)
	{
		n=strlen(a);
		planA(a,n);
	}
	return 0;
}