akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <functional>

using namespace std;
typedef long long llong;

#define MAX 1001
const llong mod = 1000000000 + 7;

int main()
{
  int N, M;
  double border = 0;
  int A[MAX];
  int flag;

  scanf("%d%d", &N, &M);

  for (int i = 0; i < N; i++)
  {
    scanf("%d", &A[i]);
    border += A[i];
  }
  border /= 4 * M;

  sort(A, A + N, greater<int>());

  flag = 1;
  for (int i = 0; i < M; i++)
  {
    if (A[i] < border)
      flag = 0;
  }

  if (flag)
    printf("Yes");
  else
    printf("No");

  return 0;
}

Measured memory_bytes: 1708
#include<stdio.h>
int main(){
    int N , A, B ;
    scanf("%d%d%d",&N,&A,&B);
    if(N>=1 && N<=50 && A>=1 && A <=50 && B>=1 && B<=50){
        if(N*A<=B){
            printf("%d",N*A);
        }  else{
            printf("%d",B);
        }
    }
}


Measured memory_bytes: 128
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int r = parseInt(sc.next());
		sc.close();
		out.println(r*2*Math.PI);
	}
}


Measured memory_bytes: 27028
#include <iostream>
#include <vector>
#include <sstream>

inline void split(const std::string& str, std::vector<int>& H) {
	const char sep = ' ';
    std::stringstream ss(str);
    std::string buffer;

	while (std::getline(ss, buffer, sep)) {
		H.push_back(std::stoi(buffer));
	}
}

int main (void) {
	std::string str;
	int N;
	std::getline(std::cin, str);
	N = std::stoi(str);
	
	std::vector<int> H;
	std::getline(std::cin, str);
	split(str, H);
	
	int i, max = 0, cnt = 0;
	
	for (i = 0; i < H.size(); ++i) {
		if (H[i] >= max) {
			max = H[i];
			++cnt;
		}
	}
	
	std::cout << cnt << std::endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<math.h>
#include<string>
#include<queue>
#include<map>
#include <stdio.h>
#include<algorithm>
using namespace std;



  bool dp[100010]={false,true,};
  int dpnum[100010]={};
  long long x[100010]={},y[100010]={};
int main() {
  int n,m;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> x[i]>> y[i];
  }
  for(int i=0;i<=n;i++){
    dpnum[i]=1;
  }
  for(int i=0;i<m;i++){
    if(dpnum[x[i]]>=1){
      if(dpnum[x[i]]==1 && dp[x[i]]==true){
        dp[x[i]]=false;
        dp[y[i]]=true;
      }
      else if(dpnum[x[i]]>1 && dp[x[i]]==true){
        dp[y[i]]=true;
      }
      dpnum[x[i]]--;
      dpnum[y[i]]++;
    }
  }
  long long ans=0;
  for(int i=0;i<=n;i++){
    if(dp[i])ans++;
  }
  cout <<ans<<endl;
  return 0;
}


Measured memory_bytes: 2304
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
k = 1-a[0]
s -= a[0]
ans = 1

for i in range(1,n+1):
  if k*2 <= s:
    k *= 2
  else:
    k = s
  ans += k
  k -= a[i]
  s -= a[i]

if k == 0 and s == 0:
  print(ans)
else:
  print(-1)

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    string a,b;
    cin>>a>>b;
    if ((a[0]==b[2])&&(a[1]==b[1])&&(a[2]==b[0]))cout<<"YES";
    else cout<<"NO";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
using namespace std;
int main(){
    long N,c=0L;
    cin>>N;
    vector<long>A(N),V(N);
    for(long i=0;i<N;i++)cin>>A[i];
    V=A;
    sort(V.begin(),V.end());
    unordered_map<long,long>m;
    for(long i=0;i<N;i++)m[V[i]]++;
    for(auto x:m)c+=x.second*(x.second-1L)/2L;
    for(long i=0;i<N;i++)cout<<c-m[A[i]]+1L<<endl;
    return 0;
}

Measured memory_bytes: 10696
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

#define maxs(x,y) (x=std::max(x,y))
#define mins(x,y) (x=std::min(x,y))

int main() {
  ull H, W;
  cin >> H >> W;
  if (H==1 || W == 1) {
    cout << "1\n";
    return 0;
  }

  ull row = H/2;
  ull c = W*row;

  if (H%2 == 1) {
    c += ((W+1)/2);
  }
  cout << c << '\n';
}


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

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	vector<string> ans(N - K, "No");
	for (int first = 0; first < (N - K); first++) {
		int last = first + K;
		if (A[first] < A[last]) ans[first] = "Yes";
	}
	for (int i = 0; i < (N - K); i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 10304
use std::cmp;
use std::io;


fn read_line() -> String {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line).unwrap();
    return String::from(line.trim());
}

