akhauriyash/Code-Regression huggingface dataset:
x, y, _, _, c = gets.chomp!.split(" ").map(&:to_i)

reds = gets.chomp!.split(" ").map(&:to_i).sort.reverse
greens = gets.chomp!.split(" ").map(&:to_i).sort.reverse
nons = gets.chomp!.split(" ").map(&:to_i).sort.reverse

red_target = reds[0..(x-1)].reverse
green_target = greens[0..(y-1)].reverse

minimum = (red_target + green_target).min
i = 0
ri = 0
gi = 0

loop do
  break if i >= c || nons[i] <= minimum

  if red_target[ri] < nons[i] && red_target[ri] < green_target[gi]
    red_target[ri] = nons[i]
    ri += 1 if ri < x - 1
  elsif green_target[gi] < nons[i]
    green_target[gi] = nons[i]
    gi += 1 if gi < y - 1
  end
  i += 1
end

puts (red_target + green_target).inject(:+)


Measured memory_bytes: 27872
#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e5 +1)
#define INFL LLONG_MAX
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

ll binpow(ll a, ll b) {
	ll x = 1;
	while (b) {
		if (b & 1) x = x * a;
		a = a * a;
		b >>= 1;
	}
	return x;
}

ll mult(ll a, ll b) {
	ll x = 0;
	while (b) {
		if (b & 1) x = (x + a);
		a = (a + a);
		b >>= 1;
	}
	return x;
}



int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;

	// Write your code here

	int t = 1;
	//cin >> t;
	while (t--) {
		ll n;
		cin >> n;
		vl v(n);
		ll S = 0;
		for (int i = 0; i < n; i++) {
			cin >> v[i];
			S = S ^ v[i];
		}

		for (int i = 0; i < n; i++) {
			cout << (S ^ v[i]) << " ";
		}
		cout << "\n";
	}


	return 0;
}

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

int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    vector<int> v;

    
    if(a + b < c * 2){
        v.push_back(a * x + b * y);
    }else{
        if(x > y){
            v.push_back(y * c * 2 + a * (x - y));
            v.push_back(c * 2 * x);
        }else if(x < y){
            v.push_back(x * c * 2 + b * (y - x));
            v.push_back(c * 2 * y);
        }else{
            v.push_back(x * c * 2);
        }
    }

    cout << *min_element(v.begin(),v.end()) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
int temp[maxn];
int main()
{
	int n, k = 0, l = 1;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		if(a[i] == i) temp[l++] = i;
	}
	for(int i = 2; i <= n; i++){
		if(temp[i] - temp[i-1] == 1){
			k++;
			i++;
		}
	}
    printf("%d\n",l-k-1);
}


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

int a[100005];
vector<int> b;
bool x[100005];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	memset(x,false,sizeof(x));
	b.push_back(a[1]);
	for(int i=2;i<=n;i++)
		if(a[i]!=a[i-1])
			b.push_back(a[i]);
	int ans=0;
	int len=b.size();
	int start=0;
	for(int i=1;i<len-1;i++)
	{
		if((b[i]>b[i-1]&&b[i]>b[i+1])||(b[i]<b[i-1]&&b[i]<b[i+1]))
		{
			if(i!=start)
			{
				ans++;
				start=i+1;
			}
		}
	}
	if(start!=n+1)
		ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1404
#include <stdio.h>

int main()
{
    int N,sum=0,i;
    scanf("%d",&N);
    i=N;
    
    while(i>0)
    {
        sum+=i%10;
        i=i/10;
    }
    if(N%sum==0)
    printf("Yes");
    else printf("No");

    return 0;
}


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

int main() {
  int a, b, c, smallest;

  cin >> a >> b >> c;
  smallest = a+b;
  if(smallest > a+c){
    smallest = a+c;
  }
  if(smallest > b+c){
    smallest = b+c;
  }
  cout << smallest;
  
}




Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<deque>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n;cin >> n;
	
	set<int> s;
	
	REP(i,n)
	{
		int tmp;cin >> tmp;s.insert(tmp);
	}
	
	cout << s.size() << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
  val (N, M) = readInts()
  val AB = (1..M).map { readInts().let { it[0] to it[1] } }.sortedBy { it.second }
  var cnt = 0
  var r = 0
  for (i in 0 until M) {
    val ab = AB[i]
    val a = ab.first
    val b = ab.second
    if (r in (a + 1)..b) continue
    cnt++
    r = b
  }
  println(cnt)
}

fun gcd(a: Int, b: Int): Int = if (a < b) gcd(b, a) else if (b == 0) a else gcd(b, a % b)
fun gcd(a: Long, b: Long): Long = if (a < b) gcd(b, a) else if (b == 0L) a else gcd(b, a % b)
fun lcm(a: Int, b: Int): Int = (a * b) / gcd(a, b)
fun lcm(a: Long, b: Long): Long = (a * b) / gcd(a, b)

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readInts() = readLine()!!.split(" ").map { it.toInt() }
fun readLongs() = readLine()!!.split(" ").map { it.toLong() }


Measured memory_bytes: 81008
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;

int main() {
	string w;
	cin >> w;
	vector<ll>a(26, 0);
	for (ll i = 0; i < w.size(); i++) {
		a[w[i]-'a']++;
	}
	for (ll i = 0; i < 26; i++) {
		if (a[i] !=0) {
			if (a[i] % 2 != 0) {
				cout << "No" << endl;
				exit(0);
			}
		}
	}
	cout << "Yes" << endl;
}





