akhauriyash/Code-Regression huggingface dataset:
cat<<EOF>Source.cpp
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;

int x[100000],y[100000],x_mod_k[100000],x_div_k[100000];
char s[100000][2];
int n,k;

void add(vector<int>&cnt,int x,int t){
	if((x_div_k[x]&1)==0){
		if(t==0){
			cnt[0]++;
			cnt[k-x_mod_k[x]]--;
		}
		else{
			cnt[k-x_mod_k[x]]++;
		}
	}
	else{
		if(t==0){
			cnt[k-x_mod_k[x]]++;
		}
		else{
			cnt[0]++;
			cnt[k-x_mod_k[x]]--;
		}
	}
}
int ans[2000];
int main(){
	scanf("%d%d",&n,&k);
	rep(i,n){
		scanf("%d%d%s",&x[i],&y[i],s[i]);
		x_mod_k[i]=y[i]%k;
		x_div_k[i]=y[i]/k;
	}
	int Max=0;
	#pragma omp parallel for schedule(dynamic, 1) num_threads(20)
	rep(i,k){
		vector<int>cnt(max(n,k));
		rep(j,n){
			if(s[j][0]=='B'){
				if(((x[j]+i)/k)%2==0){
					add(cnt,j,0);
				}
				else{
					add(cnt,j,1);
				}
			}
			else{
				if(((x[j]+i)/k)%2==0){
					add(cnt,j,1);
				}
				else{
					add(cnt,j,0);
				}
			}
		}
		rep(j,k){
			if(j)cnt[j]+=cnt[j-1];
			ans[i]=max({ans[i],cnt[j],n-cnt[j]});
		}
	}
	rep(i,k)Max=max(Max,ans[i]);
	cout<<Max<<endl;
}
EOF
g++ -O3 Source.cpp -o Source -fopenmp -std=c++11
./Source

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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}


// end of Template

int n,ans,f[200000];
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;
    for(int i=1;i<=n;i++){
        int temp;cin>>temp; temp++; f[temp]++;
    }
    for(int i=3;i<=1e5+10;i++){
        ans = max(ans, f[i] + f[i-1] + f[i-2]);
    }
    cout<<ans<<newl;

}


Measured memory_bytes: 640
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <list>
#include <cmath>
#include <stack>
#include <queue>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

int main()
{
	int n, k, s;
	cin >> n >> k >> s;
	if (s == 1000000000)
	{
		for (int i = 0; i < n; i++)
		{
			if (i < k)
			{
				cout << s;
			}
			else
			{
				cout << s - 1;
			}
			if (i != n - 1)
			{
				cout << " ";
			}
		}
	}
	else
	{
		for (int i = 0; i < n; i++)
		{
			if (i < k)
			{
				cout << s;
			}
			else
			{
				cout << s + 1;
			}
			if (i != n - 1)
			{
				cout << " ";
			}
		}
	}
}


Measured memory_bytes: 32512
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
					  cerr << "\n\n" << "Time elapsed: " << \
					  (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
					  return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'

int main()
{
	// start_routine();
	fastio;
	// #ifndef ONLINE_JUDGE
 //        freopen("input.txt", "rt", stdin);
 //        freopen("output.txt", "wt", stdout);
 //    #endif

    ll n;cin>>n;
    ll a[n],b[n],diff[n];
    for(ll i=0;i<n;i++)
    	cin>>a[i];
    for(ll i=0;i<n;i++)
    	cin>>b[i];
    for(ll i=0;i<n;i++)
    	diff[i]=a[i]-b[i];

    ll cnt=0,need=0;
    for(ll i=0;i<n;i++)
    	if(a[i]<b[i])
    		cnt++,need+=b[i]-a[i];

    sort(diff,diff+n);
    for(ll i=n-1;i>=0;i--)
    {
    	if(diff[i]<=0)
    		break;

    	if(need<=0)
    		break;

    	need-=diff[i];
    	cnt++;
    }

    if(need>0)
    	cout<<-1;
    else
    	cout<<cnt;

	// end_routine();
}

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


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

    vector<int>v(n);
    int s=0;

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

     int x;

     if(s%((4*m))==0){
        x=s/(4*m);
     }else{
      x=(s/(4*m))+1;

     }

     //cout<<x<<endl;

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

  if((n-cnt)>=m) cout<<"Yes"<<endl;
  else       cout<<"No"<<endl;


   //cout<<cnt<<endl;

    return 0;
}



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



namespace CSharpSample01
{

    
    class Program
    {
        
