akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int MAX = 3000;
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    int N, K;
    cin >> N >> K;
    cout << N - K + 1 << endl;
    for(int i=2; i<=K; ++i) {
        cout << COM(N - K + 1, i) * COM(K - 1, i - 1) % MOD << endl;
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    int y[x+2];
    y[0]=0,y[x+1]=0;
    ll sum=0;
    for (int i=1;i<=x;i++){
        cin>>y[i];
        sum+=abs(y[i]-y[i-1]);
    }
    sum+=abs(y[x+1]-y[x]);
    for (int i=1;i<=x;i++){
        cout<<sum+abs(y[i+1]-y[i-1])-abs(y[i+1]-y[i])-abs(y[i]-y[i-1])<<endl;
    }
    return 0;
}


Measured memory_bytes: 1664
//In the name of God
//SMani24
#include<bits/stdc++.h>
using namespace std;

int a, b;
string s, t, u;
map<string, int> cnt;

int main() {
	cin >> s >> t >> a >> b >> u;
	cnt[s] = a, cnt[t] = b, cnt[u]--;
	cout << cnt[s] << ' ' << cnt[t] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

const int MAXN = 200005;
int par1[MAXN], par2[MAXN];

void union_init(int d[], int s) { for (int i=0; i < s; i++) d[i]=i; }
int union_query(int d[], int n) { int res=n; while (d[res]!=res) res=d[res]; int m; while (d[n]!=n) {m=d[n];d[n]=res;n=m;} return res; };
int union_merge(int d[], int x, int y) { x=union_query(d,x); y=union_query(d,y); if (x==y)return -1; d[x]=y; return 1; }

int n, k, l;

map<PII, int> cnt;

int main() {
    GI(n); GI(k); GI(l);

    union_init(par1, n+1);
    union_init(par2, n+1);

    int u, v;

    FORN(i, k) {
        GI(u); GI(v);
        union_merge(par1, u, v);
    }

    FORN(i, l) {
        GI(u); GI(v);
        union_merge(par2, u, v);
    }

    FOR1(i, n) {
        cnt[MP(union_query(par1, i), union_query(par2, i))]++;
    }

    FOR1(i, n) {
        printf("%d ", cnt[MP(union_query(par1, i), union_query(par2, i))]);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 13568
s = input()
n = len(s) - 1
ans = 0
for i in range(2**n):
    tmp = s
    cnt = 0
    for j in range(n):
        if i >> j & 1:
            tmp = tmp[:j+cnt+1] + '+' + tmp[j+cnt+1:]
            cnt += 1
    ans += eval(tmp)
print(ans)

Measured memory_bytes: 67904
#include <bits/stdc++.h>
using namespace std;
const int N=1010;
char s[15][N];
int num[15][N];
int main()
{
    int h,w,k,ans=0;
    scanf("%d%d%d",&h,&w,&k);
    for(int i=1;i<=h;i++)
        scanf("%s",s[i]+1);
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
            num[i][j]=num[i-1][j]+num[i][j-1]-num[i-1][j-1]+s[i][j]-'0';
    }
    if(h==1)
    {
        int st=0;
        for(int i=1;i<=w;i++)
        {
            if(num[1][i]-num[1][st]==k&&i<w)
            {
                ans++;
                st=i;
            }
            printf("%d\n",ans);
            return 0;
        }
    }
    ans=h*w;
    for(int i=0;i<(1<<(h-1));i++)//行的划分种类数
    {
        int c=0,r;
        int res=__builtin_popcount(i);//cout<<"res="<<res<<endl;
        bool g=0;
        for(int j=1;j<=w;j++)//枚举列
        {
            bool f=0;
            r=0;
            for(int u=1;u<=h;u++)
            {
                if((1&(i>>(u-1)))||u==h)
                {//cout<<"u="<<u<<endl;
                    int t=num[u][j]+num[r][c]-num[r][j]-num[u][c];
                    r=u;//cout<<"t="<<t<<endl;
                    if(t>k)
                        f=1;
                }
            }
            if(f&&j==c+1)
            {
                g=1;
                break;
            }
            if(f)
            {
                res++;
                c=j-1;
            }
        }
        if(!g)
            ans=min(res,ans);
    }
    printf("%d\n",ans);
    return 0;
}


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

using namespace std;

int a[3], d[3], e[3];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d%d%d", a, a + 1, a + 2);
		for (int j = 0; j < 3; j++)
			d[j] = a[j] + max(e[(j + 1) % 3], e[(j + 2) % 3]);
		copy(d, d + 3, e);
	}
	cout << max(max(d[0], d[1]), d[2]) << endl;
	return 0;
}


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

