akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// ordered_set X;
// *X.find_by_order(i) = ith largest element (counting from zero)
// X.order_of_key(k) = number of items in X < k (strict lt)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll answer(vll& dists, ll X, int k, vll& partials) {
    int N = sz(dists);

    ll total = (N+k)*X;
    for (int i=0;i<N;i+=k) {
        int left = i;
        int right = min(i+k, N);

        int ind = (i/k)+1;
        ll coeff = 0;
        if (ind == 1) coeff = 5;
        else coeff = 2*ind + 1;

        total += coeff*(partials[right] - partials[left]);
        if (total > 1e18) return 1e18;
    }

    return total;
}

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

    int N;
    ll X;
    cin >> N >> X;

    vll dists(N);
    for (int i=0;i<N;i++) cin >> dists[i];

    sort(all(dists));
    reverse(all(dists));
    
    vll partials(N+1, 0);
    for (int i=0;i<N;i++) partials[i+1] = partials[i] + dists[i];

    ll best_total = 2000000000000000000LL;
    for (int k=1;k<=N;k++) {
        ll cur_total = answer(dists, X, k, partials);
        best_total = min(cur_total, best_total);
    }
    cout << best_total << endl;

    

    return 0;
}


Measured memory_bytes: 6296
#include<bits/stdc++.h>
using namespace std;
long long x[1000010],y[1000010];
#define int long long
signed main(){
  
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  cin>>s;
  
  if(s=="a" || s=="i" || s=="u" || s=="e" || s=="o") cout<<"vowel"<<'\n';
  else cout<<"consonant"<<'\n';
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll                  long long
#define pb                  push_back
#define mp                  make_pair
#define in                  insert
#define sz(a)               (int)(a).size()
#define all(x)              (x).begin(), (x).end()
#define fore(i,a,b)         for(ll i=a; i<b; i+=1)
#define forr(i,a)           for(ll i=a; i>=0; i-=1)
#define forg(i,b,e,c)       for (ll i=(ll)b; i<(ll)e; i+=c)
#define ford(i,a)           for(auto i=a.begin(); i!=a.end(); i++) 
#define F first
#define S second
#define min3(a, b, c)       min(min(a, b), c)
#define min4(a, b, c, d)    min(min(a, b), min(c, d))
#define max3(a, b, c)       max(max(a, b), c)
#define max4(a, b, c, d)    max(max(a, b), max(c, d))
#define endl "\n"
#define printV(arr)         fore(x,0,sz(arr)) cout << arr[x] <<" "; cout<<endl;
#define setp(x)             fixed<<setprecision(x)
 
 
using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll,ll> lll;
typedef vector<ii> vii;
typedef vector<lll> vlll;
typedef pair<string, int> si;
typedef pair<int, string> is;
typedef vector<string> vs;
const int MAX=1e5+10;
const int MOD=1000000009;
const double pi=acos(-1);
const int dx[]={0,1,-1,0};
const int dy[]={-1,0,0,1};
const int dxc[]={0,1,-1,0,1,1,-1,-1};
const int dyc[]={-1,0,0,1,-1,1,-1,1};
 
ll min(ll a, ll b){
    if(a>b) return b;
    return a;
}
ll max(ll a, ll b){
    if(a>b) return a;
    return b;
}
 
ll gcd(ll a, ll b){
    while(b!=0){
        a%=b;
        swap(a,b);
    }
    return a;
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}
bool isPrime(ll n){
    if(n<=1) return false;
    if(n==2) return true;
    if(n%2==0) return false;
    for(ll i=3; i*i<=n; i+=2){
        if(n%i==0) return false;
    }
    return true;
}
 
set<ll> gen(ll n){
    set<ll> divs;
    for(ll i=1; i*i<=n; i++){
        if(n%i==0){
            divs.insert(i);
            divs.insert(n/i);
        }
    }
    return divs;
}
 
map<ll, int> fact(ll n){
    map<ll, int> F;
    for(ll p = 2; p*p <= n; p++){
        while(n%p == 0){
            F[p]++;
            n /= p;
        }
    }   
    if(n > 1) F[n]++;
    return F;
}
 
ll sum(ll n){
    return (n*(n+1))/2;
}
 
ll binaryExp(ll a, ll b, ll c){
    if(b==0) return 1;
    if(b%2==0){
        ll temp=binaryExp(a,b/2,c);
        return (temp*temp)%c;
    }
    else{
        ll temp=binaryExp(a,b-1,c);
        return (temp*a)%c;
    }
}
 
bool isPal(string& cad){
    int p1=sz(cad)-1;
    fore(i,0,sz(cad)/2){
        if(cad[i]!=cad[p1]) return false;
        p1--;
    }
    return true;
}

double dis(double x1,double y1, double x2, double y2){
    double ff=pow(x2-x1,2)+pow(y2-y1,2);
    return sqrt(ff);
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n; cin>>n;
    string cad; cin>>cad;
    int rr=0;
    fore(i,0,n){
        if(cad[i]=='R') rr++;
    }
    int res=0;
    fore(i,0,n){
        if(cad[i]=='W' and rr>0){
            rr--;
            res++;
        }
        else if(cad[i]=='R') rr--;
    }
    cout<<res<<endl;


    return 0;
}

Measured memory_bytes: 3756
import time
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)


# 何も考えずに書いてみたやつ これ一番早いじゃん・・・
def fib_org(n):
    if n in (0, 1):
        return 1

    count = 3
    prevprev = 1
    prev = 2
    while count <= n:
        tmp = prevprev + prev
        prevprev = prev
        prev = tmp
        count += 1

    return prev


