akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;
    set<int> abet[26];
    rep(i, s.size()){
        int num = s[i] - 'a';
        abet[num].insert(i);
    }

    rep(i, q){
        int query;
        cin >> query;
        if (query == 1){
            int p1; char p2;
            cin >> p1 >> p2;
            p1--;
            int num_replace = (int)p2 - 'a';
            int num_old = s[p1] - 'a';
            abet[num_old].erase(p1);
            s[p1] = p2;
            abet[num_replace].insert(p1);

        } else {
            int p1, p2;
            cin >> p1 >> p2;
            p1--; p2--;
            int ans = 0;
            rep(j, 26){
                if(abet[j].lower_bound(p1) != abet[j].upper_bound(p2)){
                    //char c = j + 'a';
                    //cout << "["<< c << "]";
                    ans++;
                }
            }
            // rep(j, 26){
            //     cout << (char)(j + 'a') << ":";
            //     for(auto x:abet[j]){
            //         cout << x << " ";
            //     }
            //     cout << endl;
            // }
            cout << ans << endl;
        }
    }



}



Measured memory_bytes: 26244
#include <bits/stdc++.h>
using namespace std;
string s,sr;

int main()
{
  cin >> s;
  sr = s;
  int l = s.length();
  reverse(sr.begin(), sr.end());
  int res = (l+1) / 2;
  for (int i = (l+1) / 2; i < l; i++) {
    if (s[i] == sr[i] && s[i] == s[l/2]) {
      res++;
    } else {
      break;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
long long fac[201000], finv[201000], inv[201000]; 
long long MOD = 1000000007;  
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 200500; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
	long long N, A, B; COMinit(); 
	cin >> N >> A >> B; 
	long long total = 1; 
	long long now = N; long long mul = 2;
	for(int i = 0; i < 32; i++){
		if((N >> i) & 1){
			total *= mul; total %= MOD; 
		}
		mul = mul * mul % MOD; 
		if((N >> i) == 0) break; 
	}
	long long impo1 = 1; long long impo2 = 1; 
	for(long long i = N; i > N-A; i--){
		impo1 *= i; impo1 %= MOD; 
	}
	impo1 *= finv[A]; impo1 %= MOD; 
	for(long long i = N; i > N-B; i--){
		impo2 *= i; impo2 %= MOD; 
	}
	impo2 *= finv[B]; impo2 %= MOD; 
	cout << (MOD * 3 + total - 1 - impo1 - impo2) % MOD << endl; 
}

Measured memory_bytes: 4992
'use strict'

function main(input) {
  input = input.split('\n');
  const NK = input[0].split(' ').map(n => Number(n));
  const A = input[1].split(' ').map(n => Number(n));
  const countBucket = [...Array(NK[0]+1)].fill(0);

  for (const num of A) {
    countBucket[num] += 1;
  }
  console.log(countBucket.sort((a, b) => b - a).slice(NK[1]).reduce((a, b) => a + b));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 42264
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>
#include <stack>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    stack<pair<char, int>> st;
    bool ok = true;
    for(int i = 0; i < n; i++)
    {
        char ch; int x; cin >> ch >> x;
        if(ch == '(')
        {
            if(st.empty()) st.push(make_pair(ch, x));
            else if(st.top().first == '(') st.top().second += x;
            else st.push(make_pair(ch, x));
        }
        else
        {
            if(st.empty()) ok = false;
            else if(st.top().second - x >= 0)
            {
                st.top().second -= x;
                if(st.top().second == 0) st.pop();
            }
            else ok = false;
        }
    }
    if(ok and st.empty()) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}




Measured memory_bytes: 3204
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define erep(i, n) for (int i = 0; i <= (int)(n); i++)
using p = pair<int, int>;

int main() {
    int n, m; cin >> n >> m;
    vector<p> vec(m);
    rep (i, m) {
        int a, b; cin >> a >> b;
        vec[i].first = b;
        vec[i].second = a;
    }
    sort(vec.begin(), vec.end());

    int ans = 0;
    int cur = -10;
    rep (i, m) {
        if (vec[i].second < cur) continue;
        ans++;
        cur = vec[i].first;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
// #include <vector>
// #include <string>
// #include <algorithm>
// #include <set>
// #include <map>
// #include <iomanip>

// #define MOD 1000000007

using namespace std;
// typedef unsigned long long ull;
typedef long long ll;

void p() {
    cout << "\n";
}
template<class Head, class... Body>
void p(Head head, Body... body) {
    cout << head << ",";
    p(body...);
}


int main(int argc, char const *argv[]) {
    int H, W;
    cin >> H >> W;

    int ans;
    if (H % 3 == 0 || W % 3 == 0) {
        ans = 0;
    } else {
        ans = min(H, W);
        int k, l, d;
        k = H / 3; l = (W+1) / 2; d = (H-k)*l - k*W;
        // p(k,l,d,ans);
        ans = min(ans, d);
        k = (H+2) / 3; l = W / 2; d = k*W - (H-k)*l;
        // p(k,l,d,ans);
        ans = min(ans, d);
        k = (H+1) / 2; l = W / 3; d = (W-l)*k - l*H;
        // p(k,l,d,ans);
        ans = min(ans, d);
        k = H / 2; l = (W+2) / 3; d = l*H - (W-l)*k;
        // p(k,l,d,ans);
        ans = min(ans, d);
    }
    
    cout << ans << endl;

    return 0;
}


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    ll t;
    cin >> n >> t;
    ll sum = 0;
    ll mx = 0;
    REP(i, 0, n) {
        ll h;
        cin >> h;
        mx = max(mx, h);
        if (sum >= t) {
            cout << 1 << endl;
            sum += h;
            continue;
        }
        ll resT = t - sum;
        ll ans = 0;
        if (resT < h) {
            ans = 1;
            resT = 0;
        } else {
            resT -= h;
            ans = 2 + resT / mx;
        }
        cout << ans << endl;
        sum += h;
    }
    return 0;
}



Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main(){

ll n;cin >> n;
ll a[n];rep(i,n)cin>>a[i];
sort(a,a+n);
bool ok = false;
for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]){
        ok = true;
    }
}
if(ok)cout << "NO" << endl;
else cout << "YES" << endl;
return 0;
}





