akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    string s;
    cin >> s;
    ll K;
    cin >> K;
    map<string, ll> subs;
    for(ll i=0;i<s.size(); i++)
    {
        //for(ll l=1; l<=s.size()-i;l++)
        for(ll l=1; l<=K;l++)
        {
            //cerr << s.substr(i, l) << endl;
            subs[s.substr(i, l)]++;
        }
    }
    string kth;
    ll count = 0;
    for(auto itr: subs)
    {
        count++;
        if(count == K) kth = itr.first;
    }
    cout << kth << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#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 all(x) (x).begin(),(x).end()
int main(){
    int a,b;
    cin>>a>>b;
    REP(i,a){
        REP(j,b){
            string t;
            cin>>t;
            if(t=="snuke"){
                cout<<(char)('A'+j)<<i+1<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define ll long long 
const int MAX=1e9+7;
const int mod=1e9+7;

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

int aa,dao=0,shu,n, q1, h1,q2,h2;
	string ss, qian,qian2="",hou2="", hou;
	cin >> ss;
	cin >> n;
	while (n--)
	{
		cin >> aa;
		if (aa == 1)
		{
			dao++;
		}
		else
		{
			cin >> shu;
			if ((dao + shu) % 2 != 0)
			{
				cin >> qian;
				qian2 = qian + qian2;
			}
			else
			{
				cin >> hou;
				hou2 = hou2 + hou;
			}
		}

	}
	if (dao % 2 == 0)
	{
		cout <<qian2<< ss <<hou2<< '\n';
	}
	else
	{
		ss = qian2 + ss + hou2;
		reverse(ss.begin(), ss.end());
		cout << ss << '\n';
	}

}



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

int N;
vector<int> H;

int main(void) {
	cin >> N;
	H.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> H[i];

	bool ans = true;
	if (N != 1) {
		for (int i = 1; i < N; ++i) {
			if (H[i] < H[i - 1]) {
				ans = false;
				break;
			}
			if (H[i] > H[i - 1])
				--H[i];
		}
	}

	cout << (ans ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;

typedef struct Dice
{
    int top,front,right;
    Dice()
    {
        top=1;
        front=2;
        right=3;
    }
    void roll(char ch)
    {
        int temp=top;
        switch(ch)
        {
        case 'E':
            top=7-right;
            right=temp;
            break;
        case 'W':
            top=right;
            right=7-temp;
            break;
        case 'N':
            top=front;
            front=7-temp;
            break;
        case 'S':
            top=7-front;
            front=temp;
        }
    }
    void roll1(char ch)
    {
        int temp=front;
        switch(ch)
        {
        case 'r':
            front=7-right;
            right=temp;
            break;
        case 'l':
            front=right;
            right=7-temp;
            break;
        }
    }
}Dice;


int main()
{
    int s[7];
    Dice d;

    for(int i=0;i<6;i++)
    {
        cin>>s[i+1];
    }

    int n;

    cin>>n;

    int a,b;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        for(int i=0;i<3&&s[d.top]!=a;i++)
        {
                d.roll('N');
        }
        for(int i=0;i<3&&s[d.top]!=a;i++)
        {
            d.roll('E');
        }
        for(int i=0;i<3&&(s[d.front]!=b);i++)
        {
            d.roll1('r');
        }
        cout<<s[d.right]<<endl;
    }



    return 0;

}



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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
// SegmentTree<int> seg(n, 0x7FFFFFFF, [](int a, int b){return min(a, b);});
template <class T>
class SegmentTree {
    using func_t = function<T(T, T)>;
    const int sz, n;
    const T id;
    func_t merge;
    vector<T> data;
    int expand(int n) const { return n == 1 ? n : expand((n + 1) / 2) * 2; }
public:
    SegmentTree(const vector<T> &init, T id, func_t merge) :
        sz(init.size()), n(expand(sz)), id(id), data(n * 2, id), merge(merge) {
        copy(begin(init), end(init), begin(data)+n);
        RREP(i, n) {
            data[i] = merge(data[i * 2 + 0], data[i * 2 + 1]);
        }
    }
    int size() const { return sz; }
    void update(int p, T val) {
        assert (0 <= p && p < sz);
        data[p += n] = val;
        while (p /= 2) data[p] = merge(data[p * 2], data[p * 2 + 1]);
    }
    T find(int l, int r) const {
        assert (0 <= l && l <= r && r <= sz);
        l += n; r += n;
        T res1 = id, res2 = id;
        while (l != r) {
            if (l % 2) res1 = merge(res1, data[l++]);
            if (r % 2) res2 = merge(data[--r], res2);
            l /= 2; r /= 2;
        }
        return merge(res1, res2);
    }
};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vector<ll> p(n), l(n); cin >> p >> l;
    vector<ll> S(n);
    S[0] = p[0];
    rep(i, 1, n) {
        S[i] = S[i-1] + p[i];
    }
    try {
        vector<ll> ss(n+1);
        rep(i, n) ss[i+1] = S[i];
        sort(all(ss));
        rep(i, n) if (ss[i+1] - ss[i] < l[i]) throw 1;
        SegmentTree<ll> seg(vector<ll>(n, 0), 0, [](ll a, ll b) { return a + b; });
        vector<P> v;
        rep(i, n) v.pb({S[i], i});
        sort(all(v), greater<P>());
        ll ans = 0;
        each(p, v) {
            ans += seg.find(0, p.second);
            seg.update(p.second, 1);
        }
        cout << ans << endl;
    }
    catch (int err) {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 11028
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    n = II()
    BTC = 380000.0
    total = 0
    for i in range(n):
        v, t = IS().split()
        if t == 'JPY': total += int(v)
        elif t == 'BTC': total += float(v)*BTC
    print(total)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
  int n;
  char str[10000] = {0};
  cin >> n;
  if(n % 2 == 1){
    cout << "No" << endl;
    return 0;
  }
  cin >> str;
  for(int i = 0; i < n / 2; i++){
    if(str[i] != str[i + n / 2]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

using namespace std;

const int N = 1e5 + 5, M = 1e6 + 6, OO = 0x3f3f3f3f;

int a, b, c;
int main()
{
	cin >> a >> b >> c;
	cout << (b * a)/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int sum[505];

int main(){
  int N,K; cin>>N>>K;
  int A[N],tot=0;
  rep(i,N){
    cin>>A[i];
    tot+=A[i];
  }
  vector<int> V;
  for(int i=2;i*i<=tot;i++){
    if(tot%i==0){
      V.push_back(i);
      if(i*i!=tot) V.push_back(tot/i);
    }
  }
  V.push_back(tot);
  
  int ans=1;
  for(int v:V){
    vector<int> tmp;
    rep(i,N) tmp.push_back(A[i]%v);
    sort(tmp.begin(),tmp.end());
    rep(i,N+1) sum[i]=0;
    rep(i,N) sum[i+1]=sum[i]+tmp[i];
    int cnt=1e9;
    rep(i,N){
      int j=N-1-i;
      if(v*j==sum[N]) cnt=min(cnt,sum[i+1]);
    }
    if(cnt<=K) ans=max(ans,v);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  string s;
  cin >> s;

  int a = 10 * (s[0] - '0') + (s[1] - '0');
  int b = 10 * (s[2] - '0') + (s[3] - '0');

  bool ym = (b >= 1 && b <= 12), my = (a >= 1 && a <= 12);
  if (ym && my) {
    cout << "AMBIGUOUS" << endl;
  } else if (ym && !my) {
    cout << "YYMM" << endl;
  } else if (!ym && my) {
    cout << "MMYY" << endl;
  } else {
    cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=4999999996000000001;


int main(){
    int n;
    cin>>n;
    int one=0;
    int two=0;
    int four=0;
    for(int i=0;i<n;i++){
        ll a; cin>>a;
        if(a%2==1){
            one++;
        }else if(a%4!=0){
            two++;
        }else{
            four++;
        }
    }
    bool f=false;
    if(four<=one-2){
        f=false;
    }else if(four==one-1){
        if(two==0){
            f=true;
        }
    }else{
        f=true;
    }
    if(f){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    

}

Measured memory_bytes: 3504
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,d[200001]{0};
	cin>>a;
	for (int i=0;i<a-1;i++)
	{
		int c;
		cin>>c;
		d[c-1]++;
	}
	for (int i=0;i<a;i++)
		if (d[i]!=0)
			cout<<d[i]<<endl;
		else
			cout<<0<<endl;
	return 0;
}


Measured memory_bytes: 4404
N, K = gets.split.map(&:to_i)
hash = Hash.new(0)

gets.split.map { |ar|
  s = ar.to_i
  hash[s] += 1
}
# p arr

hash2 = hash.sort_by{|x, y|y}
ans = 0
while hash2.size > K
  ans += hash2[0][1]
  hash2.shift
end
puts ans

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

vector<long long> divisor(long long N) {
  vector<long long> res;
  for (long long i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      res.push_back(i);
      if (i != N / i) {
        res.push_back(N / i);
      }
    }
  }
  return res;
}

int main() {

  long long N;
  cin >> N;

  vector<long long> v = divisor(N);

  int l = v.size();
  if (l % 2 == 0) {
    cout << v[l - 1] + v[l - 2] - 2 << endl;
  } else {
    cout << (v[l - 1] * 2) - 2 << endl;
  }

}

Measured memory_bytes: 384
import java.util.Scanner;
class Main{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
int a[]=new int[10001];
int x=0;
do{
a[x]=scan.nextInt();
if(a[x]==0)break;
x++;
}while(true);
x=0;
do{
if(a[x]==0)break;
System.out.println("Case "+(x+1)+": "+a[x]);
x++;
}while(true);
}
}

Measured memory_bytes: 43656
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}
void okuri() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		ci += 4 + __builtin_ctzll((tmp & ma0) ^ ma0) >> 3;
	}
	else {
		ci += 8;
		tmp = *(ll*)ci;
		ci += 4 + __builtin_ctzll((tmp & ma0) ^ ma0) >> 3;
	}
}

int A[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), M = getint(), K = getint();

	int p = 0;
	for (; p < N; p++) {
		A[p + 1] = A[p] + getint();
		if (A[p + 1] > K) break;
	}
	for (int q = p + 1; q < N; q++) okuri();

	while (A[p] > K) p--;
	ll kotae = p;

	rep1(i, M) {
		K -= getint();
		if (K < 0) break;
		while (A[p] > K) p--;
		if (kotae < i + p) kotae = i + p;
	}

	printf("%d\n", kotae);

	Would you please return 0;
}

Measured memory_bytes: 2512
#include<iostream>
    using namespace std;
    int main()
    {
    int n;char s[1000];
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>s[i];
    int ans=0,a=0,b=0,c=0,d=0;
    for(int i=0;i<n;i++)
    {
    if(s[i]=='P'&&a==0){
    ans++;
    a=1;
    }
    if(s[i]=='W'&&b==0){
    ans++;
    b=1;
    }
    if(s[i]=='G'&&c==0){
    ans++;
    c=1;
    }
    if(s[i]=='Y'&&d==0){
    ans++;
    d=1;
    }
    }
    if(ans==1)
    {
    cout<<"One";
    }
    else if(ans==2) cout<<"Two";
    else if(ans==3)cout<<"Three";
    else cout<<"Four";
    return 0;
    } 

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

int d(int a){
a *= a;
return a;
}

int main(void){
int a, b;
double c,S,h,k,L,A;

scanf("%d %d %lf",&a,&b,&c);
c = c / 180 * M_PI;
S = a * b * sin(c) / 2;
h = 2 * S / a;
k = d(a) + d(b) - 2 * a * b * cos(c);
A = sqrt(k);

L = a + b + A;


printf("%f\n%f\n%f\n",S,L,h);

return 0;
}

Measured memory_bytes: 648
#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 reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
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*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


ll cnt[200010];

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

    ll n, k, a, maxi=0;
    cin >> n >> k;
    rep(i, n){
        cin >> a;
        cnt[a]++;
        maxi = max(a, maxi);
    }

    vector<ll> v;
    rep(i, maxi+1){
        if(cnt[i] > 0) v.push_back(cnt[i]);
    }

    if(v.size() <= k){
        cout << 0 << endl;
        return 0;
    }

    sort(v.begin(), v.end());

    ll res = 0;
    rep(i, v.size()-k){
        res += v[i];
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int n, m, s, t;
vector <int> G[N];
bool vis[N][3];
int bfs()
{
	queue <pii> q;
	q.push(mp(s, 0));
	vis[s][0] = 1;
	while(sz(q))
	{
		int u = q.front().first, step = q.front().second;
		q.pop();
		if(u==t && step%3==0) return step/3;
		for(int v: G[u])
		{
			if(vis[v][(step+1)%3]) continue;
			vis[v][(step+1)%3] = 1;
			q.push(mp(v, step+1));
		}
	}
	return -1;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> m;
 	for(int i=1; i<=m; i++)
 	{
 		int u, v;
 		cin >> u >> v;
 		G[u].pb(v);
 	}
 	cin >> s >> t;
 	cout << bfs();
	return 0;
}


Measured memory_bytes: 8320
import java.util.*;

public class Main {

	public static void main(String[] args) {
			
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long D = sc.nextInt();
		int ans = 0;
		for (int i = 0; i < N; i++) {
			double x = sc.nextDouble();
			double y = sc.nextDouble();
			if (Math.sqrt((x*x) + (y*y)) <= D)
				ans++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 62684
import sys

K = int(input())
X, Y = map(int, input().split())

mx = 1 if X >= 0 else -1
my = 1 if Y >= 0 else -1
X, Y = abs(X), abs(Y)
isSwaped = False
if X < Y:
    X, Y = Y, X
    isSwaped = True

dist = X+Y
if dist%K == 0:
    rx, ry = 0, 0
else:
    if dist%2 == 0:
        if K%2 == 0:
            if dist <= 2*K:
                R = 2*K
            else:
                R = -(-dist // K) * K
        else:
            R = -(-dist // (2*K)) * 2*K
    else:
        if K%2 == 0:
            print(-1)
            sys.exit()
        else:
            if dist <= 3*K:
                R = 3*K
            else:
                R = -(-(dist-K) // (2*K)) * 2*K + K
    r = (R-dist) // 2

    if r < K:
        rx, ry = 0, r
    else:
        rx = r//2
        ry = r-rx

anss = []
x, y = 0, 0
if -ry < y:
    dy = y+ry
    y -= dy
    x += K-dy
    anss.append((x, y))

num = (X+rx-x) // K
for _ in range(num):
    x += K
    anss.append((x, y))

if x < X+rx:
    dx = X+rx-x
    x += dx
    y += K-dx
    anss.append((x, y))

num = (Y-y) // K
for _ in range(num):
    y += K
    anss.append((x, y))

if y < Y:
    dy = Y-y
    y += dy
    x -= K-dy
    anss.append((x, y))

print(len(anss))
if isSwaped:
    print('\n'.join(map(lambda x: str(x[1]*mx)+' '+str(x[0]*my), anss)))
else:
    print('\n'.join(map(lambda x: str(x[0]*mx)+' '+str(x[1]*my), anss)))


Measured memory_bytes: 39280
#include <stdio.h>

typedef struct{
	int stone_num;	// number of stones in cup
	int turn;		// whose turn
}CUP;
CUP cup1;

int check(int n,int t,int *s){
	int i;
	for(i=0;i<n;i++){
		if((i != t) && (s[i] > 0)){
			return 1;	
		}
	}
	return 0;
}

void game(int n,int p){
	int i;
	int stone[50] = {0};		// number of stones players have
	cup1.stone_num = p;
	cup1.turn = 0;
	
	while(1){
		if(cup1.stone_num > 0){
			cup1.stone_num--;
			stone[cup1.turn]++;
			if(cup1.stone_num == 0){
				if(check(n,cup1.turn,stone) == 0){
					printf("%d\n",cup1.turn);
					break;
				}
			}
		}else{
			cup1.stone_num = stone[cup1.turn];
			stone[cup1.turn] = 0;
		}
		cup1.turn++;
		if(cup1.turn >= n) cup1.turn = 0;
	}
}

int main(void) {
	int n,p;
	scanf("%d %d",&n,&p);
	while(n != 0){
		game(n,p);
		scanf("%d %d",&n,&p);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl '\n'
typedef vector<vector<ll>> matrix;
const ll INF = 1e18;
const int MAX = 2e5+4;
const int MOD = 1e9+7;
//vector<int> dp(MAX);
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n),b(n);
	vector<pair<int,int>> M;
	for(int i=0;i<n;i++)
	{
		cin >> a[i] >> b[i];
		M.push_back(mp(b[i],a[i]));
	}
	sort(M.begin(),M.end());
	int sum=0;
	for(auto task : M)
	{
		sum+=task.second;
		if(sum>task.first)
		{
			cout << "No"; return 0;
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 3956
//英雄(笑)装備
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<string.h>
#include<vector>
#include<stdio.h>
using namespace std;
int main() {
	int a, b, c;
	scanf("%d%d", &a, &b);
	c = a + b ;
	c = c / 2;
	printf("%d\n", c);
	return 0;
}


Measured memory_bytes: 3212
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun compress(a: Array<Int>): Array<Int> {
    val n = a.count()
    val b = a.sorted().distinct().toTypedArray()
    val c = Array(n) { 0 }
    for (i in 0 until n) {
        c[i] = Arrays.binarySearch(b, a[i])
    }
    return c
}

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    val b = compress(a)
    var count = 0
    for (i in 0 until n) {
        if (b[i] % 2 != i % 2) count++
    }
    println(count / 2)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

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

int main() {
    long double D, T, S;

    cin >> D >> T >> S;

    string ans = "Yes";

    if (D/S > T) ans = "No";

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

Measured memory_bytes: 3760
def main():
    x = [int(input()) for _ in range(5)]
    print(solve(x))

def solve(x):
    y = sorted(x, key=gap, reverse=True)
    s = sum(ceil(i) for i in y[1:])
    return s + y[0]

def ceil(x):
    r = x % 10
    if r != 0:
        return x + 10 - r
    else:
        return x

def gap(x):
    r = x % 10
    if r != 0:
        return 10 - r
    else:
        return 0

main()


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    for (int i = 1; true; ++i) {
      int x = in.nextInt();
      int y = in.nextInt();
      if      (x == 0 && y == 0) break;
      else if (x < y) System.out.println(x + " "+ y);
      else            System.out.println(y + " "+ x);
    }
  }
}

Measured memory_bytes: 27180
#include <iostream>

using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN_LL(v) ll v;cin>>v;
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl
const ll INF = 1e10;

int main() {
  IN_LL(H); IN_LL(W);

  ll ans = INF;
  FOR(h, 1, H) {
    ll S1 = W * h;
    ll S2 = W/2 * (H - h);
    ll S3 = (W+1)/2 * (H - h);
    ll S_max = max(S1, max(S2, S3));
    ll S_min = min(S1, min(S2, S3));
    ans = min(ans, S_max - S_min);

    S2 = W * ((H - h) / 2);
    S3 = W * ((H - h + 1) / 2);
    S_max = max(S1, max(S2, S3));
    S_min = min(S1, min(S2, S3));
    ans = min(ans, S_max - S_min);
  }
  FOR(w, 1, W) {
    ll S1 = w * H;
    ll S2 = (W - w) * (H/2);
    ll S3 = (W - w) * ((H+1)/2);
    ll S_max = max(S1, max(S2, S3));
    ll S_min = min(S1, min(S2, S3));
    ans = min(ans, S_max - S_min);

    S2 = (W - w) / 2 * H;
    S3 = (W - w + 1) / 2 * H;
    S_max = max(S1, max(S2, S3));
    S_min = min(S1, min(S2, S3));
    ans = min(ans, S_max - S_min);
  }
  OUT(ans);

  return 0;
}


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

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

using namespace std;

bool field[21][21];

void initialize(){
    REP(i,21){
        REP(j,21){
            field[i][j] = false;
        }
    }
}

int main(){
    int n;
    while(cin >> n){
        if(n==0) break;
        initialize();
        REP(k,n){
            int x,y;
            cin >> x >> y;
            field[y][x] = true;
        }

        int m;
        int i=10, j=10, cnt=0;
        cin >> m;
        REP(k,m){
            char direct;
            int dist;
            cin >> direct >> dist;
            REP(l,dist){
                switch(direct){
                    case 'E':
                        j++;
                        break;
                    case 'W':
                        j--;
                        break;
                    case 'N':
                        i++;
                        break;
                    case 'S':
                        i--;
                        break;
                }
                if(field[i][j]){
                    cnt++;
                    field[i][j] = false;
                }
            }
        }
        if(cnt == n){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1152
N_K =input('').split(' ')
lst = []
N = int(N_K[0])
K= int(N_K[1])
for n in range(0,N+1):
    lst.append(0)
for i in range(0, K ):
    D = int(input(''))
    A = map(int, input('').split(' '))
    for d in A:
        lst[d] = 1

ans = 0
for j in lst:
    if j == 0:
        ans = ans+1
print(ans-1)

Measured memory_bytes: 9204
#include <stdio.h>

int main() {

  int max,min,mar,t,n;
  int i,j,k,h,h2 = 0;

  scanf("%d",&t); 

      for(i=0;i<t;i++) {


	scanf("%d",&n);

	max = 0;
	min = 0;


	for(j=0;j<n;j++) {

	  scanf("%d",&h);
       
	 

	  if(j !=0) {
	    mar = h2 -h;
	    if(h2 - h <  max) max = h2 - h;
	    if(h2 -h > min) min = h2 -h;
	  } 
	  h2 = h;
	     
	}
	printf("%d %d\n",-1*max,min);
      
      }

    return 0;

}

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

typedef long long LL;
const int N = 1e5;

set<int> adjx[N+5], adjy[N+5];

int n;
bool uda[N+5];
bool udy[N+5];

set<int> tmp;

LL bfs(int x){
	LL ret = adjx[x].size();
	LL dptx = 1LL;
	LL dpty = 0LL;
	uda[x] = 1;
	queue<int> qx;
	while(!qx.empty()) qx.pop();
	for(auto cur:adjx[x]){
		udy[cur] = 1;
		dpty++;
		qx.push(cur);
	}
	while(!qx.empty()){
		int now = qx.front(); qx.pop();
		for(auto cur: adjy[now]){
			if(uda[cur]) continue;
			uda[cur] = 1;
			dptx++;
			ret+=adjx[cur].size();
			for(auto lala : adjx[cur]){
				if(udy[lala]) continue;
				udy[lala] = 1;
				dpty++;
				qx.push(lala);
			}
		}
	}
//	cout << dptx << " " << dpty << " " << ret  << endl;
	return dptx*dpty - ret;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		adjx[x].insert(y);
		adjy[y].insert(x);
	}
	LL ans = 0LL;
	for(int i=1;i<=N;i++){
		if(uda[i]) continue;
		ans+=bfs(i);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 19200
using System;
using System.Linq;

namespace B___Picking_Up
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var Ai = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            Array.Sort(Ai);

            var max = Ai[Ai.Length-1];
            var min = Ai[0];

            var result = new int[N-1,2];
            for(int i = 1 ; i < Ai.Length-1;i++)
            {
                if(Ai[i] < 0)
                {
                    result[i-1,0] = max;
                    result[i-1,1] = Ai[i];
                    max -= Ai[i];
                }
                else
                {
                    result[i-1,0] = min;
                    result[i-1,1] = Ai[i];
                    min -= Ai[i];
                }
            }
            result[N-2,0] = max;
            result[N-2,1] = min;
            Console.WriteLine(max-min);
            for(int i = 0 ;i < N-1 ; i++) Console.WriteLine("{0} {1}",result[i,0],result[i,1]);
        }
    }
}


Measured memory_bytes: 27976
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
	int n,m,c;cin>>n>>m>>c;
	vector<int>b(m);
	vector<vector<int>>a(n,vector<int>(m));
	int ans=0;
	rep(i,m)cin>>b[i];
	rep(i,n)rep(j,m)cin>>a[i][j];
	rep(i,n){
		int cnt=0;
		rep(j,m){
			cnt+=a[i][j]*b[j];
		}
		cnt+=c;
		if(cnt>0)ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
N,L = map(int,input().split())
sumL = 0
mainasu = 0
plus = 0
aji = []
count = 0
for i in range(N):
  aji.append(L + i)
  sumL += L + i
  if L + i == 0:
    count = 1
  elif L + i  < 0:
    mainasu += 1
  elif L + i > 0:
    plus += 1
if count == 1:
  print(sumL)
elif mainasu > plus :
  print(sumL-max((aji)))
else:
  print(sumL-min((aji)))

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

int main() {
	int N;
	cin >> N;
	vector<long> A(N);
	for (long& i : A) cin >> i;
	long ans = A.front() / 2;
	A.front() -= A.front() / 2 * 2;
	for (int i = 1; i < N; i++) {
		if (A[i - 1] && A[i]) {
			A[i]--;
			ans++;
		}
		ans += A[i] / 2;
		A[i] -= A[i] / 2 * 2;
	}
	cout << ans;
}

Measured memory_bytes: 1152
n = gets.chomp.to_i
ary = gets.split.map(&:to_i)

map = Hash.new(0)

ary.each do |e|
  map[e] += 1
end

map2 = Hash.new

sum = 0

map.each do |k, v|
  map2[k] = v * (v-1) / 2
  sum += map2[k]
end

ary.each do |e|
  puts sum - (map[e] - 1)
end

Measured memory_bytes: 36868
N = int(input())
A = list(map(int, input().split()))
B = [0] * (N+1)

for i in range(N)[::-1]:
  if(not sum(B[::i+1])%2 == A[i]):
    B[i+1] = 1
  if(not sum(B[::i+1])%2 == A[i]):
    print(-1)
    quit()
  
print(sum(B))
for i, b in enumerate(B):
  if b == 1:
    print(i, end=" ")

Measured memory_bytes: 8384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=len(s);
    if(n==26){
      vector<char> cnt;
      int now=26;
      for(int i=25;i>0;i--){
        if(s[i]<s[i-1]){
          cnt.push_back(s[i]);
          now=i;
        }else break;
      }
      now--;
      if(now==0){
        cout<<-1<<endl;
        return 0;
      }
      cnt.push_back(s[now]);
      char ans='z';
      for(auto itr:cnt){
        if(s[now-1]<itr){
          //cout<<itr<<endl;
          ans=min(itr,ans);
        }
      }
      //cout_vec(cnt);
      rep(i,now-1){
        cout<<s[i];
      }
      cout<<ans<<endl;
      return 0;
    }
    rep(i,26){
      char now='a'+i;
      if(!count(begin(s),end(s),now)){
        cout<<s+now<<endl;
        return 0;
      }
    }
}

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

int main(){
    long long int n;
    cin >> n;
    long long int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    long long int min_v;
     
    min_v = min({a, b, c, d, e});

    long long int ans = ((n + min_v - 1) / min_v) + 4;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  string s,t;cin>>s>>t;
  vector<string> ans;
  if(s.size() < t.size()){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for(int i = 0; s.size()-t.size() >= i; i++){
    if(s[i]=='?' || s[i] == t[0]){
      bool ok = true;
      for(int j = 0; t.size() > j; j++){
        if(!(s[i+j]=='?' || s[i+j] == t[j])){
          ok = false;
          break;
        }
      }
      if(ok){
        string ret = s;
        for(int j = 0; t.size() > j; j++){
          ret[i+j] = t[j];
        }
        for(int j = 0; s.size() > j; j++){
          ret[j] = (ret[j]=='?'?'a':ret[j]);
        }
        ans.push_back(ret);
      }
    }
  }
  if(ans.empty()){
    cout << "UNRESTORABLE" << endl;
  }else{
    sort(ans.begin(),ans.end());
    cout << ans[0] << endl; 
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;


int main(){
    ll n; cin >> n;
    ll l = 1, r = 1;
    ll ans = 0;
    rep(i,n){
        ll t,a; cin >> t >> a;
        ll nl = (t + l - 1) / t;
        ll nr = (a + r - 1) / a;
        ans = max(nl, nr) * (t + a);
        l = (ans / (t+a)) * t ;
        r = (ans / (t+a)) * a;
    }

    cout << ans << endl;
}

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

int main () 
{ 
int n;cin>>n;
long long int sum=0;
 
 for(int i=1;i<=n;i++){
 	if(i%3!=0 && i%5!=0) sum+=i;
 }
  cout<<sum;
	return 0; 
} 


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N; cin >> N;
    vi p(N+1); REP1(i, N) cin >> p[i];
    int c = 0;
    REP1(i, N) if(i != p[i]) c++;
    if(c == 2 || c == 0) YES;
    else NO;
} 
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static final Scanner sc = new Scanner(System.in);
    
    public static void main(String[] args) {
        String in = nstr();
        if (in.replaceAll("x", "").isEmpty()) {
            System.out.println(0);
            return;
        }
        
        char[] a = in.toCharArray();
        int ans = 0;
        int l = 0;
        int r = in.length()-1;
        while (r >= l) {
            int xl = 0;
            while (a[l] == 'x') {
                xl++;
                l++;
            }
            
            int xr = 0;
            while (a[r] == 'x') {
                xr++;
                r--;
            }
            
            if (a[r] != a[l]) {
                System.out.println(-1);
                return;
            }
            
            ans += Math.abs(xr - xl);
            l++;
            r--;
        }
        
        System.out.println(ans);
    }
    
    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static String[] nstrs(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++) {
            a[i] = nstr();
        }
        return a;
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0);
    }

    private static char[][] nchars2(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}

Measured memory_bytes: 32576
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
 
#define  ff     first
#define  ss     second
#define  pb     push_back
#define  all(x) (x).begin(), (x).end()
#define  rep(i,a,b) for(int i=a ; i<b ; ++i)
#define  deb(x) cout << #x << " - " << x << "\n";
#define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  D2(x)  { cerr << "[" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }
#define  ps(x,y) fixed<<setprecision(y)<<x
 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 10000000;
const ll MAX_N = 1e5 + 2;

int main() {
    IOS;
    int x,y; cin>>x>>y;
    int res = -1;
    
    for(int i=0;i<=x;i++){
        for(int j=0;j<=x;j++){
            if((i+j==x) && (i*2 + 4*j == y)){
                res = 1;
                break;
            }
        }
        if(res==1) break;
    }
    
    if(res==1) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long int
#define M 998244353

#define ff first
#define ss second
using namespace std;
ll n,t,x,y,m,q,k;

int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n>>k;
      pair<ll,ll>p[k];
      for(int i=0;i<k;i++){
        cin>>p[i].ff>>p[i].ss;
      }
      ll dp[n+1]={0,1},pre[n+1]={0,1};
      for(int i=2;i<=n;i++){
        for(int j=0;j<k;j++){
          ll r=max(0ll,i-p[j].ss-1);
          ll l=max(0ll,i-p[j].ff);
          dp[i]=(dp[i] + (pre[l]-pre[r]+M)%M )%M;
        }
        pre[i]=(pre[i] + dp[i]+ pre[i-1])%M;
      }
      cout<<dp[n];
}

Measured memory_bytes: 6700
#include<bits/stdc++.h>
#define int int64_t
using namespace std;

int bit[(int)2e5+5];

void update(int idx , int val , int n) {
    for(; idx <= n; idx += (idx & (-idx))) {
        bit[idx] = max(bit[idx] , val);
    }
}

int get(int idx) {
    int ans = 0;
    for(; idx > 0; idx -= (idx & -idx)) ans = max(ans , bit[idx]);
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n , ans = 0;
    cin >> n;
    int h[n] , a[n];
    for(int i = 0; i < n; i++) cin >> h[i];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) {
        int val = get(h[i]-1) + a[i];
        update(h[i] , val , n);
        ans = max(ans , val);
    }
    cout << ans << "\n";
    
    return 0;
}



Measured memory_bytes: 8292
#include <algorithm>
#include <chrono>
#include <iostream>
#include <vector>

using namespace std;
using namespace std::chrono;

inline bool is_bit(int mask, int b) {
  return (mask >> b) & 1;
}

int get_max_power(int v) {
  int res = 1;
  while (v > 0) {
    v >>= 1;
    ++res;
  }
  return res;
}

void fill_to_left(const vector<int>& vp, vector<int>& to_left, int v) {
  const int n = vp.size();

  for (int r = n - 1, l = n - 1; r >= 0;) {
    l = r;
    while (l - 1 >= 0 && vp[l] - vp[l - 1] <= v)
      --l;
    for (int i = l; i <= r; ++i)
      to_left[i] = l;
    r = l - 1;
  }
}

void fill_to_right(const vector<int>& vp, vector<int>& to_right, int v) {
  const int n = vp.size();

  for (int l = 0, r = 0; l < n;) {
    r = l;
    while (r + 1 < n && vp[r + 1] - vp[r] <= v)
      ++r;
    for (int i = l; i <= r; ++i)
      to_right[i] = r;
    l = r + 1;
  }
}

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, v;
  cin >> n >> v;
  vector<int> vp(n);
  for (int i = 0; i < n; ++i)
    cin >> vp[i];

  int max_pw = get_max_power(v);

  vector<vector<int>> to_left(max_pw, vector<int>(n, n)), to_right(max_pw, vector<int>(n, -1));
  for (int pw = 0; pw < max_pw; ++pw) {
    fill_to_left(vp, to_left[pw], v >> (max_pw - pw - 1));
    fill_to_right(vp, to_right[pw], v >> (max_pw - pw - 1));
  }

  const int max_mask = 1 << (max_pw - 1);
  vector<int> from_left(max_mask, -1), from_right(max_mask, n);

  for (int mask = 0; mask < max_mask; ++mask) {
    int cpos = from_left[mask];
    for (int b = 0; b < max_pw - 1; ++b) {
      if (!is_bit(mask, b)) {
        const int new_mask = mask | (1 << b);
        const int new_pos = cpos + 1 < n ? to_right[b][cpos + 1] : cpos;
        from_left[new_mask] = max(from_left[new_mask], new_pos);
      }
    }
  }

  for (int mask = 0; mask < max_mask; ++mask) {
    int cpos = from_right[mask];
    for (int b = 0; b < max_pw - 1; ++b) {
      if (!is_bit(mask, b)) {
        const int new_mask = mask | (1 << b);
        const int new_pos = cpos - 1 >= 0 ? to_left[b][cpos - 1] : cpos;
        from_right[new_mask] = min(from_right[new_mask], new_pos);
      }
    }
  }

  vector<int> ans(n + 1, 0);
  for (int mask = 0; mask < max_mask; ++mask) {
    int left_mask = mask;
    int right_mask = 0;
    do {
      int l = from_left[left_mask];
      int r = from_right[right_mask];

      if (l >= r) {
        ++ans[0];
        --ans[n];
      } else {
        int mr = l + 1 < n ? to_right[max_pw - 1][l + 1] : l;
        int ml = mr >= 0 ? to_left[max_pw - 1][mr] : mr;

        if (ml <= l + 1 && mr >= r - 1) {
          ++ans[ml];
          --ans[mr + 1];
        }
      }

      if (left_mask == 0)
        break;
      left_mask = mask & (left_mask - 1);
      right_mask = mask - left_mask;
    } while (true);
  }

  for (int i = 0; i < n; ++i) {
    cout << (ans[i] == 0 ? "Impossible" : "Possible") << '\n';
    ans[i + 1] += ans[i];
  }

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


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

int main(){
  int n,m;
  cin >> n >> m;
  
  vector<int> vec(m*2);
  vector<int> count(n);
  
  for(int i=0; i<m*2;i++){
    cin >> vec.at(i);
    for(int j=1; j<=n;j++){
      if(vec.at(i) == j){
        count.at(j-1)++;
      }
    }
  }
  
  for(int i=0; i<n; i++){
    cout << count.at(i) << endl;
  }
  
}

Measured memory_bytes: 256
function Main(input){
  input = input.split("\n");
  tmp = input[0]
  var goodNumberFlag = false;
  
  if(tmp[0] == tmp[1] && tmp[1] == tmp[2]){
    goodNumberFlag = true;
  }else if(tmp[1] == tmp[2] && tmp[2] == tmp[3]){
    goodNumberFlag = true;
  }
  
  if(goodNumberFlag){
    console.log('Yes');
  }else{
    console.log('No');
  }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
void Main(){
    int N = read(), Z = 111;
    while(N>Z) Z += 111;
    printf("%d\n", Z);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
//#include "/Users/HIMANSHU PANDEY/Desktop/coding/stdc++.h"
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define ins insert
#define sb substr
#define con continue
#define ub upper_bound
#define lb lower_bound
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define pll pair<ll,ll>
#define pld pair<ld,ld>
using namespace std;
 
ll power(ll x, ll y);
ll mpower(ll x, ll y, ll p);
ll modInv(ll a, ll m);
ll gcdExtended(ll a, ll b, ll *x, ll *y);
bool isPrime(ll n);
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,i,j,k,l,h,p,q,r,x,y,z,a,b,c,d,f,n,m,M=1000000007;
    char ch,ch2,ch3;
    string s="ACL",s1,s2,s3;
     cin>>k;
     for(i=0;i<k;i++)
     {
         cout<<s;
     }
    return 0;
}
 
ll modInv(ll a, ll m)
{
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);
    ll res = (x%m + m) % m;
    return res;
}
 
ll gcdExtended(ll a, ll b, ll *x, ll *y){
    if (a == 0){
        *x = 0, *y = 1;
        return b;
    }
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1;
    *y = x1;
    return gcd;
}
 
ll mpower(ll x, ll y, ll p){
    ll res = 1;
    x = x % p;
    while(y > 0){
        if(y & 1) res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
 
ll power(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}
 
bool isPrime(ll n){
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    ll p=sqrt(n);
    for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}

Measured memory_bytes: 3676
#include <stdio.h>
#include<math.h>


int main(void)
{
	int N,i;
	
	
	
	scanf("%d",&N);
	
	for(i=1;i<10;i++){
			if(pow(2,i)>N){
			printf("%d\n",(int)pow(2,i-1));
			
			break;
			
		}
	}
	
	
	return 0;
}



Measured memory_bytes: 384