akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include<chrono>
 
using namespace std;
//using namespace std::chrono;
 
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define pb push_back
#define ins insert
#define mp make_pair
#define ff first
#define ss second
#define vl int64_t

int main()
{
	string s;
	cin>>s;
	vector<ll>v;
	ll len=s.length();
	
	for(ll i=0;i<s.length();i++)
	{
		ll temp=0;
		ll j;
		
		if(s[i]=='>')
		{
			for(j=i;j<s.length();j++)
			{
				if(s[j]=='>')
				temp++;
				
				else
				break;
			}
			
			v.pb(temp);
		}
		
		else if(s[i]=='<')
		{
			for(j=i;j<s.length();j++)
			{
				if(s[j]=='<')
				temp++;
				
				else
				break;
			}
			
			v.pb(temp);
	
		}
		
		i=j-1;
	}
	
	ll sum=0;
	if(s[0]=='<')
	{
		
		ll i;
		for(i=0;i<v.size();i+=2)
		{
			if(i+1==v.size())
			break;
			
			ll mini=min(v[i],v[i+1]);
			ll maxee=max(v[i],v[i+1]);
			
			mini-=1;
			
			mini=mini*(mini+1)/2;
			maxee=maxee*(maxee+1)/2;
			sum+=mini+maxee;
		}
		
		if(i==v.size()-1)
		sum+=v[i]*(v[i]+1)/2;
	}
	
	else
	{
		sum+=v[0]*(v[0]+1)/2;
		ll i;
		for(i=1;i<v.size();i+=2)
		{
			if(i+1==v.size())
			break;
			
			ll mini=min(v[i],v[i+1]);
			ll maxee=max(v[i],v[i+1]);
			
			mini-=1;
			
			mini=mini*(mini+1)/2;
			maxee=maxee*(maxee+1)/2;
			sum+=mini+maxee;
		}
		
		if(i==v.size()-1)
		sum+=v[i]*(v[i]+1)/2;
	}
	
	cout<<sum;
}

Measured memory_bytes: 3068
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
#include<iomanip>
#include<bitset>
#define mod 998244353
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mad(a,b) a=(a+b)%mod
#define mul(a,b) a=a*b%mod

