//* Problem  : 1183. Brackets sequence
//* Contest  : acm.timus.ru
//* Type     : Solution
//* Date     : 2008.07.07
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 6.0
//* Algorithm: DP

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <queue>

using namespace std;

#define int64 long long
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define SZ(a) (int)a.size()
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define INF 1000*1000*1000
#define ALL(a) a.begin(), a.end()

int n;

int state[128][128], a[128][128];

char s[200];

void solve()
{
	for (int i = 1; i <= n; i++)
		a[i][i] = 2;
	for (int len = 2; len <= n; len++)
		for (int i = 1, j; i <= n - len + 1; i++)
		{
			j = i + len - 1;
			a[i][j] = INF;
			if ((s[i] == '(' && s[j] == ')') || (s[i] == '[' && s[j] == ']'))
				a[i][j] = a[i+1][j-1] + 2;
			for (int k = i; k < j; k++)
				if (a[i][j] > a[i][k] + a[k+1][j])
				{
					a[i][j] = a[i][k] + a[k+1][j];
					state[i][j] = k;
				}
		}
}

void print(int i, int j)
{
	if (i > j) return;
	if (i == j)
	{
		if (s[i] == '(' || s[i] == ')') printf("()");
		else printf("[]");
	}
	else if (!state[i][j])
	{
		putchar(s[i]);
		print(i + 1, j - 1);
		putchar(s[j]);
	}
	else
	{
		print(i, state[i][j]);	
		print(state[i][j] + 1, j);
	}
}

void result()
{
	print(1, n);
	putchar('\n');
}

int main()
{
#ifdef _DEBUG
	freopen("1064", "r", stdin);
#endif
	scanf("%s", &s[1]); n = strlen(&s[1]);
	solve();
	result();
	return 0;
}

