akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(int argc, char** argv) {
	int n;
	while(scanf("%d",&n)!=EOF)
	{
	 bool flag=false;
	 while(n)
	  {int k;
	   k=n%10;
	   if(k==9)
	    {flag=true;
	     break;
	    }
	   n=n/10;
	  }
	 if(!flag)
	  printf("No\n");
	 else 
	  printf("Yes\n");
   }
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)

int main(){
  ll n,a[100010],b[100010],s=0,k;
  cin>>n;
  fr(i,n){
    cin>>a[i];
    s+=a[i];
  }
  if(s%((n*(n+1))/2)>0){
    cout<<"NO"<<endl;
    return 0;
  }
  k=s/((n*(n+1))/2);
  fr(i,n) b[i]=a[i]-a[(i+1)%n]+k;
  bool f=0;
  fr(i,n) if(b[i]<0 || b[i]%n>0) f=1;
  cout<<(f?"NO":"YES")<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 200005

// it's swapnil07 ;)

vector<int> adj[26];


signed main(){
    fast
    #ifdef SWAPNIL07
        freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
        freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
    #endif
    string s, t; cin>>s>>t;
    For(i, 0, s.length()){
        int x = s[i]-'a';
        adj[x].pb(i+1);
    }
    int prev = 0;
    int ct = 0;
    int pp;
    For(i, 0, t.length()){
        int x = t[i]-'a';
        if(adj[x].size()==0){
            cout<<-1;
            return 0;
        }
        pp = upper_bound(all(adj[x]), prev) - adj[x].begin();
        if(pp == adj[x].size()){
            ct++;
            prev = 0;
        }
        else{
            prev = adj[x][pp];
            continue;
        }
        pp = upper_bound(all(adj[x]), prev) - adj[x].begin();
        prev = adj[x][pp];
    }
    int ans = ct*(s.length()) + prev;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
    string w;
    cin >> w;

    map<int, int> m;
    for (int i = 0; i < static_cast<int>(w.size()); i++) {
        m[w[i]]++;
    }

    bool res = true;
    for (map<int, int>::iterator i = m.begin(); i != m.end(); i++) {
        res = res && (i->second % 2 == 0);
    }

    cout << (res ? "Yes" : "No") << endl;
}


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

using namespace std;

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

    int visible = 2 * D + 1;
    int ans;

    if (N % visible != 0)
    {
        ans = N / visible + 1;
    }
    else
    {
        ans = N / visible;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=300;
int N,M;
const ll MOD=1e9+7;
typedef pair<int,int> P;
vector<P> con[MAX_N+1];
ll dp[MAX_N+1][MAX_N+1][MAX_N+1];
ll dfs(int i,int r,int g,int b){
	if (dp[r][g][b]!=-1){
		return dp[r][g][b];
	}
	ll ret=0;
	REP(j,(int)con[i-1].size()){
		P p=con[i-1][j];
		int cnt=0;
		if (p.first<=r){
			cnt++;
		}
		if (p.first<=g){
			cnt++;
		}
		if (p.first<=b){
			cnt++;
		}
		if (cnt!=p.second){
			return dp[r][g][b]=0;
		}
	}
	if (i==N+1){
		return dp[r][g][b]=1;
	}
	ret=dfs(i+1,i,g,b);
	ret%=MOD;
	ret+=dfs(i+1,r,i,b);
	ret%=MOD;
	ret+=dfs(i+1,r,g,i);
	ret%=MOD;
	return dp[r][g][b]=ret;
}
int main(){
	cin>>N>>M;
	REP(i,M){
		int l,r,x;
		cin>>l>>r>>x;
		con[r].push_back(P(l,x));
	}
	memset(dp,-1,sizeof(dp));
	cout<<dfs(1,0,0,0)<<endl;
	return 0;
}

Measured memory_bytes: 213376
N, K, L = gets.split.map(&:to_i)
edges = Array.new(N+1){Hash.new}
K.times do |i|
    pp, q = gets.split.map(&:to_i)
    edges[pp][q] = 1
    edges[q][pp] = 1
end

group1 = Array.new(N+1)
g = 0

(1..N).each do |i|
    next if group1[i]
    g = i
    group1[i] = g
    updated = [i]
    while updated.length > 0
        nup = []
        updated.each do |s|
            edges[s].each do |d, _|
                next if group1[d]
                group1[d] = g
                nup.push(d)
            end
        end
        updated = nup
    end
end

edges = Array.new(N+1){Hash.new}

L.times do |i|
    r, s = gets.split.map(&:to_i)
    edges[r][s] = 1
    edges[s][r] = 1
end

group2 = Array.new(N+1)
g = 0

(1..N).each do |i|
    next if group2[i]
    g = i
    group2[i] = g
    updated = [i]
    while updated.length > 0
        nup = []
        updated.each do |s|
            edges[s].each do |d, _|
                next if group2[d]
                group2[d] = g
                nup.push(d)
            end
        end
        updated = nup
    end
end

hash = {}
code = Array.new(N + 1)
(1..N).each do |i|
    code[i] = group1[i] * (1<<64) + group2[i]
end 
(1..N).each do |i|
    hash[code[i]] ||= 0
    hash[code[i]] += 1
end

ans = []
(1..N).each do |i|
    ans[i] = hash[code[i]]
end

puts ans[1..N].join(' ')

Measured memory_bytes: 163912
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 100000
using namespace std;
typedef long long int ll;

int main(){
    string A;
    cin >> A;
    reverse(A.begin(), A.end());
    cout << A <<endl;
}

Measured memory_bytes: 1172
#include "bits/stdc++.h"
using namespace std;
int N;
vector<int>to[100005];
vector<int>dist;
void dfs(int v, int d = 0, int p = -1) {
	dist[v] = d;
	for (int e : to[v]) {
		if (p == e) {
			continue;
		}
		dfs(e, d + 1, v);
	}
}
vector<int>f(int x) {
	dist = vector<int>(N);
	dfs(x);
	return dist;
}

int main() {
	cin >> N;
	for (int n = 0; n < N - 1; ++n) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	vector<int>DistU = f(0);
	vector<int>DistV = f(N-1);
	int ans = 0;
	int ans2 = 0;
	for (int n = 0; n < N; ++n) {
		if (DistU[n] <= DistV[n]) {
			ans++;
		}
		else {
			ans2++;
		}
	}
	if (ans >= (N + 2) / 2){
		cout <<"Fennec" <<endl;
	}
	else {
		cout << "Snuke" << endl;
	}
	return 0;
}

Measured memory_bytes: 14536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    ll H,W,N;
    cin >> H >> W >> N;
    vector<ll> vec;
    for (ll i=1;i<=N;i++) {
        ll a;
        cin >> a;
        for (ll j = 0;j<a;j++) {
            vec.push_back(i);
        }
    }
    ll field[H][W];

    ll right = true; //right 1, right -1 

    ll cnt = 0; //何枚塗ったか

    ll h = 0;
    ll w = 0;
    while(cnt != H*W) {
        field[h][w] = vec[cnt]; //[h][w]をvec[cnt]で塗る
        cnt++;
        if (right) {
            if (w+1==W) {  //右に動くとはみ出るので、下へ
                h++;
                right = false; //今度は左へ
            }
            else w++;   //右へ
        }
        else {
            if (w-1 == -1) {
                h++;
                right = true;
            }
            else w--;
        }
    }
    for (ll h = 0;h<H;h++) {
        for (ll w = 0;w<W;w++) {
            if (w != W-1) cout << field[h][w] << " ";
            else cout << field[h][w] << endl;
        }
    }
}

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

int main() {
    int n;
    cin >> n;
    int ans = 1;
    
    for(int i = 2; i <= sqrt(n); i++) {
        int v = i;
        while(v <= n) {
            v *= i;
        }
        ans = max(ans, v/i);
    }
    cout << ans << endl;

    return 0;
}

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

int main()
{
    int e, y;

    cin >> e >> y;

    if (e == 0) {
        if (y >= 1868 && y <= 1911) {
            cout << 'M' << y - 1868 + 1 << endl;
        }
        else if (y >= 1912 && y <= 1925) {
            cout << 'T' << y - 1912 + 1 << endl;
        }
        else if (y >= 1926 && y <= 1988) {
            cout << 'S' << y - 1926 + 1 << endl;
        }
        else if (y >= 1989 && y <= 2018) {
            cout << 'H' << y - 1989 + 1 << endl;
        }
        else {
            cout << 'R' << y - 2019 + 1 << endl;
        }
    }
    else if (e == 1) {
        cout << y + 1868 - 1 << endl;
    }
    else if (e == 2) {
        cout << y + 1912 - 1 << endl;
    }
    else if (e == 3) {
        cout << y + 1926 - 1 << endl;
    }
    else if (e == 4) {
        cout << y + 1989 - 1 << endl;
    }

    return 0;
}



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

const int N = 1e5 + 10;

string a, b;
int cnt[2][2][N];
int q;

int main() {
  ios::sync_with_stdio(false);
  cin >> a >> b;
  int n = a.length(), m = b.length();
  for (int i = 0; i < a.length(); i++) {
    if (a[i] == 'A') cnt[0][0][i + 1]++;
    else cnt[0][1][i + 1]++;
  }
  for (int i = 0; i < b.length(); i++) {
    if (b[i] == 'A') cnt[1][0][i + 1]++;
    else cnt[1][1][i + 1]++;
  }
  for(int i = 1; i <= n; i++) {
    cnt[0][0][i] += cnt[0][0][i - 1];
    cnt[0][1][i] += cnt[0][1][i - 1];
  }
   for(int i = 1; i <= m; i++) {
    cnt[1][0][i] += cnt[1][0][i - 1];
    cnt[1][1][i] += cnt[1][1][i - 1];
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int c1 = 0, c2 = 0;
    int l1, r1, l2, r2;
    cin >> l1 >> r1 >> l2 >> r2;
    c1 = 2 * (cnt[0][0][r1] - cnt[0][0][l1 - 1]) + cnt[0][1][r1] - cnt[0][1][l1 - 1];
    c2 = 2 * (cnt[1][0][r2] - cnt[1][0][l2 - 1]) + cnt[1][1][r2] - cnt[1][1][l2 - 1];
    if(c1 % 3 == c2 % 3) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}



Measured memory_bytes: 2512
import itertools

n, m = map(int, input().split())
z = 10**9 + 7
ans = 1

if abs(n-m) > 1:
    print(0)
    exit()
else:
    for x in range(1, n+1):
        ans *= x
        ans %= z
    for y in range(1, m+1):
        ans *= y
        ans %= z

if n == m:
    ans *= 2
    ans %= z

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>

int main(void) {

  int N;
  scanf("%d",&N);
  int a[1000];
  int i;
  for(i=0;i<1000;i++){
    a[i] = 1;
  }
  a[0] = 0;
  int num = 0;
  int flag = 1;
  int m = 0;
  int b[168] = {0};
  int c[168] = {0};
  int j = 0;
  int p;

  while(flag){
    for(i=0;i<1000;i++){
      if(a[i]==1){
	m = i+1;
	break;
      }
      if(i==999){
	flag = 0;
      }
    }
    if(flag){
      for(i=0;i<1000;i++){
	if(a[i]==1 && (i+1)%m==0){
	  a[i] = 0;
	}
      }
      num++;
      //printf("%d\n",m);
      b[j] = m;
      j++;
    }
  }

  //printf("num : %d\n",num);
  int k;
  int tmp;
  for(k=2;k<N+1;k++){
    tmp = k;
    while(tmp!=1){
      for(p=0;p<168;p++){
	if(tmp!=1 && tmp%b[p]==0){
	  tmp /= b[p];
	  c[p]++;
	}
      }
    }
  }

  long int ans = 1;
  for(i=0;i<168;i++){
    ans = ans * (1+c[i]) % 1000000007;
  }

  printf("%ld\n",ans);
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> V(N);
  for (int i = 0; i < N; i++){
    cin >> V.at(i);
  }
  
  vector<int> C(N);
  for (int i = 0; i < N; i++){
    cin >> C.at(i);
  }
  
  int ans = 0;
  
  for (int i = 0; i < N; i++){
    if(V.at(i) > C.at(i)){
      ans += V.at(i) - C.at(i);
    }
  }
  
  cout << ans << endl;
}
  
    

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m, d float64
	fmt.Scan(&n, &m, &d)

	var ans float64
	if d == 0 {
		ans = (n / (n * n)) * (m - 1)
	} else {
		ans = ((2 * (n - d)) / (n * n)) * (m - 1)
	}
	fmt.Printf("%.10f\n", ans)
}


Measured memory_bytes: 512
import collections
import sys
input = sys.stdin.readline
N = int(input())
A = [input() for i in range(N)]

C = collections.defaultdict(int)
for i, x in enumerate(A):
    idx = 0
    x = x[:-1]
    if '.' in x:
        idx = x[::-1].index('.')
        x = x.replace('.', '')
    x = int(x)
    count2 = -idx
    count5 = -idx
    while(x % 2 == 0):
        x = x // 2
        count2 += 1

    while(x % 5 == 0):
        x = x // 5
        count5 += 1
    C[(count2, count5)] += 1
ans = 0
for a, b in C:
    for a2, b2 in C:
        if a+a2 >= 0 and b+b2 >= 0:
            if a == a2 and b == b2:
                ans += C[(a, b)]*(C[(a, b)]-1)
            else:
                ans += C[(a, b)]*C[(a2, b2)]
print(ans//2)


Measured memory_bytes: 23452
#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>
 
#if DEBUG
    #include "debug.h"
#else
    #define debug(args...)
#endif    

using namespace std;

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


#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = INT_MAX;
const int mod = 1e9+7;

const int N = 2e5 + 10;
inline int add(int x,int y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline int mul(int x,int y){
  x = (1LL * x * y) % mod;
  return x;
}
clock_t time_p=clock();



int32_t main(){
  fast;

  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);

  string s;
  cin >> s;
  int ans = 0;
  for(int i = 0; i < (s.length())/2; i++) {
    if(s[i] != s[s.length()-1-i])ans++;
  }
  cout << ans;

  time_p=clock()-time_p;
  cerr<<"\nTime Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++)cin >> a.at(i);
    
    int push = 1;
    
    for(int i=0; i<N; i++){
        int next_push = a.at(push - 1);
        
        //if finished
        if(next_push == 2){
            cout << i + 1 << endl;
            exit(0);
        }
        push = next_push;
    }
    cout << -1 << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()

int a[110];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m;
	cin >> n >> m;
	ll sum = 0;
	for(int i = 1; i <= n; ++i) cin >> a[i], sum += a[i];
	int cnt = 0;
	for(int i = 1; i <= n; ++i) if(a[i] * 1ll * 4 * m >= sum) cnt++;
	if(m <= cnt) cout << "Yes";
	else cout << "No";
    return 0;
}


Measured memory_bytes: 256
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
	
	io
	ll h,w;
	cin>>h>>w;
	if(h==1 || w==1)
	{
		cout<<"1";
		exit(0);
	}
	ll z=(h*w)/2;
	ll z1=(h*w-z);
	if(w%2==0)
	cout<<z;
	else
	cout<<z1;	
}

Measured memory_bytes: 256
import math
N,K = map(int,input().split())
cs = list(map(int, input().split()))
high = max(cs) + 1  # OK が取れる側
low = 0  # NG となる側
 
while high - low > 1:
  x = (high - low) // 2 + low
  cnt = 0
  for a in cs:
    cnt += math.ceil(a/x) - 1
 
  if cnt <= K:  # OK
    high = x
  else:
    low = x
print(high)


Measured memory_bytes: 31236
#include<bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
#define l long long
#define pb push_back
#define mem(a,n) memset(a,n,sizeof(a))
#define find(v,n) find(v.begin(),v.end(),n)-v.begin()
#define sort1(v) sort(v.begin(),v.end())
#define lb(v,n) lower_bound(v.begin(),v.end(),n)-v.begin()
#define ub(v,n) upper_bound(v.begin(),v.end(),n)-v.begin()
#define mod 1000000007
#define reverse(s) reverse(s.begin(),s.end())
//#define pi pair<l,l> 
const double pi=3.141592653589793;
bool isprime(l n)
{
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
			return false;
	}
	return true;
}
/*bool fact(l n)
{
	vector<l> v;
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			if(i%2==1||(n/i)%2==1)
			{
				return true;
			}
		}
	}
	return false;
}*/
l power(l a,l b)
{
	l ans=1;
	while(b>0)
	{
		if(b&1)
		{
			ans=(ans*a);
		}
		b>>=1;
		a=(a*a);
	}
	return ans;
}//prefixsums
void frooty()
{
	l n;
	cin>>n;
	l sum=0;
	l div[n+1];
	mem(div,0);
	for(l i=1;i<=n;i++)
	{
		for(l j=i;j<=n;j+=i)
		{
			div[j]++;
		}
	}
	for(l i=1;i<=n;i++)
	{
		sum+=(i*div[i]);
	}
	cout<<sum<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int q=1;
//	cin>>q;
	while(q--)
	{
		frooty();
	}
}


