akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

constexpr int N = 100000 + 10, L = 22;
int n, p[N], mx[N][L], lg[N];

int Mx(int l, int r) {
    int j = lg[r - l + 1];
    return max(mx[l][j], mx[r - (1 << j) + 1][j]);
}

int mn_idx(int l, int r, int x) {
    if(r < l || Mx(l, r) < x) return r;
    int L = l, R = r;
    while(r - l > 1) {
        int m = (l + r) >> 1;
        if(Mx(L, m) > x) {
            r = m;
        } else {
            l = m + 1;
        }
    }
    if(Mx(L, l) > x) r = l;
    return r;
}

int mx_idx(int l, int r, int x) {
    if(r < l || Mx(l, r) < x) return l;
    int L = l, R = r;
    while(r - l > 1) {
        int m = (l + r) >> 1;
        if(Mx(m, R) > x) {
            l = m;
        } else {
            r = m - 1;
        }
    }
    if(Mx(r, R) > x) l = r;
    return l;
}


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> p[i];
        mx[i][0] = p[i];
    }
    for(int i = 2; i < N; ++i) {
        lg[i] = lg[i >> 1] + 1;
    }
    for(int j = 1; j < L; ++j) {
        for(int i = 0; i + (1 << j) < N; ++i)
            mx[i][j] = max(mx[i][j - 1], mx[i + (1 << (j - 1))][j - 1]);
    }

    long long ans = 0;
    for(int i = 1; i <= n; ++i) {
        int lr = mx_idx(0, i - 1, p[i]);
        int ll = mx_idx(0, lr - 1, p[i]);
        int rl = mn_idx(i + 1, n + 1, p[i]);
        int rr = mn_idx(rl + 1, n + 1, p[i]);

        long long t = 0;
        t += 1ll * (lr - ll) * (rl - i) * p[i];
        t += 1ll * (rr - rl) * (i - lr) * p[i];
        ans += t;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 9600
# encoding: utf-8
N = int(input())
a = list(map(int, input().split()))

ans = 0
for ai in a:
    ai_tmp = ai
    ans_tmp = 0
    for i in range(32):
        if ai_tmp % 2: break
        else:
            ans_tmp += 1
            ai_tmp = ai_tmp // 2
    ans += ans_tmp

print(ans)

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

int main () {
    int N, K;
    cin >> N >> K;
    vector <int>vec(N);
    for (int i=0; i<N; i++) {
        cin >> vec.at(i);
    }
    int sum=0;
    for (int i=0; i<N; i++) {
        if (vec.at(i)>K/2) {
            sum+=(K-vec.at(i))*2;
        }
        else {
            sum+=vec.at(i)*2;
        }
    }
    cout << sum << endl;
}    

Measured memory_bytes: 3624
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

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

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let r:i32 = read();
    let d:i32 = read();
    let mut x:i32 = read();

    for i in 1..11 {
        x = r*x - d;
        println!("{}", x);
    }
}


Measured memory_bytes: 4352
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



string s;
vector<int> data[30];

