akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <queue>
#include <algorithm>
#include <set> 
#include <cstring>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define pb push_back
set<int>ss[28];
char c[500005];
int main(int argc, char** argv) {
	int n;
	string s;
	cin>>n>>s;
	rep(i,0,s.length()-1)
	{
	c[i+1]=s[i];
	ss[s[i]-'a'].insert(i+1);	
	}
	int q;
	cin>>q;
	while(q--)
	{
		int op;
		scanf("%d",&op);
		if(op==1)
		{
			int x;
			scanf("%d",&x);
			char cc;
			cin>>cc;
			ss[c[x]-'a'].erase(x);
			ss[cc-'a'].insert(x);
			c[x]=cc;
		}
		else
		{
			int l,r;scanf("%d%d",&l,&r);
			int aa=0;
			rep(i,0,25)
			{
				set<int>::iterator it;
				if(!ss[i].size())continue;
				it=ss[i].lower_bound(l);
				if(it!=ss[i].end()&&*it<=r)
				{
					aa++;
				}
				
			}
			printf("%d\n",aa);
		}
	}
	return 0;
}

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

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


Measured memory_bytes: 3100
def s():
  from sys import stdin
  read=stdin.buffer.readline
  n=int(read())
  l=list(map(int,read().split()))
  f=l[0]
  mod=10**9+7
  def gcd(s,d):
    s,d=max(s,d),min(s,d)
    while  d:
      s,d=d,s%d
    return s
  for i in l:
    f=i*f//gcd(i,f)
  ans=0
  for iu in l:
    b,u,v=mod,1,0
    while b:
      t=iu//b;iu,b=b,iu%b;u-=t*v;u,v=v,u
    ans+=(f*u%mod)%mod
    ans%=mod
  print(ans)
  
if __name__=="__main__":s()


Measured memory_bytes: 3828
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int N;
  cin >> N;
  vector<vector<pii>> A(N);
  rep(i, 0, N) {
    int a;
    cin >> a;
    rep(j, 0, a) {
      int x, y;
      cin >> x >> y;
      x--;
      A[i].eb(x, y);
    }
  }

  int ans = 0;
  rep(s, 0, 1 << N) {
    rep(i, 0, N) {
      int h = (s >> i) & 1;
      if (h) {
        rep(j, 0, sz(A[i])) {
          int x, y;
          tie(x, y) = A[i][j];
          if ((y == 0 && s >> x & 1) || (y == 1 && (s >> x & 1) == 0)) {
            goto next;
          }
        }
      }
    }
    chmax(ans, __builtin_popcount(s));
  next:;
  }
  cout << ans << endl;
  return (0 ^ _ ^ 0);
}



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

int main(){
    string s;
    cin>> s;

    int C_cnt = 0;
    for(int i=0; i<s.size(); i++){
        if(i == 0){
        if(s[0] != 'A'){
            cout<<"WA"<<endl;
            return 0;
        }
        }
        else if(1<i && i<s.size()-1 && s[i]=='C'){
            C_cnt++;
        }
        else if(s[i]-'a' < 0){
            //cout<<s[i]<<" : "<<s[i]-'a'<<endl;
            cout<<"WA"<<endl;
            return 0;
        }
    }

    if(C_cnt!=1){
        cout<<"WA"<<endl;
    }else{
        cout<<"AC"<<endl;
    }

    return 0;
}

Measured memory_bytes: 3616
n,m=map(int,input().split())
info=[]
for i in range(m):
    p,s=input().split()
    info.append([int(p),s])
ac,wa=0,0
plob=[[0,0] for i in range(n+1)] #一個目はACしたことあるか、二個目はWAを何回出してるか
for i in range(m):
    if plob[info[i][0]][0]==0:
        if info[i][1]=="WA":
            plob[info[i][0]][1]+=1
        else:
            ac+=1
            plob[info[i][0]][0]=1
            wa+=plob[info[i][0]][1]
print(str(ac)+" "+str(wa))

