akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define MAX 100005
typedef long long ll;
 
struct edge{
  ll to,cost;
  edge(ll to,ll cost):to(to),cost(cost) {}
};
 
ll n;
vector< edge > G[MAX];
ll size[MAX];
ll par[MAX];
ll dep[MAX];
ll depth[MAX];
ll dist[MAX];
ll parent[MAX];
 
void idfs(int pos,int prev=-1){
  int m=-1;
  parent[pos]=prev;

  for(edge e:G[pos]){
    if(e.to==prev)continue;
    
    depth[e.to]=depth[pos]+1;
    dist[e.to]=dist[pos]+e.cost;
    
    idfs(e.to,pos);
    size[pos]+=size[e.to];
    if(m==-1||size[m]<size[e.to])m=e.to;
  }
  
  if(m!=-1)par[m]=pos;
}
 
int calc(int x){
  if(par[x]==x)return x;
  return par[x]=calc(par[x]);
}
 
void init(){
  for(int i=0;i<MAX;i++){
    parent[i]=-1;
    depth[i]=0;
    dist[i]=0;
    size[i]=1;
    par[i]=i;
    dep[i]=0;
  }
 
  for(int i=0;i<n-1;i++){
    ll a,b,c;
    cin>>a>>b>>c;
    a--,b--;
    G[a].push_back( edge(b,c) );
    G[b].push_back( edge(a,c) );
  }
  
  idfs(0,-1);
 
  for(int i=0;i<n;i++){
    int p=calc(i);
    dep[i]=0;
    while(p){
      p=par[parent[p]];
      dep[i]++;
    }
  }
}

int lca(int a,int b){
  while(par[a]!=par[b]){
    if(depth[ par[a] ]>depth[ par[b] ])swap(a,b);
    b=parent[ par[b] ];
  }
  if(depth[a]<depth[b])return a;
  return b;
}
 
ll Cal(int a,int b){
  int c=lca(a,b);
  return dist[a]+dist[b]-dist[c]*2LL;
}
 
int main(){
  cin>>n;
  init();
  ll q,K;
  cin>>q>>K;
  K--;
  while(q--){
    ll a,b;
    cin>>a>>b;
    a--,b--;
    cout<< Cal(a,K) + Cal(K,b) <<endl;
  }
  return 0;
}


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

main() {
    while(1) {
        int n;
        cin >> n;
        if(!n) break;
        vector<string> s(n);
        rep(i, n) cin >> s[i];
        rep(i, n) {
            rep(j, s[i].size() - 1) if(s[i][j] == '.' and s[i][j + 1] != '.')
                s[i][j] = '+';
        }
        rep(i, n) {
            rep(j, s[i].size()) {
                if(s[i][j] == '+') {
                    int pos = i + 1;
                    bool flag = false;
                    int nxt;
                    rep2(k, i + 1, n - 1) {
                        if(j >= s[k].size()) break;
                        if(s[k][j] == '+') {
                            flag = true;
                            nxt = k;
                            break;
                        } else if(s[k][j] != '.')
                            break;
                    }
                    if(flag) {
                        rep2(k, i + 1, nxt - 1) s[k][j] = '|';
                    }
                }
            }
        }
        rep(i, n) rep(j, s[i].size()) if(s[i][j] == '.') s[i][j] = ' ';
        rep(i, n) cout << s[i] << "\n";
    }
}


Measured memory_bytes: 3696
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>


using ll =  long long;

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

using namespace std;

int main(){

    int x;
    cin >> x;
    int c500 = x/500;
    x -= c500*500;
    int c5= x/5;
    int ans = c500*1000+c5*5;
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
g = []
for i in range(len(h)):
    g.append(True)
# print(h)
# print(g)
for _ in range(m):
    a, b = map(int, input().split())
    # print("xxx", h[a - 1], h[b - 1])
    if h[a - 1] < h[b - 1]:
        g[a - 1] = False
    elif h[b - 1] < h[a - 1]:
        g[b - 1] = False
    else:
        g[a - 1] = False
        g[b - 1] = False
cnt = 0
for i in range(len(h)):
    if g[i]:
        cnt = cnt + 1
# print(g)
print(cnt)

# 8 6 9 1 2 1
#  x     x


Measured memory_bytes: 20004
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=105;

int main()
{
    IO;
    int n;
    cin >> n;
    cout<<((n/2)*(n-(n/2)))<<endl;
    re 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<fstream>

#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++)
using namespace std;

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
       
    ll i,j,k,p=1,q=1;
    ll n,m,tmp;
    string s[200000];
    string str;
    ll sum=0;
    ll strr[200005];
    cin>>n;
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            for(k=1;k<=n;k++){
                sum+=gcd(gcd(i,j),k);
            }
        }
    }
    cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 9896