Measured memory_bytes: 1792
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

inline ll floor(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return a / llb;
	}
	else
	{
		return - ( (-a + llb - 1) / llb);
	}
}

inline ll ceil(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return (a + llb - 1) / llb;
	}
	else
	{
		return - (-a / llb);
	}
}

inline ll getLowestOneBit(ll a)
{
	return a & (-a);
}

inline ll getHighestOneBit(ll a)
{
	while ((a & (a - 1)) != 0)
	{
		a = a & (a - 1);
	}
	return a;
}

inline bool isPower2(ull a)
{
	if (a == 0)
	{
		return false;
	}
	return !(a & (a - 1));
}

inline ll getSpecifiedBit(ll a, unsigned bit)
{
	return (a & (1LL << bit)) >> bit;
}

// computational complexity: o(log(max(a, b))) 
inline ull getGcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

template<class Integer>
inline Integer getPower(Integer base, ull exponential)
{
	Integer result = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			result = result * base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return result;
}

int main()
{
	ll N, M;
	cin >> N >> M;
	priority_queue<double> As;
	double a;
	for (ll i = 0; i < N; ++i)
	{
		cin >> a;
		As.push(a);
	}

	for (ll i = 0; i < M; ++i)
	{
		a = As.top();
		As.pop();
		As.push(a / 2);
	}

	ll res = 0;
	for (ll i = 0; i < N; ++i)
	{
		res += static_cast<ll>(As.top());
		As.pop();
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1400
a=input().split()
N=int(a[0])
M=int(a[1])
first=[]
second=[]
i=0
while i<M:
	y=input().split()
	if int(y[0])==1:
		first.append(y[1])
	elif int(y[1])==N:
		second.append(y[0])
	i+=1

first=set(first)
second=set(second)
if len(first.intersection(second))>0:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

Measured memory_bytes: 25904
def main():
    S = input()

    if S == "SUN":
        print(7)
        exit(0)
    elif S == "MON":
        print(6)
        exit(0)
    elif S == "TUE":
        print(5)
        exit(0)
    elif S == "WED":
        print(4)
        exit(0)
    elif S == "THU":
        print(3)
        exit(0)
    elif S == "FRI":
        print(2)
        exit(0)
    else:
        print(1)
        exit(0)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main(){
	int A, B, C, D;
	char S[15], T[15], U[15];
	scanf("%s %s", &S, &T);
	scanf("%d %d", &A, &B);
	scanf("%s", &U);
	C=A-1;
	D=B-1;
	if(strcmp(S, U)==0){
		printf("%d %d", C, B);
	} else {
		printf("%d %d", A, D);
	}
	return 0;
}

Measured memory_bytes: 2128
def draw_map(count_map, row_index, col_index) :
	for i in range(row_index-1, row_index+2) :
		if (i < 0 or len(count_map) <= i) :
			continue
		for j in range(col_index-1, col_index+2) :
			if (j < 0 or len(count_map[0]) <= j) :
				continue
			count_map[i][j] += 1
	
	return count_map
    				
    			

H,W = [int(i) for i in input().split()]
mines = []
for i in range(H) :
	mines.append(input())

# 白地図を用意して、1ずつ足す
# 空きマスだったら数字に置き換える
count_map = [[0 for i in range(W)] for j in range(H)]
for i in range(H) :
	for j in range(W) :
		if (mines[i][j] == "#") :
			mine_map = draw_map(count_map,i,j)

for i in range(H) :
	out_line = ""
	for j in range(W) :
		if (mines[i][j] == ".") :
			out_line += str(count_map[i][j])
		else :
			out_line += "#"
	print(out_line)
    		


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define zoom ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define precise cout.precision(8); cout << fixed;
#define seed srand(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
using namespace std;

void solve() {
    int N; cin >> N;
    int rem = (1000 - N % 1000) % 1000;
    cout << rem;
}

int main() {
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<double> a(N);
	double sum = 0;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	double ave = sum / (double)N;

	int id = 0;
	double s = abs(a[0] - ave);
	for (int i = 0; i < N; ++i) {
		double t = abs(a[i] - ave);

		if (t < s) {
			id = i;
			s = t;
		}
	}

	cout << id << endl;

	return 0;
}


Measured memory_bytes: 256
S = list(input())
if S[0] == "A" and S[2:-1].count("C") == 1:
    counter = 0
    for c in S:
        if c.lower() != c:
            counter += 1
    if counter == 2:
        print("AC")
    else:
        print("WA")
else:
    print("WA")


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

#define S size()
#define EN end()
#define BE begin()
#define LEN length()

#define endl "\n"
#define cnt count
#define in insert
#define er erase
#define fi first
#define se second
#define ld double
#define ll long long

#define gcd __gcd
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define np next_permutation

#define si set<ll>
#define sc set<char>
#define mll map<ll,ll>
#define vi vector<ll>
#define vc vector<char>
#define pll pair<ll,ll>
#define vpi vector<pll>
#define msi multiset<ll>
#define msc multiset<char>
#define vvi vector<vector<ll> >

#define all(v) v.BE,v.EN
#define godv(v) sort(all(v))
#define god(ar,n) sort(ar,ar+n)
#define godvr(v) godv(v) ; reverse(all(v))
#define godr(ar,n) god(ar,n) ; reverse(ar,ar+n)

#define iter(s) for(auto it:s)
#define forl(i,n) for(ll i=0;i<n;i++)
#define fore(i,n) for(ll i=1;i<=n;i++)
#define fora(i,v) for(ll i=0;v[i];i++)
#define forn(i,n) for(ll i=n-1;i>=0;i--)
#define forls(i,l,r) for(ll i=l;i<r;i++)
#define forns(i,l,r) for(ll i=r-1;i>=l;i--)

#define pat ll n;cin>>n;
#define wq ll q;cin>>q;while(q--)
#define tak(s) string s;cin>>s;ll n=s.LEN;
#define nokay if(ok) cout<<"YES\n";else cout<<"NO\n";
#define pat1 ll n;cin>>n;ll ar[n];forl(i,n) cin>>ar[i];
#define pat2 ll n,k;cin>>n>>k;ll ar[n];forl(i,n) cin>>ar[i];

#define inf 1e18
#define mod1 1000000007
#define mod2 998244353
#define PI 3.1415926535897932384626433832
#define eness(x) __builtin_ctzll(x)//trailing 0s
#define nhigh(x) __builtin_popcountll(x)//number of high terms
//**********************************
void Fast();
ll mf(ll x,ll mod);
ll mi(ll x,ll mod);
ll C(ll n,ll r,ll mod);
ll bpow(ll a,ll b,ll mod);

void Fast(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}
ll mf(ll x,ll mod=mod1){
    if(x<2) return 1;
    return (x*mf(x-1))%mod;
}
ll mi(ll x,ll mod=mod1){
    return bpow(x,mod-2,mod);
}
ll C(ll x,ll y,ll mod=mod1){
    if(x<y) return 0;
    return (((mf(x)*mi(mf(y)))%mod)*mi(mf(x-y)))%mod;
}
ll bpow(ll x,ll y,ll mod){
    x%=mod;
    ll res=1;
    while(y>0){
        if(y&1){
            res=res*x%mod;
        }
        x=x*x%mod;
        y>>=1;
    }
    return res;
}
//**********************************

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    Fast();
    pat;
    if(n>=30){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

ll power(ll a, ll b) {
	ll result = 1;
	while(b) {
		if(b % 2) result = (result * a) % P;
		a = (a * a) % P;
		b /= 2;
	}
	
	return result;
}

void solve() {
	int n, k;
	cin >> n >> k;
	
	ll ans = k;
	vector<ll> cnt(k + 1, 0);
	cnt[k] = 1;
	for(int i = k - 1; i >= 1; i--) {
		int nd = k / i;
		cnt[i] = power(nd, n);
		for(int j = i + i; j <= k; j += i) {
			cnt[i] = (cnt[i] - cnt[j] + P) % P;
		}
		
		ans = (ans + (cnt[i] * i) % P) % P;
	} 
	
	cout << ans << endl;
}

int main(){
#define MULTITEST 0
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else

    solve();
    
#endif

    return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
void get_unique(vector<T>& x) {
    x.erase(unique(x.begin(), x.end()), x.end());
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d) rep(j, 26) cin >> s[i][j];

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

    int ans = 0;
    vector<int> last(26, -1);
    rep(i, d) {
        ans += s[i][t[i]];
        last[t[i]] = i;
        rep(j, 26) ans -= c[j] * (i - last[j]);
        cout << ans << '\n';
    }
}

Measured memory_bytes: 3640
import math
N, K = map(int, input().split())

ans=0
for i in range(1,N+1,1):
    point = i
    count = 0
    if i>=K:
        ans +=1
    else:
        while point < K:
            point *= 2
            count += 1
        ans += 1/(2**count)

print(ans/N)


Measured memory_bytes: 39664
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,res[N],A,B,l,r,mid;
vector<int> e[N];
bool ok;
int rest(vector<int> &L){
	if (!(L.size()&1)) L.push_back(0);
	sort(L.begin(),L.end());
	for (int l=0,r=L.size()-2;l<r;l++,r--)
	if (L[l]+L[r]>mid) ok=0;
	int p=L.size()-1,len=p;
	while (p&&L[p]+L[len-p+(len-p>=p)]<=mid) p--;
	return L[p];
}
void solve(int x,int fa){
	vector<int> L;
	for (auto v:e[x])
	if (v!=fa) solve(v,x),L.push_back(res[v]+1);
	if (fa) res[x]=rest(L);
	else{
		if (L.size()&1) L.push_back(0);
		sort(L.begin(),L.end());
		for (int l=0,r=L.size()-1;l<r;l++,r--)
		if (L[l]+L[r]>mid) ok=0;
	}
}
bool check(){
	ok=1;
	solve(1,0);
	return ok&&res[1]<=mid;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	A=n-1;
	for (int i=1;i<=n;i++) A-=e[i].size()/2;
	for (l=0,r=n-1;l<r;){
		mid=(l+r)>>1;
		if (check()) r=mid;else l=mid+1;
	}
	printf("%d %d\n",A,l);
	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  int I = H - 1;
  string A = ".", B, C;
  //Aは.......
  for(int h = 1; h < W; h++) {
    A += '.';
  }
  
  
  //処理開始
  for(int i = 0; i < H; i++) {
    //文字列読み込み
    if(i == 0) {
      cin >> B;
    }
    
    if(i == I) {
      C = ".";
      for(int p = 1; p < W; p++) {
        C += '.';
      }
      
    }
    
    else {
      cin >> C;
    }
    
    //各文字の評価
    for(int j = 0; j < W; j++) {
      int k = j - 1;
      int l = j + 1;
      char x = B.at(j);
      //爆弾マスの評価
      if(x == '#') {
        cout << "#";
      }
      
      //非爆弾マスの評価
      int t = 0;
      if(x == '.') {
        if(j != 0) {
          if(B.at(k) == '#') {
          t += 1;
          }
          
           if(A.at(k) == '#') {
          t += 1;
           }
          
          if(C.at(k) == '#') {
          t += 1;
          }
          
        }
        
        if(j != W - 1) {
         if(B.at(l) == '#') {
          t += 1;
         }
          
         if(A.at(l) == '#') {
          t += 1;
         }
          
         if(C.at(l) == '#') {
          t += 1;
         } 
          
        }
        
        if(A.at(j) == '#') {
          t += 1;
        }
        
        if(C.at(j) == '#') {
          t += 1;
        }       
        
      cout << t;
      }
      //非爆弾増野評価終わり
     
    }
    //各文字の評価終わり
    cout << endl;
    A = B;
    B = C;
  }
  
  //処理終わり
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    int num = 0;
    for (int i=0; i<n; i++) {
        int h;
        cin >> h;
        if (h >= k) {
            num++;
        }
    }
    cout << num << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String[] lines = sc.next().split(",");
            int[] cards = new int[13];
            int max = 0;
            int max2 = 0;
            for (int i = 0; i < lines.length; i++) {
                int n = Integer.parseInt(lines[i])-1;
                cards[n]++;
                if (max < cards[n]) {
                    max = cards[n];
                } else if (max2 < cards[n]) {
                    max2 = cards[n];
                }
            }
            if (max >= 4) {
                System.out.println("four card");
            } else if (max == 3) {
                if (max2 == 2) {
                    System.out.println("full house");
                } else {
                    System.out.println("three card");
                }
            } else if (max == 2 && max2 == 2) {
                System.out.println("two pair");
            } else if (max == 2) {
                System.out.println("one pair");
            } else {
                int count=0;
                for (int i = 0; i < 14; i++) {
                    if(cards[i%13]==1) {
                        count++;
                        if(count==5) {
                            break;
                        }
                    }else {
                        count=0;
                    }
                }
                if(count==5) {
                    System.out.println("straight");
                }else {
                    System.out.println("null");
                }
            }
        }
    }
}


Measured memory_bytes: 25756
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int x[200000];
int y[200000];

int main()
{
	int n;
	int ans=0;
	int mid;
	
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x[i];
		y[i]=x[i];
	}
	sort(y,y+n);

	mid = (n+1)/2;

	for(int i=0;i<n;i++)
	{
		if(x[i]<y[mid])
		{
			cout<<y[mid]<<endl;
		}else{
			cout<<y[mid-1]<<endl;
		}
	}
	return 0;
}

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