int main () {
  cin >> s;
  int n = s.size();

  Rep(i, n) {
    data[s[i]-'a'].push_back(i);
  }

  Rep(k, 26) {
    int len = data[k].size();

    if (len <= 1) {
      continue;
    }

    int tmp = data[k][0];

    for (int i=1;i<len;++i) {
      int next = data[k][i];

      if ((next - tmp) <= 2) {
        cout << (tmp + 1) << " " << (next + 1) << "\n";
        return 0;
      } 

      tmp = next;
    }
  }

  cout << -1 << " " << -1 << "\n";
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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 x;
    cin >> x;
    int y=x/100;
    if (y>=20) cout << 1 << endl;
    else {
        x%=100;
        if (x<=y*5) cout << 1 << endl;
        else cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX_N 500000
vector<int>X[MAX_N]; queue<int>Q;
int COLOR[MAX_N], N, M, Q1, A, B;
int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) { cin >> A >> B; X[A].push_back(B); X[B].push_back(A); }
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (COLOR[i] == 0) {
            Q.push(i); cnt++; COLOR[i] = cnt;
            while (!Q.empty()) {
                int a = Q.front(); Q.pop();
                for (int j = 0; j < X[a].size(); j++) {
                    int to = X[a][j];
                    if (COLOR[to] == 0) {
                        COLOR[to] = cnt;
                        Q.push(to);
                    }
                }
            }
        }
    }
    cin >> Q1;
    for (int i = 0; i < Q1; i++) {
        cin >> A >> B;
        if (COLOR[A] == COLOR[B]) {
            cout << "yes" << endl;
        }
        else {
            cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 18400
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int n;
    cin>>n;
    V<int> ind(n+1,0);
    for(int i=0;i<n;i++){
        ll a;cin>>a;
        ind[a]=i;
    }
    set<int> s;
    V<ll> L(2),R(2); 
    int pos=0;
    ll a,b,c,d;
    ll ans=0;
    for(ll x=n;x>=1;x--){
        s.insert(ind[x]);
        L[0]=L[1]=-1;
        R[0]=R[1]=n;
        auto ite=s.find(ind[x]);
        pos=1;
        while(pos>=0&&ite!=s.begin()){
        ite--;
        L[pos--]=*ite;
        }
        ite=s.find(ind[x]);
        ite++;pos=0;
        while(pos<2&&ite!=s.end()){
            R[pos++]=*ite;
            if(pos!=2)ite++;
        }
        a=ind[x]-L[1];
        b=R[0]-ind[x];
        c=L[1]-L[0];
        d=R[1]-R[0];
        ans+=(a*d+b*c)*x;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 5376
#include<stdio.h>
#include<math.h>
double d,r,s,z[6];
int n,i,j,a[50];
int main(){
	for(scanf("%d",&n);n--;){
		for(i=0;i<6;i++)
			scanf("%lf",z+i);
		r=z[2];
		s=z[5];
		d=hypot(*z-z[3],z[1]-z[4]);
		printf("%d\n",a[j++]=d>r+s?0:r>d+s?2:s>d+r?-2:1);
	}
	
	return
		n==14 &&
		a[0]==1 &&
		a[1]==1 &&
		a[2]==1 &&
		a[3]==0 &&
		a[4]==2 &&
		a[5]==2 &&
		a[6]==-2 &&
		a[7]== 0&&
		a[8]== 0&&
		a[9]==1 &&
		a[10]==1 &&
		a[11]==-2 &&
		a[12]==1 &&
		a[13]==2;
}

Measured memory_bytes: 0
#define Kafuu signed
#define Chino main

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>

#define maxn 305
#define inf 0x3f3f3f3f
#define pn putchar('\n')
#define px(x) putchar(x)
#define ps putchar(' ')
#define pd puts("======================")
#define pj puts("++++++++++++++++++++++")

const int mod = 1e9+7;

using namespace std;

inline int read(){
	int x=0,y=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')y=1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return y?-x:x;
}
template<typename T>
inline T read(){
	T x=0;
	int y=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')y=1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return y?-x:x;
}
inline int ran(){
	static int seed=703;
	return seed=int(seed*48271LL%2147483647);
}
#define in(l,r,x) (l<=x&&x<=r)
vector<int>limit[maxn];
int l[maxn],c[maxn],f[maxn][maxn][maxn];
inline int count(int l,int r,int c1,int c2,int c3){
	return in(l,r,c1)+in(l,r,c2)+in(l,r,c3);
}
Kafuu Chino(){
	int n=read(),m=read(),k1,k2,k3,x,ans=0;
	for(register int i=1;i<=m;++i)
		l[i]=read(),limit[read()].push_back(i),c[i]=read();
	if(n==1){
		ans=3;
		for(register int i=1;i<=m;++i)
			if(c[i]==1)ans=min(ans,1);
			else ans=0;
		printf("%d\n",ans);
		return 0;
	}
	f[1][0][0]=1;
	for(register int c1=1;c1<n;++c1)
		for(register int c2=0;c2<c1;++c2)
			for(register int c3=0;c3<=max(c2-1,0);++c3){
				bool ok1=1,ok2=1,ok3=1;
				for(register int j=0;j<limit[c1+1].size();++j){
					x=limit[c1+1][j];
					k1=count(l[x],c1+1,c1+1,c2,c3),k2=count(l[x],c1+1,c1,c1+1,c3),k3=count(l[x],c1+1,c1,c2,c1+1);
					ok1&=(k1==c[x]),ok2&=(k2==c[x]),ok3&=(k3==c[x]);
				}
//				if(ok1)printf("f( %d, %d, %d )[%d] => f( %d, %d, %d )\n",c1,c2,c3,f[c1][c2][c3],c1+1,c2,c3);				
//				if(ok1)printf("f( %d, %d, %d )[%d] => f( %d, %d, %d )\n",c1,c2,c3,f[c1][c2][c3],c1+1,c1,c3);
//				if(ok1)printf("f( %d, %d, %d )[%d] => f( %d, %d, %d )\n",c1,c2,c3,f[c1][c2][c3],c1+1,c1,c2);
				if(ok1)(f[c1+1][c2][c3]+=f[c1][c2][c3])%=mod;
				if(ok2)(f[c1+1][c1][c3]+=f[c1][c2][c3])%=mod;
				if(ok3)(f[c1+1][c1][c2]+=f[c1][c2][c3])%=mod;
			}	
//	for(register int i=1;i<=n;++i,pd)
//		for(register int j=0;j<=n;++j,pn)
//			for(register int k=0;k<=n;++k)
//				printf("%d ",f[i][j][k]);
		for(register int j=0;j<n;++j)
			for(register int k=0;k<=max(j-1,0);++k)
				(ans+=f[n][j][k])%=mod;
	printf("%d\n",((ans<<1)%mod+ans)%mod);
}


Measured memory_bytes: 108800
#include <bits/stdc++.h>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    int ary[n];
    rep(i, n) cin >> ary[i];

    multiset<int> st;
    st.insert(ary[0]);
    REP(i, 1, n) {
        auto iter = st.lower_bound(ary[i]);
        // iter --;
        // int value = *iter;
        if (iter == st.begin() ) {
            st.insert(ary[i]);
        }
        else
        {
            iter --;
            st.erase(iter);
            st.insert(ary[i]);
            /* code */
        }
    }


    cout << st.size() << endl;
}


Measured memory_bytes: 5376
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	
	ll a,b,c;cin >> a >> b >> c;
	
	ll ret;
	if(a%2==0)ret = 0;
	else ret = b*c;
	if(b%2==0)ret = 0;
	else ret = min(ret,a*c);
	if(c%2==0)ret = 0;
	else ret = min(ret,a*b);
	
	cout << ret << endl;
		
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int h,w;
	
	scanf("%d %d",&h,&w);
	
	int a,b;
	
	scanf("%d %d",&a,&b);
	
	int remain;
	
	remain = h*w-(a*w + b*h)+(a*b);
	
	printf("%d\n",remain);
	
	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))
