akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 1e5 + 5;

ll A[N];

int main(){
    fIO

    int n, m;
    cin >> n >> m;

    ll lcm = 1LL;
    for(int i = 0; i < n; i++) {
        cin >> A[i];
        A[i] /= 2;
        lcm = (lcm * A[i]) / __gcd(lcm, A[i]);
    }

    for(int i = 0; i < n; i++) {
        if((lcm / A[i]) & 1) continue;
        return cout << 0, 0;
    }


    if(lcm > m) cout << 0;
    else cout << ((m / lcm) + 1) / 2;

//    sort(A, A + n);
//
//    ll val = A[0] / 2;
//    ll currP = 1;
//    int ans = 0;
//    while(val <= m) {
//        //cout << val << "\n";
//        int f = 1;
//        for(int i = 1; i < n; i++) {
//            //val = ai * (p + 0.5)
//            //val = ai p + ai / 2
//            // (val - ai / 2) / ai = p
//            ll curr = (val - A[i] / 2);
//            if(curr % A[i] != 0 || curr < 0) {
//                f = 0;
//                break;
//            }
//        }
//        if(f) ans++;
//        val = A[0] * currP + A[0] / 2LL;
//        currP++;
//    }
}













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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
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 */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) (x).erase(unique(all(x)), (x).end())
#define int long long

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;