Measured memory_bytes: 81780
n,q = gets.chomp.split(" ").map(&:to_i)
point = Array.new(n,0)
edge = Array.new(n).map{Array.new}
counter = Array.new(n,-1)

for i in 1..n-1 do
    a,b = gets.chomp.split(" ").map(&:to_i)
    edge[a-1].push(b)
    edge[b-1].push(a)
end

for i in 1..q do
    p0,x = gets.chomp.split(" ").map(&:to_i)
    point[p0-1] += x
end

stack = [[1,0]]
while ! stack.empty?
    tar = stack.shift
    i = tar[0]-1
    cnt = tar[1] + point[i]
    if counter[i] < 0
        counter[i] = cnt
        while ! edge[i].empty?
            nxt = edge[i].shift
            if counter[nxt-1] < 0
                stack.push([nxt,cnt])
            end
        end
    end
end

for i in 1..n do
    print counter[i-1]," "
end
print "\n"
    

Measured memory_bytes: 35040
// B - Christmas Eve Eve
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	int all = 0, maxP = 0;
	for(int i=0; i<N; ++i){
		int p; cin>>p;
		all += p;
		maxP = max(maxP, p);
	}
	cout<< all - maxP/2 <<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
	//"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	sum := 0
	for i := 1; i <= n; i++ {
		s := strconv.Itoa(i)
		if len(s)%2 == 1 {
			sum++
		}
	}
	fmt.Println(sum)
}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
using namespace std;

