akhauriyash/Code-Regression huggingface dataset:
#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 REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define pw(x) (1LL<<(x))
static const int fast_io = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();
static const int precise_doubles = [](){cout<<fixed<<setprecision(20);return 0;}();
typedef pair<int, int> PII;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) - iterator to kth largest, order_of_key(k) - #things < k
typedef long double LD;
typedef long long LL;
#define EVAL(x) x
#define SPA(x) EVAL({cout << #x" = " << x << ' ';})
#define NEWL EVAL({cout << '\n';})
#define SPAR(a, b) EVAL({cout<<#a" = ";for(auto it=a;it!=b;)cout<<*(it++)<<" ";cout<<'\n';})
#define SPAV(v) EVAL({cout<<#v" = ";for(auto it=v.begin();it!=v.end();)cout<<*(it++)<<" ";cout<<'\n';})
const int INF = 0x3f3f3f3f; // 1.0e9
const LL LINF = 0x3f3f3f3f3f3f3f3fll; // 4.5e18
const LD eps = 1e-20;
const int mod = 1e9 + 7;
inline int msum(int x, int y) {return (x+y<mod ? x+y : x+y-mod);}
inline int mdif(int x, int y) {return (x>=y ? x-y : x-y+mod);}
inline int mprod(int x, int y) { return (1ll*x*y) % mod; }
inline int mpow(int x, LL y) {LL r=1;while(y){if(y&1)r=mprod(r,x);x=mprod(x,x);y>>=1;}return r;}
inline int minv(int x) { return mpow(x, mod-2); }
#define DIE EVAL({cout << -1 << '\n'; exit(0);})
//------------------------------------------------------------------------------------------------------

const int N = 1e3 + 10;
int n, a, b, c, d;
int fac[N], ifac[N];

void pre() {
    fac[0] = ifac[0] = 1;
    FOR(i, 1, N) {
        fac[i] = mprod(fac[i-1], i);
        ifac[i] = minv(fac[i]);
    }
}

int getways(int sz, int groups_of_sz) {
    int ret = mprod(fac[sz * groups_of_sz], ifac[groups_of_sz]);
    ret = mprod(ret, minv(mpow(fac[sz], groups_of_sz)));
    return ret;
}

int Choose(int z, int k) {
    if(z < 0 or k < 0 or z < k) return 0;
    return mprod(fac[z], mprod(ifac[z-k], ifac[k]));
}

