akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

int main() {
  int N;
  cin >> N;
  int check = 1;
  int cnt = 0;
  REP(i, N) {
    int a;
    cin >> a;
    if(a == check) {
      check++;
    } else {
      cnt++;
    }
  }
  if(check == 1) {
    cout << -1 << endl;
  } else {
    cout << cnt << endl;
  }
}


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

#define SIZE 300005
#define MOD 1000000007LL
#define INF INT_MAX / 3
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i];if(i==a.size()-1)cout<<endl;else cout<<" ";}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}

int a[35];

void solve()
{
  string ans = "";
  int pre, i, dir = 0, now = 0;
  do
  {
    pre = (dir+2)%4;
    for(i=(pre+1)%4;i!=pre;++i%=4)
    {
      if(a[now]>>i&1)
      {
        dir = i;
        break;
      }
    }
    if(i == pre) dir = pre;
    switch(dir)
    {
      case 0:
        ans += "R";
        now += 1;
        break;
      case 1:
        ans += "D";
        now += 5;
        break;
      case 2:
        ans += "L";
        now -= 1;
        break;
      case 3:
        ans += "U";
        now -= 5;
        break;
    }
  }
  while(now != 0);
  cout << ans << "\n";
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  fill_n(a,35,0);
  string s;
  REP(i,9)
  {
    cin >> s;
    if(i%2==0)
    {
      int c = i/2;
      REP(j,4) if(s[j]=='1')
      {
        a[c*5+j] += 1;
        a[c*5+j+1] += 4;
      }
    }
    else
    {
      int c = (i-1)/2;
      REP(j,5) if(s[j]=='1')
      {
        a[c*5+j] += 2;
        a[(c+1)*5+j] += 8;
      }
    }
  }
  solve();
  return 0;
}

Measured memory_bytes: 1172
#include<stdio.h>
int main()
{
    int a,b,c,x,i,j,k;
    long long sum;
    while(scanf("%d%d%d%d",&a,&b,&c,&x)!=EOF)
    {    sum=0;
        for (i=0;i<=a;i++)
            for(j=0;j<=b;j++)
             for (k=0;k<=c;k++)
             if (500*i+100*j+50*k==x) sum++;
        printf("%lld\n",sum);

    }
}


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

