akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
	int x,n,m,k,i,r;
	for(;scanf("%d",&n),n;printf("%d\n",r)){
		vector<set<int> >v;
		for(i=0;i<n;i++){
			set<int>s;
			for(scanf("%d",&m),k=0;k<m;k++)scanf("%d",&x),s.insert(x);
			v.push_back(s);
		}
		set<int>t;
		for(scanf("%d",&k),m=0;m<k;m++)scanf("%d",&x),t.insert(x);
		for(r=-1,k=0;k<n;k++){
			set<int>s;
			set_intersection(v[k].begin(),v[k].end(),t.begin(),t.end(),inserter(s,s.end()));
			if(s.size()==t.size()){if(~r){r=-1;break;}r=k+1;}
		}
	}
}

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

using namespace std;

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

int main() {
  const int mod = 1e9 + 7;
  fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
  for (int i = 2; i < 100005; 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;
  }
  auto nCr = [&](int n, int r) -> long long {
    if (n < 0 or r < 0 or n < r) {
      return 0;
    }
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
  };

  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (auto &a : A) {
    cin >> a;
  }
  sort(A.begin(), A.end());
  long long f_max = 0;
  long long f_min = 0;
  for (int i = 1; i <= N; i++) {
    f_max += ((A[i - 1] % mod) * nCr(i - 1, K - 1)) % mod;
    f_max %= mod;
    f_min += ((A[i - 1] % mod) * nCr(N - i, K - 1)) % mod;
    f_min %= mod;
  }
  long long ans = (f_max - f_min) % mod;
  if (ans < 0) {
    ans += mod;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long long sum;
	int n, p, even = 0, odd = 0;
	scanf("%d %d", &n, &p);
	for (int i = 0; i < n; i++)
	{
		int temp;
		scanf("%d", &temp);
		if (temp % 2 == 0)even++;
		else odd++;
	}
	long long r = pow(2, n);
	if (p == 0)
	{
		if (odd == 0)
		{
			printf("%lld\n", r);
		}
		else
		{
			sum = pow(2, n - 1);
			printf("%lld\n", sum);
		}
	}
	else
	{
		if (odd == 0)
		{
			printf("0\n");
		}
		else
		{
			sum = pow(2, n - 1);
			printf("%lld\n", sum);
		}
	}
	return 0;
}

Measured memory_bytes: 256
import math

N = int(input())
A = list(map(int, input().split()))

gcd_l = [0]
gcd_r = [0]

for n in range(N):
    gcd_l.append(math.gcd(gcd_l[n], A[n]))
    gcd_r.append(math.gcd(gcd_r[n], A[-(n + 1)]))
#print(gcd_r)
#print(gcd_l)

gcd_r = gcd_r[::-1]
#print(gcd_r)

ans = []
for n in range(N):
    ans.append(math.gcd(gcd_l[n], gcd_r[n + 1]))
print(max(ans))
#print(ans)


Measured memory_bytes: 25752
#include <iostream>
using namespace std;
#define MAX 50
#define NIL -1
#define rep(i, n) for(int i=0;i<n;i++)

struct Node {int parent, left,right;};
Node T[MAX];

void preWalk(int u){
    if(u==NIL) return;
    cout << " " << u;
    preWalk(T[u].left);
    preWalk(T[u].right);
}
void InWalk(int u){
    if(u==NIL) return;
    InWalk(T[u].left);
    cout << " " << u;    
    InWalk(T[u].right);
}
void PostWalk(int u){
    if(u==NIL) return;
    PostWalk(T[u].left);
    PostWalk(T[u].right);
    cout << " " << u;
}

int main(void){
    int n,l,r,v,root=0;
    cin >> n;
    rep(i, n){
        T[i].parent = NIL;
    }

    rep(i, n){
        cin >>v >> l >> r;
        T[v].left = l;
        T[v].right = r;
        if(l != NIL) T[l].parent=v;
        if(r != NIL) T[r].parent=v;
    }

    rep(i, n){
        if(T[i].parent == NIL) root = i;
    }

    cout<<"Preorder" << endl;
    preWalk(root);
    cout <<endl;
    cout<<"Inorder" << endl;
    InWalk(root);
    cout <<endl;
    cout<<"Postorder" << endl;
    PostWalk(root);
    cout <<endl;
    return 0;
}

Measured memory_bytes: 3048
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
  int H, W, h, w;
  cin >> H >> W;
  cin >> h >> w;
  cout << (H-h)*(W-w) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
int main()
{
    int x;
    cin>>x;
    x%=10;
    if(x==3) puts("bon");
    else if(x==1 || x==0 || x==6 || x==8)
        puts("pon");
    else puts("hon");
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  bool isok = false;
  repeat(i,N/4+1){
    isok |= (N-4*i)%7==0;
  }
  cout << (isok? "Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int A,B,flag = 0;
	cin >> A >> B;
	for (int i = 1;i <=3;i++){
		if (A*B*i % 2 == 1){
			flag = 1;
			break;
		}
	}
	if(flag == 1){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef vector<ll> v1;
typedef vector<v1> v2;

typedef vector<vector<ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

ll n;
v2 a[20];
ll ans = 0;

bool solve(ll bit){
    // cerr << "-----" << bit << endl;
    for(ll i = 0;i < n;i++){
        if((bit & (1 << i)) != 0){
            // cerr << "!!!" << i << endl;
            // cerr << "!!!!!!" << a[i].size() << endl;
            for(v1 hoge : a[i]){
                ll x,y;
                x = hoge[0];
                y = hoge[1];
                // // cerr << x << " " << y << "-";
                if((bit & (1 << (x-1))) == 0 && y == 1) return false;
                if((bit & (1 << (x-1))) != 0 && y == 0) return false;

            }
            // // cerr << endl;
        }
    }
    // cerr << "!" << bit << endl;
    return true;
}

int main(){
    cin >> n;
    for(ll i = 0;i < n;i++){
        ll c;
        cin >> c;
        for(ll j = 0;j < c;j++){
            ll x,y;
            cin >> x >> y;
            a[i].push_back(v1({x,y}));
        }
    }
    for(ll bit = 0;bit < (1 << n);bit++){
        if(solve(bit)){
            ans = max(ans,(ll)__builtin_popcount(bit));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111





	void solve(){

		ini(n);
		vector<string> morty(n);
		FOR(i,0,n){
			in(morty[i]);
		}
		string rick;
		FOR(i,0,morty[0].size()){
			int one = 0;
			FOR(i1,1,n){
				FOR(i2,0,morty[i1].size()){
					if(morty[i1][i2] == morty[0][i]){one++;morty[i1].erase(i2,1);break;}
				}
			}
			if(one == n-1)rick+=morty[0][i];
		}
		sort(all(rick));
		out(rick);
		












	}









































int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

const ll mod = 1e9 + 7;

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

  vll s(n+1);
  rep(i, n) cin >> s[i];
  s[n] = INF;
  Sort(s);

  ll ans = 0;
  cin >> q;
  rep(i, q) {
    ll ti;
    cin >> ti;
    ll l = 0;
    ll r = n;
    while (l + 1 != r) {
      ll m = (l + r) / 2;
      if (s[m] > ti) 
        r = m;
      else
        l = m;
    }
    if (s[l] == ti) ans++;
  }  // i

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3536
N,M = [int(x) for x in input().split()]
X= [int(x) for x in input().split()]

X.sort()

Y = []
x = X[0]
for i in range(1,M):
    Y.append(abs(x - X[i]))
    x = X[i]

Y.sort(reverse=True)
ans = max(X) - min(X) - sum(Y[0:N-1])

print(ans)
  

Measured memory_bytes: 13840
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;

int main(){
	int x,y,z;
	cin>>x>>y>>z;
	cout<<(x - z) / (y + z)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n,k; cin>>n>>k;
	char s[100];
	for (int i=1; i<=n; i++) cin>>s[i];
	for (int i=1; i<=n; i++)
	{
		if (i==k) cout << (char)(s[i]-'A'+'a');
		else cout << s[i];
	}
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define P pair<int,int>
#define All(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
typedef long long ll;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
const ll LINF = 1e18;
int main() {
	int n;
	string s, w;
	cin >> n >> s >> w;
	for (int i = 0; i <= n; i++) {
		if (s.substr(i) == w.substr(0, n - i)) {
			cout << n + i << endl;
			return 0;
		}
	}
}

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

int main() {
  double w, h;
  int x, y;
  cin >> w >> h >> x >> y;
  double s = w*h/2;
  int ans;
  if (w == 2*x && h == 2*y) ans = 1;
  else ans = 0;
  printf("%lf %d\n", s, ans);
  return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

#define MAX 2500

template <typename T>
struct edge {
    int from, to;
    T cost;
    edge(int from, int to, T cost = 1) : from(from), to(to), cost(cost) {}
    bool operator<(const edge& e) const {
        return cost < e.cost;
    }
};

/*
    sからたどりつける負の閉路を検出したとき、空の vector を返す
    頂点数 V, 始点 s, 辺の集合 es, INF として LINF を使うとき :
    vector<ll> dist = BellmanFord(V, s, es, LINF);
*/
template <typename T>
vector<T> BellmanFord(int V, int s, vector<edge<T>>& es, const T INF = 1e9) {
    vector<T> dist(V, INF);
    dist[s] = 0;
    for (int i = 0; i < V - 1; i++) {
        for (edge<T>& e : es) {
            if (dist[e.from] == INF) continue;
            dist[e.to] = min(dist[e.to], dist[e.from] + e.cost);
        }
    }
    for (edge<T>& e : es) {
        if (dist[e.from] == INF) continue;
        if (dist[e.from] + e.cost < dist[e.to]) return vector<T>();
    }
    return dist;
}

template <typename T>
bool FindNegativeLoop(int V, vector<edge<T>>& es) {
    vector<T> dist(V, 0);
    for (int i = 0; i < V; i++) {
        for (edge<T>& e : es) {
            if (dist[e.to] > dist[e.from] + e.cost) {
                dist[e.to] = dist[e.from] + e.cost;
                if (i == V - 1) return true;
            }
        }
    }
    return false;
}

bool reached[MAX];
vector<int> G[MAX];

void dfs(int cur){
    if (reached[cur]) return;
    reached[cur] = true;
    for (int to : G[cur]) {
        dfs(to);
    }
}

signed main() {
    int n, m;
    ll p;
    cin >> n >> m >> p;
    vector<edge<ll>> es;
    int a[m], b[m];
    ll c[m];
    rep(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        G[b[i]].emplace_back(a[i]);
    }
    dfs(n - 1);
    rep(i, m) {
        if (!reached[a[i]] || !reached[b[i]]) continue;
        c[i] -= p;
        c[i] = -c[i];
        es.emplace_back(a[i], b[i], c[i]);
    }
    auto dist = BellmanFord(n, 0, es, LINF);
    cout << (dist.empty() ? -1 : max(0LL, -dist[n - 1])) << endl;
    return 0;
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define input(array) repi(array##_itr, array) { cin >> *(array##_itr); }
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	int ans=INF;
	cin >>n;
	Vi x(n);
	input(x);
	int cnt = 0;
	sort(all(x));
	for (int i = x[0]; i <= x.back(); i++) {
		cnt = 0;
		rep(j, n) { cnt += (x[j] - i) * (x[j] - i); }
		chmin(ans, cnt);
	    }
	cout << ans << endl;
}

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

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

	int p[M], num[100010] = {0};
	string S[M];

	set<int> used;

	int correctCount = 0;
	int wrongCount = 0;
	
	for (int i = 0; i < M; i++) {

		cin >> p[i] >> S[i];

		if (S[i] == "AC" &&  !used.count(p[i]) ) {			
			correctCount++;
			wrongCount += num[p[i]-1];
			used.insert(p[i]);
		}
		else if (S[i] == "AC" && used.count(p[i])) {
		}
		else { // S[i] == "WA"
			num[p[i]-1]++;
		}
	}

	cout << correctCount << " " << wrongCount<< endl;

	return 0;
}

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

int HowInclude2(int n) { // nを素因数分解したときに含まれる2の数
	int ans = 0;
	while (n % 2 == 0) { // 偶奇判定 2で割った余り……でも良いけど、2進数のコンピュータ上では!(n & 1)の方が速いよ
		n /= 2; // これもn >> 1の方が速い
		ans ++;
	}
	return ans;
}
int main() {
	int N, A;
	cin >> N >> A;
	int ans = HowInclude2(A);
	for (int i = 1;i < N;i ++) {
		cin >> A;
		ans = min(ans, HowInclude2(A)); // これによりansは常に解説のmin(B_1...B_i)の状態を保つよ
		// min(B_1...B_i)=min(min(B_1...B_(i-1)), B_i)であることを利用ね
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

操作を行えなくなる時はあるA_iが奇数になった時。
つまり、配列B_iをA_iを素因数分解した時含まれる2の数と定義すると、
min(B_1...B_i)が操作の行える回数になるよ
*/

Measured memory_bytes: 256
def xor(x,y):
  return str(int(x)+y).replace("2", "0")
  
input()
s = list(map(int, input().split()))
t = list(map(lambda x: int(bin(x)[2:]), s))

ans = 0
r = 0
x = 0
y = "0"
for i in range(len(s)):
  ans += r - i
  for j in range(r, len(s)):
    nx = x + s[j]
    ny = xor(y, t[j])
    if bin(nx)[2:] == ny:
      ans += 1
      r += 1
      x = nx
      y = ny
    else:
      break
  x = x - s[i]
  y = xor(y, t[i])

print(ans)

Measured memory_bytes: 25832
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
  	cin>>s;
 	int i,j,n=s.size(),count=0;
  	
  	for(i=2;i<n;i+=2){
      count=0;
		for(j=0;j<(n-i)/2;j++){
          	if(s[j]!=s[j+(n-i)/2]){
              count++;
            }
        }
      if(count==0){
         cout<<n-i<<endl;
			return 0;
      }

    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int n=0;
		for (int i = 0; i < S.length(); i++) {
			if(S.charAt(i)=='+'){
				n=n+1;
			}else{
				n=n-1;
			}
		}
		System.out.println(n);
	}
}

Measured memory_bytes: 22612
#include <cstdio>

long long int n, v, u;
int main() {
	scanf("%lld", &n);
	long long int ans = 0;
	for(int i = 1; i <= n; ++i)
	ans += (long long int)(n - i + 1) * i;
	for(int i = 1; i < n; ++i){
		scanf("%lld%lld", &v, &u);
		if(v > u){
			int t = v;
			v = u;
			u = t;
		}
		ans -= v * (n - u + 1);
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string S; cin >> S;
	int n = (int)S.length();
	string pattern1 = "", pattern2 = "";
	rep (i, n){
		if (i % 2 == 0){
			pattern1 += '0', pattern2 += '1';
		}else{
			pattern1 += '1', pattern2 += '0';
		} // end if
	} // end rep
	
	int curr1 = 0, curr2 = 0;
	rep (i, n){
		curr1 += (int)(S[i] != pattern1[i]);
		curr2 += (int)(S[i] != pattern2[i]);
	} // end rep
	
	int res = min(curr1, curr2);
	
	cout << res << endl;

	return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, m, a[101];
void solve(){
	cin >> n >> m;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		cnt += a[i];
	}
	
	int ans = m;
	for(int i = 0; i < n; i++){
		if(cnt <= a[i]*4*m) ans--;
	}
	if(ans>0) cout << "No" << endl;
	else cout << "Yes" << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <numeric>
#include <algorithm>

using namespace std;

// r = a^n % mod
int64_t mod_pow(int64_t a, int64_t n, int64_t mod) {
  int64_t r = 1;
  while (n > 0) {
    if (n & 1) {
      r = (r * a) % mod;
    }
    a = (a * a) % mod;
    n >>= 1;
  }
  return r;
}

// a^{-1} % mod
int64_t mod_inv(int64_t a, int64_t mod) {
  return mod_pow(a, mod-2, mod);
}

const int64_t kMod = 1000000007;
const int kMax = 2000017;
std::vector<int64_t> fact(kMax), fact_inv(kMax);

void combi_init() {
  const int n = fact.size();
  fact[0] = 1;
  for (int i = 1; i < n; ++i) {
    fact[i] = (i * fact[i-1]) % kMod;
  }
  fact_inv[n-1] = mod_inv(fact[n-1], kMod);
  for (int i = n-1; i > 0; --i) {
    fact_inv[i-1] = (i * fact_inv[i]) % kMod;
  }
}

int combi(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return (((fact[n] * fact_inv[k]) % kMod) * fact_inv[n-k]) % kMod;
}

int f(int r, int c) {
  return combi(r+c, c);
}

int g(int r, int c) {
  return (f(r+1, c+1) - 1 + kMod) % kMod;
}

int S(int r1, int c1, int r2, int c2) {
  return (g(r2, c2) - g(r2, c1-1) - g(r1-1, c2) + g(c1-1, r1-1) + kMod) % kMod;
}

int main() {
  combi_init();
  int r1, c1, r2, c2;
  std::cin >> r1 >> c1 >> r2 >> c2;
  std::cout << S(r1, c1, r2, c2) << std::endl;
  return 0;
}


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

int main(void){
  int n,l[11],sum = 0;
  cin >> n;
  for(int i = 0; i < n; i++)cin >> l[i];
  sort(l,l + n);
  for(int i = 0; i < n - 1; i++)sum += l[i];
  if(l[n - 1] >= sum)cout << "No\n";
  else cout << "Yes\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
pair<int, int> edge(int x_1, int y_1, int x_2, int y_2) {
  int x = x_2 + y_1 - y_2;
  int y = y_2 - x_1 + x_2;
  pair<int, int> p = make_pair(x, y);
  return p;
}
int main() {
  int x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4;
  cin >> x_1 >> y_1 >> x_2 >> y_2;
  pair<int, int> p = edge(x_1, y_1, x_2, y_2);
  x_3 = p.first;
  y_3 = p.second;
  pair<int, int> q = edge(x_2, y_2, x_3, y_3);
  x_4 = q.first;
  y_4 = q.second;
  cout << x_3 << " " <<  y_3 << " " << x_4 << " " << y_4 << endl;
}

Measured memory_bytes: 3540
#!/usr/bin/env python3
q = int(input())
ans = ""
 
# 左から埋める
while True:
  q, mod = divmod(q, 26)

  if mod == 0:
    mod = 26
    q -= 1
 
  num2alpha = lambda c: chr(c + 96)
  ans = num2alpha(mod) + ans
 
  if q == 0:
    break
 
print(ans)


Measured memory_bytes: 8940
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;


Node treeSearch(Node x, int k){
  while(x!=NIL && k!=x->key){
  if(k < x->key)
    x=x->left;
  else
    x=x->right;
  }
  return x;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y=x;
    if(z->key < x ->key)
      x=x->left;
    else
      x=x->right;
  }
  z->parent=y;
  if(y==NIL)
    root=z;
  else if(z->key < y->key)
    y->left=z;
  else
    y->right=z;
}
      


void inorder(Node u){
  if(u==NIL)
    return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)
    return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);


  
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    long long k;
    cin>>k;
    long long i=0;
    char ans='1';
    long long l=s.size();
    while(i<k&&i<l)
    {
        if(s[i]=='1')
        i++;
        else{
            ans=s[i];break;
        }
    }
    cout<<ans<<endl;
    return 0;    
}

Measured memory_bytes: 256
#!/usr/bin/env python

H, W, A, B = list(map(int,input().split()))

# 1 1 1 1 1 1 0 0 0 
# 1 1 1 1 1 1 0 0 0
# 0 0 0 0 0 0 1 1 1
# 0 0 0 0 0 0 1 1 1
# 0 0 0 0 0 0 1 1 1


row1 = "1" * max(A, W-A) + "0" * min(A,W-A)
row2 = "0" * max(A, W-A) + "1" * min(A,W-A)
for i in range(max(B,H-B)):
    print(row1)
for i in range(min(B,H-B)):
    print(row2)

Measured memory_bytes: 3956
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    T,A=map(int,input().split())
    for _ in range(N-1):
        t,a=map(int,input().split())
        res=max(-(-T//t),-(-A//a))
        T,A=t*res,a*res
    print(T+A)

if __name__ == '__main__':
    main()


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

int main() {
	int a,b,c,d;
	cin>>a>>b>>c;
	d=c-a;
	if(d<=b){
		if(c-a<=0){d=0;}
		cout<<d<<endl;
	}
	else{
		cout<<"NA"<<endl;
	}
	return 0;
}



Measured memory_bytes: 3096
from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(Q)]
ans = 0
for A in combinations_with_replacement(range(1, M+1), N):
    ans = max(ans, sum(d for a, b, c, d in l if A[b-1]-A[a-1]==c))
print(ans)


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

int main()
{
    
int n,k;cin>>n>>k;int arr[n];for(int i=0;i<n;i++)cin>>arr[i];
int dp[n];
for(int i=1;i<n;i++)
dp[i]=INT_MAX;
dp[0]=0;
for(int i=1;i<n;i++)
{
    if(i-k<0)
    {
        for(int j=0;j<i;j++)
        {
              dp[i]=min(dp[i],dp[j]+abs(arr[i]-arr[j]));
        }
    }
    else
    
    {
        for(int j=i-k;j<i;j++)
        dp[i]=min(dp[i],dp[j]+abs(arr[i]-arr[j]));
    }
}

cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-04 18:34:18
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  string s; cin >> s;
  int n = s.size();

  // p <= g

  int score = s[0] == -1 * 'g';
  int cnt_g = s[0] == 'g', cnt_p = s[0] == 'p';

  for (int i = 1; i < n; ++i) {
    if (s[i] == 'g') {
      if (cnt_p + 1 <= cnt_g) {
        ++cnt_p; ++score;
      } else {
        ++cnt_g;
      }
    } else {
      if (cnt_p + 1 <= cnt_g) {
        ++cnt_p;
      } else {
        ++cnt_g; --score;
      }
    }
  }

  cout << score << endl;

  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll h,n;
	cin >> h >> n;
	vll dp(h+1,INF);
	vvll vp(n,vll(2));
	rep(i,n){
		cin >> vp[i][0] >> vp[i][1];
	}
	dp[0]=0;
	for(ll i=1;i<=h;i++){
		for(ll j=0;j<n;j++){
			if(i-vp[j][0]<0){
				dp[i]=min(dp[i],vp[j][1]);
			}
			else{
				dp[i]=min(dp[i],dp[i-vp[j][0]]+vp[j][1]);
			}
		}
	}
	cout << dp[h] << endl;
	return 0;
}


Measured memory_bytes: 384
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MAX = 10**18
MIN = -10**18
MOD = 998244353

k,s = map(int,input().split())

cnt = 0
for i in range(k+1):
    for j in range(k+1):
        l = s-i-j
        if l>=0 and l<=k:
            cnt += 1
print(cnt)

Measured memory_bytes: 3956
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

void main()
{
    auto N = readln.chomp.to!long;
    if (!N) {
        writeln(0);
        return;
    }
    auto m = N < 0 ? 0 : 1;
    if (!m) N = -N;
    bool k;
    foreach (i; m..(62+m)) {
        if (i % 2 != m) continue;
        auto j = i + 1;
        auto x = N & (1L<<i);
        auto y = N & (1L<<j);
        if (k) {
            if (x) {
                if (y) {
                    N &= ~(1L<<i);
                    N &= ~(1L<<j);
                    k = true;
                } else {
                    N &= ~(1L<<i);
                    N |= 1L<<j;
                    k = false;
                }
            } else {
                if (y) {
                    N |= 1L<<i;
                    N &= ~(1L<<j);
                    k = true;
                } else {
                    N |= 1L<<i;
                    N |= 1L<<j;
                    k = false;
                }
            }
        } else {
            if (x) {
                if (y) {
                    N &= ~(1L<<j);
                    k = true;
                } else {
                    N |= 1L<<j;
                    k = false;
                }
            }
        }
    }
    writefln("%b", N);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
using namespace std;
using i64 = int64_t;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr i64 MOD = 1000000007;
constexpr i64 INF = 1LL << 60;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; cin >> n;
	vector<pair<int, int>> p;
	rep(i, 0, n) {
		int a;
		cin >> a;
		p.emplace_back(a, i);
	}
	sort(p.begin(), p.end());
	vector<int> ans(n);

	rep(i, 0, n) {
		int j = p[i].second;
		if (i < n / 2) ans[j] = p[n / 2].first;
		else ans[j] = p[n / 2 - 1].first;
	}
	rep(i, 0, n) cout << ans[i] << '\n';
	return 0;
}

Measured memory_bytes: 5580
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<cmath>
#include<iomanip>
using namespace std;

int main(void){
	int N,A[1000],c,hokan,flag,j,i,kaisuu;
	cin>>N;
	for(c=0;c<N;c++){
		cin>>A[c];
	}
	flag=1;
	i=0;
	kaisuu=0;
	while(flag){
		flag=0;
		for(j=N-1;i<j;j--){
			if(A[j]<A[j-1]){
				hokan=A[j];
				A[j]=A[j-1];
				A[j-1]=hokan;
				flag=1;
				kaisuu++;
			}
		}i++;
	}	for(c=0;c<N;c++){
		cout<<A[c];
		if(c!=N-1){
			cout<<" ";
		}else{
			cout<<endl;
		}
	}cout<<kaisuu<<endl;
	return 0;
}



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

int main() {
  int n;cin>>n;
  vector<int> a(n);
  set<int> st;
  rep(i,n){
    cin>>a[i];
    st.insert(a[i]);
  }
  if(n==st.size())cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 13472
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
  public static void main(String[] args) {
    try {
      BufferedReader stdReader =
        new BufferedReader(new InputStreamReader(System.in));
      String line0;
      line0 = stdReader.readLine();
      int line1 =Integer.parseInt(line0);
      int hour=line1/3600;
      int minute=(line1%3600)/60;
      int sec=(line1%3600)%60;
      stdReader.close();
      System.out.println(hour+":"+minute+":"+sec);
    } catch (Exception e) {
      e.getStackTrace();
      /*?????´??????0??????*/
      System.exit(0); 
    }
  }
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll x, y;
    cin >> x >> y;
    ll ans;
    if (x > y)
    {
        if (x < 0)
        {
            ans = 2 + abs(y) - abs(x);
        }
        else if (y > 0)
        {
            ans = 2 + abs(x) - abs(y);
        }
        else
        {
            ans = 1 + max(abs(x) - abs(y), abs(y) - abs(x));
        }
    }
    else if (y > x)
    {
        if (y <= 0)
        {
            ans = abs(x) - abs(y);
        }
        else if (x >= 0)
        {
            ans = abs(y) - abs(x);
        }
        else 
        {
            ans = 1 + max(abs(x) - abs(y), abs(y) - abs(x));
        }
    }
    else
    {
        ans = 0;
    }
    
    cout << ans << endl;
}


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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  char c; cin >> c;
  c = c + 1;
  cout << c << endl;
}


Measured memory_bytes: 3596
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
N, Y = ri_()
for i in range(N + 1):
    for j in range(N + 1):
        if 1000 * (N - i - j) == Y - 10000 * i - 5000 * j and N - i - j >= 0:
            print(i, j, N - i - j)
            exit()
print(-1, -1, -1)

Measured memory_bytes: 3188
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    TreeMap<String, TreeMap<Integer, Integer>> map = new TreeMap<String, TreeMap<Integer, Integer>>();

    for (int i = 0; i < n; i++) {
      String s = sc.next();
      int p = sc.nextInt();
      int ord = i + 1;
      if (map.containsKey(s)) {
        map.get(s).put(p, ord);
      } else {
        TreeMap<Integer, Integer> maptmp = new TreeMap<Integer, Integer>(Comparator.reverseOrder());
        maptmp.put(p, ord);
        map.put(s, maptmp);
      }
    }

    for (String key : map.keySet()) {
      for (int p : map.get(key).keySet()) {
        System.out.println(map.get(key).get(p));
      }
    }

  }
}

Measured memory_bytes: 36268
#include<iostream>
#include<vector>
#include<algorithm>


using namespace std;

int main(){
    int N,A,B,C,D;
    scanf("%d%d%d%d%d",&N,&A,&B,&C,&D);

    int mA , mC;
    int pB=0, pD=0;
    for(int i=1; i<=1000;i++){
        mA = A*i;
        if(N<=mA){
            pB = i*B;
            break;
        }

    }
    for(int i=1; i<=1000;i++){
        mC = C*i;
        if(N<=mC){
            pD = i*D;
            break;
        }

    }
    if(pD > pB){
        printf("%d\n",pB);
    }
    else{
        printf("%d\n",pD);
    }
    return 0;
}


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

struct P {int x,y;};

int main () {
  P p[4]={{-1,0},{0,-1},{1,0},{0,1}}; int n;
  while(cin>>n,n!=0){
    vector<P> v{{0,0}};int x0=0,y0=0,x1=0,y1=0;
    for(int i=1;i<n;++i){
      int a,b,x,y;cin>>a>>b;v.push_back({x=v[a].x+p[b].x,y=v[a].y+p[b].y});
      x0=min(x0,x);y0=min(y0,y);x1=max(x1,x);y1=max(y1,y);
    }
    cout<<x1-x0+1<<' '<<y1-y0+1<<endl;
  }
}

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

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

	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());

	if(s < t) cout << "Yes" << endl;
	else cout << "No" << endl;

}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c)
#define Scs(s) scanf("%s", s)
#define Scstr(s) scanf("%s", &s)
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

ll PowMod( ll b, ll k, ll m ){
  ll mul = 1;
  while( k ){
    if( k&1 ) mul *= b, mul %= m;
    b *= b;
    b %= m;
  	k >>= 1;
  }
  return mul;
}

int popn( int k ){
  int cnt = 0;
  while(k){
  	k -= ((-k)&k);
    cnt++;
  }
  return cnt;
}

int main() {
  
  int N;
  Scd(N);
  char s[202020];
  Scs(s);
  
  int B = 0;
  Rep(i,N) B += (s[i]=='1');
  
  if( B == 1 ){
    Rep(i,N){
      if( s[i] == '1' ) printf("0\n");
      else printf("%d\n", 1 + (i == N-1) );
    }
     return 0;
  }
  
  int X = B+1;
  int Y = B-1;
  int nx = 0;
  int ny = 0;
  Rep(i,N){
  	if( s[i] == '1' ) {
      nx += PowMod(2,N-i-1,X);
      ny += PowMod(2,N-i-1,Y);
      nx %= X;
      ny %= Y;
    }
  }
  
  int T;
  int ans;
  Rep(i,N){
    if( s[i] == '1' ){
      T = ny - PowMod(2,N-i-1,Y) + Y;
      T %= Y;
    }else{
      T = nx + PowMod(2,N-i-1,X) + X;
      T %= X;
    }
    ans = 1;
    while( T ){
      T %= popn(T);
      ans++;
    }
    printf("%d\n", ans);
  }
  
  return 0;

}


Measured memory_bytes: 3892
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace AtCoderBeginnerContest179
{
    class Program
    {
        static void Main(string[] args)
        {
            // 課題B - Go to Jail(2020/9/19)

            int item = int.Parse(Console.ReadLine());
            //string[] result;

            //List<string[]> iptList = new List<string[]>();
            int itemA = 0, itemB = 0, itemC = 1;
            long ptnCnt = 0;
            int tmpA, tmpB;

            for(int i=1; i<=item; i++)
            {
                for(int j=1; j<=item; j++)
                {
                    //tmpA = itemA + i;
                    //tmpB = itemB + j;

                    if (i * j < item) ptnCnt++;
                    else break;
                }
            }

            

            //var valueDict = new Dictionary<string, int>();

            //for (int i = 0; i < cnt; i++)
            //{
            //    //iptList.Add(Console.ReadLine().Split(' '));
            //    result = Console.ReadLine().Split(' ');

            //    result1 = int.Parse(result[0]);
            //    result2 = int.Parse(result[1]);

            //}

            Console.Write(ptnCnt);


            //if(getStr.Equals("s")) Console.Write(str + "es");
            //else Console.Write(str + "s");

        }
    }
}


Measured memory_bytes: 27448
{-# LANGUAGE Strict #-}

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  print $ solve n m

solve :: Int -> Int -> Int
solve n m = comb2 n + comb2 m

comb2 :: Int -> Int
comb2 n = n * (n - 1) `div` 2


Measured memory_bytes: 3844
#include<stdio.h>

int main() {
  int i;
  int s1, s2, sum;
  int max, p;
  while(1) {
    max = -1;
    for(i = 0; i < 5; i++) {
      scanf("%d %d", &s1, &s2);
      if(s1 == 0 && s2 == 0) return 0;
      sum = s1 + s2;
      if(sum > max) {
	max = sum;
	p = i;
      }
    }
    printf("%c %d\n", 'A'+p, max);
  }
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a,b,c,d,n=0;
    string s,s1,s2;
    cin >> a >> b >> c >>d;   
    if( a>=b ) n+=b;
    else n+=a;

    if (c >= d) n+=d;
    else n+=c;
    cout << n << endl;
    return 0;
} 

Measured memory_bytes: 256
/*
[abc139] E - League
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 1000;

int N;
int A[MAX_N][MAX_N - 1];
vector<int> g[MAX_N * (MAX_N - 1) / 2];
int color[MAX_N * (MAX_N - 1) / 2];
int dep[MAX_N * (MAX_N - 1) / 2];

int get_v(int x, int y) {
    if (x < y) {
        swap(x, y);
    }
    return x * (x - 1) / 2 + y;
}

bool dfs(int v) {
    color[v] = 1;
    for (int to : g[v]) {
        if (color[to] == 1) {
            return false;
        }
        if (!color[to] && !dfs(to)) {
            return false;
        }
        dep[v] = max(dep[v], dep[to] + 1);
    }
    color[v] = 2;
    return true;
}

ll solve() {
    for (int i = 0; i < N; i++) {
        for (int j = 1; j < N - 1; j++) {
            int v0 = get_v(i, A[i][j - 1]), v1 = get_v(i, A[i][j]);
            g[v0].push_back(v1);
        }
    }

    for (int v = 0; v < N * (N - 1) / 2; v++) {
        if (!color[v] && !dfs(v)) {
            return -1;
        }
    }

    int ans = *max_element(dep, dep + N * (N - 1) / 2) + 1;

    return ans;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N - 1; j++) {
            cin >> A[i][j];
            A[i][j]--;
        }
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 35456
#include <iostream>
#include <climits>
#include <cmath>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <utility>
#include <sstream>
#include <algorithm>
#include <stack>
#include <set>
#include <list>
#include <map>
#include <queue>
#include <vector>
#include <stdint.h> //uint32_t

typedef long long ll;
typedef double lf;

#define ull unsigned long long

#define FileIn(file) freopen("input.txt", "r", stdin)
#define FileOut(file) freopen("output.txt", "w", stdout)
#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0)

#define For(i, a, b) for (__typeof (a) i=a; i<=b; i++)
#define Rof(i, b, a) for (__typeof (a) i=b; i>=a; i--)
#define Rep(i, n) for (__typeof (n) i=0; i<n; i++)
#define Forit(i, s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define all(ar) ar.begin(), ar.end()
#define fill(ar, val) memset(ar, val, sizeof(ar))
#define clr(a) memset(a, 0, sizeof a)
#define sfll(a) scanf("%lld", &a)
#define pfll(a) printf("%lld", a)
#define sflf(a) scanf("%lf", &a)
#define pflf(a) printf("%lf", a)
#define sff(a) scanf("%f", &a)
#define pff(a) printf("%f", a)
#define sf(a) scanf("%d", &a)
#define pf(a) printf("%d", a)
#define nl cout << '\n';
#define SP cout << ' ';
#define gc getchar
#define chk cout << "##########\n"
#define debug1(x) cout << #x << ": " << x << endl
#define debug2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl
#define debug3(x, y, z) cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z << endl

#define PB push_back
#define max(a, b) (a < b ? b : a)
#define min(a, b) (a > b ? b : a)
#define sq(a) a * a
#define INF 0x7fffffff
#define MOD 1000000007
#define PI acos(-1.0)
#define MAX 100000000

using namespace std;

/********************* Code starts here ************************/

int main() {
    __FastIO;
    ll n{};
    cin >> n;
    ll ans{};
    for(int i = 1; i <= n; i++)
        if(i % 3 != 0 && i % 5 != 0) ans += i;
    cout << ans;
}


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

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    auto n = load<int>();
    auto height = loadMany<int>(n);
    auto dyn = vector<int>(n);
    dyn[0] = 0;
    for (auto i=1; i<n; ++i) {
        dyn[i] = dyn[i-1] + abs(height[i-1] - height[i]);
        if (i >= 2)
            dyn[i] = min(dyn[i], dyn[i-2] + abs(height[i] - height[i-2]));
    }

    cout << dyn[n-1] << '\n';
}


Measured memory_bytes: 1024