akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  string a;cin>>a;
  ll b=a.size()/2*2;
  if(b=a.size())b-=2;
  for(ll i=b;i>0;i-=2){
    string c=a.substr(0,i/2),d=a.substr(i/2,i/2);
    if(c==d){
      cout<<i;
      return 0;
    }
  }
}


Measured memory_bytes: 27032
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807

int field[1000][1000];

int check(int I, int J) {
	if (field[I][J] == 0) return false;
	int c = 0;
	for (int i = I - 1; i <= I + 1; i++) {
		for (int j = J - 1; j <= J + 1; j++) {
			if (field[i][j] == 0) c++;
		}
	}
	if (c >= field[I][J]) return true;
	else return false;
}

int main() {
	int H, W;
	cin >> H >> W;
	
	for (int i = 0; i < H; i++) {
		string tmp;
		cin >> tmp;
		for (int j = 0; j < W; j++) {
			if (tmp[j] == '.') field[i][j] = 0;
			else field[i][j] = tmp[j] - '0';
		}
	}

	set<pair<int, int> > changed;
	for (int i = 1; i < H-1; i++) {
		for (int j = 1; j < W-1; j++) {
			if (check(i, j)) {
				changed.insert(make_pair(i, j));
			}
		}
	}

	int ans = 0;
	while (true) {
		
		if (changed.size() == 0) break;
		vector<pair<int, int>> changed2;
		for (auto itr = changed.begin(); itr != changed.end(); itr++) {
			field[(*itr).first][(*itr).second] = 0;
			changed2.push_back(make_pair((*itr).first, (*itr).second));
		}
		changed.clear();

		for (auto itr = changed2.begin(); itr != changed2.end(); itr++) {
			for (int i = (*itr).first - 1; i <= (*itr).first + 1; i++) {
				for (int j = (*itr).second - 1; j <= (*itr).second + 1; j++) {
					if (check(i, j)) {
						changed.insert(make_pair(i, j));
					}
				}
			}
		}

		ans++;
	}
	cout << ans << endl;
}


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