int n,A[50];

int solve(int i,int m){ 
    if(m==0)return 1;
    if(i>=n)return 0;
    int res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin >> n;
    int m,q;
    for(int i=0;i<n;i++)cin >> A[i];

    cin >> q;
    while(q--){
        cin >> m;
        if(solve(0,m))cout << "yes\n" ;
        else cout << "no\n";
    }   
    return 0;
}



Measured memory_bytes: 3188
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n-1];
		
		int sum = 0;
		
		for(int i = 0; i < n-1; i++){
			b[i] = sc.nextInt();
		}
		a[0] = b[0];
		a[n-1] = b[n-2];
		
		for(int i = 0; i < n-2; i++){
			a[i+1] = min(b[i],b[i+1]);
			}
		for(int i = 0; i < n; i++){
			sum += a[i];
		}
		System.out.println(sum);
		}
		
		public static int min(int a, int b){
			if(a < b)
				return a;
			else
				return b;
		}
	
	}

Measured memory_bytes: 23252
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 1e5 + 5;
typedef long long ll;
const ll INF = 1e16; 
using namespace std;

int n, m, a[N], b[N]; 
ll ans = INF, f[N]; 
struct node
{
	ll a0, d;
	node(ll a = 0, ll b = 0) { a0 = a, d = b; }
	node operator + (const node &p) const
		{
			return node(a0 + p.a0, d + p.d); 
		}
};
struct SegTree
{
	struct Tree { node x; } t[N << 2];
	void pushdown(int p, int l, int r)
		{
			if(t[p].x.a0 || t[p].x.d)
			{
				int mid = (l + r) >> 1;
				t[p << 1].x = t[p << 1].x + t[p].x;
				t[p << 1 | 1].x = t[p << 1 | 1].x + node(t[p].x.a0 + (mid + 1 - l) * t[p].x.d, t[p].x.d);
				t[p].x = node(0, 0); 
			}
		}
	void modify(int p, int l, int r, int ql, int qr, node y)
		{
			if(ql > qr) return; 
			if(ql <= l && r <= qr)
			{
				y = node(y.a0 + (l - ql) * y.d, y.d); 
				t[p].x = t[p].x + y; return; 
			}
			pushdown(p, l, r); int mid = (l + r) >> 1; 
			if(ql <= mid) modify(p << 1, l, mid, ql, qr, y); 
			if(mid < qr) modify(p << 1 | 1, mid + 1, r, ql, qr, y); 
		}
	void query(int p, int l, int r)
		{
			if(l == r) return (void) (f[l] = t[p].x.a0); 
			pushdown(p, l, r); int mid = (l + r) >> 1;
			query(p << 1, l, mid), query(p << 1 | 1, mid + 1, r); 
		}
} T; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	n = read <int> (), m = read <int> ();
	for(int i = 1; i <= n; i++) a[i] = read <int> (); 
	for(int l, r, i = 2; i <= n; i++)
	{
		l = a[i - 1], r = a[i];
		if(a[i] >= a[i - 1])
		{
			T.modify(1, 1, m, l + 1, r, node(r - l, -1)); 
			for(int j = l + 1; j <= r; j++) b[j] += (r + 1 - j); 
			T.modify(1, 1, m, 1, l, node(r - l, 0));
			for(int j = 1; j <= l; j++) b[j] += r - l; 
			T.modify(1, 1, m, r + 1, m, node(r - l, 0));
			for(int j = r + 1; j <= m; j++) b[j] += r - l; 
		}
		else
		{
			T.modify(1, 1, m, l + 1, m, node(r + m - l, -1));
			for(int j = l + 1; j <= m; j++) b[j] += (r + m + 1 - j); 
			T.modify(1, 1, m, 1, r, node(r, -1));
			for(int j = 1; j <= r; j++) b[j] += (r + 1 - j); 
			T.modify(1, 1, m, r + 1, l, node(r + m - l, 0));
			for(int j = r + 1; j <= l; j++) b[j] += (r + m - l); 
		}
	}
	T.query(1, 1, m);
	for(int i = 1; i <= m; i++) ans = min(ans, f[i]);
	printf("%lld\n", ans); 
	return 0; 
}


