akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define mid (l+r)/2
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
const int N=1e6+10;
const int inf=0x3f3f3f3f;
int du[N],x[N],p[N],ans[N],top,tot,n,k;
priority_queue <int,vector<int>,greater<int> >q;
int head[N];
struct node{
	int too,next;
}edge[N*2];
void add(int a,int b)
{
    edge[++top].too=b;edge[top].next=head[a];head[a]=top;
}
int mi[N*4];
void change(int nod,int l,int r,int x,int val)
{
    if(l==r){mi[nod]=val;return;}
    if(x<=mid) change(nod*2,l,mid,x,val);
    else change(nod*2+1,mid+1,r,x,val);
    mi[nod]=min(mi[nod*2],mi[nod*2+1]);
}
int query(int nod,int l,int r,int L,int R)
{
    if(mi[nod]==inf)return inf;
    if(l==L&&r==R)return mi[nod];
    if(R<=mid)return query(nod*2,l,mid,L,R);
    else if(L>mid)return query(nod*2+1,mid+1,r,L,R);
    else return min(query(nod*2,l,mid,L,mid),query(nod*2+1,mid+1,r,mid+1,R));
}
int main()
{
    n=read();k=read();
    for(int i=1;i<=n;i++)p[read()]=i;
    memset(mi,0x3f,sizeof(mi));
    for(int i=n;i;i--)
    {
        int x=query(1,1,n,p[i],min(n,p[i]+k-1));
        if(x!=inf)add(p[i],p[x]),++du[p[x]];
        x=query(1,1,n,max(1,p[i]-k+1),p[i]);
        if(x!=inf) add(p[i],p[x]),++du[p[x]];
        change(1,1,n,p[i],i);
    }
    for(int i=1;i<=n;i++)if(!du[i])q.push(i);
    while(!q.empty())
    {
        int now=q.top();
        ans[now]=++tot;
        q.pop();
        for(int i=head[now];i;i=edge[i].next)
        {
            int v=edge[i].too;
            --du[v];
            if(!du[v])q.push(v);
        }
    }
    for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
    return 0;
}

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

using namespace __gnu_pbds;
using namespace std;

template <class T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

