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

const int mod=1000000007;
int t[200002],f[200001],n,cnt,g[200001];
struct node{int v,x;}a[200001];
struct node2{int po,x;}b[200001];
struct node3{int l,r;}c[200001],d[200001];

bool cmp(node a,node b) {return a.x<b.x;}
bool cmp2(node2 a,node2 b) {return a.x<b.x;}
bool cmp3(node3 a,node3 b) {return a.l<b.l;}
int getmax(int a,int b) {return a>b?a:b;}
int getmin(int a,int b) {return a<b?a:b;}
void add(int x,int val) {for (; x<=n; x+=(x&-x)) t[x]=getmax(t[x],val);}
int query(int x) {int ans=0; for (; x; x-=(x&-x)) ans=getmax(ans,t[x]); return ans;}
void Add(int x,int val) {for (; x<=cnt+1; x+=(x&-x)) t[x]=(t[x]+val)%mod;}
int Query(int x) {int ans=0; for (; x; x-=(x&-x)) ans=(ans+t[x])%mod; return ans;}

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++) scanf("%d%d",&a[i].x,&a[i].v),b[i].po=i,b[i].x=a[i].v;
	sort(b+1,b+1+n,cmp2);
	for (int i=1; i<=n; i++) a[b[i].po].v=i;
	sort(a+1,a+1+n,cmp);
	memset(t,0,sizeof(t)); cnt=0;
	for (int i=n; i; i--) add(a[i].v,i),f[i]=query(a[i].v);
	memset(t,0,sizeof(t));
	for (int i=1; i<=n; i++) add(n-a[i].v+1,n-i+1),g[i]=n-query(n-a[i].v+1)+1;
	for (int i=1; i<=n; i++) d[i].l=g[i],d[i].r=f[i]; 
	sort(d+1,d+1+n,cmp3);
	for (int i=n,l=n; i; i--) {if (i!=n) f[i]=f[i+1]; else f[i]=n+1; while (l&&d[l].l==i) f[i]=getmin(f[i],d[l].r),l--;}
	for (int i=1; i<=n; i++) if (f[d[i].l]>=d[i].r) c[++cnt]=d[i];
	memset(t,0,sizeof(t)); Add(1,1);
	for (int i=1,l=1,r=1,x; i<=n; i++)
	{
		while (r<cnt&&c[r+1].l<=i) r++;
		while (l<=cnt&&c[l].r<i) l++;
		x=Query(r+1)-Query(l-1); x=(x%mod+mod)%mod; Add(r+1,x);
	}
	int ans=Query(cnt+1)-Query(cnt); ans=(ans%mod+mod)%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8704
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <functional>
using namespace std;

typedef long long ll;

ll x[200001];
int n;

