akhauriyash/Code-Regression huggingface dataset:
N=int(input())
K = int(input())
def one(N):
    n = list(str(N))
    A = (len(n)-1)*9
    A += int(n[0])
    return A

def two(N):
    n = list(str(N))
    r = len(n)
    A = (int(n[0])-1)*(r-1)*9 #r-1C1*9
    A = A + (r-2)*(r-1)*81/2  #r-1C2*81
    A = A + one(N%(10**(r-1)))
    return(A)

if K==1:
    print(int(one(N)))

elif K==2:
    print(int(two(N)))

elif K==3:
    n = list(str(N))
    r = len(n)
    A = two(10**(r-1)-1)*(int(n[0])-1)
    A = A + two(N%(10**(r-1)))
    A = A + (r-2)*(r-1)*(r-3)*81*9/6
    print(int(A))



Measured memory_bytes: 3064
<?php
define('MOD', 10 ** 9 + 7);
list($n, $a, $b, $c) = ints();
init(2 * $n - 2);
$a = modDiv($a, 100 - $c);
$b = modDiv($b, 100 - $c);
$c = modDiv($c, 100);
$ans = 0;
for ($i = $n; $i <= 2 * $n - 1; ++$i) {
    $pa = modMul(modPow($a, $n), modPow($b, $i - $n));
    $pb = modMul(modPow($b, $n), modPow($a, $i - $n));
    $p = modMul($i, modMul(nCr2($i - 1, $n - 1), modAdd($pa, $pb)));
    $ans = modAdd($ans, $p);
}
if ($c > 0) $ans = modDiv($ans, modSub(1, $c));
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
// 足し算
function modAdd($x, $y)
{
    return ($x + $y) % MOD;
}

// 引き算
function modSub($x, $y)
{
    return ($x + MOD - $y) % MOD;
}

// 掛け算
function modMul($x, $y)
{
    return ($x * $y) % MOD;
}

// 割り算
function modDiv($x, $y)
{
    return modMul($x, modPow($y, MOD - 2));
}

// 累乗（繰り返し二乗法）
function modPow($n, $x)
{
    if ($x === 0) return 1;
    $res = (modPow($n, $x >> 1) ** 2) % MOD;
    if ($x % 2 === 1) $res = modMul($res, $n);
    return $res;
}

// 階乗
function modFac($n)
{
    if ($n === 0) return 1;
    return modMul($n, modFac($n - 1));
}

// 順列
function nPr($n, $r)
{
    if ($r === 0) return 1;
    return modMul(nPr($n, $r - 1), $n - $r + 1);
}

// 組み合わせ
function nCr($n, $r)
{
    $r = min($r, $n - $r);
    if ($r === 0) return 1;
    return modDiv(nPr($n, $r), modFac($r));
}

// 階乗、逆元を前処理
function init($n)
{
    global $fact, $ifact;
    $fact[0] = 1;
    for ($i = 1; $i <= $n; ++$i) $fact[$i] = modMul($fact[$i - 1], $i);
    $ifact[$n] = modDiv(1, $fact[$n]);
    for ($i = $n; $i >= 1; --$i)
        $ifact[$i - 1] = modMul($ifact[$i], $i);
}

// 順列（前処理）
function nPr2($n, $r)
{
    global $fact, $ifact;
    return modMul($fact[$n], $ifact[$n - $r]);
}

// 組み合わせ（前処理）
function nCr2($n, $r)
{
    global $fact, $ifact;
    return modMul(modMul($fact[$n], $ifact[$r]), $ifact[$n - $r]);
}


Measured memory_bytes: 33808
//Be Name Khoda
//no comment...
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e3 + 2;
const int infint = (int)1e9;
const ll inf = (ll)1e18;
int a[MAXN];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int ans = 0;
	for (int i = 1; i < n; i++)
		if(a[i] == a[i - 1])
		{
			set<int> S = {10000, 999, 998};
			S.erase(a[i - 1]);
			S.erase(a[i + 1]);
			a[i] = *S.begin();
			ans++;
		}
	cout << ans;
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
c=array(N)
N.times do|i|
    c[i]=gets.to_i
end
idx=array(N+1)
N.times do|i|
    idx[c[i]]=i
end
prev=-1
cnt=0
ans=0
1.upto(N) do|i|
  if prev<idx[i]
      cnt+=1
  else
      ans=max(cnt,ans)
      cnt=1
  end 
  prev=idx[i]
end
if ans.zero?
    puts 0
else
    puts N-ans
end

Measured memory_bytes: 17480
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cout << "[" << __LINE__ << "] ";
#define dump(i) cout << #i ": " << i << " ";
#define dumpl(i) cout << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[])
{

    vector<int> v, prime;
    int ind = 0;
    v.push_back(6);
    int c = 1;
    while (7 * c + 6 < 400000)
    {
        v.push_back(7 * c + 1);
        v.push_back(7 * c + 6);
        c++;
    }

    ind = 0;
    rep(i, v.size())
    {
        bool flg = true;
        rep(j, prime.size())
        {
            if (prime[j] == 0 || prime[j] * prime[j] > v[i])
                break;
            // cerr << v[i] << "," << prime[j] << endl;

            if (v[i] % prime[j] == 0)

            {
                flg = false;
                break;
            }
        }
        if (flg == true)
        {
            // cerr << v[i] << endl;
            prime.push_back(v[i]);
        }
    }
    int n;
    cin >> n;
    while (n != 1)
    {
        cout << n << ":";
        c = 0;
        while (n >= prime[c])
        {
            if (n % prime[c] == 0)
            {
                cout << " " << prime[c];
            }
            c++;
        }
        cout << endl;
        cin >> n;
    }
    return 0;
}