/* main */
signed main(void)
{
    string s;
    cin >> s;
    auto a = s.find('A');
    auto z = s.rfind('Z');
    cout << (z - a) + 1 << endl;
    return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;

int main() {
	int N, L;
	cin >> N >> L;
	vector<string> list(N);
	rep(i, N) cin >> list.at(i);

	sort(all(list));

	string ans = "";
	for(string s : list) {
		ans += s;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
N = INT()
A = LIST()
C = [[0] * W for i in range(H)]
num = 0
for h in range(H):
    if h % 2 == 0:
        for w in range(W):
            if A[num] > 0:
                A[num] -= 1
            else:
                num += 1
                A[num] -= 1
            C[h][w] = num + 1
    else:
        for w in range(W-1, -1, -1):
            if A[num] > 0:
                # C[h][w] = num + 1
                A[num] -= 1
            else:
                num += 1
                A[num] -= 1
            C[h][w] = num + 1

for c in C:
    print(*c, end="\n")    


Measured memory_bytes: 5964
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    long long a,b,c,d,e;
    cin>>a>>b>>c;
    d=(c-a-b)*(c-a-b);
    e=4*a*b;
    if(c>a+b&&d>e)cout<<"Yes";
    else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<ll, ll> pii;
typedef vector<vector<ll>> mat;
const ll mod = 2019;
const int MAXN = 1005;

int main() {
	
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	cout << ((s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) ? "Yes":"No") << endl;
	
}



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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");

int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}

vi vis(100001,0);
vi adj[100001];

int main()
{	
    std::ios::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    int n,k,cnt=0;cin>>n>>k;
    string s;cin>>s;
    if(n==1)
    	cout<<0<<"\n";
    else
    {
    	for(int i=0; i<n; ++i)
    	{
    		if(s[i]=='R' && s[i+1]=='R')
    			++cnt;
    		else if(s[i]=='L'  && s[i-1]=='L')
    			++cnt;
    	}
    	//cout<<cnt<<"\n";
    	cout<<min(n-1,cnt+2*k)<<"\n";
    }

}

Measured memory_bytes: 3280
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<map<int, int>> v(m);
    while (true) {
        int s, t, e;
        cin >> s >> t >> e;
        if (s == 0)break;
        v[t - 1][s - 1] += e;
    }

    int l;
    cin >> l;
    for (int i = 0; i < l; i++) {
        vector<int> ret(n);
        for (int j = 0; j < m; j++) {
            int b;
            cin >> b;

            for (auto x:v[j])ret[x.first] += b * x.second;
        }

        for (int j = 0; j < n; j++) {
            if (j > 0)cout << " ";
            cout << ret[j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 5788
import sys
sys.setrecursionlimit(10**6)
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
color = [-1] * N
def dfs(v, c):
    if color[v] != -1:
        return color[v] == c
    else:
        color[v] = c
        ret = True
        for w in edge[v]:
            ret &= dfs(w, c ^ 1)
        return ret

if dfs(0, 0) == False:
    print(N * (N - 1) // 2 - M)
else:
    c1 = color.count(0)
    c2 = color.count(1)
    assert(c1 + c2 == N)
    print(c1 * c2 - M)


Measured memory_bytes: 43844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	int N, V[100001];
	cin >> N;
	rep(i, N) cin >> V[i];

	int od[100001] = {};
	int ev[100001] = {};
	rep(i, N) {
		if (i % 2) od[V[i]]++;
		else ev[V[i]]++;
	}
	pair<int, int> odp[100001];
	pair<int, int> evp[100001];

	rep(i, 100001) {
		odp[i] = make_pair(i, od[i]);
		evp[i] = make_pair(i, ev[i]);
	}
	sort(odp, odp + 100001, [](pair<int, int> A, pair<int, int>B) {return A.second < B.second; });
	sort(evp, evp + 100001, [](pair<int, int> A, pair<int, int>B) {return A.second < B.second; });

	if (odp[100000].first != evp[100000].first) {
		co(N - odp[100000].second - evp[100000].second);
	}
	else {
		int dotti = min(N - odp[99999].second - evp[100000].second, N - evp[99999].second - odp[100000].second);
		co(dotti);
	}

	Would you please return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define INF 0x3f3f3f3f
#define pii pair<int, int>
#define ls (idx << 1)
#define rs (idx << 1 | 1)
#define mem(x, a) memset(x, a, sizeof(x))
#define AC ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;

const int maxn = 2e5 + 50;
int seg[maxn*4], a[maxn], h[maxn];

void modify(int pos, int val, int l, int r, int idx){
	if(l == r){
		seg[idx] = val;
		return;
	}
	int mid = (l + r) >> 1;
	if(pos <= mid) modify(pos, val, l, mid, ls);
	else modify(pos, val, mid + 1, r, rs);
	seg[idx] = max(seg[ls], seg[rs]);
}

int query(int A, int B, int l, int r, int idx){
	if(A <= l && B >= r) return seg[idx];
	int mid = (l + r) >> 1;
	int ans = 0;
	if(A <= mid) ans = max(ans, query(A, B, l, mid, ls));
	if(B > mid) ans = max(ans, query(A, B, mid + 1, r, rs));
	return ans;
}

main(){
	AC;
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++) cin >> h[i];
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= n; i ++){
		modify(h[i], query(1, h[i], 1, n, 1) + a[i], 1, n, 1);
	}
	cout << query(1, n, 1, n, 1) << "\n";
}

Measured memory_bytes: 10860
#include<bits/stdc++.h>
using namespace std;
int a[4][111],la[4],w0,W;
#define int64 long long int
int main(){
	int n;
	scanf("%d%d",&n,&W);
	for(int i=0; i<n; i++){
		int w,v;
		scanf("%d%d",&w,&v);
		if(i==0)w0 = w;
		w -= w0;
		a[w][++la[w]] = v;
	}
	for(int i=0; i<4; i++){
		sort(a[i]+1,a[i]+la[i]+1,greater<int>());
		for(int j=1; j<=la[i]; j++)
			a[i][j] += a[i][j-1];
	}
	int res=0;
	for(int i0=0; i0<=la[0]; i0++)
	for(int i1=0; i1<=la[1]; i1++)
	for(int i2=0; i2<=la[2]; i2++)
	for(int i3=0; i3<=la[3]; i3++)
	if(((int64)(i0+i1+i2+i3))*w0+i1+i2*2+i3*3<=W)
		res = max(res, a[0][i0]+a[1][i1]+a[2][i2]+a[3][i3]);
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {

	static int N;
	static int Q;
	static char[] d;
	static char[] t;
	static String s;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		Q = sc.nextInt();
		s = sc.next();
		t = new char[Q];
		d = new char[Q];
		for (int i=0;i<Q;i++) {
			t[i]=sc.next().charAt(0);
			d[i]=sc.next().charAt(0);
		}
		int left_edge=0;
		int right_edge=N-1;

		int left = 0;
		int right = N-1;
		do {
			if (test(N-1)=='A') {
				right_edge=N;
				break;
			}
			int center = (left + right) / 2;
			if (center==0) {
				if (test(center)=='R') {
					right_edge=center+1;
					break;
				} else if (test(center)=='A' || test(center)=='L'){
					left = center + 1;
				} else {
					right = center - 1;
				}
			}
			if (test(center)=='R' && (test(center-1)=='A' || test(center-1)=='L')) {
				right_edge=center;
				break;
			} else if (test(center)=='A' || test(center)=='L'){
				left = center + 1;
			} else {
				right = center - 1;
			}
		} while (left <= right);

		left = 0;
		right = N-1;
		do {
			if (test(0)=='A') {
				left_edge=-1;
				break;
			}
			int center = (left + right) / 2;
			if (center==N-1) {
				if (test(center)=='L') {
					left_edge=center-1;
					break;
				} else if (test(center)=='A' || test(center)=='R'){
					right = center - 1;
				} else {
					left = center + 1;
				}
			}
			if (test(center)=='L' && (test(center+1)=='A' || test(center+1)=='R')) {
				left_edge=center;
				break;
			} else if (test(center)=='A' || test(center)=='R'){
				right = center - 1;
			} else {
				left = center + 1;
			}
		} while (left <= right);
		System.out.println(right_edge-left_edge-1);
	}

	static char test(int n) {
		int tmp = n;
		for (int i=0;i<Q;i++) {
			if (s.charAt(tmp)==t[i]) {
				if (d[i]=='R') {
					tmp++;
				} else if (d[i]=='L') {
					tmp--;
				}
			}
			if (tmp<0) {
				return 'L';
			}else if(tmp>N-1) {
				return 'R';
			}
		}
		return 'A';
	}
}

Measured memory_bytes: 66728
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 

using namespace std;

int n;
int sum;

int main()
{
	scanf("%d", &n);
	sum = (n - 2) * 180;
	printf("%d\n", sum);
	
	return 0;
}


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

using namespace std;
#define ll long long
#define rep(i,n,N) for(int i=(int)n;i<=(int)N;i++)
#define rap(i,n,N) for(int i=(int)n;i>=(int)N;i--)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define pii pair<int,int> 
#define pll pair<ll,ll>
const ll MAX=2010;
const int MOD=1000000000 + 7;
const ll INF=1000000000000000000;
const int nr[]={1,-1,0,0,1,1,-1,-1};
const int nc[]={0,0,1,-1,1,-1,1,-1};
string s;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>s;
    rep(i,0,s.size()-9)cout<<s[i];
    cout<<endl;
    return 0;
}

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

int main(void){
    int n, l;
    string s;
    vector <string> str;
    int i, j;
    
    cin >> n;
    cin >> l;
    for(i = 0; i < n; i++){
        cin >> s;
        str.push_back(s);
    }
    
    for(i = 0; i < n; i++){
        for(j = 0; j < n - 1; j++){
            if(str[j] > str[j + 1]){
                s = str[j];
                str[j] = str[j + 1];
                str[j + 1] = s;
            }
        }
    }
    
    
    for(i = 0; i < n; i++){
        cout << str[i];
    }
    
    cout << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x)
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define inf std::numeric_limits<int>::max();
#define highest_2_pow(n)  __builtin_clzll((long long)0)- __builtin_clzll((long long)n) - 1
//-----------------------------------------------------------------------------------------------------
#define lli long long int 
#define int long long
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define vi vector<int>
#define vlli vector<long long int>
#define si set<int>
#define slli set<long long int>
#define mt make_tuple
#define mp make_pair
#define eb emplace_back
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
//---------------------------------------------------
using namespace std;
// GCD and LCM are available
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}

void faster(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}
void solve(){
    int n;
    cin>>n;
    vi v(n);
    vi u(n);
    rep(i,0,n) cin>>v[i];
    u = v;
    sort(all(v));
    int mx = v[n-1];
    int hf = (mx%2==0?mx/2:(mx+1)/2);
    rep(i,0,n-1){
        if(v[i]>hf) v[i] = mx-v[i];
    }
    int r = *max_element(v.begin(),v.end()-1);
    if(find(all(u),r)==u.end()) r=mx-r;
    cout<<mx<<" "<<r<<endl;
}
signed main()
{
    faster();
    int t=1;
    //cin>>t;
    while(t--) solve();
}

Measured memory_bytes: 1792
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
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...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

ll f(ll b, ll n){
    ll res;
    if(n==0) return 0;
    if(n<b) return n;
    res=f(b,n/b)+n%b;
    return res;
}
int main(){
    ll n,s;
    cin>>n>>s;
    if(s==n) cout<<n+1<<endl;
    else if(s>(n+1)/2) cout<<-1<<endl;
    else{
        REP2(i,2,sqrt(n)+1){
            if(f(i,n)==s){
                cout<<i<<endl;
                return 0;
            }
        }

        REPD2(i,sqrt(n),0){
            if((n-s)%i==0){
                ll b=(n-s)/i+1;
                if(f(b,n)!=s) continue;
                cout<<b<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3680
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		int longDistance = 0;
		for(int i = 0; i < N; i++) {
			int tmp = 0;
			if(i == N-1) {
				tmp = Math.abs(A[i]-(A[0]+K));
			} else {
				tmp = Math.abs(A[i]-A[i+1]);
			}

			if(tmp > longDistance) {
				longDistance = tmp;
			}
		}
		System.out.println(K-longDistance);
	}
}

Measured memory_bytes: 66948
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		while (true) {

			c = c - b;
			if (c <= 0) {
				System.out.println("Yes");
				break;
			}

			a = a - d;
			if (a <= 0) {
				System.out.println("No");
				break;
			}
		}

		sc.close();

	}
}

Measured memory_bytes: 35700
N = int(input())
A = list(map(int, input().split()))

ans = []


for i in A:
    if (i % 2 == 0):
        ans.append(i)

lists = len(ans)

for i in range(lists):
    if ans[i] % 3 != 0 and ans[i] % 5 != 0:
        print("DENIED")
        exit()

print("APPROVED")


Measured memory_bytes: 3060
h,w = map(int,input().split())
n = int(input())
a = map(int,input().split())

ans = sum(([i]*ai for i,ai in enumerate(a,1)),[])
ans = [ans[i*w:(i+1)*w] if i%2 ==0 else ans[(i+1)*w-1:i*w-1:-1] for i in range(h)]
for c in ans:
    print(*c)

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

using namespace std;

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

    long long n, k;
    cin >> n >> k;

    if(!k)
        return cout << n * n << '\n', 0;

    long long b = n - k;

    long long answer = 0;

    for(int i = n; i > k; --i)
    {
        long long h = n / i;

        answer += (i - k) * h;

        long long val = n - h * i;
        answer += max(0ll, val + 1 - k);
    }

    cout << answer << '\n';
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] data;
        long[] nums = new long[2];
        long tmp = 0;
        try {
            data = br.readLine().split(" ");
            for (int i = 0; i < 2; i++)
                nums[i] = Integer.parseInt(data[i]);

            while (nums[0] != 0) {
                if (nums[0] < nums[1]) {
                    tmp = nums[0];
                    nums[0] = nums[1];
                    nums[1] = tmp;
                }
                nums[0] -= nums[1];
            }
            System.out.println(nums[1]);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}


Measured memory_bytes: 24324
#include <iostream>
#include <algorithm>

using namespace std;

int func(int x, int y, char symbol) {
	switch (symbol) {
	case '+':return x + y;
	case '-':return x - y;
	default :return x * y;
	}
}


int main(void) {
	int i, j, k, flag;
	int arr[4] = { 0 };
	const char mathSymbol[] = { '+','-','*' };

	while (1) {
		for (i = 0; i < 4; i++) {
			cin >> arr[i];
			if (arr[i] == 0) {
				return 0;
			}
		}

		sort(arr, arr + 4);

		flag = 1;
		do {
			for (i = 0; i < 3; i++) {
				for (j = 0; j < 3; j++) {
					for (k = 0; k < 3; k++) {
						if (func(func(func(arr[0], arr[1], mathSymbol[i]), arr[2], mathSymbol[j]), arr[3], mathSymbol[k]) == 10) {
							flag = 0;
							cout << "(((" << arr[0] << mathSymbol[i] << arr[1] << ")" << mathSymbol[j] << arr[2] << ")" << mathSymbol[k] << arr[3] << ")" << endl;
							break;
						}

						if (func(func(arr[0], arr[1], mathSymbol[i]), func(arr[2], arr[3], mathSymbol[k]), mathSymbol[j]) == 10) {
							flag = 0;
							cout << "((" << arr[0] << mathSymbol[i] << arr[1] << ")" << mathSymbol[j] << "(" << arr[2] << mathSymbol[k] << arr[3] << "))" << endl;
							break;
						}

						if (func(func(arr[0], func(arr[1], arr[2], mathSymbol[j]), mathSymbol[i]), arr[3], mathSymbol[k]) == 10) {
							flag = 0;
							cout << "((" << arr[0] << mathSymbol[i] << "(" << arr[1] << mathSymbol[j] << arr[2] << "))" << mathSymbol[k] << arr[3] << ")" << endl;
							break;
						}

					}
					if (flag == 0) {
						break;
					}
				}
				if (flag == 0) {
					break;
				}
			}
		} while (flag && next_permutation(arr, arr + 4));

		if (flag == 1) {
			cout << "0" << endl;
		}


	}

	return 0;
}








Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=200005;
int n,a[N],x[N];
int c[N<<2];
void update(int rt,int L,int R,int xL,int xR,int v){
	if (R<xL||L>xR)
		return;
	if (xL<=L&&R<=xR){
		c[rt]=v;
		return;
	}
	int mid=(L+R)>>1,ls=rt<<1,rs=ls|1;
	if (c[rt]!=0)
		c[ls]=c[rs]=c[rt],c[rt]=0;
	update(ls,L,mid,xL,xR,v);
	update(rs,mid+1,R,xL,xR,v);
}
int ask(int rt,int L,int R,int x){
	if (c[rt]||L==R)
		return c[rt];
	int mid=(L+R)>>1,ls=rt<<1,rs=ls|1;
	if (x<=mid)
		return ask(ls,L,mid,x);
	else
		return ask(rs,mid+1,R,x);
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]),a[i]+=n-i+1;
	for (int i=1;i<=n;i++)
		update(1,1,n,i,i,n-i+1);
	LL ans=0;
	for (int i=n;i>=1;i--){
		if (a[i]==ask(1,1,n,i))
			continue;
		int pos=n-a[i]+1;
		if (pos<=0){
			puts("-1");
			return 0;
		}
		if (pos>i||ask(1,1,n,pos)!=a[i]){
			puts("-1");
			return 0;
		}
		update(1,1,n,pos,i,a[i]);
		ans+=i-pos;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4992
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {
  public static void main(String[] args) {
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      solve(br);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  static void solve(BufferedReader br) throws NumberFormatException, IOException {
    int cnt = Integer.parseInt(br.readLine());

    Set<String> set = new HashSet<>();
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < cnt; i++) {
      String[] input = br.readLine().split("\\s+");
      if (input[0].equals("insert")) {
        set.add(input[1]);
        continue;
      }

      if (set.contains(input[1])) {
        sb.append("yes\n");
      } else {
        sb.append("no\n");
      }
    }

    System.out.print(sb.toString());
  }
}



Measured memory_bytes: 324888
// D - Good Grid

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int N, C;
int D[30][30];
int c[500][500];
int cost[3][30]; // cost[k][d]: (x+y)%3 = k を色dに変えるときの違和感の合計

int calc_cost(int k, int d_to) {
	int result = 0;

	for (int i=0; i<N; i++) {
		for (int j=0; j<N; j++) {
			if ((i+j) % 3 == k) {
				int d_from = c[i][j];
				result += D[d_from][d_to];
			}
		}
	}

	//cout << "k=" << k << " d_to=" << d_to << " cost=" << result << endl; // **** debug ****
	return result;
}

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

	for (int i=0; i<C; i++) {
		for (int j=0; j<C; j++) {
			cin >> D[i][j];
		}
	}

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

	for (int k=0; k<3; k++) {
		for (int d=0; d<C; d++) {
			cost[k][d] = calc_cost(k, d);
		}
	}

	int ans = INF;

	for (int d1=0; d1<C; d1++) {
		for (int d2=0; d2<C; d2++) {
			for (int d3=0; d3<C; d3++) {
				if (d1 == d2 || d2 == d3 || d3 == d1) continue;
				else ans = min(ans, cost[0][d1] + cost[1][d2] + cost[2][d3]);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 2e5 + 5;

void debug_out() {
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    FAST
    int k,a,b;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            return cout<<"OK",0;
        }
    }
    cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin >>a>>b>>c;
    int i;
    int h=1;
    if(a>=b){
        for(i=1;i<=b;i++){
            if((a%i==0)&&(b%i==0)){
                h=i;
            }
        }
    }
    else{
        for(i=1;i<=a;i++){
            if((b%i==0)&&(a%i==0)){
                h=i;
            }
        }
    }
    if(c%h==0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string S, T; cin >> S >> T;
    if (T.substr(0, S.size()) == S) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main()
{
	int n,t=0;
	cin>>n;
	while(n>0)
	{
		int x;
		x=n%10;
		n=n/10;
		if(x>0)
		{
			t++;
		}
	}
	cout <<t;
	return 0;
}

Measured memory_bytes: 256
#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 main(){
  int n;
  cin>>n;
  vector<int> vec(n,0);
  int sum=0;
  rep(i,n){
    cin>>vec[i];
    sum+=vec[i];
  }
  int first=*max_element(vec.begin(),vec.end());
  sum-=first;
  if(sum>first){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

using namespace std;
int main() {
    int N;
    set<int> mochi;

    cin >> N;
    for (int i = 0; i < N; i++) {
        int d;
        cin >> d;
        mochi.insert(d);
    }

    cout << mochi.size() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(n) ((n) + 1LL) * (n) / 2
using namespace std;
const int mod = 1e9 + 7;
int main() {
	int n, k; cin >> n >> k;
	long long ans = 1;
	for (int i = k; i <= n; i++) 
		ans = (ans + f(n) - f(n - i) - f(i - 1) + 1) % mod;
	cout << ans;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if((a==b && b==c && a==c)||(a!=b && a!=c && b!=c)){
        cout << "No";
    }else{
        cout << "Yes";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int n, x;
set<int> s;
 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	while (n--) {
		cin >> x;
		if (s.find(x) == s.end())
			s.insert(x);
		else
			s.erase(x);
	}
	cout<<s.size()<<"\n";
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main{
  public static int min(int n,int m){
    if(n<m) return n;
    else return m;
  }
  
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    String str[]=new String[n];
    int cnt[]=new int[n];
    int flg1=0;
    int flg2=0;
    int flg3=0;
    
    int flg=0;

    for(int i=0;i<n;i++){
      str[i]=sc.next();
    }
    
    int ans=0;
    
    for(int i=0;i<n;i++){
      flg=0;
      for(int j=0;j<str[i].length();j++){
        char s=str[i].charAt(j);
        if(s=='A'){
          flg=1;
        }
        else if(s=='B'&&flg==1){
          ans+=1;
          flg=0;
        }
        else{
          flg=0;
        }
      }
    }
    
    for(int i=0;i<n;i++){
      char s=str[i].charAt(str[i].length()-1);
      char ss=str[i].charAt(0);
      
      if(s=='A') cnt[i]+=1;
      
      if(ss=='B') cnt[i]+=2;
      
      switch(cnt[i]){
        case 1:
          flg1+=1;
          break;
        case 2:
          flg2+=1;
          break;
        case 3:
          flg3+=1;
          break;
        default:
      }
    }
    ans+=min(flg1,flg2);
    if(flg3==0){
      System.out.println(ans);
    }
    else{
      if(flg1+flg2==0){
        System.out.println(ans+flg3-1);
      }
      else{
        System.out.println(ans+flg3);
      }
    }
  }
}


Measured memory_bytes: 30052
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,m;
  ll k;
  cin >> n >> m >> k;
  vector<ll> a(n+1),b(m+1);
  rep(i,n){
    ll x;
    cin >> x;
    a[i+1]=a[i]+x;
  }
  rep(i,m){
    ll x;
    cin >> x;
    b[i+1]=b[i]+x;
  }

  int ans = 0;
  int right = m;
  for(int i=0;i<=n;i++){
    ll t = a[i];
    if(t>k)break;
    while(t+b[m]>k){
      m--;
    }
    ans = max(i+m,ans);
    right=m;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6308
#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int INF = 1000000000 + 8;
constexpr int ctoi(char c)
{
    return isdigit(c) ? c - '0' : -1;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(16);

    string n;
    cin >> n;

    // 金額のその桁までを見たときの「ピッタリ払うときの最小」「1余分に払うときの最小」
    array<int, 2> dp = {0, 1};

    for (auto &&ni : n)
    {
        int d = ctoi(ni);
        array<int, 2> ndp = {INF, INF};

        ndp[false] = min(dp[false] + d, ndp[false]);
        ndp[true] = min(dp[false] + d + 1, ndp[true]);
        ndp[false] = min(dp[true] + 10 - d, ndp[false]);
        ndp[true] = min(dp[true] + 10 - d - 1, ndp[true]);

        dp = ndp;
    }

    int ans = dp[false];
    cout << ans << endl;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

using PDI = pair<double, int32>;

const int64 mod = 1e9+7;

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

int main(void){
	int32 H, W;
	string s[51];
	cin >> H >> W;
	REP(i, H) cin >> s[i];
	auto in = [&](int32 y, int32 x){return 0<=y&&y<H&&0<=x&&x<W;};
	REP(i, H){
		REP(j, W){
			int32 cnt = 0;
			if(s[i][j] == '.') continue;
			REP(k, 4){
				int32 yy = i+dy[k], xx = j+dx[k];
				if(!in(yy, xx)) continue;
				if(s[yy][xx] == '#') cnt++;
			}
			if(cnt == 0){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;

}


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

vector<ll> SieveRev(ll n){
    vector<ll> IsPrime(n+1,1);
    IsPrime[0]=IsPrime[1]=0;
    for(ll i=2;i*i<=n;i++){
        if(IsPrime[i]==1){
            for(ll j=i;i*j<=n;j++){
                IsPrime[i*j]=i;
            }
        }
    }
    for(ll i=2;i<=n;i++){
        if(IsPrime[i]==1) IsPrime[i]=i;
    }
    return IsPrime;
}

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    cin>>a[0];
    ll g=a[0],mx=a[0];
    for(ll i=1;i<n;i++){
        cin>>a[i];
        g=gcd(g,a[i]);
        mx=max(mx,a[i]);
    }
    if(g!=1){
        cout<<"not coprime"<<endl;
        return 0;
    }else{
        vector<ll> isp=SieveRev(mx);
        vector<bool> isu(mx+1,0); 
        rep(i,n){
            vector<ll> pf;
            while(a[i]!=1){
                pf.push_back(isp[a[i]]);
                a[i]/=isp[a[i]];
            }
            rep(j,pf.size()){
                if(isu[pf[j]]){
                    cout<<"setwise coprime"<<endl;
                    return 0;
                }
            }
            rep(j,pf.size()) isu[pf[j]]=1;
        }
        cout<<"pairwise coprime"<<endl;
        return 0;
    }
}

Measured memory_bytes: 19100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int ans[502][502];
int H, W, h, w;

bool solve(){
    vector<vector<int>> base(h, vector<int>(w, 4000));
    base[h-1][w-1] = - 4000 * (h * w - 1) - 1;
    int cum_sum = 0;
    memset(ans, 0, sizeof(ans));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            ans[i][j] = base[i % h][j % w];
            cum_sum += ans[i][j];
        }
    }
    if(cum_sum > 0) return true;
    return false;
}

int main(){
    cin >> H >> W >> h >> w;
    if(solve()){
        cout << "Yes" << endl;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(j != 0) cout << " ";
                cout << ans[i][j];
            }
            cout << endl;
        }
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 2588
#標準入力をリスト化するときはキャストなので、宣言と勘違いしないこと。list()を使うこと。[]ではリスト化できない。勘違いしない。
array = sorted(list(map(int,input().split())))

#最初の時点で1種類
result = 1

for i in range(len(array)-1):
 if array[i] != array[i+1] :
    result+=1

print(result)


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

int main() {
  int s, w;
  cin >> s >> w;

  if (w >= s) cout << "unsafe" << endl;
  else cout << "safe" << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#define rep(i,j,k) for(register int i = j; i <= k; i++) 
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define fi first
#define se second
//#define P pair<ull,ull>
//#define PP pair<int,pair<int,int> >
//#define mp(a,b) make_pair(a,b)
#define ll long long
#define ull unsigned long long
using namespace std;
 
inline int read() { 
	int s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;
}

const int N = 2e5+5, inf = 1e9+7;
int n, v[N], ans[N], len = 0;
struct node{ 
	int l, r, x, y; 
	node(int a=0,int b=0,int c=0,int d=0) { l = a, r = b, x = c, y = d; }
	bool operator < (const node&rhs) const { return v[x] > v[rhs.x]; } 
} c; priority_queue<node> q;
struct tag{ 
	int m1, m2; 
	tag(int a=0,int b=0) { m1 = a, m2 = b; }
} A[N<<2], a, b;

inline tag operator + (const tag&a,const tag&b) { 
	tag c;
	c.m1 = v[a.m1] < v[b.m1] ? a.m1 : b.m1;
	c.m2 = v[a.m2] < v[b.m2] ? a.m2 : b.m2;
	return c;
}
#define lc k<<1
#define rc k<<1|1
int ql, qr;
inline void build(int l,int r,int k) { 
	if( l == r ) { 
		if( l & 1 ) A[k] = tag(l,0); else A[k] = tag(0,l);
		return; 
	} 
	int mid = (l + r) >> 1;
	build(l,mid,lc), build(mid+1,r,rc), A[k] = A[lc] + A[rc];
}

inline tag query(int l,int r,int k) { 
	if( ql <= l && r <= qr ) return A[k];
	int mid = (l + r) >> 1;
	if( qr <= mid ) return query(l,mid,lc);
	else if( ql > mid ) return query(mid+1,r,rc);
	else return query(l,mid,lc) + query(mid+1,r,rc);
}
inline void add(int l,int r) {
	if( l > r ) return; 
	ql = l, qr = r, a = query(1,n,1);
	if( l & 1 ) { 
		ql = a.m1, qr = r, b = query(1,n,1), qr = b.m2; 
	} else { 
		ql = a.m2, qr = r, b = query(1,n,1), qr = b.m1;
	}
	q.push(node(l,r,ql,qr));
}

int main() {
	n = read(), v[0] = inf;
	rep(i,1,n) v[i] = read();
	build(1,n,1), add(1,n);
	while( !q.empty() ) { 
		c = q.top(), q.pop();
		ans[++len] = v[c.x];
		ans[++len] = v[c.y];
		add(c.l,c.x-1);
		add(c.x+1,c.y-1);
		add(c.y+1,c.r);
	}
	rep(i,1,n) printf("%d ", ans[i]); puts("");
	return 0; 
}

Measured memory_bytes: 10100
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto&& i : a){
        cin >> i;
    }
    double avg = accumulate(begin(a), end(a), 0.) / n;
    int ans = 0;
    for(int i = 1; i < n; i++){
        if(abs(avg - a[ans]) > abs(avg - a[i])){
            ans = i;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	void solve() throws IOException {
		int x = nextInt();
		int y = nextInt();
		
		int ans = Integer.MAX_VALUE;
		
		if (x <= y) {
			ans = Math.min(ans, y - x);
		}
		
		if (-x <= y) {
			ans = Math.min(ans, y - (-x) + 1);
		}
		
		if (x <= -y) {
			ans = Math.min(ans, -y - x + 1);
		}
		
		if (-x <= -y) {
			ans = Math.min(ans, -y - (-x) + 2);
		}
		
		out.println(ans);
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 8276
// dinosaur code by ryan the talking human.
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<(int)(n);i++)
#define per(i,a,n) for (int i=(n)-1;i>=(int)(a);i--)
template<typename T> ostream& operator<<(ostream& s, vector<T> t) {rep(i, 0, t.size()) s << (i ? " " : "") << t[i]; return s;}
template<typename T> istream& operator>>(istream& s, vector<T> &t) {rep(i, 0, t.size()) s >> t[i]; return s;}
template<typename T, typename U> ostream& operator<<(ostream& s, pair<T, U> t) {s << "(" << t.first << "," << t.second << ")"; return s;}
template<typename T, typename U> istream& operator>>(istream& s, pair<T, U> &t) {s >> t.first >> t.second; return s;}
typedef long long ll;


int main() {
    ios_base::sync_with_stdio(false);
    int n;
    ll d;
    cin >> n >> d;
    vector<ll> a(n);
    cin >> a;
    
    vector<ll> mind(n + 1);
    mind[n] = 1;
    per(i, 0, n) {
        if (llabs(mind[i + 1] - a[i]) >= mind[i + 1]) {
            mind[i] = mind[i + 1];
        } else {
            mind[i] = mind[i + 1] + a[i];
        }
    }
    vector<ll> reald(n + 1);
    reald[0] = d;
    rep(i, 0, n) {
        reald[i + 1] = min(reald[i], llabs(reald[i] - a[i]));
    }
    //cout << mind << endl;
    //cout << reald << endl;
    int qn;
    cin >> qn;
    vector<ll> q(qn);
    cin >> q;
    rep(i, 0, qn) {
        q[i]--;
        if (reald[q[i]] >= mind[q[i] + 1]) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}


Measured memory_bytes: 19072
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
int main(void){
    int n,r,p;
    while(cin>>n>>r,n){
        valarray<int> mayor(0,n);
        p=r;
        rep(i,1000000){
            if(p==0){
                p+=mayor[0]; mayor[0]=0;
            }else{
                p--;mayor[0]++;
                if(mayor[0]==r){
                    cout<<i%n<<endl;
                    break;
                }
            }
            mayor=mayor.cshift(1);
        }
    }
}

Measured memory_bytes: 3108
#include<stdio.h>
int main(void)
{
	int a,s,d[8],f,g,h,i,j;
	scanf("%d",&a);
	while(a!=0){
		for(i=1;i<=7;i++){
			d[i]=0;
		}
		for(i=1;i<=a;i++){
			f=0;
			scanf("%d",&s);
			if(s>=60){
				d[7]++;
				f++;
			}
			if(f==0&&s>=50){
				d[6]++;
				f++;
			}
			if(f==0&&s>=40){
				d[5]++;
				f++;
			}
			if(f==0&&s>=30){
				d[4]++;
				f++;
			}
			if(f==0&&s>=20){
				d[3]++;
				f++;
			}
			if(f==0&&s>=10){
				d[2]++;
				f++;
			}
			if(f==0){
				d[1]++;
				f++;
			}
		}
		for(i=1;i<=7;i++){
			printf("%d\n",d[i]);
		}
		scanf("%d",&a);
	}
	return 0;
}	

Measured memory_bytes: 1032
(function(input) {
  var p = input.replace(/\n$/, '').split('\n');
  var n = Number(p.shift());
  for (var i = 0; i < n; i++) {
    console.log(conv(p.shift()));
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function conv(s) {
  a = s.split(' ');
  for (var i = 0; i < a.length; i++) {
    var r = check(a[i]);
    if (r) {
      return conv_(s, r);
    }
  }
  return s;
}

function conv_(s, r) {
  var a = r[0];
  var b = r[1];
  var s = s.split('').map(function(e) {
    if (e === ' ') {
      return e;
    }
    return String.fromCharCode((a * e.charCodeAt(0) + b) % 26 + 'a'.charCodeAt(0));
  }).join('');
  return s;
}

function check(str) {
  if (str.length !== 4) {
    return false;
  }
  for (var i = 0; i < 26; i++) {
    for (var j = 0; j < 26; j++) {
      var s = conv_(str, [i, j]);
      if (s === 'this' || s === 'that') {
        return [i, j];
      }
    }
  }
  return false;
}

Measured memory_bytes: 20012
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7')cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

Measured memory_bytes: 3624
#include <iostream>

int main()
{
	int weight;
	while (std::cin >> weight) {
		int scale_weight = 1;
		bool printed_any = false;
		while (weight > 0) {
			if ((weight & scale_weight) != 0) {
				weight -= scale_weight;
				if (printed_any) {
					std::cout << ' ';
				}
				std::cout << scale_weight;
				printed_any = true;
			}
			scale_weight *= 2;
		}
		std::cout << std::endl;
	}

	return 0;
}

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


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

  int min = 0;
  int t_temp = a[0];
  while((t_temp % 2) == 0){
    t_temp = t_temp / 2;
    min++;
  }

  for(int j=1;j<n;j++){
    int t = a[j];
    int min_temp = 0;
    while((t % 2) == 0){
      t = t / 2;
      min_temp++;
    }
    if(min_temp < min){
      min = min_temp;
    }
  }
  cout << min << endl;
  return 0;
}

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

Measured memory_bytes: 86456