        static void Solve(int N, int[] a)
        {

            //b[i] := i番目の箱に入っているボールの数(1 or 0)(i:1～N)
            int[] b = new int[N + 1];
            //ボールが1つ入っている箱の数
            int M = 0;

            //各i番目の箱に対してb[i]を決める
            for(int i = N; i >= 1; i--)
            {
                //iの倍数のインデックスにおいて1をカウント
                int one_cnt = 0;
                for(int j = i; j <= N; j += i)
                {
                    if (b[j] == 1) one_cnt++;
                }

                //one_cntに基づいてb[i]を決める
                if (a[i] != (one_cnt % 2))
                {
                    b[i] = 1;
                    M++;
                }
             
            }

            //出力
            Console.WriteLine(M);
            if (M == 0) return;
            List<int> ans = new List<int>();
            for(int i = 1; i <= N; i++)
            {
                if (b[i] == 1) ans.Add(i);
            }

            Console.WriteLine(string.Join(" ", ans));
        }

        
        static void Main(string[] args)
        {
            //入力1(N)
            int N = int.Parse(Console.ReadLine());

            //入力2(a)
            string[] input = Console.ReadLine().Split(' ');
            int[] a = new int[N + 1];
            for(int i = 1; i <= N; i++)
            {
                a[i] = int.Parse(input[i - 1]);
            }

            Solve(N, a);
            
        }
    }

}

Measured memory_bytes: 34392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
pair<ll, ll> reverse(pair<ll, ll> p){
    ll a = -1 * p.second, b = p.first;
    if(b < 0) {a *= -1; b *= -1;}
    return make_pair(a, b);
}
int main(){
    int n;
    cin >> n;
    map<pair<ll, ll>, int> mp;
    ll a_0 = 0, b_0 = 0, a_b_0 = 0;;
    for(int i = 0 ; i < n; i++){
        ll a, b;
        cin >> a >> b;
        if(a == 0 && b == 0) {a_b_0++; continue;}
        if(a == 0) {a_0++; continue;}
        if(b == 0) {b_0++; continue;}
        ll c = gcd(a, b);
        a /= c;
        b /= c;
        if(b < 0){a *= -1; b *= -1;}
        mp[make_pair(a, b)]++;
    }
    vector<ll> po(n + 1);
    po[0] = 1;
    for(int i = 1; i <= n; i++) po[i] = po[i - 1] * 2 % MOD;
    vector<ll> combination_for_each_pair;
    for(auto itr : mp){
        auto p = itr.first;
        int x = itr.second, y;
        auto itr2 = mp.find(reverse(p));
        if(itr2 != mp.end()){
            y = itr2->second;
            mp.erase(itr2);
            combination_for_each_pair.push_back((po[x] + po[y] - 1) % MOD);
        }else{
            combination_for_each_pair.push_back(po[x]);
        }
        mp.erase(itr.first);
    }
    if(a_0 == 0 && b_0 == 0);
    else if(a_0 == 0) combination_for_each_pair.push_back(po[b_0]);
    else if(b_0 == 0) combination_for_each_pair.push_back(po[a_0]);
    else combination_for_each_pair.push_back(po[a_0] + po[b_0] - 1);
    ll sum = 1;
    for(int i = 0; i < combination_for_each_pair.size(); i++){
        sum = (sum * combination_for_each_pair[i]) % MOD;
    }
    sum = (sum + MOD + a_b_0 - 1) % MOD;
    cout << sum << "\n";
    /*for(int a : combination_for_each_pair){
        cout << a << " ";
    }
    cout <<  reverse(make_pair(2, -1)).first << " " << reverse(make_pair(2, -1)).second;*/
}

/*⠀⠀⠀⠀⠀⢀⣀⣀⣀    
⠀⠀⠀⠰⡿⠿⠛⠛⠻⠿⣷
⠀⠀⠀⠀⠀⠀⣀⣄⡀⠀⠀⠀⠀⢀⣀⣀⣤⣄⣀⡀
⠀⠀⠀⠀⠀⢸⣿⣿⣷⠀⠀⠀⠀⠛⠛⣿⣿⣿⡛⠿⠷
⠀⠀⠀⠀⠀⠘⠿⠿⠋⠀⠀⠀⠀⠀⠀⣿⣿⣿⠇
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠁

⠀⠀⠀⠀⣿⣷⣄⠀⢶⣶⣷⣶⣶⣤⣀
⠀⠀⠀⠀⣿⣿⣿⠀⠀⠀⠀⠀⠈⠙⠻⠗
⠀⠀⠀⣰⣿⣿⣿⠀⠀⠀⠀⢀⣀⣠⣤⣴⣶⡄
⠀⣠⣾⣿⣿⣿⣥⣶⣶⣿⣿⣿⣿⣿⠿⠿⠛⠃
⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄
⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡁
⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁
⠀⠀⠛⢿⣿⣿⣿⣿⣿⣿⡿⠟
⠀⠀⠀⠀⠀⠉⠉⠉
*/