int main() {
  int n;
  long long p;
  long long c = 0;
  string s;
  bool t = false;
  string ans = "Yes";
  cin >> s;

  for ( int i=0 ; i < s.size() ; i=i+2 ) {
    if (s.substr(i,2)=="hi") {
      ans = "Yes";
    } else {
      ans = "No";
      break;
    }
    
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}


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



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

	if (K > (N - 1)*(N - 2) / 2) cout << "-1";
	else
	{
		int M=0, u[10000], v[10000];

		for (int i = 0; i <= N-2; i++)
		{
			M++;
			u[i] = 1;
			v[i] = i + 2;
		}

		int L = (N - 1)*(N - 2) / 2;
		int c = M;

		for (int i = 2; i <= N-1; i++)
		{
			for (int j = i+1; j <= N; j++)
			{
				if (L == K) break;

				L--;
				u[M] = i;
				v[M] = j;
				M++;
			}
			if (L == K) break;
		}

		cout << M << endl;
		for (int i = 0; i < M; i++)
		{
			cout << u[i] << " " << v[i] << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = LLONG_MAX;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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

__attribute__ ((constructor))
void init() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
}

ll f0(ll a, ll b){
  return a - b;
}

ll f1(ll a, ll b){
  return a + b;
}

signed main(){
  ll ans = 0;
  ll n;
  cin >> n;
  set<pair<ll,ll>> s;
  rep(i,n){
    ll x, y;
    cin >> x >> y;
    s.insert({x, y});
  }
  vector<ll> v1, v2;
  for(auto u : s){
    v1.push_back(f0(u.first, u.second));
  }
  for(auto u : s){
    v2.push_back(f1(u.first, u.second));
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  cout<<max(v1.back()-v1[0],v2.back()-v2[0])<<endl;
  return 0;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')

typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int N;
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        if (N % i == 0)
        {
            int cur = N / i;
            if (i >= 1 && i <= 9 && cur >= 1 && cur <= 9)
            {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
    return 0;
}

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

bool check(string s)
{
  for(int i=0;i<s.size()-1;i++)
    {
      if(s[i]=='A')
	{
	  if(s[i+1]!='B'&&s[i+1]!='D')
	    return false;
	}
      if(s[i]=='B')
	{
	  if(s[i+1]!='A'&&s[i+1]!='C'&&s[i+1]!='E')
	    return false;
	}

      if(s[i]=='C')
	{
	  if(s[i+1]!='B'&&s[i+1]!='F')
	    return false;
	}

      if(s[i]=='D')
	{
	  if(s[i+1]!='A'&&s[i+1]!='E'&&s[i+1]!='G')
	    return false;
	}

      if(s[i]=='E')
	{
	  if(s[i+1]!='B'&&s[i+1]!='D'&&s[i+1]!='F'&&s[i+1]!='H')
	    return false;
	}

      if(s[i]=='F')
	{
	  if(s[i+1]!='C'&&s[i+1]!='E'&&s[i+1]!='I')
	    return false;
	}

      if(s[i]=='G')
	{
	  if(s[i+1]!='D'&&s[i+1]!='H')
	    return false;
	}

      if(s[i]=='H')
	{
	  if(s[i+1]!='G'&&s[i+1]!='E'&&s[i+1]!='I')
	    return false;
	}

      if(s[i]=='I')
	{
	  if(s[i+1]!='F'&&s[i+1]!='H')
	    return false;
	}
      
    }
  return true;
}

int main()
{
  string s;
  for(;cin>>s;)
    if(check(s))
      cout<<s<<endl;
}

Measured memory_bytes: 1184
#include <stdio.h>

int main(void) {
	int i,j;
	int data[10] = {0};
	int tmp;
	
	for(i=0; i<10; i++){
		scanf("%d",&data[i]);
	}
	
	for(i=0; i<3; i++){
		for(j=9; j>i; j--){
			if(data[j-1] < data[j]){
				tmp = data[j];
				data[j] = data[j-1];
				data[j-1] = tmp;
			}
		}
	}
	
	for(i=0; i<3; i++){
		printf("%d\n",data[i]);
	}
	
	return 0;
}

Measured memory_bytes: 600
push(@p,$p=$p*2+1),push@c,$c=$c*2+3for$c--..55;sub f{my($n,$x)=@_;$n?$x>1+$c[$n-1]?$p[$n-1]+1+f($n-1,$x-2-$c[$n-1]):f($n-1,$x-1):$x>0}print<>!~$"+f$`,$'

Measured memory_bytes: 640
fn main() {
    let n = read::<usize>();
    let n = n % 10;
    let ret = match n {
        2 | 4 | 5 | 7 | 9 => "hon",
        0 | 1 | 6 | 8 => "pon",
        3 => "bon",
        _ => "",
    };
    println!("{}", ret)
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 2128
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+9
#define MOD 1000000007
using namespace std;



int main(){
    int H,W,N;
    cin >> H >> W >> N;
    int sr,sc;
    cin >> sr >> sc;
    
    string S,T;
    cin >> S >> T;
    
    
    
    //上から
            int h=sr,w=sc;
    for(int i=0; i<N; i++){
        if(S[i]=='U'){
            h--;
        }
        if(h==0){
            cout<<"NO"<<endl;
            return 0;
        }
        if(T[i]=='D' && h!=H){
            h++;
        }
    }
    
    //下から
    h=sr,w=sc;
    for(int i=0; i<N; i++){
        if(S[i]=='D'){
            h++;
        }
        if(h==H+1){
            cout<<"NO"<<endl;
            return 0;
        }
        if(T[i]=='U' && h!=1){
            h--;
        }
    }
    
    //左から
    h=sr,w=sc;
    for(int i=0; i<N; i++){
        if(S[i]=='L'){
            w--;
        }
        if(w==0){
            cout<<"NO"<<endl;
            return 0;
        }
        if(T[i]=='R' && w!=W){
            w++;
        }
    }
    
    //右から
h=sr,w=sc;
    for(int i=0; i<N; i++){

        if(S[i]=='R'){
            w++;
        }
        if(w==W+1){
            cout<<"NO"<<endl;
            return 0;
        }
        if(T[i]=='L' && w!=1){
            w--;
        }
    }
    
    cout<<"YES"<<endl;
    return 0;
}


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

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

    int a;
    int ans = 0;
    for (size_t i = 1; i <= N; i++)
    {
        cin >> a;
        if (i % 2 == 1 && a % 2 == 1)
        {
            ans++;
        }
    }
    cout << ans << endl;
}


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

int main() {
  int N, A;
  int count500;
  int count1;
  
  cin >> N >> A;

  count500 = N / 500;
  count1 = N % 500;
  if (count1 > A) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long N = lread();
    auto ans = new long[](100_000_000);

    foreach (i; 1 .. 500)
        foreach (j; 1 .. 500)
            foreach (k; 1 .. 500)
            {
                ans[i * i + j * j + k * k + i * j + j * k + k * i]++;
            }
    foreach (i; 1 .. N + 1)
    {
        writeln(ans[i]);
    }
}


Measured memory_bytes: 785820
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

void dfs(int v, int n, int d, vector<vector<int>> &g, vector<bool> flag, int &ans) {
    flag[v] = 0;
    if(d+1==n) {
        ++ans;
        return;
    }
    REP(i,g[v].size()) {
        if(!flag[g[v][i]]) continue;
        dfs(g[v][i], n, d+1, g, flag, ans);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<vector<int>> g(n);
    REP(i,m) {
        int a,b; cin >> a >> b; --a, --b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    vector<bool> flag(n,1);
    int ans = 0;
    dfs(0,n,0,g,flag,ans);
    cout << ans << endl;
    return 0;
}

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

using namespace std;
int x,k,n,poz,dp[100005];
vector <int> v;
int mex(vector <int> &v)
{
    sort(v.begin(), v.end());
    for(int i=0;i<v.size();i++)
    {
        if(v[i]!=i)
            return i;
    }
    return v.size();
}
int calc(int poz)
{
    vector <int> vmex;
    for(int it : v)
    {
        if(poz-it>=0)
            vmex.push_back(dp[poz-it]);
    }
    return mex(vmex);
}
int main()
{
    cin>>n>>k;
    for(poz=1;poz<=n;poz++)
    {
        cin>>x;
        v.push_back(x);
    }
    for(poz=0 ;poz<=k;poz++)
        dp[poz]=calc(poz);

    if(dp[k])
        cout<<"First";
    else
        cout<<"Second";
    return 0;
}


Measured memory_bytes: 640
k = int(input())
def gcd(a, b, c):
    gcd1 = 1
    if a%c == 0 and b%c == 0:
        gcd1 = c
    elif a%2 == 0 and b%2 == 0 and c%2 == 0:
        gcd1 = 2
        for i in range(4, c//2+1, 2):
            if a%i == 0 and b%i == 0 and c%i == 0:
                gcd1 = i
    else:
        for i in range(3, c//2+1, 2):
            if a%i == 0 and b%i == 0 and c%i == 0:
                gcd1 = i
    # print(gcd1)
    return gcd1

sum_gcd = 0
for a in range(1, k+1):
    for b in range(1, a+1):
        for c in range(1, b+1):
            if a == b and b == c:
                sum_gcd += gcd(a, b, c)
            elif a == b or b == c or c == a:
                sum_gcd += 3*gcd(a, b, c)
            else:
                sum_gcd += 6*gcd(a, b, c)
print(sum_gcd)


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

int main() {
	string s;
	cin >> s;
	int n = s.size();
	vector<string> d = { "maerd","esare","remaerd", "resare" };
	reverse(s.begin(), s.end());
	bool elf = true;
	for (int i = 0; i < n; ) {
		if (s.substr(i, 5) == d[0] || s.substr(i, 5) == d[1]) {
			i += 5;
			continue;
		}
		if (s.substr(i, 6) == d[3]) {
			i += 6;
			continue;
		}
		if (s.substr(i, 7) == d[2]) {
			i += 7;
			continue;
		}
		elf = false;
		if (i >= n || !elf) break;
	}
	cout << (elf ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int ans = k;
		
		for(int i = 1; i < n; i++) {
			ans = ans * (k-1);
		}
		
		System.out.println(ans);
		
			
		
  	}
}


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

using namespace std;

typedef long long ll;

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

int binary_search(const vector<int> &xs, const int val, bool f(const vector<int> &, int, int)) {
    int left = -1, right = (int) xs.size(), mid;
    while (right - left > 1) {
        mid = left + (right - left) / 2; // (right + left) / 2 may cause overflow
        if (f(xs, mid, val)) left = mid;
        else right = mid;
    }

    return right;
}

/*
 * ref. https://atcoder.jp/contests/abc077/tasks/arc084_a
 */
int main(void) {
    int N;
    cin >> N;

    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    vector<int> b(N);
    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }
    vector<int> c(N);
    for (int i = 0; i < N; i++) {
        cin >> c[i];
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    ll ans = 0;
    for (int i_b = 0; i_b < N; i_b++) {
        // lower_bound (which returns the minimum index larger than or equal to val)
        int i_a = binary_search(a, b[i_b], [](const vector<int> &xs, int ind, int val) {
                return xs[ind] < val;
        });
        // upper_bound (which returns the minimum index larger than val)
        int i_c = binary_search(c, b[i_b], [](const vector<int> &xs, int ind, int val) {
                return xs[ind] <= val;
        });
        ans += ((ll) i_a) * ((ll) (c.size() - i_c));

        // Same as the above code
        // auto lb1 = lower_bound(a.begin(), a.end(), b[i_b]);
        // auto lb2 = upper_bound(c.begin(), c.end(), b[i_b]);
        // ans += (lb1 - a.begin()) * (c.end() - lb2);

        // cout <<i_a << "," << (((int) c.size()) - i_c) << " - "
        //     << (lb1 - a.begin()) << "," << (c.end() - lb2) << endl;
    }

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


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
    char s[10];
    cin>>s;
    int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
    for(int i=43;i<=45;i+=2)
        for(int j=43;j<=45;j+=2)
            for(int k=43;k<=45;k+=2){
                int ans=a;
                if(i==43) ans+=b;
                else ans-=b;
                if(j==43) ans+=c;
                else ans-=c;
                if(k==43) ans+=d;
                else ans-=d;
                if(ans==7) return cout<<a<<char(i)<<b<<char(j)<<c<<char(k)<<d<<"=7"<<endl,0;
            }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-6;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n, k; cin >> n >> k;
    vector<ld> a(n); cin >> a;
    function<bool(ld)> check = [&](ld x)->bool {
        ll cnt = 0;
        FOR(i, 0, n) {
            cnt += ll(a[i] / x);
            if (a[i] - ll(a[i] / x) * x < eps)--cnt;
        }
        return cnt <= k;
    };
    ld ok = INF, ng = 0;
    FOR(i, 0, 50) {
        ld mid = (ok + ng) / 2;
        if (check(mid))ok = mid;
        else ng = mid;
    }
    print(ll(ok + 1 - eps));

    return 0;
}

Measured memory_bytes: 6364
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>

using namespace std;



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

	double s = (a + b + c) / 2.0;

	cout << sqrt(s*(s - a)*(s - b)*(s - c)) << endl;

	return 0;
}

Measured memory_bytes: 256
/*

Bismillah_hir_rahmanir_rahim

*/

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;


#define bug cout <<"--------------------------\n"



#define inf ( ll  )( 1e18 + 100 )

#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)

#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define PI          2*acos(0.0)
#define MOD         1000000007
#define endl        '\n'
#define yes         cout << "yes" << endl
#define no          cout << "no" << endl
#define YES         cout << "YES" << endl
#define NO          cout << "NO" << endl
#define LCM(a, b)   ((a)*(b)) / __gcd(a, b)
#define INPUT       freopen("input.txt", "r", stdin);
#define OUTPUT      freopen("output.txt", "w", stdout);
#define PRINT(a)    for(auto i : a) cout << i << " "; cout << endl;


int month[] = {31,28,31,30,31,30,31,31,30,31,30,31};
string lowerCase = "abcdefghijklmnopqrstuvwxyz";
string upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

/// Graph moves
/// const int fx[] = {+1,+1,+0,-1,-1,-1,+0,+1}; /// King's move
/// const int fy[] = {+0,+1,+1,+1,+0,-1,-1,-1}; /// King's move



/// int dx[] = {0, 0, +1, -1};
/// int dy[] = {+1, -1, 0, 0};   //4 Direction Array

///  int dx[] = {0, 0, -1, +1, -1, -1, +1, +1}, dy[] = {-1, +1, 0, 0, -1, +1, -1, +1};   //8 Direction Array

///int dx[] = {-2, -2, -1, -1, +1, +1, +2, +2}, dy[] = {-1, +1, -2, +2, -2, +2, -1, +1}; //Knight Moves

///int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; ///Hexagonal Direction


bool isPallindrome(string s)
{
    string r=s;
    reverse(s.begin(),s.end());
    if(s==r)
        return true;
    return false;
}


template <typename T>
std::string NumberToString ( T Number )
{
    std::ostringstream ss;
    ss << Number;
    return ss.str();
}



int main()
{
    FIO;


    ll n ;

    cin >>  n ;

    ll ans = 0 ;

    ans = (n / 500) * 1000 ;

    n-=(n/500)*500;

    ans+=(n/5)*5;

    n-=(n/5)*5;

    cout <<ans<<endl;

    return 0;

}


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

#define ll long long
#define endl '\n'

using namespace std;

ll GCD(ll i, ll j, ll k){
	ll first = __gcd(i, j);
	ll second = __gcd(first, k);
	return second;
}

int  main (){
	//freopen("input.txt", "r", stdin);

	ll n;
	cin>>n;

	ll sum = 0;
	for(ll i=1; i<=n; i++){
		for(ll j=1; j<=n; j++){
			for(ll k = 1; k<=n; k++){
				sum += GCD(i, j, k);
			}
		}
	}
	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n >> m;
    intl a[n];
    cin(i,a);
    sort(a,a + n, greater<>());
    intl b = 0;
    rep(i,m)b += a[i];
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;0<=i;i--)
using namespace std;
#define SIZE 50
int h,w;

void solve(int map[SIZE][SIZE]){
  int dp[w][h];
  
  dp[0][0] = 0;
  for(int i=1;i<w;i++)
    dp[i][0] = map[i][0] + dp[i-1][0];
  for(int i=1;i<h;i++)
    dp[0][i] = map[0][i] + dp[0][i-1];
  
  for(int i=1;i<h;i++)
    for(int j=1;j<w;j++)
      dp[j][i] = map[j][i] + min(dp[j-1][i],dp[j][i-1]);
  
  printf("%d\n",dp[w-1][h-1]);
}

int main(){
  scanf("%d %d",&h,&w);
  int map[SIZE][SIZE];
  rep(i,h){
    char m[w];
    scanf("%s",m);
    rrep(j,w){
      map[j][i]=m[j]-'0';
    }
  }
  solve(map);
}

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

using namespace std;

string s;
int N, SN;

int main(){
	cin >> s;
	N = stoi(s);
	for(int i = 0; i < s.size(); ++i) SN += s[i] - '0';
	cout << (N % SN == 0 ? "Yes" : "No") << endl;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define long long int
#define endl "\n"
using namespace std;
int32_t main()
{	
	IOS;
	string str;
	cin>>str;
	if(str== "Sunny")
		cout<<"Cloudy"<<endl;
	else if(str== "Cloudy")	cout<<"Rainy"<<endl;
	else cout<<"Sunny"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define double long double
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, k, a[510], b[510], c[510], d[510], sum;
vector<int> divi;
signed main() {
	cin >> n >> k;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	for (int i = 1; i * i <= sum; i++) {
		if (sum % i == 0) {
			divi.push_back(i);
			if (i * i != sum)divi.push_back(sum / i);
		}
	}
	int ans = 0;
	for (int i : divi) {
		rep(j, n)b[j] = a[j] % i;
		sort(b, b + n);
		rep(j, n) {
			c[j] = b[j];
			if (j)c[j] += c[j - 1];
		}
		for (int j = n - 1; j >= 0; j--) {
			d[j] = b[j];
			if (j != n - 1)d[j] += d[j + 1];
		}
		int p, m;
		p = 0; m = n * d[0];
		if (max(p, m) <= k && abs(p - m) % i == 0)ans = max(ans, i);
		rep(j, n) {
			p = c[j];
			if (j != n - 1)m = (n - j - 1) * i - d[j + 1];
			else m = 0;
			if (max(p, m) <= k && abs(p - m) % i == 0) {
				ans = max(ans, i);
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
#define ll long long
const int maxn=100000+10;
int x[maxn],xx[maxn],w[maxn];
int i,j,k,l,r,s,t,n,m;
ll c;
inline int read()
{
    int k=1;int x=0;
    char ch=getchar();
    while ((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')
    k=-1,ch=getchar();
    while(ch>='0'&&ch<='9')
    x=x*10+ch-'0',ch=getchar();
    return k*x;
}
int main()
{
	n=read(),l=read(),t=read();
	fo(i,1,n)
		x[i]=read(),w[i]=read();
	fo(i,1,n)
	{
		if (w[i]==2) w[i]=-1;
		r=x[i]+w[i]*t;
		if (r>0) (c+=r/l)%=n;
		else if (r<0) (c+=(r+1)/l-1)%=n;
		xx[i]=(r%l+l)%l;
	}
	sort(xx+1,xx+n+1);
	c=(c+n)%n;
	fo(i,c+1,n)
		printf("%d\n",xx[i]);
	fo(i,1,c) printf("%d\n",xx[i]);
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
void prians(bool answer) {
  if(answer)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
struct data {
  int t;
  int x;
  int y;
};
vector<data> v;
int n;

bool solve();

int main() {
  int i;
  data duumy;
  cin >> n;
  duumy.t = 0;
  duumy.x = 0;
  duumy.y = 0;
  v.push_back(duumy);
  for(i = 0; i < n; ++i) {
    cin >> duumy.t >> duumy.x >> duumy.y;
    v.push_back(duumy);
  }
  prians(solve());
  return 0;
}

bool solve() {
  int t, nx, ny, now;
  for(int i = 1; i <= n; ++i) {
    t = v[i].t - v[i - 1].t;
    nx = v[i].x - v[i - 1].x;
    if(nx < 0) nx *= -1;
    ny = v[i].y - v[i - 1].y;
    if(ny < 0) ny *= -1;
    now = nx + ny;
    if(t < now || (t - now) % 2 == 1) return 0;
  }
  return 1;
}

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

    public static void main(String __[]) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        while(str.contains("B")){
            str = str.replaceAll("^B|[01]B","");
        }
        System.out.println(str);
    }
}

Measured memory_bytes: 23764
//
// Created by yamunaku on 2019/12/09.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> v(n);
    int a;
    rep(i, n){
        cin >> a;
        v[i] = vector<pair<int, int>>(a);
        rep(j, a){
            cin >> v[i][j].first >> v[i][j].second;
            v[i][j].first--;
        }
    }
    int ans = 0;
    rep(i, 1 << n){
        int tmp = 0;
        bool ok = true;
        rep(j, n){
            if(i & (1 << j)){
                for(auto &p:v[j]){
                    if(i&(1<<p.first)){
                        if(p.second==0) ok=false;
                    }else{
                        if(p.second==1) ok=false;
                    }
                }
                tmp++;
            }
        }
        if(ok) ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll A[305][305], Dist[305][305], ans = 0;
priority_queue <pair<ll, Pii>, vector<pair<ll, Pii> >, greater<pair<ll, Pii> > > que;

int main(){
  scanf("%d", &N);
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      scanf("%lld", &A[i][j]);
      if (i < j) que.push(mp(A[i][j], mp(i, j)));
      if (i != j) Dist[i][j] = 1e18;
    }
  }

  while (!que.empty()){
    pair<ll, Pii> Q = que.top(); que.pop();
    ll Cost = Q.fi;
    int i = Q.se.fi, j = Q.se.se;

    if (Dist[i][j] > Cost) ans += Cost;
    else continue;
    Dist[i][j] = Cost; Dist[j][i] = Cost;

    for (int I = 0; I < N; I++){
      for (int J = 0; J < N; J++){
        ll now = min(Dist[I][i] + Dist[j][J], Dist[I][j] + Dist[i][J]) + Dist[i][j];
        Dist[I][J] = min(now, Dist[I][J]);
      }
    }
  }

  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      if (A[i][j] != Dist[i][j]) ans = -1;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>> //a(縦行,vector<ll>(横列));
#include<algorithm>//__gcd(a,b)
#include <iostream>
#include <vector>
#include <cstdlib>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    long long N;
    cin >> N;
    long long ans=0;
    const auto &pf = prime_factorize(N);
    long long res = 1;
    for (auto p : pf) {
        for(int i=0;i<=p.second;i++){if((i+1)*(i+2)/2>p.second)break;ans++;}
    }

cout<<ans<<endl;







}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
string s;
int N;
int a[100100];
bool check(int x){
	char f = 'f';
	for(int i=0;i<N;i++){
		if(a[i]>=x)continue;
		if(f=='f')f=s[i];
		else{
			if(f!=s[i])return false;
		}
	}
	return true;
}
int main(){
	cin >> s;
	N = s.size();
	for(int i=0;i<N;i++)a[i]=max(i,N-1-i);
	int l = 1,r = N+1;
	while(r-l>1){
		int mid = (l+r)/2;
		if(check(mid))l = mid;
		else r = mid;
	}
	cout << l << endl;
	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#define M 10100

int n;
int prime[M];
int prime2[M] = {};
long long rui[M] = {};
int tmp = 0;

void c()
{
    for (int i = 0; i < 10000; i++)
    {
        prime[i] = 1;
    }
    prime[0] = prime[1] = 0;

    for (int i = 2; i < 317; i++)
    {
        if (prime[i])
        {
            for (int j = i * 2; j < M; j += i)
            {
                prime[j] = 0;
            }
        }
    }
    for (int i = 2; i < M; i++)
    {
        if (prime[i])
        {
            prime2[tmp] = i;
            tmp++;
        }
    }
}

void a()
{
    for (int i = 0; i < tmp; i++)
    {
        rui[i + 1] = rui[i] + prime2[i];
    }
}

int main()
{
    c();
    a();
    while (1)
    {
        scanf("%d", &n);
        if (n == 0)
            return 0;

        int right = 1;
        int left = 0;
        int count = 0;

        while (right != left)
        {
            if (rui[right] - rui[left] == n)
            {
                right++;
                count++;
            }
            else if (rui[right] - rui[left] < n)
            {
                right++;
            }
            else
            {
                left++;
            }
        }
        printf("%d\n", count);
    }

    return 0;
}


Measured memory_bytes: 1996
#include <stdio.h>

int main(void)
{
    int x, y;
    
    while(1) {
        scanf("%d %d", &x, &y);
        if(x == 0 && y == 0)
            break;
        if(x > y)
            printf("%d %d\n", y, x);
        else
            printf("%d %d\n", x, y);
    }

    return 0;
}

Measured memory_bytes: 600
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from collections import Counter


def counting_sort(a, b, k):
    c = Counter()
    for j in a:
        c[j] += 1
    for i in range(1, k+1):
        c[i] += c[i-1]
    for j in a[::-1]:
        b[c[j]] = j
        c[j] -= 1


n = int(stdin.readline())
data = [int(s) for s in stdin.readline().split()]
output = [0] * (n+1)
counting_sort(data, output, 10000)
print(*output[1:])

Measured memory_bytes: 176984
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

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

    int able_h = 0;
    for(int i = 0; i < N; i++){
        if(h[i] > 0){
            able_h = i;
        }
    }
    int MAX=100;
    for (int i = 0; i <= MAX; i++){
        for (int k = 0; k <= MAX; k++){
            int H = h[able_h] + abs(x[able_h] - i) + abs(y[able_h] - k);
            bool ok = true;
            for (int p = 0; p < N; p++){
                if (max(H - abs(x[p] - i) - abs(y[p] - k), 0) != h[p]){
                    ok = false;
                    break;
                }
            }
            if (ok) {
                cout << i << ' ' << k << ' '<< H << endl;
            }
        }
    }




    return 0;
}


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

int main(int argc, char** argv) {
	int n, m;
	cin >> n >> m;
	vector<int> w(n), v(n);
	for(int i = 0; i < n; i++)
	{
		cin >> v[i] >> w[i];
	}
	
	//vector<vector<int> > f(n+1, vector<int>(m+1, -1));
	vector<vector<int> > f(n+1, vector<int>(m+1));
	f[0][0] = 0;
	for(int i = 1; i < m+1; i++)
	{	//0 items CANNOT sum to any weight.
		f[0][i] = -1;
	}
	
	for(int i = 1; i < n + 1; i++)
	{
		int j;
		for(j = 0; j < m + 1; j++)
		{
			f[i][j] = f[i-1][j];
			if(j-w[i-1] >= 0 && f[i-1][j-w[i-1]] != -1)
			{
				f[i][j] = max(f[i][j], f[i-1][j-w[i-1]] + v[i-1]);
			}
			
		}
	}

	int maxV = f[n][0];
	for(int j = 1; j < m+1; j++)
	{
		if(f[n][j] > maxV) maxV = f[n][j];
	}
	
	cout << maxV << endl;
	
	return 0;
}


Measured memory_bytes: 6848
#include<bits/stdc++.h>
#define R register
#define ll long long
#define int long long
using namespace std;
ll base[40];
ll D;
ll ans=0;
ll st[40];
inline void dfs(int now,int len,ll sum){
	if(now==len/2+1){
		if(sum!=D) return;
		ll tans=st[1]>=0?(9-st[1]):(9+st[1]);
		for(R int i=2;i<now;i++) tans=tans*(st[i]>=0?(10-st[i]):(10+st[i]));
		ans+=len&1?tans*10:tans;
		return ;
	}
	if(sum+10ll*(base[len-now]-base[now-1])<D) return ;
	if(sum-10ll*(base[len-now]-base[now-1])>D) return ;
	for(R int ss=-9;ss<=9;ss++){
		st[now]=ss;
		dfs(now+1,len,sum+st[now]*(base[len-now]-base[now-1]));
	}
	return ;
}
signed main(){
	cin>>D;
	int tmp=0;ll d=D;
	base[0]=1;
	while(d) tmp++,d/=10;
	for(R int i=1;i<=18;i++) base[i]=base[i-1]*10;
	for(R int i=tmp;i<=18;i++) dfs(1,i,0);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    String Pass = sc.next();
    char Nums[]=new char[4];
    boolean result=false;
    for(int i=0;i<4;i++){
     Nums[i] =Pass.charAt(i);
    }
    for(int i=1;i<4;i++){
     if( Nums[i-1]==Nums[i]){
     	result=true;
     }
    }if(result==true){
    System.out.println("Bad");
    }else{
     System.out.println("Good");
    }
  }
  
  }


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
////////////////////////////////////////////////////////////////////

int n,a[26];
signed main(){
  cin>>n;rep(i,26)a[i] = INF;
  rep(i,n){
    string s;cin>>s;
    int cnt[26];rep(j,26)cnt[j] = 0;
    rep(j,s.length()){
      cnt[s[j]-'a']++;
    }
    rep(j,26)chmin(a[j], cnt[j]);
  }
  string ans;
  rep(i,26){
    rep(j,a[i])ans += ('a'+i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 2000000
int H,A[MAX+1];


void maxHeapify(int i){
    int l,r,big,max;
    l=2*i;
    r=2*i+1;
    
    if(l<=H && A[l]>A[i]) big=l;
    else big=i;
    if(r<=H && A[r]> A[big]) big=r;
    
    if(big!=i){
        max = A[big];
        A[big] = A[i];
        A[i] = max;
        maxHeapify(big);
    }
}

int main(){
int i;
  scanf("%d",&H);
  for( i=1 ; i<=H ; i++ )
    scanf("%d",&A[i]);
 
  for( i = H/2 ; i>0 ; i-- ) maxHeapify(i);
 
  for( i=1 ; i<=H ; i++ )
    printf(" %d",A[i]);
  printf("\n");
 
  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long a,b,s;
  cin>>a>>b>>s;

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

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

int main() {
  int N;
  cin >>N;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin >>p.at(i);
  }
  sort(p.begin(),p.end());
  int ans=0;
  for(int i=0;i<N-1;i++){
    ans+=p.at(i);
  }
  ans+=p.at(N-1)/2;

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	char cup[4];
	int ans[4]={1,0,0,0};
	int i=0;
	
	for(;cin >> cup[i];)
	{
		i++;
		if(i==3)
		{
			int a;
			a=ans[cup[0]-'A'];
			ans[cup[0]-'A']=ans[cup[2]-'A'];
			ans[cup[2]-'A']=a;
			i=0;
		}
	}
	for(i=0;i<3;i++)
	{
		if(ans[i]==1)
		{
			char a;
			a='A'+i;
			cout << a << endl;
		}
	}
}

Measured memory_bytes: 0