int main() {
	cin >> n;
	cin >> x[0];
	ll a;
	ll sum = x[0];
	for (int i = 1; i < n; i++) {
		cin >> a;
		sum += a;
		x[i] = x[i - 1] + a;
	}
	ll res = 1000000000000000000;
	for (int i = 0; i < n - 1; i++) {
		a = abs(2 * x[i] - sum);
		if (res >= a) {
			res = a;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include <string>
using namespace std;
int main()
{
  unsigned long long a,b;
  cin >> a >> b;
  int count = 1;
  for(;;){
    if(a*2 <= b){
      count++;
      a *= 2;
    } else{
      cout << count << '\n';
      break;
    }
  }
  return 0;
}


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

#define inf 0x3f3f3f3f
#define pi acos(-1)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
template<class T> bool mmin(T &a,T b){return (a>b ?(a=b,true):false);};
template<class T> bool mmax(T &a,T b){return (a<b ?(a=b,true):false);};


bool cmp(pair<pair<string,int>,int> a,pair<pair<string,int>,int> b){
	for(int i=0;i<min(a.fi.fi.size(),b.fi.fi.size());i++){
		if(a.fi.fi[i]!=b.fi.fi[i])
			return a.fi.fi[i]<b.fi.fi[i];
	}
	if(a.fi.fi.size()!=b.fi.fi.size())
		return a.fi.fi.size()<b.fi.fi.size();
	return a.fi.se>b.fi.se;
}
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<pair<pair<string,int>,int>> A(n);
	for(int i=0;i<n;i++){
		cin >> A[i].fi.fi >> A[i].fi.se;
		A[i].se=i+1;
	}
	sort(all(A),cmp);
	for(int i=0;i<n;i++)
		cout << A[i].se << '\n';
#ifdef LOCAL_DEFINE
	cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}




















Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
        sc.Scan()
        i, e := strconv.Atoi(sc.Text())
        if e != nil {
                panic(e)
        }
        return i
}

func main() {
        sc.Split(bufio.ScanWords)
        n := nextInt()
        var a []int
        for i := 0; i < n; i++ {
                a = append(a, nextInt())
        }

        ans := 0
        for i := 1; i < n; i++ {
                if a[i-1] > a[i] {
                        ans += a[i-1] - a[i]
                        a[i] = a[i-1]
                }
        }

        fmt.Printf("%d\n", ans)
}

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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> d(n + 1);
  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    d[i] = d[i - 1] + l;
    if(d[i]>x){
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << n + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define PDD pair<LD,LD>
#define eps 1e-9
#define HH1 402653189
#define HH2 1610612741

LL x, sum;

int main () {
	
	scanf("%lld", &x);
	
	FOE(i, 1, x) {
		sum += i;
		if (sum >= x) {
			printf("%d\n", i);
			return 0;
		}
	}
	
	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    VEC(int) A(N), Suffix(N + 1, 0);
    READVEC(A);
    FORD(i, N - 1, -1) {
        Suffix[i] = max(A[i], Suffix[i + 1]);
    }

    int curMax = 0;
    FOR(i, 0, N) {
        cout << max(curMax, Suffix[i + 1]) << "\n";
        curMax = max(curMax, A[i]);
    }

    return 0;
};


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, m, s, t;
    cin >> n >> m >> s >> t;
    --s;
    --t;

    array<vector<vector<pair<int64_t, int64_t>>>, 2> adjs;
    adjs[0].resize(n);
    adjs[1].resize(n);
    for (auto _ : irange(0L, m)) {
        int64_t u, v, a, b;
        cin >> u >> v >> a >> b;
        --u;
        --v;

        adjs[0][u].emplace_back(v, a);
        adjs[0][v].emplace_back(u, a);
        adjs[1][u].emplace_back(v, b);
        adjs[1][v].emplace_back(u, b);
    }

    array<int64_t, 2> start{s, t};
    vector<vector<int64_t>> costs(
            2, vector<int64_t>(n, numeric_limits<int64_t>::max()));
    for (auto i : irange(0L, 2L)) {
        priority_queue<pair<int64_t, int64_t>> q;
        q.emplace(0, start[i]);
        costs[i][start[i]] = 0;

        while (!q.empty()) {
            auto cost = -q.top().first;
            auto v = q.top().second;

            q.pop();

            if (cost > costs[i][v]) {
                continue;
            }

            for (const auto& edge : adjs[i][v]) {
                auto u = edge.first;
                auto new_cost = cost + edge.second;
                if (new_cost < costs[i][u]) {
                    costs[i][u] = new_cost;
                    q.emplace(-new_cost, u);
                }
            }
        }
    }

    vector<int64_t> ans(n + 1, numeric_limits<int64_t>::max());
    for (auto i : irange(0L, n) | reversed) {
        ans[i] = min(ans[i + 1], costs[0][i] + costs[1][i]);
    }

    for (auto i : irange(0L, n)) {
        cout << 1000000000000000L - ans[i] << "\n";
    }
}

Measured memory_bytes: 18928
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

template <typename T>
using vec1 = vector<T>;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

template <typename T>
vec1<T> cin2vec(size_t size)
{
    vec1<T> vec1;
    for (size_t i = 0; i < size; ++i) {
        vec1.push_back(cin2var<T>());
    }
    return vec1;
}

int main()
{
    const int    N(cin2var<int>());
    const string S(cin2var<string>());
    string       line(S);
    line.resize(N);
    int count = 0;
    while (true) {
        const auto iteOX(line.find("OX"));
        const auto iteXO(line.find("XO"));
        if (iteOX == string::npos && iteXO == string::npos) break;
        const auto iteMin(min(iteOX, iteXO));
        line = line.substr(iteMin + 2);
        ++count;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3336
#include "bits/stdc++.h"
using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

#define mod 1000000007

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}



signed main(void){
	int n,a,b;
	cin >> n>>a>>b;
	int ans = n / (a + b)*a+ min(n % (a + b),a);
	print(ans);
	return 0;
}

Measured memory_bytes: 256
#create date: 2020-06-13 21:00

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    s = ns()
    print(s[:3])

if __name__ == "__main__":
    main()

Measured memory_bytes: 9120
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	vector<bool> primes(100100, true);
	primes[0] = false; primes[1] = false;
	for(int i = 2; i<100101; ++i){
		if(primes[i]){
			for(int k = 2; i*k<100101; ++k){
				primes[i*k]  = false;
			}
		}
	}
	vector<bool> islike(100100, false);
	for(int i = 3; i<100101; i += 2){
		if(primes[i]&& primes[(i+1)/2]){
			islike[i] = true;
		}
	}
	vector<int> count(100100, 0);
	REP(i,100100){
		count[i] = count[i-1] + (islike[i]);
	}
	int Q; cin>>Q;
	rep(i,Q){
		int l,r; cin>>l>>r;
		cout<<count[r]-count[l-1]<<endl;
	}
	return 0;
}

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

int main(){
	string a;
	int i,n,ans;
	cin>>a;
	n=a.size();
	ans=n;
	
	for(i=1;i<n;i++)
		if(a[i]!=a[i-1])
			ans=min(ans,max(i,n-i));
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#define rep(i,N) for(int i=0; i<N;i++)
using namespace std;

int main(){
    int K;
    cin>>K;
    int b=0;
    if(7%K==0){
        cout <<1<<endl;
        return 0;
    }
    for(int i=1;i<=7;i++){
        if((((int)pow(10,i)-1)/9)*7>=K){
            b=i;
            break;
        }
    }
    if((((int)pow(10,b)-1)/9*7)%K==0){
        cout<<b<<endl;
        return 0;
    }
    int m1=(((int)pow(10,b)-1)/9*7)%K;
    int m2=((int)pow(10,b)*7)%K;
    int N=pow(10,8);
    int count=b+1;
    rep(i,N){
        m1=(m1+m2)%K;
        if(m1==0){
            cout<<count<<endl;
            return 0;
        }
        m2=(m2*10)%K;
        count++;
    }
    cout <<-1<<endl;

    return 0;
}

Measured memory_bytes: 4060
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<cctype>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define pq priority_queue
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
#define init(x) memset(x,0,sizeof(x))
bool p[100005];
int q,cnt[100005];
int l,r;
int main()
{
    ios::sync_with_stdio(false);
    init(cnt);
    for (int i=0;i<100005;++i) p[i]=1;
    p[0]=p[1]=0;
    for (int i=2;i<100005;++i){
    	if (p[i]){
    		for (int j=i*2;j<100005;j+=i){
    			if (j>=100005) break;
    			p[j]=0;
			}
		}
	}
	for (int i=0;i<100005;++i){
		if (i%2==0) cnt[i]=cnt[i-1];
		else{
			cnt[i]=cnt[i-1]+(p[i]&&p[(i+1)/2]);
		}
	}
    cin>>q;
    rep(t,q){
    	cin>>l>>r;
    	cout<<cnt[r]-cnt[l]+(l%2&&p[l]&&p[(l+1)/2])<<endl;
	}
    return 0; 
}

Measured memory_bytes: 1152
from math import *

n = int(input())

mn = n

i1 = 0
i2 = n

for i in range(1,ceil(sqrt(n))+1):
    
    if(n%i==0):
        k = n//i
        if(abs(k-i)<mn):
            i1 = i
            i2 = k
            
ans = i1 + i2 -2

print(ans)

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    int ai = a[n - 1];
    ld h = (ld)ai / 2;
    int aj = a[n - 1];
    int dist = a[n - 1];
    rep(i, n - 1){
        if(abs(h - a[i]) < dist){
            dist = abs(h - a[i]);
            aj = a[i];
        }
    }
    cout << ai << " " << aj << endl;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;


int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> a(n, vector<int>(m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
			a[i][j]--;
		}
	}

	int ans = BIG_NUM;
	vector<bool> isHeld(m, true);
	for (int i = 0; i < m;) {
		map<int, int> cnt;

		for (int j = 0; j < n; j++) {
			for (int k = 0; k < m; k++) {
				if (isHeld[a[j][k]]) {
					cnt[a[j][k]]++;
					break;
				}
			}
		}

		int ma = 0;
		for (int j = 0; j < m; j++) {
			ma = max(ma, cnt[j]);
		}

		ans = min(ans, ma);
		for (int j = 0; j < m; j++) {
			if (cnt[j] == ma) {
				isHeld[j] = false;
				i++;
			}
		}

		
	}

	cout << ans << endl;
}

Measured memory_bytes: 3920
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> c(h, vector<int>(w, 0));
    vector<vector<int>> d(h, vector<int>(w, 0));
    REP(i,h) REP(j,w) {
        cin >> c[i][j];
        d[i][j] = c[i][j];
    }
    ll ans = 0;
    REP(i,h-1) {
        REP(j,w) {
            if (c[i][j]%2 == 1) {
                ans++;
                c[i+1][j]++;
                c[i][j]--;
            }
        }
    }
    REP(i,w-1) {
        if (c[h-1][i]%2 == 1) {
            ans++;
            c[h-1][i+1]++;
            c[h-1][i]--;
        }
    }

    std::cout << ans << endl;

    REP(i,h-1) {
        REP(j,w) {
            if (d[i][j]%2 == 1) {
                printf("%d %d %d %d\n", i+1, j+1, i+2, j+1);
                ans++;
                d[i+1][j]++;
                d[i][j]--;
            }
        }
    }
    REP(i,w-1) {
        if (d[h-1][i]%2 == 1) {
            printf("%d %d %d %d\n", h, i+1, h, i+2);
            ans++;
            d[h-1][i+1]++;
            d[h-1][i]--;
        }
    }
    return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a, b, x;
	cin >> a >> b >> x;
	if (a > x) {
		cout << "NO" << endl;
   }
	 
    else if ((x - a) <= b) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

long long gcd(long long x, long long y) {
	if(y == 0) return x;
	else return gcd(y, x % y);
}

int main() {
	int n; cin >> n;
	long long t[n];
	for(int i = 0; i < n; i++) cin >> t[i];
	long long g = t[0];
	for (int i = 1; i < n; i++)
	{
		g = g / gcd(g, t[i]) * t[i];
	}
	cout << g << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

    Scanner sc = new Scanner(System.in);
    long[] arr = new long[(int)1e5];

    public static void main(String[] args){
        new Main().run();
    }

    void run() {
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();

        int s = 0;
        while (true) {
            if (s == 0) {
                if (a.length() == 0) {
                    System.out.println("A");
                    return;
                }
                if (a.charAt(0) == 'a') {
                    s = 0;
                } else if (a.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                a = a.substring(1, a.length());

            } else if (s == 1) {
                if (b.length() == 0) {
                    System.out.println("B");
                    return;
                }
                if (b.charAt(0) == 'a') {
                    s = 0;
                } else if (b.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                b = b.substring(1, b.length());
            } else {
                if (c.length() == 0) {
                    System.out.println("C");
                    return;
                }
                if (c.charAt(0) == 'a') {
                    s = 0;
                } else if (c.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                c = c.substring(1, c.length());
            }
        }

    }


}


Measured memory_bytes: 21972
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
int main(){
	cin>>n;
	cout << 0 << endl;
	string ret;
	cin >> ret;
	bool ch;
	if(ret == "Vacant"){
		return 0;
	}
	else ch = (ret == "Male");
	
	cout << (n-1)/2 << endl;
	cin >> ret;
	bool ch2;
	if(ret == "Vacant"){
		return 0;
	}
	else ch2 = (ret == "Male");
	int L,R,en;
	bool C;
	if(((n-1)/2)%2 == (ch^ch2)){
		L = (n+1)/2;
		R = n-1;
		en = n;
		C = ch;
	}
	else{
		L = 1;
		R = (n-3)/2;
		en = (n-1)/2;
		C = ch2;
	}
	while(R-L >= 1){
		int mid = (L+R)/2;
		cout << mid << endl;
		cin >> ret;
		if(ret == "Vacant"){
			return 0;
		}
		bool ch3 = (ret == "Male");
		if((en-mid)%2 == (ch3^C)){
			R = mid-1;
		}
		else{
			L = mid+1;
		}
	}
	cout << L << endl;
	cin >> ret;
	assert(ret == "Vacant");
	return 0;
}

Measured memory_bytes: 876
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0; i<n; i++){
            a[i]=sc.nextInt();
        }
        int ans1=0;
        int ans2=0;
        for(int j=0; j<n; j++){
            if(a[j]%2==0){
                ans1++;
                if((a[j]%3==0)||(a[j]%5==0)){
                    ans2++;
                }
            }
        }
        if(ans1==ans2){
            System.out.println("APPROVED");
        }
        else{
            System.out.println("DENIED");
        }
        sc.close();
    }
}

Measured memory_bytes: 21844
from collections import deque
h, w = map(int,input().split())
graph = []
finished = [[False for _ in range(w)] for _ in range(h)]
y = [0, 0, 1,-1]
x = [1,-1, 0, 0]
q = deque([])
for i in range(h):
    a = input()
    graph.append(a)
    for j in range(w):
        if a[j] == "#":
            q.append((i,j,0))
while q:
    c = q.popleft()
    for i in range(4):
        nh = c[0]+y[i]
        nw = c[1]+x[i]
        if nh < 0 or nh >= h or nw < 0 or nw >= w or graph[nh][nw] == "#" or finished[nh][nw]:continue
        finished[nh][nw] = True
        q.append((nh,nw,c[2]+1))
print(c[2])

Measured memory_bytes: 138588
#include <iostream>

using namespace std;

int main()
{
	int a, b, c, t = 0, Ans;

	cin >> a >> b >> c;

	while (t < 60)
	{
		int time = t * 60 + c;

		if (time % (a + b) >= 0 && time % (a + b) <= a)
		{
			Ans = t * 60 + c;

			break;
		}

		t++;

		if (t == 60) { Ans = -1; }
	}

	cout << Ans << endl;

	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

int main(){
		int n,i,j;
		long long a[2001],b[2001][2]={0},ans=0,k;
		scanf("%d%lld",&n,&k);
		for(i=0;i<n;i++)scanf("%lld",&a[i]);
		for(i=0;i<n;i++){
				for(j=0;j<n;j++){
						if(a[i]>a[j]){
								b[i][0]++;
								if(i<j)b[i][1]++;
						}
				}
		}
		for(i=0;i<n;i++)ans=(b[i][0]*((k*(k-1)/2)%1000000007)+b[i][1]*k+ans)%1000000007;
		printf("%lld\n",ans);
		return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
/* 値を入れ替える関数 */
void swap (int *x, int *y) {
    int temp;    // 値を一時保存する変数
    
    temp = *x;
    *x = *y;
    *y = temp;
}

/***
 * pivotを決め、
 * 全データをpivotを境目に振り分け、
 * pivotの添え字を返す
 ***/
int partition (int array[], int left, int right) {
    int i, j, pivot;
    i = left;
    j = right + 1;
    pivot = left;   // 先頭要素をpivotとする
    
    do {
        do { i++; } while (array[i] < array[pivot]);
        do { j--; } while (array[pivot] < array[j]);
        // pivotより小さいものを左へ、大きいものを右へ
        if (i < j) { swap(&array[i], &array[j]); }
    } while (i < j);
    
    swap(&array[pivot], &array[j]);   //pivotを更新
    
    return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
    int pivot;
    
    if (left < right) {
        pivot = partition(array, left, right);
        quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
        quick_sort(array, pivot+1, right);
    }
}

int main(void){
    int i,j,k;
    int N,A[200001],B[200001];
    
    scanf("%d",&N);
    for(i = 0;i < N;i++){
        scanf("%d",&A[i]);
        B[i] = A[i];
    }
    
    quick_sort(B,0,N-1);
    
    for(i = 0;i < N;i++){
        int answer = 0;
        if(B[N-1] > A[i]){
            printf("%d\n",B[N-1]);
        }else{
            printf("%d\n",B[N-2]);
        }
    }
    
    return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
struct p{int l;int r;}a[1000000];
bool cmp(p xx,p yy){
    return xx.l>yy.l;}
int main(){
    int n,h;
    int c=0;
    scanf("%d%d",&n,&h);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[c++].l);a[c].r=1;
        scanf("%d",&a[c++].l);}
    sort(a,a+c,cmp);
    int sum=0;
    for(int i=0;i<c;i++){
        if(a[i].r==1){sum++;h-=a[i].l;
            if(h<=0){printf("%d",sum);return 0;}}
        else if(a[i].r!=1){
            if(h%a[i].l==0) sum+=h/a[i].l;
            else sum+=h/a[i].l+1;printf("%d",sum);return 0;}}
    return 0; 
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<string>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
 
using namespace std;

int main(){
    int K;  cin >> K;
    string S;   cin >> S;
    int l = S.length();
    if(l <= K)  print(S);
    else    print(S.substr(0,K)+"...");
}

Measured memory_bytes: 3628
x, y = map(int, input().split())
s = [400000, 300000, 200000, 100000]

if x == 1 and y == 1:
    print(sum(s))
elif x <= 3 and y <= 3:
    print(s[x] + s[y])
elif x <= 3:
    print(s[x])
elif y <= 3:
    print(s[y])
else:
    print(0)

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, i;
    cin >> N >> i;
    cout << N - i + 1 << endl;
    return 0;
}


Measured memory_bytes: 3616
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        long n=sc.nextLong();
        long a=sc.nextLong();
		long b=sc.nextLong();
		long s=n/(a+b);
  		long ama=n%(a+b);

  		long ans=s*a;
    
 	if(ama>=a){
    		ans+=a;
    	}else{
     		ans+=ama;
   	 }

    	System.out.println(ans);
    }
}