#include <iostream>
#include<math.h>

using namespace std;

int main()
{
    int N, D;
    cin>>N>>D;
    int num = N/(2*D + 1);
    if(N%(2*D + 1) == 0)
        cout<<num;
    else
        cout<<num+1;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
	static int max;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Data>list = new ArrayList<Data>(n);
		for(int i = 0; i < n; i++) {
			String title = sc.next();
			String author = sc.next();
			Calendar date = Calendar.getInstance();
			date.clear();
			String[] datex = sc.next().split("/");
			
			date.set(Integer.parseInt(datex[0]),Integer.parseInt(datex[1]),Integer.parseInt(datex[2]));
			list.add(new Data(title,author,date));
		}
		int q = sc.nextInt();
		for(int i = 0; i < q; i++) {
			if(i != 0) System.out.println();
			ArrayList<Data> ok = new ArrayList<Data>();
			ArrayList<Data> ok2 = new ArrayList<Data>();
			String title = sc.next();
			String author = sc.next();
			Calendar from = Calendar.getInstance();
			from.clear();
			String[] datex = sc.next().split("/");
			if(datex[0].equals("*")) from.set(1970, 1,1);
			else from.set(Integer.parseInt(datex[0]),Integer.parseInt(datex[1]),Integer.parseInt(datex[2]));
			Calendar to   = Calendar.getInstance();
			to.clear();
			datex = sc.next().split("/");
			if(datex[0].equals("*")) to.set(2037, 12,31);
			else to.set(Integer.parseInt(datex[0]),Integer.parseInt(datex[1]),Integer.parseInt(datex[2]));
			
			if(title.equals("*")) ok.addAll(list);
			else 
				for(int j = 0; j < list.size(); j++) {
					if(list.get(j).title.contains(title)) ok.add(list.get(j));
				}
			if(author.equals("*")) ok2.addAll(ok);
			else
				for(int j = 0; j < ok.size(); j++) {
					if(ok.get(j).author.contains(author)) ok2.add(ok.get(j));
				}
			for(int j = 0; j < ok2.size(); j++) {
				if(ok2.get(j).date.compareTo(from) >= 0 && ok2.get(j).date.compareTo(to) <= 0) System.out.println(ok2.get(j).title);
			}
			
		}
		
	}
	static class Data {
		String title;
		String author;
		Calendar date;
		Data(String a, String b, Calendar c) {
			title = a;
			author = b;
			date = c;
		}
	}
}

Measured memory_bytes: 31876
#include <iostream>

using namespace std;

int degree[51] = {0};

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

  int N, M;
  cin >> N >> M;

  int a, b;
  for (int i = 0; i < M; ++i) {
    cin >> a >> b;
    degree[a]++;
    degree[b]++;
  }
  for (int i = 1; i <= N; ++i) {
    cout << degree[i] << endl;
  }

  return 0;
}

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

int r, n;
int buil[50] = {0};
double sun[50] = {0.0};

void sunset();
double solve();

int main() {
  cout << fixed << setprecision(8);
  int i, j, le, ri, he;
  while(1) {
    cin >> r >> n;
    for(i = 0; i < 50; ++i) buil[i] = 0;
    for(i = 0; i < 50; ++i) sun[i] = -99999;
    sunset();
    if(r + n == 0) break;
    for(i = 0; i < n; ++i) {
      cin >> le >> ri >> he;
      for(j = le; j < ri; ++j)
        buil[j + 22] = max(buil[j + 22], he);
    }
    cout << solve() << endl;
  }
  return 0;
}

void sunset() {
  int i;
  double now;
  for(i = 0; i <= r; ++i) {
    if(i == 0)
      now = 0;
    else
      now = sqrtl(r * r - i * i) - r;

    sun[i + 22] = sun[22 - i] = now;
  }
}

double solve() {
  double answer = 10000;
  for(int i = 22 - r; i <= 22 + r; ++i) {
    if(i != 22 + r)
      answer = min((double)buil[i] - sun[i], answer);
    if(i != 22 - r)
      answer = min((double)buil[i - 1] - sun[i], answer);
  }
  return answer;
}


Measured memory_bytes: 3168
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/rope>

using namespace __gnu_pbds; 
using namespace __gnu_cxx;
using namespace std;
using ll = long long;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define precision(n) fixed<<setprecision(n)

#ifdef LOCAL
    #include "debug.h"
#else
    #define debug(...) 42
#endif

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}

template<typename T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;
template<typename T> using MinPriorityQueue = priority_queue <T, vector <T>, greater <T> >;
template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);}

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937_64 mt(seed);

