Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)

	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	ps := make([]int, n)
	for i := range ps {
		sc.Scan()
		p, _ := strconv.Atoi(sc.Text())
		ps[i] = p
	}

	mp := make([]int, n+1)
	ans := make([]byte, 0)
	var pp, max int
	for _, p := range ps {
		mp[p] = 1
		if p < pp {
			if mp[p+1] != 1 {
				fmt.Println(":(")
				return
			}
			ans = append(ans, ')')
		} else {
			for i := max; i < p-1; i++ {
				ans = append(ans, '(')
			}
			ans = append(ans, '(')
			ans = append(ans, ')')
		}
		if p > max {
			max = p
		}
		pp = p
	}
	fmt.Println(string(ans))
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
bool b00l[123123];
signed main() {
	int n; string ans = "";
	int a = 0, b = 0, c;
	cin >> n;
	for1(i, n) {
		cin >> c;
		if (a < c) {
			for1(j, c - a)ans += '(';
			ans += ')';
			a = c;
		}
		else {
			bool b1 = 1;
			for (int j = c + 1; j <= a; j++)if (!b00l[j])b1 = 0;
			if (b1) { ans += ')'; }
			else {
				cout << ":(\n";
				return 0;
			}
		}
		b = c;
		b00l[c] = 1;
	}
	cout << ans << endl;
}

C++: #include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define double long double
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,int> Pi;
typedef pair<P,P> PP;
double eps=1e-8;
int mod=1e9+7;
int inf=1LL<<55;

priority_queue<P,vector<P>,greater<P> > pq;

int n,p[100000];


string ans;

signed main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>p[i];

  stack<int> st;
  int x=1;
  string ans;
  for(int i=0;i<n;i++){
    while(x<=p[i])st.push(x++),ans+='(';
    int y=st.top();
    if(y!=p[i]){cout<<":("<<endl;return 0;}
    ans+=')';
    st.pop();
  }
  cout<<ans<<endl;
  
  return 0;
}

C++: //include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	stack<LL> st;
	queue<LL> p;
	string ans = "";
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		p.push(k);
	}
	for (int i = 1; i <= n; i++) {
		ans += "(";
		st.push(i);
		while (st.size() != 0 and st.top() == p.front()) {
			ans += ")";
			st.pop();
			p.pop();
		}
	}
	if (p.size() == 0) {
		cout << ans << endl;
	}
	else {
		cout << ":(" << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> p(n);
  for(int i=0;i<n;i++) cin>>p[i],p[i]--;
  
  vector<int> q(n);
  for(int i=0;i<n;i++) q[p[i]]=i;
  
  auto NG=[&](){cout<<":("<<endl;exit(0);};
  string ans;
  stack<int> st;
  for(int i=0,k=0;i<n;i++){
    ans+='(';
    st.emplace(q[i]);
    while(!st.empty()&&st.top()==k){
      ans+=')';
      st.pop();
      k++;
    }    
  }
  
  if(!st.empty()) NG();
  cout<<ans<<endl;
  return 0;
}

C++: #include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) ;
#define LINE     ;
#define dumpV(v);
#define STOP     ;
#endif
#define mp make_pair

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fi<<", "<<a.se<<')';
    return out;
  }
}


string s;

vector<pii> u;
void calc(int& i) {
    if(i == s.size()) return;
    assert(s[i] == '(');
    int l = i;
    ++i;
    while(s[i] == '(') calc(i);
    assert(s[i] == ')');
    u.push_back(make_pair(l, i));
    ++i;
    // cout << l << " " << i << endl;
}

int main(){
    int n;
    cin >> n;
    vector<pii> v(n);
    rep(i, n) {
        int j;
        cin >> j;
        --j;
        v[i] = make_pair(j, i);
    }
    sort(all(v));
    priority_queue<int,vector<int>,greater<int> > q;
    int cur = 0;
    rep(i, n) {
        s += '(';
        q.push(v[i].se);
        while(q.top() == cur) {
            q.pop();
            ++cur;
            s+=')';
        }
    }
    int id = 0;
    while(id < s.size()) calc(id);

    dumpV(u);

    {
        map<int, int> mp;
        for(auto&& p : u) mp[p.se] = 1;
        int cnt = 0;
        for(auto&& p : mp) p.se = cnt++;
        for(auto&& p : u) p.se = mp[p.se];
    }
    {
        map<int, int> mp;
        for(auto&& p : u) mp[p.fi] = 1;
        int cnt = 0;
        for(auto&& p : mp) p.se = cnt++;
        for(auto&& p : u) p.fi = mp[p.fi];
    }
    sort(all(u));
    if(v == u) cout << s <<endl;
    else cout << ":(" << endl;

    dump(s);
    dumpV(v);
    dumpV(u);
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> q(n);
    for (int i = 0; i < n; ++i) {
        int p;
        cin >> p;
        q[p - 1] = i;
    }

    string ans;
    stack<int> st;
    int count_closing_parenthesis = 0;
    for (int i = 0; i < n; ++i) {
        ans += "(";
        st.push(q[i]);

        while (st.size() && count_closing_parenthesis == st.top()) {
            ans += ")";
            st.pop();
            count_closing_parenthesis++;
        }
    }
    if (!st.empty()) {
        cout << ":(" << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}