akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(void){
    int n,x,m,min_m=1000,sum_m=0;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>m;
        min_m = min(min_m,m);
        sum_m += m;
    }
    cout<<(n + (x-sum_m)/min_m)<<endl;

}

Measured memory_bytes: 256
A, B, M = map(int, input().split())

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

discount_list = [tuple(map(int, input().split())) for _ in range(M)]

ans = sorted(a_list)[0] + sorted(b_list)[0]

for discount in discount_list:
    tmp = a_list[discount[0]-1] + b_list[discount[1]-1] - discount[2]
    if ans > tmp:
        ans = tmp

print(ans)


Measured memory_bytes: 85996
#include<iostream>
#include<stack>
using namespace std;
stack<char> s;
int sum=0;
int main(){
	while(1){
		char t=getchar();
		if (t=='\n')
			break;
		if(!s.empty()&&s.top()!=t)
			s.pop(),sum++;
		else
			s.push(t);
			
		
	}
	cout<<sum*2<<'\n';
 
 
}

Measured memory_bytes: 384
#include <cstdio>
#include <string>
#include <iostream>

using std::string;
using std::cin;

template<class T>inline void fr(T &a) {
    T s=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=w*s;
}
template<class T>inline T fr() {T a;fr(a);return a;}
#define R() fr<int>()

string str;

signed main() {
    cin>>str;
    if(str=="MON")puts("6");
    else if(str=="TUE")puts("5");
    else if(str=="WED")puts("4");
    else if(str=="THU")puts("3");
    else if(str=="FRI")puts("2");
    else if(str=="SAT")puts("1");
    else puts("7");
    return 0;
}

Measured memory_bytes: 256
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    S = input().rstrip('\n')
    T = input().rstrip('\n')
    if T[:-1] == S:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 62272
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,k,i,nk,ans
    integer(int32), allocatable:: a(:), cnt(:), num(:)

    read*, n,k
    allocate(a(n))
    read*, a(:)
    allocate(cnt(maxval(a)), source=0)

    do i=1,n
        cnt(a(i))=cnt(a(i))+1
    end do

    nk=0
    do i=1,size(cnt)
        if (cnt(i) /= 0) nk=nk+1
    end do

    allocate(num(nk))
    nk=0

    do i=1,size(cnt)
        if (cnt(i) /= 0) then
            nk=nk+1
            num(nk)=cnt(i)
        end if
    end do
    call merge_sort(num,1,nk)
    ans=0
    i=0
    do while (nk-i > k)
        i=i+1
        ans=ans+num(i)
    end do
    print'(i0)',ans
contains
    recursive subroutine merge_sort(ar, fst, lst)
        integer(4),intent(inout):: ar(:)
        integer(4),intent(in):: fst,lst
        integer(4):: mdl

        if (lst-fst < 2) then
            if (ar(fst) > ar(lst)) call swap(ar(fst),ar(lst))
            return
        end if

        mdl = (fst+lst)/2
        call merge_sort(ar, fst, mdl)
        call merge_sort(ar, mdl+1, lst)
        call merge_(ar, fst, mdl, lst)
    end subroutine

    subroutine merge_(ar, fst, mdl, lst)
        integer(4),intent(inout):: ar(:)
        integer(4),intent(in):: fst, mdl, lst
        integer(4),allocatable:: tmp(:)
        integer(4):: li, ri, ti

        allocate(tmp(lst-fst+1))

        li=fst
        ri=mdl+1   
        ti=1

        do while (li <= mdl .and. ri <= lst)
            if (ar(li) <= ar(ri)) then
                tmp(ti) = ar(li)
                li=li+1
            else
                tmp(ti) = ar(ri)
                ri=ri+1
            end if
            ti=ti+1
        end do

        if (li <= mdl) then
            tmp(ti:) = ar(li:mdl)
        else
            tmp(ti:) = ar(ri:lst)
        end if

        ar(fst:lst) = tmp(:)
        deallocate(tmp)
    end subroutine

    subroutine swap(x,y)
        integer(4),intent(inout):: x,y
        integer(4):: tmp
        tmp = x
        x = y
        y = tmp
    end subroutine
end program name

Measured memory_bytes: 4276
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */


ll solve(){
    ll res = 0;
    ll N; cin >> N;
    vector<ll> A(N);
    for(auto& in:A) cin >> in;
    map<ll,ll> mp;
    for(int i = 0; i < N;i++) mp[A[i]]++;
    ll tate = 0;
    ll yoko = 0;
    for(auto it = mp.rbegin();it != mp.rend(); it++){
        if(it->second >= 4){
            if(tate == 0){
                tate = it->first;
                yoko = it->first;
            }else if(yoko == 0){
                yoko = it->first;
            }
        }else if(it->second >= 2){
            if(tate == 0){
                tate = it->first;
            }else if(yoko == 0){
                yoko = it->first;
            }
        }
    }
    res = tate*yoko;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll a,b; cin >> a >> b;
	if(a>b) swap(a,b);
	rep(i,b) cout << a;
	cout << endl;
}