# 教科書通りの再起のfib
def fib(n):
    if n == 0 or n == 1:
        return 1
    return fib(n - 2) + fib(n - 1)

# def fib2(n):
#     if n == 0 or n == 1:
#         return 1
#     if
#     return fib(n - 2) + fib(n - 1)


N = int(input())
F = [0 for i in range(N + 1)]


def fib_memo(n):
    if n == 0 or n == 1:
        F[n] = 1
    if F[n] != 0:
        return F[n]
    F[n] = fib_memo(n - 2) + fib_memo(n - 1)
    return F[n]


# start = time.time()
# print('case1: original fib calculator')
# print('result:{}'.format(fib_org(N)))
# elapsed_time = time.time() - start
# print("elapsed_time:{0}[sec]".format(elapsed_time))

# start = time.time()
# print('case2: base fib calculator')
# print('result:{}'.format(fib(N)))
# elapsed_time = time.time() - start
# print("elapsed_time:{0}[sec]".format(elapsed_time))

# start = time.time()
# print('case3: memo fib calculator')
# print('result:{}'.format(fib_memo(N)))
# elapsed_time = time.time() - start
# print("elapsed_time:{0}[sec]".format(elapsed_time))

# 以下提出用
print(fib_org(N))



Measured memory_bytes: 5632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ss  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define present(container, element) (container.find(element) != container.end())
#define ss  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(c) c.begin(), c.end()
#define pb push_back
#define mp make_pair
#define mod (1000000000 + 7)
#define inf (1e10+9)
#define fi first
#define se second
#define MAXN   1000001 
typedef long long ll;
using namespace std;
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> new_set;

long long fastpow(long long n, long long x, long long m){
	
    long long ret = 1;
    
    while(x){
    if(x&1) (ret*=n)%=m;
    x>>=1;
    (n*=n)%=m;
    }
  
 return ret;
}
ll add(ll a,ll b){
	return((a%mod)+(b%mod))%mod;
}
ll prod(ll a,ll b){
	a%=mod;
	b%=mod;
	return ((a%mod)*(b%mod)%mod);
}
int main()
{
	ss
    ll a,b,c,d;
    cin>>a;
    string s;
    set<string> se;
    while(a--){
    	cin>>s;
    	se.insert(s);
	}
	cout<<(int)se.size()<<endl;
    
    
    
    
   
    return  0;
}

Measured memory_bytes: 19244
import numpy as np

s = str(input())
ans = np.array([])

for i in s:
    if i == '0':
        ans = np.append(ans,'0')
    elif i =='1':
        ans = np.append(ans,'1')
    elif i == 'B':
        if len(ans) >0:
            ans = ans[:-1]
        else:
            pass

ans = ''.join(map(str,ans))
print(ans)

Measured memory_bytes: 12392
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
bool is_palindrom(string s) {
	string t = s;
	reverse(s.begin(), s.end());
	return s == t;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	string s;
	cin >> s;
	int n = s.size();
	string t = s.substr(0, (n - 1) / 2);
	string k = s.substr((n + 3) / 2 - 1);
	if (is_palindrom(s) && is_palindrom(t) && is_palindrom(k)) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
 	return 0;
}


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

int u[60], v[60], w[60], l = 0;

void set(int a, int b, int c){
	u[l] = a;
	v[l] = b;
	w[l] = c;
	l++;
}

int power(int a, int N){
	if(N == 0){
		return 1;
	}
	else if(N % 2 == 0){
		return power(a * a, N / 2);
	}
	else{
		return a * power(a, N - 1);
	}
}

int rest(int *dig, int K, int s){
	int ans = 0, i;
	for(i = s + 1; i < K; i++){
		ans += dig[i] * power(3, i);
	}
	return ans;
}

