akhauriyash/Code-Regression huggingface dataset:
#include<iostream>  
#include<vector>  
#include<string>  
#include<math.h>  
#include<algorithm>  
#include<cstring>//memset needs this head  

//一个方向可以走8000部，正反两个方向可以走的范围16000+1 
using namespace std;  
int canReach[2][16001];  
bool DP(vector<int> v,int t,int start){//v is the step vector of each axis  
    memset(canReach,0,sizeof(canReach));  
        canReach[0][8000+start]=1;//the initial place  
    if(v.size()==0)  
        return canReach[0][8000+t];  
    int i;  
    for(i=1;i<=v.size();i++){  
        for(int j=0;j<=16000;j++){  
            canReach[i%2][j]=((j+v[i-1])>16000?0:canReach[(i-1)%2][j+v[i-1]])||((j-v[i-1])<0?0:canReach[(i-1)%2][j-v[i-1]]);  
        }  
    }  
    return canReach[(i-1)%2][8000+t];  
}  
int main(){  
    string S;  
    int tx,ty;  
    cin>>S>>tx>>ty;  
    bool whichAxis=0;//the initial axis is x,1 is y;  
    vector<int> vx;  
    vector<int> vy;  
    int count=0;  
    int len=S.size();
    char c;
    //计算每次转方向时走的步数 
	for(int i=0; i<len; i++){//auto c:S  
		c=S[i];
        if(c=='T'){  
            ((whichAxis==0)?vx:vy).push_back(count);  
            count=0;  
            whichAxis=!whichAxis;  
        }  
        else{  
            count++;  
        }  
    }  
    ((whichAxis==0)?vx:vy).push_back(count);//that is important,the last several T's  
   // tx-=vx[0];//the first several step in x have decided direction.That is an error  
    int start=vx[0];  
    vx.erase(vx.begin());  
    if(DP(vx,tx,start)&&DP(vy,ty,0))  
        cout<<"Yes"<<endl;  
    else  
        cout<<"No"<<endl;  
    return 0;  
  
}  

Measured memory_bytes: 512
#include <iostream>
#include<algorithm>
using namespace std;

typedef long long ll;


const int MOD = 1e9 + 7;
const int N = 2e5 + 105;

ll qpower(ll a, ll b){
    ll ans = 1;
    while(b){
        if(b & 1) ans = ans * a %MOD;
        a = a * a %MOD;
        b >>= 1;
    }
    return ans;
}
int main(){
    ll n;
    cin >> n;
    if(n == 1){
        cout << 0 << endl;
    }else{
        cout << (qpower(10, n) - (qpower(9, n) + qpower(9, n) - qpower(8, n)) + MOD + MOD + MOD + MOD + MOD) % MOD << endl;
    }
}


Measured memory_bytes: 3168
n = int(input())
A = list(map(int, input().split()))

cnt_even, cnt_odd = 0, 0
for i in range(n):
	if A[i] % 2 == 0:
		cnt_even += 1
	else:
		cnt_odd += 1

