akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 1005;
const int mod = 1000000007;

void gcd(ll a,ll b, ll& d,ll& x,ll& y) { //      已经测试 FZU 1402
  if(!b) {
    d=a;
    x=1;
    y=0;
  } else   {
    gcd(b,a%b,d,y,x);
    y-=a/b*x;
  }
}

ll inv(ll a,ll n)  { //无逆元返回-1
  ll d,x,y;
  gcd(a,n,d,x,y);
  return d==1?(x%n+n)%(n/d):-1;
}

ll cc[maxn][maxn],f[maxn][maxn];
void init() {
  for(int i=0; i<maxn; i++)cc[i][0]=cc[i][i]=1;
  for(int i=1; i<maxn; i++)
    for(int j=1; j<i; j++)
      cc[i][j]=(cc[i-1][j]+cc[i-1][j-1])%mod;
}

int main() {
  //freopen("in.cpp","r",stdin);
  init();
  int n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  f[a-1][0]=1;
  for(int i=a-1; i<b; i++)
    for(int j=0; j<=n; j++) {
      f[i+1][j]=(f[i+1][j]+f[i][j])%mod;
      ll fenzi = 1,fenmu=1;
      for(int k=1; k*(i+1)+j<=n&&k<c; k++) {
        fenmu = fenmu * k %mod;
        fenzi = fenzi * cc[n-j-(k-1)*(i+1)][i+1]%mod;
      }
      for(int k=c; k*(i+1)+j<=n&&k<=d; k++) {
        fenmu = fenmu * k %mod;
        fenzi = fenzi * cc[n-j-(k-1)*(i+1)][i+1]%mod;
        f[i+1][j+k*(i+1)]=(f[i+1][j+k*(i+1)]+f[i][j]*fenzi%mod*inv(fenmu,mod)%mod)%mod;
      }
    }
    cout<<f[b][n]<<endl;
  return 0;
}


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