int main(){
	int L, K, N, i, j;
	int dig[20];
	scanf("%d", &L);
	for(i = 0; L != 0; i++, L /= 3){
		dig[i] = L % 3;
	}
	K = i;
	N = K + 1;
	for(i = 0; i < K - 1; i++){
		for(j = 0; j < 3; j++){
			set(i, i + 1, j * power(3, i));
		}
	}
	for(i = 0; i < K; i++){
		if(dig[i] > 0){
			set(i, N - 1, rest(dig, K, i));
		}
		if(dig[i] > 1){
			set(i, N - 1, rest(dig, K, i) + power(3, i));
		}
	}
	printf("%d %d\n", N, l);
	for(i = 0; i < l; i++){
		printf("%d %d %d\n", u[i] + 1, v[i] + 1, w[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll n, m, c;
        cin >> n >> m >> c;
        ll b[m];
        rep(i, m) cin >> b[i];
        ll a[n][m];
        ll ans = 0;
        rep(i, n) {
            rep(j, m) {
                cin >> a[i][j];
            }
        }
        rep(i, n) {
            ll temp = 0;
            rep(j, m) {
                temp += a[i][j] * b[j];
            }
            if (temp + c > 0) {
                ans++;
            }
        }
        cout << ans << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void) {
 int n, m, tmp1, tmp2, ans=0;
 cin >> n >> m;
 int left=-1, right=10000000;
 for(int i=0;i<m;i++) {
   cin >> tmp1 >> tmp2;
   if(left < tmp1) left = tmp1;
   if(right > tmp2) right = tmp2;
 }
 ans = max(right-left+1, 0);
 cout << ans << endl;
}

Measured memory_bytes: 256
def check_sort(alist):
    check = None
    for i in range(n-1):
        if alist[i] > alist[i+1]:
            check = [i]
            break
    for i in range(1,n):
        if alist[i] < alist[i-1]:
            temp = i
            break
    for i in range(1,n):
        if alist[i] < alist[i-1]:
            if alist[i] < alist[temp]:
                temp = i
    if check is not None:
        check.append(temp)
    return check
n = int(input())
raw_in = input().split()
alist = [int(x) for x in raw_in]
check_max = alist[0]
check_id = 0
status = check_sort(alist)
if status is None:
    print("YES")
else:
    alist[status[0]], alist[status[1]] = alist[status[1]], alist[status[0]]
    if check_sort(alist) is None:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 38384
# coding: utf-8
line = input().rstrip().split()

A = int(line[0])
B = int(line[1])
C = int(line[2])
D = int(line[3])

if A <= C:
    if B<= C:
        print(0)
    else:
        if B<= D:
            print(B-C)
        else:
            print(D-C)
else:
    if A <= D:
        if B <= D:
            print(B-A)
        else:
            print(D-A)
    else:
        print(0)

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

for i in range(K):
    B=[0]*(N+1)
    for j in range(N):
        l=max(0,j-A[j])
        r=min(N-1,j+A[j])
        B[l]+=1
        B[r+1]-=1
    for j in range(1,N):
        B[j]=B[j]+B[j-1]
    ok=True
    for j in range(N):
        if B[j]!=N:
            ok=False
            break
    if ok:
        print(*B[:N])
        exit()
        
    A=B.copy()
print(*A[:N])

Measured memory_bytes: 169832
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100009];
int b[100009];
int c[100009];
long long dpb[100009];
int check1(int x)
{
    int l=-1,r=n,mid;
    while(r-l>1)
    {
        mid=(l+r)/2;
        if(c[mid]>x)
            r=mid;
        else
            l=mid;
    }
    if(l!=-1&&c[l]>x)return l;
    else return r;
}
int check2(int x)
{
    int l=-1,r=n,mid;
    while(r-l>1)
    {
        mid=(l+r)/2;
        if(b[mid]>x)
            r=mid;
        else
            l=mid;
    }
    if(l!=-1&&b[l]>x)return l;
    else return r;
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        cin>>b[i];
    for(int i=0;i<n;i++)
        cin>>c[i];
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    for(int i=0;i<n;i++)
    {
        int x=b[i];
       dpb[i]=n-check1(x);
       if(i>0)
       dpb[i]=dpb[i-1]+dpb[i];
    }
    long long ans=0;
    for(int i=0;i<n;i++)
    {
       int x=a[i];
       int y=check2(x);
       long long ans1=dpb[n-1]-dpb[y-1];
       ans=ans+ans1;
    }
    cout<<ans;
}


Measured memory_bytes: 2812
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int  n = sc.nextInt();   
    int[] a = new int[n - 1];
    int[] ans = new int[n + 1];
    for(int i = 0;i < n - 1;i++){
      a[i] = sc.nextInt();
      ans[a[i]]++;
    }
    for(int j = 1;j <= n;j++){
      System.out.println(ans[j]);
    }
  }
}

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

int main() {
  int n;
  cin >> n;
  int a;
  cin >> a;
  int b;
  cin >> b;
  if (n*a > b) {
    cout << b << endl;
  } else {
    cout << n*a << endl;
  }
  
}

Measured memory_bytes: 256
#include<iostream>
using namespace std ;
#define ll long long int
#include<vector>
#include<cstring>
ll pow(ll a ,ll b)
{

    if(b==0)
        return 1 ;
    ll c = pow( a, b/2) ;
    c= c*c ;
    if(b%2==1)
        c*= a ;
    return  c ;
}


vector<pair< ll ,ll > >  pr( ll  i )
{
    ll v = i ;
    vector<ll> aa ;
    ll ini = 1 ;
    aa.push_back( 0) ;
    while(i!=0)
    {


if( i%2==1)
{
        vector<ll> values ;
for( auto j :  aa)
{

    values.push_back( j+ ini) ;
}

aa.insert( aa.end() ,  values.begin() , values.end()) ;


}
i/=2 ;

        ini= ini*2 ;



    }
    vector<pair< ll ,ll > > ans ;
    for(auto j :  aa)
    {
        if(j==0 || j== v)
            continue ;
        ans.push_back(  make_pair( j ,  v^j)) ;
     
     
    }
return ans ;



}
int main()
{

    ll  n ;
        cin>> n ;
    ll arr[n][n] ;

    for(int i = 0 ;i < n ;i++)
    {

        for(ll j =0;j < n ;j++)
            cin>>arr[i][j] ;
    }


    ll cost [pow(2 , n) ] ;
    memset(cost ,  0 , sizeof(cost)) ;
    for( ll i =0 ;i< pow(2, n)  ;i++)
    {
        ll val  = i ;

        vector<ll> values ;
        ll ini = 0 ;
        ll sum = 0;
        while( val!=0 )
        {
            if(val%2==1)
            {

                for(auto is :  values )
                {
                    sum += arr[ini][is] ;


                }
                values.push_back( ini ) ;
            }

            val/=2 ;
            ini++ ;
        }
        

        cost[i] =sum ;
    }

    ll dp[pow(2, n)]  ;
    
    memset(dp ,  0 , sizeof(dp)) ;


 for( ll i =1 ;i<pow(2, n)  ;i++)
 {
     vector<pair<ll,ll>>  doi =  pr( i) ;
      ll maxn = cost[i] ;
      for(auto j :  doi)
      {
          maxn = max( maxn , dp[j.first ]+ dp[j.second]) ;

      }

      dp[i] = maxn ;


 }
 cout<<dp[pow(2,  n)-1] <<endl ; 



}