Measured memory_bytes: 8672
import math
import sys
import heapq
sys.setrecursionlimit(10**8)

N = int(input())
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))

A1sum=[0]
A2sum=[0]
aa1 = aa2 = 0

for i in range(N):
	aa1 += A1[i]
	aa2 += A2[i]
	A1sum.append(aa1)
	A2sum.append(aa2)

ans = 0

for i in range(1,N+1):
	ue = A1sum[i]
	sita = A2sum[N] - A2sum[i-1]
	ans = max(ans, ue+sita)

print(ans)

Measured memory_bytes: 3064
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair
#define debug_vec(x, n) cout << (#x) << ": "; for(int i = 0; i < n; i++) cout << x[i] << (i == n - 1 ? "\n" : " ");
 
typedef long long ll;
typedef long double ld;

void solve(){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m);
    ll suma = 0;
    for(int i = 0; i < m; i++){
        cin >> a[i];
        suma += a[i];
    }
    cout << (suma <= n ? n - suma : -1) << "\n";
    return;
}
 
int main(){
    IOS;
    int t = 1;
    //cin >> t;
    for(int i = 1; i <= t; i++){
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007


int main() {

  int H,W;
  cin >> H >> W;

  vector<vector<string>> S(H,vector<string>(W));
  for(int i = 0;i < H;i++) {
    for(int j = 0;j < W;j++) {
      cin >> S.at(i).at(j);
      if(S.at(i).at(j) == "snuke") {
        cout << (char)(j+'A') << i+1 << endl;
      }
    }
  }


}

Measured memory_bytes: 256
n,k = map(int,input().split())
h_list = [int(input()) for _ in range(n)]
h_list.sort(reverse=True)
i = 0
j = k-1
ans = 10**9

while j < n:
    diff = h_list[i]-h_list[j]
    ans = min(ans,diff)
    i += 1
    j += 1
print(ans)

Measured memory_bytes: 7488
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9+7;
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 


void solve() {
    ll n;
    cin >> n;
    
    ll sum = 0;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=n;j++) {
            for(int k=1;k<=n;k++) {
                ll x = gcd(j,k);
                sum+= gcd(i,x);
            }
        }
    }
    cout << sum <<endl;
    
}