Measured memory_bytes: 32252
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
long long n,a[N],b[N],c[N],x,y;
long long ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	for(int i=0;i<n;i++)cin>>c[i];
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	x=0,y=0;
	for(int i=0;i<n;i++)
	{
		while(a[x]<b[i]&&x<n)x++;
		while(c[y]<=b[i]&&y<n)y++;
		ans+=x*(n-y);
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

const int INF = 1 << 30;

int main()
{
  int N, M;
  while(cin >> N >> M, N) {
    bitset< 500 > B[500];
    for(int i = 0; i < N; i++) {
      string s;
      cin >> s;
      for(int j = 0; j < M; j++) {
        B[i][j] = s[j] == '1';
      }
    }

    if(N < M) {
      int ret = 0;
      for(int i = 0; i < (1 << N); i++) {
        bitset< 500 > bit;
        for(int j = 0; j < N; j++) {
          if((i >> j) & 1) bit ^= B[j];
        }
        if(bit.none()) ret = max(ret, __builtin_popcount(i));
      }
      cout << ret << endl;
    } else {
      vector< int > curr(1 << M, -INF);
      curr[0] = 0;
      for(int i = 0; i < N; i++) {
        vector< int > next(curr);
        int mask = B[i].to_ulong();
        for(int j = 0; j < 1 << M; j++) {
          next[j ^ mask] = max(next[j ^ mask], curr[j] + 1);
        }
        curr.swap(next);
      }
      cout << curr[0] << endl;
    }
  }
}

Measured memory_bytes: 35848
s=input()

if s[0]==s[1] and s[0]==s[2] and s[0]==s[3]:
    print("No")
elif(s[0]==s[2] and s[1]==s[3]) or (s[0]==s[1] and s[2]==s[3]) or (s[0]==s[3] and s[1]==s[2]):
    print("Yes")
else:
    print("No")

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

int dist(int p, int q){
    if( p >= q) return p-q;
    else return q-p;
}

int main(){
    int a, b, c ,d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    bool ans = false;
    if(dist(a,b) > k) ans =true;
    if(dist(a,c) > k) ans =true;
    if(dist(a,d) > k) ans =true;
    if(dist(a,e) > k) ans =true;
    if(dist(b,c) > k) ans =true;
    if(dist(b,d) > k) ans =true;
    if(dist(b,e) > k) ans =true;
    if(dist(c,d) > k) ans =true;
    if(dist(c,e) > k) ans =true;
    if(dist(d,e) > k) ans =true;
    


    if(ans) cout << ":(" << endl;
    else cout << "Yay!" << endl;
}

Measured memory_bytes: 3580
// Problem : B - Trick or Treat
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n,k;
		cin>>n>>k;
		set<int> st;
		while(k--)
		{
			int d;
			cin>>d;
			while(d--)
			{
				int x;
				cin>>x;
				st.insert(x);
			}
		}
		cout<<n-st.size();    	
    }
    return 0;
}



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