Measured memory_bytes: 21844
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    Scanner sc = new Scanner(System.in);

    public static final void main(String[] args) {
        Main m = new Main();
        m.init();
        m.solve();
    }

    // ========================================================================= //
    int n, m;
    long[] xs, ys;
    P[] ps;

    public void init() {
        n = sc.nextInt();
        m = sc.nextInt();
        xs = new long[n];
        ys = new long[n];
        ps = new P[n];
        for (int i = 0; i < n; i++) {
            long x = sc.nextLong();
            long y = sc.nextLong();
            xs[i] = x;
            ys[i] = y;
            ps[i] = new P(x, y);
        }
        Arrays.sort(xs);
        Arrays.sort(ys);
    }

    public void solve() {
        long ans = Long.MAX_VALUE;
        for (int i = 0; i < n - 1; i++) {
            long sx = xs[i];
            for (int j = i + 1; j < n; j++) {
                long ex = xs[j];
                for (int k = 0; k < n - 1; k++) {
                    long sy = ys[k];
                    for (int l = k + 1; l < n; l++) {
                        long ey = ys[l];

                        int pnum = 0;
                        for (P p : ps) if (p.x >= sx && p.x <= ex && p.y >= sy && p.y <= ey) pnum++;
                        if (pnum == m) {
                            ans = Math.min(ans, (ex - sx) * (ey - sy));
                        }
                    }
                }
            }
        }
        System.out.println(ans);
    }

    class P {
        long x, y;
        P(long x, long y) {
            this.x = x;
            this.y = y;
        }
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//

ll f(int n, ll x) {
  if (n == 0) return 1;
  ll len = (1LL<<(n+1)) - 3;
  ll num = (1LL<<n) - 1;
  if (x == 1) return 0;
  else if (x <= len + 1) return f(n-1, x-1);
  else if (x == len + 2) return num + 1;
  else if (x <= 2*(len+1)) return num + 1 + f(n-1, x-len-2);
  else return 2*num + 1;
}

int main() {
  int n; ll x;
  cin >> n >> x;
  cout << f(n, x) << endl;
}

Measured memory_bytes: 3620
al,ar,bl,br,cl,cr,dl,dr=0,0,0,0,0,0,0,0
while True:
    try:
        le,re=map(float,input().split())
        if le<0.2:
            dl+=1
        if le>= 0.2 and le<0.6:
            cl += 1
        if le >= 0.6 and le<1.1:
            bl += 1
        if le >= 1.1:
            al += 1
        if re<0.2:
            dr+=1
        if re>= 0.2 and re<0.6:
            cr += 1
        if re >= 0.6 and re<1.1:
            br+= 1
        if re >= 1.1:
            ar += 1
    except:
        print(al,ar)
        print(bl,br)
        print(cl,cr)
        print(dl,dr)
        break


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pipipii = pair<ll, pair<int, pii>>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    ll ans = 0;
    int a = 0;
    for(int i = 0; i < s.size(); ++i){
        if(s[i] == 'A') ++a;
        else if(i != s.size()-1 && s[i] == 'B' && s[i+1] == 'C') ans += a, ++i;
        else a = 0;
    }
    cout << ans << "\n";
    return 0;
}

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

