akhauriyash/Code-Regression huggingface dataset:
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=5005;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
int ans[N],f[N],a[N],sz[N],n;
void dfs1(int u,int fa){
	f[u]=0;
	go(u)if(v!=fa){
		dfs1(v,u),++sz[u];
		if(a[u]>a[v])f[u]|=!f[v];
	}
}
void dfs2(int u,int fa,int pa){
	pa=(a[u]>a[fa]&&!pa);
	ans[u]=f[u]|pa;
//	vector<int>st(sz[u]+2),Pre(sz[u]+2),suf(sz[u]+2);
	int st[N],Pre[N],suf[N];
	int top=0;
	go(u)if(v!=fa)st[++top]=v;
	Pre[0]=0;fp(i,1,top)Pre[i]=Pre[i-1]|(a[u]>a[st[i]]&&!f[st[i]]);
	suf[top+1]=0;fd(i,top,1)suf[i]=suf[i+1]|(a[u]>a[st[i]]&&!f[st[i]]);
	fp(i,1,top)dfs2(st[i],u,Pre[i-1]|suf[i+1]|pa);
}
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]);
	for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v),add(v,u);
	dfs1(1,0),dfs2(1,0,1);
	fp(i,1,n)if(ans[i])printf("%d ",i);
	return 0;
}

Measured memory_bytes: 35712
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Spandan Mishra
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CAXBC solver = new CAXBC();
        solver.solve(1, in, out);
        out.close();
    }

    static class CAXBC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();

            int ans = 0;

            for (int i = 1; i <= 1000000; i++) {
                for (int j = 1; j <= 1000000; j++) {
                    if (i * j >= n)
                        break;

//                System.out.println("ans ->" + ans + " - " + i + " " + j + " " + (n - (i * j)));
                    ans++;
                }
            }

            System.out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new RuntimeException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 32904
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

ll calc(ll x){
    int p = 0;
    while (((x >> p) & 1LL) == 0) p++;
    return 1LL << p;
}

int main() {
    int n;
    ll h;
    cin >> n >> h;
    vector<string> s(n);
    REP(i,n) cin >> s[i];
    sort(ALL(s));

    // for (string str : s) cout << str << endl;

    ll gr = 0;
    REP(i,n-1){
        int j = 0;
        while (s[i][j] == s[i+1][j]) j++;
        // cout << j << endl;
        FOR(x,j+1,s[i].length()-1){
            // cout << x << endl;
            if (s[i][x] == '0') gr ^= calc(h - x);
        }
        FOR(x,j+1,s[i+1].length()-1){
            // cout << x << endl;
            if (s[i+1][x] == '1') gr ^= calc(h - x);
        }
    }

    // cout << gr << endl;

    REP(j,s[0].length()){
        // if (j == 0) continue;
        if (s[0][j] == '1') gr ^= calc(h - j);
    }

    // cout << gr << endl;

    REP(j,s[n-1].length()){
        // if (j == 0) continue;
        if (s[n-1][j] == '0') gr ^= calc(h - j);
        // cout << gr << endl;
    }

    // cout << gr << endl;

    cout << (gr != 0 ? "Alice" : "Bob") << endl;


    return 0;
}





Measured memory_bytes: 640
//Finite Disappointment and Infinite Hope
#include <bits/stdc++.h>
using namespace std;
#define help ios_base:: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.first<<","<<v.second<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    for(auto &x:c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
const ll N=2e5+5,MOD=1e9+7;
int main(){
help
    ll n,k;cin>>n>>k;
    ll a[n];for(ll i=0;i<n;i++)cin>>a[i];
    sort(a,a+n,greater<ll>() );
    ll ans = 0;
    for(ll i=k;i<n;i++)ans+=a[i];
    cout<<ans;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,n) for(lli i=0;i<n;i++)