void usaco(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

#define int long long

const int mod = 1e9+7;

int power(int x, int y)
{
    x %= mod;
    int res = 1;
    while (y)
    {
        if (y & 1) res = (res * x) % mod;
        y >>= 1;
        x = (x * x) % mod;
    }
    return res;
}

int dif(int x, int y) {return ((x-y+mod) % mod);}
int add(int x, int y) {return ((x+y+mod) % mod);}

int32_t main()
{
    usaco();
    int n;
    cin >> n;
    if (n == 1)
    {
        cout << "0\n";
        return 0;
    }
    cout << add(dif(dif(power(10, n), power(9, n)), power(9, n)), power(8, n));
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{
    int n;
    cin>>n;
    int a[n+1];
    for (int i = 1; i <= n; ++i) {
        cin>>a[i];
    }

    int ans[n+1]={0};
    for (int i = n; i >=1 ; --i) {
        int cnt=0;
        for (int j = 2*i; j <=n ; j+=i) {
            cnt+=ans[j];
        }
        if(cnt%2!=a[i]%2)
            ans[i]=1;
    }


    vector<int>res;
    for (int i = 1; i <=n ; ++i) {
        if(ans[i]==1)
            res.push_back(i);
    }

    cout<<res.size()<<"\n";
    for(auto i:res)
        cout<<i<<" ";
}

Measured memory_bytes: 4980
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int n;cin>>n;int ans=0;int m=0;
    string s;cin>>s;
    for(int i=0;i<n;i++){if(s[i]=='I'){m++;ans=max(ans,m);}else{m--;}}
    cout<<ans<<endl;
  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int a[200000], b[200000];
int *tree[200000], d[200000], cnt[200000], cnts[200000];
int n;
long long int modpow(long long int p, long long int n, long long int mod){
    long long int res = 1;
    while(n > 0){
        if(n & 1){
            res = res * p % mod;
        }
        p = p * p % mod;
        n >>= 1;
    }
    return res;
}

long long int modinv(long long int p, long long int mod) {//逆元 p^{-1}の計算
    return modpow(p, mod - 2, mod);
}

int DFS(int x, int y){//xが今いる頂点，yが前にいた頂点
    //2つの値を求める，tree[x][x_cnt] = y, tree[y][y_cnt] = xとなる
    //x_cnt, y_cnt
    int i;
    int t = 1, t_tmp;
    for(i = 0; i < cnt[x]; i++){
        if(y == tree[x][i]){
            continue;
        }
        t += DFS(tree[x][i], x);
    }
    d[x] = t;
    return t;
}

int main(void){
    int i, j;
    long long int mod = 1000000007;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        cnt[i] = 0;
        cnts[i] = 0;
        d[i] = 1;
    }
 
    for(i = 0; i < n - 1; i++){
        scanf("%d%d", &a[i], &b[i]);
        a[i]--;
        b[i]--;
        cnt[a[i]]++;
        cnt[b[i]]++;
    }
 
    for(i = 0; i < n; i++){
        tree[i] = (int *)malloc(sizeof(int) * (cnt[i] + 1));
        if(tree[i] == NULL){
            return 0;
        }
    }

    for(i = 0; i < n; i++){
        tree[a[i]][cnts[a[i]]] = b[i];
        tree[b[i]][cnts[b[i]]] = a[i];
        cnts[a[i]]++;
        cnts[b[i]]++;
    }

    DFS(0, -1);
    //long long int bunnshi1 = 0;
    long long int bunnshi = 0;
    int x1, x2;
    for(i = 0; i < n-1; i++){
        x1 = d[a[i]];
        x2 = d[b[i]];
        if(x1 > x2){
            x1 = n - x2;
        }else{
            x2 = n - x1;
        }
        bunnshi += modpow(2, n, mod) + 1 - modpow(2, x1, mod) - modpow(2, x2, mod);
        bunnshi %= mod;

        //bunnshi1 += pow(2, n) + 1 - pow(2, x1) - pow(2, x2);
    }
    //bunnshi1 += (pow(2, n) - 1) - pow(2, n-1) * n;
    //long long int bunnbo1 = pow(2, n);
    //printf("%lld %lld\n", bunnshi1 , bunnbo1);

    bunnshi += modpow(2, n, mod) - 1 - modpow(2, n-1, mod) * n;
    bunnshi %= mod;
    long long int bunnbo = modinv(2, mod);//2の逆元
    bunnbo = modpow(bunnbo, n, mod);//2の逆元をn乗する
    long long int ans = bunnshi*bunnbo%mod;
    while(ans < 0){
        ans += mod;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 24548
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#define mm(a,x) memset(a,x,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
#define ll long long
using namespace std;
const int MAXN=1e5+10;
struct 
priority_queue<int,vector<int>,greater<int> >que1;
priority_queue<int,vector<int>,greater<int> >que2;
int main(void)
{
    sync;
    int x,y,A,B,C;
    cin>>x>>y>>A>>B>>C;
    int tmp;
    for(int i=0;i<A;++i)
    {
        cin>>tmp;
        if((int)que1.size()<x)
            que1.push(tmp);
        else if(tmp>que1.top())
        {
            que1.pop();
            que1.push(tmp);
        }
    }
    for(int i=0;i<B;++i)
    {
        cin>>tmp;
        if((int)que2.size()<y)
            que2.push(tmp);
        else if(tmp>que2.top())
        {
            que2.pop();
            que2.push(tmp);
        }
    }
    for(int i=0;i<y;++i)
    {
        que1.push(que2.top());
        que2.pop();
    }
    for(int i=0;i<C;++i)
    {
        cin>>tmp;
        if(tmp>que1.top())
        {
            que1.pop();
            que1.push(tmp);
        }
    }
    ll res=0;
    while(que1.size())
	{
        res+=(ll)que1.top();
        que1.pop();
    }
    while(que2.size())
	{
        res+=(ll)que2.top();
        que2.pop();
    }
    cout<<res<<endl;
    return 0;
}

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

char s[1 << 20];
int dp[1 << 20];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> (s + 1);
	int n = strlen(s + 1); 
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		if (dp[i]) {
			if (strncmp(s + i + 1, "dream", 5) == 0) dp[i + 5] = 1;
			if (strncmp(s + i + 1, "dreamer", 7) == 0) dp[i + 7] = 1;
			if (strncmp(s + i + 1, "erase", 5) == 0) dp[i + 5] = 1;
			if (strncmp(s + i + 1, "eraser", 6) == 0) dp[i + 6] = 1;
		}
	}
	if (dp[n]) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}



Measured memory_bytes: 4112
using namespace std;
#include<string>
#include<cmath>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define ppl pair<ll,ll>
#define F first
#define S second
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)

#define fr(i,a,b) for(ll i=a;i<b;i++)
#define ffr(i,a,b) for(ll i=a;i>=b;i--)
#include<bits/stdc++.h>
#include<vector>
#define vl vector<ll>
#define PI 3.141592654
const ll N = 1e9;
#include<iterator>

void solve() {
	ll n, a = 0; cin >> n;
	char c[n], p[n];
	fr(i, 0, n) {
		cin >> c[i];
		p[i] = c[i];
	}
	sort(p, p + n);
	fr(i, 0, n) {
		if (p[i] != c[i])a++;
	}
	cout << a / 2;
}