Measured memory_bytes: 3516
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b;
    cin >> a >> b;
    if (a > b)
        cout << "a > b" << endl;
    else if (a < b)
        cout << "a < b" << endl;
    else 
        cout << "a == b" << endl;

 

}


Measured memory_bytes: 3100
#include <iostream>
#include <math.h>
using namespace std;
int main () {
    int cnt=0;
    int n,d;
    cin >> n >> d;
    double a[n],b[n];
    for(int i=0; i<n; i++) {
        cin >> a[i] >> b[i];
        double  c = (a[i]*a[i])+ (b[i]*b[i]);
        if(sqrt(c)<=d) {
            cnt++;
        } 
    }
    cout << cnt << endl;
    return 0;
}

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

 int main()
     {
    int a,b,x,d1,d2;
    cin>>x>>a>>b;
    d1=abs(x-a);
    d2=abs(x-b);
    if(d1<=d2)
        cout<<"A";
    else cout<<"B";

   return 0;
     }


Measured memory_bytes: 3600
from collections import Counter


N = int(input())
S = [input() for _ in range(N)]

C = Counter(S)

max = -1
ans = []

for k, v in C.most_common():
    if max == -1:
        max = v
    elif max > v:
        break
    ans.append(k)

ans = sorted(ans)

for a in ans:
    print(a)


Measured memory_bytes: 45032
h,w = map(int,input().split())
a = [input() for i in range(h)]
a_count = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            a_count += 1
if a_count == (h+w)-1:
    print('Possible')
else:
    print('Impossible')


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

int main(){
    int w,h;
    cin >> h >> w ; 
    while(h!=0 && w!=0){
        for(int i=0;i<w;i++) cout << "#";
        cout << "\n";
        for(int i=0;i<h-2;i++){
            cout  << "#";
            for(int j=0; j<w-2;j++){
                cout << ".";
            }
            cout << "#" << "\n";
        }
        for(int i=0; i<w;i++) cout << "#";
        cout << "\n" << "\n";
        cin >> h >> w;
    }
    return 0;
}
        


Measured memory_bytes: 3100
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;


#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

class Rule{
	public:
	vector<int> x;
	int y;
};

vector<int> A;
vector<int> B;

const int N = 26;
const int R = 60;
const int K = 10;

const int INF = 1000000000;

vector<Rule> rules;

bool input(){
	int n,m,r;
	cin>>n>>m>>r;
	
	
	if(n==0)return false;
	
	A = vector<int>(n);
	rep(i,n)cin>>A[i];
	
	B = vector<int>(m);
	rep(i,m)cin>>B[i];
	
	rules = vector<Rule>(r);
	rep(i,r){
		int m;
		cin>>m;
		rules[i].x = vector<int>(m);
		rep(j,m)cin>>rules[i].x[j];
		cin>>rules[i].y;
	}
	
	return true;
}


int tableA[N][N];
int tableB[N][N];


void printbit(int len, int state){
	reps(i,1,len+1){
		printf("%d",((state&(1<<i))>0));
	}
}

void printTable(vector<int>& vec, int table[N][N]){
	rep(i,vec.size()){
		rep(j,vec.size()){
			printbit(2, table[i][j]);
			printf(" ");
		}puts("");
	}puts("");
}

bool canConvert(int table[N][N], int st, int dist, Rule& rule, int c){
	bool dp[K][N]={false};
	rep(i,rule.x.size()){
		rep(j,dist+1){
			if(i==0)dp[i][j] = (table[st][(st+j)%c]&(1<<rule.x[i]))>0;
			else{
				rep(k,j){
					dp[i][j] |= dp[i-1][k] & ( (table[(st+k+1)%c][(st+j)%c]&(1<<rule.x[i]))>0 );
				}
			}
		}
	}
	return dp[rule.x.size()-1][dist];
}

int getTableVal(int table[N][N],int st, int dist,int c){
	int ret = 0;
	rep(i,rules.size()){
		if(canConvert(table, st, dist, rules[i], c)){
			ret |= (1<<rules[i].y);
		}
	}
	return ret;
}

void makeTable2(vector<int>& vec, int table[N][N]){
	int c = vec.size();
	rep(dist, c){
		rep(i,c){
			if(dist==0){
				table[i][i] = (1<<vec[i]);
			}else{
				table[i][(i+dist)%c] = getTableVal(table, i, dist, c);
			}
		}
	}
}


void makeTable(){
	makeTable2(A, tableA);
	makeTable2(B, tableB);
	
	/*
	printTable(A, tableA);
	printTable(B, tableB);
	*/
}