#define lb push_back
typedef long long ll;
using namespace std;
const int maxn = 1e6+5;
string s[103];
int main()
{
    int n, l; cin >> n >> l;
    for(int i = 1; i <= n; i++) cin >> s[i];
    sort(s+1, s+n+1);
    for(int i = 1; i <= n; i++) {
        cout << s[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
<?php

$line = trim(fgets(STDIN));

list($a, $b) = explode(' ', $line);


$res[] = (int) $a + (int) $b;

$res[] = (int) $a - (int) $b;

$res[] = (int) $a * (int) $b;

echo max($res[0], $res[1], $res[2]);



Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ini(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll long long

int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//ll tt;	cin>>tt;	while(tt--)
	{
		ll n,x,y,z,i,j;
		cin>>n>>x>>y;		

		map<ll,ll> m;

		for(i=1;i<n;i++)
		{
			for(j=i+1;j<=n;j++)
			{
				// cout<<i<<' '<<j<<' ';
				if(i<=x and j<y)
				{
					z=min(j-i,((x-i+1+y-j)));
					m[z]++;
				}
				else if(i<=x and j>=y)
				{
					z=min(j-i,(x-i+j-y+1));
					m[z]++;
					// cout<<m[(j-i)-(y-x)]<<endl;
				}
				else if(i>x)
				{
					z=min(j-i,(i-x+1+abs(y-j)));
					m[z]++;
				}
				else	{m[(j-i)]++;}
			}
		}

		for(i=1;i<n;i++)	cout<<m[i]<<endl;
 	
 	}
	cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
		
		
return 0;
}

Measured memory_bytes: 384
import java.io.PrintWriter
import java.util.*
import kotlin.collections.HashSet

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}


fun main() {
    val S = next()
    val K = nextInt()
    val queue = PriorityQueue<String>(S.map { it.toString() }.distinct())
    repeat(K - 1) {
        val s = queue.poll()
        val ps = S.indicesOf(s)
        val set = HashSet<String>()
        for (p in ps) {
            if (p + s.length >= S.length) continue
            set.add(S.substring(p, p + s.length + 1))
        }
        queue.addAll(set)
    }
    println(queue.poll())
}

fun String.indicesOf(s: String): List<Int> {
    val ret = ArrayList<Int>()
    var p = 0
    while (true) {
        val index = indexOf(s, p)
        if (index < 0) break
        ret.add(index)
        p = index + 1
    }
    return ret
}

Measured memory_bytes: 40504
#include<stdio.h>
#include<bits/stdc++.h>
 
#define get(a, i, j) *((*(a+i))+j)
 
typedef long long ll;
 
int N;
ll W, rec[101][2], mem[105][100005];
 
ll dp(int pos, ll cw); // cw = cumulative weight
 
int main()
{
    //freopen("input.txt", "r", stdin);
    memset(mem, -1, sizeof(mem));
 
    int i;
    scanf("%d%lld", &N, &W);
 
    for(i=0; i<N; ++i) scanf("%lld%lld", &get(rec, i, 0), &get(rec, i, 1));
 
    ll v1;
    v1 = dp(0, 0);
    //v2 = dp(0, 0);
 
    printf("%lld\n",v1);
 
    return 0;
}
 
 
ll dp(int pos, ll cw)
{
    //printf("Inside dp with pos = %d & cw = %lld\n", pos, cw);
    if(pos >= N || cw > W) {
        //printf("returning 0\n\n");
        return 0;
    }
    if(get(mem, pos, cw) > -1) {
        //printf("returning %lld from mem\n\n", get(mem, pos, cw));
        return get(mem, pos, cw);
    }
 
    ll w = get(rec, pos, 0);
 
    ll v1 = 0, v2 = 0;
 
    if((cw + w <= W ) ) {
        //printf("going to next pos including weight\n");
        v1 = get(rec, pos, 1);
        v1 += dp(pos+1, cw + w);
    }
 
    //printf("going to next pos excluding weight\n");
    v2 = dp(pos+1, cw);
 
 
    //printf("returning value either %lld or %lld\n\n", v1, v2);
    return get(mem, pos, cw) = (v1>v2)? v1:v2;
}

Measured memory_bytes: 82304
package main

import (
	"fmt"
	"sort"
)

func getArray(m map[rune]int) (a []int) {
	a = make([]int, len(m))
	index := 0
	for _, v := range m {
		a[index] = v
		index++
	}
	return
}

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	sm := make(map[rune]int, len(s))
	for _, v := range s {
		sm[v]++
	}
	sa := getArray(sm)
	sort.Ints(sa)

	tm := make(map[rune]int, len(t))
	for _, v := range t {
		tm[v]++
	}
	ta := getArray(tm)
	sort.Ints(ta)

	if len(sa) != len(ta) {
		fmt.Println("No")
		return
	}

	for i := range sa {
		if sa[i] != ta[i] {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef pair<int,int> P;
typedef pair<double,double> P_f;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define bitrep(bit,n) for(int bit=0; bit<=(1<<n);bit++)
#define MAX 100100
#define MAX_N 200100
#define MAX_T 2001001
#define SENTINEL 20010010010
#define NIL -1
static const int INF = 1 << 29;
const ll INFTY = 1LL<<50;
const int MOD=1e9+7;
ll n,x,a[MAX];
ll sum[MAX];
int main(){
    memset(sum,0,sizeof(sum));
    cin>>n>>x;rep(i,n)cin>>a[i];
    ll sum=0;
    rep(i,n-1){
        ll dif=a[i]+a[i+1]-x;
        if(dif>0){
            if(dif>a[i+1]){
                sum+=a[i+1];
                sum+=dif-a[i+1];
                a[i+1]=0;
                a[i]-=dif-a[i+1];
            }
            else {
                sum+=dif;
                a[i+1]-=dif;
            }
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	cin >> N;
	vector< int > A(N);
	int S = 0;
	rep(i, N) {
		cin >> A[i];
		S += A[i];
	}
	K = N * (N + 1) / 2;
	if (S % K) {
		cout << "NO" << endl;
		return 0;
	}
	K = S / K;
	vector< int > B(N);
	rep(i, N) B[i] = A[(i + 1) % N] - A[i] - K;
	rep(i, N) {
		if (B[i] > 0 || B[i] % N) {
			cout << "NO" << endl;
			return 0;
		}
		K += B[i] / N;
	}
	if (K)
		cout << "NO" << endl;
	else
		cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;

long long x[100001];
long long v[100001];
long long cw[100001];
long long counter_cw[100001];
long long cw_ret[100001];
long long counter_cw_ret[100001];
long long best_cw_ret[100001];
long long best_counter_cw_ret[100001];

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    long long n, c;
    cin >> n >> c;

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

    long long cur_sum = 0;
    long long best_val = 0;
    for(int i = 0; i < n; ++i) {
        cur_sum += v[i];
        cw[i] = cur_sum - x[i];
        cw_ret[i] = cur_sum - 2 * x[i];
        best_val = max(best_val, cw_ret[i]);
        best_cw_ret[i] = best_val;
    }

    cur_sum = 0;
    best_val = 0;
    for(int i = n - 1; i >= 0; --i) {
        cur_sum += v[i];
        counter_cw[i] = cur_sum - (c - x[i]);
        counter_cw_ret[i] = cur_sum - 2 * (c - x[i]);
        best_val = max(best_val, counter_cw_ret[i]);
        best_counter_cw_ret[i] = best_val;
    }

    long long res = 0;
    for(int i = 0; i < n; ++i) {
        long long cur_res = cw[i];
        if(i != n - 1) cur_res += best_counter_cw_ret[i + 1]; 
        res = max(cur_res, res);
    }
    for(int i = n - 1; i >= 0; --i) {
        long long cur_res = counter_cw[i];
        if(i != 0) cur_res += best_cw_ret[i - 1];
        res = max(cur_res, res);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 6528
MOD = 10**9 + 7
list_size = 200001

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size - 1):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)

f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)

for i in range(2, list_size + 1):
	f_r_list[-i] = int((f_r_list[-i + 1] * (list_size + 2 - i)) % MOD)

def comb(n, r):
	if n < r:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD 

n, m, k = map(int, input().split())
print(((n+m)*k*(k-1))*comb(n*m, k)*f_r_list[2]%MOD)

Measured memory_bytes: 18804
#include<iostream>
#include<string>
using namespace std;
 
int main(){
	int N;
	string S;
	bool map[100];
	string ANS;
	cin>>N;
	cin>>S;
	for(int i=0;i<N;i++){
		map[i]=true;
	}
	for(int i=0;i<N;i++){
		if(S[i]=='(' && map[i]){
			for(int j=i+1;j<N;j++){
				if(S[j]==')' && map[j]){
					map[i]=false;
					map[j]=false;
					break;
				}
			}
		}
	}
	ANS=S;
	for(int i=0;i<N;i++){
		if(map[i]){
			if(S[i]=='('){
				ANS=ANS+")";
			}
			else{
				ANS="("+ANS;
			}
		}
	}
	cout<<ANS<<endl;
	return 0;
}

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

using namespace std;

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))

template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
}

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << 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) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif



void solve()
{
    long long n;
    cin>>n;

    vector<long long> mons(n+1),heros(n);

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

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

    long long res=0;

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

        long long res1=min(heros[i],mons[i]);
        long long rem=heros[i]-res1;
        //debug(rem);
        long long res2=min(rem,mons[i+1]);
        mons[i+1]=mons[i+1]-res2;

        //debug(res1,res2);

        res+=res1+res2;
    }

    cout<<res<<endl;
}

