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 INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long

int x[100001];

signed main(){
  int n;
  cin>>n;
  int a[100001];
  int check=0,mini;
  lp(i,n){
    cin>>a[i];
    if(i==0) mini=a[i];
    if(a[i]<mini&&a[i]!=mini-1){
      cout<<":("<<endl;
      return 0;
    }
    mini=min(mini,a[i]);
  }
  int bef=0;
  string s="";
  lp(i,n){
    if(i==0||bef<a[i]){
     lp(j,a[i]-bef){
        s.push_back('(');
      }
      bef=max(a[i],bef);
    }
    s.push_back(')');
  }
  string ans=s;
  //cout<<s<<endl;
  int stat=0;
  while(1){
    stat=0;
    lp(i,s.size()){
      if(i==0)continue;
      if(s[i]==')'&&s[i-1]=='('){
        s.erase(i-1,2);
        stat=1;
      }
    }
    if(stat==0)break;
    //cout<<s<<endl;
  }
  if(s.size()==0){
    cout<<ans<<endl;
  }
  else{
    cout<<":("<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int N,A[100010];
char C[200010];

int main(){
    cin >> N;
    for(int i=1;i<=N;i++){
        cin >> A[i];
    }
    int cnt = 0,id = 1,j = 1;
    while(id<=2*N){
        while(cnt<A[j]){
            C[id] = '(';
            id++;
            cnt++;
        }
        C[id] = ')';
        j++;
        id++;
    }
    int d = 0;
    stack<int> s;
    int lid = 1,rid = 1;
    for(int i=1;i<=2*N;i++){
        if(C[i]=='('){
            s.push(lid);
            lid++;
        }
        else{
            int a = s.top(); s.pop();
            if(a!=A[rid]){
                cout << ":(" << endl;
                return 0;
            }
            rid++;
        }
    }
    for(int i=1;i<=2*N;i++) cout << C[i];
    cout << endl;
    return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

string solve(const vector<int>& P) {
  string res = "";
  vector<int> stk;
  int sum = 0;
  for (int x : P) {
    while (sum < x) {
      res += '(';
      stk.push_back(++sum);
    }
    if (!stk.empty() && stk.back() == x) {
      stk.pop_back();
      res += ')';
    } else {
      return ":(";
    }
  }
  return res;
}

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N;
  while (cin >> N) {
    vector<int> P(N);
    for (int& x : P) cin >> x;
    cout << solve(P) << endl;
  }
  return 0;
}