akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    LL n,k,s;
    cin >> n >> k >> s;
    if (k == 0) {
        if (s == 1'000'000'000) {
            REP(i,0,n) cout << 1'000'000'000 - 1 << " ";
            cout << endl;
        } else {
            REP(i,0,n) cout << s + 1 << " ";
            cout << endl;
        }
        return;
    }
    if (s != 1'000'000'000) {
        REP(i,0,k) cout << s << " ";
        REP(i,k,n) cout << 1'000'000'000 << " ";
        cout << endl;
    } else {
        REP(i,0,k) cout << 1'000'000'000 << " ";
        REP(i,k,n) cout << 1'000'000'000 - 1 << " ";
        cout << endl;
    }
}

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

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

typedef priority_queue<int> maxHeap;
typedef priority_queue<int, vector<int>, greater<int>> minHeap;
#define endl "\n"
#define int long long
#define MOD 1000000007
#define ump unordered_map
#define pb push_back
#define mp make_pair
#define pie acos(-1)
#define max(x, y) ((x > y) ? x : y)
#define min(x, y) ((x < y) ? x : y)
#define mid(s, e) ((s + (e - s) / 2))

bool test_cases;

struct precompute {
    void compute() {
    }
};

void init(bool k) {
    test_cases = k;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

struct test_cases {
    void test_case(int test) {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        int ans = 0;
        for (int i = 0; i < n - 2; i++) {
            for (int j = i + 1; j < n - 1; j++) {
                for (int k = j + 1; k < n; k++) {
                    int ai = a[i];
                    int aj = a[j];
                    int ak = a[k];
                    if (ai + aj > ak and aj + ak > ai and ak + ai > aj and ai != aj and ai != ak and aj != ak) {
                        ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
};

int32_t main() {
    init(false);
    int tc;
    if (test_cases) {
        cin >> tc;
    } else {
        tc = 1;
    }
    struct precompute l;
    l.compute();
    for (int i = 0; i < tc; i++) {
        struct test_cases o;
        o.test_case(i + 1);
    }
    return 0;
};

Measured memory_bytes: 3608
package main

import(
	"fmt"
)

func main() {
	var inp string
	fmt.Scan(&inp)
	i := 0
	result := true
	var t rune
	for _, c := range inp {
		i += 1
		if i == 1 {
			t = c
		}

		if t != c {
			result = false
			break
		}

	}
	if result == true {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ll n,z,w,A[200001];
    cin>>n>>z>>w;
    rep(i,n) cin>>A[i];
    cout<<max(abs(w-A[n-1]),abs(A[n-2]-A[n-1])*(n!=1))<<"\n";
}


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

int main() {
  
  int a=0;
  string s;
  
  cin >> a;
  cin >> s;
  
  if(a < 3200) {
    
    cout << "red" << endl;
    
  } else if(3200 <= a) {
    
    cout << s << endl;
    
  }
  
  return 0;
  
}

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

using namespace std;
bool hinaarare[4];

int main()
{
    int n;
    cin >> n;
    char cache;
    for(int i = 0; i < n; ++i) {
        cin >> cache;
        switch(cache) {
            case 'P':
               hinaarare[0] = true;
               break;
            case 'W':
               hinaarare[1] = true;
               break;
            case 'G':
               hinaarare[2] = true;
               break;
            case 'Y':
               hinaarare[3] = true;
               break;
        }
    }

    int count = 0;
    for(auto memo : hinaarare) {
        if(memo == true) ++count;
    }

    string output = count == 3 ? "Three\n" : "Four\n";
    cout << output;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) { return b / c - (a - 1) / c; }

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

int main() {
    long long a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b;
}

Measured memory_bytes: 256
#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>;

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;
    sort(begin(s), end(s));
    if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, d[100005];

void f(int p, int q) {
	if(q < d[p]) {
		d[p] = q;
		f(p*10%n, d[p]);
		f((p+1)%n, d[p]+1);
	}
}

int main() {
	cin>>n;
	for(int i=0; i<n; i++) d[i] = 99;
	f(1, 1);
	cout<<d[0];
	return 0;
}

Measured memory_bytes: 3712
# include <cstdio>

int main ( )  {
	int n, m, k ;
	scanf ( "%d%d%d", & n, & m, & k ) ;

	for ( int a = 0 ; a <= n ; ++ a )
		for ( int b = 0 ; b <= m ; ++ b )
			if ( a * m + ( n - a ) * b - a * b == k )  {
				return ! puts ( "Yes" ) ;
			}
	return ! puts ( "No" ) ;
}


Measured memory_bytes: 128
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

a,b,c,d = inpm()

ans = max(a*c,a*d,b*c,b*d)
# if (b <= 0 and d > 0) or (b > 0 and d <= 0):
#     ans = min(abs(a),abs(b)) * min(abs(c),abs(d)) * -1
# else:
#     ans = max(abs(a),abs(b)) * max(abs(c),abs(d))
print(ans)


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

int main() {
	// your code goes here
	int n;
	cin>>n;
	double arr[n];
	memset(arr, 0.0, sizeof(arr));
	for(int i=0;i<n;i++)
		cin>>arr[i];
	vector<vector<double>>dp(n+1, vector<double>(n+1, 0.0));
	dp[0][0]=1.0; // Crucial to remember
	for(int i=1;i<=n;i++)
		dp[0][i]=0;
		
	for(int i=1;i<=n;i++) {
		for(int j=0;j<=i;j++) {
			if(j == 0)
				dp[i][j]=dp[i-1][j]*(1.0-arr[i-1]);
			else
				dp[i][j]=dp[i-1][j]*(1.0-arr[i-1])+dp[i-1][j-1]*arr[i-1];
		}
	}	
	double sum=0.0;
	for(int i=(n+1)/2;i<=n;i++)
		sum+=dp[n][i];
		
	cout<<setprecision(10)<<sum<<endl;	

}

Measured memory_bytes: 70784
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    X = [0]*(N+1)

    for i in range(1,N+1):
        X[i] += A[i-1] + X[i-1]
    ans  = float('INF') 
    for i in range(1,N):
        ans = min(ans,abs(X[N] - 2*X[i]))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 100468
//phoenix




#include <bits/stdc++.h>
using namespace std;


#define spdio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fr(i,j,n) for(ll i=j; i<n; i++)
#define rfr(i,j,n) for(ll i=n-1; i>=0; i--)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a) sort(a,a+n);


typedef long double ld;
typedef long long int ll;


//getline(cin,string);
const ll inf = (ll) 1e18 + 19;



/*
ll solveDp(ll i,ll w[],ll v[],ll n,ll wt,map <ll,map <ll,ll> > &dp) {
    if(i>=n || wt<0)
        return 0;
    if(dp[wt][i])
        return dp[wt][i];
    else if(wt<w[i])
        return dp.insert(mp([wt][i]=solveDp(i+1,w,v,n,wt,dp);
    else
        return dp[wt][i]=max(solveDp(i+1,w,v,n,wt,dp),v[i]+solveDp(i+1,w,v,n,wt-w[i],dp));
}
*/



void bfs(ll k,bool vis[],ll n,vector <ll> v[]) {
    queue <ll> q;
    q.push(k);
    while(!q.empty()) {
        ll node=q.front();
        q.pop();
        cout<<node<<" ";
        vis[node-1]=true;
        fr(j,0,v[node-1].size()) {
            if(vis[v[node-1][j]-1]!=true)
                q.push(v[node-1][j]),vis[v[node-1][j]-1]=true;
        }
    }
}




void dfs(ll k,bool vis[],ll n,vector <ll> v[]) {
    cout<<k<<" ";
    vis[k-1]=true;
    fr(i,0,v[k-1].size()) {
        if(!vis[v[k-1][i]-1])
            dfs(v[k-1][i],vis,n,v);
    }
}




void cazz() {
    ll n,i,j,k,ans=0,f=0,b=1,wt,m=0;
    cin>>n;
    fr(i,1,n+1)
        fr(j,1,n+1)
            fr(k,1,n+1)
                ans+=__gcd(i,__gcd(j,k));
    cout<<ans<<"\n";
    /*cin>>n>>m;
    vector <ll> v[n];
    fr(i,0,m) {
        cin>>j>>k;
        v[j-1].pb(k);
        v[k-1].pb(j);
    }
    cout<<"\n";
    fr(i,0,n) {
        cout<<i+1<<"\t";
        fr(j,0,v[i].size()) {
            cout<<v[i][j]<<" ";
        }cout<<"\n";
    }
    cout<<"\n";
    cin>>k;
    bool vis[n]={};
    bfs(k,vis,n,v);
    cout<<"\n";
    bool vi[n]={};
    dfs(k,vi,n,v);*/
}




int main() {
    spdio;
	cazz();
	return 0;
}



Measured memory_bytes: 3664
program ABC_069_A_i18n
   implicit none
   integer l
   character(100) s
   read(*, *) s
   l = len_trim(s)
   if(l-2 <= 9) then
       write(*, '(a1,i1,a1)') s(1:1), l-2, s(l:l)
   else
       write(*, '(a1,i2,a1)') s(1:1), l-2, s(l:l)
   end if
end program ABC_069_A_i18n

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

#define show(x) cerr << #x << " = " << x << endl ;
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'

const int N = 2e5+1;
long long tree[4*N];
vector < vector < int > > v(N , vector < int >(3));
void update(int l , int r , int pos , int index , long long val)
{
	if(l > r) return;
	else if(l == r)
	{
		tree[pos] = val;
		return ;
	}
	int mid = l + (r - l)/2;
	if(index <= mid) update(l , mid , 2*pos+1 , index , val);
	else update(mid + 1 , r , 2*pos+2 , index , val);
	tree[pos] = max(tree[2*pos+1] , tree[2*pos+2]);
	// cerr <<l << " "<< r << " "<< pos << " "<< tree[pos] << endl;
	return ;
}
long long query(int ql , int qr , int l , int r , int pos)
{
	if(l > r || qr < l || ql > r) return 0;
	else if (ql <= l && qr >= r) return tree[pos];
	int mid = l + (r - l)/2;
	return max(query(ql , qr , l , mid , 2*pos+1) , query(ql , qr, mid + 1 , r , 2*pos+2));
}

int main()
{
	 #ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif
	fastio;cin.tie(0);cout.tie(0);
	int n ; cin >> n ; 
	for(int i = 0 ; i < n ; ++i)
	{
		cin >> v[i][0] ;
		v[i][1] = i;
	}
	for(int i = 0 ; i < n ; ++i)
		cin >> v[i][2];
	sort(v.begin() , v.begin()+n);
	long long x;
	for(int i = 0 ; i < n ; ++i)
	{
		x = query(0 , v[i][1] - 1 , 0 , n - 1 , 0);
		update(0 , n - 1 , 0 , v[i][1] , x + 1LL*v[i][2]);
	}
	cout << tree[0];

	return 0;
}

Measured memory_bytes: 17280
#include <fstream>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

int main()
{
    while (true) {
        string s1;
        cin >> s1;
        if (s1 == ".") {
            break;
        }
        string s2;
        cin >> s2;
        auto parse = [](const string& s) {
            vector<string> vc;
            vector<string> vo;
            bool inStringConstant{false};
            string b;
            for (auto&& c : s) {
                if (c == '"') {
                    if (inStringConstant) {
                        inStringConstant = false;
                        vc.push_back(b);
                    }
                    else {
                        inStringConstant = true;
                        vo.push_back(b);
                    }
                    b = "";
                }
                else {
                    b += c;
                }
            }
            if (!b.empty()) {
                vo.push_back(b);
            }
            return make_tuple(vo, vc);
        };

        vector<string> s1o;
        vector<string> s1c;
        vector<string> s2o;
        vector<string> s2c;
        tie(s1o, s1c) = parse(s1);
        tie(s2o, s2c) = parse(s2);

        if (s1c.size() != s2c.size() || s1o.size() != s2o.size()) {
            cout << "DIFFERENT" << endl;
            continue;
        }
        bool b{false};
        for (size_t i = 0; i < s1o.size(); ++i) {
            if (s1o[i] != s2o[i]) {
                cout << "DIFFERENT" << endl;
                b = true;
                break;
            }
        }
        if (b) {
            continue;
        }

        int count{0};
        for (size_t i = 0; i < s1c.size(); ++i) {
            if (s1c[i] != s2c[i]) {
                ++count;
            }
        }

        if (count == 0) {
            cout << "IDENTICAL" << endl;
        }
        else if (count == 1) {
            cout << "CLOSE" << endl;
        }
        else {
            cout << "DIFFERENT" << endl;
        }
    }
}

Measured memory_bytes: 3192
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;

int w, h, n;

int compress(int *x1,int *x2)
{
	vector<int>tmp;
	for (int i = 0; i <= n; ++i)
	{
		tmp.push_back(x1[i]);
		tmp.push_back(x2[i]);
	}
	sort(tmp.begin(), tmp.end());
	tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
	for (int i = 0; i < n; ++i)
	{
		x1[i] = find(tmp.begin(), tmp.end(), x1[i]) - tmp.begin();
		x2[i] = find(tmp.begin(), tmp.end(), x2[i]) - tmp.begin();
	}
	return tmp.size() - 1;
}

int x1_[1234], x2_[1234], y1_[1234], y2_[1234];

int ww, hh;
bool mask[1234][1234];
const int dxy[5] = { 1,0,-1,0,1 };
void bfs(int x, int y)
{
	queue<pair<int, int>>que;
	mask[x][y] = true;
	que.emplace(x, y);
	while (!que.empty())
	{
		x = que.front().first;
		y = que.front().second;
		que.pop();
		for (int dd = 0; dd < 4; ++dd)
		{
			if (!(0 <= x + dxy[dd] && x + dxy[dd] < ww) || !(0 <= y + dxy[dd + 1] && y + dxy[dd + 1] < hh))
			{
				continue;
			}
			if (!mask[x + dxy[dd]][y + dxy[dd + 1]])
			{
				que.emplace(x + dxy[dd], y + dxy[dd + 1]);
				mask[x + dxy[dd]][y + dxy[dd + 1]] = true;
			}
		}
	}
}

int main()
{
	for (;;)
	{
		scanf("%d %d", &w, &h);
		if (h == 0)break;
		scanf("%d", &n);
		for (int i = 0; i < n; ++i)
		{
			scanf("%d %d %d %d", x1_ + i, y1_ + i, x2_ + i, y2_ + i);
		}
		x1_[n] = 0; x2_[n] = w;
		y1_[n] = 0; y2_[n] = h;
		ww = compress(x1_, x2_);
		hh = compress(y1_, y2_);
		memset(mask, false, sizeof(mask));
		for (int i = 0; i < n; ++i)
		{
			for (int p = x1_[i]; p < x2_[i]; ++p)
			{
				for (int q = y1_[i]; q < y2_[i]; ++q)
				{
					mask[p][q] = true;
				}
			}
		}
		int ans = 0;
		for (int i = 0; i < ww; ++i)
		{
			for (int j = 0; j < hh; ++j)
			{
				if (!mask[i][j])
				{
					bfs(i, j);
					++ans;
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 4148
# coding: utf-8

class Node:
    def __init__(self, me, left, right):
        self.me = me
        self.left = left
        self.right = right
        self.parent = None

class NodeTree:
    def __init__(self, root=None):
        self.root = root
        
    def insert(self,z):
        y = None
        x = self.root
        while x != None:
            y = x
            if z.me < x.me:
                x = x.left
            else:
                x = x.right
        z.parent = y
        
        if y == None:
            self.root = z
        elif z.me < y.me:
            y.left = z
        else:
            y.right = z

    def find(self, key):
        y = None
        x = self.root
        while True:
            if x.me == key:
                return x
            elif x.me > key:
                if x.left != None:
                    x = x.left
                else:
                    return None
            else:
                if x.right != None:
                    x = x.right
                else:
                    return None
    
    def delete(self, key):
        z = self.find(key)
        if z.left == None and z.right == None:
            if z.parent.left == z:
                z.parent.left = None
            else:
                z.parent.right = None
        elif z.left != None and z.right == None:
            if z.parent.left == z:
                z.parent.left = z.left
                z.left.parent = z.parent
            if z.parent.right == z:
                z.parent.right = z.left
                z.left.parent = z.parent
        elif z.left == None and z.right != None:
            if z.parent.left == z:
                z.parent.left = z.right
                z.right.parent = z.parent
            if z.parent.right == z:
                z.parent.right = z.right
                z.right.parent = z.parent
        else:
            #y = nextPos(z) # z.right.left.left....の最下層
            y = z.right
            while y.left != None:
                y = y.left
            p = y.me
            self.delete(y.me)
            z.me = p
            
    def getPreorder(self, node, ans):
        ans.append(node)
        if node.left != None:
            self.getPreorder(node.left, ans)
        if node.right != None:
            self.getPreorder(node.right, ans)
            
    def getInorder(self, node, ans):
        if node.left != None:
            self.getInorder(node.left, ans)
        ans.append(node)
        if node.right != None:
            self.getInorder(node.right, ans)

        
def printAns(ans):
    for a in ans:
        print(" " + str(a.me),end="")
    print()
    
m = int(input().rstrip())
nt = NodeTree()
for i in range(m):
    line = input().rstrip().split()
    if line[0] == "insert":
        nt.insert(Node(int(line[1]),None,None))
    elif line[0] == "find":
        if nt.find(int(line[1])) != None:
            print("yes")
        else:
            print("no")
    elif line[0] == "delete":
        nt.delete(int(line[1]))
    else:
        ans = []
        nt.getInorder(nt.root,ans)
        printAns(ans)
        ans = []
        nt.getPreorder(nt.root,ans)
        printAns(ans)


Measured memory_bytes: 88392
#include <iostream>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
//#define hell        1000000007
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.000000001
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e7+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

using namespace std;
#include <stdio.h>

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0)
  {
    if(y%2) res=(x*res);
    x=(x*x);
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}

void solve();


void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);
/*
void sieve(){

  for(int i=2;i<=500000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=500000;j+=i)
      prime[j]=false;
    }
  }

}*/


bool comp(pair<int,int> a,pair<int,int> b){
  if(a.F!=b.F)
  return (a.F<b.F);
  else
  return a.S<b.S;
}

void solve(){
  int test;
  //cin>>test;
  test=1;
  while(test--){
    int n;
    cin>>n;
    int a[n];
    forn(i,0,n)
    cin>>a[i];

    vector<int> pos[n+1];
    forn(i,0,n){
      pos[a[i]].pb(i);
    }
    if(pos[1].size()==0){
      cout<<-1;
      return;
    }
    int cnt=1;
    int curpos=pos[1][0];

    for(int i=2;i<=n;i++){
      if(pos[i].size()==0)
      break;
      auto it=lower_bound(pos[i].begin(),pos[i].end(),curpos);
      if(it==pos[i].end())
      break;
      cnt++;
      curpos=*it;
    }
    cout<<n-cnt;
  }
}




/*bool issafe(int x,int y){
  return (x>=0 && y>=0 && x<n && y<m);
}*/

///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

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


ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1))*k);
  else
  return ((pw(k,x/2))*(pw(k,x/2)));
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
#define vecmin(A) *min_element(A.begin(),A.end())
#define vecmax(A) *max_element(A.begin(),A.end())
typedef long long ll;

int main(){
  ll a,v,b,w,t;
  cin >> a >> v >> b >> w >> t;
  if (b < a) swap(a,b);
  if (w >= v){
    cout << "NO" << endl;
    return 0;
  }
  ll lasta = a + t*v;
  ll lastb = b + t*w;
  if(lasta < lastb){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 3636
#include <stdio.h>
#include<math.h>
int count=0;
int main()
{
    char s[200005],t[200005];
    scanf("%s",s);
    scanf("%s",t);
    for(int i=0;s[i]!='\0';i++)
    {
        if(s[i]!=t[i])
        count++;
    }
    printf("%d\n",count);
}


Measured memory_bytes: 2064
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int n,m;
    cin>>n;
    vii g(n+1,vi());
    vll bit(n+1,vl(n+1));
    map<pii,int> mp;
    FOR(i,0,n-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].PB(b);
        g[b].PB(a);
        mp[MP(a,b)]=i;
        mp[MP(b,a)]=i;
    }
    cin>>m;
    vector<pii> c(m);
    FOR(i,0,m){
        int u,v;
        cin>>u>>v;
        u--;v--;
        c[i]=MP(u,v);
    }

    FOR(st,0,n){
        FOR(gl,st+1,n){
            vi fr(n,mod);
            vi visit(n,0);
            visit[st]=1;
            queue<int> q;
            q.push(st);
            while (q.size())
            {
                int nw=q.front();
                q.pop();
                if(nw==gl){
                    LL bb=0;
                    while(nw!=st){
                        int f=fr[nw];
                        int idx=mp[MP(f,nw)];
                        bb|=(1LL<<idx);
                        nw=fr[nw];
                    }
                    bit[st][gl]=bit[gl][st]=bb;
                    break;
                }
                for(const auto nx:g[nw]){
                    if(visit[nx])continue;
                    fr[nx]=nw;
                    visit[nx]=1;
                    q.push(nx);
                }
            }
            

        }
    }

    LL ans=1LL<<(n-1);
    cerr<<ans<<endl;

    FOR(i,1,1<<m){
        int cnt=0,sgn=1;
        vi used(n-1,0);
        FOR(j,0,m){
            if(i&(1<<j)){
                cnt++;
                int s=c[j].ST;
                int goal=c[j].ND;
                LL bb=bit[s][goal];
                FOR(k,0,n){
                    if(bb&(1LL<<k)){
                        used[k]=1;
                    }
                }
            }
        }
        if(cnt&1)sgn=-1;
        int unused=0;
        FOR(j,0,n-1){
            if(used[j]==0)unused++;
        }
        ans+=sgn*(1LL<<unused);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include<stdio.h>

void F(int*,int);
void A(int*,int);




  
  int main(){
  int N,i,j,v;
  int S[100];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&S[i]);
  }
 
  F(S,N);
  A(S,N); 
  return 0;
}
  
void F(int S[], int N){
  int i;

  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",S[i]);
  }
  printf("\n");
}
void A(int S[], int N){
  int j,i,v;
 
  for(i=1;i<N;i++){
    v =S[i];
    j=i-1;
  
    while(j>=0&&S[j]>v){
      S[j+1]=S[j];
      j--;
    }
 
    S[j+1]=v;
    F(S,N);
  }



}



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

int main() {
  int p,q,r, result;
  cin >> p >> q >> r;
  
  if(p >= q && p >= r){
    result = q + r;
  } else if (q >= p && q >= r){
    result = p + r;
  } else {
   result = p + q; 
  }

  
  cout << result << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
        }
        int q = sc.nextInt();
        int[] t = new int[n];
        for (int i = 0; i < q; i++) {
            t[i] = sc.nextInt();
        }
        int c = 0;
        for (int i = 0; i < q; i++) {
            // if (Arrays.binarySearch(s, t[i]) >= 0) {
            //     c++;
            // }
            int left = -1;
            int right = n;
            while (right - left > 1) {
                int mid = left + (right - left) / 2;
                if (s[mid] == t[i]) {
                    c++;
                    break;
                } else if (s[mid] > t[i]) {
                    right = mid;
                } else {
                    left = mid;
                }
            }
        }
        System.out.println(c);
    }
}

Measured memory_bytes: 77276
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    string S;
    int flag1 = 0, flag2 = 0;
    cin >> S;
    if (S.at(0) == '0')
    {
        if (S.at(1) != '0')
        {
            flag1 = 1;
        }
    }
    else if (S.at(0) == '1')
    {
        if (S.at(1) < '3')
        {
            flag1 = 1;
        }
    }
    if (S.at(2) == '0')
    {
        if (S.at(3) != '0')
        {
            flag2 = 1;
        }
    }
    else if (S.at(2) == '1')
    {
        if (S.at(3) < '3')
        {
            flag2 = 1;
        }
    }
    if (flag1 && flag2)
    {
        cout << "AMBIGUOUS" << endl;
    }
    else if (flag1)
    {
        cout << "MMYY" << endl;
    }
    else if (flag2)
    {
        cout << "YYMM" << endl;
    }
    else
    {
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <list>
#include <utility>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))
const ll mod = 1000000007;
const double eps = 1e-10;
const int MAX = 200000;

int main() {
  // three patterns
  char c;
  // 今回見ていたあまりが*10されて、次の1桁目がくっついて、13で割ったあまりの場合の数になる。
  // "非決定性有限オートマトンの場合は、ノードの長さだけの配列を用意しておいて、各配列の要素がそのターンにその配列を踏む場合の数"
  // 2次元配列が使える(高々数MB)
  int v_now[13] = {};
  int v_next[13] = {};
  // 読み取り0文字目のとき、0とみなす。
  // 13で割ったあまりが0となる場合の数が1で、他は0。
  v_now[0] = 1;
  int i = 0;
  while (true) {
    c = cin.get();
    if (c == '\n') {
      cout << v_now[5] << endl;
      return 0;
    }
    if (c =='?') { // 現在のkの状態、0~12が考えられる状態から、j(0〜9)が入ってきたときの遷移をする。
      rep(k,13) {
        rep(j,10) {
          v_next[(k * 10 + j) % 13] += v_now[k];
          v_next[(k * 10 + j) % 13] %= mod;
        }
      }
    } else { // 現在のkの状態、0~12が考えられる状態から、numが入ってきたときの遷移をする。
      int num = c - '0';
      rep(k,13) {
        v_next[(k * 10 + num) % 13] += v_now[k];
        v_next[(k * 10 + num) % 13] %= mod;
      }
    }
    rep(k,13) {
      v_now[k] = v_next[k];
      v_next[k] = 0;
    }
    i++;
  }
  return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int N, M; cin >> N >> M;
    vector<int> H(N);
    rep(i,N) cin >> H[i]; 
    vector<int> to[N];
    rep(i,M){
        int A, B; cin >> A >> B;
        A--; B--;
        to[A].push_back(B);
        to[B].push_back(A);
    }
    int cnt = 0;
    rep(i,N){
        bool isGood = true;
        for(int u: to[i]){
            if(H[i] <= H[u]) isGood = false;
        }
        if(isGood) cnt++; 
    }
    cout << cnt << endl;
}

Measured memory_bytes: 8800
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,a,b;
  cin >> N;
 
  a = N/10;
  b = N%1000;
  if (a%111==0||b%111==0){
    cout << "Yes" <<endl;
  }
  else{
    cout <<"No"<<endl;
  }
}

Measured memory_bytes: 256
module Main where

import           Control.Monad
import           Data.List
import           Data.Ord
import           Data.List.Split
import           Data.Array.IO
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  n <- readLn
  [d, x] <- map read . words <$> getLine
  as <- replicateM n readLn

  print . (x +) $ f d as
  where
    f d [] = 0
    f d (a:as) = (ceiling (fromIntegral d / fromIntegral a)) + f d as

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

int main() {
    int N, P, i;
    int odd = 0, even = 0;
    long sum = 0, sum_b;
    cin >> N >> P;
    vector<int> biscuits(N);
    for (i = 0; i < N; i++) {
        cin >> biscuits.at(i);
        if (biscuits.at(i) % 2 == 1) odd++;
    }
    even = N - odd;
    
    if (odd == 0) sum = pow(2, N);
    else sum = pow(2, N - 1);
    sum_b = pow(2, N) - sum;

    if (P == 0) cout << sum << endl;
    else cout << sum_b << endl;
}

Measured memory_bytes: 256
def get():
	p,w = map(int, raw_input().split(","))
	for i in range(W-w,-1,-1):
		if bag[i] > 0 and bag[i]+p > bag[i+w]:
			bag[i+w] = bag[i]+p
	else:
		if p > bag[w]: bag[w] = p
	return

c = 1
while True:
	W = int(raw_input())
	if W == 0: break
	bag = [0]*(W+1)
	N = int(raw_input())
	for i in range(N): get()
	w_all = max(bag)
	money = bag.index(w_all)
	print "Case {}:\n{}\n{}".format(c,w_all,money)
	c += 1

Measured memory_bytes: 4312
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DLuckyPIN solver = new DLuckyPIN();
        solver.solve(1, in, out);
        out.close();
    }

    static class DLuckyPIN {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            String s = in.next();
            int cnt = 0;
            for (int i = 0; i < 1000; i++) {
                int x = i / 100;
                int y = (i / 10) % 10;
                int z = i % 10;
                if (exist(s, (char) (x + '0'), (char) (y + '0'), (char) (z + '0'))) {
                    cnt++;
                }
            }
            out.println(cnt);
        }

        boolean exist(String s, char x, char y, char z) {
            boolean fx = false;
            boolean fy = false;
            boolean fz = false;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == x && !fx) {
                    fx = true;
                    continue;
                }
                if (s.charAt(i) == y && fx && !fy) {
                    fy = true;
                    continue;
                }
                if (s.charAt(i) == z && fy && !fz) {
                    fz = true;
                    break;
                }
            }

            return fz;
        }

    }
}



