akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
const long long INF = 1LL<<60;

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


const int iMax = 110;
const int wMax = 100100;
long long  w[iMax];
long long  v[iMax];
long long  dp[iMax][wMax]; 


int main() {
	int N,W;
	cin >> N >>W;
	
	for(int i=0; i<N; i++) {
		cin >> w[i] >> v[i];
	}

	for(int i=0; i<N; i++) {
		for(int sum_w =0; sum_w <= W; sum_w++) {
			
			// i番目の品物を選ぶとき
			if(sum_w -w[i] >=0)	{
				chmax(dp[i+1][sum_w], dp[i][sum_w-w[i]]+v[i]);
			}
			
			// i番目の品物を選ばないとき
			chmax(dp[i+1][sum_w], dp[i][sum_w]);
		}
	}
		
	//回答
	cout << dp[N][W] << endl;	
		
	return 0;
}

Measured memory_bytes: 79360
N = int(input())
A = list(map(int, input().split()))

def TwoNumber(a):
    ans = 0
    while True:
        if a % 2==0:
            a = a /2
            ans += 1
        else:
            break
    return ans

ans = 0
for i in range(len(A)):
    ans += TwoNumber(A[i])

print(ans)

Measured memory_bytes: 9972
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H, W, h, w;
    H = sc.nextInt();
    W = sc.nextInt();
    h = sc.nextInt();
    w = sc.nextInt();

    System.out.println(H*W - (h*W + w*H - h*w));
  }
}


Measured memory_bytes: 25300
#include<iostream>
#include<cstdio>
#include<cmath>
#define maxn 10005
using namespace std;
long long a[maxn],b[maxn],n,A,B;
int main()
{
 cin>>n;
 for(int i=1;i<=n;i++)
     cin>>a[i];
 for(int i=1;i<=n;i++)
    {
	 cin>>b[i];
     if(a[i]>b[i]) 
	    B+=(a[i]-b[i]);
   	 else if(a[i]<b[i]) 
		     A+=(b[i]-a[i])/2;
    }
 if(A>=B) 
    cout<<"Yes";
 else 
    cout<<"No";
 return 0;
} 

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

int main() {
  string S;
  cin >> S;
  
  if (S.at(0) == S.at(1) && S.at(0) == S.at(2)) {
    cout << "No" << endl;
  }
  else if (S.at(0) == S.at(1) && S.at(2) == S.at(3)) {
    cout << "Yes" << endl;
  }
  else if (S.at(0) == S.at(2) && S.at(1) == S.at(3)) {
    cout << "Yes" << endl;
  }
  else if (S.at(0) == S.at(3) && S.at(1) == S.at(2)) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	int ans = 0;

	int b = 1;
	for (int i = 0; i < n; ++i) {
		if (a[i] == b) {
			ans++;
			b++;
		}
	}

	if (ans == 0) {
		dunk(-1);
	}
	else {
		dunk(n - ans);
	}

	return 0;
}

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

using namespace std; 

int main(){
	
	int n , k , val; 
	
	int ans = 1e9 + 7; 
	
	vector<int> container;
	
	vector<int> dist(100007);
	
	cin >> n >> k;
	
	for(int i=0; i< n; i++){
		cin >> val;
		
		container.push_back(val);
	}
	
	sort(container.begin(),container.end());
	
	dist[0] = 0;
	
	for(int i = 1; i<n;i++){
		dist[i] = dist[i-1] + container[i] - container[i-1];
	}
	
	for(int i = 0; i<n;i++){
		if(i+k-1<n){
			ans=min(ans,dist[i+k-1] - dist[i]);
		}else{
			break;
		}
	}
	
	cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
  string c; cin >> c;
  if(c == "a" || c == "i" || c == "u" || c == "e" || c == "o"){
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;

int main(){
  double n,max=0,min=INT_MAX;
  while(scanf("%lf",&n)!=EOF){
    if(max<n) max=n;
    if(min>n) min=n;
  }
  printf("%f\n",max-min);
  return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
	string s;
	cin >> s;
	string ans = "";
	rep(i, 3) {
		if (s[i] == '1') ans += '9';
		else ans += '1';
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Set;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        long k =  Long.parseLong(br.readLine());
        
        char ans = '1';
        
        //if 
        for (int i = 0; i < k; i++) {
            if (s.charAt(i) != '1') {
                ans = s.charAt(i);
                break;
            }
        }
        System.out.println(ans);
    }
    
    
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

 
void solve()
{
    ll n;cin>>n;
    vector<ll>a(n+1);vector<ll>b(n);
    REP(i,n+1)cin>>a[i];REP(i,n)cin>>b[i];
    ll sum=0;
    for(int i=n-1;i>=0;i--)
    {
        if(b[i]>=a[i+1])
        {
            b[i]-=a[i+1];sum+=a[i+1];a[i+1]=0;
            if(b[i]>=a[i])
            {
                 b[i]-=a[i];sum+=a[i];a[i]=0;
            }else
            {
                a[i]-=b[i];sum+=b[i];b[i]=0;
            }
        }else
        {
            a[i+1]-=b[i];sum+=b[i];b[i]=0;
        }
    }
    cout<<sum<<endl;
}

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

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b, c = 0;
    cin >> a >> b;
	for (int i = a ; i <= b ; i++) if (i / 10000 == i % 10 && i / 1000 % 10 == i % 100 / 10) c++;
	cout << c;	
}

Measured memory_bytes: 3612
import java.util.Scanner;

object Main{
  def main(args: Array[String]){
    val sc = new Scanner(System.in);
    val n = sc.nextInt;
    sc.nextLine;
    val s: String = sc.nextLine;

    var countW: Array[Int] = new Array(n+1);
    var countE: Array[Int] = new Array(n+1);

    for(i <- 1 to n){
      countW(i) = countW(i-1);
      countE(i) = countE(i-1);
      s(i-1) match{
        case 'W' => countW(i) += 1;
        case 'E' => countE(i) += 1;
      }
    }

    println((for(i <- 1 to n) yield (countW(i-1) + countE(n) - countE(i))).min);
  }
}


Measured memory_bytes: 45552
#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define int long long
#define hh puts("")
using namespace std;
int r,d,x;
inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-ff;ch=getchar();}
    while(isdigit(ch)){ret=(ret<<3)+(ret<<1)+(ch^48);ch=getchar();}
    return ret*ff;
}
signed main(){
	r=read(),d=read(),x=read();
	for(int i=1;i<=10;i++){
		x=x*r-d;
		printf("%lld\n",x);
	}
    return 0;
}

