akhauriyash/Code-Regression huggingface dataset:
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

void rsorta_u32(void *base, const int count, const int size){
	typedef uint32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][0]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][0]>>(0<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][0]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][0]>>(1<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][0]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][0]>>(2<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][0]>>(3<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][0]>>(3<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	free(b);
}

int a[100000][2];
int main(void){
	int n=nextint();
	for(int i=0; i<n; i++){
		a[i][0]=nextint();
		a[i][1]=i;
	}
	rsorta_u32(a, n, 2);
	long sum=0;
	int ans=0;
	for(int i=0; i<n; i++){
		if(a[i][0]<=sum*2){
			ans++;
		}else{
			ans=1;
		}
		sum+=a[i][0];
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 2912
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;


int main()
{
	int a,p;
	ll ans=0;
	cin>>a>>p;
	cout<<(a*3+p)/2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
//J题
int a[100001];
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	cout << a[n / 2] - a[(n / 2 )- 1];
}

Measured memory_bytes: 640
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    input! {
        n: i64,
        k: i64,
    }
    let mut head = 0;
    let mut foot = 1;
    for i in 1..n + 1 {
        if i >= k {
            break;
        }
        let d =
            ((k as f64) / (i as f64)).log2();
        let m = d.ceil() as u32;
        let rhead = head * n * 2_i64.pow(m);
        let lhead = 1 * foot;
        let tmp = foot * n * 2_i64.pow(m);
        head = (rhead + lhead) / gcd(rhead + lhead, tmp);
        foot = tmp / gcd(rhead + lhead, tmp);
    }
    if n >= k {
        let t = n - k + 1;
        let rhead = head * n;
        let lhead = t * foot;
        let tmp = foot * n;
        head = (rhead + lhead) / gcd(rhead + lhead, tmp);
        foot = tmp / gcd(rhead + lhead, tmp);
    }
    println!("{}", (head as f64)/(foot as f64));
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int __gcd(int a, int b)
{
	if (b == 0)
		return a;
	return __gcd(b, a % b);
}

int gcd(int a, int b, int c)
{
	return __gcd(c, __gcd(a, b));
}

void solve()
{
	int k;
	cin >> k;
	ll count = 0;
	for (int i = 1; i <= k; i++)
	{
		for (int j = 1; j <= k; j++)
		{
			for (int l = 1; l <= k; l++)
				count += gcd(i, j, l);
		}
	}
	cout << count << "\n";



}

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

Measured memory_bytes: 3636
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  vll V(3);
  cin >> V[0] >> V[1] >> V[2];
  sort(V.begin(), V.end());

  ll ans = 0;
  while (V[0] != V[1] || V[1] != V[2]) {
    if (V[0] == V[1]) {
      V[0]++;
      V[1]++;
      ans++;
    } else if (V[2] - V[1] > 1) {
      V[1] += 2;
      ans++;
    } else if (V[1] - V[0] > 1) {
      V[0] += 2;
      ans++;
    } else if (V[0] == V[1]) {
      V[0]++;
      V[1]++;
      ans++;
    } else if (V[0] == V[2]) {
      V[0]++;
      V[2]++;
      ans++;
    } else {
      V[1]++;
      V[2]++;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons;
const dx = [1,0,-1,0];
const dy = [0,1,0,-1];
void read(T...)(auto ref T args){ 
	auto line = readln().split(); 
	foreach(i,ref arg; args) arg = line[i].to!(typeof(arg));
}
int sum(int n){return n * (n + 1)/ 2;}
int tax(int per,int yen) {return yen * (100 +per) / 100;}
void main(){
	int x,y,s;
	while(read(x,y,s),x|y|s){
		int ans ;
		//auto taxed = new int [s];
		//foreach(int i,ref t;taxed)t = tax(x,i);
		auto taxed= iota(s).map!(i => tax(x,i)).array();
		foreach(i;1..s/2+1){
			foreach(j;i..s){
				if (taxed[i] + taxed[j] == s ){
					ans = max(ans,tax(y,i) + tax(y,j));break;
				}
			}
		}
		ans.writeln;
	}
}
//[(0,0),(0,1),..]
/*		iota(1,s)
.permutations.writeln;
.map!(a => Tuple!(a,iota(1,s)))
.filter!(a => tax (x,a[0]) + tax (x,a[1]) == s)
.map!(a => tax (y,a[0]) + tax(y,a[1]))
.reduce!(max);
*/

Measured memory_bytes: 2920
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

void implant(char sf[11][12], char buf[8][9]);
char judge(char sf[11][12]);

int main()
{
	char sf[11][12], buf[8][9];
	int i;

	while(1){

		if(scanf("%s", buf[0]) == EOF)
			break;

		for(i=1; i<8; i++)
			scanf("%s", buf[i]);

		implant(sf, buf);

		printf("%c\n", judge(sf));

	}
	return 0;
}

void implant(char sf[11][12], char buf[8][9])
{
	int i, j;

	for(i=0; i<11; i++){
		for(j=0; j<11; j++){
			sf[i][j] = '0';
		}
		sf[i][11] = 0;
	}
	for(i=0; i<8; i++){
		for(j=0; j<8; j++){
			sf[i][j+1] = buf[i][j];
		}
	}
	return;
}

char judge(char sf[11][12])
{
	int i, j;
	for(i=0; i<8; i++){
		for(j=1; j<9; j++){
			if(sf[i][j] == '1')
				break;
		}
		if(sf[i][j] == '1')
				break;
	}
	if(sf[i][j+1] == '1' && sf[i+1][j] == '1' && sf[i+1][j+1] == '1') return 'A';
	if(sf[i+1][j] == '1' && sf[i+2][j] == '1') return 'B';
	if(sf[i][j+1] == '1' && sf[i][j+2] == '1') return 'C';
	if(sf[i+1][j] == '1' && sf[i+1][j-1] == '1' && sf[i+2][j-1] == '1') return 'D';
	if(sf[i][j+1] == '1' && sf[i+1][j+1] == '1' && sf[i+1][j+2] == '1') return 'E';
	if(sf[i+1][j] == '1' && sf[i+1][j+1] == '1' && sf[i+2][j+1] == '1') return 'F';
	if(sf[i][j+1] == '1' && sf[i+1][j-1] == '1' && sf[i+1][j] == '1') return 'G';
}

Measured memory_bytes: 540
#include<stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i = 0; i < n; i++){
        scanf("%d",&a[i]);
    }
    int min = a[0], max = a[0];
    long int sum = a[0];
    for(int i = 1; i < n; i++){
        if(min > a[i]) min = a[i];
        if(max < a[i]) max = a[i];
        sum += a[i];
    }
    printf("%d %d %ld\n",min, max, sum);
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>
#include <queue>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	map<ll, ll> mp;
	rep(i, 0, n) {
		ll a;
		cin >> a;
		mp[a]++;
	}
	ll ans = 0;
	for (auto itr = mp.begin();itr != mp.end();itr++) {
		if (itr->second - itr->first == 0)continue;
		else if (itr->first > itr->second) ans += itr->second;
		else ans+= abs(itr->second - itr->first);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6272
#include <stdio.h>
int main(){
	int m,fand,year,n,ri,com;
	int max,tmp,in;
	double nen;
	scanf("%d",&m);
	while(m--){
		scanf("%d%d%d",&fand,&year,&n);
		max=0;
		while(n--){
			tmp=fand;
			in=0;
			scanf("%d%lf%d",&ri,&nen,&com);
			for(int i=0;i<year;i++){
				if(ri==1)	tmp+=(int)((double)tmp*nen);
				else		in+=(int)((double)tmp*nen);
				tmp-=com;
			}
			tmp+=in;
			//printf("tmp%d:%d\n",n,tmp);
			//printf("in%d:%d\n",n,in);
			if(max<tmp) max=tmp;
		}
		printf("%d\n",max);
	}
	return 0;
}

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

int main(){
    int L, R, d;
    cin >> L >> R >> d;
    int b = R-L+1;
    vector<int> a(b);
    int m = L;
    for(int i=0; i<b; i++){
        a.at(i) = L;
        L++;
    }
    L = m;
    int ans = 0;

    for(int i=0; i<b; i++){
        if(a.at(i) % d == 0) ans++;
    }

    cout << ans  << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template <class T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	for (const auto& e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& st) {
	for (const auto& e : st) os << e << " ";
	return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const map<T1, T2>& mp) {
	for (const auto& e : mp) os << e << " ";
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T&& h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head&& h, Tail&&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

string s, t;
Int lens, lent;
vector<vector<Int> > calcNext(const string& S) {
	//int n = (int)S.size();
	vector<vector<Int> > res(lens + 1, vector<Int>(26, lens));
	for (int i = lens - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	cin >> s >> t;

	lens = s.size();
	lent = t.size();

	//next[i][c]: = S の i 文字目以降で最初に文字 c が登場する index
	vector<vector<Int>> next = calcNext(s);

	//DMP(next);

	Int temp1 = 0;//丸何セットあるか
	Int temp2 = -1;//何番目か
	Int tempc;
	for (Int i = 0; i < lent; i++) {
		tempc = t[i] - 'a';

		if (next[0][tempc]==lens) {//t中の文字が存在しない場合
			cout << -1 << "\n";
			return 0;
		}

		////if (i != lent - 1) {
		//	if (temp2 == lens - 1) {
		//		temp1++;
		//		temp2 = -1;
		//	}
		////}

		temp2 = next[temp2 + 1][tempc];
		if (temp2==lens) {
			temp1++;
			temp2 = next[0][tempc];
		}
	}

	Int ans = temp1 * lens + temp2 + 1;
	cout << ans << "\n";

}


Measured memory_bytes: 24656
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n;
    cin >> n;
    cout << (n - 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
D, N = map(int, input().split())
cnt = 0
for n in range(1, 10**7):
    d = 0
    on = n
    while True:
        if n % 100 == 0:
            d += 1
            n /= 100
        else:
            break
    if d == D:
        cnt += 1
        if cnt == N:
            print(int(on))
            break


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    string a, b; cin >> a >> b;
    string s = a + b;
    int x = stoi(s);
    if ((int)ceil(sqrt(x)) == (int)sqrt(x)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  long long int n,k;
  long long int ans=0;
  cin>>n>>k;
  for(long long int u=k;u<n+2;++u){
    long long int min=0,max=0;
    min=(u-1)*u/2;
    max=(2*n-u+1)*u/2;
    ans=(ans+max-min+1)%1000000007;
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

/*
// 1-indexed
// [0, k]の和を求める
*/
template<class T>
struct BinaryIndexedTree
{
    vector<T> dat;

    BinaryIndexedTree(int sz){
        dat.assign(sz+1, 0);
    }

    T sum(int k){
        T res = 0;
        for(k++; k > 0; k -= k & -k) res += dat[k];
        return res;
    }

    void add(int k, T x){
        for(k++; k < dat.size(); k += k & -k) dat[k] += x;
    }
};

int main(){
    int q;
    cin >> q;
    vector<LL> p(q), a, b;
    rep(i, q){
        cin >> p[i];
        if(p[i] == 1){
            LL x, y;
            cin >> x >> y;
            a.push_back(x);
            b.push_back(y);
        }
    }
    rep1(i, b.size()) b[i] += b[i-1];

    vector<LL> unzip = a;
    map<LL, LL> zip;
    sort(all(unzip));
    unzip.erase(unique(all(unzip)), unzip.end());
    rep(i, unzip.size()) zip[unzip[i]] = i;

    int n = unzip.size();
    BinaryIndexedTree<LL> num(n+1), BIT(n+1);
    int now = 0;
    rep(i, q){
        if(p[i] == 1){
            num.add(zip[a[now]] + 1, 1);
            BIT.add(zip[a[now]] + 1, a[now]);
            now++;
        }else{
            int ng = 0, ok = n;
            while(abs(ok-ng) > 1){
                int mid = (ok+ng)/2;
                int sm = num.sum(mid);
                if(sm >= (now+1)/2) ok = mid;
                else ng = mid;
            }
            int med = ok;
            LL A = unzip[med-1];
            LL B1 = BIT.sum(n)-BIT.sum(med) - A*(now-num.sum(med));
            LL B2 = A*num.sum(med-1) - BIT.sum(med-1);
            cout << A << " " << B1+B2+b[now-1] << endl;
        }
    }
}

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

int a[55];
LL dp[55][55][2505];

int main(){
	int n,m,ans = 0;
	cin >> n >> m;
	for(int i = 1;i <= n;i++) cin >> a[i],ans += a[i];
	dp[0][0][0] = 1;
	for(int i = 1;i <= n;i++){
		for(int j = 0;j <= i;j++){
			for(int k = 0;k <= ans;k++){
				if(k >= a[i] && j >= 1) 
					dp[i][j][k] += dp[i - 1][j - 1][k - a[i]]; 
				dp[i][j][k] += dp[i - 1][j][k];
			}
		}
	}
	LL sum = 0;
	for(int i = 1;i <= n;i++){
		for(int j = 0;j <= 2500;j++){
			if(j / i == m && j % i == 0){
				sum += dp[n][i][j];
			}
		}
	}
	cout << sum << endl;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    for(int i=a; i<a*b; i+=a) {
        if(i%b==c) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
	int n, a, b;
	cin >> n >> a >> b;

	if (a > b) {
		cout << b << " ";
		if (a + b > n) {
			cout << a + b - n;
		}
		else {
			cout << 0;
		}
	}
	else {
		cout << a << " ";
		if (a + b > n) {
			cout << a + b - n;
		}
		else {
			cout << 0;
		}
	}
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a[3000],b[3000],j,tmp;
    int i=0;
    for(i=0;i<3000;i++){  
        scanf("%d %d",&a[i],&b[i]);
        if(a[i]==0&&b[i]==0){
            break;
        }
    }
    for(j=0;j<i;j++){
        if(a[j]>b[j]){
            tmp=b[j];
            b[j]=a[j];
            a[j]=tmp;
        }
        printf("%d %d\n",a[j],b[j]);
    }
    return 0;
    
}


Measured memory_bytes: 2016
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define fe(vec,lambda) std::for_each(vec.begin(), vec.end(), lambda );
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#define printv(val) std::for_each(val.begin(),val.end(),[](auto x){cout<<x<<"\n";});
#define lim 1000000007ll
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T chmin(T& a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T& b,T a){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template <class T> T gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T lcm(T a, T b){return a * b / gcd(a, b);}
inline bool operator<(const pii &lhs,const pii &rhs){return(lhs.second<rhs.second);}
template<class T> vector<pair<T,T>> duplicator(const vector<T>& input){vector<pair<T,T>> out(input.size()-1);rep(i,input.size()-1){out[i].first =input[i  ];out[i].second=input[i+1];}return(out);}
vector<char> String_to_vector_char(const string& input){vector<char> out(input.size());rep(i,input.size()){out[i]=input[i];}return out;}
void YesNo(bool flag){ cout<<(flag? "Yes":"No");}
void YESNO(bool flag){ cout<<(flag? "YES":"NO");}

ll a,b,c,d,n,x;
vector<ll>v[3];
map<ll,ll>m;
string s[3],s2;
void input(){
    cin>>x>>a>>b;
}
void src(){
    if(b<=a){cout<<"delicious";}
    else if(b<=a+x){cout<<"safe";}
    else{cout<<"dangerous";}
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
strlist = list(input())
q = int(input())
for n in range(q):
    coms = input().split()
    if coms[0] == 'print':
        print(''.join(strlist[int(coms[1]):int(coms[2])+1]))
    elif coms[0] == 'reverse':
        #print(strlist)
        #print(strlist[int(coms[1]):int(coms[2])+1])
        new = list(reversed(strlist[int(coms[1]):int(coms[2])+1]))
        #print(new)
        strlist[int(coms[1]):int(coms[2])+1] = new
        #print(strlist)
    elif coms[0] == 'replace':
        strlist[int(coms[1]):int(coms[2])+1] = list(coms[3])[0:]
        #print(strlist)


Measured memory_bytes: 5628
from math import ceil
D,G = map(int,input().split())
para = [[i for i in map(int,input().split())] for j in range(D)]
result = []
for i in  range(2**D):
    ans = 0
    cnt = 0
    num = format(i,"b").zfill(D)
    for j in range(D,0,-1):

        if num[j-1] == "1" :
            ans += para[j-1][0] *100*j + para[j-1][1]
            cnt += para[j-1][0]
            
        else : pass

    if ans >= G :
        result.append(cnt)
    else :
        for j in range(D,0,-1):
            if num[j-1] == "1" : pass
            else : 
                if G <= ans + (para[j-1][0]-1)*100*(j):
                    cnt += ceil((G-ans)/(100*(j)))
                    result.append(cnt) 
                
print(min(result))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> plli;
typedef vector< vi > vvi ;
typedef vector< vlli > vvlli  ;
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define flli(i,a,b) for(long long int i=a;i<=b;i++)
#define bi(i,a,b) for(int i=a;i>=b;i--)
#define blli(i,a,b) for(long long int i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pi 2*acos(0.0)
#define pb push_back
#define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
#define present(v,num) (v.find(num)!=v.end())
#define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
#define pq priority_queue
#define mp make_pair
const int inf=INT_MAX;
const lli INF =LLONG_MAX;
const lli mod = 1e9+7;
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast;
    lli n;cin>>n;
    vlli a(n);
    flli(i,0,n-1)cin>>a[i];
    lli index=0;
    lli ans=0;
    while(index<n)
    {
    	lli temp=a[index];
    	lli count=0;
    	lli tot=0;
    	while(index<n && a[index]<=temp)
    	{
    		tot+=a[index];
    		count++;
    		index++;
    	}
    	ans+=(count*temp-tot);
    }
    cout<<ans;
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//infinity
#define INTINF 2000000000
#define LONGINF 2000000000

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



long long abso(long long a, long long b, long long n){
}

int main(){
	int n;
	cin >> n;
	vector<long long> v;
	REP(i, n){
		long long t;
		cin >> t;
		v.push_back(t - ( i + 1 ));
	}

	sort(v.begin(), v.end());
	int target = n / 2;
	long long middle = 0;
	int i = 0;
	for(long long t : v){
		if(i == target){
			middle = t;
			break;
		}
		i++;
	}
	long long m = 0;
	for(long long t : v){
		long long a = (middle > t) ? middle - t : t - middle;
		m += a;
	}
	cout << m << endl;
	return 0;
}


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

// Description: ????????????
// Verifyed: various problem 
using namespace placeholders;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const R INF = 1E40L;
const R PI = acos(-1.0L);
using P=complex<R>;
using L=struct{P s,t;};
using VP=vector<P>;
using C=struct{P c;R r;};

auto& operator >> (istream& is,P& p){ R x,y; is >> x >> y,p=P(x,y); return is;}
auto& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

inline R dot(P o,P a,P b){return real(conj(a-o)*(b-o));}
inline R det(P o,P a,P b){return imag(conj(a-o)*(b-o));}
inline P vec(L l){return l.t-l.s;}
auto sdot = bind(sgn,bind(dot,_1,_2,_3));
auto sdet = bind(sgn,bind(det,_1,_2,_3));

//projection verify AOJ CGL_1_A
P proj(L l,P p){ R u=real((p-l.s)/vec(l)); return (1-u)*l.s+u*l.t;}

// vertical parallel
// verified: AOJ CGL_2_A
bool vertical(L a,L b) {return sdot(0,vec(a),vec(b))==0;}
bool parallel(L a,L b) {return sdet(0,vec(a),vec(b))==0;}
bool eql(L a,L b){ return parallel(a,b) and sdet(a.s,a.t,b.s)==0;}

// crossing determination
// verified: AOJ CGL_2_B 
bool iss(L a,L b){
	int sa=sdet(a.s,a.t,b.s)*sdet(a.s,a.t,b.t);
	int sb=sdet(b.s,b.t,a.s)*sdet(b.s,b.t,a.t);
	return max(sa,sb)<0;
}

// crossing point 
// verified: AOJ CGL_2_C
P cross(L a,L b){
	R u=det(a.s,b.s,b.t)/det(0,vec(a),vec(b));
	return (1-u)*a.s+u*a.t;
}
	
// distance 
// verified: AOJ CGL_2_D
R dsp(L l,P p){
	P h=proj(l,p);
	if(sdot(l.s,l.t,p)<=0) h=l.s;
	if(sdot(l.t,l.s,p)<=0) h=l.t;
	return abs(p-h);
}

R dss(L a,L b){return iss(a,b)?0:min({dsp(a,b.s),dsp(a,b.t),dsp(b,a.s),dsp(b,a.t)});}

int main(void){
	int n;
	cin >> n;
	rep(i,n){
		P a,b,c,d;
		cin >> a >> b >> c >> d;
		L s1={a,b},s2={c,d};
		cout << (sgn(dss(s1,s2))==0) << endl;
	}
	return 0;
}

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

int main() {
  int x, a, b;
  cin >> x;
  for (int i = -200; i <= 200; i++) {
    for (int j = -200; j < 200; j++) {
      int val = pow(i,5.0) - pow(j,5.0);
      if (val == x) {
        a = i;
        b = j;
        break;
      }
    }
  }
  cout << a << " " << b << endl;
  return 0;
}


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

int main() {
	// your code goes here
	long long n, r;
	std::vector<long long> arr1(60);
	std::vector<long long> arr2(60);
	while (1) {
		cin >> n >> r;
		if (n == 0 && r == 0) break;
		for (auto i = 0; i < 60; i++) arr1[i]=i;
		for (auto i = 0; i < r; i++) {
			long long p, c;
			cin >> p >> c;
			// cout << "input " << p << " " << c << endl;
			
			for (auto j = 0; j < c; j++) {
				long long copy_idx = n-p-c+j+2;
				// cout << "copy " << arr1[copy_idx] << endl;
				arr2[n-c+j+1] = arr1[copy_idx];
			}
			for (auto j = 0; j < p-1; j++) {
				arr1[n-p-c+j+2] = arr1[n-p+j+2];
			}
			for (auto j = 0; j < c; j++) {
				arr1[n-c+j+1] = arr2[n-c+j+1];
			}
		}
		cout << arr1[n] << endl;
	}
	return 0;
}


Measured memory_bytes: 2964
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    vector<ll> arr={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};
    ll k;
    cin>>k;
    k-=1;
    cout<<arr[k]<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector <string> s(n);
    unordered_map<string, long long> um(n);
    for(int i=0;i<n;++i) cin >> s[i];
    long long res=0;
    for(int i=0;i<n;++i) {
        sort(s[i].begin(),s[i].end());
        um[s[i]]+=1;
        res+=um[s[i]]-1;
    }
    cout << res << endl;
}

Measured memory_bytes: 17536
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

// DAME: 
/*
    f(N) を 10 進法で表記したときに末尾に続く 0 の個数は、f(N) が 2 で割り切れる回数と f(N) が
    5 で割り切れる回数の min です。
*/
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false); 
    ll n;
    cin >> n;
    if(n<2 or n%2){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    n /= 2;
    while(n>0){
        n/=5;
        ans += n;
    }
    cout << ans << endl;
     
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,mod,dp[6060][9090],inv[6060],ans;
int main()
{
	scanf("%d %d",&n,&mod);
	inv[1]=1;
	for(int i=2;i<=3*n;++i)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	dp[0][3000]=1;
	for(int i=0;i<3*n;++i)
		for(int j=-(i/2)+3000;j<=i+3000;++j)
		{
			dp[i+1][j+1]=(dp[i+1][j+1]+1ll*inv[i+1]*dp[i][j])%mod;
			if(i+2<=3*n)dp[i+2][j-1]=(dp[i+2][j-1]+1ll*inv[i+2]*dp[i][j])%mod;
			if(i+3<=3*n)dp[i+3][j]=(dp[i+3][j]+1ll*inv[i+3]*dp[i][j])%mod;
		}
	for(int i=0;i<=3*n;++i)(ans+=dp[3*n][i+3000])>=mod?ans-=mod:0;
	for(int i=2;i<=3*n;++i)ans=1ll*ans*i%mod;
	printf("%d",ans);
	return 0;
}


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


int main(void){
  int n,k,i,p[200005];
  
  cin >> n >> k;
  for (i=0;i<n;i++) cin >> p[i];
  
  ll s=0,smax;
  for (i=0;i<k;i++) s+=p[i];
  
  smax=s;
  for (i=1;i+k-1<n;i++){
    s+=p[i+k-1]-p[i-1];
    smax=max(smax,s);
  }
  
  cout << (smax+k)/2 << '.';
  if ((smax+k)%2==0) cout << "00000000000" << endl;
  else cout << "50000000000" << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    int n;
  cin>>n;
    int ans = 100;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        int cnt = 0;
        while (a % 2 == 0)
        {
            a /= 2;
            cnt++;
        }
        ans = min(cnt, ans);
    }
    cout << ans << endl;
}

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

ll hp[100005];
int n;
ll a, b;

int check(ll t){
  ll sum = 0;
  for(int i = 0; i < n; i++){
    if(hp[i] - (b * t) <= 0) continue;
    sum += (hp[i] - (b * t)) / (a - b);
    if((hp[i] - (b * t)) % (a - b) != 0) sum++; 
  }
  return sum <= t;
}

int main(){
  cin >> n >> a >> b;
  for(int i = 0; i < n; i++) cin >> hp[i];
  sort(hp, hp + n);
  ll left = 0, right = hp[n-1];
  while(right - left > 1){
    ll mid = (left + right) / 2;
    if(check(mid)) right = mid;
    else left = mid;
  }
  cout << right << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
#define LONG LLONG_MAX/3;
#define INT INT_MAX/3;
#define mod 1000000007
#define S second
#define F first
#define int long long
using namespace std;
int a[100010];
map<int,int> m;
map<int,int> mp;
P x[100000],y[100000];
signed main(){
	int n;
	cin>>n;
	f(i,n){
		cin>>a[i];
	}
	for(int i=0;i<n;i+=2){
		m[a[i]]++;
	}
	for(int i=1;i<n;i+=2){
		mp[a[i]]++;
	}
	int i=0;
	for(pair<int,int> p: m){
		x[i].F=p.S;
		x[i].S=p.F;
		i++;
	}
	int j=0;
	for(P p:mp){
		y[j].F=p.S;
		y[j].S=p.F;
		j++;
	}
	sort(x,x+i);
	sort(y,y+j);
	if(x[i-1].S==y[j-1].S){
		if(j>=2&&i>=2) cout<<n-max(x[i-1].F+y[j-2].F,x[i-2].F+y[j-1].F)<<endl;
		else if(i>=2) cout<<n-x[i-2].F-y[j-1].F<<endl;
		else if(j>=2) cout<<n-x[i-1].F-y[j-2].F<<endl;
		else cout<<n/2<<endl;
	}
	else cout<<n-x[i-1].F-y[j-1].F<<endl;
	return 0;
}


Measured memory_bytes: 8832
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;


int main()
{
	int N;
	cin >> N;
	int cnt = 0;
	bool ans = false;
	for (int i = 0; i < N; i++) {
		int d1, d2;
		cin >> d1 >> d2;
		if (d1 == d2) cnt++;
		else cnt = 0;
		if (cnt == 3) ans = true;
	}
	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main() {

    string s; cin >> s;
    ll ans = 0,ans2 = 0;
    char mem = s[0];

    for(int i = 1; i < s.length(); i ++){
        if(mem != s[i]){
            ans ++;
            mem = s[i];
        }
    }
    mem = s[s.length()-1];

    for(int i = s.length()-2; i >= 0; i --){
        if(mem != s[i]){
            ans2 ++;
            mem = s[i];
        }
    }

    cout << min(ans,ans2);
    return 0;
}


Measured memory_bytes: 3736
import sys
from functools import reduce
import copy
import math


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    B = string_to_int(inputs[0])
    A = []

    candidate = -1
    for i, b in enumerate(B):
        if i == 0:
            A.append(b)
        else:
            if b > candidate:
                A.append(candidate)
            else:
                A.append(b)
        candidate = b
    A.append(b)
    return sum(A)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3572
#include <iostream>
#include <cstring>
#include <stack>
#include <algorithm>
using namespace std;

int N,A[100005],L[100005];

int main()
{
    L[0]=0;
    cin>>N;
    int i,j;
    for(i=1;i<=N;i++){
        cin>>A[i];
    }
    int len=1;
    L[0]=A[1];
    for(i=1;i<=N;i++){
        if(L[len-1]<A[i])L[len++]=A[i];
        else *lower_bound(L,L+len,A[i])=A[i];
    }
    cout<<len<<endl;
    return 0;
}

Measured memory_bytes: 3780
#include<iostream>
using namespace std;
int main(){
  int a,b;
  int c,d;
  cin>>a>>b>>c>>d;
  
  int k=a*b;
  //kはマスの総数
  k=k-b*c;
  //これで行の分が引かれた。
  k=k-a*d;
  //これで重複している分を含む列の分が引かれた。
  k=k+c*d;
  cout<<k;
  return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

ll mod(ll a) {
	if (a > 0) return a % MOD;
	if (a % MOD == 0) return 0;
	ll x = -a / MOD + 1;
	a += x * MOD;
	return a % MOD;
}

template <typename T> void dump(T x) { cout << x << endl; }
void dumpf(double x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
// int dx[4]    = {1, 0, -1, 0};
// int dy[4]    = {0, 1, 0, -1};
// ll pas[5001][5002];

int main() {
	IOS();
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) { cin >> a[i]; }
	ll tmp = 0;
	ll ans = 0;
	for (ll i = 62; i >= 0; --i) {
		ll t = 1ll << i;
		// dump(t);
		ll cnt1 = 0, cnt0 = 0;
		for (int j = 0; j < n; ++j) {
			// dump((a[j] & t) == t);
			if ((a[j] & t) == t)
				cnt1++;
			else
				cnt0++;
		}
		// dump(cnt1);
		if (tmp + t > k || cnt1 >= cnt0) {
			ans += cnt1 * t;
		} else {
			ans += cnt0 * t;
			tmp += t;
		}
		// dump(ans);
	}
	dump(ans);
}

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


int main()
{
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());

    int n = 0;
    int tmp = (a[2] - a[0]) / 2;
    a[0] += tmp * 2;
    n += tmp;

    tmp = (a[2] - a[1]) / 2;
    a[1] += tmp * 2;
    n += tmp;

    if (a[2]-a[1] && a[2]-a[0])
        cout << n + 1 << "\n";
    else if (!(a[2]-a[1]) && !(a[2]-a[0]))
        cout << n << "\n";
    else
        cout << n + 2 << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll N = 1e9+7;


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

	ll t = 1;
	// cin>>t;

	while(t--){
		ll n;
		cin>>n;
		if(!n) continue;
		string s, r;
		cin>>s;
		r =s;
		sort(r.begin(),r.end());
		ll cnt =0;
		for(ll i=0;i<n;++i){ if(s[i] != r[i]) ++cnt; }

		if(cnt&1) cnt = (cnt /= 2) + 1 ;
		else cnt /= 2;
		cout<<cnt<<"\n";
	}

	return 0;

}


Measured memory_bytes: 3852
n =int(input())
a = list(map(str,input().split()))
lss = []
lse = []
if n%2==0:
    for i in range(n//2):
        lss.append(a[2*i])
    for i in range(n//2):
        lse.append(a[n-(2*i+1)])

else:
    for i in range(n//2):
        lss.append(a[2*i+1])
    for i in range(n//2+1):
        lse.append(a[n-2*i-1])


ls = lse+lss

print(" ".join(ls))

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

namespace ConsoleTest
{
    static partial class Program
    {
        static void Main(string[] args)
        {
            var v = Ints();
            Console.WriteLine(string.Format("{0} {1} {2}", v[2], v[0], v[1]));
        }
    }
    static partial class Program
    {
        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }
        public static int[] Ints()
        {
            return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        }
        public static int[][] MultiInts(int num)
        {
            var result = new int[num][];
            for(int i = 0; i < num; ++i)
            {
                result[i] = Ints();
            }
            return result;
        }
        public static T[] MultiItems<T>(int num, Func<string,T> parser)
        {
            var result = new T[num];
            for(int i =0; i < num; ++i)
            {
                result[i] = parser(Console.ReadLine());
            }
            return result;
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

const int INF = 1001001001;

int main(){
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i, h) cin >> s.at(i);
  int ans = INF;
  rep(bit, 1 << (h-1)){
    int add = __builtin_popcount(bit);
    vector<int> v(add+1, 0);
    rep(j, w){
      int index = 0;
      bool f = false;
      rep(i, h){
        v.at(index) += (s.at(i).at(j) == '1');
        if(v.at(index) > k) f = true;
        if((bit & (1 << i)) != 0) index++;
      }
      if(f == true){
        add++;
        index = 0;
        rep(i, v.size()){
          v.at(i) = 0;
        }
        rep(i, h){
          v.at(index) += (s.at(i).at(j) == '1');
          if((bit & (1 << i)) != 0) index++;
        }
        bool ex = false;
        rep(i, v.size()){
          if(v.at(i) > k) ex = true;
        }
        if(ex == true){
          add = INF;
          break;
        }
      }
    }
    ans = min(add, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3652
n, m = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())

memo = {}
def dfs(p, q, s, t, turn, pss):
    if (p, q, s, t, turn, pss) in memo:
        return memo[p, q, s, t, turn, pss]
    if p == len(A) and q == len(B):
        return s-t

    res = 0
    if turn:
        # first
        if pss < 2:
            if s+t:
                res = (s - t) + dfs(p, q, 0, 0, 0, 0)
            else:
                res = dfs(p, q, 0, 0, 0, pss+1)
        else:
            return 0
        if p < len(A):
            if A[p] == -1:
                res = max(res, dfs(p+1, q, s, 0, 0, 0))
            else:
                res = max(res, dfs(p+1, q, s+A[p], t, 0, 0))
    else:
        # second
        if pss < 2:
            if s+t:
                res = (s - t) + dfs(p, q, 0, 0, 1, 0)
            else:
                res = dfs(p, q, 0, 0, 1, pss+1)
        else:
            return 0
        if q < len(B):
            if B[q] == -1:
                res = min(res, dfs(p, q+1, 0, t, 1, 0))
            else:
                res = min(res, dfs(p, q+1, s, t+B[q], 1, 0))
    memo[p, q, s, t, turn, pss] = res
    return res
print(dfs(0, 0, 0, 0, 1, 0))

Measured memory_bytes: 52776
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <sstream>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
int n, m;
vector<int> s, c;

bool check(string str) {
    if ((int)str.size() != n) return false;
    rep(i, m) {
        if (str[s[i]] != (char)(c[i] + '0')) return false;
    }
    return true;
}
string solve() {
    for (int i = 0; i <= 999; i++) {
        stringstream iss;
        iss << i;
        string str = iss.str();
        if (check(str)) return str;
    }
    return "-1";
}
int main() {
   cin >> n >> m;
   s.resize(m), c.resize(m);

   rep(i, m) cin >> s[i] >> c[i], --s[i];
   cout << solve() << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	vector<ll > p(N);
	REP(i, N) cin >> p[i];

	vector<ll> a(N), b(N);
	REP(i, N){
		a[i] = 20001*i+1;
		b[i] = 20001*(N-1-i)+1;
	}
	REP(i, N){
		b[p[i]-1] += i;
	}
	REP(i, N){
		cout << a[i] << " ";
	}
	cout << endl;
	REP(i, N){
		cout << b[i] << " ";
	}
	cout << endl;
    return 0;
}

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

using namespace std;

int main(){

    string txt;
    
    cin >> txt;

    if(txt.size() >= 4 && txt[0] == 'Y' && txt[1] == 'A' && txt[2] == 'K' && txt[3] == 'I'){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void ABC079D();

#if 1
int main()
{
	ABC079D();
	fflush(stdout);
	return 0;
}
#endif

static void ABC079D()
{
	int H, W;
	getint(H, W);

	std::vector<std::vector<int>> power(10, std::vector<int>(10, 0));
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			getint(power[i][j]);
		}
	}

	std::vector<std::vector<int>> wall(H, std::vector<int>(W));
	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			getint(wall[h][w]);
		}
	}

	std::vector<std::vector<int>> minPower(10, std::vector<int>(10, 2000));
	for (int i = 0; i < 10; i++) {
		minPower[i][i] = 0;
	}

	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				power[i][j] = std::min(power[i][j], power[i][k] + power[k][j]);
			}
		}
	}

	int ans = 0;
	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			if (wall[h][w] != -1) {
				ans += power[wall[h][w]][1];
			}
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
	int r, g, b;
	cin >> r >> g >> b;
	int sum = 0;
	sum = r * 100 + g * 10 + b;
	string s;
	sum % 4 == 0 ? s = "YES" : s = "NO";
	cout << s << endl; 
	return 0;
}

Measured memory_bytes: 256