int solveDP2(int s,int t){
	int dp[N][N]={0};
	int n = A.size();
	int m = B.size();
	rep(i,n){
		rep(j,m){
			if(tableA[s][(s+i)%n]&tableB[t][(t+j)%m])dp[i][j]=1;
			rep(k,i){
				rep(p,j){
					if(dp[k][p]==0)continue;
					if(tableA[(s+k+1)%n][(s+i)%n]&tableB[(t+p+1)%m][(t+j)%m]){
						dp[i][j] = max(dp[i][j], dp[k][p]+1);
					}
				}
			}
		}
	}
	
	/*
	printf("%d %d\n",s,t);
	rep(i,A.size()){
		rep(j,B.size()){
			printf("%d ",dp[i][j]);
		}puts("");
	}puts("");
	*/
	return dp[A.size()-1][B.size()-1];
}

int solveDP(){
	
	int ans = 0;
	rep(i,A.size()){
		rep(j,B.size()){
			ans = max(ans, solveDP2(i,j));
		}
	}
	
	if(ans==0)return -1;
	return ans;
}

int solve(){
	makeTable();
	return solveDP();
}


int main(){
	while(input()){
		printf("%d\n",solve());
	}
}


/*
5 4 3
2 1 1 2 1
1 1 2 2
2 1 2 1
3 2 2 1 2
3 1 1 2 2
0 0 0

5 4 1
2 1 1 2 1
1 1 2 2
2 1 2 1
0 0 0

3 3 2
1 1 1
2 2 1
2 1 1 2
2 2 2 1
0 0 0

*/

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b, c, d, ans;
    cin >> a >> b;
    ans = 0;
    vector<int> vec(b + 1);
    for (int i = 0; i < a; i++) {
        cin >> c;
        for (int j = 0; j < c; j++) {
            cin >> d;
            vec.at(d)++;
        }
    }
    for (int i = 0; i <= b; i++) {
        if (vec.at(i) == a) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math
N = int(input())

x = [0] * N
y = [0] * N
for index in range(N):
    x[index], y[index] = map(int, input().split())


Nbiku = math.factorial(N)
Nbikuhiku = math.factorial(N - 1) 

ans = 0
for index in range(N):
    for index2 in range(N):
        if index == index2:
            continue

        dx = x[index] - x[index2]
        dy = y[index] - y[index2]

        ans += (dx ** 2 + dy ** 2)** 0.5 * Nbikuhiku
        

print(ans / Nbiku)


Measured memory_bytes: 3064
X,N=map(int,input().split())
p=list(map(int,input().split()))
p_bar=[]
for i in range(0,102):
  if i not in p:
    p_bar.append(i)

d_min=1000
i_min = 0
for i in p_bar:
  d = abs(X-i)
  if d < d_min:
    d_min = d
    i_min = i
print(i_min)


Measured memory_bytes: 9184
a = list(map(int, input().split()))
count = a[0]
base = a[1]
how_many = 0
for i in range(count):
  num = list(map(int, input().split()))
  distance = (num[0] ** 2 + num[1] ** 2) ** (1/2)
  if distance <= base:
    how_many += 1
print(how_many)

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  REP(i, N){
    cin >> S[i];
  }

  sort(S.begin(), S.end());
  REP(i, N){
    cout << S[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  vector<long long> ans (4);
  ans[0] = a*c;
  ans[1] = a*d;
  ans[2] = b*c;
  ans[3] = b*d;
  sort(ans.begin(), ans.end());
  cout << ans[3] << endl;
}

Measured memory_bytes: 3624
#include <cstdio>

int main()
{
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    bool found = false;
    for (int i = 0; i <= n; ++ i) {
        for (int j = 0; j <= m; ++ j) {
            found |= i * m + j * n - 2 * i * j == k;
        }
    }
    puts(found ? "Yes" : "No");
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define bye return 0
using namespace std;
int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    char c;
    int n, k, x=0, y=0;

    cin >> k >> x >> y;
    k = k-x;

    for(int i=1; ;i++){

    	if(k <= y){
    		if(k == y){
    			cout << "0" << "\n";
    		}else{
    		cout << k << "\n";
    	}
    		break;
    	}

     k -= y;
      

    	
    }
    

    

    

  
   bye;

}


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

int main(){
  int n, k, a=0;
  string s;
  cin >> n >> k >> s;  
  for(int i=0; i<n-1; i++){
    if(s.at(i)==s.at(i+1))a++;
  }
  cout << min(k*2+a, n-1) << endl;
  return 0;  
}
 

Measured memory_bytes: 512
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    int n; cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    vll bit(64, 0);
    rep(i, n){
        rep(j, 64){
            if(((a[i]>>j)&1)==1) bit[j]++;
        }
    }

    ll ans = 0;
    rep(i, 64){
        ll t = bit[i] * ((ll)n - bit[i]);
        t %= MOD;
        t *= (ll)(1LL<<i)%MOD;
        t %= MOD;
        ans = (ans+t)%MOD;
    }

    pr(ans);
    return 0;}

Measured memory_bytes: 5636
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pll=pair<ll,ll>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vstr=vector<string>;

void solve() {
    ll N;
    cin >> N;
    vll A(N);
    rep(i,N) cin >> A[i];
    rep(i,N){
        if(A[i]==0){
            print(0);
            return;
        }
    }
    ll max = pow(10,18);
    ll ans = 1;
    rep(i,N){
        if(A[i]<=max/ans){
            ans *= A[i];
        }else{
            print(-1);
            return;
        }
    }
    print(ans);
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3924
/*版权所有，拷贝必究！*/
/*若想获得，请联系许希泉*/
#include<bits/stdc++.h>
#pragma GCC optimize("O999")
const int INF = 0x3f3f3f3f;
int maxn=5000005;
using namespace std;

bool is_pal(string a)
{
    string s=a;
    reverse(s.begin(),s.end());
    if(s==a)
    return true;
    else
    return false;
}
bool is_prime(int n)
{
    if(n==1)
	return false;
    if(n==2||n==3)
	return true;
    if(n%6!=1&&n%6!=5)
	return false;
    for(register int i=5;i*i<=n;i+=6)
    if(n%i==0||n%(i+2)==0)
	return false;
    return true;
}
int main()
{
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	string s1,s2;
    int h,n,m,x,y,sum=0;
    cin>>h>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    	sum+=a[i];
	}
	
    if(sum>=h)
	cout<<"Yes";
	else
	cout<<"No";
    
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int d[501][501] = {0};
int memo[501][501];

int dfs(int l, int r) {
  if (l > r)
    return 0;
  if (memo[l][r] >= 0)
    return memo[l][r];
  if (l == r)
    return memo[l][r] = d[l][l];
  if (r - l > 1) {
    return memo[l][r] =
               d[l][r] + dfs(l + 1, r) + dfs(l, r - 1) - dfs(l + 1, r - 1);
  } else {
    return memo[l][r] = d[l][r] + dfs(l, l) + dfs(r, r);
  }
}

int main() {
  for (int i = 0; i < 501; i++)
    for (int j = 0; j < 501; j++)
      memo[i][j] = -1;
  int n, m, q;
  cin >> n >> m >> q;
  vector<pair<int, int>> lr(m);
  for (int i = 0; i < m; i++) {
    cin >> lr[i].first >> lr[i].second;
  }
  vector<pair<int, int>> que(q);
  for (int i = 0; i < q; i++) {
    cin >> que[i].first >> que[i].second;
  }
  for (int i = 0; i < m; i++)
    d[lr[i].first][lr[i].second]++;
  for (int i = 0; i < q; i++) {
    cout << dfs(que[i].first, que[i].second) << endl;
  }

  return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
int n;
long long arr [ 100001 ] ;
long long dp [ 100001 ] ;
long long bus ( int x ) {
  	if ( x == n - 1  ) return  0 ;
 	if ( dp [ x ] != -1 ) return dp [ x ] ;
  	dp [ x ] =  abs ( arr [ x ] - arr [ x + 1 ] ) + bus ( x + 1 ) ;
  	if ( x != n - 2 ) dp [ x ] = min ( dp [ x ] ,   abs ( arr [ x ] - arr [ x + 2  ] ) + bus ( x + 2 ) );
  	return dp [ x ] ;
}
int main ( ) {
  memset ( dp , -1 , sizeof dp ) ;
  cin>>n;
  for ( int i = 0 ; i < n ; i++ ) cin >> arr [ i ] ;  
  cout<<bus ( 0 ) <<endl;
}

Measured memory_bytes: 4992
#include<stdio.h>
#include<string.h>
int main()
{
    char s[201];
    char t[101];
    char p[101];
    
    scanf("%s", s);
    scanf("%s", p);
    
    strcpy(t, s);
    strcat(s, t);
    
    if (strstr(s, p) == NULL){
        printf("No");
    }else {
        printf("Yes");
    }
    printf("\n");
    
    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r", stdin);
    //freopen("output.txt","w",stdout); 
    int n; cin>>n;
    int r[n+1]={};
    int w[n+1]={};
    for(int i=1;i<=n;i++)
    {
        r[i] = r[i-1];
        w[i] = w[i-1];
        char c ; cin>>c;
        if(c=='R') r[i]++;
        else w[i]++;
    }

    int ans = min(r[n],w[n]);
    for(int i=1;i<n;i++)
    {
       int change = max(w[i],r[n]-r[i]);
       ans = min(ans,change);

    }

    cout<<ans;
}   
   

Measured memory_bytes: 5208
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int a,b;
    cin>>a>>b;
    bool chex=false;
    for(float i=0;i<=1000000;i++)
    {
        int k=i*(0.08);
        int k1=i*(0.1);
        if(k==a && k1==b)
        {
            chex=true;
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
    return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N, sum;
  double K;
  sum = 0;
  cin >> N >> K;
  
  for (int i = 1 ; i <= N ; i++ )
  {
    double x;
    cin >> x;
    
    if ( x < K/2 )
      sum += 2*x;
    
    else
      sum += 2*(K - x);
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*void mayank()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}*/
#define ll long long
#define inf 1e9
const int mxN = 1e6;
ll a[mxN + 10], b[mxN + 1];
int main()
{
	//mayank();
	int n, x, t;
	cin >> n >> x >> t;
	int ans = (n / x) * t;
	if (n % x > 0) {
		ans += t;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String... args) throws IOException {
        final int[] targetAry = load();

        insertionSort(targetAry);
    }

    public static int[] load() throws IOException {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int[] nums = new int[n];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = scanner.nextInt();
        }

        return nums;
    }

    public static void insertionSort(final int[] targetAry) {
        for (int i = 0; i < targetAry.length; i++) {
            for (int j = i; 0 < j; j--) {
                if (targetAry[j - 1] > targetAry[j]) {
                    swap(targetAry, j - 1, j);
                }
                if ((1 < j) && (targetAry[j - 1] > targetAry[j - 2])) {
                    break;
                }
            }

            print(targetAry);
        }
    }

    public static void swap(final int[] targetAry, final int from, final int to) {
        final int tmp = targetAry[to];
        targetAry[to] = targetAry[from];
        targetAry[from] = tmp;
    }

    public static void print(final int[] targetAry) {
        final StringBuilder sb = new StringBuilder();
        for (int j = 0; j < targetAry.length; j++) {
            sb.append(targetAry[j]).append(j != targetAry.length - 1 ? ' ' : '\n');
        }
        System.out.print(sb.toString());
    }
}

Measured memory_bytes: 21652
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
const int MAXN = 100500;
int arr[MAXN];
int n;

int main()
{                                                     
	ios_base::sync_with_stdio(0);
	
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];

	int ans = 0;
	int i = 0;

	while (i < n)
	{
		while (i < n - 1 && arr[i] == arr[i + 1])
		{
			i++;
		}

		if (i == n - 1)
		{
			ans++;
			break;
		}

		bool is_dec = arr[i] > arr[i + 1];

		while (i < n - 1 && 
			(is_dec && arr[i] >= arr[i + 1] || !is_dec && arr[i] <= arr[i + 1]))
			i++;

	
		i++;
		ans++;
	}

	cout << ans << '\n';
	
	
	return 0;
}


Measured memory_bytes: 640
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int A = sc.nextInt();
	int B = sc.nextInt();
	if(A==B) System.out.println(2*A);
	else if(A>B)System.out.println(A+A-1);
	else System.out.println(B+B-1);
    }
}

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

int main(){
	
	string a, b;
	int n = 0;
	
	getline( cin , a ) ;
	
	for(int i = 0; i < a.size(); ++i){
		
		if(a[i] >= 'A' && a[i] <= 'Z'){
			
			a[i] += 'a' - 'A' ;
		}
	}
	while(1){
		
		cin >> b;
		
		if(b == "END_OF_TEXT") break;
		
		for(int i = 0; i < b.size(); ++i){
		
			if(b[i] >= 'A' && b[i] <= 'Z'){
			
				b[i] += 'a' - 'A';
			}
		}
		
		if(b == a) ++n;
	}
	
	cout << n << endl;
	
	return 0;
}

Measured memory_bytes: 1192
from heapq import heappop, heappush

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

h = []

ans = 0

ab.sort()
i = 0
for d in range(1, m+1):
    while i < n:
        if ab[i][0] <= d:
            heappush(h, - ab[i][1])
            i += 1
        else:
            break
    if len(h) > 0:
        ans -= heappop(h)

print(ans)

Measured memory_bytes: 31596
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 1000000000;
using namespace std;

struct data{
    int a, b, c;
};

const int N = 500;

int main(){
    int n, ma, mb;
    cin >> n >> ma >> mb;

    data d[46];
    rep(i,n) cin >> d[i].a >> d[i].b >> d[i].c;

    //dp[i][j] := i : jにするための最小のコスト
    int dp[N][N];
    rep(i,N) rep(j,N) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,n){
        for(int j = N - 1; j >= 0; j--){
            for(int k = N - 1; k >= 0; k--){
                if(j - d[i].a >= 0 && k - d[i].b >= 0){
                    dp[j][k] = min(dp[j][k], dp[j - d[i].a][k - d[i].b] + d[i].c);
                }
            }
        }
    }
    int i = 1, ans = INF;
    while(i * ma < N && i * mb < N){
        ans = min(ans, dp[i * ma][i * mb]);
        i++;
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n;
	cin >> n;
	int x = n;
	vector<int> ans;
	for(int i = 2; i * i <= x; i++) {
		while(x % i == 0) {
			x /= i;
			ans.push_back(i);
		}
	}
	if(x > 1) {
		ans.push_back(x);
	}
	sort(ans.begin(), ans.end());
	cout << n << ":";
	for(int i = 0; i < ans.size(); i++) {
		cout << " " << ans[i];
	}
	cout << endl;
	return 0;	
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {

	int n; cin >> n;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ll a; cin >> a;
		ll cnt = 0;
		while (true) {
			if (a % 2 != 0) {
				break;
			}
			a /= 2;
			cnt++;
		}
		ans += cnt;
	}

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

Measured memory_bytes: 256
//abc153E
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
  int h, n, i, k;
  scanf("%d %d", &h, &n);
  int dp[h], a[n], b[n];//dp:HPをh減らすために必要な最小魔力、a:AtackPoint、b:MagicPoint
  for(i=0; i < n; i++)
    scanf("%d %d", &a[i], &b[i]);

  for(i=0; i < h; i++){
    dp[i]=(1 + i / a[0]) * b[0];
    //printf("%d ", dp[i]);
  }
  //printf("\n");

  for(i=1; i < n; i++){
    for(k=0; k < h; k++){
      if(k < a[i]){
        if(dp[k] > b[i]) dp[k]=b[i];
      }else if(dp[k] > dp[k - a[i]] + b[i]) dp[k]=dp[k - a[i]] + b[i];
      //printf("%d ", dp[k]);
    }
    //printf("\n");
  }
  printf("%d", dp[h-1]);

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll h, w, m;
    cin >> h >> w >> m;
    vpll vp;
    map<ll, ll> mph, mpw;
    rep(i, m) {
        ll _h, _w;
        cin >> _h >> _w;
        mph[_h]++;
        mpw[_w]++;
        vp.emplace_back(_h, _w);
    }
    sort(vp.begin(), vp.end());
    vpll vph, vpw;  // count, h/w
    for(auto i = mph.begin(); i != mph.end(); ++i) {
        vph.emplace_back(i->second, i->first);
    }
    sort(vph.begin(), vph.end(), greater<pll>());
    for(auto i = mpw.begin(); i != mpw.end(); ++i) {
        vpw.emplace_back(i->second, i->first);
    }    
    sort(vpw.begin(), vpw.end(), greater<pll>());
    ll maxh = vph[0].first;
    ll maxw = vpw[0].first;
    ll ans = maxh + maxw - 1;
    bool skip = false;
    for(int i = 0; i < vph.size(); ++i) {
        if(maxh > vph[i].first) break;
        if(skip) break;
        ll curh = vph[i].second;
        for(int j = 0; j < vpw.size(); ++j) {
            if(maxw > vpw[j].first) break;
            if(skip) break;
            ll curw = vpw[j].second;
            if(!binary_search(vp.begin(), vp.end(), make_pair(curh, curw))) {
                ++ans;
                skip = true;
            }
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 62472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxV = 90010;
const int maxN = 1e6+10;
const int inf = 0x3f3f3f3f;
const ll MOD = 1e9+7;
const ll INF = 1000000000000000010LL;


ll t[maxN];
ll power(ll x,ll p)
{
	if(p == 0)
	{
		return 1;
	}
	ll t = power(x,p/2);
	t = t*t%MOD;
	if(p%2==1)
	{
		t = t*x%MOD;
	}
	return t;
}
ll calc(ll n,ll m)
{
	return t[n] * power(t[m],MOD-2)%MOD * power(t[n-m],MOD-2)%MOD;
}
int main() {
	ll X,Y;
	scanf("%lld %lld",&X,&Y);
	if((X+Y)%3 != 0)
	{
		puts("0");
		return 0;
	}
	t[0] = 1;
	for(ll i=1;i<=1000000;i++)
	{
		t[i] = (t[i-1]*i)%MOD;
	}
	if((2*X-Y)%3 == 0 && (2*Y-X)%3 == 0)
	{
		ll a = (2*X-Y)/3;
		ll b = (2*Y-X)/3;
		if(a>=0 && b>=0)
		{
			ll ans = calc(a+b,a);
			cout<<ans<<endl;
		}
		else
		{
			puts("0");
			return 0;
		}
	}
	else
	{
		puts("0");
	}
	return 0;
}

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

while True:
    A.sort()
    B=[A[0]]


    for i in range(len(A)):
        b = A[i]%B[0]
        if b != 0:
            B.append(b)

    if len(B)==1:
        print(B[0])
        break
    else :
        A = B

Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 10;


signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int A, B, Q;
  cin >> A >> B >> Q;
  vector<int> S(A+2), T(B+2), X(Q);
  S[0] = -1 * INF, T[0] = -1 * INF;
  S[A+1] = INF, T[B+1] = INF;
  for(int i=1;i<=A;i++) cin >> S[i];
  for(int i=1;i<=B;i++) cin >> T[i];
  rep(i, Q) cin >> X[i];
  rep(i, Q){
    int ans;
    int c = upper_bound(S.begin(), S.end(), X[i]) - S.begin();
    int d = upper_bound(T.begin(), T.end(), X[i]) - T.begin();
    ans = max(S[c], T[d]) - X[i];
    ans = min(ans, abs(X[i] - min(S[c-1], T[d-1])));
    ans = min(ans, abs(S[c] - T[d-1]) + min(S[c]-X[i], X[i]-T[d-1]));
    ans = min(ans, abs(T[d] - S[c-1]) + min(T[d] - X[i], X[i] - S[c-1]));
    cout << ans << endl;
  }

}

Measured memory_bytes: 3712
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
typedef long long ll;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,m; cin >> n >> m;
    ll A[10005];
    for(int i=0;i<m;i++){
        ll a; cin >> a;
        n -= a;
    }
    if(n < 0) cout << -1 << endl;
    else cout << n << endl;
    return 0;
}

Measured memory_bytes: 3656
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others

//Hang in there!

using namespace std;


int main() {
	string s;
	cin >> s;
	int l = INT_MAX;
	int r = INT_MIN;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A') {
			l = min(l, i);
		}
		if (s[i] == 'Z') {
			r = max(r, i);
		}
	}
	cout << r - l + 1 << endl;
}


