#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<vector>
using namespace std;
#define nMax 201
#define FOR(i,a,b) for(int (i) = (a) ;(i) <= (b) ; (i) ++)
#define PB push_back
#define INS insert
#define LL long long
#define bug puts("Fuck");
char s[nMax];
int n;
int dp[nMax][nMax];
bool match(int i,int j){
if(s[i] == '[') return s[j] == ']';
if(s[i] == '(') return s[j] == ')';
return false;
}
int fa[nMax][nMax];
int mark[nMax];
void Mark(int l,int r){
if( l > r) return ;
if( l == r) {
mark[l]=1;
return ;
}
if(fa[l][r] == r){
mark[l] = 0;
mark[r] = 0;
Mark(l+1,r-1);
return ;
}
Mark(l,fa[l][r]);
Mark(fa[l][r]+1,r);
}
int main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
while(cin>>s){
n = strlen(s);
memset(dp,0,sizeof(dp));
for(int i=0;i<n;i++) dp[i][i] = 1,fa[i][i] = i;
for(int l=2;l<=n;l++){
for(int i=0,j;i<n;i++)if((j = (l+i-1)) < n) {
dp[i][j] = 100101000;
if(match(i,j)) {
dp[i][j] = dp[i+1][j-1];
fa[i][j] = j;
}
for(int k=i;k<j;k++){
if(dp[i][k] + dp[k+1][j] < dp[i][j]){
dp[i][j] = dp[i][k] + dp[k+1][j];
fa[i][j] = k;
}
}
}else break;
}
memset(mark,0,sizeof(mark));
Mark(0,n-1);
for(int i=0;i<n;i++) if(mark[i]){
if(s[i] == '(' || s[i] == ')') printf("()");
else printf("[]");
}else printf("%c",s[i]);printf("\n");
}
return 0;
}