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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/

int main(void){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  a = max(a, c);
  b = min(b, d);
  if (b-a<0) cout << 0 << endl;
  else cout << b-a<< endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vll vector<ll>
#define vi vector<int>
#define vvll vector<vll>
#define wh(t) while(t--)
#define fi(n) for(ll i = 0; i < n; i++)
#define fj(n) for(ll j = 0; j < n; j++)
#define fu(i,s,e) for(ll i = s; i <=e; i++)
#define fd(i,s,e) for(ll i = s; i >=e; i--)
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define fr first
#define se second
#define sll stack<ll>
#define qll queue<ll>
using namespace std;
const ll M = 1e9+7;
//const ll M = 998244353;

ll pmp(ll x,ll n){ll a = 1;while(n > 0){if(n & 1) a = (a * x)%M;x = (x * x)%M;n = n>>1;}return a;}

void solve(){
	ll h,w,k;
	cin >> h >> w >> k;
	vvll a(h,vll(w,0));
	ll x = 0;
	fi(h){
		string s;cin >> s;
		fj(w) if(s[j]=='#') {a[i][j]=1;x++;}
	}
	ll ans =0;
	fi(1<<h){
		fj(1<<w){
			vvll v(h,vll(w,0));
			ll f = 0;
			fu(r,0,h-1){
				if(i&(1<<r)){
					fj(w){
						f+=((1-v[r][j])*a[r][j]);
						v[r][j] = 1;
					}
				}
			}
			fu(c,0,w-1){
				if(j&(1<<c)){
					fi(h){
						f+=((1-v[i][c])*a[i][c]);
						v[i][c]=1;
					}
				}
			}
			if(f==x-k) {ans++;}
		}
	}
	cout << ans;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	#endif
	ll t;
	t = 1;
	// cin >> t;
	wh(t){
		solve();
	}
	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 3788
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<ll, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
ll pow_mod(ll a, ll b, ll mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  ll x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

//非再帰抽象セグ木 0-indexed 単位元はiで指定
template <class T>
class SegmentTree {
 private:
  long long n;
  T init;
  std::vector<T> dat;
  std::function<T(T, T)> fn;

 public:
  SegmentTree(long long i, T para, std::function<T(T, T)> fun)
      : init(para), fn(fun) {
    n = 1;
    while (n < i) {
      n *= 2;
    }
    dat = std::vector<T>(2 * n - 1, init);
  }

  // k番目(0-indexed)を値aで更新,dest=trueのときは更新前を破壊して初期化する
  void update(long long k, T a, bool dest) {
    k += n - 1;
    if (dest)
      dat[k] = a;
    else
      dat[k] = fn(dat[k], a);

    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = fn(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  T query(long long a, long long b){
    assert(0<=a&&b<=n);
    T val=init;

    long long l=a+n-1,r=b+n-1;
    for(;l<r;l=(l>>1),r=(r>>1)){
      if(!(r&1)){
        r--;
        val=fn(val,dat[r]);
      }
      if(!(l&1)){
        val=fn(val,dat[l]);
        l++;
      }
    }

    return val;
  }
};

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

  ll n;
  std::cin>>n;

  std::vector<ll> a(n);
  rep(i,0,n)std::cin>>a[i];

  std::vector<ll> left(n),right(n);

  SegmentTree<ll> leftmax(n+10,-1,[](ll a,ll b){return std::max(a,b);}),rightmin(n+10,n,[](ll a,ll b){return std::min(a,b);});

  rep(i,0,n){
    left[i]=leftmax.query(0,a[i]);
    leftmax.update(a[i],i,true);
  }

  for(ll i=n-1;i>=0;i--){
    right[i]=rightmin.query(0,a[i]);
    rightmin.update(a[i],i,true);
  }

  ll ans=0;

  rep(i,0,n){
    ans+=(i-left[i])*(right[i]-i)*a[i];
  }

  std::cout<<ans;

  return 0;
}

Measured memory_bytes: 13184
import itertools
import math
import fractions
import functools
n = int(input())

maximum = math.ceil(math.sqrt(n))
minimum = 10**20
for i in range(1,maximum+1):
    j = 0
    if n % i == 0:
        j = n / i
        minimum = min(minimum,i+j)

print(int(minimum-2))

Measured memory_bytes: 73004
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  dead_code
)]
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
//use std::num;
//use petgraph::unionfind::UnionFind;
//use permutohedron::LexicalPermutation as _;

const MOD: i64 = 1000_000_007;
//#[fastout()]
fn main() {
  input! {
      N:usize,
      A:[i64;N]
  }
  let A: Vec<i64> = A;
  let mut ans = 0i64;
  let mut tmp = A[0];
  let mut S = vec![0; N + 1];
  for i in (1..N).rev() {
    S[i] = (S[i + 1] + A[i]) % MOD;
  }
  for i in 0..(N - 1) {
    ans += (A[i] * S[i + 1]) % MOD;
    ans %= MOD;
  }
  println!("{}", ans);
}


Measured memory_bytes: 7204
// list(map(int, input().rstrip().split()))
//' '.join(map(str, res)) 

#include<bits/stdc++.h>
#include<stdio.h> //per fare input output con scanf and printf
#include<stdlib.h> //per fare qsort e bsearch
#include<string.h> // per fare strcpy(sarrivo, spartenza) strcat(str, aggiungo) strcmp(a,b) che da 0 se sono uguali
#include<math.h>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<map>
 
using namespace std;
 
#define ld long double
#define ll long long int
#define vi vector <ll> 
#define pi pair <int, int>
#define binary(v, el) binary_search((v).begin(), (v).end(), (el))
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define G(n, t) get<(n)>((t)) // get element of a tuple
#define F first
#define S second
#define input(type, n) type n; cin >> n
#define FORN(n) for (ll i=0;i<(n); i++)
#define print(x) cout << x << endl
#include <iomanip>      // std::setprecision



/*struct missione {
        int s;
        int g;
    };
missione v[1000000];
 
bool Ordina (missione a, missione b) {
    return a.s < b.s;    
}*/

ll powermodp(ll x, ll y, ll p){
   // x^y mod p
   if (y==0) return 1;
   ll a = powermodp(x, y/2, p) % p;
   a = (a*a) % p;
   if (y%2) return (a*x)%p;
   return a;
}

ll inverse(ll a, ll p){
   if (a%p == 0) return 0;
   else return powermodp(a, p-2, p);
}

ll fatt (ll n, ll p) {
    ll res = 1;
    for (ll i = 1; i < n+1; ++i) {
        res *= i;
        res = res % p;
    }
    return res;
}

ll bin (ll n, ll k, ll p) {
    ll res = (fatt(n,p) % p) * inverse((fatt(n-k,p) * fatt(k,p)) % p, p);
    res = res % p;
    return res;
}

int main () {
    ll N,K;
    cin >> N >> K;
    ll p = 1000000007;
    for (ll i = 1; i < K+1; ++i) {
        if (N - K - (i-1) >= 0) {
            ll res = (bin(K-1,i-1,p) % p) * (bin(N-K+1,i,p) % p);
            res = res % p;
            if (res < 0) {
                res = p - res;
            }
            cout << res << endl;
        } else {
            cout << 0 << endl;
        }    
    }
}

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

using namespace std;

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #endif // LOCAL_EXEC
    long long int n,i,j,k,x,y,z;
    cin>>n;
    double p[n+1],dp[n+1][n+1];
    for(i=1;i<=n;i++){
        cin>>p[i];
    }
    for(i=0;i<=n;i++){
        dp[0][i]=0;
    }
    dp[0][0]=1;
    double sum=0;
    for(i=1;i<=n;i++){
        for(j=0;j<=n;j++){
            if(j<i)
            dp[i][j]=dp[i-1][j]*(1-p[i]);
            else if(j>=i)
                dp[i][j]=0;
            if(j>0)
                dp[i][j]+=dp[i-1][j-1]*p[i];
        }
    }
    for(j=n/2+1;j<=n;j++){
        sum+=dp[n][j];
    }
    printf("%.9f",sum);
    return 0;
}


Measured memory_bytes: 74112
import math

N,D = [int(i) for i in input().split()]
X = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    X.append(array)
ans = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for k in range(D):
            dist += (X[i][k]-X[j][k])**2
        if(math.sqrt(dist) == int(math.sqrt(dist))):
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,X;
  cin>>N>>M>>X;
  vector<int> A(M);
  vector<int> cnt(1000);
  for(int i=0;i<M;i++){
    cin>>A.at(i);
    A.at(i)--;
    cnt.at(A.at(i))=1;
  }
  int cost1 = 0;
  for(int i=0;i<X;i++){
    cost1+=cnt.at(i);
  }
  int cost2 = 0;
  for(int i=X;i<N;i++){
    cost2+=cnt.at(i);
  }
  int ans = min(cost1,cost2);
  cout<<ans<<endl;
  return 0;
}
    

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var hs = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        var highest = hs[0];
        var k = 1;
        for (int i = 1; i < hs.Length; i++)
        {
            if (hs[i] >= highest)
            {
                highest = hs[i];
                k++;
            }
        }

        Console.WriteLine(k);
    }
}