clock_t time_p=clock();
void printTime(){
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}
 

const int mod = 1e9 + 7;
const int N = 1e5 + 5;

int main(){
    io();
    int n, m;
    cin >> n >> m;
    int a[n];
    int sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int m4 = 4 * m;
    

    if(sum % m4) {
        sum = sum / m4;
        sum++;
    }
    else
        sum = sum / m4;
    sort(a, a + n, greater<int>());
    for(int i = 0; i < m; i++) {

        if(a[i] < sum) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";


}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
limit_num, limit_cor = tuple(int(i) for i in input().split(" "))
l_list = tuple(int(i) for i in input().split(" "))
dp = [0]


def jump_cor(n):
    if len(dp) < n + 1:
        dp.append(dp[n - 1] + l_list[n - 1])
    return dp[n]


for i in range(limit_num + 1):
    if jump_cor(i) > limit_cor:
        i -= 1
        break
print(i + 1)


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

using namespace std;

int main()
{
	int64_t  X, Y, i, n;
	cin >>  X >> Y ;
	n = Y / X;
	i = 0;
	while (n > 0)
	{
		i++;
		n = n / 2;

	}
	cout << i << endl;
	
 	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
  for (ll i = 0; i < v.size(); ++i) \
    cout << v[i] << " ";            \
  cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)
#define get(n) \
  ll n;        \
  cin >> n
#define getvec(v, n)         \
  vector<ll> v(n);           \
  for (ll i = 0; i < n; i++) \
    cin >> v[i];
#define getstr(s) \
  string s;       \
  cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

int solve(string &a, string &b)
{
  int n = a.length();
  int diff = 0;
  for (int i = 0; i < n; i++)
    if (a[i] != b[i])
      ++diff;
  return diff;
}

void mainSolve()
{
  getstr(s);
  getstr(t);
  int a = s.length();
  int b = t.length();
  int ans = b;
  for (int i = 0; i <= a - b; i++)
  {
    string x = s.substr(i, b);
    ans = min(ans, solve(x, t));
  }
  p1(ans);
}

int main()
{
  fio;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  //get(t);
  ll t = 1;
  while (t--)
  {
    mainSolve();
  }
  return 0;
}


Measured memory_bytes: 3600
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=100005;
int n,m;
priority_queue<int> hp;
int main()
{
	n=read();m=read();
	for(int i=1;i<=n;i++)hp.push(read());
	for(int i=1;i<=m;i++)
	{
		int x=hp.top();if(!x)break;
		hp.pop();x/=2;hp.push(x);
	}LL ans=0;
	while(!hp.empty())ans+=hp.top(),hp.pop();
	pr2(ans);
	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define frep(i, m, n) for(int i = m;i < n;i++)
#define frepr(i, m, n) for(int i = m;i >= n;i--)
#define vsort(v) sort(v.begin(),v.end())
#define ll long long
#define inf 999999999
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vst;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef pair<int,P> PP;
typedef pair<ll,LP> LPP;

int change(char color){
    switch(color){
        case 'R':return 0;break;
        case 'G':return 10;break;
        case 'B':return 20;break;
        default:return 30;break;
    }
}

int main(){
    int n,m;
    while(cin >> n >> m && n*m!=0){
        vi h(n),w(m);
        ll sum=0;
        rep(i,n){cin >> h[i];sum+=h[i];}
        vi ha(sum+1,0);
        sum=0;
        rep(i,m){cin >> w[i];sum+=w[i];}
        vi wa(sum+1,0);
        ll length=0;
        rep(i,n){
            length=0;
            frep(j,i,n){
                length+=h[j];
                ha[length]++;
                // cout << "i:" << i << " j:" << j  << " sum:" << length << endl;
            }
        }
        rep(i,m){
            length=0;
            frep(j,i,m){
                length+=w[j];
                wa[length]++;
                // cout << "i:" << i << " j:" << j  << " sum:" << length << endl;
            }
        }
        ll ans=0;
        // rep(i,ha.size())cout<<ha[i] << ",";
        // cout <<endl;
        // rep(i,wa.size())cout<<wa[i] << ",";
        // cout <<endl;
        rep(i,ha.size()){
            if(i>=wa.size())break;
            else if(ha[i]!=0){
                ans+=wa[i]*ha[i];
            }
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 6948
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

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

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(int x, int y){
  if(x % y == 1) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(int x, int y){
  return x * y / gcd(x, y);
}
// n個の最大公約数
ll ngcd(vector<int> a){
  int res;
  res = a[0];
  for(int i=1; i<a.size() && res!=1; i++){
    res = gcd(res, a[i]);
  }
  return res;
}
// n個の最小公倍数
ll nlcm(vector<int> a){
  int res;
  res = a[0];
  REP(i, a.size()){
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(int x){
  int i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
int digsum(int x){
  int res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  vector<string> v(n);
  rep(i,n) cin >> v[i];
  REP(i,n) {
    int last = v[i-1].size()-1;
    if(v[i-1][last] != v[i][0]){
      cout << "No" << endl;
      return 0;
    }
  }
  sort(v.begin(), v.end());
  REP(i,n){
    if(v[i] == v[i-1]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}






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

int main()
{
  unsigned long long N;
  cin >> N;
  unsigned long long sN = sqrt(N);
  unsigned long long ans = 0;
  for (int i = sN; i > 0; i--)
  {
    if (N % i == 0)
    {
      ans = i + (N / i) - 2;
      break;
    }
  }
  cout << ans << endl;
}


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

#define MOD 1000000007

int main()
{
  string s, t;
  cin >> s >> t;
  ll a, b;
  cin >> a >> b;
  string u;
  cin >> u;

  if (u == s)
  {
    cout << a - 1 << " " << b << endl;
  }
  else
  {
    cout << a << " " << b - 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//　入力マクロここまで

fn main() {
    input! {
        n: usize,
        a: [i64;n],
    }

    let mut x = 0;

    for i in 0..n {
        if i % 2==0 {
            x += a[i];
        } else {
            x -= a[i];
        }
    }
    x /= 2;
    print!("{}",2*x);
    for i in 0..n-1 {
        print!(" {}", 2*(a[i]-x));
        x = a[i]-x;
    }
    println!();
}

Measured memory_bytes: 5372
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    val t = sc.next()
    val transST = Array(26) { -1 }
    val transTS = Array(26) { -1 }

    for (i in s.indices) {
        val chS = s[i] - 'a'
        val chT = t[i] - 'a'
        if (transST[chS] == -1) {
            if (transTS[chT] == -1) {
                transST[chS] = chT
                transTS[chT] = chS
            } else if (transTS[chT] != chS) {
                println("No")
                return
            }
        } else if (transST[chS] != chT) {
            println("No")
            return
        }
    }
    println("Yes")
}


Measured memory_bytes: 33812
D,G=list(map(int,input().split()))
li=[]
P=[]
Bonus=[]
for i in range(D):
   p,c=list(map(int,input().split()))
   P.append(p)
   Bonus.append(c)

for i in range(1<<D):
   E=[d for d in range(D)]
   output=[]
   for j in range(D):
      if((i>>j)&1)==1:
         output.append(j)
   Not_output=list(set(E)-set(output))
   Not_output.sort(reverse=True)

   score=0
   solve_problems=0
   #100i点の問題はすべて解く
   for i in output:
      score+=P[i]*100*(i+1)
      score+=Bonus[i]
      solve_problems+=P[i]
   
   for i in Not_output:
      if score>=G:
         break

      elif score+(P[i]-1)*100*(i+1)<G:
         score+=(P[i]-1)*100*(i+1)
         solve_problems+=(P[i]-1)
      else:
         while(True):
            score+=100*(i+1)
            solve_problems+=1
            if(score>=G):
               break

   if score>=G:
      li.append(solve_problems)
print(min(li))

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

long long int n,id,p,q,num,time,sale[4005][2],ord[4005],pep;
long long int i,j,k;

int main(void){
	while(scanf("%lld",&n)*n){
		num=0;pep=0;time++;
		
		for(i=0;i<n;i++){
			scanf("%lld %lld %lld",&id,&p,&q);
			
			if(sale[id][1]!=time){
				sale[id][0]=p*q;
				sale[id][1]=time;
				ord[pep]=id;
				pep++;
			}else if(sale[id][0]<1000000){
				sale[id][0]+=p*q;
			}
			if(sale[id][0]>=1000000)num++;
		}

		if(num==0)printf("NA\n");

		else{
			for(i=0;i<pep;i++){
				if(sale[ord[i]][0]>=1000000 && sale[ord[i]][1]==time)printf("%lld\n",ord[i]);
			}
		}

	}
	return 0;
}

Measured memory_bytes: 656
n = input()
n = int(n)

suits_list = ['S', 'H', 'C', 'D']
cards = [[], [], [], []]

for i in range(n):
    a = input()
    suits, num = a.split(' ')
    
    for j in range(4):
        if suits == suits_list[j]:
            cards[j].append(num)

for i in range(len(suits_list)):
    for j in range(13):
        if not str(j + 1) in cards[i]:
            print('%s %d'%(suits_list[i], (j + 1)))
    


Measured memory_bytes: 5604
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kidman
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll

const int md = 1000000007;
const int INF = 1<<30;

class BBuffet {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n; in >> n;
        vi a(n),b(n),c(n-1); in >> a >> b >> c;

        int ans = 0;
        rep(i,n){
            ans += b[a[i]-1];
            if(i == n-1) break;

            if(a[i+1] - a[i] == 1) ans += c[a[i]-1];
        }

        out << ans << endl;
	}
};


int main() {
	BBuffet solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
x = int(input())
for i in range(1, 10 ** 5):
    i5 = i ** 5
    flag = False
    for j in range(i):
        j5 = j ** 5
        if i5 + j5 == x:
            flag = True
            print(i, -j)
            break
        elif i5 - j5 == x:
            flag = True
            print(i, j)
    if flag:
        break


Measured memory_bytes: 9184
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);

  for(int i = 0;i < n;i++)cin >> a[i];
  
  int now = 1;
  int cnt = 0;
  for(int i = 0;i < n;i++){
    if(now == a[i]){
      cnt++;
      now++;
    }
  }

  if(cnt == 0)cout << -1 << endl;
  else cout << n - cnt << endl;
}

Measured memory_bytes: 1792
from collections import Counter
import sys

N = int(input())
D = list(input().split())

M = int(input())
T = list(input().split())

D_count = Counter(D)
T_count = Counter(T)

for k, v in T_count.items():
    if D_count[k] < v:
        print('NO')
        sys.exit()

print('YES')



Measured memory_bytes: 126292
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> ivec;
const ll N = 1e9+7;

const int nmax = 8,m = 100;
vector<int> ab[nmax];
// int V = 0,E = 0;
// int moved[n];
int dfs(int x, int n, bool moved[nmax]){
    // rep(i,n) cout << moved[i] << ' ' ;
    // cout <<endl;
    bool allmoved = true;
    rep(i,n){
        if(moved[i] == false) allmoved = false;
    }
    if(allmoved) {
        // cout << "test" << endl;
        return 1;
    }
    // moved[x] = 1;
    int ans = 0;
    rep(i,ab[x].size()){
        int v = ab[x][i];
        // if() continue;
        if(moved[v] == 0){
            moved[v] = 1;
            ans += dfs(v,n,moved);
            moved[v] = 0;
        }
    }
    // cout << "ans"  << ' ' << ans << endl;
    return ans;
}

int main(){
    int n,m; cin >> n >> m;
    // vector<int> ab[n];
    rep(i,m){
        int a,b; cin >> a >> b;
        ab[a-1].pb(b-1);
        ab[b-1].pb(a-1);
    }
    bool moved[n] = {};
    moved[0] = true;
    cout << dfs(0,n,moved) << endl;
    return 0;
}

Measured memory_bytes: 256
s = gets.chomp.split("")
count = 0
while true
    ookisa = s.size
    # p  s[0,(ookisa/2)]
    # p   s[ookisa/2,ookisa-1]
    if s[0,(ookisa/2)] == s[(ookisa/2),ookisa-1] && ookisa % 2 == 0 && count >= 1
        puts ookisa
        break
    else
        s.pop
    end
    count += 1
end


Measured memory_bytes: 14324
import java.util.*;
public class Main{
	public static void main(String[] args){
		long ans = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		
		long[] a = new long[n];
		long[][] a2 = new long[n][40];
		for(int i=0; i<n; i++){
			long ai = sc.nextLong();
			a[i] = ai;
			
			for(int j=0; j<40; j++){
				a2[i][j] = ai % 2;
				ai -= ai % 2;
				ai /= 2;
			}
		}
		
		long[] sums = new long[40];
		for(int i=0; i<n; i++){
			for(int j=0; j<40; j++){
				sums[j] += a2[i][j];
			}
		}
		
		int kmax = 0;
		long n2 = 1;
		while(k >= n2){
			kmax++;
			n2 *= 2;
		}
		
		long n2k = n2 / 2;
		for(int i=kmax; i<40; i++){
			ans += n2 * sums[i];
			n2 *= 2;
		}
		
		int frag = 1;
		for(int i=kmax-1; i>=0; i--){
			if(sums[i]*2 < n && frag == 1){
				ans += n2k * (n-sums[i]);
				k -= n2k;
				n2k /= 2;
				while(k < n2k){
					i--;
					ans += n2k * sums[i];
					n2k /= 2;
				}
			}
			else{
				frag = 0;
				ans += n2k * Math.max(sums[i], n-sums[i]);
				n2k /= 2;
			}
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 105040
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while (true)
		{
			int a = sc.nextInt(),
				b = sc.nextInt();
			if (a == 0 && b == 0) break;
			int x = Math.max(a, b),
				y = Math.min(a, b),
				z = x % y;
			int count = 1;
			while (z != 0)
			{
				x = y;
				y = z;
				z = x % y;
				count++;
			}
			System.out.printf("%d %d\n", y, count);
		}
	}
}

Measured memory_bytes: 13000
//
//  sublime text 3,
//  emre yazicioglu
//

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;
typedef vector <ll> vll;
#define pb push_back
#define fi first
#define se second
#define INF (ll) 1e18 + 7
#define MOD (ll) 1e9 + 7

const int N = 3e3 + 7;
ll mn = INF, mx = -INF;
ll n, m, k, s, q, t;
ll a[N], b[N], c, d, e;
ll ans, cur, sum, cnt;
ll ar[N], p[N], dp[N][N][2];
string str; bool h[N];
pll pp[N]; vll v;

ll f(ll cur, ll rem, bool ok) {
  if(cur == n + 1) return 0;
  if(!rem) return 0;
  ll &r = dp[cur][rem][ok];
  if(~r) return r;
  r = -INF;
  if(!ok) r = max(r, f(cur + 1, rem - 1, 1) + b[cur]);
  if(rem >= a[cur])
    r = max(r, f(cur + 1, rem - a[cur], ok) + b[cur]);
  r = max(r, f(cur + 1, rem, ok));
  return r;
}

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

  // freopen("../in.txt","r",stdin);
  // freopen("../out.txt","w",stdout);

  memset(dp, -1, sizeof dp);
  cin >> n >> t;
  for(int i = 1; i <= n; i++)
    cin >> a[i] >> b[i];
  cout << f(1, t, 0);    
}

Measured memory_bytes: 141824
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main(void) {
    
    
    vector<pair<ld,pair<ld,ld>>> v(4);
    ld a;
    cin>>a;
    v[0]=mp(a*4,mp(a,0.25));
    cin>>a;
    v[1]=mp(a*2,mp(a,0.5));
    cin>>a;
    v[2]=mp(a,mp(a,1));
    cin>>a;
    v[3]=mp(a/2,mp(a,2));
    Sort(v);
    ld n;cin>>n;
    ll ans=0;
    for(int i=0;i<4;i++){
        if(n<v[i].second.second)continue;
        ll num=n/v[i].second.second;
        // cout<<num<<" "<<v[i].second.first<<" "<<v[i].second.second<<endl;
        ans+=v[i].second.first*num;
        n-=v[i].second.second*num;
        // cout<<num<<endl;
    }
    fin(ans);
}


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

C = [0 for _ in range(N)]
count = 0
prev = S[0]
for i, s in enumerate(S[1:]):
    now = s
    if prev + now == 'AC':
        count += 1
    C[i+1] = count
    prev = now
C

for j in range(Q):
    l, r = map(int, input().split())
    print(C[r-1] - C[l-1])

Measured memory_bytes: 52332
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String S=sc.next();

        S=S.replaceAll("eraser","-");
        S=S.replaceAll("erase","-");
        S=S.replaceAll("dreamer","-");
        S=S.replaceAll("dream","-");
        S=S.replaceAll("-","");
        if(S.length()==0){
            System.out.println("YES");
        }
        else{
            System.out.println("NO");
        }
    }
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long

const int MOD =  1000000007;
const int IINF = INT_MAX;
const ll INF = 1LL << 60;


int main() {
    string s, t; cin >> s >> t;
    int n = s.size();
    map<char, int> ms, mt;
    for(int i = 0; i < n; i++){
        ms[s[i]]++;
        mt[t[i]]++;
    }

    if(ms.size() == mt.size()){
        for(int i = 0; i < n; i++){
            if(ms[s[i]] == mt[t[i]]) continue;
            else{
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3900
#include <stdio.h>

void print_list(int a[], int n)
{
    int i;
    for (i = 0; i < n; i++){
        printf("%d", a[i]);
        if (i < n-1)
            printf(" ");
    }
    printf("\n");
}

void insertion_sort(int a[], int n)
{
    print_list(a, n);
    
    int i, j, v;
    
    for (i = 1; i < n; i++){
        j = i;
        v = a[i];
        while(j >= 1 && a[j-1] > v){
            a[j] = a[j-1];
            j--;
        }
        a[j] =  v;
        print_list(a, n);
    }
}

int main()
{
    int a[1000];
    int i, n;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);
    
    insertion_sort(a, n);
    
    return 0;
}


Measured memory_bytes: 2700
X = [list(map(int,input().split())) for i in range(3)]

if (X[1][0] - X[0][0] == X[1][1] - X[0][1] == X[1][2] - X[0][2] and\
	X[2][0] - X[0][0] == X[2][1] - X[0][1] == X[2][2] - X[0][2]):
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main( void )
{
	int c1, c2, c3;
	while ( cin >> c1 >> c2 >> c3 )
	{
		int count = 0;
		for ( int i = 1; i <= 10; i++ )
		{
			if ( i == c1 || i == c2 || i == c3 ) continue;
			if ( c1 + c2 + i <= 20 ) count ++;
		}
		if ( (double)count/7 >= 0.5 )
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>

using namespace std;

struct point{
	double x;
	double y;

	bool operator != ( point& p )
	{
		return ( x != p.x || y != p.y );
	}
	bool operator == ( point& p )
	{
		return ( x == p.x && y == p.y );
	}
};

point getLeftPoint( int n , point *points );
double getCrossProduct( const point& a , const point& b , const point& o );
point operator - ( const point& a , const point& b );
istream& operator >> ( istream& s , point& p );

int main(void)
{
	point points[100];
	int n;
	int ans;

	while(1)
	{
		cin >> n;
		if( n == 0 )
		{
			break;
		}
		for( int i = 0 ; i < n ; i++ )
		{
			cin >> points[i];
		}

		point leftPoint = getLeftPoint( n , points );
		point stdPoint = leftPoint;
		point outsideLeftPoint;
		int vertexCounter = 0;

		while(1)
		{
			for( int i = 0 ; i < n ; i++ )
			{
				int flag = 0;
				if( points[i] != stdPoint )
				{
					for( int j = 0 ; j < n ; j++ )
					{
						if( points[j] != stdPoint )
						{
							if( getCrossProduct( points[i] , points[j] , stdPoint ) > 0 )
							{
								flag = 1;
								break;
							}
						}
					}
					if( flag == 0 )
					{
						outsideLeftPoint = points[i];
						break;
					}
				}
			}
			stdPoint = outsideLeftPoint;
			vertexCounter++;
			if( outsideLeftPoint == leftPoint )
			{
				break;
			}
		}
		ans = n - vertexCounter;
		std::cout << ans << endl;
	}

	return 0;
}

point getLeftPoint( int n , point *points )
{
	point leftPoint = points[0];
	for( int i = 1 ; i < n ; i++ )
	{
		if( points[i].x < leftPoint.x )
		{
			leftPoint = points[i];
		}
	}
	return leftPoint;
}

double getCrossProduct( const point& a , const point& b , const point& o )
{
	point ao = a - o;
	point bo = b - o;
	return (ao.x * bo.y) - (ao.y * bo.x);
}

point operator - ( const point& a , const point& b )
{
	point p;
	p.x = a.x - b.x;
	p.y = a.y - b.y;
	return p;
}

istream& operator >> ( istream& s , point& p )
{
	char c;
	return s >> p.x >> c >> p.y;
}

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

#define int long long
#define w cout
#define e '\n'
#define sz(x) (int)x.size()
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.first >> p.second; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

const int N = 1e6 + 10 , mod = 998244353;


signed main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	char a , b; cin >> a >> b;
	string aa = "" , bb = "";
	for(int i = 0 ; i < a - '0' ; i ++ ){
		aa.push_back(b);
	}
	for(int i = 0 ;i < b - '0' ; i ++) {
		bb.push_back(a);
	}
	cout << min(aa, bb);
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
char s[1000001],ss[1000000];
int suu[1000000],cnt[1000000];
int main(void)
{
	int i,j,kazu,max=0,len;
	scanf("%s",s);
	kazu=0;
	cnt[kazu]=1;
	ss[kazu]=s[kazu];
	len=strlen(s);
	for(i=1;i<len;i++) {
		if(ss[kazu]==s[i]) cnt[kazu]++;
		else {
			kazu++;
			cnt[kazu]=1;
			ss[kazu]=s[i];
		}
	}
	for(i=0;i<=kazu;i++) {
		if(ss[i]=='O') {
			if(i-1>=0 && i+1<=kazu) {
				if(ss[i-1]=='J' && cnt[i-1]>=cnt[i]) {
					if(ss[i+1]=='I' && cnt[i+1]>=cnt[i]) {
						if(max<cnt[i]) max=cnt[i];
					}
				}
			}
		}
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 8684
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n, cA, cB, cAB, counter, i, j;
	counter = 0;
	string s;
	cA = 0;
	cB = 0;
	cAB = 0;
	cin >> n;
	for (i = 0; i < n; i++)
	{
      		cin >> s;
		int count = 0;
		for (j = 0; j < s.size() - 1; j++) {
			if (s.at(j) == 'A' && s.at(j + 1) == 'B') {
				count++;
			}
		}
		counter += count;
		if (s.at(s.size() - 1) == 'A' && s.at(0) == 'B') cAB++;
		else if (s.at(s.size() - 1) == 'A') cA++;
		else if (s.at(0) == 'B') cB++;
	}
	if (cAB > 0) {
		counter += cAB - 1;
		cA++;
		cB++;
	}
  if (cA==1&&cB==1&&cAB>0)cout<<counter<<endl;
  
  else 
  {counter += min(cA, cB);
 
	cout << counter << endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#define pie 3.14159265358979323846
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    int N=in();
    vector<int> ans(N,0);
    REP(i,N-1){
        int s;
        cin>>s;
        s--;
        ans[s]++;
    }
    REP(i,N){
        cout<<ans[i]<<endl;
    }
    return 0;
}


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

vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p=-1) {
  for (int u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  rep(i,q) {
    int p, x;
    cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0);
  rep(i,n) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 23552
from collections import deque
import sys
sys.setrecursionlimit(10**7)
#input = sys.stdin.readline
def solve():
  s = input()
  n = len(s)
  dp = [0]*(n+1)
  dp[0] = 0
  dp[1] = 1
  for i in range(1,n):
    if i == 1:
      if s[i-1] == s[i]:
        dp[i+1] = 1 #aa
      else:
        dp[i+1] = dp[i]+1
    else:
      if s[i] != s[i-1]:
        dp[i+1] = dp[i]+1
      else:
        dp[i+1] = dp[i-2]+2
  print(dp[n])
      
      
solve()

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

int main()
{
    long long n, m;
    cin >> n >> m;

    if (n == 1 && m == 1)
    {
        cout << 1 << endl;
    }
    else if (n == 1 && m != 1)
    {
        cout << m - 2 << endl;
    }
    else if (n != 1 && m == 1)
    {
        cout << n - 2 << endl;
    }
    //else if(n>=2&&m>=2){
    else{
        cout << (n - 2) * (m - 2) << endl;
    }


}

Measured memory_bytes: 256
from scipy.special import comb
from collections import Counter

n = int(input())
A = [int(i) for i in input().split()]

count = Counter(A)
combs = {k:comb(count[k], 2) for k in count.keys()}
combs_minas_one = {k:comb(count[k]-1, 2) for k in count.keys()}
all = sum(combs.values())

for a in A:
    ans = all - combs[a] + combs_minas_one[a]
    print(int(ans))


Measured memory_bytes: 79092
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = a; i <= b;i++) {
		if (i<=a+k-1||i>=b-k+1) {
			cout << i << endl;
		}
	}
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int v[100010];
int j[100010];

int main() {
    int n,m; cin >> n >> m;
    int AC = 0; int WA = 0;
    rep(i,m){
        int p; string s;
        cin >> p >> s;
        if(j[p] == 0){
            if(s == "AC"){
                AC++;
                WA += v[p];
                j[p]++;
            }else{
                v[p]++;
            }
        }
    }
    cout << AC << " " << WA << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
struct node{
    int value;
    node *parent,*l,*r;
    node(){
        value=-2000000001;
        parent=l=r=NULL;
    }
};

void insert(node*,int);
void Preorder(node*);
void Inorder(node*);
bool find(node*,int);
int main(void){
    int n,num;
    node *t=new node;
    string str;
    
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>str;
        if(str=="insert"){
            cin>>num;
            insert(t,num);
        }
        else if(str=="find"){
            cin>>num;
            if(find(t,num)==true) cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }
        else{
            Inorder(t);
            cout<<endl;
            Preorder(t);
            cout<<endl;
        }
    }
    
    return 0;
}
void insert(node *t,int num){
    node *z=new node;
    
    z->value=num;
    if(t->parent==NULL && t->l==NULL && t->r==NULL && t->value==-2000000001){
        t->value=num;
        return;
    }
    while(z->parent==NULL){
        if(num > t->value){
            if(t->r==NULL){
                t->r=z;
                z->parent=t;
            }
            else    t=t->r;
        }
        else{
            if(t->l==NULL){
                t->l=z;
                z->parent=t;
            }
            else    t=t->l;
        }
    }
}
void Preorder(node *t){
	cout<<" "<<t->value;
	if(t->l!=NULL) Preorder(t->l);
	if(t->r!=NULL) Preorder(t->r);
}
void Inorder(node *t){
	if(t->l!=NULL) Inorder(t->l);
	cout<<" "<<t->value;
	if(t->r!=NULL) Inorder(t->r);
}
bool find(node *t,int num){
    if(t->value==num)   return true;
    if(t->value>num && t->l!=NULL)   return find(t->l,num);
    if(t->value<num && t->r!=NULL)  return find(t->r,num);
    return false;
}

Measured memory_bytes: 21904