int main()
{
  int n,c,k; cin>>n>>c>>k;
  int t[n];
  rep(i,n) {
    cin >> t[i];
  }
  sort(t, t+n);


  int ans = 0;
  for (int i =0; i < n;) {
    ++ans;
    int start = i;
    while (i < n && t[i] - t[start] <= k && i - start < c) {
      ++i;
    }
  }

  cout << ans << endl;
  return 0;
}

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

int main() {
	int X,Y;
	cin>>X>>Y;
	vector<string> C(X);
	rep(i,X)cin>>C[i];
	rep(i,X){
		cout<<C[i]<<endl;
		cout<<C[i]<<endl;
	}
}

Measured memory_bytes: 256
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 
const ll inf = (ll)(1e9);
vector<pll> a;
ll n;
ll dp[3001][3001];

ll recurse(ll idx, ll rem) {
  if(idx == n or rem <= 0) return 0;
  ll &ans = dp[idx][rem]; 
  if(ans != -1) return ans;
  ans = 0;
  ans = a[idx].ss + recurse(idx + 1, rem - a[idx].ff);
  ans = max(ans, recurse(idx+1, rem));
  return ans;
}
int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll t;
  cin >> n >> t;
  a.resize(n);
  for(ll i = 0; i < n; i++) {
    cin >> a[i].ff >> a[i].ss;
  }
  sort(all(a));
  memset(dp, -1, sizeof dp);
  ll ans = -inf;
  for(ll i = 0; i < n; i++) {
    ans = max(ans, a[i].ss + recurse(i+1, t - a[i].ff));
  }
  cout << ans << endl;
  return 0;
} //good night.