cnt = 3 ** n - (2 ** (cnt_even))
print(cnt)

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

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

	int H,W,K;
	int i,k;
	int ans=0;
	int ctr=0;

	cin >> H >> W >> K;

	vector<vector<char>> gv(H,vector<char>(W,0));

	rep(y,H)rep(x,W){
		cin >> gv[y][x];
	}

	for(int bitx=0;bitx<(1<<W);bitx++){
		for(int bity=0;bity<(1<<H);bity++){
			ctr=0;
			for(int x=0;x<W;x++){
				if(bitx>>x & 1) continue;
				for(int y=0;y<H;y++){
					if(bity>>y & 1) continue;
					if(gv[y][x]=='#') ctr++;
				}
			}
			if(ctr==K) ans++;
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3652
# abc116 B
s = gets.to_i

u = Array.new(1000000, false)
u[s] = true
1000000.times do |i|
  s = s.even? ? s/2 : s*3+1
  if u[s]
    p i+2
    exit
  else
    u[s] = true
  end
end


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

int main(){
  int n;
  cin >> n;
  int h[n];
  rep(i,n)cin >> h[i];

  string ans="Yes";
  for(int i=n-1;i>1;i--){
    if(h[i]<h[i-1])
      if(h[i]<h[i-1]-1){
	ans="No";
	break;
      }else h[i-1]--;
  }
  cout << ans << endl;
}


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

using namespace std;

#define reps(i, n, m) for (int i = (int) (n); i < (int) (m); i++)

int n;

vector<int> solve(const string& s) {
  vector<int> res(n);
  int cnt = 1;
  reps(i, 1, n) {
    if (s[i] == 'R') cnt++;
    else {
      res[i] += cnt / 2;
      res[i-1] += cnt - cnt / 2;
      cnt = 0;
    }
  }
  return res;
}

int main() {
  string s;
  cin >> s;
  n = s.size();
  vector<int> l = solve(s);
  reverse(s.begin(), s.end());
  for (auto& c : s) c = 'R' - c + 'L';
  vector<int> r = solve(s);
  reps(i, 0, n) {
    if (i) cout << " ";
    cout << l[i] + r[n-1-i];
  }
  cout << endl;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n,m;
  cin >> n >> m ;
  vector<vector<char>> A(n,vector<char> (n));
  vector<vector<char>> B(n,vector<char> (m));
  string ans = "No" ;
  
  rep(i,n){
    rep(j,n){
      cin >> A.at(i).at(j) ;
    }
  }
  
  rep(i,m){
    rep(j,m){
      cin >> B.at(i).at(j);
    }
  }
  

  
  rep(i,n-m+1){
    rep(j,n-m+1){
      bool OK = true ;
      rep(k,m){
        rep(l,m){
          if(A.at(i+k).at(j+l) != B.at(k).at(l)) OK = false ;
        }
      }
      if(OK){
        ans = "Yes";
        break;
      }
    }
  }
       
      
  cout << ans ;
  
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    int ans = INF;
    for (int i = 0; i <= n - k; i++)
    {
        int l = x[i], r = x[i + k - 1];
        int tmp = INF;
        if (l < 0 && r < 0)
        {
            tmp = -l;
        }
        else if (l >= 0 && r >= 0)
        {
            tmp = r;
        }
        else
        {
            tmp = -l + r + min(-l, r);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template<typename T, typename E>
struct SkewHeap{
  typedef function<T(T, E)> F;
  typedef function<E(E, E)> G;
  typedef function<bool(T,T)> C;
  F f;
  G g;
  C c;
  E e;
  SkewHeap(F f,G g,C c,E e):f(f),g(g),c(c),e(e){}

  struct Node{
    Node *l,*r;
    T val;
    E add;
    Node(T val,E add):val(val),add(add){l=r=NULL;}
  };

  void eval(Node *a){
    if(a->add==e) return;
    if(a->l) a->l->add=g(a->l->add,a->add);
    if(a->r) a->r->add=g(a->r->add,a->add);
    a->val=f(a->val,a->add);
    a->add=e;
  }
  
  T top(Node *a){
    return f(a->val,a->add);
  }
  
  Node* push(T v){
    return new Node(v,e);
  }
  
  Node* meld(Node *a,Node *b){
    if(!a) return b;
    if(!b) return a;
    if(c(top(a),top(b))) swap(a,b);
    eval(a);
    a->r=meld(a->r,b);
    swap(a->l,a->r);
    return a;
  }
  
  Node* pop(Node* a){
    eval(a);
    auto res=meld(a->l,a->r);
    free(a);
    return res;
  }
  
};
//END CUT HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  using Heap=SkewHeap<int, int>;
  Heap::F f=[](int a,int b){return a+b;};
  Heap::G g=[](int a,int b){return a+b;};
  Heap::C c=[](int a,int b){return a<b;};

  Heap heap(f,g,c,0);
  auto base=heap.push(0);
  
  string s;
  while(cin>>s,s!="end"){
    int x;
    if(s=="insert"){
      cin>>x;
      auto v=heap.push(x);
      base=heap.meld(base,v);
    }
    if(s=="extract"){
      x=heap.top(base);
      base=heap.pop(base);
      cout<<x<<endl;
    }
  }
  return 0;
}
/*
  verified on 2018/01/04
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_9_C&lang=jp
*/



Measured memory_bytes: 34352
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=int_fast64_t;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double EPS=1e-9;
const int MOD=1e9+7;
struct edge{int to;ll cost;};
int main(){
    int N,M;cin>>N>>M;
    int S,T;cin>>S>>T;--S;--T;
    int U,V;cin>>U>>V;--U;--V;
    vector<vector<edge>> G(N),nG(N);
    for(int i=0;i<M;i++){
        int a,b;ll c;cin>>a>>b>>c;--a;--b;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    vector<ll> ds(N,LINF),dt(N,LINF),du(N,LINF),dv(N,LINF);
    ds[S]=0,dt[T]=0,du[U]=0,dv[V]=0;
    priority_queue<P,vector<P>,greater<P>> q;
    q.push(P(0,S));
    while(!q.empty()){
        int v=q.top().second;q.pop();
        for(auto e:G[v]){
            if(ds[e.to]<=ds[v]+e.cost)continue;
            ds[e.to]=ds[v]+e.cost;
            q.push(P(ds[e.to],e.to));
        }
    }
    q.push(P(0,T));
    while(!q.empty()){
        int v=q.top().second;q.pop();
        for(auto e:G[v]){
            if(dt[e.to]<=dt[v]+e.cost)continue;
            dt[e.to]=dt[v]+e.cost;
            q.push(P(dt[e.to],e.to));
        }
    }
    q.push(P(0,U));
    while(!q.empty()){
        int v=q.top().second;q.pop();
        for(auto e:G[v]){
            if(du[e.to]<=du[v]+e.cost)continue;
            du[e.to]=du[v]+e.cost;
            q.push(P(du[e.to],e.to));
        }
    }
    q.push(P(0,V));
    while(!q.empty()){
        int v=q.top().second;q.pop();
        for(auto e:G[v]){
            if(dv[e.to]<=dv[v]+e.cost)continue;
            dv[e.to]=dv[v]+e.cost;
            q.push(P(dv[e.to],e.to));
        }
    }
    vector<int> in(N),vs;
    for(int i=0;i<N;i++){
        for(auto e:G[i]){
            if(ds[i]+e.cost+dt[e.to]==ds[T]){
                nG[i].push_back(e);
                in[e.to]++;
            }
        }
    }
    stack<int> st;
    for(int i=0;i<N;i++){
        if(in[i]==0&&nG[i].size()){
            st.push(i);
        }
    }
    while(!st.empty()){
        int v=st.top();st.pop();
        vs.push_back(v);
        for(auto e:nG[v]){
            in[e.to]--;
            if(in[e.to]==0)st.push(e.to);
        }
    }
    ll ans=du[V];
    vector<P> dp(N,P(LINF,LINF));
    for(auto v:vs){
        dp[v].first=min(dp[v].first,du[v]);
        dp[v].second=min(dp[v].second,dv[v]);
        ans=min(ans,dp[v].first+dv[v]);
        ans=min(ans,dp[v].second+du[v]);
        for(auto e:nG[v]){
            dp[e.to].first=min(dp[e.to].first,dp[v].first);
            dp[e.to].second=min(dp[e.to].second,dp[v].second);
        }
    }
    cout<<ans<<endl;
}   


Measured memory_bytes: 28776
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 924844033;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	char memo = 'a';
	int chk = -1;char s; 
	per(i, 10) {
		int t = (int)pow(10, i);
		cout << "? " << t << endl;
		cin >> s;
		if (memo == 'a') {
			memo = s;
		}
		else {
			if (memo != s) {
				chk = i; break;
			}
		}
	}
	if (chk == -1) {
		rep(i, 11) {
			cout << "? " << 2 * (ll)pow(10, i) << endl;
			cin >> s;
			if (s == 'Y') {
				cout << "! " << (ll)pow(10, i) << endl; break;
			}
		}
	}
	else {
		int now = 0;
		rep(i, chk) {
			now *= 10;
			cout << "? " <<now+5<< endl;
			cin >> s;
			if (s == 'Y') {
				cout << "? " << now + 7 << endl;
				cin >> s;
				if (s == 'Y') {
					cout << "? " << now + 8 << endl;
					cin >> s;
					if (s == 'Y') {
						cout << "? " << now + 9 << endl;
						cin >> s;
						if (s == 'Y') {
							now += 9;
						}
						else {
							now += 8;
						}
					}
					else {
						now += 7;
					}
				}
				else {
					cout << "? " << now + 6 << endl;
					cin >> s;
					if (s == 'Y') {
						now += 6;
					}
					else {
						now += 5;
					}
				}
			}
			else {
				cout << "? " << now + 3 << endl;
				cin >> s;
				if (s == 'Y') {
					cout << "? " << now + 4 << endl;
					cin >> s;
					if (s == 'Y') {
						now += 4;
					}
					else {
						now += 3;
					}
				}
				else {
					cout << "? " << now + 2 << endl;
					cin >> s;
					if (s == 'Y') {
						now += 2;
					}
					else {
						cout << "? " << now + 1 << endl;
						cin >> s;
						if (s == 'Y') {
							now += 1;
						}
					}
				}
			}
		}
		now *= 10;
		ll nex = (ll)10 * now;
		if (nex == 0) {
			Rep(j, 1, 10) {
				cout << "? " << nex + (ll)10 * j << endl;
				cin >> s;
				if (s == 'Y') {
					now += j; break;
				}
			}
		}
		else {
			rep(j, 10) {
				cout << "? " << nex + (ll)10 * j << endl;
				cin >> s;
				if (s == 'Y') {
					now += j; break;
				}
			}
		}
		cout << "! " << now << endl;
	}
	return 0;
}

Measured memory_bytes: 716
#include <iostream>
#include <cmath>
using namespace std;

int max_exp(int n, int x){
    int max_sub, y;
    max_sub = 0;
    for(int i=2;; i++){
        y = pow(n, i);
        if(y > x){
            break;
        }
        max_sub = max(max_sub, y);
    }
    return max_sub;
}
int main(){
    int x, n, max_x, max_sub;
    cin >> x;
    n = 2;
    if(x == 1){
        cout << "1" << endl;
        return 0;
    }
    max_x = 0;
    while(n < x){
        max_sub = max_exp(n, x);
        max_x = max(max_x, max_sub);
        n++;
    }
    cout << max_x << endl;
    return 0;
}

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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

int N, M;
int S, T;
vector<int> G[100010];
int dist[100010][3] = {0};

int main()
{
    cin >> N >> M;
    for(int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
    }
    cin >> S >> T;

    priority_queue<pipii, vector<pipii>, greater<pipii> > Q;
    Q.push(mk(1, mk(S, 0)));
    while(Q.size())
    {
        pipii now = Q.top();
        Q.pop();
        int d = now.fi;
        int v = now.se.fi;
        int s = now.se.se;
        if(dist[v][s] == 0)dist[v][s] = d;
        else continue;

        for(int i = 0; i < G[v].size(); i++)
        {
            int n = G[v][i];
            Q.push(mk(d + 1, mk(n, (s + 1) % 3)));
        }
    }

    if(dist[T][0] == 0)cout << -1 << endl;
    else cout << (dist[T][0] - 1) / 3 << endl;

    return 0;
}


Measured memory_bytes: 7412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 1e5+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,0,sizeof(head));}
struct EDGE{int to,nxt,val;}ee[M*2];
void add(int x,int y){ee[++cnt].nxt=head[x],ee[cnt].to=y,head[x]=cnt;}
*/
 
char s[M];
struct na{
	int x,y;
	bool operator <(const na &r)const
	{
		return y<r.y;
	}
};
struct nb{
	int x,y;
	bool operator <(const nb &r)const
	{
		return x>r.x;
	}
};
vector<na>va;
vector<nb>vb;
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int n;
  	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		int l=strlen(s);
		int a=0,b=0;
		for(int j=0;j<l;j++)
		{
			if(s[j]=='(')a++;
			else
			{
				if(a)a--;
				else b++;
			}
		}
		//这里a的意思是需要在这个字符串后面补多少右括号，b是需要在其前面补多少左括号 
	 	//当a>b时，说明做左括号比右括号多，肯定优先放前面。显然，此时b越小在前面越优，因为需要在前面补左括号的个数就少了 
		//a<b时同理
	//	cout<<a<<" "<<b<<endl;
		if(a>=b)va.pb(na{a,b});
		else vb.pb(nb{a,b});
	} 
	sort(va.begin(),va.end());
	sort(vb.begin(),vb.end());
	bool f=true;
	int sm=0;
	for(int i=0;i<va.size();i++)
	{
		sm-=va[i].y;
		if(sm<0)f=false;//前面的左括号能否满足当前字符串的需要
		sm+=va[i].x;//当前字符串所能提供的左括号
		//肯定是左括号需求量少的在前面 
	}
	for(int i=0;i<vb.size();i++)
	{
		sm-=vb[i].y;
		if(sm<0)f=false;
		sm+=vb[i].x;
		//右边肯定是对称的来考虑，即需求后面右括号少的放在最右边 
	}
	if(sm!=0)f=false;
	if(f)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 11288
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 標準入力からデータを読み込む準備
Scanner sc = new Scanner(System.in);
// 2つの文字の固まりをそれぞれ整数値と想定して読み込む
int a = sc.nextInt();
int b = sc.nextInt();
int area = a*b/* ここを変えて面積を求めよう */;
int length = (a+b)*2 /* ここを変えて周囲の長さを求めよう */;
System.out.println(area + " " + length);
sc.close();
}
}


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

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int N;
	cin >> N;
	vector<int> s;
	int mins = 10000;
	int maxs = 0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		s.push_back(a);
		mins = min(a, mins);
		maxs = max(a, maxs);
	}
	int sum = 0;
	for (int i = 1; i <= maxs; i++) {
		int minss = -2000;
		for (int j = 0; j < N; j++) {
			if (s[j] >= i) {
				if (minss+1 != j) {
					sum++;
				}
				minss = j;
			}
		}
	}
	cout << sum;
}

