akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n,k; cin >> n >> k;
    vi a(n);
    rep(i,n) {
        cin >> a[i];
        --a[i];
    }

    /**
     * どう回るかを調べる。
     * 1->~->1の間で、
     */


    // 始点を探す
    i32 start = -1;
    vi seen(n);
    seen[0] = 1;
    i32 tmp = a[0];
    rep(_, n+3) {
        seen[tmp] += 1;
        if(seen[tmp] >= 2) {
            start = tmp;
            break;
        }
        tmp = a[tmp];
    }
    tmp = a[start];
    i32 lenOfloop = 1;
    while(tmp != start) {
//        debug(tmp);
        ++lenOfloop;
        tmp = a[tmp];
    }
//    debug(lenOfloop);
//    debug(start);

    tmp = 0;
    while(tmp != start) {
        --k;
        tmp = a[tmp];
        if(k==0) {
            cout << tmp+1 << '\n';
            return 0;
        }
    }

    i32 len = k%lenOfloop;
    i32 ans = start;
    rep(i, len) {
        ans = a[ans];
    }

    cout << ans+1 << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


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

int main(){
 int a, i=0, f5=0, f7=0;
 for(i=0; i<3;i++){
  cin>>a;
  if(a==5)f5++;
  else if(a==7)f7++;
 }
 if(f5==2&&f7==1)cout<<"YES\n";
 else cout<<"NO\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define swap(a,b) ((a != b) && (a += b,b = a - b,a -= b))
using namespace std;

int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}

int main()
{
    int sum=0;
    int max=0;

    long n;
    cin >> n;


    int min=9999999;

    while(n>99){
        int a=n%1000;

        if(min>abs(753-a))min=abs(753-a);
        n/=10;
    }
    cout << min << endl;
    return 0;
}






Measured memory_bytes: 256
import math
a, b, x = map(float, input().split())
vol = a * a * b
if x <= vol/2:
    height = (x * 2.0) / (b * a)
    ans = math.atan(b / height) * 180 / math.pi
else:
    height = ((vol - x) * 2.0) / (a * a)
    ans = math.atan(height / a) * 180 / math.pi
print(ans)

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

int main (){
    vector<int> v;
    int a,b;
    cin >> a >> b;

    v.push_back(a+b);
    v.push_back(a-b);
    v.push_back(a*b);
    sort(v.begin(),v.end());

    cout << v[2] << endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n, i, hour, minute;
	double sub;
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%d %*c %d",&hour,&minute);
		sub = (hour + minute / 60.0) * 30.0 - minute * 6.0;
		if(sub < 0)
			sub *= -1;
		if(360 - sub < sub)
			sub = 360 - sub;
		if(0 <= sub && sub < 30)
			printf("alert\n");
		else if(90 <= sub && sub <= 180)
			printf("safe\n");
		else
			printf("warning\n");
	}
	return 0;
}

Measured memory_bytes: 584
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
Scanner s = new Scanner(System.in);
		int N = Integer.valueOf(s.next());
		char[] c = s.next().toCharArray();
		int[] C = new int[N];
		int left_one = N + 1;
		int right_zero = -1;
		for(int i = 0; i < N; i++) {
			if(c[i] == 'W') {
				C[i] = 1;
				left_one = Integer.min(left_one, i);
			}else {
				C[i] = 0;
				right_zero = Integer.max(right_zero, i);
			}
		}
		
		int cnt = 0;
		while(left_one < right_zero) {
			C[left_one] = 0;
			C[right_zero] = 1;
			left_one = nextOne(C, left_one);
			right_zero = nextZero(C, right_zero);
			cnt++;
		}
		System.out.println(cnt);
	}
	
	private static int nextOne(int[] C, int left_one) {
		for(int i = left_one + 1; i < C.length; i++) {
			if(C[i] == 1) {
				return i;
			}
		}
		return -1;
	}
	private static int nextZero(int[] C, int right_zero) {
		for(int i = right_zero - 1; i > 0; i--) {
			if(C[i] == 0) {
				return i;
			}
		}
		return -1;
	}
}

