akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=100010;
char col[maxn];
vector<int> init_g[maxn],g[maxn];
ll dp_from[maxn],dp_to[maxn],dp_same[maxn];
ll min_v[maxn],sec_v[maxn];
int min_ch[maxn],sec_ch[maxn];
bool sub_white[maxn];
void init(int u,int fa){
	sub_white[u]=false;
	if(col[u]=='W') sub_white[u]=true;
	for(int i=0;i<(int)init_g[u].size();i++){
		int v=init_g[u][i];
		if(v==fa) continue;
		init(v,u);
		sub_white[u]|=sub_white[v];
		if(sub_white[v]){
			g[u].push_back(v);
			g[v].push_back(u);
		}
	}
}
void dfs(int u,int fa){
	int is_black=(col[u]=='B')?1:0;
	for(int i=0;i<(int)g[u].size();i++){
		int v=g[u][i];
		if(v==fa) continue;
		dfs(v,u);
		dp_same[u]+=dp_same[v]+2;
	}
	min_ch[u]=sec_ch[u]=-1;
	min_v[u]=sec_v[u]=1ll<<62;
	for(int i=0;i<(int)g[u].size();i++){
		int v=g[u][i];
		if(v==fa) continue;
		if(min_v[u]>=dp_same[u]-dp_same[v]-2+dp_to[v]+1){
			sec_ch[u]=min_ch[u];
			sec_v[u]=min_v[u];
			min_ch[u]=v;
			min_v[u]=dp_same[u]-dp_same[v]-2+dp_to[v]+1;
		}else if(sec_v[u]>dp_same[u]-dp_same[v]-2+dp_to[v]+1){
			sec_v[u]=dp_same[u]-dp_same[v]-2+dp_to[v]+1;
			sec_ch[u]=v;
		}
	}
	dp_from[u]=dp_same[u];
	for(int i=0;i<(int)g[u].size();i++){
		int v=g[u][i];
		if(v==fa) continue;
		dp_from[u]=min(dp_from[u],dp_same[u]-dp_same[v]-2+dp_from[v]+1);
	}
	int minus=(fa==-1)?0:1;
	if(!((is_black+(int)g[u].size()-minus)&1)) dp_from[u]++;
	if(!((is_black+(int)g[u].size())&1)) dp_same[u]++;
	if(min_ch[u]==-1) dp_to[u]=dp_same[u];
	else{
		if(!((is_black+(int)g[u].size()-1)&1)) min_v[u]++,sec_v[u]++;
		dp_to[u]=min_v[u];
	}
}
void dfs_sec(int u,int fa,ll others,ll& ans){
	int is_black=(col[u]=='B')?1:0;
	ll tot=others+2;
	for(int i=0;i<(int)g[u].size();i++){
		int v=g[u][i];
		if(v==fa) continue;
		tot+=dp_same[v]+2;
	}
	for(int i=0;i<(int)g[u].size();i++){
		int v=g[u][i];
		if(v==fa) continue;
		ans=min(ans,others+2+dp_from[v]+1+dp_same[u]-dp_same[v]-2);
		/*if(dp_from[v]+1+dp_same[u]-dp_same[v]-2==3)
			printf("de-1: %d %d %lld %lld %lld\n",u,v,dp_same[u],dp_from[v],dp_same[v]);*/
		if(v!=min_ch[u]){
			ans=min(ans,others+2+dp_from[v]+1+min_v[u]-dp_same[v]-2);
			/*if(dp_from[v]+1+min_v[u]-dp_same[v]-2==3)
				printf("de-2: %d %d\n",u,v);*/
		}else{
			ans=min(ans,others+2+dp_from[v]+1+sec_v[u]-dp_same[v]-2);
			/*if(dp_from[v]+1+sec_v[u]-dp_same[v]-2==3)
				printf("de-3: %d %d\n",u,v);*/
		}
		ll next_others=tot-dp_same[v]-2;
		if(!((is_black+(int)g[u].size())&1)) next_others++;
		dfs_sec(v,u,next_others,ans);
	}
}
int main(){
	int n,u,v;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		init_g[u].push_back(v);
		init_g[v].push_back(u);
	}
	int root=-1;
	scanf("%s",col+1);
	for(int i=1;i<=n && root==-1;i++)
		if(col[i]=='W') root=i;
	if(root==-1) puts("0"),exit(0);
	init(root,-1);
	dfs(root,-1);
	ll ans=dp_to[root];
	dfs_sec(root,-1,-2,ans);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 25472
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int H, W, K;
string S[11];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> H >> W >> K;
    REP (i, H) cin >> S[i];
    int ans = 1LL << 30;
    REP (bit, 1LL << H) {
        vector<vector<string>> vvs;
        int p = -1;
        REP (i, H) {
            if ((bit >> i & 1) != p) {
                vector<string> vs;
                vs.emplace_back(S[i]);
                vvs.emplace_back(vs);
                if (bit >> i & 1) p = 1;
                else p = 0;
            } else if ((bit >> i & 1) == p) {
                auto vs = vvs.back();
                vs.emplace_back(S[i]);
                vvs.pop_back();
                vvs.emplace_back(vs);
            }
        }

        vector<vector<int>> cnt(vvs.size(), vector<int>(W, 0));
        for (int k = 0; k < vvs.size(); ++k) {
            for (int j = 0; j < W; ++j) {
                for (int i = 0; i < vvs[k].size(); ++i) {
                    cnt[k][j] += (vvs[k][i][j] - '0');
                }
            }
        }

        bool no = false;
        for (int i = 0; i < vvs.size(); ++i) {
            for (int j = 0; j < W; ++j) {
                if (cnt[i][j] > K) no = true;
            }
        }

        if (no) continue;

        int sub = vvs.size() - 1;
        vector<int> num(vvs.size(), 0);
        for (int j = 0; j < W; ++j) {
            bool over = false;
            for (int i = 0; i < vvs.size(); ++i) {
                num[i] += cnt[i][j];
                if (num[i] > K) over = true;
            }
            if (!over) continue;
            sub++;
            for (int i = 0; i < vvs.size(); ++i) {
                num[i] = cnt[i][j];
            }
        }
        ans = min(ans, sub);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <tuple>
#include <utility>
#include <functional>
#include <sys/time.h>
#include <iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(i, m, n) for(int i = (m); i < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

constexpr int BEAM_SIZE = 1500;
constexpr int SZ = 26;
constexpr int D = 365;
array<int, SZ> C;
int SUM = 0;
array<array<int, SZ>, D> S;

struct State {
	array<int, SZ> last = {};
	array<char, D> ans;
	int score = 0, sum = 0;

	void update_score(int d, int t) {
		score += S[d][t];
		sum -= C[t] * (d + 1 - last[t]);
		last[t] = d + 1;
		sum += SUM;
		score -= sum;
	}

	int next_eval(int d, int t){
		int res = score;
		res += S[d][t];
		rep(i, SZ){
			if (i != t) res -= C[i] * (d + 1 - last[i]);
		}
		return res;
	}

	int eval() const {
		return score;
	}

	State place(int d, int t) {
		State res = *this;
		res.ans[d] = t;
		res.update_score(d, t);
		return res;
	}

	array<char, D> answer() {
		return ans;
	}
};

array<char, D> solve() {
	State initial_state;
	using f = function<bool(State&, State&)>;
	priority_queue<State, vector<State>, f> cur([](State& a, State& b){return a.eval() > b.eval();});
	cur.push(initial_state);
	priority_queue<State, vector<State>, f> nxt([](State& a, State& b){return a.eval() > b.eval();});
	rep(d, D){
		while(!nxt.empty()) nxt.pop();
		while(!cur.empty()){
			State now = cur.top(); cur.pop();
			rep(t, SZ){
				if(nxt.size() < BEAM_SIZE || now.next_eval(d, t) > nxt.top().eval()) nxt.push(now.place(d, t));
				if(nxt.size() > BEAM_SIZE) nxt.pop();
			}
		}
		swap(cur, nxt);
	}

	State res;
	while(!cur.empty()){
		if(cur.size() == 1) res = cur.top();
		cur.pop();
	}
	cerr << res.eval() << endl;
	return res.answer();
}

int main(void){
	int tmp;
	cin >> tmp;
	rep(i, SZ) cin >> C[i];
	rep(i, SZ) SUM += C[i];
	rep(i, D) rep(j, SZ) cin >> S[i][j];

	auto ans = solve();
	for (char i : ans) cout << (int)i + 1 << endl;

	return 0;
}


Measured memory_bytes: 5176
import qualified Data.Vector         as V
import qualified Data.Vector.Mutable as VM
import Control.Applicative
import Control.Monad
import Data.IORef
import Text.Printf

type Process = (String, Int)

roundRobin :: Int -> [Process] -> IO ()
roundRobin q xs = do
  queue <- V.thaw $ V.fromList (xs ++ [("String", 0)])
  front <- newIORef 0
  rear  <- newIORef n
  loop 0 queue front rear
  where
    n = length xs
    loop t vec front rear = do
      f <- readIORef front
      r <- readIORef rear
      when (f /= r) $ do
        i <- readIORef front
        writeIORef front (if i == n then 0 else i + 1)
        (name, time) <- VM.read vec i
        if time <= q
          then do
          printf "%s %d\n" name (t + time)
          loop (t + time) vec front rear
          else do
          j <- readIORef rear
          writeIORef rear (if j == n then 0 else j + 1)
          VM.write vec j (name, time - q)
          loop (t + q) vec front rear

main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine
  xs <- map (toTuple . words) <$> replicateM n getLine
  roundRobin q xs
    where toTuple [n, t]  = (n, read t)



Measured memory_bytes: 38344
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int main()
{
    int n; 
    cin >> n;
    vector<int> a(3 * n);
    rep(i, 0, 3*n)
        cin >> a[i];

    ll sum_l, sum_r;
    sum_l = sum_r = 0;
    priority_queue<int, vector<int>, greater<int>> left;
    priority_queue<int, vector<int>, less<int>> right;
    rep(i, 0, n)
    {
        left.push(a[i]);
        right.push(a[3 * n - 1 - i]);

        sum_l += (ll)a[i];
        sum_r += (ll)a[3 * n - 1- i];
    }

    vector<ll> ans(3 * n, 0);
    ans[n - 1] = sum_l;
    ans[2 * n - 1] = -sum_r;
    rep(pos, n, 2 * n)
    {
        ll new_a = a[pos];
        left.push(new_a);
        ll old_a = left.top();
        left.pop();

        sum_l = sum_l + new_a - old_a;
        ans[pos] += sum_l;

        // cout << pos << ' ' << sum_l << ' ' << new_a << ' ' << old_a << endl;
    }
    rrep(pos, 2 * n - 1, n - 1)
    {
        ll new_a = a[pos + 1];
        right.push(new_a);
        ll old_a = right.top();
        right.pop();
        // cout << pos << '*' << sum_r << ' ' << new_a << ' ' << old_a << endl;
        sum_r = sum_r + new_a - old_a;;
        ans[pos] -= sum_r;
    }

    // cout << "******" << endl;
    ll max_ans = ans[n-1];
    rep(pos, n - 1, 2 * n)
        // cout << pos << ' ' << ans[pos] << endl;
        max_ans = max(max_ans, ans[pos]);
    cout << max_ans << endl;
    return 0;
}

Measured memory_bytes: 4724
N = int(input())
H = list(map(int,input().split()))
for i in reversed(range(N-1)):
    if(H[i] <= H[i+1]):
        continue
    elif(H[i]-1 == H[i+1]):
        H[i] -= 1
    else:
        print("No")
        exit()
print("Yes")

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll N,P,sum=0; cin>>N;
	
	ll A[100050]={};

	while(N--){
		cin>>P;
		A[P]++;
		sum+=P;
	}

	ll Q;	cin>>Q;
	while(Q--){
		ll B,C;	cin>>B>>C;
		sum+=(C-B)*A[B];
		cout<<sum<<endl;
		A[C]+=A[B];
		A[B]=0;
	}
	
    return 0;
}