Measured memory_bytes: 256
import sys
import heapq as h

input=sys.stdin.readline

N,K=map(int,input().split())
sushi=[[0,0] for i in range(0,N)]
for i in range(0,N):
    t,k=map(int,input().split())
    sushi[i][1]=t
    sushi[i][0]=k

sushikind=[[] for i in range(0,N+1)]
for i in range(0,N):
    sushikind[sushi[i][1]].append(sushi[i][0])

kindmax=[0 for i in range(0,N+1)]

for i in range(0,N):
    if sushikind[i]:
        kindmax[i]=max(sushikind[i])

sushi.sort(reverse=True)
sum=0
kind=[]
kind=set(kind)
extra=[]
flag=[0 for i in range(0,N+1)]
for i in range(0,K):
    sum+=sushi[i][0]
    kind.add(sushi[i][1])
    if sushi[i][0]==kindmax[sushi[i][1]]:
        if flag[sushi[i][1]]==1:
            extra.append(sushi[i][0])
        else:
            flag[sushi[i][1]]=1
    else:
        extra.append(sushi[i][0])


set={i for i in range(1,N+1)}
set-=kind
appendix=[kindmax[i] for i in set if kindmax[i]!=0 ]
extra.sort()
appendix.sort(reverse=True)
k=len(kind)
first=k
ans=k**2+sum
for i in range(k,min(K,k+len(appendix))):
    k+=1
    sum+=appendix[k-first-1]-extra[k-first-1]
    test=k**2+sum
    if test>ans:
        ans=test

print(ans)

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

using namespace std;

#define frei(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define fred(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define fri(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define frd(i,n) for (int i = (n) - 1; i >= 0; i--)
#define foreach(it, ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )

#define uint64 unsigned long long
#define int64 long long
#define all(ar) ar.begin(), ar.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define ff first
#define ss second
#define pr pair

#define BIT(n) (1<<(n))
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a) | (b))
#define XOR(a,b) ((a) ^ (b))
#define sqr(x) ((x) * (x))

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define PI 3.1415926535897932385
#define INF 1000111222
#define eps 1e-7
#define maxN 5005



int main(int argc, char const *argv[])
{
    /* code */
    int n , k;
    cin >> n >> k;
    // if there is x stones and first player choose x - a1, x - a2, x-an then these positions are winning position of
    // player 2 then x is winning position of 1 otherwise x is winning positions of 2.
    // means lets assume at stone x if i chose a stones from x and  at position x - a is player 2 then 1st win.

    vector<int> moves(n + 1);
    for(int i = 1; i <= n; i++) cin >> moves[i];
    vector<int> dp(k+1, 2);
    for(int i = 1; i <= k; i++) {
        for(int m = 1; m <= n; m++) {
            if(moves[m] > i) continue;
            if(dp[i - moves[m]] == 2) {
                dp[i] = 1;
            }
        }
    }
    string ans = dp[k] == 1 ? "First" : "Second";
    cout << ans << endl; 
    return 0;
}


Measured memory_bytes: 640
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

sys.setrecursionlimit(10**9)
mod = 10**7+9
inf = 10**20


s = input()
if len(set(list(s)))==2:
    print("Yes")
else:
    print("No")
    

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

