akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
from math import floor

def solve():
    h, w = map(int, input().split())
    word_dict = dict(Counter(list("".join([input() for _ in range(h)]))))

    g1 = (w % 2) & (h % 2)
    g2 = floor((w % 2) * h/2) + floor((h % 2) * w/2)
    g4 = floor(h/2) * floor(w/2)
    
    for k, v in word_dict.items():
        if g1 == 0:
            break
        if v % 4 == 1 or v % 4 == 3:
            g1 -= 1
            word_dict[k] -= 1
            v -= 1
            
    for k, v in word_dict.items():
        if g4 == 0:
            break
        while v >= 4:
            g4 -= 1
            word_dict[k] -= 4
            v -= 4

    for k, v in word_dict.items():
        if g2 == 0:
            break
        while v >= 2:
            g2 -= 1
            word_dict[k] -= 2
            v -= 2
            
    print("No" if [1 for v in word_dict.values() if v != 0] else "Yes")
    
if __name__=="__main__":
    solve()


Measured memory_bytes: 39280
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int  a;
	cin>>a;
	cout<<48-a<<endl;
	return 0;
}


Measured memory_bytes: 384
N=int(input())
S = [0]*N
for i in range(N):
    S[i]=str(input())
    
print('AC x {0}'.format(S.count('AC')))
print('WA x {0}'.format(S.count('WA')))
print('TLE x {0}'.format(S.count('TLE')))
print('RE x {0}'.format(S.count('RE')))

Measured memory_bytes: 16008
def count_possible_pairs(N, K):
  if K == 0:
    return N**2
  else:
    cnt = 0      
    for b in range(K+1, N+1):
      block = (N+1) // b
      cnt += block * (b - K)    # remainders are K, K+1, ..., b-1
      res = (N+1) % b
      if res > K:
        cnt += (res - K)
    return cnt




N, K = map(int, input().split())
print(count_possible_pairs(N, K))


Measured memory_bytes: 38640
#include<iostream>

int main(){

    size_t a, b, c;
    std::cin >> a >> b >> c;

    size_t cnt = 0;
    for(size_t i = a; i <= b; i++){
        if(c % i == 0) cnt++;
    }

    std::cout << cnt << std::endl;

    return 0;
}



Measured memory_bytes: 3112
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int, input().split()))

    dic = {}
    for t in a:
        if t in dic:
            dic[t] += 1
        else:
            dic[t] = 1
    
    ans = 0
    for num, count in dic.items():
        if num > count:
            ans += count
        elif num < count:
            ans += count - num
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 17704
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP2D(a, n, m) REP(i, n) REP(j, m) printf("%lld%c", a[i][j], j + 1 == m ? '\n' : ' '); puts("")
#define ITR(c,it)  for(auto it = c.begin(); it != c.end(); it++)
#define COLOR(c, i) (c >> (10 * (3 - (i))) & 1023)

typedef long long ll;

const int N_MAX = 400;

int N;
ll C[N_MAX][4];

int M;
ll h[N_MAX];
map<ll, ll> par;
map<ll, ll> tb;
map<ll, ll> crd;

char buf[64];
char buf2[64];

char *dumpC(ll c, char * buf) {
  snprintf(
    buf,
    64,
    "%lld-%lld-%lld-%lld",
    COLOR(c, 0),
    COLOR(c, 1),
    COLOR(c, 2),
    COLOR(c, 3)
  );
  return buf;
}

ll perm(ll n, ll k) {
  if (n < 0 || k < 0 || n < k) return 0;
  ll ret = 1;
  REP(i, k) ret = ret * (n - i);
  return ret;
}

void solve() {
  REP(i, N) {
    ll c = 0;
    REP(d, 4) c = c << 10 | C[i][d];
    ll cs[4];
    REP(d, 4) {
      cs[d] = c;
      c = (c << 10 | c >> 30) & ((1LL << 40) - 1);
    }
    c = *min_element(cs, cs + 4);
    tb[c]++;
    crd[c] = count(cs, cs + 4, c);
    REP(d, 4) par[cs[d]] = c;
  }

  M = 0;
  ITR(tb, it) h[M++] = it->first;

  // ITR(par, it) {
  //   ll c = it->first, p = it->second;
  //   printf("par[%s]: %s\n", dumpC(c, buf), dumpC(p, buf2));
  // }
  // ITR(tb, it) {
  //   ll c = it->first;
  //   printf("tb[%s]: %lld\n", dumpC(c, buf), it->second);
  // }
  // ITR(crd, it) {
  //   ll c = it->first;
  //   printf("crd[%s]: %lld\n", dumpC(c, buf), it->second);
  // }

  ll ans = 0;
  REP(i, M) REP(j, M) {
    ll hi = h[i], hj = h[j];
    if (i == j && tb[hi] <= 1) continue;
    // printf("i: %d(%s), j: %d(%s)\n", i, dumpC(hi, buf), j, dumpC(hj, buf2));
    map<ll, ll> tbh;
    tbh[hi]++; tbh[hj]++;
    ll pth = tb[hi] * (tb[hj] - (i == j ? 1 : 0));
    // printf("pth: %lld * %lld = %lld\n", tb[hi], tb[hj] - (i == j ? 1 : 0), pth);
    REP(k, 4) {
      // printf(" k: %d\n", k);
      bool ok = true;
      map<ll, ll> tbs;
      REP(d, 4) {
        ll s = 0;
        s |= COLOR(hi, (1 + d) % 4) << 30;
        s |= COLOR(hi, d % 4) << 20;
        s |= COLOR(hj, (4 - d + k) % 4) << 10;
        s |= COLOR(hj, (3 - d + k) % 4);
        if (par.count(s) == 0) {
          ok = false;
          break;
        }
        tbs[par[s]]++;
      }
      if (!ok) continue;
      ll pts = 1;
      ITR(tbs, it) {
        ll s = it->first;
        ll use = it->second;
        ll cmp = perm(tb[s] - tbh[s], use);
        REP(i, use) cmp *= crd[s];
        // if (cmp != 0) {
        //   printf("  s: %s, avail: %lld, use: %lld, crd: %lld, cp: %lld\n",
        //     dumpC(s, buf), tb[s] - tbh[s], use, crd[s], cmp);
        // }
        pts *= cmp;
      }
      // if (pts != 0) printf(" pts: %lld\n", pts);
      ans += pts * pth;
    }
  }

  printf("%lld\n", ans / 6);
}