fn main() {
    let _ = read_line().parse::<i64>().unwrap();
    let values: Vec<i64> = read_line().split_whitespace().map(|v| v.parse::<i64>().unwrap()).collect();
    let min = *(values.iter().min().unwrap());
    let max = *(values.iter().max().unwrap());
    let min_index = values.iter().enumerate().filter(|&(_, v)| *v == min).nth(0).unwrap().0;
    let max_index = values.iter().enumerate().filter(|&(_, v)| *v == max).nth(0).unwrap().0;

    let p = |i0, i1| {println!("{} {}", i0 + 1, i1 + 1)};

    println!("{}", (values.len() - 1) * 2);
    if (0 < min) || (-min < max) {
        for i in (0..values.len()).filter(|i| *i != max_index) {
            p(max_index, i);
        }
        for i in 0..values.len() - 1 {
            p(i, i + 1);
        }
    } else {
        for i in (0..values.len()).filter(|i| *i != min_index) {
            p(min_index, i);
        }
        for i in (0..values.len() - 1).rev() {
            p(i + 1, i);
        }
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace2(a,b) cerr <<"a is " << a << " b is " << b << el;
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;
int main()
{
    ios;
    ll n ;
    cin >> n ;
    vl a , b , c;
    forn(i , 1, n ) {
       ll x;
       cin >> x;
       a.pb(x);
    }
    forn(i , 1 , n ){
      ll x;
      cin >> x;
      b.pb(x);
    }
    forn(i , 1,  n ) {
       ll x;
       cin >> x;
       c.pb(x);
    }
    sort(all(a));
    sort(all(b));
    sort(all(c));
    ll ans = 0 ;
    forn(i , 0 , n-1){
       ll curr = b[i] ;
       ll ind1 = -1 , ind2 = -1 ;
       ll cnt1 = 0 , cnt2 = 0 ;
       ll low = 0 , high = n-1 ;
       while(low <= high){
          ll mid = (low + high ) / 2 ;
          if(a[mid]<curr){
            ind1 = mid ;
            low = mid + 1 ;
          }
          else if(a[mid] >= curr){
            high = mid-1 ;
          }
       }
       low = 0 ; high = n -1 ;
       while(low <= high){
        ll mid = (low + high) / 2 ;
        if(c[mid]<=curr){
            low = mid + 1 ;
        }
        else if(c[mid] > curr){
            ind2 = mid ;
            high = mid - 1 ;
        }
       }
      /// cout << " i is " << i << " ind1 " << ind1 << " ind2 " << ind2 << el ;
       if(ind1 == -1 or ind2 == -1){
         ans = ans + 0 ;
         con ;
       }
       ll left = ind1 + 1 ;
       ll right = n-ind2 ;
       ans = ans + left*right ;
    }
    cout << ans << el ;
    ro ;
}





























Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define INT_MAX 2147483647
#define INT_MIN -2147483646
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
 
static const int N = 105;
 
struct vertex {
    int id;
    int d;
    bool operator<(const vertex & another) const {
        return (d != another.d ? d>another.d : id>another.id);
    }
};
 
int main() {
    vvi mx(N, vi(N, -1));
    int n;
    cin >> n;
    Loop(i, n) {
        Loop(j, n) {
            int a;
            cin >> a;
            mx[i][j] = a;
        }
    }
     
    vector<bool> color(N, 0);
    priority_queue<vertex> q;
    q.push({ 0,0 });
    int ret = 0;
    while(q.size() > 0) {
        vertex v = q.top();
        q.pop();
        if (color[v.id] == 1) continue;
        color[v.id] = 1;
        ret += v.d;
        Loop(j, n) {
            if (mx[v.id][j] != -1 && color[j] != 1){
                q.push({ j, mx[v.id][j] });
            }
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3248
import sys
N = int(input())
S = input()

if '.' not in S or '#' not in S:
  print(0)
  sys.exit()
  
l = 0  # 境界より左の'#'の数
r = S.count('.')  # 境界より右の'.'の数
ans = l+r
for s in S:
  if s == '.':
    r -= 1
  else:
    l += 1
  ans = min(l+r, ans)

print(ans)

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

int main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
 int n;
 cin >> n;
 vector<int> vec(200001);
 vector<int> cnt(n);
 long long int m = 0;
 for (int i = 0; i < n; ++i){
	 cin >> vec[i];
	 m += cnt[vec[i]];
	 ++cnt[vec[i]];
 }
 for (int i = 0; i < n; ++i){
	 cout << m - cnt[vec[i]] + 1 << '\n';
 }
} 

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 1; i < (n); ++i )
typedef std::pair<int,int> pint;

using namespace std;
typedef long long ll;

int main(){
    int N; cin >> N;
    vector<int> list;
    int ans;
    rep (i,N + 1){
        int tmp;
        cin >> tmp;
        list.push_back(tmp);
        //cout << tmp << endl;
    }
    int min = 1000000000;
    rep (i,101){
        int count = 0;
        int tmp = 0;
        for (int j = 0; j < N; j++){
            tmp = abs(list[j] - i);
            count += pow(tmp,2);
            //cout << "cout=" << count << endl;
        } 
        if (count < min){
            min = count;
            //cout << i << endl;
        }
    }
    cout << min << endl;
    return 0;
}

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

int main() {
	string s,t;
	int slen,tlen;
	cin >> s >> t;
	slen = s.length();
	tlen = t.length();
	int ans = tlen;
	for (int i = 0; i+tlen-1 < slen; i++){
		int ctr = 0;
		for (int j = 0 ; j < tlen; j++)
			if (t[j] != s[i+j])
				ctr++;

		ans = min(ans,ctr);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<pair<ll, ll>> factrize(ll n)
{
    vector<pair<ll, ll>> res;
    for (ll i = 2; i <= sqrtl(n); i++)
    {
        ll k = i;
        ll cnt = 0;
        while (n % k == 0)
        {
            n /= k;
            cnt++;
        }
        res.emplace_back(k, cnt);
    }
    if (n != 1)
    {
        res.emplace_back(n, 1);
    }
    return res;
}
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll n;
    cin >> n;
    vector<pair<ll,ll>> m = factrize(n);
    cout << n << ": ";
    for(ll i = 0; i < m.size(); i++){
        for(ll j = 0; j < m[i].second; j++){
            cout << m[i].first << (i == m.size() - 1 && j == m[i].second - 1 ? "\n" : " ");
        }
    }
}


Measured memory_bytes: 3304
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
using namespace std;
#define MAX_N 100001
#define INF 2147483647
#define REP(i,COUNT) for(int i=0;i<(int)(COUNT);i++)
struct edge{
  int to, cost;
};
typedef vector<vector<edge> > AdjList;
AdjList graph;
typedef pair<int, int> P;
typedef long long int ll;

void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
vector<int> dist;
vector<int> prever;
void dijkstra(int n,int s){
  dist = vector<int>(n,INF);
  prever = vector<int>(n,-1);
  dist[s] = 0;

  priority_queue<P, vector<P> , greater<P> > que;
  que.push(P(0,s));

  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if(dist[v] < p.first)
      continue;
    REP(i,graph[v].size()){
      edge e = graph[v][i];
      if(dist[e.to] > dist[v] + e.cost){
        dist[e.to] = dist[v] + e.cost;
        prever[e.to] = v;
        que.push(P(dist[e.to],e.to));
      }

    }

  }
}

bool bellman_ford(int n,int s){
  dist = vector<int>(n,INF);
  dist[s] = 0;
  REP(i,n)REP(v,n)REP(k,graph[v].size()){
    edge e = graph[v][k];
    if(dist[v] != INF && dist[e.to] > dist[v] + e.cost){
      dist[e.to] = dist[v] + e.cost;
      if(i == n - 1) return true;
    }
  }
  return false;
}

vector<vector<ll> > d; //d[u][v]は辺e=(u,v)のコスト, 辺が存在しないときINF
void warshall_floyd(int n){
  REP(i,n)REP(j,n)REP(k,n){
    d[j][k] = min(d[j][k],d[j][i] + d[i][k]);
  }
}

int main()
{
  int N,M,R,A,B,C;
  vector<ll> v;
  ll res=10000000000000,tmp;
  cin >> N >> M >> R;
  d = vector<vector<ll > >(N+2,vector<ll>(N+2,INF));
  REP(i,R){
    cin >> C;
    v.push_back(C);
  }
  sort(v.begin(),v.end());
  REP(i,M){
    cin >> A >> B >> C;
    d[A][B] = C;
    d[B][A] = C;
  }
  warshall_floyd(N+1);
  
  do{
    tmp = 0;
    REP(i,v.size()-1){
      tmp += d[v[i]][v[i+1]];
    }
    res = min(res,tmp);
  }while(next_permutation(v.begin(),v.end()));
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 640
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
a = rl()
cnt = 0
for idx, i in enumerate(a, 1):
  if idx&1 and i&1:
    cnt += 1
print(cnt)
    



Measured memory_bytes: 27000
#include<bits/stdc++.h>
using namespace std;
long long x[1200][3];
long long f[1200],res;
int n,m;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>x[i][0]>>x[i][1]>>x[i][2];
	for(int mask=0;mask<8;mask++){
		int t;
		for(int i=1;i<=n;i++){
			t=mask;
			f[i]=0;
			for(int j=0;j<3;j++){
				if(t%2==0)
					f[i]+=x[i][j];
				else
					f[i]-=x[i][j];
				t/=2;
			}
		}
		sort(f+1,f+n+1);
		reverse(f+1,f+n+1);
		long long cur=0;
		for(int i=1;i<=m;i++)
			cur+=f[i];
		res=max(res,cur);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	int T;
	cin>>T;
	while(T--) {
		int n;
		cin>>n;
		vector<array<ll,3>> t(n);
		ll ans=0;
		for(int i=0;i<n;++i) {
			cin>>t[i][0]>>t[i][1]>>t[i][2];
			ll v=min(t[i][1], t[i][2]);
			ans+=v;
			t[i][1]-=v;
			t[i][2]-=v;
		}
		sort(all(t), [&](array<ll,3> egyik, array<ll,3> masik) -> bool {
			return max(egyik[1], egyik[2])<max(masik[1], masik[2]);
		});
		
		set<ll> pos;
		for(int i=1;i<=n;++i) pos.insert(i);
		int cnt=0;
		for(auto i:t) {
			if(i[1]>0) cnt++;
		}
		
		for(auto& i:t) {
			if(i[1]>0 && i[0]>cnt) i[0]=cnt;
			if(i[2]>0 && i[0]<=cnt) i[0]=cnt;
		}
		
		reverse(all(t));
		for(auto i:t) {
			if(i[1]>0) {
				auto it=pos.lower_bound(i[0]+1);
				if(it!=pos.begin()) {
					it--;
					ans+=i[1];
					pos.erase(it);
				}
			}else if(i[2]>0) {
				auto it=pos.lower_bound(i[0]+1);
				if(it!=pos.end()) {
					ans+=i[2];
					pos.erase(it);
				}
			}
		}
		
		cout<<ans<<"\n";
	}
	return 0;
}


Measured memory_bytes: 17188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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


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

    int N; cin >> N;
    string ans = "";
    while (N != 0) {
        int r = N % 2;
        if (r < 0) r += 2;
        N = (N - r) / (-2);
        ans += (char)('0' + r);
    }

    reverse(ALL(ans));
    if (ans == "") ans = "0";
    COUT(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
string s;
int ans = 100000000;
void solve(string t,char c,int cnt){
	string new1;
	if(count(t.begin(),t.end(),t[0])==t.length()){
		ans = min(ans,cnt);
		return;
	}
	for(int i=0;i+1<t.length();i++){
		if(t[i]==c || t[i+1]==c){
			new1.push_back(c);
		}
		else {
			new1.push_back(t[i]);
		}
	}
	solve(new1,c,cnt+1);
}
int32_t main(){
	cin>>s;
	for(int i=0;i<s.length();i++){
		solve(s,s[i],0);
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool cmp(long long x)
{
	long long i;
	for(i=2;i*i<=x;i++)
	{
		if(x%i==0)
		return false;
	}
	return true;
}
int main()
{
	long long i,x;
	cin>>x;
	for(i=2;i<=1000000000;i++)
	{
		if(cmp(i))
		if(i>=x)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  int n, i, k = 0, f = 0;
  cin >> n >> s;
  for(i = 0; i < n; i++){
    if(s[i] == '(') k++;
    else if(k == 0) f++;
    else k--;
  }
  for(i = 0; i < f; i++) cout << '(';
  cout << s;
  for(i = 0; i < k; i++) cout << ')';
  cout << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

// https://atcoder.jp/contests/hokudai-hitachi2019-1/submissions/10518254

macro_rules! eprint {
    ($($t:tt)*) => {{
        use ::std::io::Write;
        let _ = write!(::std::io::stderr(), $($t)*);
    }};
}
macro_rules! eprintln {
    () => { eprintln!(""); };
    ($($t:tt)*) => {{
        use ::std::io::Write;
        let _ = writeln!(::std::io::stderr(), $($t)*);
    }};
}
macro_rules! dbg {
    ($v:expr) => {{
        let val = $v;
        eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
        val
    }}
}

macro_rules! mat {
    ($($e:expr),*) => { Vec::from(vec![$($e),*]) };
    ($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
    ($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
    ($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
    ($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
        $a$([$i])*.$f($($t),*)
    };
    ($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
        let t = $e;
        ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
    } };
}

pub fn readln() -> String {
    let mut line = String::new();
    ::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
    line
}

macro_rules! read {
    ($($t:tt),*; $n:expr) => {{
        let stdin = ::std::io::stdin();
        let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
            let line = line.unwrap();
            let mut it = line.split_whitespace();
            _read!(it; $($t),*)
        }).collect::<Vec<_>>();
        ret
    }};
    ($($t:tt),*) => {{
        let line = readln();
        let mut it = line.split_whitespace();
        _read!(it; $($t),*)
    }};
}

macro_rules! _read {
    ($it:ident; [char]) => {
        _read!($it; String).chars().collect::<Vec<_>>()
    };
    ($it:ident; [u8]) => {
        Vec::from(_read!($it; String).into_bytes())
    };
    ($it:ident; usize1) => {
        $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
    };
    ($it:ident; [usize1]) => {
        $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
    };
    ($it:ident; [$t:ty]) => {
        $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
    };
    ($it:ident; $t:ty) => {
        $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
    };
    ($it:ident; $($t:tt),+) => {
        ($(_read!($it; $t)),*)
    };
}


pub fn main() {
    let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: usize = 1_000_000_007;
const INF: i32 = std::i32::MAX;

fn solve() {
    let n = read!(usize);
    let a = read!([i64]);
    let mut ans = 0;
    for i in 0..n {
        if i%2==0 && a[i]%2==1 {
            ans += 1;
        }
    }
    println!("{}",ans);
    
}

fn run() {
    solve();
}


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

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

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

  char now = S[0];
  int result = 1;
  rep(i,N-1) {
    if (S[i+1]!=now) {
      result++;
      now = S[i+1];
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,j,n) for(int (i)=j;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int main(){
  int k;
  cin>>k;
  int ans =0;
  rep(i,k){
    rep(j,k){
      rep(l,k){
        int v = __gcd((i+1),(j+1));
        v=__gcd(v,(l+1));
        ans+=v;
      }
    }
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 3624
#include <stdio.h>
int main() {
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>b){
		printf("a > b\n");
	}else if(a<b){
		printf("a < b\n");
	}else if(a==b){
		printf("a == b\n");
	}
	return 0;
}
		


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	bool flag = false;
	int cnt = 0;
	while( n-- ){
		int x, y; cin >> x >> y;
		if( x == y ) ++cnt;
		else cnt = 0;
		if( cnt == 3 ) flag = true; 
	}
	if( flag ) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k, x;
	cin >> k >> x;
	if (500 * k >= x) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)


int main(){
	int n,m,x,y,cnt;
	for(;;){
		bool l[500][500]={0},f[500]={0};
		scanf("%d%d",&n,&m);
		if(n==0&&m==0)break;
		cnt=0;
		rep(i,m){
			scanf("%d%d",&x,&y);
			--x;
			--y;
			l[x][y]=l[y][x]=1;
		}
		reps(i,1,n-1){
			if(l[0][i]){
				f[i]=1;
				rep(j,n){
					if(j!=0 && l[i][j]){
						f[j]=1;
					}
				}
			}
		}
		rep(i,n)cnt+=f[i];
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 1436
#include <iostream>

using namespace std;

int main()
{
	int N;
	double answer;
	cin >> N;
	if (N % 2 == 0)
	{
		answer = (double)(N / 2) / (double)N;
	}
	else
	{
		answer = (double)((N + 1) / 2) / (double)N;
	}
	cout << answer << endl;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;



int main() {
    ll N, K, answer = 0;
    cin >> N >>K;
    vector<ll> ans(N,0);
    rep(i, K) {
        ll d;
        cin >> d;
        vector<ll> A(d,0);
        rep(j, d) {
            cin >> A[j];
        }
        rep(x, d) {
            ans[A[x] - 1]++;
        }
        
    }
    rep(k, N) if (ans[k] == 0) answer++;
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 3636
n = int(input())
status_list = [0] * 4
for i in range(n):
    status = input()
    if status == 'AC':
        status_list[0] += 1
    elif status == 'WA':
        status_list[1] += 1
    elif status == 'TLE':
        status_list[2] += 1
    else:
        status_list[3] += 1

status_case = ['AC', 'WA', 'TLE', 'RE']
for s, x in zip(status_case, status_list):
    print(s + ' x ' + str(x))

Measured memory_bytes: 9200
//%std
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out = 0, fh = 1;
	char jp = getchar();
	while ((jp > '9' || jp < '0') && jp != '-')
		jp = getchar();
	if (jp == '-')
		fh = -1, jp = getchar();
	while (jp >= '0' && jp <= '9')
		out = out * 10 + jp - '0', jp = getchar();
	return out * fh;
}
const int N = 1e6 + 10;
int main()
{
	int n = read(), m = read();
	for (int i = 1; i <= m; ++i)
	{
		n -= read();
		if (n < 0)
			break;
	}
	if (n < 0)
		n = -1;
	printf("%d\n", n);
	return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;
const ll mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector <int> a(n);
  vector <ll> cnt(n + 1, 0);
  vector <ll> cnt2(n);
  REP(i, n) {
	cin >> a[i];
	cnt[a[i]]++;
  }
  REP(i, n) {
	cnt2[i] = cnt[a[i]];
  }
  ll ans = 0;
  REP1(i, n) {
	ans += cnt[i] * (cnt[i] - 1) / 2;
  }
  REP(i, n) {
	cout << ans - cnt2[i] + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 8320
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from fractions import gcd
def resolve():
    a, b, c, d = map(int, input().split())
    L = c // gcd(c, d) * d
    a -= 1
    S = b - b // c - b // d + b // L
    T = a - a // c - a // d + a // L
    print(S - T)
resolve()

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

int main(){
  int n;
  cin>>n;
  vector<string> S(n);
  for(int i=0;i<n;++i){
    cin>>S.at(i);
  }

  //26
  string alpha="abcdefghijklmnopqrstuvwxyz";
  string ans;
  for(int i=0;i<26;++i){
    int count=50;
    for(int j=0;j<n;++j){
      int subcount=0;
      for(int k=0;k<S.at(j).size();++k){
        if(S.at(j).at(k)==alpha.at(i)){
          ++subcount;
        }
      }
      count=min(count,subcount);
    }

    for(int l=0;l<count;++l){
      ans += alpha.at(i);
    }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
        ***Fresher***
    Md Mahfujur Rahman Khan
    Dept. of CSE
    CSE-28 Batch
    JU-48 Batch
    Jahangirnagar University

*/
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
using namespace std;
#define V_ vector
#define Q_ queue
#define S_ set
#define ST_ stack
#define M_ map
#define DQ_ deque

#define pii pair<ll,ll>
#define pci pair<char,ll>
#define psi pair<string, ll>
#define pis pair<ll,string>
#define pic pair<ll, char>

#define mii map<ll,ll>
#define msi map<string, ll>
#define mis map<ll, string>
#define mib map<ll,bool>
#define msb map<string,bool>

#define vi vector<ll>
#define vs vector<string>

#define ivi vector<ll> :: iterator
#define ivs vector<string> :: iterator
#define imii map<ll,ll> :: iterator
#define imsi map<string,ll> :: iterator
#define imis map<ll, string> :: iterator
#define imib map<ll, bool> :: iterator
#define imsb map<string, bool> :: iterator

#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define F first
#define S second
#define pi 2*acos(0.0)
#define PB(x) push_back(x)
#define PP(x) push(x)
#define RSZ(n) resize(n)
#define POB pop_back()
#define P_ pop()
#define CL_ clear()
#define LEN_ length()
#define SZ_ size()
#define CNT_ count()
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define B_ begin()
#define E_ end()
#define F_ front()
#define t_ top()
#define IN_ insert
#define ER_  erase
#define GT getline
#define NL_   "\n"
#define SP_ " "

#define fr(i, n) for(i = 0; i < n; i++)
#define fe(x, n) for(i = x; i <= n; i++)

#define ul unsigned long long int
#define ll long long int
#define  MAX 250000





int main()
{

 ll n, sum = 0, mx =0, t;
 cin >> n;
 while(n--)
 {
     cin >> t;
     sum+=t;
     mx = max(mx,t);
 }
 sum -= mx;
 if(sum > mx) cout <<"Yes";
 else cout <<"No";


    return 0;

}


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

using namespace std;

using int64 = long long;

template <typename T>
class SegmentTree {
 private:
  function<T(T, T)> merge;
  T empty_value;
  vector<T> nodes;
  int num_nodes;

  // Returns the fold of overwrap between [node_l, node_r) and [l, r).
  // nodes[node_index] needs to correspond to [node_l, node_r).
  T GetRangeInternal(int node_index, int node_l, int node_r, int l, int r) {
    if (node_r <= l || r <= node_l) return empty_value;
    if (l <= node_l && node_r <= r) return nodes[node_index];
    int node_m = (node_l + node_r) / 2;
    return merge(
        GetRangeInternal(2 * node_index, node_l, node_m, l, r),
        GetRangeInternal(2 * node_index + 1, node_m, node_r, l, r));
  }

 public:
  // Arguments:
  // in_merge: The function to merge two values. It should be a monoid.
  // in_empty_value: The identity of the monoid.
  // xs: The initial values.
  SegmentTree(
      function<T(T, T)> in_merge, T in_empty_value, const vector<T>& xs) :
          merge(in_merge), empty_value(in_empty_value) {
    int n = xs.size();
    num_nodes = 1;
    while (num_nodes < n) num_nodes *= 2;
    num_nodes *= 2;
    nodes = vector<T>(num_nodes, empty_value);
    for (int i = 0; i < xs.size(); ++i) {
      nodes[num_nodes / 2 + i] = xs[i];
    }
    for (int i = num_nodes / 2 - 1; i >= 1; i--) {
      nodes[i] = merge(nodes[2 * i], nodes[2 * i + 1]);
    }
  }

  // Updates the i-th element to x.
  void Update(int i, T x) {
    nodes[num_nodes / 2 + i] = x;
    for (int cur = (num_nodes / 2 + i) / 2; cur > 0; cur /= 2) {
      nodes[cur] = merge(nodes[2 * cur], nodes[2 * cur + 1]);
    }
  }

  // Returns the fold of the range [l, r) by the merge function.
  T GetRange(int l, int r) {
    return GetRangeInternal(1, 0, num_nodes / 2, l, r);
  }

  T Get(int i) {
    return nodes[num_nodes / 2 + i];
  }
};

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

  int n;
  cin >> n;
  vector<int> hs(n);
  vector<int64> vs(n);
  for (int i = 0; i < n; i++) {
    cin >> hs[i];
    hs[i]--;
  }
  for (int i = 0; i < n; i++) {
    cin >> vs[i];
  }

  vector<int64> dp(n);
  function<int64(int64, int64)> max_fn = [&](int64 x, int64 y) { 
    return max(x, y);
  };
  SegmentTree<int64> segment_tree = SegmentTree<int64>(max_fn, 0, dp);

  for (int i = 0; i < n; i++) {
    int h = hs[i];
    int64 value = segment_tree.GetRange(0, h) + vs[i];
    segment_tree.Update(h, value);
  }
  int64 ans = segment_tree.GetRange(0, n);
  cout << ans << endl;
}


Measured memory_bytes: 8320
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define per(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define enter cout << endl
#define siz(x) ((int)x.size())
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 21 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll MOD = 1000000007 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }

int n ;
int a[N][N] ;
int dp[1 << N] ;

signed main() {
	scanf("%d", &n) ;
	for (int i = 0; i < n; i++)
	for (int j = 0; j < n; j++)
	scanf("%d", &a[i][j]) ;
	dp[0] = 1 ;
	for (int i = 1; i < (1 << n); i++) {
		int now = __builtin_popcount(i) - 1 ;
		for (int j = 0; j < n; j++)
		if (i & (1 << j) && a[now][j]){
			dp[i] = (dp[i] + dp[i ^ (1 << j)]) % MOD ;
		}
	}
	printf("%d\n", dp[(1 << n) - 1]) ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
*/


Measured memory_bytes: 8448
#include<map>
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
typedef long long int ll;
using namespace std;
#define MAXN 200001
#define X first
#define Y second
#define MOD 1000000007
#define fr(a,b,c) for(ll a=b;a<c;++a)
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

ll t,n,i,j;
int main()
{
    fastio;
    ll a,b,u,p,x;
    cin>>n>>t;
    vector < vector <ll > > adj(n+1);
    fr(i,1,n){
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    vector <ll > v;
    v.assign(n+1,0);
    vector <ll > cnt;
    cnt.assign(n+1,0);
    vector <bool > used;
    used.assign(n+1,false);
    while(t--){
        cin>>p>>x;
        v[p]+=x;
    }
    used[1]=true;
    queue <ll > q;
    q.push(1);
    cnt[1]=v[1];
    while(!q.empty()){
        u=q.front();
        q.pop();
        for(auto k:adj[u]){
            if(!used[k]){
                used[k]=true;
                q.push(k);
                cnt[k]=cnt[u]+v[k];
            }
        }
    }
    fr(i,1,n+1)
        cout<<cnt[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 19952
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define P pair<int, int>

#define MOD 1000000007
#define INF 2147483647
#define NINF (-2147483647-1)
#define LLINF 9223372036854775807
using ll = long long;
using namespace std; 

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

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;

void work() {
    ll a,b,c; cin>>a>>b>>c;
    if (c-a-b <= 0LL) {
        cout << "No\n";
        return;
    }
    ll ls = 4LL*a*b;
    ll rs = ((c-a-b) * (c-a-b)) ;
    if (ls < rs) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    work();
    return 0;
}


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

#define loop(i,first,end) for(int i=(first);i<(end);i++)
#define uint unsigned int
#define ull unsigned long long
#define ll long long
#define vint vector<int>
#define vuint vector<unsigned int>
#define vull vector<ULL>
#define vll vector<LL>
#define mod 1000000007


int main(void){
	uint n;
	vuint a;

	cin >> n;
	a.resize(n);
	loop(i, 0, n)cin >> a[i];

	sort(a.begin(), a.end());
	if (
		(
			n % 3 == 0
			&& a[0] == a[n / 3 - 1] && a[n / 3 - 1] != a[n / 3]
			&& a[n / 3] == a[(n / 3) * 2 - 1]// && a[(n / 3) * 2 - 1] != a[(n / 3) * 2]
			&& a[(n / 3) * 2] == a[n - 1]
			&& (a[n / 3] ^ a[n - 1]) == a[0]
			)
		||
		(
			a[n - 1] == 0
			)
		)
		cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = 1000000007;
using namespace std;
using vec = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};

int p, q, r;
int res = 0;

int main(int argc, char *argv[]){
    cin >> p >> q >> r;
    res = min(INF, p + q);
    res = min(res, p + r);
    res = min(res, r + q);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var n = next();
  var d = xArray(0,1e5+1);
  var tot = 0;
  for(var i = 0; i < n; i++){
    var a = next();
    d[a]++;
    tot += a;
  }
  var q = next(), ans = Array(q);
  for(var i = 0; i < q; i++){
    var b = next(), c = next();
    d[c] += d[b];
    tot += d[b]*(c-b);
    ans[i] = tot;
    d[b] = 0;
  }
  return ans.join("\n");
}

Measured memory_bytes: 63288
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
         Scanner scanner =new Scanner(System.in);
        int n=scanner.nextInt();
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        int count=0;
        for (int i = 1; i <= n; i++) {
            int c=0;
            for (int i1 = 0; i1 < String.valueOf(i).length(); i1++) {
                c=c+ Integer.valueOf(String.valueOf(i).substring(i1, i1 + 1));
            }
            if (c>=a && c<=b){
                count=count+i;
            }
        }System.out.println(count);
    }
}

Measured memory_bytes: 27860
#include <bits/stdc++.h>
using namespace std;
const int N = 102, M = 100005;

int n, m;

long long dp[M];
int main()
{
    cin >> n >> m;
    for (int i = 1; i < M; ++i)
        dp[i] = 1000000009;
    while (n--)
    {
        int x, g;
        cin >> x >> g;
        for (int i = M - 1 - g; i >= 0; --i)
            dp[i + g] = min(dp[i + g], dp[i] + x);
    }
    for (int i = M - 1; i >= 0; --i)
    {
        if (dp[i] <= m)
        {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
n = map(int, raw_input().split(' '))[0]

def dfs(i, mx, n, cur = []):
	if i==n:
		print ''.join(cur)
		return
	for v in range(0, mx + 1): dfs(i + 1, mx + (1 if v == mx else 0), n , cur + [chr(v+ ord('a'))])

dfs(0,0,n)


Measured memory_bytes: 37660
#include<bits/stdc++.h>
#define HohleFeuerwerke using namespace std
#define int long long
#pragma GCC optimize(3)
HohleFeuerwerke;
int n,k;
int ksm(int a,int b){
	if(b==0) return 1;
	if(b%2==1) return a*ksm(a,b-1);
	else{
		int num=ksm(a,b/2);
		return num*num;
	}
}
signed main()
{
	ios::sync_with_stdio(false);
	cout.tie(0);cin.tie(0);
	cin>>n>>k;
	for(int i=1;i<=1000;i++)
		if(ksm(k,i)>n){cout<<i<<endl;return 0;}
}

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

int N;
vector<int> Fdist, Sdist;
vector<vector<int>> E;

void Fsearch(int n){
    for(int i=0; i<E[n].size(); i++){
        int nxt = E[n][i];
        if(Fdist[nxt] > Fdist[n] + 1){
            Fdist[nxt] = Fdist[n] + 1;
            Fsearch(nxt);
        }
    }
}

void Ssearch(int n){
    for(int i=0; i<E[n].size(); i++){
        int nxt = E[n][i];
        if(Sdist[nxt] > Sdist[n] + 1){
            Sdist[nxt] = Sdist[n] + 1;
            Ssearch(nxt);
        }
    }
}

int main(){
    cin >> N;
    E = vector<vector<int>>(N, vector<int>());
    for(int i=0; i<N-1; i++){
        int a, b;  cin >> a >> b;
        a--;  b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    
    int inf = 1e9;
    Fdist = vector<int>(N, inf);
    Sdist = vector<int>(N, inf);
    Fdist[0] = 0;  Sdist[N-1] = 0;
    Fsearch(0);
    Ssearch(N-1);

    int f = 0, s = 0;
    for(int i=0; i<N; i++){
        if(Fdist[i] > Sdist[i]) s++;
        else f++;
    }

    if(f>s) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}


Measured memory_bytes: 9600
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;

int f(int N, int d, int x){
  vector<int> S{3, 5, 7};
  int ans=0;
  if(d>N){
    return 0;
  }
  for(int i=0; i<3; i++){
    int next_x;
    bool can=true;
    next_x = d*S[i]+x;
    if(next_x>N){
      break;
    }
    map<int,int> mp;
    int temp = next_x;
    while(temp){
      mp[temp%10]++;
      temp /= 10;
    }
    for(int j=0; j<3; j++){
      if(mp.find(S[j]) == mp.end()){
        can = false;
        break;
      }
    }
    if(can){
      ans++;
    }
    ans += f(N, d*10, next_x);
  }
  return ans;
}

int main(){
  int N;
  cin >> N;
  cout << f(N, 1, 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

string s;
llong p[200005];
llong cnt[2048];

int main() {
    cin >> s;

    reverse(s.begin(), s.end());
    p[0] = 0;
    cnt[0] = 1;
    llong c = 1;
    for (int i = 1; i <= s.size(); i++) {
        p[i] = p[i - 1];
        p[i] += (s[i - 1] - '0') * c % 2019;
        p[i] %= 2019;
        if (s[i - 1] != '0') cnt[p[i]]++;

        c *= 10;
        c %= 2019;
    }

    llong sum = 0;
    for (int i = 0; i <= s.size(); i++) {
        cnt[p[i]]--;
        sum += cnt[p[i]];
    }

    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 5188