int main() {
	fio;
#ifndef ONLINE_JUDGE
	// for getting input
	freopen("input.txt", "r", stdin);
	//for writing output
	freopen("jout.txt", "w", stdout);
#endif

	ll t;
	if (1)
		t = 1;
	else
		cin >> t;
	while (t--) {
		//cout << "Case #" << h << ":\n";
		solve();
		//h++;
		cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 4004
#include<cstdio>
#include<cstring>

using namespace std;
int main(void)
{
	char r[100000];
	int kari[100000] = {0};
	while(scanf("%s",r) != EOF)
	{
		long long int ans = 0;
		int rs = strlen(r);
		for(int i = 0;i < rs;i++)
		{
			     if(r[i] == 'I') kari[i] = 1;
			else if(r[i] == 'V') kari[i] = 5;
			else if(r[i] == 'X') kari[i] = 10;
			else if(r[i] == 'L') kari[i] = 50;
			else if(r[i] == 'C') kari[i] = 100;
			else if(r[i] == 'D') kari[i] = 500;
			else if(r[i] == 'M') kari[i] = 1000;
		}

		for(int i = 0;i < rs - 1;i++)
		{
			if(kari[i] < kari[i+1]) ans -= kari[i];
			else ans += kari[i];
		}
		ans += kari[rs -1];
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1372
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define pye cout << "Yes" << endl;
#define pno cout << "No" << endl;
#define prin(num) cout << num << endl;
#define sprin(str) cout << "str" << endl;
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100001
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<ll> PQ;
typedef pair<double, double> doup;
typedef vector<ll> vec;
typedef vector<vec> mat;


int main() {
    ll N;
    cin >> N;
    ll i;
    ll d[MAX];
    for(i=0; i<=N; i++)
        d[i]=-1;
    d[0]=0;
    queue<ll> q;
    q.push(0);
    ll u;
    ll psix, pnin;
    
    while(q.size()) {
        u=q.front(); q.pop();
        
        for(psix=1; u+psix<=N; psix*=6) {
            if(d[u+psix]==-1) {
                d[u+psix]=d[u]+1;
                q.push(u+psix);
            }
            
            for(pnin=1; u+pnin<=N; pnin*=9) {
                if(d[u+pnin]==-1) {
                    d[u+pnin]=d[u]+1;
                    q.push(u+pnin);
                }
            }
            
        }
        
    }
    
    prin(d[N]);
}


Measured memory_bytes: 1152
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353

class UnionFind:
    def __init__(self, size=None, nodes=None):
        """
        size か nodes どっちか指定。
        nodes は set、size は list を使う。
        :param int size:
        :param collections.Iterable nodes:
        """
        assert size is not None or nodes is not None
        if size is not None:
            self._parents = [i for i in range(size)]
            self._ranks = [0 for _ in range(size)]
            self._sizes = [1 for _ in range(size)]
        else:
            self._parents = {k: k for k in nodes}
            self._ranks = {k: 0 for k in nodes}
            self._sizes = {k: 1 for k in nodes}

    def unite(self, x, y):
        """
        x が属する木と y が属する木を併合
        :param x:
        :param y:
        """
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return

        # rank が小さい方が下
        if self._ranks[x] > self._ranks[y]:
            # x が root
            self._parents[y] = x
            self._sizes[x] += self._sizes[y]
        else:
            # y が root
            self._parents[x] = y
            self._sizes[y] += self._sizes[x]
            if self._ranks[x] == self._ranks[y]:
                self._ranks[y] += 1

    def root(self, x):
        """
        x が属する木の root
        :param x:
        """
        if self._parents[x] == x:
            return x
        self._parents[x] = self.root(self._parents[x])
        return self._parents[x]

    def size(self, x):
        """
        x が属する木のノード数
        :param x:
        """
        return self._sizes[self.root(x)]


N, M = list(map(int, sys.stdin.buffer.readline().split()))
P = list(map(int, sys.stdin.buffer.readline().split()))
XY = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]

uf = UnionFind(size=N + 1)
for x, y in XY:
    uf.unite(x, y)

ans = 0
for i, p in enumerate(P, start=1):
    ans += uf.root(i) == uf.root(p)
print(ans)


Measured memory_bytes: 95128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;

int main(){
    double a,b,x;
    cin>>a>>b>>x;
    double tr=a*a*b/2;
    double ans;
    if(tr>=x){
        ans=atan(a*b*b/(2*x));
    }else{
        ans=atan(2*(b-x/(a*a))/a);
    }
    cout<<fixed<<setprecision(10)<<ans*180/M_PI<<endl;
}

Measured memory_bytes: 384
n = int(input())
d = dict()
for i in range(n):
    dd = dict()
    s = input().strip()
    for c in set(s):
        dd[c] = s.count(c)

    if i == 0:
        d = dd
    else:
        deleted = []
        for c, count in d.items():
            if c not in dd:
                deleted.append(c)
                continue

            d[c] = min(d[c], dd[c])

        for c in deleted:
            del d[c]

s = ''
for c, count in sorted(d.items(), key=lambda x: x[0]):
    s += c * count

if s != '':
    print(s)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<n+1;i++)

using namespace std;
using std::swap;

//vector<long long int> p;
vector<long long int> v;
vector<long long int> w;



int main() {
	int N, M;
	cin >> N >> M;
	if (N == M) {
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}


	return 0;
}

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

int main() {
	int n;
	vector<int> va;
	
	cin >> n;
	for (int i=0; i!=n; ++i){
		int tmp;
		cin >> tmp;
		va.push_back(tmp);
	}
	for(auto rit=va.rbegin(); rit!=va.rend();++rit){
		cout << *rit;
		if (rit!=--(va.rend())){
			cout << ' ';
		}
	}
	cout << endl;
}

Measured memory_bytes: 1216
N = int(input())
A = list(map(int, input().split()))
M = [0] * (N + 1)
for i in range(N):
    M[i + 1] = max(M[i], A[i])
ans = 0
for i in range(N):
    if A[i] < M[i]:
        ans += M[i] - A[i]
print(ans)


Measured memory_bytes: 32208
import sys
input = sys.stdin.buffer.readline

def main():
    N,M = map(int,input().split())
    a = [list(map(int,input().split())) for _ in range(N)]
    
    def p(s):
        if all(s) == True:
            return 300
        al = [0 for _ in range(M)]
        for i in range(N):
            for j in a[i]:
                if not s[j-1]:
                    al[j-1] += 1
                    break
        count,index = max(al),al.index(max(al))
        s[index] = True
        return min(count,p(s))
    
    s = [False for _ in range(M)]
    print(p(s))

if __name__ == "__main__":
    main()


Measured memory_bytes: 5264
import sys
sys.setrecursionlimit(10**9)
n = int(input())
to = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b, c = map(int, input().split())
    to[a].append((b, c))
    to[b].append((a, c))

q, k = map(int, input().split())
dist_k = [0] + [-1] * n
dist_k[k] = 0

def dfs(v):
    for u, du in to[v]:
        if dist_k[u] != -1:
            continue
        dist_k[u] = dist_k[v] + du
        dfs(u)
dfs(k)
dist_xky = [0] * q
for i in range(q):
    x, y = map(int, input().split())
    dist_xky[i] = dist_k[x] + dist_k[y]
print(*dist_xky, sep='\n')

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

int main(){
	LL a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	c *= 2;
	a = min(a, c);
	b = min(b, c);
	c = min(c, a+b);
	LL ans = a*x + b*y;
	if(x > y){
		ans = min(ans, (x-y)*a + y*c);
	} else {
		ans = min(ans, (y-x)*b + x*c);		
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int x[100000];

struct UnionFind {
  UnionFind(int sz) : data(sz) {
    REP(i, sz) data[i] = -x[i];
  }

  int root(int ver) { return data[ver] < 0 ? ver : data[ver] = root(data[ver]); }

  void unite(int ver1, int ver2) {
    ver1 = root(ver1);
    ver2 = root(ver2);
    if (ver1 != ver2) {
      if (data[ver1] > data[ver2]) swap(ver1, ver2);
      data[ver1] += data[ver2];
      data[ver2] = ver1;
    }
  }

  bool same(int ver1, int ver2) { return root(ver1) == root(ver2); }

  long long size(int ver) { return -data[root(ver)]; }

private:
  vector<long long> data;
};

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m; cin >> n >> m;
  REP(i, n) cin >> x[i];
  UnionFind uf(n);
  vector<pair<int, pair<int, int> > > aby(m);
  REP(i, m) {
    int a, b, y; cin >> a >> b >> y; --a; --b;
    aby[i] = {y, {a, b}};
  }
  sort(ALL(aby));
  vector<vector<int> > edge(n);
  vector<int> ok;
  REP(i, m) {
    int cost = aby[i].first, ver1 = aby[i].second.first, ver2 = aby[i].second.second;
    uf.unite(ver1, ver2);
    if (uf.size(ver1) >= cost) ok.emplace_back(i);
    edge[ver1].emplace_back(i);
    edge[ver2].emplace_back(i);
  }
  reverse(ALL(ok));
  vector<bool> used(m, false);
  for (int num : ok) {
    used[num] = true;
    int cost = num;
    queue<int> que;
    que.emplace(aby[num].second.first);
    que.emplace(aby[num].second.second);
    while (!que.empty()) {
      int ver = que.front(); que.pop();
      for (int v : edge[ver]) if (!used[v] && v <= num) {
        used[v] = true;
        que.emplace(aby[v].second.first);
        que.emplace(aby[v].second.second);
      }
    }
  }
  int ans = m;
  REP(i, m) if (used[i]) --ans;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 8568
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,c;
    cin >> a >> b >> c;
    vi v({a, b, c});
    sort(v.begin(), v.end());
    cout << ((v.at(0) != v.at(1)?1:0) + (v.at(1) != v.at(2)?1:0) + 1) << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
)

func f(x int) int {
	if x == 0 {
		return 0
	}
	return f(x%bits.OnesCount32(uint32(x))) + 1
}

func main() {
	var n int
	var s string
	fmt.Scan(&n)
	fmt.Scan(&s)
	x := make([]int, n)
	for i, c := range s {
		x[i] = int(c - '0')
	}
	// popcount(X0)
	pc := 0
	for _, v := range x {
		pc += v
	}
	pc0 := pc + 1
	pc1 := pc - 1

	xr := [2]int{}
	r := make([][2]int, n)
	k0 := 1
	k1 := 1
	for i := n - 1; i >= 0; i-- {
		if x[i] == 1 {
			xr[0] += k0
			xr[0] %= pc0
			if pc1 > 0 {
				xr[1] += k1
				xr[1] %= pc1
			}
		}
		r[i][0] = k0
		r[i][1] = k1
		k0 = (2 * k0) % pc0
		if pc1 > 0 {
			k1 = (2 * k1) % pc1
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		var xi int
		if x[i] == 1 {
			if pc == 1 {
				fmt.Fprintln(w, 0)
				continue
			}
			xi = (xr[1] - r[i][1] + pc1) % pc1
		} else {
			xi = (xr[0] + r[i][0]) % pc0
		}
		fmt.Fprintln(w, f(xi)+1)
	}
	w.Flush()
}


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

int main(){
    vector<int> x(5);
    rep(i, 5){cin >> x[i];}
    rep(i, 5){if (x[i] == 0) cout << i+1 << endl;}
}   


Measured memory_bytes: 3620
// In the name of God //
 
#include <bits/stdc++.h>
#define ll long long
#define all(x) (x).begin(), (x).end()
#define pii pair <int, int>
using namespace std;
const int N = 2e5 + 5;

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(all(a));
    reverse(all(a));
    long long ans = 0;
    ans += a[0];
    int j = 1, k = 0;;
    for (int i = 2; i < n; i ++) {
        ans += a[j];
        k++;
        if (k == 2) {
            j++;
            k = 0;
        }
    }
    cout << ans;
}

int main()  {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
    // cin >> tt;
    for (int tc = 1; tc <= tt; ++tc) {
        solve();
    } 
}                                   

Measured memory_bytes: 4780
n,m=map(int,input().split())
a=list()
a=input().split()
a=[int(i) for i in a]
a.sort()
for i in range(m):
  if a[(n-1)-i]<sum(a)/(4*m):
    result=0
  else :
    result=1
    
if result==1:
  print('Yes')
elif result==0:
  print('No')

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

ll dp[3005][3005];
bool solved[3005][3005];
int l[3005];
int n;

ll solve(int lhs, int rhs) {
  if(lhs == rhs) {
    return l[lhs];
  }
  if(solved[lhs][rhs]) return dp[lhs][rhs];
  solved[lhs][rhs] = true;
  dp[lhs][rhs] = max(l[lhs] - solve(lhs+1, rhs), l[rhs] - solve(lhs, rhs-1));
  return dp[lhs][rhs];
}

void solve() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> l[i];
  }
  cout << solve(0, n-1) << endl;
}

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


Measured memory_bytes: 78464
#include<iostream>
#include<cmath>
#include<cstring>

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

int main(){

	char p[MAX];
	int cnt;
	memset(p,1,sizeof(p));
	p[0] = 0;
	p[1] = 0;

	for(int i=2; i<sqrt(MAX)+1;i++){
		if(p[i])
			for(int j=2*i; j<MAX; j+=i){
				p[j] = 0;
			}
	}
	int a,d,n;
	while(std::cin >> a >> d >> n, (a||d||n)){
		cnt=0;
		long int i=a;
		while(1){
			if(p[i] == 1)cnt++;
			if(cnt == n){
				std::cout << i << std::endl;
				break;
			}
			i += d;
		}
	}
	return 0;
}

Measured memory_bytes: 0
from collections import Counter
N,X,Y = map(int, input().split())
X -= 1
Y -= 1
L = []
for i in range(N-1):
  for j in range(i+1,N):
    L.append(min(abs(i-j),abs(X-i)+abs(Y-j)+1,abs(Y-i)+abs(X-j)+1))
D = Counter(L)
for k in range(1,N):
  print (D[k])

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

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

	int n, k;
	int temp;
	long long int ans(0);
	priority_queue<int, vector<int>, greater<int> > pq;;
	cin >> n >> k;

	for (int i = 0; i < n; i++) {
		cin >> temp;
		pq.push(temp);
	}

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

	for (int i = 0; i < n - k; i++)
	{
		ans += pq.top();
		pq.pop();
	}

	cout << ans;

	return 0;
}

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