Measured memory_bytes: 640
N, K = map(int, input().split())
S = str(input())
S = 'R' + S + 'L' # N+2

M1 = 0 # +2できる場所
M2 = 0 # +1できる場所
for n in range(N+1):
  if S[n]+S[n+1] == 'RL':
    if n == 0 or n == N:
      M1 += 1
    else:
      M2 += 1
      
cur_h = N - (M2*2) - (M1*1)
if cur_h == N-1:
    print(cur_h)
    exit()


if K < M2:
  res = cur_h + 2*K
elif M2 <= K and K < M2+M1:
  res = cur_h + 2*M2 + 1*(K-M2)
else:
  res = cur_h + 2*M2 + 1*M1

if res == N:
  res -= 1
print(res)

  

Measured memory_bytes: 3316
#include <algorithm>
#include <array>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)

#define pl cerr << '@' << __LINE__ << endl
#define pv(x) cerr << #x << ": " << x << endl

int main(void) {
  int n;
  cin >> n;
  array<vector<uint64_t>, 3> in;
  array<vector<uint64_t>, 3> comb;
  for (auto& x : in) x.resize(n);
  for (auto& x : comb) x.resize(n);
  for (auto& x : comb[0]) x = 1;

  rep(i, 3) rep(j, n) cin >> in[i][j];
  rep(i, 3) sort(in[i].begin(), in[i].end());

  pv(n);
  for (int i = 1; i < 3; i++) {
    int a, b;
    a = b = 0;
    comb[i][0] = 0;

    while (true) {
      while (in[i - 1][a] >= in[i][b]) {
        b++;
        if (b == n) goto END;
        pv(b);
        comb[i][b] = comb[i][b - 1];
      }
      pv(a);
      comb[i][b] += comb[i - 1][a];
      a++;
      if(a == n) break;
    }
    END:
    b++;
    for(; b < n; b++) comb[i][b] = comb[i][b-1];
  }

  cout << accumulate(comb[2].begin(), comb[2].end(), (uint64_t)0) << endl;

  return 0;
}