int main(){
	int n;
	cin >> n;
	vector<int> s;
	for ( int i = 0; i < n; i++ ) {
		s.push_back(i);
		cin >> s[i];
	}
	sort(s.begin(),s.end());
	int q;
	cin >> q;
	vector<int> t;
	for ( int i = 0; i < q; i++ ) {
		t.push_back(i);
		cin >> t[i];
	}
	sort(t.begin(),t.end());
	int c = 0;
	int i = 0;
	for ( int j = 0; j < q; j++ ) {
		while(true) {
			if ( s[i] == t[j] ) c++;
			if ( s[i] >= t[j] ) break;
			i++;
			if ( i == n ) break;
		}
		if ( i == n ) break;
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 1804
import numpy as np

n = int(input())
a = list(map(int, input().split()))

count  = 0
for i in a:
    if i < 0:
        count += 1
    elif i == 0:
        print(sum(np.abs(a)))
        exit()

if count % 2 == 0:
    print(sum(np.abs(a)))
else:
    a = np.abs(a)
    a.sort()
    b = a[0]
    a = np.delete(a, 0, 0)
    print(sum(a) - b)


Measured memory_bytes: 23304
#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 - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

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

  ll n;
  cin >> n;
  ll s[4500];
  ll mm;
  REP(i, 4500){
    s[i] = i * (i + 1) / 2;
    if(s[i] >= n){
      mm = i;
      break;
    }
  }

  ll rec = s[mm] - n;
  if(rec == 0){
    REP(i, mm) cout << i + 1 << endl;
  }
  else{
    REP(i, mm){
      if(i + 1 == rec) continue;
      else cout << i + 1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 2000005
#define VMAX 10005
int A[MAX],C[MAX],B[MAX];
int n;
void CountingSort(){
    for(int i=0;i<n;++i){
        C[A[i]]++;
    }
    for(int i=1;i<VMAX;++i){
        C[i] = C[i]+C[i-1];
    }
    for(int i=n-1;i>=0;i--){
        B[C[A[i]]] = A[i];
        C[A[i]]--;
    }
}

int main(){

    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%d",&A[i]);
    }
    for(int i=0;i<VMAX;++i){
        C[i] = 0;
    }
    CountingSort();
    for(int i=1;i<n;++i){
        printf("%d ",B[i]);
    }

    printf("%d\n",B[n]);

    return 0;
}




Measured memory_bytes: 18868
#include <cstdio>

#define iter(i, n) forw(i, 1, n)
#define iter0(i, n) for (int i = 0; i < n; ++i)
#define forw(i, a, b) for (int i = a; i <= b; ++i)

const int NR = 3010;
const int mod = 1e9 + 7;

int n, m;
int f[NR][NR][2];

inline void inc(int &x, int y) { x = (x + y) % mod; }

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

	//a[1] a[2] a[3]

	if (n == 1) {
		int ans = 2;
		iter(i, m) ans = ans * 2 % mod;
		printf("%d\n", ans);
		return 0;
	}

	forw(i, 0, n) f[0][i][i == 0] = 1;
	
	iter0(i, m) {
		forw(j, 0, n) iter0(k, 2) if (f[i][j][k]) {
			int w = f[i][j][k];
			if (j) {
				inc(f[i + 1][j][k | (j == 1)], w);
				inc(f[i + 1][j - 1][k | (j == 1)], w);
			}
			if (j < n) {
				inc(f[i + 1][j][k], w);
				inc(f[i + 1][j + 1][k], w);
			}
		}
	}
	int ans = 0;
	forw(j, 0, n) inc(ans, f[m][j][1]);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 70784
#include<iostream>
#include<iomanip>

using namespace std;

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

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  int n;
  string s;
  cin>>n;
  cin>>s;
  bool flag=true;
  rep(i,0,n/2){
    //cout<<n%2<<s[i]<<s[i+n/2]<<endl;
    if(!(n%2==0 && s[i]==s[i+n/2])){
        flag=false;
        break;
    }
  }
 !(n==1) && flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

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

int main(void) {
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e-a>k) {
        cout << ":(" << endl;
    }
    else {
        cout << "Yay!" << endl;
    }
}


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

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

const int mod = 1e9 + 7;

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    

    int n;
    cin >> n;

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

    int len = 1 << n;
    vi dp(len);
    dp[0] = 1;

    for (int i = 0; i < len - 1; ++i){
        int b = __builtin_popcount(i); //broj zauzetih zenki => sad mi je b sledeci muzjak kog treba uparim

        for (int j = 0; j < n; ++j){
            if (a[b][j] && !(i & (1 << j))){
                int m = i^(1 << j);

                dp[m] += dp[i];
                if (dp[m] >= mod) dp[m] %= mod;
            }
        }
    }

    cout << dp[len - 1] << '\n';
}

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

vector<long long> prime_enumeration(long long n){
    vector<bool> isPrime(n+1, true);
    for(long long i=2; i*i<=n; i++){
        if(isPrime[i]){
            for(long long j=2; j*i<=n; j++){
                isPrime[j*i] = false;
            }
        }
    }
    vector<long long> ret;
    for(long long i=2; i<=n; i++){
        if(isPrime[i]) ret.push_back(i);
    }
    return ret;
}

signed main(){
    auto v = prime_enumeration(100000);
    vector<int> ans;
    rep(i, v.size()){
        if((v[i]+1)%2 == 0 && *lower_bound(all(v), (v[i]+1)/2) == (v[i]+1)/2)
            ans.pb(v[i]);
    }

    int Q;
    cin >> Q;
    rep(i, Q){
        int l, r;
        cin >> l >> r;
        cout << upper_bound(all(ans), r) - lower_bound(all(ans), l) << endl;
    }
}

Measured memory_bytes: 896
public class Main {
	public static void main(String args[]) {

		java.util.Scanner sc = new java.util.Scanner(System.in);
		int N = sc.nextInt();
		int[] x = new int[N];
		int[] y = new int[N];

		for (int i = 0; i < N ;i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}

		double result = 0;
		for (int i = 0; i< N; i++) {
			for (int j = 0; j< N; j++) {
				result += Math.sqrt(Math.pow((x[i] - x[j]), 2)  + Math.pow((y[i] - y[j]), 2));
			}
		}

		int tmp = 1;
		for (int i = 0; i < N ;i++) {
			tmp = tmp*N;
		}

		System.out.println(result/N);
	}

}

Measured memory_bytes: 23636
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int a, b; cin >> a >> b;
  cout << max({a+b, a-b, a*b}) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,a,b,c,d;
    in>>n;
    vector<vector<pair<int,int>>> v(n);
    fr(i,n-1){
        in>>a>>b;
        --a,--b;
        v[a].emplace_back(b,i+1);
        v[b].emplace_back(a,i+1);
    }
    int an=0;
    fr(i,n) if(an<v[i].size()) an=v[i].size();
    cout<<an<<endl;
    queue<tuple<int,int,int>> q;
    vector<int> ans(n);
    q.emplace();
    while(!q.empty()){
        tie(a,b,c)=q.front();q.pop();
        d=1;
        for(auto i:v[a]){
            if(i.first==b) continue;
            if(d==c) ++d;
            q.emplace(i.first,a,d);
            ans[i.second]=d++;
        }
    }
    Fr(i,n-1) cout<<ans[i]<<endl;
}