Measured memory_bytes: 4424
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout << fixed << setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main() {
	int n = in();
	vector<array<int, 3>>cood(n + 1);
	cood[0] = { 0, 0, 0 };
	REP1(i, n) {
		int t = in(), x = in(), y = in();
		cood[i] = { t, x, y };
	}
	REP(i, n) {
		int dt = cood[i + 1][0] - cood[i][0];
		int manhattan = abs(cood[i + 1][1] - cood[i][1]) + abs(cood[i + 1][2] - cood[i][2]);
		if (manhattan > dt || (dt - manhattan) % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

int main(){
  vector<string> ans;
  string s;
  int K;
  cin>>s;
  cin>>K;
  for(int i=0;i<(int)s.size();i++){
    string tmp="";
    for(int j=0;j<5;j++){
      if(i+j<(int)s.size()){
        tmp+=s[i+j];
        ans.push_back(tmp);
      }
    }
  }
  sort(ans.begin(), ans.end());
  ans.erase( unique(ans.begin(), ans.end()), ans.end());
  cout<<ans[K-1]<<endl;
  return 0;
}


Measured memory_bytes: 1660
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

struct BIT{
private:
   int sz;
   vector<ll> node;
public:
   BIT(int n):sz(n),node(n+1){};
   void add(int k,ll x){
       k++;
       while(k<=sz){
           node[k]+=x;
           k+=k&-k;
       }
   }
   ll sum(int k){
       k++;
       ll ret=0;
       while(k>0){
           ret+=node[k];
           k-=k&-k;
       }
       return ret;
   }
   ll sum(int l,int r){
       return sum(r-1)-sum(l-1);
   }
   ll get(int k){
       return sum(k,k+1);
   }
};

int main(){
    cout<<fixed<<setprecision(10);
    int n;
    cin>>n;
    double a[n],b[n],c[n];
    rep(i,n)cin>>a[i]>>b[i]>>c[i];
    int ord[n];
    rep(i,n)ord[i]=i;
    sort(ord,ord+n,[&](int x,int y){return -a[y]/b[y]>-a[x]/b[x];});
    int inv[n];
    rep(i,n)inv[ord[i]]=i;
    int ord2[n];
    rep(i,n)ord2[i]=i;
    double d[n];
    rep(j,2){
    double left=-3e8,right=3e8,mid=0;
    rep(k,60){
        mid=(left+right)/2;
        BIT bit(n);
        rep(i,n)d[i]=(-a[i]*mid-c[i])/b[i];
        sort(ord2,ord2+n,[&](int x,int y){return d[x]<d[y];});
        int cnt=0;
        rep(i,n){
            int idx=inv[ord2[i]];
            cnt+=bit.sum(idx);
            bit.add(idx,1);
        }
        if(cnt<=n*(n-1)/4)left=mid;
        else right=mid;
    }
    cout<<-mid<<" ";
    rep(i,n)swap(a[i],b[i]);
    sort(ord,ord+n,[&](int x,int y){return -a[y]/b[y]>-a[x]/b[x];});
    rep(i,n)inv[ord[i]]=i;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 2304
input = gets().chomp

# input = readlines()
# meta = input.shift.chomp.split("\s").map{|x| x.to_i}

if input == 'SSS'
  puts '0'
elsif input == 'SRS' || input == 'SSR' || input == 'RSS' || input == 'RSR'
  puts '1'
elsif input == 'RRR'
  puts '3'
else
  puts '2'
end


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

int main()
{
	int n;

	while (scanf("%d", &n), n != 0){
		int prize[10000];
		for (int i = 0; i < n; i++){
			scanf("%d", &prize[i]);
		}

		if (n == 1){
			if (prize[0] >= 2){
				cout << "2" << endl;
			}
			else {
				cout << "NA" << endl;
			}
		}
		else {
			int max = 0;
			for (int i = 0; i < n; i++){
				if (max < prize[i]){
					max = prize[i];
				}
			}
			if (max < 2){
				cout << "NA" << endl;
			}
			else {
				int cnt = 0;
				for (int i = 0; i < n; i++){
					if (prize[i] != 0){
						cnt++;
					}
				}
				cout << cnt + 1 << endl;
			}
		}
	}

	return (0);
}

Measured memory_bytes: 1248
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#define INF 10000000

using namespace std;

typedef pair<int, int> P;
int n, k;
struct edge { int to, cost; };

int dijkstra2(int from, int to, vector<edge> g[101]);

int main() {
	vector<int> ans;
	while (1) {
		edge ff = { 1 , 1 };
		cin >> n >> k;
		vector<edge> g[101];

		if ((n == 0) && (k == 0)) break;
		

		for (int i = 0; i < k; i++) {
			int temp;
			cin >> temp;
			if (temp) {
				int c, d, e;
				cin >> c >> d >> e;

				edge w = { d,e };
				g[c].push_back(w);
				w.to = c;
				g[d].push_back(w);
			}
			else {
				int a, b;
				cin >> a >> b;
				ans.push_back(dijkstra2(a, b, g));
			}
		}
	}

	for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;

	return 0;
}


int dijkstra2(int from, int to, vector<edge> g[101]) {
	priority_queue<P, vector<P>, greater<P> > que;
	vector<int> d(101);
	fill(d.begin(), d.end(), INF);
	d[from] = 0;
	que.push(P(0, from));

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

	if (d[to] == INF) {
		return -1;
	}
	else {
		return d[to];
	}
	
}


Measured memory_bytes: 3104
def ncr(n, r):
  res = 1
  for k in range(r):
    res *= n - k
    res //= k + 1
  return res
 
(n, a, b) = [int(x) for x in input().split(' ')]
v = [int(x) for x in input().split(' ')]
v.sort(reverse=True)
 
su = 0
avg = 0
for x in v[:a]:
  su += x
avg = su / a
 
comb = 0
cnt1 = v.count(v[a - 1])
cnt2 = v[:a].count(v[a - 1])
if v[0] == v[a - 1]:
  for i, vi in enumerate(v[a - 1:b]):
    if vi == v[a - 1]:
      comb += ncr(cnt1, cnt2 + i)
else:
  comb = ncr(cnt1, cnt2)

print(avg)
print(comb)


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


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define pb push_back


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = pow(2, 62);
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alpha = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


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




/* main */







signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s = raw_input();
    int n = s.size();

    int ans = n * (n - 1) / 2 + 1;

    map<char, int> mp;

    rep(i,0,n) mp[s[i]]++;

    each(mp, itr){
        int cnt = itr -> second;
        ans -= cnt * (cnt - 1) / 2;
    }

    print(ans);






    

}



Measured memory_bytes: 720
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    sum = 0
    for i in range(1, N+1):
        S = str(i)
        wa = 0
        for s in S:
            wa += int(s)
        if wa >= A and wa <= B:
            sum += i
    print(sum)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    h, w = i_map()
    str_list = s_row_list(h)

    for i in range(h):
        for j in range(w):
            if str_list[i][j] == '#':
                continue
            count = 0
            for dx, dy in ([1, 0], [-1, 0], [0, 1], [0, -1], [1, 1], [1, -1], [-1, 1], [-1, -1]):
                ni = i + dx
                nj = j + dy
                if ni < 0 or ni >= h or nj < 0 or nj >= w:
                    continue
                if str_list[ni][nj] == '#':
                    count += 1
            str_list[i][j] = count

    for i in range(h):
        for j in range(w):
            print(str_list[i][j], end='')
        print('')
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 74048
#include <bits/stdc++.h>
using namespace std;
int n, a[100020], b[100020], c[100020];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &b[i]);
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &c[i]);
	}
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		int first = lower_bound(a, a + n, b[i]) - a;
		int third = n - (upper_bound(c, c + n, b[i]) - c);
		ans += (long long)first * third;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1408
// g++ -I ~/Documents/programming/cppLib -std=gnu++14 -o test ~/Documents/programming/cppLib/test.cpp && ./test && rm test
#include <bits/stdc++.h>
using namespace std;
template <typename T> using vector2 = vector <vector  <T>>;
template <typename T> using vector3 = vector <vector2 <T>>;
template <typename T> using vector4 = vector <vector3 <T>>;
using lint = long long;
#define FOR( i, a, b ) for( lint i=(a) ; i < (b) ; ++i )
#define REP( i, n )    for( lint i= 0  ; i < (n) ; ++i )
#define ALL( v )       (v).begin(), (v).end()

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

    A--; B--; C--; D--;

    vector<bool> S(N);
    REP( i, N ) {
        char c;
        cin >> c;
        S[i] = (c == '#') ? true : false;
    }

    if( A > C || B > D ) {
        cout << "No" << endl;
        return 0;
    }

    if( A < B && B < D && D < C ) {
        bool flg = true;
        for( int i=B; i<=D; i++ ) {
            if( (!S[i-1]) && (!S[i]) && (!S[i+1]) ) {
                flg = false;
            }
        }
        if( flg ) {
            cout << "No" << endl;
            return 0;
        }
    }

    if( B < A && A < C && C < D ) {
        bool flg = true;
        for( int i=A; i<=C; i++ ) {
            if( (!S[i-1]) && (!S[i]) && (!S[i+1]) ) {
                flg = false;
            }
        }
        if( flg ) {
            cout << "No" << endl;
            return 0;
        }
    }

    bool can = true;
    for( int i=A; i<C; i++ ) {
        if( S[i] && S[i+1] ) {
            can = false;
        }
    }

    for( int i=B; i<D; i++ ) {
        if( S[i] && S[i+1] ) {
            can = false;
        }
    }

    cout << (can ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

int main() {
  int x;
  cin >> x;
  int ans = 0;
  ans += 1000 * (x/500);
  x %= 500;
  ans += 5 * (x/5);
  cout << ans << endl;

  return 0;
}

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

using namespace std;

char x[20];
int a, b;

int main() {
	scanf("%d%d%s", &a, &b, x);
	for (int i = 0; i <= a + b; i++)
		if ((x[i] == '-') != (i == a)) {
			printf("No\n");
			return 0;
		}
	printf("Yes\n");
	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a == 1) {
    a += 13;
  }
  if (b == 1) {
    b += 13;
  }
  if (a > b) {
    cout << "Alice" << endl;
  }
  else if (a < b) {
    cout << "Bob" << endl;
  }
  else {
    cout << "Draw" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), G<type>())
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n, PER) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(roop, n) a[idx][roop] = v[roop]; idx++;} while(next_permutation(ALL(v))); PER = a;} while(0); // int fact(), VVI PERを宣言しておく、n=10が限界(500 ms)
#define ENDL cout << endl;

