akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

class C {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int[] A = new int[N];
        Arrays.setAll(A, i -> sc.nextInt());
        Arrays.sort(A);
        for(int i = 1; i < A.length; i++)
            if(A[i] == A[i - 1]) {
                System.out.println("NO");
                return;
            }
        System.out.println("YES");
    }
}
public class Main {
    public static void main(String... args) {
        C.main();
    }
}


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

using namespace std;

int main(int argc, char *argv[]) {
	int N, K;
	cin >> N >> K;

	vector<int> lengths;
	int cur_length; 
	for (int i = 0; i < N; i++) {
		cin >> cur_length;
		lengths.push_back(cur_length);
	}

	sort(lengths.begin(), lengths.end(), greater<int>());

	int answer = 0;
	for (int j = 0; j < K; j++) {
		answer += lengths[j];
	}

	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int X, n;
    while(cin>>X>>n){
        if(n==0){
            cout<<X<<endl;
            continue;
        }
        set<int> s;
        forn(i,n){
            int x; cin>>x;
            s.insert(x);
        }
        
        int ans = -100;
        int min_dist = 500;
        for(int i=-200; i<=200; ++i){
            if(s.count(i)==0){
                int dist = abs(X-i);
                if(dist<min_dist){
                    min_dist = dist;
                    ans = i;
                }
            }
        }

        cout<<ans<<endl;

    }
    return 0;
}

Measured memory_bytes: 3660
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int ans=0;
int n=sc.nextInt();
int a=sc.nextInt();
int b=sc.nextInt();
for(int i=1;i<=n;i++){
int sum=0,temp=i;
    while(temp!=0){
sum+=temp%10;
temp/=10;
}
if(sum>=a&&sum<=b){ans+=i;}
}
System.out.println(ans);
}}

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

#define min(a,b) (((a) > (b)) ? (b) : (a))
#define max(a,b) (((a) < (b)) ? (b) : (a))
int main(void) {
    int64_t N,M,X;
    int64_t price = LONG_MAX;
    int64_t cur_price;
    cin >> N >> M >> X;
    
    int64_t all_pattern;

    vector<int64_t> C(N);
    vector<vector<int64_t>> A(N,vector<int64_t>(M));
    for(int i=0;i<N;i++) {
        cin >> C[i];
        for(int j=0;j<M;j++) {
            cin >> A[i][j];
        }
    }

    all_pattern = 1 << N;
    
    for(int i=0;i<all_pattern;i++) {
        cur_price = 0;
        vector<int64_t> skill(M,0);
        for(int k=0;k<N;k++) {
            if(i & (1 << k)) {
                cur_price += C[k];
                for(int j=0;j<M;j++) {
                    skill[j] += A[k][j];
                }
            }
        }
        bool check = true;
        for(int j=0;j<M;j++) {
            if(skill[j] < X) {
                check = false;
                break;
            }
        }
        if(check) {
            price = min(cur_price,price);
        }
    }
    
    if(price == LONG_MAX) price = -1;
    cout << price << "\n";
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>

#include <string>

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

    int i;
    for (i = 0; i < s.size() - 2; i++) {
        if (s[i] == s[i + 1] || s[i] == s[i + 2]) {
            break;
        }
    }

    if (s[s.size() - 1] == s[s.size() - 2]) i = s.size() - 3;
    

    if (i == s.size() - 2) std::cout << -1 << " " << -1;
    else if(s[0] == s[1]) std::cout << 1 << " " << 2;
    else std::cout << i  + 1<< " " << i + 3;

    return 0;
}


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

using namespace std;

int main(){
	int A,B,C,D;
	
	cin >> A >> B >> C >> D;
	
	if(A+B==C+D)	cout << "Balanced" << endl;
	if(A+B>C+D)		cout << "Left" << endl;
	if(A+B<C+D)		cout << "Right"	<<	endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int maxn = 1e5+1000;


int n,m,a;
struct node 
 {
 	ll tt;
 	int pp;
 	int id;
 } t[maxn];

 bool cmp(node a,node b)
 {
 	return a.tt <= b.tt;
 }
ll p,y;

int s[maxn];
int pre[maxn];
int  en[maxn];
int main()
{
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(s,0,sizeof s);
		rep(i,0,m)
		{
			cin>>p>>y;
			t[i].tt = y; 
			t[i].pp = p;
			t[i].id = i;
		}
		sort(t,t+m,cmp);
		rep(i,0,m)
		{
			pre[t[i].id] = t[i].pp;
			en[t[i].id] = ++s[t[i].pp]; 
		}
		rep(i,0,m)
		{
			printf("%06d%06d\n",pre[i],en[i]);
		}

	}
}