int main(){
  int a[5]; int k;
  for(int i=0; i<5; i++){
    cin >> a[i];
  }
  cin >> k;
  
  int b=1;
  for(int i=0; i<4; i++){
    for(int j=i+1; j<5; j++){
      if(abs(a[i]-a[j])>k){b=0;}
    }
  }
         
  if(b==1){cout << "Yay!";}
  else{cout << ":(";}
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <bitset>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

const double PI=3.14159265358979323846;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REP1(i, n) for(int i = 1; i <= (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())
#define ZERO(a) memset(a, 0, sizeof(a))

#define RAD(d) (PI * (d) / 180)
#define DEG(r) (180.0 * (r) / PI)

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<class T> void dump(const vector<T> &v)
{
	REP(i, SZ(v)-1){ cout << v[i] << " "; }
	cout << v[SZ(v)-1] << endl;
}

template<class T> void dump(int w, int h, const vector<T> &v)
{
	REP(j, h){
		REP(i, w-1){ cout << v[j * w + i] << " "; }
		cout << v[j * w + w-1] << endl;
	}
}

template<class T> T accumulate(const vector<T> &v)
{
	T sum = 0;
	REP(i, SZ(v)){ sum += v[i]; }
	return sum;
}

template<class T> struct Matrix
{
	T w, h;
	vector<T> A;
	Matrix(T w_, T h_) : w(w_), h(h_), A(w * h) {}
	T get(T x, T y) const { return A[y * w + x]; }
};

template<class T> void input(Matrix<T> &m)
{
	REP(j, m.h){
		REP(i, m.w){
			cin >> m.A[j * m.w + i];
		}
	}
}

template<class T> Matrix<T> prod(const Matrix<T> &a, const Matrix<T> &b)
{
	Matrix<T> m(b.w, a.h);

	REP(j, m.h){
		REP(i, m.w){
			ll c = 0;
			REP(k, a.w){
				c += a.A[j * a.w + k] * b.A[k * b.w + i];
			}
			m.A[j * m.w + i] = c;
		}
	}

	return m;
}

void dump(const Matrix<ll> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%lld ", m.A[j * m.w + i]); }
		printf("%lld\n", m.A[j * m.w + m.w-1]);
	}
}

void dump(const Matrix<double> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%f ", m.A[j * m.w + i]); }
		printf("%f\n", m.A[j * m.w + m.w-1]);
	}
}