Measured memory_bytes: 256
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
#sort = sorted(a)[::-1] 降順
n = int(input())
import itertools
List = [0]*100
List2 = [0]*60001

for i in range(100):
    List[i] = i+1

h = list(itertools.combinations_with_replacement(List, 3))

for j in range(len(h)):
    a = h[j][0]
    b = h[j][1]
    c = h[j][2]

    sum = a*a + b*b + c*c + a*b + b*c + c*a
    if a == b == c:
        List2[sum] += 1
    elif a == b or b == c or c == a:
        List2[sum] += 3
    else:
        List2[sum] += 6

for k in range(1, n+1):
    print(List2[k])


Measured memory_bytes: 21776
def isPrime( x )
	return true if ( 2 == x || 3 == x )
	return false if ( 0 == x%2 )
	
	for i in ( 3 .. x )
		break if x < i*i
		return false if 0 == x%i
	end
	
	return true
end

n = gets.to_i
nums = []
n.times {
	nums.push( gets.to_i )
}

cnt = 0
for i in ( 0 ... n )
	if isPrime( nums[i] )
		cnt += 1
	end
end
puts( cnt )

Measured memory_bytes: 6180
#include <bits/stdc++.h>
using namespace std;
int solve(int i, int n, vector<int>& A){
    if(n==0)return 1;
    else if(i==A.size() || n<0) return 0;
    return max(solve(i+1, n-A[i], A), solve(i+1, n, A) );
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,m_i;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) cin >> A[i];
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> m_i;
        if(solve(0,m_i,A)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    
    return 0;
}


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

using namespace std;

int main(){
    string s, str;
    int cnt = 0;

    cin >> s;

    str = "CODEFESTIVAL2016";

    for (int i = 0; i < 16; i++){
        if (s[i] != str[i]){
            cnt++;
        }
    }

    cout << cnt << endl;

    return(0);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include"string"
#include"math.h"
#include <algorithm>
#include<vector>
using namespace std;

int abs(int a){
	if(a<0)return -a;
	return a;
}





long long N,K,M,re,C,spot,r,l;
bool map[51][51];
long long ans,A[100000];
string s;

int main(){
	cin>>N>>K;;
	ans=0;
	for(int i=0;i<N;i++){
		cin>>A[i];
		if(A[i]==1)spot=i;
	}

	if(spot==0){
		ans=(N-1)/(K-1);
		if((N-1)%(K-1)>0)ans++;
			cout << ans << endl;

	return 0;
	}
	re=N-1-spot;

	if(spot==N-1){
		ans=(N-1)/(K-1);
		if((N-1)%(K-1)>0)ans++;
		cout << ans << endl;

	return 0;
	}

	ans+=spot/(K-1);
	if(spot%(K-1)>0)ans++;

	if((re-(spot%(K-1)))%(K-1))ans++;
	ans+=(re-((K-1)-(spot%(K-1))))/(K-1);
	if((N-1)%(K-1)>0){
	cout << (N-1)/(K-1) +1<< endl;

	return 0;
	}else{
	cout << (N-1)/(K-1) << endl;

	return 0;
	}

}


Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

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

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    string s;
    cin >> s;

    int t=0,ans=0;
    REP(i,s.length()){
        switch (s[i]){
            case 'g':
                if(t>0){
                    t--;
                    ans++;
                }else{
                    t++;
                }
                break;
            case 'p':
                if(t>0){
                    t--;
                }else{
                    t++;
                    ans--;
                }
                break;
        }
    }

    cout << ans << ENDL;

    return 0;
}

Measured memory_bytes: 512
// In the name of God 
#include <bits/stdc++.h>

using namespace std ;
 
#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int N = 2000 + 10 , mod = ( int )1e9 + 7 , maxn = 2000 * 2000 + 10 ; 

int n , k , dp [ N ] [ N ] , fact [ maxn ] , inv [ maxn ] ;  

int pw ( int x , int y ) {
	int ret = 1;
	for ( ; y ; y >>= 1 , ( x *= x ) %= mod )
		if ( y & 1 )
			( ret *= x ) %= mod ;
	return ret ; 
}

int comb ( int n , int r ) {
	if ( n < 0 || r < 0 || n < r ) return 0 ;
	return fact [ n ] * inv [ r ] % mod * inv [ n - r ] % mod ; 
}