Measured memory_bytes: 7040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int num = 0;
		for(int i = 2; i < n; i++) {
			int k = i;
			int j = 1;
			while(k * i <= n) {
				k *= i;
				j++;
			}
			if(j > 1) {
				num = Math.max(num, k);
			}
		}
		if(n == 1) {
			System.out.println(1);
		}else {
			System.out.println(num);
		}
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define vi vector<int>
#define pb(a) push_back(a)
using namespace std;

typedef long long ll;

typedef pair<ll,ll> P1;
typedef pair<int,P1> P2;
typedef pair<P1,int> Pli;
const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

#define MAX_N 100002

int dp[MAX_N];
vector<int> G[MAX_N];
vector<int> v;
bool d[MAX_N]={};
queue<int> que;
ll x[MAX_N]={};
ll y[MAX_N]={};

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	bool flg=true;
	if(a==b&&b==c){
		if(a%2==1)flg=false;
		if(b%2==1)flg=false;
		if(c%2==1)flg=false;
		if(flg){
			cout<<"-1"<<endl;
		}else{
			cout<<"0"<<endl;
		}
		return 0;
	}
	int t=0;
	while(flg){
		if(a%2==1)flg=false;
		if(b%2==1)flg=false;
		if(c%2==1)flg=false;
		if(!flg)break;
		t++;
		int a1=(b+c)/2;
		int b1=(a+c)/2;
		int c1=(a+b)/2;
		a=a1;
		b=b1;
		c=c1;
	}
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 2688
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
// ll gcd(ll a, ll b) {
// 	if(b == 0) return a;
// 	return gcd(b, a % b);
// }

const ll MAX_N = 1e5;
 
ll N;
ll color[MAX_N]; // 各頂点が通過済みか
vector<P> uvw[MAX_N];
 
// 現在位置(x)
void dfs(ll i){
	// printf("dfs(%lld)\n", i);
	// printf("uvw[i].size()=%lld\n", uvw[i].size());
	REP(j,uvw[i].size()){
		// printf("uvw[i][j].first=%lld\n", uvw[i][j].first);
		// printf("color[uvw[i][j].first]=%lld\n", color[uvw[i][j].first]);
		if (color[uvw[i][j].first]==ll(-1)){
			// printf("?\n");
			if (uvw[i][j].second==0){
				color[uvw[i][j].first] = color[i];
			}
			else{
				color[uvw[i][j].first] = 1 - color[i];
			}
			dfs(uvw[i][j].first);
		}
	}
}
 
int main() {
	// 入力
	cin >> N;
	REP(i,N-1){
		ll u,v,w;cin>>u>>v>>w;u--;v--;
		w = w%2;
		uvw[u].pb(make_pair(v,w));
		uvw[v].pb(make_pair(u,w));
	} 
	// REP(i,N){
	// 	printf("%lld ", i);
	// 	REP(j,uvw[i].size()){
	// 		printf("(%lld, %lld), ", uvw[i][j].first, uvw[i][j].second);
	// 	}
	// 	printf("\n");
	// }
	REP(i,N) color[i] = ll(-1);
	color[0] = 0;
	dfs(0);
	
	REP(i,N){
		printf("%lld\n", color[i]);
	}
	
}


Measured memory_bytes: 10240
//AtCoder AGC 008-A
#define _USE_MATH_DEFINES

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <numeric>
#include <string>
#include <map>
#include <sstream>
using namespace std;

int main() {
	long long x, y, ans = 0;

	cin >> x >> y;

	if (abs(x) < abs(y)) {
		if (x < 0) {
			x = -x;
			ans += 1;
		}
		ans += abs(y) - abs(x);
		x = abs(y) - abs(x);
	}

	if (abs(x) > abs(y)) {
		if (x > 0) {
			x = -x;
			ans += 1;
		}
		ans += abs(x) - abs(y);
		x = abs(y) - abs(x);
	}

	if (x*y < 0) {
		x = -x;
		ans += 1;
	}

	cout << ans << endl;
}



Measured memory_bytes: 256
def check(k,p,n,weights):
    i = 0
    for j in range(k):
        s = 0 
        while (s + weights[i]) <= p:
            s += weights[i]
            i += 1
            if i == n:
                return n 
    return i 


   
n,k = list(map(int, input().split(' ')))
weights = [None for _ in range(n)]
for i in range(n):
    weights[i] = int(input())
left = 0 
right = 100000 * 10000
while left + 1 < right:
    mid = left + (right-left)//2
    result = check(k,mid,n,weights)
    if result < n:
        left = mid
    else:
        right = mid
print(left + 1)


