akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <stdio.h>
#include <functional>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MAX_INF = 9223372036854775807;
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init, ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T>& v) {
	T ans = -INF;
	rep(i, 0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}


template <class C>
void print(const C & c, std::ostream & os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}
/*
ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}
*/
bool sortreverse(ll a, ll b) {
	return a > b;
}

ll kiriage(ll a, ll b) {
	if (a % b == 0)return a / b;
	return a / b + 1;
}

ll n, m, x, y, t, q, s;

int main() {
	cin >> n;
	vl a(n);
	rep(i, 0, n) {
		cin >> a[i];
	}
	map<ll,ll> check;
	rep(i, 0, n) {
		auto itr = check.lower_bound(a[i]);
		//printf("#%d\n",(--itr) == check.end());
		if (itr == check.begin()) {
			itr = check.end();
		}
		else {
			itr--;
		}
		if (itr != check.end()) {
			if (itr->second == 1)check.erase(itr->first);
			else check[itr->first]--;
		}
		
		if (check.find(a[i]) != check.end()) {
			check[a[i]] ++;
		}
		else {
			check[a[i]] = 1;
		}
	}
	ll ans = 0;
	for (auto itr = check.begin(); itr != check.end(); ++itr) {
		ans += itr->second;
	}
	printf("%lld\n", ans);
}

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

int main() 
{
    int n;
    cin >> n;
    int d[n];
    rep(i,n) d[i] = 0;
    for (int i= 2; i<=n; i++) {
        int a;
        cin >> a;
        a--;
        d[a]++;
    }
    rep(i,n) cout << d[i] << endl;
    return 0;
}


Measured memory_bytes: 4416
# n = int(input())
# height = [int(x) for x in input().split()]
# cnt =0

# for i_index, i in enumerate(height[:-1]):
#     if i+i_index >= n:
#         continue

#     for j_index, j in enumerate(height[i_index+i+1:]):
#         if j+i == j_index+i+1:
#             cnt += 1
#             # print(i,j,j_index)
            
# print(cnt)
def count(dic,x):
    if x in dic:
        dic[x]+=1
    else:
        dic[x]=1
 
N=int(input())
A=list(map(int,input().split()))
dic1={}
dic2={}
s=0
for i in range(N):
    count(dic1,i-A[i])
    count(dic2,i+A[i])
for x in dic1:
    if x in dic2:
        s+=dic1[x]*dic2[x]
print(s)

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using vld = vector<ld>; 
using vi = vector<int>; using vvi = vector<vi>;
using P = pair<ll, ll>;

template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) {  o << "(" << v.first << ", " << v.second << ")"; return o; }
template<size_t...> struct seq{}; template<size_t N, size_t... Is> struct gen_seq : gen_seq<N-1, N-1, Is...>{}; template<size_t... Is> struct gen_seq<0, Is...> : seq<Is...>{};
template<class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get<Is>(t)), 0)...}; }
template<class Ch, class Tr, class... Args> 
auto operator<<(basic_ostream<Ch, Tr>& os, tuple<Args...> const& t) -> basic_ostream<Ch, Tr>& { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; }
ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; cout << endl; } return o; }
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]";  return o; }
template <typename T>  ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U>  ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U>  ostream &operator<<(ostream &o, const unordered_map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]";  return o; }
#define VN(v) # v
#define print(a) cout << a << "#" << VN(a) << endl;

static const double EPS = 1e-14;
static const long long INF = 1e18;
static const long long mo = 1e9+7;

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ld d; cin >> d;
    ld ret = d*sqrtl(2.0l);
    if (d < sqrtl(floorl(d)*floorl(d)+1.0l)) {
        chmax(ret, floorl(d)+1.0l);
    }
    cout << setprecision(40) << ret << endl;
    
    return 0;
}

Measured memory_bytes: 3348
use std::cmp;

fn main() {
    const A: usize= 10000;
    const B: usize= 5000;
    const C: usize= 1000;

    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut ws = s.trim().split_whitespace();
    let n: usize = ws.next().unwrap().parse().unwrap();
    let y: usize = ws.next().unwrap().parse().unwrap();

    let p = cmp::min(n, y/A);
    let q = cmp::min(n, y/B);

    for i in 0..p+1 {
        for j in 0..cmp::min(q, n-i)+1 {
            if A*i+B*j+C*(n-i-j) == y {
                println!("{} {} {}", i, j, n-i-j);
                return;
            }
        }
    }

    println!("-1 -1 -1");
}



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

using namespace std;

int N;
vector<int> h;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> N;
    h.resize(N);
    for (int i=0; i<N; ++i) {
        cin >> h[i];
    }
    
    int res = 0;
    for (int hh=1; hh<=100; ++hh) {
        int num = 0;
        bool flag = false; // 直前に見たh_iが高さhh以上か
        for (int i=0; i<N; ++i) {
            if (h[i] >= hh) {
                if (!flag) {
                    ++num;
                }
                flag = true;
            } else {
                flag = false;
            }
        }
        res += num;
    }

    cout << res << endl;
    
    return 0;
}


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