using namespace std;
typedef long long ll;

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



    int f=0, t = 0;
    for(int i = 0; i < n; i++){
        int l; cin >> l;
        if(l % 4 == 0) f++;
        else if(l % 2 == 0) t++;

    }

    for(int i = 0; i < n; i++){
        if(f > 0){
            if(i % 2 == 1){
                f--;
                if(f > 0 || i + 1 == n-1)
                    i++;
            }
        }else{
            if(t>0){
                t--;
            }else{

                cout << "No";
                return 0;
            }
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int f[105][6][3], p[105][15], n,  pr[15];
long long ans;

int calc() {
    long long ts = 0;
    for (int i=1; i<=n; i++) {
        int c = 0;
        int vp = 0;
        for (int j=1; j<=5; j++) {
            for (int k=1; k<=2; k++) {
                if (pr[vp] == f[i][j][k] && f[i][j][k] == 1) {
                    c++;
                }
                vp++;
            }
        }
        ts += (long long)p[i][c];
    }

    return ts;
}
bool first = false;
void gao(int c, int x) {
    if (c == 10) {
        long long tv = calc();
        if (first == false) {
            ans = tv;
            first = true;
        } else {
            ans = ans > tv? ans: tv;
        }

        return ;
    }
    if (x != c) {
        pr[c] = 0;
        gao(c+1, x);
    }
    pr[c] = 1;
    gao(c+1,x);
}

int main()
{
    scanf("%d", &n);
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=5; j++) {
            for (int k=1; k<=2; k++) {
                scanf("%d", &f[i][j][k]);
            }
        }
    }
    for (int i=1; i<=n; i++) {
        for (int j=0; j<=10; j++) {
            scanf("%d", &p[i][j]);
        }
    }

    for (int i=0; i<10; i++) {
            gao(0, i);
    }

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


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

using namespace std;


void solve() {
    int N; cin >> N;
    vector<pair<int, int>> red(N), blue(N);
    for (int i = 0; i < N; i++) {
        int a, b; cin >> a >> b;
        red[i] = make_pair(a, b); //(x, f)
    }
    for (int i = 0; i < N; i++) {
        int c, d; cin >> c >> d;
        blue[i] = make_pair(c, d); //(x, y)
    }

    sort(red.begin(), red.end());
    sort(blue.begin(), blue.end());
    
    vector<bool> use(N);
    int ans = 0;

    for (int i = 0; i < N; i++) {
        int ma = -1, maxj;
        bool flag = false;
        for (int j = 0; j < N; j++) {
            if (red[j].first < blue[i].first && red[j].second < blue[i].second && red[j].second > ma && !use[j]) {
                ma = red[j].second;
                maxj = j;
                flag = true;
            }
        }
        if (flag) {
            use[maxj] = true;
            ans++;
        }
    }

    cout << ans << endl;
}


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

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<string>
using namespace std;
int main(){
  int N;
  cin>>N;
  char S[100];
  set<char> ans;
  for(int i=0;i<N;i++){
    cin>>S[i];
    ans.insert(S[i]);
  }
  if(ans.size()==4){
    cout<<"Four"<<endl;
  }else{
    cout<<"Three"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
//*******************************By Harry Singh From Phillaur.
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000006
const ll mo=1000000007;
#define string_to_any_base(s,base) stoll(s, 0, base);
#define vc vector
// #define mp map<ll,ll> mp;
#define bt(M,value) bitset<M> b(value)
#define S set<ll> s;
#define ST set<string> s;
#define INF 1e15
using namespace std;
set<ll> primes;
vector<pair<ll,ll>> adj[MAX];
vector<ll> ad[MAX];
///******************************ALL important functions;
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);} 
ll lcm(ll a, ll b)  {  return (a*b)/gcd(a, b);  } 
void Sieve(){ bool prime[MAX+1]; memset(prime, true, sizeof(prime)); for (int p=2; p*p<=MAX; p++) { if (prime[p] == true) {for (int i=p*p; i<=MAX; i += p) prime[i] = false; } } for(int i=2;i<=MAX;i++)if(prime[i]==true)primes.insert(i);} 
ll comb(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;}
ll modpow(ll a, ll n=mo-2) {ll r=1;while(n)r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;return r;}





int main()
{

ll n;
cin>>n;
ll a=1,b=1;
    for(int i=1;i<=n;i++){
        ll x,y;
        scanf("%lld%lld",&x,&y);
        ll  percent=max(a/x,b/y);//// we have to start form the previous max ratio,, if it not divisilbe then affcourse ratio wil be zero baby
        while(true)
        {
            if(percent*x>=a&&percent*y>=b)
                break;
            percent++;
        }
        
        a=percent*x;
        b=percent*y;
        
    }
    printf("%lld\n",a+b);
 











}



Measured memory_bytes: 47360
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N,M = map(int, input().split())

A = []
B = []

for _ in range(M):
    a,b = map(int, input().split())
    if a == 1: A.append(b)
    elif b == N: B.append(a)

B.sort()
for a in A:
    if bisect.bisect_left(B, a) < len(B) and B[bisect.bisect_left(B, a)]==a:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

Measured memory_bytes: 20472
#include <bits/stdc++.h>
using namespace std;
int main(){
  double x,h;
  while(cin >> x >> h){
    if(x+h==0){
      return 0;
    }
    printf("%.10lf\n",x*x+2*(sqrt((x/2)*(x/2)+h*h)*x));
  }
}



Measured memory_bytes: 3172
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, M = MI()
    s = [0] * M
    c = [0] * M

    for i in range(M):
        s[i], c[i] = MI()

    for i in range(1000):
        num = str(i)

        if len(num) != N:
            continue

        if all([len(num) >= s[j] and num[s[j]-1] == str(c[j]) for j in range(M)]):
            print(num)
            return

    print(-1)


if __name__ == '__main__':
    main()


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

long long int dp[100005][4];
long long int a[100005], b[100005], c[100005];

void init(int n) {
    for (int i = 0; i < n + 3; i++) {
        for (int j = 0; j < 4; j++) dp[i][j] = -1;
    }
}

long long int solve(int pos, char prev) {
    if (pos == 0) {
        if (prev == 'a') return max(b[0], c[0]);
        if (prev == 'b') return max(c[0], a[0]);
        if (prev == 'c') return max(a[0], b[0]);
        else return max(a[0], max(b[0], c[0]));
    }
    if (dp[pos][prev - 'a'] != -1) return dp[pos][prev - 'a'];
    if (prev == 'a') {
        dp[pos][prev - 'a'] = max(b[pos] + solve(pos - 1, 'b'), c[pos] + solve(pos - 1, 'c'));
    } else if (prev == 'b') {
        dp[pos][prev - 'a'] = max(a[pos] + solve(pos - 1, 'a'), c[pos] + solve(pos - 1, 'c'));
    } else if (prev == 'c') {
        dp[pos][prev - 'a'] = max(a[pos] + solve(pos - 1, 'a'), b[pos] + solve(pos - 1, 'b'));
    } else {
        dp[pos][prev - 'a'] = max(b[pos] + solve(pos - 1, 'b'), max(a[pos] + solve(pos - 1, 'a'), 
                        c[pos] + solve(pos - 1, 'c')));
    }
    return dp[pos][prev - 'a'];
}

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

    init(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    cout << solve(n - 1, 'd') << endl;
    return 0;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  int s=0;
  int M=0;
  vector<int>P(N);for(int i=0;i<N;i++){cin>>P[i];s+=P[i];M=max(M,P[i]);}
  cout<<s-M+M/2;
  
}

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

typedef long long ll;

int main(){
  ll N; cin >> N;
  ll cnt = 1;
  for(ll i = 0; i < N; i++){
    ll a; cin >> a;
    if(a == cnt) cnt++;
  }
  
  cout << ((cnt != 1)?(N - cnt + 1):(-1)) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
//　30min
int main(void){
  int a, b;
  int ans = 0;

  scanf("%d%d", &a, &b);

  if((a+b)%2 == 0){
    ans = (a+b) / 2;
  }else if((b-a)%2 == 0){
    ans = (b-a) / 2;
  }else{
    printf("IMPOSSIBLE\n");
    return 0;
  }

  if(ans < 0){
    ans *= (-1);
  }
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
    
    int in;
    int i=1;

    while (1)
    {
        scanf("%d", &in);

        if(in == 0){
            break;
        }
        else{
            printf("Case %d: %d\n", i, in);
            i = i + 1;
        }
    }
    

    return 0;
}


Measured memory_bytes: 2084
#include <cstdio>
#include <algorithm>
#define max_a 25
#define lim_n 20
#define lim_m 60
#define max_p 20
#define max_e 10000
using namespace std;
int q[max_p+1];
struct node{
	int u,v,w;
	node(){}
	node(int _u,int _v,int _w):u(_u),v(_v),w(_w){}
};
node e[max_e+1];
struct note{
	int u,v,w,k,tg;
	note(){}
	note(int _u,int _v,int _w,int _k,int _tg):u(_u),v(_v),w(_w),k(_k),tg(_tg){}
};
note ext[max_e+1],ext2[max_e+1];
void add(note*ext,const int&l,const int&r,int&m){
	note x;
	for(int i=l; ++i<=r; ){
		x=ext[i];
		for(int j=x.w*x.k+x.tg; (j-=x.w)>=x.tg; e[++m]=node(x.u,x.v,j));
	}
}
int main(){
	int l;
	scanf("%d",&l);
	if(l<=lim_m){
		printf("2 %d\n",l);
		for(puts("1 2 0"); --l; printf("1 2 %d\n",l));
		return 0;
	}
	--l;
	for(int a=1,p,m,lst,w,n,tmp,k,k2; ++a<=max_a; ){
		for(q[p=1]=(tmp=l)%a,w=1; tmp/=a; q[++p]=tmp%a,w*=a);
		for(lst=p+1,reverse(q+1,q+p+1),q[0]=m=tmp=k=k2=0; q[--lst]==a-1; );
		for(int i=0; ++i<lst; tmp+=q[i]*w,ext[++k]=note(i+1,i+2,w/=a,a,0))
			q[i]&&(ext2[++k2]=note(1,i+1,w,q[i],tmp),1);
		n=lst+1;
		lst&&(ext2[++k2]=note(1,n,w,q[lst]+1,tmp),w/=a);
//		note x;
//		for(int i=0; ++i<=k2; printf("%d %d %d %d %d\n",x.u,x.v,x.w,x.k,x.tg))
//			x=ext2[i];
		for(int j=lst,v; ++j<=p; n=v,w/=a)
			ext[++k]=note(n,v=n+1,w,a,0);
		add(ext,0,k,m);
		add(ext2,0,k2,m);
		if(n<=lim_n&&m<=lim_m){
			printf("%d %d\n",n,m);
			for(int i=0; ++i<=m; printf("%d %d %d\n",e[i].u,e[i].v,e[i].w));
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1704
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

vector<char> d;

bool f(string s){

  for(int i=0;i<s.size();i++){
    for(int j=0;j<d.size();j++){
      if(s[i]==d[j]) return false;
      //cout<<s[i]<<" "<<d[j]<<endl;
    }
  }
  return true;
}

int main(){
  int n,k;
  char t;
  cin>>n>>k;
  for(int i=0;i<k;i++){
    cin>>t;
    d.pb(t);
  }

  int res=n;
  while(true){
    //printf("%d\n",res);
    string s=to_string(res);
    if(f(s)) break;
    res++;
  }
  cout<<res<<endl;
  return 0;
}



Measured memory_bytes: 256
object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
    val x = List(Array(0, in.next.head-1, 2147483647))
    in.foldLeft(x)((qs, q) => q match {
        case Array(0, _*) => q.tail +: qs
        case Array(1, i) => {
            println((qs.find(y => y(0) <= i && y(1) >= i).get)(2))
            qs
        }
    })
}

Measured memory_bytes: 192860
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    int test=0;
    vector <int> b(n-1);
    generate(all(b),nxt);
    test+=b[0];
    test+=b[n-2];
    for(int i=0;i<n-2;i++)
        test+=min(b[i],b[i+1]);
    cout<<test<<endl;
    
    
    return 0;   
}


 
 


Measured memory_bytes: 256
num = int(input())
s = list(map(int, input().split()))
cnt = 0

def merge(A, left, mid, right):
    global cnt
    
    L = A[left:mid] + [10**9 + 1]
    R = A[mid:right] + [10**9 + 1]
    i = 0
    j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    cnt += right - left

def merge_sort(A, left, right):
    if (left + 1) < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)


merge_sort(s, 0, num)

print(*s)
print(cnt)


Measured memory_bytes: 63692
MOD=10**9+7
cnt=0; sum=0; prev=nil; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
s=gs
msg =
 if s=='Sunny'
   'Cloudy'
 elsif s=='Cloudy'
   'Rainy'
 else
   'Sunny'
 end
puts msg

Measured memory_bytes: 1788
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void){
	int n,a[1000],i,j,sum,temp;
	cin>>n;
	for(i=0;i<n;i++) cin>>a[i];
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(a[i]>a[j]){
				temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}
		}
	}