int main() {
    pre();
    cin >> n >> a >> b >> c >> d;
    vector<int> dp(n+1, 0);
    dp[0] = 1;
    FOR(sz, a, b+1) {
        vector<int> newdp(n+1, 0);
        FOR(people, 0, n+1) {
            newdp[people] = msum(newdp[people], dp[people]);
            FOR(groups_of_sz, c, d+1) {
                int new_people = people + sz * groups_of_sz;
                if(new_people > n) break;
                newdp[new_people] = msum(newdp[new_people],
                    mprod(getways(sz, groups_of_sz),
                        mprod(Choose(new_people, people), dp[people])));
            }
        }
        dp = newdp;
    }
    cout << dp[n] << '\n';
}






























Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 1e5 + 5;
vector <int> adj[MAX];
bool vis[MAX];
int dist[MAX], par[MAX];
void bfs(int x)
{
	vis[x] = true;
	queue <int> q;
	q.push(x);
	fill(dist, dist + MAX, inf);
	dist[x] = 0;
	while(!q.empty()){
		int p = q.front();
		q.pop();
		for(auto v : adj[p]) {
			if(!vis[v]) {
				vis[v] = true;
				q.push(v);
				if(dist[p] + 1 < dist[v]) {
					dist[v] = dist[p] + 1;
					par[v] = p;
				}
			}
		}
	}
}
int main()
{
	boost;
	int n, m, i, a, b;
	cin >> n >> m;
	fo(i, 0, m) {
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	bfs(1);
	foe(i, 1, n) {
		if(dist[i] == inf) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	foe(i, 2, n)
	cout << par[i] << '\n';
}


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

int main(){
  char c;
  cin >> c;
  if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll N=1e6;

int A[N], B[N], C[N];

int main(){
	fastio;
	int x, y; cin>>x>>y;
	int a,b,c; cin>>a>>b>>c;
	For(i,0,a) cin>>A[i];
	For(i,0,b) cin>>B[i];
	For(i,0,c) cin>>C[i];
	sort(A,A+a); reverse(A,A+a);
	sort(B,B+b); reverse(B,B+b);
	sort(C,C+c); reverse(C,C+c);
	priority_queue<int, vi, greater<int> > pq;
	For(i,0,x) pq.push(A[i]);
	For(i,0,y) pq.push(B[i]);
	For(i,0,c) if(C[i]>pq.top()){
		pq.pop();
		pq.push(C[i]);
	}else break;
	ll acum=0;
	while(!pq.empty()){
		acum+=pq.top();
		pq.pop();
	}
	cout << acum << endl;
	return 0;
}



Measured memory_bytes: 10996
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll X; cin >> X;
  ll res = 0;
  REP(i, 35) {
    RNG(j, 2, 11) {
      ll v = mod_pow((ll)i, (ll)j, DVSR);
      if (v <= X) {
        res = max(v, res);
      } else {
        break;
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define mkp make_pair
#define pb push_back
#define ll long long int
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll a[n+2],b[n+1];
    for(int i=0;i<=n;i++){cin>>a[i];}
    for(int i=0;i<n;i++){cin>>b[i];}
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]<=b[i])
        {
            ans+=(a[i]);
            b[i]-=a[i];
            if(a[i+1]<=b[i])
            {
                ans+=a[i+1];
                a[i+1]=0;
               
            }
            else
            {
                a[i+1]-=b[i];
                ans+=b[i];
            }
        }
        else{
            ans+=b[i];
        }
       // cout<<ans<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        var scaner = new Scanner(System.in);
        
        var k = scaner.nextInt();
        var s = scaner.next();

        if (s.length() > k) {
            System.out.println(s.substring(0, k)+"...");
        } else {
            System.out.println(s);
        }

        scaner.close();
    }

}


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

vector<string> fix(vector<string> v){
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	int bad[20] = {};
	for(int i = 0 ; i < v.size() ; i++){
		for(int j = 0 ; j < v.size() ; j++){
			if( i != j && ~v[i].find(v[j]) ){
				bad[j] = 1;
			}
		}
	}
	vector<string> res;
	for(int i = 0 ; i < v.size() ; i++){
		if( bad[i] == 0 ) res.push_back(v[i]);
	}
	return res;
}

int dp[1<<14][14];

int main(){
	int n;
	while(cin >> n && n){
		vector<string> v(n);
		for(int i = 0 ; i < n ; i++)
			cin >> v[i];
		v = fix(v);
		n = v.size();
		int g[20][20] = {};
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < n ; j++){
				int res = v[j].size();
				int len = min(v[i].size(),v[j].size());
				for(int k = 0 ; k < v[i].size() ; k++){
					string A = v[i].substr(k);
					if( A.size() > len ) continue;
					string B = v[j].substr(0,A.size());
					//cout << A << " " << B << endl;
					if( A == B ){
						res = min( res , (int)(v[j].size() - A.size()) );
					}
				}
				g[i][j] = res;
				//cout << i << "," << j << " = " << g[i][j] << endl;
			}
		}
		for(int i = 0 ; i < (1<<14) ; i++)
			for(int j = 0 ; j < 14 ; j++)
				dp[i][j] = 1e9;
		for(int i = 0 ; i < n ; i++){
			dp[(1<<i)][i] = v[i].size();
		}
		for(int i = 0 ; i < (1<<n) ; i++){
			for(int j = 0 ; j < n ; j++){
				if( dp[i][j] > 1e8 ) continue;
				for(int k = 0 ; k < n ; k++){
					dp[i|(1<<k)][k] = min( dp[i|(1<<k)][k] , dp[i][j] + g[j][k] );
				}
			}
		}
		int ans = 1e9;
		for(int i = 0 ; i < n ; i++){
			ans = min(ans,dp[(1<<n)-1][i]);
		}
		cout << ans << endl;
		
	}
}

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


int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    int ans = 0;
    rep(i,h) cin >> s[i];
    rep(is, 1 << h)rep(js, 1 << w) {
        int cnt = 0;
        rep(i,h)rep(j,w){
            if(is >> i & 1 or js >> j & 1) continue;
            if(s[i][j] == '#') cnt++;
        }
        if(cnt == k) ans++;
    }

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

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

vector <pair<int,pair<int,string> > > v; //replyTo, (depth, M)


void put_dots(int n){
  for(int i = 0; i < n; i++){
    cout << ".";
  }
}

void output(int n){
  put_dots(v[n].second.first);

  cout << v[n].second.second << endl;
  for(int i = n; i < v.size(); i++){
    if(v[i].first == n) output(i);
  }
}

int main(){
  int n, k;
  string M;
  pair<int, pair<int, string> > p;

  cin >> n;
  cin >> k >> M;
  p = make_pair(-1, make_pair(0,M));
  v.push_back(p);

  for(int i = 1; i < n; i++){
    int depth;
    cin >> k >> M;
    k--;
    depth = v[k].second.first + 1;
    p = make_pair(k, make_pair(depth, M));
    v.push_back(p);
  }

  output(0);
  
}

