#3 和 #8 莫名RE,不知道为什么,有大佬帮忙看看吗
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
const int maxn = 1e6 + 5;
string str;
int s[maxn], top;
int vis[maxn];
int main() {
cin >> str;
int len = str.length();
for (int i = 0; i < len; i++) {
if (str[i] == '(' || str[i] == '[') {
s[++top] = i;
} else if (str[i] == ')') {
if (str[s[top]] == '(') {
vis[s[top]] = vis[i] = true;
top--;
} else {
top = 0;
}
} else {
if (str[s[top]] == '[') {
vis[s[top]] = vis[i] = true;
top--;
} else {
top = 0;
}
}
}
int ansl = 0, ansr = 0;
for (int l = 0; l < len; l++) {
int r = l;
while (vis[r]) r++;
if (r - l > ansr - ansl + 1) {
ansl = l, ansr = r - 1;
}
l = r;
}
for (int i = ansl; i <= ansr; i++) {
putchar(str[i]);
}
return 0;
}