//	for(i=0;i<n;i++) cout<<a[i]<<endl;
	sum=0;
	for(i=0;i<n-1;i++) sum+=a[i+1]-a[i];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
my $input = <>;
my ($A, $B, $K) =  split(' ', $input);

my $A_yakusu = get_yakusu($A);
my $B_yakusu = get_yakusu($B);

my @koyakusu = ();
for my $num (keys %{$A_yakusu}) {
    push @koyakusu, $num if exists $B_yakusu->{$num};
}

my @sorted = sort {$a <=> $b } @koyakusu;
print $sorted[-$K];

sub get_yakusu {
    my $number = shift;

    my $hash = {};
    for my $num ( 1.. $number ) {
        $hash->{$num} = 1 if $number % $num == 0;
    }
    return $hash;
}

Measured memory_bytes: 512
/*raghav0307 - Raghav Gupta*/

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

#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
#define int ll
const int MAX_N = 2e3 + 5;

int n;
string s;
vector<int> graph[MAX_N];

int low[MAX_N], high[MAX_N], cnt[MAX_N];

void dfs(int nd, int parent){
	cnt[nd] = 0;
	high[nd] = 0;
	low[nd] = 0;
	if(s[nd-1] == '1')	cnt[nd]++;
	int max_si = 0;
	int max_pos = 0;
	int sum_si = 0;
	int ans1 = 0;
	for(auto x : graph[nd]){
		if(x == parent)	continue;
		dfs(x, nd);
		cnt[nd] += cnt[x];
		high[nd] += cnt[x] + high[x];
		ans1 += (cnt[x] + low[x])%2;
		sum_si += (cnt[x] + high[x]);
		if((cnt[x] + high[x]) > max_si){
			max_si = (cnt[x] + high[x]);
			max_pos = x;
		}
	}
	// cout << sum_si << " " << max_si << "\n";
	int ans2 = 0;
	if(max_si*2 > sum_si){
		// cout << "Woah!\n"; 
		ans2 = 2*max_si - (sum_si - low[max_pos] + high[max_pos]);
	}
	low[nd] = max(ans1%2, ans2);
	// cout << "cnt[" << nd << "]: " << cnt[nd] << "\n";
	// cout << "low[" << nd << "]: " << low[nd] << "\n";
	// cout << "high[" << nd << "]: " << high[nd] << "\n";
}

