akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		doIt();

	}
	public static void doIt(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while(n != 0){
			
			int count = 0;
			for(int i = 1; i < n/2 + 1; i++){
				if(checkFromN(i, n)){
					count++;
				}
			}
			System.out.println(count);
			n =sc.nextInt();
		}

	}
	
	//ansと一致したらtrue
	public static boolean checkFromN(int n, int ans){
		int sum = n;
		for(int j = n+1; j < ans/2 + 2; j++){
			sum += j;
			if(sum == ans){
				return true;
			}
			else if(sum > ans){
				break;
			}
		}
		return false;
	}

}

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

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}


int main(){
	int h,w,d; cin >> h >> w >> d;
	vector<pair<int,int>> a(h*w+1);
	a[0] = make_pair(0,0);
	rep(i,h){
		rep(j,w){
			int k; cin >> k;
			a[k] = make_pair(i,j);
		}
	}
	vector<vector<int>> start(d);
	for(int i=0; i<d; i++){
		int s = 0;
		start[i].push_back(s);
		for(int j=i; j<=h*w-d; j+=d){
			auto [x1,y1] = a[j];
			auto [x2,y2] = a[j+d];
			s += abs(x1-x2) + abs(y1-y2);
			start[i].push_back(s);
		}
	}
	//print(start[0]);
	int q; cin >> q;
	Rep(q){
		int l,r;
		cin >> l >> r;
		int mod = l % d;
		cout << start[mod][r/d] - start[mod][l/d] << endl;
	}
}

Measured memory_bytes: 8628
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