int main(){
    int k;
    while(cin >> k, k){
        int sum = 0, x;
        for(int i = 0; i < k*(k-1)/2; i++)  cin >> x, sum += x;
        cout << sum/(k-1) << endl;
    }
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    int h[110];
    REP(i,N) cin >> h[i];
    int m = 0;
    REP(i,N){
        m = max(m,h[i]);
    }
    int ans = 0;
    bool flag = true;
    REP(i,m){
        REP(j,N){
        if(h[j] == 0) flag = true;
        else{
            h[j]--;
            if(flag){
                ans++;
                flag = false;
            }
        }
        }
        flag = true;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

bool check(string s){
    string t(s);
    reverse(ALL(t));
    return s == t;
}

int main(void){
    string s;
    cin >> s;
    int n = s.length(), m = n / 2;
    cout << ((check(s) && check(s.substr(0, m)) && check(s.substr(m + 1, m))) ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  string s;
  ll k;
  cin >> s >> k;
  for (ll i = 0; i < k; i++) {
    if (s[i] != '1') {
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 3580
#include <stdio.h>
//#include<math.h>
#include<string.h>
int main()
{
    char ch[10001];
    long int n,z,i;
    scanf("%ld %s", &n, &ch);
    for(i=0;ch[i]!='\0';i++){
        z = ((ch[i]-65)+n)%26;
        printf("%c",z+65);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using ll= long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__


	ll N,T;
	cin>>N>>T;
	VI t(N);
	VI dis(N-1);
	ll ans=T;
	REP(i,N){cin>>t[i];}
	REP(i,N-1){ dis.at(i)=t.at(i+1)-t.at(i);}
	REP(i,N-1){
		if (dis.at(i)>=T)ans+=T;
		else ans+=dis.at(i);
	}
	cout<<ans<<endl;

	



	

		return 0;
}


Measured memory_bytes: 4716
#include <iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

// 入力
int N;
long long W, weight[110], value[110]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[110][100100] = {0};

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {

            // i 番目の品物を選ぶ場合
            if (sum_w - weight[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            // i 番目の品物を選ばない場合
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    // 最適値の出力
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 79360
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

int facctorialMethod(int k);
int permutationMethod(int n, int r);

int main(void) {
	long long int n, p;
	long long int a[101];
	long long int gu = 0;
	long long int ki = 0;
	long long int total = 0;
	long long int point = 0;
	cin >> n >> p;
	FOR(i, 1, n) {
		cin >> a[i];
		if (a[i] % 2 == 0) {
			gu++;
		}
		else {
			ki++;
		}
	}

	if (ki == 0) {
		if (p == 1) {
			total = 0;
		}
		else {
			total = pow(2, n);
		}
	}
	else {
		total = pow(2, n - 1);
	}
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int solve(int,int,int,int *);


int main(){
  int n,q,i,top=0;
  int A[2000],m[2000];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m[i]);
  }

  for(i=0;i<q;i++){
    if(solve(top,m[i],n,A)==1) printf("yes\n");
    else                 printf("no\n");
  }
  return 0;
}

int solve(int i,int m,int n,int *a){
  int res;

  if(m==0) return 1;
  if(i>=n) return 0;

  res = solve(i+1,m,n,a) || solve(i+1,m-a[i],n,a);
  return res;

}  
  

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
	map<string, bool> memo;
	string s;
	int n, m;
	cin >> n;
	rep(i, n){
		cin >> s;
		memo[s] = 1;
	}
	cin >> m;
	int cnt = 0;
	rep(i, m){
		cin >> s;
		if(memo[s])cnt++;
	}
	FIN(cnt);

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 1384
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  if (s == "Sunny") cout << "Cloudy" << endl;
  else if (s == "Cloudy")
    cout << "Rainy" << endl;
  else
    cout << "Sunny" << endl;
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

constexpr ll mod = 1000000007;

struct M {
	ll l, r;
	bool f;
};

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

	vector<vector<M>> m(100, vector<M>());
	m[1].pb({ 1,2,true });
	m[1].pb({ 1,3,false });
	bool br = false;
	for (int i = 1; i < 99; i++) {
		for (M j : m[i]) {
			if (j.f) {
				m[i + 1].pb({ j.r,j.l + j.r,true });
				m[i + 1].pb({ j.r,j.l + 2 * j.r,false });
			}
			else m[i + 1].pb({ j.r,j.l + j.r,false });
			if (j.l + j.r > INF * 4) br = true;
		}
		if (br) break;
	}
	m[1].pb({ 1,1,true });
	vector<ll> fib(91);
	fib[0] = 1, fib[1] = 2;
	rep(i, 89) fib[i + 2] = fib[i + 1] + fib[i];
	int q;
	cin >> q;
	while (q--) {
		ll x, y;
		cin >> x >> y;
		if (x > y) swap(x, y);
		if (x == 1) cout << 1 << ' ' << y % mod << '\n';
		else {
			int px = upper_bound(all(fib), x) - fib.begin(); px--;
			int py = upper_bound(all(fib), y) - fib.begin(); py--;
			if (px == py) {
				int cnt = 0;
				for (M i : m[px]) {
					if (i.l <= x && i.r <= y) cnt++;
					if (i.r <= x && i.l <= y) cnt++;
				}
				cout << px << ' ' << cnt << '\n';
			}
			else {
				px++;
				ll ans = 0;
				for (M i : m[px]) {
					if (i.l == fib[px - 1] && i.r == fib[px + 1]) continue;
					if (i.l > x) continue;
					if (y >= i.r) ans += (y - i.r) / i.l + 1;
				}
				cout << px << ' ' << ans % mod << '\n';
			}
		}
	}
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
template <class X> void print(X x) { cout << x << endl; }
void print(vl x) {
    for(ll i : x) {
        cout << i << " ";
    }
    cout << endl;
}
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m;
ll codeforces = 1;
string S, T;
vl A, B;
void input() {
    cin>>n>>d;
    rep(i,n){
        cin>>x>>y;
        if(x*x+y*y<=d*d)ans++;
    }
}
void solve() {
    print(ans);
 }
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    while(codeforces--) {
        solve();
    }
}

Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <array>
#include <string.h>
#include <vector>
 
 
 
int main() {
	int N;
	scanf("%d", &N);
 
	std::vector<int> xv;
	std::vector<int> xv2;
 
	int tmp;
	for (int i = 0; i < N; i++) {
		scanf("%d", &tmp);
		xv.push_back(tmp);
		xv2.push_back(tmp);
	}
 
	std::sort(xv.begin(), xv.end());
	int s = xv[xv.size()/2 - 1];
	int l = xv[xv.size()/2];
 
	for (int i = 0; i < N; i++) {
		if (xv2[i] <= s) {
			printf("%d\n", l);
		}
		else {
			printf("%d\n", s);
		}
 
	}
 
 
 
 
	return 0;
}

Measured memory_bytes: 3948
#include<iostream>
#include<string.h>
#include<math.h>
#include<set>
#include<algorithm>
using namespace std;
int a[100000]; 
int main()
{
	int n,d;
	cin>>n>>d;
	if(n%(2*d+1)==0)
		cout<<n/(2*d+1);
	else
		cout<<n/(2*d+1)+1;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N, b[100];
    cin >> N;
    for (int n = 0; n < N; ++n) {
        cin >> b[n];
    }
    
    int c[100];
    for (int n = 0; n < N; ++n) {
        c[n] = (n+1) - b[n];
    }
    
    int ans[100];
    bool bOK = true;
    for (int n = 0; n < N; ++n) {
        bool bFound = false;
        for (int m = N-1-n; m >= 0; --m) {
            if (c[m] == 0) {
                bFound = true;
                ans[N-1-n] = m+1;
                for (int l = m; l < N-1-n; ++l) {
                    c[l] = c[l+1] - 1;
                }
                break;
            }
        }
        if (!bFound) {
            bOK = false;
            break;
        }
    }
    if (bOK) {
        for (int n = 0; n < N; ++n) {
            cout << ans[n] << endl;
        }
    } else {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  bool flag = false;
  for (int i = 0; i < S.length(); i++) {
	  if (T == S.substr(i, i - S.length()) + S.substr(0, i)) {
		  flag = true;
		  break;
		}
	}
  if (flag) {
	  cout << "Yes" << endl;
	}
  else {
	  cout << "No" << endl;
	}
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,n,ary[100];
  ary[0]=1;
  ary[1]=1;
  scanf("%d",&n);
  for(i=2;i<=n;i++)ary[i]=ary[i-1]+ary[i-2]; 
  printf("%d\n",ary[n]);
  return 0;
}



Measured memory_bytes: 2104
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix


def solv(N, K):
    # print('solv', N, K)
    # K == 0 なら条件を満たしたものが一つある
    if K == 0:
        # print('   ret', 1)
        return 1
    # len(N) < K ならば不可能
    if len(N) < K:
        # print('   ret', 0)
        return 0

    # 場合の数
    count = 0

    #  3abcd のような 場合
    #  29999
    #  19999 のような数を加算する
    if N[0] > 1:
        count += (N[0]-1) * solv([9] * (len(N)-1), K-1)
    #  その数を消費する場合
    if N[0] > 0:
        count += solv(N[1:], K-1)
    # 消費しない場合
    if N[0] == 0:
        count += solv(N[1:], K)
    else:
        count += solv([9] * (len(N)-1), K)

    # print('   ret count=', count)
    return count


if __name__ == "__main__":

    N = list(map(int, input()))
    K = int(input())
    ans = solv(N, K)

    print(ans)


Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}
int main(){
    ll n;
    ll a[5];
    cin >> n;
    rep(i,5)cin >> a[i];
    ll mi = *min_element(a,a+5);
    cout << (n + mi - 1) / mi + 4 << endl;
}

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

int main(void){
  int x, a, b; cin >> x >> a >> b;
  if(a >= b) cout << "delicious" << endl;
  else if(b - a <= x) cout << "safe" << endl;
  else cout << "dangerous" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


int main(){
    long long w, h, mn = 1e9, mx = 0;
    cin >> w >> h;
    if(!(w % 3) ||  !(h % 3)){
        cout << 0;
        return 0;
    }
    long long r = w / 3, l = h / 3;
    long long k = h / 2, m = w / 2;
    if(h % 2 == 1) k = r + (h + 1) / 2;
    if(w % 2 == 1) m = l + (w + 1) / 2;
    cout << min(h, min(w, min(k, m)));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testcases \
    int tcc;      \
    cin >> tcc;   \
    for (int tc = 1; tc <= tcc; tc++)
//-----------------------------------------
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef LOAFNOB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//----------------------------------------------

int main() {
    fast_io;
    int ah,as,bh,bs; cin>>ah>>as>>bh>>bs;
    bool t=1;
    while(ah >0 && bh>0){
    	if(t){
    		bh-=as;
    	}else{
    		ah-=bs;
    	}
    	t=!t;
    }
    cout<<(ah>0?"Yes":"No");
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
signed main(){
  string a; 
  cin>>a;
  int b=0,c=0;
for(int i=0;i<a.size();i++){
  if(a[i]=='C') b=1;
  if(a[i]=='F'&&b==1) c=1;
}
  if(b==1&&c==1) cout<<"Yes";
  else cout<<"No";
  cout<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





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

  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
  }

  sort(all(p));

  ll x=p[n-1];
  ll sa=INF;
  ll ans;
  rep(i,n){
    ll y=abs(2*p[i]-x);
    if(y<sa) ans=i;
    chmin(sa,y);
  }

  cout << x << " " << p[ans] << endl;
}


Measured memory_bytes: 1024
N,K = gets.split.map(&:to_i)
D = gets.split.map(&:to_i)

ans = []
nums = 10.times.to_a - D
N.to_s.chars.reverse_each do |s|
  n = s.to_i
  m = nums.find {|m| n <= m }# || nums[0]
  ans.fill(nums[0]) if m && n < m
  ans.unshift(m)
end
ans.size.times.reverse_each do |i|
  next if ans[i]
  if i == 0
    ans.fill(nums[0]).unshift(nums.find {|m| 0 < m })
  else
    j = i - 1
    ans[i] = nums[0]
    ans[j] = nums.find {|m| ans[j] < m } if ans[j]
  end
end
puts ans.join



Measured memory_bytes: 1788
#include <iostream>
#include <string>

using namespace std;

typedef long long ll;

string s;
ll ans=0;

void solve(int n, int p) {
	ll t = 0, k = s.size() - n - p;
	for (int i = 0; i < n; i++) {
		t = t * 10 + s[p + i] - '0';
	}
	for (int i = 0; i < k - 1; i++) {
		t *= 2;
	}
	ans += t;
	if (k == 0)return;
	for (int i = 1; i <= k; i++) {
		solve(i, p + n);
	}
}

int main() {
	cin >> s;
	for (int i = 1; i <= s.size(); i++) {
		solve(i, 0);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> P;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    rep(i,n){
        cin>>a[i];
    }
    sort(a,a+n,greater<int>());
    int ans=0;
    rep(i,k){
        ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  if(A + B == 15){
    cout << '+' << endl;
  }
  else if(A * B == 15){
    cout << '*' << endl;
  }
  else{
    cout << 'x' << endl;
  }
}

Measured memory_bytes: 256
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define fe(vec,lambda) std::for_each(vec.begin(), vec.end(), lambda );
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#define printv(val) std::for_each(val.begin(),val.end(),[](auto x){cout<<x<<"\n";});
#define lim 1000000007ll
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T chmin(T& a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T& b,T a){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template <class T> T gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T lcm(T a, T b){return a * b / gcd(a, b);}
inline bool operator<(const pii &lhs,const pii &rhs){return(lhs.second<rhs.second);}
template<class T> vector<pair<T,T>> duplicator(const vector<T>& input){vector<pair<T,T>> out(input.size()-1);rep(i,input.size()-1){out[i].first =input[i  ];out[i].second=input[i+1];}return(out);}
vector<char> String_to_vector_char(const string& input){vector<char> out(input.size());rep(i,input.size()){out[i]=input[i];}return out;}


ll a,b,c;
map<ll,ll> m;
void input(){
    cin>>a>>b>>c;
    m[a]++;
    m[b]++;
    m[c]++;
}
void src(){
    cout<< (m[5]==2 and m[7]==1 ? "YES":"NO");
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
   // ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#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 n, m;
  cin >> n >> m;
  rep(i, m) {
    int a;
    cin >> a;
    n -= a;
  }
  if (n < 0) cout << -1 << endl;
  else cout << n << endl;
  return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;
vector<ll> a(51, 1), p(51, 1);

ll burger(ll n, ll x) {
    if (n == 0) {
        if (x >= 1) {
            return 1;
        }
        else {
            return 0;
        }
    }
    else if (x <= a[n - 1] + 1) {
        return burger(n - 1, x - 1);
    }
    else {
        return p[n - 1] + 1 + burger(n - 1, x - a[n - 1] - 2);
    }
}

int main()
{
    ll N, X;
    cin >> N >> X;

    repd(i, 1, N + 1) {
        a[i] = 2 * a[i - 1] + 3;
        p[i] = 2 * p[i - 1] + 1;
    }

    ll ans = 0;
    if (X == 2 + a[N - 1]) {
        ans = p[N - 1] + 1;
    }
    else if (X == 3 + 2 * a[N - 1]) {
        ans = 2 * p[N - 1] + 1;
    }
    else {
        ans = burger(N, X);
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MX = 1e5+2;
int n, m, h[MX];
vector<int> adj[MX];
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> n >> m;
	for(int i=1; i<=n; i++) {
		cin >> h[i];
	}
	for(int i=0; i<m; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);		
	}
	int ans = 0;
	for(int i=1; i<=n; i++) {
		int mx = 0;
		for(int a: adj[i]) {
			mx = max(mx, h[a]);
		}
		if(mx < h[i]) {
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 10212
#include<iostream>
#include<cstdio>
#define MAX 10001
using namespace std;

struct Node{
    int rank, p;
};

Node T[MAX];
int n;

int findSet(int x){
    if( x != T[x].p){
        T[x].p = findSet(T[x].p);
    } 
    return T[x].p;
}

bool same(int x, int y){
    return findSet(x) == findSet(y);
}

void link(int x, int y){
    if( T[x].rank > T[y].rank)T[y].p = x;
       
    else if( T[x].rank < T[y].rank) T[x].p = y;
    else if ( T[x].rank == T[y].rank){
        T[y].rank++;T[x].p = y;
        
    }
}

void unite(int x, int y){
    link(findSet(x), findSet(y));
}

int main(){
    int q,com,t,s;
    scanf("%d %d",&n, &q);
    for(int i = 0; i < n; i++){
        T[i].rank = 0;
        T[i].p = i;
    }
    
    for(int i = 0; i < q; i++){
        scanf("%d %d %d",&com,&t,&s);
        if(com == 0)   unite(t,s);
   
        else if(com == 1){
            if(same(t,s)) cout << 1 << endl;
            else cout << 0 << endl;
        } 
        else break;
    }
    
   
    return 0;
}




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

using namespace std;
bool judge(string s){
    for(int i = 0; i < s.size()/2; i++){
        if(s[i] != s[s.size()-1-i]) return false;
    }
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    string s, result;
    cin >> s;

    string s1 = s.substr(0, s.size()/2);
    string s2 = s.substr(s.size() - (s.size()/2));
    if(judge(s)&&judge(s1)&&judge(s2)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    } 
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
pair<int, pair<int, int> > vv[222];
set<int> S; int ans, n;

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n; int i;
	for(i=1 ; i<=2*n ; i++) cin>>vv[i].first>>vv[i].second.first;
	for(i=1 ; i<=2*n ; i++) vv[i].second.second=(i-1)/n+1;
	sort(vv+1,vv+2*n+1);
	for(i=1 ; i<=2*n ; i++)
	{
		if(vv[i].second.second==1) S.insert(vv[i].second.first);
		if(vv[i].second.second==2)
		{
			if(S.size()==0) continue;
			int xx=vv[i].second.first;
			set<int>::iterator it;
			it=S.begin();
			if((*it)>xx) continue;
			it=S.lower_bound(xx); it--;
			ans++; S.erase((*it));
		}
	}
	cout<<ans; return 0;
}

// it may be easier than you think
// it may be harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n;
double t[105],v[105],g[105];
double ans,vt,v0,tt,vm;
int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%lf",&t[i]);
	fo(i,1,n) scanf("%lf",&v[i]);
	g[n+1]=0;
	fd(i,n,1) g[i]=min(v[i-1],min(g[i+1]+t[i],v[i]));//v[i-1]
	v0=0; 
	fo(i,1,n){
		bool fl=0;
		vt=g[i+1];//vt=min(g[i+1],v[i]);//!!!upper bound
		//!!!
		if (v0>v[i]||v0-t[i]>g[i+1]) return 1;
		tt=t[i];
		if (v0>vt){
			ans+=0.5*(v0+vt)*(v0-vt);
			tt-=v0-vt;
			vt=v0;
			fl=1;
		}
		if (v0<vt){//!!!!!!
			if (tt>=vt-v0){//!!!!!
				ans+=0.5*(v0+vt)*(vt-v0);
				tt-=vt-v0;
				v0=vt;
			}else{
				ans+=0.5*(v0+v0+tt)*tt;
				//tt=0;
				//v0+=tt;!!!!
				v0+=tt;
				tt=0;
			}
		}
		vm=min(v[i],v0+tt/2.0);
		ans+=(v0+vm)*(vm-v0);
		tt-=(vm-v0)*2;
		ans+=tt*vm;
		if (fl) v0=g[i+1];//v0=vt; !!!!
	}
	printf("%.12f\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int n,k;
    long long ans;
    cin>>n>>k;
    ans=k;
    for(int i=1;i<n;i++){
        ans*=k-1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
using namespace std;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
// spring s; cin >> s;
// cout << res << endl;
// --------write my code!!!!!----------//

// I'm trying to ~~~
int main(){
    int N; cin>>N;
    vector<string> s(N);
    rep(i,N) cin >> s[i];
    
    
    string res = "Yes";
    rep(i,N){
        if(i!=0){
            if(s[i][0]!=s[i-1][s[i-1].size()-1]){
                res="No";
                
                break;
            }
        }
        rep(j,N){
            if(i!=j){
                if(s[i]==s[j]){
                    res="No";
                    break;
                }
            }
        }
    }
    cout << res << endl;
    
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int N = Integer.parseInt(scan.nextLine());
	int ac = 0;
	int wa = 0;
	int tle = 0;
	int re = 0;

	for (int i = 0; i < N; i++) {
		String A = scan.nextLine();
		if (A.equals("AC")) {
			ac++;
		}else if (A.equals("WA")) {
			wa++;
		}else if (A.equals("TLE")) {
			tle++;
		}else {
			re++;
		}
	}

	System.out.println("AC x " + ac);
	System.out.println("WA x " + wa);
	System.out.println("TLE x " + tle);
	System.out.println("RE x " + re);

	}
}

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

int main() {
    string s, t;
    cin >> s;
    cin >> t;

    for (int i = 0; i < s.size(); i++)
    {
        string tmp = {s.back()};
        s.pop_back();
        //cout << tmp << endl;
        s.insert(0, tmp);

        //cout << s << endl;
        if (s == t)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector< vector<int> > L(M), V(N);
  int k;
  for(int i = 0; i < N; ++i){
    cin >> k;
    vector<int> t;
    int l;
    for(int j = 0; j < k; ++j){
      cin >> l;
      --l;
      L[l].push_back(i);
      t.push_back(l);
    }
    V[i] = t;
  }
  bool T[N], Useable[M];
  fill(T,T+N,false);
  fill(Useable,Useable+M,false);
  T[0] = true;
  queue<int> que;
  que.push(0);
  while(!que.empty()){
    int t = que.front();
    que.pop();
    for(int i = 0; i < V[t].size(); ++i){
      int l = V[t][i];
      if(!Useable[l]){
	Useable[l] = true;
	for(int j = 0; j < L[l].size(); ++j){
	  if(!T[L[l][j]]){
	    T[L[l][j]] = true;
	    que.push(L[l][j]);
	  }
	}
      }
    }
  }
  bool f = true;
  for(int i = 0; i < N; ++i){
    if(!T[i]){
      f = false;
      break;
    }
  }
  if(f) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

int main(void) {
    int N;cin>>N;
    map<int, int> mp;
    for (int i = 0; i < N; i++) {
        int a;cin>>a;
        if (mp.find(a) != mp.end()) mp[a] += 1;
        else mp[a] = 1;
    }
    int result = 0;
    for (map<int, int>::iterator it = mp.begin();it!=mp.end();++it) {
        int index = it->first;
        int number = it->second;
        if (index > number) {
            result += number;
        } else if (index < number) {
            result += number - index;
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;

    scanf("%d",&n);
    if(n%1000==0)
    {
        printf("0\n");
    }
    else
    {
        int x=n%1000;
    printf("%d\n",1000-x);
    }



    return 0;
}




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

int main(){
    int n, k, flag, minj;
    bool same = true;
    cin >> n;
    string a[n], b[n], tmp;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    
    k = 0;
    flag = 1;
    while (flag==1) {
        flag = 0;
        for (int i=n-1; k < i; i--) {
            if (a[i][1] < a[i-1][1]) {
                tmp = a[i];
                a[i] = a[i-1];
                a[i-1] = tmp;
                flag = 1;
            } 
        }
        k++;
    }
    
    for (int i=0; i<n-1; i++) {
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
    cout << "Stable" << endl;
    
    for(int i=0; i<n; i++) {
        minj = i;
        for(int j=i; j<n; j++ ){
            if (b[j][1] < b[minj][1]) {
                minj = j;
            }
        }
        if (minj != i) {
            tmp = b[i];
            b[i] = b[minj];
            b[minj] = tmp;
         }
    }
    
    for (int i=0; i<n-1; i++) {
        cout << b[i] << " ";
    }
    cout << b[n-1] << endl;
    
    for (int i=0; i<n; i++) {
        if (a[i] != b[i]) {
            same = false;
            break;
        }
    }
    
    if (same == true) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
    
    
    return 0;     
}



Measured memory_bytes: 3200
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

        public static long C(long n, long k)
        {
            long bunbo = 1;
            long bunsi = 1;
            for (long i = n - k+1; i <= n; i++)
                bunsi *= i;
            for (long i = 1; i <= k; i++)
                bunbo *= i;
            return bunsi / bunbo;
        }
        bool f = false;
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            var n = Read();
            char[][] s = new char[n][];
            string[] str = new string[n];

            for (int i = 0; i < n; i++)
            {
                s[i] = Console.ReadLine().ToCharArray();
                Array.Sort(s[i]);
                str[i] = new string(s[i]);
            }

            var d = new Dictionary<string, long>();

            long ans = 0;
          
            for (int i = 0; i < n; i++)
            {

                if (!d.ContainsKey(str[i]))
                {
                    d.Add(str[i], 0);
                }
                else
                {
                    d[str[i]]++;
                    ans += d[str[i]];
                }
            }


          

            Console.WriteLine(ans);
            Console.Out.Flush();
        }
    }
}



Measured memory_bytes: 37588
#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
const LL INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    LL W;
    while (cin >> n >> W) {
        list<pair<LL, LL>> a;
        a.emplace_back(0, 0);
        for (int i = 0; i < n; i++) {
            LL v, w;
            cin >> w >> v;
            if (w > W || v <= 0) continue;
            auto b = a;
            auto s = a.begin();
            for (auto& i : b) {
                i.first += w;
                if (i.first > W) continue;
                i.second += v;
                while (s != a.end() && s->first < i.first) s++;
                if (s != a.end()) {
                    if (s->first == i.first) {
                        if (s->second < i.second) s->second = i.second;
                        else continue;
                    } else {
                        if (prev(s)->second < i.second) s = a.insert(s, move(i));
                        else continue;
                    }
                } else {
                    s = a.insert(s, move(i));
                }
                s++;
                while (s != a.end() && s->second <= i.second) s = a.erase(s);
            }
        }
        LL ans = 0;
        for (auto& i : a) ans = max(ans, i.second);
        cout << ans << '\n';
    }
    return 0;
}


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

int main() {

	int N, X;
	cin >> N >> X;

	int result = 1;
	int pos = 0;
	for (int i = 0; i < N; i++) {

		int num;
		cin >> num;

		pos += num;

		if (pos <= X) {
			result++;
		}
	}

	cout << result;
}

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int N, M;
	cin >>N >>M;
	vector<vector<int>> node(N+1);
	vector<int> parent(N+1, 0);
	for (int i=1; i<=N-1+M; i++) {
		int f;
		int t;
		cin >>f >>t;
		node.at(f).push_back(t);
		parent.at(t)++;
	}
	int I=0;
	for (int i=1; i<N; i++)
		if (0==parent.at(i))
			I=i;
	vector<vector<int>> d(N+1, {0, 0});
	vector<int> linked(N+1, 0);
	vector<int> q;
	// Start Node
	d.at(I)={0, 0};
	// Put into queue
	q.push_back(I);
	int ixq=0;
	// Till all nodes done
	while(ixq<q.size()) {
		int f=q.at(ixq);
		for (int i=0; i<node.at(f).size(); i++) {
			int t=node.at(f).at(i);
			if (d.at(t).at(0)<=d.at(f).at(0))
				d.at(t)={d.at(f).at(0)+1, f};
			linked.at(t)++;
			if (0!=node.at(t).size())
				if (linked.at(t)==parent.at(t))
					q.push_back(t);
		}
		ixq++;
	}
	// Output
	for (int i=1; i<=N; i++)
		cout << d.at(i).at(1) <<endl;
	return 0;
}



Measured memory_bytes: 13052
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int[][] map = { { 0, 0, 0 }, { 0, 0, 255 }, { 0, 255, 0 },
				{ 0, 255, 255 }, { 255, 0, 0 }, { 255, 0, 255 },
				{ 255, 255, 0 }, { 255, 255, 255 } };
		String name[] = { "black", "blue", "lime", "aqua", "red", "fuchsia",
				"yellow", "white" };

		while (true) {
			String line = scanner.next();
			if (line.equals("0"))
				break;

			int[] num = new int[3];
			for (int i = 0; i < 3; i++) {
				num[i] = Integer.parseInt(line.substring(i * 2 + 1, i * 2 + 3),
						16);
			}
			double min = 1<<12;
			int ans = 0;
			for (int i = 0; i < 8; i++) {
				double sum = 0;
				for (int j = 0; j < 3; j++) {
					sum += Math.pow(num[j] - map[i][j], 2);
				}
				sum = Math.sqrt(sum);
				if (min > sum) {
					min = sum;
					ans = i;
				}
			}
			System.out.println(name[ans]);
		}
	}
}

Measured memory_bytes: 22860
#include<iostream>
#include<algorithm>

int const MAXX = 100*105;

int cb[MAXX+1];

int calc(int X) {
  if(X > MAXX || X==0) return 1;
  if(X < 100) return 0;
  if(cb[X] >= 0) return cb[X];
  int res = 0;
  for(int i = 105; i >= 100; --i) if(res < 1) {
    res = calc(X-i);
  }
  return cb[X] = res;
}

int main() {
  int X; std::cin >> X;
  std::fill_n(cb, MAXX+1, -1);
  std::cout << calc(X) << std::endl;
  return 0;
}


Measured memory_bytes: 256
a, b, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
x, y, c = m.times.map { gets.split.map(&:to_i) }.transpose

ans = Float::INFINITY

m.times do |i|
  s = a[x[i] - 1] + b[y[i] - 1] - c[i]
  ans = s if s < ans
end
am = a.min
bm = b.min
ans = am + bm if am + bm < ans
p ans


Measured memory_bytes: 20448
#include <bits/stdc++.h>
#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(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N;
map<int,int> cnt;
bool solve(){
	cin>>N;
	rep(i,N){
		int a;
		cin>>a;
		cnt[a]++;
	}
	if(cnt.size()==1){
		auto it = cnt.begin();
		int a = it->fs, x = it->sc;
		
		if(2*a<=N) return 1;	//a

		if(a+1==N) return 1;	//a+1

		return 0;

	}else if(cnt.size()==2){
		auto it = cnt.begin();
		int a = it->fs, x = it->sc;
		it++;
		int b = it->fs, y = it->sc;

		if(a+1!=b) return 0;

		if(x>=a+1) return 0;
		if(2*(a+1-x)<=y) return 1;
		return 0;
	}else{
		return 0;
	}
}
int main(){
	if(solve()) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;

int main() {
	vector<ll> S(2019);
	vector<ll> T(2019);
	ll N, M, ans;
	cin >> N >> M;
	for (int i = 1;i < N + 1;i++) {
		cin >> S[i];
	}
	for (int i = 1;i < M + 1;i++) {
		cin >> T[i];
	}
	vector<vector<ll>> X(2019, vector<ll>(2019, 0));

	for (int i = 1;i < N + 1;i++) {
		for (int j = 1;j < M + 1;j++) {
			X[i][j] = X[i - 1][j] + X[i][j - 1] - X[i - 1][j - 1];
			if (S[i] == T[j]) {
				X[i][j] += X[i - 1][j - 1] + 1;
			}
			X[i][j] += MOD;
			X[i][j] %= MOD;
		}
	}
	cout << X[N][M] + 1 << endl;
}

Measured memory_bytes: 32256
import math
N = int(input())
X = [0] * N
Y = [0] * N
for i in range(N):
    X[i], Y[i]  = map(int, input().split())

SUM = 0
CNT = math.factorial(N)
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        else:
            SUM = SUM + math.sqrt((X[i] - X[j])**2 + (Y[i] - Y[j])**2)

print(SUM/N)
    

Measured memory_bytes: 3064