int main()
{
    int t=1;

    while (t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int a,b,c,d,e; cin>>a>>b>>c>>d>>e;
    int h=c-a, m=d-b;
    int ans=h*60+m-e;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <tuple>
#include <map>
using namespace std;

#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)

typedef pair<int, int> PII;

pair<int, bool> caves[1001][1001];
bool seive[2000001];

int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

void make_seive(void) {
  for (int i = 0; i <= 2000000; i++) {
    seive[i] = true;
  }

  seive[0] = seive[1] = false;

  for (int i = 2; i * i <= 2000000; i++) {
    if (!seive[i]) continue;
    for (int j = i * i; j <= 2000000; j += i) {
      seive[j] = false;
    }
  }
}

PII make_caves(int s, int n) {
  int x = s / 2;
  int y = s / 2;

  int cave_no = 1;
  int move_no = 0;
  int move_limit = 1;

  PII start_point;

  while (cave_no < s * s) {
    for (int i = 0; i < 2; i++) {

      for (int j = 0; j < move_limit; j++) {
        caves[y][x].first = cave_no;
        caves[y][x].second = seive[cave_no];

        if (cave_no == n) {
          start_point.first = x;
          start_point.second = y;
        }

        x += dx[move_no];
        y += dy[move_no];

        cave_no++;
      }

      move_no++;
      move_no %= 4;
    }

    move_limit++;
  }

  return start_point;
}

map<PII, pair<int, PII>> memo;

pair<int, PII> dfs(int x, int y, int s, int cave_no_limit) {
  if (memo.count(PII(x, y))) return memo[PII(x,y)];

  pair<int, PII> ret;
  ret.first = caves[y][x].second;
  ret.second = PII(x, y);

  pair<int, PII> max_route;
  max_route.first = 0;
  max_route.second = PII(-1, -1);

  for (int d = -1; d <= 1; d++) {
    if (x + d < 0 || x + d >= s || y + 1 < 0 || y + 1 >= s) {
      continue;
    }

    if (caves[y+1][x+d].first > cave_no_limit) {
      continue;
    }

    pair<int, PII> route = dfs(x + d, y + 1, s, cave_no_limit);

    if (route.first == 0) continue;

    if (route.first > max_route.first) max_route = route;
    else if (route.first == max_route.first) {
      int rx = route.second.first;
      int ry = route.second.second;

      int mrx = max_route.second.first;
      int mry = max_route.second.second;

      if (caves[mry][mrx].first < caves[ry][rx].first) {
        max_route = route;
      }
    }
  }


  ret.first += max_route.first;
  if (max_route.first != 0) {
    ret.second = max_route.second;
  }

  return memo[PII(x,y)] = ret;
}

void dump_caves(int s, int x, int y) {
  for (int i = 0; i < s; i++) {
    for (int j = 0; j < s; j++) {
      char mark;
      if (j == x && i == y) mark = '!';
      else if (caves[i][j].second) mark = 'o';
      else mark = ' ';

      printf("%2d[%c] ", caves[i][j].first, mark);
    }
    printf("\n");
  }
}

int main(void) {
  int m, n;
  make_seive();

  while (cin >> m >> n, m && n) {
    memo.clear();

    int s = 1;
    while (s * s < m) s += 2;
    
    int x, y;
    tie(x, y) = make_caves(s, n);

    pair<int, PII> res = dfs(x, y, s, m);

    int cnt = res.first;
    int cave_no = caves[res.second.second][res.second.first].first;

    if (cnt == 0)
      cave_no = 0;

    cout << cnt << " " << cave_no << endl;
  }
  return 0;
}

Measured memory_bytes: 50944
#include<bits/stdc++.h>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		 int F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
	long long G()
	{
		 long long F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
}
int R(int l,int r)
{
	return (rand()<<15|rand())%(r-l+1)+l;
}
const int C=131072;
int n,m;
struct graph
{
	long long dis[111111];
	long long dm[133333];
	int min[266666];
	struct edge
	{
		int to;
		int val;
		int next;
	}e[777777];
	int pe;
	graph(){pe=111112;}
	void insert(int a,int to,int val)
	{
		e[pe]=(edge){to,val,e[a].next};
		e[a].next=pe++;
	}
	int s;
	void mdf(int p,long long v)
	{
		dm[p]=v;
		for(register int i=p+C>>1;i;i>>=1)
			min[i]=dm[min[i<<1]]<dm[min[i<<1|1]]?min[i<<1]:min[i<<1|1];
	}
	void init()
	{
		for(register int i=0;i<C;++i)dis[i]=dm[i]=0x3f3f3f3f3f3f3f3fll,min[i+C]=i;
		for(register int i=C-1;i;--i)min[i]=min[i<<1];
	}
	void sp()
	{
		init();
		dis[s]=0;
		mdf(s,0);
		for(register int i=1;i<n;++i)
		{
			int o=min[1];
			mdf(o,0x3f3f3f3f3f3f3f3fll);
			for(register int p=e[o].next;p;p=e[p].next)
				if(cmin(dis[e[p].to],dis[o]+e[p].val))
					mdf(e[p].to,dis[e[p].to]);
		}	
	}
}gs,gt;
long long ans[111111];
int main()
{
	n=io::F(),m=io::F();
	int s=io::F(),t=io::F();
	gs.s=s,gt.s=t;
	for(register int i=1;i<=m;++i)
	{
		int u=io::F(),v=io::F(),a=io::F(),b=io::F();
		gs.insert(u,v,a);
		gt.insert(u,v,b);
		gs.insert(v,u,a);
		gt.insert(v,u,b);
	}
	gs.sp();
	gt.sp();
	for(register int i=1;i<=n;++i)ans[i]=gs.dis[i]+gt.dis[i];
	for(register int i=n-1;i;--i)cmin(ans[i],ans[i+1]);
	for(register int i=1;i<=n;++i)
		printf("%lld\n",1000000000000000ll-ans[i]);
	return 0;
}


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

main(){
  int t, n;
  int V[5] = {0, 6000, 4000, 3000, 2000};
  int F[5] = {0, 0, 0, 0, 0};

  for ( int i = 0; i < 4; i++ ){
    cin >> t >> n;
    cout << V[t]*n << endl;
  }
}

Measured memory_bytes: 1164
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, t: "List[int]", x: "List[int]", y: "List[int]"):
    t.insert(0,0)
    x.insert(0,0)
    y.insert(0,0)
    for i in range(1,N+1):
        if t[i]%2 != (x[i]+y[i])%2:
            print("No")
            return 
        if t[i]<abs(x[i]-x[i-1])+abs(y[i]-y[i-1]):
            print("No")
            return 
    print("Yes")
    

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    t = [int()] * (N)  # type: "List[int]"
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        t[i] = int(next(tokens))
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, t, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 11636
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int a, b;

void solve()
{
    cin >> a >> b;
    nout((a>2*b)?(a-2*b):0);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define inf INT_MAX/3
#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define all(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define PII pair<int,int>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define LL long long
#define ll long long
#define ULL unsigned long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second
using namespace std;
int main(){
string str;
cin>>str;
REP(i,4)cout<<str[i];
cout<<" ";
REP(i,8)cout<<str[i+4];
cout<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n,i=0,syo;
        n=scan.nextInt();

        while(i<n){
            i++;
        if(i%3==0){
            System.out.print(" "+i);
            continue;
        }
        syo=i;
        while(syo!=0){
            if(syo%10==3){
                System.out.print(" "+i);
                break;
            }
            syo/=10;
        }
        
    }
    System.out.println("");

    }
}


Measured memory_bytes: 28724
//abc050_a.cpp
//Fri Oct 19 22:47:46 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int a,c;
	char b;
	cin >> a >> b >> c;

	if (b == '+'){
		cout << a+c << endl;
	}else {
		cout << a-c << endl;
	}
}

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