void Main()
{
    int n;cin>>n;

    vector<LL> a(n);
    REP(i,n){
        cin>>a[i];
    }
    SORT_ASC(a);

    int result = 1;
    FOR(i,1,n){
        if(a[i]<=a[i-1]*2){
            result++;
        }
        else{
            result=1;
        }
        a[i] += a[i-1];
    }
    cout<<result<<endl;




	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 1024
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    vector<int> A(N), pos(N);
    rep(i,0,N) {
        cin >> A[i];
        pos[ A[i] - 1 ] = i;
    }

    int ans = 0, tmp = 0, prev = -1;
    rep(i,0,N) {
        if(prev < pos[i]) tmp++;
        else {
            chmax(ans, tmp);
            tmp = 1;
        }
        prev = pos[i];
    }
    chmax(ans, tmp);

    tmp = 0, prev = INF;
    for(int i=N-1; i>=0; i--) {
        if(prev > pos[i]) tmp++;
        else {
            chmax(ans, tmp);
            tmp = 1;
        }
        prev = pos[i];
    }
    chmax(ans, tmp);

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

Measured memory_bytes: 3456
#include<stdio.h>

#define N 100000
#define Q 50000

int main(){
  int i,n,q,count=0;
  int left,right,mid;
  int S[N],T[Q];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  for(i=0;i<q;i++){
    left=0;
    right=n;
    while(left<right){
      mid=(left+right)/2;
      if(T[i]==S[mid]){
	  count++;
	  break;
	}
	if(T[i]>S[mid]){
	  left=mid+1;
	}else if(T[i]<S[mid]){
	  right=mid;
	}
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1188
import sys
input = sys.stdin.readline

def main(): 
    N,M = map(int,input().split())
    ks=[list(map(int, input().split())) for _ in range(M)]
    p = list(map(int, input().split()))
    ans = 0
    for bit in range(2**N):
        Flag = True
        for i in range(M):
            count = 0
            for j in range(1,ks[i][0]+1):
                if bit & (1<<ks[i][j]-1):
                    count += 1
            if count%2!=p[i]:
                Flag = False
                break
        if Flag:
            ans+=1
    print(ans)


if __name__ == "__main__":
    main()
    

Measured memory_bytes: 40816
#include<stdio.h>
main(){
  int i,x,y;
  for(i=1;;i++){
    scanf("%d %d",&x,&y);
    if(x==0 && y==0)break;
    if(x>y)printf("%d %d\n",y,x);
    else printf("%d %d\n",x,y);
  }
  return 0;
}




Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;

const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}



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


  double ans = 0;
  ll cost[n];
  ll num[n];

  for (int i = 0; i < n; i++) {
    cost[i] = i + 1;
    num[i] = 0;
  }

  for (int j = 0; j < n; j++) {
    for (int i = 0; i < 30; i++) {
      if (cost[j] >= k)break;
      cost[j] *= 2;
      num[j]++;
      
    }
  }


  ans = 0;
  for (int j = 0; j < n; j++) {
    double f = 1;
    for (int i = 0; i < num[j]; i++) {
        f/=2.0;
    }
    ans+=f/(double)n;
    cerr << f <<endl;
    cerr << num[j] <<endl;
  }






  cout << fixed << setprecision(15);
  cout << ans << endl;

}







Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int parent[200005], siz[200005];

int root(int x) {
  while(parent[x]!=x) x = parent[x];
  return x;
}

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

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if(siz[x]<siz[y]) swap(x, y);
  siz[x] += siz[y];
  parent[y] = x;
  return;
}

int main() {
  int N, Q;
  cin>>N>>Q;
  for(int i=0;i<N;++i) {
    parent[i] = i;
    siz[i] = 1;
  }
  int t, u, v;
  vector<bool> arr;
  for(int i=0;i<Q;++i) {
    cin>>t>>u>>v;
    if(t==0) {
      unite(u, v);
    }
    else {
      arr.push_back(same(u, v));
    }
  }
  for(int i=0;i<arr.size();++i) cout<<arr[i]<<endl;
}



Measured memory_bytes: 5116
XKD=list(input().split(' '))
X=int(XKD[0])
K=int(XKD[1])
D=int(XKD[2])
AX=abs(X)

if AX>K*D:
    print(AX-K*D)
else:
    K2=AX//D
    if (K-K2)%2==0:
        P=AX-K2*D
        print(P)
    else:
        P=abs(AX-(K2+1)*D)
        print(P)

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

int main(){
    int m1, d1, m2, d2;
    cin >> m1 >> d1;
    cin >> m2 >> d2;
    
    if(d2-d1==1) cout << "0" << endl;
    else cout << "1" << endl;
    
    
    return 0;
} 


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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> l(n);
  for (int i = 0; i < n; i++) cin >> l[i];

  int m = 0;
  int ans = 1;
  for (int j = 0; j < n; j++) {
    m += l[j];
    if (m <= x) ans++;
    else break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <set>
#include <map>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INF64 = 3e18;
const unsigned long long HASHBASE=1222827239ull;
/////////////////////////

/////////////////////////
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int n,d;
    int x[100][100];
    int ans=0;
    cin>>n>>d;
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<d;++j)
        {
            cin>>x[i][j];
        }
    }
    for(int i=0;i<n;++i)
    {
        for(int j=i+1;j<n;++j)
        {
            int sum=0;
            for(int k=0;k<d;++k)
            {
                sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            int sqrtsum=sqrt(sum);
            if(sqrtsum*sqrtsum==sum)
                ++ans;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stack>
#include<string.h>
#include<iostream>
#define maxn 1001
using namespace std;
struct node {
    int p,l,r;
}T[maxn];
void preorder(int t){
    if(t==-1)return ;
    cout<<" "<<t;
    preorder(T[t].l);
    preorder(T[t].r);
}
void inorder(int t){
    if(t==-1)return ;
    inorder(T[t].l);
    cout<<" "<<t;
    inorder(T[t].r);
}
void order(int t)
{
    if(t==-1)return ;
    order(T[t].l);
    order(T[t].r);
    cout<<" "<<t;
}
int main()
{
    int n,root,i;
    while(~scanf("%d",&n)){
    for(i=0;i<n;i++){
        T[i].p=-1;
    }
    for(i=0;i<n;i++){
        int v,l,r;
        scanf("%d%d%d",&v,&l,&r);
        T[v].l=l;
        T[v].r=r;
        if(l!=-1){
            T[l].p=v;
        }
        if(r!=-1){
            T[r].p=v;
        }
    }
    for(i=0;i<n;i++){
        if(T[i].p==-1)
            root=i;
    }
    printf("Preorder\n");
    preorder(root);
    cout<<endl;
    printf("Inorder\n");
    inorder(root);
    cout<<endl;
    printf("Postorder\n");
    order(root);
    cout<<endl;
    }
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	char ans[100][40];

	void Solve() {
		UL A, B; cin >> A >> B;
		rep(x, 100) {
			for (UL y = 0; y < 20; y++) ans[x][y] = '.';
			for (UL y = 20; y < 40; y++) ans[x][y] = '#';
		}
		A--; B--;
		rep(y, 10) {
			rep(x, 50) {
				if (B == 0) continue;
				ans[x * 2][y * 2] = '#';
				B--;
			}
		}
		rep(y, 10) {
			rep(x, 50) {
				if (A == 0) continue;
				ans[x * 2][y * 2 + 21] = '.';
				A--;
			}
		}

		cout << "40 100" << endl;
		rep(y, 40) {
			rep(x, 100) {
				cout << ans[x][y];
			} cout << endl;
		}
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+1;
const int mod = 1e9+7;

int main() {
       string s,t;
       cin >> s >> t;
       t.pop_back();
       if(s == t){
        cout << "Yes";
       }
        else 
            cout << "No";
	return 0;
}



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

long long dp[100010][4];
long long a[100010];
long long b[100010];
long long c[100010];

int main() {
  for (int i = 0; i < 100010; i++) for (int j = 0; j < 4; j++) dp[i][j] = -1;
  for (int i = 0; i < 100010; i++) {
    a[i] = b[i] = c[i] = 0;
  }
  int N; cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }

  dp[1][1] = a[1];
  dp[1][2] = b[1];
  dp[1][3] = c[1];

  for (int now = 2; now <= N; now++) {
    dp[now][1] = max(dp[now-1][2] + a[now], dp[now-1][3] + a[now]);
    dp[now][2] = max(dp[now-1][1] + b[now], dp[now-1][3] + b[now]);
    dp[now][3] = max(dp[now-1][1] + c[now], dp[now-1][2] + c[now]);
  }

  cout << max(dp[N][1], max(dp[N][2], dp[N][3])) << endl;
  return 0;
}

Measured memory_bytes: 5760
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;

static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  vector<int> palindrome;
  for(int i=1;i<=10000;i++){
    stringstream ss;
    ss << i;
    string str;
    string r_str;
    ss >> str;

    r_str = str;
    reverse(r_str.begin(),r_str.end());


    if(str == r_str){
      palindrome.push_back(i);
    }
  }

  sort(palindrome.begin(),palindrome.end());
  int num;
  while(~scanf("%d",&num)){
    int idx = lower_bound(palindrome.begin(),palindrome.end(),num) - palindrome.begin();

    int cand[3] = {INF,INF,INF};

    if(idx - 1 >= 0) cand[0] = palindrome[idx-1]; 
    cand[1] = palindrome[idx]; 
    if(idx + 1 < palindrome.size()) cand[2] = palindrome[idx+1];

    int diff = INF;
    int res = INF;
    for(int i=0;i<3;i++){
      if(abs(cand[i] - num) < diff){
	res = cand[i];
	diff = abs(cand[i] - num);
      }
      else if(abs(cand[i] - num) == diff){
	res = min(res,cand[i]);
      }
    }
    printf("%d\n",res);
  }
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    string s; cin >> s;
    ll n = s.size();
    unordered_map<char, ll> m;
    rep(i, n){
        m[s[i]]++;
    }
    ll ans = n*(n-1)/2 + 1;
    for(auto a: m){
        ans -= a.second*(a.second-1)/2;
    }
    cout << ans << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

int main() {
  long long int Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;
  S = min(min(4 * Q, 2 * H), S);
  D = min(2 * S, D);
  cout << (N / 2) * D + (N % 2) * S << endl;
}

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

int merge_count = 0;

int get_group(vector<int> &g, int s) {
	if(g[s]==-1) return s;
	else {
		int ret = get_group(g,g[s]);
		g[s] = ret;
		return ret;
	}
}

void merge_group(vector<int> &g, int g1, int g2) {
	g[g1] = merge_count;
	g[g2] = merge_count;
	merge_count++;
}

int main() {
	int n,m;
	cin >> n >> m;
	vector<int> g(n*2,-1);
	merge_count = n;

	int ans = 0;
	for(int i = 0; i < m; i++) {
		int x,y,z;
		cin >> x >> y >> z;
		x--;
		y--;
		int g1 = get_group(g,x);
		int g2 = get_group(g,y);
		if(g1!=g2) {
			ans++;
			merge_group(g,g1,g2);
		}
	}
	cout << (n-ans) << endl;
}


Measured memory_bytes: 1152
#include<stdio.h>
int main()
{
	int A,B,C,D;
	
	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&C);
	scanf("%d",&D);
	
	if(A<=B){
		if(C<=D){
			printf("%d",A+C);
		}else{
			printf("%d",A+D);
		}
	}else{
		if(B<=A){
			if(C<=D){
			printf("%d",B+C);
		}else{
			printf("%d",B+D);
		}
		}
	}
	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <queue>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

int f[10][10];
int h,w,c;
int ret=-1;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};

void pr(){
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cout << f[i][j];
        }
        cout << endl;
    }
    cout << endl;
}

void bfs(int count, int color){
    int orig,cnt=1;
    vector<pair<int,int> > vec;
    deque<pair<int ,int> > q;
    bool visited[10][10];
    
    memset(visited, false, sizeof(visited));
    orig = f[1][1];
    q.push_back(make_pair(1,1));
    visited[1][1] = true;
    vec.push_back(make_pair(1,1));
    int tx,ty,nx,ny;
    while(!q.empty()){
        ty = q.front().first;
        tx = q.front().second;
        q.pop_front();

        for(int i=0;i<4;i++){
            ny = ty + dy[i];
            nx = tx + dx[i];

            if(f[ny][nx] == orig && visited[ny][nx] == false){
                visited[ny][nx] = true;
                vec.push_back(make_pair(ny,nx));
                q.push_back(make_pair(ny,nx));
                if(orig == c)cnt++;
            }
        }
    }
    
    if(count == 5){
        ret = max(ret, cnt);
        return;
    }

    for(int i=0;i<vec.size();i++){
        f[vec[i].first][vec[i].second] = color;
    }

    for(int i=1;i<=6;i++){
        if(i != color){
            bfs(count+1,i);
        }
    }

    for(int i=0;i<vec.size();i++){
        f[vec[i].first][vec[i].second] = orig;
    }
}

int main(){
    while(cin >> h >> w >> c){
        if((h|w|c) == 0) break;
        ret = -1;
        memset(f, -1, sizeof(f));
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                cin >> f[i][j];
            }
        }
        for(int i=1;i<=6;i++){
            if(f[1][1] != i){
                bfs(0,i);
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 916
n = int(input())
ans = 0
dict = {}
for i in range(n):
    s = ''.join(sorted(input()))
    if s in dict.keys():
        dict[s] += 1
    else:
        dict[s] = 1
for i in dict.values():
    ans += i * (i - 1) / 2
print(int(ans))


Measured memory_bytes: 17852
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.LinkedList;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] commands;
		int num;
		LinkedList<Integer> list = new LinkedList<Integer>();
		for (int i = 0; i < n; i++) {
			commands = br.readLine().split(" ");
			if (commands[0].endsWith("First")) {
				list.removeFirst();
				continue;
			} else if (commands[0].endsWith("Last")) {
				list.removeLast();
				continue;
			}
			num = Integer.parseInt(commands[1]);
			if (commands[0].startsWith("i")) {
				list.addFirst(num);
			} else {
				list.remove(new Integer(num));
			}
		}
		Object[] output = list.toArray();

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < output.length; i++) {
			if (i > 0) {
				sb.append(" ");
			}
			sb.append(output[i]);
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 204312
# 入力値を数値で返す
def gets_i()
  gets.chomp.to_i
end

N = gets_i

# n_list = (1..N).to_a
# p_list = (2..N).to_a + [1]
#
# sum = 0
# n_list.each_with_index do |n, i|
#   sum += n % p_list[i]
# end
# puts sum

puts N * (N-1) / 2


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pii pair<ll,ll>
typedef long long int ll;
struct triplet{int index,a,b;};bool comp (triplet &t1, triplet &t2){return (t1.a < t2.a);}
ll dp[101][100001],n;
vector<ll> v,w;
void initialise(ll n)
{

    for(ll i=0;i<=100;i++)
        for(ll j=0;j<=100000;j++)
            dp[i][j]=-1;

}
ll solve(ll i,ll cap)
{
    if(i==n)
        return 0;
    if(dp[i][cap]!=-1)
        return dp[i][cap];
    if(cap>=w[i])
    dp[i][cap]=v[i]+solve(i+1,cap-w[i]);
    dp[i][cap]=max(dp[i][cap],solve(i+1,cap));
    return dp[i][cap];
}
int main()
{
    fio;
    ll W;
    cin>>n>>W;
    initialise(n);

    for(ll i=0;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        w.push_back(a);
        v.push_back(b);

    }

        cout<<(ll)solve(0,W);

    return 0;
}


Measured memory_bytes: 79232
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	ps := make([]int, n)
	for i := range ps {
		fmt.Scan(&ps[i])
	}
	
	ret := 0
	for i := 0; i < n-2; i++ {
		if (ps[i] < ps[i+1] && ps[i+1] < ps[i+2]) ||
		   (ps[i+2] < ps[i+1] && ps[i+1] < ps[i]) {
			   ret++
		}
	}
	fmt.Println(ret)
}


Measured memory_bytes: 512
import java.math.BigDecimal

fun main() = Thread(null, ::abc169c, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc169c() {
    val (a, b) = readLine()!!.split(' ').map { it.toDouble() }

    val answer = BigDecimal.valueOf(a).multiply(BigDecimal.valueOf(b)).toLong()

    println(answer)
}


Measured memory_bytes: 37168
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	h := nextInt()
	w := nextInt()
	a := nextInt()
	b := nextInt()

	s0 := ""
	s1 := ""

	for j := 0; j < w-a; j++ {
		s0 += "1"
		s1 += "0"
	}
	for j := 0; j < a; j++ {
		s0 += "0"
		s1 += "1"
	}

	for i := 0; i < h-b; i++ {
		fmt.Println(s0)
	}
	for i := 0; i < b; i++ {
		fmt.Println(s1)
	}
}


Measured memory_bytes: 2688
import sys
A, B = map(int, input().split())
a = min(int(A/0.08), int(B/0.08))

while True:
    if int(a*0.08) == A and int(a*0.10) == B:
        print(a)
        sys.exit()
    elif int(a*0.08) > A or int(a*0.10) > B:
        print('-1')
        sys.exit()
    else:
        a += 1




Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>

int main() {
  int a, b;
  std::cin >> a >> b;
  char base = '#';
  char paint = '.';
  int cnt = a - 1;
  std::cout << 100 << " " << 100 << std::endl;
  for (int i = 0; i < 100; ++i) {
    for (int j = 0; j < 100; ++j) {
      if (cnt <= 0 || i == 50 || i % 2 == 1 || j % 2 == 1) {
        std::cout << base;
      } else {
        std::cout << paint;
        --cnt;
      }
    }
    std::cout << std::endl;
    if (i == 50) {
      std::swap(base, paint);
      cnt = b - 1;
    }
  }
}


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  vector<ll> A(3 * N + 5, 0);
  ll pre_sum = 0, post_sum = 0;
  for (int i = 1; i <= 3 * N; ++i) {
    scanf("%lld", &A[i]);
    if (i <= N) { pre_sum += A[i]; }
    else if (i > 2 * N) { post_sum += A[i]; }
  }
  priority_queue<int, vector<int>, greater<int>> que1;
  for (int i = 1; i <= N; ++i) { que1.push(A[i]); }
  vector<ll> S(N + 5, -1);
  S[0] = pre_sum;
  for (int i = N + 1; i <= 2 * N; ++i) {
    int pos = i - N;
    que1.push(A[i]);
    ll val = que1.top(); que1.pop();
    S[pos] = max(S[pos - 1], S[pos - 1] + A[i] - val);
  }

  priority_queue<int> que2;
  for (int i = 2 * N + 1; i <= 3 * N; ++i) { que2.push(A[i]); }
  vector<ll> T(N + 5, -1);
  T[N + 1] = post_sum;
  for (int i = 2 * N; i >= N + 1; --i) {
    int pos = i - N;
    que2.push(A[i]);
    ll val = que2.top(); que2.pop();
    T[pos] = min(T[pos + 1], T[pos + 1] + A[i] - val);
  }

  ll ans = pre_sum - post_sum;
  for (int i = N; i <= 2 * N; ++i) {
    ans = max(ans, S[i - N] - T[i - N + 1]);
  }
  printf("%lld\n", ans);
  return 0;
}


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

