akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	using namespace std;
	typedef long double D;
	const D pi = atan(1.0) * 4;
	int n , m;
	int l , half;
	const int MAXN = 6e5 + 10;
	int rev[MAXN];
	class Complex{
	public:
		D re , im;
		Complex (){}
		Complex (D _r , D _i) : re(_r) , im(_i) {}
		Complex operator+ (Complex u){
			return Complex(re + u.re , im + u.im);
		}
		Complex operator* (Complex b){
			return Complex(re * b.re - im * b.im , re * b.im + im * b.re);
		}
		Complex operator* (D p){
			return Complex(re * p , im * p);
		}
		Complex operator- (Complex u){
			return Complex(re - u.re , im - u.im);
		}
		Complex operator/ (D p){
			return Complex(re / p , im / p);
		}
		Complex conj(){
			return Complex(re , -im);
		}
		void fft(Complex *b , Complex *wu){
			fft_core(b , wu);
		}
		void ifft(Complex *b , Complex *wu){
			fft_core(b , wu);
			
			for(int i = 0 ; i < l ; ++ i)
				b[i] = b[i] / l;
		}
		void get_rev(Complex *b){
			for(int i = 0 ; i < l ; ++ i)
				if(rev[i] > i)
					swap(b[i] , b[rev[i]]);
		}
		void fft_core(Complex *b , Complex *wu){
			get_rev(b);
			for(int k = 1 ; k < l ; k <<= 1)
				for(int i = 0 ; i < l ; i += (k << 1))
					for(int j = 0 ; j < k ; ++ j){
						Complex tmp1 = b[i + j] , tmp2 = b[i + j + k] * wu[k + j];
						b[i + j] = tmp1 + tmp2;
						b[i + j + k] = tmp1 - tmp2;
			}
		}
	};
	
	Complex wu1[MAXN] , wu2[MAXN];
	Complex a[MAXN] , b[MAXN] , c[MAXN];
	void init(){
		l = 1;
		while(l <= n + m)
			l <<= 1;
		
		rev[0] = 0;
		half = (l >> 1);
		for(int i = 1 ; i < l ; ++ i)
			rev[i] = ((rev[i >> 1] >> 1) | ((i & 1) ? half : 0));
		for(int i = half ; i < l ; ++ i)
			wu1[i] = Complex(cos(2 * pi * (i ^ half) / l) , sin(2 * pi * (i ^ half) / l));
		for(int i = half - 1 ; i >= 0 ; -- i)
			wu1[i] = wu1[i << 1];
		for(int i = 0 ; i < l ; ++ i)
			wu2[i] = wu1[i].conj();
	}
	
	const int MOD = 200003;
	int q[MAXN] , N;
	int w[MAXN] , g[MAXN];
	int fac[MAXN];
	int main(){
		ios::sync_with_stdio(false);
		int now = 1;
		for(int i = 0 ; i < MOD ; ++ i)
			q[i] = -1;
		for(int i = 0 ; i < MOD - 1 ; ++ i){
			q[now] = i;
			now = now * 2 % MOD;
		}
		fac[0] = 1;
		for(int i = 1 ; i < 2 * MOD ; ++ i)
			fac[i] = fac[i - 1] * 2 % MOD;
		cin >> N;
		long long ans = 0;
		for(int i = 1 ; i <= N ; ++ i){
			cin >> w[i];
			if(w[i] != 0)
				g[q[w[i]]] ++;
			ans -= 1ll * w[i] * w[i] % MOD;
		}
		n = MOD;
		m = MOD;
		for(int i = 0 ; i < MOD ; ++ i)
			b[i].re = a[i].re = g[i];
		init();
		Complex().fft(a , wu1);
		Complex().fft(b , wu1);
		for(int i = 0 ; i < l ; ++ i)
			c[i] = a[i] * b[i];
		Complex().ifft(c , wu2);
		for(int i = 0 ; i < 2 * MOD ; ++ i){
			long long x = (long long)(c[i].re + 0.5);
			ans = (ans + x * fac[i]);
		}
		cout << ans / 2 << endl;
		return 0;
	}

Measured memory_bytes: 91804
N = int(input())
S = list(input())

bl = [0] * (N+1)    # 左に黒が何個あるか
wr = [0] * (N+1)    # 右に白が何個あるか
for i in range(N): bl[i+1] = bl[i] + (1 if S[i] == '#' else 0)
for i in range(N-1,-1,-1): wr[i] = wr[i+1] + (1 if S[i] == '.' else 0)

ans = N+1
for i in range(N+1): ans = min(ans, bl[i]+wr[i])
print(ans)

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

int main() {
	int N;
	cin >> N;
  vector<ll> A(N);
	rep(i,N) cin >> A[i];
	map<int,int> mp;
	rep(i,N) mp[A[i]]++;
	for(auto e:mp){
		if(e.second >= 2){
			cout << "NO" << endl;
			return 0; 
		}
	}
	cout << "YES" << endl;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
const ll mod = 1e9 + 7;
const int inf = 1e9;

int main() {
	cin.sync_with_stdio(false);
	string S;
	cin >> S;
	ll ans = 0;
	rep(i, pow(2, S.size() - 1)){
		vector<bool>flag(S.size());
		int n = 0;
		int x = i;
		while (x >0) {
			flag[n] = x % 2;
			x /= 2;
			n++;
		}
		ll k = 1;
		rep(j, S.size()) {
			ans += (S[S.size() - 1 - j]-'0') * k;
			if (flag[j] == 0)k *= 10;
			else k = 1;
		}
	}
	cout << ans << "\n";
	
	return 0;
}

Measured memory_bytes: 256
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    ll a,b,n;
    cin>>a>>b>>n;
    cout<<(a*min(b-1,n)/b);
//    int n,m,q;
//    cin>>n>>m>>q;
//    pii p[15][15];
//    rep(i,1,10) rep(j,1,10) p[i][j]={-1,-1};
//    rep(i,1,q){
//        int a,b,c,d;
//        cin>>a>>b>>c>>d;
//        p[a][b]={c,d};
//    }
//    int x[15];
//    x[1]=1;
//    ll ans=0;
//    rep(i,2,n){
//        map<int,int>mp;
//        rep(j,1,i) if(p[j][i].F!=-1){
//            mp[x[j]+p[j][i].F]+=p[j][i].S;
//        }
//        int tp,maxi=0;
//        for(auto it:mp) if(it.S>maxi){
//            maxi=it.S;
//            tp=it.F;
//        }
//        ans+=maxi;
//        x[i]=tp;
//    }
//    cout<<ans;
//    long double x;
//    cin>>x;
//    x/=100.0;
//    long double d=1.01,prod=1.01;
//    rep(i,1,100000){
//        if(prod>x) return cout<<i,0;
//        prod*=d;
//    }
    return 0;
}


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