int main()
{
    int n;
    float m;
    cin>>n>>m;

    int arr[n], i, sum=0, count=0;

    for(i=0; i<n; i++){
        cin>>arr[i];
        sum = sum + arr[i];
    }

    for(i=0; i<n; i++){
        if(arr[i] >= ((1/(4*m))*sum))
            count++;
    }

    if(count >= m)
        cout<<"Yes";
    else
        cout<<"No";


}


Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>

int field[50][50];

using namespace std;

void searchbombs(int a, int b, int c, int d, int n) {
	int i, j, ans, m;

	//printf("searchbombs(%ld, %ld, %ld, %ld, %ld);\n", a, b, c, d, n);

	if (n == 0) return;

	if (n == (c - a + 1) * (d - b + 1)) {
		for (i = a; i <= c; i++) {
			for (j = b; j <= d; j++) {
				field[i][j] = 1;
				//cout << i << " " << j << endl;
			}
		}
		return;
	}

	if (c - a > d - b) {
		m = (a + c) / 2;
		printf("? %d %d %d %d\n", a, b, m, d);
		cin >> ans;
		searchbombs(a, b, m, d, ans);
		searchbombs(m + 1, b, c, d, n - ans);
	} else {
		m = (b + d) / 2;
		printf("? %d %d %d %d\n", a, b, c, m);
		cin >> ans;
		searchbombs(a, b, c, m, ans);
		searchbombs(a, m + 1, c, d, n - ans);
	}
	return;
}

