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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int N;
int p[300010];

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

  cin>>N;
  rep(i,N){
    cin>>p[i];
    p[i]--;
  }

  bool ok=true;
  for(ll i=0;i<N;){
    if(p[i]==i){
      i++;
      continue;
    }
    ll j=i;
    bool same=false;
    vector<int> tot;
    for(j=i;j<N&&(p[j]==j)==same;j++){
      tot.push_back(p[j]);
      same=!same;
    }
    if(j<N&&!same){
      j--; tot.pop_back();
    }
    sort(all(tot));
    bool okk=true;
    repl(k,i,j)if(tot[k-i]!=k)okk=false;
    if(!okk){
      ok=false; break;
    }
    // [i,j)
    int preinc=-1,predec=-1;
    for(ll k=i;k<j;k+=2){
      if(p[k]==k){
        ok=false; break;
      }
      if(p[k]>k){
        if(preinc>p[k]){
          ok=false; break;
        }
        preinc=p[k];
      }else if(p[k]<k){
        if(predec>p[k]){
          ok=false; break;
        }
        predec=p[k];
      }
    }
    if(!ok)break;
    i=j;
  }

  if(ok)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 200000 + 1000;
const long long INF = 0x1f1f1f1f1f1f1f1fll;

struct SegmentTree
{
	int N;
	long long s[4 * MAXN];
	void init(int n)
	{
		for(N = 1; N < (n + 2); N <<= 1);
		for(int i = 0; i <= N - 1; i++) s[i + N] = 0;
		for(int i = 0; i <= N - 1; i++) s[i] = 0;
	}
	void update(int p)
	{
		s[p] = min(s[p << 1], s[(p << 1) | 1]);
	}
	void modify(int p, long long v)
	{
		p += N;
		s[p] = v;
		for(p >>= 1; p; p >>= 1)
			update(p);
	}
	long long query(int l, int r)
	{
		long long ret = INF;
		for(l += N - 1, r += N + 1; (l ^ r) != 1; l >>= 1, r >>= 1)
		{
			if(~l & 1) ret = min(ret, s[l ^ 1]);
			if(r & 1) ret = min(ret, s[r ^ 1]);
		}
		return ret;
	} 
}
tl, tr;

int n, m;
int x[MAXN];
long long f[MAXN], all = 0;

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	int a, b;
	cin >> n >> m;
	cin >> a >> b;
	x[0] = a;
	for(int i = 1; i <= m; i++)
		cin >> x[i];

	tl.init(n), tr.init(n);
	for(int i = 1; i <= n; i++)
		f[i] = abs(b - i);
	for(int i = 1; i <= n; i++)
		tl.modify(i, f[i] - i), tr.modify(i, f[i] + i);
	for(int i = 1; i <= m; i++)
	{
		all += abs(x[i] - x[i - 1]);
		long long tmp = min(tl.query(1, x[i]) + x[i], tr.query(x[i], n) - x[i]);
		f[x[i - 1]] = min(f[x[i - 1]], tmp - abs(x[i] - x[i - 1]));
		tl.modify(x[i - 1], f[x[i - 1]] - x[i - 1]);
		tr.modify(x[i - 1], f[x[i - 1]] + x[i - 1]);
	}
	long long ans = INF;
	for(int i = 1; i <= n; i++)
		ans = min(ans, f[i] + all);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 14592
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

std::deque<char> s;
int direction;
char temp[100010];
int szTemp;

int q;
int comm;

int main()
{
	scanf("%s", temp);
	szTemp = strlen(temp);
	
	for (int i = 0 ; i < szTemp ; i++) {
		s.push_back(temp[i]);
	}
	
	direction = 1;
		
	scanf("%d", &q);
	for (int i = 0 ; i < q ; i++) {
		scanf("%d", &comm);
		if (comm == 1) {
			direction = -direction;
		} else {
			int d;
			char c;
			scanf("%d %c", &d, &c);
			
			if (direction == 1) {
				if (d == 1)
					s.push_front(c);
				else
					s.push_back(c);
			} else {
				if (d == 1)
					s.push_back(c);
				else
					s.push_front(c);
			}
		}
	}
	
	if (direction == 1) {
		std::deque<char>::iterator iS;
		for (iS = s.begin() ; iS != s.end() ; iS++) {
			printf("%c", *iS);
		}
	} else {
		std::deque<char>::reverse_iterator iS;
		for (iS = s.rbegin() ; iS != s.rend() ; iS++) {
			printf("%c", *iS);
		}
		
	}
	printf("\n");
	
			
	return 0;
}


Measured memory_bytes: 896
import sys
import math
import itertools
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

X,Y = I()
for i in range(X+1):
    if i*2+(X-i)*4 == Y:
        print('Yes')
        exit()
print('No')

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

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

int N;
int A;

int main() {
  scanf("%d", &N);

  int minval = numeric_limits<int>::max();
  REP(i,N) {
    scanf("%d", &A);
    int count = 0;
    while (A % 2 == 0) {
      ++count;
      A /= 2;
    }
    if (count < minval) minval = count;
  }

  printf("%d\n", minval);
  return 0;
}

Measured memory_bytes: 256
import CoreFoundation
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}
let n = arr[0]
let k = arr[1]

let a=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

var twoa : [Int] = []

var i = 0
var j = 0

var o = 0
var tno = 0