Measured memory_bytes: 11348
def main()->None:
    A, B, K = map(int, input().split())

    if A > K:
        print(A-K, B)
    else:
        diff = K - A
        if diff < B:
            print(0, B-diff)
        else:
            print(0, 0)





if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<cstdio>
int main()
{
	int X,A,B;
	scanf("%d%d%d",&X,&A,&B);
	if(B<=A)
	{
		printf("delicious\n");
	}
	else if(B>A+X)
	{
		printf("dangerous\n");
	}
	else printf("safe\n");
	return 0; 
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long int a[100][100001];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    long long int n,w,i,j;
    cin>>n>>w;
    long long int b[n],c[n];
    for(i=0;i<n;i++)
    {
        cin>>b[i]>>c[i];
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<=w;j++)
        {
            a[i][j]=0;
        }
    }
    for(i=0;i<n;i++)
    {
        for(j=1;j<=w;j++)
        {
            if(i==0)
            {
                if(b[i]<=j)
                {
                    a[i][j]=c[i];
                }
                else
                {
                    a[i][j]=0;
                }
            }
            else
            {
                if(b[i]>j)
                {
                    a[i][j]=a[i-1][j];
                }
                else
                {
                    a[i][j]=max(a[i-1][j],c[i]+a[i-1][j-b[i]]);
                }
            }
        }
    }
    cout<<a[n-1][w];
    return 0;
}




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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const ll INF = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int N;
vector<ll> W;

