akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
N = int(input())
N, A, B = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

S = input().rstrip()
S = sorted(S)
if S[0] == S[1] and S[2] == S[3] and S[0] != S[2]:
    print('Yes')
else:
    print('No')





# def main():

# if __name__ == '__main__':
#     main()


Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    sort(v.begin(), v.end());
    int count = 0;
    count += v[2]-v[1];
    v[0] += count;
    if ((v[2]-v[0])%2 == 0) {
        count += (v[2]-v[0])/2;
    } else {
        count += (v[2]-v[0])/2 + 2;
    }
    cout << count << endl;
}

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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main() {
    int n; cin >> n;
    map<int,int> w;
    rep(i,n){
        int a, b;
        cin >> a >> b;
        w[b] += a;
    }
    int t = 0;
    for(auto p : w){
        t += p.second;
        if(p.first < t){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

int main() {
  long N;
  cin >>N;
  long n,m;
  double root = sqrt(N);
  long nrf=floor(root);
  while(true){
    if(N%nrf==0){
      n = nrf;
      m = N/nrf;
      break;
    }else{
      nrf--;
    }
  }
  cout<<n+m-2<<endl;
}

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

const ll mod=1e9+7;

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    ll s=power(a,b/2);
    s*=s;
    s%=mod;
    if(b&1)return (s*a)%mod;
    return s%mod;
}

ll inv(ll a){
    return power(a,mod-2);
}

ll f[10000000]{0};
ll C(ll a,ll b){

    if(a<b){
        return 0;   
    }

    ll ans=1;
    ans=f[a];
    ans*=(inv(f[b]));
    ans%=mod;
    ans*=(inv(f[a-b]));

    return ans%mod;

}

int main() {
    // cout<<"Hello World!"
    f[0]=1;
    for(ll i=1;i<=1e6-1;i++){
        f[i]=f[i-1]*i;
        f[i]%=mod;
    }
    ll h,w,a,b;
    cin>>h>>w>>a>>b;

    ll ans=C(h+w-2,h-1);
    // cout<<ans<<endl;
    ll ans1=0;
    for(ll i=h-a+1;i<=h;i++){
        ans1+=(C(i+b-2,b-1)*C(h-i+1 - 2+w-b,w-b-1))%mod;
        ans1%=mod;
    }
    ans-=ans1;
    ans%=mod;
    ans=(ans+mod)%mod;
    cout<<ans<<endl;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int	A, B;
	cin >> A >> B;
	if (A <= 8 && B <= 8)cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = ((int)(n) - 1); i >= 0; i--)
#define repn(i, n) for(int i = 1; i <= (int)(n); i++)
#define reprn(i, n) for(int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
using llint = long long int;
using lint = long int;

#include <iostream>
#include <array>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;

int main() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	int old_p = 0;
	while (true) {
		auto p = s.find("#.", max(old_p - 2, 0));
		if (p != std::string::npos) {
			s.erase(p, 2);
			ans++;
			old_p = p;
		} else {
			break;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define is insert
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
//set<int, Comparator> S;
ll N,M;
vector<ll> P;
ll INF=1000*1000;
int main() {
    cin >> N >> M;
    P.resize(N,0);
    ll a=0,s=0;
    REP(i,M) {
        ll p;
        string S;
        cin >>p>>S;--p;
        if (S[0]=='A') {
            if (P[p]>=0)s++;
            a+=max(0ll,P[p]);
            P[p]-=INF;
        }else{
            P[p]+=1;
        }
    }
    cout << s<<" "<<a <<endl;

    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int color[705],l[705],r[705],a[705][705],w,b,n,m,ans;
bool dp[705][705][705];
void dfs(int u,int co)
{
	color[u]=co;
	if (co==1) w++;else b++;
	for (int v=1;v<=n;v++)
	{
		if (u!=v && a[u][v]==false && color[v]!=0 && color[v]==co)
		{
			printf("-1\n");
			exit(0);
		}
		if (u!=v && a[u][v]==false && color[v]==0)
			dfs(v,3-co);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		a[x][y]=a[y][x]=true;
	}
	for (int i=1;i<=n;i++)
	{
		w=b=0;
		if (color[i]==0) dfs(i,1);
		l[i]=w;r[i]=b;
	}
	dp[0][0][0]=1;
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<=n;j++)
			for (int k=0;k<=n;k++)
			{
				if (j>=l[i] && k>=r[i])
					dp[i][j][k]=dp[i-1][j-l[i]][k-r[i]];
				if (j>=r[i] && k>=l[i])
					dp[i][j][k]|=dp[i-1][j-r[i]][k-l[i]];
			}
	}
	ans=1e9;
	for (int i=1;i<=n;i++)
	{
		if (!dp[n][i][n-i]) continue;
		ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 343936
#include<stdio.h>
int main(void)
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if(a != b && a != c && b != c){
  printf("3\n");
} else if(a == b && a == c && b == c){
  printf("1\n");
} else {
  printf("2\n");
}
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=200010,M=4e5+5;
const int INF=0x3f3f3f3f;
int n,m;
namespace graph{
	int hed[N],h[N],cnt=1,to[M],nxt[M],cap[M],flow[M];
	int S,T;
	int d[N];bool vis[N];
	void adde(int u,int v,int _cap){
		++cnt;to[cnt]=v,cap[cnt]=_cap,nxt[cnt]=hed[u],flow[cnt]=0;hed[u]=cnt;
		++cnt;to[cnt]=u,cap[cnt]=0,nxt[cnt]=hed[v],flow[cnt]=0;hed[v]=cnt;
	}
	queue<int>Q;
	bool bfs(){
		memset(vis,0,sizeof(vis));
		memset(d,0,sizeof(d));
		Q.push(S);vis[S]=1;
		while(!Q.empty()){
			int u=Q.front();Q.pop();
			for(int i=hed[u];i;i=nxt[i]){
				int v=to[i];
				if(!vis[v]&&cap[i]>flow[i]){
					vis[v]=1,d[v]=d[u]+1;
					Q.push(v);
				}
			}
		}
		return vis[T];
	}
	int dfs(int u,int F){
		if(u==T||!F)return F;
		int flownow=0;
		for(int &i=h[u];i;i=nxt[i]){
			int v=to[i];if(d[v]!=d[u]+1)continue;
			int f=dfs(v,min(F,cap[i]-flow[i]));
			flownow+=f;F-=f;
			flow[i]+=f;flow[i^1]-=f;
			if(!F)break;
		}
		if(!flownow)d[u]=0;
		return flownow;
	}
	int max_flow(){
		int fw=0;
		while(bfs()){
			for(int i=1;i<=T;i++){
				h[i] = hed[i];
			}
			// cout << "?" << endl;
			fw+=dfs(S,INF);
		}
		return fw;
	}
}

int x[N],y[N],p[N],q[N];
int ncnt=0;
int main(){
	using namespace graph;
	cin >> n;
	for(int i=1;i<=n;i++)scanf("%d",&p[i]),p[i]++;
	for(int i=1;i<=n;++i)if(!x[i]){
		++ncnt;
		for(int j=i;!x[j];j=p[j])x[j]=ncnt;
	}
	for(int i=1;i<=n;i++)scanf("%d",&q[i]),q[i]++;
	for(int i=1;i<=n;++i)if(!y[i]){
		++ncnt;
		for(int j=i;!y[j];j=q[j])y[j]=ncnt;
	}
	S = ncnt+1,T = ncnt+2;
	int sum = 0;
	for(int i=1;i<=n;i++){
		if(p[i]==q[i]){
			if(p[i]==i)continue;sum+=2;
			adde(S,x[i],1),adde(y[i],T,1),adde(x[i],y[i],2);
		}else{
			sum++;
			if(p[i]==i)adde(S,y[i],1);
			else if(q[i]==i)adde(x[i],T,1);
			else adde(x[i],y[i],1);
		}
	}
	cout << sum - max_flow() << endl;
}


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

int main() {
  int counta=0,countb=0;
  int N,M,ask;
  cin>>N>>M;
  vector<pair<int,int>>seitou(N);
  vector<pair<int,string>>PS(M);
  rep(i,M){
    cin>>PS[i].first;
    cin>>PS[i].second;
  }
  rep(i,N){
    seitou[i].first=0;
    seitou[i].second=0;
  }
  rep(i,M){
    if(PS[i].second=="WA"){
      if(seitou[PS[i].first-1].second==0){
    seitou[PS[i].first-1].first++;
      }
    }
    else if(PS[i].second=="AC")
    seitou[PS[i].first-1].second++;
  }
  rep(i,N){
    if(seitou[i].second>0){
    counta+=seitou[i].first;
    }
    if(seitou[i].second>0){
      countb++;
    }
  }
  cout<<countb<<" "<<counta;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(2));
    for (int i = 0; i < n; i++)cin >> v[i][1] >> v[i][0];
    sort(v.begin(), v.end());
    int ret = 0;
    int finish = 0;
    for (int i = 0; i < n; i++) {
        if (v[i][1] > finish) {
            ret++;
            finish = v[i][0];
        }
    }
    cout << ret << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int N, M; cin >> N >> M;

	P lis[100005];

	for (int i = 0;i < M;i++){
		int a,b; cin >> a >> b;
		lis[i] = P(b,a);
	}

	sort(lis,lis+M);

	int now = -1;
	int ans = 0;

	for (int i = 0;i < M;i++){
		if(lis[i].second >= now){
			now = lis[i].first;
			ans++;
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 1024
#include<iostream>



using namespace std;


int main(){
  int N,T;
  int i;
  cin >> N;
  cin >> T;
  int* c;
  int* t;
  c = (int *)malloc(N * sizeof(int));
  t = (int *)malloc(N * sizeof(int));


  for (i = 1;i <=  N; i = i + 1){
    cin >> c[i];
    cin >> t[i];
  }

  int cost;
  cost = 1500;
  for (i = 1;i <= N; i = i + 1){

    if (t[i] <= T){
      if(c[i] < cost){
        cost = c[i];
      }
    }
  }

  if (cost == 1500){
    cout << "TLE" << "\n";
  }else{
    cout << cost << "\n";
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define W 0
#define G 1
#define B 2
void dfs();

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
  int v;
  color[u] = G;
  d[u] = ++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(color[v]==W){
      dfs_visit(v);
    }
  }
  color[u]=B;
  f[u]=++tt;
}

void dfs(){
  int u;
  for(u=0;u<n;u++)color[u]=W;
  tt=0;
  for(u=0;u<n;u++){
    if(color[u]==W)dfs_visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main(){
  int i,j,u,k,v;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();
 
  return 0;
}

Measured memory_bytes: 632
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  string s;std::cin >> s;ll n = s.size();
  re(l, n-1){
    if(s[l]==s[l+1]){
      std::cout << l+1 << " " << l+2  << '\n';
      return 0;
    }
  }
  re(l, n-2){
    if(s[l]==s[l+2]){
      std::cout << l+1 << " " << l+3 << '\n';
      return 0;
    }
  }
  std::cout << -1 << " " << -1  << '\n';
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e16)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }


#define MAX_E 2010
#define MAX_V 1010

ll d[MAX_V];
int V, E; //V頂点数,E辺数
int a[MAX_E], b[MAX_E];
ll c[MAX_E];

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

    cin >> V >> E;
    rep(i,E) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--; c[i] = -c[i];
    }

    rep(i,V) d[i] = INF;
    d[0] = 0;

    rep(loop,V-1){
        rep(i,E) {
            if(d[ a[i] ] != INF and d[ b[i] ] > d[ a[i] ] + c[i]) d[ b[i] ] = d[ a[i] ] + c[i];
        }
    }

    bool negative[MAX_V];
    
    rep(i,V) negative[i] = false;

    rep(loop,V) rep(i,E) {
        if(d[ a[i] ] == INF) continue;
        if(d[ b[i] ] > d[ a[i] ] + c[i]) {
            d[ b[i] ] = d[ a[i] ]+ c[i];
            negative[ b[i] ] = true;
        }
        if(negative[ a[i] ]) negative[ b[i] ] = true;
    }

    if(negative[V-1]) cout << "inf" << endl;
    else cout << -d[V-1] << endl;
    return 0;   
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
#include <math.h>
//#include <vector>
//#include <string>
//typedef long long LL;
using namespace std;
 
int main(){
    double a;
    double b;
    double x;
    double tmp;
    double tmp_value;
    double ans;
    double threshold_value;
    cin >> a >> b >> x;
    threshold_value = a*a*b/2.0;
    if(threshold_value<x){
        tmp_value = a*a*b - x;
        tmp = tmp_value/(a*a/2.0);
        ans = atan(a/tmp);
    }else{
        tmp_value = x;
        tmp = tmp_value/(a*b/2.0);
        ans = atan(tmp/b);
    }
    ans = ans/M_PI*180.0;
    ans = 90.0-ans;

    cout << setprecision(9) << ans << endl;
}

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

int main(){
    ll n,k;
    cin >> n >> k;
    if(k%2==0){
        ll a = n/k;
        ll b = 2*n/k-a;
        cout << a*a*a+b*b*b;
    }
    else{
        ll a = n/k;
        cout << a*a*a;
    }
}

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

//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }


//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;


//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())

//repetition
//------------------------------------------
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPinit(a,n) for(int i=a; i<n; i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
//clear memory
//#define CLR(a) memset((a), 0 ,sizeof(a))



int main()
{
	LL N;
	vector<LL> A;

	cin >> N;
	LL temp;
	LL max = 0;

	REP(N) {
		cin >> temp;
		A.push_back(temp);
		if (max < temp) {
			max = temp;
		}
	}

	// get 2nd greatest number
	vector<LL> B(A.size());
	std::copy(A.begin(), A.end(), B.begin());
	std::sort(B.begin(), B.end(), std::greater<LL>());

	LL max2 = 0;
	for (LL b : B)
	{
		if (b != max) {
			max2 = b;
			break;
		}
	}

	// get the greatest number and its index
	std::vector<LL>::iterator iter = std::max_element(A.begin(), A.end());
	int index = std::distance(A.begin(), iter);
	LL n_count = std::count(A.begin(), A.end(), max);
	
	if (n_count > 1) 
	{
		REP(N) {
			cout << max << endl;
		}
	}
	else {
		REP(N) {
			if (index == i) {
				cout << max2 << endl;
			}
			else
			{
				cout << max << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 4848
#include<bits/stdc++.h>
#define N 400005
using namespace std;
int n,m,x,y,to[N],fst[N],nxt[N],a,b,c,flag,vis[N],col[N],l;
void link(int x,int y)
{
	to[++l]=y;nxt[l]=fst[x];fst[x]=l;
	to[++l]=x;nxt[l]=fst[y];fst[y]=l;
}
void dfs(int x,int y)
{
	if (vis[x])
	{
		if (col[x]!=y) flag=1;
		return;
	}
	vis[x]=1;col[x]=y;
	for (int i=fst[x];i;i=nxt[i])
		dfs(to[i],y^1);
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		link(x,y);
	}
	for (int i=1;i<=n;i++)
	{
		if (!vis[i])
		{
			if (fst[i])
			{
				flag=0;
				dfs(i,0);
				if (flag) b++;else c++;
			}
			else a++;
		}
	}
	printf("%lld\n",2LL*a*n-1LL*a*a+1LL*b*b+2LL*c*c+2LL*b*c);
}

Measured memory_bytes: 8576
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
int A[5];
int main(){
    for(int i = 0; i < 5; i++) cin >> A[i];
    for(int i = 0; i < 5; i++) if(A[i]==0){
        cout << (i+1) << endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 3580
#include <stdio.h>
int main(){
  int N;
  long long int A[200000],B[200000];
  long long int S=0LL;
  scanf("%d",&N);
  for(int i=1;i<=N+1;i++) 
    scanf("%lld",A+i);
  for(int i=1;i<=N;i++) 
    scanf("%lld",B+i);
  B[0]=0;
  B[N+1]=0LL;
  long long int C=0;
  for(int i=1;i<=N+1;i++){
    S+=A[i]>B[i-1]?B[i-1]:A[i];
    A[i]=A[i]>B[i-1]?A[i]-B[i-1]:0;
    S+=A[i]>B[i]?B[i]:A[i];
    B[i]=A[i]>B[i]?0:B[i]-A[i];
  }
  printf("%lld\n",S);
  return 0;
}

Measured memory_bytes: 3308
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i=0; i<N; i++) cin >> A[i];

	vector<int> cnt(N+1);
	for(int i=0; i<N; i++) cnt[A[i]]++;

	ll total = 0;
	for(int i=0; i<=N; i++) total += (ll)cnt[i]*(cnt[i]-1)/2;

	for(int i=0; i<N; i++){
		ll x = cnt[A[i]];
		cout << total - x*(x-1)/2 + (x-1)*(x-2)/2 << endl;
	}

	return 0;
}


Measured memory_bytes: 4096
using namespace std;
#include <bits/stdc++.h>
#define frr(i, r, l) for(int i = r; i >= l; --i)
#define fr(i, l, r) for(int i = l; i < r; ++i)
#define forit(it, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
typedef pair<ll, ll> iPair; 
priority_queue< ll, vector <ll> , greater<ll>>pq1,pq2;
#define maxN 1000000000000000000
ll power(ll a,ll b){ll res=1;while(b>0){res*=a;b--;}return res;}
ll vs[200005]={0};
queue<ll>q;
vector<ll>v[200005];
ll bfs(ll a)
{
    q.push(a);
    vs[a]=1;
    ll cnt=0;

    while(!q.empty())
    {
        a=q.front();
        fr(i,0,v[a].size())
        {
            ll b=v[a][i];
            if(vs[b]==0)
            {
                q.push(b);
                vs[b]=1;
            }
        }
        q.pop();
        cnt++;
    }
    return cnt;
}
int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,x,y;
    cin>>n>>m;

    fr(i,0,m)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    ll ans=0;
    fr(i,1,n+1)
    {
        if(vs[i]==0)
        {
            ll c=bfs(i);
            ans=max(ans,c);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 18724
#include <stdio.h>

main()
{
	int l,r,d;
	int i;
	int count=0;
	
	scanf("%d",&l);
	scanf("%d",&r);
	scanf("%d",&d);
	
	for(i=l;i<=r;i++)
	{
		if(i%d==0)
		{
			++count;
		}
	}
	printf("%d",count);
}
	

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

int main() {
    int a, b;
    string s;
    cin >> a >> b >> s;
    // cout << a << " " << b << " " << s << endl;
    bool flag = true;
    int count = 0;
    for(int i=0; i<s.size(); i++){
        char c = s[i];
        if(c == '-'){
            // printf("count, a=%d, %d\n", count ,a);
            if(count != a) flag = false;
            count = 0;
        }else{
            count++;
        }
        // printf("%c\n", c);
    }
    if(count != b) flag = false;
    if(flag) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 256
import itertools
n=int(input())
A=[[] for i in range(n)]
for i in range(n):
  r=int(input())
  for j in range(r):
    A[i].append(list(map(int,input().split())))
ans=0
L=list(itertools.product([0,1],repeat=n))
for i in L:
  T=[]
  for num,j in enumerate(i):
    if j==1:
      for k in A[num]:
        T.append(k)
  if all(i[j[0]-1]==j[1] for j in T):
    ans=max(ans,sum(i))
print(ans)

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

signed main() {
	int n = in();
	int hist[8] = {};
	int sp = 0;
	REP(i, n) {
		int a = in();
		if (a < 3200)++hist[a / 400];
		else ++sp;
	}
	int cnt = 0;
	REP(i, 8) {
		if (hist[i] != 0)++cnt;
	}
	if (cnt != 0)cout << cnt << ' ' << cnt + sp << endl;
	else cout << 1 << ' ' << sp << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{

    int r,d,x,m;
    cin>>r>>d>>x;
     m=r*x-d;
     cout<<m<<"\n";
    for(int i =0; i<9 ;i++)
    {
        m=m*r-d;
        cout<<m<<"\n";




    }










}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Lesson8C 与えられた英文に含まれる、各アルファベットの数を数えるプログラム なお、小文字と大文字は区別しない
 *
 * @author Internship
 *
 */
public class Main{

	/**
	 * プログラムのエントリポイント
	 *
	 * @param args
	 */
	public static void main(String[] args) {

		// a ~ｚのパターン
		char[] chaAZ = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
				'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
				'x', 'y', 'z' };

		// a?zのパターンが各何回あるかカウントする場所
		int[] intAZ = new int[26];

		// 各行読み込む
		try {
			BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));

			String strLine = "";

			while (true) {
				strLine = insBR.readLine();

				//終了条件
				if(strLine == null) {
					break;
				}

				// 大文字は小文字にしておく
				strLine = strLine.toLowerCase();

				// char型に分解
				char[] chaAryLine = strLine.toCharArray();

				// 各a?z何回あるかカウント
				for (int i = 0; i < chaAryLine.length; i++) {
					for (int j = 0; j < intAZ.length; j++) {
						if (chaAryLine[i] == chaAZ[j]) {
							intAZ[j]++;
						}
					}
				}
			}

			// 出力
			for (int i = 0; i < intAZ.length; i++) {
				System.out.println(chaAZ[i] + " : " + intAZ[i]);
			}

		} catch (IOException e) {
			System.out.println(e);
		}

	}
}

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



int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    string s; cin >> s;
    int max_len = 0;
    for (int i = 0; i < s.length(); i++) {
        int len = 0;
        for (int j = i; j < s.length(); j++) {
            if (s[j] == 'A' || s[j] == 'T' || s[j] == 'G' || s[j] == 'C') {
                len++;
            } else break;
        }
        max_len = max(max_len, len);
    }
    
    cout << max_len << '\n';
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <time.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 5020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

struct sum2D{
	vector<vector<ll>> sum;
	ll n,m;
	
	sum2D(vector<vector<ll>> &a){
		n = a.size();
		m = a[0].size();
		sum.resize(n+1);
		rep(i,n+1) sum[i].resize(m+1,0);
		rep(i,n) rep(j,m) sum[i+1][j+1] = a[i][j];
		rep(i,n) rep(j,m+1) sum[i+1][j] += sum[i][j];
		rep(j,m) rep(i,n+1) sum[i][j+1] += sum[i][j];
	}

	ll get(int y1, int x1, int y2, int x2){
		y2++; x2++;
		return sum[y2][x2] - sum[y2][x1] - sum[y1][x2] + sum[y1][x1];
	}
};

vvl cnt(20,vl(20,0));

int main(){
	ll n; cin >> n;
	vd a(n); rep(i,n) cin >> a[i];
	vl b(n);
	vpl v(n);
	rep(i,n){
		a[i] *= 1000000000;
		b[i] = (ll)(a[i] + 0.1);
		int two = 0, five = 0;
		while(b[i] % 2 == 0) two++, b[i] /= 2;
		while(b[i] % 5 == 0) five++, b[i] /= 5;
		chmin(two,18); chmin(five,18);
		v[i] = {two,five};
		cnt[two][five]++;
	}
	sum2D sum(cnt);
	ll ans = 0;
	ll as2 = 0;
	rep(i,n){
		//print2(v[i].first, v[i].second);
		ans += sum.get(18-v[i].first, 18-v[i].second, 19, 19);
		if(v[i].first >= 9 && v[i].second >= 9) ans--, as2--;
		REP(j,18-v[i].first,19){
			REP(k,18-v[i].second,19) as2 += cnt[j][k];
		}
	}
	ans /= 2;
	as2 /= 2;
	//if(ans != as2) puts("NO");
	cout << as2 << "\n";
}

Measured memory_bytes: 9512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int n,k;cin>>n>>k;
  string s,t;cin>>s;
  t = s;
  reverse(t.begin(),t.end());
  REP(i,min(k,15)){
    s = t;
    reverse(s.begin(),s.end());
    string u = s+t;
    vector<string> v;
    REP(j,s.size()){
      v.pb(u.substr(j,s.size()));
    }
    VSORT(v);
    t = v[0];
  }
  cout<<t<<endl;


 

  return 0;
}

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

int main() {
int M1,D1,M2,D2;
cin >> M1 >> D1 >> M2 >> D2;

 if( M2-M1==1 && D1*D2 == D1 ){
 	cout << 1 << endl;
 }
 
 else{
 	cout << 0 << endl;
 }
  
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

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

    int N;
    cin >> N;
    
    int ans = 0;
    for (int i = N; i >= 1; i--) {
        int count = 0;
        if (i % 2 == 0) {
            continue;
        }
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) {
                count++;
            }
        }
        if (count == 8) {
            ans++;
        }
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  int count=0,max=-1,si=s.size();
  bool fg=false;
  rep(i,si){
    if(!fg){
      if(s[i]=='A'){
        count++;
        fg=true;
      }
    }
    else{
      count++;
      if(s[i]=='Z'){
        chmax(max,count);
      }
    }
  }
  cout<<max<<'\n';
  return(0);
}


Measured memory_bytes: 720
(n, m), *e = [[*map(int, t.split())] for t in open(0)]
q = [1]
ans = [0] * -~n
node = [[] for _ in range(-~n)]
temp = set()

for i, j in e:
    node[i].append(j)
    node[j].append(i)

while q:
    for x in q:
        for y in node[x]:
            if ans[y] == 0:
                ans[y] = x
                temp.add(y)
    q = list(temp)
    temp.clear()

if 0 in ans[2:]:
    print('No')
else:
    print('Yes', *ans[2:])


Measured memory_bytes: 61176
a = int(input())

def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False

def sieve(n):
    s = [True] * n
    for x in range(2, int(n**0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in range(0,n) if s[i] and i >= a]

s = sieve(a * 2)
print(s[0])

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

int main(void)
{
    int A, B, C, X, cnt = 0;

    cin >> A >> B >> C >> X;

    for(int i = 0; i <= A; i++)
    {
        for(int j = 0; j <= B; j++)
        {
            for(int k = 0; k <= C; k++)
            {
                if(500 * i + 100 * j + 50 * k == X) cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

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

struct W{
    string word;
    priority_queue<int> pq;
    bool operator < (const W& o) const {
        return word < o.word;
    }
};

W genW(string w, int p){
    W new_word;
    new_word.word = w;
    new_word.pq.push( -p );
    return new_word;
}

int main(){
    string w; int p;
    vector< W > ls;
    vector< W >::iterator it;
    while( cin >> w >> p ){
        it = ls.begin();
        for(; it != ls.end(); it++){
            if( it->word == w ){
                it->pq.push( -p );
                break;
            }
        }
        if( it == ls.end() ){
            ls.push_back( genW(w, p) );
        }
    }
    sort(ls.begin(), ls.end());
    for(it = ls.begin(); it!=ls.end(); it++){
        cout << it->word << endl;
        cout << -( it->pq.top() );
        it->pq.pop();
        while( !it->pq.empty() ){
            cout << ' ' << -( it->pq.top() );
            it->pq.pop();
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1252
#include<iostream>
using namespace std;
int main(){
    int x,y;
    while (true){
        cin>>x>>y;
        if(x==0 && y==0){
            break;
            
        }
        else if (x<=y){
            cout<<x<<" "<<y<<endl;
        }else{
            cout<<y<<" "<<x<<endl;
        }
    }
        return 0;
}


Measured memory_bytes: 3068
# 全計算量 O(n * log(n))

class Heap
  def initialize(cs, &block)
    @que = []
    @size = 0
    @cs = cs
    @ds = []
    @cmp = block || lambda{ |a,b| a < b }
  end

  def top
    @que[0]
  end

  # O(log(n))
  def push(x)
    i = @size
    while i > 0 do
      j = (i - 1) / 2
      break unless @cmp.call(x, @que[j])
      @que[i] = @que[j]
      i = j
    end
    @que[i] = x
    @size += 1
    @ds[x] = @cs[x]
  end

  # O(log(n))
  def trim1(n)
    x = @que[0]
    m = [n, @ds[x]].min

    return m if ((@ds[x] -= m) > 0)

    @ds[x] = @cs[x]
    @update.call(x)
    i = 0
    while (ii = i * 2 + 1) < @size do
      j1 = ii
      j2 = ii + 1
      j1 = j2 if j2 < @size && @cmp.call(@que[j2], @que[j1])
      break unless @cmp.call(@que[j1], x)
      @que[i] = @que[j1]
      i = j1
    end
    @que[i] = x
    m
  end

  # O(n * log(n))
  def trim(n, &block)
    @update = block
    n -= trim1(n) while (n > 0)
  end
end

n, k = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
fs = gets.split.map(&:to_i)
 
l = as.inject(:+) - k

if (l <= 0)
  p 0
  exit
end

# O(n * log(n))
as.sort!
fs.sort_by! {|f| -f}

max_f = fs[0]

# O(n * log(n))
afs = as.zip(fs).sort_by do |a,f| a*f end

h = l * max_f * max_f
a_acc = 0
r_acc = 0

# O(n)
fs = afs.map do |a,f| f end
a_sums = afs.map do |a,f| a_acc += a end
rs = (n-1).downto(0).map do |i| r_acc += h / fs[i] end

t = nil
lm = 0

# O(log(n))
m = (0...n).bsearch do |i|
  next true if (i == n - 1)

  a_i, f_i = afs[i]
  af = a_i * f_i

  nn = n - i - 1
  ub = a_sums[i] + af * (rs[nn-1] + nn) / h
  lb = ub - nn

  next true if (lb >= l)

  if (ub < l)
    lm = i + 1
  else
    t = af
  end
  false
end

# O(n)
if (t)
  s = a_sums[m-1]
  (m...n).each do |i| s += t / fs[i] end
  t = nil if (s < l)
end

unless (t)
  nn = n - m
  ll = (m == 0) ? l: l - a_sums[m-1]
  t = [(ll + nn) * h / rs[nn-1], afs[m][0] * afs[m][1]].min
end

# O(n)
if (lm > 0)
  l -= a_sums[lm-1]
  n -= lm
  m -= lm
  fs = fs.drop(lm)
  afs = afs.drop(lm)
end

gs = []
# O(n)
(0...m).each do |i|
  a,f = afs[i]
  l -= a
  gs.push(a*f)
end
# O(n)
(m...n).each do |i|
  f = fs[i]
  a = t / f
  l -= a
  gs.push(a*f)
end

l = -l

raise unless (l >= 0 && l <= n)

if (l == 0)
  p gs.max
else
  # O(n * log(n))
  is = (0...m).to_a + (m...n).sort_by do |i| fs[i] end

  cs = []
  q = Heap.new(cs) do |i,j| gs[i] > gs[j] end

  i0 = is.shift
  cs[i0], prev_i, prev = 1, i0, [gs[i0], fs[i0]]

  # O(n * log(n))
  is.each do |i|
    cur = [gs[i], fs[i]]
    if (cur == prev)
      cs[prev_i] += 1
    else
      q.push(prev_i)
      cs[i], prev_i, prev = 1, i, cur
    end
  end
  q.push(prev_i)

  # O(n * log(n))
  q.trim(l) do |i| gs[i] -= fs[i] end
  p gs[q.top]
end

Measured memory_bytes: 64964
n = int(input())
dic = {0:'a',1:'b',2:'c',3:'d',4:'e',5:'f',6:'g',7:'h',8:'i',9:'j'}
ans = [["a",1]]
for i in range(1,n):
    tmp=[]
    for prev,val in ans:
        for j in range(val+1):
            tmp.append([prev+dic[j],val]) if j!=val else tmp.append([prev+dic[j],val+1])
    ans=tmp
ans=sorted(ans,key=lambda x:x[0])
for i in range(len(ans)):
    print(ans[i][0])

Measured memory_bytes: 25716
package main
import "fmt"
var n int
var A []int
func min(a, b int) int {
	if a < b { return a }
	return b
}
func abs(a int) int {
	if a < 0 { return -a }
	return a
}
func main() {
	_,e := fmt.Scanf("%d", &n)
	if e!= nil { return }
	if n<=1 {
		fmt.Println(0)
		return
	}
	A = make([]int, n+1)
	for i:=1; i<=n; i++ {
		_,e := fmt.Scanf("%d", &A[i])
		if e != nil { return }
	}
	if n == 2 {
		fmt.Println(abs(A[2]-A[1]))
		return
	}
	dp := make([]int, n+1)
	dp[1] = 0
	dp[2] = abs(A[2]-A[1])
	for i:=3; i<=n; i++ {
		dp[i] = min(dp[i-1] + abs(A[i] - A[i-1]), dp[i-2]+abs(A[i] - A[i-2]))
	}
	fmt.Println(dp[n])
}


Measured memory_bytes: 6320
#define ENABLE_DEBUG 0
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#if ENABLE_DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                \
  do {                            \
    cerr << " \033[33m (L";       \
    cerr << __LINE__ << ") ";     \
    cerr << #__VA_ARGS__ << ": "; \
    cerr << "\033[0m";            \
    debug(__VA_ARGS__);           \
    cerr << endl;                 \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, escaper, chaser;
  cin >> N >> escaper >> chaser;
  escaper--;
  chaser--;
  vector<vector<int>> adj(N);
  REP(i, N - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  DEBUG("input ok");
  vector<int> depth(N, -1), parent(N, -1);
  depth[chaser] = 0;
  deque<tuple<int, int>> q;
  q.emplace_back(chaser, 0);
  while (q.size()) {
    auto [node, d] = q.front();
    q.pop_front();
    for (int x : adj[node]) {
      if (depth[x] != -1) continue;
      depth[x] = d + 1;
      parent[x] = node;
      q.emplace_back(x, d + 1);
    }
  }
  DEBUG("bfs ok");

  vector<int> maxdepth(N, -1);
  auto dfs = [&](auto rec, int i) -> int {
    if (maxdepth[i] != -1) return maxdepth[i];
    int md = depth[i];
    for (int x : adj[i]) {
      if (depth[x] > depth[i]) {
        int d = rec(rec, x);
        md = max(md, d);
      }
    }
    maxdepth[i] = md;
    return md;
  };
  const int height = dfs(dfs, chaser);
  DEBUG("dfs ok", height);

  vector<int> path;
  path.reserve(height);
  for (int i = escaper; i != chaser; i = parent[i]) {
    path.push_back(i);
  }
  path.push_back(chaser);

  int steps = 0;
  int e = escaper, c = chaser;
  REP(i, path.size()) {
    e = path[i], c = path[path.size() - 1 - i];
    if (depth[e] - 1 <= depth[c] + 1) break;
    steps++;
  }
  int dist = depth[e] - depth[c];
  assert(dist == 1 || dist == 2);
  steps += maxdepth[e] - depth[e];
  if (dist == 2) {
    steps++;
  }

  cout << steps << endl;
}


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

int main() {
  int N;
  cin >> N;
  string s;
  rep(i, N) {
    cin >> s;
    if (s == "Y") {
      cout << "Four" << endl;
      break;
    }
    if (i == N - 1) {
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	string S;
	cin >> S;
	bool flag = true;
	if (S[a] != '-')flag = false;
	int cnt = 0;
	for (int i = 0; i < S.size(); i++) {
		for (char c = '0'; c <= '9'; c++) {
			if (S[i] == c)cnt++;
		}
	}
	if (cnt != a + b)flag = false;
	if (flag)cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,a[MAXN],fac[MAXN],invfac[MAXN];
int pos[MAXN],p;
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
int fpow(int x,int c) {
    int t = x,res = 1;
    while(c) {
	if(c & 1) res = mul(res,t);
	t = mul(t,t);
	c >>= 1;
    }
    return res;
}
int C(int n,int m) {
    if(n < m) return 0;
    return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
void Solve() {
    read(N);
    for(int i = 1 ; i <= N + 1; ++i) read(a[i]);
    for(int i = 1 ; i <= N + 1; ++i) {
	if(pos[a[i]]) p = i;
	else pos[a[i]] = i;
    }
    fac[0] = 1;
    for(int i = 1 ; i <= N + 1 ; ++i) {
	fac[i] = mul(fac[i - 1],i);
    }
    invfac[N + 1] = fpow(fac[N + 1],MOD - 2);
    for(int i = N ; i >= 0 ; --i) {
	invfac[i] = mul(invfac[i + 1],i + 1);
    }
    for(int i = 1 ; i <= N + 1 ; ++i) {
	int res = C(N + 1,i);
	res = inc(res,MOD - C(pos[a[p]] - 1 + N + 1 - p,i - 1));
	out(res);enter;
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 2816
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

int of(ll a,ll b)
{
	if((a*b)/b!=a)
	return 1;
	return 0;
}

int main()
{ios_base::sync_with_stdio(false);
ll a=1,b=1;
int t;
gl(t);
while(t--)
{
	ll x,y;
	cin>>x>>y;
	ll c,d,lo=1,hi=1e18+7,mid;
	while(lo<hi)
	{
		mid=(lo+hi)/2;
		if(of(mid,x)||of(mid,y))
		hi=mid;
		else if(mid*x>=a&&mid*y>=b)
		hi=mid,c=mid*x,d=mid*y;
		else lo=mid+1;
	}
	a=c;b=d;
}
ol(a+b);
return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n)
	fmt.Scan(&k)
	h := make([]int, n)
	res := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
		if h[i] >= k {
			res++
		}
	}
	fmt.Println(res)

}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<string>> S(H, vector<string>(W));
    for(int i=0;i<H;i++)
        for(int j=0;j<W;j++)
            cin >> S[i][j];
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S[i][j] == "snuke"){
                cout << char('A' + j) << i + 1 << endl;
                return 0;
            }
        }
    }

}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<ll,int> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

ll n;

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

	cin>>n;
	ll cnt=1,m=1;
	while(m*2<=n) m*=2,cnt++;
	cout<<(m*2-1==n?cnt:cnt-1)<<endl;

	return 0;
}



Measured memory_bytes: 3156
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
String A=sc.next();
String B=sc.next();
if(A.length()>B.length()){
    out.println("GREATER");
}else if(A.length()<B.length()){
    out.println("LESS");
}else{
int n=A.length();
int[] a=new int[n];
int[] b=new int[n];
    for (int i = 0; i < n; i++) {
        a[i]=Integer.parseInt(Character.toString(A.charAt(i)));
        b[i]=Integer.parseInt(Character.toString(B.charAt(i)));
    }
int c=0;
    for (int i = 0; i < n; i++) {
        c=a[i]-b[i];
        if(c>0){
            out.println("GREATER");
        break;
        }else if(c<0){
            out.println("LESS");
        break;
        }
    }
    if(c==0)out.println("EQUAL");
}
}
}

Measured memory_bytes: 21972
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

bool check(string s) {
	for (int i = 0; i < s.size() - 1; i++) {
		if (s[i] != s[i + 1])return false;
	}
	return true;
}
int main() {
	string s;
	cin >> s;

	int ans = 1e5;
	for (int i = 0; i < 26; i++) {
		string sa = s;
		int t = 0;
		while (check(sa)==false) {
			string sb;
			for (int j = 0; j < sa.size() - 1; j++) {
				char n = 'a' + i;
				if (sa[j] == n || sa[j + 1] == n)sb.push_back(n);
				else sb.push_back(sa[j]);
			}
			sa = sb;
			t++;
		}
		ans = min(ans, t);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256