string &to_upper(string &s)
{
	REP(i, s.length()){
		if('a' <= s[i] && s[i] <= 'z'){
			s[i] -= 32;
		}
	}

	return s;
}

string &to_lower(string &s)
{
	REP(i, s.length()){
		if('A' <= s[i] && s[i] <= 'Z'){
			s[i] += 32;
		}
	}

	return s;
}

// すべての約数を列挙する
template <class T> vector<T> get_divisors(T n)
{
	vector<T> ret;
	for(T i = 1; i * i <= n; i++){
		if(n % i == 0){
			ret.push_back(i);
			if(i * i != n)
				ret.push_back(n / i);
		}
	}
	sort(ALL(ret));
	return ret;
}

// 1-sqrt(N)までの約数を列挙する
template <class T> vector<T> get_divisors2(T n)
{
	vector<T> ret;
	for(T i = 1; i * i <= n; i++){
		if(n % i == 0){
			ret.push_back(i);
		}
	}
	return ret;
}

int F(ll A, ll B)
{
	return LEN(to_string(max(A, B)));
}

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

	VI buka(N+1);
	fill(ALL(buka), 0);

	for(int i = 2; i <= N; i++){
		int a;
		cin >> a;
		buka[a]++;
	}

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

	return 0;
}


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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> ans(n,0);
  int w=0,e=0;
  for(int i=n-1;i>=0;i--){
    ans[i]+=e;
    if(s[i]=='E')e++;
  }
  for(int i=0;i<n;i++){
    ans[i]+=w;
    if(s[i]=='W') w++;
  }
  int fans=n;
  for(int i=0;i<n;i++){
    fans=min(fans,ans[i]);
  }
  cout << fans << endl;
}


