akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <cmath>
#include <map>
#include <tuple>
#include <complex>

#define MOD 1000000007

using namespace std;

typedef long long ll;

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<string> vs;

typedef pair<ll, ll> pll;
typedef pair<int, int> pi;

typedef vector<pll> vpl;
typedef vector<pi> vpi;
typedef vector<vs> vvs;

typedef vector<pll> vvpl;
typedef vector<vpi> vvpi;

typedef queue<ll> ql;
typedef queue<int> qi;
typedef queue<pll> qpl;
typedef queue<pi> qpi;

template <typename T>
void printv(const vector<T>& v) {
    for (int i = 0; i < v.size(); ++i) {
        printf("[%d] %d\n", i, v[i]);
    }
}

template <typename T>
void printvv(const vector<T>& vv) {
    for (int i = 0; i < vv.size(); ++i) {
        for (int j = 0; j < vv[i].size(); ++j) {
            printf("[%d][%d] %d\n", i, j, vv[i][j]);
        }
    }
}

template <typename T, typename U>
void printp(const pair<T, U>& p) {
    cout << p.first << " " << p.second << endl;
}

template <typename T>
void printvp(const vector<pair<T, T>>& vp) {
    for (int i = 0; i < vp.size(); ++i) {
        printf("[%d] %d, %d\n", vp[i].first, vp[i].second);
    }
}

template <typename T>
void printvvp(const vector<vector<pair<T, T>>>& vvp) {
    for (int i = 0; i < vvp.size(); ++i) {
        for (int j = 0; j < vvp[i].size(); ++j) {
            printf("[%d][%d] %d, %d\n", i, j, vvp[i][j].first, vvp[i][j].second);
        }
    }
}

int main() {
    int N; cin >> N;
    vi cost(N);
    for (int i = 0; i < N; ++i) cin >> cost[i];
    vi dp(N, 0);

    for (int i = 0; i < N; ++i) {
        if (i == 0) continue;
        if (i == 1) dp[i] = abs(cost[i]-cost[i-1]);
        if (i >= 2) dp[i] = min(abs(cost[i]-cost[i-1]) + dp[i-1], abs(cost[i]-cost[i-2]) + dp[i-2]);
    }
    cout << dp[N-1] << endl;

    return 0;
}


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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

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