signed main(){
	fast_io();
	cin >> n;
	cin >> s;
	for(int i = 0; i < n-1; i++){
		int a, b;
		cin >> a >> b;
		graph[a].pb(b);
		graph[b].pb(a);
	}
	int ans = 1e8;
	for(int i = 1; i <= n; i++){
		dfs(i, -1);
		if(low[i] == 0) ans = min(ans, high[i]/2);
	}

	if(ans == (int)1e8)	cout << "-1";
	else cout << ans;

	return 0;
}

Measured memory_bytes: 640
#include <stack>
using namespace std;

struct Rectangle {
  int height;
  int pos;
};
 

#include <stdio.h>
#define SIZ 1400
int m[SIZ+1][SIZ+1];
int st[SIZ];
char z[9999999];
int get(){
	static int input_count=0;
	int r=0;
	for(;'0'<=z[input_count]&&z[input_count]<='9';)r=r*10+z[input_count++]-'0';
	input_count++;
	return r;
}
int main(){
	fread(z,1,sizeof(z),stdin);
	int i,j,k,y=get(),x=get(),r,ptr;
	for(j=0;j<y;j++)for(r=i=0;i<x;m[j][i]=r,i++){
		int t=get();
		r=t==0?r+1:0;
	}
	r=0;
/*
	for(i=0;i<x;i++)for(ptr=j=0;j<=y;j++){
		//printf("%d %d %d %d\n",i,j,ptr,m[j][i]);
		if(!ptr || st[ptr-1]<m[j][i])st[ptr++]=m[j][i];
		else{
			for(;ptr && st[ptr-1]>m[j][i];){
				int _y=(j-(ptr-1)),_x=st[--ptr];
				//printf("%d %d\n",_x,_y);
				if(r<_x*_y)r=_x*_y;
			}
			st[ptr++]=m[j][i];
		}
	}
*/
	Rectangle rect;
	for(int i=0;i<x;i++){
		stack<Rectangle> stk;
		for(int j=0;j<=y;j++){
			rect.height = m[j][i];
			rect.pos = j;
			if(stk.empty() || stk.top().height < rect.height){
				stk.push(rect);
			}else{
				int target = j;
				for(;!stk.empty() && stk.top().height >= rect.height;){
					Rectangle pre = stk.top(); stk.pop();
					int area = pre.height * (j - pre.pos);
					r = max(r, area);
					target = pre.pos;
				}
				rect.pos = target;
				stk.push(rect);
			}
		}
	}

	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 14312
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<int>> a(n, vector<int>(m));
  vector<int> cost(n);
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    for (int j = 0; j < m; j++) 
      cin >> a[i][j];
  }
  bool can = false;
  ll res = numeric_limits<ll>::max();
  for (int i = 0; i <= (1 << n); i++) {
    vector<int> picked(n);
    for (int j = 0; j < n; j++) 
      if ((1 << j) & i)
        picked[j] = 1;
    vector<ll> tot(m);
    ll cur = 0;
    for (int j = 0; j < n; j++) {
      if (picked[j]) {
        cur += cost[j];
        for (int k = 0; k < m; k++) 
          tot[k] += a[j][k];
      }
    }
    bool ok = true;
    for (ll p : tot) 
      if (p < x)
        ok = false;
    if (ok) {
      res = min(res, cur);
      can = true;
    }
  }
  if (!can) {
    cout << "-1\n";
  } else {
    cout << res << '\n';
  }
  return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	string S;
	cin >> S;
	reverse(S.begin(), S.end());
	string comp[] = { "dreamer","eraser","dream","erase" };
	REP(i, 4) reverse(comp[i].begin(), comp[i].end());
	int l = 0;
	while (l < S.size()) {
		if (S.substr(l, 7) == comp[0]) {
			l += 7;
			continue;
		}
		else if (S.substr(l, 6) == comp[1]) {
			l += 6;
			continue;
		}
		else if (S.substr(l, 5) == comp[2] || S.substr(l, 5) == comp[3]) {
			l += 5;
			continue;
		}
		else {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;
using ll = long long;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int main() 
{
	int h, w, i, j, n;
	char s[51][51] = {};

	cin >> h >> w;

	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			cin >> s[i][j];
		}
	}

	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			n = 0;
			if (s[i][j] == '#') {
				cout << '#';
				continue;
			}
			if (i > 0 && j > 0 && s[i - 1][j - 1] == '#') {
				n++;
			}
			if (i > 0 && s[i - 1][j] == '#') {
				n++;
			}
			if (i > 0 && j < w - 1 && s[i - 1][j + 1] == '#') {
				n++;
			}
			if (j > 0 && s[i][j - 1] == '#') {
				n++;
			}
			if (j < w - 1 && s[i][j + 1] == '#') {
				n++;
			}
			if (i < h - 1 && j > 0 && s[i + 1][j - 1] == '#') {
				n++;
			}
			if (i < h - 1 && s[i + 1][j] == '#') {
				n++;
			}
			if (i < h - 1 && j < w - 1 && s[i + 1][j + 1] == '#') {
				n++;
			}
			cout << n;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll long long
using namespace std;
int main(){
    int N;
    cin >> N;
    int A;
    int mx = -INF,mn = INF;
    ll sum = 0;
    for(int i=1;i<=N;i++){
        cin >> A;
        mx = max(mx,A);
        mn = min(mn,A);
        sum += A;
    }
    cout << mn << " " << mx << " " << sum << endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const double PI = acos(-1);
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    double a, b, x; cin >> a >> b >> x;
    double t;
    if (x >= a * a * b / 2) {
        t = atan(2*b/a - 2*x/a/a/a);
    } else {
        t = atan(a*b*b/2/x);
    }
    cout << fixed << setprecision(9) << 180.0 / PI * t << endl;
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define asort(x) sort(x.begin(),x.end())

bool isPrime(ll n) {
    ll sq = sqrt(n);
    for(int i = 3; i < sq; i += 2) {
        if(n % i == 0) return false;
    }
    return true;
}

int main() {
    ll n;
    ll sum = 0;
    cin >> n;
    vector<ll> a(n+1,0);
    for(int i = 1; i <= n; i++) {
        for(int j = i; j <= n; j+=i) a[j]++;
    }
    rep(i,n+1) sum += i * a[i];
    cout << sum << endl;
    return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  rep(i,H) {
    cin >> a[i];
  }
  
  vector<bool> row(H, false);
  vector<bool> col(W, false);
  rep(i,H) {
    rep(j,W) {
      if (a[i][j]=='#') {
        row[i] = true;
        col[j] = true;
      }
    }
  }
  
  rep(i,H) {
    if (!row[i]) continue;
    rep(j,W) {
      if (!col[j]) continue;
      cout << a[i][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())

a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()

d = 0
e = 0
ans = 0
for i in b:
    while i > a[min(d,n-1)] and d <= n-1:
        d += 1
    while i >= c[min(e,n-1)] and e < n:
        e += 1
    ans += d*(n-e)

print(ans)

Measured memory_bytes: 23328
#include <bits/stdc++.h>
#define fr first
#define sc scanf
#define pf printf
#define se second
#define sq(x) x * x
#define ll long long
#define pb push_back
#define mk make_pair
#define ld long double
#define pr pair<int,int>
#define sz(s) int(s.size())
#define piip pair< pair<ll,ll>,ll >
#define fin(s) freopen( s, "r", stdin )
#define fout(s) freopen( s, "w", stdout )
#define TIME ios_base::sync_with_stdio(0)
using namespace std;

const ll INF = 1e9;
const ll N = 2e2+7;
const ll mod = 1e9 + 7;
const long double eps = 1E-7;
ll a, b, n , cnt ,mx,ans,c;
ll used[ N ];
ld x , y;
string s[4]={"A","C","G","T"};
char z;
int main()
{
        TIME;
        cin >> z;
        if( z=='A' )
        cout<<"T";
        if( z=='T' )
            cout<<"A";
        if( z=='G' )
            cout<<"C";
        if( z=='C' )
            cout<<"G";
}


/* MADE BY
//________________________________________________________
//________________________________________________________ //
                                                           //
// ██╗   ██╗     ██████╗     ███████╗    ██╗    ███╗   ██╗ //
// ╚██╗ ██╔╝    ██╔═══██╗    ██╔════╝    ██║    ████╗  ██║ //
//  ╚████╔╝     ██║   ██║    ███████╗    ██║    ██╔██╗ ██║ //
//   ╚██╔╝      ██║   ██║    ╚════██║    ██║    ██║╚██╗██║ //
//    ██║       ╚██████╔╝    ███████║    ██║    ██║ ╚████║ //
//    ╚═╝        ╚═════╝     ╚══════╝    ╚═╝    ╚═╝  ╚═══╝ //
//________________________________________________________ //
//________________________________________________________ */


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	char a[4],b[4];
	scanf("%s%s",a,b);
	if((a[0]==b[2])&&(a[1]==b[1])&&(a[2]==b[0])){
		printf("YES");
	}else{
		printf("NO");
	}
	return 0;
}

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

int main() {
  int N;
  vector<int> h(100010);
  vector<int> dp(100010);

  int res = 0;

  cin >> N;
  rep(i,N){
    cin >> h.at(i);
  }  

  dp.at(1) = abs(h.at(1) - h.at(0));

  for(int i=2; i < N; i++){
    dp.at(i) = min(dp.at(i-1)+abs(h.at(i) - h.at(i-1)),
                   dp.at(i-2)+abs(h.at(i) - h.at(i-2)));
  }

  cout << dp.at(N-1) << endl;
  
  return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    int x = sc.nextInt();
    int ans = x;
    for(int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int b = ((d - 1) / a) + 1;
      ans += b;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1000000000; 

int main(){
  ll h,w;
  cin >> h >> w;
  if(h == 1 || w == 1){
    cout << 1 << endl;
    return 0;
  }
  cout << (h*w+1)/2 << endl;
}

Measured memory_bytes: 764
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    h, w = LI()
    a, b = LI()
    return (h - a) * (w - b)


print(main())


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

int main()
{
	string s1,s2;
	cin >> s1 >> s2;
	reverse(s2.begin(),s2.end());
	if(s1 == s2){
		cout << "YES\n";
	}else{
		cout << "NO\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int a, b, c, t, res;

signed main() {
	cin >> a >> b >> c;
	res = min(a,c), a -= res, c -= res;
	t = min(b,c), b -= t, c -= t, res += t*2;
	res += b;
	if (c) res++;
	cout << res << endl;
}

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

const int MN = 310;
using D = double;
int n;

D dp[MN][MN][MN];
bool vis[MN][MN][MN];
D solve(int one, int two, int three) {
    if (!one && !two && !three) return 0;
    if (vis[one][two][three]) return dp[one][two][three];
    vis[one][two][three] = true;
    D ans = 1;
    if (one) ans += D(one) / D(n) * solve(one-1, two, three);
    if (two) ans += D(two) / D(n) * solve(one + 1, two-1, three);
    if (three) ans += D(three) / D(n) * solve(one, two + 1, three-1);
    ans *= D(n) / D(one + two + three);
    return dp[one][two][three] = ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(20) << fixed;

    cin >> n;
    int one = 0, two = 0, three = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a == 1) one++;
        else if (a == 2) two++;
        else three++;
    }

    cout << solve(one, two, three) << endl;
    return 0;
}


Measured memory_bytes: 256256
#include<stdio.h>

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

int main(void){
  int n,m; scanf("%d%d",&n,&m);
  long long int h[n];
  rep(i,0,n-1){
    scanf("%lld",&h[i]);
  }

  int cnt[n];
  rep(i,0,n-1){
    cnt[i] = 0;
  }

  rep(i,1,m){
    int a,b;
    scanf("%d%d",&a,&b);
    if(h[a-1] < h[b-1]){
      cnt[a-1]++;
    }
    else if(h[a-1] > h[b-1]){
      cnt[b-1]++;
    }
    else{
      cnt[a-1]++;
      cnt[b-1]++;
    }
  }

  int result = 0;
  rep(i,0,n-1){
    if(cnt[i] == 0){
      result++;
    }
  }

  printf("%d",result);
  return 0;
}


Measured memory_bytes: 2872
from sys import stdin
n = int(stdin.readline().rstrip())
li = []
for i in range(n):
    s = int(stdin.readline().rstrip())
    lin = [list(map(int,stdin.readline().rstrip().split())) for _ in range(s)]
    li.append(lin)
ma = 0
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
for i in range(2**n):
    keta = Base_10_to_n(i,2).zfill(n)
    point = keta.count("1")
    flag = False
    for j,k in enumerate(keta):
        if k == "1":
            for l in li[j]:
                if keta[l[0]-1] != str(l[1]):
                    flag = True
    if flag:
        continue
    ma = max(ma,point)
print(ma)

Measured memory_bytes: 3188
package main

import (
	"bytes"
	"fmt"
)

var (
	n    int
	m    int
	sum  int
	tmp  int
	p, x int
)

func main() {
	b := bytes.NewBufferString("")

	fmt.Scan(&n)
	t := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		t[i] = tmp
		sum += tmp
	}

	fmt.Scan(&m)
	for i := 0; i < m; i++ {
		fmt.Scan(&p, &x)
		b.WriteString(fmt.Sprintln(sum - (t[p-1] - x)))
	}

	fmt.Print(b.String())

}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 1000000009;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

int main()
{
//IOIOI
	int n;
	while (cin >> n && n)
	{
		int m; cin >> m;
		string s; cin >> s;
		int ans = 0;
		int pre = s[0] == 'I' ? 0 : -1;
		for (int i = 1; i < m; i++)
		{
			if (s[i - 1] == 'O' && s[i] == 'I')
			{
				pre++;
				if (pre >= n) ans++;
			}
			else if (s[i - 1] == 'I' && s[i] == 'O');//pre=pre
			else pre = s[i] == 'I' ? 0 : -1;
		}
		cout << ans << endl;
	}
	return 0;
}

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

#define ll long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

set<ll> v[200005];
bool vis[200005]={false};
vector<ll> vv;

void dfs(ll idx)
{
	vis[idx]=true;
	for(auto it:v[idx])
	{
		if(!vis[it])
		{
			dfs(it);
			vv.push_back(it);
		}
	}
}

void solve()
{
	ll n,m;
	cin>>n>>m;
	for(ll i=0;i<m;i++)
	{
		ll x,y;
		cin>>x>>y;
		v[x].insert(y);
		v[y].insert(x);
	}
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			vv.clear();
			dfs(i);
			ans=max(ans,(ll)vv.size());
			//cout<<(ll)vv.size()<<endl;
		}
	}
	cout<<ans+1;
}

int main()
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

Measured memory_bytes: 46120
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<=n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
signed main(){
  int a,b;
  cin>>a>>b;
  rep(i,a){
  rep(j,a){
    int c=a-i-j;
  if(i*10000+j*5000+c*1000==b&&0<=c){
    cout<<i<<' '<<j<<' '<<c<<endl;
    return 0;
    }
  }
  }
  cout<<"-1 -1 -1";
}

Measured memory_bytes: 256
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()
BtoC = [0 for i in range(N+1)]
for i in range(N-1, -1, -1):
    c_idx = bisect.bisect_right(C, B[i])
    BtoC[i] = BtoC[i+1] + (N - c_idx)
count = 0
for i in range(N):
    b_idx = bisect.bisect_right(B, A[i])
    count += BtoC[b_idx]


print(count)

Measured memory_bytes: 23360
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	int l = floor(sqrt(2 * n));
	if (2 * n != l * (l + 1))
	{
		cout << "No" << endl;
		return 0;
	}
	vector<vector<int>> res(l + 1);
	rep(i, l)res[0].push_back(i + 1);
	for (int i = 1; i <= l; ++i)
	{
		rep(j, i)res[i].push_back(res[j][i - 1]);
		int next = res[i - 1].back() + 1;
		for (int j = i; j < l; ++j)
		{
			res[i].push_back(next);
			++next;
		}
	}
	cout << "Yes" << endl;
	cout << l + 1 << endl;
	rep(i, l + 1)
	{
		cout << l << " ";
		for (int x : res[i])cout << x << " ";
		cout << "" << endl;
	}
}

Measured memory_bytes: 2304
#include<stdio.h>
#include<cmath>
using namespace std;
typedef long long llong;

int main()
{
    llong A,B;
    scanf("%lld %lld",&A,&B);

    A = A - 1;
    llong Adigit = 0;
    llong Bdigit = 0;

    llong tempRem = 0;
    tempRem = A % 4;
    if (tempRem == 1 || tempRem == 2){
        Adigit = 1;
    }

    tempRem = B % 4;
    if (tempRem == 1 || tempRem == 2){
        Bdigit = 1;
    }

    for (int i = 1; i < 40; i++){
        tempRem = A % (llong)powl(2, i + 1);
        if (tempRem >= (llong)powl(2, i)){
            tempRem = (tempRem + 1) % 2;
            Adigit = Adigit + tempRem * (llong)powl(2, i);
        }

        tempRem = B % (llong)powl(2, i + 1);
        if (tempRem >= (llong)powl(2, i)){
            tempRem = (tempRem + 1) % 2;
            Bdigit = Bdigit + tempRem * (llong)powl(2, i);
        }
    }
    // 出力
    printf("%lld\n", (llong)(Bdigit ^ Adigit));
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#define long long int int
using namespace std;

const int maxk = 18;

class edge{
public:
  int t,c,l;

  edge(int to, int color, int length) : t(to),c(color),l(length) {}
};

int depth[100005];
int parent[maxk + 1][100005];
vector<edge> g[100005];
int dist[100005];

void dfs(int v, int prev, int d, int de) {
  depth[v] = d;
  parent[0][v] = prev;
  dist[v] = de;
  for(int i = 0; i < g[v].size(); i++) {
    int u = g[v][i].t;
    if(u != prev) {
      // dist[u] = dist[v] + g[v][i].l;
      dfs(u,v,d+1,de+g[v][i].l);
    }
  }
  
  return;
}

  

void init(int V) {
  dfs(0,-1,0,0);
  
  for(int k = 0; k < maxk; k++) {
    for(int i = 0; i < V; i++) {
      if(parent[k][i] < 0) parent[k+1][i] = -1;
      else parent[k+1][i] = parent[k][parent[k][i]];
    }
  }
  return;
}

int lca(int u, int v) {
  if(depth[u] > depth[v]) swap(u,v);
  for(int k = 0; k < maxk; k++) {
    if((depth[v] - depth[u]) >> k & 1) {
      v = parent[k][v];
    }
  }
  if(u == v) return u;
  for(int k = maxk - 1; k >= 0; k--) {
    if(parent[k][u] != parent[k][v]) {
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}


int n,q;

typedef pair<int,int> P;
map<int,P> s[100005];

int C[100005];
int D[100005];


void dfs2(int v, int prev) {
 
  for(auto itr = s[v].begin(); itr != s[v].end(); ++itr) {
    int u = itr->first;
    itr->second.first = C[u];
    itr->second.second = D[u];
    
  }

  for(int i = 0; i < g[v].size(); i++) {
    int u = g[v][i].t;
    if(u != prev) {
      C[g[v][i].c]++;
      D[g[v][i].c] += g[v][i].l;
      dfs2(u,v);
      C[g[v][i].c]--;
      D[g[v][i].c] -= g[v][i].l;
    }
  }
  
}

int x[100005];
int y[100005];
int u[100005];
int v[100005];

signed main() {
  cin >> n >> q;



  for(int i = 0; i < n - 1; i++) {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    a--,b--;
    g[a].push_back(edge(b,c,d));
    g[b].push_back(edge(a,c,d));
  }

    init(n);
 
  for(int i = 0; i < q; i++) {
    cin >> x[i] >> y[i] >> u[i] >> v[i];
    u[i]--,v[i]--;
   
    s[u[i]][x[i]] = P(0,0);
    s[v[i]][x[i]] = P(0,0);
    int t = lca(u[i],v[i]);
    s[t][x[i]] = P(0,0);
  }
  dfs2(0,-1);

  for(int i = 0; i < q; i++) {
    int tmp = s[u[i]][x[i]].first * y[i];
    int tmp2 = s[v[i]][x[i]].first * y[i];
    int tmp3 = s[lca(u[i],v[i])][x[i]].first * y[i];

    int tmp4 = s[u[i]][x[i]].second;
    int tmp5 = s[v[i]][x[i]].second;
    int tmp6 = s[lca(u[i],v[i])][x[i]].second;
    
    int di = dist[u[i]] + dist[v[i]] - 2 * dist[lca(u[i],v[i])];
    int di2 = tmp4 + tmp5 - 2 * tmp6;
    int di3 = tmp + tmp2 - 2 * tmp3;
    
    
    cout << di - di2 + di3 << endl;
    
  }
}
			      


Measured memory_bytes: 41784
n = int(input())
a = list(map(int, input().split()))

c = [0 for i in range(1+10**5)]

for i in range(n):
    c[a[i]] += 1

ans = 0
for i in range(1+10**5):
    if i==0:
        if ans < c[i]+c[i+1]:
            ans = c[i]+c[i+1]
    elif i==10**5:
        if ans < c[-2]+c[-1]:
            ans = c[-2]+c[-1]
    elif ans < c[i-1] + c[i] + c[i+1]:
        ans = c[i-1] + c[i] + c[i+1]

print(ans)
    

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

int main()
{
    int ans = 0;
    string in_str;
    while(getline(cin, in_str))
    {
        string work_str;
        for(int i=0; i<in_str.size(); i++)
        {
            if(in_str[i] >= '0' && in_str[i] <='9')
            {
                string ch(1, in_str[i]);
                work_str = work_str + ch;
                if(i == in_str.size()-1)
                {
                    ans += std::stoi(work_str); 
                    work_str.clear();
                }
            }
            else
            {
                if(work_str.size() > 0)
                {
                    ans += std::stoi(work_str); 
                    work_str.clear();
                }
            }    
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3156
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (unsigned int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}

class AEatingSymbolsEasy {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    string S;
    cin >> S;
    int ans = 0;
    rep(i, S.size()) {
      if (S[i] == '+') ans++;
      if (S[i] == '-') ans--;
    }
    cout << ans << endl;
  }
};


signed main() {
  AEatingSymbolsEasy solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

def main():
    n = int(input())
    a = list(map(int, input().split()))
    so = [0 for i in range(n)]
    for i in range(n - 1):
        j = a[i]
        so[j - 1] += 1
    for s in so:
        print(s)

if __name__ == "__main__":
    main()


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

int main(int argc, char const *argv[]) {
    int N;
    string S;
    cin >> N >> S;

    int num = 1;
    for (int i = 0; i < N-1; i++) {
        if (S.at(i) == S.at(i+1)) continue;
        else {
            num += 1;
        }
    }

    cout << num << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

 
int main() {
  int H=0,A=0;
  cin >> H >> A;
  if(H<=A){
    cout << 1 << endl;
  }
  else if(H % A == 0){
    cout << H/A << endl;
  }
  else {
    cout << H/A + 1 << endl;
  }
}

Measured memory_bytes: 256