int main() {
  int x, y;
  long long int total = 0, max = -10000000, min = 10000000;

  cin >> x;
  for(int i = 0; i < x; ++i) {
    cin >> y;
    total += y;
    if(max < y) {
      max = y;
    }
    if(min > y) {
      min = y;
    } 
  }
  cout << min << " " << max << " " << total << endl;
}

Measured memory_bytes: 3080
S = str(input())
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])


for i in range(0, 2):
    for j in range(0, 2):
        for k in range(0, 2):
            ans = ''
            if i == 0:
                AB = A + B
                ans += str(A) + '+' + str(B)
            else:
                AB = A - B
                ans += str(A) + '-' + str(B)
            if j == 0:
                ABC = AB + C
                ans += '+' + str(C)
            else:
                ABC = AB - C
                ans += '-' + str(C)
            if k == 0:
                ABCD = ABC + D
                ans += '+' + str(D)
            else:
                ABCD = ABC - D
                ans += '-' + str(D)
            if ABCD == 7:
                ans += '=7'
                print(ans)
                quit()

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
  long int num,sum;
  scanf("%ld",&num);
  char s[4000]={};
  scanf("%s",s,num);
  long int count_r=0,count_g=0,count_b=0;
  for(int a=0;a<=num-1;a++){
    if(s[a]=='R')count_r++;
    else if(s[a]=='G')count_g++;
    else count_b++;
  };
  sum=count_r*count_g*count_b;
  long int i,j,k;
  for(j=0;j<=num-2;j++){
    for(i=j+1;2*i-j<=num-1;i++){
      k=2*i-j;
      if(s[j]!=s[i]&&s[k]!=s[i]&&s[k]!=s[j])
        sum--;
    };
  };
   printf("%ld",sum);
};
            
             

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

int main() {
  int r,g,b;
  cin >> r >> g >> b;
  int sum = 100*r + 10*g + b;
  if(sum%4 == 0){
    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++)

using namespace std;

int n;
vector<int> G[100000];

bool vis[100000];
vector<int> ans;

void dfs(int u){
	vis[u]=true;
	ans.emplace_back(u);
	for(int v:G[u]) if(!vis[v]) { dfs(v); break; }
}

int main(){
	int m; scanf("%d%d",&n,&m);
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}

	dfs(0);
	reverse(ans.begin(),ans.end());
	ans.pop_back();
	dfs(0);

	printf("%d\n",ans.size());
	for(int u:ans) printf("%d ",u+1);

	return 0;
}


Measured memory_bytes: 9720
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  vector<int> p(N), s(N); REP(i, N) cin >> p[i];
  s = p;
  sort(ALL(s));

  int cnt = 0;
  REP(i, N) {
    if (p[i] != s[i]) cnt++;
    if (cnt > 2) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    string a,b,c; cin>>a>>b>>c;
    cout<<char(int(a[0])-32)<<char(int(b[0])-32)<<char(int(c[0])-32)<<endl;
}

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

int main() {
	int N; cin >> N;
	int A[100010];
	for(int i=0; i<N; ++i) cin >> A[i];
	sort(A, A+N, greater<int>());
	long sum=0;
	for(int i=1; i<N; ++i) sum += A[i];
	int p=1;
	for(int i=1; i<N && sum*2>=A[i-1]; ++i){
	        ++p;
	        sum -= A[i];
	}
	cout << p << endl;
	return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vl a(n);
  multiset<ll> s;
  REP(i,n) {
    ll ai;
    cin >> ai;
    a[i] = -ai;
  }
  REP(i,n){
    auto it = s.upper_bound(a[i]);
    if(it!=s.end()){
      s.erase(it);
    }
    s.insert(a[i]);
  }

  cout << s.size() << endl;
  return 0;
}


Measured memory_bytes: 5760
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  list($s) = explode(" ", trim(fgets(STDIN)));

  $max=0;
  for($i=0;$i<$n;$i++){
    $in=[];
    $cnt=0;
    for($j=0;$j<$n;$j++){
      if($j<=$i){
        $in[$s[$j]]=true;
      }else{
        if(isset($in[$s[$j]])){
          $cnt++;
          unset($in[$s[$j]]);
        }
      }
    }
//    echo $cnt." ";
    $max=max($max,$cnt);
  }

  echo $max;

Measured memory_bytes: 16220
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <set>

using namespace std;

vector<int> V[2];
set<int> S[2][2];

string s;

int x, y;