using ll = long long;

int b[200001];

int main() {

    int n;
    cin >> n;
    vector<int> a(n);

    rep(i, n) {
        cin >> a[i];
    }

    int l=0, r=0;
    rep(i, n) {
        if (i%2) {
            b[n-1-r] = a[n-1-i];
            r++;
        }
        else {
            b[l] = a[n-1-i];
            l++;
        }
    }

    rep(i, n) {
        cout << b[i] << ' ';
    }
    cout << endl;



}


Measured memory_bytes: 3712
#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 N; cin >> N;
  vector<int> X(N);
  rep(i,N) cin >> X[i];

  int ans = 10000000;
  sort(X.begin(), X.end());
  for (int i = X[0]; i <= X[N-1]; i++) {
    int s = 0;
    for (int j = 0; j < N; j++) {
      s += abs(pow(i-X[j], 2));
    }
    ans = min(ans, s);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    int anti[n];
    fill(anti,anti+n,n);
    for(int i=0; i<m; i++){
        int a,b;
        cin >> a >> b;
        if(anti[a-1] > b-1){
            anti[a-1] = b-1;
        }
    }
    int st = 0;
    int cnt = 0;
    while(st < n){
        int tmp=anti[st];
        for(int i=st; i<tmp; i++){
            if(anti[i] < tmp){
                tmp = anti[i];
            }
        }
        cnt++;
        st = tmp;
    }
    cout << cnt-1 << endl;
    return 0;
}


Measured memory_bytes: 640
H, W, K = map(int,input().split())
grid = [list(input()) for i in range(H)]
total = 0
for mask1 in range(1<<H):
    for mask2 in range(1<<W):
        ct = 0
        for i in range(H):
            for j in range(W):
                if grid[i][j]=='#' and not (1<<i)&mask1 and not (1<<j)&mask2:
                    ct += 1
        if ct==K:
            total += 1