Measured memory_bytes: 23508
from collections import defaultdict
def root(x, par):
    while par[x] >= 0:
        x = par[x]
    return x

def unite(x,y,par):
    rx = root(x,par)
    ry = root(y,par)
    if rx != ry:
        if rx > ry:
            rx, ry = ry, rx
        par[rx] += par[ry]
        par[ry] = rx

def same(x,y,par):
    rx = root(x,par)
    ry = root(y,par)
    return rx == ry

def size(x, par):
    return -par[root(x,par)]

N, K, L = map(int, input().split())
par1 = [-1]*N
par2 = [-1]*N

for i in range(K):
    A, B = map(int, input().split())
    A, B = A-1, B-1
    unite(A, B, par1)

for i in range(L):
    C, D = map(int, input().split())
    C, D = C-1, D-1
    unite(C, D, par2)

G = defaultdict(list)
for i in range(N):
    G[(root(i, par1), root(i, par2))].append(i)
Ans = [0]*N
for city_list in G.values():
    for city in city_list:
        Ans[city] = len(city_list)
for i in Ans:
    print(i, end=" ")

Measured memory_bytes: 134648
using System;

namespace ITP1_9
{
    class Program
    {
        static void Main()
        {
            var w = Console.ReadLine();
            int c = 0;
            while(true)
            {
                var t = Console.ReadLine();
                if (t == "END_OF_TEXT") break;
                foreach(var u in t.ToLower().Split())
                    if (w == u) c++;
            }
            Console.Write("{0}\n", c);
        }
    }
}