Measured memory_bytes: 7040
#include "bits/stdc++.h"
using namespace std;
void __dump(int x){cerr << x;}
void __dump(long long x){cerr << x;}
void __dump(long double x){cerr << fixed << setprecision(3) << x;}
void __dump(char x){cerr << '\'' << x << '\'';}
void __dump(const string &x){cerr << '"' << x << '"';}
void __dump(const char *x){cerr << '"' << x << '"';}
void __dump(bool x){cerr << (x ? "true" : "false");}
void _dump(){cerr << "\n";}
template <typename T, typename U> void __dump(const pair<T, U> &x){cerr << '{'; __dump(x.first); cerr << ','; __dump(x.second); cerr << '}';}
template <typename T, typename U, typename V> void __dump(const tuple<T, U, V> &x){cerr << '{'; __dump(get<0>(x)); cerr << ',';  __dump(get<1>(x)); cerr << ',';  __dump(get<2>(x)); cerr << '}';}
template <typename T> void __dump(const T& x){int f=0; cerr << '{'; for(auto&i:x) cerr << (f++ ? "," : ""), __dump(i); cerr << "}";}
template <typename T, typename ... U> void _dump(T t, U ... u){__dump(t); if(sizeof...(u)) cerr << ", "; _dump(u...);}
#define dump(x ...) cerr  <<  "|| "  <<  # x  <<  "  =  ", _dump(x) 
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ln '\n'
#define __ ' '
#define LL long long
#define LD long double
#define pii pair<int,int>
const int INF = 1e9;
const int N = 1e3;