const int INF = 2e9;
const LL MOD = 1e9 + 7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string alp = "abcdefghijklmnopqrstuvwxyz";
  LL n;
  cin >> n;
  string ans = "";
  while(n > 0)
  {
    n--;
    int idx = n%26;
    ans += alp[idx];
    n /= 26;
  }
  REVERSE(ans);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		Coor[] cs = new Coor[n];
		for(int i = 0; i < n; i++){
			st = new StringTokenizer(br.readLine());
			int x = Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());
			char d = st.nextToken().charAt(0);
			cs[i] = new Coor(x, y, d);
		}
		double a = 0, b = 2*1e8+1;
		for(int iter = 0; iter < 200; iter++){
			double c = (2*a+b)/3;
			double d = (a+2*b)/3;
			double C = eval(cs, c);
			double D = eval(cs, d);
			if(C < D) b = d;
			else a = c;
		}
		System.out.println(eval(cs, a));
	}
	static double eval(Coor[] cs, double t){
		double maxx = -1e8, maxy = -1e8, minx = 1e8, miny = 1e8;
		for(Coor c: cs){
			double x = c.movex(t);
			double y = c.movey(t);
			maxx = Double.max(maxx, x);
			minx = Double.min(minx, x);
			miny = Double.min(miny, y);
			maxy = Double.max(maxy, y);
		}
		return (maxx - minx)*(maxy - miny);
	}
	static class Coor{
		int x, y; char d;
		public Coor(int x, int y, char d){
			this.x = x; this.y = y; this.d = d;
		}
		public String toString(){
			return x+" "+y;
		}
		public double movex(double t){
			if(d == 'L') return x-t;
			else if(d == 'R') return x+t;
			else return x;
		}
		public double movey(double t){
			if(d == 'U') return y+t;
			else if(d == 'D') return y-t;
			else return y;
		}
	}
	static class CoorNS implements Comparable<CoorNS>{
		int x, y; char d;
		public CoorNS(int x, int y, char d){
			this.x = x; this.y = y; this.d = d;
		}
		@Override
		public int compareTo(CoorNS c) {
			return y - c.y;
		}
		public String toString(){
			return x+" "+y;
		}
	}
	static class CoorWE implements Comparable<CoorWE>{
		int x, y; char d;
		public CoorWE(int x, int y, char d){
			this.x = x; this.y = y; this.d = d;
		}
		@Override
		public int compareTo(CoorWE c) {
			return x - c.x;
		}
		public String toString(){
			return x+" "+y;
		}
	}

}


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

