akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H,W;
  cin>>H>>W;
  vector<vector<char>> S(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>S.at(i).at(j);
    }
  }
  vector<int> A(H),B(W);
  for(int i=0;i<H;i++){
    int count=0;
    for(int j=0;j<W;j++){
      if(S.at(i).at(j)=='.'){
        count++;
      }
    }
      if(count==W){
        A.at(i)=i+1;
      }
  }
  for(int j=0;j<W;j++){
    int count=0;
    for(int i=0;i<H;i++){
      if(S.at(i).at(j)=='.'){
        count++;
      }
    }
    if(count==H){
      B.at(j)=j+1;
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(A.at(i)==0&&B.at(j)==0){
        cout<<S.at(i).at(j);
      }
    }
    if(A.at(i)==0){
      cout<<endl;
  }
  }
    cout<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static long ans;
  public static int n;
  public static int r;
  public static int[] rk;
  public static long[][] dp;
  public static boolean[] used;
  public static int[] perm;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    int m = sc.nextInt();
    r = sc.nextInt();
    used = new boolean[r];
    perm = new int[r];
    rk = new int[r];
    ans = Long.MAX_VALUE;
    for(int i = 0; i < r; i++) {
      rk[i] = sc.nextInt() - 1;
    }
    dp = new long[n][n];
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        if(i != j) dp[i][j] = (long)Math.pow(10, 15);
      }
    }
    for(int i = 0; i < m; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      long c = sc.nextLong();
      dp[a][b] = c;
      dp[b][a] = c;
    }
    for(int k = 0; k < n; k++) {
      for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
          dp[i][j] = Math.min(dp[i][j], dp[i][k] + dp[k][j]);
        }
      }
    }
    dfs(0);
    System.out.println(ans);
  }

  public static void dfs(int i) {
    if(i == r) {
      long t = 0;
      int[] p = new int[r];
      for(int j = 0; j < r; j++) {
        int d = perm[j];
        p[j] = rk[d];
      }
      for(int j = 0; j < (r - 1); j++) {
        t += dp[p[j]][p[j + 1]];
      }
      ans = Math.min(ans, t);
    } else {
      for(int j = 0; j < r; j++) {
        if(!used[j]) {
          perm[i] = j;
          used[j] = true;
          dfs(i + 1);
          used[j] = false;
        }
      }
    }
  }
}

Measured memory_bytes: 46036
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl;
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}
 
typedef pair<ll,ll> Pair;
const ll inf =1000000007;

vector<ll> ans;

void dfs(string s,ll c){//今の文字列と、目標の文字数
    if(s.size()==c){
        ll a=stoll(s);
        ans.pb(a);
    }
    else{
        ll b=s.size()-1;
        ll u=s[b]-'0';
        for(ll i=-1;i<2;i++){
            if(u+i<0) continue;
            if(u+i>9) continue;
            string e="";
            e+=to_string(u+i);
            dfs(s+e,c);
        }
    }
}

ll k;

void solve(){
    cin >> k;
    for(ll i=1;i<11;i++){
        for(char s='1';s<='9';s++){
            string d="";d+=s;
            dfs(d,i);
        }
    }
    cout << ans[k-1] << endl;
}

int main(){
    solve();
}



Measured memory_bytes: 2544
#include<bits/stdc++.h>
using namespace std;
main(){
long long i,j,k,l,m,n,p,q;
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
while(cin>>m>>n>>p){
    q=0;
    if(n>p)swap(n,p);
    for(i=1;i<=p;i++){
        if(n<=i*m&&p>=i*m){q++;cout<<"OK"<<endl; break;}
    }
    if(q==0)cout<<"NG"<<endl;
} return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n;
  cin>>n;
  vector<int> cs(n);
  for(int i=0;i<n;i++) cin>>cs[i],cs[i]--;

  vector<vector<int>> G(n);
  for(int i=1;i<n;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }

  using ll = long long;
  ll all=0;
  vector<ll> cnt(n,0),sub(n,0);

  vector<ll> ans(n,(ll)n*(n-1)/2);
  MFP([&](auto dfs,int v,int p)->int{
    sub[v]=1;
    ll bfr=cnt[cs[v]];
    for(int u:G[v]){
      if(u==p) continue;
      ll pre=all-cnt[cs[v]];
      sub[v]+=dfs(u,v);
      ll nxt=all-cnt[cs[v]];
      ans[cs[v]]-=(nxt-pre)*(nxt-pre-1)/2;
    }
    cnt[cs[v]]=bfr+sub[v];
    all++;
    return sub[v];
  })(0,-1);

  for(int c=0;c<n;c++){
    ll pre=0,nxt=n-cnt[c];
    ans[c]-=(nxt-pre)*(nxt-pre-1)/2;
  }
  for(int c:cs) ans[c]++;

  for(ll a:ans) cout<<a<<newl;
  return 0;
}