int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ans1 = a * x + b * y;
    int ans2;
    if (x >= y){
        ans2 = min(a * (x - y) + 2 * c * y, 2 * c * x); 
    }
    else {
        ans2 = min(2 * c * x + b * (y - x), 2 * c * y); 
    }
    cout << min(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

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

  if (x == 1) {
    cout << 1 << endl;
    return 0;
  }

  ll minn = 1;
  ll maxn = 1e6;
  ll ans;
  while (true) {
    ll n = (minn + maxn) / 2;
    ll s1 = n * (n+1) / 2;
    ll s2 = (n-1) * n / 2;

    if (n == 1) {
      s1 = 1; s2 = 3;
    }
    
    if (x <= s1 && x > s2) {
      ans = n;
      break;
    }

    if (x < s1) {
      maxn = n;
    } else {
      minn = n;
    }

  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  
  if (a == b && a != c)
    printf("%s", "Yes");
  else if (a == c && a != b)
    printf("%s", "Yes");
  else if (b == c && b != a)
    printf("%s", "Yes");
  else
    printf("%s", "No");
  return (0);
}

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

#define FOR(i,a,b)  for(int i = a; i < b; ++i)
#define FORR(i,a,b) for(int i = a; i <= b; ++i)
//#define LOCAL_DEFINE
using namespace std;

#define maxn 123456
double dist[maxn];
map<string, int>mp;
struct Edge {
    int src, dest;
    double weight;
};

struct Graph {
    int V, E;
    struct Edge* edge;
};

struct Graph* createGraph(int V, int E){
    struct Graph* graph = new Graph;
    graph->V = V;
    graph->E = E;
    graph->edge = new Edge[E];
    return graph;
};

bool flag;

bool BellmanFord(Graph* graph, int src){
    for (int i = 0; i <= graph->V - 1; ++i) {
        for (int j = 0; j < graph->E; ++j) {
            if(dist[graph->edge[j].src] * graph->edge[j].weight > dist[graph->edge[j].dest])
            dist[graph->edge[j].dest] = dist[graph->edge[j].src] * graph->edge[j].weight;
        }
    }
    for (int j = 0; j < graph->E; ++j) {
        if(dist[graph->edge[j].src] * graph->edge[j].weight > dist[graph->edge[j].dest])
            //cout << "exist negative weight cycle" <<endl;
            return true;
    }
    return false;
}

char uppper(char c){
    if(c >= 'a' && c <= 'z')return c - 'a' + 'A';
}

typedef long long ll;
bool check(ll x, ll y){
    if( x >= 2 || y >= 2)return true;
    return false;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //cin.precision(10);
    //cout << fixed;g

#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif
    ll x, y;
    cin >> x >> y;
    if(abs(x - y) > 1)cout << "Alice" << endl;
    else cout << "Brown" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<long long,long long> p;
int z[100010],n,m,k,r;
long long x,y,d[100010],a,b;
vector<int> v[100010];
queue<p>P;priority_queue<p,vector<p>,greater<p> >Q;
int main(){
	cin>>n>>m>>k>>r>>x>>y;
	for(int i=0;i<n;i++)z[i]=0,d[i]=1145141145141919;
	for(int i=0;i<k;i++){
		int c;cin>>c;c--;
		z[c]=2;
		P.push(make_pair(c,r));
	}
	for(int i=0;i<m;i++){
		int a,b;cin>>a>>b;a--,b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	while(!P.empty()){
		a=P.front().first,b=P.front().second;P.pop();
		if(b)for(int i=0;i<v[a].size();i++){
			if(!z[v[a][i]]){
				z[v[a][i]]=1;
				P.push(make_pair(v[a][i],b-1));
			}
		}
	}
	Q.push(make_pair(0,0));
	while(!Q.empty()){
		a=Q.top().first,b=Q.top().second;Q.pop();
		if(d[b]>a){
			d[b]=a;
			for(int i=0;i<v[b].size();i++){
				if(z[v[b][i]]==2)continue;
				Q.push(make_pair(a+(z[v[b][i]]?y:x),v[b][i]));
			}
		}
	}
	cout<<d[n-1]-(z[n-1]?y:x)<<endl;
	return 0;
}

Measured memory_bytes: 11052
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

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

int main(){

	double x,y;
	vector<P> v;
	while(~scanf("%lf,%lf",&x,&y)){
		v.push_back(P(x,y));
	}
	
	double cx = (v[0].first + v[1].first + v[2].first) / 3.0;
	double cy = (v[0].second + v[1].second + v[2].second) / 3.0;
	
	double S=0;
	for(int i=0;i<v.size();i++){
		int idx1 = i;
		int idx2 = (i+1) % v.size();
		double a = sqrt(pow(v[idx1].first - v[idx2].first,2.0) + pow(v[idx1].second - v[idx2].second,2.0));
		double b = sqrt(pow(v[idx1].first - cx,2.0) + pow(v[idx1].second - cy,2.0));
		double c = sqrt(pow(v[idx2].first - cx,2.0) + pow(v[idx2].second - cy,2.0));

		double z = (a+b+c)/2.0;
		double tmp_s = sqrt(z*(z-a)*(z-b)*(z-c));
		S+=tmp_s;
	}

	printf("%.7f\n",S);

}

Measured memory_bytes: 0
import math

data = input().split()
x1 = float(data[0])
x2 = float(data[2])
y1 = float(data[1])
y2 = float(data[3])
x3 = x1 - x2 if x1 > x2 else x2 - x1
y3 = y1 - y2 if y1 > y2 else y2 - y1
print("%.8f" % math.sqrt(x3 * x3 + y3 * y3))


Measured memory_bytes: 5640
H, N = map(int, input().split())
L = []
for _ in range(N):
    a, b = map(int, input().split())
    L.append((a, b))

INF = 1000000000
dp = [INF] * (H+1 + 10000)
dp[H] = 0
for h in range(H-1, -10000, -1):
    tmp = INF
    for a, b in L:
        if h + a <= H:
            c = dp[h+a] + b
            tmp = tmp if tmp < c else c
    dp[h] = tmp

print(min(dp[0], min(dp[H+1:])))

Measured memory_bytes: 42332
import java.util.Scanner;

public class Main {
	
	public static int solution(int[] a1, int[] a2) {
		int count = 0;
		for (int i = 0; i < a2.length; i++) {
			for (int j = 0; j < a1.length; j++) {
				if (a2[i] - a1[j] == 0) {
					count += 1;
					break;
				}
			}
		}
		return count;
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a1 = new int[n];
		for (int i = 0; i < n; i++){
		    a1[i] = in.nextInt();
		}
		int n2 = in.nextInt();
		int[] a2 = new int[n2];
		for (int i = 0; i<n2; i++){
		    a2[i] = in.nextInt();
		}
		int out = solution(a1,a2);
		System.out.println(out);
	}

}


Measured memory_bytes: 39620
n, y = map(int,input().split())
a=-1
b=-1
c=-1
for i in range(n+1):
    for j in range(n+1-i):
        total = i*10000+j*5000+(n-i-j)*1000
        if total==y:
            a=i
            b=j
            c=n-i-j
            
            
print(a,b,c)



Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  string s;std::cin >> s;
  re(i, s.size()) s[i] = 'x';
  std::cout << s << '\n';
  return 0;
}


Measured memory_bytes: 888
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 19 + 7
EPS = 10 ** -10

N = INT()
A = LIST()
mx = 0
ans = 0
for a in A:
    if a > mx:
        mx = a
    else:
        ans += abs(mx - a)
print(ans)


Measured memory_bytes: 33628
#include <bits/stdc++.h>
#define endl '\n'
#define _USE_MATH_DEFINES
using namespace std;

int main() {
	
	ios::sync_with_stdio(false);
    cin.tie(0);
    
    int i;
    char in;
    cin>>in;
    if(in>=65&&in<=90) cout<<"A";
    else cout<<"a";
	return 0;
}

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

int main(){
    double pi=acos(-1);
	double a, b, x;
    cin >> a >> b >> x;
    
    double ans;
    if(2*x>a*a*b){
        ans=atan(2*(a*a*b-x)/a/a/a)*180/pi;
    }else{
        ans=90-atan(2*x/a/b/b)*180/pi;
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] a;
		a = new int[n];
		for(int i=0;i<n;i++){
			a[i]=sc.nextInt();
		}
		int cnt=0;
		int flag=1;
		int tmp,j;
		while(flag==1){
			flag=0;
			for(j=n-1;j>0;j--){
				if(a[j]<a[j-1]){
					tmp=a[j];
					a[j]=a[j-1];
					a[j-1]=tmp;
					cnt++;
					flag=1;
				}
			}
		}
		for(int i=0;i<n-1;i++){
			System.out.printf("%d ",a[i]);
		}
		System.out.printf("%d",a[n-1]);
		System.out.printf("\n");
		System.out.println(cnt);
		sc.close();
	}
}


Measured memory_bytes: 26584
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int a[] = new int[M];
    int b[] = new int[M];
    int ans[] = new int[N];
    
    for(int i = 0; i<N;i++){
    	ans[i] = 0;
    }
    
    for(int i = 0; i<M ;i++){
    	a[i] = sc.nextInt();
    }
    for(int i = 0; i<M ;i++){
    	b[i] = sc.nextInt();
    }
    for(int i = 0; i < M; i++){
    	for(int s = 1;s<=N;s++){
    		if(a[i] == s){
    			ans[s-1]++;
    		}
    		if(b[i] == s){
    			ans[s-1]++;
    		}
    	}
    }
    for(int i = 0; i<N ;i++){
    	System.out.println(ans[i]);
    }
  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
long long a[32];
void find(long long n)
{
	int flag=1;
	if(n==0)
	return ;
	if(n<0)
	{
		flag=0;
		n=-n;
	}
	int k=log2(n);
	if(flag==1)
	{
		if(k==0)
		a[0]=1;
		else if(k%2==1)
		{
			a[k+1]=1;
			find(n-pow(2,k+1));
		}
		else
		{
			long long nn=(pow(4,k/2+1)-1)/3;
			if(nn>=n)
			{
				a[k]=1;
				find(n-pow(2,k));
			}
			else
			{
				a[k+2]=a[k+1]=1;
				find(n-pow(2,k+1));
			}
		}
	}
	else
	{
		if(k==0)
		{
			a[0]=1;a[1]=1;
		}
		else if(n==2)
		{
			a[1]=1;
		}
		else if(k%2==0)
		{
			a[k+1]=1;
			find(pow(2,k+1)-n);
		}
		else
		{
			long long nn=2*(pow(4,(k+1)/2)-1)/3;
			if(nn>=n)
			{
				a[k]=1;
				find(pow(2,k)-n);
			}
			else
			{
				a[k+2]=a[k+1]=1;
				find(pow(2,k+1)-n);
			}
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
	int i=31;
	long long n;
	cin>>n;
	if(n==0)
	cout<<0;
	else
	{
		find(n);
		while(!a[i--]);
		for(int j=i+1;j>=0;j--)
		cout<<a[j];
	}

	return 0;
}

Measured memory_bytes: 384
N = int(input())
B = list(map(int, input().split()))
ans = [-1 for i in range(N)]
B_pair = [(B[i], i) for i in range(N - 1)]
B_pair.sort()
for (b, i) in B_pair:
    if ans[i] < 0:
        ans[i] = b
    if ans[i + 1] < 0:
        ans[i + 1] = b
print(sum(ans))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <string>
#define SIZE 100005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int A[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	int ret=0;
	for(int i=0;i<n;i++)
	{
		ret++;
		int f=A[i];
		while(i<n&&A[i]==f) i++;
		if(i==n) break;
		if(A[i]>f)
		{
			while(i+1<n&&A[i+1]>=A[i]) i++;
		}
		else
		{
			while(i+1<n&&A[i+1]<=A[i]) i++;
		}
	}
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL<<60;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------
// snukeさんのmodint
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// mint N;
//cout << N.x << endl;

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

// combination c(N);
// mint ans = c(N,n);
// cout << ans.x << endl;
// Nとnはll型(mintではない)

int main(){
  ll N,K;
  cin >> N >> K;
  vector<ll> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  mint sum_min = 0;
  combination c(N);
  for(ll i=0; i<N-K+1; i++){
    mint co = c(N-i-1, K-1);
    co *= A[i];
    sum_min += co;
  }
  mint sum_max = 0;
  sort(A.begin(),A.end(),greater<ll>());
  for(ll i=0; i<N-K+1; i++){
    mint co = c(N-i-1,K-1);
    co *= A[i];
    sum_max += co;
  }
  mint ans = sum_max - sum_min;
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main() {
  int number_n;
  scanf("%d", &number_n);
  if(number_n % 111 == 0) {
    printf("%d\n", number_n);
  } else {
    printf("%d\n", number_n + (111 - (number_n % 111)));
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  long long a[100009],ans=0,cnt=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  a[n]=-100000;
  sort(a,a+n);
  for(int i=0;i<n;i++){
    cnt++;
    if(a[i]!=a[i+1]){
      if(cnt<a[i])ans+=cnt;
      else ans+=cnt-a[i];
      cnt=0;
    }
  }
  cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
const int MOD = 1000000009;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  int a[100005], b[100005];
  ll ans = 0;

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

  for(int i = 0;i < n;i++){
    if(a[i] >= b[i]){
      ans += b[i];
    }else{
      ans += a[i] + min(b[i] - a[i], a[i + 1]);
      a[i + 1] -= min(b[i] - a[i], a[i + 1]);
    }
  }

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


Measured memory_bytes: 1024
n = int(input())

work = [True] *  55556
work[0] = False
work[1] = False
primes = []
for i in range(55556):
    if work[i]:
        for j in range(2* i, 55556, i):
            work[j] = False

ret = [2]
i = 6
while len(ret) != n:
    i += 5
    if work[i]:
        ret.append(i)

print(' '.join(map(str,ret)))


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(double, a, b);
  print(ceil((a + b) / 2));
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    map<int, int> mp;
    rep(i, n) {
        mp[a[i]] ++;
    }

    int num = mp.size();
    if(num < k) {
        cout << 0 <<  endl;
        return 0;
    }
    vector<int> ans;
    for(auto v : mp) {
        ans.push_back(v.second);
    }
    int delnum = num - k;
    sort(ans.begin(), ans.end());
    ll anss = 0;
    rep(i, delnum) {
        anss += ans[i];
    }
    cout << anss << endl;
    return 0;
}


Measured memory_bytes: 11516