print(total)

Measured memory_bytes: 74052
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int N,i;
  cin>>N;
  int A[N];
  double ans;
  
  for(i=0;i<N;i++){
  cin>>A[i];
    
  }
  sort(A,A+N);
  ans=(A[0]+A[1])/2.0;
  for(i=2;i<N;i++){
  ans=(A[i]+ans)/2.0;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
//C++14 (GCC 5.4.1)
 
#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007
 
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)
 
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }
 
#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)
#define lower_bound_idx(V,c) distance(V.begin(),lower_bound(V.begin(),V.end(),c))
 
int getqry(){
    string g;
    cin>>g;
    if(g=="Male")return 1;
    else if(g=="Female") return 2;
    return 0;
}
 
int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N;
    cin >>N;
    int a=0,b=N-1,m;
 
    cout<<a<<endl<<flush;
    int gta=getqry();
    if(gta==0)return 0;
    cout <<b<<endl<<flush;
    int gtb=getqry();
    if(gtb==0)return 0;
    int gtm;
 
    while(1){
        m=(a+b)/2;
        cout <<m<<endl<<flush;
        gtm=getqry();
        if(gtm==0)return 0;
        if((m-a)%2==1 && gta!=gtm || (m-a)%2==0 && gta==gtm){
            a=m;gta=gtm;
        }else{
            b=m;gtb=gtm;
        }
    }
 
    return (0);
}

