akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
#include<iomanip>

using namespace std;
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define RED 3
vector<long long int> A(1000050,0);
long long int N,P;
long long int P1;
long long int ans=1;
long long int cnt=0;

int main(void){
 long long int i=2;
 int check=1;
 cin>>N>>P;
 P1=P;

 if(N==1){
  cout<<P<<endl;
  return 0;
 }

 while(P>1 && i<=sqrt(P1)){
  if(P%i==0){
   cnt++;
   P/=i;
   if(cnt>=N){
    if(cnt>0 && cnt%N==0){
     ans*=i;
    }
   }
  }
  else{
   i++;
   cnt=0;
   check=1;
  }
 }
 
 cout<<ans<<endl; 
 return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <string>

using namespace std;

int main(){
    int n; cin >> n;
    int depth = 0;
    bool ok = 1;
    for(int i=0; i<n; i++){
        char pare; cin >> pare;
        int pm;
        if(pare == '(') pm = 1;
        else pm = -1;
        
        int k; cin >> k;
        depth += pm * k;
        if(depth < 0){
            ok = 0;
            break;
        }
    }
    if(ok && depth == 0) cout << "YES";
    else cout << "NO";
    cout << endl;
}

Measured memory_bytes: 1156
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	long long int n,ans = 1e18;
	cin >> n;
	for (long long int i = 1; i * i <= n; i++)
	{
		if (n % i != 0)continue;
		long long int j = n / i;
		ans = min(ans, i + j - 2);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
D, G = map(int, input().split(' '))
p_c_pairs = [((i+1) * 100, list(map(int, input().split(' ')))) for i in range(D)]

import math
ans = float('inf')
p_c_pairs.sort(key=lambda x: -x[0])
for d in range(1<<D):
    # print(bin(d))

    cnt = 0
    g = G
    for i in range(D):
        if 1 & (d >> i):
            score, (p, c) = p_c_pairs[i]
            g -= score * p + c
            cnt += p

    if g > 0:
        for i in range(D):
            if not (1 & (d >> i)):
                score, (p, c) = p_c_pairs[i]
                n = min(p, int(math.ceil(g/score)))
                g -= score * n
                cnt += n
                break

    # print(bin(d), g)
    if g <= 0:
        ans = min(ans, cnt)

print(ans)

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

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((ll)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const int INF = 1e9+10;
const ll mod = 998244353;
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; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 


int main() {
    int H, W, K;
    cin >> H >> W >> K;
    int ans = 0;
    vector<string> A(H);
    rep(i, H){
        cin >> A[i];
    }
    
    
    
    rep (bit, 1 << H){
        rep (bit2, 1 << W){
            int cnt = 0;
            rep (i, H){
                rep(j, W){
                    if ((bit & (1 << i))  &&
                        (bit2 & (1 << j))  &&
                        A[i][j] == '#'){
                        cnt ++;
                    }
                }
            }
            if (cnt == K)ans++;
        }
    }
    cout << ans;    
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const ll mod = 1000000007;
ll N, T;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> T;
    vector<ll> v(N);
    for(int i = 0; i < N; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    ll ans = 1;
    ll l = 0;
    for(ll i = 0; i < N; i++) {
        while(v[l] < v[i] - T) l++;
        ans *= (i - l + 1);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3564
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;



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

	cin >> N;
	vector<int>v(N);
	vector<int>w(N);
	for (auto &i : v)cin >> i;
	for (auto &i : w)cin >> i;
	vector<int>p(N);
	int a = 0, b = 0;
	for (int i = 0; i < N; i++)p[i] = i + 1;
	int cnt = 0;
	do {
		if (p == v)a = cnt;
		if (p == w)b = cnt;
		cnt++;
	} while (next_permutation(p.begin(), p.end()));
	cout << abs(a - b) << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;

#define INF 0xc0c0c0c0
#define NINF 0x3f3f3f3f

#define FOR(i, a, b) for((i)=a; i<b; ++(i))
#define EFOR(i, a, b) for((i)=a; i>b; --(i))

#define MLC(n, type) (type*)malloc(n*sizeof(type))
#define CLC(n, type) (type*)calloc(n, sizeof(type))

#define MAXN 100000+2

void solver(int *nums, int numsSize) {
	int i = 0, j = numsSize - 1;
	long long int sum1 = 0, sum2 = 0;
	sort(nums, nums+numsSize);

	for (i = 0; i+1<=j-1; ++i,--j) {
		sum1 += nums[j] + nums[j-1] - (nums[i]<<1);
		sum2 += (nums[j]<<1) - nums[i] - nums[i+1];
	}

	if (i == j) {
		sum1 = max(sum1, sum1 - nums[i] + nums[i-1] + nums[numsSize-1] - nums[i]);
		sum2 = max(sum2, sum2 - nums[j+1] + nums[i] + nums[i] - nums[0]);
	}
	else {
		sum1 += (nums[numsSize-1] - nums[i] > nums[j] - nums[i])?(nums[numsSize-1] - nums[i]):(nums[j] - nums[i]);
		sum2 += (nums[j] - nums[0] > nums[j] - nums[i])?(nums[j] - nums[0]):(nums[j] - nums[i]);
	}

	printf("%lld\n", max(sum1, sum2));
	return;
}

int main() {
	int i,n;
	int a[MAXN] = {0};

	scanf("%d", &n);

	FOR(i, 0, n) {
		scanf("%d", &a[i]);
	}

	solver(a, n);
	return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    String s = sc.nextLine();
    
    int c = 0;
    for(int i = 0; i < N; i++){
      if(s.charAt(i) == 'E'){
        c++;
      }
    }
    
    int d = 0;
    int n = c;
    for(int i = 0; i < N; i++){
      if(s.charAt(i) == 'E'){
        c--;
      }else{
        d++;
      }
      if(c+d < n){
        n = c+d;
      }
    }
    System.out.println(n);
  }
}

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

bool kouji[20][20];
int dp[20][20];

void init(void) {
    for(int i=0; i<20; i++) for(int j=0; j<20; j++) {
        kouji[i][j] = false;
        dp[i][j] = 0;
    }
}

int main(void) {
    int a, b, n;
    while(1) {
        cin >> a >> b;
        if(a == 0 and b == 0) break;
        cin >> n;

        init();
        for(int i=0; i<n; i++) {
            int x, y;
            cin >> x >> y;
            kouji[y][x] = true;
        }

        for(int y=1; y<=b; y++) {
            for(int x=1; x<=a; x++) {
                if(kouji[y][x]) continue;
                if(x == 1 and y == 1) {
                    dp[y][x] = 1;
                } else {
                    dp[y][x] = dp[y][x-1] + dp[y-1][x];
                }
            }
        }
        cout << dp[b][a] << endl;
    }

    return 0;
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<long long> a(n), b(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n; i++){
		if(i % 2) b[i] = 2;
		else b[i] = -2;
	}
	b[0] /= 2, b[n - 1] /= 2;
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	long long ans1 = 0, ans2 = 0;
	for(int i = 0; i < n; i++){
		ans1 += a[i] * b[i];
	}
	for(int i = 0; i < n; i++){
		b[i] *= -1;
	}
	for(int i = 0; i < n; i++){
		ans2 += a[i] * b[n - 1 - i];
	}
	cout << max(ans1, ans2) << endl;
	return 0;
}

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

const int N = 1e5 + 5;

int v[N];

int main() {
#ifdef HOME
	freopen("arc.in", "r", stdin);
	freopen("arc.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n, x, ant(0);

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

	for (int i = 0; i < N; ++i)
		ant = max(ant, v[i]);

	cout << ant << endl;

	return 0; }

Measured memory_bytes: 640
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    tt=LI()
    vv=LI()+[0]
    #区間の変わり目においてのvの最大値を左右から調べる
    y=0
    max_vL=[1000]*(n-1)
    max_vR=[1000]*(n-1)
    for i in range(n-1):
        y=min(vv[i],vv[i+1],y+tt[i])
        max_vL[i]=y
    y=0
    for i in range(n-2,-1,-1):
        y=min(vv[i+1],vv[i],y+tt[i+1])
        max_vR[i]=y
    #print(max_vR)
    #print(max_vL)
    #左右のminを取ることで、変わり目のvを決める
    yy=[0]*(n+1)
    for i in range(n-1):
        yy[i+1]=min(max_vL[i],max_vR[i])
    #print(yy)
    #各区間の面積を求める
    ans=0
    for t,y0,y1,v in zip(tt,yy,yy[1:],vv):
        h=(t+y0+y1)/2
        ans+=((h+y0)*(h-y0)+(h+y1)*(h-y1))/2
        if h>v:ans-=(h-v)**2
    print(ans)

main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	i64 a, b; scanf("%lld%lld", &a, &b);

	int ans = 1;
	i64 g = std::__gcd(a, b);
	if(g == 1) {
		printf("1\n");
		return 0;
	}
	for(i64 i = 2; i * i <= g; i++) {
		if(g % i) continue;

		while(!(g % i)) g /= i;
		ans++;
	}
	if(g != 1) ans++;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        char c[] = s.toCharArray();
        int a = 0;
        int b = 0;
        for (int i = 0; i < s.length(); i++) {
            if (c[i] == 'A') {
                a = i + 1;
                break;
            }
        }
        for (int i = s.length() - 1; i >= 0; i--) {
            if (c[i] == 'Z') {
                b = i + 1;
                break;
            }
        }
        System.out.println(b - a + 1);
    }
}

Measured memory_bytes: 26808
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7,INF=1e18;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    // cin>>t;
    while(t--)
    {
        int n,k,ans=0;
        cin>>n>>k;
        vector<int> a(10,0);
        for(int i=0;i<k;i++)
        {
            int d;
            cin>>d;
            a[d]=1;
        }
        for(int i=n;i<=100000;i++)
        if(i>=n)
        {
            int x=i,flag=0;
            while(x)
            {
                int p=x%10;
                if(a[p])
                {
                    flag=1;
                }
                x/=10;
            }
            if(flag==0)
            {
                ans=i;
                break;
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
 
int main() {
    int N, D;
    double X;
    cin >> N >> D;
    X = (double)N/(2*D+1) ;
    cout << ceil(X) << endl;
}

Measured memory_bytes: 256
/*
Author: CNYALI_LK
LANG: C++
PROG: e.cpp
Mail: cnyalilk@vip.qq.com
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %lld\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %lld\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
using namespace std;
const double eps=1e-8;
const double pi=acos(-1.0);
typedef long long ll;
typedef pair<ll,ll> pii;
template<class T>ll chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>ll chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
template<class T>ll dcmp(T a,T b){return a>b;}
template<ll *a>ll cmp_a(ll x,ll y){return a[x]<a[y];}
#define min mmin
#define max mmax
#define abs aabs
ll read(){
	ll s=0;
	ll base=0;
	char c;
	while(!isdigit(c=getchar()))if(c=='-')base=1;
	while(isdigit(c)){s=s*10+(c^48);c=getchar();}
	if(base)s=-s;
	return s;
}
ll x[200005],y[200005];
ll f[4005][4005],fac[8005],inv[8005],invf[8005];
const ll p=1000000007,t=2001;
int main(){
#ifdef cnyali_lk
	freopen("e.in","r",stdin);
	freopen("e.out","w",stdout);
#endif
	ll n;
	fac[0]=fac[1]=inv[1]=invf[0]=invf[1]=1;
	for(ll i=2;i<=t*4;++i){
		fac[i]=fac[i-1]*i%p;
		inv[i]=(p-p/i)*inv[p%i]%p;
		invf[i]=invf[i-1]*inv[i]%p;
	}
	n=read();
	for(ll i=1;i<=n;++i){
		x[i]=read();y[i]=read();
		++f[t-x[i]][t-y[i]];
	}
	for(ll i=1;i<=t*2;++i)for(ll j=1;j<=t*2;++j)f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%p;
	ll cnt=0;
	for(ll i=1;i<=n;++i)cnt=(cnt+f[t+x[i]][t+y[i]]-fac[x[i]*2+y[i]*2]*invf[x[i]*2]%p*invf[y[i]*2]%p+p)%p;
	printf("%lld\n",cnt*((p+1)>>1)%p);
	return 0;
}



Measured memory_bytes: 128896
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] H = new int[N];
		int a = 0;
		for(int i=0; i<N; i++) {
			H[i] = sc.nextInt();
		}
		sc.close();
		int b = 0;
		for(int i=0; i<N; i++) {
			if(b<=H[i]) {
				a++;
				b = H[i];
			}
		}
		System.out.println(a);

	}

}

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


int n;

int brute(int * arr, int * barr, int h, int dp[]){
	// cout<< h<< endl;
	if(h <= 0){
		return 0;
	}
	if(dp[h] != -1){
		return dp[h];
		
	}
	
	int first = INT_MAX;
	for(int i = 0; i < n; i++){
		first = min(first, barr[i] + brute(arr, barr, h - arr[i], dp));
	}
	dp[h] = first;
	return first;
}

int main() {
	int h;
	cin >> h>>n;
	int arr[n], barr[n];
	int dp[h + 1];
	memset(dp, -1, sizeof(dp));

	for(int i = 0; i < n; i++){
		cin >> arr[i]>> barr[i];
	}
	cout << brute(arr, barr, h, dp);
	// for(int i = 0; i<=h; i++){
	// 	cout << dp[i] << " ";
	// }
	// your code goes here
	return 0;
}

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

int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin>>n;
	long long a[5] = {0};
	for(int i = 0; i < n; i++)
	{
		string t;
		cin>>t;
		
		if(t[0] == 'M') a[0]++;
		if(t[0] == 'A') a[1]++;
		if(t[0] == 'R') a[2]++;
		if(t[0] == 'C') a[3]++;
		if(t[0] == 'H') a[4]++;
	}
	
	long long ans = 0;
	
	for(int i = 0; i < 5; i++)
	{
		for(int j = i+1; j < 5; j++)
		{
			for(int k = j+1; k < 5; k++)
			{
				ans += a[i]*a[j]*a[k];
			}
		}
	}
	
	cout<<ans<<endl;

	return 0;
}

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


using namespace std;

int64_t N, M;
vector<int64_t> A;

bool chk(int64_t x) {
	int64_t cnt = 0;
	for (int i = 0; i < N; i++) {
		int64_t pos = lower_bound(A.begin(), A.end(), x - A[i]) - A.begin();
		cnt += (N - pos);
	}
	return cnt < M;//X以上の和がM個未満かどうか
}

int main() {


	
	cin >> N >> M;
	A.resize(N);

	for (int64_t i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());

	int64_t ng = 0, ok = 9223372036854775807;

	while (abs(ok - ng) > 1) {
		int64_t mid = (ok + ng) / 2;
		if (chk(mid)) ok = mid;
		else ng = mid;
	}
	//終了時にngにX-1,okにXが入っている。

	int64_t ans = 0;
	vector<int64_t> wa(N + 1); //Aの累積和
	for (int i = 0; i < N; i++) wa[i + 1] = wa[i] + A[i];
	for (int i = 0; i < N; i++) {
		int64_t pos = upper_bound(A.begin(), A.end(), ng - A[i]) - A.begin();
		int64_t cnt = N - pos;
		ans += cnt * A[i] + (wa[N] - wa[pos]);
		M -= cnt;
	}
	ans += M * ng;
	cout << ans << endl;
}





Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	static int N;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		int top = 100010;
		int[] dp = new int[top]; //余裕をもって10プラス
		dp[0] = 0;
		
		for (int i = 1; i < top; i++) {
			int wkN = 1;
			dp[i] = Integer.MAX_VALUE;
			while (wkN <= i) {
				dp[i] = Math.min(dp[i], dp[i - wkN]+1);
				wkN *= 6;
			}
			wkN = 1;
			while (wkN <= i) {
				dp[i] = Math.min(dp[i], dp[i - wkN]+1);
				wkN *= 9;
			}
		}
		System.out.println(dp[N]);
		
	}
}

Measured memory_bytes: 23252
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cmath>		
#include <stdio.h>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int (i) = 0; (i) < int(n); i++)
#define mod 1000000007
#define fst first
#define pb push_back

int deg[60];

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		deg[a - 1]++;
		deg[b - 1]++;
	}
	for (int i = 0; i < n; i++) {
		cout << deg[i] << endl;
	}
}

Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,A,B = MI()
    S=ST()
    C=A+B
    for s in S:
        if s=="a":
            if C:
                print("Yes")
                C-=1
            else:
                print("No")
        elif s=="b":
            if C and B:
                print("Yes")
                C-=1
                B-=1
            else:
                print("No")
        else:
            print("No")
if __name__ == '__main__':
    main()

Measured memory_bytes: 7340
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        long mod = 1000000007L;
        long sum = 0;
        long[] times = new long[k + 1];
        for (int gcd = k; gcd >= 1; --gcd) {
            long currentTimes = pow(k/gcd, n, mod);
            for (int i = 2 * gcd; i <= k; i += gcd) {
                currentTimes = (currentTimes - times[i] + mod) % mod;
            }
            times[gcd] = currentTimes;
            sum += gcd * currentTimes % mod;
            sum %= mod;
        }
        System.out.println(sum);

    }

    public static long pow(long base, long exp, long mod) {
        if (exp == 0) {
            return 1;
        }
        long half = pow(base, exp / 2, mod);
        if (exp % 2 == 0) {
            return half * half % mod;
        } else {
            return ((half * half % mod) * base % mod) % mod;
        }
    }
}


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

#define EPS (1e-10)

class Point{
public:
  double x,y;
  
  Point(double x = 0, double y = 0): x(x),y(y){}
 
  Point operator + (Point p){
    return Point( x+p.x , y+p.y );
  }
  Point operator - (Point p){
    return Point( x-p.x , y-p.y );
  }
  Point operator * (double a){
    return Point( a*x , a*y );
  }
 
  double abs(){
    return sqrt(norm());
  }
  double norm(){
    return x*x+y*y;
  }
};
 
double dot(Point a,Point b){
  return a.x*b.x + a.y*b.y;
}
 
double cross(Point a,Point b){
  return a.x*b.y - b.x*a.y;
}
 
int ccw( Point p0 , Point p1 , Point p2 ){
  Point a = p1 - p0;
  Point b = p2 - p0;
  if( cross(a,b) > EPS ) return 1;
  if( cross(a,b) < -EPS ) return -1;
  if( dot(a,b) < -EPS ) return 2;
  if( a.norm() < b.norm() ) return -2;
  return 0;
}

int main(){
  Point p0,p1,p2;
  int n;

  cin >> p0.x >> p0.y >> p1.x >> p1.y;
  cin >> n;
  for(int i = 0 ; i < n ; i++){
    cin >> p2.x >> p2.y;

    switch(ccw(p0,p1,p2)){
    case 1:
      cout << "COUNTER_CLOCKWISE" << endl;
      break;
    case -1:
      cout << "CLOCKWISE" << endl;
      break;
    case 2:
      cout << "ONLINE_BACK" << endl;
      break;
    case -2:
      cout << "ONLINE_FRONT" << endl;
      break;
    default:
      cout << "ON_SEGMENT" << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    ll k,d,x;
    cin >> x >> k >> d;
    x = abs(x);
    ll l = (x+d+1)/d;
    if(k < l) {
        cout << abs(x-k*d) << endl;
        return 0;
    }
    ll rem = k - l;
    if(rem%2 == 0) {
        cout << abs(x-l*d) << endl;
    } else {
        cout << abs(x-(l-1)*d) << endl;
    }
}


Measured memory_bytes: 3648
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    int x=abs(c-a);
    int y=abs(d-b);
    string s;
    if(a<c){
        if(b<d){
            rep(i,x)s+='R';rep(i,y)s+='U';
            rep(i,x)s+='L';rep(i,y)s+='D';
            s+='D';
            rep(i,x+1)s+='R';rep(i,y+1)s+='U';
            s+='L';s+='U';
            rep(i,x+1)s+='L';rep(i,y+1)s+='D';
            s+='R';
        }
        else{
            rep(i,x)s+='R';rep(i,y)s+='D';
            rep(i,x)s+='L';rep(i,y)s+='U';
            s+='U';
            rep(i,x+1)s+='R';rep(i,y+1)s+='D';
            s+='L';s+='D';
            rep(i,x+1)s+='L';rep(i,y+1)s+='U';
            s+='R';
        }
    }
    else{
        if(b<d){
            rep(i,x)s+='L';rep(i,y)s+='U';
            rep(i,x)s+='R';rep(i,y)s+='D';
            s+='D';
            rep(i,x+1)s+='L';rep(i,y+1)s+='U';
            s+='R';s+='U';
            rep(i,x+1)s+='R';rep(i,y+1)s+='D';
            s+='L';
        }
        else{
            rep(i,x)s+='L';rep(i,y)s+='D';
            rep(i,x)s+='R';rep(i,y)s+='U';
            s+='U';
            rep(i,x+1)s+='L';rep(i,y+1)s+='D';
            s+='R';s+='D';
            rep(i,x+1)s+='R';rep(i,y+1)s+='U';
            s+='L';
        }
    }
    cout<<s<<endl;
}

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

template <typename T, typename P = less<>>
struct slide {
	deque<T> q;
	P p;
	int size() const { return q.size(); }
	void push(T &&x) {
		while (!q.empty() && !p(q.back(), x))
			q.pop_back();
		q.push_back(x);
	}
	template <typename ...U>
	void push(U &&...x) { push(T(x...)); }
	const T &top() const { return q.front(); }
	void pop() { q.pop_front(); }
};
int d[222222];
int main() {
	int n, k;
	cin >> n >> k;
	slide<int> s;
	slide<int, greater<>> t;
	for (int i = 0; i < n; i++)
		scanf("%d", d + i);
	for (int i = 0; i < k; i++)
		s.push(d[i]), t.push(d[i]);
	int b = s.size() == k;
	int r = 1 - b;
	for (int i = k; i < n; i++) {
		int m = s.top();
		s.push(d[i]), t.push(d[i]);
		if (s.top() == d[i - k])
			s.pop();
		if (t.top() == d[i - k])
			t.pop();
		if (s.size() == k)
			b = 1;
		else if (m != d[i - k] || t.top() != d[i])
			r++;
	}
	cout << r + b << endl;
	return 0;
}


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

#define REP(i, n) for(int i=1; i<=n; i++)
using namespace std;
typedef long long ll;
const int MAX = 1100100;

int N;
ll A[MAX], P[MAX], sol;
set<ll> S;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> N;
	REP(I, N){
		cin >> A[I];
		P[A[I]] = I;
	}
	S.insert(0);
	S.insert(N+1);
	
	REP(I, N){
		set<ll>::iterator it2 = S.upper_bound(P[I]);
		set<ll>::iterator it1 = it2; it1--;
		
		ll lo = *it1;
		ll hi = *it2;
		
		ll lft = P[I] - lo;
		ll rgt = hi - P[I];
		
		sol += I*lft*rgt;
		
		S.insert(P[I]);
	}
	cout << sol << endl;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int n,k;
  cin >> n >> k;
  vi x(n);
  REP(i,n) cin >> x[i];
  int ans=0;
  REP(i,n) {
    ans+=min(abs(x[i]-k),x[i])*2;
  }
  cout <<ans << endl;
  return 0;
}


Measured memory_bytes: 3548
n=int(input())
ta=0
xa=0
ya=0
for i in range(n):
    t,x,y=map(int,input().split())
    if (x-xa)+(y-ya)>(t-ta) or (x+y+t)%2:
        print("No")
        exit()
    else:
        ta=t
        xa=x
        ya=y
print("Yes")

Measured memory_bytes: 3060
S = input()
T = input()
if len(S) < len(T):
    print('UNRESTORABLE')
    exit()

for i in range(len(S)-len(T)+1)[::-1]:
    for j in range(len(T)):
        # print(S[:i], len(S), len(T), S[i+j])
        if S[i+j] != T[j] and S[i+j] != '?':
            break
    else:
        S = S[:i] + T + S[i+len(T):]
        S = S.replace('?', 'a')
        print(S)
        break
else:
    print('UNRESTORABLE')

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Wed Aug 26 18:57:13 JST 2020
 **/

template <class T, class S> T make_vec(S x) { return x; }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

template <char margin = 'A', int char_size = 26> struct Trie {
    struct TrieNode {
        std::array<int, char_size> node;
        TrieNode() { node.fill(-1); };
        typename std::array<int, char_size>::iterator begin() { return node.begin(); }
        typename std::array<int, char_size>::iterator end() { return node.end(); }
        int& operator[](int i) { return node[i]; }
    };
    std::vector<TrieNode> tree;
    std::vector<int> num;  // 部分木内の個数
    Trie() : tree(1), num(1) {}
    void insert(const std::string& s) {
        num[0]++;
        int t = 0;
        for (char c : s) {
            int d = c - margin;
            if (tree[t][d] == -1) {
                tree[t][d] = tree.size();
                tree.emplace_back();
                num.push_back(0);
            }
            t = tree[t][d];
            num[t]++;
        }
    }
    void erase(const std::string& s) {
        int par = 0;
        num[par]--;
        for (char c : s) {
            int d = c - margin;
            int nxt = tree[par][d];
            assert(nxt != -1 && "s does not exist");
            if (--num[nxt] == 0) tree[par][d] = -1;
            par = nxt;
        }
    }
};

signed main() {
    Int n;
    std::cin >> n;
    std::vector<std::string> ss(n);
    REP(i, n) std::cin >> ss[i], std::reverse(ALL(ss[i]));
    std::sort(ALL(ss), [&](std::string a, std::string b) { return a.size() < b.size(); });

    Int ans = 0;
    Trie<> t;
    auto num = make_vec<Int>(1, 26, 0);
    for (const std::string& s : ss) {
        std::vector<Int> cnt(26);
        for (char c : s) cnt[c - 'a']++;
        Int idx = 0;
        REP(i, s.size() - 1) {
            REP(c, 26) { ans += num[idx][c] && cnt[c] > 0; }
            Int c = s[i] - 'a';
            cnt[c]--;
            if (t.tree[idx][c] == -1) {
                t.tree[idx][c] = t.tree.size();
                t.tree.emplace_back();
                num.emplace_back(26);
            }
            idx = t.tree[idx][c];
        }
        num[idx][s.back() - 'a']++;
    }
    std::cout << ans << std::endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, W, H;
    cin >> n >> W >> H;
    int y[H + 1] = {};
    int x[W + 1] = {};
    rep(i, n) {
        int X, Y, w;
        cin >> X >> Y >> w;
        y[max(0LL, Y - w)]++;
        y[min(Y + w, H)]--;
        x[max(0LL, X - w)]++;
        x[min(X + w, W)]--;
    }
    rep(i, H) y[i + 1] += y[i];
    rep(i, W) x[i + 1] += x[i];
    bool ok1 = true;
    bool ok2 = true;
    rep(i, H) {
        if (y[i] == 0) {
            ok1 = false;
            break;
        }
    }
    rep(i, W) {
        if (x[i] == 0) {
            ok2 = false;
            break;
        }
    }
    if (ok1 || ok2) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 4772
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

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

using namespace std;

typedef long long ll;

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

  ll n, m; cin >> n >> m;
  ll ans = (n * 100 + m * 1800) * (1LL << m);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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 dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s;
    cin >> s;
    rep(i,3)cout << s[i];
}

Measured memory_bytes: 3648
dishes_time = []
dishes_time.append(int(input()))
dishes_time.append(int(input()))
dishes_time.append(int(input()))
dishes_time.append(int(input()))
dishes_time.append(int(input()))

temp = 10
index = 0
for i,dish in zip(range(len(dishes_time)),dishes_time):
    if temp > int(str(dish)[-1]) and int(str(dish)[-1])!=0:
        temp = int(str(dish)[-1])
        index = i

for i in range(len(dishes_time)):
    if index != i:
        if dishes_time[i]%10!=0:
            dishes_time[i] = (dishes_time[i]//10)*10 + 10
print(sum(dishes_time))


Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  bool ok=false;
  int cnt=0;
  while(n--)
  {
    int a,b;
    cin>>a>>b;
    if(a==b)
    {
      cnt++;
    }
    else
    {
      cnt=0;
    }
    if(cnt==3)
    {
      ok=true;
    }
  }
  if(ok)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}
  

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MOD = 1e9+7;
const ll LINF = 1e18;
const int INF = 1e9;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

int main()
{
    cin >> N >> M >> L;

    if(N>M) swap(N,M);
    if(M>L) swap(M,L);
    if(N>M) swap(N,M);

    cout << (M-N)+(L-M);
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

struct eda {
	int a;
	int b;
	long long int w;
};

int main() {
	int N, i, dp[100000], n;
	struct eda abw[100000];

	memset(dp, -1, sizeof(dp));

	scanf("%d", &N);

	if (N == 1) {
		printf("0");
		return 0;
	}

	for (i = 0; i < N - 1; i++) {
		scanf("%d %d %lld", &abw[i].a, &abw[i].b, &abw[i].w);
		abw[i].a--;
		abw[i].b--;
		abw[i].w = abw[i].w % 2;
	}

	dp[abw[0].a] = 0;
	if (abw[0].w) {
		dp[abw[0].b] = (1 + dp[abw[0].a]) % 2;
	}
	else {
		dp[abw[0].b] = dp[abw[0].a];
	}

	n = N - 2;

	while (n > 0) {
		for (i = 1; i < N - 1; i++) {
			if (dp[abw[i].a] != -1 && dp[abw[i].b] == -1) {
				if (abw[i].w) {
					dp[abw[i].b] = (1 + dp[abw[i].a]) % 2;
				}
				else {
					dp[abw[i].b] = dp[abw[i].a];
				}
				n--;
			}
			else if (dp[abw[i].a] == -1 && dp[abw[i].b] != -1) {
				if (abw[i].w) {
					dp[abw[i].a] = (1 + dp[abw[i].b]) % 2;
				}
				else {
					dp[abw[i].a] = dp[abw[i].b];
				}
				n--;
			}
		}
	}

	for (i = 0; i < N; i++) {
		printf("%d\n", dp[i]);
	}

	return 0;
}

Measured memory_bytes: 2304
while 1:
	n, m = map(int, raw_input().split(" "))
	if (n,m) == (0,0):
		break
	tarou = [int(raw_input()) for i in range(n)]
	t_total = sum(tarou)
	hanako = [int(raw_input()) for i in range(m)]
	h_total = sum(hanako)
	pair = (101,101)
	for t in tarou :
		for h in hanako:
			if t_total - t + h == h_total - h + t:
				if t + h <= sum(pair):
					pair = (t,h)
	if pair == (101,101):
		print -1
	else :
		print pair[0], pair[1]

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

int main() {
    string s;
    int n;
    int b = 0;
    int w = 0;
    
    cin >> s;
    n = s.length();
    
    for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
            b += ((i % 2) ? 0 : 1);
            w += ((i % 2) ? 1 : 0);
        }
        else {
            b += ((i % 2) ? 1 : 0);
            w += ((i % 2) ? 0 : 1);
        }
    }
    
    cout << min(b, w) << endl;
    return 0;
}

Measured memory_bytes: 512
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
 
ll power(ll x, ll y); 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitcount(n) __builtin_popcountll(n)
#define in_edges(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_dedges(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B);}
#define in_wedges(M) repp(I, 1, M){int A, B, C; cin >> A >> B >> C; v[A].pb(B, C), v[B].pb(A, C);}
#define in_dwedges(M) repp(I, 1, M){int A, B, C; cin >> A >> B >> C; v[A].pb(B, C);}
#define endl "\n"

const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 18;
const int inf = 2e9;

const int N = 2e5 + 5;
int a[N], b[N];
int A[N], B[N];
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    quickio
    int n;
    cin >> n;
    repp(i, 1, n) cin >> a[i];
    repp(i, 1, n) cin >> b[i];

    repp(i, 1, n) A[a[i]]++, B[b[i]]++;
    repp(i, 1, n) if(A[i] + B[i] > n){
        cout << "No\n";
        return 0;
    }

    cout << "Yes\n";
    rep(i, 1, N) A[i] += A[i - 1], B[i] += B[i - 1];
    int mx = 0;
    repp(i, 1, N) mx = max(mx, A[i] - B[i - 1]);
    repp(i, 1, n) cout << b[(i - mx + n - 1) % n + 1] << " ";
}

ll power(ll x, ll y){ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

Measured memory_bytes: 6728
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
static const int giga = pow(10,9);

int main(void){
  int a,b,x;
  cin >> x >> a >> b;
  if(b-a <= 0){
    cout << "delicious" << endl;
  } else if(b-a <= x){
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
const ll mod = 1e9 + 7;
int main()
{
	SPEED
	ll s;
	cin >> s;

	vector<ll> dp(s+10);
	if(s<3)
	{
		cout << 0;
		return 0;
	}

	dp[0] = 1;

	for (ll sum = 3; sum <= s; ++sum)
	{
		for (ll coins = 3; coins <= sum; ++coins)
		{
			dp[sum] += dp[sum-coins];
			dp[sum] %= mod;
		}
	}

	// for (int i = 0; i < s+1; ++i)
	// {
	// 	cout << dp[i] << " ";
	// }
	cout << (dp[s])%mod;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string s;
    int num[101] = {0};
    int min = 1001;

    cin >> s;

    for (int i = 0; i <= (int)s.size() - 3; i++) {
        string t;
        t = s.substr(i, 3);
        if (min > abs(753 - stoi(t))) {
            min = abs(753 - stoi(t));
        }
    }

    cout << min << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <utility>
#include <queue>
#include <tuple>
//#include <boost/optional.hpp>
//using boost::optional;
//auto const none = boost::none;

struct None {} none;
template<class T> struct optional {
  bool b; T t;
  optional() : b(false), t() {}
  optional(None rhs) : b(false), t() { (void)rhs; }
  optional(T t) : b(true), t(t) {}
  explicit operator bool() const { return b; }
  T& operator*() { return t; }
  auto& operator=(None rhs) { (void)rhs; b=false; return *this; }
  auto& operator=(T const& rhs) { b=true; t = rhs; return *this; }
};



// unweighted graph
struct Graph {
  using size_t = std::size_t;
  size_t n; std::vector<std::vector<size_t>> dat;
  Graph() {}
  Graph(size_t n) : n(n), dat(n) {}
  auto& operator[](size_t i) { return dat[i]; }
  auto begin() { return dat.begin(); }
  auto end() { return dat.end(); }
  void de(size_t i, size_t j) { dat[i].push_back(j); }
  void e(size_t i, size_t j) { de(i, j); de(j, i); }
};

// adjacency list (weighted graph)
template<class T> struct GraphL {
  using size_t = std::size_t;
  struct E {
    size_t to; T w;
    E(size_t to) : to(to), w() {}
    E(size_t to, T w) : to(to), w(w) {}
  };
  size_t n; std::vector<std::vector<E>> dat;
  GraphL() {}
  GraphL(size_t n) : n(n), dat(n) {}
  auto& operator[](size_t i) { return dat[i]; }
  auto begin() { return dat.begin(); }
  auto end() { return dat.end(); }
  size_t size() const { return n; }
  void de(size_t i, size_t j, T t) { dat[i].push_back(E(j, t)); }
  void e(size_t i, size_t j, T t) { de(i, j, t); de(j, i, t); }
};

template<class U, class T, class F=std::plus<>> auto dijkstra(GraphL<T> g, std::size_t s, U u, F f=F()) {
  using pr = std::pair<U, std::size_t>;
  std::vector<optional<U>> r(g.size());
  std::priority_queue<pr, std::vector<pr>, std::greater<>> que;
  que.emplace(*(r[s]=u), s);
  while(!que.empty()) {
    U w; std::size_t v; std::tie(w, v) = que.top(); que.pop();
    if(r[v] && *r[v] < w) continue;
    for(auto const& e : g[v]) {
      U nw = f(w, e.w);
      if(!r[e.to] || nw < *r[e.to]) que.emplace(*(r[e.to]=nw), e.to);
    }
  }
  return r;
}



#include <iostream>

void GRL_1_A() {
  using namespace std;
  size_t N, M, r;
  cin >> N >> M >> r;
  GraphL<long long> g(N);
  for(size_t i=0;i<M;++i) {
    size_t s, t; long long d;
    cin >> s >> t >> d;
    g.de(s, t, d);
  }
  auto d = dijkstra(g, r, 0LL);
  for(auto& r : d) if(r) cout << *r << '\n'; else cout << "INF\n";
}

signed main() {

  GRL_1_A();

  return 0;
}



Measured memory_bytes: 31580
#include<bits/stdc++.h>
#define ll long long
#define inf 9999999999999999
#define F first
#define S second
#define eb emplace_back
#define mpp make_pair
#define P(x) cout<<__LINE__ <<": "<<#x<<' '<<(x)<<'\n'
#define dbg cout<<__LINE__ <<": 0manush\n"
#define read(x) freopen("input.txt","r",stdin)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pi 2*acos(0.0)
#define ee exp(1)
#define mx 100009
#define mod 10000007
using namespace std;
ll dp[mx];
int main(){//read(x);
//fast;
ll r,g,h,i,j,x,t,y,z=0,e,f,a,b,c,d,n,l,k;

    cin>>n;
    ll m[n];
    for(i=0;i<n;i++)cin>>m[i];
    dp[n-1]=0;
    dp[n-2]=abs(m[n-1]-m[n-2]);
    for(i=n-3;i>=0;i--){
        a=dp[i+1]+abs(m[i]-m[i+1]);
        b=dp[i+2]+abs(m[i]-m[i+2]);
        dp[i]=min(a,b);
    }
    //cout<<"Case "<<++z<<": ";
    cout<<dp[0]<<endl;

}





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

// dp[day][activity]
int dp[100001][3];

int main() {
	int n;
	cin >> n;
	vector<int> a(n, 0), b(n, 0), c(n, 0);

	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}

	//BaseCases
	dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0];

	for (int i = 1; i < n; i++) {
		dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
	}

	cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl;
	return 0;

}

Measured memory_bytes: 5612
main() {
	unsigned long long d, n, m;
	double t;
	scanf("%llu%llu%llu", &n, &m, &d);
	if (d == 0)
		t = 1.0 * ((double)m - 1.0) / (double)n;
	else
		t = 2.0 * ((double)m - 1.0) * (1.0 - ((double)d / n)) / n;
	printf("%.10lf", t);
}

Measured memory_bytes: 128