Measured memory_bytes: 70784
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(vec, s) vec.find(s) != vec.end()

int main() {
	set<int> S;
	int q;
	cin >> q;
	Rep(i, q) {
		int n, x;
		cin >> n >> x;
		if (n == 0) {
			S.insert(x);
			cout << S.size() << endl;
		}
		else if (n == 1) {
			if (S.find(x) != S.end()) cout << 1 << endl;
			else cout << 0 << endl;
		}
		else if (n == 2) {
			S.erase(x);
		}
	}
	return 0;
}


Measured memory_bytes: 12360
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
	    int n = sc.nextInt();
		int m = sc.nextInt();
		
		int k = n;
		int t = 0;
		
		while(true) {
			int ans = 4*k+2*t;
			if(ans == m) {
				System.out.println("Yes");
				return;
			} else {
				k--;
				t++;
			}
			
			if(k == -1) {
				System.out.println("No");
				return;
			}
		}

		//String s = sc.next();
		//long n = sc.nextLong();
		//double n = sc.nextDouble();
		
		//for(int i = 0; i < ; i++)

		//System.out.println("Yes");
		//System.out.println("No");
		

	}
}


Measured memory_bytes: 35784
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
typedef pair<int, bool> sP;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;



void solve() {
	int x, y; cin >> x >> y;
	int score = 0;
	if (x <= 3)score += 100000 * (4 - x);
	if (y <= 3)score += 100000 * (4 - y);
	if (x == 1 && y == 1)score += 400000;
	cout << score << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(9);
	//init();
	solve();
	//stop
		return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>


using namespace std;



int main()
{
	bool points[5][5][4];
	for (int i = 0; i < 5; ++i)
		for (int j = 0; j < 5; ++j)
			for (int k = 0; k < 4; ++k)
				points[i][j][k] = false;

	for (int i = 0; i < 9; ++i)
	{
		int y = i/2;
		if (i%2 == 0)
		{
			for (int j = 0; j < 4; ++j)
			{
				int e;
				scanf("%1d", &e);
				if (e)
					points[y][j][1] = points[y][j+1][3] = true;
			}
		}
		else
		{
			for (int j = 0; j < 5; ++j)
			{
				int e;
				scanf("%1d", &e);
				if (e)
					points[y][j][2] = points[y+1][j][0] = true;
			}
		}
	}

	int x, y;
	x = 1;
	y = 0;
	int dir = 1;
	int dx[] = { 0, 1, 0, -1 };
	int dy[] = { -1, 0, 1, 0 };
	char* ds = "URDL";
	putchar(ds[dir]);
	while (!(x == 0 && y == 0))
	{
		if (points[y][x][(dir+3)%4])
			dir = (dir+3)%4;
		else if (points[y][x][dir])
			;
		else if (points[y][x][(dir+1)%4])
			dir = (dir+1)%4;
		else
			dir = (dir+2)%4;

		x += dx[dir];
		y += dy[dir];
		putchar(ds[dir]);
	}
	putchar('\n');

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int N;
int P[200000+1];
int seq[200000+1];

int main(void){
    map<int,int> ord;
    GI(N);
    REP(i,N){
        GI(P[i]);
        ord[P[i]-1] = i;
    }
    int ans = 0;
    REP(i,N){
        if(i==0)
            seq[i]=1;
        else{
            if(ord[i-1] < ord[i])
                seq[i] = seq[i-1]+1;
            else
                seq[i] = 1;
        }
        ans = max(ans, seq[i]);
    }
    printf("%d\n",N-ans);
    return 0;
}


Measured memory_bytes: 11264
# coding: utf-8
n = int(input())

from collections import defaultdict
d = defaultdict(int)
maxnum = 0
maxli = []

for _ in range(n):
    s = input()
    d[s] += 1
    if d[s] > maxnum:
        maxnum += 1
        maxli = [s]
    elif d[s] == maxnum:
        maxli.append(s)
    
maxli.sort()

for l in maxli:
    print(l)

Measured memory_bytes: 100484
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, x, y;
	cin >> n >> x >> y;

	vector<int> distances(2 * n);
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			int shortest = min(j - i, abs(x - i) + abs(y - j) + 1);
			++distances[shortest];
		}
	}

	for (int i = 1; i < n; ++i) {
		cout << distances[i] << "\n";
	}

	return 0;

}