for i in 0..<n {
  for j in 0..<n {
    if( a[i] > a[j] ){
      o += 1
    }
  }
}

for i in 0..<n {
  //var tmp = a[i%(n)]
  for j in i+1..<n{
    if( a[i] > a[j] ){
      tno += 1
    }
  }
}

var limit : Int = Int( pow( Double(10), Double(9) ) ) + 7

//var test : Int = 998244353 * 998244352 / 2 
//test = test * tno
//print( test, tno )
let K = (k * (k-1) / 2) % limit
var ans = 0
ans += (o%limit * K) % limit + (tno%limit * k) % limit
var zensya = ( ( o % limit ) * k )
var kousya = ( ( ( k * ( k - 1 ) ) / 2 ) ) % limit
kousya = kousya * tno
print( ans % limit )
//print( ( zensya + kousya ) % limit )

Measured memory_bytes: 4204
#include <iostream>
using namespace std;
int calc(int x) {
	int ret = 0;
	while(x % 100 == 0) {
		x /= 100;
		++ret;
	}
	return ret;
}
int main() {
	int D, N;
	cin >> D >> N;
	int cnt = 0, val = 0;
	while(cnt < N) {
		++val;
		if(calc(val) == D) ++cnt;
	}
	cout << val << '\n';
	return 0;
}




Measured memory_bytes: 256
M, K = map(int, input().split())
if M == 1 and K == 0:
    print("0 0 1 1")
elif M == 1 and K == 1:
    print(-1)
elif K >= 2 ** M:
    print(-1)
else:
    ans = []
    for i in range(2 ** M):
        if i != K:
            ans.append(i)
    ans.append(K)
    for i in range(2 ** M - 1, -1, -1):
        if i!= K:
            ans.append(i)
    ans.append(K)
    print(" ".join(map(str, ans)))

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

#define ll long long
#define endl "\n";
#define mod 1000000007
#define pii pair<int,int>
#define vii vector<pii>
#define mp make_pair
#define all(a) a.begin(), a.end()
#define mk(arr,n,type) type *arr=new type[n];