Measured memory_bytes: 9168
n, m = map(int, input().split())

key = [0]*n
wa = [0]*n
for i in range(m):
    p, s = map(str, input().split())
    p = int(p)
    if s == "WA":
        if key[p-1]:
            continue
        else:
            wa[p-1] = wa[p-1]+1
    if s == "AC":
        if key[p-1]:
            continue
        else:
            key[p-1] = True
ac = sum(key)
wan = 0
for i in range(n):
    if key[i]:
        wan += wa[i]
print(ac, wan)

Measured memory_bytes: 4596
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

struct AdjacentMatrix {
    mat: Vec<Vec<usize>>,
}

impl AdjacentMatrix {
    pub fn new(n: usize) -> AdjacentMatrix {
        AdjacentMatrix {
            mat: vec![vec![]; n],
        }
    }

    pub fn connect(&mut self, x: usize, y: usize) {
        self.mat[x].push(y);
        self.mat[y].push(x);
    }
}

struct Solver {
    adj_mat: AdjacentMatrix,
    colors: Vec<i32>,
}

impl Solver {
    fn solve(&mut self, idx: usize, color: i32) -> bool {
        if self.colors[idx] != 0 && self.colors[idx] != color {
            return false;
        }
        self.colors[idx] = color;
        let adjacents = self.adj_mat.mat[idx].iter().cloned().collect::<Vec<_>>();
        for i in adjacents {
            if self.colors[i] == 0 {
                let result = self.solve(i, color * -1);
                if !result {
                    return false;
                }
            } else if self.colors[i] == color {
                self.colors[i] = 2;
                return false;
            }
        }
        true
    }
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut pairs = vec![];
    for _ in 0..m {
        let v = read_vec::<usize>();
        let (a, b) = (v[0] - 1, v[1] - 1);
        pairs.push((a, b));
    }
    let mut adj_mat = AdjacentMatrix::new(n);
    for &pair in pairs.iter() {
        adj_mat.connect(pair.0, pair.1);
    }
    let colors = vec![0; n];
    let mut solver = Solver {
        adj_mat: adj_mat,
        colors: colors,
    };
    if solver.solve(0, 1) {
        let mut even_count = 0i64;
        for i in 0..n {
            if solver.colors[i] == 1 {
                even_count += 1;
            }
        }
        let odd_count = n as i64 - even_count;
        println!("{:?}", odd_count * even_count - m as i64);
    } else {
        println!("{:?}", n as i64 * (n as i64 - 1) / 2 - m as i64);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 15228
#include <iostream>

using namespace std;

int main ()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b)
    swap(a,b);
    if(a>c)
    swap(a,c);
    if(b>c)
    swap(b,c);
    cout<<a<<" "<<b<<" "<<c<<endl;
    
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

template <typename T>
class SegTree {
private:
    int n;
    vector<T> data;
    T id;
    function<T(T, T)> update;
    function<T(T, T)> merge;