int n, arr[N+3];
vector<pii> group[2];
vector<int> taken[2];
LL sum[2];
set<int> need;
vector<int> operations;

int main(){ FAST
	cin >> n;
	for(int i=1; i<=n; ++i){
		cin >> arr[i];
	}

	for(int i=1; i<=n; ++i){
		group[i%2].emplace_back(arr[i], i);
	}

	for(int g=0; g<=1; ++g){
		sort(all(group[g]));

		sum[g] = group[g].back().first;
		taken[g].emplace_back(group[g].back().second);

		for(int i=size(group[g])-2; i>=0; --i){
			if(group[g][i].first <= 0) break;
			sum[g] += group[g][i].first;
			taken[g].emplace_back(group[g][i].second);
		}
	}

	int best = (sum[0] > sum[1]) ? 0 : 1;
	
	for(int ind: taken[best]) need.insert(ind);

	vector<int> v(n);
	for(int i=1; i<=n; ++i){
		v[i-1] = i;
	}

	while(size(v) > 1){
		if(!need.count(v.front())){
			operations.emplace_back(1);
			v.erase(v.begin());
		}
		else if(!need.count(v.back())){
			operations.emplace_back(size(v));
			v.erase(v.begin()+size(v)-1);
		}
		else{
			assert(size(v) >= 3);

			if(need.count(v[2])){
				operations.emplace_back(2);
				v.erase(v.begin());
				v.erase(v.begin());
			}
			else{
				assert(size(v) >= 5);
				operations.emplace_back(3);
				v.erase(v.begin()+1);
				v.erase(v.begin()+1);
			}
		}
	}

	cout << sum[best] << ln;
	cout << size(operations) << ln;
	for(int ind: operations) cout << ind << ln;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  vi a = {0, 6000, 4000, 3000, 2000};
  rep(i, 4) {
    int t, n;
    cin >> t >> n;
    cout << a[t] * n << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  int A[N];

  rep(cnt, N) {
    cin >> A[cnt];
  }
  
  int num = 0;
  while(1) {
    int sum = 0;
    rep(cnt, N) {
      sum += A[cnt] % 2;
      A[cnt] /= 2;
    }
    
    if (sum == 0) {
      num++;
    } else {
      break;
    }
  }
  
  cout << num << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
struct line {
	int l, r;
	bool operator < (const line& b) const {
		if (l != b.l) {
			return l < b.l;
		}
		return r < b.r;
 	}
};
int n;
vector<line> a;
vector<int> memo;
int solve(int ind) {
	if (ind == n - 1) {
		return 1;
	}
	if (ind == n) {
		return 0;
	}
	if (memo[ind] != 0) {
		return memo[ind];
	}
	line p = {a[ind].r, -1};
	int nxt = upper_bound(a.begin(), a.end(), p) - a.begin();
	int now = 1 + solve(nxt);
	now = max(now, solve(ind + 1)); 
	memo[ind] = now;
	return memo[ind];
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	cin >> n;
	a.resize(n);
	memo.resize(n);
	for (int i = 0; i < n; ++i) {
		int x, r;
		cin >> x >> r;
		a[i].l = x - r;
		a[i].r = x + r;
	}
	sort(a.begin(), a.end());
	cout << solve(0) << '\n';
	return 0;
}


Measured memory_bytes: 4608
/*maximum subarray sum 
 * kadane algo space optimize dp
*/




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


signed main()
{
	string a,b;
	cin>>a>>b;
	int n = a.length();
	int m = b.length();
	int dp[n+1][m+1];
	for(int i = 0;i<=n;i++)
	{
		dp[i][0] = 0;
	}
	for(int i = 0;i<=m;i++)
	{
		dp[0][i] = 0;
	}
	
	for(int i = 1;i<=n;i++)
		{
			for(int j = 1;j<=m;j++)
			{
				if(a[i-1]==b[j-1])
				dp[i][j] = dp[i-1][j-1] +1 ;
				else
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
				 
			}
		}
	//~ for(int i = 0;i<=n;i++){
		//~ for(int j = 0;j<=m;j++)
		//~ {
			//~ cout<<dp[i][j]<<" ";
		//~ }
		//~ cout<<endl;}
	int len = dp[n][m];
	string s="";
	int i = n, j = m;
	while(i > 0 && j > 0)
	{
		if(a[i-1]==b[j-1])
		{
			s+=a[i-1];
			--i,--j;
		}
		else if(dp[i-1][j] > dp[i][j-1])
		--i;
		else 
		--j;
	}
	
	reverse(s.begin(),s.end());
	cout<<s<<endl;
	
}


Measured memory_bytes: 73936
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] array=new int[20];
        int c=0;
        for(int i=0;;i++){
            int n=sc.nextInt();
            int[] array2=new int[n];
            if(n==0){
                break;
            }
            int min=1001;
            int max=-1;
            int cmin=0,cmax=0;
            int S=0;
            for(int j=0;j<=n-1;j++){
                array2[j]=sc.nextInt();
                if(array2[j]<min){
                    cmin=j;
                    min=array2[j];
                }
                if(array2[j]>max){
                    cmax=j;
                    max=array2[j];
                }
            }
            for(int j=0;j<=n-1;j++){
                if((j==cmin)||(j==cmax)){
                    continue;
                }else{
                    S+=array2[j];
                }
            }
            array[i]=(int)S/(n-2);
            S=0;
            c++;
        }
        for(int i=0;i<c;i++){
            System.out.println(array[i]);
        }
    }
}