#define repb(i,n) for(lli i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
#define all(X) X.begin(),X.end()
#define iterate(X) for(it=X.begin();it!=X.end();it++)
lli combi(lli n,lli k)
{
    lli ans=1;
    k=k>n-k?n-k:k;
    lli j=1;
    for(;j<=k;j++,n--)
    {
        if(n%j==0)
        {
            ans*=n/j;
        }else
        if(ans%j==0)
        {
            ans=ans/j*n;
        }else
        {
            ans=(ans*n)/j;
        }
    }
    return ans;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli findlcm(vector <lli> arr, lli n)
{
    lli ans = arr[0];
    for (lli i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (gcd(arr[i], ans)));

    return ans;
}
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli x;
    cin>>x;
    lli a=inf,b=inf;
    for(lli i=-1000;i<=1000;i++){
    	for(lli j=-1000;j<=i;j++){
    		lli vala=pow(i,5);
    		lli valb=pow(j,5);
    		if((vala-valb)==x){
    			a=i;
    			b=j;
    			break;
			}
		}
		if(a!=inf)
		break;
	}
	cout<<a<<" "<<b;
    return 0;
}


Measured memory_bytes: 4072
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  vector<vector<int>> f(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i + j == 0) {
        f[0][0] = (s[0][0] == '#');
        
      } else {
        f[i][j] = (int) 1e9;
        if (i > 0) f[i][j] = min(f[i][j], f[i - 1][j] + (s[i - 1][j] == '.' && s[i][j] == '#'));
        if (j > 0) f[i][j] = min(f[i][j], f[i][j - 1] + (s[i][j - 1] == '.' && s[i][j] == '#'));
      }
    //   cout << f[i][j] << " ";
     
    }
    // cout << '\n';
  }
  cout << f[h - 1][w - 1] << '\n';
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MOD (1000000007)
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

const int MAX = 400001;
ll fac[MAX], finv[MAX], inv[MAX];

void init(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

ll comb(int n, int k){
  if(n < k) return 0;
  if(n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

  int n, m;
  cin >> n >> m;

  vector< int > pc;
  int mm = m;
  for(ll i = 2; i * i <= mm; i++){
    if(mm % i != 0) continue;
    int count = 0;
    while(mm % i == 0){
      ++count;
      mm /= i;
    }
    pc.push_back(count);
  }
  if(mm != 1) pc.push_back(1);

  init();

  ll ans = 1;
  for(int c: pc){
    ans = (ans * comb(c + n - 1, n - 1)) % MOD;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9600
def main():
    a, b, c, k = map(int, input().split())
    ans = min(a, k)
    k = max(k-a, 0)
    if k == 0:
        print(ans)
        return
    k = max(k-b, 0)
    if k == 0:
        print(ans)
        return
    print(ans - k)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 61916
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long LL;
LL w;
int a, b;
int s[105];
int main()
{
	scanf("%d %d",&a,&b);
	if(b == 10 ||b == 20|| b== 30||b == 40||b == 50|| b== 60|| b== 70||b == 80||b==90)
	{
		w = a * 100 + b;
	}
	else 
	{
	int c = b;
	int x = 0;
	while(c)
	{
		c = c / 10;
		x++;
	}
	for(int i = 1;i <= x;i++)
	{
		a = a * 10;
	}
	w = a + b;
	}
//	printf("%lld\n",w);
    double p = sqrt(w);
    int q = sqrt(w);
    if(q == p) printf("Yes\n");
    else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int x, y, a;
    int x_max = W;
    int x_min = 0;
    int y_max = H;
	int y_min = 0;
	for(int i = 0; i < N; i++){
		cin >> x >> y >> a;
		switch(a){
            case 1:
                if(x_min < x){
                    x_min = x;
                }
                break;
            case 2:
                if(x_max > x){
                    x_max = x;
                }
                break;
            case 3:
                if(y_min < y){
                    y_min = y;
                }
                break;
            case 4:
                if(y_max > y){
                    y_max = y;
                }
                break;
            }
	}

	if(x_max > x_min && y_max > y_min) {
		cout << (x_max - x_min) * (y_max - y_min) << endl;
	} else {
		cout << 0 << endl;
	}


	return 0;
}

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

const int MOD=998244353;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}

vector<ll>divisor(ll n){
	vector<ll>res;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			res.push_back(i);
			if(i!=n/i)res.push_back(n/i);
		}
	}
	return res;
}

ll dp[500000];

int main(){
	int n;string s;cin>>n>>s;
	auto v=divisor(n);
	for(int k:v){
		if((n/k)%2==0)continue;
		ll sum=0;
		rep(i,k){
			if(s[i]=='1')(sum+=ppow(2,k-i-1))%=MOD;
		}
		int g=0;
		bool ok=false;
		while(g<n){
			char c=s[g%k];
			if((g/k)%2==1)c=(c=='0'?'1':'0');
			if(s[g]==c)g++;
			else{
				if(s[g]<c)ok=false;
				else ok=true;
				break;
			}
		}
		if(g==n||ok)sum++;
		dp[k]=sum%MOD;
	}
	for(int i=1;i<=n;i++){
		if(!dp[i])continue;
		for(int j=2*i;j<=n;j+=i)(dp[j]+=MOD-dp[i])%=MOD;
	}
	ll all=1;
	rep(i,n){
		if(s[i]=='1')(all+=ppow(2,n-i-1))%=MOD;
	}
	ll ans=0;
	for(int k:v){
		(ans+=2*k*dp[k])%=MOD;
		(all+=MOD-dp[k])%=MOD;
	}
	(ans+=all*2*n)%=MOD;
	cout<<ans<<endl;
}

Measured memory_bytes: 2180
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	As := ReadInts(N)

	m := make(map[int]int)
	for i := 0; i < N; i++ {
		m[i-As[i]]++
	}

	ans := 0
	for i := 0; i < N; i++ {
		ans += m[i+As[i]]
	}
	fmt.Println(ans)
}