Measured memory_bytes: 47820
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % mod;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
array<int, 101> factoring(int x) {
    array<int, 101> ret{};
    for (int i = 2; x >= i * i; i++) {
        while (x % i == 0) {
            ret[i]++;
            x /= i;
        }
    }
    if (x > 1) ret[x]++;
    return ret;
}
signed main() {
    int n;
    cin >> n;
    array<int, 101> fac{};
    for (int i = 1; i < n + 1; i++) {
        array<int, 101> save;
        save = factoring(i);
        for (int j = 0; j < n + 1; j++) {
            fac[j] += save[j];
        }
    }
    int cnt2, cnt4, cnt14, cnt74;
    int ans = 0;
    for (int i = 2; i < 101; i++) {
        for (int j = i; j < 101; j++) {
            for (int k = 2; k < 101; k++) {
                if (fac[k] >= 2 && fac[j] >= 4 && fac[i] >= 4 && i != k && k != j && j != i) {
                    ans++;
                }
            }
        }
    }
    for (int j = 2; j < 101; j++) {
        for (int k = 2; k < 101; k++) {
            if (fac[k] >= 4 && fac[j] >= 14 && k != j) {
                ans++;
            }
        }
    }
    for (int j = 2; j < 101; j++) {
        for (int k = 2; k < 101; k++) {
            if (fac[k] >= 2 && fac[j] >= 24 && k != j) {
                ans++;
            }
        }
    }
    for (int k = 2; k < 101; k++) {
        if (fac[k] >= 74) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
unsigned int a,n;
int IsPrime(int n)
{
	int i;

	if (n < 2)
		return 0;
	else if (n == 2)
		return 1;

	if (n % 2 == 0)
		return 0;

	for (i = 3; i <= n / i; i += 2)
		if (n % i == 0)
			return 0;
	return 1;
}
int main() {
	int temp=0,flag=0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (IsPrime(a) == 1)temp++;
	}
	cout << temp << endl;
}

Measured memory_bytes: 3072
#include <iomanip>
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    long double a, b, x;
    cin >> a >> b >> x;
    long double ans = 0;
    long double PI = (acos(-1));
    if(a * a * b / 2 >= x){
        ans = atan((a * b * b) / (2 * x));
    }else{
        ans = atan(2 * (a * a * b - x) / (a * a * a));
    }
    cout << fixed << setprecision(15);
    cout << ans * 180.0 / PI << endl;
    return 0;
}

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