int main(void) {
	long long int i, j, H, W, N, K;
	long long int x, ans = 0;


	cin >> H >> W >> N >> K;

	searchbombs(0, 0, H-1, W-1, N);

	x = 1;

	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			//cout << field[j][i];
			ans += field[i][j] * x;
			ans %= K;
			x *= 2;
			x %= K;
		}
	}

	printf("! %lld\n", ans);

	system("pause");

	return 0;
}


Measured memory_bytes: 716
from math import *
N = int(input())
T = []
A = []
for i in range(0, N):
    ti, ai = [int(x) for x in input().split()]
    T.append(ti)
    A.append(ai)

prevT = T[0]
prevA = A[0]
for i in range(1, N):
    nextfacT = int(ceil((prevT + T[i] - 1) // T[i]))
    nextfacA = int(ceil((prevA + A[i] - 1) // A[i]))
    nextfac = max(nextfacT, nextfacA)
    prevT = nextfac * T[i]
    prevA = nextfac * A[i]

print(prevA+prevT)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
  
using namespace std;
  
int LevenshteinDistance(string s, string t) {
    
  int len_s = s.size();
  int len_t = t.size();
    
  vector<vector<int> > dp(len_s+1, vector<int>(len_t+1, 0));
  
  for(int i=0; i<=len_s; i++)
    dp[i][0] = i;
    
  for(int i=0; i<=len_t; i++)
    dp[0][i] = i;
    
  int cost;
  for(int i=1; i<=len_s; i++) {
    for(int j=1; j<=len_t; j++) {
      if(s[i-1] == t[j-1]) cost = 0;
      else cost = 1;
        
      dp[i][j] = min(dp[i-1][j] + 1, min(dp[i][j-1] + 1, dp[i-1][j-1] + cost));
    }
  }
    
  return dp[len_s][len_t];
}
  
int main() {
    
  string s, t;
    
  std::cin >> s >> t;
    
  std::cout << LevenshteinDistance(s, t) << endl;
    
  return 0;
}


Measured memory_bytes: 6848
#include <iostream>
#include <cstring>
#include <cstdio>

#define Maxn 200010
#define LL long long

using namespace std;

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

int n, a[Maxn];

struct Edge {
    int next, to;
}
edge[Maxn * 2];
int head[Maxn], edge_num;

void add_edge(int from, int to) {
    edge[++edge_num].next = head[from];
    edge[edge_num].to = to;
    head[from] = edge_num;
}

bool vis[Maxn];

int main() {
    n = read();
    int u, v;
    for(int i = 1; i < n; ++i) {
        u = read(); v = read();
        add_edge(u, v);
        add_edge(v, u);
    }
    LL ans = 0, res = 0;
    for(int u = 1; u <= n; ++u) {
        int cnt = 0;
        for(int i = head[u]; i; i = edge[i].next) {
            int v = edge[i].to;
            if(vis[v]) ++cnt;
        }
        a[u] = a[u - 1] + 1 - cnt;
        res += a[u];
        vis[u] = 1;
    }
    ans = res;
    for(int u = 2; u <= n; ++u) {
        // cout << res << endl;
        res -= (n - u + 1);
        --res;
        for(int i = head[u - 1]; i; i = edge[i].next) {
            int v = edge[i].to;
            if(v >= u) res += (n - v + 1);
        }
        ans += res;
    }
    cout << ans << endl;
    return 0;
}

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



int main()
{
 
    int n,num,aaa=0,i;
    cin >> n;
 
    int a[200000];
    for (i = 0; i < n; i++) {
        cin >> a[i];

    }

    std::sort(a, a+n);
//    res = 1;
    for (num = 0; num < n-1; num++) {
  //      for (num2 = res; num2 <= n; num2++) {
            if (a[num] == a[num+1]) {


                cout << "NO" << endl;
                return 0;
            }
    //    }
    //    res++;

    }
 //   cout << aaa;

 //   if (aaa==1) {
        // 出力
 //   }
//    else {

        // 出力
        cout << "YES" << endl;

  //  }

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if (a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if (c <= a && a <= b)
        cout << b << " " << a <<" " << c << endl;
    else if (c <= b && b <= a)
        cout << c << " " << b << " " << a << endl;
    else if (b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else if (c <= a && a <= b)
        cout << c << " " << a << " " << b << endl;
    
 

}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
int main()
{
        ll a,b,sum=1,f=0;
        cin>>a>>b;
        for(int i=20;i<=b;i++)
        {
                ll  c=i,flag=0;
                while(1){
                      ll b=(c%10) ;
                      if(b<2) flag=1;
                      sum*=b;
                      c=(c/10);
                      if(c==0) break;
                }
                if(flag==0){
                if(sum<=a) f++;
                }
                sum=1;
        }
        cout<<f<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String a=sc.next();
		int ax=Integer.parseInt(a,16);

		String b=sc.next();
		int bx=Integer.parseInt(b,16);

		if(ax>bx) {
			System.out.println(">");
		}

		else if(ax==bx) {
			System.out.println("=");
		}

		else if(ax<bx) {
			System.out.println("<");
		}
	}
}

Measured memory_bytes: 21716
a, b, c, d = map(int, input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

e = lcm(c, d)

x = b - a + 1
y = b // c - (a - 1) // c
z = b // d - (a - 1) // d
w = b // e - (a - 1) // e

print(x - y - z + w)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

int main() {
	string S, T = "";
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'b') T = T + 'd';
		if (S[i] == 'd') T = T + 'b';
		if (S[i] == 'p') T = T + 'q';
		if (S[i] == 'q') T = T + 'p';
	}
	reverse(T.begin(), T.end());
	if (S == T) cout << "Yes";
	else cout << "No";
}

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

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pair<ll,ll>> vii;
typedef vector<vii> vvii;
typedef pair<ll,ll> ii;
typedef unordered_map<ll,ll> umii;
typedef unordered_set<ll> usi;

#define pb push_back
#define mp make_pair
#define sz(vs) (ll)(vs.size())
#define rep(i,a,b) for (ll i=a;i<b;i++)
#define iter(i,c) for (auto i:c)
#define printarr(a,st,e,s) cout<<s<<a[st];rep(noname,st+1,e) cout<<" "<<a[noname];cout<<"\n"
// #define printarr(a,st,e,s) cout<<s<<": ["<<a[st];rep(noname,st+1,e) cout<<", "<<a[noname];cout<<"]\n"
#define printus(c,s) cout<<s<<": {";for (auto noname:c) cout<<noname<<",";cout<<"}\n"
#define printum(c,s) cout<<s<<": {";for (auto noname:c) cout<<noname.first<<":"<<noname.second<<", ";cout<<"}\n"
#define MAXN 100005

ll n,m;

void solve() {
	cin>>n>>m;
 cout<<(n*m);
}

void aux() {
}

int main() {
	aux();
	ll _ = 1;
	// cin>>_;
	while(_--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 3636
#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; 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;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N, Q; cin >> N >> Q;
  dsu d(N);
  rep(i, Q) {
    ll t, u, v;
    cin >> t >> u >> v;
    if(t == 0) {
      d.merge(u,v);
    } else {
      cout << ((d.same(u, v))?1:0) << endl;
    }
  }
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 4036
N,D = map(int,input().split())
def dist(p1,p2,d):
    g = 0
    for i in range(d):
        g += abs(p1[i]-p2[i])**2
    g2 = int(g**(0.5))
    return g**(0.5) == g2

p = []
for _ in range(N):
    l = list(map(int,input().split()))
    p.append(l)

c = 0
for i in range(N):
    for j in range(N):
        if i < j:
            if dist(p[i],p[j],D):
                c += 1
print(c)

Measured memory_bytes: 3064
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static int N;
        static long mod = 1000000007;
        static char[] az = Enumerable.Range('a', 'z' - 'a' + 1).Select(i => (Char)i).ToArray();
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var B = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            //var N = long.Parse(Console.ReadLine());
            //var A = new int[N];
            var C = new long[N];
            long sum = 0L;
            for (int i = 0; i < N; i++)
            {
                C[i] = A[i] - B[i];

                if(C[i] < 0)
                {
                    var tmp = Abs(C[i]);
                    sum += (tmp+1) / 2;
                    C[i] = ((tmp % 2 == 0) ? 0 : 1);
                }
            }

            if(sum >= C.Sum())
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

            
            //R = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            //var S = Console.ReadLine();

        }
        // ユークリッドの互除法 
        public static int Gcd(int a, int b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }
}


Measured memory_bytes: 30500
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	N := sc.nextInt()
	M := sc.nextInt()
	X := sc.nextInt()
	C := make([]int, N)
	A := make([][]int, N)
	for i := 0; i < N; i++ {
		C[i] = sc.nextInt()
		A[i] = make([]int, M)
		for j := 0; j < M; j++ {
			A[i][j] = sc.nextInt()
		}
	}

	ans := math.MaxInt64

	for s := 0; s < 1<<N; s++ {
		cost := 0
		m := make([]int, M)
		for i := 0; i < N; i++ {
			if (s>>i)&1 == 1 {
				cost += C[i]
				for j := 0; j < M; j++ {
					m[j] += A[i][j]
				}
			}
		}
		ok := true
		for j := 0; j < M; j++ {
			if m[j] < X {
				ok = false
				break
			}
		}
		if ok {
			if ans > cost {
				ans = cost
			}
		}
	}

	if ans == math.MaxInt64 {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

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

    ll a[n];
    int four = 0;
    int two = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] % 4 == 0){
            four++;
        }else if(a[i] % 2 == 0){
            two++;
        }
    }

    int len = n;
    int flag = 0;

    if(two == 0){
        flag = 1;
    }

    for(int i = two; i < n; i++){
        if(four != 0 && flag == 0){
            four--;
            flag = 1;
        }else if(flag == 1){
            flag = 0;
        }else if(flag == 0){
            flag = 2;
            break;
        }
    }

    if(flag != 2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n = INT()
a = LIST()

c = [1]*(n+1)
for i in range(1, n+1):
    c[i] = (c[i-1]-a[i-1])*2
if a[n]>c[n]:
    print(-1)
    sys.exit()
b = [0]*(n+1)
res = [0]*(n+1)
b[n] = a[n]
res[n] = a[n]
for i in range(n-1, -1, -1):
    if (c[i]-a[i])*2 <res[i+1]:
        print(-1)
        sys.exit()
    b[i] = min(c[i]-a[i], res[i+1])
    res[i] = a[i] + b[i]
print(sum(res)) 

Measured memory_bytes: 707244
#include <stdio.h>

int main(void)
{
	int a,o,j;
	
	for(a=1;a<=9;a++){
		for(j=1;j<=9;j++){
			o=a*j;
			printf("%dx%d=%d\n",a,j,o);
		}
	}
	return 0;
}

Measured memory_bytes: 524
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def comb(n, k):
    if n < 0 or n < k or k < 0:
        return 0
    return fac[n] * ifac[k] * ifac[n - k] % mod


n, k, *a = map(int, read().split())
a.sort()
mod = 10 ** 9 + 7
ans = 0
fac = [1] * n
inv = [1] * n
ifac = [1] * n
for i in range(2, n):
    fac[i] = fac[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    ifac[i] = ifac[i - 1] * inv[i] % mod
for i, aa in enumerate(a):
    ans += aa * (comb(i, k - 1) - comb(n - 1 - i, k - 1))
    ans %= mod
print(ans)


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int n;cin >>n;
    vector<int>l(n);
    for (int i = 0; i < n; ++i) {
        cin >>l[i];
    }
    sort(all(l));
    int ans=0;
    for (int i = 0; i < n-1; ++i) {
        for (int j = i+1; j < n; ++j) {
            int sum=l[i]+l[j];
            int k=lower_bound(all(l),sum)-l.begin();
            if(k>=n)k--;
            if(l[k]>=sum)k--;
            ans+=k-j;
//            cout <<i<<" "<<j<<" "<<k<<endl;
        }
    }
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 3620