long modpow(long x, long y, long m){
	long res = 1l, tmp = x;
	while(y){
		if(y&1)res = res * tmp % m;
		tmp = tmp * tmp % m;
		y >>= 1;
	}
	return res;
}

int bit_rev(int x, int h){
	int res = 0;
	for(int i=0; i<h; i++){
		res <<= 1;
		res |= x&1;
		x >>= 1;
	}
	return res;
}
void bit_rev_perm(long a[], int h){
	long *A = (long*)malloc(sizeof(long) * (1<<h));
	memcpy(A, a, sizeof(long) * (1<<h));
	for(int i=0; i<1<<h; i++){
		a[bit_rev(i, h)] = A[i];
	}
	free(A);
	return;
}
void dft(long a[], int h, bool sign, long m, long r){
	bit_rev_perm(a, h);
	for(int s=1; s<=h; s++){
		int tmp = 1<<s;
		long zeta = modpow(r, (m-1)>>s, m);
		if(!sign)zeta = modpow(zeta, m-2, m);
		for(int k=0; k<1<<h; k+=tmp){
			long pow_zeta = 1;
			for(int j=0; j<tmp/2; j++){
				long t = pow_zeta * a[k+j+tmp/2] % m,
					 u = a[k+j];
				a[k+j] = (u + t) % m;
				a[k+j+tmp/2] = (m + u - t) % m;
				pow_zeta = zeta * pow_zeta % m;
			}
		}
	}
	return;
}