int main()
{
	int A,B,C,D;cin>>A>>B>>C>>D;
  	double result = (double)A*B/2.00000;
  	if(A==2*C && B==2*D)cout<<fixed<<result<<" "<<1<<endl;
  	else cout<<fixed<<result<<" "<<0<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;

int main(void) {

  int a, b;
  cin >> a >> b;
  if( (a+b) % 2 == 0 ) cout << (a+b)/2 << endl;
  else cout << (a+b)/2 + 1 << endl;

  return 0;
}

// EOF


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<vector<char>> a(h, vector<char>(w));
	rep(i, h)rep(j, w) cin >> a[i][j];
	rep(i, w + 2) cout << '#';
	cout << endl;
	rep(i, h) {
		cout << '#';
		rep(j, w) cout << a[i][j];
		cout << '#' << endl;
	}
	rep(i, w + 2) cout << '#';
	cout << endl;
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    set<string> x;
    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        x.insert(s);
    }
    cout << x.size() << endl;
}

Measured memory_bytes: 19180
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_9_B
#???????????? 17:55~

def maxHeapify(heap, index):
    left_index = 2 * index
    right_index = 2 * index + 1

    if left_index < len(heap) and heap[left_index] > heap[index]:
        largest_index = left_index
    else:
        largest_index = index

    if right_index < len(heap) and heap[right_index] > heap[largest_index]:
        largest_index = right_index

    if not largest_index == index:
        heap[index], heap[largest_index] = heap[largest_index], heap[index]
        maxHeapify(heap, largest_index)
    