#define N 600010
ll n,l[N],r[N];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
	cin>>l[i]>>r[i];
    }
    sort(l,l+n,greater<ll>());
    sort(r,r+n);
    ll lsum=0,rsum=0;
    ll ans=0;
    for(int i=0;i<n;i++){
	chmax(ans,lsum-rsum);
	chmax(ans,lsum-rsum+l[i]*2);
	chmax(ans,lsum-rsum-r[i]*2);
	lsum+=2*l[i];
	rsum+=2*r[i];
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 3072
n = input()
S = list(map(int, input().split()))
q = input()
T = list(map(int, input().split()))

def binarySearch(key, A):
    n = len(A)
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            return True
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return False

count = 0
for elem in T:
    if binarySearch(elem, S):
        count = count + 1
print(count)


Measured memory_bytes: 16708
#include <cstdio>
#include <cstring>

int main()
{
    char data[100010];
    char result[100010];
    scanf("%s", data);
    
    int len = strlen(data);
    for (int i = 0; i < len; i+=2)
    {
       result[i>>1] = data[i];
    }

    printf("%s", result);
    return 0;
}

Measured memory_bytes: 384
fun main (args : Array<String>) {
	val (a, b) = readLine()!!.split(" ")
	val A : Int = a.toInt()
	val B : Int = b.toInt()
	if ( (A >= 1) && (A <= 9) && (B >= 1) && (B <= 9) ) {
		var calc = A * B
		return println("${calc}")
	} else {
		return println("-1")
	}
}

Measured memory_bytes: 37896
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	for(int i=0; i<N; i++){
		cin >> a.at(i);
	}

	int cnt=0;
	int tmp=0;
	int is_up=0;//0まだ-1さがる1あがる
	int is_end=1;//0つづいてる1はじまってない
	for(int i=0; i<N; i++){
//		cout << a.at(i) << " a[i] " << tmp << " tmp " << is_end << " is_end " << is_up << endl;
		if(is_end==1){
			cnt++;
			tmp=a.at(i);
			is_end=0;
		}else{
			if(is_up==0){
				//まだあがるかさがるかきまってない
				if(tmp<a.at(i)){
					is_up=1;
				}else if(tmp>a.at(i)){
					is_up=-1;
				}
				tmp=a.at(i);
			}else if(is_up==1){
				if(tmp>a.at(i)){
					is_end=1;
					is_up=0;
					i--;
				}else{
					tmp = a.at(i);
				}
			}else{
				if(tmp<a.at(i)){
					is_end=1;
					is_up=0;
					i--;
				}else{
					tmp = a.at(i);
				}
			}
		}
//		cout << a.at(i) << " a[i] " << tmp << " tmp " << is_end << " is_end " << is_up << endl;
	
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 100000000
#define MAX 
using namespace std;
bool debug=false;

int cost[105][105];
int d[105];
bool used[105];
int n;

void Input(){
  cin>>n;
  rep(i,0,n)rep(j,0,n)cost[i][j]=INF;
  for(int i=0;i<n;i++){
  	int from,to,num,c;
  	cin>>from>>num;
  	for(int j=0;j<num;j++){
  		cin>>to>>c;
  		cost[from][to]=c;
  	}
  }
  rep(i,0,105){
    used[i]=false;
    d[i]=INF;
  }
}

void solve(){
  d[0]=0;
  while(1){
    int vertex=-1;

    for(int i=0;i<n;i++){
      if(!used[i]&&(vertex==-1||d[i]<d[vertex])){
	    vertex=i;
      }
    }
    if(vertex==-1)break;
    used[vertex]=true;
    for(int i=0;i<n;i++){
      d[i]=min(d[i],d[vertex]+cost[vertex][i]);
    }
  }
}

int main(){
  Input();
  solve();
  for(int i=0;i<n;i++)cout<<i<<" "<<d[i]<<endl;
  return 0;
}

Measured memory_bytes: 3096
N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]
ok = 10**9
ng = 0
while ng + 1 < ok:
    c = ok + ng >> 1
    G = [max(0, h-c*B) for h in H]
    n = sum(-(-g//(A-B)) for g in G)
    if c >= n:
        ok = c
    else:
        ng = c
print(ok)


Measured memory_bytes: 21536
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int n, k;
  scan(n, k);
  int m = 20;
  vector<double> po(m);
  po[0] = 1;
  rep (i, m-1) {
    po[i+1] = po[i] * 0.5;
  }

  double ans = 0;
  FOR (i, 1, n+1) {
    int point = i;
    int cnt = 0;
    while (point < k) {
      cnt += 1;
      point *= 2;
    }
    assert (cnt < m);
    //debug3(i, cnt, po[cnt]);
    ans += po[cnt];
  }
  ans /= n;
  print(ans);

  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
struct st{
  int x,y,b,d;
  st(int x,int y,int b,int d):x(x),y(y),b(b),d(d){}
};
int main(){
  int w,h;
  while(cin>>w>>h,w||h){
    char m[h][w];
    int i,j,k,b,ans=1<<28,x,y;
    typedef pair<int,int> P;
    vector<P> v;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	cin >> m[i][j];
	if(m[i][j]=='o') x=j,y=i,m[i][j]='.';
	if(m[i][j]=='*') v.push_back(P(j,i));
      }
    }
    int n=v.size();
    bool used[h][w][1<<n];
    memset(used,0,sizeof(used));
    queue<st> q;
    int ax[]={1,-1,0,0};
    int ay[]={0,0,1,-1};
    q.push(st(x,y,0,0));
    while(!q.empty()){
      st s=q.front();q.pop();
      if(s.x<0||w<=s.x||s.y<0||h<=s.y) continue;
      if(m[s.y][s.x]=='x') continue;
      if(used[s.y][s.x][s.b]) continue;
      used[s.y][s.x][s.b]=true;
      if(s.b==(1<<n)-1) {
	ans=min(ans,s.d);
	continue;
      }
      for(k=0;k<4;k++){
	x=s.x+ax[k];y=s.y+ay[k];b=s.b;
	for(i=0;i<n;i++)
	  if(x==v[i].first&&y==v[i].second) b|=(1<<i);
	q.push(st(x,y,b,s.d+1));
      }
    }
    
    if(ans==(1<<28)) cout << -1 << endl;
    else cout << ans << endl;
  }
  return 0;
}

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

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

using namespace std;

const int IINF = INT_MAX;

struct Data{
  int x,y,oxygen,left,right,money;
  bool operator < ( const Data& data ) const {
    if( money != data.money )return money > data.money;
    return oxygen < data.oxygen;
  }
};

int H,W,f,m,o,c[20][20],dp[20][20][60][20][20];
int dx[] = {-1,+1};
int dy[] = {+0,+0};

bool isValid(int x,int y){ return 0 <= x && x < W && 0 <= y && y <= H; }


int main(){
  while( cin >> W >> H, W|H ){
    cin >> f >> m >> o;
    rep(i,W) c[0][i] = 0;
    rep(i,H) rep(j,W) cin >> c[i+1][j];
    rep(i,H+2) rep(j,W) rep(k,m+1) rep(y,W) rep(x,W) dp[i][j][k][y][x] = IINF;
    priority_queue<Data> Q;
    rep(i,W) {
      dp[0][i][o][i][i] = 0;
      Q.push((Data){i,0,o,i,i,0});
    }
    

    int ans = IINF;
    while( !Q.empty() ){
      Data data = Q.top(); Q.pop();

      if( data.y == H ) {
        ans = data.money;
        break;
      }
      if( data.oxygen <= 1 ) continue;
      int oxygen = data.oxygen - 1;
      assert( oxygen >= 1 );
      rep(i,2){
        int nx = data.x + dx[i], ny = data.y + dy[i], left = data.left, right = data.right;
        if( !isValid(nx,ny) ) continue;
        int nmoney = data.money;
        int noxygen = oxygen;
        if( left > nx || right < nx ) {
          if( c[ny][nx] < 0 ) nmoney  -= c[ny][nx];
          else                noxygen += c[ny][nx];
        }
        noxygen = min(noxygen,m);
        if( dp[ny][nx][noxygen][min(left,nx)][max(right,nx)] > nmoney ) {
          dp[ny][nx][noxygen][min(left,nx)][max(right,nx)] = nmoney;
          Q.push((Data){nx,ny,noxygen,min(left,nx),max(right,nx),nmoney});
        }
      }

      int nx = data.x, ny = data.y + 1, nmoney = data.money, noxygen = oxygen;
      if( c[ny][nx] < 0 ) nmoney  -= c[ny][nx];
      else                noxygen += c[ny][nx];
      noxygen = min(noxygen,m);
      if( dp[ny][nx][noxygen][nx][nx] > nmoney ) {
        dp[ny][nx][noxygen][nx][nx] = nmoney;
        Q.push((Data){nx,ny,noxygen,nx,nx,nmoney});
      }
    }
    if( ans == IINF || ans > f ) puts("NA");
    else cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 22784
import java.math.BigInteger;
import java.util.*;


public class Main {
	
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String s = sc.next();
			int n = sc.nextInt();
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < s.length(); i++){
				if(i % n == 0){
					sb.append(s.charAt(i));
				}
			}
			System.out.println(sb.toString());
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <queue>
#include <numeric>
#include <iomanip>

using namespace std;

#define ll long long
constexpr ll inf = 1e9+7;

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

    ll N;
    cin>>N;
    vector<double> ts(N), vs(N);
    for (ll n = 0; n < N; n++) cin>>ts[n];
    for (ll n = 0; n < N; n++) cin>>vs[n];

    double T = accumulate(begin(ts), end(ts), 0.0);
    vector<double> v(2*T+1);
    for (ll t = 0; t <= 2*T; t++) v[t] = min(0.5*t, T-0.5*t);

    double t_begin = 0;
    for (ll n = 0; n < N; n++) {
        for (ll t = 0; t <= 2*T; t++) {
            double new_v;
            if (0.5 * t < t_begin) new_v = (t_begin - 0.5 * t) + vs[n];
            else if (0.5 * t < t_begin + ts[n]) new_v = vs[n];
            else new_v = (0.5 * t - t_begin - ts[n]) + vs[n];

            v[t] = min(v[t], new_v);
        }
        t_begin += ts[n];
    }
    double ans = 0.0;
    for (ll t = 0; t < 2*T; t++) ans += 0.5 * (v[t] + v[t+1]) / 2.0;
    cout<<setprecision(8)<<ans<<endl;

    return 0;
}

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

using namespace std;
typedef long long ll;

const int maxN = 100010;

queue<int> Q;
vector<int> G[maxN];
int pc[maxN], cnt[3];

int bfs(int u){
	Q.push(u);
	++cnt[pc[u] = 1];
	while(Q.size()){
		u = Q.front(); Q.pop();
		for(int i = 0; i < G[u].size(); ++i){
			int v = G[u][i];
			if(!pc[v]){
				++cnt[pc[v] = 3 - pc[u]];
				Q.push(v);
			}
			else if(pc[v] != 3 - pc[u]) return 0;
		}
	}
	return 1;
}

int main (){
	int n, m, i, a, b;
	scanf("%d%d", &n, &m);
	for(i = 0; i < m; ++i){
		scanf("%d%d", &a, &b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	ll ans;
	if(bfs(1)) ans = cnt[1] * 1ll * cnt[2] - m;
	else ans = n * 1ll * (n - 1) / 2 - m;
	printf("%lld\n", ans);
	return 0;
}


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

int N, M;

struct Unionfind {
    vector<int> par, rank;
    
    Unionfind(int n) {
        par.resize(n);
        fill(par.begin(), par.end(), -1);
        rank.resize(n);
    }
    
    int root(int x) {
        int r = x;
        while (!(par[r]<0)) r = par[r];
        int t = x;
        
        while (t!=r) {
            int tmp = t;
            t = par[t];
            par[tmp] = r;
        }
        
        return r;
    }
    
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        
        if (rx==ry) return;
        
        if (rank[rx]<=rank[ry]) {
            par[ry] += par[rx];
            par[rx] = ry;
            
            if (rank[rx]==rank[ry]) rank[ry]++;
        }
        else {
            par[rx] += par[ry];
            par[ry] = rx;
        }
    }
    
    bool is_same(int x, int y) {
        return root(x)==root(y);
    }
    
    int count(int x) {
        return -par[root(x)];
    }
};

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> M;
    Unionfind uf(N);
    rep(i, M) {
        int X, Y, Z; cin >> X >> Y >> Z;
        uf.unite(X-1, Y-1);
    }
    set<int> s;
    rep(i, N) s.insert(uf.root(i));
    cout << s.size() << endl;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
const int INF=2E9;

int main(){
    int N;
    cin >> N;
    array<int,200010> A;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    array<int,200010> B=A;
    sort(A.begin(),A.end()-200010+N);
    int midL=A[N/2-1];
    int midR=A[N/2];
    for(int i=0;i<N;i++){
        if(B[i]>=midR){
            cout << midL << endl;
        }else cout << midR << endl;
    }
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

const int MAX_W=50;

char a[MAX_W][MAX_W];
bool checked[MAX_W][MAX_W];
int w,h;

pair<int,char> dfs(int x,int y){
  if(x<0||y<0||x>=w||y>=h) return make_pair(0,0);
  if(a[y][x]==1) return make_pair(0,1);
  if(a[y][x]==2) return make_pair(0,2);
  if(checked[y][x]) return make_pair(0,0);
  checked[y][x]=true;
  pair<int,char> l=dfs(x-1,y);
  pair<int,char> u=dfs(x,y-1);
  pair<int,char> r=dfs(x+1,y);
  pair<int,char> d=dfs(x,y+1);
  char c=l.second|u.second|r.second|d.second;
  if(c==255||c==3) return make_pair(0,255);
  if(c!=0) return make_pair(l.first+u.first+r.first+d.first+1,c);
  return make_pair(l.first+u.first+r.first+d.first+1,0);
}

int main(){ _;
  while(cin>>w>>h,(w|h)!=0){
    REP(i,h)REP(j,w){
      cin>>a[i][j];
      a[i][j]=a[i][j]=='B'?1:a[i][j]=='W'?2:0;
    }
    REP(i,h)REP(j,w) checked[i][j]=false;
    int area_b=0,area_w=0;
    REP(i,h)REP(j,w){
      pair<int,char> p=dfs(j,i);
      if(p.second==1) area_b+=p.first;
      else if(p.second==2) area_w+=p.first;
    }
    cout<<area_b<<" "<<area_w<<endl;
  }
}

Measured memory_bytes: 1392
if __name__=="__main__":
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    A_sum_arr,B_sum_arr = [0],[0]
    for i in range(len(A)):
        A_sum_arr.append(A[i]+A_sum_arr[i])
    for i in range(len(B)):
        B_sum_arr.append(B[i]+B_sum_arr[i])
    count = 0
    j = len(B_sum_arr) - 1
    for i,A_sum in enumerate(A_sum_arr):
        if A_sum > K:
            break
        else:
            b_val = K - A_sum
            while b_val < B_sum_arr[j]:
                j -= 1
            count = max(count,(i+j))
    print(count)

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int e;

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>e;
		if(e==0)break;
		int res=INF;
		for(int y=0;y*y<=e;y++){
			for(int z=0;z*z*z<=e-y*y;z++){
				minch(res,e-y*y-z*z*z+y+z);
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

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

int main(){
  int n;
  cin >> n; 
  vector<double> v(n,0);
  rep(i,n) cin >> v[i];
  sort(v.begin(),v.end());
  rep(i,n-1){
    v[i+1] =(v[i+1]+ v[i])/2.0;
  }
  cout << v[n-1] << endl;
}


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

int main(void)
{
	int w, h, n;
	cin >> w >> h >> n;
	int box[w][h] = {0};
	for (int i = 0; i < n; i++) {
		int xi, yi, ai;
		cin >> xi >> yi >> ai;
		switch (ai) {
			case 1:
				for (int x = 0; x < xi; x++) {
					for (int y = 0; y < h; y++) {
						box[x][y] = 1;
					}
				}
				break;
			case 2:
				for (int x = xi; x < w; x++) {
					for (int y = 0; y < h; y++) {
						box[x][y] = 1;
					}
				}
				break;
			case 3:
				for (int x = 0; x < w; x++) {
					for (int y = 0; y < yi; y++) {
						box[x][y] = 1;
					}
				}
				break;
			case 4:
				for (int x = 0; x < w; x++) {
					for (int y = yi; y < h; y++) {
						box[x][y] = 1;
					}
				}
				break;
		}
	}

	int count = 0;

	for (int x = 0; x < w; x++) {
		for (int y = 0; y < h; y++) {
			count += box[x][y];
		}
	}

	cout << w*h-count << endl;
	return 0;
}


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

const int MAXN = 1000, MOD = 1000 * 1000 * 1000 + 7;
int f[MAXN + 1], f1[MAXN + 1], dp[MAXN + 1][MAXN + 1];

int binPow(int a, int n) {
    if(n == 0)
        return 1;
    else if(n & 1)
        return (1LL * binPow(a, n  - 1) * a) % MOD;
    else {
        int d = binPow(a, n / 2);
        return (1LL * d * d) % MOD;
    }
}

void add(int& a, int b) {
    a += b;
    if(a >= MOD)
        a -= MOD;
}

int C(int n, int k) {
    int res = (1LL * f[n] * f1[k]) % MOD;
    res = (1LL * res * f1[n - k]) % MOD;
    return res;
}

int main() {
    //ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    f[0] = 1;
    f1[0] = 1;
    for(int i = 1; i <= n; i++) {
        f[i] = (1LL * f[i - 1] * i) % MOD;
        f1[i] = binPow(f[i], MOD - 2);
        assert(((ll)f[i] * f1[i]) % MOD == 1);
    }
    dp[a - 1][n] = 1;
    for(int cnt = a; cnt <= b; cnt++) {
        for(int lost = n; lost >= 0; lost--) {
            add(dp[cnt][lost], dp[cnt - 1][lost]);
            if(lost < c * cnt)
                continue;
            int val = 1;
            for(int curG = 1; curG < c; curG++) {
                val = (1LL * val * C(lost - (curG - 1) * cnt, cnt)) % MOD;
            }
            for(int curG = c; curG <= d && lost >= curG * cnt; curG++) {
                val = (1LL * val * C(lost - (curG - 1) * cnt, cnt)) % MOD;
                add(dp[cnt][lost - curG * cnt], (((1LL * dp[cnt - 1][lost] * val) % MOD) * (ll)f1[curG]) % MOD);
            }
        }
    }
    cout << dp[b][0] << endl;
    return 0;
}

Measured memory_bytes: 4224
N, A, B, K = map(int, input().split())
mod = 998244353

# 階乗 & 逆元計算
factorial = [1]
inverse = [1]
for i in range(1, N+2):
    factorial.append(factorial[-1] * i % mod)
    inverse.append(pow(factorial[-1], mod-2, mod))


# 組み合わせ計算
def nCr(n, r):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % mod


ans = 0
for x in range(N+1):
    y = (K - A * x) / B
    if y.is_integer():
        ans += nCr(N, x) * nCr(N, int(y)) % mod

print(ans % mod)


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int main()
{
    int N;
    cin >> N;
    set<int> st;
    vector<int> prime;
    map<int, int> mp;
    reps(i, 2, 55556)
    {
        if (st.count(i))
            continue;
        prime.push_back(i);
        int tmp = i;
        tmp -= tmp / 10 * 10;
        mp[tmp]++;
        reps(j, i + 1, 55556)
        {
            if (j % i == 0)
                st.insert(j);
        }
    }
    cout << "2";
    rep(i, 10)
    {
        if (mp[i] >= N - 1)
        {
            int cnt = N - 1;
            rep(j, prime.size())
            {
                int tmp = prime[j];
                tmp -= tmp / 10 * 10;
                if (tmp == i)
                {
                    cout << " " << prime[j];
                    cnt--;
                }
                if (cnt == 0)
                {
                    cout << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}


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

int main() {
    int s, w;
    cin >> s >> w;
    if (w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T;
  cin >> S >> T;
  
  int count = 0;
  
  for (int i = 0; i < S.length(); i ++) {
  	char a = S[i];
    char b = T[i];
    
    if (a != b) {
      count++;
    }
  }
 
  cout << count << endl;
}


Measured memory_bytes: 3916
import java.util.Scanner;
 
public class Main {
	public static int maxDepth;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		String head = "ABD";
		if (n <= 999)
			head = "ABC";
			
		System.out.println(head);
	}
}

Measured memory_bytes: 21332
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
#include <utility>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*///map < string, ll> s;

/*i++ずつずらす
a[0] a[1] a[2]//a[1] a[2] a[3]
a[0] a[2] a[4]//a[1] a[3] a[5]
/*if (N % 2 != 0)a = N / 2;
else a = N / 2 - 1;
for (int i = 1;i <= a;i++) {
	for (int j = 0;j < N - (i * 2);j++) {
		if (S[j] != S[j + i] && S[j + i * 2] != S[j] && S[j + i] != S[j + i * 2]) sum--;
		if (sum == 0)break;
	}
}*/

//mapの使い方
/*map<int, int> mp;
for (int i = 0; i < N; i++)
	mp[a[i]]++;

int ans = 0;
for (auto p : mp) {
	int x = p.first;
	int n = p.second;
	if (n < x) ans += n;
	else ans += n - x;
}*/
//cout << std::fixed << std::setprecision(12) <<<< endl;

int main() {
	ll A; string B;
	cin>>A>>B;
	ll b =(B[0]-'0')*100+(B[2]-'0')*10+(B[3]-'0');
	cout<<(A*b)/100<<endl;
}

Measured memory_bytes: 3556
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
const double pi = 3.14159265358979;
int main(){
	int a,b,h,m;
	cin >> a >> b >> h >> m;

	double ang_h = h * 30 + 30 * ((double) m / 60);
	double ang_m = m * 6;

	double theta = min(abs(ang_h-ang_m),360-(ang_h-ang_m));
	double ans = sqrt(a*a+b*b-2*a*b*cos(theta*pi/180));

	printf("%.14lf\n",ans);
}


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

int main(){
    char s[1010];
    char stringdes[]= "s";
    char stringdees[]= "es";

    scanf("%s",s);

    int tams = strlen(s);

    for(int i=0;i<=tams;i++){
        if(s[tams-1]!='s'){
            strcat(s,stringdes);
            break;



        }
        if(s[tams -1]=='s'){
            strcat(s,stringdees);

            break;


        }

    }



    printf("%s\n",s);







    return 0;
}


Measured memory_bytes: 1656
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 1e7+1;
const long double PI = acos(-1);


int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n, ans = 0;

    cin >> n;

    for (ll i=1; i<=n; i++){
        ll y = n/i;
        ans += i*((y*(y+1))/2);
    }

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

Measured memory_bytes: 3608
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main(void){
	int N;
	cin >> N;
	long A[N];
	long long result = 1;
	long long thre = 1000000000000000000;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}	
	sort(A,A+N);
	if (A[0] == 0){
		cout << 0 << endl;
		return 0;
	}
	else {
		for (int i = N-1; i >=0; i--) {
			if (A[i] <= thre/result){
				result *= A[i];
			}
			else{
			 cout << -1 << endl;
			 return 0;
			}
		}
	}
	cout << result << endl;

return 0;
}


Measured memory_bytes: 3948
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int x;
  cin >> x;
  x = x ^ 1;
  cout << x << endl;
}

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

typedef pair<int, int> node;
typedef vector<node> Adj_list;
typedef vector<Adj_list> Adj_lists;

class less_cost{
public:
  bool operator()(const node lhs, const node rhs) const{
    return lhs.second > rhs.second;
  }
};

int main(){

  int n;
  scanf("%d", &n);

  Adj_lists adj_lists(n);

  // read weigts
  for(int i=0; i<n; i++){
    int u, k;
    scanf("%d %d", &u, &k);
    for(int j=0; j<k; j++){
      int v,c;
      scanf("%d %d", &v, &c);
      adj_lists.at(u).push_back(node(v, c));
    }
  }

  // initialize cost
  vector<int> d(n, INT_MAX);
  d.at(0) = 0;
  priority_queue<node, vector<node>, less_cost> pq;
  pq.push(node(0, d.at(0)));
  vector<bool> is_belong_to_sssp(n, false);

  //dijkstra's algorithm
  while(!pq.empty()){
    // extract node u in V-S that has minimum cost
    const node u = pq.top();
    pq.pop();

    // if u's cost is larger than d[u],
    // than ignore this one
    if(u.second > d.at(u.first)) continue;


    is_belong_to_sssp.at(u.first) = true;

    // update node in V-S and adjacent to u
    for(const node& v : adj_lists.at(u.first)){
      if(!is_belong_to_sssp.at(v.first) && d.at(u.first) + v.second < d.at(v.first)){
        d.at(v.first) = d.at(u.first) + v.second;
        pq.push(node(v.first, d.at(v.first)));
      }
    }
  }

  // output
  for(int i=0; i<n; i++){
    printf("%d %d\n", i, d.at(i));
  }

  return 0;
}



Measured memory_bytes: 7912
#include "bits/stdc++.h"
using namespace std;
int N, K, h[100002], dp[100002];
int main(){
    scanf("%d %d %d", &N, &K, &h[1]);
    for(int i=2; i<=N; i++){
        scanf("%d", &h[i]);  dp[i] = 1e9;
        for(int j=i-1; j>=max(1, i-K); j--){
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }
    printf("%d\n", dp[N]);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define N 100100
using namespace std;
int a[N],n,sg=1;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		if(i>=a[i+1]){
			for(int j=i+1;j<=n&&a[j]==i;j++) sg^=1;
			sg&=(a[i]-i+1);
			printf("%s\n",sg?"Second":"First");
			return 0;
		}
	}
}

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

namespace _0217
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                int n = RInt();
                if (n == 0) break;
                
                Dictionary<int,int> patients = new Dictionary<int,int>(n);
                for(int i = 0; i < n ; i++)
                {
                     int[] items = RIntAr();   
                     patients.Add(items[0],items[1] + items[2]);
                }
                
               var item = patients.OrderByDescending(x => x.Value).First();
               Console.WriteLine("{0} {1}",item.Key,item.Value);
            }

        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}




Measured memory_bytes: 27520
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string S;
    cin >> S;
    int s;
    s = S.size();
    if(S[s-1] != 's'){
        S.push_back('s');
    }
    else if(S[s-1] == 's'){
        S += "es";
    }
    cout << S;
}

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

bool isPalindrome(string str) 
{ 
    // Start from leftmost and rightmost corners of str 
    int l = 0; 
    int h = str.length() - 1; 
  
    // Keep comparing characters while they are same 
    while (h > l) 
    { 
        if (str[l++] != str[h--]) 
        { 
            return false;
        } 
    } 
    return true;
} 

int main(){
    string str;
    cin>>str;
    int n = str.length();
    string str1 = str.substr(0,((n-1)/2));
    string str2 = str.substr(((n+3)/2)-1,n-1);

    if(isPalindrome(str)==true&&isPalindrome(str1)==true&&isPalindrome(str2)==true) cout<<"Yes";
    else cout<<"No";

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[10005];
int m;
char c;
int main()
{
	while(scanf("%c",&c)&&c!='\n')
	{
		if(c=='B')
		{
			if(m!=0) m--;
		}
		else a[++m]=c;
	}
	for(int i=1;i<=m;i++) cout<<a[i];
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=min((a), (b))

const int MOD=1000000007;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x, t;
	cin>>x>>t;
	cout<<max(0, x-t)<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define trav(v, x) for (auto v : x)
#define re(x, y, z) for (int x=y; x<z; ++x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;


int main() {
    int n, k;
    cin >> n >> k;
    vi c(n + 1), p(n + 1);
    vector<bool> vis(n+1, 0);
    for (int i = 1; i <= n; ++i) cin >> p[i];
    for (int i = 1; i <= n; ++i) cin >> c[i];
    ll res = -1e18;
    for (int i = 1; i <= n; ++i) {
        if (vis[i]) continue;
        int x = i;
        vi cycle;
        while (!vis[x]) {
            vis[x] = 1;
            cycle.push_back(x);
            x = p[x];
        }
        ll sum = 0;
        for (int v : cycle) sum += c[v];
        ll q = k / cycle.size();
        ll r = k % cycle.size();
        ll res_t = q * sum;
        int m = cycle.size();
        for (int i = 0; i < m; ++i) cycle.push_back(cycle[i]);
        ll sum_r = 0;
        if (q >= 1) res = max(res, res_t);
        for (int t = 1; t <= r; ++t) {
            sum_r = 0;
            for (int i = 0; i < 2 * m; ++i) {
                sum_r += c[cycle[i]];
                if (i >= t) sum_r -= c[cycle[i-t]];
                if (i < t - 1) continue;
                res = max(res, sum_r + res_t);
            }
        }
        if (q >= 1) res_t -= sum;
        for (int t = 1; t <= min(k, m); ++t) {
            sum_r = 0;
            for (int i = 0; i < 2 * m; ++i) {
                sum_r += c[cycle[i]];
                if (i >= t) sum_r -= c[cycle[i-t]];
                if (i < t - 1) continue;
                if (res_t >= 0) res = max(res, sum_r + res_t);
                else res = max(res, sum_r);
            }
        }
    }
    cout << res << endl;
    return 0;
}

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

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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = (int)s.size();
  ll cnt = 0, ans = 0;
  rep(i, n) {
    if (s[i] == 'W') {
      ans += i - cnt;
      cnt++;
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3740
/*
	Author      : akgarhwal
	Date        : 18-04-2017 14:30:04
	Description : 
*/

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

typedef long long 			ll;
typedef vector<int> 		vi; 
typedef pair<int,int> 		ii; 
#define sz(a) 				int((a).size()) 
#define pb 					push_back 
#define all(c) 				(c).begin(),(c).end() 
#define tr(c,i) 			for(auto i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) 		((c).find(x) != (c).end()) 
#define cpresent(c,x) 		(find(all(c),x) != (c).end())  

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

	int n,X,Y;
	cin>>n>>X>>Y;
	string s;
	cin>>s;
	int fy =0,sy=0;
	for(int i=0; i< sz(s); i++){
		if(s[i] == 'a' and (fy+sy) < (X+Y)){
			fy++;
			cout<<"Yes\n";
		}
		else if(s[i] == 'b' and (fy+sy) < (X+Y) and (sy) < Y ){
			cout<<"Yes\n";
			sy++;
		}
		else{
			cout<<"No\n";
		}

	}
	return 0;
}

Measured memory_bytes: 896
import sys

def insertionSort( nums, n, g ):
	cnt = 0
	i = g
	while i < n:
		v = nums[i]
		j = i - g
		while 0 <= j and v < nums[j]:
			nums[ j+g ] = nums[j]
			j -= g
			cnt += 1
		nums[ j+g ] = v
		i += 1
	return cnt
		
def shellSort( nums, n ):
	g = []
	val = 1
	while val <= n:
		g.append( val )
		val = 3*val+1
	
	g.reverse( )
	m = len( g )
	print( m )
	print( " ".join( map( str, g ) ) )
	cnt = 0
	for i in range( m ):
		cnt += insertionSort( nums, n, g[i] )
	print( cnt )
    
n = int( sys.stdin.readline( ) )
nums = []
for i in range( n ):
	nums.append( int( sys.stdin.readline( ) ) )

shellSort( nums, n )
print( "\n".join( map( str, nums ) ) )

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int N, M;
const int MAX = 1e5 + 1;


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

    cin >> N >> M;
    vector<map<int, int>> cnt(M);
    vector<int> cnt_all(M);
    
    rep(i, N) {
        int X; cin >> X;
        cnt[X % M][X]++;
        cnt_all[X % M]++;
    }

    int ans = 0;
    for (int i=0; i<=M/2; i++) {
        if (i == 0 || i*2 == M) {
            ans += cnt_all[i] / 2;
        } else {
            int a = i, b = M - i;
            if (cnt_all[a] < cnt_all[b]) swap(a, b);
            int ss = cnt_all[a], ts = cnt_all[b];
            int same_match_max = (ss - ts) / 2;
            map<int, int> S = cnt[a];
            for (auto s : S) {
               if (ss > ts && s.second > 1) {
                   int same_match = min(same_match_max, s.second/2);
                   same_match_max -= same_match;
                   ans += same_match;
               } 
            }
            ans += ts;
        }
        // DUMP2(i, ans);
    }

    cout << ans << endl;
}


Measured memory_bytes: 9984
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');

        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        int ans = 0;

        int ansA = a + b;
        int ansB = a - b;
        int ansC = a * b;

        if (ansA >= ansB && ansA >= ansC)
        {
            ans = ansA;
        }
        else if (ansB >= ansC && ansB >= ansA)
        {
            ans = ansB;
        }
        else
        {
            ans = ansC;
        }

        Console.Write(ans);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, a, b) for(int i = a; i >= b; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
const int INF = 1e9;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
int main() {
    int n;
    cin >> n;
    ll b[n];
    REP(i, n-1) cin >> b[i];
    ll sum = 0;
    sum = b[0] * 2;
    FOR(i, 1, n-1) {
        if(b[i] < b[i-1]) {
            sum -= b[i-1];
            sum += b[i];
        }
        sum += b[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
N = int(input())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def digit(n):
    i = 0
    while n != 0:
        n = n // 10
        i += 1
    return i

divisor_list = make_divisors(N)

length = len(divisor_list)

if length % 2 == 0:
    ans = max(digit(divisor_list[length//2 - 1]),digit(divisor_list[length//2]))
else:
    ans = digit(divisor_list[length//2])

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
using namespace std;
using ll = long long;

int main(){
    ll n;
    cin >> n;
    double a;
    int ans = 12;
    for(int b = 1; b <= sqrt(n); b++){
        a = n / (double)b;
        if(a != n / b) continue;
        int cnt = 0;
        while(a >= 1){
            cnt++;
            a /= 10;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import os

A = [0, 0]
B = [0, 0]
C = [0, 0]
D = [0, 0]

for s in sys.stdin:
    l, r = map(float, s.split())

    if l >= 1.1:
        A[0] += 1
    elif l >= 0.6:
        B[0] += 1
    elif l >= 0.2:
        C[0] += 1
    else:
        D[0] += 1

    if r >= 1.1:
        A[1] += 1
    elif r >= 0.6:
        B[1] += 1
    elif r >= 0.2:
        C[1] += 1
    else:
        D[1] += 1

print(*A)
print(*B)
print(*C)
print(*D)

Measured memory_bytes: 7360
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i <= 25; i++) {
    for (int j = 0; j <= 15; j++) {
      if (n == 4*i+7*j) {
	dump("Yes");
	return 0;
      }
    }
  }
  dump("No");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 100000
typedef long long ll;
int n, k;
ll T[MAX];

int check(ll P) { // k台以下で詰めるか？不足するならpを増やす十分すぎるならpを減らす
  int i = 0;
  for ( int j = 0; j < k; j++ ) {
    ll s = 0;
    while( s + T[i] <= P ) { // p以下である限り、積む。
      s += T[i];
      i++;
      if ( i == n ) return n;
    }
  }
  return i;
}

int solve(int sum){
  ll left = 0;
//  ll right = 100000 * 10000; // 荷物の個数k * 1個当たり最大重量
  ll right = sum;
  ll mid;
  while ( right - left > 1 ) { // binarySearch
    mid = (left + right) / 2;
    // mid == P を決めて左から何個積めるかチェック nなら全て。ダメならn未満
    int v = check(mid);
    if ( v >= n ) right = mid;
    else left = mid;
  }
  // right == left になったら、loopを抜けてright or mid or left を返す
  return right;
}

int main() {
  cin >> n >> k;
  int sum = 0;
  for ( int i = 0; i < n; i++ ) {
    cin >> T[i];
    sum += T[i];
  }
  ll ans = solve(sum);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3856
import java.util.Scanner;
public class Main{
static int[]check;//1=checked,0=yet,2=checking
static int[][]graph;
static int[][]hz;//[][0]:discovery [][1]:finishing
static int cnt=0,n;
final static int MAX=100;
	public static void main(String[] args) {
		int i,j,s,pn,num;
		// TODO Auto-generated method stub
		Scanner sca = new Scanner(System.in);
		n=sca.nextInt();
		check=new int[n+1];
		hz=new int[n+1][2];
		graph=new int[MAX+1][MAX+1];
		for(i=1;i<=n;i++){
			num=sca.nextInt();
			pn=sca.nextInt();
			for(j=0;j<pn;j++){
				s=sca.nextInt();
				graph[num][s]=1;
			}
		}
		explores();
		for(i=1;i<=n;i++){
				System.out.println(i+" "+hz[i][0]+" "+hz[i][1]);
		}

	}
	public static void explores(){
		int i;
		for(i=1;i<=n;i++){
			if(check[i]==0)expl(i);
		}
	}
	public static void expl(int now){
		int i;
		check[now]=2;
		hz[now][0]=++cnt;
		for(i=1;i<=n;i++){
			if(graph[now][i]==1&&check[i]==0)expl(i);
		}
		check[now]=1;
		hz[now][1]=++cnt;
	}

}



Measured memory_bytes: 28512
#include <iostream>
#include <cstring>
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;


int main() {
    int N;
    cin >> N;
    int ans = 0;
    if (N % 2 == 0) {
        ans = N /2;
    }
    else {
        ans = N/2 +1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		String s1=scan.nextLine();
		String s2=scan.nextLine();
		String s3=scan.nextLine();
		System.out.print(s1.charAt(0));
		System.out.print(s2.charAt(1));
		System.out.print(s3.charAt(2));
	}
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	cin>>n;
	vector<int> a(n+1);
	repi(i,1,n+1)cin>>a[i];

	vector<int> b(n+1,0);
	for (int i = n; i >=1; i--){
		int cnt=0;
		for (int j = i+i; j <= n; j+=i){
			cnt+=b[j];
		}
		if(cnt%2==0){
			if(a[i]==1) b[i]=1;
		}else{
			if(a[i]==0) b[i]=1;
		}
	}
	cout<<accumulate(all(b),0)<<endl;
	repi(i,1,n+1)if(b[i]>0)cout<<i<<endl;
	return 0;
}

Measured memory_bytes: 2432