signed main() {
    boost;
    solve();
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
 
 
struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;
 
//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
 
  using P = pair<Int, Int>;
  vector<P> vp;
  for(Int i=0;i<m;i++){
    Int b,c;
    cin>>b>>c;
    vp.emplace_back(c,b);
  }
  
  sort(a.begin(),a.end());
  sort(vp.begin(),vp.end());
  
  Int ans=0;
  for(Int i=0;i<n;i++){
    if(vp.empty()||vp.back().first<=a[i]){
      ans+=a[i];
      continue;
    }
    ans+=vp.back().first;
    vp.back().second--;
    if(vp.back().second==0) vp.pop_back();
  }  
  cout<<ans<<endl;
  return 0;
}

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

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();

	int n; cin >> n;
	int a; cin >> a;
	int cnt = 0;
	while (n) {
		cnt++;
		n /= a;
	}
	cout << cnt << "\n";

	return 0;
}

Measured memory_bytes: 256
K=int(input())
s=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(s[K-1])


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	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;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)



//小文字=大文字+32
int main() {
	int a, b;
	cin >> a >> b;
	int ans = 0;
	if (a > b) {
		ans += a;
		a--;
	}
	else {
		ans += b;
		b--;
	}
	if (a > b) {
		ans += a;
		a--;
	}
	else {
		ans += b;
	}
	cout << ans;
}
	