Measured memory_bytes: 256
//  Created by ZJYelizaveta on 2017年09月16日 星期六 20时35分44秒
//  Copyright (c) 2017年 ZJYelizaveta. All rights reserved.

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
template<typename T> T readIn() {
	T x(0), f(1);
	char ch = getchar();
	while (ch < '0' || ch > '9') {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	return x * f;
}
int n, a;

int main()
{
	n = readIn<int>(), a = readIn<int>();
	int ans = n * n - a;
	printf("%d\n", ans);
	return 0;
}


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

char a[MAX][MAX];
int n, m;
int dis[MAX][MAX];
const int mx[] = {0, 1}, my[] = {1, 0};

struct node{
    int x, y, dis;
    friend bool operator <(node a, node b){
        return a.dis > b.dis;
    }
};
priority_queue<node> q;

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        scanf("%s", a[i]+1);
    }
    memset(dis, 0x3f, sizeof(dis));
    dis[1][1] = a[1][1]!='.';
    q.push((node){1, 1, a[1][1]!='.'});
    while(!q.empty()){
        node t = q.top();
        q.pop();
        if(t.dis > dis[t.x][t.y]) continue;
        for(int i = 0; i < 2; i++){
            int u = t.x+mx[i], v = t.y+my[i];
            if(u <= 0 || u > n || v<=0 || v>m) continue;
            if(dis[u][v] > t.dis+(a[t.x][t.y]=='.' && a[u][v]!='.')){
                dis[u][v] = t.dis+(a[t.x][t.y]=='.' && a[u][v]!='.');
                q.push((node){u, v, dis[u][v]});
            }
        }
    }
    cout << dis[n][m] << endl;

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    int i,j,flag=1;
    char c[2][3];
    for(i=0;i<2;i++){
        for(j=0;j<3;j++) cin>>c[i][j];
    }
   for(i=0;i<2;i++){
        for(j=0;j<3;j++){
            if(c[i][j]!=c[1-i][2-j]){
                flag=0;
                break;
        }
    }
   }
    if(flag) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

ans = 0
count = 0

for i in range(N - 1):
  if H[i] >= H[i + 1]:
    count += 1
  else:
    ans = max(ans, count)
    count = 0

ans = max(ans, count)
print(ans)

Measured memory_bytes: 14252
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

// CHECK THE LIMITS
typedef long long ll;

static const int NMAX = 1e5+5;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

vector<int> v[NMAX];
map<pair<int,int>,int> colorare;
int aux[NMAX];