Measured memory_bytes: 4836
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = (a), i_len = (b); i < i_len; ++i)

int main()
{
    ll x;
    cin >> x;
    ll res = 0;
    res += x/11LL * 2LL;
    x %= 11LL;
    if(0 < x && x <= 6LL) res += 1;
    else if(x > 6LL) res += 2;
    else res += 0;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
/* SmartCoder Mar 31, 2019 */
#include <bits/stdc++.h>
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(__typeof((c).begin()) 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() )
#define minei(x)  min_element(x.begin(),x.end())-(x).begin()
#define maxei(x)  max_element(x.begin(),x.end())-(x).begin()

#define uns(v)     sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define acusum(x)  accumulate(x.begin(),x.end(),0)
#define acumul(x)  accumulate(x.begin(),x.end(),1, multiplies<int>());
#define bits(x)     __builtin_popcount( x )
#define oo INT_MAX
#define inf 1000000000

const double pi = acos(-1.0);
const double eps = 1e-11;
#define MAXN 100007
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
void fastIO() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int sh[MAXN]; //Stone Height
int dp[MAXN];
int main() {
	fastIO();
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> sh[i];
		dp[i] = inf;
	}
	dp[1] = 0;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= k && i + j <= n; j++) {
			dp[i + j] = min(dp[i + j], abs(sh[i + j] - sh[i]) + dp[i]);
		}
	}
	cout << dp[n] << endl;
	return 0;
}


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