Measured memory_bytes: 256
#import collections
N = int(input())
res = 1e9
for i in range(1,N//2+1):
    A,B = i,N-i
    r = 0
    a,b=str(A),str(B)
    for mystr in [a,b]:
        for j in mystr:
            r += int(j)
    res = min(r,res)
print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
#define debug(x) (cout << "#x = " << (x) << endl)
#define lowbit(x) (x & -x)
#define Set(x, i) memset(x, i, sizeof x)
#define R register
#define For( i, j, k ) for(R int i = (j); i <= (k); ++i)
#define Rep( i, j, k ) for(R int i = (j); i >= (k); --i)
#define Cross( i, j, k ) for(R int i = (j); i; i = (k))
typedef long long ll;
using namespace std;
const ll N = 511;
const ll INF = 5e16;

namespace IO {

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar (x % 10 | 48);
	}

	inline void wrn ( ll x ) { write(x); putchar (' '); }

	inline void wln ( ll x ) { write(x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x); wln (y); }

}

using namespace IO;

namespace Cesare {

	ll n, k, S, a[N], b[N];

	vector <ll> Ve;

	inline int Check ( ll x ) {
		ll cnt = 0, pos = n, C = 0;
		For ( i, 1, n ) b[i] = a[i] % x;
		
		sort(b + 1, b + n + 1);
		
		For ( i, 1, pos ) {
			cnt += b[i], C = b[i];
			for (; C && pos; ) 
				if (C >= x - b[pos]) 
					C -= x - b[pos], --pos;
				else b[pos] += C, C = 0;
		} return cnt <= k;
	}