//  dp[i][j] := ??¨?????¨[i, j]????????????????????????????°?
//  dp[i][j] = min(dp[i][k] + dp[k+1][j] + w[i][j])
// sum[i][j] = w_i + ... + w_j
ll dp[4010][4010];
ll p[4010][4010];
ll sum[4010];

ll cost(int i, int j)
{
    return sum[j+1] - sum[i];
}

int main()
{
    cin >> N;
    W.resize(N);
    rep(i, N) cin >> W[i];
    
    sum[0] = 0LL;
    for (int i=0; i<N; i++) {
        sum[i+1] = sum[i] + W[i];
    }

    rep(i, N) rep(j, N) dp[i][j] = (i == j ? 0LL : INF);
    rep(i, N) p[i][i] = i;

    REP(l, 1, N) {
        rep(i, N-l) {
            int j = i + l;
            int k0 = p[i][j-1], k1 = p[i+1][j];
            REP(k, k0, k1 + 1) {
                ll tmp = dp[i][k] + dp[k+1][j] + cost(i, j);
                if (tmp < dp[i][j]) {
                    dp[i][j] = tmp;
                    p[i][j] = k;
                }
            }
        }
    }

   cout << dp[0][N-1] << endl;
}

Measured memory_bytes: 205936
#include<iostream>

using namespace std;