def main():
    n_node = int(input())
    target_list = [""] + [int(n) for n in input().split()]
    for i in range(1, int(len(target_list) / 2) + 1)[::-1]:
        maxHeapify(target_list, i)
        
    print(*target_list)
if __name__ == "__main__":
    main()

Measured memory_bytes: 65916
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 7)
    {
        if (b == 5 && c == 5)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    else if (b == 7)
    {
        if (a == 5 && c == 5)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    else if (c == 7)
    {
        if (b == 5 && a == 5)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad.ST
import Data.Array.ST


readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [h,w] <- getIntList
    grid <- V.fromList <$> replicateM h (VU.fromList <$> getLine)
    print $ solve h w grid

solve h w grid = runST $ do
    arr <- newArray ((-1,-1),(h-1,w-1)) 0 :: ST s (STUArray s (Int,Int) Int)
    writeArray arr (0,0) 1
    forM_ [0..h-1] $ \i -> do
        forM_ [0..w-1] $ \j -> do
            when (i+j /= 0 && grid V.! i VU.! j == '.') $ do
                pi <- readArray arr (i-1,j)
                pj <- readArray arr (i,j-1)
                writeArray arr (i,j) $ (pi + pj) `mod` 1000000007
    readArray arr (h-1,w-1)

Measured memory_bytes: 59644
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (a) - 1; (i) >= (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main(){
    string s;
    ll k;
    cin >> s >> k;
    rep0(i, s.size()){
        if(i == s.size() - 1)s[i] = (s[i] - 'a' + k) % 26 + 97;
        else if(s[i] != 'a' && s[i] + k >= 123){
            k -= 123 - s[i];
            s[i] = 'a';
        }
    }
    pf(s);
    return 0;
}


Measured memory_bytes: 512
n = int(input())
H = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
for i in range(n):
    b, f, r, v = map(int, input().split())
    H[b-1][f-1][r-1] += v
for b in range(4):
    for f in range(3):
        A = map(str, H[b][f])
        a = ' '+' '.join(A)
        print(a)
    if b == 3:
        exit()
    print('#'*20)



Measured memory_bytes: 5604
'use strict'

function main(input) {
  let a = input.split(/\n|\s/).map(v => ~~v)
  a = a.slice(0, -1)

  const grid = a[0] * a[1]
  const black = a[2] * a[1] + a[3] * a[0] - a[2] * a[3]
  console.log(grid - black)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

using namespace std;

int fir[3] = {0, 0, 0};

int* recal(int* arr, int newval){
    for(int i = 0; i < 3; i++){
        if(arr[i] <= newval){
            swap(arr[i], newval);
        }
    }
    return arr;
}

int main(){
    for(int i = 0; i < 10; i++){
        int t;
        cin >> t;
        recal(fir, t);
    }
    for(int i = 0; i <3; i++){
        cout << fir[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
using namespace std;
map<int, int> ct;
map<int, int> ct2;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPS 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define AFOR(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n, m, l;
int a, b, c;
string s[MN];
string str;
string ans;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

/*
int N;
cin >> N;
vi vect(N);
FOR(i,N) cin >> vec.at(i);*/
//sort(vec.begin(),vec.end());
//vvi data(N,vi(4));


/*	int bfs(int x, int y,vvi &A,vvi flag) {
		queue<pii> que;
		que.push(pii(x, y));
		while (que.size()) {
			pii p = que.front(); que.pop();
			AFOR(i, 4) {
				int nx = p.first + dx[i]; int ny = p.second + dy[i];
				if (0 <= nx && nx < N && 0 <= ny && ny < N) {
					if (A.at(p.first).at(p.second) + flag.at(p.first).at(p.second) < A.at(nx).at(ny)) {
						A.at(nx).at(ny) = A.at(p.first).at(p.second) + flag.at(p.first).at(p.second);
						que.push(pii(nx, ny));
					}
				}
			}
		}
		return 0;
	}
	*/
	/*int gcd(int p, int q){
		while(q != 0){
		int r = p % q;
		p = q;
		q = r;
		}
	return p;
	}*/
int N;
int A[200100];
int L[200100];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int H, M, X, Y, K;
	cin >> H >> M >> X >> Y >> K;
	int ans;
	H *= 60;
	X *= 60;
	H = H + M;
	X = X + Y;
	X = X - K;
	ans = X - H;

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,l;
  cin >> n >> l;
  vector<string>vec(n);
  
  rep(i,n) cin >> vec[i];
  sort(vec.begin(),vec.end());
  
  rep(i,n) cout << vec[i];
  
  cout << endl;
 
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  int d,g;
  cin >> d >> g;
  vector<int> p(d),c(d);
  rep(i,d) cin >> p[i] >> c[i];
  
  int ans = 1 << 30;
  for(int bit = 0; bit < (1 << d);bit++){
    int question = 0; int score = 0; 
    for(int i = 0; i < d;i++){
      if(bit & (1<<i)){//もしiビット目が立っていたら
        question += p[i]; //全問回答する
        score += p[i]*(i+1)*100 + c[i]; //ボーナスも含めて足しこむ
      }
    }
    if(score < g){//それでも点数が足りなかった場合
      for(int j = d-1;j>=0;j--){//高い方の問題からビットチェック
        if(!(bit & (1<<j))){//フラグが立っていないものがあったら
          for(int k = 0;k<p[j]-1;k++){//問題数まで足し込んでいく
            question++;
            score += (j+1)*100;
            if(score>=g) break; //scoreが目標値まで達したらbreak;
          }
          break; //ループ脱出
        }
      }
    }
    if(score>=g){
      //cout << bitset<5>(bit) << " " << score << " " << question << endl;
      chmin(ans,question);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))

cnt = 1
last = [-1,-1,-1]

for a in A:
    cnt *= last.count(a-1)
    cnt %= MOD
    if cnt == 0:
        break
    last[last.index(a-1)] += 1

print(cnt)

Measured memory_bytes: 14056
H,W = gets.split.map(&:to_i)

if H%3==0 || H%3==0
  p 0
  exit
end

# first
short_height = (H.to_f/3.to_f).round
rest_height = (H-short_height)

# cut different directions
short_width = (W.to_f/2.to_f).round
rest_width = (W-short_width)
a = W * short_height
b = rest_height*short_width
c = rest_height*rest_width

# cut same directions
second_short_height = ((H-short_height).to_f/2.to_f).round
b2 = second_short_height*W
c2 = (rest_height-second_short_height)*W

pattern1 = [a,b,c].max - [a,b,c].min
pattern2 = [a,b2,c2].max - [a,b2,c2].min

result1 = [pattern1, pattern2].min

#second
short_height = (W.to_f/3.to_f).round
rest_height = (W-short_height)

# cut different directions
short_width = (H.to_f/2.to_f).round
rest_width = (H-short_width)
a = H * short_height
b = rest_height*short_width
c = rest_height*rest_width

# cut same directions
second_short_height = ((W-short_height).to_f/2.to_f).round
b2 = second_short_height*H
c2 = (rest_height-second_short_height)*H

pattern1 = [a,b,c].max - [a,b,c].min
pattern2 = [a,b2,c2].max - [a,b2,c2].min

result2 = [pattern1, pattern2].min


result = [result1, result2].min
p result




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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(), (a).end()

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

void sayYes() {puts("Yes");}
void sayNo() {puts("No");}
template<class T> bool chmin(T&a,T b) {if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b) {if(a<b){a=b;return true;}return false;}

class FastIO {
public:
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
    }
    ~FastIO() {}

    template <class T>
    void scan(T &v) {
        cin >> v;
    }
    template <class T, class... Rest>
    void scan(T &v, Rest&... rest) {
        scan(v);
        scan(rest...);
    }

    template <class T>
    void print(T v) {
        cout << v;
    }
    template <class T, class... Rest>
    void print(T v, Rest... rest) {
        print(v);
        print(" ");
        print(rest...);
    }
    template <class T>
    void prints(vector<T> v) {
        for (T t: v) {
            print(t);
            print(" ");
        }
        print("\n");
    }
    template <class T>
    void prints(T v) {
        print(v);
        cout << "\n";
    }
    template <class T, class... Rest>
    void prints(T v, Rest... rest) {
        print(v);
        print(" ");
        prints(rest...);
    }
};

FastIO io;
void _main(FastIO&);
int main() {
    _main(io);
}

int getDigits(ll n) {
    ll c = 0;
    while (n > 0) {
        n >>= 1;
        c++;
    }
    return c;
}

void use(int N, int M, vector<ll>& A) {
    vector<ll> digits(N);

    for (int d = 32; d>=0; d--) {
        REP(i, N) digits[i] = getDigits(A[i]);
        for (int i = 0; digits[i] == d && i < N; i++) {
            A[i] >>= 1;
            M--;
            if (M == 0) return;
        }
        sort(ALL(A), greater<ll>());
    }
}

void _main(FastIO &io) {
    int N, M; io.scan(N, M);
    vector<ll> A(N);
    REP(i, N) io.scan(A[i]);
    sort(ALL(A), greater<ll>());
    
    use(N, M, A);
    
    ll sum = 0;
    REP(i, N) sum += A[i];

    io.print(sum);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=(int)(n);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int N;
    cin>>N;
    vector<double> a(N),b;
    cin>>a;
    multiset<double> c(ALL(a));
    b=a;
    sort(ALL(b));
    REP(i,N) {
        int w=distance(begin(b),lower_bound(ALL(b),a[i]));
        int d=c.count(a[i])-1;
        int l=N-w-d;
        cout<<(l*0+d*1+w*3)<<endl;
    }
    return 0;
}

Measured memory_bytes: 8700
import string

s = input()
n = len(s)
ans = n
for chara in string.ascii_lowercase:
    left_max = 0
    right_max = 0
    ri = 0
    temp = 0
    for index, c in enumerate(s):
        if c == chara:
            left_max = max(temp, left_max)
            temp = 0
            ri = index
        else:
            temp += 1
    right_max = n - ri - 1
    ans = min(max(right_max, left_max), ans)
print(ans)


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

int main(){
	// #ifndef ONLINE_JUDGE
	// 	freopen("./a.in","r",stdin);
	// 	freopen("./a.out","w",stdout);
	// #endif

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

	  int h,w;
	  cin >> h >> w;

	  vector<string> grid(h);
	  for(int i=0; i<h; i++){
	  	cin >> grid[i];
	  }

	  vector< vector<int> > dist(h, vector<int>(w,-1));
	  vector<pair<int,int> > que;

 	  for(int i=0; i<h; i++){
	  	for(int j=0; j<w; j++){
	  		if(grid[i][j]=='#'){
	  			que.emplace_back(i,j);
	  			dist[i][j]=0;
	  		}
	  	}
	  }
	  
	  for(int b=0; b<que.size(); b++){
	  	for(int dx=-1; dx<=1; dx++){
			for(int dy=-1; dy<=1; dy++){
	  			if(dx*dx + dy*dy == 1){
					int xk = que[b].first + dx;
					int yk = que[b].second + dy;
	  				if(xk>=0 && yk>=0 && xk<h && yk<w && dist[xk][yk] == -1 ){
	  					que.emplace_back(xk,yk);
	  					dist[xk][yk] = dist[que[b].first][que[b].second] + 1;
	  				}	  				
	  			}
	  		}	  		
	  	}
	  }
	  cout << dist[que.back().first][que.back().second] << endl;
	  // for(int i=0; i<h; i++){
	  // 	for(int j=0; j<w; j++){
	  // 		cout << dist[i][j];
	  // 	}
	  // 	cout << endl;
	  // }


}

Measured memory_bytes: 15340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll n,m;
cin >> n>>m;
ll t[n] = {};
rep(i, m)
{
    ll a,b;
    cin >> a>>b;
    t[a-1]++;t[b]--;
}
rep1(i,n){
    t[i]+=t[i-1];
}
rep(i,n){
    if(t[i]==m)ans++;
}

cout << ans << endl;
return 0;
}

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

using namespace std;

char ask(int mid) {
	printf("%d\n", mid);
	fflush(stdout);
	string s; cin >> s;
	return s[0];
}

main() {          
	char s;
	int n; scanf("%d", &n);
	s = ask(0);
	int l = 0;
	int r = n / 2 + 1;
	char fr = s;
	char sc;
	if (fr == 'M') sc = 'F';
	else if (fr == 'F') sc = 'M';
	else {
		return 0;
	} 
	while (r - l > 1) {
		int mid = (l + r) >> 1;
    mid = mid * 2;
		s = ask(mid);
		if (s == sc) {
			r = mid / 2;
		} else if (s == fr) {
			l = mid / 2;
		} else {
			return 0;
		}
	}
	s = ask(l * 2 + 1);
	return 0;
}

Measured memory_bytes: 852
import java.util.Scanner;
import java.util.LinkedList;

public class Main{
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		int timeRestriction = in.nextInt();
		int currentTime = 0;
		LinkedList<RRSHelper> schedule = new LinkedList<RRSHelper>();
		for(int i = 0; i < num; i++) {
			schedule.add(new RRSHelper(in.next(), in.nextInt()));
		}
		in.close();
		RRSHelper temp = new RRSHelper();
		while(!schedule.isEmpty()) {
			if(schedule.peek().timeCheck() <= timeRestriction) {
				temp = schedule.remove();
				currentTime = currentTime + temp.timeCheck();
				temp.setTime(currentTime);
				System.out.println(temp);
			} else {
				temp = schedule.remove();
				currentTime = currentTime + timeRestriction;
				temp.subTime(timeRestriction);
				schedule.add(temp);
			}
		}
	}
}

class RRSHelper {
	String name;
	int timeleft;
	public RRSHelper(String x, int y) {
		name = x;
		timeleft = y;
	}
	public RRSHelper() {
	}
	
	public void addTime(int x) {
		timeleft = timeleft + x;
	}
	public void subTime(int x) {
		timeleft = timeleft - x;
	}
	public void setTime(int x) {
		timeleft = x;
	}
	public int timeCheck() {
		return timeleft;
	}
	public String toString() {
		return name + " " + timeleft;
	}
	
}


Measured memory_bytes: 73672
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			StringBuilder answer = new StringBuilder();
			String lb = System.getProperty("line.separator");
			
			String str = input.readLine();
			int m;
			int h;
			while (!str.equals("-")) {
				m = Integer.parseInt(input.readLine());

				for (int i = 0; i < m; i++) {
					h = Integer.parseInt(input.readLine());
					str = (str.substring(h, str.length()) + str.substring(0, h));
				}
				answer.append(str).append(lb);
				str = input.readLine();
			}
			
			System.out.print(answer.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static boolean isNumber (String s) {
		try {
			Integer.parseInt(s);
			return true;
		} catch (NumberFormatException e) {
			return false;
		}
	}
}

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

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

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}

use std::cmp::{max, min};

fn main() {
    let a:usize = read();
    let b: String = read();
    let b_char: Vec<char> = b.chars().collect();
    let ascii_uppercase: Vec<_> = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars().collect();

    let ans = b_char.iter().map(|&c| {
        ascii_uppercase[((0..26).find(|&i| ascii_uppercase[i] == c).unwrap() + a) % 26]
            .to_string()
    })
    .collect::<Vec<_>>()
    .join("");
    println!("{}", ans)
}


Measured memory_bytes: 4352
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define cy cout << "Yes" << endl
#define cn cout << "No" << endl
typedef long long ll;

void Main()
{
	int N, A, B;
  	cin >> N;
	if(N == 1){
    	puts("Hello World");
      	return;
    }
  	if(N == 2){
  		cin >> A >> B;
      	cout << A+B << endl;
      	return;
    }
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256