#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 1000005
string str;
int n,f[N];
int main(){
cin>>str;
n=str.size();
str=" "+str;
for(int i=1;i<=n;i++){
int v=f[i-1];
if(str[i]=='('||str[i]=='['){
continue;
}
if(str[i]==')'){
if(str[i-v-1]=='(')
f[i]=v+2;
}
if(str[i]==']'){
if(str[i-v-1]=='[')
f[i]=v+2;
}
}
int ans=0;
int s=0;
for(int i=1;i<=n;i++){
int v=f[i];
f[i]+=f[i-v];
if(f[i]>ans){
ans=f[i];
s=i;
}
}
for(int i=s-ans+1;i<=s;i++)cout<<str[i];
return 0;
}