Measured memory_bytes: 28936
#include <stdio.h>
#include <iostream>
#include <vector>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;

ll dp[100025] = {};
bool br[100025] = {};

int main() {
	int n,m;
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int a;
		cin >> a;
		br[a] = true;
	}
	dp[0] = 1;
	for(int i = 0; i < n; i++) {
		if(!br[i+1]) dp[i+1] = (dp[i]+dp[i+1])%MOD;
		if(!br[i+2]) dp[i+2] = (dp[i]+dp[i+2])%MOD;
	}
	cout << dp[n] << endl;
}


Measured memory_bytes: 1152
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(){};
    Edge(int to0, int cost0){to = to0; cost = cost0;}
};

long long minSpanningTree(const vector<vector<Edge> >& edges)
{
    int n = edges.size();
    vector<bool> used(n, false);
    int usedNum = 0;
    vector<int> minCost(n, INT_MAX);
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, 0));

    long long ret = 0;
    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(used[v])
            continue;
        ret += p.first;
        used[v] = true;
        if(++usedNum == n)
            return ret;
        for(unsigned i=0; i<edges[v].size(); ++i){
            Edge e = edges[v][i];
            if(!used[e.to] && e.cost < minCost[e.to]){
                minCost[e.to] = e.cost;
                q.push(make_pair(e.cost, e.to));
            }
        }
    }
    return -1;
}

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<vector<Edge> > edges(n);
        for(int i=0; i<m; ++i){
            int a, b, cost;
            cin >> a >> b >> cost;
            edges[a].push_back(Edge(b, cost));
            edges[b].push_back(Edge(a, cost));
        }

        cout << minSpanningTree(edges) << endl;
    }
}

Measured memory_bytes: 0
n, k = map(int, input().split())
hashMap = {i+1:0 for i in range(n)}
for _ in range(k):
  input()
  for i in map(int, input().split()):
    hashMap[i] += 1

ans = 0
for i,v in hashMap.items():
  if v == 0:
    ans += 1
print(ans)
  

Measured memory_bytes: 9184