    T _query(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return id;
        if(a <= l && r <= b) return data[k];
        
        T vl = _query(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = _query(a, b, 2 * k + 2, (l + r) / 2, r);
        return merge(vl, vr);
    }

public:
    SegTree(int _n, T _id, function<T(T, T)> _update, function<T(T, T)> _merge)
    : id(_id), update(_update), merge(_merge) {
        n = 1;
        while(n < _n) n <<= 1;
        data = vector<T>(2 * n - 1, id);
    }

    void change(int k, T x) {
        k += n - 1;
        data[k] = update(data[k], x);
        while(k > 0) {
            k = (k - 1) / 2;
            data[k] = merge(data[2 * k + 1], data[2 * k + 2]);
        }
    }

    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    T operator[](int k) {
        return data[k + n - 1];
    }
};

const long long MOD = 998244353;
static const int n_max = 200000;
long long powtwo[n_max + 1];

void powtwoinit() {
    powtwo[0] = 1LL;
    for(int i=1; i<=n_max; ++i) {
        powtwo[i] = powtwo[i - 1] * 2LL % MOD;
    }
}

int main() {
    int N;
    cin >> N;
    vector<P> x(N), y(N);
    for(int i=0; i<N; ++i) {
        int a, b;
        cin >> a >> b;
        x[i] = P(a, i);
        y[i] = P(b, i);
    }
    sort(begin(x), end(x));
    sort(begin(y),end(y));
    vector<P> point(N);
    for(int i=0; i<N; ++i) {
        point[x[i].second].first = i;
        point[y[i].second].second = i;
    }
    sort(begin(point), end(point));

    SegTree<int> done(N, 0, plus<int>(), plus<int>());
    SegTree<int> undone(N, 0, plus<int>(), plus<int>());
    for(int i=0; i<N; ++i) undone.change(i, 1);

    long long res = 0;
    powtwoinit();
    for(P p : point) {
        int y = p.second;
        done.change(y, 1);
        undone.change(y, -1);

        vector<int> num(4);
        num[0] = undone.query(y + 1, N);
        num[1] = done.query(y + 1, N);
        num[2] = done.query(0, y);
        num[3] = undone.query(0, y + 1);

        long long tmp = powtwo[N] - 1;
        for(int i=0; i<4; ++i) {
            tmp = (tmp - powtwo[num[i] + num[(i + 1) % 4]] + MOD) % MOD;
            tmp = (tmp + powtwo[num[i]]) % MOD;
        }
        res = (res + tmp) % MOD;
    }
    cout << res << endl;
}

Measured memory_bytes: 10624
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
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; }

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >>d;
    bool ans = true;
    while(a>0 || b>0) {
        c -= b;
        if(c<=0) {
            break;
        }
        a -= d;
        if(a<=0) {
            ans = false;
            break;
        }
    }
    if(ans) cout << "Yes" <<endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define mx 200005
#define inf 999999999999
#define gcd __gcd
#define pb push_back
#define mk make_pair
#define bs binary_search
#define ub upper_bound
#define lb lower_bound
#define endl "\n"
#define vl vector<ll>
#define vs vector<string>
using namespace std;

bool isp[mx];

void sv(){

	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}

ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	//sv();
	