int main() {
	long long h, w;
	cin >> h >> w;
	long long m = h * w / 2;
	if (h % 2 == 1 && w % 2 == 1)
		m++;
	if (h == 1 || w == 1)
		m = 1;
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define RFOR(i, begin, end) for(int i=(end)-1, i##_begin_=(begin);i>=i##_begin_;i--)
#define rep(i, N) FOR(i, 0, N)
#define rrep(i, N) RFOR(i, 0, N)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long int;
using V = vector<ll>;
using P = pair<ll, ll>;
using VP = vector<P>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
constexpr int inf = 1e9;
constexpr int mod = 1e9+7;
ll gcd(ll a, ll b) { return b? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}


int main() {
    ll n;
    cin >> n;
    V a(n);
    rep(i, n) cin >> a[i];

    ll ret = a[0];
    FOR(i, 1, n) ret = min(ret, gcd(max(ret, a[i]), min(ret, a[i])));
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <memory.h>
using namespace std;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct katana{
	int a,b;
}k[100010];
int n,h;
int ans;
bool cmp(katana x,katana y)
{
	return x.b>y.b;
}
int main()
{
	//freopen("Katana.in","r",stdin);
	//freopen("Katana.out","w",stdout);
	cin>>n>>h;
	int i,j;
	int maxv=0;
	for(i=1;i<=n;i++)
		cin>>k[i].a>>k[i].b,maxv=max(maxv,k[i].a);	
	sort(k+1,k+n+1,cmp);
	i=1;
	while(i<=n&&k[i].b>maxv)
	{
		h-=k[i].b;
		ans++;
		if(h<=0)
		{
			cout<<ans<<endl;
			return 0;
		}
		i++;
	}
	ans+=h/maxv;
	if(h%maxv!=0)ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

enum Event{
	None,
	Move_On,
	Get,
	Lose,
};

struct Info{
	void init(){
		value = 0;
		event = None;
	}
	Event event;
	int value;
};

int main(){

	int X,Y,Z,V[4],N,E,A,next_masu;
	Event event[4] = {None,Move_On,Get,Lose};
	double dp[51][5001];
	double ans;
	Info info[51];

	while(true){
		scanf("%d %d %d",&X,&Y,&Z);
		if(X == 0 && Y == 0 && Z == 0)break;

		for(int i = 0; i <= Y; i++)info[i].init();

		for(int i = 0; i < X; i++){
			scanf("%d",&V[i]);
		}

		for(int i = 0; i < Z; i++){
			scanf("%d %d %d",&N,&E,&A);
			info[N].event = event[E];
			info[N].value = A;
		}

		for(int i = 0; i <= Y; i++){
			for(int k = 0; k <= Z*100; k++)dp[i][k] = 0.0;
		}

		dp[0][0] = 1.0;

		for(int masu = 0; masu <= Y-1; masu++){
			for(int score = 0; score <= Z*100; score++){
				if(dp[masu][score] == 0.0)continue;

				for(int dice = 0; dice < X; dice++){

					if(masu + V[dice] > Y){
						next_masu = Y;
					}else{
						next_masu = masu + V[dice];
					}

					if(info[next_masu].event == None){

						dp[next_masu][score] += dp[masu][score]/(double)(X);

					}else if(info[next_masu].event == Move_On){

						if(next_masu + info[next_masu].value > Y){
							next_masu = Y;
						}else{
							next_masu = next_masu + info[next_masu].value;
						}
						dp[next_masu][score] += dp[masu][score]/(double)(X);

					}else if(info[next_masu].event == Get){

						dp[next_masu][score+info[next_masu].value] += dp[masu][score]/(double)(X);

					}else{ //info[next_masu].event == Lose

						if(score < info[next_masu].value){

							dp[next_masu][0] += dp[masu][score]/(double)(X);

						}else{

							dp[next_masu][score-info[next_masu].value] += dp[masu][score]/(double)(X);
						}
					}
				}
			}
		}

		ans = 0;

		for(int i = 0; i <= Z*100; i++){
			ans += (double)i*dp[Y][i];
		}

		printf("%.0f\n",floor(ans));

	}

	return 0;
}

Measured memory_bytes: 4592
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

int main(){
	int duration;
	while(~scanf("%d",&duration)){
		if(duration == 0) break;
		int n;
		scanf("%d",&n);

		int sum = 0;
		for(int i=0;i<n;i++){
			int a,b;
			scanf("%d %d",&a,&b);
			sum += b - a;
		}

		if(sum >= duration) printf("OK\n"); 
		else printf("%d\n",duration - sum); 
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,cnt = 0;
  cin >> a >> b;
  c = 1;
  while(true){
    if(c<b){
      c += a-1;
      cnt++;
    }else{
     break; 
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}
const ll MOD = 1000000007LL;
const int MAX = 1e5 + 1;

struct Combinations {

  long long mod;
  vector<long long> inv;
  vector<long long> fact;
  vector<long long> inv_fact;

  Combinations(int n, long long m) : inv(n), fact(n), inv_fact(n), mod(m) {
    inv[1] = 1;
    for (long long i = 2; i < n; i++) {
      inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    }
    fact[0] = inv_fact[0] = 1;
    for (long long i = 1; i < n; i++) {
      fact[i] = (fact[i - 1] * i) % mod;
      inv_fact[i] = (inv_fact[i - 1] * inv[i]) % mod;
    }
  }

  long long nPr(long long n, long long r) {
    if (n < r)
      return 0;
    return fact[n] * inv_fact[n - r] % mod;
  }

  long long nCr(long long n, long long r) {
    if (n < r)
      return 0;
    return nPr(n, r) * inv_fact[r] % mod;
  }

  long long nHr(long long n, long long r) { return nCr(n + r - 1, r); }
};

void solve(long long n, vector<long long> a) {
  Combinations inst(200010, MOD);

  map<ll, int> M;
  int r, l;
  r = l = -1;

  REP(i, n + 1) {
    if (M[a[i]] > 0) {
      r = i;
      l = M[a[i]] - 1;
      break;
    }
    M[a[i]] = i + 1;
  }

  // cerr << n << " " << r << " " << l << endl;

  FOR(i, 1, n + 2) {
    ll ans = inst.nCr(n + 1, i) - inst.nCr(n - r + l, i - 1) + MOD;
    // cerr << inst.nCr(n + 1, i) << " " << inst.nCr(n - r + l, i - 1) << endl;
    ans %= MOD;
    cout << ans << endl;
  }
}

int main() {
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<long long> a((n + 1) - 1 + 1);
  for (int i = 0; i <= (n + 1) - 1; i++) {
    cin >> a[i];
  }
  solve(n, a);
  return 0;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll largest_element(ll n)
{
	if(n==1)
		return 1;
	ll low=0;
	ll high=n;
	while(low<high)
	{
		ll mid = low + (high - low)/2;
		if(mid*(mid+1)/2 >=  n)
		{
			high = mid;
		}
		else
		{
			low = mid+1;
		}
	}
	return low;
}
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n;
	cin>>n;
	while(n>0)
	{
		cout<<largest_element(n)<<'\n';
		n-=largest_element(n);
	}
}

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

int main(){
	
	int a, b, c, d, n;
	int i;
	int cnt;

	while (cin >> n) {
		cnt = 0;
		for (a = 0; a <= 9; a++) {
			for (b = 0; b <= 9; b++) {
				for (c = 0; c <= 9; c++) {
					for (d = 0; d <= 9; d++) {
						if (a + b + c + d == n) {
							cnt++;
						}
					}
				}
			}
		}
		printf("%d\n", cnt);
	}
	return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

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

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


int main() {
  int N;
  cin >> N;
  vector< int > A(N);
  cin >> A;

  int x = 0;
  for(auto &p : A) x += p & 1;
  if(x == N || x == 0) cout << 0 << endl;
  else if(x % 2) cout << N - 1 << endl;
  else cout << N - 2 << endl;
}



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

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        int A = int.Parse(inputs[0]);
        int B = int.Parse(inputs[1]);

        int count = 0;
        for(int i = 0; i < 2; i++)
        {
            if(A < B)
            {
                count += B;
                B--;
            }else {
                count += A;
                A--;
            }
        }

        Console.WriteLine(count);
    }

}



Measured memory_bytes: 11092
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n, m, l, i, j, k;
  cin >> n >> m >> l;
  vector<vector<int> > A(n, vector<int>(m, 0));
  vector<vector<int> > B(m, vector<int>(l, 0));
  vector<vector<long long> > C(n, vector<long long>(l, 0));

  for (i=0; i<n; i++) {
    for (j=0; j<m; j++) {
      cin >> A.at(i).at(j);
    }
  }

  for (i=0; i<m; i++) {
    for (j=0; j<l; j++) {
      cin >> B.at(i).at(j);
    }
  }
  
  for (i=0; i<n; i++) { // 3
    for (j=0; j<l; j++) { // 3
      for (k=0; k<m; k++) { // 2
        C.at(i).at(j)+=A.at(i).at(k)*B.at(k).at(j);
      }
    }
  }

  for (i=0; i<n; i++) {
    for (j=0; j<l; j++) {
      cout << C.at(i).at(j);
      if (j<l-1) cout << " ";
      else cout << endl;
    }
  }
}


Measured memory_bytes: 3184
#define REP(i, n) for(int i = 0; i < (int)n; ++i)
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<algorithm>

using namespace std;

string ogrid[50];
string grid[50];
void solve() {
    int h, w;
    vector<char> types;
    set<char> st;
    cin >> h >> w;
    REP(i, h) {
        cin >> ogrid[i];
    }
    REP(i, h) REP(j, w) {
        if (ogrid[i][j] != '.' && st.find(ogrid[i][j]) == st.end()) {
            st.insert(ogrid[i][j]);
            types.push_back(ogrid[i][j]);
        }
    }
    sort(types.begin(), types.end());
    bool safe = false;
    do {
        REP(i, h) grid[i] = ogrid[i];
        bool allok = true;
        // REP(i, types.size()) cout << types[i] << "\t";
        // cout << endl;
        for(auto ti : types) {
            bool ok = true;
            int l = w, r = -1, t = h, b = -1;
            REP(i, h) REP(j, w) {
                if (grid[i][j] == ti) {
                    l = min(l, j);
                    r = max(r, j);
                    t = min(t, i);
                    b = max(b, i);
                }
            }
            REP(i, h) REP(j, w) {
                if (!ok) break;
                if (grid[i][j] == '?') continue;
                if (grid[i][j] == ti) {
                    if (!(i >= t && i <= b && j >= l && j <= r)) {
                        ok = false;
                    }
                        grid[i][j] = '?';
                } else {
                    if (i >= t && i <= b && j >= l && j <= r) ok = false;
                }
            }
            allok &= ok;
            if (!allok) {
            // cout << ti << endl;
            break;
            }
        }
        if (allok) {
            safe = true;
            break;
        }
    } while (next_permutation(types.begin(), types.end()));
    cout << (safe ? "SAFE" : "SUSPICIOUS") << endl;

}
int dddd;
int main() {
    cin >> dddd;
    REP(hoge, dddd) {
        solve();
    }
}


Measured memory_bytes: 3172
#include<iostream>
#include<cstring>
#include<cstdio>
#include<iomanip>
#include<algorithm>
using namespace std;
long long a[200005],n;
int t=0;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template <class T>
inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    char A = a[0] - 'a' + 'A';
    char B = b[0] - 'a' + 'A';
    char C = c[0] - 'a' + 'A';
    cout << A << B << C << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int s=0;
    s=min(a,k);
    if(s==k)
        cout<<s;
    else{
        k=k-a;
        k=k-b;
        if(k<=0)
            cout<<s;
        else{
            s-=min(c,k);
            cout<<s;
        }
    }
    cout<<"\n";
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <iostream>

using namespace std;

int d[10][10000];

int main()
{
	while(1)
	{
		int r,c;
		scanf("%d%d",&r,&c);
		if(r == 0 && c == 0)
		{
			break;
		}
		for(int i = 0; i < r; i++)
		{
			for(int ii = 0; ii < c; ii++)
			{
				scanf("%d",&d[i][ii]);
			}
		}
		int maxw = 0;
		for(int i = 0; i < (1 << r); i++)
		{
			int now = 0;
			for(int ii = 0; ii < c; ii++)
			{
				int w = 0;
				for(int j = 0; j < r; j++)
				{
					if(0 == (i & (1 << j)))
					{
						if(d[j][ii] == 0)
						{
							w++;
						}
					}
					else
					{
						if(d[j][ii] != 0)
						{
							w++;
						}
					}
				}
				now += max(w,r - w);
			}
			maxw = max(maxw,now);
		}
		printf("%d\n",maxw);
	}
	return 0;
}

Measured memory_bytes: 1572
#include <iostream>

using namespace std; 

int main(void) {
	int N,X;
	cin >> N >> X;
	int now = 0;
	int count = 1;
	for (int i = 0; i < N; ++i) {
		int L;
		cin >> L;
		now += L;
		if (now <= X) {
			++count;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int N;
  cin >> N;
  vector<int> a(3 * N);
  for (int i = 0; i < 3 * N; i++)
  {
    cin >> a.at(i);
  }

  sort(a.begin(), a.end(), greater<int>());

  int ans = 0;
  for (int i = 1; i < 2 * N; i += 2)
  {
    ans += a.at(i);
  }

  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)    cerr<<#x<<" : "<<x<<endl;
#define trace2(x,y) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<" | "<<#z<<" : "<<z<<endl;
#define fast_io 	std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

using namespace std;//int cnt=0;
vi dfs(int u,vi &vis,vi &ret,vector<vi > &adj)
{
	if(vis[u]==1)return ret;
	vis[u]=1;
	ret.pb(u);
	for(auto v:adj[u])
	{
		if(vis[v])continue;
		dfs(v,vis,ret,adj);
	}
	return ret;	
}

int main()
{
	fast_io;
	int n,m;
	cin>>n>>m;
	vi a(n+1);vi ind(n+1);
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		//scanf("%d",&a[i]);
		ind[a[i]]=i;
	}
	vector<vi > adj(n+1);
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		//scanf("%d %d",&x,&y);trace2(x,y)
		x=a[x];y=a[y];
		adj[x].pb(y);
		adj[y].pb(x);
	}
	vi vis(n+1,0);
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(vis[i]==0)
		{
			vi ret;
			vi temp=dfs(i,vis,ret,adj);
			unordered_map<int,int> m;
			for(int j=0;j<ret.size();j++)
			{
				m[ind[ret[j]]]++;//trace2(ret[j],ind[ret[j]])
			}
			for(int j=0;j<ret.size();j++)
			{
				if(m[ret[j]])ans++;//trace2(i,ret[j])
			}
		}
	}
	cout<<ans;
	//cerr<<1.0*clock()/CLOCKS_PER_SEC;
	return 0;
}

Measured memory_bytes: 18940
/*selection sort*/
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
    int i,j,k,cnt;
    cin>>k;
    int a[k];
    for(i=0;i<k;i++){
        cin>>a[i];
    }
    cnt = 0;
    for(i=0;i<k;i++){
        int m = i;
        for(j=i;j<k;j++){
            if(a[j]<a[m]){
                m = j;
            }
        }
        swap(a[i],a[m]);
        if(i!=m)cnt++;

    }
    cout << a[0];
    for(i=1;i<k;i++){
        cout << " " << a[i] ;
    }
    cout<<endl<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

bool check(int n)
{
  if(n%2==1){
    int m = 0;
    for(int i=0;i<n;i++){
      if(n%(i+1)==0)m++;
    }
    if(m==8){return true;}else{return false;}
  }else{return false;}
}

int main(){
  int n,m;
  m = 0;
  scanf("%d",&n);
  
  for(int i=0;i<n;i++){
    if(check(i+1))m++;
  }
  
  printf("%d",m);
  return 0;
}

Measured memory_bytes: 128
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

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

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
    if (ib == ie) {
        ib = ibuf;
        ie = ibuf + fread(ibuf, 1, BUFF, stdin);
    }
    return ib == ie ? -1 : *ib++;
}

}

LL read() {
    using namespace _buff;
    LL ret = 0;
    bool pos = true;
    char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

int main() {
    int k = read();
    if (k == 1) {
        puts("1\n");
        puts("1");
    } else {
        int n = (k + 3) >> 2 << 1;
        cout << n << '\n';
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                int a = (i + j) % n + 1;
                if (i & 1) a += n;
                if (a > k) a -= n;
                printf("%d ", a);
            }
            putchar('\n');
        }
    }
    return 0;
}


Measured memory_bytes: 1152
#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;

llong n, k, s;
llong c = 1e9;

int main() {
    cin >> n >> k >> s;

    for (int i = 0; i < k; i++) {
        cout << s << ' ';
    }
    for (int i = 0; i < n - k; i++) {
        if (s == c) cout << s - 1 << ' ';
        else cout << s + 1 << ' ';
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1280
x,k,d =map(int, input().split())

if x >0:
  cnt = x // d
  if cnt <= k:
    if (k - cnt) % 2 == 0:
      ans = x%d
    else:
      ans = abs(x%d - d)
  else:
    ans = abs(x - k*d)
elif x < 0:
  cnt = abs(x) // d
  if cnt <= k:
    if (k - cnt) % 2 == 0:
      ans = abs(x + d*cnt)
    else:
      ans = abs(x + d*(cnt+1))
  else:
    ans = abs(x + k*d)
else:
  if k%2 == 0:
    ans = 0
  else:
    ans = d
print(ans)

Measured memory_bytes: 9216
N = int(input())
takahashi = 1
aoki = 1
for i in range(N):
  T, A = map(int,input().split())
  n = max((takahashi + T - 1) // T, (aoki + A - 1) // A)
  takahashi = n*T
  aoki = n*A
print(takahashi+aoki)


Measured memory_bytes: 70988
#include <iostream>
using namespace std;
// 再帰関数
static void Sub_QuickSort(int* pnData, int nFirst, int nLast);

// クイックソート
void QuickSort(int* pnData, int nNumOf)
{
    Sub_QuickSort(pnData, 0, nNumOf - 1);
}

// 再帰関数
// nFirst : ブロックの最初のインデックス
// nLast  : ブロックの最後のインデックス
static void Sub_QuickSort(int* pnData, int nFirst, int nLast)
{
    int iLess    = nFirst;  // 前半のインデックス
    int iGreater = nLast;   // 後半のインデックス
    int x;                  // 「ある値」

    // 「ある値」は両端の要素の平均値にする
    x = (pnData[nFirst] + pnData[nLast]) / 2;

    // 交換ループ
    // 位置が逆になると終了
    while(iLess < iGreater)
    {
        // x より小さい要素は無視
        while(pnData[iLess] < x)
            iLess++;
        // x より大きい要素は無視
        while(pnData[iGreater] > x)
            iGreater--;

        // 位置がちゃんとしているときは交換し、
        // iLess と iGreater を１つずつ進める
        if(iLess < iGreater)
            swap(pnData[iLess++], pnData[iGreater--]);
    }
    // iLess == iGreater で終わった時は、
    // iGreater < iLess になるようにする
    if(iLess == iGreater)
    {
        if(pnData[iLess] < x)
            iLess++;
        else if(pnData[iLess] > x)
            iGreater--;
    }

    // 次のブロックのサイズが２以上の時は再帰
    if(iLess >= nFirst + 2)
        Sub_QuickSort(pnData, nFirst, iLess - 1);
    if(iGreater <= nLast - 2)
        Sub_QuickSort(pnData, iGreater + 1, nLast);
}
int main(){
  int n, m;
  int x[100000], l[100000];
  cin >> n >> m;
  for(int i=0; i<m; i++)cin >> x[i];

  if(m==1){
    cout << "0" << endl;
    return 0;
  }
  
  QuickSort(x, m);
    
  for(int i=0; i<m-1; i++){
    l[i]=x[i+1]-x[i];
  }
   
  QuickSort(l, m-1);
  int sum=0;
 
  for(int i=0; i<m-n; i++){
    sum += l[i];
  }
  
  cout << sum << endl;
  return 0;
}

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

int main(){
    int s1, s2, s3;
    scanf("%d/%d/%d", &s1, &s2, &s3);
    if(s1 < 2019){
        cout << "Heisei" << endl;
    }else{
        if(s2 < 4 || (s2 == 4 && s3 <= 30)){
            cout << "Heisei" << endl;
        }else{
            cout << "TBD" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int N;
  cin >> N;
  int hh,nn,ww;
  erep1(h,3500){
    erep1(n,3500){
      if(4*n*h > (n+h)*N){
        if(n*h*N % (4*n*h - (n+h)*N) == 0){
          nn = n;
          hh = h;
          ww = n*h*N / (4*n*h - (n+h)*N);
          break;
        }
      }
    }
  }
  cout << hh << " " << nn << " " << ww << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int A, B, C, D;
  cin>>A>>B>>C>>D;

  Int turn = 0;
  while(A > 0 && C > 0){
    if(turn == 0) C -= B;
    else A -= D;
    turn = !turn;
  }
  cout<<(turn? "Yes":"No")<<endl;

  return 0;
}


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

using ll=long long;



void solve(){
    string s;
    cin>>s;
    int cnt=0;
    for(auto c:s){
        if(c=='+'){
            cnt++;
        }else{
            cnt--;
        }
    }  
    cout<<cnt<<endl;
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N,M;
		N =sc.nextInt();
		M =sc.nextInt();
		int a[] = new int[N];
		int count =0;
		int total=0;
		for (int i=0;i<N;i++) {
			a[i] =sc.nextInt();
			total+=a[i];
		}
		for (int i=0;i<N;i++) {
			if (a[i]*4*M>=total) {
				count ++;
			}
		}


		if (count >=M) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    string s;
    int ac=0,wa=0,tl=0,re=0;
    while(t--){
        cin>>s;
        if(s=="AC") ac++;
        else if(s=="WA")wa++;
        else if(s=="TLE")tl++;
        else if(s=="RE")re++;
    }
    cout<<"AC x "<<ac<<"\nWA x "<<wa<<"\nTLE x "<<tl<<"\nRE x "<<re<<endl;
}


Measured memory_bytes: 3588
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
using namespace std;

unsigned long long int f(unsigned long long n, unsigned long long x){
  if(n==-1) return 0;
  else return (n/x+1);
}
int main(){
unsigned long long  a,b,x; cin >>a>>b>>x;

if(a==b && a%x==0) {cout<<1<<endl; return 0;}

cout<<f(b,x)-f(a-1,x)<<endl;
}


Measured memory_bytes: 256
//

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

ll A[200000];
map<ll, ll> ball_count;
map<ll, ll> comb;

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

	for (int i=0; i<N; i++) {
		cin >> A[i];
		ball_count[A[i]]++;
	}

	ll comb_total = 0;
	for (auto itr=ball_count.begin(); itr!=ball_count.end(); itr++) {
		ll ball_n = itr->first;
		ll ball_c = itr->second;
		ll c = ball_c * (ball_c - 1) / 2;
		comb[ball_n] = c;
		comb_total += c;
	}

	ll ans;
	for (int i=0; i<N; i++) {
		ll ball_c = ball_count[A[i]];
		ll c = (ball_c - 1) * (ball_c - 2) / 2;
		ans = comb_total - comb[A[i]] + c;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 18944
#include<bits/stdc++.h>
using namespace std;
int main()
{
  list<char> S;
  string A;
  cin >> A;
  for(int i=0; i<A.size(); i++){
    if(A.at(i)=='0'){
      S.push_back('0');
    }
    else if(A.at(i)=='1'){
      S.push_back('1');
    }
    else if(A.at(i)=='B'){
      if(S.size()!=0)
        S.pop_back();
    }
  }
  for(list<char>::iterator it=S.begin(); it!=S.end(); it++){
    cout << *it;
  }
  cout << endl;
}


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

void prians(bool answer) {
  if(answer)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
string s[2];

int main() {
  cin >> s[0] >> s[1];
  prians(s[0][0] == s[1][2] && s[0][1] == s[1][1] &&
         s[0][2] == s[1][0]);
  return 0;
}

Measured memory_bytes: 256
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let m = sc.read();
    let mut l_max = 0;
    let mut r_min = 1 << 30;
    for _ in 0..m {
        let l = sc.read();
        let r = sc.read();
        l_max = std::cmp::max(l, l_max);
        r_min = std::cmp::min(r, r_min);
    }
    if l_max <= r_min {
        println!("{}", r_min - l_max + 1);
    } else {
        println!("{}", 0);
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8572
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l
　 　　　／` ミ＿x ノ   Zzz..
　　 　 /　 　 　 |   コード見ちゃだめ！！
　　　 /　 ヽ　　  ﾉ
　 　 │　　|　|  |
　／￣|　　 |　|  |
　| (￣ヽ＿_ヽ_)_ _)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define REP(i, n) for (int i = 0; i < n; i++)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

int main() {
  int n, k, r, s, p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;

  // rがグー、sがチョキ、pがパー
  map<char, ll> win;
  win['r'] = p;
  win['p'] = s;
  win['s'] = r;

  vector<vector<ll>> dp(101010, vector<ll>(3, 0));

  ll ans = 0;

  for (int i = 0; i < n; i++) {
    if (i < k)
      ans += win[t[i]];
    else if (t[i] != t[i - k])
      ans += win[t[i]];
    else
      t[i] = '0';
  }
  cout << ans << endl;
}


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

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

vector<vector<pair<int, ll>>> eda(100000 + 5); // pair には num, dist
vector<ll> dist(100000 + 5);

void makeCost(int n, int k)
{
  queue<pair<pair<int,ll>, int>> q; // pair には ((num, dist) from)
  dist[k] = 0;
  for (auto a : eda[k]) {
    q.push(make_pair(a, k));
  }

  while (!q.empty()) {
    auto now = q.front();
    q.pop();
    int number = now.first.first;
    int from = now.second;
    ll distance = now.first.second;
    dist[number] = dist[from] + distance;
    for (auto tmp : eda[number]) {
      if (tmp.first == from) continue;
      q.push(make_pair(tmp, number));
    }
  }
}

int main()
{
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    eda[a].push_back(make_pair(b, c));
    eda[b].push_back(make_pair(a, c));
  }

  int q, k;
  cin >> q >> k;

  makeCost(n, k);

  rep (i, q) {
    int x, y;
    cin >> x >> y;
    cout << dist[x] + dist[y] << endl;
  }
}



Measured memory_bytes: 13560
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAXN = 100000;
const int MAXK = 100000;
const int nullvalue = -12345678;
typedef long long LL;
vector<pair<int, int>> edgelist;
vector<int> adj[MAXN + 1];

bool visited[MAXN + 1];
int ancestor[MAXN + 1];
int possible[MAXN + 1];
int n, k;
void dfs(int u){
	visited[u] = true;
	for (int v : adj[u]){
		if (not visited[v]){
			ancestor[v] = u;
			dfs(v);
		}
	}
}

void bfs(){
	memset(visited, 0, sizeof visited);
	for (int i = 0; i < MAXK + 1; i++){
		possible[i] = nullvalue;
	}
	possible[1] = k;
	visited[1] = true;
	visited[0] = true;

	queue<int> frontier;
	int temp_k = k - 1;
	for (int v : adj[1]){		
		possible[v] = temp_k;
		--temp_k;
		frontier.push(v);
	}

	while (not frontier.empty()){
		int u = frontier.front(); frontier.pop();
		visited[u] = true;
		if (adj[u].size() <= 2){
			if (possible[u] == nullvalue){
				possible[u] = k - 2;
			}
			for (int v : adj[u]){
				if (not visited[v]){
					frontier.push(v);
				}
			}
		}
		else{
			int temp_k = k - 2;
			if (possible[u] == nullvalue){
				possible[u] = k - 2;
			}
			for (int v : adj[u]){
				if (not visited[v]){
					possible[v] = temp_k;
					--temp_k;
					frontier.push(v);
				}
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> k;
	for (int i = 0; i < n - 1; i++){
		int a, b; cin >> a >> b;
		edgelist.push_back(make_pair(a, b));
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	adj[0].push_back(1);
	adj[1].push_back(0);
	memset(visited, 0, sizeof visited);
	dfs(1);
	LL ans = 1;
	bfs();
	for (int i = 1; i <= n; i++){
		cerr << possible[i] << ' ';
		ans *= possible[i]; ans %= MOD;
	}
	if (ans < 0) ans = 0;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9716
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int main(void)
{
  int N, T;
  vector< int > c(100), t(100);
  cin >> N >> T;
  for (int i = 0; i < N; i++) {
    cin >> c[i] >> t[i];
  }

  int ans = 2000;
  for (int i = 0; i < N; i++) {
    if (c[i] < ans && t[i] <= T) {
      ans = c[i];
    }
  }
  if (ans == 2000) {
    cout << "TLE" << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (input) {
    //??\????????????????????????????????????
    var inputArray = input.split(' ');
    //??\?????????????????°????????????
    var num = inputArray.map(function(x){
        return parseInt(x);
    });

var W = num[0];
var H = num[1];
var x = num[2];
var y = num[3];
var r = num[4];
var answer = 'Yes';
if(((x+r) > W) || ((x-r) < 0) || ((y+r) > H) || ((y-r) < 0)){
    answer = 'No';
}
console.log(answer);
});

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

int main() {
	bool check = false;
	int N, A;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A;
		if (A % 2 == 1) check = true;
	}
	if (check) cout << "first";
	else cout << "second";
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
    int n,cnt=0;
    char a[100],b[100],c[100];
    scanf("%d",&n);
    scanf("%s",a);
    scanf("%s",b);
    scanf("%s",c);
    for(int i=0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            if(b[i]==c[i])
            {
                
            }else{
                cnt++;
            }
        }else{
            if(b[i]==c[i])
            {
                cnt++;
            }else{
                if(a[i]==c[i])
                {
                    cnt++;
                }else{
                    cnt+=2;
                }
            }
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 1676