#include <bits/stdc++.h>
#define GOOD_LUCK ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define itn int
#define INF 100000000
#define MOD 998244353
#define MAX 103
#define endl "\n"
#define ff first
#define ss second
using namespace std;
int temp;
signed main() {
GOOD_LUCK
int t;
t = 1;
// cin >> t;
while (t--) {
int n;
string a;
cin >> a;
n = a.size();
if (n % 2 != 0) {
cout << -1;
return 0;
}
stack <char> s;
map <char, int> m;
for (int i=0; i < n; i++) {
m[a[i]]++;
if (s.empty()) s.push(a[i]);
else if (s.top() == a[i]) s.pop();
else s.push(a[i]);
}
/*for (auto i : m) {
cout << i.ff << ' ' << i.ss;
cout << endl;
}*/
if (s.empty()) {
for (auto i : m) {
if (i.ss % 2 != 0) {
cout << -1;
return 0;
}
}
string ans = "";
for (int i=0; i < n; i++) {
if (m[a[i]] > 0) {
ans = ans + '(';
m[a[i]]-=2;
}
else {
ans += ')';
}
}
cout << ans;
}
else {
cout << -1;
}
}
return 0;
}
// Problem C
// by Ekber_Ekber
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |