akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define endl            "\n"
#define ll              long long
#define ld              long double 
#define ull             unsigned long long int
#define MOD             (ll)(1e9 + 7)
#define vll             vector<ll>
#define pll             pair<ll,ll>
#define mll             map<ll,ll>
#define vpll            vector<pair<ll,ll>>
#define mpll            map<pair<ll,ll>,ll>
#define len(x)          x.length()
#define all(x)          x.begin(),x.end()
#define deb1(x)         cout<<#x<<" "<<x<<endl;
#define deb2(x,y)       cout<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<endl;
#define deb3(x,y,z)     cout<<#x<<" "<<x<<"\t"<<#y<<" "<<y<<"\t"<<#z<<" "<<z<<endl;
#define fr(a,b,c)       for(auto a=b;a<c;a++)
#define frc(a,b,c)      for(auto a=b;a!=c;a++)
#define pb(x)           push_back(x)
#define lb(v,x)         lower_bound(v.begin(), v.end(), x)
#define ub(v,x)         upper_bound(v.begin(), v.end(), x)
#define GR              (double)(1 + sqrt(5)) / 2
#define fib(n)          (ll)round(pow(GR,n) / sqrt(5))
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define out1(x)         cout<<x<<" "<<endl
#define out2(x,y)       cout<<x<<" "<<y<<endl
#define ARRAY(a,n)      vll a; fr(i,0,n) { ll temp; cin>>temp; a.pb(temp); }  
#define PRINT(a)        for(auto x:a)cout<<x<<" ";cout<<endl
#define MAX             100005
template<typename T>
void output_vector(const vector<T> &v, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());
 
    for (int i = start; i < end; i++)
        cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}


void solve(){
    int n,k;cin>>n>>k;int a[n+1];
    fr(i,1,n+1)cin>>a[i];
    int dp[n+1]={0};
    dp[n-1]=abs(a[n-1]-a[n]);
    for(int i=n-2;i>=1;i--){
        dp[i]=INT_MAX;
        for(int w=1;w<=k;w++){
            if(i+w<=n){
                int x=abs(a[i]-a[i+w])+dp[i+w];
                dp[i]=min(dp[i],x);
            }
        }
    }
    out1(dp[1]);
}

int main()
{   

    // FIO;
    // ll test;cin>>test;
    // while(test--)
    solve();
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<assert.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int n,a[100100],b[5],m;
vector<pair<string,int> >ask;
string s[100100],ans="";

int work(string s,string t)
{
    rep(i,0,1) rep(j,0,1)
        if (s[i]==t[j]) return (s[i]-'A');
}

int main()
{
    n=read();
    rep(i,0,2) a[i]=read();
    rep(i,1,n) cin >> s[i];
    int c=1;
    //cout << work("BC","AB") << endl;
    rep(i,1,n)
    {
        if ((i==n) || (s[i]!=s[i+1]))
        {
            ask.pb(mkp(s[i],c));
            c=1;
        }
        else c++;
    }
    m=ask.size();
    int now=0;
    rep(i,0,m-1)
    {
        string op=ask[i].fir;int c=ask[i].sec;
        assert(c>0);now+=c;
        int x=op[0]-'A',y=op[1]-'A';
        if ((!a[x]) && (!a[y]))
        {
            puts("No");
            return 0;
        }
        if (a[x]<a[y]) swap(x,y);
        //cout << x << " " << y << endl;
        rep(j,1,c)
            if (j&1) ans=ans+(char)('A'+y);else ans=ans+(char)('A'+x);
        if (c&1) {a[x]--;a[y]++;}
        if (i+1<m)
        {
            string nxtop=ask[i+1].fir;
            int p=work(nxtop,op),q=x+y-p,r=3-x-y;
            if ((!a[r]) && (!a[p]))
            {
                //cout << 'a' << endl;
                int tmp=now-1;
                while (ans[tmp]==('A'+p)) tmp--;
                a[p]++;a[q]--;
                ans[tmp]=(char)('A'+p);
                a[p]++;a[q]--;
                if (a[q]<0) {puts("No");return 0;}
            }
        }
    }
    puts("Yes");
    rep(i,0,n-1) {putchar(ans[i]);puts("");}
    return 0;
}
        

Measured memory_bytes: 11652
n=int(input())
count = 0
if n == 0:
  print(0)
elif n == 1:
  print(1)
elif n >= 10 and n <100:
  count = count + 1
  n = n%10
  if n == 1:
    count = count + 1
  print(count)
elif n >= 100:
  count = count + 1
  n = n%100
  if n >= 10:
    count = count + 1
    n = n%10
    if n == 1:
      count = count + 1
  else :
    if n ==1:
      count = count + 1
  print(count)


Measured memory_bytes: 3060
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,k = MAP()
s = input()
unhappy=0
if s[0]=="L":
    unhappy+=1
if s[n-1]=="R":
    unhappy+=1

for i in range(n-1):
    if s[i:i+2]=="RL":
        unhappy+=2
print(n-max(1,unhappy-(2*k)))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
using pr = tuple<string, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;
const int INF = 100000000;
// " ", ' '

// プロトタイプ宣言
// int myfunc(int, vvec);

// グローバル変数
// int N, M;
// vvec data(N, vec(M));

// 関数：

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N; cin >> N;
	string s; int p;
	vector<pair<pair<string, int>, int>> ps(N);
	for (int i=0; i<N; i++) {
		cin >> s >> p;
		ps.at(i).first = make_pair(s, -p);
		ps.at(i).second = i;
	}

	sort(ps.begin(), ps.end());

	for (int i=0; i<N; i++) {
		cout << ps.at(i).second+1 << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  if (a == b && b == c) { cout << 1; }
  else if (a != b && b != c && c != a ) { cout << 3; }
  else { cout << 2; }
  return 0;
} 

Measured memory_bytes: 764
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define chmin(x,y) x = min(x, y)
#define chmax(x,y) x = max(x, y)
vector<int> dx = {-1, 1,  0, 0};
vector<int> dy = { 0, 0, -1, 1};

const int INF = 1e9;

int main () {
    int h, w; cin >> h >> w;
    vector<vector<char>> a(h, vector<char> (w));
    vector<vector<int>> num(h, vector<int> (w, INF));
    queue<P> que;
    rep(y, h) rep(x, w) {
        cin >> a[y][x];
        if (a[y][x] == '#') {
            que.push({x, y});
            num[y][x] = 0;
        }
    }

    while (!que.empty()) {
        P p = que.front(); que.pop();
        int x = p.first, y = p.second;
        rep(i, 4) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
            if (num[ny][nx] != INF) continue;
            if (a[ny][nx] == '#') continue;
            a[ny][nx] = '#';
            num[ny][nx] = num[y][x] + 1;
            que.push({nx, ny});
        }
    }
    int ans = 0;
    rep(y, h) rep(x, w) chmax(ans, num[y][x]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 16240
#!/usr/bin/env python3

from math import *
from itertools import *
from collections import *
from bisect import *


if __name__ == '__main__':
    n,m = map(int, input().split())

    if n == 1:
        if m == 1:
            print(1)
        else:
            print(m-2)
    elif m == 1:
        print(n-2)
    else:
        center = n*m - 2*n - 2*m + 4
        print(center)



Measured memory_bytes: 3316
import sys
range = xrange
input = lambda: sys.stdin.readline().rstrip()

h,w = [int(x) for x in input().split()]
A = [list(input()) for _ in range(h)]

found = [False]*(w*h)

cur = []
for y in range(h):
    for x in range(w):
        if A[y][x]=='#':
            cur.append(y*w+x)
            found[y*w+x]=True


counter = 0
while cur:
    counter += 1
    tmp = []
    
    while cur:
        ind = cur.pop()
        y,x = divmod(ind,w)

        if 0<=x-1 and not found[ind-1]:
            tmp.append(ind-1)
            found[ind-1] = True
        if x+1<w and not found[ind+1]:
            tmp.append(ind+1)
            found[ind+1] = True

        if 0<=y-1 and not found[ind - w]:
            tmp.append(ind - w)
            found[ind-w] = True
    
        if y+1<h and not found[ind + w]:
            tmp.append(ind + w)
            found[ind+w] = True
    cur = tmp

print counter-1

Measured memory_bytes: 129192
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int X, Y, Z, K;
vector<ll> A, B, C;

void solve1() {
    vector<ll> E(X*Y);
    int e = 0;
    for (int i = 0; i < X; i++) {
        for (int j = 0; j < Y; j++) {
            E[e++] = A[i] + B[j];
        }
    }
    sort(E.begin(), E.end(), greater<ll>());
    int lim = min((int)E.size(), K);
    vector<ll> EC(lim*Z);
    int ec = 0;
    for (int i = 0; i < lim; i++) {
        for (int j = 0; j < Z; j++) {
            EC[ec++] = E[i] + C[j];
        }
    }
    sort(EC.begin(), EC.end(), greater<ll>());
    for (int i = 0; i < K; i++) {
        cout << EC[i] << endl;
    }
}

void solve1a() {
    if (X > K) {
        sort(A.begin(), A.end(), greater<ll>());
    }
    if (Y > K) {
        sort(B.begin(), B.end(), greater<ll>());
    }
    int lim_a = min(K, X);
    int lim_b = min(K, Y);
    vector<ll> E(lim_a * lim_b);
    int e = 0;
    for (int i = 0; i < lim_a; i++) {
        for (int j = 0; j < lim_b; j++) {
            E[e++] = A[i] + B[j];
        }
    }
    sort(E.begin(), E.end(), greater<ll>());
    int lim_e = min((int)E.size(), K);
    vector<ll> EC(lim_e*Z);
    int ec = 0;
    for (int i = 0; i < lim_e; i++) {
        for (int j = 0; j < Z; j++) {
            EC[ec++] = E[i] + C[j];
        }
    }
    sort(EC.begin(), EC.end(), greater<ll>());
    for (int i = 0; i < K; i++) {
        cout << EC[i] << endl;
    }

}

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    
    cin >> X >> Y >> Z >> K;
    A.resize(X); for (auto& a : A) cin >> a;
    B.resize(Y); for (auto& b : B) cin >> b;
    C.resize(Z); for (auto& c : C) cin >> c;

    solve1a();
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

ll p[11];
ll d,g;
ll c[11];
ll sum = 0;
int ans = INF;
int rest_max = INF;

int main(){
  cin >> d >> g;
  REP(i,d) cin >> p[i] >> c[i];
  REP(mask, 1<<d){
    ll s = 0;
    int num = 0;
    int rest_max = 0;
    REP(i,d){
      if(mask >> i & 1){
        s += 100*(i+1)*p[i]+c[i];
        num += p[i];
      }else{
        rest_max = i;
      }
    }
    if(g>s){
      ll ps = 100*(rest_max+1);
      int need = (g-s+ps-1)/ps;
      if(need>p[rest_max]) continue;
      num+=need;
    }
    ans = min(ans,num);
  }
  cout << ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    int n,m;cin>>n>>m;
    vin a(m+1);
    rep(i,m)cin>>a[i];
    a[m]=n+1;
    if(m>1){
        rep(i,m-1){
            if(a[i+1]-a[i]==1){
                cout<<0<<endl;
                return 0;
            }
        }
    }
    vll dp(n+1);//dp[i]:i段目までの行き方。壊われた階段は考慮しない。
    dp[0]=1;
    dp[1]=1;
    rep(i,n-1){
        dp[i+2]=dp[i+1]%inf+dp[i]%inf;
        dp[i+2]%=inf;
    }
    ll sum=dp[a[0]-1];
    rep(i,m){
        sum*=dp[a[i+1]-a[i]-2];
        sum%=inf;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    while(true){
      cin >> n;
      if(n == 0) return 0;
      string s[n];
      rep(i,n) cin >> s[i];
      string ans[n];
      vector<bool> flag(n+10,false);
      for(ll i = n-1; i >= 0; i --){
        int lv = 0;
        rep(j,s[i].size()){
          if(s[i][j] == '.') lv++;
          else break;
        }
        if(lv != 0)FOR(j,lv-1,n) flag[j] = false;
        rep(j,lv){
          if(j == lv-1){
            ans[i] += '+';
            flag[j] = true;
          }
          else if(flag[j]){
            ans[i]+= '|';
          }else{
            ans[i] += ' ';
          }
        }
        ans[i] += s[i].substr(lv);
      }
      rep(i,n){
        cout << ans[i] << endl;
      }
    }

    return 0;
}



Measured memory_bytes: 4224
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int n,i,j,tmp;
	int f[2][101],a[2][101];
	scanf("%d",&n);
	for(i=0;i<2;i++)
	{
		for(j=0;j<n;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<2;i++)
	{
		for(j=0;j<n;j++)
		{
			tmp=0;
			if(i==1)
			{
				tmp=max(tmp,f[i-1][j]);
			}
			if(j>0)
			{
				tmp=max(tmp,f[i][j-1]);
			} 
			f[i][j]=a[i][j]+tmp;
		}
	}
	printf("%d\n",f[1][n-1]);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include <algorithm>
#include <queue>
#include <climits>
#include<cmath>
#include <sstream>
#include <iomanip>

bool sort_pair( std::pair< int64_t, std::string > origin, std::pair< int64_t, std::string > another )
{
    return origin.first < another.first;
}


int main()
{

    int a;
    
    std::cin>> a;

    std::vector< int > b( a, 0 );

    for( int i = 0; i < a; i++ )
    {
        std::cin>> b[i];
    }

    std::sort( b.begin(), b.end() );

    int c = a / 2 - 1;
    int d = a / 2;
    int answer = 0;

    if( b[c] != b[d] )
    {
        answer = b[d] - b[c];
    }
    
    std::cout<< answer;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
int main(){
long h,w,a[101][101],f,i,j;
string s[101];
for(;;){
cin>>h>>w;
if(h==0)break;
for(i=0;i<h;i++)cin>>s[i];
for(i=0;i<h;i++)
for(j=0;j<w;j++)a[i][j]=0;
i=j=0;
a[i][j]=1;
for(;;){
if(s[i][j]=='>')j++;
else if(s[i][j]=='<')j--;
else if(s[i][j]=='^')i--;
else if(s[i][j]=='v')i++;
else{f=0;break;}
if(a[i][j]==1){f=1;break;}
a[i][j]=1;
}
if(f==0)cout<<j<<" "<<i<<endl;
else cout<<"LOOP"<<endl;
}
return 0;
}

Measured memory_bytes: 1308
#include<iostream>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
    if (b == 0)
        return a;
    else
        return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a / g * b;
}


int main() {
    int N;
    cin >> N;
    ll ans = 1LL;
    ll T[110];
    for (int i = 0; i < N; ++i) {
        cin >> T[i];
        ans =lcm(ans, T[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
edge=[]
branch=[[] for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    edge.append((a-1,b-1,c))
    branch[a-1].append((b-1,c))
    branch[b-1].append((a-1,c))

dist=[]
def makedist(start,branch):
    check={start,}
    mind=[10**7 for i in range(n)]
    mind[start]=0
    while len(check)>0:
        now=check.pop()
        for k in branch[now]:
            if k[1]+mind[now]<mind[k[0]]:
                mind[k[0]]=k[1]+mind[now]
                check|={k[0],}
    return mind
for i in range(n):
    dist.append(makedist(i,branch))
ans=0
for k in edge:
    for s in range(n):
        if abs(dist[s][k[0]]-dist[s][k[1]])==k[2]:
            ans+=1
            break
print(m-ans)

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(){
    string Sa,Sb,Sc;
    cin >> Sa >> Sb >> Sc;
    string *s = &Sa;
    bool end = false;

    while (true){
        switch (*s->c_str()){
        case 'a': s->erase(0,1); s=&Sa; break;
        case 'b': s->erase(0,1); s=&Sb; break;
        case 'c': s->erase(0,1); s=&Sc; break;
        default:
            if (s == &Sa) {printf("A"); end = true; break;}
            else if (s == &Sb) {printf("B"); end = true; break;}
            else if (s == &Sc) {printf("C"); end = true; break;}
        }
        if(end) break;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
  while (1) {
    string s;
    cin >> s;
    if (s == "-") break;
    int n;
    cin >> n;
    while (n) {
      n--;
      int h;
      cin >> h;
      string b1 = s.substr(0, h);
      string b2 = s.substr(h);
      s = b2 + b1;
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(ReadLine());
        int[] names = new int[5];
        char[] MARCH = new char[5]{ 'M', 'A', 'R', 'C', 'H' };
        for(int i = 0; i < N; i++)
        {
            string s = ReadLine();
            for(int j = 0; j < 5; j++)
            {
                if (s[0] == MARCH[j])
                    names[j]++;
            }
        }

        long ans = 0;

        for(int i = 0; i < 3; i++)
        {
            for(int j = i + 1; j < 4; j++)
            {
                for(int k = j + 1; k < 5; k++)
                {
                    ans += (long)names[i] * names[j] * names[k];
                }
            }
        }
        WriteLine(ans);
    }
}

Measured memory_bytes: 15188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
int main()
{
	int n,m;cin>>n>>m;
	map<int,int> mp;
	mp[3]=100000;mp[2]=200000;mp[1]=300000;
	if(n==1&&m==1) cout<<mp[n]+mp[m]+400000<<endl;
	else cout<<mp[n]+mp[m]<<endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, A):
    for i, a in enumerate(A):
        if a == 1:
            break

    l = A[:i]
    r = A[i+1:]
    ans = math.ceil((len(l)+len(r)) / (K-1))


    return ans


def main():
    N, K = read_int_n()
    A = read_int_n()
    print(slv(N, K, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 16208
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    int n;cin>>n;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    int M = *max_element(all(v));
    int cnt = 0;
    rep(i,n){
        if(M==v[i])cnt++;
    }
    if(cnt > 1){
        rep(i,n){
            cout << M << endl;
        }
    }else{
        rep(i,n){
            if(v[i]==M){
                int ans = 0;
                rep(j,n){
                    if(j==i)continue;
                    ans = max(ans,v[j]);
                }
                cout << ans << endl;
            }else{
                cout << M << endl;
            }
        }
    }
}



Measured memory_bytes: 2432
use std::io;


/// https://beta.atcoder.jp/contests/arc070/tasks/arc070_a
/// (1..t) の部分和からXが生成できるときの最小のt
fn main() {
    let x = read_one::<usize>();
    let mut ans = 0;
    for i in 1.. {
        if (i * (i + 1) / 2) >= x { ans = i; break; }
    }
    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(){
    static const int INF = 1e9 + 7;
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(auto&& i : a){
        cin >> i;
    }
    long long ans = 0;
    for(int i = 0; i < n; i++){
        long long left = 0, right = 0;
        for(int j = 0; j < i; j++){
            left += a[j] < a[i];
        }
        for(int j = i + 1; j < n; j++){
            right += a[j] < a[i];
        }
        unsigned long long add = (left + right);
        add *= (k - 1);
        add %= INF;
        add *= k;
        add %= INF;
        add *= modinv(2, INF);
        add %= INF;
        add += right * k;
        ans += add;
        ans %= INF;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll h,w,n;cin>>h>>w>>n;
    swap(h,w);
    vp v(n);
    rep(i,n)cin>>v[i].se>>v[i].fi;
    rep(i,n){
        v[i].fi--;v[i].se--;
    }
    sort(all(v));
    vi ma(h);
    ma[0]=0;
    REP(i,1,h){
        ma[i]=ma[i-1]+1;
        while(binary_search(all(v),P(i,ma[i])))ma[i]++;
    }
    ll ans=w;
    vvi s(h);
    rep(i,n)s[v[i].fi].pb(v[i].se);
    rep(i,h){
        int k=lb(s[i],ma[i]+1);
        if(k!=s[i].size())chmin(ans,s[i][k]);
    }
    out(ans);
}

Measured memory_bytes: 13824
#include<iostream>
#define ll long long
using namespace std;
int main(){
    ll x,y;
    cin>>x>>y;
    ll ans=0;
   if(x+y==0)ans++;
   else if(y-x>=0){
        if(y*x<0)ans=min(abs(x+y),abs(x-y))+1;
        else ans=y-x;
   }
   else {
        ans=min(abs(x+y),abs(x-y))+1;
        if(x*y>0)ans++;
   }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  
  int N;
  scanf("%d", &N );
  
  int A;
  int k = 0;
  int i;
  int ans = 1;
  int num = 0;
  
  for( i = 0; i < N; i++ ){
    scanf("%d", &A);
    num++;
    if( A % 2 ) k++;
    
  }
  
  if( (k % 2) && num != 1 ) ans = 0;
  
  
  if( ans )puts("YES");
  else{ puts("NO");}
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;

int main() {
  int X,N;
  cin>>X>>N;
  vector<int>vec(N+1);
  for(int i=0;i<N;i++){cin>>vec.at(i);}
  vec.at(N)=130;
for(int u=0;u<N;u++){for(int v=u+1;v<N;v++){if(vec.at(u)==vec.at(v)){
  vec.at(v)=120;
  }}}
     sort(vec.begin(),vec.end());
  int p,q=0;
  for(int j=0;j<N;j++){if(X!=vec.at(j)){p++;}
                else{q=j;
             break; }  }
  if(p==N){cout<<X<<endl;}
  else{
    for(int k=0;k<N;k++){if(q-k-1>=0 && q+k+1<N+1){
  if(vec.at(q-k-1)!=X-k-1){cout<<X-k-1<<endl;
                          break;}
      else if(vec.at(q+k+1)!=X+k+1){cout<<X+k+1<<endl;
                          break;}
      else if(q-k-1==0 && vec.at(q+k+1)!=120){cout<<X-k-2<<endl;
                 break;}
      else if(vec.at(q+k+1)==120){cout<<X+k+2<<endl;
      break;}}
      else if(q==0){cout<<vec.at(0)-1<<endl;
                   break;}

  }}
  }




Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define int 		long long
#define vi 			vector<int>
#define vec(x) 		vector<x>
#define matrix 		vector<vector<int>>
#define pii 		pair<int,int>
#define rep(i,s,e)  for(int i=s;i<e;i++)
#define rrep(i,e,s) for(int i=e;i>=s;i--)
#define MOD			1000000007
#define pb 			push_back
#define ff 			first
#define ss 			second		
#define w(x)		int x; cin>>x; while(x--)
const int INF=1e18;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k-1)  returns iterator to kth element starting from 0; Returns the kth smallest element
// order_of_key(k) returns count of elements strictly smaller than k;Returns the number of elements less than k
// erase,insert same as normal set

string s,t;

void solve(){
	cin>>s>>t;

	int n=s.length(),m=t.length();

	int dp[n+1][m+1];
	memset(dp,0,sizeof(dp));

	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i-1]==t[j-1]){
				dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}

	string ans="";
	int i=n,j=m;
	while(i>0 && j>0){
		if(dp[i][j-1]==dp[i][j]){
			j--;
		}
		else if(dp[i-1][j]==dp[i][j]){
			i--;
		}
		else{
			ans+=s[i-1];
			i--,j--;
		}
	}

	if(s.length()==0){
		cout<<" "<<endl;return;
	}

	reverse(ans.begin(), ans.end());
	cout<<ans<<endl;
}
 
int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
// #endif
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
int n;
vector<int> g[maxn];
int col[maxn],num[3];
int p[maxn],a[maxn];
void dfs(int u,int f,int c)
{
	col[u]=c;
	num[c]++;
	for(int v:g[u])if(v!=f)dfs(v,u,3-c);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;++i)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1,0,1);
	int x=1,y=2,z=3;
	if(num[1]<=n/3)
	{
		for(int i=1;i<=n;++i)if(col[i]==1)p[i]=z,z+=3;
		for(int i=1;i<=n;++i)if(!p[i])
		{
			if(x<=n)p[i]=x,x+=3;
			else if(y<=n)p[i]=y,y+=3;
			else p[i]=z,z+=3;
		}
	}
	else if(num[2]<=n/3)
	{
		for(int i=1;i<=n;++i)if(col[i]==2)p[i]=z,z+=3;
		for(int i=1;i<=n;++i)if(!p[i])
		{
			if(x<=n)p[i]=x,x+=3;
			else if(y<=n)p[i]=y,y+=3;
			else p[i]=z,z+=3;
		}
	}
	else
	{
		for(int i=1;i<=n;++i)
		{
			if(col[i]==1)
			{
				if(x<=n)p[i]=x,x+=3;
				else p[i]=z,z+=3;
			}
			else
			{
				if(y<=n)p[i]=y,y+=3;
				else p[i]=z,z+=3;
			}
		}
	}
	for(int i=1;i<=n;++i)printf("%d ",p[i]);
}

Measured memory_bytes: 19200
#include <stdio.h>
int main(){
  int n,x[105];
  int sum[105],msum=1000000;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&x[i]);
  }
  for(int j=1;j<=100;j++){
    sum[j]=0;
    for(int k=0;k<n;k++){
      sum[j]=sum[j]+(x[k]-j)*(x[k]-j);
    }
    if(sum[j]<msum){
      msum=sum[j];
    }
  }
  printf("%d",msum);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;

int main(){
    int a,b,c,num = 0;
    cin >> a >> b >> c;
    
    for(int i=a;i<=b;++i){
        if(c%i == 0){
            ++num;
        }
    }
    
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 3120
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

typedef struct _node {
  unsigned int id;
  unsigned int rank;
  struct _node* parent;
} Node;

typedef Node* NodePointer;

NodePointer root(NodePointer, unsigned int);
void unite(NodePointer, unsigned int, unsigned int);
bool isSame(NodePointer, unsigned int, unsigned int);

int main () {
  unsigned int n, m, q;
  unsigned int s, t;

  scanf("%u %u", &n, &m);
  NodePointer friends = (NodePointer)malloc(sizeof(Node)*n);
  for (unsigned int i = 0; i < n; ++i) {
    friends[i].id     = i;
    friends[i].rank   = 0;
    friends[i].parent = &friends[i];
  }

  for (unsigned int i = 0; i < m; ++i) {
    scanf("%u %u", &s, &t);
    unite(friends, s, t);
  }

  scanf("%u", &q);
  for (unsigned int i = 0; i < q; ++i) {
    scanf("%u %u", &s, &t);    
    if (isSame(friends, s, t)) {
      printf("yes\n");
    } else {
      printf("no\n");
    }   
  }

  return 0;
}

NodePointer root(NodePointer friends, unsigned int x) {
  if (friends[x].parent == &friends[x]) {
    return &friends[x];
  } else {
    friends[x].parent = root(friends, friends[x].parent->id);
    return friends[x].parent;
  }
}

void unite (NodePointer friends, unsigned int x, unsigned int y) {
  NodePointer rx = root(friends, x);
  NodePointer ry = root(friends, y);
  if (rx == ry) {
    return;
  }
  
  if (rx->rank < ry->rank) {
    rx->parent = ry;
  } else {
    ry->parent = rx;
    if (rx->rank == ry->rank) {
      rx->rank++;
    }
  }
}

bool isSame (NodePointer friends, unsigned int x, unsigned int y) {
  NodePointer rx = root(friends, x);
  NodePointer ry = root(friends, y);

  return rx == ry;
}



Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  int c = 0;
  for (int i = a; i <= b; i++) {
    if(i / 10000 == i % 10 && (i % 10000) / 1000 == (i % 100) / 10){
      c++;
    }   
  }
  cout << c << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    ll ans = 0;
    rep(b, 60) {
        ll msk = 1ll << b;
        ll zero = 0, one = 0;
        rep(i, n) {
            if (a[i] & msk) one++;
            else zero++;
        }
        ans += ((((msk % (ll)(1e9+7)) * zero) % (ll)(1e9+7)) * one) % (ll)(1e9+7);
        ans %= (ll)1e9+7;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int a, b;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b;
	cout << max(2 * a - 1, max(2 * b - 1, a + b)) << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  sort(a.begin(),a.end());
  cout << a.at(n-1) - a.at(0) << endl;
 }


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int f(vector<int> h) {
    int result = 1;
    int min = h[0];

    for (int i = 1; i < h.size(); i++) {
        if (min <= h[i]) {
            min = h[i];
            result++;
        }
    }

    return result;
}

int main() {

    int n;
    cin >> n;

    vector<int> h;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        h.push_back(tmp);
    }

    int result = f(h);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
from functools import reduce

def gcd(x, y):
    if (y==0):return x
    else:return gcd(y, x%y)

N = int(input())
*A, = map(int, input().split())
mod = 10**9 + 7
lcm = reduce(lambda a,b: a*b//gcd(a,b), A)

print(sum(map(lambda x: lcm//x, A))%mod)

Measured memory_bytes: 4708
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	vl a(n), b(n);
	FOR(i,0,n) cin >> a[i];
	FOR(i,0,n) cin >> b[i];

	ll m = 0;
	FOR(i,0,n) m += b[i]-a[i];
	
	FOR(i,0,n) {
		if (b[i] <= a[i]) m -= a[i]-b[i];
		else if ((b[i]-a[i])&1) m--;
	}
	cout << ((m < 0) ? "No" : "Yes") << endl;
}



Measured memory_bytes: 384
n = int(input())
d = list(map(int,input().split()))
m = [0]
for i in range(1,n):
  m.append(2*d[i-1] - m[i-1])
diff = 2*d[n-1] - m[n-1]
M = [diff//2]
for i in range(1,n):
  M.append(2*d[i-1] - M[i-1])
ans = list(map(str,M))
print(' '.join(ans))

Measured memory_bytes: 25048
package main

import "fmt"

func main() {
	road := make([]int, 5)
	check := make([]int, 6)
	for i := 0; i < 3; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		road[a]++
		road[b]++
	}
	for i := 1; i <= 4; i++ {
		check[road[i]-1]++
	}
	if check[0] == 2 && check[1] == 2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vikas.k
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int N = in.nextInt();
            String s = in.nextLine();

            int cntOpen = 0;
            int cntClose = 0;

            for (int i = 1; i <= N; i++) {
                if (s.charAt(i - 1) == '(') {
                    cntOpen++;
                } else {
                    if (cntOpen > 0) {
                        cntOpen--;
                    } else {
                        cntClose++;
                    }
                }
            }

            for (int i = 1; i <= cntOpen; i++) {
                s += ')';
            }

            for (int i = 1; i <= cntClose; i++) {
                String s1 = '(' + s;
                s = s1;
            }

            out.print(s);
        }

    }

    static class FastScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        public FastScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String nextLine() {
            String ret = "";
            try {
                ret = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ret;
        }

    }
}



Measured memory_bytes: 21716
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x; cin >> x;
    ll ans = 1;
    for(ll i = 2; i <= x; i++){
        ll ret = i;
        while(ret <= x){
            ret *= i;
            if(ret <= x){
                chmax(ans, ret);
            }
        }
    }
    cout << ans;
    cout << endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    deque<ll> d;
    rep(i, n) {
        int idx = lower_bound(d.begin(), d.end(), a[i]) - d.begin();
        if ( idx == 0 ) {
            d.push_front(a[i]);
        }
        else {
            d[idx-1] = a[i];
        }
    }
    cout << d.size() << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector> 

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int> inp(n),dp(n,0);
    
    
    for(int i=0;i<n;++i){
        cin>>inp[i];
    }
    
    dp[1] = abs(inp[1]-inp[0]);
    dp[2] = min(abs(inp[2]-inp[0]),dp[1]+abs(inp[2]-inp[1]));
    
    for(int i=3;i<n;++i){
        dp[i] = min(abs(inp[i]-inp[i-1])+dp[i-1],abs(inp[i]-inp[i-2])+dp[i-2]);
    }
    
    cout<<dp[n-1];

    return 0;
}

Measured memory_bytes: 4020
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;
#define ll long long
#define vel vector<int>
#define vvel vector<vel>
#define vvvel vector<vvel>
#define veb vector<bool>
#define pin pair<int,int>
#define mkp make_pair
#define mot pair<D,D>//time,dist
#define root pair<int,mot>
using namespace std;
vvel ta_min(0);
vvel ta_max(0);
int leth = 1024 * 512;
int siz = leth * 2;
void mmax(ll &a, ll b) { a = max(a, b); }
void mmin(ll &a, ll b) { a = min(a, b); }
int main() {
	int k, s; cin >> k >> s;
	int ans = 0;
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			int z = s - x - y;
			if (0 <= z and z <= k) { ans++; }
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define all(v) v.begin(),v.end()
#define v vector
#define vi vector<int>
#define vi2 vector<vector<int>>
#define vl vector<long long>
#define vl2 vector<vector<long long>>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

int main(){
    long double pi = 3.141592653589793238;
    long double kakudo;
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    kakudo = 2 * pi *m/60 - 2*pi*(h*60+m)/720;
    long double ans = sqrtl(a*a+b*b-2*a*b*cos(kakudo));
    cout << setprecision(100) << ans << endl;
}

Measured memory_bytes: 4164
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define REPA(x, v) for(auto&& x:v)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(v.rbegin(),v.rend())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

bool ans[100][100];

int main(void)
{
    int A,B;
    cin >> A >> B;
    
    pii now = {0,0};
    REP(i, A-1){
        if(i!=0&&(i%50)==0){
            now.se += 2;
        }
        ans[now.fi+1][now.se] = ans[now.fi][now.se+1] = ans[now.fi+1][now.se+1] = true;
        (now.fi += 2) %= 100;
    }

    now.fi = 0;
    now.se += 3;
    if(A==1) B++;
    REP(i, B-1){
        if(i!=0&&(i%50)==0){
            now.se += 2;
        }
        ans[now.fi][now.se] = true;
        (now.fi += 2) %= 100;
    }

    pr(100, 100);
    REP(i, 100){
        REP(j, 100){
            cout << (ans[i][j] ? "#" : ".");
        }
        cout << endl;
    }


}

Measured memory_bytes: 3596