akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <math.h>

int main()
{
    int a, b, k;
    int turn = 0;
    scanf("%d%d%d", &a, &b, &k);
    while (k > 0) {
        if (turn == 0) {
            if (a%2 != 0) {
                a --;
                b = b + a/2;
                a = a/2;
                turn = 1;
                k --;
            } else {
                b = b + a/2;
                a = a/2;
                turn = 1;
                k --;
            }
        } else {
            if (b%2 != 0) {
                b --;
                a = a + b/2;
                b = b/2;
                turn = 0;
                k --;
            } else {
                a = a + b/2;
                b = b/2;
                turn = 0;
                k --;
            }
        }
    }
    printf("%d %d\n", a, b);
    return 0;
}


Measured memory_bytes: 128
///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

void solve() {
    int n;
    string s;
    cin >> s;
    n = size(s);

    int p = 0, g = 0, res = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'g' && p + 1 <= g) {
            ++p;
            ++res;
        } else if (s[i] == 'g') {
            ++g;
        } else {
            if (p + 1 <= g) {
                ++p;
            } else {
                ++g;
                --res;
            }
        }
    }
    cout << res << "\n";
}

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

    int z = 1;
    /// cin >> z;

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

    return 0;
}


Measured memory_bytes: 3792
#include<iostream>
using namespace std;
long long int divEnemy(long long int input){
	long long int counter=0;
	while(input!=1){
		input/=2;
		counter++;
	}
	return counter;
}
long long int k(long long int n){
	long long int out=1;
	for(long long int i=0;i<n;i++){
		out*=2;
	}
	return out;
}
int main(){
	long long int HP;
	cin >> HP;
	cout << k(divEnemy(HP)+1)-1 << endl;
	return 0;
}



Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let a: usize = sc.read();
    let b: usize = sc.read();
    if (a.count_ones() & 1) == (b.count_ones() & 1) {
        println!("NO");
        return;
    }
    let ans = solve(n, a, b);
    println!("YES");
    for (i, ans) in ans.into_iter().enumerate() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", ans);
    }
    println!();
}