int main(){
  int N ; cin >> N;
  bool flag = false;
  for(int x = 0; x <= 25; x++){
    for(int y = 0; y <= 14; y++){
      if( 4 * x + 7 * y == N){flag = true;}}}
  if(flag){cout << "Yes" << endl;}
  else{cout << "No"<< endl;}
  
  return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

ll y[10000005];

int main() {
    int D; cin >> D;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    int s[D][26];
    rep(i,D) rep(j,26) cin >> s[i][j];
  rep(i,D) cout << 1 << endl;
}


Measured memory_bytes: 3656
#include<iostream>
using namespace std; 
int main()
{
  string a;
  int i,x,Ans;
  cin >> a;
  long long A=stoll(a);
  if(A<10)Ans=A;
  else {
    for(i=0;i<a.size();i++){
      x+=a[i]-48;
    }
    if(a[0]-49+(a.size()-1)*9<x)Ans=x;
    else Ans=a[0]-49+(a.size()-1)*9;
  }
    printf("%d",Ans);
}

Measured memory_bytes: 256
/*input 
4
-100 -100 -100 -100
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
const ld PI = 4*atan((ld)1);

int N;
vi v;
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> N;
	F0R(i, N) {
		v.pb(0); cin >> v[i];
	}

	int ans = MOD;
	FOR(i, -100, 101) {
		int tot = 0;
		F0R(j, N) {
			tot += (v[j] - i) * (v[j] - i);
		}
		ans = min(tot, ans);
	}
	cout << ans << '\n';
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

const UINT mod = 1000000007;

UINT PowMod(UINT x, UINT y)
{
	if (y == 0)
	{
		return 1;
	}
	else if (y == 1)
	{
		return x % mod;
	}
	else if (y % 2 == 0)
	{
		auto tmp = PowMod(x, y / 2);
		return tmp * tmp % mod;
	}
	else
	{
		auto tmp = PowMod(x, y / 2);
		return (tmp * tmp % mod) * x % mod;
	}
}

UINT getModInv(UINT N)
{
	return PowMod(N, mod - 2);
}

INT dp[100010][13] = {};
char s[100010];

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

	INT len = _s.length();
	for (size_t i = 1; i <= len; i++)
	{
		s[i] = _s[len - i];
	}

	INT ten13 = 1;
	dp[0][0] = 1;
	for (size_t i = 1; i <= len; i++)
	{
		if (s[i] == '?')
		{
			for (size_t j = 0; j < 13; j++)
			{
				for (size_t p = 0; p < 10; p++)
				{
					dp[i][j] += dp[i - 1][(j - ten13 * p + 130) % 13];
				}
			}
		}
		else
		{
			INT a = s[i] - '0';
			for (size_t j = 0; j < 13; j++)
			{
				dp[i][j] = dp[i - 1][(j - ten13 * a + 130) % 13];
			}
		}
		ten13 = (ten13 * 10) % 13;
		for (size_t j = 0; j < 13; j++)
		{
			dp[i][j] %= mod;
		}
	}

	cout << dp[len][5] << endl;
}


Measured memory_bytes: 10752
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> pii;
long long cnt[10];

int main() {
	long long h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	set<pii> st;
	cnt[0] = (h-2)*(w-2);
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		a--;  b--;
		for(int sh=max(0, a-2), ih=sh; ih<min(a+1LL, h-2); ih++) {
			for(int sw=max(0, b-2), iw=sw; iw<min(b+1LL, w-2); iw++) {
				int blk = 0;
				for(int ii=0; ii<3; ii++) {
					for(int ij=0; ij<3; ij++) {
						if( st.find(pii(ih+ii, iw+ij)) != st.end() ) {
							blk++;
						}
					}
				}
				cnt[blk]--;
				cnt[blk+1]++;
			}
		}
		st.insert(pii(a,b));
	}
	rep(i,10) {
		cout << cnt[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>

using namespace std;

int main(void) {
    int64_t A, B, K;
    cin >> A >> B >> K;
    if(A >= K) {
        cout << A-K << " " << B << endl;
    } else {
        cout << 0 << " " << max(A+B-K, 0L) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <functional>
using namespace std;

int main(void) {
	int A, B;
	string s;
	cin >> A >> B >> s;
	if (s.length() > A + B + 1) {
		cout << "No" << endl;
		return 0;
	}
	
	for (int i = 0; i < A + B + 1;i++) {
		if (i <= A - 1) {
			if ( s[i]>'9' || s[i] <'0') {
				cout << "No" << endl;
				return 0;
			}
		}
		else if (i == A) {
			if (s[i] != '-') {
				cout << "No" << endl;
				return 0;
			}
		}
		else if (i > A) {
			if (s[i]>'9' || s[i] <'0') {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/
template<typename T=lnt>
struct RangeSum
{
	T v;
	static RangeSum I() { return RangeSum(0); }
	RangeSum(T v) : v(v) {}
	static RangeSum f(const RangeSum& lhs, const RangeSum& rhs) { return lhs+rhs; }
	operator T() const { return v; }
};

template<typename M>
struct SegmentTree
{
	const int n;
	std::vector<M> data;
	SegmentTree(int n) : n(n),data(n<<1,M::I()) {}
	M& operator[](int i) { return data[i+n]; } // pair with update/build
	void update(int i) { for(i+=n;i>1;i>>=1) data[i>>1]=M::f(data[i],data[i^1]); }
	void build() { for(int i=n-1;i>0;i--) data[i]=M::f(data[i<<1],data[i<<1|1]); }
	M fold(int l, int r) const {
		M L=M::I(),R=M::I();
		for(l+=n,r+=n;l<r;l>>=1,r>>=1) {
			if(l&1) L=M::f(data[l++],L);
			if(r&1) R=M::f(R,data[--r]);
		}
		return M::f(L,R);
	}
};


template <typename T>
std::vector<int> sort_indexes(const std::vector<T> &v) {
	std::vector<int> idx(v.size());
	std::iota(idx.begin(), idx.end(), 0);
	std::sort(idx.begin(), idx.end(), [&v](int i1, int i2) {return v[i1] < v[i2];});
	return idx;
}

int main() {
	lnt n,q;
	std::cin >> n >> q;
	std::vector<lnt> c(n);
	rep(i,n) std::cin >> c[i];
	std::vector<std::pair<lnt,lnt> > qu;
	rep(i,q) {
		lnt l,r;
		std::cin >> l >> r;
		qu.emplace_back(l-1,r);
	}
	auto idx = sort_indexes<std::pair<lnt,lnt> >(qu);
	using M=RangeSum<lnt>;
	SegmentTree<M> seg(n+1);
	std::map<lnt,std::vector<lnt> > map;
	rep(i,n) {
		map[c[i]].emplace_back(i);
		if(map[c[i]].size()==1) seg[i]=1;
	}
	seg.build();
	lnt j=0;
	std::vector<lnt> ans(q);
	rep(i,n) {
		while(j<q&&qu[idx[j]].first==i) {
			ans[idx[j]]=seg.fold(i,qu[idx[j]].second);
			j++;
		}
		// c[i] disappears
		auto ub = std::upper_bound(all(map[c[i]]),i);
		if(ub!=map[c[i]].end()) {
			seg[*ub]=1; seg.update(*ub);
		}
	}
	debug("?");
	rep(i,q) print(ans[i]);
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Combination {
    Combination(ll n) {
        mNumTbl.resize(n + 1);
        mInverseNumTbl.resize(n + 1);
        mNumTbl[0] = 1;
        mInverseNumTbl[0] = 1;
        FOR(i, n + 1, 1) {
            mNumTbl[i] = (mNumTbl[i - 1] * i) % MOD;
        }
        FOR(i, n + 1, 1) {
            mInverseNumTbl[i] = modpow(mNumTbl[i]);
        }
    }

    ll get(ll n, ll r) {
        if (n < r || n < 0)
            return 0;
        return (((mNumTbl[n] * mInverseNumTbl[r]) % MOD) * mInverseNumTbl[n - r]) % MOD;
    }

    ll modpow(ll n) {
        ll s = 1, p = n;
        for (ll i = 0; (1LL << i) <= MOD - 2; ++i, p = (p * p) % MOD) {
            if (((MOD - 2) & (1 << i)) == 0)
                continue;
            s *= p;
            s %= MOD;
        }
        return s;
    }

    vector<ll> mInverseNumTbl;
    vector<ll> mNumTbl;
};

int main() {
    ll N, K;
    cin >> N >> K;
    Combination cmb(N + 5);

    ll ans = 1;
    REP(i, std::min(N - 1, K)) {
        ll p = cmb.get(N, i + 1);//! 0になるところを選ぶ
        ll q = cmb.get(N - (i + 1) + i, i + 1);//! 残りのN-iにi+1個を振り分ける

        ans = (ans + p * q) % MOD;
    }

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

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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
//}}}


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

  int p = 0; int q = 0;
  rep(i, n){
    if (a[i]>b[i]){
      q += a[i]-b[i];
    }
    else if (a[i]<b[i]){
      p += (b[i]-a[i])/2;
      p += (b[i]-a[i])%2;
      q += (b[i]-a[i])%2;
    }
  }
  int k = accumulate(b, b+n, 0LL) - accumulate(a, a+n, 0LL);
  dump(p, q, k);

  if (k-p < 0 || k-q < 0){
    cout << "No" << endl;
  }
  else if ((k-p)*2 == (k-q)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 384
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

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

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[]){
	int n;
	int x,y;
	cin >> n;
	OUT(600 * (n / 15) + 800 * (n - n / 15)) BR;
	RET;
}


Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int M = nextInt();

		int[][] AB = new int[N][2];
		for(int i=0;i<N;i++) {
			AB[i] = nextIntArray(2);
		}
		Arrays.sort(AB,(a1,a2)->Integer.compare(a2[1],a1[1]));
		Arrays.sort(AB,(a1,a2)->Integer.compare(a1[0],a2[0]));

		List<Integer> list = new ArrayList<Integer>();
		long sum = 0;
		int AB_i = 0;
		for(int l=1;l<=M;l++) {
			int Search_l = -1;
			while(AB_i<N&&AB[AB_i][0]==l) {
				int Insert_i = Search(list ,AB[AB_i][1],Search_l);
				if(M<Insert_i)break;// 候補外となるため挿入する必要なし
				list.add(Insert_i,AB[AB_i][1]);
				AB_i++;
			}

			if(list.size()>0) {
				sum+=list.get(0);
				list.remove(0);
			}
		}

		out.println(sum);
	}

	//二部探索
	static int Search(List<Integer> list, int k, int Search_l) {
		int l = Search_l;
		int r = list.size();
		while(r - l > 1) {
			int mid = (r + l) / 2;
			if(list.get(mid) <= k) r = mid;
			else l = mid;
		}
		return r;
	}


	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

}

Measured memory_bytes: 65924
#!/usr/bin/env python3
# -*- Coding: utf-8 -*-

import sys


def main():
    X = input()
    t = 0
    s = 0

    for x in X:
        if x == 'T':
            if s == 0:
                t += 1
            else:
                s -= 1
        else:
            s += 1

    print(t+s)


if __name__ == '__main__':
    main()


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

int main(){
  int N,K;
  string S;
  cin >> N >> K;
  cin >> S;
  int X[N];
  for(int i=0;i<N;i++){
    X[i]=0;
  }
  int start=0;
  if (S[0]-'0'==0)start=1;
  int before=S[0]-'0';
  for(int i=0;i<N;i++){
    if(before!=S[i]-'0')start++;
    X[start]+=1;
    before=S[i]-'0';
  }
  /*
  for(int i=0;i<start+1;i++){
    cout << X[i] << endl;
  }
  */
  long long int max=0;
  if ((start+1)/2<=K){
    for (int i=0;i<start+1;i++) max+=X[i];
    cout << max << endl;
  }else {
    for (int i=1;i<=start-K*2+2;i+=2){
      long long int value=0;
      for(int j=i-1;j<=i+K*2-1;j++){
        value+=X[j];
      }
      if (max<value) max=value;
    }
    cout << max << endl;
  }
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int n,a,b,p;
multiset<int>s;
main(){
    cin>>n;
    while(n--)cin>>a,s.insert(a);
    while(s.size()){
        a=*s.rbegin();
        s.erase(s.find(a));
        p=1;
        while(p<=a)p*=2;
        if(s.find(p-a)!=s.end())s.erase(s.find(p-a)),b++;
    }
    cout<<b<<'\n';
}

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

int main() {
	 ios_base::sync_with_stdio(false);
	  cin.tie(NULL);
	  int n;
	  cin>>n;
	  string s = "ACL";
	  for(int i=0; i<n; i++){
	  	cout<<s;
	  }

	  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t h,w;
  cin >> h >> w;
  
  if(h==1 || w==1){
    cout << 1 << endl;
  }
  else{
  cout << ((h*w)+1)/2 << endl;
}
}


Measured memory_bytes: 256
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long
using namespace std;
#define ss second
#define ff first
int32_t main()
{
    fastio;
    int T,n,m,i,j,k,a,b,c;
    T=1;
    string str;
    while(T --> 0)
    {
        cin>>str;
        int l=str.length();
        for(i=0;i<l;i++)
        if(str[i]=='7')
            break;

        i==l? cout<<"No":cout<<"Yes";
    }
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)1e5+111;
ll const LG=(ll)log2(N)+1;


void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        
        cin>>n;

        map<string,ll> mp;
        string s;
        mp["AC"]=0;
        mp["TLE"]=0;
        mp["WA"]=0;
        mp["RE"]=0;
        for(i=0;i<n;i++){
                cin>>s;
                mp[s]++;
        }
        
        cout<<"AC x "<<mp["AC"]<<endl;
        cout<<"WA x "<<mp["WA"]<<endl;
        cout<<"TLE x "<<mp["TLE"]<<endl;
        
        cout<<"RE x "<<mp["RE"];
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
void solve(long long N, std::vector<long long> a){
  sort(all(a));
  ll ans = 0;
  for (int i = N; i < N*3; i+=2) {
    ans += a[i];
  }
  cout << ans << endl;
}

int main(){
    long long N;
	scanf("%lld",&N);
	std::vector<long long> a(3*N);
	for(int i = 0 ; i < 3*N ; i++){
		scanf("%lld",&a[i]);
	}
    solve(N, std::move(a));
}


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

signed main() {
	int n,s;
	cin>>n>>s;
	int w[n+1],v[n+1];
	for(int i=1;i<=n;i++) cin>>w[i]>>v[i];
	int dp[n+1][s+1];
	for(int i=0;i<=n;i++)
		for(int j=0;j<=s;j++)
			if(i==0 or j==0) dp[i][j]=0;
			else if(j>=w[i])
			dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
			else dp[i][j]=dp[i-1][j];
	cout<<dp[n][s];	
	return 0;
}

Measured memory_bytes: 79104
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8');
//const input = fs.readFileSync('./input.txt', 'utf8');

_a(input);

function _a(input: string) {
  const X = parseInt(input);
  console.log(X < 30 ? 'No' : 'Yes');
}


Measured memory_bytes: 29680
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;


#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

auto sumdig(ll num) {
	ll dig, sum;
	sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}

auto mdist(pair<int, int> a, pair<int, int> b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}

class four {
public:
	int a, b, c, d;
};



int main() {
	double A, B, N;
	cin >> A >> B >> N;

	ll ans;


	N = min(N, B - 1);


	ans = (ll)((A * N) / B) - A * (ll)(N / B);

	cout << ans << endl;


	return 0;
}



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

bool ok(char c) { return c == 'A' || c == 'T' || c == 'C' || c == 'G'; }

int main() {
    string s;
    cin >> s;
    int ans = 0;
    for (int start = 0; start < s.size(); start++) {
        int acc = 0;
        for (int ofst = 0; start + ofst < s.size(); ofst++) {
            if (ok(s[start + ofst])) {
                acc++;
                if (start + ofst == s.size() - 1) {
                    ans = max(ans, acc);
                }
            } else {
                ans = max(ans, acc);
                break;
            }
        }
    }
    cout << ans << endl;
}

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

void Main() {
	int n, m;
	cin >> n >> m;
	int **A = new int* [n];
	int *b = new int[m];
	long *c = new long[n];
	for (int i = 0; i < n; i++) {
		A[i] = new int[m];
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> A[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (i == 0 && j == 0) {
				c[i] = 0;
			}
			c[i] += A[i][j] * b[j];
		}
	}

	for (int i = 0; i < n; i++) {
		cout << c[i] << endl;
	}
	delete[] A, b, c;
}

int main() {
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 3140
#include <iostream>
#include <string>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

std::string S;

int main()
{
  std::cin >> S;

  int ans = 1<<30;

  int cnt = 0;
  rep( i, S.size() )
  {
    if( S[i] != (i%2)+'0' )
      ++cnt;
  }

  ans = std::min( ans, cnt );

  cnt = 0;

  rep( i, S.size() )
  {
    if( S[i] != ((i+1)%2)+'0' )
      ++cnt;
  }

  ans = std::min( ans, cnt );

  printf( "%d\n", ans );

  return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
	public static void main(String args[]){
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNext()){	
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int ans = a+b;
			if(ans<10){
				System.out.println("1");
			}
			if(ans<100 && ans>9){
				System.out.println("2");
			}
			if(ans<1000 && ans>99){
				System.out.println("3");
			}
			if(ans<10000 && ans>999){
				System.out.println("4");
			}
			if(ans<100000 && ans>9999){
				System.out.println("5");
			}
			if(ans<1000000 && ans>99999){
				System.out.println("6");
			}
			if(ans<10000000 && ans>999999){
				System.out.println("7");
			}
		}
	}

}

Measured memory_bytes: 26204
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as VU
import Data.Bool (bool)

main :: IO ()
main = do
  [a, b, q] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  ss <- (VU.fromList <$>) . sequence . replicate a $ unsafeTextToInt <$> T.getLine :: IO (VU.Vector Int)
  ts <- (VU.fromList <$>) . sequence . replicate b $ unsafeTextToInt <$> T.getLine :: IO (VU.Vector Int)
  xs <- sequence . replicate q $ unsafeTextToInt <$> T.getLine :: IO [Int]
  let
    dist :: Int -> Int
    dist x = minimum [x - min sL tL, min (x - sL) (tR - x) + (tR - sL), min (x - tL) (sR - x) + (sR - tL), max sR tR - x]
      where
        (sL, sR) = case binaryMaxIndex (< x) ss of
                     Nothing -> (-10 ^ 11, ss VU.! 0)
                     Just i  -> (ss VU.! i, bool (10 ^ 11) (ss VU.! succ i) (i < pred a))
        (tL, tR) = case binaryMaxIndex (< x) ts of
                     Nothing -> (-10 ^ 11, ts VU.! 0)
                     Just i  -> (ts VU.! i, bool (10 ^ 11) (ts VU.! succ i) (i < pred b))
  mapM_ print . map dist $ xs

binaryMaxIndex :: VU.Unbox a => (a -> Bool) -> VU.Vector a -> Maybe Int
binaryMaxIndex p = binaryMaxInt <$> ((p .) . (VU.!)) <*> (,) 0 . pred . VU.length
{-# INLINE binaryMaxIndex #-}

binaryMaxInt :: (Int -> Bool) -> (Int, Int) -> Maybe Int
binaryMaxInt p = check
  where
    check :: (Int, Int) -> Maybe Int
    check ij@(i, _) | not (p i) = Nothing
                    | otherwise = Just $ unsafeBinaryMaxInt p ij
{-# INLINE binaryMaxInt #-}

unsafeBinaryMaxInt :: (Int -> Bool) -> (Int, Int) -> Int
unsafeBinaryMaxInt p = check
  where
    check :: (Int, Int) -> Int
    check ij@(_, j) | p j       = j
                    | otherwise = search ij
    search :: (Int, Int) -> Int
    search = fst . until ((==) <$> fst <*> pred . snd) halve
      where
        halve :: (Int, Int) -> (Int, Int)
        halve (i, j) | p m       = (m, j)
                     | otherwise = (i, m)
          where
            m = (i + j) `div` 2
{-# INLINE unsafeBinaryMaxInt #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 89468
#include <bits/stdc++.h>
using namespace std;
int main(){
    long double  a,b,c;
    cin>>a>>b>>c;
    long double ans=c-a-b;
    long double ans2=2*sqrt(a*b);
    if(ans2<ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,x;
  cin >> a >> b;
  
  x = (a * b) % 2;
  
  if(x == 0){
    cout << "Even" << endl;
  }
   else{
    cout << "Odd" << endl;
  }
 
}
    

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int max, i, j, k, div, count, rest;
	int n[100];
	int x[100];

	i =0;

	while (1){
		scanf("%d %d", &n[i], &x[i]);
		if(n[i] == 0 && x[i] == 0){
			break;
		}
		i++;
	}

	i = 0;
	count = 0;

	while (1){
		if(n[i] == 0 && x[i] == 0){
			break;
		}
		max = x[i] - 3;
		if (max > n[i]){
			max = n[i];
		}
		for (j = max; j > 2; j--){
			if(j > x[i]/3){
				rest = x[i] - j;
				for(k = 1; k < (float)rest/2; k++){
					if(rest - k < j){
						count++;
					}
				}
			}
		}
		printf("%d\n", count);
		count = 0;
		i++;
	}

	return 0;
}



Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
int f,p;
string s;
map<char,int>m;
int bns1();
int g_A(){
  int r=0;
  if(s[p]=='('){
    p++;
    r=bns1();
    p++;
  }
  else{
    while(isdigit(s[p])){
      r=r*10+(s[p]-'0');
      p++;
    }
  }
  return r;
}
int bns3(){
  int res=g_A();
  if(p>=s.size())return res;
  while(m[s[p]]==3){
    int t=p++;
    if(s[t]=='+')res+=g_A();
    if(s[t]=='-')res-=g_A();
    if(s[t]=='*')res*=g_A();
  }
  return res;
}
int bns2(){
  int res=bns3();
  if(p>=s.size())return res;
  while(m[s[p]]==2){
    int t=p++;
    if(s[t]=='+')res+=bns3();
    if(s[t]=='-')res-=bns3();
    if(s[t]=='*')res*=bns3();
  }
  return res;
}
int bns1(){
  int res=bns2();
  if(p>=s.size())return res;
  while(m[s[p]]==1){
    int t=p++;
    if(s[t]=='+')res+=bns2();
    if(s[t]=='-')res-=bns2();
    if(s[t]=='*')res*=bns2();
  }
  return res;
}
int dfs(){
  int res=LLONG_MIN;
  r(i,3)r(j,3)r(k,3){
    m['+']=i+1;
    m['-']=j+1;
    m['*']=k+1;
    p=0;
    res=max(res,bns1());
  }
  return res;
}
main(){
  cin>>s;
  cout<<dfs()<<endl;
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define fo(i,n)         for(i=0;i<n;i++)
#define Fo(i,k,n)       for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x, y)      cout << #x << "=" << x << "," << #y << "=" << y << endl
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 3e5, M = N;
//=======================

vi g[N];

void solve() {
	int i, j, n, m;
	cin >> n;
	string s;
	cin >> s;
	int w = 0, r = 0;
	bool violating = 0;
	fo(i, n) {
		if (s[i] == 'R') {
			r++;
			if (w > 0)
				violating = 1;
		}
		else w++;
	}
	if (!violating) {
		cout << 0;
		return ;
	}
	int real_count = 0;
	fo(i, n - w) {
		if (s[i] == 'W')
			real_count++;
	}
	cout << real_count;
}

int32_t main()
{
	FIO;
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	solve();
	return 0;
}

void ipgraph(int n, int m) {
	int i, u, v;
	while (m--) {
		cin >> u >> v;
		u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par) {
	for (int v : g[u]) {
		if (v == par) continue;
		dfs(v, u);
	}
}

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

int main() {
	
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n) cin >> p[i];
	int mn = n + 1;
	int ans = 0;
	rep(i, n){
		if(mn > p[i]){
			ans++;
			mn = p[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import re
import doctest


class IO_for_Contest(object):
    @staticmethod
    def my_input():
        # return raw_input()
        return input()

    @staticmethod
    def read_from_input():
        n, l = IO_for_Contest.read_n_int(2)
        raw_s = []
        for x in range(n):
            raw_s.append(IO_for_Contest.read_line())
        return list(map(lambda x: x[0:l], raw_s))

    @staticmethod
    def read_line():
        return IO_for_Contest.my_input().strip()

    @staticmethod
    def read_int():
        return int(IO_for_Contest.my_input().strip())

    @staticmethod
    def read_n_int(n):
        return list(map(
                int,
                re.split('\s+', IO_for_Contest.my_input().strip())))[: n]


def solve():
    a = IO_for_Contest.read_from_input()
    a.sort()
    print(''.join(a))

if __name__ == '__main__':
    # doctest.testmod()
    solve()

Measured memory_bytes: 8864
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
// namespace mp = boost::multiprecision;
// using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
// using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,m;
  cin>>n>>m;
  ll l,r;
  vector<ll>v(n+1,0);
  vector<ll>vv(n+1,0);
  for(ll i=0;i<m;i++){
    cin>>l>>r;
    l--;
    r--;
    v[l]++;
    v[r+1]--;
  }
  ll ans=0;
  vv[0]=v[0];
  for(ll i=1;i<n+1;i++){
    vv[i]=v[i]+vv[i-1];
  }
  for(ll i=0;i<n;i++){
    if(vv[i]==m){
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
k = int(input())
lunlun = []
def dfs(A):
    if len(A) > 10:
        return 
    else:
        num = int(A[-1])
        lunlun.append(int("".join(A)))
        if num == 0:
            for i in range(0, 2):
                A.append(str(i))
                dfs(A)
                A.pop()
        elif num == 9:
            for i in range(8, 10):
                A.append(str(i))
                dfs(A)
                A.pop()
        else:
            for i in range(num-1, num+2):
                A.append(str(i))
                dfs(A)
                A.pop()

for i in range(1, 10):
    dfs([str(i)])
lunlun.sort()
print(lunlun[k-1])

Measured memory_bytes: 94988