void input() {
  scanf("%d", &N);
  REP(i, N) REP(j, 4) scanf("%lld", &C[i][j]);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <vector>
#define rep(i,n) for (int i = 0; i < n; ++1)
using namespace std;
int main(){
int a,b,c;
cin >> a >> b >> c;
if (a < b && b < c) {
cout << "Yes"<<endl;
}
else {
cout << "No"<<endl;
}
return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
typedef pair<int,int> P;
typedef long long ll;
ll n,m,k,ans;
string s,t;

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

  ll s[n+1] = {};
  rep(i,n) s[a[i]]++;
  ll sum = 0;
  rep(i,n+1){
    if(s[i]) sum += s[i]*(s[i]-1)/2;
  }
  rep(i,n){
    ll tmp = 0;
    if(s[a[i]] > 0) tmp = - s[a[i]]*(s[a[i]]-1)/2 + (s[a[i]]-1)*(s[a[i]]-2)/2;
    cout << sum + tmp << "\n";
  }
}

Measured memory_bytes: 4864
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<assert.h>
using namespace std;
typedef long long LL;
char s[100];
const int N = 105;
const int M = 100050;
const int inf = (int)1e9+2;
struct node{
    int a,b,c;
    void read(){
        scanf("%s%d%s%d",s,&a,s,&b);
        if(s[0]=='S') c=0;
        else c=1;
    }
    bool operator <(const node tmp)const{
        if(c!=tmp.c) return c<tmp.c;
        return b*tmp.a>tmp.b*a;
    }
    void print(){
        cout<<a<<" "<<b<<" "<<c<<endl;
    }
}no[N];
int val[N],n,m;
LL opt[M],dp[M];
int main()
{
    while(scanf("%d",&n),n)
    {
        for(int i=1;i<=n;++i)
            scanf("%d",val+i);
        scanf("%d",&m);
        for(int i=1;i<=m;++i)
            no[i].read();
        sort(no+1,no+1+m);
//        for(int i=1;i<=m;++i)
//            no[i].print();
        int al;
        for(al=1;al<=m;++al)
            if(no[al].c==1) break;
        for(int i=0;i<M;++i){
            opt[i]=inf;opt[0]=0;
            for(int j=1;j<al;++j){
                int pi=i-no[j].b;
                if(pi<0) pi=0;
                if(opt[i]>opt[pi]+no[j].a)
                    opt[i]=opt[pi]+no[j].a;
            }
        }
        LL ans=inf;
        for(int i=0;i<M;++i)
        {
            dp[i]=inf; dp[0]=0;
            for(int j=al;j<=m;++j){
                int pi=i-no[j].b;
                if(pi<0) pi=0;
                if(dp[i]>dp[pi]+no[j].a)
                    dp[i]=dp[pi]+no[j].a;
            }
            LL tmp=dp[i];
            for(int j=1;j<=n;++j){
                int nv=val[j]-i;
                if(nv<0) nv=0;
                tmp+=opt[nv];
            }
            if(ans>tmp) ans=tmp;
        }
        if(ans>=inf) assert(0);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 2800
#include<bits/stdc++.h>
using namespace std;
#define Elhabashy ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void input()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
}
const int N=1e6+2,mod=1e9+7;
typedef long long ll;
ll n,dp[N][2][2];
ll solve(int i=1,bool f1=0,bool f2=0){
    if(i>n){
        if(f1&&f2)return 1;
        return 0;
    }
    ll &ret=dp[i][f1][f2];
    if(~ret)return ret;
    ret=0;
    for(int j=0;j<=9;j++){
        if(j==0)
            ret+=solve(i+1,1,f2);
        else if(j==9)ret+=solve(i+1,f1,1);
        else ret+=solve(i+1,f1,f2);
        ret%=mod;
    }
    return ret%mod;
}
int main(){
    Elhabashy
    input();
    cin>>n;
    memset(dp,-1,sizeof dp);
    cout<<solve()%mod<<endl;
}


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

int main(){
	string a;
	cin >> a;
	for (int i = a.size() - 1; i >= 0; i--){
		cout << a[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
///                    BISMILLAHIR RAHMANIR RAHIM
int main()
{
    string s,t;
    cin>>s >> t;
    int cnt=0;
    int n=s.length();
    for(int i=0;i<n;i++){
        if(s[i] != t[i]){
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

/// A L H A M D U L I L L A H


Measured memory_bytes: 3912
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)

//AB^2=AC^2+BC^2-2*AC*BC*COSC

signed main(){
    double A,B,H,M;
    cin>>A>>B>>H>>M;

    double Ha=H*360/12+M*360/12/60;
    double Ma=M*360/60;

    double ag=min(Ha-Ma,360-(Ha-Ma));

    //cout<<Ha<<","<<Ma<<","<<ag<<endl;

    printf("%.15f\n",sqrt(A*A+B*B-2*A*B*cos(ag/180.0*acos(-1.0))));
}



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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;
const ll INF = 1e6 + 2;


ll powmod(ll a, ll b){
    ll res = 1;
    while(b){
        if(b % 2) res = (res * a) % MOD;
        a = (a*a) % MOD;
        b /= 2;
    }
    return res;
}

ll inv(ll x){
    return powmod(x, MOD - 2) % MOD;
}

ll choose(ll n, ll r, vector<ll> &fact){
    return (((fact[n] * inv(fact[n - r])) % MOD) * inv(fact[r])) % MOD;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w, a, b;
    ll answer = 0;
    cin >> h >> w >> a >> b;
    
    vector<ll> fact(INF);
    fact[0] = 1;
    fact[1] = 1;
    for(int i = 2; i < INF; i++){
        fact[i] = (i * fact[i - 1]) % MOD;
    }
    
    for(ll i = b + 1; i <= w; i++){
        answer = (answer + choose(h - a - 1 + i - 1, i - 1, fact)*choose(a - 1 + w - i, w - i, fact)) % MOD;
    }
    cout << answer << "\n";
    
    return 0;
}

Measured memory_bytes: 11124
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9+5;
const ll INF=1e18+5;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  if(n%10==3) {
    cout << "bon" << endl;
  }
  else if(n%10==0||n%10==1||n%10==6||n%10==8) {
    cout << "pon" << endl;
  }
  else {
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void extended_euclid(ll x,ll y,ll *c,ll *a,ll *b){
  ll a0,a1,a2,b0,b1,b2,r0,r1,r2,q;r0=x;r1=y;a0=1;a1=0;b0=0;b1=1;
  while(r1>0){q=r0/r1;r2=r0%r1;a2=a0-q*a1;b2=b0-q*b1;r0=r1;r1=r2;a0=a1;a1=a2;b0=b1;b1=b2;}
  *c=r0;*a=a0;*b=b0;
}

ll get_inv(ll n, ll p){
  ll a,b,c;
  extended_euclid(n,p,&c,&a,&b);
  if(a<p) a+=p;
  return a%p;
}

ll fact[2000100],fact_inv[2000100];

void init() {
  fact[0]=1;
  REP(i,1,2000100) fact[i]=fact[i-1]*i%MAX;
  fact_inv[2000050]=get_inv(fact[2000050],MAX);
  rrep(i,2000050)fact_inv[i]=fact_inv[i+1]*(i+1)%MAX;
}

ll nCr(int N,int K){
  if(K<0||K>N)return 0;
  return fact[N]*fact_inv[K]%MAX*fact_inv[N-K]%MAX;
}

ll nHr(int N, int K){
  if(!N&&!K)return 1;
  if(!N)return 0;
  return nCr(N+K-1, K);
}

void Main() {
  init();
  ll n,m;
  cin >> n >> m;
  REP(i,1,m+1) {
    ll x=n-m;
    ll ans=nCr(m-1,i-1)*nCr(x-1,i-1)*2%MAX;
    ans+=nCr(m-1,i-1)*nCr(x-1,i)%MAX;
    ans+=nCr(m-1,i-1)*nCr(x-1,i-2)%MAX;
    if(x==0) {
      if(i==1) ans=1;
      else ans=0;
    }
    pr(ans%MAX);
  }
}

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


Measured memory_bytes: 31488
#include<stdio.h>
#include<string.h>
int main(){
  char str[10],str1[21];
  int i,n,cnt=0,l;
  scanf("%s",str);
  l=strlen(str);
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",str1);
    strncat(str1,str1,l-1);
    if(strstr(str1,str)!=NULL)cnt++;
  }
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 616
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n;
double p[3000],dp[3000][3000],ans;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    rep(i,1,n+1)
    cin>>p[i];
    dp[0][0]=1;
    rep(i,1,n+1)
    {
    	rep(h,0,i+1)
    	{
    		dp[h][i-h]=(h?p[i]*dp[h-1][i-h]:0)+(i-h?(1-p[i])*dp[h][i-h-1]:0);
    		if(i==n&&h>i-h)
    			ans+=dp[h][i-h];
    	}
    }
    printf("%0.12lf\n",ans);

}


Measured memory_bytes: 70016
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M; ll S;
ll C[55], D[55], Dist[int(2e5)];
vector <Pli> Graph[int(2e5)];

int main(){
  scanf("%d%d%lld", &N, &M, &S);
  for (int i = 0; i < M; i++){
    int U, V; ll A, B;
    scanf("%d%d%lld%lld", &U, &V, &A, &B);
    U--; V--;
    for (int j = A; j <= 2500; j++){
      Graph[2501 * U + j].push_back({B, 2501 * V + j - A});
      Graph[2501 * V + j].push_back({B, 2501 * U + j - A});
    }
  }
  for (int i = 0; i < N; i++) {
    scanf("%lld%lld", C + i, D + i);
    for (int j = 0; j <= 2500; j++){
      if (j + C[i] <= 2500) {
        Graph[2501 * i + j].push_back({D[i], 2501 * i + j + C[i]});
      }else{
        Graph[2501 * i + j].push_back({D[i], 2501 * i + 2500});
      }
    }
  }

  fill(Dist, Dist + int(2e5-1), -1);
  priority_queue <Pli, vector<Pli>, greater<Pli> > que;
  que.push({0, min(S, (ll)2500)});

  while (!que.empty()){
    Pli Q = que.top(); que.pop();
    if (Dist[Q.se] != -1) continue;
    Dist[Q.se] = Q.fi;
    for (int i = 0; i < Graph[Q.se].size(); i++){
      Pli next = Graph[Q.se][i];
      if (Dist[next.se] != -1) continue;
      que.push({Q.fi + next.fi, next.se});
    }
  }

  for (int i = 1; i < N; i++){
    ll ans = Dist[i * 2501];
    for (int j = 0; j <= 2500; j++){
      ans = min(ans, Dist[i * 2501 + j]);
    }
    printf("%lld\n", ans);
  }

  return 0;
}


Measured memory_bytes: 28232
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    vector<char> v(6);
    for (int i = 0; i < 6; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < 3; i++) {
        if (v[i] != v[5 - i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}




Measured memory_bytes: 3624
import bisect

n, m = map(int, input().split())

data = [[] for _ in range(n)]
query = []

for i in range(m):
    array = list(map(int, input().split()))
    query.append(array)
    a = array[0] - 1
    b = array[1]
    data[a].append(b)

cnt = 0
for i in data:
    i.sort()
    data[cnt] = i
    cnt += 1
    
for i, j in query:
    num = bisect.bisect_left(data[i-1], j) + 1
    x = str(i).zfill(6)
    y = str(num).zfill(6)
    z = str(x) + str(y)
    print(z)

Measured memory_bytes: 36672
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define rep(i,a,n) for(int i=(a);i<(n);i++)
using namespace std;

int main() {
	ll int n;
	cin >> n;
	string t = "MARCH";
	ll int sum[5] = { 0 };
	rep(i, 0, n) {
		string s;
		cin >> s;
		rep(j, 0, 5) if (s[0] == t[j])sum[j]++;
	}
	ll int ans = 0;
		rep(i, 0, 3) {
			rep(j, i + 1, 4) {
				rep(k, j + 1, 5) {
					ans += sum[i] * sum[j] * sum[k];
				}
			}
		}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll w, a, b;
    cin >> w >> a >> b;

    if(b+w < a) {
        out(a - (b+w));
    }
    else if(a+w < b) {
        out(b - (a+w));
    }
    else {
        out(0);
    }

    re0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let a: u64 = read();
    println!("{}", a + a * a + a * a * a);
}


Measured memory_bytes: 2112
#include <iostream>
#include <fstream>
#include <numeric>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <deque>
#include <bitset>
#include <cstring>
#include <sstream>
#include <complex>

#define f first
#define s second
#define ll long long
#define ld double
#define pb push_back
#define all(x) x.begin(),x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment
 
using namespace std;
 
double start_moment = 0;
double get_runtime() { return 1.0*clock()/CLOCKS_PER_SEC; }
void reset_timer() { start_moment = get_runtime(); }
double timer_time() { return get_runtime() - start_moment; }
void runtime(){cout<<fixed<<setprecision(5)<<get_runtime()<<'\n';}
 
typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;
 
template <class T>void read(vector<T> &a,ll n){T x; a.clear();for(ll i=0;i<n;i++){cin>>x;a.pb(x);}}
template <class T>void write(vector<T> &a){for(T x : a) cout<<x<<' ';cout<<'\n';}

string s,t;


int main()
{
    ios_base::sync_with_stdio(0);
//    freopen("INPUT.txt","r",stdin);
//    freopen("OUTPUT.txt", "w", stdout);
    
    int res=1342342;
    cin>>s>>t;
    for(int i=0;i+t.size()-1<s.size();i++)
    {
        int cnt=0;
        for(int j=0;j<t.size();j++)
            if(s[i+j]!=t[j])
                cnt++;
        res=min(res,cnt);
    }
    cout<<res;
    
    
}


Measured memory_bytes: 3148
n = int(input())
L = list(map(int,input().split()))
L.sort()

from collections import Counter
L = Counter(L)

cnt = 0
one = 0
for v in L.values():
    if v%2 ==0:
        cnt +=1
    else:
        one +=1
if cnt%2 == 0:
    one +=cnt
else:
    one +=(cnt-1)
print(one)

Measured memory_bytes: 21956
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int AB = sc.nextInt();
        int BC = sc.nextInt();
        int CA = sc.nextInt();
        
        int S = 0;
        if( AB * AB == BC * BC + CA * CA ) S = BC * CA / 2;
        if( BC * BC == CA * CA + AB * AB ) S = CA * AB / 2;        
        if( CA * CA == AB * AB + BC * BC ) S = AB * BC / 2;                
     
        System.out.println( S );   
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n,m,x,y,i,ans;
	cin>>n>>m>>x>>y;
	int xi[n],yi[m];
	for(i=0;i<n;i++)cin>>xi[i];
	for(i=0;i<m;i++)cin>>yi[i];
	sort(xi,xi+n);sort(yi,yi+m);
	int maxxi=max(x,xi[n-1]),minyi=min(yi[0],y);
//	cout<<maxxi<<" "<<minyi<<endl;
	if(maxxi<minyi)cout<<"No War";
	else cout<<"War"<<endl;
	
		
	return 0;
}

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

int N , M ;
long long ans ;
struct Data{
	long long a , b , c ;
	long long g ;
	bool operator < ( const Data &A ) const {
		return g > A.g ;
	}
} d[1005] , x[1005] ;

long long solve( int S ){
	for( int i = 1 ; i <= N ; i ++ ){
		x[i] = d[i] ;
		x[i].g += ( ( S&1 ) ? 1 : -1 ) * d[i].a ;
		x[i].g += ( ( S&2 ) ? 1 : -1 ) * d[i].b ;
		x[i].g += ( ( S&4 ) ? 1 : -1 ) * d[i].c ;
	} sort( x + 1 , x + N + 1 ) ;
	long long sa = 0 , sb = 0 , sc = 0 ;
	for( int i = 1 ; i <= M ; i ++ )
		sa += x[i].a , sb += x[i].b , sc += x[i].c ;
	return abs( sa ) + abs( sb ) + abs( sc ) ;
}

int main(){
	scanf( "%d%d" , &N , &M ) ;
	for( int i = 1 ; i <= N ; i ++ )
		scanf( "%lld%lld%lld" , &d[i].a , &d[i].b , &d[i].c ) ;
	for( int i = 0 ; i <= 7 ; i ++ )
		ans = max( solve( i ) , ans ) ;
	printf( "%lld" , ans ) ;
}


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

int main(){
  string s;
  cin >>s;
  int start,end ;
  for(int i = s.size() -1; i >0;i--){
     if(s.at(i) == 'Z')  {end = i;break;}
  }
  for(int i = 0;i <= end;i++){
    if(s.at(i) == 'A'){start = i; break;}
  }
  cout << end - start +1;
  return 0;
}


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

int main()
{
	int x,y,sum=0;
	cin>>x>>y;
	
	for(int i=0;i<=x;i++)
	{
		sum=(i*2)+((x-i)*4);
		if(sum==y)
		{
		  cout<<"Yes";
		  return 0;
		}
	}
	
	cout<<"No";
	
	return 0;
	
}

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

const long long INF = (1 << 30);

int main(){
  int n;
  cin >> n;
  
  long long h[100000];
  long long dp[100010];
  
  rep(i,n) cin >> h[i];
  rep(i,n) dp[i] = INF;
  
  dp[0] = 0;
  
  rep(i,n){
    dp[i+1] = min(dp[i] + abs(h[i] - h[i+1]), dp[i+1]);
    dp[i+2] = min(dp[i] + abs(h[i] - h[i+2]), dp[i+2]);
  }
  
  cout << dp[n-1] << endl;
  
  return 0;
}

Measured memory_bytes: 1792
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

s = gets.chomp.split("")

count = 0

if s[0] == "R"
  if s[1] == "R"
    if s[2] == "R"
      puts 3
    else
      puts 2
    end
  else
    puts 1
  end
else
  if s[1] == "R"
    if s[2] == "R"
      puts 2
    else
      puts 1
    end
  else
    if s[2] == "R"
      puts 1
    else
      puts 0
    end
  end
end


Measured memory_bytes: 14416
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

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

	int N, R; cin >> N >> R;
	if (N >= 10) cout << R << endl;
	else cout << 100 * (10 - N) + R << endl;

	return 0;
}

Measured memory_bytes: 256
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int dp[2010][2010], pos[2][2010];

const int SIZE = 1 << 12;
struct segtree {
    int node[2*SIZE];
    segtree() {
        memset(node, 0, sizeof(node));
    }
    void init() {
        memset(node, 0, sizeof(node));
    }
    void update(int x, int val) {
        x += SIZE - 1;
        node[x] += val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = node[2*x+1] + node[2*x+2];
        }
    }
    int query(int a, int b, int l=0, int r=SIZE, int k=0) {
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        int mid = (l + r) / 2;
        int vl = query(a, b, l, mid, 2*k+1);
        int vr = query(a, b, mid, r, 2*k+2);
        return vl + vr;
    }
};
 
segtree seg;
signed main() {
    fill(dp[0], dp[2010], INF);
    dp[0][0] = 0;
    int N; cin >> N;

    for(int i=0; i<2*N; i++) {
        char c; int val; cin >> c >> val; val--;
        int col = (c == 'B' ? 1 : 0);
        pos[col][val] = i;
    }

    // black, white
    for(int i=0; i<=N; i++) {
        seg.init();
        for(int k=0; k<i; k++) seg.update(pos[1][k], 1);
        for(int j=0; j<=N; j++) {
            int target = i + j;
            if(i != N) {
                int inv1 = seg.query(pos[1][i], 2*N);
                chmin(dp[i+1][j], dp[i][j] + (pos[1][i] + inv1 - target));
            }

            if(j != N) {
                int inv2 = seg.query(pos[0][j], 2*N);
                chmin(dp[i][j+1], dp[i][j] + (pos[0][j] + inv2 - target));
                seg.update(pos[0][j], 1);
            }
        }
    }
    cout << dp[N][N] << endl;
    return 0;
}

Measured memory_bytes: 31872
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;


class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        StringBuilder ans = new StringBuilder();
        while (true)
        {
            int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            if(inpt[0] == 0 && inpt[1] == 0) {
                break;
            }
            string row = string.Empty.PadLeft(inpt[1], '#');
            for(int i=0; i<inpt[0];i++) {
                ans.AppendLine(row);
            }
            ans.AppendLine(string.Empty);
        }
        Console.Write(ans.ToString());    
    }




    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


3 4
5 6
2 2
0 0


";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

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

int main(){
	int x;
	scanf("%d", &x);
	vector<int> prime;
	for(int i = 2; i <= 200000; i++) {
		bool flag = true;
		for(int j = 0; j < (int)prime.size(); j++) {
			if(i % prime[j] == 0) {
				flag = false;
				break;
			}
		}
		if(flag) {
			prime.push_back(i);
			if(i >= x) {
				printf("%d\n", i);
				return 0;
			}
		}
	}
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
vector<int> w(100000);
int N,K;

int check(int P){
    int i=0,s;
    for(int j=0;j<K;j++){
        s=0;
        while(s+w.at(i)<=P){
            s+=w.at(i);
            i++;
            if(i==N)return N;
        }
    }
    return i;
}

int serch(){
    int left=0,right=1000000000,mid;
    while(left<right-1){
        mid=(left+right)/2;
        if(check(mid)>=N)right=mid;
        else left=mid;
    }
    return right;
}

int main(){
    cin>>N>>K;
    for(int i=0;i<N;i++)cin>>w.at(i);
    cout<<serch()<<endl;
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1000;
const char ENDL = '\n';
ll N;


ll answer(ll x, ll N, vector<ll> C, vector<ll> S, vector<ll> F) {
	ll sub = 0, judge;

	if (x == N - 1)
		return 0;

	repf(i, x, N - 1) {
		judge = S[i];
		while (1) {
			
			if (sub <= judge) {
				sub = judge + C[i];
				break;
			}
			else
				judge += F[i];
		}
	}
	return sub;
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> N;
	vector<ll> C(N), S(N), F(N);
	rep(i, N-1)
		cin >> C[i] >> S[i] >> F[i];
	ll Ans;

	rep(i, N) {
		Ans = answer(i, N, C, S, F);
		cout << Ans << ENDL;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    int N;
    cin >> N;
    ll ans = 0;
    rep2(i,1, N+1) {
        if (N%i == 0) {
            ans += N/i -1;
        }
        else {
            ans += N/i;
        }
    }
    cout << ans << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

// O(V^2 E)なのでフローが小さいときはFord-Fulkersonにすべき
template<class V> class MaxFlow_dinic {
public:
	struct edge { int to,reve;V cap;};
	static const int MV = 221100;
	vector<edge> E[MV];
	int itr[MV],lev[MV];
	void add_edge(int x,int y,V cap,bool undir=false) {
		E[x].push_back((edge){y,(int)E[y].size(),cap});
		E[y].push_back((edge){x,(int)E[x].size()-1,undir?cap:0});
	}
	void bfs(int cur) {
		MINUS(lev);
		queue<int> q;
		lev[cur]=0;
		q.push(cur);
		while(q.size()) {
			int v=q.front(); q.pop();
			ITR(e,E[v]) if(e->cap>0 && lev[e->to]<0) lev[e->to]=lev[v]+1, q.push(e->to);
		}
	}
	V dfs(int from,int to,V cf) {
		if(from==to) return cf;
		for(;itr[from]<E[from].size();itr[from]++) {
			edge* e=&E[from][itr[from]];
			if(e->cap>0 && lev[from]<lev[e->to]) {
				V f=dfs(e->to,to,min(cf,e->cap));
				if(f>0) {
					e->cap-=f;
					E[e->to][e->reve].cap += f;
					return f;
				}
			}
		}
		return 0;
	}
	V maxflow(int from, int to) {
		V fl=0,tf;
		while(1) {
			bfs(from);
			if(lev[to]<0) return fl;
			ZERO(itr);
			while((tf=dfs(from,to,numeric_limits<V>::max()))>0) fl+=tf;
		}
	}
};

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<101010> PF,QF;
MaxFlow_dinic<int> mf;

int N;
int P[101010],Q[101010];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>P[i];
		PF(i,P[i]);
	}
	FOR(i,N) {
		cin>>Q[i];
		QF(i,Q[i]);
	}
	int prof=0;
	FOR(i,N) {
		if(P[i]==i&&Q[i]==i) continue;
		prof++;
		if(P[i]==i) {
			mf.add_edge(100010+QF[i],200020,1);
		}
		else if(Q[i]==i) {
			mf.add_edge(0,5+PF[i],1);
		}
		else if(P[i]!=Q[i]) {
			mf.add_edge(100010+QF[i],5+PF[i],1);
		}
		else {
			mf.add_edge(100010+QF[i],5+PF[i],1);
			mf.add_edge(5+PF[i],100010+QF[i],1);
		}
	}
	cout<<prof-mf.maxflow(0,200020)<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 17408
#include <iostream>
#include <algorithm>

using namespace std;

bool judge ( int x, int y, int z )
{
  if ( x == y && z == y) return true;
  else return false;
}

int main()
{
  int a[3];
  int cnt = 0;

  for ( int i = 0; i < 3; ++i ) cin >> a[i];
  sort(a,a+3);

  int tmp1,tmp2;
  tmp1 = a[2]-a[1];
  tmp2 = a[2]-a[0];

  if ( tmp1%2 && tmp2%2 ) {
    --tmp1; --tmp2; ++cnt;
    cnt += ( tmp1+tmp2)/2;
  } else if ( !(tmp1%2) && !(tmp2%2) ) {
    cnt += (tmp1+tmp2)/2;
  } else {
    if ( tmp1%2 ) ++tmp1;
    if ( tmp2%2 ) ++tmp2;
    ++cnt;
    cnt += (tmp1+tmp2)/2;
  }
  cout << cnt << endl;
}


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

int main()
{
    int n;
    cin>>n;
    long long int count =0;
    long long int ae=0, bs=0, ab=0;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        for(int i=0;i<s.length() -1; i++)
        {
            if(s[i]=='A' && s[i+1]=='B')
                count++;
        }
        if(s[0]=='B' && s[s.length()-1]=='A')
            ab++;
        else if(s[0]=='B')
            bs++;
        else if(s[s.length()-1]=='A')
            ae++;

    }
    if(ab>0)
    {
        count+=ab-1;
        if(ae>0)
        {
            count+=1;
            ae--;
        }
        if(bs>0)
        {
            count+=1;
            bs--;
        }
        count+=min(ae, bs);
    }
    else
    {
        count+=min(ae, bs);
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
N,C=map(int,input().split())

l=[[]for i in range(C)]
for i in range(N):
    s,t,c=map(int,input().split())
    l[c-1].append([s,t])
    
for i in range(C):
    if len(l[i])>=2:
        l[i].sort()
    #print(l)
        X=[]
        Y=l[i][0]
        for j in range(1,len(l[i])):
            
            #if i==2:
                #print(l[i],j)
            if j!=len(l[i])-1:
                #if i==2:
                    #print(Y[1],l[i][j][0])
                if Y[1]==l[i][j][0]:
                    Y[1]=l[i][j][1]
                else:
                    X.append(Y)
                    Y=l[i][j]
                    #print(Y)
            else:
                if Y[1]==l[i][j][0]:
                    Y[1]=l[i][j][1]
                    X.append(Y)
                else:
                    X.append(Y)
                    X.append(l[i][j])
        l[i]=X
#print(l)
TV=[0 for i in range(2*10**5+5)]

for i in range(C):
    for j in range(len(l[i])):
        TV[l[i][j][0]*2-1]+=1
        TV[l[i][j][1]*2]-=1
#print(TV[:10])
ANS=[TV[0]]
for i in range(1,len(TV)):
    ANS.append(ANS[i-1]+TV[i])
print(max(ANS))


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

using namespace std;

typedef long long LL;
const int MAXN = 200005;
int n;
LL a[MAXN], sum[MAXN], sumxor[MAXN];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &a[i]);
    sum[1] = sumxor[1] = a[1];
    for (int i = 2; i <= n; i++) {
        sum[i] = sum[i - 1] + a[i];
        sumxor[i] = sumxor[i - 1] ^ a[i];
    }
    LL ans = 0;
    int l = 1;
    for (int r = 1; r <= n; r++) {
        while ((sum[r] - sum[l - 1]) != (sumxor[r] ^ sumxor[l - 1])) l++;
        ans += r - l + 1;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 4992
M=10**9+7
f=[1]
for j in range(1,10**6):f+=f[-1]*j%M,
i=[pow(f[-1],M-2,M)]
for j in range(1,10**6)[::-1]:i+=i[-1]*j%M,
x,y=map(int,input().split())
n,m=divmod(x+y,3)
print((m<1)*(x*2>=y)*(y*2>=x)*(y-n<=n)*f[n]*i[~n-n+y]*i[~y+n]%M)

Measured memory_bytes: 82392
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define pb push_back
#define eb emplace_back

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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>
T gcd(T a, T b){
    if( b==0 ) return a;
    else return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

template<class T>
void dcomb(T n,T m, string s){
    if(n==0) cout << s << endl;
    else {
        for(T i=0; i<m; ++i){
            dcomb(n-1,m,s+to_string(i));
        }
    }
}

int main(){
    int n;
    cin >> n;
    graph g(n);
    vector<pair<int, int>> vp;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        g[a].eb(b);
        g[b].eb(a);
        vp.eb(a,b);
    }    
    int m = 0;
    map<pair<int, int>,int> I;
    vector<int> cs(n,0);
    queue<int> que;
    vector<int> used(n,0);
    used[0] = 1;
    que.emplace(0);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        if(m<int(g[v].size())) m = g[v].size();
        int cur=1;
        for(int nv:g[v]){
            if(used[nv]){
                continue;
            }
            if(cur==cs[v]) cur++;
            cs[nv] = I[make_pair(v,nv)] = I[make_pair(nv,v)] = cur++;
            que.emplace(nv);
            used[nv]= 1;
        }
    }

    cout << m << endl;
    for(auto p:vp) cout << I[p] << endl;
    return 0;
}

Measured memory_bytes: 20084
#include <iostream>
#include <string>
#include <regex>
 
int main() {
    std::string str;
    std::cin >> str;
    std::regex re(",+");
    std::string format = " ";
 
    std::cout << std::regex_replace(str, re, format) << std::endl;
 
    return 0;
}

Measured memory_bytes: 504
c_list = [int(c) for c in input()]
n = len(c_list)

o_count = [0, 0]
for i in range(0, n, 2):
    o_count[int(c_list[i])] += 1

e_count = [0, 0]
for i in range(1, n, 2):
    e_count[c_list[i]] += 1

print(min(o_count[1] + e_count[0], o_count[0] + e_count[1]))

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,r1,r2,r3;
 
  cin >> a;
  cin >> b;
  cin >> c;
 
  r1 = a+b;
  r2 = b+c;
  r3 = a+c;
  if(r1 <= r2 && r1 <= r3)
    cout << r1 << endl;
    else
      if(r2 <= r1 && r2 <= r3)
        cout << r2 <<endl;
        else 
          cout << r3 << endl;
}


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

int main(){
  int n;
  int a[10][10];
  int sum, amount;
  int i, j;

  while(cin>>n){
    if(n==0) break;
    for(i=0; i<n; i++){
      for(j=0; j<n; j++){
        cin>>a[i][j];
      }
    }

    for(i=0; i<n; i++){
      sum=0;
      for(j=0; j<n; j++){
        printf("%5d", a[i][j]);
        sum+=a[i][j];
      }
      printf("%5d\n", sum);
    }
    amount=0;
    for(j=0; j<n; j++){
      sum=0;
      for(i=0; i<n; i++){
        sum+=a[i][j];
      }
      printf("%5d", sum);
      amount+=sum;
    }
    printf("%5d\n", amount);
  }

  return 0;
}

Measured memory_bytes: 0
//To include everything you need
#include <bits/stdc++.h>
using namespace std;


int main()
{
    long long n,a,b;
    cin>>n>>a>>b;

    if(n<=a){
        cout<<n;
        return 0;
    }

    if(n<= a+b){
        cout<<a;
        return 0;
    }
    if(a == 0){
        cout<<0;
        return 0;
    }
    long long A=0,B=0,remain=0;
    long long count = n/(a+b);
    A += count*a;
    B += count*b;
    remain = n-A-B;
    A+= a<=remain ? a : remain;
    cout<<A;

    return 0;    
}

Measured memory_bytes: 256
import bisect
N = int(input())
A, B = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
P.sort()
problem_first = bisect.bisect_right(P, A)
problem_second = bisect.bisect_right(P, B) - bisect.bisect_left(P, A + 1)
problem_third = N - bisect.bisect_left(P, B + 1)
ans = min([problem_first, problem_second, problem_third])
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    int h,w;
    while(1){
        cin >> h >> w;
        
        if(h == 0 && w == 0){
            break;
        }
        for(int i = 0;i < h;++i){
            // 偶数時
            if(i % 2 == 0){
                for(int j = 0;j < w;++j){
                    if(j % 2 == 0){
                        cout << "#";
                    }
                    else{
                        cout << ".";
                    }
                }
            }else{
                for(int j = 0;j < w;++j){
                    if(j % 2 == 0){
                        cout << ".";
                    }
                    else{
                        cout << "#";
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}



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

int main() {
  const auto f = [] { int x; cin >> x; return x; };
  const auto g = [] { int64_t x; cin >> x; return x; };
  const int N = f();
  const int64_t K = g();
  const auto ab = [f, N] {
    vector<pair<int, int>> ab;
    for (int i = 0; i < N; ++i) {
      const int a = f(), b = f();
      auto pair = make_pair(a, b);
      ab.push_back(pair);
    }
    sort(ab.begin(), ab.end());
    return ab;
  }();
  const auto a = [ab] {
    vector<int> a;
    for (const auto& x : ab) a.push_back(x.first);
    return a;
  }();
  const auto b = [ab] {
    vector<int> b;
    for (const auto& x : ab) b.push_back(x.second);
    return b;
  }();
  const auto b_cum = [b] {
    vector<int64_t> b_cum(b.begin(), b.end());
    for (int i = 1; i < b_cum.size(); ++i)
      b_cum[i] += b_cum[i - 1];
    return b_cum;
  }();
  const auto bound = lower_bound(b_cum.begin(), b_cum.end(), K);
  const int index = distance(b_cum.begin(), bound);
  cout << a[index] << endl;
}


Measured memory_bytes: 3172
#include<stdio.h>
int main() {
	int a, b, c;
	int  i = 0, l = 0;
	scanf("%d %d %d", &a, &b, &c);
	while (1) {
		l++;
		if (l% 7 == 0)i += b;
		i += a;
		if (i >= c) {
			printf("%d\n", l); break;
		}
	}
}


Measured memory_bytes: 2748