Measured memory_bytes: 852
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int count = 0;
        for(int i = a;i <= b;i++){
            String str = String.valueOf(i);
            StringBuffer sb = new StringBuffer(str);
            String rev = sb.reverse().toString();
            if(str.equals(rev))
                count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 36948
package main

import (
	"fmt"
	"io"
	"os"
)

func proc(r io.Reader, w io.Writer) {
	var a, b int
	fmt.Fscanf(r, "%d %d", &a, &b)

	sum := a + b
	if sum%2 == 0 {
		fmt.Fprintf(w, "%d", sum/2)
		return
	}

	fmt.Fprintf(w, "IMPOSSIBLE")
}

func main() {
	proc(os.Stdin, os.Stdout)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

int main()
{
    int i = 0;
    while (true)
    {
        ++i;
        int x;
        cin >> x;
        if (x)
        {
            cout << "Case " << i << ": " << x << endl;
        }
        else
        {
            break;
        }
    }

    return 0;
}


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


def main():
    n = int(input())
    A = [int(i) for i in input().strip().split()]
    B = [int(i) for i in input().strip().split()]

    _diff_A, _diff_B = 0, 0
    m = sum(B) - sum(A)  # 操作回数の上限
    for i in range(n):
        if A[i] > B[i]:
            _diff_A += A[i] - B[i]
        elif B[i] > A[i]:
            _diff_B += (B[i] - A[i] + 1) // 2

    if _diff_B <= m and _diff_A <= m:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int N, K;
  while(cin>>N>>K){
    vector<int> mbr[50];
    REP(i, K){
      int m; cin>>m;
      while(m--){
        int t; cin>>t;
        mbr[i].push_back(t);
      }
    }
    set<int> wrong[51];
    int R; cin>>R;
    while(R--){
      int u, v; cin>>u>>v;
      wrong[u].insert(v);
      wrong[v].insert(u);
    }
    int ans = 0;
    REP(i, K){
      REP(j, mbr[i].size()){
        bool hate = false;
        REP(k, mbr[i].size()){
          if(wrong[mbr[i][j]].count(mbr[i][k])) hate = true;
        }
        if(hate) ans += 1;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

typedef long long LL;

// 

int main()
{
	LL n;
	cin>>n;
	if(n&1) cout<<0<<endl;
	else
	{
		LL ans=0;
		while(n)
		{
			ans+=n/5/2;
			n/=5;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main(){
      int X;
      cin >>X;
      bool ans[10000];
      ans[1] = true;

      for(int i=2;i<=1000;i++){
              for(int j=2;pow(i,j) <= 1000;j++){
                  ans[(int)pow(i,j)] = true;
              }
      }
      for(int i=X; i >=0; i--){
            if(ans[i] == true){
                  cout << i << endl;
                  break;
            }
      }
} 

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

ans = 0

def odd():
    global ans
    ans += (B - A) // 2

if (B - A) % 2 == 0:
    odd()
else:
    if (N - B) <= (A - 1):
        ans += (N - B) + 1
        A += (N - B) + 1
        B = N
    else:
        ans += (A - 1) + 1
        B -= (A - 1) + 1
        A = 1
    odd()

print(ans)

Measured memory_bytes: 9192
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a<6) b=0;
	if(a>=6&&a<=12) b/=2;
	printf("%d\n",b);
	return 0;
}

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




int main(){
    ll N;cin>>N;
    string s;cin>>s;
    ll cn=0,head=0;
    rep(i,0,N){
        if(s.at(i)==')'){
            cn--;
            if(cn<0){
                head++;
                cn++;
            }
        }
        else{
            cn++;
        }
    }
    rep(i,0,head)cout<<'(';
    cout<<s;
    rep(i,0,cn)cout<<')';
    cout<<endl;
}







Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <utility>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
using ll = long long;
using VI = vector<int>;


int main() {
    string s;
    cin >> s;
    if (s == "ABC") cout << "ARC\n";
    else cout << "ABC\n";
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
using namespace std;

#define MOD 1000000007
#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    string s;
    cin >> s;

    cout << "ABC" + s << endl;
}


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

int N, C;
const int MAX_N = 500 + 10;
const int MAX_C = 30 + 10;
int D[MAX_C][MAX_C];
int c[MAX_N][MAX_N];

int main() {
    cin >> N >> C;
    for (int i = 0; i < C; i++) {
        for (int j = 0; j < C; j++) {
            cin >> D[i][j];
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> c[i][j];
        }
    }
    
    pair<int, int> zero[C], one[C], two[C];
    for (int i = 0; i < C; i++) { 
        zero[i].second = i;
        one[i].second = i;
        two[i].second = i;            
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if ((i+j) % 3 == 0) {
                for (int k = 0; k < C; k++) {
                    zero[k].first += D[c[i][j] - 1][k];
                }
            }
            else if ((i+j) % 3 == 1) {
                for (int k = 0; k < C; k++) {
                    one[k].first += D[c[i][j] - 1][k];
                }
            }
            else {
                for (int k = 0; k < C; k++) {
                    two[k].first += D[c[i][j] - 1][k];
                }
            }
        }
    }

    sort(zero, zero+C);
    sort(one, one+C);
    sort(two, two+C);

    int ans = 1.0e9;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (zero[i].second != one[j].second &&
                    one[j].second != two[k].second &&
                    two[k].second != zero[i].second) {
                    
                    ans = min(ans, zero[i].first + one[j].first + two[k].first);    
                }
            }
        }
    }

    cout << ans << endl;    

    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  int n;cin>>n;
  map<ll,ll> mp;
  vector<ll> A(n);
  rep(i,n){
    ll a;cin>>a;
    A[i] = a;
  }
  ll ans = 0;
  REP(i,n){
    ans += mp[i + A[i]];
    mp[i - A[i]]++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 27488
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
  	ios_base::sync_with_stdio();
  	cin.tie(NULL);
	int n;
	cin>>n;
	vector<int> height(n+1),dp(n+1);
	for(int  i=1;i<=n;i++)
		cin>>height[i];
	dp[1]=0;dp[2]=abs(height[2]-height[1]);
	for(int i=3;i<=n;i++)
	{
		int a=dp[i-1]+abs(height[i]-height[i-1]);
		int b=dp[i-2]+abs(height[i]-height[i-2]);
		dp[i]=min(a,b);
	}
	cout<<dp[n];
}


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

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind<int> uf(N);
    for (int i = 0; i < M; ++i) {
        int l, r, d;
        cin >> l >> r >> d;
        --l, --r;
        if (uf.issame(l, r)) {
            int diff = uf.diff(l, r);
            if (diff != d) {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            uf.merge(l, r, d);
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 1536
#include <cmath>
#include <iostream>
using ll = long long int;
int main(void) {
  int n;
  int ans = 0;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    ll x;
    std::cin >> x;
    int c = 0;
    while (x % 2 == 0) {
      x /= 2;
      c++;
    }
    ans += c;
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,y,count=0,check=0;
  string ans;
  cin >> x >> y;
  int cr,tu;
  for(int i=0; i<=x; i++){
    cr = i; //i = cr
    tu = x-i; 
    if(2 * cr + 4 * tu == y) check = 1;
  }
  if(check !=0){
    ans = "Yes";
  }else{
    ans = "No";
  }
  cout << ans << endl;
}

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

using namespace std;


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000007
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

vector<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	vi primes;
	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.pb(i);
	}
	return primes;
}



set<int> primeFactors(int  n)
{
	set<int> factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors.insert(2);

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		while (n % i == 0)
		{
			factors.insert(i);
			n /= i;
		}
	}
	if (n > 2)
		factors.insert(n);
	return factors;
}


// int power(int x, unsigned int y, int p)
// {
// 	int res = 1;     // Initialize result

// 	x = x % p; // Update x if it is more than or
// 	// equal to p

// 	if (x == 0) return 0; // In case x is divisible by p;

// 	while (y > 0)
// 	{
// 		// If y is odd, multiply x with result
// 		if (y & 1)
// 			res = (res * x) % p;

// 		// y must be even now
// 		y = y >> 1; // y = y/2
// 		x = (x * x) % p;
// 	}
// 	return res;
// }
// Graph------------------------------------------------------------------------


int32_t main()
{
	FIO;
	//c_p_c();
// --------------------------------------------------

	string s, t;
	cin >> s;
	cin >> t;
	int n = s.length();
	int m = t.length();
	if (n + 1 != m )
	{
		cout << "No" << endl;
	}
	else
	{
		for (int i = 0; i < n; i++)
		{
			if (s[i] != t[i])
			{
				cout << "No" << endl;
				return 0;
			}
		}

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

}





Measured memory_bytes: 3672
#include<cstdio>
#include <iostream>

int main(){
    char cc[9] = {0};
    int i=0;
    while (i<9){
        char c;
        std::cin >> c;
        if('a' <= c && c <= 'z'){
            cc[i++] = c;
        }
    }
    std::cout << cc[0] << cc[4] << cc[8];
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math

def floor_div(x,d):
    if x%d != 0:
        return int(x/d)+1
    else:
        return int(x/d)

N = int(input())

A = list(map(int, input().split()))

n_not_leaf = 0
sum_node = 0

num_node = [0 for d in range(N+1)]
max_node = [0 for d in range(N+1)]

# 各層のnodeのmax個を計算
for d in range(N+1):
    if d == 0:
        max_node[0] = 1
    else:
        max_node[d] = (max_node[d-1]-A[d-1])*2
    
    if d != N and max_node[d]-A[d] < 1:
        print(-1)
        exit()
if max_node[N]-A[N] < 0:
    print(-1)
    exit()


for d in reversed(range(N+1)):
    if d == N:
        num_node[N] = min(A[N], max_node[N])
    else:        
        if floor_div(num_node[d+1],2)+A[d] > max_node[d]:
            print(-1)
            exit()
        else:
            num_node[d] = min(num_node[d+1]+A[d], max_node[d])

print(sum(num_node))

Measured memory_bytes: 680064
#include<bits/stdc++.h>
#define mod 1000000007

using namespace std;

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

int main(){
    int n, m;
    cin >> n >> m;
    int s[10005];
    int t[10005];
    for(int i = 0; i < n; i++)cin >> s[i];
    for(int i = 0; i < m; i++)cin >> t[i];
    ll dp[2005][2005] = {0};
    for(int i = 0; i <= n; i++)dp[i][0]=1;
    for(int i = 0; i <= m; i++)dp[0][i]=1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(s[i-1] == t[j-1])dp[i][j]=(dp[i][j-1]+dp[i-1][j])%mod;
            else dp[i][j] = (dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]+mod)%mod;
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}

Measured memory_bytes: 31744
import java.util.*;
import java.io.*;

public class Main {
	
	static int M[][];
	
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt(); M=new int[n][n];
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++)M[i][j]=Integer.parseInt(in.next());
		}
		prim(n);
	}
	
	static void prim(int n) {
		int INF=2000000000, d[]=new int[n], p[]=new int[n];
		char color[]=new char [n]; 
		for(int i=0;i<n;i++) {
			d[i]=INF;
			color[i]='W';
		}
		
		d[0]=0; p[0]=-1; //set [0] as start node
		
		while(true) {
			int mincost=INF,u=-1;
			for(int i=0;i<n;i++) {
				if(color[i] !='B' && d[i]<mincost) {
					mincost=d[i];
					u=i;
				}
			}
			
			if(mincost==INF)break;
			
			color[u]='B';
			
			for(int v=0;v<n;v++) {
				if(color[v]!='B' && M[u][v]!=-1) {
					if(M[u][v]<d[v]) {
						d[v]=M[u][v];
						p[v]=u;
						color[v]='G';
					}
				}
			}
		}
		
		int dsum=0;
		for(int i=1;i<n;i++) {
			dsum+=M[i][p[i]];
		}
		System.out.println(dsum);
	}

}




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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string t;
    cin >> t;
    int n = t.size();
    for (int i = 0; i < n; i++) {
        if (t[i] == '?') {
            t[i] = 'D';
        }
    }
    cout << t << '\n';
    return 0;
}