Measured memory_bytes: 41328
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int d;
  ll g;
  cin >> d >> g;
  vector<ll> p(d);
  vector<ll> c(d);
  rep(i, d) cin >> p[i] >> c[i];
  ll ans = 1000;
  for (int bit = 0; bit < (1 << d); bit++){
    vector<bool> bonus_valid(d,false);
    ll sum_score = 0;
    ll problems = 0;
    rep(i, d){
      if(bit & (1 << i)){
        problems += p[i];
        bonus_valid[i] = true;
        sum_score += 100 * (i + 1) *  p[i] + c[i];
      }
    }
    if(sum_score >= g){
      ans = min(ans, problems);
      continue;
    }else{
      ll rest = g - sum_score;
      bool out = false;
      rrep(i, d){
        if(!bonus_valid[i]){
          ll plus = rest / (100 * (i + 1));
          if(rest % (100 * (i + 1)) != 0)plus++;
          if(plus >= p[i]) out = true;
          else{
            problems += plus;
            break;
          }
        }
      }
      if(out)continue;
      ans = min(ans, problems);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3576
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
using lint=int64_t;
using namespace std;

int main()
{
	lint N;
	cin >> N;

	lint indexof[100010];
	for(lint i=1;i<=N;i++)
	{
		lint p;
		cin >> p;
		indexof[p]=i;
	}

	multiset<lint> ipool;
	ipool.insert(0);
	ipool.insert(0);
	ipool.insert(N+1);
	ipool.insert(N+1);
	
	lint ans=0;
	for(lint i=N;i>=1;i--)
	{
		lint l2,l1,r1,r2;
		auto itr=ipool.lower_bound(indexof[i]);
		r1=*itr;
		++itr;
		r2=*itr;
		--itr;--itr;
		l1=*itr;
		--itr;
		l2=*itr;

		ans+=((indexof[i]-l1)*(r2-r1)+(l1-l2)*(r1-indexof[i]))*i;
		//ans+=(indexof[i]-l1)*(r2-r1)*i;
		//ans+=(l1-l2)*(r1-indexof[i])*i;

		ipool.insert(indexof[i]);
	}

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



Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    if (a == 0 && b == 0) cout << 0 << endl;
    else{
        ll blue_red = n / (a + b);
        ll amari = n % (a + b);
        ll blue = min(amari, a);
        cout << (blue_red * a) + blue << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) (vec).begin(),(vec).end()
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n;
long long res,tmp,MOD=1000000007;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	res=1;
	for(int i=1;i<=n;i++)
		res=(res*10LL)%MOD;
	tmp=1;
	for(int i=1;i<=n;i++)
		tmp=(tmp*9LL)%MOD;
	res=(res-tmp+MOD)%MOD;
	tmp=1;
	for(int i=1;i<=n;i++)
		tmp=(tmp*9LL)%MOD;
	res=(res-tmp+MOD)%MOD;
	tmp=1;
	for(int i=1;i<=n;i++)
		tmp=(tmp*8LL)%MOD;
	res=(res+tmp)%MOD;
	cout<<res<<endl;
	return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int c = 0;
    for(int i=0; i<3; i++)
    {
        if(s[i] == '1') c++;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Network{
	private:
	int V;
	struct edge{
		ll to,cap,rev;
	};
	vector<vector<edge> > g;
	ll DFS(int v,int t,ll f,vi& iter,vi level){
		if(v==t) return f;
		for(int &i=iter[v];i<g[v].size();i++){
			edge &e=g[v][i];
			if(e.cap>0&&level[v]<level[e.to]){
				ll d=DFS(e.to,t,min(f,e.cap),iter,level);
				if(d>0){
					e.cap-=d;
					g[e.to][e.rev].cap+=d;
					return d;
				}
			}
		}
		return 0;
	}
	void BFS(int s,vi& level){
		level=vi(V,-1);
		queue<int> que;
		level[s]=0;
		que.push(s);
		while(!que.empty()){
			int v=que.front();
			que.pop();
			for(int i=0;i<g[v].size();i++){
				edge &e=g[v][i];
				if(e.cap>0&&level[e.to]<0){
					level[e.to]=level[v]+1;
					que.push(e.to);
				}
			}
		}
	}
	public:
	Network(int v){
		V=v;
		g=vector<vector<edge> >(v);
	}
	void add_edge(int s,int t,ll c){
		g[s].push_back(edge{t,c,(int)g[t].size()});
		g[t].push_back(edge{s,0,(int)g[s].size()-1});
	}
	ll Dinic(int s,int t){
		ll res=0;
		while(1){
			vi iter(V),level;
			BFS(s,level);
			if(level[t]<0) return res;
			ll f;
			while((f=DFS(s,t,inf,iter,level))>0) res+=f;
		}
	}
};

int n;

int main(){
	cin>>n;
	Network g(n+2);
	ll res=0;
	for(int i=1;i<=n;i++){
		int a;
		cin>>a;
		if(a>=0){
			g.add_edge(i,n+1,a);
			res+=a;
		}
		else g.add_edge(0,i,-a);
		for(int j=2*i;j<=n;j+=i) g.add_edge(i,j,INF);
	}
	cout<<res-g.Dinic(0,n+1)<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        int sum = 0;

        for(int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
            sum += a[i];
        }
        Arrays.sort(a);
        boolean ok = true;
        for(int i = 1 ; i <= m ; i++){
            if(a[n-i]*(4*m) < sum){
                ok = false;
            }
        }

        System.out.println(ok?"Yes":"No");
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
#define spn setprecision
#define fr(x,a,b,c) for(int x = a; x <= b; x+=c)
using namespace std;
ll multiply(ll num1, ll num2, ll mod) { // with mod > 1e9
	ll ans = 0;
	num1 %= mod;
	num2 %= mod;
	while (num2) {
		if (num2&1) {
			ans += num1;
			ans %= mod;
		}
		num1 *= 2;
		num1 %= mod;
		num2 /= 2;
	}
	return ans;
}
ll powmod2(ll base,ll exponent,ll mod){ // with mod > 1e9
	ll ans = 1;
	while (exponent) {
		if (exponent&1) {
			ans = multiply(ans, base, mod);
		}
		base = multiply(base, base, mod);
		exponent /= 2;
	}
	return ans;
}
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
int main() {
	int n,inp,ans=0;
	sd(n);
	while(n--){
		sd(inp);
		while(inp%2==0){
			inp/=2;
			ans++;
		}
	}
	pd(ans);
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
string st;
int main(){
	ios::sync_with_stdio(0);
	cin>>st;
	for(int i=0;i<st.size();i++){
		if(st[i]=='C'){
			for(int j=i+1;j<st.size();j++){
				if(st[j]=='F'){
					cout<<"Yes";
					return 0;
				}
			}
		}
	}
	cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
struct edge {int to,w,p;};
int n,m,k,used[202],a,b,c,cnt,A,B;
vector<edge> v[202];
int dfs(int s,int t,int r){
    if(s==t)return r;
    used[s]=1;
    for(int i=0;i<v[s].size();i++){
        edge &u=v[s][i];
        if(used[u.to]==0&&u.w>0){
            int F=dfs(u.to,t,min(r,u.w));
            if(F>0){
                u.w-=F;v[u.to][u.p].w+=F;return F;
            }
        }
    }
    return 0;
}
int main(void){
    cin>>n>>m>>k;
    for(int i=0;i<k;i++){
        cin>>A>>B;
        a=A,b=B+100;
        edge p={b,1,(int)v[b].size()};v[a].push_back(p);
        edge q={a,0,(int)v[a].size()-1};v[b].push_back(q);
    }
    for(int i=0;i<n;i++){
        a=200,b=i;
        edge p={b,1,(int)v[b].size()};v[a].push_back(p);
        edge q={a,0,(int)v[a].size()-1};v[b].push_back(q);
    }
    for(int i=0;i<m;i++){
        a=i+100,b=201;
        edge p={b,1,(int)v[b].size()};v[a].push_back(p);
        edge q={a,0,(int)v[a].size()-1};v[b].push_back(q);
    }
    int res=0;
    while(1){
        for(int i=0;i<202;i++)used[i]=0;
        int P=dfs(200,201,1e9);
        if(P==0)break;
        res++;
    }
    cout<<res<<endl;
}



Measured memory_bytes: 3336
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

using Graph = vector<vector<int>>;
vector<bool> seen;
int n, m;
int ans = 0;

void dfs(const Graph &g, int v, int num) {
  seen[v] = true;
  if (num == n) {
    ans++;
  }

  for (auto next_v: g[v]) {
    if (seen[next_v]) continue;
    dfs(g, next_v, num + 1);
  }

  seen[v] = false;
}

int main(void) {
  cin >> n >> m;
  Graph g(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  seen.assign(n, false);
  dfs(g, 0, 1);

  cout << ans << endl;

  return 0;
}

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

char ch[100];

bool check(int t)
{
	if(ch[0]!='A')return 0;
	ch[0]='a';
	int k=0;
	for(int i=2;i<t-1;i++)
		if(ch[i]=='C')k++,ch[i]='c';
	if(k!=1)return 0;
	for(int i=0;i<t;i++)
		if(ch[i]<'a'||ch[i]>'z')return 0;
	return 1;
}

int main()
{
	scanf("%s",ch);
	
	if(!check(strlen(ch)))printf("WA");
	else printf("AC");
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    long long int x=1,i,n,a[100009],flag[100009]= {0};
    scanf("%lld",&n);
    for(i=0; i<n; i++)
    {
        scanf("%lld",&a[i]);
        flag[a[i]]++;
    }
    if(n%2==1)
    {
        if(flag[0]!=1)
        {
            x=0;
        }
        else
        {
            for(i=0; i<n; i++)
            {
                if(a[i]!=0&&flag[a[i]]!=2)
                {
                    x=0;
                }
            }
        }
    }
    else if(n%2==0)
    {
        if(flag[0]!=0)
        {
            x=0;
        }
        else
        {
            for(i=0; i<n; i++)
            {
                if(a[i]!=0&&flag[a[i]]!=2)
                {
                    x=0;
                }
            }
        }
    }
    for(i=1; i<=n/2; i++)
    {
        x=x*2;
        x=x%1000000007;
    }
    printf("%lld\n",x);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int a=0, M=N, sum=0;
  
  for(int i=8;i>=0;i--) {
    a=M/pow(10, i);
    M-=a*pow(10, i);
    sum+=a;
  }
  
  if(N%sum==0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define N 100005
using namespace std;
ll a[N+3],seg[4*N+3];
int main(){
    int n,m;
    cin>>n>>m;
    cout<<(n-1)*(m-1)<<endl;
}


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

#define MAXINF 1000000005
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define repc(it, x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rrepc(it, x) for(auto it = (x).rbegin(); it != (x).rend(); ++it)
#define all(x) (x).begin(), (x).end()

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n, 0);
    ll total = 0;
    rep(i, n) {
        cin >> h[i];
        total += h[i];
    }
    if(n <= k) {
        cout << 0 << endl;
        return 0;
    } else if (k == 0) {
        cout << total << endl;
        return 0;
    }
    sort(all(h));
    rep(i, k) {
        total -= h[n-i-1];
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int w,h,n;
  cin >> w >> h >> n;
  vector<vector<char>> maze(h+1,vector<char>(w+1,'W'));
  rep(i,n){
    int x,y,a;
    cin >> x >> y >> a;
    if(a == 1){
      rep1(i,h) rep1(j,w) if(j<=x) maze[i][j] = 'B';
    }
    if(a == 2){
      rep1(i,h) rep1(j,w) if(j>x) maze[i][j] = 'B';
    }
    if(a == 3){
      rep1(i,h) rep1(j,w) if(i<=y) maze[i][j] = 'B';
    }
    if(a == 4){
      rep1(i,h) rep1(j,w) if(i>y) maze[i][j] = 'B';
    }
  }//i
  int ans = 0;
  rep1(i,h) rep1(j,w) ans += maze[i][j] == 'W';
  cout << ans << endl;
}

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

int main() {
  string s;
  cin >> s;
  cout << (s[s.size()-1] == 's' ? s.append("es") : s.append("s")) << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector

int main(){
    int n;
    cin >> n;
    ve<ll> a(n);
    ll b=0;
    rep(i,n){
        cin >> a[i];
        b ^= a[i];
    }
    rep(i,n-1) cout << (b^a[i]) << " ";
    cout << (b^a[n-1]) << endl;
    return 0;
}

Measured memory_bytes: 4732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N;
vector<int> s;
int main() {
  cin >> N;
  s.resize(N);
  rep(i, N) cin >> s[i];

  ll ans = 0;
  for (int c = 1; c <= N - 1; ++c) {
    ll score = 0;
    vector<bool> used(N, false);
    for (int i = 0; i < N - 1; i += c) {
      if (N - 1 - i - c <= 0) break;
      if (used[i] || used[N - 1 - i] || i == N - 1 - i) break;
      score += ll(s[i]) + s[N - 1 - i];
      used[i] = used[N - 1 - i] = true;
      ans = max(ans, score);
    }
  }

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


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>

int main(){
    long N,M,K;
    std::cin >> N >> M >> K;
    long A[200000]={};
    long B[200000]={};
    for(long i=0; i<N; i++){
        std::cin >> A[i];
    }
    for(long i=0; i<M; i++){
        std::cin >> B[i];
    }
    long A_sum[200000+1]={};
    long B_sum[200000+1]={};
    A_sum[0]=0;
    B_sum[0]=0;
    for(long i=1;i<=N; i++){
        A_sum[i]=A_sum[i-1]+A[i-1];
    }
    for(long i=1;i<=M; i++){
        B_sum[i]=B_sum[i-1]+B[i-1];
    }

    long max=0;
    long B_index=M;
    bool bflag=0;
    for(long i=0; i<=N; i++){
        if(A_sum[i]>K){
            break;
        }
        for(long j=B_index; j>=0; j--){
            if(A_sum[i]+B_sum[j]<=K){
                B_index=j;
                if((i)+(j)>max){
                    max = i+j;
                }
                break;
            }else if(j==0){
                if((i)>max){
                    max = i;
                }
            }
        }
    }

    std::cout << max << std::endl;
    return 0;
}

Measured memory_bytes: 9868
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;

  int C[VMAX+ 1];
  int n,i,j;
  scanf("%d",&n);

  A = malloc(sizeof(short)*n + 1);
  B = malloc(sizeof(short)*n + 1);

  for(i = 0; i <= VMAX; i++) C[i] = 0;

  for(i = 0; i < n; i++){
    scanf("%hu",&A[i + 1]);
    C[A[i + 1]]++;
  }
  for(i = 1; i <= VMAX; i++) C[i] = C[i] + C[i - 1];

  for(j = 1; j <= n; j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i = 1; i <= n; i++){
    if(i > 1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 9584
/*input

*/


// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}

int solve()
{
	string s;cin>>s;
	string r;cin>>r;
	ll ans=0;
	rep(i,0,sz(s)) ans+=(s[i]!=r[i]);
	cout<<ans<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 3888
import sys
sys.setrecursionlimit(10**6)

MAX = 10 ** 4 + 5


def main(input, print):
    N = int(input())
    ans = [0] * MAX
    for x in range(1, 99):
        for y in range(1, 99):
            for z in range(1, 99):
                a = x**2+y**2+z**2+x*y+y*z+z*x
                if a < MAX:
                    ans[a] += 1
    for i in range(1, N+1):
        print(ans[i])


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 74452
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
int main(){
	ll k,a[100000],flag,max,min;
	flag=0;
	scanf("%lld",&k);
	for(int i=0;i<k;i++){
		scanf("%lld",a+i);
	}
	reverse(a,a+k);
	max=2;
	min=2;
	for(int j=0;j<k;j++){
		if(max/a[j]==min/a[j] && max%a[j]!=0 && min%a[j]!=0){
			flag=1;
		}
		if(flag==1){
			break;
		}
		else{
			if(min%a[j]!=0){
				min=min-min%a[j]+a[j];
			}
			max=max-max%a[j]+a[j]-1;
		}
	}
	if(flag==0){
		printf("%lld %lld",min,max);
	}
	else{
		printf("-1");
	}
}


Measured memory_bytes: 896
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout << fixed << setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll a = in(), b = in(), k = in();
	REP(i, k) {
		if (i % 2 == 0) {
			if (a % 2 == 1)--a;
			b += a / 2;
			a /= 2;
		} else {
			if (b % 2 == 1)--b;
			a += b / 2;
			b /= 2;
		}
	}
	cout << a << ' ' << b << endl;
}

Measured memory_bytes: 256
import itertools

n=int(input())
lis=[list(map(int,input().split())) for _ in range(2)]
ans=0

for li in itertools.product([0,1], repeat=n):
  v=0
  for id,l in enumerate(li):
    if l:
      v += lis[0][id] - lis[1][id]
      
  if v > ans:
    ans=v
    
print(ans)

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

int main(void){
    int a,b;
    cin >> a;
    cin >> b;
    int d=a/b;
    int r=a%b;
    double f=double(a)/double(b);
    cout << d;
    cout << " ";
    cout << r;
    cout << " ";
    cout << fixed << std::setprecision(5) << f;
    cout << endl;
   
}


Measured memory_bytes: 3268
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;



int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> G(n);
    for (int i = 0; i < n-1; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        G[a].emplace_back(b, i);
        G[b].emplace_back(a, i);
    }
    int m;
    cin >> m;
    vector<int> us(m), vs(m);
    vector<ll> inds(m);
    for (int i = 0; i < m; ++i) {
        cin >> us[i] >> vs[i];
        us[i]--; vs[i]--;
        ll v = 0;
        auto rec = [&](int x, int par, int dest, auto &&f) -> int {
            if(x == dest) return 1;
            for (auto &&j : G[x]) {
                if(j.first != par){
                    v += 1LL << j.second;
                    int ret = f(j.first, x, dest, f);
                    if(ret) return 1;
                    v -= 1LL << j.second;
                }
            }
            return 0;
        };
        rec(us[i], -1, vs[i], rec);
        inds[i] = v;
    }
    ll ans = 1LL << (n-1);
    for (int i = 1; i < (1 << m); ++i) {
        ll sign = (__builtin_popcount(i)&1 ? -1 : 1), val = 0;
        for (int j = 0; j < m; ++j) {
            if(i & (1 << j))val |= inds[j];
        }
        ll x = 1LL << (n-1 - __builtin_popcountll(val));
        ans += x*sign;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = [0] + list(map(int, input().split()))
ok = [0] + [1 for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    if h[a] <= h[b]:
        ok[a] = 0
    if h[b] <= h[a]:
        ok[b] = 0

print(sum(ok))

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

#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
namespace adaptor = boost::adaptors;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

void Main()
{
	int A, B;
	cin >> A >> B;

	cout << A * B;
	return;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int f(int x) { return x <= 9 ? x : f(x / 10) + x % 10;}
int main()
{
	int n;
	int ans = -1;
	scanf("%d", &n);
	for(int i = 1; i <= n - i; ++i)
	{
		int ret = f(i) + f(n - i);
		ans = i == 1 ? ret : min(ans, ret);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int main(void) {
    string S;
    cin >> S;
    map<int,int> mp;
    for(int i=0; i<26; i++) {
        char c = 'A' + i;
        mp[count(S.begin(), S.end(), c)]++;
    }
    if(mp[2] == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set


int main() 
{
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll arr[3][n+1];
	REP(i,0,n+1){
		arr[0][i] = 0; arr[1][i] = 0; arr[2][i] = 0;
	}
	REP(i,0,n){
		if(s[i] == 'R') arr[0][i]++;
		else if(s[i] == 'G') arr[1][i]++;
		else arr[2][i]++;
	}
	REPI(i,0,n){
		arr[0][i] += arr[0][i+1];
		arr[1][i] += arr[1][i+1];
		arr[2][i] += arr[2][i+1];
	}
	ll sum = 0;
	REP(i,0,n-2){
		REP(j,i+1,n-1){
			if(s[i] != s[j]){
				if((s[i] == 'R' && s[j] == 'G') || (s[j] == 'R' && s[i] == 'G')){
					sum += arr[2][j + 1];
					if(j + j - i <= n)
						sum -= arr[2][j + j - i];
					if(j + j - i + 1 <= n)
						sum += arr[2][j + j - i + 1];
				}
				else if((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')){
					sum += arr[1][j + 1];
					if(j + j - i <= n)
						sum -= arr[1][j + j - i];
					if(j + j - i + 1 <= n)
						sum += arr[1][j + j - i + 1];	
				}
				else if((s[i] == 'B' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'B')){
					sum += arr[0][j + 1];
					if(j + j - i <= n)
						sum -= arr[0][j + j - i];
					if(j + j - i + 1 <= n)
						sum += arr[0][j + j - i + 1];	
				}
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}  


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#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 tc(t) 			int t;cin >> t;while(t--)
#define for0(i , n)		for(int i=0;i<n;i++)
#define loop(i , a, b)	for(int i=a;i<=b;i++)
#define endl 			'\n'
#define inf 			1e18
#define fi 				first
#define se 				second

int XX[8]={+1, +1, +1, 0, 0, -1, -1, -1};
int YY[8]={+1, 0, -1, +1, -1, +1, 0, -1};
int dx[4]={-1,1,0,0};
int dy[4]={0,0,1,-1};


signed main() {

	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

	int n;
	cin>>n;

	int a[n];

	for0(i,n) cin>>a[i];

	sort(a,a+n);

	int ans=0;

	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			for(int k=0;k<j;k++){
				if(a[i]!=a[j] && a[j]!=a[k] && a[i]<a[j]+a[k]){
					ans++;
				}
			}
		}
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3608
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}

	public Main(){
		new B().doIt();
	}
	
	
	class B{
		char[] line;
		int pos;

		int exp(){
			int r = term();
			while(true){
				char c = line[pos++];
				if(c=='+')r+=term();
				else if(c=='-')r-=term();
				else break;
			}
			return r;
		}

		int term(){
			int r = fact();
			while(true){
				char c = line[pos++];
				if(c=='*') r*=fact();
				else if(c=='/')r/=fact();
				else break;
			}
			pos--;
			return r;
		}

		int fact(){
			char c = line[pos++];
			if(c=='(')return exp();
			if(c=='-')return -fact();
			if(c=='+')return fact();
			int x = c-'0';
			while(true){
				c = line[pos++];
				if(Character.isDigit(c)){
					x *= 10;
					x += c-'0';
				}
				else break;
			}
			pos--;
			return x;
		}
		
		int left_to_right(){
//			System.out.println(Arrays.toString(line));
			int result = Integer.parseInt(line[0]+"");
			for(int i=1;i<line.length-1;i+=2){
				if(line[i]=='+'){
					result += Integer.parseInt(line[i+1]+"");
				}else{
					result *= Integer.parseInt(line[i+1]+"");
				}
			}
			return result;
		}
		
		void doIt(){
			line = (in.next()+"=").toCharArray();
			pos = 0;
			int a = exp();
			int b = left_to_right();
			int c = in.nextInt();
			if(a == b&&a == c)System.out.println("U");
			else if(a == c)System.out.println("M");
			else if(b==c)System.out.println("L");
			else System.out.println("I");
		}
	}
	
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vst = vector<st>;
using vch = vector<char>;
using vbl = vector<bl>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = 0;
  if(a < d){
    ans += a;
    d -= a;
  }
  else{
    cout << d << endl;
    return 0;
  }
  d -= b;
  cout << (d > 0 ? a - d : a) << endl;
}

Measured memory_bytes: 3596
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    ll a, b; cin >> a >> b;
    a--;
    ll ansa=0, ansb=0;

    ll bi = 1;
    rep(i, 63){
        ll diva = a / bi;
        ll divb = b / bi;
        bi *= 2;
        ll mda = a % bi;
        ll mdb = b % bi;

        if(i==0){
            if((((diva+1)/2)%2)==1) ansa += 1;
            if((((divb+1)/2)%2)==1) ansb += 1;
            continue;
        }

        if(diva%2==1 && mda%2==0) ansa += (1LL<<i);
        if(divb%2==1 && mdb%2==0) ansb += (1LL<<i);
    }

    ll ans;
    // pr(ansa);
    // pr(ansb);
    if(a==-1) ans = ansb;
    else ans = ansa^ansb;

    pr(ans);

    // pr(ans^a);
    return 0;}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
typedef long long ll;
 
int main(){
    int n;
    cin >> n;
    ll a[n+1], b[n];
    rep(i, n+1) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll ans = 0;
    rep(i,n){
        ll c;
        c = min(a[i],b[i]);
        ans += c;
        a[i] -= c;
        b[i] -= c;
        c = min(a[i+1],b[i]);
        ans += c;
        a[i+1] -= c;
        b[i] -= c;
    }
    cout << ans << endl;
    return 0;
}

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

#define forn(i,x,y) for(int i = int(x); i<int(y); i++)
#define debug(x) cerr << #x << " == " << (x) << '\n';
#define all(V) V.begin(), V.end()
#define on(x, b) (x & (1LL << b))
#define trav(x, v) for(auto &x : v)

#define f first
#define s second

int N, M, Q;
int a[55], b[55], c[55], d[55];

ll rec(int i, vector<int> &curr) {
    if(i == N) {
        ll e = 0;
        for(int j = 0; j < Q; j++) {
            if(curr[b[j] - 1] - curr[a[j] - 1] == c[j]) e += d[j];
        }
        return e;
    }
    
    vector<int> nxt = curr;
    ll ans = 0;
    for(int j = curr.back(); j <= M; j++) {
        nxt.push_back(j);
        ans = max(ans, rec(i + 1, nxt));
        nxt.pop_back();
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> M >> Q;
    int tem = -1;
    for(int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        if(a[i] == 1 and b[i] == 2) {
            tem = i;
        }
    }
    vector<int> start(1, 1);
    cout << rec(1, start) << "\n";
    return 0;
}

/* don't forget to check:
   int overflow
   min/max cases (n = 1)
   printing index of sorted array
   limits for ans (start with inf)
   s = 'x' + s is linear! dont use it!
 */


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

int main(){
  int a;
  cin>>a;
  vector<int>an(1000000);
  an.at(0)=a;
  int ans=0,b=0;
  for(int i=1;;i++){
    if(an.at(i-1)%2==0){
      an.at(i)=an.at(i-1)/2;
      for(int j=i-1;j>=0;j--){
        if(an.at(i)==an.at(j)){
          ans=i+1;
          b=1;
          break;
        }
      }
    }
    else{
      an.at(i)=an.at(i-1)*3+1;
      for(int j=i-1;j>=0;j--){
        if(an.at(i)==an.at(j)){
          ans=i+1;
          b=1;
          break;
        }
      }
    }
    if(b)
      break;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
/*------- Constants---- */

#define LL                      long long
#define Ulong                   unsigned long long
#define REP(i,n)                for(long long i=0; i < n ; i++ )
#define mp                      make_pair
#define pb                      push_back
#define all(x)                  (x).begin(),(x).end()
#define PI                      acos(-1.0)
#define EPS                     1e-14
#define F                       first
#define S                       second
#define di(x)                   int x; input(x)
#define in(x)                   input(x)
#define in2(x,y)                in(x),in(y)
#define in3(x,y,z)              in(x),in2(y,z)
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl
#define nl                      cout<<endl
#define ms(ara_name,value)      memset(ara_name,value,sizeof(ara_name))
#define IO                      ios_base::sync_with_stdio(0);cin.tie(0)
#define READ                    freopen("/home/matrixcode/Desktop/in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
template<class T> inline void input(T &x) {
  register char c = getchar();x = 0;
  int neg = 0;
  for(; ((c<48 || c>57) && c != '-'); c = getchar());
  if(c=='-'){neg = 1;c = getchar();}
  for(; c>47 && c<58 ; c = getchar()){x = (x<<1) + (x<<3) + c - 48;}
  if(neg) x = -x;
}
inline long long bigmod(long long p,long long e,long long M){
  long long ret = 1;
  for(; e > 0; e >>= 1){
    if(e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  } return ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

/***************************** END OF TEMPLATE *******************************/

const int N = 3e5+5;
int h[N];
int dp[N];
int main()
{
  int n;
  in(n);
  dp[0] = 0;
  in(h[0]);
  for(int i = 1; i < n; i ++) {
    in(h[i]);
    dp[i] = INT_MAX;
    if( i > 0 ) {
      dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
    }
    if(i > 1) {
      dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
var
	N,X,Y,loop,k,ans,z,t:Longint;
begin
	read(N,X,Y);
	loop:=Y-X+1;
	for k:=1 to N-1 do begin
		ans:=0;
		if X<k then z:=X-1 else z:=k-1;
		if k-z<=loop div 2 then begin
			if 2*k-loop-1>0 then t:=2*k-loop-1 else t:=0;
			inc(ans,(z-t div 2)*2);
			if(loop mod 2=0)and(loop div 2<k)and(k-loop div 2<X)then dec(ans);
		end;
		if N-Y<k-1 then z:=N-Y else z:=k-1;
		if k-z<=loop div 2 then begin
			if 2*k-loop-1>0 then t:=2*k-loop-1 else t:=0;
			inc(ans,(z-t div 2)*2);
			if(loop mod 2=0)and(loop div 2<k)and(k-loop div 2<N+1-Y)then dec(ans);
		end;
		if N+1+X-Y>k then inc(ans,N+1+X-Y-k);
		if k=1 then dec(ans)else begin
			if X-1>=k-1 then dec(ans);
			if N-Y>=k-1 then dec(ans);
		end;
		if k*2<loop then begin
			inc(ans,loop);
		end else if k*2=loop then begin
			inc(ans,loop div 2);
		end;
		writeln(ans);
	end;
end.


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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll N;
    cin>>N;
    vector<ll> A(N);
    rep(i,N){
        cin>>A[i];
    }

    sort(A.begin(),A.end(),greater<ll>());

    ll ans = 0;
    ll a = 0,v = 0;
    priority_queue<ll> q;
    q.push(A[0]);

    rep(i,N-1){
        a = A[i+1];
        v = q.top();q.pop();
        ans += v;
        q.push(a);
        q.push(a);
    }
    cout<<ans<<"\n";


	
	return 0;
}

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

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

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

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

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

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

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

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

fn main() {
    input! {
        s1: String,
        s2: String,
    }
    let c1 = s1.chars().collect::<Vec<_>>();
    let c2 = s2.chars().collect::<Vec<_>>();
    if c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0] {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k;
    cin >> k;
    ll n = 50;
    vector<ll> a(n, k/n + n - 1);
    k %= n;
    rep(i,n){
        if(i < k) a[i]++;
        else a[i] -= k;
    }
    cout << n << endl;
    rep(i,n) cout << a[i] << " ";
    cout << endl;
    return 0;
}

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


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

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

cd = lcm(c, d)

div_c = b // c - (a-1)//c
div_d = b // d - (a-1)//d
div_cd = b // cd - (a-1)//cd
count = b - a + 1 - div_c - div_d + div_cd
print(count)


Measured memory_bytes: 3060