int main(){
  vector<int> vec = {1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
  int k;
  cin >> k;
  cout << vec[k-1] << endl;

}

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

int main(void)
{
	int dest, duration, verocity;
	std::cin >> dest >> duration >> verocity;
	int reach = verocity * duration;
	std::string output = (reach >= dest) ? "Yes" : "No";
	std::cout << output << std::endl;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

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

  int N,C,K;
  cin >> N >> C >> K;
  vec T(N); rep(i,N) cin >> T[i];
  sort(ALL(T));

  int res = 0;
  rep(i, N) {
    int t = T[i];   // バスの出発時刻
    int num = 1;    // バスに乗せる人数
    int j = i+1;    // どこまで乗せるかのインデックス
    for(int j = i+1; j<N && num<C && T[j]-t<=K; j++) {
      num++;
      i = j;        // 乗ることが決定した人の最後尾までiを進める
    }
    res++;
  }
  cout << res << endl;



  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef pair<int,int> P;
using Int = long long;
using VI = vector<int>;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

signed main(){
    Int n,m;cin >> n >> m;
    vector<Int> p(m),y(m);
    for(Int i=0;i<m;i++) cin >> p[i] >> y[i];
    using P = pair<Int,Int>;
    vector<P> vp;
    for(Int i=0;i<m;i++) vp.emplace_back(y[i],i);
    sort(vp.begin(),vp.end());
    vector<string> ans(m);
    vector<Int> cnt(n+1,0);
    for(Int i=0;i<m;i++){
        Int x=vp[i].second;
        ans[x]=to_string(++cnt[p[x]]);
        while(ans[x].size()<6u) {ans[x] = '0'+ans[x];}
        ans[x] = to_string(p[x]) + ans[x];
        while(ans[x].size()<12u) ans[x]='0'+ans[x];
    }
    for(string s:ans) cout << s << endl;
    
}

Measured memory_bytes: 10864
#include<stdio.h>
int main()
{
    int a,b,c,sum1,sum2,sum3;
    scanf("%d%d%d",&a,&b,&c);
    sum1=a+b;
    sum2=b+c;
    sum3=c+a;
    {
        if(sum1<sum2 && sum1<sum3)
            printf("%d\n",sum1);
        else if(sum2<sum1 && sum2<sum3)
            printf("%d\n",sum2);
        else
            printf("%d\n",sum3);
    }
    return 0;
}

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

int main() {
    int N, T;
    cin >> N >> T;
    vector<int> v(N);
    for (int& x : v) cin >> x;

    int ans = T;
    for (int i = 0; i <= N-2; i++) {
        ans += min(v[i+1] - v[i],  T);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#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 ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

ll mod_pow(ll x, ll n, ll mod) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % mod, n / 2, mod);
	if (n & 1) res = res * x % mod;
	
	return res;
}

vector<ll> fact, inv;
void fact_inv(int n, ll mod) {
	fact.resize(n + 1);
	inv.resize(n + 1);
	
	fact[0] = 1;
	FOR(i, 1, n + 1) fact[i] = fact[i - 1] * i % mod;
	inv[n] = mod_pow(fact[n], mod - 2, mod);
	for (int i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

ll ncr(ll n, ll r, ll mod) {
	if (n < r || r < 0 || n < 0) return 0;
	return fact[n] * inv[r] % mod * inv[n - r] % mod;
}

int H, W, A, B;

int main() {
	cin >> H >> W >> A >> B;
	
	fact_inv(212345, MOD);
	
	ll ans = 0;
	REP(i, H - A) (ans += ncr(B-1 + i, B-1, MOD) * ncr(W-B-1 + H-i-1, H-i-1, MOD)) %= MOD;
	cout << ans << endl;
	return 0;
}


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

int main(void){
    int n,m,q;
    cin >> n >> m >> q;
    int station[n+1][n+1];
    int ans[n+1][n+1];
    rep(i,n+1)rep(j,n+1){
        station[i][j] = 0;
        ans[i][j]= 0;
    }
    int a,b;
    rep(i,m){
        scanf("%d %d", &a,&b);
        station[a][b]++;
    }
    rep(i,n)rep(j,n-i){
        if(i == 0)ans[j][i+j] = station[j+1][i+j+1];
        else ans[j][j+i] = ans[j][i+j-1]+ans[j+1][i+j]-ans[j+1][i+j-1]+station[j+1][i+j+1];
    }
    rep(i,q){
        scanf("%d %d", &a,&b);
        printf("%d\n",ans[a-1][b-1]);
    }
    return 0;
}

Measured memory_bytes: 2944
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    string a, b;
    cin >> a >> b;
    vector<string> c(2);

    string a_, b_;
    rep(i, 0, stoi(b)) {
        a_ += a;
    }

    rep(i, 0, stoi(a)) {
        b_ += b;
    }
    c[0] = a_;
    c[1] = b_;
    sort(c.begin(), c.end());
    cout <<  c[0] << endl;
    return 0;
}

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

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef long double ld;

void solve() {
	int n;
	cin >> n;
	set<string> shit;
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		shit.insert(s);
	}  
	cout << int(shit.size()) << endl;
}

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

Measured memory_bytes: 19184
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,a[200010]={},f=0;
	cin>>n;
	FOR(i,0,n){
		cin>>a[i];
		if(a[i]>i){
			f=1;
		}
	}
	FOR(i,1,n){
		if(a[i-1]+2<=a[i]){
			f=1;
		}
	}
	LL ans=0LL;
	int cf=0;
	//cerr<<"pass"<<endl;
	FORD(i,n,0){
		if(cf){
			if(a[i]==a[i+1]-1){

			}else if(a[i]>=a[i+1]){
				ans+=a[i];
			}else{
				f=1;
				/*
				int idx=0,dum=0;
				FOR(j,0,1e2){
					idx=0;
					while(1){
						idx++;
						dum=idx+dum/idx;
						if(idx>1e7)break;
					}
					cerr<<dum<<endl;
				}//*/
			}
		}else{
			ans+=a[i];
			cf=1;
		}
	}
	if(f){
		cout<<-1<<endl;
	}else{
		cout<<ans<<endl;
	}
    return 0;
}


Measured memory_bytes: 1024
# D
n = int(input())
a = list(map(int, input().split()))
ans = [0 for i in range(n+1)]
a.reverse()
for i,num in enumerate(a):
    sum_a = 0
    for j in range(0, n+1, (n-i)):
        sum_a += ans[j]
    if sum_a%2 == 0:
        if num == 1:
            ans[n-i] = 1
    else:
        if num == 0:
            ans[n-i] = 1
sum_ans = 0
ansprint = []
for i,num in enumerate(ans):
    if num == 1:
        ansprint.append(i)
        sum_ans+=1
print(sum_ans)
print(*ansprint, sep=' ')



Measured memory_bytes: 70620
#include<bits/stdc++.h>
#define MOD 1e9+7
using namespace std;
#define  pp push_back
#define  po pop_back
#define  mp make_pair
#define clr(a) memset(a,0,sizeof(a))
#define neg(a) memset(a,-1,sizeof(a))
#define fas(a) memset(a,false,sizeof(a))
#define debug(x) cout<<#x<<": "<<x<<endl
#define debug1(x) cout<<#x<<": "<<x<<" "
#define rev(x) reverse(x.begin(), x.end())
#define int long long 
#define F first
#define S second
//int a[2000];
void printvector(std::vector<int> v){  for (int i = 0; i < v.size(); ++i){cout<<v[i]<<" ";}cout<<""<<endl;}
void printarray(int a[],int n){for (int i = 0; i < n; ++i){cout<<a[i]<<" ";}cout<<""<<endl;}
 
 

 

void  solve()
{
   int n,k;cin>>n>>k;
   int a[n];
   for(int i=0;i<n;i++)cin>>a[i];
   deque <int> dq;
   int mi[n-k+2];
   int ma[n-k+2];
   for(int i=0;i<k-1;i++)
   {
      while(!dq.empty()&&a[dq.back()]>=a[i])dq.pop_back();dq.push_back(i);
   }
   for(int i=0;i<n-k+2;i++)
   {
     while(dq.front()<i)dq.pop_front();
     mi[i]=a[dq.front()];
     while(!dq.empty()&&a[dq.back()]>=a[i+k-1])dq.pop_back();dq.push_back(i+k-1);
   }

   dq.clear();for(int i=0;i<n;i++)a[i]=-a[i];
   for(int i=0;i<k-1;i++)
   {
      while(!dq.empty()&&a[dq.back()]>=a[i])dq.pop_back();dq.push_back(i);
   }
   for(int i=0;i<n-k+2;i++)
   {
     while(dq.front()<i)dq.pop_front();
     ma[i]=-a[dq.front()];
     while(!dq.empty()&&a[dq.back()]>=a[i+k-1])dq.pop_back();dq.push_back(i+k-1);
   }

 //  printarray(mi,n-k+2);
 //  printarray(ma,n-k+2);



   for (int i = 0; i < n; ++i){a[i]=-a[i];}
   
   int ap=0;
   int l=0;
   for(int i=0;i<n;i++)
   {
      if(i!=0&&a[i]<a[i-1])
      {
          if(l>=k)ap++;
          l=0;
      }
      l++;
   }
   if(l>=k)ap++;


   int ans=0;
   for(int i=0;i<n;i++)
   {
      int j=i+k-1;
      if(j>=n)break;
      if(j+1<n)
      {
          if(a[i]<mi[i+1]&&ma[i+1]<a[j+1])continue;
          else ans++;
      }
      else
      {
         ans++;
      }

     // debug(ans);   
   }


   if(ap>=1)
   {
      ap--;
      ans-=ap;
   }    

   cout<<ans<<endl;










}




 int32_t main() 
{

 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
    
   solve();

return 0;

}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
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; }
const long long INF = 1LL<<60;
/* t    s  <実際> 
[] [ab] <ab>　<=先頭c 
[c] [ab] <cab> <=末尾a
[c] [aba] <caba> <= reverse
[aba] [c] <abac> <=末尾d
[aba] [cd] <abacd> <= reverse
[cd] [aba] <dcaba> 
*/
int main(){
    string s;cin >> s;
    int q;cin >> q;
    string t;
    rep(qi,q){
        int ty;cin >> ty;
        if(ty == 1){
            swap(s,t);
        }else{
            int f;char c;
            cin >> f >> c;
            if(f == 1){
                t += c;
            }else{
                s += c;
            }
        }
    }
    reverse(t.begin(),t.end());
    t += s;
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 1128
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);