//library//
ll mod_fact(ll a, ll mod){
    ll ans = 1;
    while(a > 1){
        ans = ans * a % mod;
        a--;
    }
    return ans; 
}
ll mod_pow(ll a, ll b, ll mod){
    ll ans = 1;
    while(b > 0){
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
ll mod_inv(ll a, ll mod){
    return mod_pow(a, mod - 2, mod);
}
ll gcd(ll a, ll b){
    while(a % b){
        return gcd(b, a % b);
    }
    return b;
}
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

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

int main(void)
{
    vector<int> A(5);
    vector<int> B(5);
    for (int i = 0; i < 5; i++)
    {
        cin >> A[i];
        if (A[i] % 10 == 0)
        {
            B[i] = 0;
        }
        else
        {
            B[i] = 10 - A[i] % 10;
        }
    }
    // 添え字取得
    vector<int>::iterator max = max_element(B.begin(), B.end());
    size_t max_index = distance(B.begin(), max);
    int sol = 0;
    // 待ち時間は、どの注文する順番で頼んでも、同じ時間かかる
    // 理由としては、結局10秒の倍数だけ待つため
    // なので、待ち時間が最大のものが最後に注文するべきもの
    for (int i = 0; i < 5; i++)
    {
        if (i != max_index)
        {
            if (A[i] % 10 == 0)
            {
                sol += A[i];
            }
            else
            {
                sol += A[i] + 10 - A[i] % 10;
            }
        }
        else
        {
            sol += A[i];
        }
    }
    cout << sol;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;
string s;
vector<int> S;
int sum[3][4010];

int calc(int a,int b){
  rep(i,3) if(i!=a && i!=b) return i;
  return 0;
}

void solve(){
  cin >> n;
  cin >> s;
  rep(i,n){
    if(s[i]=='R'){
      S.push_back(0);
    }
    if(s[i]=='B'){
      S.push_back(1);
    }
    if(s[i]=='G'){
      S.push_back(2);
    }
  }
  rep(i,n){
    rep(k,3){
      sum[k][i+1]=sum[k][i]+(S[i]==k);
    }
  }
  ll ans=0;
  rep(i,n){
    Rep(j,i+1,n){
      if(S[i]==S[j]) continue;
      int p=calc(S[i],S[j]);
      ans+=sum[p][n]-sum[p][j];
      if(2*j-i<n){
        if(S[2*j-i]==p) ans-=1;
      }
    }
  }
  cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 3692
while 1:
    N = int(raw_input())
    if N == 0: break
    W,H = map(int,raw_input().split())
    A = [[0]*W for _ in range(H)]
    for i in range(N):
        w,h = map(int,raw_input().split())
        A[h-1][w-1] = 1
    S,T = map(int,raw_input().split())
    S,T = S,T
    
    ans = 0
    for h in range(H-T+1):
        for w in range(W-S+1):
            ans = max(ans, sum(sum(A[h+i][w:w+S]) for i in range(T)))
    print ans

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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

int dh[4]={1,0,-1,0};
int dw[4]={0,1,0,-1};

int main() {
  int H, W, D;
  cin >> H >> W >> D;

  vector<int> h(H * W);
  vector<int> w(H * W);
  rep0(i, H) rep0(j, W) {
    int temp;
    cin >> temp;
    h[temp - 1] = i;
    w[temp - 1] = j;
  }

  vector<vector<int>> cost(D, vector<int>(H * W / D + 1, 0));

  rep0(i, D) {
    cost[i][0] = 0;

    rep1(j, H * W / D) {
      if (i + j * D >= H * W) break;
      int h1 = h[i + j * D];
      int w1 = w[i + j * D];
      int h2 = h[i + j * D - D];
      int w2 = w[i + j * D - D];
      cost[i][j] = cost[i][j - 1] + abs(h1 - h2) + abs(w1 - w2);
    }
  }
  // SHOW2(cost);

  int Q;
  cin >> Q;
  rep0(i, Q) {
    int l, r;
    cin >> l >> r;
    int costL = cost[(l - 1) % D][(l - 1) / D];
    int costR = cost[(r - 1) % D][(r - 1) / D];
    cout << costR - costL << BR;
  }
  return 0;
}

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

using namespace std;

int main(){
    int h, n;
    cin >> h >> n;
    vector<int> A(n), B(n);
    for (int i = 0; i < n; i++)
        cin >> A[i] >> B[i];

    vector<int> DP(h + 1, 1e9);
    DP[0] = 0;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < n; j++){
            int k = min(h, i + A[j]);
            DP[k] = min(DP[k], DP[i] + B[j]);
        }
    }
    cout << DP[h] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

template<typename T> class SegmentTree{
  private:
    typedef std::function<T(T,T)> F;
    int n;
    T d0;
    vector<T> vertex;
    F f;
    F g;
  public:
    SegmentTree(F f,F g,T d):d0(d),f(f),g(g){}
    void init(int _n){
        n=1;
        while(n<_n) n*=2;
        vertex.resize(2*n-1,d0);
    }
    void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0;i<n_;i++) vertex[n+i-1]=v[i];
        for(int i=n-2;i>=0;i--)
        vertex[i]=f(vertex[2*i+1],vertex[2*i+2]);
    }
    void update(int i,T x){
        int k=i+n-1;
        vertex[k]=g(vertex[k],x);
        while(k>0){
            k=(k-1)/2;
            vertex[k]=f(vertex[2*k+1],vertex[2*k+2]);
        }
        return;
    }
    T query(int l,int r){
        T vl=d0,vr=d0;
        l+=n-1;
        r+=n-1;
        for(;l<=r;l/=2,r=r/2-1){
            if(l%2==0) vl=f(vl,vertex[l]);
            if(r&1) vr=f(vr,vertex[r]);
        }
        return f(vl,vr);
    }
};

int main(){
    int N;cin>>N;
    vector<int> P(N);
    REP(i, N) cin >> P[i],P[i]--;
    SegmentTree<int> seg([](int a,int b){return a+b;},[](int a,int b){return a+b;},0);
    seg.init(N);
    int ans=0;
    REP(i,N){
        if(seg.query(0,P[i])==0) ans++;
        seg.update(P[i],1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
 
int main () {
int K, A, B;
  cin >> K >> A >> B;
  
  if(A%K==0 || B%K==0){
    cout << "OK" <<endl;
  }
  else if(A/K != B/K){
    cout << "OK" <<endl;
  }
  else {
    cout << "NG" <<endl;
  }


}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll N, A[3000], dp[3000][3005];
bool used[3000][3005];

ll score(ll l, ll r){
    if (used[l][r]) return dp[l][r];
    used[l][r] = true;

    ll ret;
    if (l == r)
        ret = A[l];
    else
        ret = max(A[l] - score(l + 1, r), A[r] - score(l, r - 1));
    
    dp[l][r] = ret;
    return ret;
}
int main() {
    init();
    cin>>N;
    rep(i, N) cin >> A[i];
    cout << score(0, N - 1) << endl;
}

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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
  int n;
  cin >> n;
  vector<int> X(n + 1), Y(n + 1), H(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> X[i] >> Y[i] >> H[i];
  }
  for (int x = 0; x <= 100; ++x) {
    for (int y = 0; y <= 100; ++y) {
      set<int> h;
      int mn = INT_MAX;
      for (int i = 1; i <= n; ++i) {
        int dis = abs(x - X[i]) + abs(y - Y[i]);
        if (H[i] > 0) {
          h.insert(H[i] + dis);
        } else {
          mn = min(mn, dis);
        }
      }
      if (h.size() == 1) {
        int height = *h.begin();
        if (height <= mn) {
          cout << x << " " << y << " " << *h.begin() << "\n";
          return;
        }
      } else if (h.size() == 0 && mn == 1) {
        cout << x << " " << y << " " << mn << "\n";
        return;
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test_case();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a,b,c,d,n,m,p,q,x[200001],y,k,h,w,sum,mi,ma,ans,l,r,res;
string s;
typedef vector<int> VI;
typedef vector<pair<int,int> > VP;

// 2 6 3
// 6 6 3 : 2
// 6 6 5 : 3
// 6 6 7 : 4
// 7 7 7

int main(){
    cin>>a>>b>>c;
    ma = max(a,max(b,c));
    sum+=(ma-a)/2;
    sum+=(ma-b)/2;
    sum+=(ma-c)/2;
    VI v;
    v.pb((ma-a)%2);v.pb((ma-b)%2);v.pb((ma-c)%2);
    sort(all(v));
    rep(i,3)d(v[i]);
    if(v[0]==0 && v[1]==0 && v[2]==0)p(sum);
    else if(v[0]==0 && v[1]==0 && v[2]==1)p(sum+2);
    else if(v[0]==0 && v[1]==1 && v[2]==1)p(sum+1);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define RPT(i, b, e) for (int i = (b); i <= (e); i++)
#define RPT1(i, n) RPT(i, 1, n)

int N, a[200001];
int ans;

void resolve()
{
    cin >> N;
    RPT1(i, N) cin >> a[i];

    bool b = false;
    ans = 0;

    int cur_num = 1;
    int prev_index = 0;
    RPT1(i, N)
    {
        if (a[i] == cur_num) {
            b = true;
            ans += i - prev_index - 1;
            prev_index = i;
            cur_num++;
        } else if (b && i == N) {
            ans += i - prev_index;
        }
    }

    if (!b) ans = -1;
    cout << ans << endl;
}

int main()
{
    resolve();
    return 0;
}


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

int main() {
    int V[25], C[25], N;
    cin >> N;

    for(int i = 0; i < N; i = i + 1) {
        cin >> V[i];
    }
    for(int i = 0; i < N; i = i + 1) {
        cin >> C[i];
    }

    int sum = 0;
    for(int i = 0; i < N; i = i + 1) {
        if (V[i] - C[i] > 0) {
            sum = sum + V[i] - C[i];
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    double o[2][3],d;
    for(int i=0; i<2; i++) for(int j=0; j<3; j++) cin >>o[i][j];
    d = sqrt((o[1][0]-o[0][0])*(o[1][0]-o[0][0])+(o[1][1]-o[0][1])*(o[1][1]-o[0][1]));
    if(o[0][2]+o[1][2]<d) cout <<"0"<<endl;
    else if(o[0][2]>o[1][2]){
      if(o[0][2]-o[1][2] > d) cout <<"2"<<endl;
      else cout <<"1"<<endl;
    }
    else{
      if(o[1][2]-o[0][2] > d) cout <<"-2"<<endl;
      else cout <<"1"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <string>   
#include <algorithm>

using namespace std;

int check(string target){
    int tmp = 0;
    for(int j = 0; j < target.size(); ++j){
        if(target[j] != 'A' && target[j] != 'C' && target[j] != 'G' && target[j] != 'T'){
            return j;
        }
    }

    return target.size();
} 

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

    int ans = 0;

    for(int i = 0; i < S.size(); ++i){
        ans = max(check(S.substr(i)), ans);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N, D= map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(N)]
count=0
for i in range(N):
    for j in range(i+1,N):
        tmp = 0
        for k in range(D):
            if i != j:
                tmp += (arr[i][k]-arr[j][k])**2
        tmp = tmp**0.5
        if tmp == int(tmp):
            count = count+1
print(count)

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> dishes(n);
  for (auto &x : dishes) {
    cin >> x;
  }
  vector<int> point(n);
  for (auto &x : point) {
    cin >> x;
  }
  vector<int> bonus(n - 1);
  for (auto &x : bonus) {
    cin >> x;
  }
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    if (dishes[i] - dishes[i + 1] == -1) {
      ans += bonus[dishes[i] - 1];
    }
  }
  for (int i = 0; i < n; i++) {
    ans += point[dishes[i]  - 1];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3") 

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

typedef long long int           ll;
typedef unsigned long long int  ull;
typedef long double             ld;

typedef pair<int, int>          pii;
typedef pair<ll,ll>             pll;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef vector<pii>             vpii;
typedef vector<pll>             vpll;

#define test(t)		        int t; cin >> t; while(t--)
#define f(i, a, b)	        for(int (i) = (a); (i) < (b); ++(i))
#define all(a)		        (a).begin(), (a).end()
#define endl 		        "\n"
#define maxvec(vec)             *max_element(all(vec))
#define minvec(vec)             *min_element(all(vec))
#define maxarr(arr)             *max_element(arr, arr + n)
#define minarr(arr)             *min_element(arr, arr + n)
#define deb(x)		        cout << #x << "--" << x << "--" << endl;
#define deb2(x,y)	        cout << #x << "-" << x << "-" << " ~~ " <<  #y << "-" << y << "-" << endl;
#define deba(arr)	        cout << #arr << " ~ [ "; for(auto n: arr) cout << n << " "; cout << "]" << endl;
#define debap(arr)	        cout << #arr << " ~ [ "; for(auto n: arr) cout << n.first << "-" << n.second << " "; cout << "]" << endl;
#define fast 		        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define mx9		1000000007
#define mx7		10000007
#define mx6		1000006
#define mx5		200005
#define inf		1<<30                                 
#define eps		1e-9
#define mod		1000000007
#define PI		3.141592653589793238462643383279502884L

void solve()
{
  ll n;
  cin >> n;
  ll a[4] = {0};
  f(i, 0, n)
  {
    string s;
    cin >> s;
    if(s[0] == 'A')
      a[0] += 1;
    if(s[0] == 'W')
      a[1] += 1;
    if(s[0] == 'T')
      a[2] += 1;
    if(s[0] == 'R')
      a[3] += 1;
  }
 	cout << "AC x " << a[0] << endl;
  cout << "WA x " << a[1] << endl;
  cout << "TLE x " << a[2] << endl;
cout << "RE x " << a[3] << endl;
}

int main()
{
    fast;
    //test(t)
        solve();
    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <algorithm>
#define inf 0x3f3f3f3f
#define lowbit(x) (x&-x)

using namespace std;

bool sumv[100005];

void add(int x) {
  for(;x;x-=lowbit(x)) sumv[x]^=1;
}

bool sum(int x,int n) {
  int s=0;
  for(;x<=n;x+=lowbit(x)) s^=sumv[x];
  return s;
}

inline int check(int x,int y,int z) {
  if (x%3==0&&y==x-1&&z==x-2) return -(x/3);
  if (z%3==0&&y==z-1&&x==z-2) return z/3;
  return inf;
}

int num[3][100005],a[100005];

int main() {
  int n;
  scanf("%d",&n);
  for(int i=0;i<3;i++)
    for(int j=1;j<=n;j++) scanf("%d",&num[i][j]);
  bool s1=0,s2=0;
  for(int i=1;i<=n;i++) {
  	int t=check(num[0][i],num[1][i],num[2][i]);
  	if (t==inf||((i&1)^(t&1))) {
  		puts("No");
  		return 0;
	  }
	a[i]=abs(t);
	if ((i&1)&&t<0) s1^=1;
	if ((!(i&1))&&t<0) s2^=1;
  }
  bool s3=0,s4=0;
  for(int i=1;i<=n;i+=2) {
  	s3^=sum(a[i],n);
  	add(a[i]);
  }
  memset(sumv,0,sizeof(sumv));
  for(int i=2;i<=n;i+=2) {
  	s4^=sum(a[i],n);
  	add(a[i]);
  }
  puts((s1==s4&&s2==s3)?"Yes":"No");
  return 0;
}

Measured memory_bytes: 1792
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

 */

#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define debug(x) cout<<#x<<": "<<x<<endl
#define For(i, st, en) for(ll i=st; i<en; i++)
#define rfor(i, st, en) for(ll i=st; i>=en; i--)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define printv(x) For(i, 0, x.size()){cout<<x[i]<<" ";} cout<<endl;
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define int long long
#define F first
#define S second
#define pb push_back
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector< vector<int> > vvi;
typedef vector< pair<int, int> > vpi;
#define MAXN 300005
#define MOD 1000000007
#define INF 1000000000000000007

double dp[301][301][301];

signed main(){
	fast
	int n; cin>>n;
	int temp;
	vi v(4, 0);	
	For(i, 0, n){
		cin>>temp;
		v[temp]++;
	}
	double N = (double)n;
	int a = v[1];
	int b = v[2];
	int c = v[3];
	// int mm = a+b+c+1;
	For(k, 0, N+1){
		For(j, 0, N+1){
			For(i, 0, N+1){
				if(i+j+k>N){
					dp[i][j][k]=0;
					continue;
				}
				if(i==0 & j==0 & k==0){
					dp[i][j][k] = 0;
				}else{
					double sum=(i+j+k);
					dp[i][j][k]=N/sum;
					double count=0;
					double val=0;
					if(i>0){
						val+=dp[i-1][j][k]*(i/sum);
					}
					if(j>0){
						val+=dp[i+1][j-1][k]*(j/sum);
					}
					if(k>0){
						val+=dp[i][j+1][k-1]*(k/sum);
					}
					dp[i][j][k]+=val;
				}
			}
		}
	}
	cout<<fixed<<setprecision(15);
	cout<<dp[a][b][c]<<endl;
    return 0;
}
    



Measured memory_bytes: 213376
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>
#include <stdlib.h>


int main(){
    
    
   ll n;
   ll m;
   cin >> n >> m;
   vector<ll> a(m);
   ll sum = 0LL;
   for(ll i=0LL;i < m;i++) {
       cin >>a[i];
       sum += a[i];
   }
   if(n - sum >=0) cout << n - sum << endl;
   else cout << -1 << endl;
}

Measured memory_bytes: 3236
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

using P = pair<int, int>;
vector<vector<int>> edge;
void dfs(int node, vector<int>& height, vector<bool>& isVisited, vector<P>& parent)
{
    isVisited[node] = true;
    height[node] = 0;

    rep(i, edge[node].size())
    {
        int nx = edge[node][i];
        if (!isVisited[nx]) {
            dfs(nx, height, isVisited, parent);
        }

        height[node] = max(height[node], height[nx] + 1);
    }

    rep(i, edge[node].size())
    {
        int nx = edge[node][i];
        P p = make_pair(height[node] - height[nx], node);
        parent[nx] = min(parent[nx], p);
    }
}

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

    vector<bool> isRoot(n, true);
    edge.resize(n);
    rep(i, n + m - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        edge[a].push_back(b);
        isRoot[b] = false;
    }

    int root;
    rep(i, n)
    {
        if (isRoot[i]) {
            root = i;
        }
    }

    vector<int> height(n, 0);
    vector<bool> isVisited(n, false);
    vector<P> parent(n, make_pair(n + 1, -1));
    dfs(root, height, isVisited, parent);

    rep(i, n)
    {
        int pnode;
        tie(ignore, pnode) = parent[i];
        cout << pnode + 1 << endl;
    }

    return 0;
}

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

using namespace std;

int n;
double x[11];
string u[11];
double answer = 0;

int main(){
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> x[i] >> u[i];
    if(u[i] == "BTC"){
      answer += 380000.0 * x[i];
    }else{
      answer += x[i];
    }
  }
  cout << answer << endl;

}

Measured memory_bytes: 888
n = int(input())
s = str(input())

a = []
b = 0
for i in range(1,n):
    if s[i] == s[i-1]:
        b += 1
    else:
        a.append(b)
        b = 0
    if i == n-1:
        a.append(b)
        b = 0

c = 0
for i in range(len(a)):
    c += a[i]

print(n-c)


Measured memory_bytes: 3956
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    n: usize,
    a: [usize; n],
    b: [usize; n],
    c: [usize; n]
    }
    let mut ans = 0;
    let (mut a, mut b, mut c) = (a, b, c);
    a.sort();
    b.sort();
    c.sort();
    let mut mb = vec![0; n];
    for i in (0..n).rev() {
        let t = n - c.upper_bound(&b[i]);
        if i + 1 < n {
            mb[i] = mb[i + 1] + t;
        } else {
            mb[i] = t;
        }
    }
    for &i in &a {
        let t = b.upper_bound(&i);
        if t < n {
            ans += mb[t];
        }
    }
    println!("{}", ans);
}

use std::cmp::{Ordering, min};

pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (high + low) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();
        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}




Measured memory_bytes: 8444
#include <set>
#include <cstdio>
#include <vector>
#include <utility>
#include <iterator>
using namespace std;

int main() {
    unsigned n; unsigned long long k; scanf("%u%llu", &n, &k);
    vector<unsigned> a(n);
    for (unsigned& x : a) scanf("%u", &x), --x;
    set<pair<unsigned, unsigned>> s;
    vector<pair<unsigned, unsigned>> edges;
    pair<unsigned, unsigned> p = make_pair(0U, *a.cbegin());
    pair<set<pair<unsigned, unsigned>>::iterator, bool> _ = make_pair(s.end(), false);
    while ((_ = s.insert(p)).second) edges.emplace_back(p), p = make_pair(p.second, a.at(p.second));
    unsigned c = 0;
    vector<pair<unsigned, unsigned>>::iterator it = edges.begin();
    for (; *it != *_.first; ++c) it = next(it);
    unsigned sz = distance(it, edges.end());
    if (!sz) sz = s.size();
    //printf("s.size()=%u c=%u sz=%u _.first=(%u;%u)\n", s.size(), c, sz, _.first->first, _.first->second); // DEBUG
    printf("%u", (c > --k ? next(edges.begin(), k)->second : next(it, (k - c) % sz)->second) + 1);
    return 0;
}

Measured memory_bytes: 14260
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
// #define MAX 20
#define INF (int)1e18

template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}

vector<int> a;
int n;
map<pair<int,int>,int> done;


int f(int l,int r,int left)
{
	if(left==0)
		return 0;
	if((r-l+1+1)/2<left || r<l)
		return -INF;
	if(done.find({l,left})!=done.end())
		return done[{l,left}];
	return done[{l,left}]=max(a[l]+f(l+2,r,left-1), f(l+1,r,left));
}


signed main()
{
	fio
	cin>>n;
	a.resize(n);
	fo(i,n)	
		cin>>a[i];
	cout<<f(0,n-1,n/2)<<'\n';
	printclock;
}


Measured memory_bytes: 34676
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

void calc(vector<int>& mem, int a[], int n){
    rep(i, 1 << n){
        int s = 0;
        rep(j, n) if((i >> j) & 1) s += a[j];
        mem[i] = s;
    }
    return;
}

int main(){
    int n; cin >> n;
    int a[n]; rep(i, n) cin >> a[i];
    int q; cin >> q;
    int m[q]; rep(i, q) cin >> m[i];
    vector<int> mem(1 << n);

    calc(mem, a, n);
    sort(mem.begin(), mem.end());

    rep(i, q) cout << (binary_search(mem.begin(), mem.end(), m[i]) ? "yes" : "no") << endl;
    return 0;
}


Measured memory_bytes: 6984
c = [list(map(int, input().split())) for _ in range(3)]
if c[0][0] - c[1][0] == c[0][1] - c[1][1] == c[0][2] - c[1][2] and c[1][0] - c[2][0] == c[1][1] - c[2][1] == c[1][2] - c[2][2]:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const double PI  = 3.141592653589793238463;
const int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

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

template<typename T>
string join(const vector<T>& vec, string sep = " "){
    stringstream ss;
    for(int i = 0; i < vec.size(); i++){
        ss << vec[i] << (i + 1 == vec.size() ? "" : sep);
    }
    return ss.str();
}

int solve(int h, int w, const M& css, const M& ass){
    M dss = css;
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            for(int k = 0; k < 10; k++){
                dss[j][k] = min(dss[j][k], dss[j][i] + dss[i][k]);
            }
        }
    }
    
    int s = 0;
    for(const auto& as : ass){
        for(const auto& a : as){
            if(a != -1){
                s += dss[a][1];
            }
        }
    }
    return s;
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int h, w;
    cin >> h >> w;
    M css(10, V(10));
    cin >> css;
    M ass(h, V(w));
    cin >> ass;

    cout << solve(h, w, css, ass) << endl;

    return 0;
}


Measured memory_bytes: 384
n, m = [int(i) for i in input().split()]

anss = [0 for i in range(n)]
all_wa = 0
for i in range(m):
    p, s = input().split()
    p = int(p)
    if anss[p-1] == "AC":
        continue
    elif s == "WA":
        anss[p-1] += 1
    else:
        all_wa += anss[p-1]
        anss[p-1] = "AC"

print(anss.count("AC"), all_wa)

Measured memory_bytes: 3888
import sys
input = sys.stdin.readline

def main():
    N,K,Q = map(int,input().split())
    A = [int(input()) for _ in range(Q)]
    num_a = [K-Q for _ in range(N)]
    for i in range(Q):
        num_a[A[i]-1] += 1

    for i in num_a:
        if i >= 1 :
            print("Yes")
        else:
            print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 11780
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

ll gcd(ll a,ll b)
{
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

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



int main(){
    double n,k,sum=0;
    cin>>n>>k;
    
    rrep(i,n){
        if(i>=k) sum+=1.0;
        else{
            double f=1,e=1;
            while(f<k/i){
                f*=2;
                e*=0.5;
            }
            sum+=e;
            }
        }
    cout<<fixed<<setprecision(13)<<sum/n<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb emplace_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define ll long long
#define INF 2000000000
string a,b;
int main(){
        int n,m;
        while(cin>>a){
                int ans;
                if(a=="SUN") ans=7;
                if(a=="MON") ans=6;
                if(a=="TUE") ans=5;
                if(a=="WED") ans=4;
                if(a=="THU") ans=3;
                if(a=="FRI") ans=2;
                if(a=="SAT") ans=1;
                cout<<ans<<"\n";
        }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;     

int ta[100][100];
const int BAN=10;
int main(){
 char ttmp;
int y,x,s,cnt=0,ma=0;
while(cin>>x>>ttmp>>y>>ttmp>>s){
	x+=2,y+=2;
	if(s==1){
	 ta[y][x]++;
	 ta[y+1][x]++;
	 ta[y][x-1]++;
	 ta[y-1][x]++;
	 ta[y][x+1]++;
	}
	if(s==2||s==3){
	for(int i=-1;i<=1;i++)for(int j=-1;j<=1;j++)ta[y+i][x+j]++;
	}
	if(s==3){
	ta[y+2][x]++;
	ta[y][x+2]++;
	ta[y-2][x]++;
	ta[y][x-2]++;
	}
}//endwhile
/*for(int i=2;i<BAN+2;i++){
	for(int j=2;j<BAN+2;j++){
	cout<<ta[i][j];
	}
	cout<<endl;
}*/
for(int i=0+2;i<BAN+2;i++){
	for(int j=0+2;j<BAN+2;j++){
	if(ta[i][j]==0)cnt++;
	ma=max(ma,ta[i][j]);
	}
}
cout<<cnt<<endl<<ma<<endl;
return 0;
}

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

static const int N = 100;

int main() {

    int n;
    cin >> n;

    int M[N][N] = {0};
    int u, k, v;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        --u;
        for (int j = 0; j < k; ++j) {
            cin >> v;
            --v;
            M[u][v] = 1;
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (j) cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<stdio.h>
using namespace std;

int n,A[50];

int solve(int i,int m){
  if(m==0) return 1;
  if(i>=n) return 0;
  int res = solve(i+1,m) || solve(i+1,m-A[i]);
  return res;

}

int main(){
  int q,M,i;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&M);
    if(solve(0,M))printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

Measured memory_bytes: 3120
IDENTIFICATION DIVISION.
      PROGRAM-ID. 051A.
      DATA DIVISION.
      WORKING-STORAGE SECTION.
      01 S PIC X(19).
      01 IDX PIC 9(1).
      
      PROCEDURE DIVISION.
      ACCEPT S.
      INSPECT S REPLACING ALL "," BY " ".
      DISPLAY S.
      STOP RUN.

Measured memory_bytes: 636
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
  int N;
  int A;
  cin >> N >> A ;
  N %= 500;
  if(N <= A){
    cout << "Yes";
  }else{
    cout << "No";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256