Measured memory_bytes: 4288
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)

int main()
{
    int N;
    cin >> N;
    long long A[110];
    rep(i, 0, N)
    {
        cin >> A[i];
    }
    long long max = 0;
    rep(i, 0, N)
    {
        rep(r, 0, N)
        {
            if (i == r)
            {
                continue;
            }
            long long d = abs(A[i] - A[r]);
            if (d > max)
            {
                max = d;
            }
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
//17:23-17:25
//17:29-18:00
//9:33-10:04
const ll ALP='z'-'a'+1,MAX_Q=2e5;
ll N,Q;
string s;
char t[MAX_Q],d[MAX_Q];
bool C(ll i,ll f){
    REP(j,Q){
        if(t[j]==s[i]){
            if(d[j]=='L'){
                i--;
            }else{
                i++;
            }
            if(i<0 || i>=N){
                break;
            }
        }
    }
    if(f==0 && i<0){
        return true;
    }
    if(f==1 && i>=N){
        return true;
    }
    return false;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>Q>>s;
    REP(i,Q){
        cin.ignore();
        cin>>t[i]>>d[i];
    }
    ll ans=N;
    ll l=-1,r=N;
    while(r-l>1){
        ll m=(l+r)>>1;
        if(C(m,0)){
            l=m;
        }else{
            r=m;
        }
    }
    ans-=l+1;
    l=-1;
    r=N;
    while(r-l>1){
        ll m=(l+r)>>1;
        if(C(m,1)){
            r=m;
        }else{
            l=m;
        }
    }
    ans-=N-r;
    cout<<ans<<endl;
}


Measured memory_bytes: 976
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n; std::vector<int> x(n), y(n), h(n);
	std::vector<std::vector<std::pair<int, int>>> X(101), Y(101);
	for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> h[i];
	
	for(int i = 0; i < 101; i++) {
		for(int j = 0; j < 101; j++) {
			for(int l = 0; l < n; l++) {
				int H = std::abs(x[l] - i) + std::abs(y[l] - j) + h[l];
				
				bool f = true;
				for(int k = 0; k < n; k++) {
					f &= std::max(0, H - std::abs(x[k] - i) - std::abs(y[k] - j)) == h[k];
				}
				
				if(f) {
					cout << i << " " << j << " " << H << endl;
					return 0;
				}
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int n, p[1010], x[1010];
    cin >> n;
    REP(i, n - 1)
    cin >> p[i + 2];
    REP(i, n)
    cin >> x[i + 1];

    p[1] = 0;

    V g[1010];
    int cn[1010];
    memset(cn, 0, sizeof(cn));
    REP(i, n - 1)
    {
        g[p[i + 2]].push_back(i + 2);
        cn[p[i + 2]]++;
    }

    V s;

    while (true)
    {
        bool ok = true;
        for (int i = 1; i <= n; i++)
        {
            if (cn[i] == 0)
            {
                cn[i]--;
                cn[p[i]]--;

                s.push_back(i);
                ok = false;
                break;
            }
        }

        if (ok)
            break;
    }

    int dp[1010];

    for (int i : s)
    {
        int d[1010][5050];

        memset(d, -1, sizeof(d));

        for (int j = 0; j <= x[i]; j++)
            d[0][j] = 0;

        int sum = 0;

        for (int j = 0; j < g[i].size(); j++)
        {
            sum += x[g[i][j]] + dp[g[i][j]];
            for (int k = 0; k <= x[i]; k++)
            {
                bool check = false;
                if (k - x[g[i][j]] >= 0 && d[j][k - x[g[i][j]]] >= 0)
                    d[j + 1][k] = max(d[j + 1][k], x[g[i][j]] + d[j][k - x[g[i][j]]]), check = true;
                if (k - dp[g[i][j]] >= 0 && d[j][k - dp[g[i][j]]] >= 0)
                    d[j + 1][k] = max(d[j + 1][k], dp[g[i][j]] + d[j][k - dp[g[i][j]]]), check = true;
            }
        }

        if (d[g[i].size()][x[i]] < 0)
        {
            cout << "IMPOSSIBLE" << endl;
            return 0;
        }
        dp[i] = sum - d[g[i].size()][x[i]];
    }

    cout << "POSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 20352
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
typedef mp::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n;i>0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;


int main()
{
    int a,b;
    cin>>a>>b;
    cout<<(24+a+b)%24<<endl;
    return 0;
}


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

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  int ans = log(N) / log(K) + 1;
  cout << ans << endl;
}


Measured memory_bytes: 640
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

template<typename T>
struct BIT_{
  int n;
  vector<T> bit;
  BIT_(int n_){
    n = n_;
    bit = vector<T>(n+1, 0);
  }
  void add(int a, T w){
    for(int x = a; x < n; x |= (x + 1)){
      bit[x] += w;
    }
  }
  T sum(int a){
    T res = 0;
    for(int x = a; x >= 0; x = (x & (x + 1)) - 1){
      res += bit[x];
    }
    return res;
  }
};

typedef struct BIT_<int> BITI;
typedef struct BIT_<long long> BITL;

int main(int argc, char const* argv[])
{
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a;
  vector<ll> ab;
  ll res = 0;
  rep(i, n){
    ll x;
    cin >> x;
    x -= k;
    if(i > 0)x += a[i - 1];
    a.pb(x);
    ab.pb(x);
    if(x >= 0)res++;
  }
  sort(a.begin(), a.end());
  vector<int> c = vector<int>(n, 0);
  BITI biti(n);
  rep(i, n){
    c[i] = lower_bound(a.begin(), a.end(), ab[i]) - a.begin();
  }
  rep(i, n){
    res += biti.sum(c[i]);
    biti.add(c[i], 1);
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 4964
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<int,int> Q;
typedef pair<int,Q> P;
 
int main(){
    int n,m,a;
 
    while(cin >> n >> m >> a , n | m | a){
	vector<P> v;
	int h,p,q;
	for(int i = 0 ; i < m ; i++){
	    cin >> h >> p >> q;
	    v.push_back(P(h,Q(p,q)));
	}
	sort(v.begin(),v.end(),greater<P>());
 
	for(int i = 0 ; i < (int)v.size() ; i++){
	    if(v[i].second.first == a) a = v[i].second.second;
	    else if(v[i].second.second == a) a = v[i].second.first;
	}
	cout << a << endl;
    }
 
    return 0;
}

Measured memory_bytes: 3028
#include<bits/stdc++.h>
using namespace std;
     
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define double long double
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007  
#define mod2 998244353  
#define pi 3.14159265358979323846 

int solve(){
    int n;
    cin>>n;
    cout<<(n/500)*1000+((n%500)/5)*5;
    return 0;
}   
     
signed main(){
    IOS;
    //freopen("input.txt", "r" , stdin);
    //freopen("output4.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        cout<<"\n";
      // cout<<" * "<<t<<"\n";
    }
//    return 0;
} 

Measured memory_bytes: 256
n, q = map(int, input().split())
s = list(input())
num = [0] * n
count = 0
for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        count += 1
    num[i + 1] = count
for i in range(q):
    l, r = map(int, input().split())
    ans = num[r - 1] - num[l - 1]
    print(ans)

Measured memory_bytes: 12116
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) FOR(i,0,n)
 
int main(){
	
	string s;cin >> s;
	rep(i,s.size()-1)
	{
		if(s[i] == 'A' and s[i+1]=='C')
		{
			cout << "Yes" <<endl;
			return 0;
		}
	}
	cout << "No" <<endl;
	
}

//cout << ans << endl;

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

using namespace std;

#define mod 1000000007LL
int main() {
	long long int N, W;
	cin >> N >> W;
	vector<long long int>D( N + 1, LLONG_MAX / N / 6 );
	long long int maxnum = LLONG_MAX / 6;
	for( size_t i = 0; i < N; i++ ) {
		cin >> D[i];
		maxnum = min( maxnum, D[i] );
	}
	sort( D.begin(), D.end() );
	long long int ans = 0;
	long long int initw = 0;
	for( long long int index = 0; initw <= W &&index <= N; index++ ) {
		vector<long long int>dp( W + 1 );
		dp[initw]++;

		for( size_t i = index + 1; i <= N; i++ ) {
			for( int j = W; j >= D[i]; j-- ) {
				dp[j] += dp[j - D[i]];
				dp[j] %= mod;
			}
		}
		for( int i = W; i > W - D[index] && i >= 0; i-- ) {
			ans += dp[i];
			ans %= mod;
		}
		initw += D[index];
	}
	if( N == 1 ) {
		ans = 1;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define mod 163577857
#define w(t) int t; cin>>t;while(t--)
void solve() {

}
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt" , "r", stdin);
   // freopen("output.txt" , "w", stdout);
#endif

    int a , b, c, k;
    cin >> a >> b >> c >> k;
    int sum = 0;

    int cnt = 0;
    while (1) {
        while (a > 0) {
            cnt += 1;
            sum++;
            a--;
            if (cnt == k)break;


        }
        if (cnt == k)break;


        while (b > 0) {
            cnt += 1;
            b--;
            if (cnt == k)break;

            //sum++;
        }
        if (cnt == k)break;
        while (c > 0) {
            c--;
            sum--;
            cnt += 1;
            if (cnt == k)break;

        }
        if (cnt == k)break;


    }
    cout << sum << "\n";



    return 0;
}


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

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define MP make_pair
#define PB push_back

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

//最大公約数
LL gcd(LL n, LL m) {
	if (m == 0)return n;
	return gcd(m, n%m);
}

//最小公倍数
LL lcm(LL n, LL m) {
	LL g = gcd(n, m);
	return n / g * m;
}

int main() {
	LL x, y;
	cin >> x >> y;
	cout << gcd(x, y) << endl;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,srt,end) for (long long i = (srt); i<(long long)(end); i++)
typedef long long ll;
ll N,A,B;
int main(){
    cin>>N>>A>>B;
    ll syo=N/(A+B);
    ll amari=N%(A+B);
    ll ans=0;
    //場合分け必要
    if(amari>=A)ans=A*syo+A;
    if(amari<A)ans=A*syo+amari;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
using namespace std;

int main(){
    double r;
    cin>>r;
    cout<<fixed<<setprecision(6);
    cout<<r*r*M_PI<<" "<<r*2*M_PI<<endl;
}


Measured memory_bytes: 3284
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int mod = 998244353;
const int MAXN = 2 * 105000;

class SegmentTree {
private: 
  const long long INF = 1e18;
  vector<long long> tree;
  int n;
public:
  void init(int sz) {
    n = 1;
    while (n < sz) {
      n *= 2;
    }
    tree.assign(2 * n, -INF);
  }

  // l, r are in [0, n - 1]
  long long getMax(int l, int r) {
    l = n + l; r = n + r;
    long long res = -INF;
    
    while (l <= r) {
      if (l & 1) {
        res = max(res, tree[l]);
        l++;
      }
      if (r % 2 == 0) {
        res = max(res, tree[r]);
        r--;
      }
      l /= 2; r /= 2;
    }

    return res;
  }

  // pos is in [0, n - 1]
  void update(int pos, long long val) {
    pos = n + pos;
    tree[pos] = val;
    pos /= 2;
    while (pos >= 1) {
      tree[pos] = max(tree[pos * 2], tree[pos * 2 + 1]);
      pos /= 2;
    }
  }
};

int n;
vector < pair<int, int> > v;
long long dp[MAXN][2];
set < pair<int, int> > st;
long long upTo[MAXN];
SegmentTree tree;


int main() { 

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int from, to;
    scanf("%d %d", &from, &to);
    to = from + to - 1;
    v.push_back({from, to});
  }
  sort(all(v));

  tree.init(n);

  for (int i = n - 1; i >= 0; i--) {
    upTo[i] = v[i].second;
    if (i == n - 1) {
      dp[i][0] = 1;
      dp[i][1] = 1;
    } else {  
      auto it = st.lower_bound({v[i].second + 1, -123});
      if (it != st.begin()) {
        it--;
        int r = it->second;
        upTo[i] = max(upTo[i], tree.getMax(i, r));
      }
      dp[i][1] = (dp[i + 1][0] + dp[i + 1][1]) % mod;

      it = st.upper_bound({upTo[i], 123123123});
      if (it != st.end()) {
        int pos = it->second;
        dp[i][0] = (dp[pos][0] + dp[pos][1]) % mod;
      } else {
        dp[i][0] = 1;  
      }
    }
    tree.update(i, upTo[i]);
    st.insert({v[i].first, i});

    // cerr << dp[i][0] << " " << dp[i][1] << endl;
  }

  long long ans = (dp[0][0] + dp[0][1]) % mod;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 19952
class priorityQueue {
  constructor() {
    this.keys = [];
    Number.prototype.parentIdx = function() { return Math.ceil(this/2 - 1); };
    Number.prototype.leftIdx = function() { return this * 2 + 1; };
    Number.prototype.rightIdx = function() { return this * 2 + 2; };
  }

  insert(key) { this.heapIncrease(this.keys.push(key) - 1); }

  heapIncrease(idx) {
    const keys = this.keys;
    for (let i=idx, p=idx.parentIdx(); i > 0 && keys[i] > keys[p]; i=p, p=i.parentIdx()) {
      keys[p] = [keys[i], keys[i] = keys[p]][0];
    }
  }

  extract() {
    const res = this.keys[0];
    this.keys[0] = this.keys.pop();
    this.maxHeapify(0);
    return res;
  }

  maxHeapify(idx) {
    const keys = this.keys, n = keys.length;
    const innerMaxHeapify = (i) => {
      let left, right, largest = i;
      left = i.leftIdx();
      right = i.rightIdx();
      if (left < n && Number(keys[left]) > Number(keys[largest])) largest = left;
      if (right < n && Number(keys[right]) > Number(keys[largest])) largest = right;
      if (largest != i) {
        keys[largest] = [keys[i], keys[i] = keys[largest]][0];
        innerMaxHeapify(largest);
      }
    };
    innerMaxHeapify(idx);
  }
}

(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  lines.pop();
  const queue = new priorityQueue();
  let str = '';
  lines.forEach(function(cmd) {
    switch(cmd.charAt(0)) {
      case 'i': queue.insert(Number(cmd.split(' ')[1])); break;
      case 'e': str += `${queue.extract()|0}\n`; break;
    }
  });
  process.stdout.write(str);
})();




Measured memory_bytes: 206008
#include<stdio.h>
#include<string.h>
int main(void){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a<c)
    printf("1");
    else
    {
        printf("0");
    }
    
    return 0;
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
a_t = [0]
for i in range(n):
    a_t.append(a[i] + a_t[i])
ans = 0
ans_ = 0
count = 0
count_ = 0
for i in range(1, n + 1):
    if i == 1:
        if a_t[i] >= 0:
            ans += a_t[i] + 1
            count += -(a_t[i]) - 1
    else:
        if a_t[i - 1] + count > 0:
            if a_t[i] + count > 0:
                ans += a_t[i] + count + 1
                count += -(a_t[i] + count) - 1
            if a_t[i] + count == 0:
                ans += 1
                count -= 1
        elif a_t[i - 1] + count < 0:
            if a_t[i] + count < 0:
                ans += -(a_t[i] + count) + 1
                count += -(a_t[i] + count) + 1
            if a_t[i] + count == 0:
                ans += 1
                count += 1
for i in range(1, n + 1):
    if i == 1:
        if a_t[i] <= 0:
            ans_ += -a_t[i] + 1
            count_ += -(a_t[i]) + 1
    else:
        if a_t[i - 1] + count_ > 0:
            if a_t[i] + count_ > 0:
                ans_ += a_t[i] + count_ + 1
                count_ += -(a_t[i] + count_) - 1
            if a_t[i] + count_ == 0:
                ans_ += 1
                count_ -= 1
        elif a_t[i - 1] + count_ < 0:
            if a_t[i] + count_ < 0:
                ans_ += -(a_t[i] + count_) + 1
                count_ += -(a_t[i] + count_) + 1
            if a_t[i] + count_ == 0:
                ans_ += 1
                count_ += 1
print(min(ans, ans_))


Measured memory_bytes: 14340
// ABC44-A.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	cout << min(k, n) * x + max(n - k, 0) * y << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define ll long long
#define LIM 1000000
#define M 1000000007
using namespace std;
ll v[LIM];
int main() {
  ll n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    v[a]++;
  }
  if (v[0] > 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 1; i < n; i++) {
    if (v[i] != 2 && v[i] != 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = 1;
  for (int i = 0; i < n / 2; i++) {
    ans = ans * 2 % M;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include <algorithm>
#include <array>
#include <cmath>
#include <cstring>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

int gcd(int x, int y) {
  x = std::abs(x); y = std::abs(y);
  int a = std::max(x,y), b = std::min(x,y);
  int r = a % b;
  while(r!=0){ a = b; b = r; r = a % b; }
  return b;
}

long long lcm(int x, int y) {
  return (long long)x * y / gcd(x, y);
}

int main(void) {
  int N, M;
  scanf("%d %d", &N, &M);
  std::vector<std::pair<int, int>> cities(M), sorted(M);
  for (int i = 0; i < M; ++i) {
    scanf("%d %d", &(cities[i].first), &(cities[i].second));
    sorted[i] = cities[i];
  }
  sort(sorted.begin(), sorted.end());
  int c = 0, n = 0;
  std::vector<std::pair<int, int>> ids(M);
  for (int i = 0; i < M; ++i) {
    if (sorted[i].first != c) {
      c = sorted[i].first;
      n = 0;
    }
    ids[i].first = c; ids[i].second = ++n;
  }
  for (int i = 0; i < M; ++i) {
    std::vector<std::pair<int, int>>::iterator it = std::lower_bound(sorted.begin(), sorted.end(), cities[i]);
    int idx = it - sorted.begin();
    printf("%06d%06d\n", ids[idx].first, ids[idx].second);
  }

  return 0;
}

Measured memory_bytes: 3840
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut dp: Vec<bool> = vec![false; 200020];

    // true: 先手が負け状態
    // 負け状態に遷移させることができれば、勝ち
    dp[0] = true;
    for i in 1..k + 1 {
        let mut make = true;
        for j in 0..n {
            if i >= a[j] && dp[i - a[j]] {
                make = false;
                break;
            }
        }
        dp[i] = make;
    }

    if dp[k] {
        println!("Second");
    } else {
        println!("First");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define REP(n)    for(int i = 0; i < (n); ++i)
#define RREP(n)   for(int i = (n); i >= 0; --i)
#define FOR(m, n) for(int i = (m); i < (n); ++i)
#define SZ(x)       ( (int)(x).size() )
#define BIT(n)      ( 1LL << (n) )
#define EXIST(x)    ( (x).find()		!= (x).end() )
#define DEBUG(n)    cerr << #n << " : " << n << '\n';
#define PB  push_back
#define UB  upper_bound			//k <
#define LB  lower_bound			//k	<= 
#define F   first
#define S   second
#define INF 1.0e9


using namespace std;

typedef long long			ll;
typedef pair<int, int>		pii;
typedef pair<long			long, long long>   pll;
typedef vector<int>			vi;
typedef vector<double>		vd;
typedef vector<long long>   vll
;

template<class T> void chmax(T &	a, const T & b){ if( a < b ) a = b; }
template<class T> void chmin(T &	a, const T & b){ if( a > b ) a = b; }

int r_up(const int a, const int b){ return (a + b - 1) / b; }

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

struct UFT{
  vi	p;
  UFT(){}
  UFT(int N)       { p.resize( N, -1 ); }
  int	par(int a)   { if( p[a] >= 0 ){ p[a]  = par( p[a] ); return p[a]; } return a;  }
  int size(int a)  { return -p[par(a)]; }
  bool	same(int a, int b) { return par(a)	 == par(b); }
  void unite(int	a, int b){
	a													  = par(a);  b = par(b);
	if( a == b ) return;
	if( size(a) < size(b) ) swap(a,b);
	p[a]												 -= size(b);
	p[b]												  = a;
  }
};

int main(){
  cout<<"Christmas";
  int d;cin>>d;
  REP(25-d)
	cout<<" Eve";
  cout<<endl;
  return 0;
}


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

class DisjointSet{
  public:
    vector<int> rank, p;

    DisjointSet(){}
    DisjointSet(int size){
        rank.resize(size, 0);
        p.resize(size, 0);
        for(int i = 0; i < size; i++) makeSet(i);
    }

    void makeSet(int x){
        p[x] = x;
        rank[x] = 0;
    }

    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }
    
    void unite(int x, int y){
        link(findSet(x), findSet(y));
    }

    void link(int x, int y){
        if(rank[x] > rank[y]){
            p[y] = x;
        }else{
            p[x] = y;
            if(rank[x] == rank[y]){
                rank[y]++;
            }
        }
    }

    int findSet(int x){
        if(x != p[x]){
            // path compression
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

#define N 100
double x[N], y[N], z[N], r[N];

struct Edge{
    int from, to;
    double dist;
    Edge() {}
    Edge(int f, int t, double d) : from(f), to(t), dist(d) {}
    bool operator<(const Edge other) const{
        return dist < other.dist;
    }
};

double getDist(int i, int j){
    return sqrt(pow(x[j]-x[i], 2.0) + pow(y[j]-y[i], 2.0) + pow(z[j]-z[i], 2.0));
}

int main(){
    int n;
    while(cin >> n, n){
        for(int i = 0; i < n; i++){
            cin >> x[i] >> y[i] >> z[i] >> r[i];
        }

        DisjointSet uf(n);
        vector<Edge> res;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                double d = getDist(i,j);
                if(d > r[i]+r[j])    res.push_back(Edge(i,j,d-r[i]-r[j]));
                else                 uf.unite(i,j);
            }
        }

        sort(res.begin(), res.end());

        double ans = 0;
        for(int i = 0; i < res.size(); i++){
            if(!uf.same(res[i].from, res[i].to)){
                uf.unite(res[i].from, res[i].to);
                ans += res[i].dist;
            }
        }

        cout << fixed << setprecision(3) << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3344
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<bitset>

#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define rep2d(n,m) Srep(n) Lrep(j,0,m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    cout << ((a * b) % 2 == 0 ? "Even" : "Odd") << endl;
}


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

 
const int INF = (int) 1e9;

struct point {
	int x;
    int y;
	point() : x(0), y(0) {}
};
 
struct fenwick_tree {
	int n;
	unordered_map<int, int> F;
 
    fenwick_tree() : n(INF) {
        F.rehash((int) 1e5);
    }
	void upd(int i, int x) {
		for (; i < n; i |= i + 1)
			F[i] = max(F[i], x);
	} 
	int get(int i) {
		int res = 0;
		for (; i >= 0; i &= i + 1, --i)
			res = max(res, F[i]);
		return res;
	}
};
 
 
bool cmp(point a, point b) {
    return make_pair(a.x, a.y) < make_pair(b.x, b.y); 
}
 
 
int main() {
#ifdef NICK
	freopen("input.txt", "r", stdin);
#else

#endif
    point start, finish;
    int n;
    cin >> start.x >> start.y;
    cin >> finish.x >> finish.y;
    cin >> n;
    point p[n];
    for (int i = 0; i < n; i++) {
        cin >> p[i].x >> p[i].y;
    }
    if (start.x > finish.x)
        swap(start, finish);
    if (start.y > finish.y) {
        finish.y = 2 * start.y - finish.y;
        for (int i = 0; i < n; i++) {
            p[i].y = 2 * start.y - p[i].y;
        }
    }
    vector<point> a;
    for (int i = 0; i < n; i++) {
        if (start.x <= p[i].x && p[i].x <= finish.x && start.y <= p[i].y && p[i].y <= finish.y)
            a.emplace_back(p[i]);
    }
    fenwick_tree dp;
    sort(a.begin(), a.end(), cmp);
    for (int i = 0; i < (int)a.size(); ++i)
        dp.upd(a[i].y, dp.get(a[i].y) + 1);
    int cur = dp.get(INF);
    long double ans = 0;
    if (cur != min(finish.y - start.y, finish.x - start.x) + 1)
        ans = 100.0 * (finish.y + finish.x - start.y - start.x) - 20.0 * cur + 5 * M_PI * cur;
    else
        ans = 100.0 * (finish.y + finish.x - start.x - start.y) - 20.0 * cur + 5 * M_PI * (cur - 1) + 10 * M_PI;
    cout << fixed << setprecision(13) << ans << "\n";
	return 0;
}


Measured memory_bytes: 68384
//#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, beg, end) for (int i = (beg); i < (end); i++)

bitset<100000001> notPrime;
ll next(int i)
{
    while (notPrime[i] != 0)
    {
        i++;
    }
    return i;
}
unordered_map<ll, bool> pt;
bool isPrime(ll num)
{
    if (pt.find(num) != pt.end())
    {
        return pt[num];
    }
    if (num == 1)
    {
        pt.insert({num, false});
        return false;
    }
    if (num == 2 || num == 3)
    {
        pt.insert({num, true});
        return true;
    }
    if (num % 6 != 1 && num % 6 != 5)
    {
        pt.insert({num, false});
        return false;
    }
    if (num < 100000000 && notPrime[num] == 0)
    {
        pt.insert({num, true});
        return true;
    }
    else if (num < 100000000 && notPrime[num] == 1)
    {
        pt.insert({num, false});
        return false;
    }

    ll t = sqrtl(num);
    for (ll i = 5; i < t + 1; i++)
    {
        if (num % i == 0 || num % (i + 2) == 0)
        {
            pt.insert({num, false});
            return false;
        }
    }
    pt.insert({num, true});
    return true;
}

int main()
{
    long long b = 100000000;

    long long s = sqrtl(b) + 1;

    for (ll i = 2; i <= s; i++)
    {
        if (!notPrime[i])
        {
            for (ll j = i; j <= b / i; j++)
            {
                notPrime[i * j] = 1;
            }
        }
    }

    ll n;
    cin >> n;
    s = n / 2;
    ll ans = 0;
    if (n > 100000000)
    {
        if (isPrime(n))
        {
            cout << 1 << endl;
            return 0;
        }
    }

    for (ll i = 2; i <= n; i = next(i + 1))
    {
        ll k = i;
        while (k <= n)
        {
            ll d = n / k;
            if (k * d == n)
            {
                ans++;
            }
            else
            {
                break;
            }

            n = d;
            k *= i;
        }
        if (n > 100000000)
        {
            if (isPrime(n))
            {
                ans++;
                break;
            }
        }
    }

    cout << ans << endl;
}

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

if(n>=400 and n<600):print(8)
elif(n>=600 and n<800):print(7)
elif(n>=800 and n<1000):print(6)
elif(n>=1000 and n<1200):print(5)
elif(n>=1200 and n<1400):print(4)
elif(n>=1400 and n<1600):print(3)
elif(n>=1600 and n<1800):print(2)
elif(n>=1800 and n<2000):print(1)


Measured memory_bytes: 8996