int main() {
    string S; cin >> S;
    if(S.size() == 2) cout << S << endl;
    else {
        reverse(S.begin(),S.end());
        cout << S << endl;
    }
}

Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int n;
	int a[100010];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	cout << a[n / 2] - a[n / 2 - 1] << endl;
}


Measured memory_bytes: 4016
n = int(input())
f = []
for i in range(n):
  f.append(list(map(int,input().split())))
p = []
for i in range(n):
  p.append(list(map(int,input().split())))
time = [0,0,0,0,0,0,0,0,0,1]
def suc(time):
  point = 10 - 1
  while point >= 0:
    if time[point] == 0:
      time[point] = 1
      return time
      break
    else:
      time[point] = 0
      point -= 1
  else:
    return 'over'
can = []
while time != 'over':
  add = 0
  for i in range(n):
    cnt = 0
    for j in range(10):
      cnt += f[i][j] * time[j]
    add += p[i][cnt]
  can.append(add)
  time = suc(time)
print(max(can))

Measured memory_bytes: 3064
#include<fstream>
#include<string>
#include<iostream>
#include<sstream>
#include<iterator>
#include<cmath>
 
using namespace std;
 
int main(){
 long long int N;
 cin >> N;
 if(N%2==1)cout << 0 << endl;
 else if(N<10)cout << 0 << endl;
 else{
     long long int count = 0;
     int i;
     int j;
     long long int M;
     for(i=1;i<19;i++){
         N /= 10;
         count += N;
         M = N;
         j = 0; 
         while(M!=0){
             j++;
             M /= 5;
             if(M%2==1)count += (M/2 + 1);
             if(M%2==0)count += M/2;  
         }
     } 
     cout << count << endl;
 }
 return 0;
}

Measured memory_bytes: 256
def cc
    n,m = gets.chomp.split(/\s/).map{|x| x.to_i}

    ab = []
    for i in 1..n
        ab.push(gets.chomp.split(/\s/).map{|x| x.to_i})
    end
    ab = ab.sort{|c,d| c[0] <=> d[0]}

    pr = 0
    for i in 0..(n-1)
        a = ab[i][0]
        b = ab[i][1]
        if b >= m
            pr += a*m
            m = 0
        else
            pr += a*b
            m -= b
        end

        break if m < 0
    end

    puts pr
end

cc

Measured memory_bytes: 13944
// AOJ 2884 Tanka Number
// 2018.3.23 bal4u

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// n番目（最初は１番目の10）の短歌数は何桁で表現されるか
int keta(long long n) {
	int i; for (i = 2; ; i++) if (81LL * ((1LL << i) - i - 1) > n) return i;
}

// n桁の数字が最大何番目までの短歌数を表現するか
long long total_combi(int keta) { return 81LL * ((1LL << keta) - keta - 1); }


char ans_[60], *ans;
long long N;

// d1:1つ目の数字, d2:2つ目の数字, N: 残りの組み合わせ, k: 残りの桁数
void calc(int d1, int d2, long long N, int k)
{
	int i;
	long long s, s1, s2;

	if (k <= 0) return;
	if (d2 >= 0) {
		s = (1LL << (k - 1));
		*ans = (((N < s) ^ (d1 > d2)) ? d1 : d2);
		*ans++ += '0';
		calc(d1, d2, N % s, k - 1);
	}
	else {
		s = 0;
		s1 = 9LL * ((1LL << (k - 1)) - 1), s2 = 1LL << (k - 1);
		for (i = 0; i <= 9; i++) {
			if (i == d1) {
				if (k == 1) continue;
				if (s + s1 > N) {
					*ans++ = d1 + '0';
					calc(d1, d2, N - s, k - 1);
					break;
				}
				s += s1;
			}
			else {
				if (s + s2 > N) {
					*ans++ = i + '0';
					calc(d1, i, N - s, k - 1);
					break;
				}
				s += s2;
			}
		}
	}
}