void fastio() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int main() {
    fastio();
    string s;
    cin >> s;

    if (s=="ABC") cout << "ARC";
    else cout << "ABC";

    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;

const bool DEBUG = 0;
const int MAXN = 100005;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	ll a,b,c,d; cin>>a>>b>>c>>d;
	ll ans=-INF;
	amax(ans,a*c);
	amax(ans,b*d);
	amax(ans,a*d);
	amax(ans,b*c);
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
/*
bool cmp(pair<int,int> a,pair<int,int> b){
    if(a.second!=b.second){
        return a.second>b.second;
    }
    else{
        return a.first > b.first;
    }
}*/

int main(){
    int n,m;
    cin >> n >> m;
    priority_queue <int> q;
    vector<vector<int> > in(100000);
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        in[a].push_back(b);
    }
    long long ans = 0;
    
    for(int i=1;i<=m;i++){
        //cout << now <<endl;
        for(int j=0;j<in[i].size();j++){
            q.push(in[i][j]);
        }
        if(!q.empty()){
            ans += q.top();
            q.pop();
        }
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
ll bg = 20000001;
#define ff(i,n) for(i=0;i<n;i++) 
void dfs(ll i,ll vis[],ll p[],vector<vector<ll> > &adj,ll par)
{
	vis[i] = 1;
	p[i] = par;
	ll j;
	for(j=0;j<adj[i].size();j++)
	{
		if(vis[adj[i][j]]==0)
		{
			dfs(adj[i][j],vis,p,adj,i);
		}
	}
}
ll dp[140000][26];
string s;
ll fun(ll l,ll r,ll alpha)
{
	ll mid = (l+r)/2;
	if(l==r)
	{
		if((s[l-1]-'a')!=alpha)
		   return 1;
		else
		   return 0;   
	}
	ll l1 = ((r-mid)-(dp[r][alpha]-dp[mid][alpha])) + fun(l,mid,alpha+1);
	ll l2 = ((mid-l+1)-(dp[mid][alpha]-dp[l-1][alpha])) + fun(mid+1,r,alpha+1);
	ll l3 = min(l1,l2);
	return l3;
}
int main()
{
	ll test,t;
	t=1;
	for(test=1;test<=t;test++)
	{
		ll i,n,a=0;
		ll x,y,z;
		cin>>n;
		ll f = sqrt(n)+1;
		ll dp[n+1] = {0};
		for(x=1;x<=f;x++)     
		    for(y=1;y<=f;y++)
		        for(z=1;z<=f;z++)
		        	{
		        		ll ans = (x*x + y*y + z*z + x*y + y*z + x*z);
		        		if(ans<=n)
						  dp[ans]++;	
					}
		for(i=1;i<=n;i++)
		    cout<<dp[i]<<endl;			
	}
	return 0;
} 

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <functional>
#include <sstream>
#include <bitset>

using namespace std;

typedef long long ll;
const ll MinInF = -1e18;
ll dp[41][2];

int nth_bit(ll num, int n) {
  return (num >> n) & 1;
}

void chmax(ll& a, ll b) {
  a = max(a,b);
}

int main() {
  int N;
  ll K;
  cin>>N>>K;
  vector<ll> A(N,0);
  for (int i = 0; i < N; i++) cin>>A[i];
  for (int i = 0; i <= 40; i++) {
    for (int j = 0; j < 2; j++) {
      dp[i][j] = MinInF;
    }
  }
  dp[40][0] = 0;
  for (int i = 39; i >= 0; i--) {
    ll D = 1LL<<i;
    int num1 = 0;
    for (int j = 0; j < N; j++) if (nth_bit(A[j],i)) num1++;
    int num0 = N -num1;
    if (nth_bit(K,i)) {
      chmax(dp[i][0],dp[i+1][0]+D*num0);
      chmax(dp[i][1],dp[i+1][0]+D*num1);
    } else {
      chmax(dp[i][0],dp[i+1][0]+D*num1);
    }
    chmax(dp[i][1],dp[i+1][1]+D*max(num0,num1));
  }
  ll ans = max(dp[0][0],dp[0][1]);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
///*
#include<iostream>
using namespace std;

int main() {

	int a, b;

	cin >> a >> b;
	a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 ? cout << "Possible" : cout << "Impossible";

	return 0;
}

//*/

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

using namespace std;

int main()
{
	
	int a, b;
	cin >> a >> b;
	if (a > b)
		cout << "a > b"<<endl;
	else
	{
		if ((a == b))
			cout << "a == b" << endl;
		else
			cout << "a < b" << endl;
	}
    return 0;
}




Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const int inf=1e9;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
char gc() {
    char ch=getchar();
    while(ch!='W'&&ch!='B') ch=getchar();
    return ch;
}
struct edge { int to,nxt; } e[N<<1];
int h[N];
void adde(int u,int v) {
    static int tot=1;
    e[++tot]=(edge){v,h[u]};h[u]=tot;
    e[++tot]=(edge){u,h[v]};h[v]=tot;
}
int n,rt=0,tot=0,du[N],col[N],val[N],ans=0,d=0,dp1[N],dp2[N];
bool ban[N];
void dfs(int u,int fa) {
    ban[u]=col[u];
    for(int i=h[u];i;i=e[i].nxt) {
        int v=e[i].to; if(v==fa) continue;
        dfs(v,u); ban[u]&=ban[v];
        if(!ban[v]) du[u]++,du[v]++;
    }
}
void dp(int u,int fa) {
    tot+=du[u];
    if((col[u]+du[u])&1) val[u]=0;
    else val[u]=2,tot++;
    int mx1=0,mx2=0;bool flag=0;
    for(int i=h[u];i;i=e[i].nxt) {
        int v=e[i].to; if(v==fa||ban[v]) continue;
        flag=1; dp(v,u);
        d=max(d,max(mx1+val[u]+dp2[v],mx2+val[u]+dp1[v]));
        mx1=max(mx1,dp1[v]);mx2=max(mx2,dp2[v]);
    }
    dp1[u]=mx1+val[u];dp2[u]=flag?mx2+val[u]:-inf;
}
int main() {
    cin>>n;
    for(int i=1,u,v;i<n;i++) u=gi(),v=gi(),adde(u,v);
    for(int i=1;i<=n;i++) col[i]=gc()=='B';
    for(int i=1;i<=n;i++) if(!col[i]) rt=i;
    if(!rt) return puts("0"),0;
    dfs(rt,0);dp(rt,0);
    printf("%d\n",tot-d);
    return 0;
}
//orzgzy
//鸡贼明年进队超稳


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

int main() {
    long long n;
    cin >> n;
    string s=to_string(n);
    string ss=s.substr(0,1);
    int a=s.size();
    int com1=0;
    com1+=stoi(ss)-1;
    com1+=9*(a-1);
    int com2=0;
    while(n>0){
        com2+=n%10;
        n/=10;
    }
    cout << max(com1,com2) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#define ll long long
#define max(a,b) (a>b?a:b)
#define maxn 100050
#define min(a,b) (a<b?a:b)
using namespace std;
ll dp[maxn];
int main(){
	int n,W;
	scanf("%d%d",&n,&W);
	for (int j=1;j<=1e5;j++)
	dp[j]=1e12;
	for (int i=1;i<=n;i++){
		int a,b;
		scanf("%d%d",&a,&b); 
		for (int j=1e5;j>=b;j--)
		dp[j]=min(dp[j-b]+a,dp[j]);
	}
	for (int i=1e5;i>=0;i--)
	if (dp[i]<=W) return printf("%d\n",i),0;
	return 0;
}
/*
dp[i][j]表示前i个价值和为j的最小重量 
*/

Measured memory_bytes: 896
#include<iostream>
#include<cstring>
using namespace std;
#define LL long long
char str[15];
LL ans;
void dfs(LL sum,LL now,LL len){
	if(now==len){
		ans+=sum;
		return;
	}
	for(LL i=now;i<len;++i){
		LL tmp=0;
		for(LL j=now;j<=i;++j)
			tmp=tmp*10+(str[j]-'0');
		dfs(sum+tmp,i+1,len);
	}
	return;
}
int main(){
	cin>>str;
	int len=strlen(str);
	dfs(0,0,len);
	cout<<ans;
	return 0;
}

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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

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

using namespace std;

ll n,x,y;

void w(vector<vector<ll>> &g, vector<ll> &c, ll n){
    for (ll i = 0; i < n; i++) {    // 始点
        for (ll j = i + 1; j < n; j++) {  // 終点
            int temp = min(j - i, abs(i - x) + abs(j - y) + 1);
            c[temp]++;  
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> x >> y;
    vector<vector<ll>> g(n,vector<ll>(n,INF));

    REP(i,n-1){
        g[i][i+1] = 1;
        g[i+1][i] = 1;
    }
    g[x-1][y-1] = 1;
    g[y-1][x-1] = 1;
    x--,y--;

    vector<ll> c(n,0);
    w(g,c,n);

    for(int i = 1;i < n;i++)cout << c[i] << endl;

    return 0;
}

Measured memory_bytes: 31616
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
//datatypes
	#define ll 			long long
	#define vi 			vector<int>
	#define vll 		vector<ll>
	#define si 			set<int>
	#define vii 		vector<ii>
	#define ii 			pair<int,int>
	#define vpll		vector<pll>
	#define pii 		pair<int,int>
	#define pll 		pair<ll, ll>
	#define mii 		map<int,int>
	#define ord_set		tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
	#define M 			1000000007
	#define narak 		998244353
	#define pi 			acos(-1)
	#define inf 		2147483647
	#define infl 		9223372036854775807
	#define infd 		1.7e308
	#define invd 		1.7e-308
	#define sz(x) 		(ll)x.size()
	#define fr 			first
	#define sc 			second
	#define pb 			push_back
	#define mkp 		make_pair
	#define rep(i,a,b) 	for(int i=a; i<b; ++i)
	#define rep0(i,a)	for(int i=0; i<a; ++i)
	#define rep1(i,a)	for(int i=1; i<=a; ++i)
	#define trav(a) 	for(auto &x:a)
	#define test 		cout<<"hello\n";
	#define all(x) 		(x).begin(),(x).end()
	#define mem(x,val)	memset(x, val, sizeof(x))
	#define sa(x) 		std::sort(all(x))
	#define endl 		'\n'
	#define __lcm(m,n) 	m*(n/__gcd(m,n))
	#define fill(a,n) 	for(int xxx=0;xxx<n;++xxx) cin>>(a)[xxx]
	#define maxa(v)		*(max_element(all(v)))
	#define mina(v)		*(min_element(all(v))
	#define inputFile 	freopen("input.txt", "r", stdin); 
	#define outputFile	freopen("output.txt", "w", stdout);
	#define disp(a) 	trav(a) cout<<x<<" "; cout<<endl;
  	//#define int long long

template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T,typename U> std::ostream& operator<<(std::ostream& out, std::pair<T,U> a) {out<<a.fr<<" "<<a.sc; return out;}
template<typename T,typename U> std::istream& operator>>(std::istream& in, std::pair<T,U> &a) {in>>a.fr>>a.sc; return in;}
template<typename T> static inline void sd(vector<T> &x) {sort(all(x), greater<T>()) ; }
const int N=301;
int n;
double dp[N][N][N]={};

signed solve()
{
	cin>>n;
    int cnt[4]={};
    rep(i,0,n){int x;
    	cin>>x;
    	cnt[x]++;
    }
    dp[0][0][0]=0;
    for(int three=0; three<=n; ++three)
    {
    	for(int two=0; two<=n; ++two)
    	{
    		for(int one=0; one<=n; ++one)
    		{
    			int zero = n -(three+two+one);
    			if(zero == n)
    				continue;
    			if(three+two+one > n)
    				continue;
    			double val = 1;
    			if(three>0)
    			val += (1.0*three/n)*(dp[three-1][two+1][one]);
    			if(two>0)
    			val += (1.0*two/n)*(dp[three][two-1][one+1]);
    			if(one>0)
    			val += (1.0*one/n)*(dp[three][two][one-1]);
    			val /= (1.0-1.0*zero/n);
    			dp[three][two][one] = val;
    		}
    	}
    }
    cout<<fixed<<setprecision(12)<<dp[cnt[3]][cnt[2]][cnt[1]];
	return 0;
}

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
        
		solve();
        
	}
	//cout << "\nTime : " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 111160
n = int(input())
A = []
for i in range(n):
	A.append(int(input()))
	
B = A.copy()
B.remove(max(B))

A_max = max(A)
B_max = max(B)

for i in range(n):
	if A[i] == A_max:
		print(B_max)
	else:
		print(A_max)

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

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int count = 0;

    for (int used_a = 0; used_a <= a; used_a++) {
        for (int used_b = 0; used_b <= b; used_b++) {
            int temp = x - (500 * used_a + 100 * used_b);
            if (temp >= 0 && temp % 50 == 0 && temp / 50 <= c) {
                count++;
                //cout << used_a << ' ' << used_b << ' ' << temp / 50 << endl;
            }
        }
    }
    
    cout << count << endl;
}

Measured memory_bytes: 3604
void main() {
	auto ip = readAs!(int[]), N = ip[0], M = ip[1];
	auto arr = new int[](N+1);
	foreach(i; 0..M) {
		auto ip2 = readAs!(int[]), L = ip2[0], R = ip2[1];
		arr[L-1]++;
		arr[R]--;
	}
	auto arr2 = new int[](N+1);
	arr2[0] = arr[0];
	foreach(i; 1..N) arr2[i] = arr2[i-1] + arr[i];
	arr2.count!(i => i == M).writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

int N;

int main() {
  cin >> N;
  int H[N];
  for (int i = 0; i < N; i++) cin >> H[i];
  
  for (int i = N - 2; i >= 0; i--) {
    if (H[i] <= H[i + 1]) continue;
    else if (H[i] - H[i + 1] == 1) H[i] -= 1;
    else {
      cout << "No" << endl;
      exit(0);
    }
  }
  
  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define ret return
#define all(vl) vl.begin(),vl.end()
#define sor sort 
#define cl clear
#define m_p make_pair 
#define sz(a) a.size()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;
typedef map<string,ll> mapstl;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t,a,k;
	cin>>t>>a>>k;
	if(t>=k)
	{
		cout<<t-k<<" "<<a<<endl;
	}
	else if(t<k&&(t+a)>=k)
	{
		ll cha = k-t;
		cout<<0<<" "<<a-cha<<endl;
	}
	else
	{
		cout<<"0 0\n";
	}
	return 0;
}

Measured memory_bytes: 3620
import collections
n=int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a=collections.Counter(prime_factorize(n)).values()
res=0
for count in a:
    i=1
    while count>=0:
        count-=i
        i+=1
        res+=1
    res-=1
print(res)

Measured memory_bytes: 9464
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


//main function
fn main() {
    let n: i32 = read();
    let l: i32 = read();
    let mut min:i32 = 400;
    let mut mini:i32 = 400;
    let mut sum = 0;
    for i in 0..n{
	let  number = l+i;
	sum += number;
	
	let absnum = if number < 0 {number*-1 } else {number};
	min = if absnum < min { mini = number; absnum} else {min}
    }
    println!("{}",sum-mini);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n
#define pl(n) cout<<n<<" "
const int N=1e5+2;
const int inf= (int)(1e19+10LL);
    
void solve(){
   int n,m;
   sl(n);sl(m);
   Vl graph[n+1];
   Vl ht(n+1);
   for(int i=1;i<=n;i++)sl(ht[i]);
   for(int i=1;i<=m;i++){
   	int u,v;
   	 sl(u);sl(v);
   	 graph[u].pb(v);
   	 graph[v].pb(u);
   }
   int gd=0;
   for(int i=1;i<=n;i++){
   	int mx=ht[i];
   	bool check=true;
   	 for(auto it:graph[i]){
   	   	if(mx<=ht[it]){
   	   		check=false;
   	   	}
   	 }
   	 if(check)gd++;
   }
   cout<<gd<<endl;
   
}

signed main(){
  int test=1;
// sl(test);
 while(test--){
 	solve();
 }
 
}


Measured memory_bytes: 9776
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
vector<int> adj[100001];
int dp[100001];
int dfs(int node)
{
   if(dp[node]!=-1)
       return dp[node];
   dp[node]=0;
   for(int i=0;i<adj[node].size();++i)
   {
       dp[node]=max(dp[node],1+dfs(adj[node][i]));
   }
   return dp[node];
}
signed main()
{
   SPEED;
   int n,m,ans=0;
   cin>>n>>m;
   memset(dp,-1,sizeof(dp));
   for(int i=0;i<m;++i)
   {
       int u,v;
       cin>>u>>v;
       adj[u].push_back(v);
   }
   for(int i=1;i<=n;++i)
   {
       ans=max(ans,dfs(i));
   }
   cout<<ans;
}

Measured memory_bytes: 11756
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;

// 2019/07/10
int main(){//bit演算
  int n,m;
  cin>>n>>m;
  vector<int> a(n);
  REP(i,m){
    int k;
    cin>>k;
    REP(j,k){
      int s;
      cin>>s;
      s--;
      a[s]|=1<<i;
    }
  }
  // pの入力
  int p=0;
  REP(i,m){
    int x;
    cin>>x;
    p|=x<<i;
  }
  // スイッチの推し方を全部試す
  int ans=0;
  for(int s=0;s<(1<<n);s++){
    int t=0;//どの電球がついてるか
    REP(i,n){
      if(s>>i&1){//i bit目がたってるか？
        t^=a[i];//xor
      }
    }
    if(t==p){
      ans++;
    }
  }

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


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int N;
  cin >> N;
  
  vector<int> A(N + 2, 0);
  for (int i = 1; i <= N; ++i) {
    cin >> A[i];
  }
  
  int sum = 0;
  for (int i = 1; i < A.size(); ++i) {
    sum += abs(A[i] - A[i - 1]);
  }
  
  for (int i = 1; i <= N; ++i) {
    int a = A[i] - A[i - 1];
    int b = A[i + 1] - A[i];
    
    if (1LL * a * b >= 0) {
      cout << sum << '\n';
    } else {
      cout << sum - 2 * min(abs(a), abs(b)) << '\n';
    }
  }
  
  return 0;
}


Measured memory_bytes: 1664
N = int(input())
list_deme = [0]*N
for n in range(N):
    i = list(map(int, input().split()))
    if i[0] == i[1]:
        list_deme[n] = 1
stack = 0
for i in list_deme:
    if i == 1:
        stack += 1
    elif stack < 3 and i == 0:
        stack = 0

if stack > 2:
    print("Yes")
else:
    print("No")


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

int main(){
    string s;
    cin >> s;
    int a = 0, b= 0;
    for(int i =0; i < 3; i++){
        if(s[i]== 'A'){
            a ++;
        }
        else{
            b++;
        }
    }
    if(a > 0&&b>0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }    
}

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

//#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
using intmap = map<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
inline bool bit (ll b, ll i) { return b & (1 << i); }
inline ll ceiv (ll a, ll b) { return (a + b - 1) / b; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define debug(x) cerr << #x << ": " << x << '\n'
#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()

signed main() {
    string s, t;
    cin >> s >> t;
    int ans = INT_MAX;
    rep(i,s.length() - t.length() + 1){
        int rpls = 0;
        rep(j,t.length()){
            if(s[i+j] != t[j]){
                rpls++;
            }
        }
        ans = min(ans, rpls);
    }
    cout << ans << endl;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n,m; cin >> n >> m;
    vvl g(n);
    rep(i,m){
        int a,b; cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i,n){
        if(g[i].size() % 2){
            out("NO");
            return 0;
        }
    }
    out("YES");
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main(){
    string s;
    cin >> s;
    sort(all(s));
    bool ans = false;
    if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) ans = true;
    cout << (ans?YES:NO) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,k;
	cin>>a>>b>>k;
	int i;
	for(i=a;i<=b&&i<a+k;i++)
	{
		cout<<i<<endl;
	}
	for(int j=b-k+1<i?i:b-k+1;j<=b;j++)
	{
		cout<<j<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

const LL mod = 1000000007;
LL N, ans;
std::vector<LL>T, A, h;

int main()
{
	in >> N;
	T.resize(N), A.resize(N), h.resize(N);
	rep(i, N) in >> T[i];
	rep(i, N) in >> A[i];
	if (T[N - 1] != A[0])
	{
		out << 0 << std::endl;
		return 0;
	}
	rep(i, N)
	{
		if (i == 0)
		{
			h[i] = T[i];
			h[N - i - 1] = A[N - i - 1];
		}
		else
		{
			if (T[i - 1] < T[i])
			{
				if (h[i] > 0 && h[i] != T[i])
				{
					out << 0 << std::endl;
					return 0;
				}
				h[i] = T[i];
			}
			if (A[N - i - 1] > A[N - i])
			{
				if (h[N - i - 1] > 0 && h[N - i - 1] != A[N - i - 1])
				{
					out << 0 << std::endl;
					return 0;
				}
				h[N - i - 1] = A[N - i - 1];
			}
			if (h[i] > T[i] || h[i] > A[i])
			{
				out << 0 << std::endl;
				return 0;
			}
		}
	}
	ans = 1;
	rep(i, N)
	{
		if (h[i] == 0)
		{
			ans *= std::min(T[i], A[i]);
			ans %= mod;
		}
	}
	out << ans << std::endl;
	return 0;
}

Measured memory_bytes: 2688
/*****************************************************
 *     created by: nayakashutosh9
 * "Winners Never Quit and Quitters Never Win".
*****************************************************/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define inf 1e18
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int N = 300005;
/**********************************************************************************************/


void solve() {
	string s; cin >> s;
	int ans = 0, mx = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'S') ans = 0;
		else ans++;
		mx = max(mx, ans);
	}
	cout << mx << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1, z = 1;
	// cin >> t; cin.ignore();
	while (t--) {
		// cout << "Case #" << (z++) << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}

Measured memory_bytes: 3648
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000100010001000100LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main(){ 
    int n, t; cin >> n >> t;
    vector<pii> food(n);
    rep(i, n){
        int a, b; cin >> a >> b;
        food[i] = {a, b};
    }
    sort(all(food));

    int mx = -1;
    vector<vector<int>> dp(n+1, vector<int>(t, -1));
    dp[0][0] = 0;
    rep(i, n){
        rep(j, t){
            if(dp[i][j] == -1) continue;
            int a = food[i].first, b = food[i].second;
            //i番目の食事を食べる
            if(j + a >= t){ //合計コストがt以上になった場合、それ以上は食べられない。お会計
                chmax(mx, dp[i][j] + b);
            }else{
                chmax(dp[i+1][j+a], dp[i][j] + b);
            }
            //食べない
            chmax(dp[i+1][j], dp[i][j]);
        }
    }
    rep(i, t){
        chmax(mx, dp[n][i]);
    }
    cout << mx << ln;
}

Measured memory_bytes: 35584
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	scan.next();
	String s = scan.next();
	scan.next();

	StringBuilder str = new StringBuilder();
	str.append('A');
	str.append(s.charAt(0));
	str.append('C');
	System.out.println(str.toString());
	scan.close();
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

// void chmod(ll &M){
//     if(M >= mod) M %= mod;
//     else if(M < 0){
//         M += (abs(M)/mod + 1)*mod;
//         M %= mod;
//     }
// }



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

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

	vector<int> left(n+5, 0), right(n+5, 0);
	for(int i=0; i<n-1; ++i){
		if(s[i] == 'W') left[i+1] = left[i]+1;
		else left[i+1] = left[i];
	}

	for(int i=n-1; i>0; --i){
		if(s[i] == 'E') right[i-1] = right[i]+1;
		else right[i-1] = right[i];
	}

	int ans = 1e8;
	for(int i=0; i<n; ++i){
		chmin(ans, right[i]+left[i]);
	}
	cout << ans << '\n';
	
	// for(int i=0; i<n; ++i){
	// 	printf("left[%d]:%d, right[%d]:%d\n", i, left[i], i, right[i]);
	// }
	return 0;
}

Measured memory_bytes: 2964
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
import           Data.Ord

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  [s, t] <- words <$> getLine
  [a, b] <- readIntList
  u <- getLine
  putStrLn $ if u == s then show (a - 1) ++ " " ++ show b else show a ++ " " ++ show (b - 1)


Measured memory_bytes: 380
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()


ll n, k, s[1000], t[1000], up[1000], ut[1000], ans = 0, now = 1, u,mxu = INF;
int main() {
	cin >> n >> k;
	u = k;
	REP(i, n) {
		ll a;
		cin >> a;
		REPO(j, INF) {
			if (a == 0)break;
			else {
				if (a % 2 == 1)s[j]++;
				a /= 2;
			}
		}
	}
	REPO(i, INF) {
		if (k == 0)break;
		else {
			if (k % 2 == 1) {
				t[i]++;
			}
			else mxu = min(mxu, i);
			k /= 2;
		}
	}
	if (u == 0) {
		REPO(i, 500) {
			ans += now * s[i];
			now *= 2;
		}
		cout << ans << endl;
		return 0;
	}
	else {
		REPO(i, 50) {
			up[i] = up[i - 1] + now * max(n - s[i], s[i]);
			now *= 2;
		}
		now = 1;
		REPO(i, 50) {
			if (t[i] == 1) {
				if (i < mxu) ut[i] = max(up[i - 1] + now * max(n - s[i], s[i]), ut[i - 1] + now * max(n - s[i], s[i]));
				else ut[i] = max(up[i - 1] + now * s[i], ut[i - 1] + now * max(n - s[i], s[i]));
			}
			else ut[i] = ut[i - 1] + now * s[i];
			now *= 2;
		}
		
	}
	cout << ut[50] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxx = 1e6 ;
const ll mod = 1e9 + 7;
ll t, T, n, m, k, ans[maxx], tong, r, o[12], h;
struct icon
{
    ll pos  , val , mn;
};
icon b[maxx];
bool ss(const icon&x, const icon&y)
{
    return (x.val < y.val) || (x.val == y.val && x.pos < y.pos);
}
ll c[maxx], f[2002][2002], ma[12][12];
map<ll, ll> mp;
char ch;
vector<ll> adj[maxx];
string s;
ll a[maxx], dd[maxx], vit[maxx];

set<ll> st[maxx];
vector<ll> bo[maxx], sat[maxx];
void bfs(ll u, ll x)
{
    a[u] = x;
    for(auto v: bo[u])
    {
        if(a[v] == 0)
        {
            bfs(v, x);
        }
    }
}
void dfs(ll u, ll x)
{
    dd[u] = x;
    for(auto v: sat[u])
    {
        if(dd[v] == 0)
        {
            dfs(v, x);
        }
    }
}
vector<pair<pair<ll, ll>, ll>> tp;
void sol()
{
    cin >> n >>  k >> m;
    ll x, y;
    for(int i = 1; i <= k; i ++)
    {
        cin >> x >> y;
        bo[x].push_back(y);
        bo[y].push_back(x);
    }
    for(int i = 1; i <= m; i ++)
    {
        cin >> x >> y;
        sat[x].push_back(y);
        sat[y].push_back(x);
    }
    fill_n(dd, n+1, 0);
    fill_n(a, n+1, 0);
    for(int i = 1; i <= n; i ++)
    {
        if(a[i] == 0)
            bfs(i, i);
    }
    for(int i = 1; i <= n; i ++)
        {
            if(dd[i] == 0)dfs(i, i);
        }
    for(int i = 1; i <= n; i ++)
    {
        tp.push_back({{a[i], dd[i]}, i});
    }
    sort(tp.begin(), tp.end(), [](const pair<pair<ll, ll>, ll> &x, const pair<pair<ll, ll>,ll> &y)
         {
            return ((x.first.first < y.first.first) || (x.first.first == y.first.first && x.first.second < y.first.second));
         });
    h = 0;
    for(int i = 0; i < n; i ++)
        {
            t = 1;
            ++h;
            while(i + 1 < n && (tp[i].first.first == tp[i+1].first.first) && (tp[i+1].first.second == tp[i].first.second))
            {
                ans[tp[i].second] = h;
                ++t;
                ++i;
            }
            ans[tp[i].second] = h;
            c[h] = t;
        }
    for(int i = 1; i <= n; i ++)
        cout << c[ans[i]] <<" ";
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    sol();
}




Measured memory_bytes: 146668
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int& x : a) {
		cin >> x;
		--x;
	}
	int d = log2(k)+2;
	vector<vector<int>> dp(n, vector<int>(d));
	for (int i=0; i<n; i++) {
		dp[i][0] = a[i];
	}
	for (int j=1; j<d; j++) {
		for (int i=0; i<n; i++) {
			dp[i][j] = dp[dp[i][j-1]][j-1];
		}
	}
	int idx = 0, cur = 0;
	while (k) {
		if (k&1) cur = dp[cur][idx];
		idx++;
		k/=2;
	}
	cout << cur+1 << '\n';
}

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

int main(){
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (0<=x-r && x+r<=W && 0<=y-r && y+r<=H){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 1160
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1

def main():
    def cnt(x):
        res = 0
        for i in range(9999, x + 1):
            s = str(i)
            for c0, c1 in zip(s, s[::-1]):
                if c0 != c1: break
            else:
                res += 1
        return res

    a, b = map(int, input().split())
    print(cnt(b) - cnt(a - 1))

main()


Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>

using namespace std;

void b_yymm_or_mmyy(void) {
	string s;
	cin >> s;
	int upper, lower;
	string sub_s;
	sub_s = s.substr(0, 2);
	upper = stoi(sub_s);
	sub_s = s.substr(2, 2);
	lower = stoi(sub_s);

	string upper_type, lower_type;
	if (upper > 12) {
		upper_type = "YY";
	}
	else if (upper == 0) {
		upper_type = "YY";
	}
	else {
		upper_type = "MM";
	}
	if (lower > 12) {
		lower_type = "YY";
	}
	else if (lower == 0) {
		lower_type = "YY";
	}
	else {
		lower_type = "MM";
	}
	
	if (upper_type == "YY" && lower_type == "MM")      cout << "YYMM" << endl;
	else if (upper_type == "MM" && lower_type == "YY") cout << "MMYY" << endl;
	else if (upper_type == "YY" && lower_type == "YY") cout << "NA" << endl;
	else                                               cout << "AMBIGUOUS" << endl;
}

int main()
{
    b_yymm_or_mmyy();

    return 0;
}


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

int main(){
  int N;
  cin>>N;
  double A[N];
  double B[N];
  int ans=0;
  double midA,midB;
  for(int i=0;i<N;i++){
    cin>>A[i]>>B[i];
  }
  sort(A,A+N);
  sort(B,B+N);
  if(N%2==0){
    midA=(A[N/2]+A[(N/2)-1])/2;
    midB=(B[N/2]+B[(N/2)-1])/2;
    ans=(int)((midB-midA)/(0.5)+1);
  }
  if(N%2==1){
    midA=A[(N-1)/2];
    midB=B[(N-1)/2];
    ans=(int)(midB-midA+1);
  }  
  cout<<ans<<endl;
  //cout<<midA<<" "<<midB<<endl;
  return 0;
  }

Measured memory_bytes: 6848
N = int(input())
A = list(map(int, input().split()))

if len(A) == 1:
    print(A[0])
    exit(0)

B_left = []
B_right = []
for i, a in enumerate(A):
    if i % 2 == 0:
        B_right.append(a)
    else:
        B_left.append(a)

if len(A) % 2 == 0:
    B = B_left[::-1] + B_right
else:
    B = B_right[::-1] + B_left
print(*B)


Measured memory_bytes: 104916
//Contest with Drinks Easy

#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>

using namespace std;

int main()
{
    int N,M;
    vector<int> T;

    vector<int> P;
    vector<int> X;

    cin >> N;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        T.push_back(x);
    }
    cin >> M;
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        P.push_back(x);
        X.push_back(y);
    }

    for (int i = 0; i < M; i++) {
        int sum = 0;
        for (int j = 0; j < N; j++) {
            if (j == P[i] - 1) {
                sum += X[i];
            }
            else {
                sum += T[j];
            }
        }
        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[n],b[n];
  map<int,int> aa;
  rep(i,n){
    cin>>a[i];
    if(aa[a[i]]>n){cout<<"No"<<endl;return 0;
    }
  }
  rep(i,n){
    cin>>b[i];
    if(aa[b[i]]>n){cout<<"No"<<endl;return 0;
    }
  }
  int prev=-1;
  int j=0;
  rep(i,n){
    if(a[i] != prev) j=0;
    if(a[i]==b[i]){
      for(;j<n;j++){
	if(a[i]!=b[j] && a[i]!=a[j]){
	  swap(b[i],b[j]);
	  break;
	}
      }
      if(a[i]==b[i]){cout<<"No"<<endl;return 0;
      }
    }
    prev=a[i];
  }
  cout<<"Yes"<<endl;
  rep(i,n){
    if(i) cout<<" ";
    cout<<b[i];
  }
  cout<<endl;
      
  return 0;
}


Measured memory_bytes: 19196
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

a.sort()
b.sort()
c.sort()

BtoC = [0]*(n+1)
for i in range(n):
  bin_l, bin_r = 0, n
  while bin_r - bin_l > 1:
    key = (bin_r + bin_l)//2
    if b[i] >= c[key]:
      bin_l = key
    else:
      bin_r = key
  if bin_l == n-1 and b[i] < c[-1]:
    BtoC[i] = 1
  elif bin_r == 1 and b[i] < c[0]:
    BtoC[i] = n
  else:
    BtoC[i] = n-bin_r

for i in range(n-1, -1, -1):
  BtoC[i] += BtoC[i+1]

ans = 0
for i in range(n):
  bin_l, bin_r = 0, n
  while bin_r - bin_l > 1:
    key = (bin_r + bin_l)//2
    if a[i] >= b[key]:
      bin_l = key
    else:
      bin_r = key
  if bin_l == n-1 and a[i] < b[-1]:
    ans += BtoC[n-1]
  elif bin_r == 1 and a[i] < b[0]:
    ans += BtoC[0]
  else:
    ans += BtoC[bin_r]
print(ans)     

Measured memory_bytes: 23008
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+7;
#define ll long long

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	if(n%k){
		printf("1\n");
	}else{
		printf("0\n");
	}
	//printf("%d\n",n%k); 
	return 0; 
}

Measured memory_bytes: 256