Measured memory_bytes: 3536
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define ALL(x) (x).begin(),(x).end()
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

int main() {
  int A, P; cin >> A >> P;
  // vector<int> A, D;
  // vector<pair<int, int> > V(M);
  // rep(i,N){
  //   int a; cin >> a;
  //   A.push_back(a);
  // }
  // sort(ALL(A));
  // rep(i,M){
  //   int b, c; cin >> b >> c;
  //   V[i] = {c,b};
  // }
  // sort(V.rbegin(), V.rend());

  cout << (A*3+P)/2 << endl;

  return 0;
}


Measured memory_bytes: 256
from sys import stdin, stdout

n, m = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
M = 10 ** 9 + 7

N = 10 ** 6 + 2
scount = [0 for i in range(N)]
ccount = [0 for i in range(N)]
ans = 1

for v in a:
    scount[v] += 1
    
    if scount[v] == 2:
        ans = 0

for v in b:
    ccount[v] += 1
    
    if ccount[v] == 2:
        ans = 0

column, string = 0, 0

for x in range(n * m, 0, -1):
    if scount[x] and ccount[x]:
        string += 1
        column += 1
        continue
    elif scount[x]:
        ans *= column
        string += 1
    elif ccount[x]:
        ans *= string
        column += 1
    else:
        ans *= string * column - (n * m - x)
    
    ans %= M