int main() {
	int n;

	cin >> n;

	map<int, int> cnt;

	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		cnt[a]++;
	}

	int ans = 0;
	for (auto p : cnt) {
		int x = p.first;
		int c = p.second;

		if (c > x) {
			ans += c - x;
		}
		else if (c < x) {
			ans += c;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4736
#約数全部
def Divisors(N):
    N=abs(N)
    L,U=[],[]
    k=1
    while k*k <=N:
        if N%k== 0:
            L.append(k)
            if k!=N//k:
                U.append(N//k)
        k+=1
    return L+U[::-1]

def f(A,B):
    M=max(A,B)
    return len(str(M))
#================================================
N=int(input())
L=Divisors(N)
Y=float("inf")
for a in L:
    Y=min(Y,f(a,N//a))
print(Y)

Measured memory_bytes: 68600
#include<stdio.h>
#include <string.h>



int main(){
  int n;

  scanf("%d", &n);

  if(n%2 == 0){
    printf("%d\n",n/2);
  }else if(n == 1){
    printf("1\n");
  }else{
    printf("%d\n", (n/2)+1);
  }
}

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

int main() {
  int m,n;
  cin >> m >> n;
  vector<int> vec(m);
  rep(i,m) {
    int x;
    cin >> x;
    vec[i]=x;
  }
  int64_t total=0;
  int ans=0;
  rep(i,m) total += vec[i];
  int a = total/(4*n);
  if(total%(4*n)!=0) a++;
  rep(i,m) {
    if (vec[i] >= a) ans++;
  }
  if(ans >=n) cout << "Yes" << endl;
  else cout << "No" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int sum = accumulate(a.begin(), a.end(), 0);
    int b = a[n - m];
    if (4 * m * b < sum) {
        cout << "No" << '\n';
    } else {
        cout << "Yes" << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
s = input()

cnt_1 = 0
cnt_2 = 0

pattern = "01"

for i in range(len(s)):
    if s[i] != pattern[i % 2]:
        cnt_1 += 1
    
    if s[i] != pattern[(i + 1) % 2]:
        cnt_2 += 1

print(min(cnt_1, cnt_2))

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

int gcd(int p,int q){
    if(p%q == 0){
        return q;
    }
        return gcd(q,p%q);
}

int main(){
    int a,b,c,k; cin >> a >> b >> c >> k;
    int ans = 0;
    if(a>0 && k>0){
        if(a>=k){
            ans += k;
            k = 0;
        }else{
            ans += a;
            k -= a;
        }
    }
    if(b>0 && k>0){
        if(b>=k){
            k = 0;
        }else{
            k -= b;
        }
    }
    if(k>0){
        ans -= k;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3524
import java.util.*;

public class Main {
	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int ans = a*n;
		if (ans > b) {
			ans = b;
		}
		// 出力
		System.out.println(ans);

		sc.close();

	}
}

Measured memory_bytes: 20820
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

map<long long, int> factorization(long long N) {
	map<long long, int> re;
	while (true) {
		if (N % 2 == 0) {
			N /= 2;
			re[2]++;
			if (N == 1) break;
		}
		else {
			break;
		}
	}
	for (int loop = 3; (long long)loop * (long long)loop <= N; loop += 2) {
		if (N % loop == 0) {
			N /= loop;
			re[loop]++;
			loop -= 2;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	return re;
}

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination1 {
private:
	int m_module = 1000000007;
	vector<struct Memo> memo;
public:
	int calculate(int, int);
	Combination1(int, int);
};
int Combination1::calculate(int n, int k) {
	return ((memo[n].fact * memo[k].fact_inv) % m_module * memo[n - k].fact_inv) % m_module;
}
Combination1::Combination1(int memo_max, int module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

class Combination2 {
private:
	int size = 0;
	bool add(int);
public:
	vector<int> sequence;
	bool next_combination(void);
	Combination2(int, int);
};
bool Combination2::add(int index) {
	if (index == (int)sequence.size() - 1 && sequence[index] == size - 1
		|| index < (int)sequence.size() - 1 && sequence[index] == sequence[index + 1] - 1) {
		if (index == 0) {
			return false;
		}
		else {
			bool re = add(index - 1);
			sequence[index] = sequence[index - 1] + 1;
			return re;
		}
	}
	else {
		sequence[index]++;
		return true;
	}
}
bool Combination2::next_combination(void) {
	return (sequence.size() == 0) ? false : add(sequence.size() - 1);
}
Combination2::Combination2(int n, int r) {
	size = n;
	for (int loop = 0; loop < r; loop++) sequence.push_back(loop);
	return;
}

void A_Password(void) {

	int N; cin >> N;

	cout << N * N * N << flush;
	return;
}

void B_Buffet(void) {

	int N; cin >> N;
	vector<int> A(N); for (int& it : A)cin >> it;
	int sum = 0;
	for (int loop = 0; loop < N; loop++) {
		int B; cin >> B;
		sum += B;
	}
	vector<int> C(N - 1); for (int& it : C)cin >> it;
	
	for (int index = 0; index < N - 1; index++) {
		if (A[index] + 1 == A[index + 1]) sum += C[A[index] - 1];
	}

	cout << sum << flush;
	return;
}

void C_Maximal_Value(void) {

	int N; cin >> N;
	vector<int> B(N - 1); for (int& it : B)cin >> it;

	int sum = B[0] + B[N - 2];
	for (int index = 0; index < N - 2; index++) {
		sum += min(B[index], B[index + 1]);
	}

	cout << sum << flush;
	return;
}

int main(void) {

	//A_Password();
	//B_Buffet();
	C_Maximal_Value();
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int main(){
    ll X;
    cin >> X;
    if(X >= 30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll a,b,h,m; cin>>a>>b>>h>>m;
    double ang1=6.0*m, ang2=30.0*h+0.5*m;
    double res = a*a + b*b - 2*a*b*cos(abs(ang1 - ang2)*acos(-1)/180);
    cout << fixed << setprecision(15) << sqrt(res) <<endl;
    return 0;
}

Measured memory_bytes: 4232
using System;
using System.Collections.Generic;
using System.Linq;

namespace MyProgram{
    class AtCoder{
        static void Main(){
            var N = int.Parse(Console.ReadLine());
            var s = new int[N];
            for(var i=0;i<N;i++){
                s[i] = int.Parse(Console.ReadLine());
            }
            bool flag = false;
            Array.Sort(s);
            long sum=0;
            long min=0;
            for(var i=0;i<N;i++){
                sum+=s[i];
                if(flag == false&&s[i]%10!=0){
                    flag = true;
                    min = s[i];
                }
            }
            if(sum%10==0){
                if(min==0)sum=0;
                else sum = sum-min;
            }

            System.Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>

int n ;
char s[300005];

int main()
{
  std::cin >> n;
  std::cin >> s;


  int ans;
  int numEW = 0;

  for(int i=1; i<n; i++)
    if(s[i]=='E') numEW++;

  ans = numEW;
    
  for(int i=0; i<n; i++)
  {
    ans = std::min(ans, numEW);
    numEW += (s[i]=='W');
    numEW -= (s[i+1] == 'E');
  }

  std::cout << ans << '\n';
}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 2 * (int)1e5 + 1000;
int n, p[maxn];
 
int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
#endif
	
	cin >> n;
	for1(i, n) cin >> p[i];
	int min_num = INT_MAX;
	int ans = 0;
	for1(i, n) {
		uin(min_num, p[i]);
		if (p[i] == min_num) ++ans;
	}
	cout << ans << '\n';
		
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
const int mod = 1e9 + 7;

int main(){
    ll n; cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];
    ll times = 0;
    ll index = 0;
    while(times < 2*n){
        if(index==1){
            cout << times << endl;
            return 0;
        }
        ll t = a[index] - 1;
        index = t;
        times++;
    }
    puts("-1");
}

Measured memory_bytes: 1024
import copy


def actual(n, P):
    nums_asc = sorted(P)

    if nums_asc == P:
        return 'YES'

    N = len(P)
    for i in range(N):
        for j in range(1, N):
            swapped_nums = copy.deepcopy(P)

            swapped_nums[i] = P[j]
            swapped_nums[j] = P[i]

            if swapped_nums == nums_asc:
                return 'YES'

    return 'NO'

n = int(input())
P = list(map(int, input().split()))

print(actual(n, P))

Measured memory_bytes: 3444
#include<iostream>
#include<queue>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<map>

using namespace std;

int main(){
    int mx=0;
    string s;
    cin >> s;
    for(int i=0;i<=s.length();i++){
        int tmp=0;
        for(int j=0;j<s.length();j++){
            if(j<i){
                tmp+=int(s[j])-48;
            }
            else if(j==i){
                tmp+=int(s[j])-49;
            }
            else{
                tmp+=9;
            }
        }
        mx = max(tmp, mx);
    }
    cout << mx << endl;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  string S;

  cin >> S;

  llong sum = 0;
  for (auto c: S) {
    sum += c - '0';
  }

  cout << (sum % 9 == 0 ? "Yes": "No") << endl;

  return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main()
{
    int n, m;

    while (cin >> n >> m, n) {
        vector<string> winning_num(n);
        map<string, int> hash;

        for (int i = 0; i < n; ++i) {
            string s;
            int m;

            cin >> s >> m;
            winning_num[i] = s;
            hash[s] = m;
        }

        int sum = 0;
        for (int i = 0; i < m; ++i) {
            string s;

            cin >> s;
            for (int j = 0; j < n; ++j) {
                bool flag = true;

                for (int k = 0; k < 8; ++k) {
                    if (winning_num[j][k] != '*' && winning_num[j][k] != s[k]) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {

                    sum += hash[winning_num[j]];
                    break;
                }
            }
        }

        cout << sum << endl;
    }

    return 0;
}

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

#define repr(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define irepr(i,a,b) for(int i=a, i##_len=(b); i>=i##_len; --i)
#define irep(i,n) for(int i=n, i>=0; --i)

#define printline(str) cout << str << "\n"

bool IsAsc(const vector<int>& v){
  int x = v[0];
  repr(i,1,v.size()){
    if( x > v[i]){
      return false;
    }
    x = v[i];
  }
  return true;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> v(N);
  rep(i,N){
    cin >> v[i];
  }

  if( IsAsc(v)){
    printline("YES");
    return 0;
  }else{

    rep(i,N){
      repr(j,i+1,N){
        vector<int> tmp;
        copy(v.begin(), v.end(), back_inserter(tmp));
        int t = tmp[i];
        tmp[i] = tmp[j];
        tmp[j] = t;
        if( IsAsc(tmp)){
          printline("YES");
          return 0;
        }
      }
    }
  }
  printline("NO");

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	vector<int>L(N);
	for (int i = 0; i < N; i++) {
		cin >> L.at(i);
	}
	sort(L.begin(), L.end(), greater<int>());
	int ans = 0;
	for (int i = 0; i < K; i++) {
		ans += L.at(i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N, M;
pair <int, int> Nodes[100005];
int A[100005], B[100005], Pos[100005];
vector <int> G[100005], GG[100005];
bool Active[100005];
int TT[100005], R[100005];
pair <int, int> Sz[100005];
long long Sum[100005], DP[100005];
void Unite(int x, int y)
{
    if(x == y)
        return;
    if(R[x] < R[y])
    {
        TT[x] = y;
        //Val[y] += Val[x];
        Sz[y] = max(Sz[y], Sz[x]);
    }
    else
        TT[y] = x, Sz[x] = max(Sz[x], Sz[y]);
    if(R[x] == R[y])
        ++R[x];
}
int Father(int x)
{
    int init = x;
    while(TT[x] != x)
    {
        x = TT[x];
    }
    while(init != x)
    {
        int nxt = TT[init];
        TT[init] = x;
        init = nxt;
    }
    return x;
}
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
    {
        cin >> A[i] >> B[i];
        TT[i] = i;
        Sz[i] = make_pair(max(0, A[i] - B[i]), i);
        A[i] = max(0, A[i] - B[i]);
        Nodes[i] = make_pair(A[i], i);
    }
    for(int i = 1; i <= M; i++)
    {
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    sort(Nodes + 1, Nodes + N + 1);
    for(int i = 1; i <= N; i++)
        Pos[Nodes[i].second] = i;
}

void buildTree()
{
    for(int i = 1; i <= N; i++)
    {
        int node = Nodes[i].second;
        Active[node] = 1;
        for(int j = 0; j < G[node].size(); j++)
        {
            int neighb = G[node][j];
            if(Pos[neighb] > Pos[node])
                continue;
            if(Father(node) != Father(neighb))
            {
                GG[Sz[Father(node)].second].push_back(Sz[Father(neighb)].second);
                Unite(Father(node), Father(neighb));
            }
        }
    }
}

void DFS(int node)
{
    Sum[node] = B[node];
    int cnt = 0;
    for(int i = 0; i < GG[node].size(); i++)
    {
        int neighb = GG[node][i];
        DFS(neighb);
        Sum[node] += Sum[neighb];
        ++cnt;
    }
    DP[node] = 1000000000000000;
    if(cnt == 0)
    {
        DP[node] = A[node] + B[node];
        return;
    }
    for(int i = 0; i < GG[node].size(); i++)
    {
        int neighb = GG[node][i];
        long long s = Sum[node] - Sum[neighb];
        DP[node] = min(DP[node], max(0LL, DP[neighb] - A[node]) + s + A[node]);
    }
}
int main()
{
    Read();
    buildTree();
    DFS(Nodes[N].second);
    cout << DP[Nodes[N].second] << "\n";
    return 0;
}


Measured memory_bytes: 19580
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll E = lcm(C, D);
    ll ac = (A-1) / C;
    ll bc = (B) / C;
    ll ad = (A-1) / D;
    ll bd = (B) / D;
    ll ae = (A-1) / E;
    ll be = (B) / E;

    const auto f = [C, D, E](ll x)
    {
        ll c = x / C;
        ll d = x / D;
        ll e = x / E;
        return x - c - d + e;
    };
    ll ans = f(B) - f(A - 1);
    //
    /*ll ans = (B- A + 1) - ((bc - ac) + (bd - ad) - (be- ae));*/
    cout << ans;
    //
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
bool bfsconnected(int *a, int i, int j,int n){
	queue<int> q;
	//bool conn=false;
	bool visited[n];
	FOR(i,n) visited[i]=false;
	/**(a+i*n+j)=0;
	*(a+j*n+i)=0;
*/
	q.push(i);
	while(!q.empty()){
		int s=q.front();
		q.pop();
		visited[s]=true;
		FOR(k,n) {
			if(*(a+n*s+k)==1 && k==j && s!=i) return true;
			else if(*(a+n*s+k )==1 && !visited[k] && (s!=i || k!=j)) q.push(k);
		}
	}
	return false;
}


int main(){
	int n,m;
	cin >> n >> m;
	int s,t;
	int *edges=new int[n*n];
	FOR(i,n) FOR(j,n) *(edges+i*n+j)=0;
	

	FOR(i,m){
		cin >> s >>t;
		*(edges+(s-1)*n+t-1)=1;
		*(edges+(t-1)*n+s-1)=1;
	}

	//FOR(i,n) FOR(j,n) cout << *(edges+i*n+j) <<" \n"[j==n-1];
	int sum=0;
	for(int i=0; i < n;i++){
		for(int j=0;j<=i;j++){
			if(*(edges+i*n+j)==1) {
				
				if(!bfsconnected(edges,i,j,n)) sum++;//cout << i+1 <<" "<<j+1 <<"\n";
			}
		}	
	}
	cout << sum;
	 

	return 0;
}

Measured memory_bytes: 256
/*input
10000000
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double

typedef pair<int,int> pi;

typedef vector<int> vi;
typedef vector<pi> vpi;

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define gcd __gcd

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int n;
  cin >> n;
  int st = n;
  int sum = 0;
  while(n > 0){
  	sum += n%10;
  	n /= 10;
  }
  n = st;
  int lg = log10(n);
  if(pow(10,lg) == n)cout << "10";
  else cout << sum << endl;
  return 0;
}

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   long n, a, b;
   LI xs;
   bool f(long t) {
      long rem = 0;
      for(long i = 0; i < n; ++i) {
         long x2 = xs[i] - b * t;
         if( x2 <= 0 ) break;
         rem += (x2 + (a - b) - 1) / (a - b);
      }
      dumpll(t, rem);
      return rem <= t;
   }
   void solve() {
      scan(n, a, b);
      xs.resize(n);
      for(long &x : xs) scan(x);
      std::sort(xs.begin(), xs.end());
      std::reverse(xs.begin(), xs.end());
      long res = (1LL << 30) - 1;
      for(long i = 29; i >= 0; --i) {
         long t = res - (1LL << i);
         if( f(t) ) res = t;
      }
      printf("%ld\n", res);
   }
};

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 1152
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n, l;
int a[210];

int minDiff;
int sumInMinDiff;
int sum;


int main()
{
	scanf("%d%d", &n, &l);
	
	sum = 0;
	for (int i = 1 ; i <= n ; i++)
	{
		a[i] = l + i - 1;
		sum = sum + a[i];
	}
	
	minDiff = abs(a[1]);
	sumInMinDiff = sum - a[1];
	for (int i = 2 ; i <= n ; i++)
	{
		int absA = abs(a[i]);
		if (minDiff > absA)
		{
			minDiff = absA;
			sumInMinDiff = sum - a[i];
		}
	}
	
	printf("%d\n", sumInMinDiff);
	

	return 0;
}



Measured memory_bytes: 128
use std::collections::BinaryHeap;
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let mut queue = BinaryHeap::new();
    let n: i32 = read();
    let m: i64 = read();
    for _ in 0..n {
        let price: i64 = read();
        queue.push(price);
    }
    for _ in 0..m {
        let price = queue.pop().unwrap();
        // round
        queue.push(price / 2);
    }
    let mut sum = 0;
    for price in queue {
        sum += price;
    }
    println!("{}", sum);
}


Measured memory_bytes: 4352
n = int(input())
a = list(map(int, input().split()))
uno = a.count(1)
dos = a.count(2)
tres = n - uno - dos
dp = [[[0]*(n+1) for _ in range(dos+tres+1)] for j in range(tres+1)]
for k in range(tres+1):
  for j in range(dos+tres-k+1):
    for i in range(n+1-j-k):
      if i+j+k == 0: continue
      v = i+j+k
      res = n
      if i: res += i * dp[k][j][i-1]
      if j: res += j * dp[k][j-1][i+1]
      if k: res += k * dp[k-1][j+1][i]
      dp[k][j][i] = res / v
print(dp[tres][dos][uno]) 

Measured memory_bytes: 496776
using System;
using System.Linq;

public class Pg
{
    enum Cup{A,B,C}
    public static void Main()
    {
        var cup = new int[] { 1, 0, 0 };
        var cup2 = new char[] { 'A', 'B', 'C' };
        string line;
        var a = 0;
        var b = 0;
        while ((line = Console.ReadLine()) != null)
        {
            string[] swap = line.Split(',');
            if (swap[0] == "A")
            {
                a = 0;
            }
            else if (swap[0] == "B")
            {
                a = 1;
            }
            else
            {
                a = 2;
            }
            if (swap[1] == "A")
            {
                b = 0;
            }
            else if (swap[1] == "B")
            {
                b = 1;
            }
            else
            {
                b = 2;
            }
            cup = Swap(cup, a, b);
        }
        for (int i = 0; i < 3; ++i)
            if (cup[i] == 1)
            {
                Console.WriteLine(cup2[i]);
            }
    }
    private static int[] Swap(int[] a, int b, int c)
    {
        var tmp = a[b];
        a[b] = a[c];
        a[c] = tmp;
        return a;
    }
}


Measured memory_bytes: 15852
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	n <- readLn
	as <- zipWith (-) [ 1 .. ] <$> getList
	let
		b1 = sort as !! ( n `div` 2 )
		b2 = if 2 <= n then sort as !! ( n `div` 2 + 1 ) else 0
	print $ minimum $ map ( sum . map abs ) $ map ( \b -> map ( (-) b ) as ) [ b1, b2 ]

Measured memory_bytes: 47484
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    int A,B;cin >> A >> B;
    if(B%A==0)cout << A+B << endl;
    else cout << B-A << endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;
	string s;cin>>s;
	rep(i, s.length()){
		if(i%2 == 0&&s[i]=='L'){
			cout <<"No"<<endl;
			return 0;
		}
		if(i%2 == 1&&s[i]=='R'){
			cout <<"No"<<endl;
			return 0;
		}
	}
	cout << "Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque

H, W = map(int, input().split())

maze = []
for _ in range(H):
    maze.append(input())


def bfs(sy, sx):
    table = [[-1] * W for _ in range(H)]
    table[sy][sx] = 0
    queue = deque([[sy, sx]])
    while queue:
        y, x = queue.popleft()
        for dy, dx in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            ny, nx = y + dy, x + dx
            if 0 <= ny < H and 0 <= nx < W and maze[ny][nx] == '.' and table[ny][nx] == -1:
                table[ny][nx] = table[y][x] + 1
                m = table[ny][nx]
                queue.append([ny, nx])
    return m


ans = 0
for y in range(H):
    for x in range(W):
        if maze[y][x] == '.':
            ans = max(ans, bfs(y, x))
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    ll n, a, b; cin >> n >> a >> b;
    ll ans = n / (a+b);
    ans *= a;
    ll rem = n % (a+b);
    if(0 <= rem && rem <= a){
        ans += rem;
    }
    else{
        ans += a;
    }
    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	double a, b, c, d, e, f, x, y;

	while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){
		x = (c*e - b*f) / (a*e - b*d) + 0.0;                          
        y = (a*f - d*c) / (a*e - b*d) + 0.0;
		printf("%.3lf %.3lf\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 648
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


int main()
{
string s;
cin>>s;
int c=0;
if(s[0]=='R'&& s[1]=='R'&&s[2]=='R'){cout<<3;return 0;}
if(s[0]=='S'&& s[1]=='S'&&s[2]=='S'){cout<<0;return 0;}
if(s[0]=='R'&& s[1]=='R'&&s[2]=='S'){cout<<2;return 0;}
if(s[0]=='R'&& s[1]=='S'&&s[2]=='S'){cout<<1;return 0;}
if(s[0]=='S'&& s[1]=='R'&&s[2]=='R'){cout<<2;return 0;}
if(s[0]=='S'&& s[1]=='R'&&s[2]=='S'){cout<<1;return 0;}
if(s[0]=='R'&& s[1]=='S'&&s[2]=='R'){cout<<1;return 0;}
cout<<1;
   return 0;
 }



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

#ifdef ONLINE_JUDGE
#define endl "\n"
#endif
using namespace std;
typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
typedef vector <ll> v;
typedef vector <v> vv;
typedef vector <ld> vld;
typedef vector<bool> vb;
typedef vector <string> vs;
typedef pair <ll, ll> pll;
typedef vector <pll> vpll;
const ll MOD = 1e9 + 7;
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
#define yes cout << "Yes\n";
#define no cout << "No\n";
#define yesno(f) \
    if (f)       \
        yes else no;
#define noo \
    { no return; }
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define sz(x) (ll) x.size()
#define sq(x) ((x) * (x))

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<typename T = ll>
vector <T> ga(ll n, bool oneIndexed = false) {
    vector <T> a = vector<T>(n + oneIndexed);

    for (ll i = 0; i < n; i++) {
        T p;
        cin >> p;
        a[i + oneIndexed] = p;
    }

    return move(a);
}

template<typename T, typename A>
void pa(vector < T, A >
const &a,
ll begin = 0, ll
end = -1
) {
if (end == -1)
end = sz(a) - 1;
for (
ll i = begin;
i <=
end;
i++) {
cout << a[i] << " ";
}
cout <<
endl;
}

bool ispali(string &s, ll b, ll e) {
    while (b <= e) {
        if (s[b] != s[e])return false;
        b++;
        e--;
    }
    return true;
}

void solve() {
    string s;
    cin >> s;
    ll n = sz(s);
    bool b1 = ispali(s, 0, n - 1);
    bool b2 = ispali(s, 0, (n - 1) / 2 - 1);
    bool b3 = ispali(s, (n + 3) / 2 - 1, n - 1);
    yesno(b1 && b2 && b3);
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // ll t;cin >> t;while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<long long> solve(vector<int> A) {
	int N = A.size();
	vector<long long> dp(N);
	vector<double> diff(N - 1);
	set<int> four;
	for (int i = N - 2; i >= 0; --i) {
		dp[i] = dp[i + 1];
		diff[i] = double(A[i + 1]) / A[i];
		while (diff[i] < 0.9999999999) {
			diff[i] *= 4;
			dp[i] += (N - i - 1) * 2;
			if (!four.empty()) {
				int ptr = *four.begin();
				dp[i] -= (N - ptr - 1) * 2;
				diff[ptr] /= 4;
				if (diff[ptr] < 3.9999999999) four.erase(ptr);
			}
		}
		if (diff[i] >= 3.9999999999) four.insert(i);
	}
	return dp;
}
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	vector<long long> ldp = solve(A);
	reverse(A.begin(), A.end());
	vector<long long> rdp = solve(A);
	reverse(rdp.begin(), rdp.end());
	long long ans = min(ldp[0], rdp[N - 1] + N);
	for (int i = 0; i < N - 1; ++i) {
		ans = min(ans, ldp[i + 1] + rdp[i] + i + 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6484
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      s: String
   }

   let mut x = 0;
   let mut m = 0;
   for c in s.chars() {
      if c == ')' {
         x -= 1;
         m = std::cmp::min(m, x);
      } else {
         x += 1;
      }
   }
   for _ in 0..(-m) {
      print!("(");
   }
   for c in s.chars() {
      print!("{}", c);
   }
   for _ in 0..x-m {
      print!(")");
   }
   println!("");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ull unsigned ll
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define piii pair <pii,int>
#define piiii pair <pii,pii>
#define plll pair <pair <ll, ll>, ll>
#define rep0(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep(i,x,y) for(ll i=x;i<=y;i++)
#define reprev(i,n) for(ll i=n;i>=0;i--)
#define all(c) c.begin(),c.end()
#define print(a) rep0(i,a.size()) cout << a[i] << " "
#define hi() cout << "\nHello, I am error. Can you find me? :):):)\n"
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_eppoch().count())
 
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;

const int mod = 1e9+7;
const long double pi = acos(-1);

ll power(ll x, ll y){
	x %= mod;
	if(y == 0) return 1;
	if(y == 1) return x;
	ll num = power(x,y/2) % mod;
	if(y%2 == 0) return (num*num)%mod;
	else return (((num*num)%mod)*x)%mod;
}

ll fun(ll n, ll x){
	ll num = 1;
	rep0(i,n+2) num *= 2;
	num -= 3;

	ll tmp = 1;
	rep0(i,n+1) tmp *= 2;
	tmp -= 1;

	if(n == 0) return 1;
	if(x == 1) return 0;
	if(x < num/2) return fun(n-1,x-1);
	if(x == num/2) return fun(n-1,x);
	if(x == num/2 + 1) return fun(n-1,x) + 1;
	if(x >= num) return 2*fun(n-1,x) + 1;
	return fun(n-1,x) + 1 + fun(n-1,x-tmp);
}

void solve(){

	ll n, x;
	cin >> n >> x;
	ll ans = fun(n, x);
	cout << ans;

	return;
}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		// cout << "Case #" << t << ": ";
		solve();
		// cout << "\n";
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  cin>>S>>T;
  int s_size = S.size();
  int ans =0;
  for (int i=0; i<s_size; i++){
    if (S[i] != T[i]) ans++;
  }
  cout << ans;
  return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  long long N; cin >> N;
  ll ans = N - 1;

  REP(i, 1, ((ll)sqrt(N) + 2)) {
    if (N % i) { continue; }
    ll j = N / i;
    ans = min(ans, (ll)(i - 1) + (j - 1));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,ans,a[20],cnt,sum;
int main()
{
	scanf("%lld",&n);
	while(n)
	{
		a[++cnt]=n%10;
		n/=10;
		sum+=a[cnt];
	}
	int ans=9*(cnt-1)+a[cnt]-1;
	if(sum>ans) ans=sum;
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int W = 716070898, P = 998244353, I2 = 499122177;

void add(int&x , int y) {
  if ((x += y) >= P)
    x -= P;
}

void sub(int& x, int y) {
  if ((x -= y) < 0)
    x += P;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  cin >> N;
  vector<int> pw(N);
  pw[0] = 1;
  for (int i = 1; i < N; ++i) pw[i] = pw[i - 1] * (ll)W % P;
  int l = 0;
  while ((1 << l) < N) ++l;
  vector<int> SG1, SG2, SG3;
  auto getSG = [&]() {
    vector<int> ret(N);
    int M;
    cin >> M;
    vector<vector<int>> G(N);
    while (M--) {
      int u, v;
      cin >> u >> v;
      --u; --v;
      if (u > v) swap(u, v);
      G[u].push_back(v);
    }
    for (int i = N - 1; i >= 0; --i) {
      vector<bool> vis(G[i].size() + 1);
      for (int v : G[i])
        if (ret[v] <= G[i].size())
          vis[ret[v]] = true;
      while (vis[ret[i]]) ++ret[i];
    }
    return ret;
  };
  SG1 = getSG();
  SG2 = getSG();
  SG3 = getSG();
  auto toWt = [&](const vector<int>& SG) {
    vector<int> ret(1 << l);
    for (int i = 0; i < N; ++i)
      add(ret[SG[i]], pw[i]);
    return ret;
  };
  auto A1 = toWt(SG1), A2 = toWt(SG2), A3 = toWt(SG3);
  auto FWT = [&](vector<int>& A) -> void {
    for (int i = 0; i < l; ++i)
      for (int j = 0; j < (1 << l); ++j)
        if (!((j >> i) & 1)) {
          int a0 = A[j], a1 = A[j ^ (1 << i)];
          A[j] = (a0 + a1) % P;
          A[j ^ (1 << i)] = (a0 - a1 + P) % P;
        }
  };
  FWT(A1);
  FWT(A2);
  FWT(A3);
  for (int i = 0; i < (1 << l); ++i)
    A1[i] = A1[i] * (ll)A2[i] % P * A3[i] % P;
  FWT(A1);
  int ans = A1[0] * (ll)W % P * W % P * W % P;
  for (int i = 0; i < l; ++i)
    ans = ans * (ll)I2 % P;
  cout << ans;

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 5976
#include<iostream>
using namespace std;
typedef long long ll;

ll abss(ll n){ return (n > 0 ? n : -n); }

int main(){
	int n; cin >> n;
	ll a[n];
	ll sum = 0;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		sum += a[i];
	}
	ll subs = 0;
	ll ans = 1145141919810364364;
	for(int i = 0; i < n - 1; ++i){
		subs += a[i];
		ans = min<ll>(ans, abss(subs - (sum - subs)));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792