int32_t main()                     
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	fact [ 0 ] = inv [ 0 ] = 1 ;
	for ( int j = 1 ; j < maxn ; ++j ) {
		fact [ j ] = fact [ j - 1 ] * j % mod ;
		inv [ j ] = pw ( fact [ j ] , mod - 2 ) ; 
	}
	cin >> n >> k ;
	if ( k == 1 )
		return cout << 1 << '\n' , 0 ;
	dp [ 0 ] [ 0 ] = 1 ; 
	for ( int i = 0 ; i <= n ; ++i ) {
		for ( int j = 0 ; j <= i ; ++j ) {
			if ( j )
				dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ; 
			if ( i ) {
				int rem = i * ( k - 1 ) + j - 1 ; 
				dp [ i ] [ j ] += ( dp [ i - 1 ] [ j ] * comb ( rem , k - 2 ) % mod ) ;
				if ( dp [ i ] [ j ] >= mod )
					dp [ i ] [ j ] -= mod ; 
			}
			//cout << "hey " << i << ' ' << j << ' ' << dp [ i ] [ j ] << '\n' ; 
		}
	}
	cout << ( dp [ n ] [ n ] * fact [ n ] ) % mod << '\n' ;
}


Measured memory_bytes: 94208
#!/usr/bin/env python3
n, k = map(int, input().split())
data = [list(map(int,input().split())) for i in range(k*2)]
d = data[0::2]
a = data[1::2]
a = ', '.join(map(str, a))
a = a.replace("[","")
a = a.replace("]","")
list_a = list(map(int, a.split(",")))
list_a = list(set(list_a))
ans = n - len(list_a)
print(ans)


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

string str;
int in[10];
char op[10];
bool flag;

void dfs(int cur)
{
	if(flag==true)return;
	
	if(cur==3)
	{
		int tmp=in[0];
		for(int i=0;i<3;i++)
		{
			if(op[i]=='+')tmp+=in[i+1];
			if(op[i]=='-')tmp-=in[i+1];
		}
		if(tmp==7)
		{
			flag=true;
			for(int i=0;i<3;i++)
				cout << in[i] << op[i];
			cout << in[3];
			cout << "=7" << endl;
		}
		return;
	}
	
	op[cur]='+';
	dfs(cur+1);
	op[cur]='-';
	dfs(cur+1);
	return;
}