void bfs(int maxi)
{
	vector<bool> visited(NMAX,false);
	queue<int> coada;
	coada.push(1);

	visited[1] = true;
	int cycle = 1;
	while(!coada.empty())
	{
		int node = coada.front();
		coada.pop();
		visited[node] = true;
		for(auto &child : v[node])
		{
			if(visited[child] == false)
			{
				cycle = (aux[node] + 1) % (maxi+1);
				if(cycle == 0)
					cycle = 1;
				colorare[{node,child}] = cycle;
				aux[node] = cycle;
				aux[child] = cycle;
				coada.push(child);
			}
		}

	}
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int n;
	cin >> n;
	vector<pair<int,int> > order;
	for(int i = 0; i< n-1;++i)
	{
		int a,b;
		cin >> a >> b;
		order.push_back({a,b});
		v[a].push_back(b);
		v[b].push_back(a);
	}
	int sol = 0;
	for(int i =1; i<= n;++i)
	{
		sol = max(sol, (int)v[i].size());
	}
	bfs(sol);
	cout << sol << '\n';
	for(int i = 0; i< (int) order.size();++i)
	{
		cout << colorare[order[i]] << '\n';
	}

    return 0;
}

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


int main() {
    int n, d1, d2;
    cin >> n;
    bool chk=false;
    int cnt=0;
    for (int i=0;i<n;i++) {
        cin >> d1 >> d2;
        
        if (d1 == d2) cnt++;
        else cnt=0;

        if (cnt==3) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9+7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,m, ans=0;

	cin >>n;
	VI a(n);
	rep(i, n) cin >>a[i];
	
	while(1){
		int mnx = min_element(all(a)) - a.begin();
		if(sz(a)==1) break;
		rep(j, n) if(j != mnx) a[j] = a[j]%a[mnx];
		//for(auto z :a) printf("%d, ",z); puts("");
		a.erase(remove(all(a), 0),a.end());
	}
	
	cout << a[0] <<"\n";
	return 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
struct LS {
	ll num, cost;
	//値、遅延配列
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x%p;
		x = x * x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n, q;
string s;
int M, C;
//今の範囲に入っているMの数、いまの範囲に入っているCの数
int sum;
//今の範囲のk-DMC数
signed main() {
	cin >> n >> s >> q;
	for (int z = 0; z < q; z++) {
		int k;
		cin >> k;
		M = 0;
		C = 0;
		sum = 0;
		int r = 0;
		//[l,r)
		int ans = 0;
		for (int l = 0; l < n; ) {
			while (l < n&&s[l] != 'D') {
				if (s[l] == 'C') {
					C--;
				}
				if (s[l] == 'M'){
					M--;
					sum -= C;
				}
				l++;
				if (l == r) {
					if (s[r] == 'C') {
						C++;
						sum += M;
					}
					if (s[r] == 'M') {
						M++;
					}
					r++;
				}
			}
			if (l == n) goto loop;
			while (r <= n && r - l < k) {
				if (s[r] == 'C') {
					C++;
					sum += M;
				}
				if (s[r] == 'M') {
					M++;
				}
				r++;
			}
			ans += sum;
			l++;
		}
	loop:;
		cout << ans << endl;
	}
}

Measured memory_bytes: 1412
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;	
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n) 
{
	for (int i = 0; i < n; ++i)
		cout << arr[i] << ' ';
	cout << endl;
}

template <typename X> ostream& operator << (ostream& x,const vector<X>& v){ for (X a : v) x << a << ' '; return x;} 
template <typename X, typename Y> ostream& operator << (ostream& x, const vector< pair<X, Y> >& v) {for (pair <X, Y> it : v) x << it.first << ' ' << it.second << endl; return x;} 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (pair <T, S> it : v) os << it.first << " => " << it.second << endl; return os; }
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
int modulo = 1e9 + 7;

int fpow(int a, int n) 
{
	int ans = 1;
	while (n) 
	{
		if (n&1) ans = (ans*a)%modulo;
		a = (a*a)%modulo; n = n >> 1;
	}
	return ans;
}

signed main() 
{
	fast_io();
	int a,b; cin >> a >> b;
	if (a > 9 or b > 9)
	{
		cout << -1 << endl;
	}
	else
		cout << a*b << endl;
	return 0;
}

Measured memory_bytes: 256
# -*-???coding:utf-8 -*- 
class Node
  attr_accessor :key, :left, :right
  def initialize key
    @key = key
  end

  def inorder
    left.inorder if left
    print " ", key
    right.inorder if right
  end

  def preorder
    print " ", key
    left.preorder if left
    right.preorder if right
  end
end

def insert
  z = Node.new $key.to_i
  x = $root
  while x
    y = x  #???????¨????
    x = z.key < x.key ? x.left : x.right  #?????????????§????/?????????????§????
  end

  unless y  #y???nil?????´???
    $root  = z
  else
    z.key < y.key ? y.left = z : y.right = z  #z???y?????????????????????/z???y?????????????????????
  end
end

n = gets.to_i
n.times do
  command, $key = gets.split
  if command == "insert"
    insert
  else
    $root.inorder
    puts 
    $root.preorder
    puts
  end
end

Measured memory_bytes: 47888
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

#define TIME_MAX 3000
int main(void) {
    int num, limit;
    cin >> num >> limit;
    vector<pii> foods(num);
    for(int i = 0; i < num; i++) {
        int time, point;
        cin >> time >> point;
        foods[i] = make_pair(time, point);
    }

    // asc_by_time
    sort(foods.begin(), foods.end());
    vector<vector<int>> dp(num+1, vector<int>(limit+TIME_MAX+1));
    for(int i = 1; i <= num; i++) {
        pii f = foods[i-1];
        // eat
        for(int t = 0; t <= limit+TIME_MAX; t++) {
            dp[i][t] = dp[i-1][t]; // stay
            // slide
            if(t>=0) dp[i][t] = max(dp[i][t-1], dp[i][t]);
            if(t >= f.first && t-f.first<limit) {
                dp[i][t] = max(dp[i][t], dp[i-1][t-f.first]+f.second);
            }
        }
    }

    cout << dp[num][limit+TIME_MAX] << endl;
    return 0;
}

Measured memory_bytes: 73740
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


# globals
inf = float('inf')
N, K = 0, 0
S = ""
M = 300000


def set_inputs():
    global N, K, S
    N, K = get_li()
    S = get_str()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    cont = []
    cur = S[0]
    count = 1
    for s in S[1:]:
        if cur == s:
            count += 1
        else:
            cont.append((count, cur == "1"))
            cur = s
            count = 1
    cont.append((count, cur == "1"))
    
    lc = len(cont)
    if lc == 1:
        print(len(S))
        return
    cont = cont + ([(0, None)] * M)
    if cont[0][1] == False:
        cont = [(0, None)] + cont
    ans = 0
    tmp = sum(map(operator.itemgetter(0), cont[:2*K+1]))
    ans = tmp
    i = 2
    while i < lc + 1:
        tmp = tmp - cont[i-2][0] - cont[i-1][0] + cont[i+2*K-1][0] + cont[i+2*K][0]
        ans = max(ans, tmp)
        i += 2
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

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); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll a, b, t;
    cin >> a >> b >> t;

    cout << t / a * b << endl;

    return 0;
}


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