Measured memory_bytes: 9436
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, a[112345], b[112345], c[112345];
    V g[112345];

    cin >> n;
    REP(i, n - 1)
    {
        cin >> a[i] >> b[i];
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }

    REP(i, n)
    cin >> c[i];

    sort(c, c + n);

    int cn = 0;

    priority_queue<P, vector<P>, greater<P>> q;

    int e[112345];
    memset(e, 0, sizeof(e));

    REP(i, n)
    {
        q.push({g[i + 1].size(), i + 1});
        e[i + 1] = g[i + 1].size();
    }

    bool used[112345];
    fill(used, used + n + 1, false);

    int res[112345];

    ll sum = 0;

    while (q.size())
    {
        while (q.size() && used[q.top().second])
            q.pop();

        if (!q.size())
            break;

        P p = q.top();
        used[p.second] = true;
        res[p.second] = c[cn];
        cn++;

        //cout << "#" << e[p.second] << " " << p.second << endl;

        for (int i : g[p.second])
        {
            if (!used[i] || (used[i] && res[i] > res[p.second]))
                sum += c[cn - 1];

            e[i]--;
            q.push({e[i], i});
        }
    }

    cout << sum << endl;

    for (int i = 1; i <= n; i++)
        cout << res[i] << (i < n ? " " : "\n");

    return 0;
}

Measured memory_bytes: 5632
h, w = map(int, input().split())
s = ['0'*(w+2)]

for i in range(1,h+1) :
    tmp = input().replace('.', '0')
    tmp = tmp.replace('#', '1')
    s.append('0' + tmp + '0')
s.append('0'*(w+2))

ans = [''*w for _ in range(h)]
for i in range(h) :
    for j in range(w) :
        if s[i+1][j+1] == '1' :
            ans[i] += '#'
        else :
            ans[i] += str(int(s[i][j])  +int(s[i+1][j])  +int(s[i+2][j])+
                          int(s[i][j+1])+                 int(s[i+2][j+1])+
                          int(s[i][j+2])+int(s[i+1][j+2])+int(s[i+2][j+2]))

for ss in ans :
    print(ss)

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

const long long MOD = 1000000007;
const long long inverse2 = 500000004;
int main(){
    int n, m; cin >> n >> m;
    vector<int> graph[n+1]; set<pair<int, int> > edges;
    for (int i = 0; i < m; i++){
        int u, v; cin >> u >> v;
        if (edges.find({min(u, v), max(u, v)}) != edges.end()){
            continue;
        }
        graph[u].push_back(v);
        graph[v].push_back(u);
        edges.insert({min(u, v), max(u, v)});
    }
    int maxi = 0;
    list<int> queue;
    vector<int> used(n+1);
    for (int i = 1; i <= n; i++){
        if (used[i] == 1) continue;
        queue.push_back(i); used[i] = 1;
        int num = 0;
        while (!queue.empty()){
            int u = queue.front(); queue.pop_front();
            num++;
            for (int v : graph[u]){
                if (used[v] == 1) continue;
                queue.push_back(v);
                used[v] = 1;
            }
        }
        maxi = max(maxi, num);
    }
    cout << maxi << '\n';
    return 0;
}

Measured memory_bytes: 25724
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000000000000001;
const long double E = 0.00000001;

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    cout << n+n*n+n*n*n << endl;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,m;
  cin>>n>>m;
  int k,sum=0;
  for(int i=0;i<m;i++)
  {
    cin>>k;
    sum=sum+k;
    
  }
  if(sum>=n)
  {
    cout<<"Yes";
  }
  else
  {
    cout<<"No";
  }

}


Measured memory_bytes: 384
class Process:
    def __init__(self, data):
        self.name = data[0]
        self.time = int(data[1])

    def process(self, quantum):
        if self.time <= quantum:
            time, self.time = self.time, 0
            return time

        self.time -= quantum
        return quantum

    def isProcessed(self):
        return self.time == 0

    def getName(self):
        return self.name

def main():
    n, q = map(int, input().split())

    queue = []
    for _ in range(n):
        queue.append(Process(input().split()))

    elapsed = 0
    while len(queue) > 0:
        p = queue.pop(0)
        elapsed += p.process(q)

        if p.isProcessed():
            print('{} {}'.format(p.getName(), elapsed))
        else:
            queue.append(p)

if __name__ == '__main__':
    main()



Measured memory_bytes: 17244
n, m = map(int, input().split())
h = list(map(int, input().split()))
good = [1 for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    if h[a-1] == h[b-1]:
        good[a-1] = 0
        good[b-1] = 0
    elif h[a-1] > h[b-1]:
        good[b-1] = 0
    elif h[a-1] < h[b-1]:
        good[a-1] = 0
print(sum(good))

Measured memory_bytes: 20148
#include"bits/stdc++.h"
using namespace std;
int dp[3001][3001];
int solve(int i,int j,string &s1,string &s2){

    if(i<0 || j<0)
        return 0;
  	if(dp[i][j]!=-1)
        return dp[i][j];
    if(s1[i]==s2[j])
        return dp[i][j] = 1+solve(i-1,j-1,s1,s2);
    return dp[i][j] = max(solve(i-1,j,s1,s2),solve(i,j-1,s1,s2));
}
int main(){

    //freopen("input.txt","r",stdin);
    string s1,s2;
    cin>>s1;
    cin>>s2;
    memset(dp,-1,sizeof(dp));
    solve(s1.length()-1,s2.length()-1,s1,s2);
    int start = s1.length()-1,end=s2.length()-1;
    string answer="";
    while(start>=0 && end>=0){
        if(s1[start]==s2[end]){
            answer = s1[start]+answer;
            start--;
            end--;
        }else if(start>=1 && dp[start][end]==dp[start-1][end]){
            start--;
        }else{
            end--;
        }
    }
    cout<<answer<<endl;
    return 0;
}

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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)
#define SORT(a) sort(ALL(a))
#define VSORT(a, type) sort(ALL(a),greater<type>())
#define MAPIN(a,i,j) (a).insert(make_pair(i,j))

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef unsigned long long lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > Matrix;

