括号匹配(捉鬼)
#include<iostream> #include<cstdio> #include<algorithm> #include<vector> #include<queue> #include<cstring> #include<map> #include<stack> #define mp make_pair #define pb push_back #define fi first #define se second #define pw(x) (1ll << (x)) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() #define rep(i,l,r) for(int i=(l);i<(r);i++) #define per(i,r,l) for(int i=(r);i>=(l);i--) #define FOR(i,l,r) for(int i=(l);i<=(r);i++) #define eps 1e-9 #define PIE acos(-1) #define cl(a,b) memset(a,b,sizeof(a)) #define fastio ios::sync_with_stdio(false);cin.tie(0); #define lson l , mid , ls #define rson mid + 1 , r , rs #define ls (rt<<1) #define rs (ls|1) #define INF 0x3f3f3f3f #define LINF 0x3f3f3f3f3f3f3f3f #define lowbit(x) (x&(-x)) #define sqr(a) a*a #define ll long long #define ull unsigned long long #define vi vector<int> #define pii pair<int, int> #define dd(x) cout << #x << " = " << (x) << ", " #define de(x) cout << #x << " = " << (x) << "\n" #define endl "\n" using namespace std; vector<pii>ans; stack< pair<char,int> > s; int main() { int n; string str; cin>>n;n<<=1; cin>>str; int ok=1; int CNT=0,cnt=0; rep(i,0,n){ if(str[i]>='a'&&str[i]<='z')cnt++;else CNT++; if(s.empty())s.push(mp(str[i],cnt)); else { // de(str[i]); pair<char,int> t=s.top(); // de(t.fi);de(t.se); // de(abs(str[i]-t)); // de('A'-'a'); if(abs(str[i]-t.fi)==abs('A'-'a')){ if(str[i]-t.fi==('A'-'a'))ans.pb(mp(CNT,t.se)); else ans.pb(mp(t.se,cnt)); s.pop(); }else { if(str[i]>='a'&&str[i]<='z')s.push(mp(str[i],cnt)); else s.push(mp(str[i],CNT)); } } // de(s.size()); } // de(s.size()); sort(all(ans)); if(s.empty())rep(i,0,sz(ans))printf("%d%c",ans[i].se,i==n-1?'\n':' '); else puts("Impossible"); return 0; }