Measured memory_bytes: 4224
// 2011/07/02 Tazoe

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
	while(true){
		string str;
		cin >> str;
		if(cin.eof())
			break;

		for(int i=0; i<str.size(); i++)
			if(str[i]==',')
				str[i] = ' ';

		istringstream ist(str);
		int l[11], v1, v2;
		int tot = 0;
		for(int i=1; i<=10; i++){
			ist >> l[i];
			tot += l[i];
		}
		ist >> v1 >> v2;

		int pas = tot*v1;
		int sum = 0;
		for(int i=1; i<=10; i++){
			sum += l[i];
			if(sum*(v1+v2)>=pas){
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
    int a, b, k;
    cin >> a >> b >> k;

    if (k >= b - a + 1) {
        for (int i = a; i <= b; i++) {
            cout << i << endl;
        }
        return 0;
    }

    if (k * 2 >= b - a + 1) {
        for (int i = a; i <= b; i++) {
            cout << i << endl;
        }
        return 0;
    }

    for (int i = a; i < a + k; i++) {
        cout << i << endl;
    }
    for (int i = b - k + 1; i <= b; i++) {
        cout << i << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <cassert>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

ll N,M;
ll A[100100],B[100100];
vector<ll> vec[100100];
ll d[100100];

bool isoddloop(ll s){
  d[s] = 2;
  queue<P> q;
  q.push(make_pair(s,s));
  ll cnt = 0;
  while(!q.empty()){
    ll l = q.size();
    //cerr << "l:" << l << endl;
    cnt++;
    rep(j,l){
      P tmp = q.front();
      q.pop();
      ll prev = tmp.first;
      ll now = tmp.second;
      rep(i,vec[now].size()){
        if(vec[now][i] != prev){
          ll tt = vec[now][i];
          if(d[tt] > 0 && d[tt]%2 != cnt%2){
            //cerr << "  pos:" << tt << "  cnt:" << cnt << endl;
            return true;
          }
          else if(d[tt] == 0){
            //cerr << "pos:" << tt << "  cnt:" << cnt << endl;
            d[tt] = cnt;
            q.push(make_pair(now,tt));
          }
        }
      }
    }
  }
  return false;
}
int main(){
  cin >> N >> M;
  rep(i,M){
    cin >> A[i] >> B[i];
    vec[A[i]].push_back(B[i]);
    vec[B[i]].push_back(A[i]);
  }
  if(isoddloop(1)){
    //assert(0);
    ll ans = N*(N-1)/2;
    ans -= M;
    cout << ans << endl;
  }
  else{
    
    ll a = 0;
    ll b = 0;
    rep(i,N){
      //cerr << " " << d[i+1] << endl;
      if(d[i+1] % 2 == 0) a++;
      else b++;
    }
    cout << a*b - M << endl;
  }
}


Measured memory_bytes: 9472
#include <iostream>
#include <cmath>
using ll = long long;

int main() {
    ll x; std::cin >> x;
    ll y=0, n=100;
    while(n<x) {
        n += n/100;
        ++y;
    }
    std::cout << y << std::endl;

    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
using namespace std;
int main(){
    string S;
    for (int i=0; i<6; i++) cin>>S[i];
    int con=0;
    for (int i=0; i<6; i++){
        if(S[i]=='1')con++;
    }
    cout<<con<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

#define gec     getchar
#define FILE(F) freopen(F".in","r",stdin),freopen(F".out","w",stdout)
#define DEBUG   fprintf(stderr,"Passing [%s] in Line (%d)\n",__FUNCTION__,__LINE__)

typedef long long ll;
template<typename T>
inline void read(T &x)
{
	x=0;bool f=0; char c=gec();
	for(;c<'0'||c>'9';c=gec())f=(c=='-');
	for(;c>='0'&&c<='9';c=gec())x=x*10+c-'0';
	x=f?-x:x;
}

const int MAXN(100010);
int n,m,a[MAXN];
ll Sum;
ll D[MAXN],DD[MAXN];
void put(int x,int y,int a,int b)//[x..y]+[a,a+b.a+b*2+....a+(y-x)*b]
{
	DD[x]+=a;
	DD[x+1]+=b-a;
	DD[y+1]-=a+(y-x+1)*b;
	DD[y+2]+=a+(y-x)*b;
}

int main()
{
	read(n);read(m);
	for(int i=1;i<=n;i++)read(a[i]);
	for(int i=1;i<n;i++)
	{
		if(a[i+1]>a[i])Sum+=a[i+1]-a[i];
		else 		 Sum+=a[i+1]+m-a[i];
	}
	for(int i=1;i<n;i++)
	{
		if(a[i+1]>=a[i])put(a[i]+1,a[i+1],0,1);
		else 		 
		{
			if(a[i]==m)put(1,a[i+1],0,1);
			else put(a[i]+1,m,0,1),put(1,a[i+1],m-a[i],1);
		}
	}	
	for(int i=1;i<=m;i++)DD[i]+=DD[i-1];
	for(int i=1;i<=m;i++)DD[i]+=DD[i-1];
	for(int i=2;i<=m;i++)
		if(DD[1]<DD[i])DD[1]=DD[i];
	printf("%lld\n",Sum-DD[1]);
	return 0;
}	


Measured memory_bytes: 1280
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define rep(i, e) for(int i = 0; i < e; i++)
#define repp(i, s, e) for(int i = s; i < e; i++)
#define MAX_N 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define NIL -1
typedef pair<ll, ll> P;

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

ll rec(ll H){
    if(H==1)return 1;
    return 2 * rec(H/2) + 1;
}

int main() {
    ll H;

    cin>>H;
    cout << rec(H) << endl;
}


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

int main(){
    long long int n,k;
    cin>>n>>k;
    vector<int> a(n),b(n);
    vector<long long int> sum(1e5+1,0);
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        sum[a[i]]+=b[i];
    }
    vector<long long int> sumsum(1e5+1,0);
    sumsum[0]=sum[0];
    for(int i=1;i<1e5+1;i++){
        sumsum[i]=sumsum[i-1]+sum[i];
    }
    cout<<(lower_bound(sumsum.begin(),sumsum.end(),k)-sumsum.begin())<<endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    int k, q;
    cin >> k >> q;
    Vl d(k);
    for (int i = 0; i < k; i++) {
        cin >> d[i];
    }

    Vl m(q), x(q), n(q);
    for (int i = 0; i < q; i++) {
        cin >> n[i] >> x[i] >> m[i];
    }

    Vl dm(k);
    for (int i = 0; i < q; i++) {
        ll out = 0;
        ll a_last = x[i] % m[i];
        for (int j = 0; j < k; j++) {
            dm[j] = d[j] % m[i];
            if (j <= (n[i] - 1) % k - 1) {
                a_last += dm[j] * ((n[i] - 1) / k + 1);
                if (dm[j] == 0)
                    out += (n[i] - 1) / k + 1;
            }
            else {
                a_last += dm[j] * ((n[i] - 1) / k);
                if (dm[j] == 0)
                    out += (n[i] - 1) / k;
            }
        }
        out += a_last / m[i];
        cout << n[i] - 1 - out << "\n";
    }

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stack>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    string nap;
    cin >> n >> nap;
    stack<int> S;
    string odp = "";
    for (int i = 0; i < n; ++i)
    {
        if (nap[i] == '(')
        {
            S.push(i);
            odp += "(";
        }
        else
        {
            if (S.size() != 0)
            {
                S.pop();
                odp += ")";
            }
            else
                odp = "(" + odp + ")";
        }
    }
    while (S.size() != 0)
    {
        odp += ")";
        S.pop();
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 256
// 2011/05/25 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		double xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2;
		cin >> xa1;
		if(cin.eof())
			break;
		cin >> ya1 >> xa2 >> ya2 >> xb1 >> yb1 >> xb2 >> yb2;

		double x1 = xa2-xb1;
		double x2 = xa1-xb2;
		double y1 = ya2-yb1;
		double y2 = ya1-yb2;

		if(x1*x2<=0.0&&y1*y2<=0.0)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

	return 0;
}

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


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br   = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int	nNum = 0;
		int	nTmp = 0;
		int	nSum = 0;
		int	nMax = 0;

		while((nNum = getNum()) != 0) {
			nSum = getNum();
			nMax = nSum;
			for (int n = 1; n < nNum; n++) {
				nTmp = getNum();
				nSum = Math.max(nSum + nTmp, nTmp);
				nMax = Math.max(nSum, nMax);
			}
			System.out.println(nMax);
		}
	}

	private static int getNum() {
		return Integer.parseInt(parseStdin());
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

Measured memory_bytes: 21600
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define speedhack ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define fromfile freopen("input.txt", "r", stdin);  freopen("output.txt", "w", stdout); 
#define mod int (1e9+7)
#define MAXN int (1e9)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;




ll a,b,c,k;

int main() {
    speedhack;
    //fromfile;
    cin >> a >> b >> c >> k;
    if (a>=k){
        cout << k;
        return 0;
    }
    else if (a + b >= k){
        cout << a;
        return 0;
    }
    else{
        cout << a - (k-(a+b));
        return 0;
    }




    }

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        int[] dpa = new int[n], dpb = new int[n], dpc = new int[n];
        Arrays.fill(dpa, inf);
        Arrays.fill(dpb, inf);
        Arrays.fill(dpc, inf);
        int[] a = new int[n], b = new int[n], c = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.ni();
            b[i] = in.ni();
            c[i] = in.ni();
        }
        dpa[0] = a[0];
        dpb[0] = b[0];
        dpc[0] = c[0];
        for (int i = 1; i < n; i++) {
            dpa[i] = Math.max(dpb[i-1],dpc[i-1])+a[i];
            dpb[i] = Math.max(dpa[i-1],dpc[i-1])+b[i];
            dpc[i] = Math.max(dpa[i-1],dpb[i-1])+c[i];
        }
        out.println(Math.max(dpa[n-1], Math.max(dpb[n-1], dpc[n-1])));
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 44664
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

#from fractions import Fraction
from math import gcd

mod = int(1e9+7)
n = ii()
cnd = {}
azero = 0
bzero = 0
allzero = 0
for _ in range(n):
    a,b = iim()
    if a == 0:
        if b != 0:
            azero += 1
        else:
            allzero += 1
    elif b == 0:
        bzero += 1            
    else:
        '''
        ratio = Fraction(a,b)
        before = cnd.get(ratio,False)
        if before:
            cnd[ratio] = [before[0]+1,before[1]]
        else:
            invratio = Fraction(-b,a)
            check = cnd.get(invratio,False)
            if check:
                cnd[invratio] = [check[0],check[1]+1]
            else:
                cnd[ratio] = [1,0]
        '''
        g = gcd(a,b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        cnd[(a,b)] = cnd.get((a,b),0)+1


noreg = 0
if azero == 0 or bzero == 0:
    noreg += max(azero,bzero)
    ans = 1
else:
    ans = (2**azero%mod + 2**bzero%mod - 1)%mod
#print('ans block')
#print(ans,noreg)
#print(cnd)
for k,item in cnd.items():
    a,b = k
    if b>0:
        m = cnd.get((b,-a),False)
        if m:
            ans *= (2**item%mod+2**m%mod-1)%mod
        else:
            noreg += item
    else:
        m = cnd.get((-b,a),False)
        if not m:
            noreg += item
#print('hoge')
print(int((ans*((2**noreg)%mod)-1+allzero)%mod))

Measured memory_bytes: 49180
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 200020
using namespace std;
LL read(){
    LL nm=0,fh=1; char cw=getchar();
    for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
    for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
    return nm*fh;
}
LL ans,sum0,sum1,sig;
LL n,m,fs[M],nt[M<<1],to[M<<1],col[M],f[M],sz[M],tmp;
LL fd(LL x){return x==f[x]?x:f[x]=fd(f[x]);}
void link(LL x,LL y){nt[tmp]=fs[x],fs[x]=tmp,to[tmp++]=y;}
void merge(LL x,LL y){x=fd(x),y=fd(y);if(x!=y) f[x]=y,sz[y]+=sz[x];}
bool check(LL x,LL now){
    if(col[x]) return col[x]==now; col[x]=now;
    for(LL i=fs[x];i!=-1;i=nt[i])
        if(!check(to[i],3-now)) return false;
    return true;
}
int main(){
    n=read(),m=read(),memset(fs,-1,sizeof(fs));
    for(LL i=1;i<=n;i++) f[i]=i,sz[i]=1;
    for(LL i=1;i<=m;i++){
        LL x=read(),y=read();
        link(x,y),link(y,x),merge(x,y);
    }
    for(LL i=1;i<=n;i++) if(fd(i)==i&&sz[i]==1) sig++;
    for(LL i=1;i<=n;i++){
        if(fd(i)!=i||sz[i]==1) continue;
        if(check(i,1)) sum0++;
        else sum1++;
    }
    ans+=sig*((n<<1)-1)-sig*(sig-1);
    ans+=((sum0*sum0)<<1);
    ans+=sum1*(sum0<<1)+sum1*sum1;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 12032
#include <cstdio>
#include <algorithm>

using namespace std;

struct SegmentTree
{
  vector< int > seg;
  int sz;

  SegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz - 1, 0);
  }

  void set(int k, int x)
  {
    seg[k + sz - 1] = x;
  }

  void build()
  {
    for(int k = sz - 2; k >= 0; k--) {
      seg[k] = max(seg[2 * k + 1], seg[2 * k + 2]);
    }
  }

  int rmq(int a, int b, int k, int l, int r)
  {
    if(a >= r || b <= l) return (0);
    if(a <= l && r <= b) return (seg[k]);
    return (max(rmq(a, b, 2 * k + 1, l, (l + r) >> 1),
                rmq(a, b, 2 * k + 2, (l + r) >> 1, r)));
  }

  int rmq(int a, int b)
  {
    return (rmq(a, b, 0, 0, sz));
  }
};

struct edge
{
  int to, cost;
};

int N;
vector< edge > g[100000];

int start[100000], stop[100000], ptr, depth[100000];

void dfs(int idx, int par)
{
  start[idx] = ptr++;
  for(edge& e : g[idx]) {
    if(e.to == par) continue;
    depth[e.to] = depth[idx] + e.cost;
    dfs(e.to, idx);
  }
  stop[idx] = ptr;
}

pair< int, int > dia(int idx, int par)
{
  pair< int, int > ret(0, idx);
  for(edge& e : g[idx]) {
    if(e.to == par) continue;
    auto child = dia(e.to, idx);
    ret = max(ret, {child.first + e.cost, child.second});
  }
  return (ret);
}

int calc(int idx)
{
  ptr = 0;
  depth[idx] = 0;
  dfs(idx, -1);
  SegmentTree tree(2 * N);
  for(int i = 0; i < N; i++) tree.set(start[i], depth[i]);
  tree.build();

  int ret = 0;
  for(int i = 0; i < N; i++) {
    for(edge e : g[i]) {
      if(depth[e.to] < depth[i]) e.to = i;
      ret = max(ret, max(tree.rmq(0, start[e.to]), tree.rmq(stop[e.to], 2 * N)) + e.cost);
    }
  }
  return (ret);
}

int main()
{
  scanf("%d", &N);
  for(int i = 1; i < N; i++) {
    int P, W;
    scanf("%d %d", &P, &W);
    g[P].push_back((edge) {i, W});
    g[i].push_back((edge) {P, W});
  }
  auto p = dia(0, -1);
  auto q = dia(p.second, -1);
  printf("%d\n", max(calc(p.second), calc(q.second)));
}

Measured memory_bytes: 17604
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<float.h>
using namespace std;


int main() {
    int n, k;
    cin >> n >> k;
    if (n%k == 0)cout << 0 << endl;
    else cout << 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;

int main()
{
	int x;
	cin >> x;
	if (x < 600) {
		printf("8");
	} else if (x < 800) {
		printf("7");
	} else if (x < 1000) {
		printf("6");
	} else if (x < 1200) {
		printf("5");
	} else if (x < 1400) {
		printf("4");
	} else if (x < 1600) {
		printf("3");
	}else if(x<1800){
		printf("2");
	} else {
		printf("1");
	}
	


	return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;
long long n, k, a, b, A[1000001];
int main(){
  cin >> n >> k;
  rep(i, n){
    cin >> a >> b;
    A[a-1]+=b;
  }
  rep(i, 1000001){
    k-=A[i];
    if(k <= 0){
      cout << i + 1 <<endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
#coding: utf-8
import sys

# 入力
n = int(sys.stdin.readline().strip())
s = list(sys.stdin.readline().strip())


counts = []
counts.append([0] * n)
counts.append([0] * n)

length = len(s)

if (s[0] == 'W'):
     counts[0][0] = counts[0][0] + 1

if (s[length - 1] == 'E'):
    counts[1][length-1] = counts[1][length-1] + 1



for i in range(1, length):
    counts[0][i] = counts[0][i - 1]
    counts[1][length -1 - i] = counts[1][length - i]

    if (s[i] == 'W'):
        counts[0][i] = 1 + counts[0][i]

    if (s[length - i - 1] == 'E'):
        counts[1][length - i - 1] = 1 + counts[1][length - i - 1]

leaders = [0] * n
for i in range(length):
    if (i == 0):
        leaders[i] = counts[1][i + 1]
    elif(i == length - 1):
        leaders[i] = counts[0][i - 1]
    else:
        leaders[i] = counts[0][i - 1] + counts[1][i + 1]


# 出力
print(min(leaders))

Measured memory_bytes: 31808
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        string str = Console.ReadLine();

        if(str == "Sunny")
        {
            str = "Cloudy";
        }else if(str == "Cloudy")
        {
            str = "Rainy";
        }
        else if (str == "Rainy")
        {
            str = "Sunny";
        }

        Console.WriteLine(str);

        Console.ReadKey();


    }



    public static int GetInputInt()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] GetInputsInt()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
    public static List<int> GetInputsIntList()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
    }
    public static List<float> GetInputsFloatList()
    {
        return Console.ReadLine().Split(' ').Select(float.Parse).ToList();
    }

    public static char[] GetInputChar()
    {
        return Console.ReadLine().ToCharArray();
    }

    public static long GetInputLong()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] GetInputsLong()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }

}


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


int main() {
  ll N = 0;
  cin >> N;
  vector<string> S(N);
  map<string, int> count;
  rep(i, N) cin >> S.at(i); 
  rep(i, N) count[S.at(i)]++;
  cout << count.size() << endl;
}


Measured memory_bytes: 25076
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		LinkedList<string> answer = new LinkedList<string>();
		foreach(var c in Console.ReadLine()){
		    answer.AddLast(c.ToString());
		}
		bool reverse = false;
		
		long Q = long.Parse(Console.ReadLine());
		for(var i = 0; i < Q; i++){
		    var input = Console.ReadLine().Split(' ');
		    switch(input[0]){
		        case "1":
		            reverse = !reverse;
		            continue;
		        case "2":
		            switch(input[1]){
		                case "1":
		                    if(reverse)
		                        answer.AddLast(input[2]);
		                    else
		                        answer.AddFirst(input[2]);
		                    break;
		                case "2":
		                    if(reverse)
		                        answer.AddFirst(input[2]);
		                    else
		                        answer.AddLast(input[2]);
		                    break;
		                default :
		                    break;
		            }
		            break;
		        default :
		            break;
		    }
		}
		
		var ans = answer.ToArray();
		if(reverse) {
		    for(var i = ans.Length - 1; i >= 0; i--){
		        Console.Write(ans[i]);
		    }
		}else{
		    for(var i = 0; i < ans.Length; i++){
		        Console.Write(ans[i]);
		    }
		}
		Console.WriteLine();
	}
}

Measured memory_bytes: 43420
N = int(input())
s = str(N)
count = 0
if len(s) == 1:
    count += N
    print(count)
elif 1 < len(s) < 3:
    count += 9
    print(count)
elif len(s) == 3:
    count += 9
    count += N-99
    print(count)
elif 3 < len(s) < 5:
    count += 9 + 900
    print(count)
elif len(s) == 5:
    count += 9 + 900 + N-9999
    print(count)
elif len(s) > 5:
    count += 90909
    print(count)

Measured memory_bytes: 3064
N = int(input())
H = list(map(int, input().split()))
max_n = 0
tmp = 0
for i in range(N-1):
  if H[i] >= H[i+1]:
    tmp += 1
  else:
    max_n = max(max_n, tmp)
    tmp = 0
    
print(max(max_n, tmp))

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

#define int long long

const int N = 26;
int n, ans, mark[N];
string s;

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	while (n--) {
		cin >> s;
		mark[s[0] - 'A']++;
	}
	vector <int> vec = {mark['M' - 'A'], mark[0], mark['R' - 'A'], mark[2], mark['H' - 'A']};
	
	for (int i = 0; i < 5; i++)
		for (int j = i + 1; j < 5; j++)
			for (int k = j + 1; k < 5; k++)
				ans += vec[i] * vec[j] * vec[k];
	cout << ans << endl;
}

Measured memory_bytes: 384
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
s = input()
if s[-1]=="s":
    print(s+"es")
else:
    print(s+"s")


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

int N,R,T;
int p[128];

int loc[128] = {0};
int table[1024][1024] = {0};

int main(){
	scanf("%d%d%d",&N,&R,&T);
	for(int i = 1; i <= N; i++){
		scanf("%d",&p[i]);
	}

	int ans = 0;
	for(int t = 1; t <= T; t++){
		for(int n = 1; n <= N; n++){
			loc[n] = (loc[n] + p[n]) % R; // n人目の今の場所
			if(t != 1){
				table[t][loc[n]]++; // 空の容器を置く
			}
			if(table[t-1][loc[n]] > 0){
				table[t-1][loc[n]]--; // 容器に飲料を入れる
			}
			else{
				ans++; // 新しい容器を使う
			}
		}
		for(int r = 0; r < R; r++){
			table[t][r] += table[t-1][r]; // 使われなかった容器を次に持ち越す
		}
	}
	
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 7156
#include <stdio.h>

int main()
{
	int n;
	int i, j;
	int a[3];
	int max;

	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d %d %d", &a[0], &a[1], &a[2]);
		for(j=0; j<3; j++) a[j]*=a[j];
		max=0;
		for(j=0; j<3; j++){
			if(max<a[j]) max=a[j];
		}
		if(a[0]+a[1]+a[2]==2*max) printf("YES\n");
		else printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;



signed main()
{
    string A, B, C;
    cin >> A >> B >> C;
    
    cout << A[0] << B[0] << C[0] << endl;
}


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

using namespace std;
typedef long long ll;

ll modPow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = modPow(x * x, n / 2);
  if (n & 1) res = res * x;
  return res;
}

int main(void) {
  ll n;
  cin >> n;

  int cnt = 0;
  n++;
  while (n % 2 == 0) {
    n /= 2;
    cnt++;
  }

  cout << modPow(2, cnt) << endl;

  return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

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

    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}


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

typedef long long ll;
int const INF = 1000000000;

int n;
int a, b;
vector<ll> v(50);

ll comb[51][51];

void Comb() {
  for (int i = 0; i < 51; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (j == 0 || i == j) {
        comb[i][j] = 1LL;
      } else {
        comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
      }
    }
  }
}



int main(){
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    long double sum = 0;
    for (int i = 0; i < a; i++){
        sum += v[i];
    }
    sum /= a;
    cout << fixed << setprecision(10) <<  sum << endl;

    Comb();
    ll cnt = 0LL;
    int last = count(v.begin(), v.end(), v[a-1]);
    if (v[a-1] == v[0]){
        for (int i = a; i <= b; i++){
            cnt += comb[last][i];
        }
    } else {
        int i = 0;
        while(v[i] != v[a-1]) i++;
        cnt = comb[last][a-i];
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=2e+18;
const double EPS=1e-9;
const int MOD=998244353;

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

set<string> st;

char d(char a,char b){
	for(int i = 0;i < 3;i++){
		if(i + 'a' != a && i + 'a' != b) return i + 'a';
	}
}

signed main(){
	int n,cnt = 0,dp1[200010][3][4] = {},dp2[200010][3] = {},ans = 0;
	bool flag = true,same = true;
	string s;
	cin >> s;
	n = s.length();
	if(n <= 3){
		queue<string> que;
		que.push(s);
		while(!que.empty()){
			s = que.front();que.pop();
			st.insert(s);
			for(int i = 0;i < n - 1;i++){
				if(s[i] != s[i + 1]){
					string t = s;
					t[i] = d(s[i],s[i + 1]);
					t[i + 1] = d(s[i],s[i + 1]);
					if(!st.count(t)) que.push(t);
				}
			}
		}
		cout << st.size() << endl;
		return 0;
	}
	dp1[0][0][3] = 1;
	dp2[0][0] = 1;
	for(int i = 0;i < n;i++){
		cnt += s[i] - 'a';
		if(i){
			if(s[i] == s[i - 1]) flag = false;
			else same = false;
		}
		for(int j = 0;j < 3;j++){
			for(int k = 0;k < 4;k++){
				for(int l = 0;l < 3;l++){
					if(k != l) (dp1[i + 1][(j + l) % 3][l] += dp1[i][j][k]) %= MOD;
				}
				if(k != 3) (dp2[i + 1][(j + k) % 3] += dp2[i][j]) %= MOD;
			}
		}
	}
	for(int i = 0;i < 3;i++) (ans += dp1[n][cnt % 3][i]) %= MOD;
	if(same) cout << 1 << endl;
	else cout << (dp2[n][cnt % 3] - ans + flag + MOD) % MOD << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  vector<pair<int, int>> reds(N), blues(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d %d", &reds[i].first, &reds[i].second);
  }
  for (int i = 0; i < N; ++i) {
    scanf("%d %d", &blues[i].first, &blues[i].second);
  }

  sort(blues.begin(), blues.end());
  vector<int> used(N, 0);
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    int bx = blues[i].first, by = blues[i].second;
    int ix = -1, diff = INF;
    for (int j = 0; j < N; ++j) {
      if (used[j]) { continue; }
      int rx = reds[j].first, ry = reds[j].second;
      if (rx >= bx or ry >= by) { continue; }
      if (by - ry < diff) {
        diff = by - ry;
        ix = j;
      }
    }
    if (ix != -1) {
      used[ix] = 1;
      ++ans;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  unsigned long long n;
  cin>>n;
  unsigned long long a=n,i,b=1;
  for(i=1;i<=(int)sqrt(n);i++){
    if(n%i==0 && n/i+i<a+b){a=n/i;b=i;}
  }
  cout<<a+b-2<<endl;
}

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

int a[2];
int main(){
  string str;
  cin >> str;
  for(auto &c:str)
  	a[c-'A']++;
  if(a[0] and a[1])
    	cout << "Yes\n";
  else
    	cout << "No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main(){
  string s,ans;
  cin>>s;
  rep(i,s.size()){
    if (i%2==0) {
      ans+=s.at(i);
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 512
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define mor > muu & operator << (
#define R22(r) sim > typename \
  enable_if<1 r sizeof dud<c>(0), muu&>::type operator<<(c g) {
sim > struct rge { c b, e; };
sim > rge<c> range(c h, c n) { return {h, n}; }
sim > auto dud(c* r) -> decltype(cerr << *r);
sim > char dud(...);
struct muu {
#ifdef LOCAL
stringstream a;
~muu() { cerr << a.str() << endl; }
R22(<) a << boolalpha << g; ris; }
R22(==) ris << range(begin(g), end(g)); }
sim, class b mor pair < b, c > r) { ris << "(" << r.first << ", " << r.second << ")"; }
sim mor rge<c> u) {
  a << "[";
  for (c i = u.b; i != u.e; ++i)
    *this << ", " + 2 * (i == u.b) << *i;
  ris << "]";
}
#else
sim mor const c&) { ris; }
#endif
muu & operator()() { ris; }
};
#define imie(r...) "[" #r ": " << (r) << "] "
#define imask(r...) "[" #r ": " << bitset<8 * sizeof(r)>(r) << "] "
#define arr(a, i) "[" #a imie(i) ": " << a[i] << "] "
#define arr2(a, i, j) "[" #a imie(i) imie(j) ": " << a[i][j] << "] "
#define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ")

const int N = 2e5 + 7;
int per[N];
int a[N];

long long dp[N];

long long D[N];

void insert(int x, long long w) {
    for (; x < N; x += (x&-x)) D[x] = max(D[x], w);
}

long long query(int x) {
    long long res = 0;
    for (; x > 0; x -= (x&-x)) res = max(res, D[x]);
    return res;
}

int n;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", per + i);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    
    long long wyn = 0;
    for (int i = 1; i <= n; ++i) {
        dp[i] = query(per[i]) + a[i];
        insert(per[i], dp[i]);
        wyn = max(wyn, dp[i]);
    }
    printf("%lld\n", wyn);
    return 0;
}


Measured memory_bytes: 4992
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
    const list = lines[1].split(" ").map(v=>v-0);
    list.sort((a,b)=>a-b);
    let ans = 0;
    for(let i=0;i<list.length;i++){
        for(let j=i+1;j<list.length;j++){
            if(list[i] == list[j]) continue;
            for(let k=j+1;k<list.length;k++){
                if(list[j] == list[k]) continue;
                if(list[k]< list[i]+list[j]) ans++;
            }
        }
    }
    
    console.log(ans);
});

check = (a)=>{
    return a.toString()===a.toString().split("").reverse().join("")?1:0;
}


Measured memory_bytes: 32860
#include <cstdio>

typedef long long LL;

int main()
{
	LL x; scanf("%lld", &x);
	LL ans = x / 11; ans <<= 1;
	LL r = x % 11;
	if(r) ans++; if(r > 6) ans++;
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
#define double long long
using namespace std;
signed main() {
    int N, X;
    cin >> N >> X;
    int A = 0;
    int i;

    vector<int>L(N);

    for (i = 0; i < N; i++) {
        cin >> L.at(i);
        A += L.at(i);
        if (A > X) {
            break;
        }
        
    }
    cout << i + 1 << endl;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
using namespace std;
int vis[200001];
char str[200001];
int main()
{
	
	cin>>str;
	int len=strlen(str);
	int l=0,y=0;
	int sum=0;
	for(int i=0;i<len;i++)
	{
		if(str[i]=='0') l++;
		else y++;
	}
	printf("%d",min(l,y)*2);
}

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


int main() {

	int n, m;
	cin >> n >> m;
	vector<int> d(n + 1);
	vector<unsigned int> w(n + 1);
	for (int i = 0; i < m; i++) {
		int b;
		cin >> b;
		d[b] = 1;
	}
	w[0] = 1;
	w[1] = d[1] ? 0 : 1;
	for (int i = 2; i <= n; i++) {
		w[i] = w[i - 1] + w[i - 2];
		if (w[i] > 1000000007)
			w[i] -= 1000000007;
		if (d[i]) w[i] = 0;
	}

	cout << w[n] << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<fstream>
#include<sstream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
#include<valarray>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<list>
#include<utility>
#include<bitset>
#include<algorithm>
#include<functional>
using namespace std;
int main()
{
	int n,sum,k;
	cin>>n;k=n;
	while(n!=0){
		sum+=n%10;
		n/=10;
	}
	if (k%sum==0)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;

int main(){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    if(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2])cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c,x,count=0,i,j;
  scanf("%d%d%d%d",&a,&b,&c,&x);
  x/=50;
  for(i=0;i<=a;i++)
    for(j=0;j<=b;j++)
      if(x-10*i-2*j<=c && 0<=x-10*i-2*j)
        count++;
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main ()
{
  int min,max,num;
  
  cin >> min >> max >> num;
  
  int result = 0;
  
  for (int i = min ; i <= max; ++i) {
    if ((i % num) == 0)
      ++result;
    
  }
  
  
  cout << result;

}

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

using namespace std;

using ll = long long;

class Problem {
public:
    Problem(int _n) : n(_n), a(_n) {}
    ll Solve() {
        for (int i = 0; i < n; ++i) cin >> a[i];
        for (int i = 1; i < n; ++i) a[i] += a[i - 1];


        vector<ll> l(n);
        for (int i = 2; i < n; ++i) {
            l[i] = l[i - 1];
            while (l[i] + 1 < i &&
                   abs(2 * a[l[i]] - a[i]) >= abs(2 * a[l[i] + 1] - a[i]))
                ++l[i];
        }

        vector<ll> r(n);
        r[n - 3] = n - 2;
        for (int i = n - 4; 0 <= i; --i) {
            r[i] = r[i + 1];
            while (i < r[i] - 1 && abs(2 * a[r[i]] - a[i] - a[n - 1])
                   >= abs(2 * a[r[i] - 1] - a[i] - a[n - 1]))
                --r[i];
        }

        ll ans = a[n - 1];
        for (int i = 1; i <= n - 3; ++i) {
            ll s1 = a[l[i]], s2 = a[i] - a[l[i]],
                s3 = a[r[i]] - a[i], s4 = a[n - 1] - a[r[i]];
            ans = min(ans, max({s1, s2, s3, s4}) - min({s1, s2, s3, s4}));
        }


        return ans;
    }

private:
    int n;
    vector<ll> a;
};

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

    int n;
    cin >> n;
    Problem p(n);
    cout << p.Solve() << endl;

    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
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)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      int x,t;
      cin >> x >> t;
      cout << max(0,x-t) << endl;
      return 0;}

Measured memory_bytes: 256
x1 = input().split()
N = int(x1[0])
M = int(x1[1])
S = []
A = []
K = []
F = []
for i in range(M):
    S.append(0)
for i in range(N):
    K.append(0)
for i in range(N):
    A.append(input().split())
    K[i] = int(A[i][0])
    for j in range(K[i]):
        F.append(int(A[i][j+1]))
    for j in F:
        S[j - 1] += 1
    F = []
ans = 0
for i in range(M):
    if S[i] == N:
        ans += 1
print(ans)


Measured memory_bytes: 3064