Measured memory_bytes: 256
M,D =map(int,input().split())
count = 0
for i in range(M):
  for j in range(D-21):
    a = int((j+22)/10)
    b = (j+22) - (a*10)
    if a >=2 and b>=2 and i+1 == a * b:
      count += 1
print(count)

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

using namespace std;
#define taskname "TEST"
#define pb	push_back
typedef long double ld;
typedef long long ll;
const int maxn = 1e6;
int n , a[maxn] , dp[maxn] , k;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r"))
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
    cin >> n >> k;
    cin >> a[1];
    for(int i = 2 ; i <= n ; ++i)
    {
        cin >> a[i];
        dp[i] = 1e9;
        for(int j = 1 ; j <= k ; ++j)
            if(i > j)dp[i] = min(dp[i] , dp[i - j] + abs(a[i] - a[i - j]));
    }
    cout << dp[n];
}


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

int main() {
  int i, s, a;
  //int	N, H, h=0, i, s;
  string	S;
  // int	i, j, l, ll;
  // char b;
  //  int N, K, KK, x, s=0;
  cin >> S;
  for (i = s = 0; i < S.length(); i++) {
    if ( S[i] == '0' ) {
      a = i % 2;
    } else {
      a = 1 - (i % 2);
    }
    s += a;
  }
  // cout <<s << endl;
  if ( S.length() > 2 * s ) {
    cout << s;
  } else {
    cout << S.length() - s;
  }
  cout << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;

//ここから
void solve(){
  int r,g;
  cin>>r>>g;
  cout<<2*g-r;
}

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

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        boolean flag = true;

        if((1 <= A && A <= 9) && (1 <= B && B <= 9)) {
            System.out.println(A * B);
        } else {
            System.out.println(-1);
        }
        
    }
}

