akhauriyash/Code-Regression huggingface dataset:
mod = 10 ** 9 + 7
H, W, K = map(int, input().split())
dp = [[0] * W for i in range(H + 1)]

dp[0][0] = 1
for i in range(H):
    for j in range(W):
        for k in range(1 << (W - 1)):
            ok = True
            if '11' in bin(k):
                ok = False
            if ok:
                if j >= 1 and ((k >> (j - 1)) & 1):
                    dp[i + 1][j - 1] += dp[i][j]
                    dp[i + 1][j - 1] %= mod
                    #print(1, i, bin(k), j, dp)
                    
                elif j <= W -2 and ((k >> j) & 1):
                    dp[i + 1][j + 1] += dp[i][j]
                    dp[i + 1][j + 1] %= mod
                    #print(2, i, bin(k), j, dp)
                    
                else:
                    dp[i + 1][j] += dp[i][j]
                    dp[i + 1][j] %= mod
                    #print(3, i, bin(k), j, dp)
            
print(dp[H][K - 1])

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

int main() {
  string s;
  cin >> s;
  string ans;
  for (char c : s) {
    if (c == 'B') {
      if (!ans.empty()) ans = ans.substr(0, ans.size() - 1);
    } else {
      ans += c;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
double dp[2][100];
double ch[100][100];
double max(double a,double b){return a>b?a:b;}
int main(){
	int n,m;
	int i,j,k;
	while(1){
	scanf("%d %d",&n,&m);
	if(n==0)return 0;
	for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%lf",&ch[i][j]);
	for(i=0;i<n;i++)dp[0][i]=1.0f;
	for(i=1;i<m;i++){
		for(j=0;j<n;j++){
			dp[i%2][j]=0.0f;
			for(k=0;k<n;k++)dp[i%2][j]=max(dp[i%2][j],dp[(i+1)%2][k]*ch[k][j]);
		}
	}
	double ans=0.0f;
	for(i=0;i<n;i++)ans=max(ans,dp[(m+1)%2][i]);
	printf("%.2lf\n",ans);
	}
}

Measured memory_bytes: 1172
using System;

namespace ITP1_7_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input_num = Console.ReadLine().Split(' ');
            int row = int.Parse(input_num[0]);
            int column = int.Parse(input_num[1]);
            int sum_all = 0;
            string[] value = null;
            int[,] input = new int[row, column];
            int[] sum = new int[column];


            for (int i=0; i<row; i++)
            {
                value = Console.ReadLine().Split(' ');

                for (int j=0; j<column; j++)
                {
                    input[i, j] = int.Parse(value[j]);
                }
            }

            
            for (int i=0; i<row; i++)
            {
                sum_all = 0;
                for (int j=0; j<column; j++)
                {
                    Console.Write("{0} ", input[i,j]);
                    sum_all += input[i,j];
                    sum[j] += input[i,j];
                }
                Console.Write(sum_all);
                Console.WriteLine();
 
            }

            sum_all = 0;
            for (int j=0; j<column; j++)
            {
                Console.Write("{0} ", sum[j]);
                sum_all += sum[j];
            }

            Console.Write(sum_all);
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9316
#include <stdio.h>

int main(void)
{
    int A, B, K, i;
    int min, cnt = 0;
    scanf("%d%d%d", &A, &B, &K);

    min = A < B ? A : B;            

    for (i = min; i > 0; i--)
    {
        if(A % i == 0 && B % i == 0){
            cnt++;
            if(cnt == K){
                break;
            }
        }
    }
    printf("%d\n", i);
    
    return 0;
}

Measured memory_bytes: 128
S = input()
Q = int(input())

head = ''
tail = ''
rev = False

for i in range(Q):
    Query_i = input().split()

    if Query_i[0] == '1':
        rev = not rev
    
    elif Query_i[0] == '2':
        F_i, C_i = Query_i[1], Query_i[2]

        if not rev and F_i == '1':
            head += C_i
        elif not rev and F_i == '2':
            tail += C_i
        elif rev and F_i == '1':
            tail += C_i
        elif rev and F_i == '2':
            head += C_i

res = ''
if not rev:
    for c in reversed(head):
        res += c
    res += S
    res += tail
else:
    for c in reversed(tail):
        res += c
    for c in reversed(S):
        res += c
    res += head

print(res)


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


int main() {
   // freopen("input.txt", "r", stdin);
    
    long long n;
    cin >> n;

    long long res = 0;
    res += (n / 500) * 1000;
    n -= 500 * (n / 500);

    res += (n/ 5) * 5;
    cout << res;

    return 0;
}

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

int main() {
	
	int r, c, sy, sx, gy, gx; cin >> r >> c;
	sy = 1;
	sx = 1;
	gy = r;
	gx = c;
	vector<vector<char>> a(r + 2, vector<char>(c + 2, 'e'));
	int cnt = 0;
	for (int i = 1; i <= r; i++) for (int j = 1; j <= c; j++) {
		cin >> a[i][j];
		if (a[i][j] == '#') cnt++;
	}

	// BFS のためのデータ構造
	vector<vector<int>> dist(r + 2, vector<int>(c + 2, -1)); // 全頂点を「未訪問」に初期化
	queue<pair<int, int>> que;

	// 初期条件
	dist[sy][sx] = 0;
	que.push({ sy,sx });

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

	// BFS 開始 (キューが空になるまで探索を行う)
	while (!que.empty()) {

		pair<int, int> p = que.front(); // キューから先頭頂点を取り出す
		que.pop();

		// p から辿れるマスをすべて調べる
		for (int i = 0; i < 4; i++) {

			int y_next = p.first + dy[i];
			int x_next = p.second + dx[i];

			if (dist[y_next][x_next] != -1) continue;
			if (a[y_next][x_next] == 'e' || a[y_next][x_next] == '#') continue;

			// 新たなマス { y_next, x_next } について距離情報を更新してキューに追加する
			dist[y_next][x_next] = dist[p.first][p.second] + 1;
			que.push({ y_next, x_next });

		}

	}
	if (dist[gy][gx] != -1) cout << r * c - (dist[gy][gx] + 1) - cnt << endl;
	else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <vector>

#define int long long
using namespace std;
const int Mod = 998244353;

int cnt[8];
int32_t main(){

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

    int n;
    string s;
    cin>>n>>s;

    int ans = 1;
    cnt[0] = n;
    for(auto ch:s){
        int d = 0;
        if(ch=='G') d = 1;
        else if(ch=='B') d = 2;
        for(int i = 6;~i;i--){
            if(i&(1<<d)) continue;
            if(cnt[i]){
                ans = ans*cnt[i]%Mod;
                cnt[i]--;
                cnt[i^(1<<d)]++;
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#define ll long long
using namespace std;

int main(){
    int N;  cin >> N;
    vector<string> s(N);

    int ans = 0;
    for(int i=0; i<N; i++){
        cin >> s[i];
        int L = s[i].length();
        for(int j=0; j<L-1; j++){
            if(s[i][j]=='A' && s[i][j+1]=='B') ans++;
        }
    }

    vector<int> c(3,0);
    for(int i=0; i<N; i++){
        if(s[i][0]!='B' && s[i][s[i].length()-1]=='A') c[0]++;
        if(s[i][0]=='B' && s[i][s[i].length()-1]!='A') c[1]++;
        if(s[i][0]=='B' && s[i][s[i].length()-1]=='A') c[2]++;
    }

    if(c[2]!=0){
        if(c[0]>0 && c[1]>0){
            ans += c[2] + 1 + min(c[0]-1, c[1]-1);
        }else if(c[0]==0 && c[1]==0){
            ans += c[2]-1;
        }else{
            ans += c[2];
        }
    }else{
        ans += min(c[0], c[1]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int K = sc.nextInt();
		
		int countA = 0;
		int countB = 0;
		int[] Ayaku = new int[A + 1];
		int[] Byaku = new int[B + 1];
		int[] yaku = new int[A + 1];
		
		for(int i = 1; i <= A; i++) {
			if(A % i == 0) {
				countA++;
				Ayaku[countA] = i;
			}
		}
		
		for(int i = 1; i <= B; i++) {
			if(B % i == 0) {
				countB++;
				Byaku[countB] = i;
			}
		}
		int countK = 0;
		for(int i = 1; i <= countA; i++) {
			for(int j = 1; j <= countB; j++) {
				if(Ayaku[i] == Byaku[j]) {
					countK++;
					yaku[countK] = Ayaku[i];
				}
			}
		}
		System.out.println(yaku[countK + 1 - K]);
	}
}


Measured memory_bytes: 21844
#ライブラリインポート
from collections import defaultdict
con = 10 ** 9 + 7

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	X = getlist()
	ans = 1
	c = 0
	for i in range(N):
		c += 1
		if 2 * c > X[i] + 1:
			ans = (ans * c) % con
			c -= 1
	# print(ans)
	# print(c)
	
	for i in range(1, c + 1):
		ans = (ans * i) % con
	print(ans)

if __name__ == '__main__':
	main()

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

using namespace std;

#define llong long long int
#define rep(i, n) for (int i = 0; i < n; ++i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    vector<int> dp(n, 0);
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; ++i) {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i]- h[i - 2]));
    }

    cout << dp[n - 1] << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K;
    cin >> K;
    queue<string> q;
    string t = "";
    q.push(t);
    while(!q.empty() && K > 0){
        string cur = q.front();
        q.pop();
        if(cur == ""){
            for(char c='1';c<='9';c++){
                string tmp = cur + c;
                K--;
                if(K == 0){
                    cout << tmp << endl;
                    break;
                }
                q.push(tmp);
            }
        }
        else{
            for(char c='0';c<='9';c++){
                if(abs((cur.back() - '0') - (c - '0')) > 1) continue;
                string tmp = cur;
                tmp += c;
                K--;
                if(K == 0){
                    cout << tmp << endl;
                    break;
                }
                q.push(tmp);
            }
        }
    }
}

Measured memory_bytes: 4864
// 2018/12/14 Tazoe

#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
	int W, H;
	cin >> W >> H;

	bool flg = true;

	int a[1000] = {0};
	int sum_a = 0;
	for(int i=0; i<W; i++){
		cin >> a[i];
		sum_a += a[i];
		if(a[i]>H)
			flg = false;
	}

	int b[1000] = {0};
	int sum_b = 0;
	for(int i=0; i<H; i++){
		cin >> b[i];
		sum_b += b[i];
		if(b[i]>W)
			flg = false;
	}

	if(sum_a!=sum_b || !flg){
		cout << 0 << endl;
		return 0;
	}

	while(true){
		sort(a, a+W, greater<int>());
		sort(b, b+H, greater<int>());

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

		if(b[a[0]-1]<=0){
			cout << 0 << endl;
			return 0;
		}

		for(int i=0; i<a[0]; i++){
			b[i]--;
		}
		a[0] = 0;
	}
}



Measured memory_bytes: 3172
/*
She came from the past
She was never meant to last
Her destiny was fatal
From the start
A messenger from hell
She cast a deadly spell
On all of those who dare
To cross her heart
Ain't no use in you trying to run
Fate has taken it's toll
Just one look and the damage is done
Burn your eyes
Turn your heart into stone
History foretold of a circle
Cast in gold
An evil seed of power
Sealed within
But fate has lent a hand
Destroyed the golden band
And freed her soul
To wash the land with sin
Ain't no use in you trying to run
Fate has taken it's toll
Just one look and the damage is done
Burn your eyes
Turn your heart into stone
She cast a deadly spell
She put a spell on you
She's got evil in her heart
Turn your heart into stone
Turn your heart into stone
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh
#define hash asdgasdgasdgdfrywewery

#define eps 1e-8
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 600031;

int n;
int ans;

int cnt[1000];

bool is_good(long long val){
	for (int i=0;i<10;i++){
		cnt[i]=0;
	}
	while (val){
		cnt[val%10]++;
		val/=10;
	}
	return (cnt[3]>0&&cnt[5]>0&&cnt[7]>0);
}

void backtrack(long long val){
	if (val>n)
		return;
	if (is_good(val))
		++ans;
	backtrack(val*10+3);
	backtrack(val*10+5);
	backtrack(val*10+7);
}

int main(){
//	freopen("apache.in","r",stdin);
//	freopen("apache.out","w",stdout);
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);

	cin>>n;
	backtrack(0);

	cout<<ans<<endl;

//	cin.get(); cin.get();
	return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
  vector<int> ans;
  while (true) {
    int n, k;
    cin >> n >> k;
    if (n == 0 && k == 0) break;
    vector<string> c(n);
    rep(i,n) cin >> c[i];

    set<string> num;
    sort(c.begin(), c.end());
    do {
      string tmp;
      rep(i,k) {
	tmp += c[i];
      }
      num.insert(tmp);
    } while (next_permutation(c.begin(), c.end()));
    ans.push_back(num.size());
  }

  rep(i,ans.size()) cout << ans[i] << endl;
  return 0;
}



Measured memory_bytes: 3424
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,M;
  cin >> N >> M;
  vp ab(M);
  rep(i,M) {
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    ab[i] = P(b,a);
  }
  sort(rng(ab));
  int ans = 0;
  int lim = -INF;
  rep(i,M) {
    int a = ab[i].second;
    int b = ab[i].first;
    if(a < lim) continue;
    ans++;
    lim = b;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

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

    long long ac = a*c, ad = a*d, bc = b*c, bd = b*d;

    if (ac >= ad && ac >= bc && ac >= bd)
    {
        cout << ac << endl;
    }
    else if (ad >= ac && ad >= bc && ad >= bd)
    {
        cout << ad << endl;
    }
    else if (bc >= ad && bc >= ac && bc >= bd)
    {
        cout << bc << endl;
    }
    else cout << bd << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
inline ll power(ll x, ll y, ll p=1000000007 )
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
const ll p=1000000007;
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll n,k,j;
  cin>>n>>k;
  ll a[k+1];
  ll i=k,sum=0;
  while(i)
  {
  	a[i]=power(k/i,n);
  	j=2*i;
  	while(j<=k)
  	{
  		a[i]+=p-a[j];
  		a[i]%=p;
  		j+=i;
  	}
  	sum+=i*a[i];
  	sum%=p;
  	i--;
  }
  deb(sum);
}


Measured memory_bytes: 4428
Scanf.scanf "%d" @@ fun n ->
  let ab = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun x y -> x,y)) in
  let ab = Array.init n (fun i -> ab.(n-1-i)) in
  Array.fold_left (fun (s,d) (x,y) ->
    let p = ((x+d+y-1)/y*y - (x+d)) mod y in (s+p, d+p)) (0,0) ab
  |> fst |> Printf.printf "%d\n"

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    ll n; cin >> n;

    string S;

    while(true){
        if(n <= 26){
            S += (char)('a'+n-1);
            break;
        }
        if(n%26 == 0){
            S += 'z';
            n -= 26;
        }else{
            S += (char)('a'+(n%26)-1);
            n -= (n%26);
        }
        n /= 26;
    }

    /*
    while(true){
        if(n <= 26){
            // cout << (char)('a'+n-1) << endl;
            S += (char)('a'+n-1);
            break;
        }else{
            // cout << (char)('a'+(n%26)-1);
            if(n%26 == 0){
                S += (char)('a'+25);
            }else{
                S += (char)('a'+(n%26)-1);
            }
            n /= 26;
        }
    }
    */

    int Ss = S.size();
    for(int i=Ss-1; i>=0; i--){
        cout << S[i];
    }cout << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+2;
string s,p;
int main()
{
    ft
    int t,i,j,n,m,l,r,z;
    cin>>s>>p;
    if(s==p)
    {
        cout<<"EQUAL\n";
    }
    else
    {
        l=s.size();
        r=p.size();
        if(l>r)
        {
            cout<<"GREATER\n";
        }
        else if(l<r)
        {
            cout<<"LESS\n";
        }
        else
        {
            if(s>p)
            {
                cout<<"GREATER\n";
            }
            else
            {
                cout<<"LESS\n";
            }
        }
    }
    return 0;
}



Measured memory_bytes: 256
/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C&lang=jp*/
#include <iostream>
#include <string.h>

#define MAX 36

using namespace std;

struct card{
    char suit;
    int value;
};

void bubbleSort(struct card *a,int n){
    for(int i=0;i<n-1;i++){
        for(int j=n-1;i<j;j--){
            if(a[j].value<a[j-1].value){
                swap(a[j],a[j-1]);
            }
        }
    }
}

void selectionSort(struct card *a,int n){
    for(int i=0;i<n-1;i++){
        int minj=i;
        for(int j=i+1;j<n;j++){
            if(a[j].value<a[minj].value){
                minj=j;
            }
        }
        swap(a[i],a[minj]);
    }
}

void show(struct card *a,int n){
    for(int i=0;i<n;i++){
        cout<<a[i].suit<<a[i].value;
        if(i<n-1){
            cout<<" ";
        }else{
            cout<<endl;
        }
    }
}

void isStable(struct card *a, struct card *b, int n){
    for(int i=0;a != nullptr && i<n;i++){
        if(a[i].suit!=b[i].suit){
            cout<<"Not stable"<<endl;
            return;
        }
    }
    cout<<"Stable"<<endl;
}

void isStable(struct card *b){
    isStable(nullptr,b,0);
}

int main(){
    int n;
    struct card a[MAX], b[MAX],s[MAX];

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i].suit>>a[i].value;
    }
    memcpy(b,a, sizeof(a));
    bubbleSort(b,n);
    show(b,n);
    isStable(b);
    memcpy(s,a, sizeof(a));
    selectionSort(s,n);
    show(s,n);
    isStable(b, s, n);
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
ll N,M;
vl A,cum;
bool isOK(int index,ll &m, ll &sum) {
    int l=0,r=N-1;
    while(l<N){
        if(A[l]+A[r]>=index){
            sum+=A[l]*(r+1)+cum[r];
            m+=r+1;
            l++;
        }else if(r>0)r--;
        else l++;
    }
    if (m>=M) return true;
    else return false;
}

ll binary_search() {
    int ok = -1;
    int ng = 200001; 
    ll m,sum;
    while (abs(ok - ng) > 1) {
        m=0,sum=0;
        int mid = (ok + ng) / 2;
        if (isOK(mid,m,sum)) ok = mid;
        else ng = mid;
    }
    sum-=(m-M)*ok;
    return sum;
}
int main() {
    cin>>N>>M;
    for (int i = 0; i < N; i++){
        int a; cin>>a;
        A.push_back(a);
    }
    sort(A.begin(),A.end(),greater<int>());
    cum.push_back(A[0]);
    for (int i = 1; i < N; i++){
        cum.push_back(cum[i-1]+A[i]);
    }
    cout<<binary_search()<<endl;
}

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

using namespace std;

typedef long long int ll;

int main(){
	int n,l;
	cin >> n >> l;
	string s[n];
	for (int i = 0; i < n; i++){
		cin >> s[i];
	}
	sort(s,s + n);
	for (int i = 0; i < n; i++){
		cout << s[i];
	}	
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int n;

    cin >> n;

    long res0 = 0;
    long res1 = 1;

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        int n0, n1;
        if (x % 2 == 0) {
            n0 = 1;
            n1 = 2;
        } else {
            n0 = 2;
            n1 = 1;
        }
        long nres0 = (res0 + res1) * n0 + res0 * n1;
        long nres1 = res1 * n1;
        res0 = nres0;
        res1 = nres1;
    }
    cout << res0 << "\n";


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <bits/stdc++.h>
#include <cmath>
#include <stdio.h>
#include <utility>
using namespace std;
#define ll long long

int main()
{
   string s;cin>>s;
   string temp="";
   for(int i=0;i<s.length();i++){
       if(s[i]=='0'){
           temp+='0';
       }else if(s[i]=='1'){
           temp+='1';
       }else{
           if(temp.length()!=0){
           temp.erase(temp.length()-1,1);
       }}
   }
   cout<<temp<<endl;
return 0;
}


Measured memory_bytes: 256
#include <ctype.h>
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

//char rbuf[]; int rbufl;
//#define getchar() rbuf[rbufl++]
#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }
void printint(int32_t x){ if(x<0){x=-x; putchar('-');}else if(x==0){putchar('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar(s[i]); putchar('\n'); }
void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	for(int k=0; k<4; k++){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(k<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(k<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	}
	free(b);
}

long d[100000][2];

int main(void){
	long n=nextlong();
	int x=nextint();
	int m=nextint();
	if(x==0){
		printf("%d\n", 0);
		return 0;
	}
	long k, l;
	int xx;
	int now=x;
	long ans=0;
	for(k=0;; k++){
		if(d[now][0]!=0){
			xx=now;
			l=d[now][0];
			ans-=d[now][1];
			now=d[now][1];
			break;
		}
		d[now][0]=k;
		d[now][1]=ans;
		ans+=now;
		now=(long)now*now%m;
	}
	k=k-l;
	if(n>=l){
		n-=l;
		ans = now+ (long)ans*(n/k);
		now=xx;
		for(long i=0, t=n%k; i<t; i++){
			ans+=now;
			now=(long)now*now%m;
		}
	}else{
		ans=0;
		now = x;
		for(long i=0; i<n; i++){
			ans+=now;
			now=(long)now*now%m;
		}
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 3160
#include<stdio.h>
int main()
{
 char s[3];

 
  
 scanf("%s",&s);

 if(s[0]=='a'){
  if((s[1]=='b'&&s[2]=='c')||(s[1]=='c'&&s[2]=='b')){
    printf("Yes");
  }
   else printf("No");
 }
    if(s[0]=='b'){
  if((s[1]=='a'&&s[2]=='c')||(s[1]=='c'&&s[2]=='a')){
    printf("Yes");
  }
      else printf("No");
 } 
  if(s[0]=='c'){
  if((s[1]=='a'&&s[2]=='b')||(s[1]=='b'&&s[2]=='a')){
    printf("Yes");
  }
   else printf("No");
 }
   return 0;
}
    

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

int main()
{
  int64_t N, cnt = 0;
  cin >> N;
  vector<int64_t> L(N);
  for (int64_t i = 0; i < N; i++)
    cin >> L.at(i);
  sort(L.begin(), L.end());
  for (int64_t i = 0; i < N - 2; i++)
  {
    int64_t a = L.at(i);
    for (int64_t j = i + 1; j < N - 1; j++)
    {
      int64_t b = L.at(j);
      auto itr = lower_bound(L.begin(), L.end(), a + b);
      cnt += distance(L.begin(), itr) - (j + 1);
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int n;
		cin>>n;
		bool flag=true;
		for(int i=0;i<n;i++){
			int z;
			cin>>z;
			if(z%2==0){
				if(z%3!=0&&z%5!=0){
					cout<<"DENIED";
					return 0;
				}
			}
		}
		cout<<"APPROVED";
	}
	return 0;
}

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

int main() {
    string S;
    int count = 0 , d_res = 0 ,d_max = 0;
    cin >> S;
    S += " ";
    if(S[0] == '?'){
        if(S[1] == 'D'){
            S[0] = 'P';
        }else{
            S[0] = 'D';
        }
    }
    for (int i=1; i < S.size(); i++ ){
        if(S[i] == '?'){
            if(S[i-1] == 'P'){
                S[i] = 'D';
            }else if(S[i+1] == 'D'){
                S[i] = 'P';
            }else if(S[i-1] == 'D'){
                S[i] = 'D';
            }else{
                S[i] = 'D';
            }
        }
    }
    for (int i=0; i < S.size()-1; i++ ){
        cout << S[i] ;
    }
    
}


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

long f(long n) {
  return n * (n - 1) / 2;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, int> MA;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    MA[A.at(i)]++;
  }
  long ans = 0;
  for (auto [a, b] : MA) ans += f(b);
  for (auto a : A) cout << ans - f(MA[a]) + f(MA[a] - 1) << "\n";
}

Measured memory_bytes: 10056
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <fstream>
#include <set>
#include <cmath>
#include <array>
#include <iomanip>
#include <cassert>

using namespace std;

int main(void) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int64_t answer = 0;

    int64_t a_i;
    cin >> a_i;


    int64_t a_o;
    cin >> a_o;

    int x;
    cin >> x;

    int64_t y_1, y_2;
    cin >> y_1;
    cin >> y_2;


    answer += a_o * 2;

    auto try_this = [=](int sub) {
        int64_t mag = min({a_i, y_1, y_2}) - sub;

        if (mag < 0) {
            return (int64_t)0;
        }

        return 6 * mag + ((a_i - mag) / 2) * 4 + ((y_1 - mag) / 2) * 4 + ((y_2 - mag) / 2) * 4;
    };
    cout << (answer + std::max(try_this(0), try_this(1))) / 2;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
S = input().split('/')
for i in range(3):
    S[i] = int(S[i])
if S[0] == 2019:
    if S[1] >= 5:
        print('TBD')
    else:
        print('Heisei')
elif S[0] > 2019:
    print('TDB')
else:
    print('Heisei')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int a, b, c, x;
    cin >> c >> b >> a >> x;

    int conta = 0;

    for ( int i = 0; i <= a; i++ ) {
        for ( int j = 0; j <= b; j++ ) {
            for ( int k = 0; k <= c; k++ ) {
                int aux = i * 50 + j * 100 + k * 500;
                if ( aux == x ) {
                    // cout << i << " <- i j -> " << j << "  k -> " << k << endl;
                    conta++;
                    break;
                } else if ( aux > x ) break;
            }
        }
    }

    cout << conta << endl;

    return 0;
}

Measured memory_bytes: 256
#include<map> sorry luma  use for not while
int64_t K,d=1,n,_;int S(int64_t n){return n?S(n/10)+n%10:0;}main(){for(scanf("%d",&K);printf("%ld\n",n+=d),--K;S(_=n+d+d)*(n+d)<=S(n+d)*_?:d*=10);}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
static const int MAX = 10000;

int n, T[MAX+1];

void solve(){
  vector<int> S;
  for ( int i = 1; i <= (n-1)/2; i++ ) T[i] = 0;
  for ( int i = 1; i <= n-1; i++ ) S.push_back((i*i)%n);
  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());
  for ( int i = 0; i < S.size(); i++ ){
    for ( int j = 0; j < S.size(); j++ ){
      if ( i == j ) continue;
      int d = S[j] - S[i];
      if ( d < 0 ) d += n;
      if ( d > (n-1)/2 ) d = n-d;
      T[d]++;
    }
  }
  for ( int i = 1; i <= (n-1)/2; i++ ) cout << T[i] << endl;
}

main(){
  while(1){
    cin >> n;
    if ( n == 0 ) break;
    solve();
  }
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << a * b / 2 << endl;
}


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

namespace CSharpSample01
{


    class Program
    {


        static void Main(string[] args)
        {

            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            int ans = 0;

            for(int i = 1; i < N; i++)
            {
                var left = new Dictionary<char, int>();
                var right = new Dictionary<char, int>();
                int cnt = 0;

                for(int j = 0; j < i; j++)
                {
                    if (!left.ContainsKey(S[j])) left[S[j]] = 1;
                }
                for(int j = i; j < N; j++)
                {
                    if (!right.ContainsKey(S[j])) right[S[j]] = 1;
                }

                foreach(var s in left)
                {
                    if (right.ContainsKey(s.Key)) cnt++;
                }

                if (ans < cnt) ans = cnt;

            }

            Console.WriteLine(ans);

        }
    }
}

Measured memory_bytes: 13268
s = int(input())
a = []
a.append(s)
def f(n):
        if n%2 == 0:
                a.append(n//2)
        else:
                a.append(3*n+1)

def is_unique(seq):
        return len(seq) == len(set(seq))

while True:
        f(a[-1])
        if is_unique(a) == False:
                print(len(a))
                break

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

int main(){
  int N, K, ans=0;
  cin >> N >> K;
  int x[N];
  for (int i = 0; i < N; i++){
    cin >> x[i];
  }

  for (int i = 0; i < N; i++){
    if(x[i] < (K - x[i])){
      ans += x[i] * 2;
    }else{
      ans += (K - x[i]) * 2;
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 3748
s=int(input())
F=[0]
F.append(s)

def calc(x):
  if x%2==0:
    return x/2
  else:
    return 3*x+1

for i in range(2, 1000000):
  a=calc(F[i-1])
  if a in F:
    print(i)
    break
  else:
    F.append(a)

Measured memory_bytes: 3060
require 'matrix'

class String
    def integers
        split(" ").map(&:to_i)
    end
end

loop {
    n, k = gets.integers
    break if n == 0

    stock = Vector[*gets.integers]
    n.times{ stock = stock - Vector[*gets.integers] }
    puts stock.all?{|x| x >= 0} ? 'Yes' : 'No'
}

Measured memory_bytes: 7612
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll n; cin >> n;
    ll jud = n%1000;

    cout << (1000 - jud)%1000 << endl;


}

Measured memory_bytes: 3620
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

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

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

// =========ここまでテンプレ============

int main()
{
    ll n, m, x;
    cin >> n >> m >> x;
    vector<ll> c(n);
    vector<vector<ll>> a(n, vector<ll>(m));
    rep(i, n)
    {
        cin >> c[i];
        rep(j, m)
        {
            cin >> a[i][j];
        }
    }

    ll lowest = LLONG_MAX;
    // 全cの組み合わせiを走査
    rep(i, 1 << n)
    {
        vector<ll> understands(m);
        ll cost = 0;
        // 参考書_jを走査
        rep(j, n)
        {
            if (i & 1 << j)
            {
                cost += c[j];
                // アルゴリズム_kを走査
                rep(k, m)
                {
                    understands[k] += a[j][k];
                }
            }
        }
        bool ok = true;
        // アルゴリズム _kを走査
        rep(k, m) ok = ok && understands[k] >= x;
        if (ok)
            lowest = min(lowest, cost);
    }
    if (lowest == LLONG_MAX)
        cout << -1 << endl;
    else
        cout << lowest << endl;
}


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

int main(){

    int a,b;
    int ans = 0;

    cin >> a >> b;

    for(int i = 1; i <= 3; i++){
        if(i != a && i != b){
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(raw_input())
S = map(int,raw_input().strip().split(' '))

def partition(S,p,r):
    x = S[r]
    i = p-1
    for j in range(p,r):
        if S[j] <= x:
            i += 1
            S[j],S[i]=S[i],S[j]
    S[i+1],S[r]=S[r],S[i+1]
    for j in range(len(S)):
        if j == i+1: print "["+str(S[j])+"]",
        else: print S[j],

partition(S,0,len(S)-1)

Measured memory_bytes: 14804
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;

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


Measured memory_bytes: 256
n=str(input())
N = int(n)
m=int(input())
cnt = 0
for i in range(m):
    if i >= N:
        break
    if n[i] == "1":
        cnt +=1
    else:
        break
      
    
if cnt == m:
    print(1)
elif cnt == 0:
    print(n[0])
elif  cnt < m:
    print(n[cnt])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define lowbit(x) ((x)&(-(x)))
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const int maxn = 1e7 + 10;
int N, f[maxn];
int main()
{
    scanf("%d", &N);
    for(register int i = 1; i <= N; ++i)
        for(register int j = i; j <= N; j += i)
            f[j]++;
    LL ans = 0;
    for(int K = 1; K <= N; ++K)
        ans += 1LL * K * f[K];
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 42780
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
#define MX 200009
using ll = long long;
using P = pair<int, int>;

template <typename T>
struct SegmentTree {
  int N;
  T init;
  vector<T> dat;
  SegmentTree(int n, T init) : init(init) {
    N = 1;
    while (N < n) N *= 2;
    dat.assign(2*N-1, init);
  }
  void update(int i, T x) {
    i += N - 1;
    dat[i] += x;
    while (i > 0) {
      i = (i - 1) / 2;
      dat[i] = dat[i*2+1] + dat[i*2+2];
    }
  }
  T query(int a, int b) { return query(a, b, 0, 0, N); }
  T query(int a, int b, int i, int l, int r) {
    if(r <= a || b <= l) return init;
    if(a <= l && r <= b) return dat[i];
    T vl = query(a, b, i*2+1, l, (l+r)/2);
    T vr = query(a, b, i*2+2, (l+r)/2, r);
    return vl + vr;
  }
};

vector<int> to[MX];
int in[MX], out[MX], k = 0;

void dfs(int v, int p=-1) {
  in[v] = k++;
  for (auto u : to[v]) {
    if (u == p) continue;
    dfs(u, v);
  }
  out[v] = k;
}

ll f(ll n) { return n * (n + 1) / 2; }

int main() {
  int n;
  cin >> n;
  vector<int> c(n);
  rep(i,n) cin >> c[i], c[i]--;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(0);
  vector<int> vs[n];
  rep(i,n) vs[c[i]].push_back(i);
  SegmentTree<int> st(n, 0);
  rep(i,n) st.update(i, 1);

  rep(i,n) {
    ll ans = f(n);
    vector<P> hist;
    vector<int>& nvs = vs[i];
    sort(nvs.begin(), nvs.end(), [&](int a, int b) {
      return in[a] > in[b];
    });
    for (auto v : nvs) {
      int cnt = 1;
      for (auto u : to[v]) {
        if (in[u] < in[v]) continue;
        ans -= f(st.query(in[u], out[u]));
        cnt += st.query(in[u], out[u]);
      }
      st.update(in[v], -cnt);
      hist.emplace_back(in[v], cnt);
    }
    ans -= f(st.query(in[0], out[0]));
    for (auto p : hist) st.update(p.fi, p.se);
    cout << ans << endl;
  }
  return(0);
}


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

int main()
{
   long long n,k;
   string s;
   
   cin>>n;
   cin>>s;
   k=0;
   for(int i=0;i<n;i++)
   {
      if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
      k++;
   }
   cout<<k<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	string S;
	cin >> S;
	if (S[1] == S[2]) {
		if (S[1] == S[0] || S[1] == S[3]) {
			cout << "Yes" << endl;
			return 0;

		}
	}

	cout << "No" << endl;
}

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

int main() {
  ll n, c, k;
  cin >> n >> c >> k;
  vector<ll> t(n);
  rep(i, n) cin >> t[i];
  sort(t.begin(), t.end());
  vector<bool> done(n, false);
  ll cnt = 0;
  rep(i, n) {
    if (done[i]) continue;
    ll idx = i;
    ll departure = t[idx] + k;
    ll capacity = c;
    while (t[idx] <= departure && capacity != 0) {
      done[idx] = true;
      capacity--;
      idx++;
      if (idx >= n) break;
    }
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i,a) for(int i = 0 ; i < a ; i++)
#define fll(i,a) for(ll i = 0 ; i < a ;i++)
#define forab(i,a,b) for(int i = a ; i < b ; i++)
#define prec(x) cout<<fixed<<setprecision(x)
#define ff first
#define ss second

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1

void solve()
{
	ll n;
	cin >> n;

	string ans = "";

	while (n)
	{
		ll k = n / 26;
		ll z = n % 26;

		if (z == 0)
		{
			k--;
			ans += (char)('z');
		} else
			ans += (char)('a' + z - 1);

		n = k;
	}
	reverse(ans.begin() , ans.end());
	cout << ans  << "\n";
}

int main() {

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

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}


Measured memory_bytes: 3620
//AnkitCode99
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define vl vector<ll>
#define all(v) (v.begin(),v.end())
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
using namespace std;
int main()
{
	fast;
    char ch;
  	cin>>ch;
  cout<<++ch;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  long long int ans = 1;
  long long int mod = 1e9+7;
  for(int i=1; i<=n; i++){
    ans *= i;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int n; cin >> n;
	vector<ll> A(n);
	ll ma = 0;
	rep(i, n) {
		cin >> A[i];
		chmax(ma, A[i]);
	}
	ll sum = accumulate(ALL(A), 0LL);
	sum -= ma;

	cout << sum + ma / 2 << endl;

	return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end() 
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e9+10;
ll MOD=  1e9+7 ;
const ll mxn= 1e6+10;
const int N=10000005;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,k,m,q,x,y;
ll fast_exp(ll base, ll exp) {
    ll res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base)%MOD;
       base=(base*base)%MOD;
       exp/=2;
    }
    return res%MOD;
}
ll nCr(ll n,ll r){
    ll res=1LL;
    for(int i=2;i<=r;i++) res*=(fast_exp(i,MOD-2)), res%=MOD;
    for(ll i=n;i>=(n-r+1);i--) res*=i, res%=MOD;
    return res;
}
// 810092880
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n>>x>>y;
    //cout<<fast_exp(2,n)<<' '<<nCr(n,x)<<' '<<nCr(n,y)<<'\n';
    cout<<(fast_exp(2,n)-nCr(n,x)-nCr(n,y)+2*MOD-1)%MOD<<'\n';
}

Measured memory_bytes: 256