akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(){
    int n;
    while(cin>>n,n){
        vector<int>v(n);
        for(int i=0;i<n;++i){
            string s;
            cin>>s;
            v[i]=s.length();
        }
        for(int i=0;i<n;++i){
            int a=0,b=0,c=0,d=0,e=0,j=i;
            bool flag=0;
            while(a<5){
                a+=v[j++];
                if(a==5){
                    while(b<7){
                        b+=v[j++];
                        if(b==7){
                            while(c<5){
                                c+=v[j++];
                                if(c==5){
                                    while(d<7){
                                        d+=v[j++];
                                        if(d==7){
                                            while(e<7){
                                                e+=v[j++];
                                                if(e==7){
                                                    cout<<i+1<<endl;
                                                    flag=1;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if(flag)break;
        }
    }
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

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

const ll INF = (1LL<<60);
const int INFi = (1<<29);

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

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


int main(){

    ll n; cin >> n;

    cout << 3*n*n << endl;

    return 0;
}

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

int main() {
  string S;
  cin >> S;
  long long K;
  cin >> K;
  string T = S + S;
  string T_ = S + S + S;
  long long N = S.size();
  long long count = 0;
  for (int i = 1; i < N; i++){
    if (S[i] == S[i - 1]){
      count++;
      i++;
    }
  }
  long long count_ = 0;
  for (int i = 1; i < 2 * N; i++){
    if (T[i] == T[i - 1]){
      count_++;
      i++;
    }
  }
  count_ -= count;
  long long count__ = 0;
  for (int i = 1; i < 3 * N; i++){
    if (T_[i] == T_[i - 1]){
      count__++;
      i++;
    }
  }
  count__ -= count + count_;
  
  if (count == count_) cout << count * K << endl;
  else {
    if (count_ == count__){
      cout << count + count_ * (K - 1) << endl;
    }
    else {
      if (K % 2 == 0) cout << (K / 2) * (count + count_) << endl;
      else cout << count + (count + count_) * ((K - 1) / 2) << endl;
    }
  }
}

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

#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

const int N = 1e5 + 10;
const int Mod = 1e9 + 7;

int Pow(int x, int e) {
	int ret = 1;
	while (e) {
		if (e & 1) ret = 1ll * ret * x % Mod;
		x = 1ll * x * x % Mod;
		e >>= 1;
	}
	return ret;
}

int A[N], inv[N], n;

int main() {

	scanf("%d", &n);
	For(i, 1, n) scanf("%d", &A[i]);
	For(i, 1, n) inv[i] = (inv[i - 1] + Pow(i, Mod - 2)) % Mod;

	int ans = 0;
	For(i, 1, n) ans = (ans + 1ll * A[i] * (inv[i] + inv[n - i + 1] - 1)) % Mod;
	For(i, 1, n) ans = 1ll * ans * i % Mod;
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

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

int main() {
    int h, w;
    cin >> h >> w;
    auto v = make_v(h+2, w+2, 'X');
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) {
            v[i+1][j+1] = s[j];
        }
    }
    string s[2];
    cin >> s[0] >> s[1];
    int ans = 0;
    for (int i = 1; i < h; ++i) {
        for (int j = 1; j < w; ++j) {
            int x = 0;
            if(v[i][j] == s[0][0] && v[i][j+1] == s[0][1] && v[i+1][j] == s[1][0] && v[i+1][j+1] == s[1][1]) ans++;
        }
    }
    int ans2 = 0;
    string t = "JOI";
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            char tmp = v[i+1][j+1];
            int p = 0;
            for (int k = 0; k < 2; ++k) {
                for (int l = 0; l < 2; ++l) {
                    if(v[i+k][j+l] == s[0][0] && v[i+k][j+1+l] == s[0][1] &&
                    v[i+1+k][j+l] == s[1][0] && v[i+1+k][j+1+l] == s[1][1]) p--;
                }
            }
            for (auto &&q : t) {
                v[i+1][j+1] = q;
                int pp = p;
                for (int k = 0; k < 2; ++k) {
                    for (int l = 0; l < 2; ++l) {
                        if(v[i+k][j+l] == s[0][0] && v[i+k][j+1+l] == s[0][1] &&
                           v[i+1+k][j+l] == s[1][0] && v[i+1+k][j+1+l] == s[1][1]) pp++;
                    }
                }
                ans2 = max(ans2, pp);
            }
            v[i+1][j+1] = tmp;
        }
    }
    cout << ans + ans2 << "\n";
    return 0;
}



Measured memory_bytes: 3928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll a, v, b, w, t; cin >> a >> v >> b >> w >> t;
	ll d = abs(a-b);
	ll z = v-w;
	
	if(z <= 0){
		print("NO")
	}else if(z * t >= d){
		print("YES")
	}else{
		print("NO")
	}
	
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;
typedef long long ll;

int main(){

  string s;

  getline(cin, s);

  for(int i=0; i<s.size(); i++){
    if(s[i]>='a' && s[i]<='z'){
      s[i] = s[i]-'a'+'A';
    }else if(s[i]>='A' && s[i]<='Z'){
      s[i] = s[i]-'A'+'a';
    }
    cout<<s[i];
  }
  cout<<endl;
}

Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
string s;
int a;
int main()
{
	cin>>s;
	a=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='C')
		{
			a=1;
		}
		if(s[i]=='F' && a==1)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  ll A[N], B[N], C[N];
  REP(i, N) { cin >> A[i]; }
  REP(i, N) { cin >> B[i]; }
  REP(i, N) { cin >> C[i]; }

  sort(A, A + N);
  sort(C, C + N);

  ll sum = 0;
  REP(i, N) {
    ll numA = lower_bound(A, A + N, B[i]) - A;
    ll numC = C + N - upper_bound(C, C + N, B[i]);
    sum += numA * numC;
  }
  cout << sum;
  return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    string s;
    cin >> n >> s;
    vector<set<ll>> vs(26);
    for(i = 0;i < n;++i){
        char tmp = s.at(i);
        vs.at(tmp - 'a').insert(i);
    }
    vector<char> ss(n);
    for(i = 0;i < n;++i){
        ss.at(i) = s.at(i);
    }
    ll q;
    cin >> q;
    for(i = 0;i < q;++i){
        ll com;
        cin >> com;
        if(com == 1){
            ll ind;
            char c;
            cin >> ind >> c;
            --ind;
            /**
            char tmp = ss.at(ind);
            ss.at(ind) = c;
            vs.at(tmp - 'a').erase(ind);
            vs.at(c - 'a').insert(ind);
            **/
            rep(j,26){
                vs.at(j).erase(ind);
            }
            vs.at(c-'a').insert(ind);
        }else{
            ll l,r;
            cin >> l >> r;
            ll ans = 0;
            rep(j,26){
                auto it1 = vs.at(j).lower_bound(l-1);
                auto it2 = vs.at(j).lower_bound(r);
                if(it1 != it2) ++ans;
            }
            /**
            rep(j,26){
                auto it = vs.at(j).lower_bound(l-1);
                if(it != vs.at(j).end()){
                    if(*it < r) ++ans;
                }
            }
            **/
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 24708
#!/usr/bin/env node

"use strict";

let main = (input) => {
    let inputList = input.split('\n');
    let n = inputList[0];
    if(n%2==1) return "No";

    let str = inputList[1];
    let nh = Number.parseInt(n/2);
    return str.substring(0,nh)==str.substring(nh) ? "Yes" : "No";
}

console.log(main(require("fs").readFileSync("/dev/stdin", "utf-8")));

Measured memory_bytes: 11468
# from collections import defaultdict


# # 試し割り法による素因数分解
# # defaultdictにつっこむやつ
# def prime_factorize_dict(n):
#     dd = defaultdict(int)
#     while n % 2 == 0:
#         dd[2] += 1
#         n //= 2
#     f = 3
#     while f * f <= n:
#         if n % f == 0:
#             dd[f] += 1
#             n //= f
#         else:
#             f += 2
#     if n != 1:
#         dd[n] += 1
#     return dd


k = int(input())
# print(prime_factorize_dict(k))
if k % 2 == 0:
    print(-1)
else:
    count = 1
    if k == 1 or k == 7:
        print(1)
    else:
        now = 7 % k
        while (1):
            count += 1
            now = ((now * 10 + 7) % k) % k
            if now == 0:
                print(count)
                exit()
            if count >= 1000000:
                print(-1)
                exit()


Measured memory_bytes: 9096
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll N;
    cin>>N;
    vector<ll> A(N),A_minus,A_plus;
    REP(i,N){
        cin>>A[i];
        if(A[i]>=0) A_plus.push_back(A[i]);
        else A_minus.push_back(A[i]);

    }
    sort(ALL(A));
    sort(ALL(A_minus));
    sort(ALL(A_plus));
    
    ll sum=0;
    vector<pair<ll,ll>> ans(N-1);
    if(A_minus.size()==0){
        ll x,y;
        x=A[0];
        y=A[1];
        ans[0]=make_pair(x,y);
        REP2(i,1,N-1){
            x-=y;
            y=A[i+1];
            if(i==N-2){
                sum=y-x;
                ans[i]=make_pair(y,x);
                break;
            }
            ans[i]=make_pair(x,y);   
        }
    }else if(A_plus.size()==0){
        ll x,y;
        sort(ALL(A),greater<ll>());
        x=A[0];
        y=A[1];
        ans[0]=make_pair(x,y);
        REP2(i,1,N-1){
            x-=y;
            y=A[i+1];
            ans[i]=make_pair(x,y);   
        }
        sum=x-y;
    }else{
        ll x,y;
        //マイナス1個とプラス多数
        x=A_minus[0];
        REP(i,A_plus.size()-1){
            y=A_plus[i];
            ans[i]=make_pair(x,y);
            x-=y;
        }
        ll y_last=x;
        //プラス1個とマイナス多数
        x=A_plus[A_plus.size()-1];
        REP2(i,1,A_minus.size()){
            y=A_minus[i];
            ans[A_plus.size()-2+i]=make_pair(x,y);
            x=x-y;
        }
        ans[N-2]=make_pair(x,y_last);
        sum=x-y_last;

    }
    cout<<sum<<endl;
    REP(i,N-1){
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }

}

Measured memory_bytes: 6564
import java.util.Arrays;
import java.util.Scanner;

class C {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int K = sc.nextInt();
        final int N = sc.nextInt();
        final int[] A = new int[N];
        Arrays.setAll(A, i -> sc.nextInt());
        int ans = A[N - 1] - A[0];
        for (int i = 1; i < N; i++)
            ans = Math.min(ans, K - A[i] + A[i - 1]);
        System.out.println(ans);
    }
}
public class Main {
    public static void main(String... args) {
        C.main();
    }
}


Measured memory_bytes: 67228
#include <iostream>
#include <cstring>
#define LEN 100001
using namespace std;
typedef struct pp
{
    int time;
    char name[100];
}P;

P QUEUE[LEN];
int head=0,tail=0,n=0; //??´??????????°????????????°???

void enqueue(P New_Member)
{
   QUEUE[tail]=New_Member;
   tail=(tail+1)%LEN;
}

P dequeue()
{
    P x=QUEUE[head];
    head=(head+1)%LEN;
    return x;
}
bool isEmpty()
{
    return (head==tail);
}

int main() {

    int Handle_Time;
    int Whole_Time=0;
    cin>>n>>Handle_Time;
    for(int i=0;i<n;i++)
    {
        char Name[100]; int t;
        cin>>Name>>t;
        P x;
        strcpy(x.name,Name);
        x.time=t;
        enqueue(x);
    }

    while(!isEmpty())
    {
        P x=dequeue();
        if(x.time>Handle_Time)
        {
            x.time-=Handle_Time; //??????????????¶??´
            Whole_Time+=Handle_Time;
            enqueue(x); //?????°??\???
        }
        else
        {
            Whole_Time+=x.time;
            cout<<x.name<<' '<<Whole_Time<<endl;
        }
    }
}

Measured memory_bytes: 13256
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize, x: u64,
        mut a: [u64; n]
    }

    let mut cnt = 0u64;
    if a[0] > x {
        cnt += a[0] - x;
        a[0] = x;
    }
    for i in 0..n-1 {
        if a[i] + a[i+1] > x {
            cnt += a[i+1] + a[i] - x;
            a[i+1] = x - a[i];
        }
    }
    println!("{}", cnt);
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>

using namespace std;
int main(void){
	int N;
	cin >> N;
	vector<double> x(N);
	vector<string> u(N);
	long double max = 0;
	for(int i = 0; i < N;i++){
		cin >> x[i];
		cin >> u[i];
	}
	for(int i = 0; i < N; i++){
		if(u[i][0] == 'B')
			max += x[i] * 380000.0;
		else
			max += x[i];
	}
	cout << max << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define CLR(array) memset( array, 0, sizeof array )
typedef long long int ll;


int main(){
	int n;
	char str[100];
	scanf("%d %s", &n, str);

	int res = 0;
	for( int i = 0; i < n; i++ ){
		if( i >= 2 && str[i] == 'C' && str[i-1] == 'B' && str[i-2] == 'A' )
			res++;
	}

	printf("%d\n", res);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    
    ll k;
    cin >> k;
    
    queue<ll> q;
    for(ll i = 1; i <= 9; i++){
        q.push(i);
    }
    if(k <= 9){
        cout << k;
        return 0;
    }
    k -= 9;
    
    while(1){
        
        ll top = q.front();
        q.pop();
        ll remain = top % 10;
        ll temp = top*10;
        if(remain - 1 >= 0){
        ll p = temp + remain - 1;
        
        q.push(p);
        k--;
        if(k == 0){
            cout << p;
            return 0;
        }
        }
        q.push(temp+remain);
        
        k--;
        if(k == 0){
            cout << temp + remain;
            return 0;
        }
        if(remain +1 <= 9){
            ll p = temp + remain +1;
            q.push(p);
            k--;
            if(k == 0){
                cout << p;
            return 0;
            }
            
        }
        
    }
    
}









Measured memory_bytes: 3884
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <vector>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
struct Edge
{
    int next, to;
    Edge(int next = 0, int to = 0):next(next), to(to) {};
}edge[N<<1];
int tot, head[N];
void _add(int x, int y) { edge[++tot] = Edge(head[x], y), head[x] = tot; }
void add(int x, int y) { _add(x, y), _add(y, x); }
int n, root, fa[N], w[N], s[N], d[N];
int find(int x)
{
    if(fa[x] == x) return x;
    int anc = find(fa[x]); d[x] ^= d[fa[x]];
    return fa[x] = anc;
}
void merge(int x, int y)
{
    int fx = find(x), fy = find(y);
    if(fx != fy) d[fx] = d[x]^d[y]^1, fa[fx] = fy;
}
int dfs(int x, int fa)
{
    vector<int> u; w[x] = 0;
    for(int i = head[x]; i; i = edge[i].next)
    {
        int y = edge[i].to; if(y == fa) continue;
        u.push_back(dfs(y, x)), s[x] ^= 1, w[x] ^= 1;
    }
    if(!w[x]) u.push_back(x);
    for(int i = 1; i < u.size(); i += 2) merge(u[i], u[i+1]);
    head[x] = 0; return u[0];
}
int main()
{
    n = read();
    for(int i = 1; i <= n; ++i) fa[i] = i;
    for(int i = 1, f; i <= n; ++i) 
        if((f = read()) == -1) root = i; else add(f, i);
    dfs(root, 0), tot = 0;
    for(int i = 1, f; i <= n; ++i) 
        if((f = read()) == -1) root = i; else add(f, i);
    dfs(root, 0);
    for(int i = 1; i <= n; ++i) if(s[i]) return puts("IMPOSSIBLE"), 0;
    puts("POSSIBLE");
    for(int i = 1; i <= n; ++i) printf("%d ", w[i]?0:((find(i), d[i])?-1:1));
    return 0;
}

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

int main(void)
{
    char str[1000],order[100][8],copy[1000], p[1000], keep[100][1000];
    int i, j, k, q, a, b, count=0;
    char *s1="print", *s2="reverse", *s3="replace";
    
    scanf("%s", str);
    scanf("%d", &q);
    
    for(i=0; i<q; i++){
        scanf("%s %d %d", order[i], &a, &b);
        if(strcmp(order[i],s1)==0){
            for(j=a, k=0; j<=b; j++, k++){
                keep[count][k]=str[j];
            }
            count++;
        }else if(strcmp(order[i],s2)==0){
            for(j=a; j<=b; j++){
                copy[j]=str[j];
            }
            for(j=a, k=b; j<=b; j++, k--){
                str[k]=copy[j];
            }
        }else if(strcmp(order[i],s3)==0){
            scanf("%s", p);
            for(j=a,k=0; j<=b; j++,k++){
                str[j]=p[k];
            }
        }
    }
    
    for(i=0; i<count; i++){
        printf("%s\n", keep[i]);
    }
    
    return 0;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<ll> P(N);
    REP(i, N) cin >> P[i];
    bool flag = true;
    ll ans = 0;
    ll minElement = LONG_MAX;
    REP(i, N)
    {
        if (P[i] <= minElement)
        {
            ans++;
        }
        minElement = min(minElement, P[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	static int buk[26];
	memset(buk,10,sizeof(buk));
	for(int i=nxi(); i; --i){
		static char str[51];
		static int tmp[26];
		memset(tmp,0,sizeof(tmp));
		scanf("%s",str);
		for(int j=strlen(str)-1; j>=0; --j){
			++tmp[str[j]-'a'];
		}
		for(int j=0; j<26; ++j){
			apn(buk[j],tmp[j]);
		}
	}
	for(int i=0; i<26; ++i){
		for(int j=0; j<buk[i]; ++j){
			putchar('a'+i);
		}
	}
	puts("");
	return 0;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int, input().split()))
x=2
y=2
A=A[::-1]
for i in range(N):
  nmin=((x+A[i]-1)//A[i])*A[i]
  nmax=y-y%A[i]
  if nmin>nmax:
    print(-1)
    exit()
  x=nmin
  y=nmax+A[i]-1
print(x,y)

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

ll K, N;

int main(void) {
  cin >> K >> N;

  if(K % 2 == 0) {
    cout << K / 2;
    REP(i, 1, N) cout << " " << K;
    cout << endl;
  } else {
    vector<ll> ans(N, (K + 1) / 2);
    ll j = 0;
    REP(i, 0, N / 2) {
      if(ans[N - 1 - j] == 0) j++;
      ans[N - 1 - j]--;
      if(j > 0 && ans[N - 1 - j] > 0) for(; j > 0; j--) ans[N - j] = K;
    }
    cout << ans[0];
    REP(i, 1, N) {
      if(ans[i] == 0) break;
      cout << " " << ans[i];
    }
    cout << endl;
  }
}


Measured memory_bytes: 4608
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

S = ns()
if S[0] == "7":
    print('Yes')
    exit(0)
if S[1] == "7":
    print('Yes')
    exit(0)
if S[2] == "7":
    print('Yes')
    exit(0)
print('No')


Measured memory_bytes: 9076
n, m = map(int,input().split())
h = list(map(int, input().split()))
tallneigh = [0]*n
G = [[] for i in range(n)]
g = [1 for i in range(n)]

for i in range(m):
    ai, bi = map(int, input().split())
    if h[ai-1] > h[bi-1]:
        g[bi-1] = 0
    elif h[bi-1] >h[ai-1]:
        g[ai-1] = 0
    else:
        g[ai-1] = 0
        g[bi-1] = 0
print(sum(g))

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

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

int main() {
	int a, b; cin >> a >> b;
	cout << (long long) a * b / gcd(a, b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N,M;cin>>N>>M;
  priority_queue<long> q;
  
  vector<pair<long,long> >jobs(N);
  for(int i=0;i<N;i++)cin>>jobs[i].first>>jobs[i].second;
  sort(jobs.begin(),jobs.end());
  long ans=0;
  int id=0;
  for(int i=0;i<M;i++){
    //cout<<" "<<i<<endl;
    while(id<N && jobs[id].first-1<=i){
      //cout<<jobs[id].second<<endl;
      q.push(jobs[id].second);
      id++;
    }
    if(q.size()){ans+=q.top();q.pop();}
  }
  cout<<ans<<endl;
}

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

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

using namespace std;

int main() {
  int cnt=0;
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    if(cnt)cout<<endl;
    cout<<"Case "<<(++cnt)<<":"<<endl;
    int box[7][7][7];
    REP(i,7)REP(j,7)REP(k,7)box[i][j][k] = 0;
    REP(i,5){
      REP(j,5){
        string s;
        cin>>s;
        REP(k,5)box[i+1][j+1][k+1] = s[k]-'0';
      }
    }
    int m1,m2;
    cin>>m1;
    vector<int> v1(m1);
    REP(i,m1) cin>>v1[i];
    cin>>m2;
    vector<int> v2(m2);
    REP(i,m2) cin>>v2[i];
    REP(i,n){
      int adj[5][5][5];
      REP(j,5)REP(k,5)REP(l,5)adj[j][k][l]=0;
      REP(j,5)REP(k,5)REP(l,5){
        REP(p,3)REP(q,3)REP(r,3){
          adj[j][k][l] += box[j+p][k+q][l+r];
        }
      }
      REP(j,5)REP(k,5)REP(l,5){
        if (box[j+1][k+1][l+1] == 0){
          if(find(begin(v1),end(v1),adj[j][k][l])!=end(v1))
            box[j+1][k+1][l+1] = 1;
          else
            box[j+1][k+1][l+1] = 0;
        } else {
          if(find(begin(v2),end(v2),adj[j][k][l]-1)!=end(v2))
            box[j+1][k+1][l+1] = 1;
          else
            box[j+1][k+1][l+1] = 0;
        }
      }
    }
    REP(i,5){
      REP(j,5){
        REP(k,5){
          cout<<box[i+1][j+1][k+1];
        }
        cout<<endl;
      }
      if(i!=4)
        cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1212
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
        String line = br.readLine();
        String[] lineArray = line.split(" ");
        int H = Integer.parseInt(lineArray[0]);
        int W = Integer.parseInt(lineArray[1]);

        char[][] campus = new char[H + 2][W + 2];

        for (int i = 1; i < H+1; i++) {
            line = br.readLine();
            for (int j = 1; j < W+1; j++) {
                campus[i][j] = line.charAt(j-1);
            }
        }

        String result = "Yes";
        for (int i = 1; i < H+1; i++) {
            for (int j = 1; j < W+1; j++) {
                if( !(campus[i-1][j] == '#' || campus[i][j-1] == '#' || campus[i][j+1] == '#' || campus[i+1][j] == '#' ) && campus[i][j] == '#' ){
                    result = "No";
                    break;
                }
            }
            if(result.equals("No")){
	            break;
            }
        }

        System.out.println(result);

    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int A, B; cin >> A >> B;
    vector d(A, vector(B, 0));
    for(auto& v : d){
        for(auto& t : v) cin >> t;
    }
    int ofs[101][101];
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            ofs[i][j] = 0;
            for(int a=1;a<=A;a++){
                for(int b=1;b<=B;b++){
                    ofs[i][j] = max(ofs[i][j], d[a-1][b-1]-(i*a+j*b));
                }
            }
        }
    }
    bool ok = true;
    for(int a=1;a<=A;a++){
        for(int b=1;b<=B;b++){
            int r = 10000;
            for(int i=0;i<=100;i++){
                for(int j=0;j<=100;j++){
                    r = min(r, i*a+j*b+ofs[i][j]);
                }
            }
            if(r != d[a-1][b-1]) ok = false;
        }
    }
    if(ok){
        cout << "Possible" << endl;
        cout << 300 << " " << 200 + 101*101 << endl;
        for(int i=1;i<=100;i++){
            cout << i << " " << i+1 << " X" << endl;
            cout << 151+i << " " << 150+i << " Y" << endl;
        }
        for(int i=0;i<=100;i++){
            for(int j=0;j<=100;j++){
                cout << i+1 << " " << j+151 << " " << ofs[i][j] << endl;
            }
        }
        cout << 1 << " " << 151 << endl;
    } else {
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 3672
use itertools::Itertools;
use proconio::input;

fn main() {
    input!(n: usize, a: [usize; n], b: [usize; n]);

    if let Some(ans) = solve(n, &a, &b) {
        println!("Yes");
        println!("{}", ans.iter().map(|&v| v.to_string()).join(" "))
    } else {
        println!("No")
    }
}

fn solve(n: usize, a: &[usize], b: &[usize]) -> Option<Vec<usize>> {
    let mut d = 0;
    let b = [b; 2].concat();
    for i in 0..n {
        while i + d < n && a[i] >= b[i + d] {
            d += 1;
        }
        if a[i] == b[i + d] {
            return None;
        }
    }
    Some((&b[d..d + n]).into())
}


Measured memory_bytes: 12500
N = int(input())

INF = 10 ** 9 + 7
G = [[int(_) for _ in input().split()] for _ in range(N)]
G2 = [G[_].copy() for _ in range(N)]

for k in range(N):
    for i in range(N):
        for j in range(N):
            G2[i][j] = min(G2[i][j], G2[i][k] + G2[k][j])

            if G2[i][j] < G[i][j]:
                print(-1)
                exit()
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if i == j: continue
        elif G2[i][j] == G[i][j]:
            v = G2[i][j]
            for k in range(N):
                if i == j or i == k or j == k: continue
                if G2[i][k] + G2[k][j] == G2[i][j]:
                    v = 0
                    break
            ans += v
print(ans)


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

struct UnionFind {
    vector<int> d; // 根なら (-サイズ), そうでないなら親の番号
    UnionFind(int N) : d(N, -1){} // 全て根として初期化

    int root(int x) { // データ x が属する木の根を再帰で得る
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }

    bool unite(int x, int y) { // x と y の木を併合. 併合した場合 true
        x = root(x); y = root(y); // x <- x の根, y <- y の根
        if (x == y) return false; 
        // merge technique（データ構造をマージするテク. 小を大にくっつける）
        if (d[x] > d[y]) swap(x, y);    // x の木のサイズ > y の木のサイズにする. d[x], d[y] < 0 に注意.
        d[x] += d[y];   // x の木のサイズ += y の木のサイズ
        d[y] = x;   // y の親は x
        return true;
    }

    bool same(int x, int y) { // 2つのデータ x, y が属する木が同じなら true
        return root(x) == root(y);
    }
    
    int size(int x) { // 素集合のサイズ
        return -d[root(x)]; // d[root(x)] < 0 に注意.
    }
};

void Main(){
	int n, k, l; cin >> n >> k >> l;
	
	UnionFind tree1(n), tree2(n);
	vi t1(n), t2(n);
	map<P, int> mp;
	
	rep(i, k) {
	    int p, q; cin >> p >> q;
	    p--; q--;	   
	    tree1.unite(p,q);
	}
    
	rep(i, l){
	    int p, q; cin >> p >> q;
	    p--; q--;	   
	    tree2.unite(p,q);
	}
	
    rep(i, n){
        t1[i] = tree1.root(i);
        t2[i] = tree2.root(i);
        // cout << i << ": " << t1[i] << " " << t2[i] << endl;
        mp[P(t1[i], t2[i])]++;
    }

	rep(i, n) {
	    cout << mp[P(t1[i], t2[i])] << " ";
	}
	cout << endl;
	return;
}

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

Measured memory_bytes: 17680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
      solve();
  }
}


void solve() {
  int n, d;
  cin >> n >> d;
  int ans = n;
  int tmp = 2 * d + 1;
  ans = (ans + tmp - 1) / tmp;
  cout << ans << endl;
}


Measured memory_bytes: 256
def co(x):
    m = 0
    while True:
        if x==1:
            break
        if x%2==0:
            x = x//2
            m+=1
        else:
            x = int(x*3+1)
            m+=1
    print(m)
while True:
    n = int(input())
    if n==0:
        break
    co(n)


Measured memory_bytes: 5592
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
		 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
	    public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();	
	        long[] a = new long[N];
	        for (int i=0 ; i<N; i++) {
	            a[i] = Long.parseLong(sc.next());
	        }
	        Arrays.parallelSort(a);
	        long ans=0;
	        if(N%2==0) {
		        for(int i=0;i<N/2-1;i++) {
		        	ans=ans-2*a[i];
		        }
		        ans=ans-a[N/2-1];
		        ans=ans+a[N/2];
		        for(int i=N/2+1;i<N;i++) {
		        	ans=ans+2*a[i];
		        }
	        } else {
	        	for(int i=0;i<N/2;i++) {
	        		ans=ans-2*a[i];
	        	}
	        	ans=ans+a[N/2];
	        	ans=ans+a[N/2+1];
	        	for(int i=N/2+2;i<N;i++) {
	        		ans=ans+2*a[i];
	        	}
	        	long tmp=0;
	        	for(int i=0;i<N/2-1;i++) {
	        		tmp=tmp-2*a[i];
	        	}
	        	tmp=tmp-a[N/2-1];
	        	tmp=tmp-a[N/2];
	        	for(int i=N/2+1;i<N;i++) {
	        		tmp=tmp+2*a[i];
	        	}
	        	ans=Math.max(ans, tmp);
	        }
	        
	        
	        System.out.println(ans);
	        
	    }
	}

Measured memory_bytes: 48996
N, L = list(map(int, input().split()))

tastes = [L + i -1 for i in range(1, N+1, 1)]

if tastes[0] * tastes[-1] <= 0:
    print(sum(tastes))
else:
    if min(tastes) < 0:
        print(sum(tastes) - tastes[-1])
    else:
        print(sum(tastes) - tastes[0])

Measured memory_bytes: 3060
var x,y,t:array[0..100000]of longint;
    n,i:longint;
begin
  readln(n);
  for i:=1 to n do
    readln(t[i],x[i],y[i]);
  for i:=1 to n do
    if (x[i]+y[i]>t[i])or((t[i]-x[i]-y[i])mod 2<>0) then
    begin
      writeln('No');
      halt;
    end;
  writeln('Yes');
end.

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

const int INF = 2147483647;

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;}

int main(){
    
    int A[4][4];for(int i = 0; i < 3; i++){for(int j = 0; j < 3; j++){cin >> A[i][j];}}
    bool bingo[4][4]; for(int i = 0; i < 3; i++){for(int j = 0; j < 3; j++){bingo[i][j] = false;}}
    int N; cin >> N;
    int b;

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

        cin >> b;

        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(A[j][k] == b){bingo[j][k] = true;}
            }
        }
    }

    bool judge = false;

    for(int i = 0; i < 3; i++){
        if((bingo[i][0] & bingo[i][1]) & bingo[i][2]){judge = true;}
        if((bingo[2][i] & bingo[1][i]) & bingo[0][i]){judge = true;}
    }

    if((bingo[0][0] & bingo[1][1]) & bingo[2][2]){judge = true;}
    if((bingo[2][0] & bingo[1][1]) & bingo[0][2]){judge = true;}

    if(judge){cout << "Yes" << endl;}else{cout << "No" << endl;}
}

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

int main(){
  int n;cin>>n;
  vector<double> v(n);
  for(auto &i : v) cin>>i;
  sort(v.begin(),v.end());
  double ans=v[0];
  for(int i=1;i<n;i++){
    ans=(ans+v[i])/2;
  }
  cout<<ans<<"\n";
	return 0;
}
  

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int array[5];
  cin >> array[0] >> array[1] >> array[2] >> array[3] >> array[4];
  int sumA = 0;
  for (int i=0; i<5; i++) {
    if (array[i]%10 == 0) {
      sumA += array[i];
    } else {
      sumA += array[i] - array[i]%10 + 10;
    }
  }
  int min;
  if (array[0]%10 == 0) {
    min = 10;
  } else {
    min = array[0]%10;
  }
  for (int j=1; j<5; j++) {
    if (array[j]%10 == 0) {
      continue;
    } else {
      if (min>array[j]%10) {
        min = array[j]%10;
      }
    }
  }
  if (min == 10) {
    cout << sumA << endl;
  } else {
    cout << sumA-10+min << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
using namespace std;
#define ll long long
const ll N = 2e5+107;
ll n,m,k,i,j,sum,rasp=INT_MIN,a[N],b[N];
int main ()
{
    cin>>n>>m>>k;
    for (i=1;i<=n;++i)
        cin>>a[i];
    for (i=1;i<=m;++i)
        cin>>b[i],sum+=b[i];
    j=m;
    for (i=0;i<=n;++i)
    {
        sum+=a[i];
        while (sum>k && j)
        {
            sum-=b[j];
            j--;
        }
        if (sum>k) break; /// importanta pentru cand sunt eliminate toate din b[], dar suma celor din a[] (pana la i) ramane mai mare decat k (prin adaugarea ultimului element)
        rasp=max(rasp,i+j);
    }
    cout<<rasp<<"\n";
}



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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;

vll seen;
void dfs(vvll& graph, ll i){
	seen.at(i) = 1;
	vrep(j, graph.at(i)) if(seen.at(j) == 0) dfs(graph, j);
}

int main(){
	ll n;
	cin >> n;
	vst s(n);
	vll p(n);
	rep(i, 0, n) cin >> s.at(i) >> p.at(i);

	vll ord(n);
	iota(all(ord), 0);
	sort(all(ord), [&](ll i, ll j){
		if(s.at(i) == s.at(j)) return p.at(i) > p.at(j);
		return s.at(i) < s.at(j);
	});

	vrep(i, ord) cout << i + 1 << endl;
}

Measured memory_bytes: 256
def main():
    x = int(input())

    primes = [3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313]

    if x == 2:
        return 2
    x += (x+1)%2
    while True:
        isPrime = True
        for p in primes:
            if x == p:
                return p
            if x % p == 0:
                isPrime = False
                break
        if isPrime:
            return x
        else:
            x += 2

if __name__ == "__main__":
    print(main())

Measured memory_bytes: 3064
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
k = sum(b) - sum(a)
cnt = 0
for i in range(n):
  if b[i] < a[i]:
    cnt += a[i] - b[i]
  elif (b[i] + a[i]) % 2 == 1:
    cnt += 1
if cnt <= k:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define ll long long
#define rw freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define EPS 1e-6
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace std;
const int N=2e5+5;
int a[N],b[N],n;
vi bb;
int main()
{
#ifdef ONLINE_JUDGE
    FAST;
#endif
    while(cin>>n)
    {
        lp(i,1,n) cin>>a[i];
        lp(i,1,n) cin>>b[i];
        ll ans=0;
        lp(k,0,29)
        {
            ll T=(1LL<<k);
            bb.clear();
            lp(i,1,n) bb.pb(b[i]%(2*T));
            sort(all(bb));
            int cnt=0;
            lp(i,1,n)
            {
                int aa=a[i]%(2*T);
                cnt+=lower_bound(all(bb),(2*T)-aa)-lower_bound(all(bb),T-aa);
                cnt+=lower_bound(all(bb),(4*T)-aa)-lower_bound(all(bb),(3*T)-aa);
            }
            if (cnt&1)
                ans+=T;
        }
        cout<<ans<<"\n";
    }
    return 0;
}

Measured memory_bytes: 2936
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//ここまでテンプレ
const int alpha=26;
int main(){
	string S;
	cin>>S;
	S='@'+S;
	int N=S.length();
	//DQ[i][j]=i文字目以降で最初に文字jが現れる場所(自身を含まない)
	int DQ[SIZE][alpha]={};
	for(int i=0;i<alpha;i++)
		DQ[N-1][i]=-1;
	//DP[i]=i文字目以降の部分列ではない文字列のなかで最も短いものの文字数
	int DP[SIZE]={};
	for(int i=0;i<N;i++)
		DP[i]=INF;
	DP[N-1]=1;

	//DQの遷移
	for(int i=N-2;i>=0;i--){
		for(int j=0;j<alpha;j++)
			DQ[i][j]=(S[i+1]-'a'==j?i+1:DQ[i+1][j]);
	}
	//DPの遷移
	for(int i=N-2;i>=0;i--){
		for(int j=0;j<alpha;j++)
			DP[i]=(DQ[i][j]==-1?1:min(DP[i],DP[DQ[i][j]]+1));
	}
	/*
	for(int i=0;i<N;i++){
		for(int j=0;j<alpha;j++)
			cout<<DQ[i][j]<<" ";
		cout<<endl;
	}
	for(int i=0;i<N;i++)
		cout<<DP[i]<<endl;
	*/
	//構築
	string T;
	int idx=0;
	while(1){
		//DQを見て、一番DPが小さい文字のなかで一番辞書順で小さいものに飛ぶ
		int next=-1,mini=INF;
		//-1に飛ぶとまずいので、-1が出たら別ルートに入る
		bool flag=0;
		for(int i=alpha-1;i>=0;i--){
			if(DQ[idx][i]==-1){
				flag=1;
				continue;
			}
			if(DP[DQ[idx][i]]<=mini){
				next=DQ[idx][i];
				mini=DP[next];
			}
		}
		if(flag){
			//DQが-1になるものの中で一番辞書順で小さいものをつけて終了
			for(int i=0;i<alpha;i++){
				if(DQ[idx][i]==-1){
					T+='a'+i;
					goto brk;
				}
			}
		}
		T+=S[next];
		idx=next;
	}
	brk:
	cout<<T<<endl;
	return 0;
}

Measured memory_bytes: 21696
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <string.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
bool prime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main()
{
ll ans=0,n;

cin >> n;

int table[n]={};
rep(i,n) {
    cin >> table[i];
}
rep(i,n){
int tempsoin=table[i];
for(ll j = 2; j <= tempsoin; ){
    if(tempsoin%j==0){
        tempsoin=tempsoin/j;
        ans++;
        
    }
    else break;
}}

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





Measured memory_bytes: 256
n = int(input())
x = [int(i) for i in input().split()]
y = []
for i in range(n):
	y.append([x[i],i+1])
y.sort()
a,b = y[n//2][0],y[(n-2)//2][0]
for i in range(len(y)//2):
	y[i][0],y[i][1] = y[i][1],a
for i in range(len(y)//2,n):
	y[i][0],y[i][1] = y[i][1],b
y.sort()
for i in y:
	print(i[1])

Measured memory_bytes: 40768