akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n, m, k; cin >> n >> m >> k;
    rep(h,n+1)rep(w,m+1) {
        auto f = [&](int h, int w) {return h*m-2*h*w+w*n;};
        if (f(h,w) == k) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"

using namespace std;

void Main() {
    int X, N;
    cin >> X >> N;
    set<int> p;
    for (int i = 0; i < N; ++i) {
        int ptemp;
        cin >> ptemp;
        p.insert(ptemp);
    }

    int ans = 0;
    for (int i = 0; i < 150; ++i) {
        if (p.count(X - i) == 0) {
            ans = X - i;
            break;
        }
        else if (p.count(X + i) == 0) {
            ans = X + i;
            break;
        }
        else {
            continue;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a<b){
        cout << "a < b" << endl;
    }else if(a == b){
        cout << "a == b" << endl;
    }else{
        cout << "a > b" << endl;
    }
}


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

int main(){
    int N; cin >> N; int sum = 0; string S = to_string(N);
    for (int i = 0; i < S.size(); i++) sum += (S[i]-'0');

    if (N % sum == 0) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
#include<numeric>
using namespace std;
typedef long long ll;
//ll mod = 1e9+7;
ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> hw(h, vector<char>(w));
    vector<vector<int>> cnt_v(h);
    vector<vector<int>> ans(h, vector<int>(w, 1e8));
    vector<int> check(h, 0);
    rep(i, h) rep(j, w) {
        cin >> hw[i][j];
        if ( hw[i][j] == '#' ) {
            ++check[i];
        }
    }
//    rep(i, h) {
//        for ( auto tmp_num : cnt_v[i] ) {
//            cout << tmp_num << " ";
//        }
//        cout << endl;
//    }
    int cnt = 1;
    rep(i, h) {
        if ( check[i] == 0 ) {
            continue;
        }
        rep(j, w) {
            ans[i][j] = cnt;
            if ( hw[i][j] == '#' && check[i] > 1 ) {
                ++cnt;
                --check[i];
            }
        }
        ++cnt;
    }
    for ( int i = 1; i < h; ++i ) {
        if ( ans[i][0] == 1e8 ) {
            copy(ans[i-1].begin(), ans[i-1].end(), ans[i].begin());
        }
    }
    for ( int i = h - 2; i >= 0; --i ) {
        if ( ans[i][0] == 1e8 ) {
            copy(ans[i+1].begin(), ans[i+1].end(), ans[i].begin());
        }
    }
    rep(i, h) {
        rep(j, w) {
            if ( j != 0 ) {
                cout << " ";
            }
            cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i = s; i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,0,h) cin >> s[i];
  vector<vector<int>> yoko(h, vector<int>(w,0));
  rep(i,0,h) {
    rep(j,0,w) {
      if (j == 0) {
        if (s[i][j] == '.') yoko[i][j] = 1;
        continue;
      }
      if (s[i][j] == '.') yoko[i][j] = yoko[i][j-1] + 1;
    }
    rrep(j,w-1,0) {
      if (yoko[i][j] == 0 || yoko[i][j+1] == 0) continue;
      yoko[i][j] = yoko[i][j+1];
    }
  }
  vector<vector<int>> tate(h, vector<int>(w,0));
  rep(i,0,w) {
    rep(j,0,h) {
      if (j == 0) {
        if (s[j][i] == '.') tate[j][i] = 1;
        continue;
      }
      if (s[j][i] == '.') tate[j][i] = tate[j-1][i] + 1;
    }
    rrep(j,h-1,0) {
      if (tate[j][i] == 0 || tate[j+1][i] == 0) continue;
      tate[j][i] = tate[j+1][i]; 
    }
  }
  int ans = 0;
  rep(i,0,h) rep(j,0,w) {
    ans = max(ans, yoko[i][j] + tate[i][j] - 1);
  }
  cout << ans << endl;
  return 0;
}


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

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

    long long mn = 1e12;
    for(long long i=2;i<=sqrt(n);i++){
        if(n%i==0){
            mn = min(mn,i-1+(n/i)-1);
        }
    }
    if(mn==1e12)cout<<n-1<<'\n';
    else cout<<mn<<'\n';
}


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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  string S; cin >> S;

  if(S[2] == S[3] && S[4]==S[5]){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3608
#include <iostream>

using namespace std;

typedef long long ll;

ll l[200005];
ll r[200005];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if (i + a < n)
            l[i + a]++;
        if (i - a >= 0)
            r[i - a]++;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += l[i] * r[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 6724
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int main(){
    string s; cin >> s;
    int xx , yy; cin >> xx >> yy;
    vector<int> x,y;
    bool nowx = true;
    int count =0;
    int tcount = 0;
    bool minusx=false;
    REP(i,s.length()){
        if(nowx){
            if(s[i]=='F'){
                if(tcount!=0&&x.size()==0){
                    minusx = true;
                }
                count++;
                if(i==s.size()-1){
                    x.push_back(count);
                }
            }else{
                tcount++;
                if(count!=0){
                    x.push_back(count);
                    count =0;
                }
                nowx = false;
            }
        }else{
            if(s[i]=='F'){
                count++;
                if(i==s.size()-1){
                    y.push_back(count);
                }
            }else{
                tcount++;
                if(count!=0){
                    y.push_back(count);
                    count =0;
                }
                nowx = true;
            }
        }
    }
    bool ansx, ansy ;
    if(x.size()!=0 ){
        set<int> xdp[x.size()];
        xdp[0].insert(x[0]);
        if(minusx)xdp[0].insert(-x[0]);
        REP(i,x.size()-1){
            auto it = xdp[i].begin();
            while(it!=xdp[i].end()){
                xdp[i+1].insert(*it+x[i+1]);
                xdp[i+1].insert(*it-x[i+1]);
                it++;
            }
        }
       if(xdp[x.size()-1].count(xx)==1){
            ansx = true;
        }else{
            ansx = false;
        }
    }else{
        if(xx==0){
            ansx = true;
        }else{
            ansx = false;
        }

    }
    if(y.size()!=0){
        set<int> ydp[y.size()];
        ydp[0].insert(y[0]);
        ydp[0].insert(-y[0]);
        REP(i,y.size()-1){
            auto it = ydp[i].begin();
            while(it!=ydp[i].end()){
                ydp[i+1].insert(*it+y[i+1]);
                ydp[i+1].insert(*it-y[i+1]);
                it++;
            }
        }
       if(ydp[y.size()-1].count(yy)==1){
            ansy = true;
        }else{
            ansy = false;
        }
    }else{
        if(yy==0){
            ansy = true;
        }else{
            ansy = false;
        }
    }
    if(ansx && ansy){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 167296
#include<bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0);
using namespace std;
ll a , b  , cnt , n , m , ans , mn;
int main(){
    string s;
    cin >> s;
    if( int(s.find('7')) >= 0 )
        cout << "Yes";
    else
        cout << "No";
}
/// ab#c ad#c
/// ab## c#d#

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

	int n;
	cin >> n;

	vector<vector<int>> col(2, vector<int>(n, 0));
	rep (i, 0, n)
		cin >> col[0][i];
	rep (i, 0, n)
		cin >> col[1][i];

	int res = 0;
	int sum = 0;
	rep (i, 0, n)
		sum += col[0][i];
	sum += col[1][n - 1];
	res = sum;

	for (int i = n - 1; i > 0; i--) {
		sum += col[1][i - 1] - col[0][i];
		res = max(res, sum);
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#pragma GCC optimize("unroll-loops")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define ST string
#define BS bitset
#define VE vector
#define VL vector<LL>
#define VP vector<pair<LL,LL>>
#define VVL vector<vector<LL>>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define EB emplace_back
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define LB(a,n) *lower_bound(ALL(a),n)
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000000000001
#define NUM 200010
#define FAST cin.tie(0);ios::sync_with_stdio(false)

void Yn(LL a){if(a)printf("Yes\n");else printf("No\n");}
void YN(LL a){if(a)printf("YES\n");else printf("NO\n");}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(m,d);x-=k*y;swap(x,y);}return mod(a*mod(x,MOD),MOD);}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(pair<LL,LL> a,pair<LL,LL> b){if(a.second!=b.second)return a.second<b.second;return a.first<b.first;}

LL N;
VVL g(NUM);
map<LL,LL> dps[NUM],dpa[NUM];
LL dfs(LL i,LL p,LL f=0){
  if(dpa[i].count(p))return dpa[i][p];
  LL n=g[i].size(),ret=1,s=0;
  if(p!=-1)n--;
  if(f||p==-1){
    for(LL j:g[i])if(j!=p){
      ret*=(dfs(j,i,f)*finv[dps[j][i]+1])%MOD;
      ret%=MOD;
      s+=dps[j][i]+1;
    }
    dps[i][p]=s;
    ret=(ret*fact[s])%MOD;
  }else{
    ret=DIV(ret,dfs(p,i,f));
    dps[i][p]=N-2-dps[p][i];
    s=(fact[dps[i][p]]*fact[dps[p][i]+1])%MOD;
    s=(s*finv[N-1])%MOD;
    ret*=(dfs(i,-1,f)*s)%MOD;
    ret%=MOD;
  }
  return dpa[i][p]=ret;
}

int main(){
  FAST;
  comi();
  LL i,ans=0,a,b;
  cin>>N;
  rep(i,N-1){
    cin>>a>>b;
    g[a].EB(b);
    g[b].EB(a);
  }
  dfs(1,-1,1);
  rep(i,N)cout<<dfs(i+1,-1)<<endl;
}


Measured memory_bytes: 129920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = parseInt(line);
			if (n == 0) {
				break;
			}

			boolean[] cards = new boolean[2 * n + 1];
			TreeSet<Integer> taro, hana, turn;
			taro = new TreeSet<Integer>();
			hana = new TreeSet<Integer>();
			//配る
			for (int i = 0; i < n; i++) {
				cards[Integer.parseInt(br.readLine())] = true;
			}
			for (int i = 1; i < cards.length; i++) {
				if (cards[i]) {
					taro.add(i);
				} else {
					hana.add(i);
				}
			}
			//遊ぶ
			int deck = 0;
			turn = taro;
			while (true) {
				if (turn.ceiling(deck) != null) {
					deck = turn.ceiling(deck);
					turn.remove(deck);
				} else {
					deck = 0;
				}
				if (turn.size() == 0) {
					break;
				}
				if (turn == taro) {
					turn = hana;
				} else {
					turn = taro;
				}
			}
			System.out.println(hana.size() + "\n" + taro.size());
		}
	}
}

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

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define ld long double
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 2e5 + 100;
const int M = (int) 2e6 + 100;
const int K = (int) 200;
const int INF = (int) 1e9 + 7;
const int mod = (int) 998244353;
const ld EPS = (ld) 1e-9;
const ll LINF = (ll) 1e18;

int n, k;
vec v[2];

int main() {
	srand(time(0));
    cin >> n >> k;
    int ptr = 0;
    for (int i = 1, x; i <= n; i++) {
        cin >> x;
        if (x <= 0) {
            v[0].pb(x);
        } else {
            v[1].pb(x);
        }
    }
    reverse(all(v[0]));
    int ans = INF;
    for (int i = 0; i < sz(v[0]); i++) {
        int kk = k - i - 2;
        int c = abs(v[0][i]) * 2;
        if (kk >= sz(v[1])) continue;
        if (kk >= 0) {
            c += v[1][kk];
        }
        ans = min(ans, c);
    }
    for (int i = 0; i < sz(v[1]); i++) {
        int kk = k - i - 2;
        int c = abs(v[1][i]) * 2;
        if (kk >= sz(v[0])) continue;
        if (kk >= 0) {
            c += abs(v[0][kk]);
        }
        ans = min(ans, c);
    }
    if (k <= sz(v[0])) ans = min(ans, -v[0][k - 1]);
    if (k <= sz(v[1])) ans = min(ans, v[1][k - 1]);
    cout << ans;
	return 0;
}


Measured memory_bytes: 1020
def isBingo(listA, listB):
    count = 0
    for i in listA:
        if i in listB:
            count += 1    
        if count == 3:
            return True
    return False


A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
b = []
for i in range(N):
    b.append(int(input()))

tate1 = []
tate1.append(A1[0])
tate1.append(A2[0])
tate1.append(A3[0])

tate2 = []
tate2.append(A1[1])
tate2.append(A2[1])
tate2.append(A3[1])

tate3 = []
tate3.append(A1[2])
tate3.append(A2[2])
tate3.append(A3[2])

naname1 = []
naname1.append(A1[0])
naname1.append(A2[1])
naname1.append(A3[2])

naname2 = []
naname1.append(A1[2])
naname1.append(A2[1])
naname1.append(A3[0])




if isBingo(A1, b):
    print('Yes')
elif isBingo(A2, b):
    print('Yes')
elif isBingo(A3, b):
    print('Yes')
elif isBingo(tate1, b):
    print('Yes')
elif isBingo(tate2, b):
    print('Yes')
elif isBingo(tate3, b):
    print('Yes')
elif isBingo(naname1, b):
    print('Yes')
elif isBingo(naname2, b):
    print('Yes')
else:
    print('No')

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

using namespace std;

int main(void)
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < n - k; i++) {
		cout << (a[i] < a[i + k] ? "Yes" : "No") << endl;
	}
	
	return 0;
}