Measured memory_bytes: 3772
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

typedef long long ll;

int A,B,C;

int main()
{
	cin >> A >> B >> C;
	for (int i = 1;i <= 10000000;i++)
	{
		if (A & 1 || B & 1 || C & 1)
		{
			cout << i - 1 << endl;
			return 0;
		}
		int da = A >> 1,db = B >> 1,dc = C >> 1;
		A = db + dc;
		B = da + dc;
		C = da + db;
	}
	cout << -1 << endl;
	return 0;
}

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;




void one_case() {
   int a, b;
   cin >> a >> b;
   cout << (a * b % 2 ? "Odd\n" : "Even\n");
}


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


    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int a[10000];
int main()
{
    ll n;cin>>n;
	int i=0;
	while(n)
	{
	
		a[i]=n%26;
		n/=26;
		i++;
	}
	for (int j =0; j <i; j++)
	{
		//cout<<a[j]<<endl;
		if(a[j]<=0&&j!=i-1)
		{
			a[j]+=26;
			a[j+1]--;
		}
	}
	int t=1;
	for (int j= i-1; j>=0; j--)
	{
		if(j==i-1&&a[j]==0) continue;
		cout<<char(a[j]+'a'-1);
	}
	return 0;
}



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

using namespace std;

bool Compare(int a, int b)
{
    return a<b;
}

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

    vector<int> v;
    int n,k,x;
    cin>>n>>k;

    for(int i=1; i<=n; i++)
    {
        cin>>x;
        v.push_back(x);
    }
    sort(v.begin(), v.end(), Compare);
    x=0;
    for(int i=0; i<k; i++)
    {
        x += v[i];
    }

    cout<<x;


    return 0;
}