int main() {
    ll n,i,j,k,a,b,c;
    vi l,m;

    cin>>n;
    SIZE(l,n);
    rep(i,n){
        cin>>l[i];
    }
    SORT(l);
    k=0;
    rep(a,n-2){
        repj(b,a+1,n-1){
            repj(c,b+1,n){
                if(l[c]<l[a]+l[b])k++;
                else break;
            }
        }
    }
    cout<<k;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<ll,int>;

struct edge{int to,cost;};

const int N = 2002;
const ll INF = LLONG_MAX/3;
vector<edge> G[N];

ll dp[N];
int pw[N];
void dfs(int v, int p, int pe){
    dp[v] = pe;
    pw[v] = pe;
    for(const auto &e:G[v])if(e.to != p){
        dfs(e.to, v, e.cost);
        dp[v] = max(dp[v], dp[e.to]+pe);
    }
    if(p==-1) dp[v] = -INF;
}

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

    rep(i,n-1){
        int a,b,c;
        cin >>a >>b >>c;
        --a;
        --b;
        G[a].pb({b,c});
        G[b].pb({a,c});
    }

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

    vector<ll> cand;
    rep(i,n){
        dfs(i,-1,0);
        // rep(j,n) printf(" %d: dp[%d] = %d\n",i,j,dp[j]);

        vector<ll> add;
        vector<bool> used(n);
        // (value,id)
        priority_queue<pi> pq;
        rep(j,n) pq.push({dp[j],j});

        while(!pq.empty()){
            pi p = pq.top();
            pq.pop();

            ll val = p.fi;
            int id = p.se;
            if(used[id] || id==i) continue;

            // printf(" %d : %d\n", i,id);

            add.pb(s[i]*val);
            int now = id;
            while(now != -1){
                int nx = -1;
                for(const auto &e:G[now]){
                    if(!used[e.to] && dp[now] - pw[now] == dp[e.to]) nx = e.to;
                }

                used[now] = true;
                now = nx;
            }
        }

        for(ll j:add) cand.pb(j);
    }

    sort(all(cand), greater<ll>());
    int sz = cand.size();
    // dbg(sz);dbg(cand);
    ll ans = 0;
    rep(i,min(sz,m)) ans += cand[i];
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 36020
// I can't tell you what it really is,
// I can only tell you what it feels like.
#include "bits/stdc++.h"
using namespace std;
 
// #define int long long
#define F first
#define S second
#define sz(x) ((int)x.size())
#define rep(i,a,n) for (int i = a; i <= n; ++i)
#define all(v)  v.begin(), v.end()
#define pb push_back
#define P pair < int, int >
#define E cout << '\n'

const int mod = 1e9 + 7;
const int N = 4e5 + 5;

int dp[N];
bool vis[N];
vector < int > v[N];

void dfs(int x) {
  vis[x] = 1;
  // cout << x << ' ';
  for (int i : v[x]) {
    if (!vis[i]) {
      dfs(i);     
    }
     dp[x] = max(dp[x], 1 + dp[i]);
  }
}
 
inline void solve() {
   int n, m, l, r;
   cin >> n >> m;
   rep(i,1,m) {
    cin >> l >> r;
    v[l].pb(r);
   }
   rep(i,1,n)
    if (!vis[i]) {
      dfs(i);//E;
    }
  cout << *max_element(dp+1,dp+1+n);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  //cin >> t; while(t--)
  solve();
  return 0;
}

Measured memory_bytes: 15616
/*	[]__________[][][][]____[][][][][]__{}__[][][][]____[][][][][]__[][][][]
    []__________[]______________[]__________[]__________[]__________[]____[]
    []__________[][][][]________[]__________[][][][]____[]__________[]____[]
    []__________[]______________[]________________[]____[]__[][][]__[]____[]
    []__________[]______________[]________________[]____[]______[]__[]____[]
    [][][][]____[][][][]________[]__________[][][][]____[][][][][]__[][][][]
*/
#include <bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define endl '\n'
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define decimal(x) cout<<fixed<<setprecision(x);
bool prime[100005]; 
void Sieve(int n) {
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
} 
vector<int>grapj[100005];
bool vis[100005];
void solve()
{
    int n;
cin>>n;
int c=0;
int ans=0;
for(int i=0;i<n;i++)
{
    int a,b;
    cin>>a>>b;
    if(a==b)
    c++;
    else
    {
        ans=max(ans,c);
        c=0;
    }
}
ans=max(c,ans);
if(ans>=3)
cout<<"Yes";
else
{
    cout<<"No";
}

}	
signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 5956
#include <stdio.h>
#include <iostream>
#include <math.h>

using namespace std;
int N = 999999;
int prime[999999];
int status[999999/32];

bool Check(int N, int pos)
{
	return (bool)(N&(1<<pos));
}
int Set(int N, int pos)
{
	return N = N | (1<<pos);
}
void sieve()
{
	int i, j, sqrtN;
	sqrtN = sqrt(N);

	for(i=3; i<=sqrtN; i+=2)
	{
		if(Check(status[i/32], i%32) == 0)
		{
			for(j=i*i; j<=N; j+=(2*i))
				status[j/32] = Set(status[j/32], j%32);
		}
	}
	int k = 1;
	prime[0] = 2;
	for(int i=3; i<=N; i+=2)
	{
		if(Check(status[i/32], i%32) == 0)
			prime[k++] = i;
	}
}
int main()
{
	sieve();
	int k, num, count = 0;
	k=0;
    while(scanf("%d", &num)!=EOF)
    {
        k=0;
    	count = 0;

        for(int i=1; i<=num; i++)
        {
            if(i == prime[k])
                {
                    count++;
                    k++;
                }
        }
        printf("%d\n", count);
    }
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N) cin >> A[i];
  sort(A.rbegin(),A.rend());
  ll ans = 0;
  int t = N-1;
  rep(i,N){
    int lim=2;
    if(i==0) lim=1;
    rep(j,lim){
      if(t>0){
        ans += A[i];
        t--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4020
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        x: isize
    };

    let res = if x >= 30 { "Yes" } else { "No" };
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2244
N,M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N)]
#print(N,M)
AB.sort()
#print(AB)

cnt=0
amnt=0
for i in AB:
  if cnt>=M:
    break
  elif cnt + i[1]>M:
    for j in range(1,i[1]):
      if cnt>=M:
        break
      else:
        cnt += 1
        amnt += i[0]
  else:
    cnt += i[1]
    amnt += i[0]*i[1]
print(amnt)

Measured memory_bytes: 27884
#include <iostream>
#include <string>
#include <bitset>
#include <map>
using namespace std;

std::map<int, long long> mp1;
std::map<int, long long> mp2;
unsigned long ans1 = 0;
unsigned long ans2 = 0;
 
long long pow(long long n, long long p, long long m)
{
    if(m == 0) return 0;
    if(p == 0) return (1 % m);
    long long ret = 1;
    for (; p > 0; p >>= 1, n = n * n % m){
		if (p%2 == 1){
			ret = ret * n % m;
		}
	}
	return ret;
}

std::map<int, long long> results;

unsigned long f(std::bitset<200000>& bs, int hibit, long long index)
{
    long long n = -1;
    long long count = 0;
    
    // 初回だけmpを使って計算
    //int hibit = bs.count();
    if(bs[index] == 0){
        hibit++;
        n = ans1 + mp1[index];
    }else{
        hibit--;
        if(hibit <= 0) return count;
        n = ans2 - mp2[index];
        if(n < 0) n += hibit;
    }
    if(n >= hibit){
        n = n % hibit;
    }
    count++;
 
    // 計算量削減のため初回計算後のnとそれに対する計算回数を記憶しておく
    std::map<int, long long>::iterator itr = results.find(n);
    if(itr != results.end()){
        return itr->second;
    }
    int tmp = n;
    while(n != 0){
        std::bitset<200000> tmpbs(n);
        n = n % tmpbs.count();
        count++;
    }
    results.emplace(tmp, count);
 
    // nが0になるまでの操作回数を返す
    return count;
}
 
int main()
{
    long long N;
    std::cin >> N;
    std::string X;
    std::cin >> X;
 
    // 前準備
    std::bitset<200000> bs(X);
    const int count = bs.count();
 
    // 制約から1<=Nなので、count=0のケースは考慮不要
    for(long long i=N-1; i>=0; i--){
        mp1[i] = pow(2, i, count+1);
        mp2[i] = pow(2, i, count-1);
        if(bs[i] == 1){
            ans1 += mp1[i];
            ans2 += mp2[i];
        }
    }

    // ここから本処理
    for(long long i=N-1; i>=0; i--){
        unsigned long result = f(bs, count, i);
        std::cout << result << std::endl;
    }
}

Measured memory_bytes: 29268
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
ll mod = 1e9 + 7;
ll fact[500002];
ll D[500002];
ll power(ll x, ll y) {
	ll ans = 1;
	while(y) {
		if(y & 1) {
			ans = (ans * x) % mod;
		}
		x = (x * x) % mod;
		y /= 2;
	}
	return ans;
}
ll modinverse(ll x) {
	return power(x, mod - 2);
}
ll combi(ll n, ll r) {
	return (fact[n]*modinverse((fact[r] * fact[n-r])%mod))%mod;
}
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m, i;
    cin >> n >> m;
    fact[0] = 1;
    for(i = 1; i <= 500001; i++) {
    	fact[i] = (fact[i-1] * i) % mod;
    }
    ll sub = 0, cur = 1;
    for(i = 1; i <= n; i++) {
    	ll add = (combi(n, i) * ((combi(m - i, n - i) * fact[n - i])%mod))%mod;
    	add = (cur * add)%mod;
    	if(add < 0) {
    		add = add + mod;
    	}
    	sub = (sub + add)%mod;
    	if(sub < 0) {
    		sub = sub + mod;
    	}
    	cur = -cur;
    }
    ll ans = ((((combi(m, n) * fact[n])%mod) - sub)%mod + mod)%mod;
    ans = (ans * ((combi(m, n) * fact[n])%mod))%mod;
    cout << ans << "\n";
}

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

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