const long mod = 998244353;
int N, M;
long A[1<<20], B[1<<20];
int main(){
	scanf("%d%d", &N, &M);
	for(int i=0; i<N; i++)scanf("%ld", &A[i]);
	for(int i=0; i<M; i++)scanf("%ld", &B[i]);
	dft(A, 20, true, mod, 3);
	dft(B, 20, true, mod, 3);
	for(int i=0; i<1<<20; i++)A[i] = A[i] * B[i] % mod;
	dft(A, 20, false, mod, 3);
	long inv = modpow(1<<20, mod-2, mod);
	for(int i=0; i<N+M-1; i++){
		if(i)putchar(32);
		printf("%ld", A[i] * inv % mod);
	}putchar(10);
	return 0;
}

Measured memory_bytes: 35300
import sys

H,W = map(int,input().split())

table = [[0]*(W+1) for i in range(H+1)]

for row in range(H):
  work = list(map(int,input().split()))
  for col in range(W):
    table[row][col] = work[col]

for row in range(H):
  for col in range(0,W):
    table[row][W] += table[row][col]

for col in range(0,W+1):
  for row in range(0,H):
    table[H][col] += table[row][col]

for row in range(0,H+1):
  print("%d"%(table[row][0]),end="")
  for col in range(1,W+1):
    print(" %d"%(table[row][col]),end="")
  print()


