akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 5;
int a[N][N];
int n = 3, m;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    rep(i, 1, n) {
        rep(j, 1, n) {
            cin >> a[i][j];
        }
    }
    cin >> m;
    while(m--) {
        int x;
        cin >> x;
        rep(i, 1, n) {
            rep(j, 1, n) {
                if(a[i][j] == x) {
                    a[i][j] = 0;
                }
            }
        }
    }
    int cd = 0, cdd = 0;
    rep(i, 1, n) {
        int cnt = 0, cntt = 0;
        rep(j, 1, n) {
            cnt += a[i][j] == 0;
            cntt += a[j][i] == 0;
        }
        if(cnt == 3 || cntt == 3) {
            cout << "Yes" << endl;
            return 0;
        }
        cd += a[i][i] == 0;
        cdd += a[i][3 - i + 1] == 0;
    }
    if(cd == 3 || cdd == 3) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    vector<ll> sum(N+1);
    for (int i = 0; i < N; i++) sum[i+1] = sum[i] + a[i];

    map<ll, ll> mp;
    for (int i = 0; i < N+1; i++) mp[sum[i] % M]++;

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        mp[sum[i] % M]--;
        ans += mp[sum[i] % M];
    }
    cout << ans << '\n';
}


Measured memory_bytes: 5760
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define ll long long

void solve()
{
    ll a;
    string s;
    cin >> a;
    cin >> s;
    cout << ((a >= 3200) ? s : "red") << endl;
}

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


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int r,m,a,b,l=0;
  scanf("%d %d",&r,&m);
  while(m--){
    scanf("%d %d",&a,&b);
    if(l<a)l=a;
    if(r>b)r=b;
  }
  if(l>r+1)l=r+1;
  printf("%d\n",r-l+1);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)(x).size())

typedef	long long ll;

const int MAXN = 1e5;

int id[MAXN];
int deg[MAXN];
int ans[MAXN];

int nb_personnes, nb_amities, nb_ennemis;

void init(void)
{
	for (int i(0); i < nb_personnes; ++i)
		id[i] = -1;
}

int find(int u)
{
	if (id[u] < 0)
		return u;
	return id[u] = find(id[u]);
}

void merge(int u, int v)
{
	u = find(u), v = find(v);
	if (u == v)
		return ;
	if (-id[u] < -id[v])
		swap(u, v);
	id[u] += id[v];
	id[v] = u;
}

int main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin >> nb_personnes >> nb_amities >> nb_ennemis;
	
	init();
	for (int i(0); i < nb_amities; ++i)
	{
		int u, v;
		cin >> u >> v;
		merge(u-1, v-1);
		deg[u-1]++;
		deg[v-1]++;
	}
	for (int i(0); i < nb_personnes; ++i)
		ans[i] = -id[find(i)] - deg[i]-1;

	for (int i(0); i < nb_ennemis; ++i)
	{
		int u, v;
		cin >> u >> v;
		if (find(u-1) == find(v-1))
		{
			ans[u-1]--;
			ans[v-1]--;
		}
	}
	for (int i(0); i < nb_personnes; ++i)
		cout << ans[i] << ' ';
	cout << endl;
}	



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

char toLowercase(char c){
    if(c == 'A') return 'a';
    if(c == 'B') return 'b';
    if(c == 'C') return 'c';
}