int main()
{
	int k;

	while (scanf("%lld", &N) && N) {
		ans = ans_;
		k = keta(N);
		N -= total_combi(k - 1);
		if (N == 0) {
			k--;
			memset(ans, '9', k - 1);
			ans[k - 1] = '8', ans[k] = 0;
		}
		else {
			long long t = (9LL * ((1LL << (k - 1)) - 1));
			int d = 1 + (int)(--N / t);
			*ans++ = d + '0';
			calc(d, -1, N % t, k - 1);
			*ans = 0;
		}
		puts(ans_);
	}
	return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    double a, b, c, d;
    cin >> a >> b >> c >> d;
    if (c == a / 2 && d == b / 2)
        cout << a * b / 2 << ' ' << 1 << '\n';
    else
        cout << a * b / 2 << ' ' << 0 << '\n';

    return 0;
}


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

int main(){
    int N;
    string S;
    cin >> N >> S;
    vector<int> BLACK(N + 1, 0);
    vector<int> WHITE(N + 1, 0);
    for (int i = 0; i < N; i++) {
        BLACK[i + 1] = BLACK[i];
        if(S[i] == '#')BLACK[i + 1]++;
    }
    
    reverse(S.begin(), S.end());
    for (int i = 0; i < N; i++) {
        WHITE[i + 1] = WHITE[i];
        if(S[i] == '.')WHITE[i + 1]++;
    }
    reverse(WHITE.begin(), WHITE.end());
    int ans = 1e6;
    for (int i = 0; i <= N; i++) {
        ans = min(ans, BLACK[i] + WHITE[i]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
	vector<int> num{ 100, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

	int k;
	cin >> k;

	cout << num.at(k) << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
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;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll aa , bb;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->aa - ((fr*)q)->aa;}

int main(void){
    char s[100005];
    ll n;
    scanf("%s",s);
    n=strlen(s);
    // ll [n];
    ll judge=0;
    rep(i,0,n){
        if(s[i]=='e'){  
            if(i+4>n-1) {judge=1; break;}
            else if(s[i+1]=='r' &&s[i+2]=='a' &&s[i+3]=='s' &&s[i+4]=='e'){
                if(i+5<n && s[i+5]=='r') i+=5;
                else i+=4;
            }else {judge=1; break;}
        }else if(s[i]=='d'){
            if(i+4>n-1) break;
            else if(s[i+1]=='r' &&s[i+2]=='e' &&s[i+3]=='a' &&s[i+4]=='m'){
                if(i+6<n && s[i+5]=='e' && s[i+6]=='r' && (i+7==n || s[i+7]!='a') ) i+=6;
                else i+=4;
            }else {judge=1; break;}
        }else{
            judge=1;
            break;
        }
    }
    if(judge){
        printf("NO\n");
    }else{
        printf("YES\n");
    }
    // printf("\n");
    return 0;
}


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

int main() {
    int n, a, b, c, x;
    while (cin>>n>>a>>b>>c>>x, n||x||a||b||c) {
        vector<int> p(n);
        for(auto& i: p) cin>>i;

        int count = 0;
        int i = 0;
        while (count <= 10000) {
            if (x == p[i]) {
                i++;
            }
            if (n == i) break;
            
            x = (a * x + b) % c;
            count++;
        }

        if (count > 10000) cout << -1 << endl;
        else cout << count << endl;
    }

    return 0;
}



Measured memory_bytes: 3080
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	long n = read.to!long;
	long ga = read.to!long;
	long sa = read.to!long;
	long ba = read.to!long;
	long gb = read.to!long;
	long sb = read.to!long;
	long bb = read.to!long;
	
	// A → B
	long best1 = -1;
	for(long g = 0; g * ga <= n; g += 1){
		for(long s = 0; g * ga + s * sa <= n; s += 1){
			long b;
			if(ba < bb) b = (n - g * ga - s * sa) / ba;
			else b = 0;
			
			long d = n - g * ga - s * sa - b * ba;
			
			long x = g * gb + s * sb + b * bb + d;
			if(best1 < x) log("g:", g, " s:", s, " b:", b, " d:", d, "best was:", best1, " now:", x);
			best1 = max(best1, x);
		}
	}
	
	n = best1;
	log("ok. n:", n);
	
	long z;
	if(gb < sb){
		z = gb, gb = sb, sb = z;
		z = ga, ga = sa, sa = z;
	}
	if(sb < bb){
		z = sb, sb = bb, bb = z;
		z = sa, sa = ba, ba = z;
	}
	if(gb < sb){
		z = gb, gb = sb, sb = z;
		z = ga, ga = sa, sa = z;
	}
	
	// B → A
	long best2 = -1;
	bool f2 = 0;
	for(long g = 0; g * gb <= n; g += 1){
		if(f2 == 0 && g > sb * bb){
			f2 = 1;
			g = (n - gb * sb * bb) / gb - 1;
			continue;
		}
		bool f = 0;
		for(long s =0; g * gb + s * sb <= n; s += 1){
			if(f == 0 && s > bb){
				f = 1;
				s = (n - g * gb - sb * bb) / sb - 1;
				continue;
			}
			
			
			long b;
			if(bb < ba) b = (n - g * gb - s * sb) / bb;
			else b = 0;
			
			long d = n - g * gb - s * sb - b * bb;
			
			long x = g * ga + s * sa + b * ba + d;
			if(best2 < x) log("g:", g, " s:", s, " b:", b, " d:", d, "best was:", best2, " now:", x);
			best2 = max(best2, x);
		}
	}
	
	best2.writeln;
}

/*
Bでは一旦全部どんぐりに替えるとして、
A→BとB→Aでそれぞれ考えればよい。


*/


long gcd(long a, long b){
	if(a % b == 0) return b;
	if(a < b) return gcd(b, a);
	else return gcd(b, a % b);
}
long lcm(long a, long b){
	return (a / gcd(a, b) * b);
}


Measured memory_bytes: 256