Measured memory_bytes: 1384
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG arc/arc096/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll ans = 0;
    if(2 * c <= a + b){
        if(x < y){
            ans += 2 * c * x;
            ans += (y - x) * min(b, 2 * c);
        }else{
            ans += 2 * c * y;
            ans += (x - y) * min(a, 2 * c);
        }
    }else{
        ans += a * x + b * y;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
def f(a,b,c):
    return a*b<100*c
m,rd,rr,cd,cr=map(int,input().split())
ex=cd*100//rd
if(f(ex,rd,cd)):ex+=1
ey=cr*100//rr
if(f(ey,rr,cr)):ey+=1
print(m-ex-ey if m-ex-ey>=0 else -1)

Measured memory_bytes: 7748
s = gets.chomp
s.reverse!
words = ["dream", "dreamer", "erase", "eraser"].map {|s| s.reverse }
until s.empty?
  reduce = false
  words.each do |v|
    if s.index(v) == 0
      s = s[v.length, s.length - v.length]
      reduce = true
      break
    end
  end

  unless reduce
    puts "NO"
    exit 0
  end
end
puts "YES"


Measured memory_bytes: 2812
#include <iostream>
#include <math.h>

int main() {
	using namespace std;
	long i,n,tyul,to=0, hyo=0;
	double tyu;
	cin >> n;
	long k[n];


	for (i = 0; i < n; i++) {
		cin >> k[i];
		to += k[i];
	}
	tyu = (double) to / n;
	tyul = round(tyu);

	for (i = 0; i < n; i++) {
		hyo += pow(k[i]-tyul , 2);
	}

	cout << hyo << endl;
	return 0;
}

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

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

int main() {
	ll N, bottleneck = LONG_MAX;
	cin >> N;
	for(int i = 0; i < 5; i++) {
		ll capacity;
		cin >> capacity;
		bottleneck = min(bottleneck, capacity);
	}
	ll ans = (N - 1) / bottleneck + 5;
	cout << ans << endl;
}


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

int main() {
    int n, m;
    int l[101000];
    int r[101000];
    int ans = 0;
    int l_max = -1;
    int r_min = INT_MAX;
    
    cin >> n >> m;
    
    for (int i = 0; i < m; i++) {
        cin >> l[i] >> r[i];
    }
    
    for (int i = 0; i < m; i++) {
        l_max = max(l_max, l[i]);
        r_min = min(r_min, r[i]);
    }
    
    if ((l_max > r_min)) {
        ans = 0;
    }
    else if (l_max > n) {
        ans = 0;
    }
    else if ((l_max <= n) && (r_min >= n)) {
        ans = n - l_max + 1;
    }
    else {
        ans = r_min - l_max + 1;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int[] sums = new int[n];
        for (int i = 1; i < n; i++) {
            for (int j = i + 1; j <= n; j++) {
                int dis = Math.min(j - i, Math.abs(x - i) + 1 + Math.abs(y - j));
                sums[dis]++;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i < n; i++) {
            sb.append(sums[i]).append("\n");
        }
        System.out.print(sb);
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<cstring>

namespace Q_Q//>_< QAQ
{
	const int N=101000;

	struct exdus
	{
		int fa[N],w[N];
		void reset(int n){for(int i=1;i<=n;i++)fa[i]=i,w[i]=0;}
		int ask(int p)
		{
			if(p==fa[p])return p;
			int h=fa[p],ret=ask(h);
			w[p]=w[p]^w[h],fa[p]=fa[h];
			return ret;
		}
		void link(int u,int v)
		{
			int fu=ask(u),fv=ask(v);
			fa[fu]=fv,w[fu]=w[u]^w[v]^1;
		}
	}d;

	bool ty[N];
	int n;

	struct tree
	{
		int begin[N],next[N],to[N];
		int cson[N];
		int root,e;
		void add(int x,int y)
		{
			to[++e]=y;
			next[e]=begin[x];
			begin[x]=e;
		}
		void reset()
		{
			for(int i=1,x;i<=n;i++)
			{
				scanf("%d",&x);
				if(x<0)root=i;
				else add(x,i),cson[x]++;
			}
		}
		int dfs(int p)
		{
			int ret=0;
			for(int i=begin[p],x;i;i=next[i])
			{
				x=dfs(to[i]);
				if(!ret)ret=x;
				else d.link(x,ret),ret=0;
			}
			if(ty[p])ret=p;
			return ret;
		}
		inline void work(){dfs(root);}
	}T0,T1;

	bool initialize()
	{
		scanf("%d",&n);
		T0.reset(),T1.reset();
		for(int i=1;i<=n;i++)
		{
			ty[i]=T0.cson[i]&1;
			if(ty[i]!=(T1.cson[i]&1))return 0;
			ty[i]^=1;
		}
		d.reset(n);
		return 1;
	}

	int ans[N];
	
	void solve()
	{
		if(!initialize()){printf("IMPOSSIBLE\n");return;}

		T0.work(),T1.work();
		for(int i=1;i<=n;i++)
			if(!ty[i])ans[i]=0;
			else if(d.fa[i]==i)ans[i]=1;
		for(int i=1;i<=n;i++)
			if(ty[i] && d.fa[i]!=i)
				ans[i]=ans[d.ask(i)]*(d.w[i]?-1:1);

		printf("POSSIBLE\n");
		for(int i=1;i<=n;i++)
			printf("%d ",ans[i]);
		printf("\n");
	}
}

int main()
{
	Q_Q::solve();
	return 0;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    auto c = make_vec<int>(3, 3);
    REP(i, 3) {
        REP(j, 3) { cin >> c[i][j]; }
    }
    bool flag = true;
    REP(i, 2) {
        REP(j, 2) {
            if (c[i][j] - c[i + 1][j] != c[i][j + 1] - c[i + 1][j + 1]) {
                flag = false;
            }
            if (c[i][j] - c[i][j + 1] != c[i + 1][j] - c[i + 1][j + 1]) {
                flag = false;
            }
        }
    }
    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

vector<long>l(51),p(51);
long f(long n,long x){
  if(n==0){
    if(x<=0){
      return 0;
    }
    else{
      return 1;
    }
  }
  else if(x<=1+l.at(n-1)){
    return f(n-1,x-1);
  }
  else{
    return p.at(n-1)+1+f(n-1,x-2-l.at(n-1));
  }
}
int main() {
  long n,x;
  cin >>n>>x;
  l.at(0)=1;
  p.at(0)=1;
  rep2(i,1,51){
    l.at(i)=2*l.at(i-1)+3;
    p.at(i)=2*p.at(i-1)+1;
  }
  
  cout<<f(n,x)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
const ll inf = 1001001001;
const ll mod = 1000000007;
 
int main() {
    int n;
    cin >> n;
    vector<ll>divi(n);
    rep(i, 2, n+1){
        //iの約数の個数を数える
        int temp = i;
        sqrep(j, 2, i){
            while(temp%j ==0){
                temp /= j;
                divi[j-1]++;
            }
        }
        if(temp != 1)divi[temp-1]++;
    }
    ll ans = 1;
    rep(i, 1, n){
        ans = (ans*(divi[i]+1))%mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
  string s,ans="keyence";
  cin>>s;
  bool flag=false;

  rep(i,s.size())
  for(int j=i;j<s.size();j++){
    string tmp="";
    rep(k,i) tmp+=s[k];
    for(int k=j+1;k<s.size();k++) tmp+=s[k];

    if(tmp==ans) flag=true;
  }

  if(flag || s==ans) cout<<"YES";
  else cout<<"NO";
}

Measured memory_bytes: 256
n,k=gets.split.map(&:to_i)
arr=diff=[]
n.times { arr << gets.to_i }
arr.sort!
v=arr[-1]-arr[0]
 
(0..n-k).each do |i|
  diff = arr[i+k-1] - arr[i]
  v = [diff, v].min
end
puts v

Measured memory_bytes: 4016
N, *P = map(int, open(0).read().split())

min_v = 10 ** 6
max_v = 0
ans = 0
for i in range(N):
    if P[i] < min_v:
        ans += 1
        min_v = P[i]
    elif P[i] > max_v:
        max_v = P[i]
        
print(ans)


Measured memory_bytes: 84996
#define LOCAL
#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 rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

ll dp[MAX * 2];
vector<int> g[MAX * 2];
vector<pair<ll, ll> > ans;

void solve(int v, int bef, ll sum){
  sum += dp[v];
  ans.push_back({v, sum});
  for(int u : g[v]){
    if(u == bef) continue;
    solve(u, v, sum);
  }
}

int main(int argc, const char * argv[]) {
  std::cout << std::fixed << std::setprecision(15);

  int N, M; cin >> N >> M;
  rep(i, N-1){
    int a, b; cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  memset(dp, 0, sizeof(dp));

  rep(i, M){
    ll p, x; cin >> p >> x;
    p--;
    dp[p] += x;
  }

  solve(0, -1, 0);
  sort(ALL(ans));
  rep(i, ans.size()){
    if(i) cout << " ";
    cout << ans[i].second;
  }
  cout << endl;
}  


Measured memory_bytes: 31344
#include <iostream>
#include <vector>
#include <map> 
#include <algorithm>
#include <cstring>

#define ll long long
using namespace std; 

void solve(){
  int H,W; 
  int mod= 1e9+7;
  cin>> H >> W; 
  char matrix[H][W]; 
  for(int i=0;i<H; i++){
    for (int j = 0; j < W; j++){
      cin >> matrix[i][j];
    }
  }
  long dp[H][W]; 
  dp[H-1][W-1] = 1; 
  for(int i=W-2; i>=0; i--){
    dp[H-1][i] = dp[H-1][i+1]; 
    if(matrix[H-1][i]=='#')
      dp[H-1][i] = 0;  
  }
  for(int i=H-2; i>=0; i--){
    dp[i][W-1] = dp[i+1][W-1];
    if(matrix[i][W-1] == '#')
      dp[i][W-1] = 0; 
  }
  for(int i=H-2; i>=0; i--){
    for(int j=W-2; j>=0; j--){
      dp[i][j] = (dp[i+1][j] + dp[i][j+1])%mod; 
      if(matrix[i][j]=='#')
        dp[i][j] = 0; 
    }
  }
  cout << dp[0][0] << "\n"; 
}

int main(){
  int t=1; 
  // cin>>t; 
  while(t--){
    solve(); 
  }
 return 0;
}

Measured memory_bytes: 12380
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

using namespace std;

vector<string> field;
int w,h;

int bfs(int sx,int sy){

	bool passed[21][21];
	for(int i = 0; i < 21; i++)
		fill(passed[i],passed[i]+21,false);

	queue<pair<int,int> > *prv = new queue<pair<int,int> >();
	queue<pair<int,int> > *nxt = new queue<pair<int,int> >();

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

	prv->push(make_pair(sy,sx));
	while(prv->size()){
		while(prv->size()){
			pair<int,int> cp = prv->front();prv->pop();
			if(passed[cp.first][cp.second])
				continue;
			passed[cp.first][cp.second] = true;
			for(int i = 0; i < 4; i++){
				pair<int,int> np = cp;
				np.first += dy[i];
				np.second += dx[i];
				// ツ各ツ陛サツ古シツづ鳴暗堋督ョ
				if(np.first >= 0 && np.second >= 0 && np.first < h && np.second < w){
					if(passed[np.first][np.second] || field[np.first][np.second] == '#')
						continue;
					nxt->push(np);
				}
			}
		}
		swap(prv,nxt);
	}

	delete prv,nxt;

	int cnt = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(passed[i][j])
				cnt++;
		}
	}

	return cnt;
}

int main(){

	while(cin >> w >> h && !(w == 0 && h == 0)){
		int sx,sy;
		for(int i = 0; i < h; i++){
			string str;
			cin >> str;
			field.push_back(str);
			for(int k = 0; k < str.size(); k++){
				if(str[k] == '@'){
					sx = k;
					sy = i;
				}
			}
		}
		cout << bfs(sx,sy) << endl;

		field.clear();
	}

	return 0;
}

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

using namespace std;

typedef long long ll;

ll Solve(ll n)
{
    if(!n)  return 0;

    return 1 + 2 * Solve(n / 2);
}

int main()
{
    ll n;   cin >> n;

    cout << Solve(n) << endl;
}


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

const int MOD = 1e9 + 7;
std::map<std::pair<long long, long long>, int> dp;

long long dfs(long long A, long long B){
	if(dp.count({A, B})) return dp[{A, B}];
	
	long long ret = dfs(A / 2, B / 2);
	if(A > 0 and B > 0) ret += dfs((A - 1) / 2, (B - 1) / 2); ret %= MOD;
	if(A > 1) ret += dfs((A - 2) / 2, B / 2); ret %= MOD;
	
	return dp[{A, B}] = ret;
}

int main(){
	long long n; std::cin >> n; dp[{0, 0}] = 1;
	
	std::cout << dfs(n, n) << std::endl;
	return 0;
}


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


using namespace std;

int main(){
    int N, input;
    cin >> N;
    vector<long long> A;
    for(int i = 0; i < N; i++){
        cin >> input;
        A.push_back(input);
    }
    std::sort(A.begin(), A.end());
    cout << A[N - 1] - A[0] << endl;
}

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

int main() {
  int N,R,r;
  cin >> N >> R;
	if(N >= 10){
    	r = R;
      	cout << r <<endl;
    }else{
    	r=100*(10-N)+R;
        cout << r <<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int diff_height[13] = {0,0,1,0,1,1,1,0,-1,1,-1,1,1};
int diff_row[13]    = {0,1,0,1,0,1,1,-1,1,0,1,-1,1};
int diff_col[13]    = {1,0,0,1,1,0,1,1,0,-1,1,1,-1};

int N,M,Q;

bool rangeCheck(int height,int row,int col){
	if(height >= 0 && height <= N-1 && row >= 0 && row <= N-1 && col >= 0 && col <= N-1)return true;
	else{
		return false;
	}
}

void func(){

	char board[N][N][N];

	for(int h = 0; h < N; h++){
		for(int row = 0; row < N; row++){
			for(int col = 0; col < N; col++){
				board[h][row][col] = '*';
			}
		}
	}

	int pile_num[N][N];
	for(int row = 0; row < N; row++){
		for(int col = 0; col < N; col++){
			pile_num[row][col] = 0;
		}
	}

	char which = '*';
	int ans;

	int input_col,input_row,tmp_height,tmp_row,tmp_col,num;
	bool clearFLG = false;

	char base_color;

	for(int loop = 1; loop <= Q; loop++){
		scanf("%d %d",&input_col,&input_row);
		input_row--;
		input_col--;

		if(pile_num[input_row][input_col] == N)clearFLG = true;

		if(clearFLG)continue;

		if(loop%2 == 1){
			board[pile_num[input_row][input_col]++][input_row][input_col] = 'b';
		}else{
			board[pile_num[input_row][input_col]++][input_row][input_col] = 'w';
		}

		for(int height = 0; height < N; height++){
			for(int row = 0; row < N; row++){
				for(int col = 0; col < N; col++){
					if((loop%2 == 1 && board[height][row][col] != 'b') || (loop%2 == 0 && board[height][row][col] != 'w'))continue;

					base_color = (loop%2 == 1) ? 'b':'w';

					for(int i = 0; i < 13; i++){

						tmp_height = height;
						tmp_row = row;
						tmp_col = col;

						num = 0;

						do{
							num++;

							tmp_height += diff_height[i];
							tmp_row += diff_row[i];
							tmp_col += diff_col[i];

						}while(rangeCheck(tmp_height,tmp_row,tmp_col) == true && board[tmp_height][tmp_row][tmp_col] == base_color);

						if(num >= M){
							clearFLG = true;
							break;
						}
					}
					if(clearFLG)break;
				}
				if(clearFLG)break;
			}
			if(clearFLG)break;
		}

		if(clearFLG){

			if(loop%2 == 1){
				which = 'b';
			}else{
				which = 'w';
			}
			ans = loop;
		}
	}

	switch(which){
	case '*':
		printf("Draw\n");
		break;
	case 'b':
		printf("Black %d\n",ans);
		break;
	case 'w':
		printf("White %d\n",ans);
		break;
	}
}


int main(){

	while(true){
		scanf("%d %d %d",&N,&M,&Q);
		if(N == 0 && M == 0 && Q == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3172
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    ll n; cin>>n;
    ll ans=0;
    for(ll i=1; i*i<n; i++){
        if(n%i!=0) continue;
        if(n/i-i>1){
            ans+=(n/i-1);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(void){
    int n,a,ans;
    cin>>n;
    ans = 30;
    for(int i=0;i<n;i++){
        cin>>a;
        int j=0;
        while( a%2 == 0){
            a /= 2;
            j ++;
        }
        ans = min(ans,j);
        if(ans == 0) break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        final FastReader s=new FastReader();
        int n = s.nextInt();
        int x = s.nextInt();
        int t = s.nextInt();
        int res = (n/x)*t;
        if(n%x!=0) res+=t;

        System.out.println(res);
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
        public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try { st = new StringTokenizer(br.readLine()); }
                catch (final IOException  e) { e.printStackTrace(); }
            }
            return st.nextToken();
        }
        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() { return Long.parseLong(next()); }
        double nextDouble() { return Double.parseDouble(next()); }
        String nextLine() {
            String str = "";
            try { str = br.readLine(); }
            catch (final IOException e) { e.printStackTrace(); }
            return str;
        }
    }
}

Measured memory_bytes: 25352
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>> 
#define vi vector<int> 
#define vpii vector<pair<int,int>> 
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(int i = 0; i < n; ++i)
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N,W;
    cin >> N >> W;
    vector<int> wt(N),val(N);
    for(int i = 0; i < N ; ++i)
    {
        cin >> wt[i] >> val[i];
    }
    vector<vector<int>> dp(N + 1,vector<int>(W + 1));

    vector<int> dp1(W + 1),dp2(W + 1);
    for(int i = 1; i <= N; ++i)
    {
        for(int j = 0; j <= W; ++j)
        {
            dp2[j] = dp1[j];
            if(j - wt[i - 1] >= 0)
            {
                dp2[j] = max(dp2[j],dp1[j - wt[i - 1]] + val[i - 1]);
            }
        }
        dp1 = dp2;
    }
    cout << dp2[W];
}

Measured memory_bytes: 81008
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int m = fs.nextInt();
		long sum = 0;
		long digit = 0;
		for(int i=0;i<m;i++) {
			int d = fs.nextInt();
			long c = fs.nextLong();
			digit += c; //桁数
			long t = c * d;
			sum += t;
		}
		long ans = (sum-1)/9 + digit - 1;
		System.out.println(ans);
		
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}


Measured memory_bytes: 44068
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

ll N, M;

int main(){
	cin >> N >> M;
	priority_queue<ll> A;
	rep(i, N) {
		ll a;
		cin >> a;
		A.push(a);
	}

	while(M) {
		ll a = A.top();
		A.pop();
		A.push(a/2);
		M--;
	}

	ll ans = 0;
	while(!A.empty()) {
		ll a = A.top();
		A.pop();
		ans += a;
	}
	cout << ans << endl;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int m = max(a, max(b, c));
  cout << (a + b + c - m) + m * pow(2, k) << "\n";
}


Measured memory_bytes: 384
n = input()

if (n[0] == '1'):
	n = '9' + n[1] + n[2]
elif (n[0] == '9'):
	n = '1' + n[1] + n[2]

if (n[1] == '1'):
	n = n[0] + '9' + n[2]
elif (n[1] == '9'):
	n = n[0] + '1' + n[2]

if (n[2] == '1'):
	n = n[0] + n[1] + '9'
elif (n[2] == '9'):
	n = n[0] + n[1] + '1'

print(n)


Measured memory_bytes: 3064
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

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

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")



/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main() { 
  long long n,k;cin>>n>>k;
  vector<long long> a(n);
  for(int i = 0; n > i; i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end(),greater<int>());
  long long ans = 0;
  for(int i = k; n > i; i++)ans += a[i];
  cout << ans << endl;
}

Measured memory_bytes: 1792
import sys
H, N = map(int, input().split())
data = [int(i) for i in input().split()]
DATA = sorted(data, reverse=True)
count = 0
 
for i in range(N):
  H = H - DATA[i]
  if H <= 0:
    print("Yes")
    sys.exit()
else:
  print("No")

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

#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define fst first
#define snd second

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<int>> a(3, vector<int>(n));
    for (int i = 0; i < n; i++)
    {
        cin >> a[0][i] >> a[1][i] >> a[2][i];
    }
    vector<vector<ll>> dp(3, vector<ll>(n));
    dp[0][0] = a[0][0];
    dp[1][0] = a[1][0];
    dp[2][0] = a[2][0];
    for (int i = 1; i < n; i++)
    {
        for (int cur = 0; cur < 3; cur++)
        {
            for (int prev = 0; prev < 3; prev++)
            {
                if (cur != prev)
                {
                    dp[cur][i] = max(dp[cur][i], dp[prev][i - 1] + a[cur][i]);
                }
            }
        }
    }
    cout << max({dp[0][n - 1], dp[1][n - 1], dp[2][n - 1]});
    return 0;
}

Measured memory_bytes: 4600
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define yes cout<<"yes"<<'\n'
#define no cout<<"no"<<'\n'
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    VI a(n); REP(i,n) cin >> a[i];
    int ans = 0;
    bool ok = 1;
    while(ok){
        REP(i,n){if(a[i]%2==0)a[i]/=2; else ok = 0;}
        if(ok) ans++;
    }
    out(ans);

    return 0;
}

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

void solve()
{
    int n, m;
    cin >> n >> m;

    vector<int> adj[n];
    while(m--)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    queue<int> q;
    bool visited[n] = {0};
    int distance[n] = {};
    q.push(0);
    visited[0] = true;

    while(!q.empty())
    {
        int s = q.front(); q.pop();
        for(int u :adj[s])
        {
            if(visited[u]) continue;
            visited[u] = true;
            distance[u] = s;
            q.push(u);
        }
    }
    for(bool b :visited)
    {
        if(b == false)
        {
            cout << "No" << endl;
            break;
        }
    }
    cout << "Yes" << endl;
    for(int i = 1; i<n; i++)
    {
        cout <<  distance[i]+1 << endl;
    }

}


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


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

using ll = long long;

int main()
{
    int N, A, B; cin >> N >> A >> B;

    auto best = vector<ll>(B+1), ways = vector<ll>(B+1);
    ways[0] = 1;
    for (auto i = 0; i < N; i++)
    {
        ll x; cin >> x;

        for (auto k = B; k >= 1; k--) if (ways[k-1] != 0)
        {
            if (best[k-1] + x > best[k])
            {
                best[k] = best[k-1] + x;
                ways[k] = ways[k-1];
            }
            else if (best[k-1] + x == best[k])
                ways[k] += ways[k-1];
        }
    }

    auto numerator = 0LL, denominator = 1LL, total_ways = 1LL;
    for (auto k = A; k <= B; k++)
    {
        if (best[k] * denominator > numerator * k)
        {
            numerator = best[k];
            denominator = k;
            total_ways = ways[k];
        }
        else if (best[k] * denominator == numerator * k)
            total_ways += ways[k];
    }

    cout << fixed << setprecision(6) << double(numerator)/double(denominator) << endl;
    cout << total_ways << endl;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- replicateM n $ readLn :: IO [Int]
  putStr . unlines . map show $ solve n as

solve n as
  | mx == mx2 = replicate n mx
  | otherwise = [ if a == mx then mx2 else mx | a <- as]
  where
    mx = maximum as
    mx2 = maximum $ delete mx as



Measured memory_bytes: 62076
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  string S;
  cin>>S;
  int N=S.size();
  vector<int> A(N+1,0),B(N+1,0);
  for(int i=0;i<N;i++){
    if(S[i]=='<')
      A[i+1]=A[i]+1;
    else
      A[i+1]=0;
  }
  for(int i=N;i>0;i--){
    if(S[i-1]=='>')
      B[i-1]=B[i]+1;
    else
      B[i-1]=0;
  }
  int ans=0;
  for(int i=0;i<=N;i++)
    ans+=max(A[i],B[i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 11692
N, Q = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N - 1)]
P = [list(map(int, input().split())) for _ in range(Q)]
G = [[] for _ in range(N + 1)]
X = [0] * (N + 1)
for a, b in L:
    G[a].append(b)
for p, x in P:
    X[p] += x
for a, A in enumerate(G):
    for b in A:
        X[b] += X[a]
print(" ".join(map(str, X[1:])))


Measured memory_bytes: 139616
#include<bits/stdc++.h>
using namespace std;
int main()
{
	bool flag=false;
	string A,B;
	int a,b,k,b1;
	cin>>A>>B;
	b1=B.length();
	a=atoi(A.c_str());
	b=atoi(B.c_str());
	k=(pow(10,b1))*a+b;
	for(int i=1;i<=k;i++)
		if(i*i==k) flag=true;
	if(flag==true) cout<<"Yes"<<endl;
	else cout<<"No"<<endl; 
	return 0;
}

Measured memory_bytes: 512
N, K = gets.split.map(&:to_i)
S = gets.chomp.chars
n = 0
ok_count = 0
prev = nil
S.each do |ch|
  if ch == prev
    ok_count += 1
  else
    n += 1
  end
  prev = ch
end
diff = [n - 1, K * 2].min
ans = ok_count + diff
puts ans


Measured memory_bytes: 6908
// 5/4
// 過去問ガリガリ

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

int main() {
    int N;
    cin >> N;
    
    vector<int> X(N);
    rep(i, N) cin >> X[i];

    int ans = 100000000;

    for (int p = 1; p <= 100; p++) {
        int dist = 0;

        rep(i, N) {
            dist += pow(X[i] - p, 2.0);
        }

        ans = min(ans, dist);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	char[] arr = sc.next().toCharArray();
    	int sum = 0;
    	for (char c : arr) {
    	    sum += c - '0';
    	    sum %= 9;
    	}
    	if (sum == 0) {
    	    System.out.println("Yes");
    	} else {
    	    System.out.println("No");
    	}
    }
}



Measured memory_bytes: 40652
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		execute7_2();
	}
	
	

	private static void execute7_2() {
		try (Scanner sc = new Scanner(System.in)) {
			int N = sc.nextInt();

			Long s[] = new Long[N];

			for (int i = 0; i < N; i++) {
				s[i]=sc.nextLong();
			}
			
			Arrays.sort(s, Comparator.reverseOrder());
			

			boolean d=false;
			for (int i = 1; i < N; i++) {
				if(s[i-1].equals(s[i])) {
					d=true;
					break;
				}
			}
			
			if(d) {
				System.out.println("NO");
			} else {
				System.out.println("YES");
			}
			
		}
	}
}

Measured memory_bytes: 95852
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll N=5000*5000+5;
const ld pi=3.14159265359;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()

ll n,a[3],b[3],dp[N];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	REP(i,3)cin>>a[i];
	REP(i,3)cin>>b[i];
	dp[0]=0;
	REP1(i,n){
		dp[i]=i;
		REP(j,3){
			if(i>=a[j])dp[i]=max(dp[i],dp[i-a[j]]+b[j]);
		}
	}
	n=dp[n];
	REP1(i,n){
		dp[i]=i;
		REP(j,3){
			if(i>=b[j])dp[i]=max(dp[i],dp[i-b[j]]+a[j]);
		}
	}
	cout<<dp[n]<<"\n";	
	return 0;
}



Measured memory_bytes: 195584