using namespace std;

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

int N, K;
int s[3005][3005];

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    if (c == 'W') x += K;
    x %= 2 * K;
    y %= 2 * K;
    s[x][y]++;
    s[x + K][y + K]++;
    s[x + K][y]--;
    s[x][y + K]--;
  }
  for (int i = 0; i <= 3 * K; i++) {
    for (int j = 0; j <= 3 * K; j++) {
      s[i + 1][j] += s[i][j];
    }
  }
  for (int i = 0; i <= 3 * K; i++) {
    for (int j = 0; j <= 3 * K; j++) {
      s[i][j + 1] += s[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < K; j++) {
      int a = s[i][j];
      a += s[i + 2 * K][j];
      a += s[i][j + 2 * K];
      a += s[i + K][j + K];
      a += s[i + 2 * K][j + 2 * K];
      chmax(ans, a);
    }
    for (int j = K; j < 2 * K; j++) {
      int a = s[i][j];
      a += s[i + K][j - K];
      a += s[i + K][j + K];
      a += s[i + 2 * K][j];
      chmax(ans, a);
    }
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 35584
N,K=(int(i) for i in input().split(' '))
x=[int(i) for i in input().split(' ')]
time=None
index=0
l=len(x)
while True:
  if x[index]==0:
    K-=1
    x.remove(index)
  elif x[index]>0:
    break
  index+=1
  if index==l:
    break
x.insert(index,0)
if K==0:
  time=0
for i in range(max(0,K-len(x)+index+1),min(K+1,index+1)):
  if -x[index-i]>x[index+K-i]:
    time_tmp=-x[index-i]+2*x[index+K-i]
  else:
    time_tmp=-2*x[index-i]+x[index+K-i]
  if time==None:
    time=time_tmp
  if time_tmp<time:
    time=time_tmp
print(time)

Measured memory_bytes: 14780
#include<bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define ll         	long long int
#define pb          push_back
#define ar 			array
#define mp 			make_pair
#define f(i,n)   	for(ll i =0;i<n;i++)
#define inf 		INT_MAX
#define pll 		pair<ll, pair<ll,ll>>
const ll INF = 1e18;
void init(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE 
		freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#endif
}
void solve(){
	ll n;
	cin>>n;
	vector<ll>a(n);
	ll zero = 0;
	for(ll i = 0;i<n;i++){
		cin>>a[i];
		zero += !a[i];
	}
	
	if(zero > 0){
		cout<<"0"<<endl;
		return;
	}
	
	ll prod = 1;
	for(ll i = 0; i<n;i++){
		if(a[i] <= floor(INF / prod)){
			prod *= a[i];
			if(prod > INF){
				cout<<"-1"<<endl;
				return;
			}
		}
		else{
			cout<<"-1"<<endl;
			return;
		}
	}
	cout<<prod<<endl;
	
}
int main(){
	init();
	ll t = 1;
	//cin>>t;
	for(ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
    cout.precision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) { 
        solve();
    }
    return 0;
}

void solve() { 
	int a, b;
	cin >> a >> b;
	int lol = (1 ^ 2) ^ 3;
	cout << (lol ^ a ^ b);    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define MAX 2000000
#define INFTY (1<<30)

void swap(int *,int *);
void maxHeapify(int);
int extract();
void increaseKey(int,int);
void insert(int);

int H,A[MAX+1];

int main(){
  int key;
  char com[10];

  while(1){
    scanf("%s",com);
    if(com[0]=='e' && com[1]=='n')break;
    if(com[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }else{
      printf("%d\n",extract());
    }
  }
  return 0;
}
void swap(int *a,int *b){
  int tmp;
  tmp=*a;
  *a=*b;
  *b = tmp;

}

void maxHeapify(int i){
  int l,r,largest;
  l=2*i;
  r=2*i+1;

  if(l <= H && A[l] > A[i])largest=l;
  else largest=i;
  if(r<=H && A[r] > A[largest])largest=r;
  if(largest!=i){
    swap(&A[i],&A[largest]);
    maxHeapify(largest);
  }
}
int extract(){
  int maxv;
  if(H<1)return -INFTY;
  maxv=A[1];
  A[1]=A[H--];
  maxHeapify(1);
  return maxv;
}
void increaseKey(int i,int key){
  if(key<A[i])return;
  A[i]=key;
  while(i>1 && A[i/2]<A[i]){
    swap(&A[i],&A[i/2]);
    i=i/2;
  }
}

void insert(int key){
  H++;
  A[H]=-INFTY;
  increaseKey(H,key);
}



















































Measured memory_bytes: 5592
use std::collections::HashSet;
fn main() {
    let mut s = read::<String>()
        .chars()
        .collect::<HashSet<char>>()
        .into_iter()
        .collect::<Vec<_>>();
    s.sort();
    //println!("{:?}", s);
    for i in 97..122 + 1 {
        let c: char = std::char::from_u32(i as u32).unwrap();
        if !s.contains(&c) {
            println!("{}", c);
            return;
        }
    }
    println!("None");
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

int main() {
    string S, T;
    cin >> S >> T;
    int n = S.length();
    string TT = T.substr(0, n);
    if (S == TT) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3624
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}
 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;
}

const ll N=2e6+5;

ll dp[N];

bool use[N];

int main()
{ 

  IOS;

  ll n,k;
  cin>>n>>k;

  cout<<n*n-k<<endl;
return 0;
 
}



Measured memory_bytes: 3624
#include <iostream>
#include <unordered_set>

int main() {
	int n, m;
	std::cin >> n >> m;

	std::unordered_set<int> f1, fn;
	for (int i = 0; i < m; ++i) {
		int a, b;
		std::cin >> a >> b;

		if (a == 1) {
			if (fn.find(b) != fn.end()) {
				std::cout << "POSSIBLE" << std::endl;
				return 0;
			}
			f1.insert(b);
		}
		if (b == n) {
			if (f1.find(a) != f1.end()) {
				std::cout << "POSSIBLE" << std::endl;
				return 0;
			}
			fn.insert(a);
		}
	}

	std::cout << "IMPOSSIBLE" << std::endl;
}

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

int main(){
  int k,s;
  cin >> k >> s;

  int ans = 0;
  for (int i = 0; i <= k; i++)
  {
    for (int j = 0; j <=k; j++)
    {
      int z = s-i-j;
      if(z>=0 && z<=k) ans++;
    }
  }

  cout << ans << endl;  
}

Measured memory_bytes: 256
import heapq

N=int(input())
A=list(map(int,input().split()))

B=A[:N]
S=sum(B)
heapq.heapify(B)

BS=[0]*(3*N)
BS[N]=S
for i in range(N,2*N):
    if B[0]<A[i]:
        x=heapq.heappop(B)
        S+=A[i]-x
        heapq.heappush(B,A[i])

    BS[i+1]=S
        
    
C=[-c for c in A[2*N:]]
S=-sum(C)
heapq.heapify(C)

CS=[0]*(3*N)
CS[2*N]=S

for i in range(2*N-1,N-1,-1):
    if -C[0]>A[i]:
        x=-heapq.heappop(C)
        S+=A[i]-x
        heapq.heappush(C,-A[i])

    CS[i]=S

ANS=-float("inf")
for i in range(N,2*N+1):
    ANS=max(ANS,BS[i]-CS[i])

print(ANS)

Measured memory_bytes: 37212
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String r = sc.nextLine();
		char[] s = r.toCharArray();
		String ans = "AC";
		int i;
		int c=0;
		if((s[0]!='A')||(Character.isUpperCase(s[1]))) {
			ans = "WA";
		}else {
			for(i=2;i<r.length()-1;i++) {
				if(Character.isUpperCase(s[i])) {
					if(s[i]!='C') {
						ans = "WA";
						break;
					}else {
						c++;
						if(c>1) {
							ans ="WA";
							break;
						}
					}
				}
			}
			if(c!=1) {
				ans="WA";
			}else if(Character.isUpperCase(s[r.length()-1])) ans = "WA";
		}
		System.out.println(ans);

	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

int main() {
	int n, w;
	cin >> n >> w;
	struct { int v, w; } item[101];
	for (int i = 1; i <= n; i++) {
		cin >> item[i].v >> item[i].w;
	}
	int dp[101][10001] = {};
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= w; j++) {
			if (j < item[i].w)
				dp[i][j] = dp[i-1][j];
			else
				dp[i][j] = max(dp[i-1][j], dp[i][j-item[i].w] + item[i].v);
		}
	}
	cout << dp[n][w] << endl;
	return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;

const int M = 303;

const int mod = 998244353;

int add(int x) {  
  return x;
}

template<typename... T>
int add(int x, T... y) {  
  x += add(y...);
  if (x >= mod)
        x -= mod;
  return x;
}

template<typename... T>
int udd(int &x, T... y) { 
  return x = add(x, y...);
}

template<typename... T>
int sub(int x, T... y) { 
  return add(x, mod - add(y...));
}

int mul(int x) { 
  return x;
}

template<typename... T>
int mul(int x, T... y) { 
  return 1ll * x * mul(y...) % mod;
}

int bin(int x, int to) { 
  int y = 1;
  while (to) { 
        if (to & 1)
                  y = mul(x, y);
            x = mul(x, x);
                to >>= 1;
  }
  return y;
}

int inv(int x) { 
  assert(x != 0);
  return bin(x, mod - 2);
}

bool a[M][M];
int n, m;

void sbt(int from, int what) {
  for (int i = 0; i < m; ++i)
    a[from][i] ^= a[what][i];
}

void swp(int x, int y) {
  for (int i = 0; i < m; ++i)
    swap(a[x][i], a[y][i]);
}

void read() {
  cin >> n >> m;

  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      int x;
      cin >> x;
      a[i][j] = x == 1;
    }
}

void kill() {
  int rank = 0;
  for (int i = 0; i < m; ++i) {
    int x = -1;
    for (int j = rank; j < n; ++j)
      if (a[j][i])
        x = j;
    if (x != -1) {
      swp(x, rank);
      ++rank;
      for (int j = rank; j < n; ++j)
        if (a[j][i])
          sbt(j, rank - 1);
    }
  }

  int ans = sub(bin(2, n), bin(2, n - rank));
  ans = mul(ans, bin(2, m - 1));

  cout << ans << "\n";
}

int main() {
#ifdef LOCAL
  assert(freopen("e.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  read();
  kill();

}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
/*
  1
4 2 3 5
  6
*/
class Dice {
private:
  int s[6];
public:
  Dice();
  Dice(int t[6]);
  int get(int pos);
  void set(int pos, int x);
  void move(char dir);
  bool operator==(Dice d);
  bool eq(Dice d);
};

Dice::Dice() {
  for (int i = 0; i < 6; i++) {
    s[i] = 0;
  }
}

Dice::Dice(int t[6]) {
  for (int i = 0; i < 6; i++) {
    s[i] = t[i];
  }
}

int Dice::get(int pos) {
  return s[pos];
}

void Dice::set(int pos, int x) {
  s[pos] = x;
}

bool Dice::operator==(Dice d) {
  for (int i = 0; i < 6; i++) {
    if (s[i] != d.get(i)) {
      return false;
    }
  }
  return true;
}

bool Dice::eq(Dice d) {
  for (int i = 0; i < 4; i++) {
    d.move('W');
    for (int j = 0; j < 4; j++) {
      d.move('N');
      for (int k = 0; k < 4; k++) {
        d.move('W');
        if (*this == d) {
          return true;
        }
      }
    }
  }
  return false;
}

void Dice::move(char dir) {
  int t;
  switch (dir) {
    case 'N': {
      t = s[0];
      s[0] = s[1];
      s[1] = s[5];
      s[5] = s[4];
      s[4] = t;
      break;
    }
    case 'E': {
      t = s[3];
      s[3] = s[5];
      s[5] = s[2];
      s[2] = s[0];
      s[0] = t;
      break;
    }
    case 'W': {
      t = s[0];
      s[0] = s[2];
      s[2] = s[5];
      s[5] = s[3];
      s[3] = t;
      break;
    }
    case 'S': {
      t = s[4];
      s[4] = s[5];
      s[5] = s[1];
      s[1] = s[0];
      s[0] = t;
      break;
    }
  }
}

int main() {
  bool f = false;
  int n, t;
  Dice *d;
  vector<Dice> ds;

  cin >> n;
  for (int i = 0; i < n; i++) {
    d = new Dice;
    for (int j = 0; j < 6; j++) {
      cin >> t;
      d->set(j, t);
    }
    ds.push_back(*d);
  }

  for (int i = 0; i < n; i++) {
    for (int j = n - 1; i < j; j--) {
      if (ds[i].eq(ds[j])) {
        f = true;
        goto end;
      }
    }
  }

  end:
  if (f) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}

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

using Int = long long;
using ll = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

template<typename T> void drop(T x){cout<<x<<endl;exit(0);};

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

  ll s,t,p,q,m,y;
  cin>>s>>t>>p>>q>>m>>y;

  cout<<(t^s^y)<<endl;
  return 0;
}



Measured memory_bytes: 3196
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

struct {
  int MAXN; vector<ll> bit;

  void init(int n) {
    MAXN = n;
    bit.resize(n+1);
  }

  // update bit[j] (j >= i > 0) with max(bit[j], x)
  void update(int i, ll x) {
    while (i <= MAXN) {
      bit.at(i) = max(bit.at(i), x);
      i += i & -i;
    }
  }

  void reset() {
    bit.assign(MAXN+1, 0LL);
  }

  // get max bit[j] (0 <= j <= i)
  ll getmax(int i) {
    ll s = 0;
    while (i>0) {
      s = max(bit.at(i), s);
      i -= i & -i;
    }
    return s;
  }
} B;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  vector<int> h(n); rep(i, n) cin >> h[i];
  vector<int> a(n); rep(i, n) cin >> a[i];

  B.init(n);
  rep(i, n) {
    ll x = B.getmax(h[i]);
    x += a[i];
    B.update(h[i], x);
  }
  cout << B.getmax(n) << endl;
}


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

vector<ll> divisor(ll n)
{
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end()); // 昇順に並べる
  return ret;
}

//繰り返し自乗法(modなし)
ll mypow(ll x, ll n){
  if(n == 0)
    return 1;
 
  if(n % 2 == 0)
    return mypow(x * x, n / 2);
  else
    return x * mypow(x, n - 1);
}


int main() {
  ll x;
  cin >> x;
  for (int i = -1000; i <= 1000; i++){
    for (int j = -1000; j <= 1000; j++) {
      ll tmp = mypow(i,5) - mypow(j,5);
      if(tmp == x){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3492
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i)

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

char S[222222], T[222222];

int main() {
  // ios_base::sync_with_stdio(0);

  int H, W, N, x, y;
  scanf("%d%d%d%d%d%s%s", &H, &W, &N, &y, &x, S, T);
  --x, --y;

  int left = 0, right = W, top = 0, bottom = H;
  bool ok = true;
  FORD(i,N,0) {
    if (T[i] == 'D') top = max(0, top-1);
    else if (T[i] == 'U') bottom = min(H, bottom+1);
    else if (T[i] == 'L') right = min(W,right+1);
    else if (T[i] == 'R') left = max(0, left-1);

    if (S[i] == 'D') --bottom;
    else if (S[i] == 'U') ++top;
    else if (S[i] == 'L') ++left;
    else if (S[i] == 'R') --right;
    if (left >= right || top >= bottom) ok = false;
  }

  ok = ok && left <= x && x < right && top <= y && y < bottom;
  printf(ok ? "YES\n" : "NO\n");
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 100005
#define ll signed long long int
using namespace std;


signed main()
{
    FAST;
    ll n, m;
    cin >> n >> m;
    if(n == m){
    	cout << "Yes";
    	return 0;
	}
	cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <stack>
using namespace std;
typedef long long int ll;

int main(){
	string s; cin >> s;
	bool a[26];
	bool b=true;
	for(int i=0;i<26;i++){
		a[i]=true;
	}
	for(int i=0;i<s.size();i++){
		if(a[s[i]-'a']){
			a[s[i]-'a']=false;
		}
		else{
			while(a[s[i]-'a']==false){
				s[i]++;
				if(s[i]>'z')break;
			}
			if(s[i]>'z'){
				cout << -1 << endl;
				return 0;
			}
			b=false;
			a[s[i]-'a']=false;
		}
	}
	if(b){
		for(int i=0;i<26;i++){
			if(a[i]){
				s+='a'+i;
				b=false;
				break;
			}
		}
	}
	if(b){
		int id=-1;
		for(int i=s.size()-2;i>=0;i--){
			if(s[i]<s[i+1]){
				id=i;
				break;
			}
		}
		if(id==-1){
			cout << -1 << endl;
			return 0;
		}
		else{
			string t=s.substr(0,id);
			int id2=id+1;
			for(int i=id2;i<s.size();i++){
				if(s[i]<s[id2]&&s[i]>s[id]){
					id2=i;
				}
			}
			t+=s[id2];
			cout << t << endl;
			return 0;
		}
	}
	if(b){
		cout << -1 << endl;
		return 0;
	}
	cout << s << endl;
}

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

int main() {
  string S,T;
  cin >> S >> T;
  int counter=0;
  for (int i=0; i<S.size(); i++){
    if (S.at(i) != T.at(i)){
      counter++;
    }
  }
  cout << counter <<endl;
}


Measured memory_bytes: 3824
import collections
import math


class Solution:
    def solve(self, A, B):
        for i in range(10**4):
            aTax, bTax = math.floor(i*0.08), math.floor(i * 0.1)

            if aTax == A and bTax == B:
                return i

        return -1


sol = Solution()

[A, B] = list(map(int, input().strip().split()))
print(sol.solve(A, B))


Measured memory_bytes: 3316
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 1e6+10;
char s[N],t[N];
int f[222],n,cnt;
void solve(int x, int y) {
	REP(i,1,cnt) {
		if (s[i]==x) s[i]=y;
		else if (s[i]==y) s[i]=x;
	}
}

int main() {
	scanf("%s%s", s+1, t+1);
	n = strlen(s+1);
	REP(i,1,n) {
		if (f[s[i]]&&f[s[i]]!=t[i]) return puts("No"),0;
		f[s[i]] = t[i];
	}
	REP(i,'a','z') if (f[i]) { 
		s[++cnt]=i;
		t[cnt]=f[i];
	}
	REP(i,1,cnt) if (s[i]!=t[i]) solve(s[i],t[i]);
	REP(i,1,cnt) if (s[i]!=t[i]) return puts("No"),0;
	puts("Yes");
}









Measured memory_bytes: 640
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(c-(a-b), 0) << endl;
	return 0;
}

Measured memory_bytes: 256
//mangesh2102000

#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int 
#define ld long double
#define pb push_back
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define F first
#define S second
#define mod 1000000007

int n,k;
int a[105];

int dp[105][100005];
int pf[105][100005];

void solve(int t)
{
    cin >> n >> k;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }

    for(int i=0;i<=n;i++)
        dp[i][0] = pf[i][0] = 1;

    for(int i=0;i<=k;i++)
        pf[0][i] = 1;

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(j-a[i]-1 >= 0)
            {
                dp[i][j] = (pf[i-1][j] - pf[i-1][j-a[i]-1]) % mod;
                if(dp[i][j] < 0)
                    dp[i][j] += mod;
            }
            else
            {
                dp[i][j] = pf[i-1][j] % mod;
                if(dp[i][j] < 0)
                    dp[i][j] += mod;   
            }

            pf[i][j] = (pf[i][j-1] + dp[i][j]) % mod;
            if(pf[i][j] < 0)
                pf[i][j] += mod;
        }
    }

    cout << dp[n][k];
    //cout << "Case #" << t << ": ";    
}   


int32_t main()
{
    IOS;
    int t;
    t=1;
    for(int i=1;i<=t;i++)
    {
        solve(i);
    }

    return 0;
}

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

int main(){
    
    // 1. 入力情報.
    int N, K;
    scanf("%d %d", &N, &K);
    
    // 2. 差が1の整数を, ともに選ばないように選べる個数.
    int count = N / 2;
    if(N & 1) count++;
    
    // 3. 出力
    if(count >= K) printf("%s\n", "YES");
    else           printf("%s\n", "NO");
    return 0;
    
}

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

 int q;

 int lcs(char X[],char Y[]){
       int m,n,i,j,C[1001][1001],maxl=0;
       m=strlen(X);
       n=strlen(Y);

       for(i=0;i<=m;i++){C[i][0]=0;}
       for(j=0;j<=n;j++){C[0][j]=0;}

       for(i=1;i<=m;i++){
               for(j=1;j<=n;j++){
                         if(X[i-1]==Y[j-1]){C[i][j]=C[i-1][j-1]+1;}
                         else C[i][j]=(C[i][j-1]>=C[i-1][j]?C[i][j-1]:C[i-1][j]);
                         maxl=(maxl>C[i][j]?maxl:C[i][j]);
                         }
               }
       return maxl;
       }
       

 int main(){
       int i,q,ans;
       char X[1001];
       char Y[1001];
       scanf("%d",&q);
       for(i=0;i<q;i++){
                scanf("%s",&X);
                scanf("%s",&Y);
                printf("%d\n",lcs(X,Y));
                }
       return 0;
       }



Measured memory_bytes: 5664