Measured memory_bytes: 6252
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<stdio.h>
using namespace std;
typedef unsigned long long ll;
ll mod = (10e+8)+ 7;

int main(){
	int N;
	int ans = 0;
	cin>>N;
	vector<int> W(N);
	for(int i = 0; i < N ; i ++){
		cin>>W[i];
		ans += W[i];
	}
	int a = 0;
	int b = 0;
	
	for(int T = 0; T < N; T++){
		
		a = b = 0;
		for(int i = 0; i < N; i++){
			if(i <= T)a+=W[i];
			else b+=W[i];
		}
		ans = min(ans, abs(a - b));
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ll;
 
struct Point {
    ll x, y;
 
    bool operator<(const Point &other) const {
        return x == other.x ? y < other.y : x < other.x;
    }
 
    Point operator-(const Point &other) const {
        return Point{x - other.x, y - other.y};
    }
};
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
 
    int n;
    cin >> n;
 
    vector<Point> pts(n);
    for (Point &p : pts)
        cin >> p.x >> p.y;
 
    sort(pts.begin(), pts.end());
    map<Point, int> occ;
 
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
          if(i != j)
            ++occ[pts[j] - pts[i]];
 
 
        int ans = n;
        for(auto e : occ)
            ans = min(ans, n- e.second);
        cout << ans;
    return 0;
}

Measured memory_bytes: 384
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()


def main():
    n, m, x = map(int, input().split())
    A = list(map(int, input().split()))
    idx = bisect_left(A, x)
    print(min(idx, m - idx))


if __name__ == "__main__":
    main()


Measured memory_bytes: 62132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    string s; cin >> s;
    s[5] = ' ', s[13] = ' ';
    cout << s << "\n";
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

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 ll INF=1e18;
const ll mod=1e9+7;

int main(){
    ll N;
    cin >> N;
    for(ll n=1;n<=3500;n++){
        for(ll w=1;w<=3500;w++){
            if(4*n*w-N*(n+w)>0){
                ll le=0,ri=3500;
                while(ri-le>1){
                    ll h=(ri+le)/2;
                    if((4*n*w-N*(n+w))*h-N*n*w>=0) ri=h;
                    else le=h;
                }
                if((4*n*w-N*(n+w))*ri-N*n*w==0){
                    cout << ri << " " << n << " " << w << endl;
                    return 0;
                }
            }
            else{
                ll le=0,ri=3500;
                while(ri-le>1){
                    ll h=(ri+le)/2;
                    if((4*n*w-N*(n+w))*h-N*n*w<=0) ri=h;
                    else le=h;
                }
                if((4*n*w-N*(n+w))*ri-N*n*w==0){
                    cout << ri << " " << n << " " << w << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}



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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

string a;
map<char,lli> m;
lli n;
lli ans;

int main(){
  cin >> a;
  for(char c : a){
    m[c]++;
  }
  n = a.size();
  ans = n*(n-1)/2;
  for(auto x : m){
    lli k = x.second;
    ans -= k*(k-1)/2;
  }
  cout << ans+1 << endl;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b>=c)
        puts("Yes");
    else
        puts("No");
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = 0;
            for (int i = 0; i < 4; i++)
            {
                a += ReadInt();
            }
            WriteLine(Floor(a / 60.0));
            WriteLine(a % 60);

        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=n-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    string s;
    int q;
    cin>>s>>q;

    vi que_t(q),que_f(q);
    vc<char> s1,s2,que_c(q);
    rep(i,q){
        cin>>que_t[i];
        if(que_t[i]==2){
            cin>>que_f[i]>>que_c[i];
        }
    }
    int rev=1;
    rep(i,q){
        if(que_t[i]==1)rev=!rev;
        else{
            if(que_f[i]-1==rev)s1.push_back(que_c[i]);
            else s2.push_back(que_c[i]);
        }
    }

    if(rev){
        rrep(i,s2.size())cout<<s2[i];
        cout<<s;
        rep(i,s1.size())cout<<s1[i];
        cout<<"\n";
    }else{
        rrep(i,s1.size())cout<<s1[i];
        rrep(i,s.length())cout<<s[i];
        rep(i,s2.size())cout<<s2[i];
        cout<<"\n";
    }

    return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(){
	int n;
	std::bitset<18> flag;
	int num_all_subsets = 0;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	num_all_subsets = pow(2, n);

	std::cout << "0:" << std::endl;

	for(int i = 1; i < num_all_subsets; i++){
		flag = std::bitset<18>(i);
		int num_subsets = flag.count();

		std::cout << i << ":";
		for(int j = 0; j < 18; j++){
			std::bitset<18> mask;

			mask.set(j);

			if(flag.test(j) && mask.test(j)){
				std::cout << " " << j;
			}
		}
		std::cout << std::endl;
	}

	return 0;
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string S;
    cin >> S;
    bool a = false, b = false;
    for(char c: S){
        if(c == 'A') a = true;
        if(c == 'B') b = true;
    }
    if(a && b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

public class Hello
{
    public static void Main()
    {
        var hs = new HashSet<int>();
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
            hs.Add(int.Parse(Console.ReadLine().Trim()));
        Console.WriteLine(hs.Count());
    }
}


Measured memory_bytes: 13280
import java.math.BigInteger;
import java.util.PriorityQueue;
import java.util.Scanner;
	
	class Main {
		public static void main(String args[]) {
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int l = sc.nextInt();
			
			PriorityQueue<String> list = new PriorityQueue<>();
			for (int i = 0; i < n; i++) {
				list.add(sc.next());
			}
			
			for (int i = 0; i < n; i++) {
				System.out.print(list.poll());
			}
			
		}
	}

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

int main(){
  int N,M;
  cin >> N >> M; //nm=65
  vector<int> H(N);
  vector<int> GM(N);
  for(int i =0;i<N;i++){
    cin >> H.at(i);//869121
  }
  for(int i =0;i<M;i++){
    int A,B;
    cin >>A>>B;
    if(H.at(A-1)>H.at(B-1)){
      GM.at(B-1)++;
    }
    else if(H.at(A-1)<H.at(B-1)){
      GM.at(A-1)++;
    }
    else if(H.at(A-1)==H.at(B-1)){
      GM.at(A-1)++;
      GM.at(B-1)++;
    }
  }
  int answer = 0;
  for(int i =0;i<N;i++){
    if(GM.at(i)==0){
      answer++;
    }
  }
  cout << answer << endl; 
  return 0;
}

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

using namespace std;

namespace {
    int N, A, B;
    void input() {
        cin >> N >> A >> B;
    }

    void solve() {
        cout << min(A * N, B) << endl;
    }
}

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



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

const int ARR_MAX = 1000000;
int fl[ARR_MAX];
int sm[ARR_MAX+1] = {0};

void init_arr();
void isfl(int);

int main(void) {
  int tag;
  init_arr();

  while(1){
    cin >> tag;
    if(tag == 0 || cin.eof()) break;
    isfl(tag);
    cout << sm[tag] << endl;
  }
  return 0;
}

void init_arr(){
  for(int i=0;i<ARR_MAX;i++) fl[i] = 1;
}

void isfl(int tag){
  int i,lim,idx = 2;
  fl[0] = 0;
  fl[1] = 0;

  lim = sqrt(tag);

  while(idx <= lim){
    if(fl[idx] == 1) for(i = idx*2;i<=tag;i+=idx) fl[i] = 0;
    idx++;

  }
  for(int i = 2;i<=tag;i++) sm[i] = sm[i-1] + fl[i];
  return;
}

Measured memory_bytes: 10860
#include <bits/stdc++.h>
#define LL long long
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF INT_MAX
#define inf LLONG_MAX
using namespace std;

const int N = 1e6 + 5;

int a[N];

int c[N], cc[N];

int main() {

    int n; scanf("%d", &n);

    rep(i, 1, n) scanf("%d", &a[i]);

    for(int i = 1; i <= n; i += 2) {
        c[a[i]]++;
    }
    for(int i = 2; i <= n; i += 2) {
        cc[a[i]]++;
    }
    int ma = 0, mx = -1, maa = 0, mxx = -1;
    for(int i = 1; i <= n; i += 2) {
        if(c[a[i]] > ma) {
            maa = ma; mxx = mx;
            ma = c[a[i]]; mx = a[i];
        }
        else if(c[a[i]] > maa) {
            maa = c[a[i]]; mxx = a[i];
        }
        c[a[i]] = -1;
    }
    int MA = 0, MX = -1, MAA = 0, MXX = -1;
    for(int i = 2; i <= n; i += 2) {
        if(cc[a[i]] > MA) {
            MAA = MA; MXX = MX;
            MA = cc[a[i]]; MX = a[i];
        }
        else if(cc[a[i]] > MAA) {
            MAA = cc[a[i]]; MXX = a[i];
        }
        cc[a[i]] = -1;
    }
    if(mx != MX) {
        printf("%d\n", n - ma - MA);
    }
    else {
        int ans1 = ma + MAA;
        int ans2 = maa + MA;
        printf("%d\n", n - max(ans1, ans2));
    }
    return 0;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define ff first
#define ss second
#define long int64_t
using namespace std;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<> dis(0, INF<<1);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args)
{ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma+1, args...); }

int main()
{
	fio;
	string s;
	cin >> s;
	s += '0';
	long ans = 0;
	char p = 0;
	int cnt = 0, pc = 0;
	for(char c : s)
	{
		if(p == c)
			cnt++;
		else
		{
			if(p == '<')
				ans += (cnt * 1ll * (cnt + 1)) >> 1;
			else
			{
				ans += (cnt * 1ll * (cnt - 1)) >> 1;
				if(pc < cnt)
					ans += cnt - pc;
			}
			pc = cnt;
			cnt = 1;
			p = c;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1172