int main()
{
	cin >> str;
	for(int i=0;i<str.size();i++)
		in[i]=str[i]-'0';
	
	dfs(0);
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl0

ll modpow(ll x, ll y, ll m){
    if(y==0) return 1;
    ll res = modpow(x,y/2,m);
    return res * res % m * (y&1 ? x : 1) % m;
}

int h,w,n,k;

int ask(int a, int b, int c, int d){
    printf("? %d %d %d %d\n", a, b, c-1, d-1);
    fflush(stdout);
    int p;
    cin >> p;
    return p;
}

int ans[50][50];

void solve(int i1, int j1, int i2, int j2, int n){
    int h = i2 - i1;
    int w = j2 - j1;
    if(n == 0 || n == h*w){
        for(int i = i1; i < i2; ++i){
            for(int j = j1; j < j2; ++j){
                ans[i][j] = n == 0 ? 0 : 1;
            }
        }
    } else {
        if(h >= w){
            int x = ask(i1, j1, i1 + h/2, j2);
            solve(i1, j1, i1 + h/2, j2, x);
            solve(i1 + h/2, j1, i2, j2, n - x);
        } else {
            int x = ask(i1, j1, i2, j1 + w/2);
            solve(i1, j1, i2, j1 + w/2, x);
            solve(i1, j1 + w/2, i2, j2, n - x);
        }
    }
}

int main(){
    cin >> h >> w >> n >> k;
    memset(ans, -1, sizeof ans);
    solve(0, 0, h, w, n);

    // rep(i,h){
    //     rep(j,w){
    //         cerr << ans[i][j];
    //     }
    //     cerr << endl;
    // }

    ll sigma = 0;
    rep(i,h)rep(j,w){
        sigma += ans[i][j] * modpow(2, i*w + j, k);
        sigma %= k;
    }
    cout << "! " << sigma << endl;
}


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

int main() {
  string s;

  cin >> s;
  for(int i=0;i<s.size();i++) {
    if(s[i] == '1') s[i] = '9';
    else if(s[i] == '9') s[i] = '1';
  }

  cout << s << endl;
}


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

ll mod_pow(ll a, ll n, ll m){
    ll res = 1;
    while(n){
        if(n & 1) res = res*a%m;
        a = a*a%m;
        n >>= 1;
    }
    return res;
}

struct modint {
    ll n;
    modint(): n(0) {;}
    modint(ll m): n(m) {
        if(n >= mod) n %= mod;
        else if(n<0) n = (n%mod+mod)%mod;
    }
    operator int(){return n;}
};

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

ll inv(ll a, ll p){
    return (a == 1 ? 1 : (1 - p*inv(p%a, a))/a+p);
}

modint operator/(modint a, modint b){return a*modint(inv(b, mod));}

const int max_n = 1<<18;
modint fact[max_n], factinv[max_n];
void init_f(){
    fact[0] = modint(1);
    for(int i=0;i<max_n-1;i++){
        fact[i+1] = fact[i]*modint(i+1);
    }
    factinv[max_n-1] = modint(1)/fact[max_n-1];
    for(int i=max_n-2;i>=0;i--){
        factinv[i] = factinv[i+1]*modint(i+1);
    }
}

modint comb(int a, int b){
    if (a < 0 || b < 0 || a < b) return 0;
    return fact[a]*fact[b]*factinv[a-b];
}

modint calc(ll n, ll k){
    modint res = 1;
    for(int i=1;i<=k;i++){
        res = res / (modint)i;
        res = res * modint(n+1-i);
    }
    return res;
}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    modint ans = mod_pow(2, n, mod) - 1;
    ans -= calc(n, a);
    ans -= calc(n, b);
    cout << ans << endl;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int a,ans=0;
  while(1){
    ans=0;
    cin>>s;
    if(s=="#") break;
    for(int i=0;i<s.size();i++){
      if(i==0){
	if(s[i]=='y'||s[i]=='u'||s[i]=='i'||s[i]=='o'||s[i]=='p'||s[i]=='h'||s[i]=='j'||s[i]=='k'||s[i]=='l'||s[i]=='m'||s[i]=='n')  a=0;
	else a=1;
      }
      else if(a==1){
	if(s[i]=='y'||s[i]=='u'||s[i]=='i'||s[i]=='o'||s[i]=='p'||s[i]=='h'||s[i]=='j'||s[i]=='k'||s[i]=='l'||s[i]=='m'||s[i]=='n'){
	  ans++;
	  a=0;
	}
      }
      else if(a==0){
	if(s[i]!='y'&&s[i]!='u'&&s[i]!='i'&&s[i]!='o'&&s[i]!='p'&&s[i]!='h'&&s[i]!='j'&&s[i]!='k'&&s[i]!='l'&&s[i]!='m'&&s[i]!='n'){
	  ans++;
	  a=1;
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3192
#include <cstdio>
#include <vector>
#include <algorithm>
#include <tuple>
#include <cassert>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;
template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }

template <typename UnaryPredicate>
ll binsearch(ll l, ll r, UnaryPredicate p) { // [l, r), p is monotone
    assert (l < r);
    -- l;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        (p(m) ? r : l) = m;
    }
    return r; // = min { x | p(x) }
}

int main() {
    // input
    int n, v; scanf("%d%d", &n, &v);
    vector<int> x(n); repeat (i, n) scanf("%d", &x[i]);
    // solve
    vector<int> vs;
    for (int cur_v = v; cur_v > 0; cur_v /= 2) vs.push_back(cur_v);
    vs.push_back(0);
    whole(reverse, vs);
    int k = vs.size();
    vector<vector<pair<int, int> > > range(k); // [l, r]
    repeat (l, n) {
        range[0].emplace_back(l, l);
    }
    repeat (i, k-1) {
        int v = vs[i+1]; // shadowing
        for (int j = 0; j < range[i].size(); ) {
            int l1, r1; tie(l1, r1) = range[i][j];
            ++ j;
            while (j < range[i].size()) {
                int l2, r2; tie(l2, r2) = range[i][j];
                assert (r1 + 1 == l2);
                if (x[l2] - x[r1] <= v) {
                    r1 = r2;
                    ++ j;
                } else {
                    break;
                }
            }
            range[i+1].emplace_back(l1, r1);
        }
    }
    vector<int> dp_l(1 << (k-1));
    vector<int> dp_r(1 << (k-1), n-1);
    repeat (s, 1 << (k-1)) {
        repeat (i, k-1) if (not (s & (1 << i))) {
            int t = s | (1 << i);
            int jr = binsearch(0, range[i].size(), [&](ll j) {
                int l, r; tie(l, r) = range[i][j];
                return dp_l[s] < l;
            }) - 1;
            int jl = binsearch(0, range[i].size(), [&](ll j) {
                int l, r; tie(l, r) = range[i][j];
                return dp_r[s] <= r;
            });
            setmax(dp_l[t], jr < range[i].size() ? range[i][jr].second + 1 :  n);
            setmin(dp_r[t], jl < range[i].size() ? range[i][jl].first  - 1 : -1);
        }
    }
    // output
    for (auto it : range[k-1]) {
        int l, r; tie(l, r) = it;
        bool possible = false;
        repeat (s, 1 << (k-1)) {
            int t = ((1 << (k-1)) - 1) & ~ s;
            if (l <= dp_l[s] and dp_r[t] <= r) {
                possible = true;
                break;
            }
        }
        repeat (i, r - l + 1) {
            printf("%s\n", possible ? "Possible" : "Impossible");
        }
    }
    return 0;
}


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

using namespace std;

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n; cin >> n;
	ll tot = 0;
	int nbs = 35;
	vector<int> bits(nbs, 0);
	REPU(i, 0, nbs) {
		if (i % 2 == 0) {
			tot |= 1LL << i;
			bits[i] = 1;
		}
	}
	tot -= n;
	REPU(i, 0, nbs) if (tot >> i & 1) {
		bits[i] -= 1;
	}
	int last = 0;
	REPU(i, 0, nbs) if (bits[i] != 0) {
		last = i;
	}
	string ans(last + 1, '0');
	REPU(i, 0, last + 1) {
		if (bits[i] != 0) ans[i] = '1';
	}
	reverse(ALL(ans));
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())
lines = sys.stdin.readlines()

works = [None]*n
_ = 0
for l in lines:
    works[_] = tuple(map(int, l.split(" ")))
    _ += 1

works.sort(key=lambda w:w[1], reverse=True)


time = 9999999999999999999999999
for i,w in enumerate(works):
    time = min(time,w[1]) - w[0]

print("Yes" if time >= 0 else "No")

Measured memory_bytes: 96604
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
    int n,i;
    cin>>n;
    int ar[n];
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    int dp[n];
    dp[0]=0;
    dp[1]=abs(ar[0]-ar[1]);
    for(i=2;i<n;i++)
    {
        dp[i]=min(abs(ar[i]-ar[i-1])+dp[i-1],abs(ar[i]-ar[i-2])+dp[i-2]);
        
    }

    cout<<dp[n-1];
 }

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int n;
    cin>>n;
    vi a(3*n);
    cin>>a;
    priority_queue<int,vector<int>,greater<int>> pq0;
    priority_queue<int> pq1;
    int sum0=0,sum1=0;
    REP(i,n) pq0.push(a[i]), sum0+=a[i];
    vector<int> b(n*3),c(n*3);
    b[n-1]=sum0;
    REPF(i,n,3*n) {
        if(pq0.top()<a[i]) {
            sum0-=pq0.top();
            pq0.pop();
            pq0.push(a[i]);
            sum0+=a[i];
        }
        b[i]=sum0;
    }


    for(int i=n*3-1;i>=n*2;i--) {
        sum1+=a[i];
        pq1.push(a[i]);
    }
    c[n*2]=sum1;
    for(int i=n*2-1;i>=0;i--) {
        if(pq1.top()>a[i]) {
            sum1-=pq1.top();
            pq1.pop();
            pq1.push(a[i]);
            sum1+=a[i];
        }
        c[i]=sum1;
    }
    int ans=-INF;
    for(int i=n;i<=2*n;i++) {
        chmax(ans,b[i-1]-c[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9588
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <list>

using namespace std;
typedef long long ll;

// #define DEBUG

int find(int a[], int x)
{
    while (a[x] != x)
    {
        a[x] = a[a[x]];
        x = a[x];
    }
    return x;
}

void unite(int a[], int x, int y)
{
    x = find(a, x);
    y = find(a, y);
    if (x != y)
    {
        a[x] = y;
    }
}

int main()
{
#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, q, op, x, y;
    cin >> n >> q;
    int a[n+1];
    for (int i = 0; i <= n; i++){
        a[i] = i;
    }
    
    for (int i = 0; i < q; i++)
    {
        cin >> op >> x >> y;
        if (op == 0)
        {
            unite(a, x, y);
        }
        else
        {
            cout << ((find(a, x) == find(a, y)) ? 1 : 0) << endl;
        }
    }

    return 0;
}


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

using ll = long long;

constexpr int INF =1e9;

constexpr ll mod = 1e9+7;

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    for(int i=0; i<n; ++i) {
        cin >> x[i];
    }
    for(int j=0; j<m; ++j) {
        cin >> y[j];
    }
    ll xsum = 0, ysum = 0;
    for(int i=0; i<n-1; ++i) {
        (xsum += (x[i+1] - x[i]) * (i+1) * (n-1-i)) %= mod;
    }
    for(int i=0; i<m-1; ++i) {
        (ysum += (y[i+1] - y[i]) * (i+1) * (m-1-i)) %= mod;
    }
    cout << (xsum * ysum) % mod << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n, k, q;
    vector<int> p;
    cin >> n >> k >> q;
    p.assign(n, 0);
    for(int i=0;i<q;i++){
        int a;
        cin >> a;
        p[--a]++;
    }
    for(int i=0;i<n;i++){
        if(k > q-p[i])puts("Yes");
        else puts("No");
    }
}


Measured memory_bytes: 1024
// Hint: Don't look, No need, Let'em Play.

#pragma optimize("O2")
#include <bits/stdc++.h>
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

void solve() {
   int x, y;
   cin >> x >> y;
   for (int i = 0; i <= x; ++i) {
        int a = i, b = x - i;
        if (2 * a + 4 * b == y) {
            cout << "Yes" << '\n';
            return;
        }
   }
   cout << "No" << '\n';
}

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


  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<ll> Vec;
typedef vector<Vec> DVec;
typedef priority_queue<P, vector<P>, greater<P>> PQ;

#define fi             first
#define se             second
#define pb             push_back
#define INF            LLONG_MAX/3
#define MOD            1000000007
#define bcnt           __builtin_popcount
#define all(x)         (x).begin(),(x).end()
#define uni(x)         x.erase(unique(all(x)),x.end())
#define ub(x,y)        (upper_bound(all(x),y)-x.begin())
#define lb(x,y)        (lower_bound(all(x),y)-x.begin())
#define ssort(x)       sort(all(x))
#define rep(i,n)       repl(i,0,n-1)
#define mkp(x,y)       make_pair(x,y)
#define mmax(x,y)      (x>y?x:y)
#define mmin(x,y)      (x<y?x:y)
#define maxch(x,y)     x=mmax(x,y)
#define minch(x,y)     x=mmin(x,y)
#define exist(x,y)     (find(all(x),y)!=x.end())
#define each(itr,v)    for(auto itr:v)
#define repl(i,a,b)    for(ll i=(ll)(a);i<=(ll)(b);i++)
#define dvec(n1,n2,i)  DVec(n1,Vec(n2,i))

int main(){
  cin.sync_with_stdio(false);
  ll N;
  cin >> N;
  Vec A(N,0),B(N,0),b(N,0);
  ll ans = 0;

  rep(i,N)cin>>A[i];
  rep(i,N)cin>>B[i];

  rep(k,29){
    ll T = 1 << k;
    rep(i,N)b[i] = B[i] % (2*T);
    ssort(b);
    ll t_sum=0;
    rep(i,N){
      ll aa = A[i] % (T*2);
      ll T1 = lb(b, T-aa);
      ll T2 = lb(b, 2*T-aa);
      ll T3 = lb(b, 3*T-aa);
      t_sum += (T2-T1) + (N-T3);
    }
    if (t_sum % 2 != 0)ans += T;
  }
  cout<< ans <<endl;
}



Measured memory_bytes: 5120
#include <iostream>

using namespace std;
long long a[100010],b[50];
int main(){
	long long i,n,k,x = 0,ans = 0;
	cin >> n >> k;
	for(i=0;i<n;i++){
		long long c,res = 0;
		cin >> a[i];
		c = a[i];
		while(c>0){
			b[res] += c&1;
			c /= 2; res++;
		}
	}
	for(i=49;i>=0;i--){
		if((x + (1LL<<i))>k) continue;
		if(n>2*b[i]){
			x += 1LL<<i;
		}
	}
	for(i=0;i<n;i++){
		ans += x^a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;
int main(){
int n;
long long a;
long long minValue =1000000;//最小値を1000000にすることから始める
long long maxValue =-1000000;
long long sum =0;

cin >> n;
for(int i=1;i<=n;i++){
cin >> a;
if(a<minValue){minValue=a;}
if(a>maxValue){maxValue=a;}
sum += a;
}

cout << minValue << " " << maxValue << " " << sum << endl;



return 0;

}



Measured memory_bytes: 3116
n=int(input())
def abc(N,a,b,c):
    return 4*a*b*c-N*(a*b+b*c+c*a)
for i in range(1,3501):
    flag=0
    if (1/i)>=(4/n):
        continue
    for j in range(i,3501):
        if 4*i*j-n*i-n*j>0:
            k=int((n*i*j)/(4*i*j-n*i-n*j))
            if k>0:
                if abc(n,i,j,k)==0:
                    print(i,j,k)
                    flag=1
                    break
    if flag>0:
        break

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <assert.h>
#include <sstream>
#include <type_traits>
#define SET(x,y) x |= (1 << y)
#define CLEAR(x,y) x &= ~(1<< y)
#define READ(x,y) ((0u == (x & (1<<y)))?0u:1u)
#define TOGGLE(x,y) (x ^= (1<<y))
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define si(n) scanf("%d",&n)
#define sf(n) scanf("%f",&n)
#define sl(n) scanf("%lld",&n)
#define slu(n) scanf("%llu",&n)
#define sd(n) scanf("%lf",&n)
#define ss(n) scanf("%s",n)
#define pnl printf("\n")
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pF first
#define pS second
#define CL(a,b) memset(a,b,sizeof(a))
#define sqr(x) ((x)*(x))
#define intLIMIT numeric_limits<int>
#define longLIMIT numeric_limits<long long>
#define GCD(a,b) __gcd((a),(b))
#define dbl(x) (double)(x)
#define vi vector <int>
#define vii vector < pair <int, int> >
#define vll vector <long long>
#define allof(x) (x).begin(), (x).end()
#define fastCin cin.sync_with_stdio(0);cin.tie(0)
#define scanUnsigned(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#define printArr(a,l) cout<<#a<<": ";for(int i=0;i<(l);i++){cout<<a[i]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(int i=0;i<(r);i++){for(int j=0;j<(c);j++){cout<<a[i][j]<<" ";}cout<<endl;}
char _;
using namespace std;
void PRINT (int x, int y) { for (int i = y-1; i >= 0; i--) { cout << READ(x,i); } cout << endl; }

vector<string>vec_splitter(string s){s+=',';vector<string>res;while(!s.empty()){res.push_back(s.substr(0,s.find(',')));s=s.substr(s.find(',')+1);}
return res;}
void debug_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,__attribute__((unused))int LINE_NUM){cerr<<endl;}
template<typename Head,typename...Tail>void debug_out(vector<string>args,int idx,int LINE_NUM,Head H,Tail...T){if(idx>0)cerr<<", ";else cerr<<"Line("<<LINE_NUM<<") ";stringstream ss;ss<<H;cerr<<args[idx]<<" = "<<ss.str();debug_out(args,idx+1,LINE_NUM,T...);}
#ifdef LOCAL_DBG
#define dbg(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define dbg(...) 42
#endif

ll mod = 1e9+7;

ll dp[2005] = {0};

ll solve (int rem) {
	if (dp[rem] != -1) {
		return dp[rem];
	} else if (rem==0) {
		dp[rem] = 1;
	} else if (rem > 0 && rem < 3) {
		dp[rem] = 0;
	} else {
		dp[rem] = 0;
		for (int x = 3; x <= rem; x++) {
			dp[rem] += solve (rem-x);
			dp[rem] %= mod;
		}
	}
	return dp[rem];
}

int main () {
	fastCin;
	CL (dp,-1);
	int s;
	cin >> s;
	cout << solve (s) << "\n";
	return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int D; cin >> D;
    vector<ll> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<ll>> s(D, vector<ll>(26));
    rep(i, D)rep(j, 26) cin >> s[i][j];
    vector<ll> t(D);
    rep(i, D) cin >> t[i];
    ll ans = 0;
    vector<ll> last(26);
    ll M; cin >> M;
    ll date, q;
    rep(k, M) {
        cin >> date >> q;
        t[date-1] = q;
        last.clear();
        last.resize(26);
        ans = 0;
        for (int d = 1; d <= D; d++) {
            for (int i = 1; i <= 26; i++) {
                if (t[d-1] == i) {
                    ans += s[d-1][i-1];
                    last[i-1] = d;
                }
                else {
                    ans -= c[i-1]*(d-last[i-1]);
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vi a;

int main(){
	cin>>n>>m;
	a=vi(n);
	int s=0,t=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		s+=a[i];
	}
	for(int i=0;i<n;i++) if(a[i]*4*m>=s) t++;
	cout<<(t>=m?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

//約数列挙
vll d;
void enum_divisor(ll n) {
   for(ll i = 1; i * i <= n; i++) {
       if(n % i == 0) {
           d.push_back(i);
           if(i * i != n) d.push_back(n / i);
       }
   }
   sort(all(d));
   return;
}

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

    enum_divisor(m);

    ll ans = 1;
    for(ll p : d) {
        if(n <= m / p) ans = max(ans, p);
    }

    cout << ans << endl;

    return 0;
}



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


int main() {
    std::string s;
    std::cin >> s;
    if (s.find('a') != std::string::npos && s.find('b') != std::string::npos && s.find('c') != std::string::npos) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    return 0;
}

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

int main () {
    char s[101], p[101], t[201];
    
    scanf("%s", &s);
    scanf("%s", &p);
    
    strcpy(t, s);
    strcat(t, s);
    
    if (strstr (t, p) != NULL)
        printf("Yes\n");
    else
        printf("No\n");
        
    return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pairll=pair<ll,ll>;
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll npr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

bool IsPrime(ll num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int main() {
	int n; cin>>n;
	int h[n]; for(int &hi: h) cin>>hi;
	int score[n]={0};

	for(int i=0; i<n; i++) {
		if(i==0) continue;
		if(i==1) {
			score[i] = score[i-1] + ABS(h[i]-h[i-1]);
			continue;
		}
		score[i] = min(score[i-1]+ABS(h[i]-h[i-1]), score[i-2]+ABS(h[i]-h[i-2]));
	}
	cout << score[n-1] << endl;
}

Measured memory_bytes: 1024
#include <stack>
#include <cstdio>

using namespace std;
stack<int> y;
stack<int> x;
bool c[52][52];

int check(int arg[][52], int i, int j);

int main(void){
	int w, h;
	int arg[52][52];
	int i, j, si, sj;
	int count;


	scanf("%d %d", &w, &h);
	while(w!=0 && h!=0){
		count=0;
		for(i=0; i<=h+1; i++){
			for(j=0; j<=w+1; j++){
				if(i==0 || i==(h+1) || j==0 || j==(w+1)){
					c[i][j]=false; 
					arg[i][j]=0;
				}
			}
		}

		for(i=1; i<=h; i++){
			for(j=1; j<=w; j++){ 
				scanf("%d",&arg[i][j]);
				if(arg[i][j])
					c[i][j]=true;
				else
					c[i][j]=false;
			}
		}

		for(i=1; i<=h; i++){
			for(j=1; j<=w; j++){
				if(arg[i][j]==1 && c[i][j]==true){
					y.push(i);
					x.push(j);
					while(!x.empty() && !y.empty()){
							si=y.top();sj=x.top();
							y.pop();x.pop();
							check(arg, si, sj);

					}
					count++;

				}
			}
		}


		printf("%d\n", count);
		scanf("%d %d", &w, &h);
	}

	return 0;
}

int check(int arg[][52], int i, int j){
	int flag = 0;

	c[i][j]=false;
	if(arg[i+1][j]==1 && c[i+1][j]==true){
		c[i+1][j]=false;
		y.push(i+1);
		x.push(j);
		flag = 1;
	}
	if(arg[i][j+1]==1 && c[i][j+1]==true){
		c[i][j+1]=false;
		y.push(i);
		x.push(j+1);
		flag = 1;
	}
	if(arg[i-1][j]==1 && c[i-1][j]==true){
		c[i-1][j]=false;
		y.push(i-1);
		x.push(j);
		flag = 1;
	}
	if(arg[i][j-1]==1 && c[i][j-1]==true){
		c[i][j-1]=false;
		y.push(i);
		x.push(j-1);
		flag = 1;
	}
	if(arg[i-1][j+1]==1 && c[i-1][j+1]==true){
		c[i-1][j+1]=false;
		y.push(i-1);
		x.push(j+1);
		flag = 1;
	}
	if(arg[i-1][j-1]==1 && c[i-1][j-1]==true){
		c[i-1][j-1]=false;
		y.push(i-1);
		x.push(j-1);
		flag = 1;
	}
	if(arg[i+1][j+1]==1 && c[i+1][j+1]==true){
		c[i+1][j+1]=false;
		y.push(i+1);
		x.push(j+1);
		flag = 1;
	}
	if(arg[i+1][j-1]==1 && c[i+1][j-1]==true){
		c[i+1][j-1]=false;
		y.push(i+1);
		x.push(j-1);
		flag = 1;
	}

	if(flag)
		return 1;
	else
		return 0;
}

Measured memory_bytes: 1080
A, B, K = map(int, input().split())
G = 0
while A % B != 0:
	A, B = B, A % B
else:
	G = B
list = []
for i in range(1, G + 1, 1):
	if G % i == 0:
		list.append(i)
print(G // list[K - 1])


Measured memory_bytes: 2940
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	aa := make([]int, n)

	broken := 0
	prev := 0
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
		if aa[i] == prev+1 {
			prev++
			continue
		}
		broken++
	}

	if prev == 0 {
		broken = -1
	}

	fmt.Println(broken)

	writer.Flush()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

int main(){
    int n,m;
    while(cin>>n>>m){
        vi a(n);
        forn(i,n) cin>>a[i];
        int sum  = accumulate(all(a),0);
        sort(a.rbegin(), a.rend());
        double cut = sum /(double) (4*m);

        int cnt = 0;
        for(auto x: a){
            if(x>=cut) ++cnt;
        }

        string out = cnt>=m ? "Yes" : "No";
        cout<<out<<endl;
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i=0;i<n;i++){
        cin >> h.at(i);
    }
    bool can =true;
    for (int i=n-2;i>=0;--i){
        if(h.at(i)-h.at(i+1)>1)
            can = false;
        if(h.at(i)-h.at(i+1)==1){
            h.at(i)-=1;
        }
    }
    if (can)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 640