int main()
{
	ios::sync_with_stdio(false);
	cin >> s >> x >> y;
	bool dir = 0;
	int cnt = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != 'T')
			cnt++;
		else
		{
			V[dir].push_back(cnt);
			cnt = 0;
			dir ^= 1;
		}
	}
	if (cnt != 0)
		V[dir].push_back(cnt);
	S[0][0].insert(V[0][0]);
	S[0][1].insert(0);
	for (int i = 1; i < V[0].size(); i++)
	{
		for (set<int>::iterator it = S[0][0].begin(); it != S[0][0].end(); it++)
			S[1][0].insert(*it + V[0][i]), S[1][0].insert(*it - V[0][i]);
		S[0][0] = S[1][0];
		S[1][0].clear();
	}
	for (int i = 0; i < V[1].size(); i++)
	{
		for (set<int>::iterator it = S[0][1].begin(); it != S[0][1].end(); it++)	
			S[1][1].insert(*it + V[1][i]), S[1][1].insert(*it - V[1][i]);
		S[0][1] = S[1][1];
		S[1][1].clear();
	}
	if (S[0][0].find(x) != S[0][0].end() && S[0][1].find(y) != S[0][1].end())
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;	
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define lli long long int
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	lli n,m;
	cin >> n >> m;
	{
		cout<<((n*(n-1))/2+(m*(m-1))/2)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
int ans(char c,bool one){
	if ('2' <= c&&c <= '9')
		return c - '0';
	else if (c == 'A')
		return (one ? 1 : 11);
	else
		return 10;
}

int main() {
	int n;
	cin >> n;
	REP(game_num, n){
		char cards[10];
		for (int i = 0; i < 10; i++){
			cin >> cards[i];
		}

		int sum = 0;
		bool herashita = false;
		bool one = false;
		for (int i = 0; i < 2; i++){
			int a = ans(cards[i], one);
			if (a == 11)one = true;
			sum +=a;
		}
		if (sum == 21){
			cout << "blackjack" << endl;
			continue;
		}
		else if (sum == 17&&!one ||sum>=18){
			cout << sum << endl;
			continue;
		}

		REP(i, 8){
			int a = ans(cards[i+2], one);
			if (a == 11)one = true;
			sum += a;
			if (sum >= 22){
				if (!one){
					cout << "bust" << endl;
					break;
				}
				sum -= 10;
				one = false;
			}
			if (17 <= sum){
				if (sum == 17 && one)
					continue;
				cout << sum << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1164
#include<iostream>
using namespace std;
 
class Dice{
		int _num[6];
	public:
        void set(int num[6]){
            for(int i = 0; i < 6; i++) _num[i] = num[i];
        }
        void printTop(){
			cout << _num[0] << endl;
        }
        void printRight(){
			cout << _num[2] << endl;
        }
		void N(){
			swap(_num[0],_num[4]);
			swap(_num[0],_num[5]);
			swap(_num[0],_num[1]);
		}
		void S(){
			swap(_num[0],_num[1]);
			swap(_num[0],_num[5]);
			swap(_num[0],_num[4]);			
		}
		void W(){
			swap(_num[0],_num[3]);
			swap(_num[0],_num[5]);
			swap(_num[0],_num[2]);			
		}
		void E(){
			swap(_num[0],_num[2]);
			swap(_num[0],_num[5]);
			swap(_num[0],_num[3]);			
		}
		void SetTop(int n){
			if(_num[2] == n) W();
			else if(_num[3] == n) E();
			else{
				while(1){
					if(_num[0] == n) break;
				S();
				}
			}
		}
		void SetFront(int n){
			while(1){
				if(_num[1] == n) break;
				S(); W(); N();
			}
		}
		int Get(int n){
			return _num[n];
		}

};
 
int main(){
	int num[6];
	for(int i = 0; i < 6; i++) cin >> num[i];
	Dice d1;
	d1.set(num);

	for(int i = 0; i < 6; i++) cin >> num[i];
	Dice d2;
	d2.set(num);
	
	d1.SetTop(d2.Get(0));
	d1.SetFront(d2.Get(1));
	
	bool judge = true;
	for(int i = 0; i < 6; i++){
		if(d1.Get(i) != d2.Get(i)){
			judge = false;
			break;
		}
	}
	
	if(judge) cout << "Yes" << endl;
	else      cout << "No" << endl;
	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;

int main(int argc, char ** argv) {
	ll N;
	cin >> N;
	vi a(N,0);
	for(ll i=0; i<N; i++) cin >> a[i];
	sort(a.begin(), a.end());
	cout << a[N-1] - a[0] << endl;
	return 0;
}


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

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

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

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


// ABC45
void solve()
{
    vs s(3);
    cin >> s[0] >> s[1] >> s[2];

    int turn = 0;
    while(true)
    {
        if(s[turn].length() == 0)
        {
            cout << char('A' + turn) << endl;
            return;
        }

        char card = s[turn].front();
        s[turn].erase(s[turn].begin());

        turn = card - 'a';
    }
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>

using namespace std;
typedef long long ll;

vector<ll> ans;

int main() {
	while (1) {
		ll N, M, P, X, winNum = 0, sum = 0;
		cin >> N >> M >> P;
		if (N == 0 && M == 0 && P == 0)break;
		for (int i = 1; i <= N; i++) {
			cin >> X;
			sum += X;
			if (i == M)winNum = X;
		}
		if (winNum == 0) {
			ans.push_back(0);
		}
		else {
			ans.push_back(sum * (100 - P) / winNum);
		}
	}
	for (int i = 0; i < ans.size(); i++)cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 3064
import std.stdio;
import std.string, std.conv;
import std.algorithm, std.array;
import std.typecons;

void main() {
  for(;;) {
    auto s = readln.split.map!(to!int).array;
    int N = s[0], M = s[1];
    if(N == 0 && M == 0) break;
    if((N * M) % 2 == 0) writeln("yes");
    else writeln("no");
  }
}

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

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

	if (s[0] == s[1] or s[1] == s[2] or s[2] == s[3]) {
		cout << "Bad" ;
	}
	else {
		cout << "Good" ;
	}



	return 0;
}

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

typedef long long ll;

const ll MAX = 510000;
const ll MOD = (ll)1e9 + 7;

ll fac[MAX], finv[MAX], inv[MAX]; // a!(fac[a]), (a!)^{-1}(finv[a]), a^{-1}(inv[a])

								  // テーブルを作る前処理
void comb_init() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll 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;
	}
}

ll mod_comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	// 前処理
	comb_init();

	ll H, W, A, B;
	cin >> H >> W >> A >> B;

	ll sum=0;
	for (ll i = B; i < W; i++) {
		ll st, tg;
		//cout << i+H-A-1 <<"C"<< i <<" "<< A+W-2-i <<"C"<< W-1-i << endl;
		st = mod_comb(i+H-A-1, i);
		tg = mod_comb(A+W-2-i, W-1-i);
		sum += st*tg%MOD;
	}

	cout << sum%MOD << endl;
}


Measured memory_bytes: 12160
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define MOD 1e9+7

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;
typedef vector<long long int> vll;

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

	vector<vll> vec(4, vll(s.size() + 1, 0));
	vec[0][0] = 1;
	rep(i, 0, s.size()) {
		if (s[i] == '?') vec[0][i + 1] = vec[0][i] * 3;
		else vec[0][i + 1] = vec[0][i];
		vec[0][i + 1] %= (i64)MOD;
	}
	rep(i, 0, s.size()) {
		if (s[i] == 'A') vec[1][i + 1] = vec[1][i] + vec[0][i];
		else if (s[i] == '?') vec[1][i + 1] = vec[1][i] * 3 + vec[0][i];
		else vec[1][i + 1] = vec[1][i];
		vec[1][i + 1] %= (i64)MOD;
	}
	rep(i, 0, s.size()) {
		if (s[i] == 'B') vec[2][i + 1] = vec[2][i] + vec[1][i];
		else if (s[i] == '?') vec[2][i + 1] = vec[2][i] * 3 + vec[1][i];
		else vec[2][i + 1] = vec[2][i];
		vec[2][i + 1] %= (i64)MOD;
	}
	rep(i, 0, s.size()) {
		if (s[i] == 'C') vec[3][i + 1] = vec[3][i] + vec[2][i];
		else if (s[i] == '?') vec[3][i + 1] = vec[3][i] * 3 + vec[2][i];
		else vec[3][i + 1] = vec[3][i];
		vec[3][i + 1] %= (i64)MOD;
	}
	cout << vec[3][s.size()] << endl;
}


Measured memory_bytes: 4352
import collections

s = input()
s1 = collections.deque([])
s2 = collections.deque([])
sum_ = 0
for i,ch in enumerate(s):
    if ch == "\\":
        s1.append(i)
    elif ch == "/" and len(s1)>0:
        j = s1.pop()
        sum_ += i - j
        a = i - j
        while len(s2) > 0 and s2[-1][0]>j:
            a += s2.pop()[1]
        s2.append([j,a])
ans = []
while len(s2)>0:
    ans.append(s2.pop()[1])
ans.reverse()
print(sum(ans))
ans.insert(0,len(ans))
print(*ans)


Measured memory_bytes: 6772
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;
#define M 100

int main(){
  int a, b, N, i, j, K, l[M], max=0;
  cin >> N >> K;
  for (i = 0; i < N; i++)
    cin >> l[i];
  sort(l, l+N, greater<int>());
  for (i = 0; i < K; i++){
    max += l[i];
  }
  cout << max << endl;
  return 0;
}


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

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(12);
  cout << fixed;
  int n;
  double s = 0, o = 1;
  cin >> n;
  for(int i = 0; i < n; i++){
    int k;
    cin >> k;
    s += o / k;
  }
  cout << o / s;
}


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

int main(){
  int n,m,minv,maxv;
  vector<int> r;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>m;
    r.push_back(m);
  }
  minv=r[0];
  maxv=-1000000000;
  for(int i=1;i<n;i++){
    maxv=max(maxv,r[i]-minv);
    minv=min(minv,r[i]);
  }
  cout<<maxv<<endl;
}


Measured memory_bytes: 2064
package main
import "fmt"

func main(){
	var p int

	fmt.Scanf("%d", &p)

	switch {
		case p>=400 && p<=599:
			fmt.Println("8")
		case p>=600 && p<=799:
			fmt.Println("7")
		case p>=800 && p<=999:
			fmt.Println("6")
		case p>=1000 && p<=1199:
			fmt.Println("5")
		case p>=1200 && p<=1399:
			fmt.Println("4")
		case p>=1400 && p<=1599:
			fmt.Println("3")
		case p>=1600 && p<=1799:
			fmt.Println("2")
		case p>=1800 && p<=1999:
			fmt.Println("1")
	}
}

Measured memory_bytes: 1832
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e10;
const long double PI = (acos(-1));

string dream = "maerd";
string dreamer = "remaerd";
string erase = "esare";
string eraser = "resare";

signed main() {
	string S;
	cin >> S;
	reverse(S.begin(), S.end());
	rep(i, S.size()) {
		string a, b, c, d;
		if (i + 5 <= S.size())a = S.substr(i, 5);
		if (i + 6 <= S.size())b = S.substr(i, 6);
		if (i + 7 <= S.size())c = S.substr(i, 7);
		if (i + 5 > S.size()) {
			cout << "NO" << endl;
			return 0;
		}
		if (i + 7 <= S.size()) {
			if (a == dream || a == erase)i += 4;
			else if (b == eraser)i += 5;
			else if (c == dreamer)i += 6;
			else {
				cout << "NO" << endl;
				return 0;
			}
		}
		else if (i + 6 <= S.size()){
			if (a == dream || a == erase)i += 4;
			else if (b == eraser)i += 5;
			else {
				cout << "NO" << endl;
				return 0;
			}
		}
		else {
			if (a == dream || a == erase)i += 4;
			else {
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a[1000],i,n;
    
    scanf("%d",&n);
    for (i=0; i<n; i++) {
        scanf("%d",&a[i]);
    }
    for (i=n-1; i>=1; i--) {
        printf("%d ",a[i]);//数列の要素の間に１つの空白を入れて下さい
    }
    printf("%d\n",a[0]);//最後の数の後に空白は入らないことに注意して下さい
    
    return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define Speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

#define st              first
#define nd              second
#define pb              push_back
#define pf              push_front
#define all(a)          (a).begin(), (a).end()
#define lwb             lower_bound
#define upb             upper_bound
#define vvll            vector<vector<ll> >
#define Mset(s, n)      memset(s, n, sizeof(s))
#define Sz(a)           int((a).size())
#define Max(a, b, c)    max(max((ll)(a), (ll)(b)), (ll)(c))
#define Min(a, b, c)    min(min((ll)(a), (ll)(b)), (ll)(c))
#define Unique(a)       sort(all(a)); (a).resize(unique(all(a)) - (a).begin())

typedef long double ld;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;
const int oo = 2e9;
const ld PI = acos((ld) -1);
int Getbit(ll x, int k){return (x >> (k - 1)) & 1;}
ll Lcm(ll a, ll b) {return a / __gcd(a, b) * b;}
bool isPrime(ll n){for(ll i = 2; i * i <= n; i++){if(n % i == 0) return 0;} return (n > 1) ? 1 : 0;}
ll Powmod(ll n, ll k, ll p = MOD) {ll r = 1; for(; k; k /= 2, n = n * n % p){if(k & 1) r = r * n % p;} return r;}

const int N = 2e5 + 5;

ll n, m, k;
int a[N];

void Solve(){
    cin >> n >> k;
    double res = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        a[i]++;
        a[i] += a[i - 1];
        if(i >= k) res = max(res, 0.5 * (a[i] - a[i - k]));
    }
    cout << res;
}


int main(){
    Speed;
    cout << fixed << setprecision(10);
    int query = 1;
//    cin >> query;
    while(query--) Solve();
}


Measured memory_bytes: 1024
#d=日数, c=満足低下度, s=満足上昇度, t=コンテストの日程 
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(d)]


res = 0
last = [0 for i in range(26)]
#old = t[dq[j][0] - 1]
#t[dq[0] - 1] = dq[1]
for day in range(d):
  t = s[day].index(max(s[day])) + 1
  m = s[day].index(max(s[day]))
  res += max(s[day])
  last[m] = day + 1
  #for i in range(26):
    #res -= c[i] * (day + 1 - last[i])
  combined1 = [x * (day + 1 - y) for (x, y) in zip(c, last)]
  res -= sum(combined1)
  #t[dq[j][0] - 1] = old
  print(t)

Measured memory_bytes: 9276
def summ(a):
    for i in range(1,a):
        a += a-i
    return a

n,k = map(int,input().split())
p = list(map(int,input().split()))

s = [0]
for i in range(len(p)):
    s.append(s[i] + p[i])

max_value = 0

for i in range(0,len(s)-k):
    if(s[i+k] - s[i] > max_value):
        max_value = s[i+k] - s[i]
        max_start = i

ans_pre = []

for j in range(k):
    ans_pre.append(p[max_start + j])

ans = 0.0

for i in range(len(ans_pre)):
    ans += ((ans_pre[i]*(1+ans_pre[i]))/2)/ans_pre[i]
print(ans)

Measured memory_bytes: 25308
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
int a[maxn];

int main() {
    int n,l,pos=0;
    read(n);read(l);
    REP(i,1,n) {
        read(a[i]);
        if(a[i]+a[i-1]>=l) pos=i-1;
    }
    //printf("%d\n",pos);
    if(!pos) {
        printf("Impossible\n");
        return 0;
    }
    printf("Possible\n");
    REP(i,1,pos-1) printf("%d\n",i);
    PER(i,n-1,pos) printf("%d\n",i);
    return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>

int main(void){
    int n,q,i,j,ri,li;
    scanf("%d%d",&n,&q);
    char s[n];
    scanf("%s",s);
    int l[q],r[q],ac[n];

    for(i=0; i<q; i++){
        scanf("%d%d",&l[i],&r[i]);
    }

    ac[0] =0;
    for(i=1; i<n; i++){
        ac[i] = ac[i-1];
        if(s[i-1] =='A' && s[i] =='C')
        ac[i]++;
    }

    for(i=0; i<q; i++){
        printf("%d\n",ac[r[i]-1] - ac[l[i]-1] );
    }


    return 0;
}

Measured memory_bytes: 2048
#include <stdio.h>

static const int N = 1000;

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

int main(){
    int n, i, j, key;
    int A[N];
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);

    for(i = 1; i < n; i++)
    {
        trace(A, n);
        key = A[i];
        for (j = i - 1; j >= 0; j--)
        {
            if (A[j] > key)
                A[j + 1] = A[j];
            else
                break;
        }
        A[j + 1] = key;
        
    }
    
    trace(A, n);

    return 0;
}

Measured memory_bytes: 1756
from itertools import accumulate

N = int(input())
M1 = list(map(int, input().split()))
M2 = list(map(int, input().split()))
M1a = list(accumulate(M1))
M2a = list(accumulate(M2[::-1]))
#print(M1a)
#print(M2a)

ans = -1
for i in range(N) :
    c = M1a[i] + M2a[N - 1 - i]
    if c > ans :
        ans = c
print(ans)

Measured memory_bytes: 3064
/*********************************************************************| 
|---------|    /\  ....                  ....                         |         
     |        /  \   \                    /  /------| ----- |-------| |
     |       /    \   \                  /  /           |   |         |
     |      /      \   \       /\       /  |            |   |         |
     |     /        \   \     /  \     /   |---|        |   |----|    |
     |    /__________\   \   /    \   /        |---|    |   |         |
     |   /            \   \ /      \ /              |   |   |         |
     |  /              \   |        |               /   |   |         |
     _ __              __ ...      ...      |------/  ----- _         |
                                                                      |  
        Md Tawsif Rahman                                              |
        Institute Of Information Technology                           |
        Jahangirnagar University                                      |                                                                         
                                                                      |
**********************************************************************/                 
#include<bits/stdc++.h>

using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define pii pair <int, int>
#define xx first
#define yy second
#define vi vector < int >
#define vl vector < ll >
#define vp vector < pii > 
#define inf  100000000 
#define f(i, c, n) for(i = c; i < n; i++)
#define fe(i, c, n) for(i = c; i <= n; i++)
#define fr(i, n, c) for(i = n - 1; i >= c; i--) 
#define vbe(a) a.begin(), a.end()
#define vsort(a) sort(a.begin(), a.end())
#define mem(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define srti(a, n) sort(a, a + n)
#define srtd(a, n) sort(a, a + n, greater<int>())
#define LB(a, x) (lower_bound(vbe(a), x) - a.begin())
#define UB(a, x) (upper_bound(vbe(a), x) - a.begin())

#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)

#define fast ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
int i, j, temp;
// int convert_str_to_int(string s) {
//     stringstream str(s);
//     int x = 0;
//     str >> x;
//     return x;
// }


/********************|
                     |
   START HERE        |
                     |
*********************/
void solve() {
    string s1 = "ABC", s2 = "ARC";
    string s;
    cin >> s;
    if(s == s1) cout << s2 << endl;
    else cout << s1 << endl; 


}
int main() {
    // int t;
    // cin >> t;
    // while(t--) {
    //     solve();
    // }
    solve();
}

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

using i64 = int64_t;

int main(){
    int n, x;
    cin >> n >> x;
    int ans = 1, d = 0;
    for(int i=0;i<n;++i){
        int l;
        cin >> l;
        if(d+l <= x)ans++;
        d += l;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import bisect
n = int(input())
aas = list(map(int, input().split()))
aas.sort()
l = aas[-1]
a = l // 2
b = l // 2 + 1
idx_a = bisect.bisect_left(aas,a)
idx_b = bisect.bisect_left(aas,a)
res = []
if aas[idx_a] != l:
    res.append(idx_a)
if aas[idx_b] != l:
    res.append(idx_b)
if idx_a > 0:
    if aas[idx_a-1] != l:
        res.append(idx_a-1)
if idx_b > 0:
    if aas[idx_b-1] != l:
        res.append(idx_b-1)
if idx_a < n - 1:
    if aas[idx_a+1] != l:
        res.append(idx_a+1)
if idx_b < n - 1:
    if aas[idx_b+1] != l:
        res.append(idx_b+1)
best = l // 2
res_f = n - 1
for i in set(res):
    if abs(best-aas[i]) <= abs(best-aas[res_f]):
        res_f = i
    if l%2 != 0:
        if abs(best+1 - aas[i]) <= abs(best+1 - aas[res_f]):
            res_f = i
print(str(l)+" "+str(aas[res_f]))

Measured memory_bytes: 20232
#include <iostream>
#include <string>
using namespace std;
         
int main() {
  int m,n;
  string a;
  cin>>a;
  for(int i=0;i<a.size();i++){
    if(a[i]=='A'){
      m=i;
      break;
    }
  }
  for(int b=a.size();b>0;b=b-1){
    if(a[b]=='Z'){
      n=b;
      break;
    }
  }
  cout<<n-m+1<<endl;

  return 0;
  
}



Measured memory_bytes: 640
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
C = [0] + gets.split.map(&:to_i)
s = 0
(0...N).step do |i|
  s += B[A[i] - 1]
  if i > 0 && (A[i] - A[i-1]) == 1
    s += C[A[i-1]]
  end
end
puts s

Measured memory_bytes: 1788
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var A = new int[N];
		for (var i = 0; i < N; i++) A[i] = F;
		Array.Sort(A);
		var coeff = new List<int>();
		if (N % 2 == 0)
		{
			for (var i = 0; i < N / 2 - 1; i++) coeff.Add(-2);
			coeff.Add(-1);
			coeff.Add(1);
			for (var i = 0; i < N / 2 - 1; i++) coeff.Add(2);
		}
		else
		{
			for (var i = 0; i < (N - 1) / 2; i++) coeff.Add(-2);
			coeff.Add(1);
			coeff.Add(1);
			for (var i = 0; i < (N - 3) / 2; i++) coeff.Add(2);
		}
		var ans = 0L;
		for (var i = 0; i < N; i++) ans += coeff[i] * A[i];
		var ans2 = 0L;
		for (var i = 0; i < N; i++) ans2 -= coeff[N - i - 1] * A[i];
		WriteLine(Max(ans, ans2));
	}
}


Measured memory_bytes: 16476
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	int n;
	cin >> n;

	int temp = n;
	int sum = 0;
	while(temp > 0)
	{
		sum += temp%10;
		temp = temp / 10;
	}

	if(n%sum == 0)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 256
// #include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#define pb emplace_back
#define LOCAL
  
using namespace std;
  
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+5;
typedef long long ll;
typedef pair<int,int> Pii;
 
template <typename T>inline void read(T& t){
    char c=getchar();t=0;
    int f=1;
    while(!isdigit(c)){
       if(c=='-')f=-1;
        c=getchar();
    }
    while(isdigit(c))t=t*10+c-48,c=getchar();
    t=f*t;
}
  
template <typename T,typename... Args> inline void read(T& t,Args&... args){
    read(t);read(args...);
}

int r[maxn<<2],c[maxn<<2];
int r2[maxn<<2],c2[maxn<<2];
map<int,map<int,int>> mps;
 
int main(){
    int t=1;
    // read(t);
    while(t--){
        int h,w,m;
        read(h,w,m);
        int max1=-1,max2=-1;
        for(int i=1;i<=m;i++){
            int h1,w1;
            read(h1,w1);
            r[h1]++;
            max1=max(max1,r[h1]);
            c[w1]++;
            max2=max(max2,c[w1]);
            mps[h1][w1]++;
        }
        int tmp1=0,tmp2=0;
        for(int i=1;i<=max(h,w);i++){
            if(r[i]==max1){
                r2[tmp1++]=i;
            }
            if(c[i]==max2){
                c2[tmp2++]=i;
            }
        }
        bool flag=true;
        for(int i=0;i<tmp1;i++){
            for(int j=0;j<tmp2;j++){
                if(!mps[r2[i]][c2[j]]){
                    flag=false;
                    break;
                }
            }
        }
        printf("%lld\n",max1+max2-(flag?1:0));
    }
    return 0;
}

Measured memory_bytes: 59448
#include <iostream>

using namespace std;

int main()
{
    long long int a, b, x;
    long long int c,z,k;
    cin >> a >> b >> x;
    c = b/x;
    z = a/x;
    long long int res = c - z;
    if(a % x == 0)
        res++;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int dp[3005][3005];
int main() {
	int N,T;
	cin >> N >> T;
	vector<pair<int, int>>P;
	for (int n = 0;n<N;++n) {
		int x, y;
		cin >> x >> y;
		P.emplace_back(make_pair(x, y));
	}
	sort(P.begin(),P.end());
	int ans = 0;
	for (int i = 0;i < N;++i) {
		for (int j = 0; j < T;++j) {
			dp[i + 1][j] = max(dp[i + 1][j],dp[i][j]);
			int nj = j + P[i].first;
			if (nj < T) {
				dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + P[i].second);
			}
		}
		int now = dp[i][T - 1] + P[i].second;
		ans = max(ans, now);
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 38888
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
 long long int dp[n][k+1];
  for(int i=0;i<n;i++)
    dp[i][0]=1;
  vector<long int> c(n);
  int i,j,z;
  for(i=0;i<n;i++)
    cin>>c[i];
  sort(c.begin(),c.end());
  for(i=0;i<n;i++)
    for(j=1;j<k+1;j++)
      dp[i][j]=0;
  for(i=1;i<k+1;i++)
    if(i<=c[0])
      dp[0][i]=1;
  for(i=1;i<n;i++)
  {
    for(j=1;j<k+1;j++)
    {
      if(c[i]==0)
        continue;
      if(j==1)
        dp[i][j]=(dp[i-1][0]+dp[i-1][1])%mod;
      else if(j<=c[i])
        dp[i][j]=(dp[i][j-1]+dp[i-1][j])%mod;
      else if(dp[i][j-1]!=0){
        dp[i][j]=(dp[i][j-1]-dp[i-1][j-1-c[i]]+mod+dp[i-1][j])%mod;
      }
      else break;
    /* int  count=0;
      for(z=max(0,j-c[i]);z<=j;z++)
        count+=dp[i-1][z];
      dp[i][j]=count;*/
    }
  }
  cout<<dp[n-1][k]%mod;
  return 0;
}

Measured memory_bytes: 81692
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) r.begin(),r.end()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007;



string s[12];
vector<vi> f(12,vi(12,0));
int ans=0;
int dx[]={-1,0,1,0},dy[]={0,-1,0,1};

void init(){
	rep(i,12){
		rep(j,12){
			f[i][j]=0;
			s[i][j]='\0';
		}
	}
	ans=0;
}

void calc(int x,int y,int fl){
	if(x<0||x>11||y<0||y>11)return;
	if(s[y][x]=='0'||f[y][x])return;
	f[y][x]=1;
	if(!fl)ans++;
	for(int i=0; i<4; i++){
		calc(x+dx[i],y+dy[i],1);
	}
}

int main(){
	while(1){
		init();
		for(int i=0; i<12; i++){
			cin>>s[i];
		}
		rep(i,12){
			rep(j,12){
				calc(i,j,0);
			}
		}
		if(s[0][0]!='\0')cout<<ans<<endl;
		if(cin.eof())break;
	}
}

Measured memory_bytes: 1208
#include "bits/stdc++.h"

using namespace std;

void solve(void)
{
	string s, t;
	cin >> s >> t;
	int n = s.size();
	vector<int> atb(26, -1), bta(26, -1);
	for (int i = 0; i < n; i++)
	{
		int a = s[i] - 'a';
		int b = t[i] - 'a';
		if (atb[a] < 0) atb[a] = b;
		else
		{
			if (atb[a] != b)
			{
				cout << "No" << endl;
				return;
			}
		}
		if (bta[b] < 0) bta[b] = a;
		else
		{
			if (bta[b] != a)
			{
				cout << "No" << endl;
				return;
			}
		}
	}

	cout << "Yes" << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define INF 1e9
typedef long long ll;

int main(void){
  int N;cin >> N;
  bool has_howtoBuy=false;
  while(N>=0){
    if(N%4==0) has_howtoBuy = true;
    N-=7;
  }
  if(has_howtoBuy) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <cassert>

class CombinationMod {
 public:
  CombinationMod(int nmax) : nmax_(nmax), xfact_(nmax+1), xfactinv_(nmax+1) {
    xfact_[0] = 1;
    xfactinv_[0] = 1;
    for (long long i = 1; i <= nmax; ++i) {
      xfact_[i] = (xfact_[i - 1] * i) % kMod;

      long long pow2 = xfact_[i];
      long long ansnow = 1;
      int j = kMod - 2;
      while (j > 0) {
        if (j % 2 == 1) {
          ansnow = (ansnow * pow2) % kMod;
        }
        j /= 2;
        pow2 = (pow2 * pow2) % kMod;
      }
      xfactinv_[i] = ansnow;

      assert( (xfact_[i] * xfactinv_[i]) % kMod == 1 );
    }
  }

  long long calc(int n, int m) {
    if (m < 0 || m > n) return 0;
    return (xfact_[n] * xfactinv_[m] % kMod) * xfactinv_[n - m] % kMod;
  }

 private:
  static constexpr int kMod = 1000000007;
  long long nmax_;
  std::vector<long long> xfact_;
  std::vector<long long> xfactinv_;
};

int main(int argc, char* argv[]) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  /* */
  long long kMod = 1000000007;
  int h, w, a, b;
  std::cin >> h >> w >> a >> b;

  CombinationMod comb(h + w);
  long long ans = 0;
  for (int i = 0; i < h - a; ++i) {
    ans = (ans + comb.calc(b + i, b) * comb.calc((h - i - 1) + (w - b - 2), w - b - 2)) % kMod;
    if (i == h - a - 1) {
      ans = (ans + comb.calc(b + i, b) * comb.calc((h - i - 2) + (w - b - 1), w - b - 1)) % kMod;
    }
  }
  std::cout << ans << std::endl;
  /* */

  return EXIT_SUCCESS;
}


Measured memory_bytes: 3328
# 入力 : 数字
N = int(input())
ListA = [int(x) for x in input().split()]

count = 0

while 1 :
    exist_odd = False

    for i in range(len(ListA)) :
        if ListA[i]%2 != 0 :
            exist_odd = True
    if exist_odd :
        break

    for i in range(len(ListA)) :
        ListA[i] /= 2

    count += 1

print(count)


Measured memory_bytes: 3060
n=int(raw_input())
a=map(int,raw_input().split())
b={}
for i in a :
    if i in b :
        b[i] += 1
    else :
        b[i] = 1
c = []
for i,j in b.items():
    if j>=2 :
        c.append(i)
    if j>=4 :
        c.append(i)
        
c=sorted(c)
if len(c) >= 2 :
    c = sorted(c)
    print c[-1]*c[-2]
else :
    print 0

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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

ll n,k;

ll intlog(ll base, ll x) {
    return (ll)(log(x) / log(base));
}

int main(){
  cin >> n >> k;
  cout << intlog(k,n)+1;
  return 0;
}


Measured memory_bytes: 512
from collections import Counter
[N,M] = list(map(int,input().split()))
A = list(map(int,input().split()))

D = dict(Counter(A))  #Aの要素の個数を数える。
for i in range(M):
    B,C = list(map(int,input().split()))
    D[C] = D.get(C,0) + B  #DのCがBあるっていう情報追加
# print(D)

K = sorted(list(D.keys()),reverse=True)  #Dのkeyを降順にソート
# print(K)

out = 0
cnt = 0 #N回で終了
now = 0
while cnt<=N-1:
    if D[K[now]] > 0: #大きい順に、D[K[now]]かい繰り返す
        out += K[now]
        D[K[now]] -= 1
        cnt+=1
    else:
        now+=1
print(out)

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

vector<int> Zalgo(const string &S){
    int N = (int)S.size();
    vector<int> res(N);
    res[0] = N;
    int i = 1, j = 0;
    while(i < N) {
        while(i+j < N && S[j] == S[i+j]) j++;
        res[i] = j;
        if(j == 0){
            i++;
            continue;
        }
        int k = 1;
        while(i+k < N && k+res[k] < j){
            res[i+k] = res[k];
            k++;
        }
        i += k;
        j -= k;
    }
    return res;
}

int main(){
    int N; cin >> N;
    string S; cin >> S;
    string T;
    int ans = 0;
    rep(i, N-1){
        auto a = Zalgo(S.substr(i));
        rep(j, a.size()){
            int cnt = min(j, a[j]);
            ans = max(ans, cnt);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3664
import java.util.Scanner;

public class Main
{ //202 is the modular multiplicative inverse of 10 under 2019.
	static int mod(int x)
	{
		int an = x%2019;
		while(an<0)an+=2019;
		return an;
	}

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		
		int n = s.length();
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++)
		{
			a[i] = s.charAt(i) - '0';
		}
		
		long[] avail = new long[2019];
		
		int backtransmul = 1;
		int backtransadd = 0;
		long score = 0;
		int curval = 0;
		for(int i = 0; i < n; i++)
		{
			curval = mod(curval*10 + a[i]);
			int cura = mod((0 * backtransmul) - backtransadd);
			avail[cura]++;
			
			backtransmul = mod(backtransmul*202);
			backtransadd = mod(backtransadd + backtransmul*a[i]);
			
			int curc = mod((0 * backtransmul) - backtransadd);
			score += avail[curc];
		}
		
		System.out.println(score);
	}

}


Measured memory_bytes: 32228
import math
B=0

while True:
    N=int(input())
    
    if N==0:
        break
    L=list(input().split())
    L=[int(s) for s in L]
    M=sum(L)/len(L)
    
    for i in range(N):
        B+=(L[i]-M)**2
        i+=1
    
    A=B/N
    A=math.sqrt(A)
    
    print(A)
    B=0


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

using namespace std;

const int MAXN = 1e5 + 5;

int niz[MAXN], DP[MAXN], n;

int main()
{
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> niz[i];
	DP[0] = 0;
	DP[1] = abs(niz[0] - niz[1]);
	for(int i = 2; i < n; i++)
	{
		DP[i] = min(DP[i - 1] + abs(niz[i - 1] - niz[i]), DP[i - 2] + abs(niz[i] - niz[i - 2]));
	}
	cout << DP[n - 1];
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<climits>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
string s;
int main(){
  cin>>s;
  int ss=s.size();
  cout<<s[0]<<ss-2<<s[ss-1]<<"\n";

  return 0;
}


Measured memory_bytes: 256