int main() {
	ios_base::sync_with_stdio(false);

	string s;
	cin >> s;
	fori(i, 0, 8) {
		s.pop_back();
	}
	cout << s << '\n';

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int ans[200005];


int main(){
    int n;
    cin >> n;
    rep(i, n-1){
        int a;
        cin >> a;
        a--;
        ans[a]++;
    }

    rep(i, n){
        cout << ans[i] << endl;
    }    
        
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 4400
#include<stdio.h>
#include<bits/stdc++.h> 
#include<iostream>
#include <ctype.h>
# define lldi unsigned long long int
using namespace std; 

string cadena;
int  dp[4000][4000]={0};
int lcs(string s1, string s2){
	
	int tam1=s1.length();
	int tam2=s2.length();


	for(int i=1;i<=tam1;i++){
		for(int j=1;j<=tam2;j++){
				if(s1[i-1]==s2[j-1]){
					dp[i][j]=dp[i-1][j-1]+1;
					
				}
				else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	
	int i=tam1;
	int j=tam2;
	int band=0;
	while(i>0 && j>0){
			
		if(s1[i-1]==s2[j-1]){
			cadena.push_back(s1[i-1]);
			i--;j--;
		}
		 
		else if(dp[i][j-1]>dp[i-1][j])j--;
		else
			i--;

	}
	if(cadena.size()==0)printf("\n");
	else{
			for(int i=cadena.size()-1;i>=0;i--)
				cout<<cadena[i];
			cout<<endl;
	}
		
		
}		

int main() 
{ 
	string s1,s2;
	cin>>s1;
	cin>>s2;
	lcs(s1,s2);
 
    return 0; 
} 

Measured memory_bytes: 47360
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    S = iss()

    ret, cnt = 0, 0
    for s in S:
        if s == 'B':
            cnt += 1
        if s == 'W':
            ret += cnt
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10264
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <cstring>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PPII;
typedef pair<int, PPII> PPPII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

bool senbei[10010][11] = {};
int main(void){
	int r, c;
	while(cin >> r >> c && r && c){
		ll res = 0;
		memset(senbei, 0, sizeof senbei);
		REP(i, r){
			REP(j, c){
				cin >> senbei[j][i];
			}
		}
		REP(i, 1 << r){
			bool isTurned[10] = {};
			int a = i;
			int b = 0;
			int cnt = 0;
			while(a > 0){
				if(a & 1){
					isTurned[b] = true;
				}
				b++;
				a = a >> 1;
			}
			REP(j, c){
				int cnt_a = 0;
				REP(k, r){
					if(isTurned[k] ^ senbei[j][k]) cnt_a++;
				}
				cnt += max(cnt_a, r-cnt_a);
			}
			res = max(res, (ll)cnt);
		}
	cout << res << endl;
	}
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(),v.end()
#define UN(v) sort(ALL(v)),v.erase(unique(ALL(v)))
#define FILL(x,y) memset(x,y,sizeof(x))
#define EACH(v,it) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
string s;
ll ans,last,sum;
/*---main code---*/

int main()
{
	FIO;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='B')
		{
			sum++;
		}
		else
		{
//			cout<<ans<<' '<<last<<' '<<sum<<'\n';
			ans+=(last+sum);
			last+=sum;
			sum=0;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>

int main(){
	int n, x, y;
	std::cin >> n >> x >> y;
	x--;
	y--;
	std::vector<int> k(n, 0);
	for(int st=0; st<n-1; st++){
		for(int end=st+1; end<n; end++){
			int d2 = std::abs(st-x) + std::abs(end-y) + 1;
			int d = std::min(end-st, d2);
			// int d;
			// if(end <= x or y <= st){
			// 	std::cout << "p1 ";
			// 	d = end - st;
			// }else if(st <= x and y <= end){
			// 	std::cout << "p2 ";
			// 	d = x - st + end - y + 1;
			// }else if(x<=st and st<=y and y<=end){
			// 	std::cout << "p3 ";
			// 	d = std::min(end-st, (end-y)+(st-x)+1);
			// }else{
			// 	std::cout << "p4 ";
			// 	d = std::min(end-st, -(end-y)-(st-x)+1);
			// }
			k[d]++;
			// printf("%d - %d : d = %d\n", st+1, end+1, d);
		}
	}

	for(int i=1; i<n; i++){
		std::cout <<k[i]<< std::endl;
	}
	return 0;
}


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

typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

void Main() {
    int a,b,h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}

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


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

int main(void){
    int k;
    cin >> k;
    
    vector<bool> d(1000005,false);

    if(7%k==0){cout << 1 << endl; return 0;}

    int dr = 7;
    int rest = 7;
    ll cnt = 1;
    d[7] = true;

    do{
        cnt++;
        dr *= 10;
        dr %= k;
        rest += dr;
        rest %= k;
        if(d[rest]){cout << -1 << endl; return 0;}
        else d[rest] = true;
    }while(rest!=0);

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lesson1
{
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            int N = int.Parse(Console.ReadLine());
            if (!(1 <= N && N <= 10000)) return;
            // 整数の入力
            int A = int.Parse(Console.ReadLine());
            if (!(0 <= A && A <= 1000)) return;

            int remainingN = N / 500;
            int RN = N - remainingN * 500;
            if (RN <= A) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13140
// https://atcoder.jp/contests/dp/tasks/dp_c
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <limits>
using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define EACH(i, n) for (auto &i: n)

int main() {
  int n;

  cin >> n;

  vector<long long> a(n), b(n), c(n);
  FOR(i, n) {
    cin >> a[i] >> b[i] >> c[i];
  }

  vector<vector<long long> > dp(n, vector<long long>(3, 0));
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  for (int i = 1; i < n; i++) {
    dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
    dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
    dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
  }
  cout << *max_element(dp[n - 1].begin(), dp[n - 1].end()) << endl;

  return 0;
}


Measured memory_bytes: 8064
n = int(input())
lst = [int(input()) for i in range(n)]

maxi = [0, 0]
for i in range(n):
  if lst[i] > maxi[0]:
    maxi = [lst[i], i]
    
maxi2 = 0
for j in range(n):
  if j == maxi[1]:
    continue
  else:
    if lst[j] > maxi2:
      maxi2 = lst[j]
    
for i in range(n):
  if i != maxi[1]:
    print(maxi[0])
  else:
    print(maxi2)

Measured memory_bytes: 12532
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(;;){
        int m,n;
        cin>>m>>n;
        if(!m) return 0;
        vector<bool> p(8000000,0);
        int res=m;
        rep(i,0,n){
            rep(j,1,8000000/res+1){
                p[res*j]=1;
            }
            while(p[res]) res++;
        }
        cout <<res<<"\n";
    }
}


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

typedef long double ld;
typedef long long int ll;
vector<vector<ll>> adjlist;
ll max(ll x, ll y) { return (x > y) ? x : y; }
ll min(ll x, ll y) { return (x > y) ? y : x; }
#define sfor(a, n, i) for (ll i = a; i < n; i++)
#define rfor(n, a, i) for (ll i = n; i >= a; i--)
#define mod 1000000007
#define pb push_back
#define in insert
#define mp make_pair
#define inf mod
#define bg begin()
#define ed end()
#define sz size()
#define vi vector<ll>
#define vc vector<char>
#define vinv vector<vector<ll, ll>>
#define imap map<ll, ll>
#define cmap map<char, ll>
#define smap map<string, ll>
#define iset set<ll>
#define bit(x, i) (x & (1 << i))
int main()
{
    ll n, w;
    cin >> n >> w;
    pair<ll, ll> vw[n + 1];
    vw[0] = {0, 0};
    sfor(01, n + 1, i) cin >> vw[i].first >> vw[i].second;
    // sfor(01, n + 1, i)
    // {
    //     cout << vw[i].first << " " << vw[i].second;
    //     cout << endl;
    // }

    vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, 0));
    sfor(1, w + 1, i)
    {
        sfor(1, n + 1, j)
        {
            if (vw[j].first <= i)
            {
                ll temp = max(dp[j - 1][i], vw[j].second + dp[j - 1][i - vw[j].first]);
                dp[j][i] = temp;
            }
            else{
                dp[j][i]=dp[j-1][i];
            }
        }
    }
    // sfor(0, n + 1, i)
    // {
    //     sfor(0, w + 1, j)
    //     {

    //         cout << dp[i][j] << " "; //= max(dp[j - 1][i], vw[j].second + dp[j - 1][i - vw[j].first]);
    //     }
    //     cout << endl;
    // }
    cout << dp[n][w] << endl;
    return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
int ar[105];
bool dp[100100];
int main()
{
    int n, k;
    scanf("%d", &n); scanf("%d", &k);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &ar[i]);
    }
    sort(ar, ar + n);
    for (int i = 1; i <= k; ++i)
    {
        for (int j = 0; j < n && ar[j] <= i; ++j)
        {
            dp[i] |= (!dp[i - ar[j]]);
        }
    }
    if (dp[k])
        cout << "First";
    else
        cout << "Second";
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int N;
LL a[55];

int main(void)
{
	cin >> N;
	int big = INT_MIN, sml = INT_MAX;
	int bs = -1, ss = -1;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		//big = max(big, a[i]);
		//sml = min(sml, a[i]);
		if (big < a[i]) {
			big = a[i];
			bs = i;
		}
		if (sml > a[i]) {
			sml = a[i];
			ss = i;
		}
	}

	vector<pair<int, int>>out;

	int minus = -1;
	if (sml <= 0 && 0 <= big) {
		if (abs(sml) < abs(big)) {
			for (int i = 0; i < N; ++i) {
				if (bs != i && a[i] < 0) {
					//cout << bs << " " << i << endl;
					out.push_back({ bs,i });
					a[i] += a[bs];
				}
			}
			minus = 0;
		}
		else {
			for (int i = 0; i < N; ++i) {
				if (ss != i && a[i] > 0) {
					//cout << ss << " " << i << endl;
					out.push_back({ ss,i });
					a[i] += a[ss];
				}
			}
			minus = 1;
		}
	}
	else {
		if (0 <= sml)minus = 0;
		else minus = 1;
	}
	if (minus) {
		for (int i = 0; i < N; ++i)a[i] = -a[i];
	}
	for (int i = 0; i < N - 1; ++i) {
		if ((minus && (a[N - i - 1] > a[N - i - 2])) || (!minus && (a[i] > a[i + 1]))) {
			//cout << i << " " << i + 1 << endl;
			if (minus) {
				out.push_back({ N - i - 1,N - i - 2 });
				a[N - i - 2] += a[N - i - 1];
			}
			else {
				out.push_back({ i,i + 1 });
				a[i + 1] += a[i];
			}
		}
	}
	cout << out.size() << endl;
	for (int i = 0; i < out.size(); ++i) {
		cout << out[i].first + 1 << " " << out[i].second + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323
 
//void quick(int *,long long,long long);
int m(int n,int a[14]);

int main(){
     
	int  a[14];
	char b[15];
	int i,j,k,temp,flag,can;

	while(scanf("%s",b)!=EOF){
		can=0;
		for(i=1;i<=9;i++){
			for(j=0;j<13;j++)
				a[j]=b[j]-'0';
			a[13]=i;
			for(j=13;j>=1;j--)
				for(k=0;k<=j-1;k++){
					if(a[k]>a[k+1]){
						temp=a[k];
						a[k]=a[k+1];
						a[k+1]=temp;
					}
				}
			k=1;
			flag=1;
			for(j=0;j<13;j++){
				if(a[j]==a[j+1]){
					k++;
					if(k>4){
						flag=0;
						break;
					}
				}else
					k=1;
			}
			if(flag==1&&k<=4){
				if(m(14,a)==1){
					if(can==0)
						can=1;
					else
						printf(" ");
					printf("%d",i);
				}
			}
		}
		if(can==1)
			printf("\n");
		else
			printf("0\n");
	}
    return 0;
}

int m(int n,int a[14]){

	int i,j,k1,k2,k3,m1,m2,m3,flag;
	int b[14];
	int c[14];

	for(i=0;i<n;i++)
		b[i]=a[i];

	if(n==2){
		if(b[0]==b[1])
			return 1;
		else
			return 0;
	}else{
		flag=0;
		i=0;
		while(i<n){
			m1=b[i];
			if(i+2<n&&b[i+1]==m1&&b[i+2]==m1){
				for(j=0;j<n;j++)
					c[j]=b[j];
				for(j=i;j+3<n;j++)
					c[j]=c[j+3];
				if(m(n-3,c)==1)
					return 1;
			}
			i++;
			while(i<n&&b[i]==m1)
				i++;
		}
		i=0;
		while(i<n){
			k1=i;
			m1=b[k1];

			k2=k1+1;
			while(k2<n&&b[k2]==m1)
				k2++;

			if(k2>=n)
				break;
			else if(b[k2]==m1+1)
				m2=b[k2];
			else{
				i=k2;
				continue;
			}
			
			k3=k2+1;
			while(k3<n&&b[k3]==m2)
				k3++;

			if(k3>=n)
				break;
			else if(b[k3]==m2+1)
				m3=b[k3];
			else{
				i=k2;
				continue;
			}

			for(j=0;j<k1;j++)
				c[j]=b[j];
			for(j=k1;j+1<k2;j++)
				c[j]=b[j+1];
			for(j=k2-1;j+2<k3;j++)
				c[j]=b[j+2];
			for(j=k3-2;j+3<n;j++)
				c[j]=b[j+3];

			if(m(n-3,c)==1)
				return 1;
			else
				i=k2;
		}
		return 0;
	}
}

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

const int INF = 1e9;

int main() {
  int a[5];
  for (int i=0;i<5;i++) {
    cin>>a[i];
  }

  int sum=0;
  for (int i=0;i<5;i++) {
    sum+=(a[i]-1)/10*10+10;
  }
  int min_mod=10;
  for (int i=0;i<5;i++) {
    if ((a[i]%10)<min_mod && a[i]%10 != 0) {
      min_mod=a[i]%10;
    }
  }
  cout<<(sum-(10-min_mod))<<endl;

}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

lim = 10 ** 5 + 2
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, lim + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    # 累計
    factinv.append((factinv[-1] * inv[-1]) % mod)

def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % mod

N = getN()
A = getList()

lista = [0] * (max(A) + 1)
double = 0
dou_ind_2 = 0
for i in range(N + 1):
    if lista[A[i]] > 0:
        double = A[i]
        dou_ind_2 = i
        break
    lista[A[i]] += 1

dou_ind_1 = 0
for i in range(N + 1):
    if A[i] == double:
        dou_ind_1 = i
        break

outer = dou_ind_1 + (N - dou_ind_2)

for i in range(1, N + 2):
    if i == 1:
        print(N)
        continue
    print((cmb(N + 1, i) - cmb(outer, i - 1)) % mod)

Measured memory_bytes: 115148
#include<iostream>
using namespace std;
typedef long long llong;

int main(){
    llong i, n, sum=0;
    cin >> n;
    for(i=1; i<=n; i++){
        if(i % 3 != 0 && i % 5 !=0) sum += i;
    }

    cout << sum << endl;
}

Measured memory_bytes: 3600
import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String saa = sc.next(), sbb = sc.next(), scc = sc.next();
		int na = saa.length(), nb = sbb.length(), nc = scc.length();
		int a = 0, b = 0, c = 0, turn = 0;
		while(true){
			if(turn == 0){
				if(a == na){
					System.out.println('A');
					break;
				}
				turn = saa.charAt(a) - 'a';
				a++;
			}else if(turn == 1){
				if(b == nb){
					System.out.println('B');
					break;
				}
				turn = sbb.charAt(b) - 'a';
				b++;
			}else{
				if(c == nc){
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c) - 'a';
				c++;
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 22608
import sys
from random import *
from collections import *
from heapq import *

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
dij = [(1, 0), (-1, 0), (0, 1), (0, -1)]

class UnionFind:
    def __init__(self, n):
        self.state = [-1] * n
        # self.size_table = [1] * n
        # cntはグループ数
        # self.cnt = n

    def root(self, u):
        v = self.state[u]
        if v < 0: return u
        self.state[u] = res = self.root(v)
        return res

    def merge(self, u, v):
        ru = self.root(u)
        rv = self.root(v)
        if ru == rv: return
        du = self.state[ru]
        dv = self.state[rv]
        if du > dv: ru, rv = rv, ru
        if du == dv: self.state[ru] -= 1
        self.state[rv] = ru
        # self.cnt -= 1
        # self.size_table[ru] += self.size_table[rv]
        return

    # グループの要素数
    # def size(self, u):
    #     return self.size_table[self.root(u)]

n,q=MI()
uf=UnionFind(n+1)
for _ in range(q):
    t,u,v=MI()
    if t:print((uf.root(u)==uf.root(v))*1)
    else:uf.merge(u,v)


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i_len=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back
#define mp make_pair

int main()
{
    ll N;
    cin >> N;
    
    vector<pair<ll,ll>> P;
    ll a;
    REP(i,1,N+1) {
        cin >> a;
        P.pb(mp(a, i));
    }
    sort(ALL(P));

    REP(i,0,N) PS(P[i].second);
    PR("");

    return 0;
}

/*
    1 2 3 4 5 6 7 8
    8 2 7 3 4 5 6 1
    8 2 4 5 6 7 3 1
*/

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

namespace Aizu01
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] height = new int[10];
            string line;
            for (int i = 0; i < 10; i++)
            {
                line = Console.ReadLine();
                height[i] = int.Parse(line);
            }

            Array.Sort(height);



            for (int i = 0; i < 3; i++)
            {
                Console.Write("{0}\n", height[9-i]);
            }
        }

    }
    
}

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


int main()
{
    int N;
    cin >> N;

    for(int i = 0; i < N; i++) {
        int Y, M, D;
        cin >> Y >> M >> D;
        
        int res = 1;
        for(; D < ((Y % 3 == 0 || M % 2 == 1) ? 20 : 19); D++) res++;
        for(; M < 10; M++) res += ((Y % 3 == 0 || (M+1) % 2 == 1) ? 20 : 19);
        for(; Y < 999; Y++) res += ((Y+1) % 3 == 0 ? 20 * 10 : 20 * 5 + 19 * 5);

        cout << res << endl;
    }
}

Measured memory_bytes: 1160
#include <stdio.h>
#define N 10010
int n;
int father[N];
int findfather(int x){
    return x == father[x] ? x : findfather(father[x]);
}
void init(){
    for(int i = 0; i < n; i++) father[i] = i;
}
int main(){
    int m;
    scanf("%d %d", &n, &m);
    init();
    for(int i = 0; i < m; i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        if(a == 0){
            father[findfather(c)] = findfather(b);
        }
        else{
            printf("%s\n", findfather(b) == findfather(c) ? "1" : "0");
        }
    }
    return 0;
}



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


int main()
{
  int i,j,k;
  int N=0;
  
  char str[] = "abcdefghijklmnopqrstuvwxyz";
  
  char c=' ';
  scanf("%c",&c);
  
  for(i=0;i<strlen(str);i++){
    if( c == str[i] ){
      printf("%c\n",str[i+1]);
      break;
    }
  }

  return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  int up_c = N/4;
  int up_d = N/7;
  
  bool can = false;
  
  for(int i=0; i< (up_c + 1); i++){
    for(int j=0; j<(up_d+ 1);j++){
      int amount = 4*i + 7*j;
      if(amount == N){
        can = true;
        break;
      }
    }
    if(can) break;
  }
  
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

struct location{
	int x;
	int y;
};

void solve(int m, int n, location sample[], location star[])
{
	if (m == 1){
		cout << star[0].x - sample[0].x << " " << star[0].y - sample[0].y << endl;
		return;
	}

	for (int i1 = 0; i1 < n; i1++){//star start
		for (int j = 1; j < m; j++){//sample end
			location vec_sample;
			vec_sample.x = sample[j].x - sample[0].x;
			vec_sample.y = sample[j].y - sample[0].y;

			for (int i2 = 0; i2 < n; i2++){//star end
				location vec_star;
				vec_star.x = star[i2].x - star[i1].x;
				vec_star.y = star[i2].y - star[i1].y;

				if (vec_sample.x == vec_star.x && vec_sample.y == vec_star.y){
					break;
				}
				if (i2 == n - 1){
					goto wrong;
				}	
			}
		}
		cout << star[i1].x - sample[0].x << " " << star[i1].y - sample[0].y << endl;
		return;
	wrong:;
	}
}

int main()
{
	while (1){
		int m;
		cin >> m;
		if (!m){ break; }

		int n;
		location sample[200], star[1000];
		for (int i = 0; i < m; i++){
			cin >> sample[i].x >> sample[i].y;
		}
		cin >> n;
		for (int i = 0; i < n; i++){
			cin >> star[i].x >> star[i].y;
		}

		solve(m, n, sample, star);
	}
	return 0;
}

Measured memory_bytes: 1168
N,M=map(int,input().split())
A=[input()for i in range(N)]
B=[input()for i in range(M)]
for i in range(N-M+1):
    for j in range(len(A[0])-len(B[0])+1):
        l=[]
        for k in range(M):
            l.append(A[i+k][j:j+M])
        if l==B:print('Yes');exit()
print('No')

Measured memory_bytes: 9116
#include <stdio.h>
#include <stdlib.h>

#define Maxn 51

struct Pair {
	int first, second;
};
int cmp(const void *a, const void *b) {
	Pair p = *(Pair*)a, q = *(Pair*)b;
	int cmp1 = q.first - p.first;
	if (cmp1) return cmp1;
	cmp1 = q.second - p.second;
	return cmp1;
}

Pair v[Maxn];

int ans[Maxn * Maxn], sz;
int main() {
	register int i, j;
	int n, k, pre1 = -1, pre2, x;
	scanf("%d%d", &n, &k);
	for (i = 0; i < n; ++ i)
		scanf("%d", &v[i].first), v[i].second = i + 1;
	for (i = 0; i <= k; ++ i) {
		qsort(v, n, sizeof(v[0]), cmp);
		for (j = 0; j < n; ++ j)
			if (v[j].second ^ pre1) {
				pre2 = v[j].second;
				ans[++ sz] = v[j].second;
				if (-- v[j].first < 0)
					return puts("-1") & 0;
			}
		pre1 = pre2;
	}
	printf("%d\n", sz);
	for (i = 1; i <= sz; ++ i)
		printf("%d%c", ans[i], i == sz ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC118A
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] n = Console.ReadLine().Split(' ');
			int a = int.Parse(n[0]);
			int b = int.Parse(n[1]);

			if ((b % a) == 0)
				Console.WriteLine(a + b);

			else
				Console.WriteLine(b - a);

		}
	}
}


Measured memory_bytes: 13140
import scala.io.{StdIn => in}

object Main extends App {
  val n = in.readInt
  val h = in.readLine.split(" ").map(_.toInt)

  val ans = h./:(0,0) {
    case ((acc, max), i) => {
      if(i >= max) (acc+1, i)
      else (acc, max)
    }
  }._1

  println(ans)
}

Measured memory_bytes: 25536
s = input()
s_list = list(s)
count = s.count('B')
for _ in range(count):
  ind = s_list.index('B')
  if ind > 0:
    s_list[ind-1] = ''
  s_list[ind] = ''
  s = ''.join(s_list)
  s_list = list(s)
s = ''.join(s_list)
print(s)

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

const string num[11] = {"0111111", "0000110", "1011011",
                        "1001111", "1100110", "1101101",
                        "1111101", "0100111", "1111111",
                        "1101111", "0000000"};
int main()
{
    int n;

    while (cin >> n, n != -1) {
        int bf = 10;

        for (int i = 0; i < n; i++) {
            int inp;
            string ans;

            cin >> inp;            
            for (int i = 0; i < 7; i++)
                if (num[inp][i] != num[bf][i]) 
                    ans.push_back('1');
                else
                    ans.push_back('0');
            cout << ans << endl;

            bf = inp;
        }
    }

    return 0;
}

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

using namespace std;

int main(void) {
  int a[5];
  int k;
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
  
  int M = a[0];
  int m = a[0];
  for (int i = 0; i < 5; i++){
    M = max(M, a[i]);
    m = min(m, a[i]);
  }

  //cout << M << m << endl;

  if (M - m <= k) 
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
 
  
 
using namespace std;
 
  
 
int main()
{
    int a, b;
     
    cin >> a >> b;
    if (a > b)
      cout << "a > b" << endl;
    else if (a < b)
      cout << "a < b" << endl;
    else
      cout << "a == b" << endl;
    
    return 0;}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll h,w;
	cin>>h>>w;
	ll ans = 1e18;
	for(int i = 1; i<=h; i++)
	{
		ll area1 = w*i, area2 = (h-i)/2 * w, area3 = h*w-area1-area2;
		ans = min(ans,max({area1,area2,area3})-min({area1,area2,area3}));
		area2 = w/2 *(h-i), area3 = h*w-area1-area2;
		ans = min(ans,max({area1,area2,area3})-min({area1,area2,area3}));
	}
	for(int i = 1; i<= w;i++)
	{
		ll area1 = h*i, area2 = (w-i)/2 * h, area3 = h*w-area1-area2;
		ans = min(ans,max({area1,area2,area3})-min({area1,area2,area3}));
		area2 = h/2 *(w-i), area3 = h*w-area1-area2;
		ans = min(ans,max({area1,area2,area3})-min({area1,area2,area3}));
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace  std;

int main(void)
{
    int N;
    string S;
    cin >> N >> S;

    int count = 0;
    int l = 0, r = S.length()-1;
    while(1)
    {
        for(; l <= r; l++){
            if(S[l] == 'W'){
                break;
            }
        }
        for(; l <= r; r--){
            if(S[r] == 'R'){
                break;
            }
        }
        if(l <= r){
            count++;
            l++, r--;
        }
        else{
            break;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=1e3+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=1e9;
const double ep=1e-7;
using namespace std;
int main()
{
	int n,i,ans=0;
	char s[maxn];
	scanf("%d",&n);
	scanf("%s",s+1);
	for(i=3;i<=n;i++)
	{
		if(s[i]=='C'&&s[i-1]=='B'&&s[i-2]=='A')ans++;
	}
	printf("%d\n",ans);
}

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

int main() {
	int n, k;
	cin >> n >> k;
	int p[n];
	for (int i=0; i<n; i++)
	    cin >> p[i];
	sort(p, p+n);
	int ans = 0;
	for (int i=0; i<k; i++)
	    ans += p[i];
	cout << ans << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007


string s[10]={
	"* = ****",
	"* =* ***",
	"* =** **",
	"* =*** *",
	"* =**** ",
	" *= ****",
	" *=* ***",
	" *=** **",
	" *=*** *",
	" *=**** "
};



int main(){
	int n;
	//string t;
	bool f=false;
	while(cin>>n){
		if(f)cout<<endl;
		else f=true;
		for(int i=0; i<8; i++){
			string t;
			for(int j=n; j>0; j/=10){
				t+=s[(j%10)][i];
			}
			for(int j=t.size(); j<5; j++){
				t+=s[0][i];
			}
			reverse(all(t));
			cout<<t<<endl;
		}
	}
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define MAXN 3010
#define int long long
#define INF 123456789
using namespace std;

int dp[MAXN][MAXN];
int V[MAXN];

int solve(int i,int j){
	if(i>j)return 0;
	if(dp[i][j]!=-INF)return dp[i][j];
	
	int op1 = V[i]+min(solve(i+1,j-1),solve(i+2,j));
	int op2 = V[j]+min(solve(i+1,j-1),solve(i,j-2));
	return dp[i][j]=max(op1,op2);
}

int32_t main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			dp[i][j]=-INF;
	int soma=0;
	for(int i=0;i<n;i++){
		cin>>V[i];
		soma+=V[i];
	}
	int X = solve(0,n-1);
	int Y = soma - X;
	
	cout<<X-Y<<endl;	
		
}

Measured memory_bytes: 71040
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e-a<=k)cout << "Yay!" << endl;
  else cout << ":(" << endl;


}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
void solve()
{
    ld a, b;
    cin>>a>>b;
    cout<<(ll)floor(a*b);
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}


Measured memory_bytes: 3732
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    int n;
    cin >> n;
    vector<ll> a;
    REP(i, n) {
        ll input;
        cin >> input;
        a.push_back(input);
    }
    sort(ALL(a));

    int ans = a[0];
    while(a.size() >= 2) {
        ans = a[0];
        vector<int> erase_index;
        FOR(i, 1, a.size()) {
            a[i] = a[i] % a[0];
            if (a[i] == 0) {
                erase_index.push_back(i);
            }
        }
        for(int i = erase_index.size()-1; i >= 0; i--) {
            a.erase(a.begin() + erase_index[i]);
        }
        sort(ALL(a));
        // EACH(x, a) {
        //     P(x)
        // }
        // P("===============")
    }
    P(ans);

    return 0;
}


Measured memory_bytes: 1908
#include <iostream>

using namespace std;

int main(){
    int n,x;
    cin >> n >> x;
    int minD=1000;
    int total=0;
    for(int i=0;i<n;i++){
        int a=0;
        cin >> a;
        total+=a;
        minD=min(minD,a);
    }
    cout << n+(x-total)/minD << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  n %= 10;
  switch (n) {
    case 3:
      cout<<"bon"<<endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout<<"pon"<<endl;
      break;
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout<<"hon"<<endl;
      break;
  }
  return 0;
}


Measured memory_bytes: 3636
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,a[55][30]={},cnt=0,x[30]={};
  string s;
  cin >> n;
  for(int i=0; i<30; i++) {
    x[i]=inf;
  }
  for(int i=0; i<n; i++) {
    cin >> s;
    int a[30]={};
    for(int j=0; j<s.size(); j++) {
      a[s[j]-'a']++;
    }
    for(int j=0; j<30; j++) {
      x[j]=min(x[j],a[j]);
    }
  }
  for(int i=0; i<26; i++) {
    for(int j=0; j<x[i]; j++) {
      cout << char('a'+i);
    }
  }
  cout << endl;
}

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


int tab[500][500];
bool sit[500][500];
vector<int> pp;

int n;

void print_tab() 
{
    for (int i = 0;i < n ;i++) 
    {
        for (int j = 0; j < n; j++)
        {
            cout << tab[i][j] << " ";
        }
        cout << endl;
    }
}

pair<int, int> get_co(int k) {
    int i = k / n;
    int j = k % n;
    pair<int, int> tmp = make_pair(i,j);
    return tmp;
}

vector<pair<int, int> > get_neigh(int x, int y)
{
    vector<pair<int, int> > tmp;
    if ((x-1) >= 0) tmp.push_back(make_pair(x-1, y));
    if ((x+1) < n) tmp.push_back(make_pair(x+1, y));
    if ((y-1) >= 0) tmp.push_back(make_pair(x, y-1));
    if ((y+1) < n) tmp.push_back(make_pair(x, y+1));

    return tmp;
}

int main() {
    
    cin >> n;
    for (int i = 0; i < (n * n); i++) {
        int tmp;
        cin >> tmp;
        pp.push_back(tmp-1);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int min_w = min(i, abs(n-i-1));
            int min_h = min(j, abs(n-j-1));
            tab[i][j] = min(min_w, min_h);
            sit[i][j] = 1;
        }
    }


    ll hate = 0;
    for (int p : pp) {
        pair<int, int> tmp = get_co(p);
        int x = tmp.first;
        int y = tmp.second;

        hate += tab[x][y];

        // cout << x << " " << y << endl;
        sit[x][y] = 0;

        // Update Cost
        queue<pair<int,int> > to_update;
        to_update.push(make_pair(x,y));
        while (!to_update.empty()) 
        {
            pair<int,int> now = to_update.front();
            to_update.pop();
            int x_now = now.first;
            int y_now = now.second;
            // cout << x << " " << y << endl;
            // break;

            vector<pair<int, int> > neighbor = get_neigh(x_now, y_now);

            int n_cost = sit[x_now][y_now] * 1 + tab[x_now][y_now];
            // printf("Current cost %d\n", n_cost);
            for (auto nb: neighbor)
            {
                int x_n = nb.first;
                int y_n = nb.second;
                // printf("Neighbor cos at %d %d is %d\n", x_n, y_n, tab[x_n][y_n]);
                if (tab[x_n][y_n] > n_cost)
                {
                    tab[x_n][y_n] = n_cost;
                    to_update.push(make_pair(x_n, y_n));
                }
            }
        }
        // print_tab();
    }
    // cout << "yoo" << endl;

    cout << hate << endl;
    return 0;
}

Measured memory_bytes: 5616
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  double edp[n + 1][n + 1][n + 1];
  int b[3] = {0};
  for (int i = 0; i < n; i++)
    b[a[i] - 1]++;
  edp[0][0][0] = 0.0;

  for (int k = 0; k <= n; k++) {
    for (int j = 0; j <= n; j++) {
      for (int i = 0; i <= n; i++) {
        if (i == 0 && j == 0 && k == 0) {
          continue;
        }
        if (i + j + k > n)
          continue;
        edp[i][j][k] = 1.0;
        if (i > 0)
          edp[i][j][k] += edp[i - 1][j][k] * i / n;
        if (j > 0 && i < n)
          edp[i][j][k] += edp[i + 1][j - 1][k] * j / n;
        if (k > 0 && j < n)
          edp[i][j][k] += edp[i][j + 1][k - 1] * k / n;
        edp[i][j][k] /= (double)(i + j + k) / n;
      }
    }
  }
  printf("%.12lf\n", edp[b[0]][b[1]][b[2]]);
  return 0;
}


Measured memory_bytes: 213248
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    cout << (h*w) - ((h/a)*a)*((w/b)*b) << endl;
    return 0;
}


Measured memory_bytes: 3108
#include <stdio.h>
#include <string.h>

#define Q_MAX (400000)

typedef struct {
	char block[10][11];
    int num[3];
	int time;
} COLOR;

int head, tail;
COLOR queue[Q_MAX];

void enq(COLOR t)
{
	queue[tail++ % Q_MAX] = t;
}

void deq(COLOR *t)
{
	*t = queue[head++ % Q_MAX];
}

int conv(char c)
{
    return ((c > 'B') + (c > 'G'));
}

int x, y;

void dfs(COLOR *exm, char c, char change, int p, int q)
{
	int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
	int i;
	
    exm->num[conv(exm->block[q][p])]--;
    exm->num[conv(c)]++;
	exm->block[q][p] = c;
	
	for (i = 0; i < 4; i++){
		if (0 <= p + dx[i] && p + dx[i] < x && 0 <= q + dy[i] && q + dy[i] < y && exm->block[q + dy[i]][p + dx[i]] == change){
			dfs(exm, c, change, p + dx[i], q + dy[i]);
		}
	}
}

int main(void)
{
	COLOR puzzle, temp;
	int i, j;
	char c;
    
	while (1){
		scanf("%d%d", &x, &y);
		
		if (x + y == 0){
			break;
		}
        memset(puzzle.num, 0, sizeof(puzzle.num));
        
		
		for (i = 0; i < y; i++){
			for (j = 0; j < x; j++){
				do {
					c = getchar();
				} while (c != 'R' && c != 'G' && c != 'B');
				
				if (c != 'R' && c != 'G' && c != 'B'){
					return (1);
				}
				puzzle.block[i][j] = c;
                puzzle.num[conv(puzzle.block[i][j])]++;
			}
		}
		memset(queue, 0, sizeof(queue));
		head = tail = 0;
		puzzle.time = 0;
		enq(puzzle);
        
		while (1){
			deq(&temp);
			
			if (temp.num[0] == x * y || temp.num[1] == x * y || temp.num[2] == x * y){
				break;
			}
			
			if (temp.block[0][0] != 'R'){
				puzzle = temp;
				puzzle.time = temp.time + 1;
				dfs(&puzzle, 'R', temp.block[0][0], 0, 0);
				enq(puzzle);
			}
			
			if (temp.block[0][0] != 'G'){
				puzzle = temp;
				puzzle.time = temp.time + 1;
				dfs(&puzzle, 'G', temp.block[0][0], 0, 0);
				enq(puzzle);
			}
			
			if (temp.block[0][0] != 'B'){
				puzzle = temp;
				puzzle.time = temp.time + 1;
				dfs(&puzzle, 'B', temp.block[0][0], 0, 0);
				enq(puzzle);
			}
		}
		
		printf("%d\n", temp.time);
	}
	
	return (0);
}

Measured memory_bytes: 49000
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }


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

int main() {
  int l;
  cin >> l;
  int shift = 22;
  while (shift >= 0) {
    if (l >> shift & 1) break; 
    --shift;
  }
  int n = shift;
  vector<Edge> ans;
  for (int i = n; i > 0; --i) {
    int from = n-i+1;
    int to = n-i+2;
    ans.push_back(Edge(from, to, 0));
    ans.push_back(Edge(from, to, pow(2,i-1)));
  }

  int weight = pow(2,n);
  shift = n-1;
  while (shift >= 0) {
    if (l >> shift & 1) {
      int from = 1;
      int to = n-shift+1;
      ans.push_back(Edge(from, to, weight));
      weight += pow(2,shift);
    }
    --shift;
  }

  cout << n+1 << " " << ans.size() << endl;
  for (auto e : ans) {
    cout << e.from << " " << e.to << " " << e.weight << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int get_num_of_area( int n );

int main(void)
{
	int n;

	while(1)
	{
		cin >> n;
		if( cin.eof() ) break;
		cout << get_num_of_area( n ) << endl;
	}

	return 0;
}

int get_num_of_area( int n )
{
	/*
		初期平面数1から直線本数が1本増えるごとに
		エリア数は直線本数総数分だけ増える。
	*/
	return 1 + n*(n+1)/2;
}

Measured memory_bytes: 1160