func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 14936
#include <cstdio>
#include <string>
using namespace std;

char buf[1000];
string enc, ans;

string decrypt(string s, int k) {
  string ret = "";
  for (int i=0; i<s.size(); i++) {
    char c = s[i];
    if ('a' <= c && c <= 'z') {
      ret += ('a' + ((c-'a')+k)%26);
    } else {
      ret += c;
    }
  }
  return ret;
}

int main() {
  while (1) {
    if (fgets(buf, 100, stdin) == NULL) break;
    enc = buf;
    for (int i=0;i<26;i++) {
      ans = decrypt(enc, i);
      if (ans.find("the") != string::npos) break;
      if (ans.find("this") != string::npos) break;
      if (ans.find("that") != string::npos) break;
    }

    printf("%s", ans.c_str());
  }
}

Measured memory_bytes: 2748
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>

using namespace std;

void solve(int a)
{
if (!(a%1000)) cout << 0;
else cout << 1000-(a%1000);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a; cin >> a; solve (a);
    return 0;
}

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

int main()
{
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	int aa = 100 * a, bb = 100 * b;
	int r_num = 0, r_den = 1;
	int r_sugar = 0, r_sugarwater = 0;
	
	for(int ia=0; aa*ia<=f; ia++)
	{
		int r1 = f - aa*ia;
		for(int ib=0; bb*ib<=r1; ib++)
		{
			int r2 = r1 - bb*ib;
			for(int ic=0; c*ic<=r2; ic++)
			{
				int r3 = r2 - c*ic;
				for(int id=0; d*id<=r3; id++)
				{
					int water = aa*ia + bb*ib;
					int sugar_capacity = water / 100 * e;
					int sugar = c*ic + d*id;
					if(sugar <= sugar_capacity)
					{
						int x_num = sugar;
						int x_den = sugar + water;
						if(x_num*r_den >= r_num*x_den)
						{
							r_num = x_num;
							r_den = x_den;
							r_sugar = sugar;
							r_sugarwater = sugar + water;
						}
					}
					
				}
			}
		}
	}
	cout << r_sugarwater << " " << r_sugar << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 3000010
typedef long long LL;
int a[N], tot, n, m;
LL sum;
 
int main() {
    //freopen("sample.in", "r", stdin);
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        int tmp; scanf("%d", &tmp);
        sum += tmp;
        while (tmp) {
            a[++tot] = tmp - tmp / 2, tmp /= 2;
        }
    }
    if (m >= tot) return cout << 0 << endl, 0;
    nth_element(a + 1, a + tot - m + 1, a + tot + 1);
    //for(int i = 1; i <= tot; i++) cout << a[i] << endl;
    int kth = a[tot - m + 1], num = 0;
    for(int i = 1; i <= tot; i++)
        if (a[i] > kth) sum -= a[i], num++;
    sum = sum - (LL)kth * (m - num);
    cout << sum << endl;
}

Measured memory_bytes: 11904
#include <iostream>

using namespace std;