int main(){
  int i,n,taro=0,hanako=0;
  char w_taro[101],w_hanako[101];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %s",w_taro,w_hanako);
    if(strcmp(w_taro,w_hanako)>0) taro+=3;
    if(strcmp(w_taro,w_hanako)==0){taro++; hanako++;}
    if(strcmp(w_taro,w_hanako)<0) hanako+=3;
  }
  printf("%d %d\n",taro,hanako);
  return 0;
}

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

int main(){
  int N;
  char S[10000];
    cin>>N>>S;
  int unko=strlen(S);
  for(int i=0;i<unko;i++){
    int se=S[i];
    se=((se-'A')+N)%26+'A';
      putchar(se);
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map> 
#include <algorithm>
#include <cstring>
using namespace std; 

void solve(){

}

int main(){
  int t; 
  cin>>t; 
  int ans=0; 
  for(int i=0; i<t; i++){
      int num; 
      cin>>num; 
      if(i%2==0 && num%2==1){
          ans++;
      }
  }
  cout << ans << "\n"; 
 return 0;
}

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

int main() {
  long long int N;
  cin >> N;
  long long int ans = 100;
  for (long long int A = 1; A <= sqrt(N); A++) {
    if (N % A == 0) {
      long long int B = N / A;
      long long int X = log10(B) + 1;
      ans = min(ans, X);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int A, B;
	//long long N, M;
	//double d, e;
	//string s, t;
	//vector<int> v;
	//vector<pair<int, int>> pl;

	//while() {}
	//for(int i=0; i<N; i++) {}
	
	cin >> A >> B;
	if((A+B)%2) {
		cout << "IMPOSSIBLE";
	} else {
		int result = abs(A-B)/2;
		int K;
		if(A < B) {
			K = A + result;
		} else {
			K = B + result;
		}
		cout << K;
	}
	// cout << "[deb: val ]" << val <<endl;
	return 0;
}



Measured memory_bytes: 256
n, c, k = list(map(int, input().split()))
ts = []
for i in range(n):
    ts.append(int(input()))
ts = sorted(ts)
cnt = 0
fst = 0
ret = 1
for p in ts:
    if fst==0:
        fst = p
        cnt += 1
    elif p-fst > k or cnt >= c:
        ret += 1
        cnt = 1
        fst = p
    else:
        cnt += 1
    # print("\t", cnt ,fst, ret, p)
print(ret)




Measured memory_bytes: 8280
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)
// コンパイル　g++ -std=c++17 a.cpp

int main() {
    vector<vector<ll>> bingo(3, vector<ll>(3));
    rep(i,3){
        rep(j,3){
            cin >> bingo.at(i).at(j);
        }
    }
    ll n;
    cin >> n;
    vector<ll> vec(n);
    rep(i, n) cin >> vec.at(i);

    vector<vector<ll>> res(3, vector<ll>(3));

    rep(i,n){
        rep(j,3){
            rep(k,3){
                if(vec.at(i) == bingo.at(j).at(k)){
                    res.at(j).at(k)++;
                }
            }
        }
    }

    string ans = "No";
    //横
    rep(i,3){
        if(res.at(i).at(0) == 1 && res.at(i).at(1) == 1 && res.at(i).at(2) == 1){
            ans = "Yes";
        }
    }
    //縦
    rep(i,3){
        if(res.at(0).at(i) == 1 && res.at(1).at(i) == 1 && res.at(2).at(i) == 1){
            ans = "Yes";
        }
    }
    //ななめ
    if(res.at(0).at(0) == 1 && res.at(1).at(1) == 1 && res.at(2).at(2) == 1){
        ans = "Yes";
    }
    if(res.at(0).at(2) == 1 && res.at(1).at(1) == 1 && res.at(2).at(0) == 1){
        ans = "Yes";
    }

    cout << ans << endl;





}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>

#define REP(idx, end) for(int idx = 0; idx < end; ++idx)

using namespace std;
typedef long long lint;
const int MOD = 1000000007;

int main() {

	cin.tie(0);

	int A, B, C, D;
	cin >> A >> B >> C >> D;

	if (A*B > C*D) {

		cout << A * B;
	}
	else cout << C * D;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>		// standard input output
#include <iostream>		// input output stream, cin cout( console in console out)
#include <cmath>		// circle math ( sin, con, sinh
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>		// input output manipulation

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep3(i, a, n) for(int i = (int)(a); i < (int)(n); i++)
#define ll long long

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }




int main() {
  int N,K; // 変数の宣言
  cin >> N >> K; // 標準入力
  vector<int> p(N);
  rep(i,N) {
    cin >> p.at(i);
  }

  sort(p.begin(),p.end());
  int ans=0;
  rep(i,K){
    ans +=p[i];
    
  }
  
 cout << ans << endl;
}



Measured memory_bytes: 3232
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.1415;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

//////////////////////////////////

vector<vector<int>> bingo(3, vector<int>(3));
vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;

	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

ll getGcd(ll a, ll b) {
	if (a < b) {
		ll temp = b;
		b = a;
		a = temp;
	}

	ll r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

int getNum(ll target) {

	int bottom = 0;
	int top = 151;
	while (1 < top - bottom) {
		int middle = (top + bottom) / 2;
		if (false/*target < line[middle]*/)top = middle;
		else bottom = middle;
	}
	return bottom;
}

int main() {

	ll A, B, C, K; cin >> A >> B >> C >> K;
	ll ans = 0;
	if (K < A) {
		ans += K;
	}
	else if (K <= A + B) {
		ans += A;
	}
	else {
		ans += A;
		K -= (A + B);
		ans -= K;
	}
	cout << ans << endl;
}




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

int res = 0, h, w;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
char land[105][105];

void dfs(int x, int y) {
    char tmp = land[x][y];
    land[x][y] = '.';
    for (int i = 0; i < 4; ++i) {
        int nx = x + dx[i], ny = y + dy[i];
        if (nx >= 0 && nx < h && ny >= 0 && ny < w && land[nx][ny] == tmp)
            dfs(nx, ny);
    }
}

int cal_blocks() {
    res = 0;
    for (int i = 0; i < h; ++i) 
        for (int j = 0; j < w; ++j) {
            if (land[i][j] != '.') {
                res += 1;
                dfs(i, j);
            }
        }
    return res;
}

int main() {
    while (cin >> h >> w) {
        if (h == 0 && w == 0) break;
        for (int i = 0; i < h; ++i) 
            for (int j = 0; j < w; ++j) 
                cin >> land[i][j];
        cout << cal_blocks() << endl;
    }
    return 0;
}


Measured memory_bytes: 3556
#include<stdio.h>

int main(){
int X,Y;
  int t=0;
  scanf("%d %d",&X,&Y);
 for(int i=2*X;i<4*X+2;i+=2){
   if(Y==i){
     t=1;
     break;
   }
 }
  if(t==1)printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 1644
#include <iostream>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
using namespace std;
vector <int> v ;
int dp[100006]; 
int n , a ; 
int solve (int idx)
{
	
	if (idx >=n )
	return 1e9+7; 
	
	if (idx==n-1) return 0; 
	
	if(dp[idx]!=-1)
	return dp[idx]; 
	
	int a = abs(v[idx]-v[idx+1])+solve (idx+1);
	int b = abs(v[idx]-v[idx+2])+solve (idx+2); 
	return dp[idx]=min(a,b); 
}
int main() {
	cin>>n  ; 
	for (int i=0 ; i<n ; i++)
	{
		cin>>a ; 
		v.push_back(a);
	}
	memset (dp, -1 , sizeof dp ); 
	int ans = solve(0); 
	printf("%d",ans ); 
	return 0;
}


Measured memory_bytes: 5880
#include <iostream>
#include <algorithm>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
#define INF 100000000
using namespace std;

int N, A[1000000];

int main(void) {
  while(cin >> N, N) {
    REP(i, 0, N) cin >> A[i];
    sort(A, A + N);

    int ans = INF;
    REP(i, 0, N - 1) ans = min(ans, A[i + 1] - A[i]);
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3116
#include <cstdio>

int n;
int A[200];

int aaa(int target, int sum, int index){
  if(index == n){
    return target == sum;
  }
  if(aaa(target, sum + A[index], index + 1)){
    return 1;
  }
  if(aaa(target, sum, index + 1)){
    return 1;
  }
  return 0;
}

int aaa(int target){
  return aaa(target, 0, 0);
}

int main(){
  int q;
  int M[2000];
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for(int i = 0; i < q; i++){
    scanf("%d", &M[i]);
  }
  for(int i = 0; i < q; i++){
    if(aaa(M[i])){puts("yes");}
    else{puts("no");}
  }
}

Measured memory_bytes: 1000
#include <stdio.h>
int main(void)
{
	int N, A, B ;

	do {
		scanf("%d%d%d", &N, &A, &B);
	} while (N < 1 && 20 < N && A < 1 && 50 < A && B < 1 && 50 < B);

		if (N * A > B) {
			printf("%d\n", B);
		}
		else if (N * A < B) {
			printf("%d\n", N * A);
		}
		else {
			printf("%d\n", B);
		}
	return 0;
}

Measured memory_bytes: 128
N=int(input())
line=input().split(" ")
dp=[]
for i in range(N):
    line[i]=int(line[i])
    dp.append(10000000000)
dp[0]=0
dp[1]=abs(line[1]-line[0])
for j in range(2,N):
    dp[j]=min(dp[j], dp[j-1]+abs(line[j]-line[j-1]))
    dp[j]=min(dp[j], dp[j-2]+abs(line[j]-line[j-2]))
print(dp[N-1])

Measured memory_bytes: 11708
#include<stdio.h>
int A[100000], n;

int BinarySearch(int key)
{
	int left = 0;
	int right = n;
	int mid;
	while(left < right)
	{
		mid = (left + right) / 2;
		if(A[mid] == key)
			return 1;
		if(key > A[mid])
			left = mid + 1;
		else if(key < A[mid])
			right = mid;
	}
	return 0;
}
int main()
{
	int i, q, k, sum = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", &A[i]);
	scanf("%d", &q);
	for(int i = 0; i < q; i++)
	{
		scanf("%d", &k);
		if(BinarySearch(k))
			sum++;
	}
	printf("%d\n", sum);
	return 0;	
		
}



Measured memory_bytes: 2972
N,K = map(int,input().split())
A = list(map(int,input().split()))
hoge = [[]for i in range(200001)]
for i in range(N):
    hoge[A[i]].append(i)
NEXT = [-1]*N
for i in hoge:
    for j in range(-len(i),0):
        NEXT[i[j]] = i[j+1]
i = 1
p = 0
while i < K:
    #print(i,p)
    if NEXT[p] <= p:
        i += 1
    if NEXT[p] == N-1:
        i += 1
    p = (NEXT[p]+1)%N
    if p == 0:
        i = ((K-1)//(i-1))*(i-1)+1
while p < N:
    if NEXT[p] <= p:
        print(A[p],end = " ")
        p += 1
    else:
        p = NEXT[p]+1
print()

Measured memory_bytes: 43968
import java.io.*;
import java.util.*;

public class Main {

    static long mod = (long) (1e9 + 7);

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        int total = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (i != j) {
                    int ans = a[i] * a[j];
                    total += ans;
                }
            }
        }
        out.println(total);
        out.close();
    }

    static long[][] powMat(long[][] a, long pow) {
        if (pow == 1) {
            return a;
        } else {
            if (pow % 2 == 0) {
                return powMat(mul(a, a), pow / 2);
            } else {
                return mul(a, powMat(mul(a, a), pow / 2));
            }
        }
    }

    static long[][] mul(long[][] a, long[][] b) {
        int n = a.length;
        long[][] c = new long[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    c[i][k] = (c[i][k] + (a[i][j] * b[j][k]) % mod) % mod;
                }
            }
        }
        return c;
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 22228
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
 
using namespace std;
 
typedef long long ll;
 
int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> V(N);
    for (ll i=0; i<N; ++i) {
        cin >> V[i];
    }
 
    ll res = 0;
    for (int p=0; p<=min(N, K); ++p) {
        for (int q=0; p+q<=min(N, K); ++q) {
            vector<ll> v;
            ll cur = 0;
            for (int i=0; i<p; ++i) {
                v.push_back(V[i]);
                cur += V[i];
            }
            for (int i=0; i<q; ++i) {
                v.push_back(V[N-1-i]);
                cur += V[N-1-i];
            }
            sort(v.begin(), v.end());
            for (int k=0; k<min(K-p-q, (ll)v.size()); ++k) {
                if (v[k] < 0) cur -= v[k];
            }
            res = max(res, cur);
        }
    }
    
    cout << res << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	long long n,a,b,max,min;
	cin>>n>>a>>b;
	min=a*(n-1)+b;
	max=a+b*(n-1);
	if(a>b)cout<<0<<endl;
	else if(n==1 && a!=b)cout<<0<<endl;
	else cout<<max-min+1<<endl;
	return 0;
}

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

const string T[] = {"dream", "dreamer", "erase", "eraser"};

string S;

bool check(const string& str, int idx){
    for(int i = 0; i < str.length(); i++){
        int Sidx = idx + i;
        if(Sidx > S.length() || str[i] != S[Sidx]){
            return false;
        }
    }
    return true;
}

bool dfs(int idx){
    if(idx == S.length()) return true;

    bool res = false;
    for(int t = 0; t < 4; t++){
        if(S.substr(idx, T[t].size()) == T[t]){
            res |= dfs(idx + T[t].size());
        }
    }
    return res;
}

int main(void){
    cin >> S;
    if(dfs(0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 2432
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 100100
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int a[MAX],n,m,S[MAX],top;
int main()
{
	n=read();m=read();
	for(int i=1;i<=m;++i)
	{
		a[i]=read();
		if(a[i]&1)S[++top]=i;
	}
	if(top>2){puts("Impossible");return 0;}
	if(top)swap(a[1],a[S[1]]);
	if(top>1)swap(a[m],a[S[2]]);
	if(m==1)
	{
		if(a[1]==1)printf("1\n1\n1\n");
		else printf("%d\n2\n%d 1\n",a[1],a[1]-1);
		return 0;
	}
	for(int i=1;i<=m;++i)printf("%d ",a[i]);puts("");
	printf("%d\n",m-(a[m]==1));
	printf("%d ",a[1]+1);
	for(int i=2;i<m;++i)printf("%d ",a[i]);
	if(a[m]>1)printf("%d ",a[m]-1);
	puts("");return 0;
}


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

int main(){
  long long N;
  cin>>N;
  if(N==0){
    cout<<0<<endl;
    return 0;
  }
  vector<int> A(0);
  for(int i=0;N!=0;i++){
    if(N%2==0){
      A.push_back(0);
    }else{
      A.push_back(1);
      if(i%2==0)
        N--;
      else
        N++;
    }
    N/=2;
  }
  for(int i=A.size()-1;i>=0;i--)
    cout<<A[i];
  cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll>vi;
vector<ll> :: iterator vt;
ll arr[200009];
int main()
{
    ll n,a,b,c,t,d,e,x,y,z,j,i,k,flag =0,maxi=LONG_LONG_MIN ,mini=LONG_LONG_MAX,sum=0;
    map<ll,ll>mp;
    map<ll,ll> :: iterator mt;
    string s, ss;
    cin>>a>>b>>c>>x>>y;
    ll sum1 =0 ;
    sum1 = a*x + b*y;
    mini = min(x,y);
    sum = c * mini *2;
    x-=mini;
    y-=mini;
    if(x == 0)
    {

        if(c*2>=b)
        sum+= y*b;
        else
            sum+=y*c*2;
    }
    else if(y == 0)
    {
        if(c*2>=a)
        sum+=x *a;
        else
            sum+=x*c*2;
    }
    cout<<min(sum,sum1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
  int n;
  int sum;
  int *b;
  scanf("%d",&n);
  b=(int*)malloc((n-1)*sizeof(int));
  for (int i=0;i<n-1;i++) scanf("%d",&b[i]);
  sum=0;
  sum+=b[0];
  sum+=b[n-2];
  for (int i=0;i<n-2;i++){
    if (b[i]<b[i+1]) sum+=b[i];
    else sum+=b[i+1];
  }
  printf("%d\n",sum);
  free(b);
  return 0;
}

Measured memory_bytes: 128
#ABC166b
n, k = map(int,input().split())
d = [0]*k
a = [1]*n

for i in range(k):
    d[i] = int(input())
    sunuke_i = map(int,input().split())
    for t in sunuke_i:
        a[t-1]=0
print(sum(a))


Measured memory_bytes: 9188
package main

import (
	"fmt"
)

func main() {
	var n, m, x int
	var d int
	a := make(map[int]int)
	fmt.Scanf("%d %d %d", &n, &m, &x)
	for i := 1; i <= m; i++ {
		fmt.Scanf("%d", &d)
		a[d]++
	}
	fmt.Println(calc(n, m, x, a))
}

func calc(n, m, x int, a map[int]int) int {
	var total1, total2 int
	for i := x; i <= n; i++ {
		total1 += a[i]
	}
	for i := x; i >= 0; i-- {
		total2 += a[i]
	}
	if total1 > total2 {
		return total2
	} else {
		return total1
	}
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void push(int);
int pop(void);
int sp=0, st[100];

int main(){
  char S[100];
  int a;

  while(scanf("%s ",S)!=EOF){
    switch(S[0]){
    case '+':
      push(pop()+pop());
      break;
    case '-':
      a=pop();
      push(pop()-a);
      break;
    case '*':
      push(pop()*pop());
      break;
    case '/':
      a=pop();
      push(pop()/a);
      break;
    default:
      push(atoi(S));
      break;
    }
  }
  printf("%d\n",pop());
  return 0;

}

void push(int w){
  st[sp++]=w;
}

int pop(void){
  return st[--sp];
}

Measured memory_bytes: 552
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>

#define LP(i,n) for(int i=0;i<n;i++)
#define Mset(x,v) memset(x,v,sizeof(x))
#define INF INT_MAX

using namespace std;
using LL=long long;

int I[1005];

int main(){
    int n;
    cin>>n;
    LP(i,n) cin>>I[i];
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(abs(I[i]-I[j])%(n-1)==0){
                cout<<I[i]<<" "<<I[j]<<endl;
                return 0;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3120
//By Vlgd
/*
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int root,par[N],chl[N][21];
int depth(int n){
	if (par[n]==-1) return 0;
	else return 1+depth(par[n]);
}	
main(){
	int n,node,deg,xx;
	scanf("%d",&n);
	for (int i=0;i<n;i++) par[i]=-1;
	for (int i=0;i<n;i++){
		scanf("%d%d",&node,&deg);
		chl[node][0]=deg;
		for (int j=1;j<=deg;j++){
			scanf("%d",&xx);
			chl[node][j]=xx;
			par[xx]=node; 
		}	
	}
	for (int i=0;i<n;i++)
		if (par[i]==-1){
			root=i;
			break;
		}
	for (int i=0;i<n;i++){
		printf("node %d: ",i);
		printf("parent = %d, ",par[i]); 
		printf("depth = %d, ",depth(i));
		if (par[i]==-1) printf("root, ");
		else if (chl[i][0]!=0) printf("internal node, ");
		else printf("leaf, "); 
		printf("["); 
		for(int j=1;j<=chl[i][0];j++){
			printf("%d",chl[i][j]);
			if (j!=chl[i][0]) printf(", "); 
		}
		printf("]\n");
	}
} 
*/
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
struct node{int p,l,r;};
node T[N];
int n,D[N];
void print(int u){
	int i,c;
	cout<<"node "<<u<<": ";
	cout<<"parent = "<<T[u].p<<", ";
	cout<<"depth = "<<D[u]<<", ";
	if (T[u].p==-1) cout<<"root, ";
	else if (T[u].l==-1) cout<<"leaf, ";
	else cout<<"internal node, ";
	cout<<"[";
	for (i=0,c=T[u].l;c!=-1;i++,c=T[c].r){
		if (i) cout<<", ";
		cout<<c;
	}
	cout<<"]"<<endl;
}
int rec(int u,int p){
	D[u]=p;
	if (T[u].r!=-1) rec(T[u].r,p);
	if (T[u].l!=-1) rec(T[u].l,p+1);
}
main(){
	int i,j,d,v,c,l,r;
	cin>>n;
	for (i=0;i<n;i++) T[i].p=T[i].l=T[i].r=-1;
	for (i=0;i<n;i++){
		cin>>v>>d;
		for (j=0;j<d;j++){
			cin>>c;
			if (j==0) T[v].l=c;
			else T[l].r=c;
			l=c;
			T[c].p=v;
		}
	}
	for (i=0;i<n;i++){
		if (T[i].p==-1) r=i;
	}
	rec(r,0);
	for (i=0;i<n;i++) print(i);
}

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


Measured memory_bytes: 7760
#############################################################
class UnionFind():
    def __init__(self, n):
        # 正==子: 根の頂点番号 / 負==根: 連結頂点数
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        #要素xが属するグループの根を返す
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        #要素xが属するグループと要素yが属するグループとを併合する
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        # 要素xが属するグループのサイズ（要素数）を返す
        return -self.parents[self.find(x)]

    def same(self, x, y):
        # 要素x, yが同じグループに属するかどうかを返す
        return self.find(x) == self.find(y)

    def members(self, x):
        # 要素xが属するグループに属する要素をリストで返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        # すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        # グループの数を返す
        return len(self.roots())

    def all_group_members(self):
        # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
#############################################################

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = []

N, M = LI()
xyz = [LI() for _ in range(M)]
cou = int(0)
uf = UnionFind(N)

for i in range(M):
    if not uf.same(xyz[i][0]-1, xyz[i][1]-1):
        uf.union(xyz[i][0]-1, xyz[i][1]-1)

cou = uf.group_count()
ans = cou

print(ans)


Measured memory_bytes: 32256
/*********************************************************************| 
|---------|    /\  ....                  ....                         |         
     |        /  \   \                    /  /------| ----- |-------| |
     |       /    \   \                  /  /           |   |         |
     |      /      \   \       /\       /  |            |   |         |
     |     /        \   \     /  \     /   |---|        |   |----|    |
     |    /__________\   \   /    \   /        |---|    |   |         |
     |   /            \   \ /      \ /              |   |   |         |
     |  /              \   |        |               /   |   |         |
     _ __              __ ...      ...      |------/  ----- _         |
                                                                      |  
        Md Tawsif Rahman                                              |
        Institute Of Information Technology                           |
        Jahangirnagar University                                      |                                                                         
                                                                      |
**********************************************************************/                 
#include<bits/stdc++.h>

using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define pii pair <int, int>
#define xx first
#define yy second
#define vc vector < int >
#define vcll vector < ll > 
#define f(i, c, n) for(i = c; i < n; i++)
#define fr(i, n, c) for(i = n - 1; i >= 0; i--) 
#define vbe(a) a.begin(), a.end()
#define mem(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))

#define srti(a, n) sort(a, a + n)
#define srtd(a, n) sort(a, a + n, greater<int>())
#define LB(a, x) (lower_bound(vbe(a), x) - a.begin())
#define UB(a, x) (upper_bound(vbe(a), x) - a.begin())

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

int i, j, k;
vc prime;
vc is_prime;

int gcd(int a, int b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return (a * b) / (__gcd(a, b));
}
 
void solve() {

    int n; cin >> n;
    int arr[n + 10];
    f(i, 0, n) cin >> arr[i];
    int crt = 1;
    int ans = 0;
    f(i, 0, n) {
        if(arr[i] == crt) {
            ans++;
            crt++;
        }
    }
    
    if(ans == 0) ans = n + 1;
    cout << n - ans << endl;
}
int main() {
    // int t; cin >> t; while(t--) 
    solve();
    
   
}  

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

using namespace std;

const int MAX_N = 100000;
vector<int> graph[MAX_N];

int costnod[MAX_N];
bool viz[MAX_N];

int dfs(int nod) {
  int minnod = nod;
  viz[nod] = true;
  for(auto it:graph[nod])
    if(!viz[it]) {
      int r = dfs(it);
      if(costnod[r] < costnod[minnod])
        minnod = r;
    }
 return minnod;
}

int main() {
  int n, m, a, b, comp, x;
  long long rez = 0LL;
  scanf("%d%d", &n, &m);
  for(int i = 0; i < n; ++i)
    scanf("%d", &costnod[i]);
  for(int i = 0; i < m; ++i) {
    scanf("%d%d", &a, &b);
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  
  comp = 0;
  for(int i = 0; i < n; ++i)
    if(!viz[i]) {
      comp++;
      x = dfs(i);
      rez += costnod[x];
      costnod[x] = 1000000001;
    }
  if(comp > 1) {
    if(n < 2 * (comp - 1))
      printf("Impossible");
    else {
      std::sort(costnod, costnod + n);
      for(int i = 0; i < comp - 2; ++i)
        rez += costnod[i];
      printf("%lld", rez);
    }
  } else if(comp == 1)
    printf("0");
  return 0;
}


Measured memory_bytes: 6272
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	final int LEN = 100000;

	void doIt() {
		int n = sc.nextInt();
		int cnt[] = new int[LEN + 1];
		int sum[] = new int[LEN + 1];
		Arrays.fill(cnt, 0);
		sum[0] = 0;
		for(int i = 0; i < n; i++) {
			cnt[sc.nextInt()]++;
		}
		for(int i = 1; i <= LEN; i++) {
			sum[i] = sum[i - 1] + cnt[i];
		}
		int ans = 0;
		for(int i = 0; i <= LEN; i++) {
			if(sum[LEN] - sum[i] == sum[i])ans++;
		}
		System.out.println(ans);
		
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 50364
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  cout<<(A-C)*(B-D);
return 0;}


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

int Rand(int x) {return rand() * rand() % x + 1;}

#define vi vector<int>
#define pii pair<int, int >
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define LL long long
const int INF = 0x3f3f3f3f, N = 305, M = 2000005, MOD = 1e9 + 7;

int a[N][N], vis[N], has[N];
int main() {
	ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
	int n, m;
	cin >> n >> m;
	for(int i = 1;i <= n;i ++) {
		for(int j = 1;j <= m;j ++) {
			cin >> a[i][j];
		}
		has[a[i][1]] ++;
	}
	int ans = INF; 
	while(1) {
		int maxn = 0, k = -1;
		for(int i = 1;i <= m;i ++) if(!vis[i] && has[i] > maxn) maxn = has[i], k = i;
		if(k == -1) break;
		ans = min(ans, maxn);
		for(int i = 1;i <= m;i ++) has[i] = 0; 
		vis[k] = 1;
		for(int i = 1;i <= n;i ++) {
			for(int j = 1;j <= m;j ++) if(!vis[a[i][j]]) {
				has[a[i][j]] ++;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	ll  arr[n];
	cin >> arr[0];
	__int128  lcm = arr[0];
	for (int i = 1; i < n; i++) {
		cin >> arr[i];
		lcm = (lcm * arr[i]) / __gcd((__int128)arr[i], lcm);
	}

	cout << (ll)lcm;

	return 0;

}


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

using namespace std;

int main(){
    int X, Y, A, B, C;
    while(cin >> X >> Y >> A >> B >> C){
        vector<int> p(A), q(B), r(C);
        for(auto& t : p) cin >> t;
        for(auto& t : q) cin >> t;
        for(auto& t : r) cin >> t;
        sort(p.rbegin(), p.rend());
        sort(q.rbegin(), q.rend());
        sort(r.rbegin(), r.rend());
        long long res = 0;
        for(int i=0;i<X;i++) res += p[i];
        for(int i=0;i<Y;i++) res += q[i];
        for(int i=0;i<C;i++){
            bool checkX = (Y == 0 || (X != 0 && p[X-1] < q[Y-1]));
            if(checkX){
                if(r[i] > p[X-1]) res += r[i] - p[X-1];
                else break;
                --X;
            } else {
                if(r[i] > q[Y-1]) res += r[i] - q[Y-1];
                else break;
                --Y;
            }
            if(X == 0 && Y == 0) break;
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main(){
    int N,max=1,count,maxcount=0,a;
    cin >> N;
    for (int i=1;i<=N;i++){
        count=0;
        a=i;
        while(a%2==0){
            a=a/2;
            count++;
        }
        if (maxcount<count){
            maxcount=count;
            max=i;
        }
    }
    cout << max;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m, ans, pan;
int vis[maxn], cnt[maxn];
int main() {
	scanf("%d%d", &n, &m);
	while(m--) {
		int p;
		char s[10];
		scanf("%d%s", &p, s);
		if(s[0] == 'A') {
			if(!vis[p]) {
				vis[p] = 1;
				++ans;
				pan += cnt[p];
			}
		}
		if(s[0] == 'W') {
			++cnt[p];
		}
	}
	printf("%d %d\n", ans, pan);
	return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include <cstdlib>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include <assert.h>
#include<map>
#include<set>
#include<bitset>
#include <iomanip>
#include<stack>
#include <unordered_map>
#include<cmath>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define INF 0x7f7f7f7f //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.14159265358979323846264338327950254
#define pb push_back
#define ll long long
#define debug cout << "debug\n";
#define STDIN freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);
#define scai(x) scanf("%d", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define scaf(x) scanf("%lf", &x)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define For(m,n) for (int i = m;  i < n; i++)
#define PII pair<int,int>
#define PLL pair<long, long>
#define ft first
#define sd second
#define pb push_back
const int maxn=333333,mod=1000000009;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){char ch=getchar();int x=0,f=0;while(ch<'0'||ch>'9')f|=ch=='-',ch=getchar();while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();return f?-x:x;} 
#define int ll
PII a[200000];
signed main()
{
    //STDIN;
    int n;
    n = 1000;
    
    int cnt = 0;
    int k; cin >> k;
    for (int i = 0; i <= n; i++)
    {
        int t = i*i*i*i*i;
        // cout << t << endl;
        a[cnt++] = {i, t};
        a[cnt++] = {-i,-t};
    }
    for (int i = 0; i < cnt - 1 ;i++)
    {
        for (int j = i + 1; j < cnt; j++)
        {
            if (a[i].second - a[j].second == k) 
            {
                cout << a[i].first << " " << a[j].first << endl;
                // cout << i << " " << j << endl;
                return 0;
            }
            else if (a[j].second - a[i].second == k)
            {
                cout << a[j].first << " " << a[i].first << endl;
                // cout << j << " " << i << endl;
                return 0;
            }
        }
    }
}

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

void solve(long long N, std::vector<long long> P){
  long long count = 0;
  long long mymin = P[0];

  REP(i, N) {
    if(mymin >= P[i]) count++;
    mymin = min(mymin, P[i]);
  }
  cout << count << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::vector<long long> P(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&P[i]);
  }
    solve(N, std::move(P));
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define gc getchar()
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
inline int read(){char ch=gc;int w=1,s=0;while(!isdigit(ch)){if(ch=='-') w=-1;ch=gc;};while(isdigit(ch)){s=s*10+ch-'0';ch=gc;} return w*s;}
struct node{
	int to,next;
}e[1000010];
int du[1000100][2],h[1000010],tot,x[1000010],y[1000010];
int n,m,vis[1000010];
queue<int> q;
inline void add(int from,int to){e[++tot].next=h[from];h[from]=tot;e[tot].to=to;}
char s[1000010];
int main()
{
	n=read();m=read();
	scanf("%s",s+1);int len=strlen(s+1);for(rint i=1,u,v;i<=m;++i) u=read(),v=read(),add(u,v),add(v,u),x[i]=u,y[i]=v;
	for(rint i=1;i<=m;++i) du[x[i]][s[y[i]]-'A']++,du[y[i]][s[x[i]]-'A']++;
	for(rint i=1;i<=n;++i) if(!du[i][0]||!du[i][1]) vis[i]=1,q.push(i);
	while(!q.empty())
	{
		int u=q.front();q.pop();
		for(rint i=h[u];i;i=e[i].next)
		{
			int to=e[i].to;if(vis[to]) continue;
			du[to][s[u]-'A']--;
			if(!du[to][1]||!du[to][0])
			{
				q.push(to);
				vis[to]=1;
			}
		}
	}int ans=0;
	for(rint i=1;i<=n;++i) ans+=vis[i];
	if(ans==n)
	{
		cout<<"No\n";
	}
	else{
		cout<<"Yes\n";
	}
	return 0;
}



Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  int sum=0;
  for(int i=0;i<N;i++){
    char A;
    cin>>A;
    char c='Y';
    if(A==c){
      cout<<"Four"<<endl;
      sum=1;
      break;
    }
  }
   if(sum!=1){
     cout<<"Three"<<endl;
   }


}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>
#include<cmath>
#include<queue>

typedef long long ll;
using namespace std;
#define mod 10007
#define rep(i,n) for(ll i=0;i<n;i++)

int main(void){
  int a,b;
  cin >> a >> b;
  int cnt_s=1;
  int cnt_a=0;
  while(cnt_s<b){
    cnt_s=cnt_s-1+a;
    cnt_a++;
  }
  cout << cnt_a << endl;
  return 0;

}


Measured memory_bytes: 256
from itertools import*
a,b=map(int,input().split())
s=input()
table=[0]*(a-1)
for i in range(a-1):
    if s[i:i+2]=="AC":
        table[i]=1
x=[0]+list(accumulate(table))
for i in range(b):
    c,d=map(int,input().split())
    print(x[d-1]-x[c-1])

Measured memory_bytes: 8740
fun main(args: Array<String>) {
    a43(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

fun a43(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val to = args[0].toInt()
    print((1..to).sum())
}

Measured memory_bytes: 31872