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 <bits/stdc++.h>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD=1e9+7;
const int MAX=1e5+100;

int main() {
  int n;cin>>n;
  vector<int> ps(n);
  REP(i,n) cin>>ps[i];

  // 現在存在している「(」の数と、今)を置いたら、そこの数字は何になるかだけ保存しておく
  int lcnt = 0;
  vector<int> nums;
  string res;
  REP(i,n) {
    if (!nums.empty() && ps[i]<nums.back()) {
      OUT(":(");
      return 0;
    }

    if (ps[i]>lcnt) {
      int gap = ps[i]-lcnt;
      REP(j,gap) {
        res.push_back('(');
        nums.push_back(lcnt+j+1);
      }
      lcnt += gap;
    }

    res.push_back(')');
    nums.pop_back();
  }
  OUT(res);

  return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> p(n);
	REP(i, n) cin >> p[i];
	string ans = "";
	int pos = 0;
	stack<int> st;
	REP(i, n) {
		if(!st.empty() && p[i] == st.top()) {
			ans += ")";
			st.pop();
		} else if(p[i] > pos) {
			while(pos < p[i]) {
				pos++;
				st.push(pos);
				ans += "(";
			}
			ans += ")";
			st.pop();
		} else {
			cout << ":(" << endl;
			return 0;
		}
	}
	cout << ans << endl;
}
/* --------------------------------------- */

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int p[125252];
char s[252521];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",p+i);
  int it = 0;
  int cnt = 0;
  stack<int> S;
  REP(i,n){
    while(S.empty() || S.top() < p[i]){
      s[it++] = '(';
      S.push(++cnt);
    }
    if(S.top() != p[i]){
      puts(":("); return 0;
    }
    S.pop();
    s[it++] = ')';
  }
  if(S.size() > 0){
    puts(":("); return 0;
  }else{
    puts(s);
  }
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll n;
  cin >> n;

  vector<ll> p(n);
  for (ll i = 0; i < n; ++i) {
    cin >> p[i];
    p[i]--;
  }

  bool ok = true;
  ll cur = 0;
  stack<ll> stack;
  stringstream ss;
  for (ll i = 0; i < n; ++i) {
    for (; cur <= p[i]; ++cur) {
      ss << "(";
      stack.push(cur);
    }

    if (stack.top() != p[i]) {
      ok = false;
      break;
    }

    ss << ")";
    stack.pop();
  }

  if (ok) {
    cout << ss.str() << endl;
  } else {
    cout << ":(" << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<stack>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	cin>>n;
	int p[n];
	string res="";
	stack<int> st;
	rep(i,n)cin>>p[i];
	st.push(-1);
	bool check=false;
	int cnt=1;
	rep(i,n){
		int tmp=st.top();
		st.pop();
		if(tmp==-1){
			st.push(-1);
			while(cnt<=p[i]){
				st.push(cnt);
				cnt++;
				res+="(";
			}
			res+=")";
		}else{
			if(tmp<p[i]){
				while(cnt<=p[i]){
					st.push(cnt);
					cnt++;
					res+="(";
				}
				res+=")";
			}else if(tmp>p[i]){
				check=true;
				break;
			}else{
				res+=")";
			}
		}
		if(st.top()!=-1)st.pop();
	}
	if(check)cout<<":("<<endl;
	else cout<<res<<endl;
	return 0;
}