int main() {
  int n;
  int fn = 0;
  int m;
  cin >> n;
  m = n;

  for(int i = 100000000; i >= 1; i = i / 10) {
    fn += n / i;
    n = n - (n / i) * i;
  }

  if(m % fn == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
int dy[4] = { 1, 0, -1, 0 }, dx[4] = { 0, 1, 0, -1 };
typedef pair<ll, ll> P;
const long long INF = 1ll << 60;
const int MAX = 210;

int N, M, R;
ll dist[MAX][MAX]; // d[a][b]はaからbへの距離

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> R;
    vector<int> vec;
    for (int i = 0; i < R; i++) {
        int tmp;
        cin >> tmp;
        --tmp;
        vec.push_back(tmp);
    }
    // Floyd-Warshallの初期化: dist[i][i] = 0
    for (int i = 0; i < 210; i++) {
        for (int j = 0; j < 210; j++) {
            dist[i][j] = INF;
        }
        dist[i][i] = 0;
    }

    // 入力
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        dist[a][b] = dist[b][a] = c;
    }

    // Floyd-Warshallで各点への距離を求めている
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    // R!通りの探索
    ll res = INF;
    // 訪れる町を昇順にソート
    sort(vec.begin(), vec.end());
    do {
        ll tmp = 0;
        // 訪れる町の距離を求める
        for (int i = 1; i < vec.size(); i++) {
            tmp += dist[vec[i]][vec[i - 1]];
        }
        // 最小のものを答えとする
        res = min(res, tmp);
    } while (next_permutation(vec.begin(), vec.end()));
    // next_permutationを用いることですべての順列で試す

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

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

using namespace std;

int main(){

  long N,K,a,b,s;
  bool can;
  can=true;

  cin>>N>>K;

  s=N/K;
  a=abs(N-(s*K));
  b=abs(N-((s+1)*K));
  //cout<<s<<" "<<a<<" "<<b<<endl;
  if(a>b){
  cout<<b<<endl;
  }
  else{
  cout<<a<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

locale l = locale::classic();

int main(){
    while(1){
        string s;
        cin >> s;
        ll ans=0;
        rep(i,s.size()){
            ans += s[i] - '0';
        }
        if(!ans) return 0;
        cout << ans << endl;
    }
}


Measured memory_bytes: 3176
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 110;
const int bias = 5;
LL dp[MAX][MAX * bias][MAX];
int N, W, w[MAX], v[MAX];
int mins;

int main(void) {
    memset(dp, -1, sizeof(dp));
    scanf("%d%d", &N, &W);
    REP(i, N) {
        scanf("%d%d", w + i, v + i);
        if (i == 0) {
            mins = w[i];
        }
        w[i] -= mins;
    }
    dp[0][0][0] = 0;
    REP(i, N) {
        REP(j, MAX * bias)
            REP(k, MAX) chmax(dp[i + 1][j][k], dp[i][j][k]);
        REP(j, MAX * bias) {
            REP(k, MAX) {
                if (dp[i][j][k] != -1 && j + w[i] < MAX * bias && k + 1 < MAX) {
                    chmax(dp[i + 1][j + w[i]][k + 1], dp[i][j][k] + v[i]);
                }
            }
        }
    }
    LL ans = 0;
    REP(i, N + 1) {
        REP(j, MAX * bias) {
            REP(k, MAX) {
                if (j + 1ll * k * mins <= W) {
                    chmax(ans, dp[i][j][k]);
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 52224
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
X,Y = LI()
for x,y in itertools.product(range(X+1),range(Y+1)):
    if x+y==X and 2*x+4*y==Y:
        print('Yes')
        break
else:
    print('No')


Measured memory_bytes: 9176
N, K = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(N)]
x_sort = sorted(XY, key=lambda x: x[0])


def check(l, r, b, t):
    cnt = 0
    for x, y in XY:
        if r >= x and x >= l and t >= y and b >= y:
            cnt += 1
    return cnt >= K


ans = 10**20

for i in range(N - K + 1):
    xl = x_sort[i][0]
    for j in range(i + K - 1, N):
        dx = x_sort[j][0] - xl

        points = sorted(x_sort[i: j+1], key=lambda x: x[1])

        rest = j - i + 1
        for p in range(rest - K + 1):
            yd = points[p][1]
            for q in range(p + K - 1, rest):
                dy = points[q][1] - yd
                ans = min(ans, dx*dy)

print(ans)


Measured memory_bytes: 3064
a,b,c,d=map(int,input().split())
a-=1
def gcd(a,b):
    if b==0: return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)
aa= b//c-a//c 
bb= b//d-a//d 
cc= b//lcm(c,d)- a//lcm(c,d)
print(b-a-(aa+bb-cc))

Measured memory_bytes: 9060
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b;
  cin >> a >> b;
  cout << a * b - a - b + 1 << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

public class AtCoderC
{
    static void Main()
    {
        long n;
        long k;
        long q;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            n = long.Parse(words[0]);
            k = long.Parse(words[1]);
            q = long.Parse(words[2]);
        }

        int[] count = new int[n];
        for (int i = 0; i < q; i++)
        {
            int num = int.Parse(Console.ReadLine());
            count[num - 1]++;
        }

        for (int i = 0; i < n; i++)
        {
            if (k - q + count[i] > 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 17600
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main(){
    input!{
        n: i32,
        a: [i32; n],
    }
    let mut b = a.clone();
    b.sort();
    b.reverse();
    for i in 0..n as usize{
        if a[i] == b[0]{
            println!("{}", b[1]);
        }
        else{
            println!("{}", b[0]);
        }

    }


}

Measured memory_bytes: 7676
n=io.read("*n")
while 1 do
	s={}
	a=n
	cnt=0
	while a~=0 do
		if s[a%10]==nil then
			cnt=cnt+1
		end
		s[a%10]=1
		a=math.floor(a/10)
	end
	if cnt==1 then
		print(n)
		os.exit()
	end
	n=n+1
end

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		sc.close();
		
		//3文字目と4文字目が等しい
		if(str.charAt(2) == str.charAt(3)) {
			if(str.charAt(4) == str.charAt(5)) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}else {
			System.out.println("No");
		}
	}
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b;
  c = a % 2;
  d = b % 2;
  
  if (c == 1 && d == 1){
    cout << "Odd" << endl;
  }
  
  else {
    cout << "Even" << endl;
  }
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back

int main() {
  int x,y; cin>>x>>y;
  rep(i,x+1) rep(j,x+1) {
    if(i*2+j*4==y&&i+j==x) {
      cout<<"Yes\n";
      return 0;
    }
  }
  cout<<"No\n";
}


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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    char ans= abs(a-b)<abs(a-c)?'A':'B';
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

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

int main() {
    int n;
    cin >> n;
    rep(i, n, n + 10000) {
        if (is_prime(i)) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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

using namespace std;
using Int = long long;

const int nax = 10005;

string s;
int D;

const int mod = int(1e9 + 7);

void add(int &a, int b) {
  a += b;
  if(a >= mod) a -= mod;
}

int dp[nax][101][2];

int rec(int pos, int sum, int cross) {
  if(pos == (int) s.length()) {
    return sum == 0;
  }
  if(dp[pos][sum][cross] != -1) {
    return dp[pos][sum][cross];
  }
  int x = 0;
  for(int d = 0; d < 10; ++d) {
    if(cross && d > (s[pos] - '0')) {
      break;
    }
    add(x, rec(pos + 1, (sum + d) % D, cross && d == (s[pos] - '0')));
  }
  return dp[pos][sum][cross] = x;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> s >> D;
  int res = 0;
  memset(dp, -1, sizeof dp);
  for(int i = 0; i < (s[0] - '0'); ++i) {
    add(res, rec(1, i % D, 0));
  }
  add(res, rec(1, (s[0] - '0') % D, 1));
  cout << (res - 1 + mod) % mod << '\n';
  return 0;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x) make_pair(x)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
 
int main() {

    int n;
    cin>>n;
    vector<int> p(n);
    rep(i,n)    cin>>p.at(i);

    int mini=p[0];
    int ans=1;
    for(int i=1;i<n;i++) {
        if(p[i]<=mini) {
            mini=p[i];
            ans++;
        }       
    }

    cout<<ans<<endl;

 return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int h = sc.nextInt();
		int n = sc.nextInt();
		int[] list = new int[n];

		for (int i = 0; i < n; i++) {
			list[i] = sc.nextInt();
		}

		for (int i = 0; i < n; i++) {
			h -= list[i];
		}

		if (h <= 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}
}

Measured memory_bytes: 59348
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }
 
    // 素数である
    return 1;
}
 
int main(){
    lint N,M;
    cin>>N>>M;
    vector<lint>  from;
    vector<lint> out;
    rep(i,M){
        lint g,y;
        cin>>g>>y;
        if(g==1)from.push_back(y);
        if(y==N)out.push_back(g);
    }
    sort(from.begin(),from.end());
    if(from.size()==0||out.size()==0){
        cout<<"IMPOSSIBLE";
        return 0;
    }
      
       
        rep(i,out.size()){
            if(binary_search(from.begin(),from.end(),out[i])){
                cout<<"POSSIBLE";
                return 0;
            }
        }
        cout<<"IMPOSSIBLE";
}

Measured memory_bytes: 1984
// A - Fifty-Fifty

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

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

	sort(S.begin(), S.end());

	if (S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

int main() {
    long long N, H, W, A, B;
    int ans = 0;

    cin >> N >> H >> W;
    for (int i = 0; i < N; i++) {
        cin >> A >> B;
        if (A >= H && B >= W) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI(N);
  while (N > 0) {
    int n = 1;
    while (n * (n + 1) / 2 < N) {
      n++;
    }
    print(n);
    N -= n;
  }
  return 0;
}

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

char alphas[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

 
int main(){
    int N;
    long long int sum=1;
    vector<int> num(26,0);
    cin >> N;
    string S;
    cin >> S;
    for(int i=0;i<N;i++){
        for(int j=0;j<26;j++){
            if(S[i]==alphas[j]){
                num[j]++;
            }
        }
    }

    for(int i=0;i<26;i++){
        sum *= (num[i]+1);
        sum %= 1000000007;
    }

    cout << sum-1 << endl;
}

Measured memory_bytes: 512
#include<stdio.h>

static const int N = 1000;

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

int main(){
  int n, i, j;
  int A[N+1];
  int key;
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  //  trace(A, n);
  
    for(i =1; i<=n ;i++) {
    key = A[i];
    j=i-1;
    
    while (j >= 0 && A[j] > key) {    
    A[j+1] = A[j];
        j--;
    A[j+1] = key;
     }
    trace(A,n);
    }  
   

  return 0;
}

Measured memory_bytes: 2732
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n; cin >> n;
  vector<ll> sum(n+1, 0);
  REP(i,n) sum[i+1] = sum[i] + (i+1);

  ll ans = 0;
  for(ll i=1; i<=n; i++){
    ans += i * sum[n/i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 81324
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)
#define Rep(i, n) for(i = 1; i < n; i++)
#define Ans(s) cout << s << endl;

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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 GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

int main()
{
	int x, y, z;
	cin >> x >> y >> z;

	int ans = x / (y + z);

	if ((y + z) * ans + z > x) ans--;
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int count = 0;
        for(int i=0;i<n;i++){
            long p = sc.nextLong();
            long q = sc.nextLong();
            double ans = Math.sqrt((p*p)+(q*q));
            if(ans<=d)count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 59248
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
// ver1.7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

int F(int a,int b){
  int c;
  c = max(leng(a),leng(b));
  return c;
}

signed main() {
  int n;
  cin >> n;
  int so;
  so = sqrt(n);
  int ans = INF;
  int memo;
  repeq(i,1,so){
    if(n%i!=0) continue;
    memo = n/i;
    ans = min(ans,F(i,memo));
    //cout << memo <<' '<<i << endl; 
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n;
  cin >> n;
  vector<i64> a(n);
  for (i64 i = 0; i < n; i++)
    cin >> a[i];
  vector<i64> ans(n);
  for (i64 i = 0; i < n; i++)
    ans[a[i] - 1] = i + 1;
  for (i64 i = 0; i < n; i++)
    cout << ans[i] << (i + 1 == n ? "\n" : " ");
  return 0;
}


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

typedef long long int ll ;

ll gcd(ll aaa,ll bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

ll lcm(ll m,ll n)
{
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}

int main() {

	string S;
	cin >> S;
	long ans=0,r=0,b=0,count=0;
	if(S[0] == '0') {
		r++;
	}else {
		b++;
	}
	for(long i = 1; i < S.size(); i++) {
		if(S[i] != S[i-1]) {
			if(count == 1){
				ans += min(r,b) * 2;
				if(r < b) {
					b -= r;
					r = 0;
				}else{
					r -= b;
					b = 0;
				}
				count = 0;
				if(S[i] == '0') {
					r++;
				}else {
					b++;
				}
			}else {
				count = 1;
				if(S[i] == '0') {
					r++;
				}else {
					b++;
				}
			}
		}else {
			if(S[i] == '0') {
					r++;
				}else {
					b++;
				}
		}
	}
	if(count = 1) {
		ans += min(r,b) * 2;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
import sys
import itertools as itr
readline = sys.stdin.buffer.readline
N=int(readline())
n=int(pow(N,0.5))
chk=list(itr.product(range(1,n),repeat=3))
cnt=[0]*(N+1)
for c in chk:
  i=c[0]
  j=c[1]
  k=c[2]
  if i*i+j*j+k*k+i*j+j*k+k*i<=N:
    cnt[i*i+j*j+k*k+i*j+j*k+k*i]+=1
for i in range(1,N+1):
  print(cnt[i])

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

using namespace std;

int gcd(int x, int y){
    if(x > y){
        swap(x, y);
    }
    return x ? gcd(y%x, x) : y;
}

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

    int n, x;
    cin >> n >> x;
    int arr[110000] = { 0 };
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    arr[n] = x;
    sort(arr, arr+110000, greater<int>());

    int ans = 0;
    if(n == 1){
        ans = arr[0] - arr[1];
    }
    else{
        for(int i = 0; i < n; i++){
            if(ans == 0){
                ans = arr[i] - arr[i+1];
            }
            else{
                ans = gcd(arr[i] - arr[i+1], ans);
            }
        }
    }

    cout << ans << '\n';

    return 0;
}



Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<cassert>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<bitset>

#define rep(n) for(int i=0;i<n;++i)
#define repp(j, n) for(int j=0;j<n;++j)
#define reppp(i, m, n) for(int i=m;i<n;++i)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 10e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;

    ll ans = 0LL;
    bool b = false;
    ll w_i = 0LL;
    for(ll i=0;i<ll(s.length());++i) {
        if(b) {
            if(s[i] == 'W') {
                ans += i-w_i;
                ++w_i;
            }
        } else {
            if (s[i] == 'B') b = true;
            else ++w_i;
        }
    }
    cout << ans << endl;
}


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

int main(){
  int k;
  cin >> k;
  int ans = 0;
  for(int a=1; a<=k; a++)for(int b=1; b<=k; b++)for(int c=1; c<=k; c++){
    ans += gcd(a, gcd(b, c));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int	num = 0;
		while((num = parseNum())!= 0) {
			fact(num);
		}
	}

	private static void fact(int n) {
		int		t = 0;
		int[]	a = new int[2];

		for(int i = 2; i <= n; i++) {
			for(t = i; t % 2 == 0; t /= 2) {
				a[0]++;
			}

			for(t = i; t % 5 == 0; t /= 5) {
				a[1]++;
			}
		}

		System.out.println(Math.min(a[0], a[1]));
	}

	private static int parseNum() {
		int		num    = 0;
		String	strNum = parseStdin();

		if (strNum != null) {
			num = Integer.parseInt(strNum);
		}

		return num;
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, l[100];

int main() {
	cin >> n;
	
	l[0] = 2;
	l[1] = 1;
	
	incII(i, 2, n) {
		l[i] = l[i - 1] + l[i - 2];
	}
	
	cout << l[n] << endl;
	
	return 0;
}


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

#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")

using namespace std;

typedef long long ll;
typedef long double ld;


void solve() {
    int x, n;
    cin >> x >>  n;
    set<int> have;
    for (int i = 0; i < n; ++i) {
        int val; cin >> val;
        have.insert(val);
    } 
    for (int d = 0; d <= n + 2; ++d) {
        if (!have.count(x - d)) {
            cout << x - d << "\n";
            return;
        } 
        if (!have.count(x + d)) {
            cout << x + d << "\n";
            return;
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <math.h>
#include<string.h>

int main(){
	int joi, ioi, i, len;
	char str[10000];
	while(scanf("%s", &str) != EOF){
		joi = ioi = 0;
		len = strlen(str);
		for(i = 0; i < len - 2; i++){
			if(str[i] == 'J' && str[i + 1] == 'O' && str[i + 2] == 'I') joi++;
			if(str[i] == 'I' && str[i + 1] == 'O' && str[i + 2] == 'I') ioi++;
		}
		printf("%d\n%d\n", joi, ioi);
	}
	return 0;
}

Measured memory_bytes: 552