	ll a[6],i,j,k,lst,mn=inf, id=0;
	for(i=0;i<5;i++)
	{
	    cin>>a[i];
	    if(a[i]%10 && a[i]%10 <mn)
	    {
	        mn= a[i]%10;
	        id=i;
	    }
	}
	ll ans=a[id];
	for(i=0;i<5;i++){
	    if(i!=id)
	    {
	        ans+= (a[i]/10 + (a[i]%10 !=0))*10;
	    }
	}
	cout<<ans;
    return 0;
}























Measured memory_bytes: 256
h, w, d = [int(x) for x in input().split()]
n = h * w

p_list = [None] * (n + 1)
for i in range(h):
    a_list = [int(x) for x in input().split()]
    for j in range(w):
        p_list[a_list[j]] = (i, j)

m_a_list = [0] * (n + 1)
for start in range(1, d + 1):
    p_i, p_j = p_list[start]
    p_target = start
    for target in range(start + d, n + 1, d):
        n_i, n_j = p_list[target]
        m = abs(n_i - p_i) + abs(n_j - p_j)
        m_a_list[target] = m + m_a_list[p_target]
        p_i, p_j, p_target = n_i, n_j, target

q = int(input())
for _ in range(q):
    l, r = [int(x) for x in input().split()]
    print(m_a_list[r] - m_a_list[l])