Measured memory_bytes: 3664
l = raw_input().split()
N = int(l[0])
K = int(l[1])

l = raw_input().split()
V = [int(x) for x in l]
# print(N, K, V)

def take_left(v, n):
    if n == 0:
        return []
    return v[:n]

def take_right(v, n):
    if n == 0:
        return []
    return v[-n:]

max_v = 0

for num_ret in range(K):
    for num_take_left in range(K - num_ret + 1):
        V_tmp = [x for x in V]
        # print('V_tmp first', V_tmp)
        num_take_right = K - num_ret - num_take_left
        # print(num_ret, num_take_left, num_take_right)
        l = take_left(V_tmp, num_take_left)
        del V_tmp[:num_take_left]
        r = take_right(V_tmp, num_take_right)
        del V_tmp[num_take_right:]
        taken = l + r
        taken.sort()
        # print('l,r,taken,tmp', l, r, taken, V_tmp)
        for i in range(num_ret):
            if len(taken) == 0:
                break
            if taken[0] < 0:
                del taken[0]
            else:
                break
        v = sum(taken)
        # print('v={}'.format(v))
        if max_v < v:
            max_v = v

print(max_v)


Measured memory_bytes: 2696
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<ll> enum_div(ll n) {
    std::vector<ll> ret;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    string S;
    cin >> S;

    int a = 0;
    ll ans = 0;
    REP(i, S.length()) {
        if (S[i] == 'A') {
            a++;
        } else if (S.substr(i, 2) == "BC") {
            ans += a;
            i++;
        } else {
            a = 0;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 720
S = input()

count = 0
mod_check = [0] * 2019
mod_check[0] = 1
check_S = 0
d = 1
for i in reversed(S):
    check_S += int(i) * d
    check_S %= 2019
    mod_check[check_S] += 1
    d *= 10
    d %= 2019
    count += 1
mod_match = 0
for x in mod_check:
    mod_match += x * (x - 1) // 2
print(mod_match)


Measured memory_bytes: 68192
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007


int main() {

  int N;
  cin >> N;

  int c = 0;
  for(int i = 0;i < N;i++) {
    int a;
    cin >> a;
    c = c^a;
  }

  if(c == 0) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 384
url = "https://atcoder.jp//contests/abc057/tasks/abc057_c"
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def main():
    n = int(input())
    ans = 10000000000000000
    ns = make_divisors(n)
    for i in range(0, (len(ns)//2) + 1):
        tmp = max(len(str(ns[i])), len(str(ns[len(ns)-i-1])))
        ans = tmp if tmp < ans else ans
    if len(ns) % 2 != 0:
            tmp = len(str(ns[len(ns) // 2]))
            ans = tmp if tmp < ans else ans
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9228
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 701;

int n;

int used[N];
int g[N][N];
int cl[N];

int fl = 0;

void dfs(int cur, int c, int &c1, int &c2) {
	cl[cur] = c;
	used[cur] = 1;
	if (c) c1++;
	else c2++;
	for (int i = 0; i < N; i++) {
		if (!used[i] && g[cur][i]) {
			dfs(i, c ^ 1, c1, c2);
		}
		if (used[i] && cl[cur] == cl[i] && g[cur][i]) {
			fl = 1;
		}
	}
}

void init() {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			g[i][j] = (i != j);
		}
	}
}

vector<pair<int, int>> solve() {
	vector<pair<int, int>> v;
	for (int i = 0; i < n; i++) {
		if (!used[i]) {
			int c1 = 0;
			int c2 = 0;
			dfs(i, 0, c1, c2);
			v.push_back({c1, c2});
		}
	}
	if (fl) {
		cout << -1 << endl;
		exit(0);
	}
	return v;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);


	int m;
	cin >> n >> m;
	init();
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u][v] ^= 1;
		g[v][u] ^= 1;
	}
	vector<pair<int, int>> v = solve();
	bitset<N> cn;
	cn[0] = 1;
	for (auto t : v) {
		cn = (cn << t.first) | (cn << t.second);
	}
	int ans = m;
	for (int lp = 0; lp <= n; lp++) {
		if (!cn[lp]) continue;
		int rp = n - lp;
		ans = min(ans, lp * (lp - 1) / 2 + rp * (rp - 1) / 2);
	}
	cout << ans << endl;
}


Measured memory_bytes: 2176
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(vec, s) vec.find(s) != vec.end()
#define Set_union(A, B, res) set_union(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_intersection(A, B, res) set_intersection(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_difference(A, B, res) set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_symmetric_difference(A, B, res) set_symmetric_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));

int main() {
	int N;
	string c;
	cin >> N >> c;
	int left = 0, right = N - 1;
	int ans = 0;
	while (true) {
		// cout << c << " " << ans << endl;
		while (left < N && c[left] == 'R') left++;
		while (right >= 0 && c[right] == 'W') right--;
		if (left > right) break;
		swap(c[left], c[right]);
		ans++, left++, right--;
	}
	while (left < N) {
		if (c[left] == 'R') ans++;
		left++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3744
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

struct Number {
	ll num;
	int State;
	bool operator <(const Number& b) {
		return num < b.num;
	}
};

Number A[100010];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i].num;
		A[i].State = (i + 1) % 2;
	}
	sort(A, A + N);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (A[i].State != (i + 1) % 2)  ans++;
	}
	cout << ans / 2 << endl;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<deque>
#define INF int(1e9)
using namespace std;
int read()
{
    int f=1,x=0;
    char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
    return f*x;
}
bool flag;
int ball[11];
void DFS(int left,int right,int now)
{
	if(now>10)
	{
		flag=1;	
		return ;
	}
	if(ball[now]>left&&ball[now]>right) 
		return ;	
	if(ball[now]<left)
		DFS(ball[now],right,now+1);
	else
		DFS(left,ball[now],now+1);
	return ;
}
int main()
{
	int t=read();
	while(t!=0)
	{
		t--;
		flag=0;
		for(int i=10;i>=1;i--)
			ball[i]=read();
		DFS(INF,INF,1);
		if(flag==1)
			printf("YES\n");
		else
			printf("NO\n");
	}
    return 0;
}

Measured memory_bytes: 2504