	inline void Solve() {
		sort(Ve.begin(), Ve.end());
		Rep ( i, Ve.size(), 1 )
			if (Check(Ve[i - 1])) 
				return (void) (wln(Ve[i - 1]));
	}

	int main() {
		n = read(), k = read();
		For ( i, 1, n ) S += a[i] = read();
		for (int i = 1; i * i <= S; ++i) 
			if (S % i == 0) {
			Ve.push_back(i);
			if (i * i != S) Ve.push_back(S / i);
		}
		return Solve(), 0;
	}

}

int main()
{
	return Cesare :: main();
}

/*

*/



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

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

    ll r = 0;
    int s = 0;
    for (int i0 = 0, i1 = 0; i0 < n;) {
        while (i1 < n && (s & a[i1]) == 0) s ^= a[i1++];
        r += i1 - i0;
        s ^= a[i0++];
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h> 
using namespace std;
int main()
{
	int X;
	cin>>X;
	if(X>=400 and X<=599)
	cout<<"8";
	if(X>=600 and X<=799)
	cout<<"7";
	if(X>=800 and X<=999)
	cout<<"6";
	if(X>=1000 and X<=1199)
	cout<<"5";
	if(X>=1200 and X<=1399)
	cout<<"4";
	if(X>=1400 and X<=1599)
	cout<<"3";
	if(X>=1600 and X<=1799)
	cout<<"2";
	if(X>=1800 and X<=1999)
	cout<<"1";
	return 0;
}

Measured memory_bytes: 3632
class Node
  def initialize(index, left, right)
    @index = index
    @parent = -1
    @left = left
    @right = right
    @sibling = -1
  end

  attr_accessor :index, :left, :right, :parent, :sibling
end
class BinaryTree
  def initialize(n)
    @node_list = []
    @visited_node = []
    n.times do |i|
      node_list << Node.new(i, nil, nil)
    end
  end

  def create_node(index, left, right)
    node_list[index].left = left
    node_list[index].right = right
    if left != -1
      node_list[left].sibling = right
      node_list[left].parent = index
    end
    if right != -1
      node_list[right].parent = index
    node_list[right].sibling = left
    end
  end

  def preorder_tree_walk(index)
    visited_node << index
    return if node_list[index].left == -1 && node_list[index].right == -1
    if node_list[index].left != -1
      preorder_tree_walk node_list[index].left
    end
    if node_list[index].right != -1
      preorder_tree_walk node_list[index].right
    end
  end

  def inorder_tree_walk(index)
    return if index == -1
    if node_list[index].left != -1
      inorder_tree_walk node_list[index].left
    end
    visited_node << index
    if node_list[index].right != -1
      inorder_tree_walk node_list[index].right
    end
  end

  def postorder_tree_walk(index)
    return if index == -1
    if node_list[index].left != -1
      postorder_tree_walk node_list[index].left
    end
    if node_list[index].right != -1
      postorder_tree_walk node_list[index].right
    end
    visited_node << index
  end

  def search_root
    node_list.find { |node| node.parent == -1 }
  end

  attr_accessor :node_list, :visited_node
end

n = gets.to_i
tree = BinaryTree.new n
n.times do
  input = gets.split(' ').map(&:to_i)
  tree.create_node input[0], input[1], input[2]
end

tree.preorder_tree_walk tree.search_root.index
puts "Preorder\n #{tree.visited_node.join ' '}"
tree.visited_node = []
tree.inorder_tree_walk tree.search_root.index
puts "Inorder\n #{tree.visited_node.join ' '}"
tree.visited_node = []
tree.postorder_tree_walk tree.search_root.index
puts "Postorder\n #{tree.visited_node.join ' '}"



Measured memory_bytes: 6896
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main (void)
{
	char str1[1200];
	int i = 0;
	scanf("");
	fgets(str1 , 1300 , stdin);
	while(str1[i] != '\0')
	{
		if(str1[i] >= 'a' && str1[i] <= 'z')
		{
			str1[i] -= 32;
		}
		else if(str1[i] >= 'A' && str1[i] <= 'Z')
		{
			str1[i] += 32;
		}
		i++;
	}
	printf("%s" , str1);
 } 


Measured memory_bytes: 2028