Measured memory_bytes: 15772
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(V) sort((V).begin(),(V).end())
#define pb push_back
#define endl '\n'
#define int long long

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

// 変数定義
int n;
vector<int> ans;
//

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 1, sqrt(n)+1) {
    if (n % i == 0) {
      ans.pb(i + (n/i) - 2);
    }
  }
  SORT(ans);
  cout << ans[0] << endl;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static readonly int INF = int.MaxValue / 2;

        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int n = int.Parse(Console.ReadLine());

            int[,] map = new int[n + 1, n + 1];

            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    map[i, j] = INF;
                }
            }

            for (int i = 0; i < n; i++)
            {
                int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                int from = input[0];
                int len = input[1];

                for (int j = 0; j < len; j++)
                {
                    int to = input[2 + j];

                    map[from, to] = 1;
                }
            }

            for (int k = 1; k <= n; k++)
            {
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= n; j++)
                    {
                        map[i, j] = Math.Min(map[i, j], map[i, k] + map[k, j]);
                    }
                }
            }

            int p = int.Parse(Console.ReadLine());

            while (p-- > 0)
            {
                int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                int from = input[0];
                int to = input[1];
                int maxV = input[2];

                int v = map[from, to] + 1;

                if (v > maxV) sb.AppendLine("NA");
                else sb.AppendLine(v.ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9284