Measured memory_bytes: 4016
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

bool is_prime(int n)
{
    if(n<=1)
        return false;
    for(int i=2; i*i<=n; i++){
        if(n%i==0)
            return false;
    }
    return true;
}

int gcd(int a, int b)
{
    if(b==0)
        return a;

    return gcd(b, a%b);
}

int main(){
    bool is_prime[1000000];

    is_prime[0] = is_prime[1] = false;

    for(int i=2; i<1000000; i++){
        is_prime[i] = true;
    }

    for(int i=2; i*i<1000000; i++){
        if(is_prime[i]){
            for(int j=i*i; j<1000000; j+=i){
                is_prime[j] = false;
            }
        }
    }

    int n_prime[1000000];

    int cnt = 0;
    for(int i=0; i<1000000; i++){
        if(is_prime[i]){
            cnt++;
        }
        n_prime[i] = cnt;
    }

    while(1){
        int n;
        cin >> n;
        if(cin.eof()){
            break;
        }
        cout << n_prime[n] << endl;
    }
}


Measured memory_bytes: 7884
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, H[25];

int main(){
  cin >> N;
  for (int i = 0; i < N; i++) cin >> H[i];

  int ans = 0, now = 0;
  for (int i = 0; i < N; i++){
    if (now <= H[i]) ans++;
    now = max(now, H[i]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3548
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    char s[60];
    scanf("%s",s);
    if (strlen(s)>9){
        printf("NO\n");
    } else {
        int count=0;
        if (s[0]=='A'){
            if (s[1]=='K' && s[2]=='I' && s[3]=='H'){
                count+=4;
            } else {
                printf("NO\n");
                return 0 ;
            }
        } else if (s[0]=='K' && s[1]=='I' && s[2]=='H'){
            count+=3;
        } else {
            printf("NO\n");
            return 0 ;
        }
        if (s[count]=='A' && s[count+1]=='B'){
            count+=2;
        } else if (s[count]=='B'){
            count+=1;
        } else {
            printf("NO\n");
            return 0 ;
        }
        if (s[count]=='A' && s[count+1]=='R'){
            count+=2;
        } else if (s[count]=='R'){
            count+=1;
        } else {
            printf("NO\n");
            return 0 ;
        }
        if (s[count]=='A' && strlen(s)==count+1){
            printf("YES\n");
        } else if (strlen(s)==count) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
	return 0 ;
}

Measured memory_bytes: 128
if ARGV[0]=="LOCAL_DEV"
  define_method("debug") do |var|
    p var
  end
else
  define_method("debug") do |var|
  end
end

N=STDIN.gets.strip.to_i
S=STDIN.gets.strip
ans=S
i=0
S.chars do |s|
  if s=='('
    i+=1
  else
    if i>0
      i-=1
    else
      ans='('+ans
    end
  end
end
i.times do
  ans+=')'
end
puts ans


Measured memory_bytes: 1788
#include <stdio.h>
#include <assert.h>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp make_pair

#define NUM (120000)
int N, M, Q, Y[NUM];
vector<int> ls[NUM];
pair<int, int> ord[NUM];
int hi[NUM], p[NUM], c[NUM], f[NUM], b[NUM], ans[NUM];
vector<pair<int, int> > a[NUM];

void fix(int k) {
    sort(a[k].begin(), a[k].end());
    f[k] = a[k][0].first;
    c[k] = 0;
    rep (i, a[k].size()) c[k] += a[k][i].second == -1 ? 1 : c[a[k][i].second];
}

void build() {
    Y[M] = -1;
    rep (i, N) hi[i] = -1;
    rep (i, M+1) ord[i] = mp(Y[i], i);
    sort(ord, ord+M+1);
    for (int ik = M; ik > 0; ik--) {
        const int k = ord[ik].second;
        a[k].clear();
        p[k] = -1;
        rep (i, ls[k].size()) {
            const int ix = ls[k][i]-1;
            if (hi[ix] == -1) a[k].push_back(mp(ix, -1));
            else {
                a[k].push_back(mp(f[hi[ix]], hi[ix]));
                assert(p[hi[ix]] == -1);
                p[hi[ix]] = i;
            }
            hi[ix] = k;
        }
        fix(k);
    }
    a[M].clear();
    rep (i, N) if (hi[i] == -1) a[M].push_back(mp(i, -1));
    rep (i, M) if (p[i] == -1) a[M].push_back(mp(f[i], i));
    fix(M);
    b[M] = 0;
    rep (ik, M+1) {
        const int k = ord[ik].second;
        int z = b[k];
        rep (i, a[k].size()) {
            if (a[k][i].second == -1) {
                ans[z] = a[k][i].first;
                z++;
            }
            else {
                b[a[k][i].second] = z;
                z += c[a[k][i].second];
            }
        }
    }
}

int main() {
    for (;;) {
        scanf("%d%d%d", &N, &M, &Q);
        if (N == 0) return 0;
        rep (i, M) {
            scanf("%d", Y+i);
            int L;
            scanf("%d", &L);
            ls[i].resize(L);
            rep (j, L) scanf("%d", &ls[i][j]);
        }
        build();
        rep (i, Q) {
            int q;
            scanf("%d", &q);
            printf("%d\n", ans[q-1]+1);
        }
        printf("\n");
    }
}

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

const int N = 1e5 + 10;
const int mod = 1e9 + 7;
typedef long long ll;

inline ll qpow(ll a, ll b) {
  ll res = 1;
  for (; b; b >>= 1, a = 1ll * a % mod * a % mod) {
    if (b & 1) {
      res = 1ll * res * a % mod;
    }
  }
  return res;  
}

int n, m, i, j, k;
ll dp[N];

int main() {
  scanf("%d %d", &n, &k);
  ll ans = 0;
  for (int i = k; i >= 1; i--) {
    dp[i] = qpow(k / i, n);
    for (int j = i * 2; j <= k; j += i) {
      dp[i] = (dp[i] - dp[j] + mod) % mod;
    }
    ans = (ans + 1ll * i % mod * dp[i] % mod) % mod;
  }
  printf("%lld\n", ans);
  return 0;  
} 


Measured memory_bytes: 4596
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[1000005];
int n,i,j;
int inf=1e9;
int mi=inf,ma;
int cnt=0;
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		mi=min(mi,a[i]);
	}
	for(i=1;i<=n;i++)a[i]-=mi;
	for(i=1;i<=n;i++)
	{
		if(a[i]>1)
		{
			printf("No\n");
			return 0;
		}
		ma=max(ma,a[i]);
	}
	if(ma==0)
	{
		if(mi==n-1)
		{
			printf("Yes\n");
			return 0;
		}
		if(mi*2<=n)
		{
			printf("Yes\n");
			return 0;
		}
		printf("No\n");
		return 0;
	}
	else
	{
		for(i=1;i<=n;i++)if(a[i]==0)cnt++;
//		printf("%d %d\n",cnt,mi);
		if(cnt>mi)
		{
			printf("No\n");
			return 0;
		}
		int qt=mi+1-cnt;
//		printf("%d %d\n",cnt,qt);
		if(cnt+qt*2<=n)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	return 0;
}


Measured memory_bytes: 640
unittest
{
	assert( [ "3", "2 2 4" ].solve == "4 0 4" );
	assert( [ "5", "3 8 7 5 5" ].solve == "2 4 12 2 8" );
	assert( [ "3", "1000000000 1000000000 0" ].solve == "0 2000000000 0" );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	
	// 最初の山の降雨量を計算
	auto anss = new long[ n ];
	anss[ 0 ] = as[ 0 ];
	for( auto i = 1L; i < as.length; i += 2 )
	{
		anss[ 0 ] += -as[ i ] + as[ i + 1 ];
	}
	
	// 2番目以降の山の降雨量を計算
	foreach( i, a, b; lockstep( as, anss[ 0 .. $ - 1 ] ) )
	{
		anss[ i + 1 ] = a * 2 - b;
	}
	return anss.to!( string[] ).join( " " );
}


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

typedef long long ll;

const int MOD = 1e9+7;
const int N = 100001;

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

	ll ans = 1; vector<int> c(4,0);
	for (int i = 0; i < n; ++i) {
		ll tmp = 0, x = 3;
		for (int j = 0; j < 3; ++j) {
			if (a[i] == c[j]) {
				tmp++; x = j;
			}
		}
		(ans *= tmp) %= MOD;
		c[x]++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
<?php

$stdin = fopen('php://stdin', 'r');
list($n, $m) = sscanf(fgets($stdin), '%d%d');

$a = array();
for ($i = 0; $i < $n; ++$i) {
    $a[$i] = fgets($stdin);
}

$check = function ($i, $j) use ($a, $n, $m) {
    return ($i >= 0 && $i < $n && $j >= 0 && $j < $m && $a[$i]{$j} == '#');
};

for ($i = 0; $i < $n; ++$i)
    for ($j = 0; $j < $m; ++$j)
        if ($a[$i]{$j} == '#' &&
            !$check($i - 1, $j) && !$check($i + 1, $j) &&
            !$check($i, $j - 1) && !$check($i, $j + 1))
        {
            echo 'No';
            return;
        }

echo 'Yes';
?>

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
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 (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int x,n;
  cin >> x >> n;
  vector<int> p(105, 0);
  REP(i,n) {
    int v;
    cin >> v;
    p[v] = 1;
  }

  int ans = abs(x- (-1));
  int ansn = -1;
  REP(i,105) {
    if (p[i] == 1) continue;
    int diff = abs(x - i);
    if (ans > diff) {
      ans = diff;
      ansn = i;
    }
  }

  COUT(ansn);

  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>



typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)



ll fast_pow(ll x,ll n,ll mod){
    if (n==0) return 1;
    ll res=fast_pow(x*x %mod,n/2,mod);
    if (n&1) res=res*x%mod;
    return res;
}

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

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

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;




int main(){
    int n;
    cin>>n;
    printf("%d",n*n*3);
    
}


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

const int N=2e6+10,Mod=1e9+7;

int x[N],y[N],fact[N],inv[N];

void Init() {
	for (int i=0;i<6;++i) scanf("%d",&x[i]);
	for (int i=0;i<6;++i) scanf("%d",&y[i]);
}

void Prepare() {
	int n=2e6;
	fact[0]=1; for (int i=1;i<=n;++i) fact[i]=1ll*fact[i-1]*i%Mod;
	inv[0]=inv[1]=1; for (int i=2;i<=n;++i) inv[i]=1ll*(Mod-Mod/i)*inv[Mod%i]%Mod;
	for (int i=2;i<=n;++i) inv[i]=1ll*inv[i-1]*inv[i]%Mod;
}

int C(int n,int m) { return 1ll*fact[n]*inv[n-m]%Mod*inv[m]%Mod; }

int G(int x,int y,int s,int t) {
	int ans=0;
	for (int i=0;i<=x;++i) 
		ans=(ans+1ll*(i+y+1)*C(i+y,i)%Mod*C(s-i+t-y-1,t-y-1))%Mod;
	for (int i=0;i<=y;++i) ans=(ans+1ll*(i+x+1)*C(i+x,i)%Mod*C(s-x-1+t-i,s-x-1))%Mod;
	return ans;
}

int F(int xl,int yl,int xr,int yr,int s,int t) {
	return (0ll+G(xr,yr,s,t)-G(xl-1,yr,s,t)-G(xr,yl-1,s,t)+G(xl-1,yl-1,s,t))%Mod;
}

void Solve() {
	Prepare();
	x[0]--; y[0]--; x[5]++; y[5]++;
	int ans=0;
	for (int a=0;a<2;++a)
		for (int b=0;b<2;++b)
			for (int c=0;c<2;++c)
				for (int d=0;d<2;++d) {
					int op=a^b^c^d; if (!op) op=1;else op=-1;
					ans=(ans+op*F(x[2]-x[a],y[2]-y[b],x[3]-x[a],y[3]-y[b],x[4|c]-x[a],y[4|d]-y[b]))%Mod;
				}
	printf("%d\n",(ans+Mod)%Mod);
}

int main() {
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int n, m; cin >> n >> m;
    vector<int> s(n), t(m);
    REP(i, 0, n) cin >> s[i];
    REP(i, 0, m) cin >> t[i];

    ll dp[n + 1][m + 1] = {};
    REP(i, 0, n + 1) dp[i][0] = 1;
    REP(i, 0, m + 1) dp[0][i] = 1;
    REP(i, 0, n) {
        REP(j, 0, m) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD;
            }
            dp[i + 1][j + 1] = ((dp[i + 1][j + 1] + dp[i + 1][j]) % MOD + dp[i][j + 1]) % MOD;
            dp[i + 1][j + 1] = (MOD + dp[i + 1][j + 1] - dp[i][j]) % MOD;

        }
    }
    cout << dp[n][m] << endl;
    return 0;
}

Measured memory_bytes: 34872
N = int(input())
A = ['z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
B = []
while N != 0:
        B.append(A[N % 26])
        if N % 26 != 0:
            N //= 26
        elif N % 26 == 0:
            N //= 26
            N -= 1

B.reverse()
C = ''
for i in range(len(B)):
    C += B[i]
print(C)

Measured memory_bytes: 9208
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
bool a[110];
int n,m,x,y,i,ans,an;
int main(){
cin>>n>>m>>x;
for(i=0;i<m;i++){
cin>>y;
a[y]=true;}
for(i=x-1;i>0;i--)
if(a[i]==true)
ans++;
for(i=x+1;i<=n;i++)
if(a[i]==true)
an++;
ans=min(ans,an);
cout<<ans;
system("pause");
return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    cout << fixed << setprecision(10);

    long double L;
    cin >> L;
    cout << L*L*L/27 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<char,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;

//すべて半閉区間で扱う
struct FenwickTree {
  vector<ll> v;
  ll n;
  FenwickTree(ll n) : n(n), v(n) {}
  void add(ll i, ll x) {
    i++;
    while (i <= n) {
      v[i - 1] += x;
      i += i & -i;
    }
  }
  ll sum(ll i) {
    ll r = 0;
    while (i >= 1) {
      r += v[i - 1];
      i -= i & -i;
    }
    return r;
  }
};
 
struct ExFenwickTree {
  FenwickTree p, q;
  ExFenwickTree(ll n) : p(n + 1), q(n + 1) {}
  void add(ll l, ll r, ll w) {
    p.add(l, -w * l);
    p.add(r, w * r);
    q.add(l, w);
    q.add(r, -w);
  }
  ll sum(ll r) {
    return p.sum(r) + q.sum(r) * r;
  }
};
//↑すべて半閉区間で扱う



int main(){
    ll N;
    cin >> N;
    string S;
    cin >> S;
    ll Q;
    cin >> Q;
    Map m;
    char c='a';
    for(ll i=0;i<26;i++){
        m[c]=i;
        c++;
    ;}

    //M[m[c]]のtreeのj番目はS[j]でのcの出現回数
    vector<ExFenwickTree> M(26,ExFenwickTree(N));

    for(ll i=0;i<N;i++){
        M[m[S[i]]].add(i,i+1,1)
    ;}

    for(ll i=0;i<Q;i++){
        ll type;
        cin >> type;
        if(type==1){
            ll a;
            cin >> a;a--;
            char b;
            cin >> b;
            M[m[S[a]]].add(a,a+1,-1);
            S[a]=b;
            M[m[b]].add(a,a+1,1);
            
        }
        else if(type==2){
            ll l;
            cin >> l;l--;
            ll r;
            cin >> r;r--;
            ll count=0;
            for(ll i=0;i<26;i++){
                if(M[i].sum(r+1)!=M[i].sum(l)){
                    count++;
                }
            ;}
            cout<<count<<endl;
        }
    ;}


    
    return 0;
}


Measured memory_bytes: 211844
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

// Union-Find 木 (Verified: AtCoder Typical Contest 001 B)
struct UnionFind {
private:
    const int n;
    int size_;
    vector<int> uf;
public:
    // 初期化 UnionFind uni(n) のように宣言すれば良い
    UnionFind(int _n) : n(_n), size_(_n), uf(_n, -1) {}
    // find (木の根を求める)
    int find(int x) {return (uf[x] < 0) ? x : uf[x] = find(uf[x]);}
    // x と y が同じ集合に属するかどうか
    bool same(int x, int y) {return find(x) == find(y);}
    // x が属する集合の要素数
    int size(int x) {return -uf[find(x)];}
    // 集合はいくつあるか
    int size()      {return size_;}
    // x と y の属する集合を併合
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        size_--;
        if(-uf[x] < -uf[y]) swap(x, y);
        uf[x] += uf[y]; uf[y] = x;
        return true;
    }
};


int main() {
    int N, M, K; cin >> N >> M >> K;
    UnionFind uf(N);
    vector<int> ans(N);
    for(int i=0; i<M; i++) {
        int u, v; cin >> u >> v; u--; v--;
        uf.unite(u, v);
        ans[u]--;
        ans[v]--;
    }

    vector< vector<int> > G(N);
    for(int i=0; i<K; i++) {
        int u, v; cin >> u >> v; u--; v--;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    for(int i=0; i<N; i++) {
        ans[i] += uf.size(i) - 1;
        for(auto j : G[i]) {
            if(uf.same(i, j)) ans[i]--;
        }
        cout << ans[i] << " \n"[i + 1 == N];
    }
    return 0;
}


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

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  
  if((C >= A) && (B >= C))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

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

using namespace std;

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

    for(int i = 0; i < s.size(); i++) {
        if((i+1) % 2 == 1) {
            cout << s[i];
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 512
n,k=map(int,input().split())
A=list(map(int,input().split()))

s=sum(A)
import math
def yakusu(n):
  ans_local=set()
  for i in range(1,int(math.sqrt(n))+1):
    if n%i==0:
      ans_local = ans_local | set([i,n//i]) #setなので平方数でもOK
  return list(ans_local)  #必要に応じてsort

yaku=sorted(yakusu(s), reverse=1)
#print(yaku)
for mod in yaku:
    B=[i%mod for i in A if i%mod!=0]
    if B==[] : print(mod);exit()
    if len(B)==1:
        q=B[0]
        if 0<=q<=k or mod-k<=q: print(mod);exit()
        else:continue
    B.sort()
    r=[B[0]]*len(B)
    for i in range(len(B)-1):
        r[i+1]= r[i]+B[i+1]
    now=float("INF")
    for i in range(1,len(B)): #切り方
        if r[i-1] ==  mod*(len(B)-i)-(r[-1]-r[i-1]) and r[i-1]<=k:
            print(mod);exit()

    


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

int main(){
	long long a,b;
	cin>>a>>b;
	long long c=1;
	for(int i=0;i<a;i++){
		c*=100;
	}
	if(b==100){
		cout<<c*101<<endl;
	}
	else{
		cout<<c*b<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n, a, b;
int main() {
	while (true) {
		cin >> a >> b;
		if (a == 0 && b == 0) {
			break;
		}
		n = (b - a) / 100;
		cout << n % 5 << ' ' << (n / 5) % 2 << ' ' << n / 10 << endl;
	}
}

Measured memory_bytes: 1160
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n,p[100005],q[100005],base;
struct uf{
	int par[100005];
	void init(){rep(i,100005)par[i]=i;}
	int find(int x){ if(x==par[x]) return x;else return par[x]=find(par[x]);}
	void unite(int x,int y){
		x = find(x); y = find(y); if(x == y) return;
		par[x] = y;
	}
	bool same(int x,int y){ return find(x) == find(y); }
}a,b;
int gain[200005];
vector<P1>edgee;

struct edge
{
	int to,cap,rev;
};
#define SZ 200005
vector<edge>G[SZ];
bool used[SZ];
int itr[SZ],level[SZ];
void add_edge(int from,int to,int cap)
{
	G[from].push_back((edge){to,cap,G[to].size()});
	G[to].push_back((edge){from,0,G[from].size()-1});
}
void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int>q;
	level[s] = 0; q.push(s);
	while(!q.empty()){
		int v = q.front(); q.pop();
		for(int i=0;i<G[v].size();i++){
			edge &e = G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to] = level[v]+1;
				q.push(e.to);
			}
		}
	}
}
int dfs(int v,int t,int f)
{ 
	if(v==t) return f;
	for(int &i=itr[v];i<G[v].size();i++)
	{
		edge &e=G[v][i];
		if(e.cap>0 && level[v] < level[e.to])
		{ 
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0) 
			{ 
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t)
{ 
	int flow=0,f;
	while(bfs(s),level[t]>=0)
	{
		memset(itr,0,sizeof(itr));
		while( (f=dfs(s,t,INF)) > 0){
			flow += f;
		}
	}
	return flow;
}

int main(){
	scanf("%d",&n);
	a.init(); b.init();
	//0...p[i] 1...i
	rep(i,n){
		scanf("%d",&p[i]);
		a.unite(i,p[i]);
	}
	//0...i 1...q[i]
	rep(i,n){
		scanf("%d",&q[i]);
		if(q[i] != i) base++;
		b.unite(i,q[i]);
	}
	rep(i,n){
		if(p[i] == q[i] && p[i] == i) continue;
		else if(p[i] == i){
			gain[b.find(i)+n] += -1;
		}else if(q[i] == i){
			gain[a.find(i)] += 1;
		}
		else if(p[i] == q[i]){
			edgee.pb(mp(1,mp(b.find(i)+n,a.find(i))));
			edgee.pb(mp(1,mp(a.find(i),b.find(i)+n)));
		}
		else{
			edgee.pb(mp(1,mp(b.find(i)+n,a.find(i))));
		}
	}
	rep(i,2*n){
		if(gain[i] > 0){
			base += gain[i];
			add_edge(200001,i,gain[i]);
		}
		else if(gain[i] < 0){
			add_edge(i,200002,-gain[i]);
		}
	}
	rep(i,edgee.size()) add_edge(edgee[i].sc.fi,edgee[i].sc.sc,edgee[i].fi);
	cout << base - max_flow(200001,200002) << endl;
}


Measured memory_bytes: 18416
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using std::cout;
using std::cin;
using std::endl;

int main(){
  const int N_max = 10000;

  int N;
  int candidates[N_max];
  std::vector<int> primes;

  cin >> N;
  for(int i =0; i<N; ++i){
    cin >> candidates[i];
  }
  int max_candidate = *std::max_element(candidates, candidates+N);
  int sqrt_max_candidate = static_cast<int>(sqrt(max_candidate));
  // cout << "max_candidate: " << max_candidate << endl;
  // cout << "sqrt_max_candidate: " << sqrt_max_candidate << endl;

  //list
  for(int cand = 2; cand <= sqrt_max_candidate; ++cand){
    bool is_a_prime = true;
    for(const int &i : primes){
      if (0 == cand%i){
	is_a_prime = false;
	break;
      }
    }
    if(is_a_prime){
      primes.push_back(cand);
    }
    // if (cand % 10000==0){
    //   cout << "checked: " << cand << endl;
    // }
  }

  // for(const int &i : primes){
  //   cout << i << endl;
  // }


  //count
  int num_of_primes = 0;
  for(int i = 0; i<N; ++i){
    if(candidates[i] <= sqrt_max_candidate && static_cast<bool>(std::binary_search(primes.begin(), primes.end(), candidates[i]))){
      ++num_of_primes;
    }
    else if(candidates[i] > sqrt_max_candidate){
      bool is_a_prime = true;
      for(const int &p : primes){
	if (0==candidates[i]%p){
	  is_a_prime = false;
	  break;
	}
      }
      if (is_a_prime) ++num_of_primes;
    }
  }
  cout << num_of_primes <<endl;
  
  return 0;
}

Measured memory_bytes: 1268
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main(){
  int n, d;
  cin >> n >> d;
  vector<vector<int>> p(n, vector<int>(d));
  rep(i,n){
    rep(j,d)
      cin >> p[i][j];
  }
  int ans=0;
  for(int i=0; i<n-1; i++){
    for(int j=i+1; j<n; j++){
      double tmp=0;
      rep(k,d)
        tmp += pow(p[i][k]-p[j][k],2);
      tmp = sqrt(tmp);
      if(tmp == (int)tmp)
          ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using ll=long long;

int main(){

int N;
string S,T;
cin >> N;
cin >> S;

int a=S.size();

int j=0;

for(int i=0;i<a-2;++i){
T=S.substr(i,3);
if(T=="ABC"){++j;}
}

cout << j << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
lli par[200000];
vector<lli>k[200000];
lli find(lli a) {
	if (a == par[a])return a;
	return find(par[a]);
}
void unite(lli a,lli b) {
	a = find(a);
	b = find(b);
	if (k[b].size() > k[a].size())swap(a, b);
	lli t=k[b].size();
	for (lli i=0;i<t;i++){
		k[a].push_back(k[b][i]);
	}
	par[b] = a;
}

int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
	lli n,m;
	cin>>n>>m;
	lli a[m][2];
	for(lli i=0;i<m;i++){
		cin>>a[i][0]>>a[i][1];
	}
	lli ans1=(n*(n-1))/2;
	loop(i,1,n+1) {
		par[i] = i;
		k[i].push_back(i);
	}
	vl ans;
	for(lli i=m-1;i>=0;i--){
		ans.pb(ans1);
		if(find(a[i][0])==find(a[i][1])){continue;
		}
		ans1=ans1-(k[find(a[i][0])].size()*k[find(a[i][1])].size());
		//cout<<k[find(a[i][0])].size()<<" "<<k[find(a[i][1])].size()<<endl;
		unite(a[i][0],a[i][1]);
		
	}
	reverse(ans.begin(),ans.end());
	for(lli i=0;i<ans.size();i++)cout<<ans[i]<<endl;
	/*loop(i,0,n-1) {
		lli a, b; cin >> a >> b;
		unite(a, b);
	}*/
	//lli t=k[find(1)].size();
	//for (lli i=0;i<t;i++)cout <<k[find(1)][i]<< " ";
    return 0;
}


Measured memory_bytes: 21492
import copy
H, W, K = map(int,input().split())

row_black = [0]*H
column_black = [0]*W
row_position = []
column_position =[]
full = 0
res = 0
for i in range(H):
    row_position.append([])
for j in range(W):
    column_position.append([])

for i in range(H):
    s = list(input())
    for j in range(W):
        if s[j] =="#":
            row_black[i] +=1
            column_black[j] +=1
            row_position[i].append(j)
            column_position[j].append(i)
            full +=1

n = H+W

for i in range(2**n):
    r = copy.copy(row_black)
    c = copy.copy(column_black)
    temp = 0
    for j in range(n):
        if i & (1<<j):
            if(j<H):
                temp += r[j]
                r[j] = 0
                for k in row_position[j]:
                    c[k] -=1
            else:
                temp += c[j-H]
                c[j-H] = 0
                for k in column_position[j-H]:
                    r[k] -=1
        if full - temp < K:
            break
    if full - temp == K:
        res +=1

print(res)

#print(row_black)
#print(column_black)
#print(row_position)
#print(column_position)

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

int main() {
  int a, b, c, d, e, f;
  std::cin >> a >> b >> c >> d >> e >> f;

  std::vector<bool> water(f + 1, false);

  water[0] = true;
  for (int i = 0; i <= f; i++) {
    if (water[i]) {
      if (i + 100 * a <= f) {
        water[i + 100 * a] = true;
      }
      if (i + 100 * b <= f) {
        water[i + 100 * b] = true;
      }
    }
  }
  water[0] = false;
  std::vector<bool> suger(f + 1, false);

  suger[0] = true;
  for (int i = 0; i <= f; i++) {
    if (suger[i]) {
      if (i + c <= f) {
        suger[i + c] = true;
      }
      if (i + d <= f) {
        suger[i + d] = true;
      }
    }
  }

  double h = 0;
  int w = 100 * a, s = 0;
  for (int i = 1; i <= f; i++) {
    if (water[i]) {
      const auto s_max = std::min(i / 100 * e, f - i);
      int k = 0;
      for (int j = s_max; 0 <= j; j--) {
        if (suger[j]) {
          k = j;
          break;
        }
      }
      double p = static_cast<double>(100 * k) / (i + k);
      if (h < p) {
        h = p;
        w = i;
        s = k;
      }
    }
  }

  std::cout << w + s << " " << s << std::endl;
  return 0;
}

Measured memory_bytes: 256