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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int h, w, n; cin >> h >> w >> n;
  vector<set<int>> me(h + 1);
  rep(i, n) {
    int x, y; cin >> x >> y;
    me[x].insert(y);
  }
  int acc = 0;
  for (int i = 2; i <= h; i++) {
    if (me[i].size() == 0) continue;
    if (me[i].count(i - acc) > 0) {
      acc++;
    }
    auto it = me[i].upper_bound(i - acc);
    while (it != me[i].end()) {
      me[i].erase(it++);
    }
  }
  int ans = h;
  for (int i = 2; i <= h; i++) {
    if (me[i].size() > 0) {
      ans = i - 1;
      break;
    }
  }
  cout << ans << '\n';
}


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

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

    int n;
    cin >> n;
    vector<int> s(n);
    rep(i, n) cin >> s[i];

    int q;
    cin >> q;
    vector<int> t(q);
    rep(i, q) cin >> t[i];

    int res = 0;
    rep(i, q){
        int target = t[i];

        int l = 0;
        int r = n-1;

        if(target == s[l] || target == s[r]){
            ++res;
            continue;
        }


        while(abs(r-l) > 1){
            int m = (l + r) / 2;

            if(target == s[m]){
                ++res;
                break;
            }

            if(target < s[m]) r = m;
            if(target > s[m]) l = m;
        }

    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3344
from itertools import combinations
n,m,x = map(int,input().split())
l = [[0]*(m+1) for i in range(n)] #入力の通りに2次元リストに入れる
for i in range(n):
    k = list(map(int,input().split()))
    for j in range(m+1):
        l[i][j] = k[j]
seq = [i for i in range(n)] #0~n-1のリストを作る
combis = [] #選ぶ参考書の組み合わせたちのリスト
for i in range(1,n+1): #i個選ぶ時の組み合わせを上で作ったリストに加えていく
    combis += list(combinations(seq,i))
ans = [] #条件を満たした組み合わせの合計金額たちを入れるリスト
for p in combis: #全ての組み合わせを試していく
    pcomp = [0]*m #組み合わせpの時の理解度
    pmoney = 0 #組み合わせpの時の金額
    for q in p: #組み合わせpの時に買う参考書q
        for j in range(m):
            pcomp[j] += l[q][j+1] #理解度のリストpcompに得られた理解度を足していく
        pmoney += l[q][0] #参考書qを買った時に値段を追加
    flag = True #目標達成したかどうか
    for i in pcomp:
        if i < x:
            flag = False
            break
    if flag: #目標達成したならこの組み合わせの合計金額をメモ
        ans.append(pmoney)
if ans == []: #満たした組み合わせがないなら
    print(-1)
else: #満たした組み合わせがあるなら金額の最小値を出力
    print(min(ans))

Measured memory_bytes: 68956
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;

static const long long MOD = 1000000007;

struct modll {
	long long x;
	modll() { }
	modll(int _x) : x(_x) { }
	operator int() const { return (int)x; }
	modll operator+(int y) { return (x + y + MOD) % MOD; }
	modll operator+=(int y) { x = (x + y + MOD) % MOD; return *this; }
	modll operator-(int y) { return (x - y + MOD) % MOD; }
	modll operator-=(int y) { x = (x - y + MOD) % MOD; return *this; }
	modll operator*(int y) { return (x * y) % MOD; }
	modll operator*=(int y) { x = (x * y) % MOD; return *this; }
	modll operator/(int y) { return (x * modpow(y, MOD - 2)) % MOD; }
	modll operator/=(int y) { x = (x * modpow(y, MOD - 2)) % MOD; return *this; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

modll get_all_sum(const std::vector<int>& x) {
	int size = (int)x.size();
	modll r = 0, sum = 0;
	for (int i = 1; i < size; ++i) {
		r += modll(x[i] - x[i - 1]) * min(i, size - i) * max(size - i, i);
	}
	return r;
}

void solve(int n, int m, std::vector<int> &x, std::vector<int> &y) {
	modll ans = get_all_sum(x) * get_all_sum(y);
	cout << ans << endl;
}

int main() {
	int n, m;
	std::cin >> n >> m;
	std::vector<int> x(n), y(m);
	for (int i = 0; i < n; i++) {
		std::cin >> x[i];
	}
	for (int i = 0; i < m; i++) {
		std::cin >> y[i];
	}
	solve(n, m, x, y);
	return 0;
}


Measured memory_bytes: 3972
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N; cin >> N;
  for(int i = 0; i <= N; i++) {
    int j = (int)(i * 1.08);
    if(j == N) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
}


Measured memory_bytes: 3628
from operator import itemgetter
n = int(input())
list1 = [list(map(int,input().split())) for i in range(n)]

list1.sort(key=itemgetter(1))
megalovania = 0
for i in range(n):
	megalovania += list1[i][0]
	if megalovania > list1[i][1]:
		print("No")
		exit()
print("Yes")






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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    string s;
    cin >> s;
    
    //int x = ctoi(s[0]);
    //cout << x <<endl;
    
    for(int tmp = 0; tmp < (1<<3); tmp++){
        bitset<3> bit(tmp);
        
        int sum = ctoi(s[0]);
        //cout << sum << endl;
        for(int i=0; i < 3; i++){
            if(bit.test(i)){
                sum += ctoi(s[i+1]);
            }else{
                sum -= ctoi(s[i+1]);
            }
            
        }
        
        //cout << sum << endl;
        if(sum==7){
            cout << s[0];
            for(int i=0; i < 3; i++){
                if(bit.test(i)){
                    cout << "+" << s[i+1];
                }else{
                    cout << "-" << s[i+1];
                }
                
            }
            cout << "=7" << endl;
            break;
        }
        
    }
    
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

bool r = false;
deque<char> que;
int Q;
signed main(){
	string S;
	cin >> S;
	rep(i, S.size()) que.pb(S[i]);
	cin >> Q;
	rep(q, Q){
		int t;
		cin >> t;
		if(t == 1){
			r = !r;
		}
		else{
			int f;
			cin >> f;
			char c;
			cin >> c;
			if(f == 1){
				if(r == false) que.push_front(c);
				else que.push_back(c);
			}
			else{
				if(r == false) que.push_back(c);
				else que.push_front(c);
			}
		}
	}
	if(r == false){
		while(!que.empty()){
			cout << que.front();
			que.pop_front();
		}
		cout << endl;
	}
	else{
		while(!que.empty()){
			cout << que.back();
			que.pop_back();
		}
		cout << endl;
	}
}

Measured memory_bytes: 896
#include <stdio.h>

int main(void) {
	int a[3][3];
	int n;
	int num = 0;
	int flag = 0;
	int b[10];
	int x[8][3] = {
		{0,1,2},
		{0,1,2},
		{0,1,2},
		{0,0,0},
		{1,1,1},
		{2,2,2},
		{0,1,2},
		{0,1,2}
	};
	int y[8][3] = { 
		{0,0,0},
		{1,1,1},
		{2,2,2},
		{0,1,2},
		{0,1,2},
		{0,1,2},
		{0,1,2},
		{2,1,0}
	};


	for (int i = 0; i < 3; i++)
	        scanf("%d%d%d", &a[i][0], &a[i][1], &a[i][2]);

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
		scanf("%d", &b[i]);

	for (int i = 0; i < 8; i++) {
		num = 0;
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < n; k++)
				if (a[x[i][j]][y[i][j]] == b[k])
					num++;
		}
		if (num == 3) {
			flag = 1;
			break;
		}
	}

	printf("%s", (flag == 0) ? "No" : "Yes");

	return 0;
}

Measured memory_bytes: 128
(let* ((n (read))
       (b (make-array `(,n) :initial-element 0))
       (a 0))
  (loop :for i :from 1 :to (1- n)
        :do (setf (aref b i) (read)))
  ;
  (incf a (aref b 1))
  (loop :for i :from 2 :to (1- n)
        :do (incf a (min (aref b (1- i)) (aref b i))))
  (incf a (aref b (1- n)))
  (format t "~A~%" a))


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

struct data{
  int type; //0 - empty   , 1 - update
  ll value;
};

const int MAX_N = 1<<17;
int n,dat[2*MAX_N-1];
data td[2*MAX_N-1];

//?????????
void init(int n_){
  //????´???°n???2???????????????
  n=1;
  while(n<n_)n*=2;
  for(int i=0;i<2*n-1;i++){
    dat[i]=INT_MAX;
    td[i]=(data){0,0};
  }
}

//[a,b)???????°????????±???????
//query(a,b,0,0,n)
ll update(int a,int b,int x=-1,int k=0,int l=0,int r=n){
  if(r<=a||b<=l)return dat[k];
  if(a<=l&&r<=b){
    td[k]=(data){1,x};
    return dat[k]=x;
  }
  
  if(td[k].type){
    dat[k*2+1]=dat[k*2+2]=td[k].value;
    td[k*2+1]=td[k*2+2]=(data){1,td[k].value};
  }
  td[k].type=0;

  ll vl=update(a,b,x,k*2+1,l,(l+r)/2);
  ll vr=update(a,b,x,k*2+2,(l+r)/2,r);
  return dat[k]=min(vl,vr);
}

ll find(int a,int b,int k=0,int l=0,int r=n){
  if(r<=a||b<=l)return INT_MAX;
  if(a<=l&&r<=b)return dat[k];

  if(td[k].type){
    dat[k*2+1]=dat[k*2+2]=td[k].value;
    td[k*2+1]=td[k*2+2]=(data){1,td[k].value};
  }
  
  td[k].type=0;

  ll vl=find(a,b,k*2+1,l,(l+r)/2);
  ll vr=find(a,b,k*2+2,(l+r)/2,r);
  return min(vl,vr);
}


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

  while(q--){
    int cmd;
    cin>>cmd;
    if(cmd==0){
      int s,t,x;
      cin>>s>>t>>x;
      update(s,t+1,x);
    }
    else {
      int s,t;
      cin>>s>>t;
      cout <<find(s,t+1)<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 8188
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long int lld;
#define sq(x) x*x
#define fr(i,m,n) for(i=m;i<n;i++)
#define vec vector<int>
#define sint set<int>
#define qint queue<int>
#define mip map<int,int>
#define pint priority_queue<int>
#define pb push_back
#define pp pop_back()
#define ft first
#define sd second
#define full(v) v.begin(),v.end()

int main()
{
    int i,j,k,a,b,c,x,y,z,n,m,t;
    string s,u,v;
    fr(i,1,6){
        cin>>x;
        if(x==0) y=i;
    }
    cout<<y<<endl;
}



Measured memory_bytes: 3560
#include <iostream>
using namespace std;
typedef long long ll;

int t[51] {0};
int p[51] {0};

ll thick(int i){
    if(i == 0){
        return 1;
    }
    if(t[i] != 0){
        return t[i];
    }
    else{
        return thick(i - 1) * 2 + 3;
    }
}

ll patty(int i){
    if(i == 0){
        return 1;
    }
    if(p[i] != 0){
        return p[i];
    }
    else{
        return patty(i - 1) * 2 + 1;
    }
}

ll ans(int i, ll s){
    if(i == 0){
        return 1;
    }
    if(s == 1){
        return 0;
    }
    if(2 <= s && s <= thick(i - 1) + 1){
        return ans(i - 1, s - 1);
    }
    if(s == thick(i - 1) + 2){
        return patty(i - 1) + 1;
    }
    if(thick(i - 1) + 3 <= s && s <= thick(i - 1) * 2 + 2){
        return patty(i - 1) + ans(i - 1, s - (thick(i - 1) + 2)) + 1;
    }
    else{
        return patty(i);
    }
}

int main()
{
    int n;
    cin >> n;
    ll x;
    cin >> x;
    cout << ans(n, x) << endl;
}

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

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	int ans = INF;
	string S;
	vector<int> conw, cone;
	
	cin>>N;
	cin>>S;
	
	conw.resize(N+1);
	cone.resize(N+1);
	
	for(int i = 0; i < S.size(); i++){
		if(S[i] == 'W') conw[i+1]++;
		if(S[i] == 'E') cone[i+1]++;
	}
	
	for(int i = 0; i < S.size(); i++){
		conw[i+1] += conw[i];
		cone[i+1] += cone[i];
	}
	
	for(int i = 0; i < S.size(); i++){
		ans = min(ans, conw[i] - conw[0] + cone[N] - cone[i+1]);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    string ans = "Yes";
    if(N%2 == 1) ans = "No";
    else {
        rep(i,N/2) {
            if(S[i] != S[i+N/2]) {
                ans = "No";
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define Max 100000+5
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define pb push_back
int mod = 1000000007;
int mod1 = 998244353;
vector<int> g[Max];
bool vis[Max];
int d, x, y;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
void ex(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        ex(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}


void dfs(int u){

	vis[u]=1;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(vis[v]!=1)
			dfs(v);
	}
}



int power(int a,int b){
    if(b==1)return a;
    if(a>mod)a%=mod;
    int r=1;
    while(b){
        if(b&1)r=r%mod*a%mod;
        a=a%mod*a%mod;
        b/=2;
    }
    return r;
}
class uf{
    vector<int> v;
    vector<int> sz;
    
    
    public :
    uf(int n){
        v.resize(n+1);
        iota(v.begin()+1,v.end(),1);
        sz.resize(n+1,1);
        //1 to sz
    }
    int root(int b){
        while(v[b]!=b){
            b = v[b];
        }   
        return b;
    }
    void u(int a, int b){
        //combine a and b
        
        int ra=root(a);
        int rb=root(b);
        if(ra==rb)return ;
        if(sz[ra]<sz[rb]){
            v[ra] = v[rb];
            sz[rb]+=sz[ra];
        }else{
            v[rb]=v[ra];
            sz[ra]+=sz[rb];
        }
    }
    bool f(int a,int b){
        //same set
        return (root(a)==root(b));
    }
   
    
};
vector<int> matmul(vector<int> a,vector<int> b){
    vector<int> c(4,0);
    c[0] = (a[0]%mod*b[0]%mod + a[1]%mod*b[2]%mod)%mod;
    c[1] = (a[0]%mod*b[1]%mod + a[1]%mod*b[3]%mod)%mod;
    c[2] = (a[2]%mod*b[0]%mod + a[3]%mod*b[2]%mod)%mod;
    c[3] = (a[2]%mod*b[1]%mod + a[3]%mod*b[3]%mod)%mod;
    return c;
}
vector<int> id={1,0,0,1};

int32_t main(){
	IO
	//freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
	int n;
  	cin>>n;
  	cout<<1000*((n+999)/1000)-n;
}


Measured memory_bytes: 5924
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

i64 n;
vector<i64> x, r;

double f(double p)
{
  double ret = 1e18;
  for (i64 i = 0; i < n; i++)
  {
    double d = abs(p - x[i]);
    ret = min(ret, sqrt((double)r[i] * r[i] - d * d));
  }
  return ret;
}

int main()
{
  cin >> n;
  x.resize(n);
  r.resize(n);
  for (i64 i = 0; i < n; i++)
    cin >> x[i] >> r[i];
  double a = -1e18, b = 1e18;
  for (i64 i = 0; i < n; i++)
  {
    a = max(a, (double)x[i] - r[i]);
    b = min(b, (double)x[i] + r[i]);
  }
  while (0.00001 < b - a)
  {
    if (f((a * 2 + b) / 3) < f((a + b * 2) / 3))
      a = (a * 2 + b) / 3;
    else
      b = (a + b * 2) / 3;
  }
  cout << fixed << setprecision(4) << f(b) << endl;
  return 0;
}



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

int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>> matrix(H, vector<char>(W));
	rep(i, H) rep(j, W) cin >> matrix[i][j];

	vector<bool> row(H, false);
	vector<bool> col(W, false);

	rep(i, H) rep(j, W) {
		if (matrix[i][j]=='#') {
			row[i] = true;
			col[j] = true;
		}
	}
	
	rep(i, H) {
		if (row[i]) {
			rep(j, W) {
				if (col[j]) cout << matrix[i][j];
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=100111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

int main(){
	while(1){
		int n,m,c[20],x;
		cin>>n>>m;
		if(n==0&&m==0)break;
		rep(i,0,m)cin>>c[i];
		ll dp[20020][256];//dp[i][j]: n=iの時にyi=jを選んだ最小値.
		rep(i,0,20020)rep(j,0,256)dp[i][j]=INF;
		dp[0][128]=0;
		rep(i,0,n){
			cin>>x;
			rep(j,0,256){
				rep(k,0,m){
					int y=min(255,max(0,j+c[k]));
					dp[i+1][y]=min(dp[i+1][y],dp[i][j]+(y-x)*(y-x));
				}
			}
		}
		ll ans=INF;
		rep(i,0,256)ans=min(ans,dp[n][i]);
		print(ans);
	}

}


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

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
const int loose = 0;
const int tight = 1;

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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n,k;
	cin>>n>>k;
	Array a(n,0);
	REP(i,n) cin>>a[i];

	sort(all(a));

	auto check = [&](ll x, ll ai)->ll{
		if(ai > 0){
			ll d=x/ai;
			if(x<0 && x%ai!=0) d--; 
			return upper_bound(all(a),d) - a.begin();
		}else if(ai==0){
			return (x>=0)?n:0;
		}else{
			ll d=x/ai;
			if(x<0 && x%ai!=0) d++;
			return a.end()-lower_bound(all(a),d);
		}	
	};

	ll l=-INF;
	ll r=INF;
	while(r-l>1){
		ll mid=l+r>>1;
		ll con=0;
		REP(i,n){
			con+=check(mid,a[i]);
			if(a[i]*a[i]<=mid) con--;
		}
		con/=2;
		if(con>=k) r=mid;
		else l=mid;
	}

	cout<<r<<en;
	return 0;
}

Measured memory_bytes: 1792
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      a: i64,
      b: i64,
      q: usize,
      mut ss: [i64; a],
      mut ts: [i64; b],
      xs: [i64; q],
    }
    const INF: i64 = 1 << 50;
    ss.push(INF);
    ss.push(-INF);
    ss.sort();
    ts.push(INF);
    ts.push(-INF);
    ts.sort();

    for i in 0..q {
        let x = xs[i];
        let s = ss.binary_search(&x);
        let t = ts.binary_search(&x);
        let s = match s {
            Err(v) => v,
            _ => unreachable!()
        };
        let t = match t {
            Err(v) => v,
            _ => unreachable!()
        };

        let mut ans = INF;

        let d = max(ss[s], ts[t]) - x;
        ans = min(d, ans);

        let d = x-min(ss[s-1], ts[t-1]);
        ans = min(d, ans);

        let d = (ss[s]-x)*2 + x-ts[t-1];
        ans = min(ans, d);

        let d = (ss[s]-x) + (x-ts[t-1])*2;
        ans = min(ans, d);

        let d = (ts[t]-x)*2 + (x-ss[s-1]);
        ans = min(ans, d);

        let d = (ts[t]-x) + (x-ss[s-1])*2;
        ans = min(ans, d);

        println!("{}", ans);
    }
}


Measured memory_bytes: 11516
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

a=gets.to_i
b=gets.to_i
c=gets.to_i
d=gets.to_i
ans=0
if a<b
  ans+=a
else
  ans+=b
end
if c<d
  ans+=c
else
  ans+=d
end
puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<sstream>
#include<iomanip>
#include<bitset>
#include<map>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
using namespace std;
int main(){
  int n,sum=0;
  string s;
  cin>>n>>s;
  rep(i,0,n-2){
    if(s.at(i)=='A'&&s.at(i+1)=='B'&&s.at(i+2)=='C')
      ++sum;
  }
  ou(sum);
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9 + 7;
const int maxn = 1<<21;

void add(ll& x, ll y) {
    if (x>=mod) x%=mod;
    if (y>=mod) y%=mod;
    x += y;
    if (x>=mod) x%=mod;
}

ll pw(ll x, ll y) {
    ll res=1;
    while (y) {
	if (y%2) res=res*x%mod;
	x=x*x%mod;y=y/2;
    }
    return ((res%mod)+mod)%mod;
}


int n;
int a[maxn];
int acc[maxn];


vector<int> inds[maxn];
int zero[maxn];

ll qry0(int l, int r) {
    if (l>r) return 0;
    return zero[r] - (l>0 ? zero[l-1] : 0);
}


ll solve(vector<int> a) {
    // count odd length subsequences that alternate: 101..0101, must start and end with 1
    vector<ll> dp(2, 0);
    dp[0] = 1;
    //101010...01

    int len = a.size();
    for (int i=0; i<len; i++) {
	dp[1]=(dp[1]+dp[0])%mod;
	if (i+1<len) {
	    ll zcnt = qry0(a[i], a[i+1]);
	    dp[0]=(dp[1]*zcnt%mod + dp[0])%mod;
	}
    }

    return dp[1];
}

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

    cin>>n;
    for (int i=0; i<n; i++) {
	cin>>a[i];
    }

    
    for (int i=0; i<n; i++) {
	acc[i+1]=acc[i]^a[i];
    }

    //watch(acc[n]);

    if (acc[n] != 0) {
	// even # of dividers
	// alternating parity of indices
	vector<int> v;
	for (int i=1; i<n; i++) {
	    if (acc[i]==0) {
		v.push_back(0);
	    }
	    if (acc[i]==acc[n]) {
		v.push_back(1);
	    }
	}

	//101010
	//even length, alternate
	vector<ll> dp(2, 0);
	dp[0] = 1;
	for (int x: v) {
	    if (x==0) {
		dp[0]=(dp[0]+dp[1])%mod;
	    } else {
		dp[1]=(dp[1]+dp[0])%mod;
	    }
	}
	
	out(dp[0]);
    } else {
	for (int i=1; i<n; i++) {
	    inds[acc[i]].push_back(i);
	    if (acc[i]==0) zero[i]++;
	}

	for (int i=1; i<=n+2; i++) {
	    zero[i]+=zero[i-1];
	}

	
	ll res = 0;
	add(res, pw(2, inds[0].size()));

	for (int x=1; x<maxn; x++) {
	    if (inds[x].empty()) {
		continue;
	    }
	    add(res, solve(inds[x]));
	}
	
	cout<<res<<endl;
    }
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<int> pq;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        pq.push(x);
    }
    while (m--) {
        int tp = pq.top();
        pq.pop();
        pq.push(tp / 2);
    }
    long long ans = 0;
    while (!pq.empty()) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,i,j,c,y;
    cin>>x;
    for(i=-200;i<200;i++)
    {
        for(j=200;j>=-100;j--)
        {
            y=pow(i,5)-pow(j,5);
            if(y==x)
            {
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4040
n = int(input())
R = []
for i in range(n):
    a = int(input())
    R.append(a)

m = R[0]
M = R[1] - R[0]

for i in range(1,n):
    M = max(M,R[i] - m)
    m = min(m,R[i])

print(M)



Measured memory_bytes: 13584
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N, Q;
int A[100010];
int X[100010];
int cum1[100010];
int cum2[100010];

bool check(int x, int m) {
  int pos = lower_bound(A, A+N, x-(A[m]-x)) - A;
  int numT = N - m;
  int numA = m - pos;
  return numT - numA <= 1;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> Q;
  REP(i, N) cin >> A[i];
  REP(i, Q) cin >> X[i];

  REP(i, N) cum1[i+1] = cum1[i] + A[i];
  REP(i, N) cum2[i+1] = cum2[max(0LL, i-1)] + A[i];

  REP(i, Q) {
    int ok = N-1, ng = 0;
    while (ok - ng > 1) {
      int m = (ok + ng) / 2;
      if (check(X[i], m)) ok = m;
      else ng = m;
    }
    int numT = N - ok;
    int sumT = cum1[N] - cum1[ok];
    int rem = max(0LL, N - 2 * numT);
    sumT += cum2[rem];
    cout << sumT << endl;
  }

  return 0;
}

Measured memory_bytes: 4864
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

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

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    int R,G,B,N; cin >> R >> G >> B >> N;
    ll ans=0LL;

    for(int r=0; r < (N/R)+1; r++){
        for(int g=0; g < ((N-R*r)/G)+1; g++){
            if( (N-R*r-G*g)%B==0){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
S = input()

ans = []
right = N

while right > 0:
    left = right
    for i in range(M):
        if S[right-i-1] == '0':
            left = right-i-1
        if left == 0:
            break
    if left == right:
        print(-1)
        break
    ans.append(right-left)
    right = left
else:
    print(*reversed(ans))

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

N = int(input())
A = [int(i) for i in input().split()]

number = 0
now_i = 1
one_flag = False
for a in A:
    if a != now_i:
        number += 1
    else:
        now_i += 1
        one_flag = True

if one_flag is False:
    print('-1')
else:
    print(number)

Measured memory_bytes: 24744
<?php
  
fscanf(STDIN, "%d", $N);
$A_array = explode(" ", trim(fgets(STDIN)));
fscanf(STDIN, "%d", $Q);

$sum_A = array_sum($A_array);
foreach ($A_array as $A) {
 	 if (!empty($A_num[$A])) {
       $A_num[$A]++;
     }else{
       $A_num[$A] = 1;
     }
}

for($i = 0;$i < $Q;$i++) {
  fscanf(STDIN, "%d %d", $B, $C);
  if (!empty($A_num[$B])) {
    $d = $C - $B;
    $sum_A = $sum_A + $d * $A_num[$B];
    if (!empty($A_num[$C])) {
      $A_num[$C] += $A_num[$B];
    } else {
      $A_num[$C] = $A_num[$B];
    }
  	$A_num[$B] = 0;
  }
  echo $sum_A . "\n";
}

Measured memory_bytes: 28196
#include <stdio.h>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

const int MAX_N = 2e5 + 100, MOD = 1e9 + 7;

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

int N, X, Y, Inv[MAX_N], Fast[MAX_N];
int MinL[MAX_N], MinR[MAX_N];
vector<int> Color[MAX_N];
vector<pi> List;

int getMulti(int a, int b) {
	ll res = 1, pow = a;
	while(b) {
		if(b%2 == 1) res *= pow, res %= MOD;
		pow *= pow; pow %= MOD;
		b /= 2;
	}
	return res;
}

int main() {
	scanf("%d%d%d", &N, &X, &Y);
	for(int i=0; i<N; i++) {
		int c, w; scanf("%d%d", &c, &w);
		Color[c].push_back(w);
	}
	for(int c=1; c<=N; c++) {
		sort(Color[c].begin(), Color[c].end());
	}
	MinL[0] = MinR[N+1] = MOD;
	for(int i=1; i<=N; i++)
		MinL[i] = min(MinL[i-1], Color[i].size()>0?Color[i][0]:MOD);
	for(int i=N; i>=1; i--)
		MinR[i] = min(MinR[i+1], Color[i].size()>0?Color[i][0]:MOD);
	for(int c=1; c<=N; c++) {
		int n = (int)Color[c].size();
		for(int i=n-1; i>=1; i--)
			if(Color[c][i] + Color[c][0] > X && MinL[c-1] + Color[c][i] > Y && MinR[c+1] + Color[c][i] > Y)
				Color[c].pop_back();
		if(Color[c].size() == 1)
			if(Color[c][0] > X && MinL[c-1] + Color[c][0] > Y && MinR[c+1] + Color[c][0] > Y)
				Color[c].pop_back();
		if(Color[c].size() != 0) {
			List.emplace_back(Color[c][0], (int)Color[c].size());
		}
	}
	Inv[0] = 1; Fast[0] = 1;
	for(int i=1; i<=N; i++)
		Fast[i] = 1ll * Fast[i-1] * MOD;
	for(int i=1; i<=N; i++)
		Inv[i] = 1ll * Inv[i-1] * getMulti(i, MOD-2) % MOD;


	sort(List.begin(), List.end());
	int LN = (int)List.size();
	for(int i=LN-1; i>=0; i--)
		if(List[i].first + List[0].first > Y)
			List.pop_back();

	int sum = 0;
	for(pi &e : List) sum += e.second;

	int ans = 1;
	for(int i=1; i<=sum; i++)
		ans = 1ll * ans * i % MOD;


	for(pi &e : List)
		ans = 1ll * ans * Inv[e.second] % MOD;

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

/*
2 2 5
1 1
2 4

*/

Measured memory_bytes: 13688
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

#define min(a, b) ((a) < (b)? (a) : (b))

#define square(x) ((x) * (x))

int main()
{
	int N, D;
	cin >> N >> D;
	vector<vector<int>> x;
	x.resize(N);
	for (int i = 0; i < N; i++)
	{
		x[i].resize(D);
		for (int d = 0; d < D; d++)
		{
			cin >> x[i][d];
		}
	}

	int ans = 0;
	for (int i = 0; i < N - 1; i++)
	{
		for (int j = i + 1; j < N; j++)
		{
			int sq = 0;
			for (int d = 0; d < D; d++)
			{
				sq += square(x[i][d] - x[j][d]);
			}
			int dst = (int)std::sqrt(sq);
			if (dst * dst == sq)
			{
				ans++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <string.h>
#define INF 10000
using namespace std;
int maze[33][33];
int d[33][33];
int w,h;
void solve(int i,int j,int c){
  if(i<0||i>=h) return;
  else if(j<0||j>=w) return;
  if(d[i][j]<=c) return;
  d[i][j]=c;
  //cout<<i<<","<<j<<":"<<c<<endl;
  if(!(maze[i][j]&1)) solve(i-1,j,c+1);
  if(!((maze[i][j]>>1)&1)) solve(i,j-1,c+1);
  if(!((maze[i][j]>>2)&1)) solve(i+1,j,c+1);
  if(!((maze[i][j]>>3)&1)) solve(i,j+1,c+1);
  return;
}
int main(void){
  int i,j;
  int res;
  string s;
  while(cin>>w>>h,w|h){
    getline(cin,s);
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        maze[i][j]=0;
        d[i][j]=INF;
      }
    }
    
    for(i=0;i<((h*2)-1);i++){
      getline(cin,s);
      //cout<<i<<":"<<s<<endl;
      if(i%2==0){
        for(j=1;j<s.length();j+=2){
          if(s[j]=='1'){
            maze[i/2][j/2]+=8;
            maze[i/2][(j/2)+1]+=2;
          }
        }
      }
      else{
        for(j=0;j<s.length();j+=2){
          if(s[j]=='1'){
            maze[i/2][j/2]+=4;
            maze[(i/2)+1][j/2]+=1;
          }
        }
      }
    }
    solve(0,0,1);
    /*
    cout<<":"<<endl;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        //cout<<d[i][j]<<" ";
        printf("%3d ",d[i][j]);
      }
      cout<<endl;
    }
    cout<<":";
    */
    if(d[h-1][w-1]==INF) cout<<0<<endl;
    else cout<<d[h-1][w-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

public class Program
{
	static public void Main(string[] args)
	{
		var data = ReadNums();
		var h = data[0];
		var a = ReadNums();
		var sum = a.Sum();
		if(sum >= h)
		{
			Console.WriteLine("Yes");
		}
		else
		{
			Console.WriteLine("No");
		}
		return;
	}
	static public int[] ReadNums()
	{
		return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
	}
}

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

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

    if(N % 2 == 0) printf("0.50000000\n");
    else {
        printf("%.7f\n", (double)((N + 1) / 2) / N);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
using namespace std;

int main(){
  int a[3],max=0,sum=0;
  rep(i,3) cin >> a[i];
  rep(i,3){
    if (max<a[i]) max=a[i];
    sum += a[i];
  }
  cout << sum-max << endl;
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
a, brray = n.times.map{gets.split.map(&:to_s)}.transpose
array = a.map{|x| x.to_f}
i = 0
sum = 0
while i < n
  if brray[i] == "JPY"
    sum += array[i]
  else
    sum += array[i]*380000
  end
  i += 1
end
puts sum


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int m,k; cin>>m>>k;
    int maxi=pow(2,m);
    if(k>=maxi){
        cout<<-1<<endl;
        return 0;
    }
    if(k==0){
        for(int i=0;i<maxi;i++){
            cout<<i<<" "<<i<<(i==maxi-1?"\n":" ");
        }
        return 0;
    }
    if(m==1&&k==1){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=0;i<maxi;i++){
        if(i!=k) cout<<i<<" ";
    }
    cout<<k<<" ";
    for(int i=maxi-1;i>=0;i--){
        if(i!=k) cout<<i<<" ";
    }
    cout<<k<<endl;
    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;

public class Program333
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());

        var xy = Console.ReadLine().Split(' ');
        var f = new Dictionary<int, int>();
        var s = new Dictionary<int, int>();
        for (int i = 0; i < n; i = i + 2)
        {
            var n1 = int.Parse(xy[i]);
            var n2 = int.Parse(xy[i + 1]);
            if (f.ContainsKey(n1))
            {
                f[n1]++;  //todo
            }
            else
            {
                f.Add(n1, 1);
            }

            if (s.ContainsKey(n2))
            {
                s[n2]++;  //todo
            }
            else
            {
                s.Add(n2, 1);
            }
        }

        var second = new KeyValuePair<int, int>();
        foreach (var skv in s)
        {
            if (second.Value < skv.Value)
            {
                second = skv;
            }
        }

        var fsMaxCount = 0;
        foreach (var kv in f)
        {
            var sMaxCount = 0;
            if (kv.Key != second.Key)
            {
                sMaxCount = second.Value;
            }
            else
            {
                foreach (var skv in s)
                {
                    if (skv.Key != kv.Key)
                    {
                        sMaxCount = Math.Max(sMaxCount, skv.Value);
                    }
                }

            }

            fsMaxCount = Math.Max(fsMaxCount, kv.Value+sMaxCount);
        }


        var result = n - fsMaxCount;
        Console.WriteLine(result);


    } // Main
}     // Class





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

int main(){
string A,B ; cin >> A; cin >> B;
 
  int s = (int) A.size(); int t = (int) B.size();
  
  reverse(A.begin(),A.end());
  reverse(B.begin(),B.end());
  
  if( t > s){cout << "UNRESTORABLE";}
  else{
    bool flag = false;
    for(int i = 0; i <= s - t ; i++)
    {
      flag = true;
      for(int j = 0; j <= t - 1; j++){
        if(A[ i + j ] != '?' && A[i+j] != B[j])
                                      { flag = false;}}
       if(flag){//AとBが照合できた
                   for(int k = 0; k <= t - 1; k++){
                                                    A[i+k] = B[k];}
                   for(int l = 0; l < s; l++){ 
                                                    if(A[l] == '?'){ A[l] = 'a';}
                   }
   break;}
  }// i ループとじ]
      if(!flag){cout << "UNRESTORABLE" ; return 0; }
    
    reverse(A.begin(),A.end());
    reverse(B.begin(),B.end());
        
       for(int i = 0; i < s ; i++){cout << A[i];}}//else閉じ
                
   return 0;}
        
        
       
            


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

int main(){
    string S;
    int w;
    cin >> S >> w;
    rep(i, S.size()){
        if(i % w == 0){
            cout << S[i];
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n;
  string s;
  cin >> n >> s;
  ll ans;
  map<char, ll> m;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') m['R']++;
    if (s[i] == 'G') m['G']++;
    if (s[i] == 'B') m['B']++;
  }
  ans = m['R'] * m['G'] * m['B'];
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int k = j + j - i;
      if (k < n) {
	if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) ans--;
      }
    }
  }

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


Measured memory_bytes: 3616
n, t = map(int, input().split())
lst = [0 for _ in range(t)]
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
for a, b in ab:
    ans = max(ans, lst[-1] + b)
    for i in range(t - 1, a - 1, -1):
        lst[i] = max(lst[i], lst[i - a] + b)

print(ans)

Measured memory_bytes: 75288
#include <stdio.h>
#define MAX2(x,y)	((x)>(y)?(x):(y))
#define MIN2(x,y)	((x)<(y)?(x):(y))
#define MIN3(x,y,z)	((x)<(MIN2(y,z)) ? (x):(MIN2(y,z)))
#define ABS(x)		((x)<0 ? -(x):(x))

int main(){
    int         a,b,c,x,y;

    scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);

    //それぞれ買う
    int each = a*x + b*y;

    //A,B少ない方に合わせてCを買って、残りは単体で買う
    int tmp = x>y ? a:b;
    int mix = 2*c*MIN2(x,y) + tmp*ABS(x-y);

    //余ってもいいからCだけで買う
    int only = 2*c*MAX2(x,y);

    //比較
    printf("%d\n", MIN3(each, mix, only));
    return 0;
}

Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
bool is;
char ch,now,a;
string s;
stack<int> t;
int main()
{
	cin>>s; int n=s.size();
	for(int i=0;i<n;i++)
	    t.push(s[i]);
	for(int i=0;i<n;i++)
	{
		now=t.top();
	    if(now=='b') a='d';
	    else if(now=='d') a='b';
	    else if(now=='p') a='q';
	    else if(now=='q') a='p';
	    if(a==s[i]) t.pop();
		else
		{
			is=1; break;
		}
	}
	if(!is) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  vector<ll> A(N+1);
  rep(i, 0, N + 1) {
    cin >> A[i];
  }
  vector<ll> B(N);
  rep(i, 0, N) {
    cin >> B[i];
  }
  ll ans = 0;
  ll n = 0;
  rep(i, 0, N)   {
    ans += min(B[i], A[i]);
    if (B[i] > A[i]) {
      B[i] -= A[i];
      n = min(A[i+1], B[i]);
      ans += n;
      A[i+1] -= n;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
in2= input()
in2b = raw_input()
in2b = in2b.split()

c =0
for i in in2b:
    in2b[c]=int(i)
    c+=1
    


j = 0
pair =0 
while j < in2:
    i = in2b[j]
    if (j+1<i):
        if in2b[i-1] == j+1:
            pair+=1
    j+=1
        
print pair

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<ll> cnt(N+1);
  cnt[0] = 3;
  rep(i, N) cin >> A[i];
  ll ans = 1;
  rep(i, N) {
    cnt[A[i]+1]++;
    ans *= cnt[A[i]];
    ans %= mod;
    cnt[A[i]]--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
T = list(input())

n = len(T)
T.append("P")
T.insert(0,"D")


ans = []
for i in range(1,n+1):
    if T[i] == "?":
        if T[i-1] == "P":
            T[i] = "D"
        elif T[i-1] == "D":
            T[i] = "D"

   








print("".join(T[1:n+1]))




Measured memory_bytes: 77264
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		 String A  = in.next();
		 
		 if(A.equals("Sunny")){System.out.print("Cloudy");}
		 if(A.equals("Cloudy")){System.out.print("Rainy");}
		 if(A.equals("Rainy")){System.out.print("Sunny");}
	}
}

Measured memory_bytes: 21716