Measured memory_bytes: 23124
s = input()
s_l = list(s)

ans = 100
for l in set(s_l):#それぞれの文字列で行い、ansの最小値を記録
    tmp = 0
    score = 0
    for word in s:
        if l == word:
            score = max(score,tmp)
            tmp = 0
        else:
            tmp += 1
    score = max(score, tmp)
    ans = min(ans, score)

print(ans)

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

int main() {
   int x, y, z;
   cin >> x >> y >> z;

   cout << z << " " << x << " " << y << endl;
}

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

int main() {
  int N, sum=0;
  cin >> N;
  
  for (int i = 0; i<N; i++){
    int l,r;
    cin >> l >> r;
    sum += r-l+1;
  }
  
  cout << sum << endl;
 
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()

	c:=1
	for i:=0;i<N;i++{
		if c<K{
			c*=2
		}else{
			c+=K
		}
	}
	fmt.Println(c)


}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

int main(){
    int n;
    bool card[4][14] = {};
    
    cin >> n;
    for(int i = 0; i < n; i++){
        int rank;
        char pic;
        cin >> pic >> rank;
        switch(pic){
        case 'S': card[0][rank] = true; break;
        case 'H': card[1][rank] = true; break;
        case 'C': card[2][rank] = true; break;
        case 'D': card[3][rank] = true; break;
        }
    }
    
    for(int i = 0; i < 4; i++){
        char pic;
        switch(i){
        case 0: pic = 'S'; break;
        case 1: pic = 'H'; break;
        case 2: pic = 'C'; break;
        case 3: pic = 'D'; break;
        }
        for(int j = 1; j <= 13; j++){
            if(!card[i][j]){
                cout << pic << " " << j << endl;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;    
    string a;
    int i,ans=0,sum=0;
    cin>>n>>a;
    for(i=0;i<n;i++){
        if(a[i]=='D')ans--;
        else ans++;
        sum=max(ans,sum);
    }
    cout<<sum<<endl;
    return 0;
}

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

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

    int n=s.size();
    int memo=1000;
    int xxx;
    for(int i=0;i<n-2;i++){
        xxx=abs((s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0')-753);
        memo=min(memo,xxx);

    }
    
    cout<<memo<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(c >= a && c <= b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
vector<int> es[100010];

void solv() {
	
	int n,m;
	cin >> n >> m;
	for (size_t i = 0; i < m; i++)
	{
		int u,v;
		cin >> u >> v;
		es[u].push_back(v);
	}
	int s, t;
	cin >> s >> t;
	priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;
	q.push({ 0,2,s});

	int d[3][100010];
	memset(d, -1, sizeof(d));

	while (!q.empty())
	{
		auto v = q.top();
		q.pop();
		int cnt = v[0];
		int step = v[1];
		int f = v[2];
		if (d[step][f] != -1 && d[step][f] <= cnt) continue;
		d[step][f] = cnt;
		int nextcnt = step == 2 ? cnt + 1 : cnt;
		int nextstep = (step + 1) % 3;

		for (auto e : es[f]) {
			
			q.push({ nextcnt,nextstep,e,f });
		}
	}

	cout << d[2][t] << endl;

}

int main() {
	COMinit();
	solv();

	return 0;
}
 

Measured memory_bytes: 21296
#include <iostream>

int main() {
    uint32_t a, b, c;
    std::cin >> a >> b >> c;

    uint32_t count = 0;
    for (uint32_t i = a; i <= b; ++i) {
        if (c % i == 0) {
            ++count;
        }
    }

    std::cout << count << std::endl;
}


Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;

ll dp[100001];

int main(void){
    cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	vl h(n);
	rep(i,n){
	    cin>>h[i];
	    dp[i] = inf;
	}
	dp[0] = 0;
	rep(i,n){
	    rep1(j,k+1){
	        if(i+j<n) dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
	    }
	}
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int l,m,n;
  while(cin>>l&&l){
    for(i=0;i<12;i++){
      cin>>m>>n;
      l-=m-n;
      if(l<=0)
	break;
    }
    for(j=i+1;j<12;j++)
      cin>>m>>n;
    if(i==12)
      cout<<"NA"<<endl;
    else
      cout<<i+1<<endl;
  }
  return 0;
}
      

Measured memory_bytes: 0
import collections

h,w,k=map(int,input().split())
sy,sx,gy,gx=map(int,input().split())
sy,sx,gy,gx=sy-1,sx-1,gy-1,gx-1
board=[input() for _ in range(h)]
q=collections.deque()
q.append((sx,sy))
checked=[[0]*w for _ in range(h)]
checked[sy][sx]=1
cost=[[10**18]*w for _ in range(h)]
cost[sy][sx]=0
dx=[1,0,-1,0]
dy=[0,1,0,-1]
while len(q)!=0:
  x,y=q.popleft()
  c=cost[y][x]
  for i in range(4):
    for j in range(1,k+1):
      if x+j*dx[i]<0 or w<=x+j*dx[i] or y+j*dy[i]<0 or h<=y+j*dy[i]:
        break
      if board[y+j*dy[i]][x+j*dx[i]]=='@':
        break
      if cost[y+j*dy[i]][x+j*dx[i]]<=c:
        break
      if cost[y+j*dy[i]][x+j*dx[i]]>c+1:
        q.append((x+j*dx[i],y+j*dy[i]))
        cost[y+j*dy[i]][x+j*dx[i]]=c+1
if cost[gy][gx]==10**18:
  print(-1)
else:
  print(cost[gy][gx])

Measured memory_bytes: 108404
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;

#define M 1046527
#define NIL (-1)
#define L 14
char H[M][L]; /* Hash Table */

//文字から対応する整数へ変換
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

size_t length(const std::string& str) {
    return str.length();
}


/* convert a string into an integer value */
//文字列から数値に変換してkeyを生成
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < length(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){
    return key % M;
}
int h2(int key){ 
    return 1 + (key % (M - 1));
}

//ダブルハッシュ
int find(char str[]){
    int key, h;
    key = getKey(str); //文字列を数値に変換
    for ( int i = 0; ; i++ ){
        h = (h1(key) + i*h2(key)) % M;
        if (strcmp(H[h], str) == 0) return 1; //文字列の比較
        else if (strlen(H[h] ) == 0) return 0;
    }
    return 0;
}

int insert(char str[]){
    int key, h;
    key = getKey(str); //文字列を数値に変換
    for(int i = 0; ; i++){
        h = (h1(key) + i*h2(key)) % M;
        if( strcmp(H[h], str) == 0 ) return 1;
        else if ( strlen(H[h]) == 0) {
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main(){
    int i, n;
    char str[L], com[9];
    for ( int i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	    scanf("%s %s", com, str);
	
	    if ( com[0] == 'i' ){
	        insert(str);
	    } else {
	        if (find(str)){
	    	printf("yes\n");
	        } else {
	    	printf("no\n");
	        }
	    }
    }

    return 0;
}



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

#define int long long

const int MAX_DIGIT = 50;
int dp[100][2]; // dp[i][j]: 上からi桁目までみたとき、jはi桁目までで確定してるかどうか

signed main() {
  int N, K;
  cin >> N >> K;

  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  fill(dp[0], dp[100], -1);
  dp[MAX_DIGIT][0] = 0; // 初期状態。上位桁から決めていき、最初はマスク値がK以下か確定していない状態

  for (int digit = MAX_DIGIT-1; digit >= 0; digit--) {
    int mask = 1LL << digit; // 上からdigit桁目を立てたマスク

    // Aでもともと上からdigit桁目にビットが立っているものの個数
    int num = 0;
    for (int i = 0; i < N; i++) {
      if (A[i] & mask) {
        num++;
      }
    }

    // マスク値の上からdigit桁目を0, 1にしたときのスコア
    int score0 = mask * num; // 上からdigit桁目のマスクビットを立てない時のスコア
    int score1 = mask * (N - num); // 上からdigit桁目のマスクビットを立てる時のスコア

    // 1 -> 1(マスク値がK以下に確定した状態 -> マスク値がK以下に確定した状態）
    // マスク値がK以下であることは確定しているので、上からdigit桁以降のビットは立てても立てなくても良い
    // なので、ビットを立てたときと立ててないときのスコアの大きい方を採用する
    if (dp[digit+1][1] != -1) {
      dp[digit][1] = max(dp[digit][1], max(dp[digit+1][1] + score0, dp[digit+1][1] + score1));
    }

    // 0 -> 1(マスク値がK以下に確定していない状態 -> マスク値がK以下に確定した状態)
    // Kの立っている上からdigit桁目を引っ込めることでマスク値がK以下に確定する。なのでscore0を採用する
    if (dp[digit+1][0] != 1) {
      if (K & mask) { // Kの上からdigit桁目が立っていたら引っ込める
        dp[digit][1] = max(dp[digit][1], dp[digit+1][0] + score0);
      }
    }

    // 0 -> 0(マスク値がK以下に確定していない状態 -> マスク値がK以下に確定していない状態)
    // Kの上からdigit桁目をそのままにするということ
    // なので、Kの上からdigit桁目が0ならscore0を採用し、 Kの上からdigit桁目が1ならscore1を採用する
    if (dp[digit+1][0] != -1) {
      if (K & mask) { // Kの上からdigit桁目が立ってる
        dp[digit][0] = max(dp[digit][0], dp[digit+1][0] + score1);
      } else { // Kの上からdigit桁目が立ってない
        dp[digit][0] = max(dp[digit][0], dp[digit+1][0] + score0);
      }
    }
  }

  // dp[0][1]: K以下のマスク値を使った時の最大値
  // dp[0][0]: マスク値Kを使った時の最大値
  cout << max(dp[0][1], dp[0][0]) << endl;

  return 0;
}


Measured memory_bytes: 1024
from collections import deque
def color_available(unavailable, K):
    idx = 0
    L = len(unavailable)
    unavailable = sorted(unavailable)
    for color in range(K):
        if idx < L and color == unavailable[idx]:
            idx += 1
        else:
            yield color

def bfs(graph, N, K, start):
    colors = [dict() for _ in range(N)]
    visited = [0] * N
    visited[start] = 1
    que = deque([start])
    while que:
        node = que.popleft()
        gen = color_available(colors[node].values(), K)
        color = 1
        for n in graph[node]:
            if not visited[n]:
                visited[n] = 1
                color = next(gen)
                colors[node][n] = color
                colors[n][node] = color
                que.append(n)
    return colors

N = int(input())
graph = [[] for _ in range(N)]
inputs = tuple(tuple(map(lambda n: int(n) - 1, input().split())) for _ in range(N - 1))
counts = [0] * N
for i, j in inputs:
    graph[i].append(j)
    graph[j].append(i)
    counts[i] += 1
    counts[j] += 1
K = max(counts)
colors = bfs(graph, N, K, 0)
print(K)
for i, j in inputs:
    print(colors[i][j] + 1)

Measured memory_bytes: 62136
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

ll gcd(ll a, ll b) {
  if (a < b) {
    swap(a, b);
  }
  int mod;
  mod = a % b;
  if (mod == 0) {
    return b;
  }
  a = b;
  b = mod;
  return gcd(a, b);
}

ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll len = b - a + 1;
    ll div1, div2, div3;
    div1 = b / c - (a - 1) / c;
    div2 = b / d - (a - 1) / d;
    div3 = b / lcm(c, d) - (a - 1) / lcm(c, d);
    ll ans = len - div1 - div2 + div3;
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
constexpr int MX = 100005;
int n, k, r[3], s, p, sc[MX][3], ans;
char t[MX], v[] = "spr";
int main(){
	scanf("%d%d%d%d%d\n%s", &n, &k, r, r+1, r+2, t);
	rep(i,n) rep(j,3) sc[i][j] = (i<k ? 0 : max(sc[i-k][(j+1)%3], sc[i-k][(j+2)%3])) + (t[i] == v[j] ? r[j] : 0);
	for(int i=max(0,n-k); i<n; i++) ans += max({sc[i][0],sc[i][1],sc[i][2]});
	printf("%d\n", ans);
}

Measured memory_bytes: 1536
import collections

n = int(input())
a = input()
b = input()
c = input()
#print(c[1])
ans = 0
for i in range(n):
    l = [a[i],b[i],c[i]]
    #print(l)
    ct = collections.Counter(l)
    #print(len(ct))
    ans += len(ct)-1
    
print(ans)

Measured memory_bytes: 3316
n = gets.to_i
arr=gets.split(' ').map &:to_i

e=Hash.new(0)
o=Hash.new(0)
arr.each_with_index do |a,i|
  e[a] += 1 if i%2==0
  o[a] += 1 if i%2==1
end
ee=e.sort_by {|_,v| -v}
oo=o.sort_by {|_,v| -v}

ans = if ee.first[0] != oo.first[0]
  n - ee[0].last - oo[0].last
else
  [
    n - ee[0].last - (oo.size > 1 ? oo[1].last : 0),
    n - (ee.size > 1 ? ee[1].last : 0 ) - oo[0].last
  ].min
end
puts ans

Measured memory_bytes: 20472
import numpy as np
n,w = map(int, input().split())

items = list(map(int, input().split()) for _ in [0]*n)
dp = np.zeros(w+1, dtype='int64')

for weight, value in items:
    dp[weight:] = np.maximum(dp[weight:], dp[:w-weight+1] + value)
print(dp.max())


Measured memory_bytes: 20656
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int x,k;
    cin >> x >> k;
    int s[k+1];
    rep(i,k)cin >> s[i];
    s[k] = 1001001001;
    int q;
    cin >> q;
    int t[q],a[q];
    rep(i,q)cin >> t[i] >> a[i];
    int ans[q];

    int ma = x;
    int mi = 0;
    int arg_ma = x;
    int arg_mi = 0;

    int i = 0;
    int j = 0;
    while(true){
        if(j == q)break;
        if(t[j] < s[i]){ // クエリ
            int dt = t[j];
            if(i>0)dt -= s[i-1];
            // cout << j << " : ";
            if(i % 2 == 0){ // Aが上
                if(a[j] <= arg_mi){
                    // cout << 'a';
                    ans[j] = max(0, mi - dt);
                }else if(arg_ma <= a[j]){
                    // cout << 'b';
                    ans[j] = max(0, ma - dt);
                }else{
                    // cout << 'c';
                    ans[j] = max(0, mi + (a[j] - arg_mi) - dt);
                }
            }else{ // Bが上
                if(a[j] <= arg_mi){
                    ans[j] = min(x, x - ma + dt);
                }else if(arg_ma <= a[j]){
                    ans[j] = min(x, x - mi + dt);
                }else{
                    ans[j] = min(x, x - ma + (a[j] - arg_mi) + dt);
                }
            }
            // cout << ans[j] << ' ' << i << endl;
            j++;
        }else{ // 時計をひっくり返す
            int dt = s[i];
            if(i>0)dt -= s[i-1];
            if(i % 2 == 0){ // arg_mi 上がる
                if(mi - dt < 0){
                    arg_mi += -(mi - dt);
                }
            }else{ // arg_ma 下がる
                if(mi - dt < 0){
                    arg_ma -= -(mi - dt);
                }
            }
            int ma_ = max(0, ma-dt);
            int mi_ = max(0, mi-dt);
            ma = x - mi_;
            mi = x - ma_;

            // cout << i << " : " << ma << ' ' << mi << ' ' << arg_ma << ' ' << arg_mi << endl;

            i++;
        }
    }

    rep(ite,q){
        cout << ans[ite] << endl;
    }

    return 0;
}
 
 


Measured memory_bytes: 2816
(function(stdin) {
    var lines = stdin.toString();
    var x = parseInt(lines);
    var h = Math.floor(x / 3600);
    var m = Math.floor(x % 3600 /60);
    var s = x%60;
    console.log(h+':'+m+':'+s);
 }(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

int wa(int n){
    int sum = 0;
    while (n > 0) { // n が 0 になるまで
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int N, A, B;
    cin>> N >> A >> B;
    int ans=0;
    for(int i=1; i<=N; i++){
        int sum=wa(i);
        if(sum>=A && sum<=B) ans+=i;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  long long N = input();
  vector<long long> A;
  for(long long i=0;i<N;i++){
    long long a = input();
    A.push_back(a);
  }
  const long long bitNum = 62;
  vector<long long> res;
  for(long long i=0;i<bitNum;i++){
    long long count1 = 0;
    long long count0 = 0;
    for(auto iter:A){
      if (iter & ((long long)1<<i)){
        count1++;
      }
      else{
        count0++;
      }

    }
    res.push_back(count1*count0);
  }
  long long ret = 0;
  const long long l = pow(10,9)+7;
  for(long long i=0;i<res.size();i++){
    long long l1 = res[i]%l;
    long long l2 = ((long long)1<<i)%l;
    long long a = l1 * l2;
    ret += a%l;
  }
  output(ret%l);

  return 0;
}

Measured memory_bytes: 6512
#include <stdio.h>

void trace(int A[], int N){
    int i;
    for (i = 0; i< N; i++) {
        if (i>0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}

void insertionSort(int A[],int N) {
    int j, i, v;
    for (i = 1; i<N; i++){
        v = A[i];
        j = i-1;
        while(j>=0 && A[j] >v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A,N);
    }
}

int main(){
    int N,i,j;
    int A[100];
    
    scanf("%d",&N);
    for (i=0; i < N; i++) scanf("%d", &A[i]);
    trace(A,N);
    insertionSort(A, N);
    
    return 0;
}


Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll a,v,b,w,t;
	cin>>a>>v>>b>>w>>t;
	if(v<=w)cout<<"NO";
	else{
		if(t*(v-w)>=abs(a-b))cout<<"YES";
		else cout<<"NO";
	}
	return 0;
}


Measured memory_bytes: 3592
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
long long n,a,b,c,d,e,x;
int main(){
	cin>>n>>a>>b>>c>>d>>e;
	x=min(min(min(min(a,b),c),d),e);
	cout<<(n+x-1)/x+4<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,k;
  string s;
  char c;
  cin >> n >> s >> k;
  c = s[k-1];
  for(int i=0;i<n;i++){
    if(c==s[i]) cout << s[i];
    else cout <<"*";
  }
  cout << "\n";
}


Measured memory_bytes: 256
N,D = map(int,input().split())
x = [[int(i) for i in input().split()] for i in range(N)]
count = 0
for i in range(N-1):
    for j in range(i+1,N):
        list_c = [(x2-x1)**2 for (x2,x1) in zip(x[j],x[i])]
        a=sum(list_c)**0.5
        if a.is_integer() == True:
            count += 1
print(count)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
namespace AOJ
{

    class Program
    {
        static void Main(string[] args)
        {
            int r = int.Parse(Console.ReadLine());
            while (r--!=0)
            {
                string str = Console.ReadLine();
                var arr = str.ToCharArray();
                
                int max = int.Parse(new string(arr.OrderByDescending(x=>x).ToArray()));
                int min = int.Parse(new string(arr.OrderBy(x=>x).ToArray()));
                Console.WriteLine(max - min);
            }
        }
    }
}

Measured memory_bytes: 6348
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
char chr;
int W,H,N;
int X[10001],Y[10001];
int main() {
	cin>>W>>H>>N;

	for(int i=0;i<N;i++){
		cin>>X[i]>>Y[i];
	}
	int S=0;
	int R=0;
	for(int i=0;i<N-1;i++){
		if((X[i]-X[i+1])*(Y[i]-Y[i+1])>=0)S=max(abs(X[i+1]-X[i]),abs(Y[i+1]-Y[i]));
		else S=abs(X[i+1]-X[i])+abs(Y[i+1]-Y[i]);

		R+=S;

	}


	cout<<R<<endl;
	return 0;
}

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

int main(){
    while(1){
        int N, A, B, C, X;
        cin >> N >> A >> B >> C >> X;
        if(N == 0) break;
        
        auto slot = [&](){ X = (A * X + B) % C; };
        
        auto frame = [&](int y){
            int t = 0;
            for(; y != X && t <= 10000; t++){
                slot();
            }
            return t;
        };
        
        int sum = 0;
        for(int i = 0; i < N; i++){
            int Y;
            cin >> Y;
            sum += frame(Y) + 1;
            slot();
        }
        sum -= 1;
        cout << (sum > 10000 ? -1 : sum) << endl;
    }
    return 0;
}

Measured memory_bytes: 1156