fn solve(n: usize, a: usize, b: usize) -> Vec<usize> {
    if n == 1 {
        vec![a, b]
    } else {
        // assert!((a.count_ones() & 1) != (b.count_ones() & 1));
        let x = (0..)
            .filter(|&i| (a & (1 << i)) != (b & (1 << i)))
            .next()
            .unwrap();
        let na = ((a >> (x + 1)) << x) + (((1 << x) - 1) & a);
        let nb = ((b >> (x + 1)) << x) + (((1 << x) - 1) & b);
        // assert_eq!(na & (1 << x), 0);
        // assert_eq!(nb & (1 << x), 0);
        // assert_eq!((na.count_ones() & 1), (nb.count_ones() & 1));

        let c = na ^ 1;
        let q = solve(n - 1, na, c);
        let r = solve(n - 1, c, nb);
        let m = 1 << n;
        let mut ans = vec![0; m];
        for i in 0..(m / 2) {
            let q = q[i];
            ans[i] = (a & (1 << x)) + ((q >> x) << (x + 1)) + (((1 << x) - 1) & q);
        }
        for i in (m / 2)..m {
            let r = r[i - (m / 2)];
            ans[i] = (b & (1 << x)) + ((r >> x) << (x + 1)) + (((1 << x) - 1) & r);
        }
        ans
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void anss(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  string s,t,u;cin>>s>>t>>u;
  string v;
  v+=s[0]+'A'-'a';
  v+=t[0]+'A'-'a';
  v+=u[0]+'A'-'a';
  cout<<v<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cxxabi.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mp make_pair
#define fi first
#define se second
#define All(x) (x).begin(),(x).end()
#define TYPEVS(x) typeid(x).name()
#define TYPEGC(x) abi::__cxa_demangle(typeid(x).name(), 0, 0, 0)
#define Y1 "YES"
#define N1 "NO"
#define ENDL '\n'
#define count2(x) _builtin_popcount(x)
int main(){
	ll n,m;
	cin>>n>>m;
	cout<<n*m; 
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  
  int s;
  cin >> s;
  vec1 a = {s};
  int c = 0;
  for(int i = 0; i < 10e10; i++) {
    int b = a.back();
    if(b == 1) c++;
    if(c == 2) break;
    if(b % 2 == 0) {
      a.push_back(b/2);
    } else {
      a.push_back(b*3+1);
    }
  }
  int tmp = 0;
  int ans = 1000000;
  for(int i = 0; i < a.size(); i++) {
    for(int j = i+1; j < a.size(); j++) {
      if(a.at(i) == a.at(j)) {
        tmp = max(i,j);
        tmp++;
        ans = min(ans,tmp);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
  for(;;) {
    int n, m;
    cin >> n >> m;
    if(n == 0) break;
    vector<int> ss, ts;
    int sss = 0;
    for(int i = 0; i < n; i++) {
      int c;
      cin >> c;
      ss.push_back(c);
      sss += c;
    }
    int ttt = 0;
    for(int i = 0; i < m; i++) {
      int c;
      cin >> c;
      ts.push_back(c);
      ttt += c;
    }
    int xs = -1;
    int xt = -1;
    for(int s : ss) {
      for(int t : ts) {
        if (sss - ttt == 2 * (s - t)) {
          if(xs < 0 || xs + xt > s + t) {
            xs = s;
            xt = t;
          }
        }
      }
    }
    if(xs < 0) {
      cout << "-1" << endl;
    } else {
      cout << xs << " " << xt << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3148
using System;
class Program
{
	static void Main()
	{
        string[] a = Console.ReadLine().Split(' ');
		int b = int.Parse(a[0]);
		int c = int.Parse(a[1]);
        string r = "No";
        for(int i=0; i<=b; i++)
        {
            if(i*4+(b-i)*2 == c)
            {
                r = "Yes";
                break;
            }
        }

		Console.WriteLine(r);
	}
}

Measured memory_bytes: 27184
#include <iostream>
#include <utility>

using namespace std;

int ct[2000][2000];
int r[2000][2000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    int x, y;
    char c;
    cin>>n>>k;
    int kk=k+k;
    for(int i=0; i<n; i++){
        cin>>x>>y>>c;
        if(c=='W'){
            x+=k;
        }
        ++ct[y%(kk)][x%(kk)];
        ++ct[(y+k)%(kk)][(x+k)%(kk)];
    }
    
    for(int i=0; i<kk; i++){
        r[i][0]=0;
        for(int j=0; j<k; j++) r[i][0]+=ct[i][j];
        for(int j=1; j<kk; j++){
            r[i][j]=r[i][(j+kk-1)%kk]-ct[i][(j+kk-1)%kk]+ct[i][(j+k-1)%kk];
        }
    }

    for(int i=0; i<kk; i++){
        ct[0][i]=0;
        for(int j=0; j<k; j++) ct[0][i]+=r[j][i];
        for(int j=1; j<kk; j++){
            ct[j][i]=ct[(j+kk-1)%kk][i]-r[(j+kk-1)%kk][i]+r[(j+k-1)%kk][i];
        }
    }

    int maxcount=0;
    for(int i=0; i<kk; i++){
        for(int j=0; j<kk; j++){
            maxcount = max(ct[i][j], maxcount);
        }
    }
    cout<<maxcount<<'\n';
    return 0;
}


Measured memory_bytes: 31488
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
using namespace std;

int main() {
    int m;
    string train;
    cin >> m;
    for(int j=0; j<m; ++j) {
        cin >> train;
    
        set<string> ret;

        ret.insert(train);

        for(int i=1; i<=train.size(); ++i) {
            string before, before2, after;
            before = before2 = train.substr(0, i);
            after = train.substr(i, train.size()-i);
            ret.insert(after + before);

            reverse(before.begin(), before.end());
            ret.insert(before + after);
            ret.insert(after + before);

            reverse(after.begin(), after.end());
            ret.insert(before2 + after);
            ret.insert(after + before2);

            ret.insert(before + after);
            ret.insert(after + before);
        }

        cout << ret.size() << endl;
    }
}


Measured memory_bytes: 3156
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	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<class T> inline std::istream& operator >> (std::istream& is, std::vector<T>& v) { for (T& x : v) { is >> x; }return is; }
	template<class T> inline std::ostream& operator << (std::ostream& os, const std::vector<T>& v) {
		for (auto itr = v.begin(); itr != v.end();) { os << (*itr) << ((++itr != v.end()) ? " " : ""); }
		return os;
	}
	template<class V, typename T>inline void fill(V& v, const T& val) { v = val; }
	template<class V, typename T>inline void fill(std::vector<V>& v, const T& val) { for (V& x : v) { fill(x, val); } }
	template<class V, typename H>inline void resize(std::vector<V>& v, const H h) { v.resize(h); }
	template<class V, typename H, typename... T>inline void resize(std::vector<V>& v, const H& h, const T& ... t) { v.resize(h); for (auto& x : v) { resize(x, t...); } }
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }

	void solve() {
		IOS;
		string s;
		cin >> s;
		if (s == "ABC") {
			s = "ARC";
		} else {
			s = "ABC";
		}
		put(s);
	}
} // namespace idaten

int main() {
	idaten::solve();
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int mod = 1000000007;

bool is_prime(int num){
    for(int i = 2; i < num / 2; i++){
        if(num % i == 0){
            return false;
        }
    }
    return true;
}

int main(){
    int x;
    cin >> x;

    do{
        if(is_prime(x)){
            cout << x << endl;
            return 0;
        }
    }while(x++);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

size_t calc_order_time_sum(const vector<uint64_t>& dishes)
{
    size_t skip_index = 0;
    size_t max_wait_time = 0;
    for (int i = 0; i < dishes.size(); ++i) {
        size_t wait_time = ((dishes[i] % 10) == 0)
            ? 0
            : 10 - (dishes[i] % 10);
        if (wait_time > max_wait_time) {
            max_wait_time = wait_time;
            skip_index = i;
        }
    }
    // cout << "skip_index:" << skip_index << endl;

    size_t order_time_sum = 0;
    for (int i = 0; i < dishes.size(); ++i) {
        if (i == skip_index) { continue; }
        if ((dishes[i] % 10) == 0) {
            order_time_sum += dishes[i];
        } else {
            order_time_sum += static_cast<uint64_t>(floor(dishes[i] / 10)) * 10 + 10;
        }
        // cout << order_time_sum << endl;
    }
    order_time_sum += dishes[skip_index];
    // cout << order_time_sum << endl;

    return order_time_sum;
}

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

    const size_t length = 5;
    vector<uint64_t> dishes(length, 0);

    for(size_t i = 0; i < length; ++i)
    {
        cin >> dishes[i];
        assert(1 <= dishes[i] && dishes[i] <= 123);
    }

    cout << calc_order_time_sum(dishes) << endl;

    // vector<uint64_t> dishes1 = {29,20,7,35,120};
    // cout << calc_order_time_sum(dishes1) << endl;

    // vector<uint64_t> dishes2 = {101,86,119,108,57};
    // cout << calc_order_time_sum(dishes2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e18
#define int long long
using namespace std;
typedef pair<int,int> P;
 
struct Graph{
  Graph(int n):E(n),d(n){};
  vector<vector<P>>E;
  vector<int>d;
  void add_edge(int a,int b,int c){
    E[a].push_back({b,c});
  }
  bool bellmanFord(int s){
    int sz=d.size();
    fill(d.begin(),d.end(),INF);
    d[s]=0;
    for(int i=0;i<sz;++i)
      for(int j=0;j<sz;++j)
        for(P& p:E[j])
          if(d[j]!=INF&&d[j]+p.second<d[p.first]){
            d[p.first]=d[j]+p.second;
            if(i==sz-1&&p.first==sz-1)return false;
          }
    return true;
  }
};
 
main(){
  int n,m,a,b,c;
  cin>>n>>m;
  Graph E(n);
  for(int i=0;i<m;++i){
    cin>>a>>b>>c;
    E.add_edge(--a,--b,-c);
  }
  if(E.bellmanFord(0))cout<<-E.d[n-1]<<endl;
  else cout<<"inf"<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

int c[1000];

int main(){
    int n, k;
    cin >> n >> k;
    
    rep(i, k){
        int d; cin >> d;
        rep(j, d){
            int a;
            cin >> a;
            a--;
            c[a]++;
        }
    }

    int ans = 0;
    rep(i, n){
        if(c[i]==0) ans++;
    }
    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1e9+7;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  for(ll i = 0; i < n; ++i) cin >> a[i];
  ll cnt = 0, cnt2 = 0;
  for(ll i = 0; i < n; ++i){
    for(ll j = 0; j < i; ++j){
      if(a[i] > a[j]) ++cnt2;
    }
    for(ll j = i+1; j < n; ++j){
      if(a[i] > a[j]) ++cnt,++cnt2;
    }
  }
  ll ans = 0;
  ans = ((cnt%MOD)*k)%MOD;
  ans = (ans+(cnt2%MOD)*((k*(k-1)/2)%MOD))%MOD;
  cout << (ans+MOD)%MOD;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>                                                                          
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0; i<N; i++){
    cin >> L.at(i);
  }
  int max=0;
  int number=0;
  for(int i=0; i<N; i++){
    if(max<L.at(i)){
      max=L.at(i);
      number=i;
    }
  }
  int sum=0;
  for(int i=0; i<N; i++){
    if(i!=number){
      sum+=L.at(i);
    }
  }
  if(max<sum){
    cout << "Yes" << endl;
  }
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int a,b,q;
	cin >> a >> b >> q;
	vector<ll> s(a),t(b),x(q);
	
	rep(i,0,a) cin >> s[i];
	rep(i,0,b) cin >> t[i];

	rep(i,0,q){
		ll x;
		cin >> x;
		vector<ll> ans;

		if( x <= s[s.size()-1] && x <= t[t.size()-1] ){
			ll tmp1 = *lb(s,x);
			ll tmp2 = *lb(t,x);
			ans.push_back(  max( tmp1 , tmp2 ) - x );
			//cout << "1:" << ans[ans.size()-1] << endl;
		}

		if( x <= s[s.size()-1] && x > t[0] ){
			ll tmp1 = *lb(s,x);
			int idx2 = ub(t,x) - t.begin() - 1;
			if( idx2 >= 0 ) ans.push_back( min( abs(tmp1 - x) , abs(t[idx2] - x)) + abs(tmp1 - t[idx2]));
			//cout << "2:" << ans[ans.size()-1] << endl;
		}

		if( x <= t[t.size()-1] && x > s[0] ){
			ll tmp1 = *lb(t,x);
			int idx2= ub(s,x) - s.begin() - 1;
			if( idx2 >= 0 ) ans.push_back( min( abs( tmp1 - x ) , abs(s[idx2] - x ) ) + abs( tmp1 - s[idx2] ) );
			//cout << "3:" << ans[ans.size()-1] << endl;
		}

		if( x > s[0] && x > t[0] ){
			int idx1 = ub(s,x) - s.begin() - 1;
			int idx2 = ub(t,x) - t.begin() - 1;
			if( idx1 >= 0 && idx2 >= 0 ) ans.push_back( x - min(s[idx1] , t[idx2] ) );
			//cout << "4:" << ans[ans.size()-1] << endl;
		}

		vsort(ans);

		cout << ans[0] << endl;
	}


	ret 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

int a[26]; string w;
int main(){
    int n;
    cin >> n;
    vector<int> b(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    sort(b.begin(), b.end());
    int ans = b[n/2]-b[n/2-1];

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long ta[399999];

int main()
{
    long long n;
  	cin >> n;
    vector<long long> a(n);
    vector<long long> c(n);
    
    long long i;
    for(i=0;i<n;i++){
        cin >> a.at(i) ;
        c.at(i)= a.at(i)-i-1;

    }  
    sort(c.begin(),c.end());
    int m = (int)(n/2);
    long center = c.at(m);
    long answer=0;
    for(i=0;i<n;i++){
//        cout << a.at(i) << endl ;
        answer += abs(a.at(i)-i-1-center);


    }
    cout << answer << endl;   
}



Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<time.h>
#include<vector>
#define ll long long
using namespace std;

int main()
{
    int n,a[105];
    int ans = 0;
    cin>>n;
    for(int i=1; i<=n; ++i){
        cin>>a[i];
    }
    for(int i=1; i<=n; i+=2){
        if(a[i]%2==1)
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3604
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
int a[11000];
int s[110][110];
int h,w,n;

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

queue<int>v;
void dfs(){
	int i=0,j=0;
	
	for(i=0;i<h;i++){
		if(i%2){
			for(j=0;j<w;j++){
				s[i][j]=v.front();
				v.pop();
			}
		}else{
			for(j=w-1;j>=0;j--){
				s[i][j]=v.front();
				v.pop();
			}
		}
		
	}
	
}

int main(){
	int t;
	
	scanf("%d %d",&h,&w);
	scanf("%d",&n);
	while(!v.empty())v.pop();
	for(int i=0;i<n;i++){
		scanf("%d",&t);
		while(t>0){
			v.push(i+1);
			t--;
		}
	}
	memset(s,0,sizeof(s));
	
	dfs();
	
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(j)printf(" ");
			printf("%d",s[i][j]);
		}
		printf("\n");
	}
	
}

Measured memory_bytes: 384
def resolve():
    num_ten, num_load = map(int, input().split())
    hiehgts = list(map(int, input().split()))
    tenbos = [[]for i in range(num_ten)]
    ans = 0
    for i in range(num_load):
        a, b = map(int, input().split())
        tenbos[a-1].append(b-1)
        tenbos[b-1].append(a-1)

    for index in range(len(tenbos)):
        height = hiehgts[index]
        heightest = True

        for tenbo in tenbos[index]:
            if (hiehgts[tenbo] >= height):
                heightest = False
        if heightest:
            ans += 1

    print(ans)
resolve()

Measured memory_bytes: 92984
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        Map<String,Integer> map = new HashMap<String,Integer>();
        int max = 1;
        for(int i=0;i<N;i++){
            String temp = sc.next();
            if(map.containsKey(temp)){
                int value = map.get(temp) + 1;
                map.put(temp , value);
                if(value > max){
                    max = value;
                }

            }else{
                map.put(temp,1);
            }

        }
        List maxstr = new ArrayList<String>();
        for (String key: map.keySet()) {
            if(map.get(key) == max){
                maxstr.add(key);
            }
        }

        Collections.sort(maxstr);

        for(int i=0;i<maxstr.size();i++){
            System.out.println(maxstr.get(i));
        }

    }
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    int arr[n];
    int ans[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        ans[i]=INT_MAX;
    }
    ans[0]=0;
    for(int i=0;i<n;i++){
        if(i+1<n)
            ans[i+1]=min(ans[i+1],abs(arr[i+1]-arr[i])+ans[i]);
        if(i+2<n)
            ans[i+2]=min(ans[i+2],abs(arr[i+2]-arr[i])+ans[i]);
    }
    cout<<ans[n-1]<<endl;
    return 0;
}

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

int main() {
  int N,a,b,c,d;
  cin>>N;
  	a= N/1000;
    b= (N - a*1000)/100;
    c= (N - a*1000 - b*100)/10;
    d= N - a*1000 - b*100 - c*10;
  if(a==b && b==c||b==c && c==d)
        cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;
}


Measured memory_bytes: 256
require 'matrix'

n, m, x = gets.split.map(&:to_i)
a = Matrix.zero(n, m + 1)
n.times do |i|
  b = gets.split.map(&:to_i)
  0.upto(m) do |j|
    a[i, j] = b[j]
  end
end
min = Float::INFINITY
[0, 1].repeated_permutation(n) do |bit|
  ans = 0
  sum = 0
  1.upto(m) do |j|
    sum = 0
    n.times do |i|
      if bit[i] == 1
        sum += a[i, j]
      end
    end
    break if sum < x
  end
  if sum >= x
    n.times do |i|
      if bit[i] == 1
        ans += a[i, 0]
      end
    end
    min = ans if min > ans
  end
end
puts (min == Float::INFINITY ? -1 : min)

Measured memory_bytes: 15304
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main() {
  int r, D,x_2000;
  cin >> r>>D >> x_2000;
  vector<int> v(10);
  int tem=x_2000;
  REP(i,10){
    tem = r * tem - D;
    v.at(i) = tem;
  }
  REP(i,10){
    cout << v.at(i)<<endl;
  }
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAXN = 1e5 + 100;
vector <int> g[MAXN];
const int MOD = 1e9 + 7;
int n, k;
typedef long long ll;
 
int dfs(int v, int p, int start) {
	ll ans = 1;
	for (auto u : g[v]) {
		if (u == p) continue;
		ans *= ((ll)dfs(u, v, k - 2) * start) % MOD;
		ans %= MOD;
		start--;
	}
	if (p == -1) {
		ans *= k;
		ans %= MOD;
	}
	return ans;
}
 
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	cout << dfs(1, -1, k - 1);
	return 0;
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main() {
  ll N;
  cin>>N;
  vector<double> v(N);
  rep0(i,N){cin>>v[i];}
  sort(all(v));
  reverse(all(v));
  for(ll i=N-1;i>=1;i--){
    v[i-1]=(double)(v[i]+v[i-1])/2;
  }
  cout<<v[0]<<endl;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
long double n,m,total,v[10001],nr;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        total+=v[i];
    }
    for(int i=1;i<=n;i++)
        if(v[i]>=total/(4*m))
            nr++;
    if(nr>=m)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using static System.Console;

static class Extensions {
   public static int ToInt(this string str) {
      return int.Parse(str);
   }
}

class Program {
   public static void Main(string[] args) {
      var arr = ReadLine().Split(' ').Select(x => x.ToInt()).ToArray();
      var a = arr[0];
      var b = arr[1];
      
      if (b % a == 0) {
         WriteLine(a + b);
      } else {
         WriteLine(b - a);
      }
   }
}


Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long e[100010];
int main() {
    long long n, k;
    cin >> n >> k;
    long long ans = 0;
    for (long long i = 1; i <= k; i++) {
        long long m = k / i;
        long long b = 0;
        for (long long j = 1; j * j <= i; j++) {
            if (i % j == 0) {
                b += e[j];
                if (j != i / j && j != 1) {
                    b += e[i / j];
                }
            }
        }
        if (i == 1) {
            b = 0;
        }
        long long n1 = n;
        long long ans1 = 1;
        while (n1 > 0) {
            if ((n1 & 1) == 1) {
                ans1 = ans1 * m % 1000000007;
            }
            m = m * m % 1000000007;
            n1 >>= 1;
        }
        ans += ans1 * (i - b) % 1000000007;
        ans %= 1000000007;
        e[i] = (i - b);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4372
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;


int main() {
	int n;
	deque<ll> a;
	cin >> n;
	ll sum = 0;
	rep(i, n) {
		ll x;
		cin >> x;
		a.push_back(x);
		sum += x;
	}

	ll snuke = 0, araiguma = sum, ans = 1LL << 60;

	rep(i, n-1) {
		snuke += a[i];
		araiguma = sum - snuke;
		ans = min(abs(snuke - araiguma), ans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1920
#include<iostream>

using namespace std;

int main() {
	char s[3];
	int i,money=700;

	for (i = 0; i < 3; i++) {
		cin>>s[i];
	}
	for (i = 0; i < 3; i++) {
		if (s[i] == 'o') {
			money += 100;
		}
	}
	cout << money;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+1;
const int mod = 1e9+7;
struct data
{
	int v;char c;
};
bool cmp(data a,data b){
	return (a.v>b.v);
};
vector<data> all;
int main() {
	int x,y,a,b,c;data inp;
	sd(x);sd(y);sd(a);sd(b);sd(c);
	inp.c='R';
	for(int i = 1; i <= a; i++){
		sd(inp.v);all.pb(inp);
	}
	inp.c='G';
	for(int i = 1; i <= b; i++){
		sd(inp.v);all.pb(inp);
	}
	inp.c='C';
	for(int i = 1; i <= c; i++){
		sd(inp.v);all.pb(inp);
	}
	sort(all.begin(),all.end(),cmp);
	ll sum=0;int r=0,g=0,col=0,i=0;
	while(r+g+col<x+y){
		if((all[i].c=='R')&&(r<x)){
			r++;sum+=all[i].v;
		}
		if((all[i].c=='G')&&(g<y)){
			g++;sum+=all[i].v;
		}
		if(all[i].c=='C'){
			col++;sum+=all[i].v;
		}
		i++;
	}
	plld(sum);
	return 0;
}

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

int main(){
    int N;
    int64_t K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    
    int last[200001];
    static int64_t dub[60][200000];
    for(int i=2*N-1; i>=0; i--){
        if(i<N) dub[0][i] = last[A[i]] - i + 1;
        last[A[i%N]] = i;
    }
    const int64_t INF = 1e18;
    for(int k=0; k<59; k++) for(int i=0; i<N; i++){
        int64_t d1 = dub[k][i];
        int j = (i+d1) % N;
        dub[k+1][i] = min(INF, d1 + dub[k][j]);
    }
    int64_t done = 0;
    for(int k=59; k>=0; k--){
        int64_t d = dub[k][done%N];
        if(done + d <= N*K) done += d;
    }

    vector<int> ans;
    bitset<200001> exist;
    while(done < N*K){
        int a = A[done%N];
        if(exist[a]){
            while(exist[a]){
                exist[ans.back()] = 0;
                ans.pop_back();
            }
        }else{
            exist[a] = 1;
            ans.push_back(a);
        }
        done++;
    }
    int sz = ans.size();
    for(int i=0; i<sz; i++) cout << ans[i] << " \n"[i==sz-1];
}


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const ll MOD = 1000000007;

int main() {
	int n; cin >> n;
	string s; cin >> s;
	vi cnt(26);
	rep(i, s.size()) cnt[s[i]-'a']++;
	ll ans = 1;
	rep(i, 26) {
		ans = ans * (cnt[i] + 1) % MOD;
	}
	ans--;
	if (ans < 0) ans += MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
// while (clock()<=69*CLOCKS_PER_SEC)
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define erase_duplicates(x) sort(all(x)); (x).resize(distance((x).begin(), unique(all(x))));


using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<
T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#define cerr if(0)cout
#endif

const int maxn = (3000)+7;
const int maxk = 20;
const int inf = (1e9)+7;
const LL LLinf = ((LL)1e18)+7LL;
const LD eps = 1e-9;
const LL mod = 998244353;

// ***************************** CODE ***************************** //

LL dp[maxn][maxn][2];

void add(LL & a, LL b)
{
  a += b;
  a %= mod;
  a += mod;
  a %= mod;
}

int main()
{
	_upgrade
  int a, b, c, d;
  cin>>a>>b>>c>>d;
  dp[a][b][0] = 1;
  for(int i = a;i <= c;i++)
    for(int j = b;j <= d;j++)
    {
      add(dp[i][j + 1][0], dp[i][j][0] * (LL)i);
      add(dp[i + 1][j][1], (dp[i][j][0] + dp[i][j][1])* (LL)j);
      add(dp[i][j + 1][0], dp[i][j][1]);
    }
  add(dp[c][d][0], dp[c][d][1]);
  cout<<dp[c][d][0];
	return 0;
}


Measured memory_bytes: 144516
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

signed main() {
	int n, a;
	cin >> n >> a;
	for (int i = 0; i <= a; i++)
		if ((n - i) % 500 == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	cout << "No" << endl;
	return 0;
}

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

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

    for(int i = 0; i*4 <= N; i++){
        for(int j = 0; j*7 <= N; j++){
            if(i*4 + j*7 == N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<int,int> mapa;
const int ms = 2e5 + 9;
int vet[ms],n;
bool f = 0;
ll M = 1e9+7;
ll fexp(ll v, ll p){
	if(p == 0)
		return 1;
	if(p == 1)
		return v;
	ll ans = fexp(v,p/2);
	ans*=ans;
	ans%=M;
	if(p&1)
		ans*=v;
	return ans%M;

}

int main(){
	int a,b;
	cin >> n;
	for(int i = 0;i<n;i++){
		cin >> a;
		mapa[a] ++;
		if((n&1) and mapa[0] > 1)
			f = 1;
		if(mapa[a] >2)
			f = 1;
		if((a&1) and n&1)
			f = 1;
		if(a%2 == 0 and n&2 == 0)
			f = 1;
	}
	for(auto it : mapa){
		if(it.first !=0 and it.second !=2)
			f = 1;
	}
	if(f)
		cout<<0;
	else{
		ll sz = mapa.size();
		if(n&1)
			sz--;
		cout<<fexp(2,sz);
	
	}
}

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

using namespace std;

const int mod = 1007050321;
const int base = 521;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const int inf = 2e9;

int n,X,Y,ans[N];

int main() {
    ios_base :: sync_with_stdio(0),cin.tie(0),cout.tie(0);

    cin >> n >> X >> Y;

    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            if (j < X || i > Y) ans[j-i]++;
            else if (i <= X && j >= Y) ans[X-i+j-Y+1]++;
            else if (X <= i && j <= Y) ans[min(j-i,i-X+Y-j+1)]++;
            else if (X >= i && j >= X && j <= Y) ans[X-i+min(j-X,Y-j+1)]++;
            else if (i <= Y && i >= X && j >= Y) ans[j-Y+min(Y-i,i-X+1)]++;
        }
    }

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

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 5005
mt19937 myrand(time(0));

ll p[mx],c[mx];
bool vis[mx];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    ll n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>p[i];
    for(int i=1;i<=n;i++) cin>>c[i];
    ll ans=-2e18;
    for(int i=1;i<=n;i++){
        vector<ll> v;
        memset(vis,0,sizeof vis);
        ll tmp=-2e18,x=i;
        while(!vis[p[x]]){
            //debug()<<imie(x);
            x=p[x];
            v.pb(c[x]);
            vis[x]=1;
        }
        //debug()<<imie(i)imie(v);
        for(int j=1;j<(int)v.size();j++) v[j]+=v[j-1];
        int sz=v.size();
        for(int j=0;j<(int)v.size();j++){
            if(k<(j+1)) break;
            ll cnt=(k-j-1)/sz;
            ll tmp2=v[j];
            tmp=max(tmp,tmp2);
            tmp=max(tmp,tmp2+(cnt*v[sz-1]));
        }
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())

using namespace std;
typedef pair<int,int> P;

// 最大公約数
int64_t gcd(int64_t a, int64_t b) {
  return b != 0 ? gcd(b, a % b) : a;
}

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

int ctoi(char c){
  return c - '0';
}

int main(){
  int64_t n;
  cin >> n;
  vector<int64_t> vec(n);
  REP(i,n){
    cin >> vec.at(i);
  }
  vector<int64_t> vec2;
  REP(i,n){
    if (vec2.size() == 0){
      vec2.push_back(vec.at(i));
    }else{
      auto tmp = lower_bound(ALL(vec2), vec.at(i)) - vec2.begin();
      if (tmp == 0){
        vec2.insert(vec2.begin(), vec.at(i));
      }else{
        vec2.at(tmp-1) = vec.at(i);
      }
      
    }
  }
  cout << vec2.size() << endl;
  return 0;
}



Measured memory_bytes: 2168
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int N, M, V, P;
  cin >> N >> M >> V >> P;
  vi A(N);
  cin >> A;
  sort(rall(A));
  vi S = A;
  psum(S);

  dump(A);

  int ans = P;
  rep(i, P, N) {
    int x = A[i] + M;
    if (A[P - 1] > x) continue;
    int r = M * V - M * (1 + (P - 1) + (N - 1 - i));
    int s = (i - P + 1) * x - (S[i - 1] - (P >= 2 ? S[P - 2] : 0));
    dump(x, r, s);
    if (r <= s) {
      dump("ok");
      ans++;
    }
  }
  cout << ans << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 1792
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class Main {
	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0;i<n;i++)a[i]=sc.nextInt();
        long ans = pow(3,n);
        long tmp=1;
        for(int i = 0;i<n;i++){
            if(a[i]%2==0)tmp*=2;
        }
        System.out.println(ans-tmp);
    }
    public static final long pow(long x, long n) {
        long sum = 1;
        while (n > 0) {
            if ((n & 1) == 1) {  //ビットが立っていたら
                sum *= x;        //x^2^k1 * x^2^k2 * x^2^k3 * ・・・
            }
            x *= x;              //((x^2)^2)^2・・・
            n >>= 1;
        }
        return sum;
    }
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


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

int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    vector<bool> dp(1000000+10,true);
    map<int,int> cnt;
    set<int> dic;

    for(int i=0; i<N; i++){
        cin>>A[i];
        cnt[A[i]]++;
        dic.insert(A[i]);
    }
    sort(A.begin(),A.end());

    for(int i=1; i<1000000+10; i++){
        if(dic.count(i)){
            for(int j=2*i; j<=1000000+10; j += i){
                dp[j] = false;
            }
        }
    }

    int ans = 0;

    for(int i=0; i<N; i++){
        if(cnt[A[i]] >= 2) continue;
        if(dp[A[i]]) ans++;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 22720