#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define INF 1e18//change to const int INF=1e18 if causing problem
const ll MOD=998244353;
const ll alt=1e10;
const ll inf=1e9+7;//Precalc is not a bad idea
//#define int ll
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define mod(a) (a+inf)%inf
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(){
string s,c="";
cin>>s;
vector<int> p[26];
vector<int> cnt(26,0);
vector<int> a(sz(s),0);
for(int i=0;i<sz(s);i++){
a[i]=cnt[int(s[i])-'a']+1;
cnt[int(s[i])-'a']+=1;
p[int(s[i])-'a'].pb(i);
c+='0';
}
for(int i=0;i<26;i++){
vector<int> m(sz(p[i]),0);
int j=0;
while(j<sz(p[i])){
if(m[j]==0){
for(int k=sz(p[i])-1;k>j;k--){
if(m[k]==0 and (p[i][j]+p[i][k])%2==1 and (a[p[i][j]]+a[p[i][k]])%2==1){
m[j]=1,m[k]=1;
c[p[i][j]]='(';
c[p[i][k]]=')';
break;
}
}
}
j++;
}
}
bool flag=true;
for(int i=0;i<sz(c);i++){
if(c[i]=='0'){
flag=false;
break;
}
}
if(flag==true) cout<<c<<endl;
else cout<<-1<<endl;
return 0;
}
//Icebear#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define INF 1e18//change to const int INF=1e18 if causing problem
const ll MOD=998244353;
const ll alt=1e10;
const ll inf=1e9+7;//Precalc is not a bad idea
//#define int ll
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define mod(a) (a+inf)%inf
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(){
string s,c="";
cin>>s;
vector<int> p[26];
vector<int> cnt(26,0);
vector<int> a(sz(s),0);
for(int i=0;i<sz(s);i++){
a[i]=cnt[int(s[i])-'a']+1;
cnt[int(s[i])-'a']+=1;
p[int(s[i])-'a'].pb(i);
c+='0';
}
for(int i=0;i<26;i++){
vector<int> m(sz(p[i]),0);
int j=0;
while(j<sz(p[i])){
if(m[j]==0){
for(int k=sz(p[i])-1;k>j;k--){
if(m[k]==0 and (p[i][j]+p[i][k])%2==1 and (a[p[i][j]]+a[p[i][k]])%2==1){
m[j]=1,m[k]=1;
c[p[i][j]]='(';
c[p[i][k]]=')';
break;
}
}
}
j++;
}
}
bool flag=true;
for(int i=0;i<sz(c);i++){
if(c[i]=='0'){
flag=false;
break;
}
}
if(flag==true) cout<<c<<endl;
else cout<<-1<<endl;
return 0;
}
//Icebear
Compilation message
match.cpp: In function 'int main()':
match.cpp:29:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i=0;i<sz(s);i++){
| ^
match.cpp:38:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | while(j<sz(p[i])){
| ^
match.cpp:53:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i=0;i<sz(c);i++){
| ^
match.cpp: At global scope:
match.cpp:67:10: error: redefinition of 'const ll MOD'
67 | const ll MOD=998244353;
| ^~~
match.cpp:5:10: note: 'const ll MOD' previously defined here
5 | const ll MOD=998244353;
| ^~~
match.cpp:68:10: error: redefinition of 'const ll alt'
68 | const ll alt=1e10;
| ^~~
match.cpp:6:10: note: 'const ll alt' previously defined here
6 | const ll alt=1e10;
| ^~~
match.cpp:69:10: error: redefinition of 'const ll inf'
69 | const ll inf=1e9+7;//Precalc is not a bad idea
| ^~~
match.cpp:7:10: note: 'const ll inf' previously defined here
7 | const ll inf=1e9+7;//Precalc is not a bad idea
| ^~~
match.cpp:85:5: error: redefinition of 'int main()'
85 | int main(){
| ^~~~
match.cpp:23:5: note: 'int main()' previously defined here
23 | int main(){
| ^~~~
match.cpp: In function 'int main()':
match.cpp:91:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for(int i=0;i<sz(s);i++){
| ^
match.cpp:100:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | while(j<sz(p[i])){
| ^
match.cpp:115:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | for(int i=0;i<sz(c);i++){
| ^