int main(){
    int n, k;
    cin >> n >>  k;
    string s;
    cin >> s;
    s.at(k - 1) = toLowercase(s.at(k - 1));
    cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    string s;
    ll k;
    cin >> s >> k;

    char res = '1';
    int onecnt = 0;
    rep(i, s.size()){
        if(s[i] != '1'){
            res = s[i];
            break;
        }else{
            onecnt++;
        }
    }

    if(onecnt >= k){
        res = '1';
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	
	int n;
	string s;
	cin >> n >> s;
	if (s.substr(0, n / 2) == s.substr(n / 2, n)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 380
//C
#include <bits/stdc++.h>
using namespace std;
string S;


int main(){
    int N,Q; cin >> N >> Q;
     cin >> S;
    int l[Q];
    int r[Q];
    for(int i=0;i<Q;i++) {cin >> l[i] >> r[i]; l[i]--; r[i]--;}

    vector<int> arr(N,0);
    int num = 0;
    for(int i=0; i<N;i++){
        if(S[i] == 'A'){
            if(S[i+1] == 'C') num++;
        }
        arr[i] = num;
    }
    //for(int i=0;i<N;i++) cout << arr[i];

    
    for(int i=0;i<Q;i++){
        int s = l[i]-1;
        int g = r[i]-1;
        int ans = arr[g] - arr[s];
        cout << ans << endl;
    }

}

Measured memory_bytes: 2304
// Devarshi

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn=1000001;

int main(){

sync


string s;
cin>>s;
//cout<<s<<endl;
forn(i,s.size()){
    if(s[i]=='1') s[i]='9';
    else s[i]='1';
}
cout<<s;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

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

  string msg = "Christmas";
  if (D <= 24) msg += " Eve";
  if (D <= 23) msg += " Eve";
  if (D <= 22) msg += " Eve";
  cout << msg << endl;

  return 0;
}


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

//010101
//101010
int a1, a2;
char s[200010];

int main() {
    scanf("%s", s + 1);
    for(int i = 1; s[i]; i ++) {
        if(i & 1) {
            a1 += (s[i] != '0');
            a2 += (s[i] != '1');
        } else {
            a1 += (s[i] != '1');
            a2 += (s[i] != '0');
        }
    }
    printf("%d\n", min(a1, a2));
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstdlib>
using namespace std;
#define LEN 100005

struct rw{
	char name[100];
	int t;
}s[LEN],u;


int head,tail,c;

void enqueue(rw x){
	s[tail]=x;
	tail=(tail+1)%LEN;
}

rw dequeue(){
	rw x=s[head];
	head=(head+1)%LEN;
	return x;
}

int min(int x,int y){
	return x<y?x:y;
}


int main(){
	int n,q,cnt=0;
	scanf("%d %d",&n,&q);
	for(int i=1;i<=n;i++){
		scanf("%s",s[i].name);
		scanf("%d",&s[i].t);
	}
	
	head=1;tail=n+1;
	while(head != tail){
		u=dequeue();
		c=min(u.t,q);
		u.t-=c;
		cnt+=c;
		if(u.t){
			enqueue(u);
		}
		else{
			printf("%s %d\n",u.name,cnt);
		}
	}
	return 0;
}


Measured memory_bytes: 13356
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

const int MAXN = 105;
int main()
{
	bool flag1=0,flag2=0;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		//cout<<s[i]<<endl;
		if(s[i]=='C')
		{
			flag1=1;
		}
		if((s[i]=='F') && (flag1==1))
		{
			flag2=1;
		 } 
	}
	//cout<<flag1<<" "<<flag2<<endl;
	if((flag1==1)&&(flag2==1))
	{
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import Data.Bits

main :: IO ()
main = do
  a:b:_ <- fmap (\x -> read x :: Int) <$> words <$> getLine
  print $ (xors (a - 1)) `xor` (xors b)
    where
      xors a = (((a + 1) `div` 2) .&. 1) `xor` (if (a .&. 1) == 1 then 0 else a)


Measured memory_bytes: 508
def ip():
  	return list(map(int, input().split()))
[n,k]=ip()
arr=ip()
s=0
e=k
u=n-k
while u:
  if arr[s]<arr[e]:
      print("Yes")
  else:
      print("No")
  s+=1
  u-=1
  e+=1
    

Measured memory_bytes: 31616
N,W=map(int,input().split())
vw=[list(map(int,input().split())) for _ in range(N)]
DP=[[0 for i in range(10001)] for j in range(100)]
for idx in range(N):
    for weight in range(10001):
        if weight<vw[idx][1]:
            DP[idx][weight]=DP[idx-1][weight]
        else:
            DP[idx][weight]=max(DP[idx][weight-vw[idx][1]]+vw[idx][0],DP[idx-1][weight])

print(DP[N-1][W])


Measured memory_bytes: 42236
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	int X = 0;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		X ^= a[i];
	}

	for (int i = 0; i < N; ++i) {
		cout << (X ^ a[i]) << (i < N - 1 ? " " : "\n");
	}

	return 0;
}



Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n, m;
	cin >> n >> m;
	VI a(n);
	REP(i, n)
		cin >> a[i];
	sort(ALL(a));
	ll ans = 0;
	int ma;
	while(1) {
		ma = distance(a.begin(), lower_bound(a.begin(), a.end(), a[n - 1] / 2));
		for (int i = n - 1; i >= ma; i--) {
			a[i] /= 2;
			m--;
			if (m == 0) {
				REP(i, n)
					ans += a[i];
				cout << ans;
				return 0;
			}
		}
		sort(ALL(a));
	}
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
                                                                            
  
int main(void){
                                                                                                
      
    char s[101];

    char c[3];

    int l = 0;

      
    scanf("%s", s);
   
  
    l = strlen(s);

    c[0] = s[0];

    c[1] = l - 2;

    c[2] = s[l-1];


    printf("%c%d%c\n", c[0], c[1], c[2] );


    return 0;
                                                          
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ST first
#define ND second
#define ll long long
#define ld long double
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;

const ll  INF = 1e9 + 9;
const ll  MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;
 
// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)
 
//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<ll > gen(0,n-1);
//gen(gener); // generate random number

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

	int n; cin >> n;
	
	vector<ll> tab(n);
	
	for(int i = 0; i < n; i++) cin >> tab[i];
	
	ll xorr = 0;
	for(int i = 2; i < n; i++) xorr ^= tab[i];
	
	ll summ = tab[0] + tab[1]; 
	ll andd = (summ - xorr)/2;

	ll a = andd, b = andd;
	bool ok = true;
	if((summ - xorr) % 2) ok = false;
	for(ll i = 62; i >= 0; i--){
		if(andd & (1ll << i)){
			if(xorr & (1ll << i)){
				ok = false;
				break;
			} else {
				a |= (1ll << i);
				b |= (1ll << i);
			}
		} else {
			if(xorr & (1ll << i)){
				if((a | (1ll << i)) <= tab[0]) a |= (1ll << i);
				else b |= (1ll << i);
			}
		}
	}
	if(a == 0 || b == 0) ok = false;
	if(a > tab[0]) swap(a,b);
	if(!ok || a > tab[0]){
		cout << -1;
	} else {
		cout << tab[0] - a;
	}
	cout << "\n";
}

Measured memory_bytes: 3644
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextWord() string {
	sc.Scan()
	str := sc.Text()
	return str
}

func nextInt() int {
	i, e := strconv.Atoi(nextWord())
	if e != nil {
		panic(e)
	}
	return i
}

func main(){
	sc.Split(bufio.ScanWords)
	n := nextInt()
	h := make([]int,0)
	for i := 0; i < n ; i++ {
		h = append(h, nextInt())
	}

	ans := "Yes"
	for i := n - 1 ; i > 0; i-- {
		if h[i] < h[i-1] {
			h[i-1] -= 1
			if h[i] < h[i-1] {
				ans = "No"
				break
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5760
#include <stdio.h>

int main(){
    int x, y;

    scanf("%d %d", &x, &y);
    if(
        ((4*x - y >= 0)
        && (y - 2*x >=0))
        && (y % 2==0)
    ){
        printf("Yes");
    }else{
        printf("No");
    }
}

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

ll C, D;

ll calc_gcd(ll x, ll y) {
    if (y == 0) return x;
    return calc_gcd(y, x % y);
}

ll cnt(ll X) {
    ll res = 0;
    res += X / C;
    res += X / D;
    res -= (X / (C * D / calc_gcd(C, D)));
    return X - res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B >> C >> D;
    cout << cnt(B) - cnt(A - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + (ll)b) % mod
#define MUL(a, b) a = (a * (ll)b) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rer(i, a, b) for(int i = a - 1; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<pi, pi> ppi;
typedef vector<ll> vec;

const int MAX_N = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const ll inf = 1LL << 60;

void Debug() {cout << '\n'; }

template<class FIRST, class... REST> 
void Debug(FIRST arg, REST... rest) { cout << arg << " "; Debug(rest...); }

template<class T>
ostream& operator<< (ostream& out, const vector<T>& v) {
	out << "[";
	if(!v.empty()) {
		rep(i, 0, (int)v.size() - 1) out << v[i] << ", ";
		out << v.back();
	}
	out << "]";
  return out;
}

template<class S, class T>
ostream& operator<< (ostream& out, const pair<S, T>& v) {
	out << "(" << v.first << ", " << v.second << ")";
	return out;
}

///g++ -g3 -std=c++0x -DLOCAL -Wall -ftrapv -D_GLIBCXX_DEBUG -Wl,-stack,268435456 -o
///g++ -O2 -std=c++0x -DLOCAL -Wall -Wl,-stack,268435456 -o

///////////////////////////////////////////////////////////////////////

int N;
int A[MAX_N];

ll solve2() {
	ll res = 0, ans = 0;
	rep(i, 0, N) {
		res += A[i];
		//debug(i, res, ans);
		if(i % 2 == 0) {
			if(res <= 0) {
				ans += 1 - res;
				res = 1;
			}
		}
		else {
			if(res >= 0) {
				ans += res + 1;
				res = -1;
			}
		}
	}
	return ans;
}

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	ll ans = inf;
	ans = min(ans, solve2());
	rep(i, 0, N) A[i] *= -1;
	ans = min(ans, solve2());
	cout << ans << "\n";
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);	
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}




Measured memory_bytes: 640
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int K;
int X;
int main(){
  rd(K);
  rd(X);
  if(500*K>=X){
    wt_L("Yes");
    wt_L('\n');
  }
  else{
    wt_L("No");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191229-1 [beta]

// --- original code ---
// int K, X;
// {
//   rd(K,X);
//   wt(if[500K>=X,"Yes","No"]);
// }


Measured memory_bytes: 256
#include<stdio.h>
#define N 45
int Fib[N];

int F(int n){
  if(n==0||n==1)return Fib[n]=1;
  if(Fib[n]!=0)return Fib[n];
  return Fib[n]=F(n-1)+F(n-2);
}

int main(){
  int n,i;
  for(i=0;i<N;i++)Fib[i]=0;
  scanf("%d",&n);
  printf("%d\n",F(n));
  return 0;
}




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


int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;++i){
    cin >> a[i];
  }
  for(int i=0;i<n;++i){
    cin >> b[i];
  }
  bool ok = true;
  for(int i=0;i<n;++i){
    if(a[i]<b[i]) ok=false;
  }
  if(ok){
    cout << '0' << endl;
    return 0;
  }
  int kazu=0;
  long long s=0;
  priority_queue<long long> que;
  for(int i=0;i<n;++i){
    if(a[i]<b[i]){
      kazu++;
      s+=(b[i]-a[i]);
    }
    if(a[i]>=b[i]){
      que.push(a[i]-b[i]);
    }
  }
  int num=0;
  while(!que.empty() && s>0){
    num++;
    s=s-que.top();
    que.pop();
  }
  if(s>0){
    cout << "-1" << endl;
  }else{
    int ans=num+kazu;
    cout << ans << endl;
  }
  return 0;

}


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

const int limit = 100010;
using edge = struct {int to; ll cost; };
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d) {
    depth[v] = d;
    for(auto &e : tree[v]) {
        if(e.to == p) continue;
        dfs(e.to, v, d + e.cost);
    }
}

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

    for(int i = 0; i < N-1; ++i) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        a--, b--;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }

    int Q, K;
    scanf("%d %d", &Q, &K);
    K--;

    dfs(K, -1, 0);
    for(int i = 0; i < Q; ++i){
        int x, y;
        scanf("%d %d", &x, &y);
        x--, y--;
        printf("%lld\n", depth[x] + depth[y]);
    }

    return 0;
}

Measured memory_bytes: 14336
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main() {
	double x1, y1, x2, y2, x, y, ans;
	cin >> x1 >> y1 >> x2 >> y2;
	x = x1 - x2;
	y = y1 - y2;
	ans = sqrt(x*x + y*y);
	printf("%f", ans);
	return 0;
}

Measured memory_bytes: 1228
# 高橋くんと見えざる手
n, t = map(int, input().split())
a = list(map(int, input().split()))

max_value = [[0, n] for i in range(n + 1)]

# max_value[i]=後ろからi番目までの値で最も大きい値
for i in range(1, n + 1):
    num = a[-i]
    if max_value[i - 1][0] < num:
        max_value[i][0] = num
        max_value[i][1] = n + 1 - i
    else:
        max_value[i] = max_value[i - 1]


min_value = [10**10 for i in range(n + 1)]
# min_value[i]=初めからi番目までの値で最も小さい値
for _ in range(n):
    x = a[_]
    min_value[_ + 1] = min(min_value[_], x)

max_dif = 0
for i in range(1, n + 1):
    if max_value[i][0] > min_value[n - i]:
        max_dif = max(max_dif, max_value[i][0] - min_value[n - i])


disk = []
for i in range(1, n + 1):
    base = a[i - 1]
    if base + max_dif == max_value[n - i][0]:
        disk.append((i, max_value[n - i][1]))

######


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


uni = UnionFind(n)
for some in disk:
    a, b = some[0], some[1]
    uni.union(a, b)
for i in range(n + 1):
    uni.find(i)

# UnionFind

group = {i: [] for i in range(n + 1)}

for i in range(n + 1):
    group[uni.par[i]].append(i)
ans = 0
for i in range(n + 1):
    L = len(group[i])
    ans += L * (L - 1) // 2
print(ans)


Measured memory_bytes: 88596
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			if(a[i] == i + 1) {
				if(i + 1 < N) {
					//swapしないとまずいとき
					cnt++;
					int tmp = a[i];
					a[i] = a[i + 1];
					a[i + 1] = tmp;
				}
				else {
					cnt++;
					int tmp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = tmp;
				}
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 52080
n, m = map(int, input().split())
adjList = [[0] * n for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    adjList[a][b] = 1
    adjList[b][a] = 1
def applyComp(a):
    for i in range(len(a)):
        for j in range(len(a[i])):
            a[i][j] = 1 - a[i][j]
applyComp(adjList)

visited = [0] * n
def dfs(u, parent=-1, color=1):
    if visited[u]:
        if visited[u] != color:
            print(-1)
            exit()
        return 0, 0
    visited[u] = color
    oneCount = 0
    twoCount = 0
    if color == 1:
        oneCount += 1
    else:
        twoCount += 1
    for v in range(n):
        if u == v or u == parent:
            continue
        if adjList[u][v]:
            p = dfs(v, u, 3 - color)
            oneCount += p[0]
            twoCount += p[1]
    return oneCount, twoCount
connSize = []
for i in range(n):
    if visited[i]:
        continue
    connSize.append(dfs(i))
dp = [False] * (n + 1)
dp[0] = True
for c1, c2 in connSize:
    ndp = [False] * (n + 1)
    for i in range(n + 1):
        if dp[i]:
            ndp[i+c1] = True
            ndp[i+c2] = True
    dp = ndp
print(min(sum(sz * (sz - 1) // 2 for sz in [sz1, n - sz1]) for sz1 in range(n+1) if dp[sz1]))

Measured memory_bytes: 85460
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, a, b, c, d;
 
  cin >> N;
  d = N % 10;
  c = ( (N % 100) - d ) / 10;
  b = ( (N % 1000) - c - d ) / 100;
  a = ( N - b - c - d ) / 1000;
  
  if ((a == b && b == c) || (b == c && c == d)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
 }


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int ans = 1;
  for (int i = 0; i < N; i++) {
    if (ans < K)
      ans *= 2;
    else
      ans += K;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = 0;
            while ((n = int.Parse(Console.ReadLine())) != 0)
            {
                int r = 1, a = 1, b = 2, c = 3;
                while (n-- != 0)
                {
                    r += Solve(Console.ReadLine(), ref a, ref b, ref c);
                }
                Console.WriteLine(r);
            }
        }

        static int Solve(string s, ref int a, ref int b, ref int c)
        {
            switch (s)
            {
                case "North":
                    DiceSwap(ref a, ref b);
                    break;
                case "East":
                    DiceSwap(ref c, ref a);
                    break;
                case "West":
                    DiceSwap(ref a, ref c);
                    break;
                case "South":
                    DiceSwap(ref b, ref a);
                    break;
                case "Right":
                    DiceSwap(ref b, ref c);
                    break;
                case "Left":
                    DiceSwap(ref c, ref b);
                    break;
            }
            return a;
        }

        static void DiceSwap(ref int a, ref int b)
        {
            var tmp = a;
            a = b;
            b = 7 - tmp;
        }
    }
}

Measured memory_bytes: 5848
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-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;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint,dijkstra

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        cin>>n;
        vl A(n);
        rep(i,n)cin>>A[i];
        sort(all(A));
        ll sum=0;
        ll res=0;
        rep(i,n-1){
            sum+=A[i];
            if(sum*2>=A[i+1])continue;
            res=i+1;
        }
        cout<<n-res<<endl;
    }

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

int main(){
  int n,x;
  cin>>n>>x;
  vector<int> a(n);
  for(int i=0; i<n; i++)cin>>a.at(i);

  sort(a.begin(),a.end());
  int ans=0;
  for(int i=0; i<n; i++){
    x-=a.at(i);
    ans++;
    if(x<=0)break;
  }
  if(x!=0)ans--;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int h,n;
  cin >> h >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n) h -= a[i];
  if (h <= 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 768
N, qms = map(int, input().split())

raw_proc = [input() for i in range(N)]
queue = [{} for i in range(N+1)]
for i in range(N):
    name, time = raw_proc[i].split()
    time = int(time)
    queue[i] = {"name": name, "time": time}

def enque(tail, p):
    queue[tail] = p
    tail = (tail+1) % (N+1)
    return tail

def deque(head):
    proc = queue[head]
    head = (head+1) % (N+1)
    return proc, head


if __name__ == '__main__':
    head = 0
    tail = N
    total_time = 0
    while head != tail:
        p, head = deque(head)
        t = min(qms, p["time"])
        p["time"] = p["time"] - t
        total_time += t
        if p["time"] > 0:
            tail = enque(tail, p)
        else:
            print("{} {}".format(p["name"], total_time))


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

int main() {
	int x, y;
	int l, s;
	cin >> x >> y;
	if (x > y) {
		l = x; s = y;
	}
	else {
		l = y; s = x;
	}

	while (1) {
		//cerr << l << " " << s << endl;
		int k = l % s;
		if (k == 0) {
			cout << s << endl;
			break;
		}
		l = s;
		s = k;
	}


	return 0;
}

Measured memory_bytes: 1160
#include"bits/stdc++.h"
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (b - 1); i >= a; i--)
#define RREP(i, n) RFOR(i, 0, n)
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define rrep(i, a, b) for (auto i = a; i > b; i--)
#define fs first
#define sc second
typedef pair<int, int> P;

const int N = 1111*1111;
vector<int> flag(N, 0), prime(N,0);
int n, m;
int a[1111][1111];
int ans[1111][1111];
int visit[1111][1111];
int sx, sy, cnt;

void check(int cur, int x, int y) {
	if (cur == n) sx = x, sy = y;
}

void bfs() {
	queue<P> que;
	que.push(P(sx, sy));

	int dy[] = { -1,0,1 };
	while (que.size()) {
		P p = que.front(); que.pop();
		if (p.fs + 1 == cnt) break;
		REP(i, 3) {
			int Y = p.sc + dy[i];
			if (0 <= Y && Y < cnt && a[p.fs + 1][Y] <= m) {
				ans[p.fs + 1][Y] = max(ans[p.fs + 1][Y],ans[p.fs][p.sc] + (prime[a[p.fs + 1][Y]] == 1));
				if(visit[p.fs + 1][Y] == 0) que.push(P(p.fs + 1, Y)), visit[p.fs+1][Y]++;
			}
		}
	}
}

void solve() {
	cin >> m >> n;
	if (n == 0) exit(0);
	cnt = 1;
	while (cnt*cnt < m) cnt += 2;

	int cur = 2, id = 1, x = cnt / 2, y = cnt / 2;
	a[x][y] = 1;

	if (n == 1) sx = x, sy = y;
	
	while (cur <= cnt * cnt) {
		REP(_, id) y++, a[x][y] = cur, check(cur,x,y),cur++;
		REP(_, id) { x--, a[x][y] = cur, check(cur, x, y), cur++; if (cur > cnt*cnt) goto out; }
		REP(_, id + 1) y--, a[x][y] = cur, check(cur, x, y),cur++;
		REP(_, id + 1) x++, a[x][y] = cur, check(cur, x, y),cur++;
		id += 2;
	}
    out:;

	//cout << sx << " " << sy;
	REP(i, cnt) REP(j, cnt) ans[i][j] = 0, visit[i][j] = 0;
	if (prime[a[sx][sy]]) ans[sx][sy] = 1;
	bfs();

	//cout << sx << " " << sy << endl;

	int res = 0 ,num = 0;
	REP(i, cnt) REP(j, cnt) {
		if (prime[a[i][j]] == 0) continue;
		if (ans[i][j] > res) res = ans[i][j], num = a[i][j];
		else if (ans[i][j] == res) num = max(num, a[i][j]);
	}

	if (res == 0) cout << "0 0" << endl;
	else cout << res << " " << num << endl;

}


int main() {
	FOR(i, 2, N) {
		if (flag[i] == 0) {
			prime[i]++;
			FOR(j, 1, N) {
				if (i*j >= N) break;
				flag[i*j]++;
			}
		}
	}

	while (1) solve();
}


Measured memory_bytes: 25520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

bool compare(int a, int b, int c) {
  if(a == b && a == c && b == c) return true;
  return false;
}

int A[3][3];

void solve(istream& cin, ostream& cout) {
  REP(i, 3) REP(j, 3) cin >> A[i][j];
  int N;
  cin >> N;
  vector<int> b(N);
  REP(i, N) cin >> b[i];
  REP(k, N) REP(i, 3) REP(j, 3) {
      if (b[k] == A[i][j]) A[i][j] = 0;
  }
  bool flag = false;
  REP(i, 3) {
    if(compare(A[i][0], A[i][1], A[i][2]) ||
    compare(A[0][i], A[1][i], A[2][i])) {
      flag = true;
      break;
    }
  }
  if (compare(A[0][0], A[1][1], A[2][2]) ||
  compare(A[0][2], A[1][1], A[2][0])) flag = true;
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<pair<int, int>> vc(n);
	for (int i = 0; i < n; i++) {
		cin >> vc[i].first;
	}
	for (int i = 0; i < n; i++) {
		cin >> vc[i].second;
	}
	int max = -1;
	int t = 0;
	for (int i = 0; i < pow(2, n); i++) {
		t = 0;
		for (int j = 0; j < n; j++) {
			if ((i >> j) & 1 == 1) {
				t += vc[j].first - vc[j].second;
			}
		}
		if (max < t) {
			max = t;
		}
	}
	cout << max << endl;

	return 0;
}

Measured memory_bytes: 256
N,A,B = map(int,input().split())
H = []
for _ in range(N):
    H.append(int(input()))
H = sorted(H)
def check(x):
    cnt = 0
    for h in H:
        if h > x * B:
            tmp = (h - x*B) // (A-B)
            #切り上げ
            if tmp * (A-B) != h - x*B: tmp += 1
            cnt += tmp
    if cnt <= x:
        return True
    else:
        return False
# (l,r]
def bisect(l,r):
    if r - l == 1: return r
    mid = (l+r) // 2
    if check(mid):
        return bisect(l,mid)
    else:
        return bisect(mid,r)
    
print(bisect(0,10**12))


Measured memory_bytes: 8284
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
	int ans = 0;
  	ll n, k; cin >> n >> k;
  	while (n != 0) {
    	n /= k;
      	ans += 1;
    }
  	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using 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,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000000;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<int>h(N);
	rep(i, N)cin >> h[i];
	int ans = 0;
	vector<int>cnt(N, 0);
	while (1) {
		bool is = false;
		rep(i, N) {
			if (h[i] == cnt[i]) {
				if (is)break;
				else continue;
			}
			else {
				is = true;
				++cnt[i];
			}
		}
		if (!is) {
			cout << ans << "\n";
			return 0;
		}
		++ans;
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String N = in.next();

            int n = Integer.valueOf(N);
            int s = 0;

            for (int i = 0; i < N.length(); i++) {
                s += Integer.valueOf(N.charAt(i) - 48);
            }

            if (n % s == 0) {
                out.println("Yes");
            } else {
                out.println("No");
            }
            return;

        }

    }
}



Measured memory_bytes: 21844
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int n;

int main()
{
    cin >> n;
    vector<vector<int>> to(n), dist(n);
    vector<int> ans(n,-1);
    queue<int> q;

    for (int i = 0; i<n-1;i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        to[a].push_back(b), dist[a].push_back(c);
        to[b].push_back(a), dist[b].push_back(c);
    }
    q.push(0);
    ans[0] = 0;
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for (int i = 0; i < to[v].size();i++){
            int a = to[v][i];
            int w = dist[v][i];
            if(ans[a]!=-1)
                continue;
            ans[a] = (ans[v] + w) % 2;
           // cerr << a << " " << ans[a] << endl;
            q.push(a);
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 11904
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    ll A,B,C,D,E,N,X[10];
    ll ans=0;
    string S;
    bool F;
int main(){
    REP(i,5)cin>>X[i];
    REP(i,5){
        if(X[i]==0){cout<<i+1;}
    }
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;
using ll=long long;
const int mod=1e9+7;
const int N = 2e5+5;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderset; 

vector<ll> sieve(ll n) {     
    bool prim[n+1]; 
    memset(prim, true, sizeof(prim)); 
  
    for (ll p=2; p*p<=n; p++) {
        if (prim[p] == true) { 
            for (ll i=p*p; i<=n; i += p) 
                prim[i] = false; 
        } 
    }
    vector<ll>vec;
    for(int i=2;i<=n;i++){
        if(prim[i]){
            vec.push_back((ll)i);
        }
        
    }
    return vec;
}


void solve(){
  string s;
  cin>>s;
  s.back()=='s'?cout<<s<<"es":cout<<s<<"s";
   
  
    
}

int main(){
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout); 
    #endif*/
        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
        int T=1;
        //cin>>T;
        while(T--){
          solve();
        }
        return 0;
        
}

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

int main(){
    int N;
    cin >> N;
    int B[N-1];
    for(int i=0; i<N-1; i++){
        cin >> B[i];
    }
    int ans = B[0];
    for(int i=1; i<N-1; i++){
        ans += min({B[i],B[i-1]});
    }
    ans += B[N-2];

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

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

int main() {
    int k, ans = 0;
    cin >> k;
    REP(i, 1, k) REP(j, i+1, k+1) {
        if ((i % 2 == 0 && j % 2 == 1) || (i % 2 == 1 && j % 2 == 0)) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

const int maxn=3e2+7;
char mp[maxn][maxn];

int main (){
    int ans=0,n;
    cin>>n;
    for(int i=0;i<n;i++) scanf("%s",mp[i]);
    for(int i=0;i<n;i++){
        int cnt=n;
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++)
                if(mp[(k+i)%n][j]!=mp[(j+i)%n][k]) cnt=0;
        }
        ans+=cnt;
    }
    cout<<ans<<endl;
    return 0;
}


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

#define T first
#define S second
int main() {
    int n; cin >> n;
    vector<pair<int, int>> acts(n);             // t, s
    for (auto &p: acts) cin >> p.S >> p.T;      // s, t
    sort(acts.begin(), acts.end());
    int ans = 0, lst = 0;
    for (auto p: acts) if (lst < p.S) ans++, lst = p.T;
    cout << ans << endl;
    return 0;
}


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

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, k, n) for (int i = (k); i < (n); i++)
#define rrep(i, k, n) for (int i = (k); i > (n); i++)
#define pb push_back
#define vec vector
#define ref(a) &(a)

typedef long long ll;

using namespace std;

int n;
vec<int> p;

int solve() {
  int c = 0;
  rep(i, n) {
    if (i && n - i > 1) {
      vec<int> v; irep(j, i-1, i+2) v.pb(p[j]);
      sort(v.begin(), v.end());
      if (p[i] == v[1]) c++;
    }
  }
  return c;
}

int main() {
  cin >> n;
  rep(i, n) {
    int x; cin >> x;
    p.pb(x);
  }
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 
 using namespace std;
  
 int main()
 {
   long long int n;
   long long result=1;
   cin>>n;
   while(n>1)
   {
     result*=n;    
     n--;
   }
   cout<<result<<endl;
   //while(1);      
   return 0;    
 }

 
 

Measured memory_bytes: 3024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
typedef long long ll;
//プロトタイプ宣言
int gcd(int , int);


int main(){
  ios_base::sync_with_stdio(false);
  ll n,ans = 0;
  cin >> n;
  string s;
  unordered_map<string,ll> mp;
  while(n>0){
    cin >> s;
    sort(s.begin(),s.end());
    ans += mp[s];
    mp[s]++;
    n--;
  }
  cout << ans << endl;
}








































//以下、ライブラリ
//ユークリッドの互除法

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
}



Measured memory_bytes: 10660