stdout.write(str(ans))

Measured memory_bytes: 117196
/*
[abc116] D - Various Sushi
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;

int N, K;
pli dt[MAX_N];
int cnt[MAX_N + 1];

ll solve() {
    sort(dt, dt + N, greater<pli>());

    ll s = 0, x = 0;
    for (int i = 0; i < K; i++) {
        s += dt[i].first;
        if (cnt[dt[i].second] == 0) {
            x++;
        }
        cnt[dt[i].second]++;
    }

    ll ans = s + x * x;
    int j = K - 1;
    for (int i = K; i < N; i++) {
        if (cnt[dt[i].second] > 0) {
            continue;
        }

        for (; j >= 0; j--) {
            if (cnt[dt[j].second] > 1) {
                break;
            }
        }
        if (j < 0) {
            break;
        }

        s += dt[i].first;
        s -= dt[j].first;
        cnt[dt[i].second]++;
        cnt[dt[j].second]--;
        j--;
        x++;

        ans = max(ans, s + x * x);
    }

    return ans;
}

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> dt[i].second >> dt[i].first;
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 2176
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() { cin.tie(nullptr); ios_base::sync_with_stdio(false); }
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

signed main()
{
  string s;
  cin >> s;
  if (s[0] == s[1] && s[1] == s[2] ||
      s[1] == s[2] && s[2] == s[3])
  {
    puts("Yes");
  }else {
    puts("No");
  }

  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
struct N{int p,l,r;};
N T[100000];
int n,d,k,c,x,r,i,j,m,o,D[100000];
void R(int r,int d){
  D[r]=d;
  if(T[r].r+1)R(T[r].r,d);
  if(T[r].l+1)R(T[r].l,d+1);
}
main(){
  scanf("%d",&n);
  for(;j<n;++j)T[j].p=T[j].l=T[j].r=-1;
  for(;i++<n;)
    for(scanf("%d%d",&d,&k),j=0;j<k;x=c){
      scanf("%d",&c);
      T[c].p=d;
      j++?T[x].r=c:T[d].l=c;
    }
  for(;m<n;++m)r=T[m].p+1?r:m;
  R(r,0);
  for(;o<n;++o){
    printf("node %d: parent = %d, depth = %d, ",o,T[o].p,D[o]);
    printf(T[o].p+1?T[o].l+1?"internal node, [":"leaf, [":"root, [");
    for(i=0,j=T[o].l;j+1;)printf(i++?", %d":"%d",j),j=T[j].r;
    printf("]\n");
  }
}

Measured memory_bytes: 7264
# D - Xor Sum 2
# https://atcoder.jp/contests/arc098/tasks/arc098_b

import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]

def main_lte(N, An):
    ans = N
    for l in range(N):
        for r in range(l+1, N):
            a = An[l]
            b = An[l]
            for i in range(l+1, r+1):
                a ^= An[i]
                b += An[i]
            if a == b:
                ans += 1
    print(ans)

def main_lte2(N, An):
    ans = N
    for l in range(N):
        a = An[l]
        b = An[l]
        for r in range(l+1, N):
            a ^= An[r]
            b += An[r]
            if a == b:
                ans += 1
            else:
                continue
    print(ans)

def main(N, An):
    ans = 0
    n = 0
    l = 0
    for r in range(N):
        n2 = An[r]
        if n & n2 == 0:
            n += n2
        else:
            while True:
                n -= An[l]
                l += 1
                if n & n2 == 0:
                    n += n2
                    break
        ans += r + 1 - l
    print(ans)

N = i2n()
An = i2nn()
main(N, An)


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

int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	ll l;

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

	}
	sort(ALL(a));
	double m = a[n - 1];
	ll ans = LINF;
	for(int i = 0; i < n - 1; i++) {
		if (abs(ceil(m / 2) - a[i]) < abs(ceil(m / 2) - ans) && m >= a[i]){
			ans = a[i];
		}
	}
	cout << ll(m) << " " << ans << endl;
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define VI vector<int>
#define VII vector<vector<int>>
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)

int dp[100100];

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

    fill(dp,dp+100100,N);
    dp[0] = 0;

    for(int i=1;i<=N;++i){
        dp[i] = min(dp[i],dp[i-1]+1);
        for(int pow6=6;pow6<=i;pow6*=6){
            dp[i] = min(dp[i],dp[i-pow6]+1);
        }
        for(int pow9=9;pow9<=i;pow9*=9){
            dp[i] = min(dp[i],dp[i-pow9]+1);
        }
    }

    cout<<dp[N]<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    if(n%10==9||n/10==9)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    
    
    return 0;   
}




 
 


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,a,b;
	scanf("%d",&n);
	if(n==1){
		printf("Hello World\n");
	}
	else{
		scanf("%d %d",&a,&b);
		printf("%d\n",a+b);
	}
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long k = sc.NextLong();
        long[] x = sc.LongArray();

        long answer = long.MaxValue;

        for (int i = 0; i <= n - k; i++)
        {
            long tmpAnswer = 0;
            if (x[i] * x[i + k - 1] >= 0)
            {
                tmpAnswer += Math.Max(Math.Abs(x[i + k - 1]), Math.Abs(x[i]));
            }
            else
            {
                tmpAnswer += x[i + k - 1] - x[i];
                tmpAnswer += Math.Min(Math.Abs(x[i + k - 1]), Math.Abs(x[i]));
            }
            answer = Math.Min(answer, tmpAnswer);
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 38316
input()
num_list = raw_input().split()
num_list = map(int, num_list)

def selection_sort(num_list, count): 
    for i in range(0, len(num_list)):
        minj = i 
        for j in range(i, len(num_list)):
            if num_list[j] < num_list[minj]:
                minj = j 
        if minj != i:
            temp = num_list[minj]
            num_list[minj] = num_list[i]
            num_list[i]= temp
            count += 1
        i += 1
    return count, num_list

count = 0 
count, num_list = selection_sort(num_list, count)
num_list = map(str, num_list)
print " ".join(num_list)
print count

Measured memory_bytes: 6356