int main() {

    int n, k;
    cin >> n >> k;

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

    sort(p.begin(), p.end());

    int ans = 0;
    rep(i, k) ans += p[i];

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3632
#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 pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int n;
    cin>>n;
    int cnt=0,ans=0,ai,pre=-1;
    rep(i,n){
        cin>>ai;
        if(pre!=ai){
            ans+=cnt/2;
            cnt=1;
            pre=ai;
        }
        else ++cnt;
    }
    cout<<ans+cnt/2<<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++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007;

vector<vector<int>> to;

int main() {
    int N,M;
    cin>>N>>M;
    to.resize(3*N,vector<int>(0));
    
    rep(i,M){
        int a,b;
        cin>>a>>b;
        --a;--b;
        to[3*a].pb(3*b+1);
        to[3*a+1].pb(3*b+2);
        to[3*a+2].pb(3*b);
    }
    int S,T;
    cin>>S>>T;
    --S;--T;
    S*=3;T*=3;
    
    vector<int> minlen(3*N,-3);
    queue<P> visited;
    visited.push({S,0});
    while(!visited.empty()){
        P v=visited.front();visited.pop();
        if(minlen.at(v.first) == -3){
            minlen.at(v.first)=v.second;
            P nex;
            nex.second=v.second+1;
            for(int u:to[v.first]){
                nex.first=u;
                visited.push(nex);
            }
        }
    }
    cout<<minlen.at(T)/3<<endl;
/*rep(i,N){
    rep(j,to2.at(i).size()){
        cout<<to2.at(i).at(j)<<" ";
    }
    cout<<endl;
}*/
}

Measured memory_bytes: 17792
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int prime[1000010];
bool is_prime[1000010];
bool hit[1000010];
bool is_prime2(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}
vector<long long> calc_divisor(long long n) {//約数列挙
    vector<long long> res;
    for (long long i = 1LL; i*i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            long long j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.begin(), res.end());
    return res;
}
void sieve(int n){
    // n以下の素数を求める
    int p = 0;
    for(int i=0;i<=n;i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <=n ; i++){
        if(is_prime[i]){
            prime[p++]=i;
            for(int j=2*i;j <=n;j+=i) is_prime[j] = false;
            int j = i;
            hit[j] = true;
            while(j<=1000004/i){
                j *= i;
                hit[j] = true;
            }
        }
    }
}
int main(){
    cout << fixed << setprecision(10);
    rep(i,1000010) hit[i] = false;
    sieve(1000005);
    ll n;
    cin >> n;
    vector<ll> search = calc_divisor(n);
    search.push_back(n);
    ll cnt = 0;
    set<ll> sll;
    for(auto u : search){
        if(u<100010){
            if(hit[u] && n%u==0){
                if(sll.find(u)==sll.end()){
                    //cout << u << endl;
                    cnt++;
                    sll.insert(u);
                    n /= u;
                }
            }
        }else{
            if(is_prime2(u) && n%u==0){
                if(sll.find(u)==sll.end()){
                    cnt++;
                    sll.insert(u);
                    n /= u;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 5932
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n,x;
    while( scanf("%d%d", &n, &x ) && (n!=0 || x!=0)) {
        int cnt=0;
        int i,j,k;
        for(i=1; i<=n; i++) {
            for(j=i+1; j<=n; j++) {
                int y = x-i-j;
                if(y>j && y<=n) {
                    cnt++;
                }
            }
        }
        printf("%d\n", cnt);
    }

    return 0;
}



Measured memory_bytes: 2752
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define gc getchar
#define ll long long
#define db double
#define pii pair<int,int>
#define fi first
#define se second
#define Vi vector<int>
#define Vp vector<pii>

using namespace std;

inline void cmax(int &x,int y){y>x?x=y:0;}
inline void cmin(int &x,int y){y<x?x=y:0;}

int read(){
	char ch=gc(); int x=0,op=1;
	for (;!isdigit(ch);ch=gc()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=gc()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}

const int N=1e5+100;
int n,cnt,a[N],b[N];

int main(){
	scanf("%d",&n);
	rep (i,1,n) scanf("%d",&a[i]),b[i]=a[i];
	sort(b+1,b+1+n);
	rep (i,1,n){
		a[i]=lower_bound(b+1,b+1+n,a[i])-b;
		if (i&1) cnt+=!(a[i]&1);
		if (!(i&1)) cnt+=a[i]&1;
	}
	printf("%d\n",cnt>>1);
	return 0;
}

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

struct node {
	int id, score;
};
bool operator<(node a, node b) {
	if (a.score == b.score)return a.id < b.id;
	return a.score > b.score;
}
int s[100000], cnt[100000];
int d[1000000], t[1000000], x[1000000];
int main() {
	int n, r, l; scanf("%d%d%d", &n, &r, &l);
	set<node>que;
	rep(i, r)scanf("%d%d%d", &d[i], &t[i], &x[i]);
	rep(i, r) {
		d[i]--;
		s[d[i]] += x[i];
		que.insert({ d[i],s[d[i]] });
		while (!que.empty() && (*que.begin()).score != s[(*que.begin()).id])que.erase(que.begin());
		if (i == r - 1)cnt[(*que.begin()).id] += l - t[i];
		else cnt[(*que.begin()).id] += t[i + 1] - t[i];
	}
	printf("%d\n", max_element(cnt, cnt + n) - cnt + 1);
}

Measured memory_bytes: 41196