Problem:
Parentheses
Dave loves strings consisting only of '(' and ')'. Especially, he is interested in balanced strings. Any balanced strings can be constructed using the following rules:
A string "()" is balanced.
Concatenation of two balanced strings are balanced.
If $T$ is a balanced string, concatenation of '(', $T$, and ')' in this order is balanced. For example, "()()" and "(()())" are balanced strings. ")(" and ")()(()" are not balanced strings.
Dave has a string consisting only of '(' and ')'. It satises the followings:
You can make it balanced by swapping adjacent characters exactly $A$ times.
For any non-negative integer $B$ ($B < A$), you cannot make it balanced by $B$ swaps of adjacent characters.
It is the shortest of all strings satisfying the above conditions.
Your task is to compute Dave's string. If there are multiple candidates, output the minimum in lexicographic order. As is the case with ASCII, '(' is less than ')'.
Input
The input consists of a single test case, which contains an integer $A$ ($1 \leq A \leq 10^9$).
Output
Output Dave's string in one line. If there are multiple candidates, output the minimum in lexicographic order.
Sample Input 1
1
Output for the Sample Input 1
)(
There are infinitely many strings which can be balanced by only one swap. Dave's string is the shortest of them.
Sample Input 2
4
Output for the Sample Input 2
)())((
String "))(()(" can be balanced by 4 swaps, but the output should be ")())((" because it is the minimum in lexicographic order.

Submitted solutions:

code_snippet: #include <random>
#include "bits/stdc++.h"
//#include <atcoder/all>

using namespace std;
// using namespace atcoder;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld eps = 1e-12;
constexpr int inf = numeric_limits<int>::max() / 2;
constexpr ll mod = 1e9 + 7;
mt19937_64 rnd{random_device()()};

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll a;
  cin >> a;
  auto generate = [](int n) {
    string s = "";
    for (int i = 0; i < n; i++) s += ')';
    for (int i = 0; i < n; i++) s += '(';
    return s;
  };
  string ans = "";
  for (ll i = 1; i <= a; i++) {
    ll sum = i * (i + 1) / 2;
    if (sum < a) continue;
    ans = generate(i);
    break;
  }
  ll x = ans.size() / 2;
  ll diff = x * (x + 1) / 2 - a;
  while (diff--) {
    int sz = ans.size();
    for (int i = 0; i < sz - 1; i++) {
      if (ans[i] == ')' && ans[i + 1] == '(') {
        swap(ans[i], ans[i + 1]);
        break;
      }
    }
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 390
memory_kb: 3584
final_rank: 6

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cassert>

using namespace std;

using lint = long long;
using ldouble = long double;

string rec(int A, int L) {
    if (L <= 0) {
        assert(A == 0);
        return "";
    }

    int D;
    for (D = 0; D * (D + 1) / 2 < A; ++D) {}

    string ret;
    for (int i = 0; i < L - D; ++i) ret += "()";
    return ret + ')' + rec(A - D, D - 1) + '(';
}

int main() {
    int A;
    cin >> A;
    int D;
    for (D = 1; D * (D + 1) / 2 < A; ++D) {}
    cout << ')' + rec(A - D, D - 1) + '(' << endl;
    return 0;
}
accuracy: 1
time_ms: 530
memory_kb: 8868
final_rank: 9

code_snippet: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

signed main(void) {
    int in;
    cin >> in;
    int n = 1;
    while(!((n-1)*n < 2*in && 2*in <= n*(n+1)))n++;
    string s = "";
    rep(i,n)s = ")" + s + "(";
    int t = n*(n+1)/2-in;
    swap(s[n], s[n-t]);
    cout << s << endl;
}
accuracy: 1
time_ms: 160
memory_kb: 3392
final_rank: 2

code_snippet: #include<iostream>

#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#define set(x,y) memset(x,y,sizeof(x))
#define scan(x) scanf("%d",&x)
#define For(x,y,z)  for(int x=y;x<=z;x++)
using namespace std;

const int MAXN = 100010;

int get(int n)
{
    int i=1;
    for( i=1;i<=100000;i++)
    {
        if(n<=((i+1)*i/2))
            return i;
    }
}
long long getmax(int n,int maxn)
{
    long long ans=0;
    for(int i=maxn-n+1;i<=maxn;i++)
        ans+=i;

    return ans;
}
int main()
{
    int n;
    cin>>n;
    int pairs=get(n);
   // cout<<pairs<<endl;
    long sumright=((pairs*2*(pairs*2+1))/2-pairs)/2+pairs;
    sumright-=n;//
    long sumleft=(pairs*2+1)*2*pairs/2-sumright;
   //cout<<sumleft<<endl;
              int cnt=0;
              bool a[MAXN];
           set(a,0);
    for(int i=1;i<=2*pairs;i++)
    {
        if(cnt==pairs)
            break;
        if((sumleft-i>i||(sumleft-i==0))&&((sumleft-i)<=getmax(pairs-cnt-1,2*pairs)))
        {
           // cout<<getmax(pairs-cnt-1,2*pairs)<<endl;
            cnt++;
            sumleft-=i;
            a[i]=1;
        }
    }
    for(int i=1;i<=2*pairs;i++)
        if(a[i])
        {
           cout<<'(';
        }
    else
        cout<<')';

    cout<<endl;
    //out(n);
    return 0;
}
accuracy: 0.024096385542168676
time_ms: 460
memory_kb: 3172
final_rank: 14

code_snippet: #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
void work(int n)
{
	n=(n+1)>>1;
	int tmp=n;
	while(tmp>=10)
	{
		tmp-=10;
		printf("))))))))))");
	}
	for(int i=1;i<=tmp;++i)
	printf(")");
	while(n>=10)
	{
		n-=10;
		printf("((((((((((");
	}
	for(int i=1;i<=n;++i)
	printf("(");
	printf("\n");
}
int main()
{
	int n;
	scanf("%d",&n);
	if(!(n&1))
	{
		printf(")(");n--;
	}
	
	work(n);
	return 0;
}
accuracy: 0.024096385542168676
time_ms: 1540
memory_kb: 3136
final_rank: 17

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

ll n;
string res;

int main(){
	cin.sync_with_stdio(false);
  cin>>n;
  ll sum=0;
  repl(i,1,n+1){
    ll nxt=i+1;
    if(nxt*(nxt+1)/2>n){
      n-=i*(i+1)/2;
      string tmp;
      rep(j,i)tmp='('+tmp;
      rep(j,i)tmp=')'+tmp;
      if(n>0){
        res=")"+tmp.substr(0,n-1)+"("+tmp.substr(n-1,tmp.size()-n+1);
      }else res=tmp;
      break;
    }
  }
  cout<<res<<endl;
  return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 3372
final_rank: 1

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

ll n;
string res;

int main(){
	cin.sync_with_stdio(false);
  cin>>n;
  while(n>0){
    repl(i,1,n+1){
      ll nxt=i+1;
      if(nxt*(nxt+1)/2>n){
        n-=i*(i+1)/2;
        rep(j,i)res='('+res;
        rep(j,i)res=')'+res;
        break;
      }
    }
  }
  cout<<res<<endl;
	return 0;
}
accuracy: 0.024096385542168676
time_ms: 110
memory_kb: 3288
final_rank: 11

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

#define N 100010

using namespace std;

const int inf = 0x3f3f3f3f;
map<int,int>Map;
int a[N],k;
char s[N];
int main()
{
    int n,x = 0;
    for( k = 1; x <= 1000000000; k++)
    {
        x += k;
        Map[x] = k;
        a[k] = x;
    }
    scanf("%d",&n);
    if(Map.find(n) != Map.end())
    {
        for(int i = 1; i <= Map[n]; i++)
            printf(")");
        for(int i = 1; i <= Map[n]; i++)
            printf("(");
        printf("\n");
    }
    else
    {
        int x = n;
        while(Map.find(x) == Map.end())x++;
        int l = x;
        x = Map[x];
        n = l - n;
        for(int i = 1; i <= 2*x; i++)
            if(i <= x)s[i] = ')';
            else s[i] = '(';
        s[x*2+1] = '\0';
        while(n --)
        {
            swap(s[x],s[x+1]);
            x--;
        }
        puts(s+1);
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5508
final_rank: 7

code_snippet: #include <iostream>
#include <string>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
int a,i,p;
int main() {
    cin >> a;
    while (p < a){
        i++;
        p += i;
    }
    string s;
    REP(j,i) s = s + ')';
    REP(j,i) s = s + '(';
    swap(s[i], s[i-p+a]);
    cout << s << endl;
    return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 3400
final_rank: 3

code_snippet: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int a;
    cin >> a;
    int i = 0, p = 0;
    while (p < a){
        i++;
        p += i;
    }
    string ans;
    REP(j,i) ans = ans + ')';
    REP(j,i) ans = ans + '(';
    int j = i - (p - a);
    swap(ans[i], ans[j]);
    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 3400
final_rank: 3

code_snippet: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int a;
    cin >> a;
    VI x;
    int p = 0;
    for (int i = 1; p <= a; i++){
        p += i;
        x.push_back(p);
    }
    string ans;
    while (a){
        int i = 0;
        while (i < x.size()-1 && x[i+1] <= a) i++;
        a -= x[i];
        REP(j,i+1) ans = "(" + ans;
        REP(j,i+1) ans = ")" + ans;
    }
    cout << ans << endl;

    return 0;
}
accuracy: 0.024096385542168676
time_ms: 120
memory_kb: 3276
final_rank: 12

code_snippet: #include <iostream>
#include <string>
using namespace std;
using ll = long long;

int main() {
    ll A;
    cin >> A;
    ll i = 1;
    while((i + 1) * i / 2 < A) {
        ++i;
    }
    string res = "()";
    for(int j=0; j<i-1; ++j) {
        res += ')';
    }
    for(int j=0; j<i-1; ++j) {
        res += '(';
    }
    A -= i * (i-1) / 2;
    for(int j=0; j<A; ++j) {
        for(int k=0; k<res.size()-1; ++k) {
            if(res[k] == '(' && res[k+1] == ')') {
                swap(res[k], res[k+1]);
                break;
            }
        }
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 770
memory_kb: 3316
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define  mx 10000000
#define m 44722

int ar[m+5],num;


int main()
{
    int val = 0,in=0;
    for(int i=1;i<mx;i++){

        //if(in>44715) cout<<val<<" "<<in<<endl;
        val+=i;
        if(in==44721+1) break;
        ar[++in] = val;

    }
    //cout<<in<<" "<<ar[in];
    scanf("%d",&num);

    if(num==1){
        cout<<")("<<endl;
        return 0;
    }
    else if(num==2){
        cout<<")()("<<endl;
        return 0;
    }
    else if(num==3){
        cout<<"))(("<<endl;
        return 0;
    }

    int idx;
    for(int i=1;i<=m;i++){
        if(num<=ar[i]){
            idx = i;
            break;
        }
    }
    //cout<<idx<<endl;
    int n = idx;

    char x[idx*2+5];

    for(int i=1;i<=idx*2;i++){
        if(i%2==0) x[i] = '(';
        else x[i] = ')';
        //printf("%c",x[i]);
    }
    //cout<<endl;

    int hi = idx*2;
    int lo = 1;

    for(int i=1;i<=num;i++){

        lo++;
        hi--;
        int l=lo,h=hi;
        int loop = hi-lo+1;
        //cout<<loop<<endl;
        for(int j=1;j<=loop/2;j++){

            swap(x[h],x[h-1]);
            n++;
            if(n==num){
                for(int k=1;k<=idx*2;k++) printf("%c",x[k]);
                cout<<endl;
                return 0;
            }
            h-=2;
        }
        /*if(hi-lo==1){
            for(int k=1;k<=idx*2;k++) printf("%c",x[k]);
            cout<<endl;
            return 0;
        }*/
    }

    return 0;
}
accuracy: 0.024096385542168676
time_ms: 610
memory_kb: 3308
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define  mx 10000000
#define m 44722

int ar[m+5],num;

int srch(int i,int j)
{
    if(j-i==1){
        if(ar[i]==num) return i;
        else return j;
    }
    int mid = (i+j)/2;
    if(ar[mid]==num) return mid;

    if(num>ar[mid]) srch(mid,j);
    else if(num<ar[mid]) srch(i,mid);
}
int main()
{
    int val = 0,in=0;
    for(int i=1;i<mx;i++){

        //if(in>44715) cout<<val<<endl;
        val+=i;
        if(in==44721+1) break;
        ar[++in] = val;

    }
    //cout<<in<<" "<<ar[in];
    scanf("%d",&num);

    if(num==1){
        cout<<")("<<endl;
        return 0;
    }
    else if(num==2){
        cout<<")()("<<endl;
        return 0;
    }
    else if(num==3){
        cout<<"))(("<<endl;
        return 0;
    }

    int idx = srch(1,m);

    int n = idx;

    char x[idx*2+5];

    for(int i=1;i<=idx*2;i++){
        if(i%2==0) x[i] = '(';
        else x[i] = ')';
    }

    int hi = idx*2;
    int lo = 1;

    for(int i=1;i<=num;i++){

        lo++;
        hi--;
        int l=lo,h=hi;
        int loop = hi-lo+1;
        //cout<<loop<<endl;
        for(int j=1;j<=loop/2;j++){

            swap(x[h],x[h-1]);
            n++;
            if(n==num){
                for(int k=1;k<=idx*2;k++) printf("%c",x[k]);
                cout<<endl;
                return 0;
            }
            h-=2;
        }
        if(hi-lo==1){
            for(int k=1;k<=idx*2;k++) printf("%c",x[k]);
            cout<<endl;
            return 0;
        }
    }

    return 0;
}
accuracy: 0.024096385542168676
time_ms: 670
memory_kb: 3340
final_rank: 16

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

string s;

int main()
{

    long long i,j,k,l,m,n,o,p;

    char sf[10005],sb[10005];
    for(i=0;i<10000;i++)
    {
        sf[i]='(';
        sb[i]=')';
    }
    sf[10000]='\0';
    sb[10000]='\0';

    cin>>n;

    if(n==1)
    {
        printf(")(\n");
        return 0;
    }

    int number=(n/3);

    if(n%3!=0)
        number++;

    long long lim=number*3;
    long long check=lim-n;

    number++;

    if(check==1)
    {
        for(i=0; i<number-1; i++)
            {
                if(i+10000<number-1)
                    {printf("%s",sb);i+=10000;}
                else
                printf(")");
            }
        printf("()");
        for(i=0; i<number-1; i++)
            {
                 if(i+10000<number-1)
                    {printf("%s",sf);i+=10000;}
                else
                printf("(");

            }
            //printf("(");

            printf("\n");
    }

    else if(check==0)
    {
        for(i=0; i<number; i++)
            if(i+10000<number-1)
                    {printf("%s",sb);i+=10000;}
                else
                printf(")");
//printf("()");
        for(i=0; i<number; i++)
            if(i+10000<number-1)
                    {printf("%s",sf);i+=10000;}
                else
                printf("(");

             printf("\n");
    }
    else if(check==2)
    {
        for(i=0; i<number-2; i++)
            if(i+10000<number-1)
                    {printf("%s",sb);i+=10000;}
                else
                printf(")");
        printf("())");
        for(i=0; i<number-1; i++)
               if(i+10000<number-1)
                    {printf("%s",sf);i+=10000;}
                else
                printf("(");
             printf("\n");
    }

    return 0;
}
accuracy: 0.024096385542168676
time_ms: 420
memory_kb: 3308
final_rank: 13

code_snippet: //#include <bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<deque>
#include<functional>
#include<string>
#include<iostream>
#include<cctype>
#include<set>
#include<climits>
#include<iomanip>
#include<cassert>
#include<sstream>

#define pb push_back
#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x) if(x>=mod) x-=mod;if(x<0) x+=mod;
#define MOD(x,y) (((x)*(y))%mod)
#define ODD(x) (((x)&1)==0?(0):(1))
#define Set(N,cur) N=(N|(1LL<<cur))
#define Reset(N,cur) N=(N&(~(1LL<<cur)))
#define Check(N,cur) (!((N&(1LL<<cur))==0))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)

using namespace std;


#define LL long long
#define LLU long long unsigned int
typedef long long vlong;
typedef unsigned long long uvlong;
typedef pair < int, int > pii;
typedef pair < vlong, vlong > pll;
typedef vector<int> vi;
typedef vector<vlong> vl;
typedef vector<pll> vll;

#ifdef forthright48
     #include <ctime>
     clock_t tStart = clock();
     #define debug(args...) {dbg,args; cerr<<endl;}
     #define timeStamp debug ("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)
     #define bug printf("%d\n",__LINE__);

#else
    #define debug(args...)  // Just strip off all debug tokens
    #define timeStamp
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;

inline vlong gcd ( vlong a, vlong b ) {
    a = ABS ( a ); b = ABS ( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;
}

vlong ext_gcd ( vlong A, vlong B, vlong *X, vlong *Y ){
    vlong x2, y2, x1, y1, x, y, r2, r1, q, r;
    x2 = 1; y2 = 0;
    x1 = 0; y1 = 1;
    for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) {
        q = r2 / r1;
        r = r2 % r1;
        x = x2 - (q * x1);
        y = y2 - (q * y1);
    }
    *X = x2; *Y = y2;
    return r2;
}

inline vlong modInv ( vlong a, vlong m ) {
    vlong x, y;
    ext_gcd( a, m, &x, &y );
    x %= m;
    if ( x < 0 ) x += m;
    return x;
}

inline vlong power ( vlong a, vlong p ) {
    vlong res = 1, x = a;
    while ( p ) {
        if ( p & 1 ) res = ( res * x );
        x = ( x * x ); p >>= 1;
    }
    return res;
}

inline vlong bigmod ( vlong a, vlong p, vlong m ) {
    vlong res = 1 % m, x = a % m;
    while ( p ) {
        if ( p & 1 ) res = ( res * x ) % m;
        x = ( x * x ) % m; p >>= 1;
    }
    return res;
}


//int knightDir[8][2] = { {-2,1},{-1,2},{1,2},{2,1},{2,-1},{-1,-2},{1,-2},{-2,-1} };
//int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
//int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1},{-1,-1},{1,1},{1,-1},{-1,1}};
const vlong inf = 2147383647;
const vlong mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-9;

///======================  TEMPLATE ENDS HERE  =====================///


/** WARNING WARNING WARNING **/
//  1. Simulate Sample Test Case Before Coding
//  2. Read Input & Output Format Before Coding
//  3. Check Corner Case Specially When N<3
//  4. Check Array Size, Mod Value & Long Long
//  5. Check DP1 Memoization Part & Call Parameters
//  6. Check Problem No When Submitting



int main () {
    #ifdef forthright48
    //freopen ( "Ainput.txt", "r", stdin );
    //freopen ( "output.txt", "w", stdout );
    #endif // forthright48

    //while(1){
        vlong n;
        scanf ( "%lld", &n );

        string s = "";

        vlong now = 1;
        while (n > 0) {

            //debug(n, s);

            if (now >= n) {
                vlong cur = now;
                while (cur > n) {
                    s = ')' + s;
                    cur--;
                }
                s = '(' + s;
                while (cur > 0) {
                    s = ')' + s;
                    cur--;
                }
                n = 0;
            }

            else {
                s = '(' + s;
                n -= now;
            }

            now++;

        }

        printf("%s\n", s.c_str());


    //}


    return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 3408
final_rank: 5

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

using namespace std;

#define pb push_back
#define ll unsigned long long
#define pii pair<int,int>
#define uu first
#define vv second
#define INF 1000000000
#define V 38

bool used[100000001];
vector<int>v;

int pow10(int n)
{
    int prod = 1;
    while(n--)prod*=10;
    return prod;
}

void rec(int koto,int konta,int hmm)
{
    if(koto==0)
    {
        v.pb(hmm);
        return ;
    }
    if(konta==10)return;
    //for(int i=konta;i<=9;i++)
    rec(koto-1,konta+1,hmm+(konta)*pow10(koto-1));
}
bool is(int n)
{
    int y = sqrt(n);
    for(int i=1;i<=y;i++)
    {
        if(n%i==0 and used[i])
        {
            int  r = n/i;
            if(r!=i and used[r])return 1;
        }
    }
    return 0;
}

int main()
{
    //cout<<num(122345678)<<endl;
    int n;
    cin>>n;
    if(n&1)
    {
        if(n==1)
        {
            cout<<")(\n";
            return 0;
        }
        int m = (n-3)/2;
        cout<<"))";
        char ch[3]="()";
        if(m<1000000)while(m--)cout<<ch;
        else
        {
            char ch[11] = "()()()()()";
            int r = m/5;
            while(r--)cout<<ch;
            r = m%5;
            while(r--)cout<<"()";
        }
        cout<<"((\n";
    }
    else
    {
        cout<<")(";
        n--;
        if(n==1)
        {
            cout<<")(";
            return 0;
        }
        int m = (n-3)/2;
        cout<<"))";
        char ch[3]="()";
        if(m<1000000)while(m--)cout<<ch;
        else
        {
            char ch[11] = "()()()()()";
            int r = m/5;
            while(r--)cout<<ch;
            r = m%5;
            while(r--)cout<<"()";
        }
        cout<<"((\n";
    }
}
accuracy: 0.024096385542168676
time_ms: 1750
memory_kb: 3036
final_rank: 18

code_snippet: #include <bits/stdc++.h>
#define int long long
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define DEBUG(x) cerr << #x << " " << x << endl
using namespace std;
 
int magic(int A) {
  for(int k = 0; ; ++k) {
    if(A <= k * (k + 1) / 2) return k;
  }
  return -1;
}
 
string paren(int a, int n) {
  // DEBUG(a);
  // DEBUG(n);
  if(a == n * (n + 1) / 2) {
    string ret;
    REP(i,n) ret += ")";
    REP(i,n) ret += "(";
    return ret;
  }
  else {
    int rem = a - n;
    int k = magic(rem);
    string ret = ")";
    for(int i = 0; i < n - 1 - k; ++i) ret += "()";
    ret += paren(rem, k);
    ret += "(";
    return ret;
  }
}
 
signed main() {
  int A; cin >> A;
  int k = magic(A);
  cout << paren(A, k) << endl;
}
accuracy: 1
time_ms: 520
memory_kb: 9632
final_rank: 10