akhauriyash/Code-Regression huggingface dataset:
n, t = map(int, input().split())
dp1 = [[-float("inf") for i in range(t)] for i in range(n + 1)]
dp1[0][0] = 0
dp2 = [[-float("inf") for i in range(t)] for i in range(n + 1)]
dp2[n][0] = 0
ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))
for i in range(n):
    a, b = ab[i]
    for j in range(t - 1, -1, -1):
        if j >= a:
            dp1[i + 1][j] = max(dp1[i][j], dp1[i][j - a] + b)
        else:
            dp1[i + 1][j] = dp1[i][j]
for i in range(n + 1):
    for j in range(t - 1):
        dp1[i][j + 1] = max(dp1[i][j], dp1[i][j + 1])
for i in range(n - 1, -1, -1):
    a, b = ab[i]
    for j in range(t - 1, -1, -1):
        if j >= a:
            dp2[i][j] = max(dp2[i + 1][j], dp2[i + 1][j - a] + b)
        else:
            dp2[i][j] = dp2[i + 1][j]
for i in range(n + 1):
    for j in range(t - 1):
        dp2[i][j + 1] = max(dp2[i][j], dp2[i][j + 1])
ans = [max([dp1[i][j] + dp2[i + 1][t - 1 - j] + ab[i][1] for j in range(t)]) for i in range(n)]
print(max(ans))

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

int main(){
  int N;cin>>N;
  vector<int> A(N);rep(i,N)cin>>A[i];
  vector<pair<int,int>> P;
  int buy=A[0],sell;
  bool flag=true;
  for(int i=1;i<N;++i){
    if(flag && A[i]>=A[i-1]) continue;
    if(flag && A[i]<A[i-1]){
      sell = A[i-1];
      P.push_back({buy,sell});
      flag = false;
    }
    if((!flag) && A[i]>=A[i-1]){
      buy = A[i-1];
      flag = true;
    }
  }
  if(flag) P.push_back({buy,A[N-1]});
  ll ans = 1000;
  rep(i,P.size()){
    ll stock = ans / P[i].first;
    ans -= stock * P[i].first;
    ans += stock * P[i].second;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
N = int(input())
X = input()

X_pc = X.count("1")
X_res_m1 = 0
X_res_p1 = 0
for i, s in enumerate(reversed(X)):
    if s == "1":
        if X_pc > 1:
            X_res_m1 += pow(2, i, X_pc - 1)
            X_res_m1 %= X_pc - 1

        X_res_p1 += pow(2, i, X_pc + 1)
        X_res_p1 %= X_pc + 1

f = [-1] * (X_pc + 1)
f[0] = 0
for n in range(1, X_pc + 1):
    pc = format(n, "b").count("1")
    f[n] = f[n % pc] + 1

ans = []
for i, s in enumerate(reversed(X)):
    if s == "1":
        if X_pc > 1:
            fx = (X_res_m1 - pow(2, i, X_pc - 1)) % (X_pc - 1)
            ans.append(f[fx] + 1)
        else:
            ans.append(0)

    else:
        fx = (X_res_p1 + pow(2, i, X_pc + 1)) % (X_pc + 1)
        ans.append(f[fx] + 1)

print(*reversed(ans), sep="\n")


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)

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

typedef long long ll;

const string YES = "Yes";
const string NO = "No";

int main() {
    int A, B;
    cin >> A >> B;
    cout << A * B << endl;
    return 0;
}

Measured memory_bytes: 3624
while True:
    l = list(map(int, input().split()))
    a,b = l[0],l[1]
    if a == 0 and b == 0:
        break
    print("#"*b)
    for i in range(a-2):
        print("#"+"."*(b-2)+"#")
    print("#"*b)
    print()



Measured memory_bytes: 5612
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

int n,m,n_;
struct data{
	int val,lazy;
	data(){}
	data(int vv,int la){
		val=vv;
		lazy=la;
	}
};

data dat[1<<20];

void lazy_evaluate(int k){
	dat[k].val+=dat[k].lazy;
	if(k+1<n_){
		dat[k*2+1].lazy+=dat[k].lazy;
		dat[k*2+2].lazy+=dat[k].lazy;
	}
	dat[k].lazy=0;
}

void lazy_update(int k){
	dat[k].val=dat[k*2+1].val+dat[k*2+2].val;
}

void update(int a,int b,int v,int k=0,int l=0,int r=n_){
	lazy_evaluate(k);
	if(r<=a || b<=l)return;
	if(a<=l && r<=b){
		dat[k].lazy+=v;
		lazy_evaluate(k);
		return;
	}
	update(a,b,v,k*2+1,l,(l+r)/2);
	update(a,b,v,k*2+2,(l+r)/2,r);
	lazy_update(k);
}

int query(int a,int b,int k=0,int l=0,int r=n_){
	lazy_evaluate(k);
	//printf("query %d %d %d %d %d %d\n",a,b,k,l,r,dat[k].val);
	if(r<=a || b<=l)return 0;
	if(a<=l && r<=b)return dat[k].val;
	int vl=query(a,b,k*2+1,l,(l+r)/2);
	int vr=query(a,b,k*2+2,(l+r)/2,r);
	lazy_update(k);
	return vl+vr;
}

vector<PP> vec;


int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		vec.push_back(PP(r-l+1,P(l,r)));
	}
	n_=1;
	while(n_<m+1)n_*=2;
	sort(vec.begin(),vec.end());
	int j=0;
	for(int i=1;i<=m;i++){
		while(j<n && vec[j].first<i){
			update(vec[j].second.first,vec[j].second.second+1,1);
			//printf("upd %d %d\n",vec[j].second.first,vec[j].second.second+1);
			j++;
		}
		int v=0;
		int res=n-j;
		while(v<=m){
			res+=query(v,v+1);
			//printf("q%d %d\n",v,query(v,v+1));
			v+=i;
		}
		printf("%d\n",res);
	}
	return 0;
}


Measured memory_bytes: 8560
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn check(s: Vec<char>) -> bool {
    if s[0] != 'A' {
        return false;
    }
    for i in 1..s.len() {
        if s[i] != 'C' && !s[i].is_lowercase() {
            return false;
        }
    }
    let mut count = 0;
    for i in 2..s.len() - 1 {
        if s[i] == 'C' {
            count += 1;
        }
    }
    count == 1
}

fn main() {
    input! {
        s: String,
    }
    println!("{}", if check(s.chars().collect()) { "AC" } else { "WA" });
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005;
int n,a[N],s[N];
ll c[3*N];
int lowbit(int x){return x&(-x);}
void add(int x){
	for(;x<=2*N;x+=lowbit(x))c[x]++;
}
ll query(ll x){
	ll res=0;
	for(;x;x-=lowbit(x))res+=c[x];
	return res;
}
bool check(int x){
	ll res=0;
	memset(c,0,sizeof(c));
	s[0]=0;
	for(int i=1;i<=n;i++)
		s[i]=s[i-1]+(a[i]>=x?1:-1);
	for(int i=0;i<=n;i++){
		res+=query(s[i]+N);
		add(s[i]+N);
	}
	if(res>=1LL*n*(n+1)/4)return 1;
	else return 0;
}
int main(){
	int l=0,r=0,ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		r=max(r,a[i]);
	}
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid)){
			l=mid+1;
			ans=mid;
		}
		else r=mid-1;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 6872
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
using namespace std;
ifstream f ("test.in"); ofstream g ("test.out");
int k,n,dp[100005],v[100005];
int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;dp[i]=(1<<30),i++) cin>>v[i];
    dp[1]=0;
    dp[2]=abs(v[1]-v[2]);
    for(int i=3;i<=n;i++)
        for(int j=i-1;j>=i-k and j;j--)
            dp[i]=min(dp[i],dp[j]+abs(v[i]-v[j]));
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  char S[SIZE], T[SIZE];
  vector<int> vec[26];
  int N, M;

  scanf("%s%s", S, T);
  N = strlen(S);
  M = strlen(T);

  for (int i=0; i<N; i++)
    vec[S[i]-'a'].push_back(i);
  for (int i=0; i<N; i++)
    vec[S[i]-'a'].push_back(i + N);

  int loop = 0, index = -1;

  for (int i=0; i<M; i++) {
    if (vec[T[i]-'a'].empty()) {
      puts("-1");
      return 0;
    }

    int al = T[i] - 'a';

    auto it = lower_bound(vec[al].begin(), vec[al].end(), index + 1);

    index = *it;

    debug(index);

    if (index >= N) {
      index = index - N;
      loop++;
    }
  }

  printf("%lld\n", (ll)loop * N + index + 1);

  return 0;
}


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

int main(){
    int N;
    cin >> N;
    
    int W[101];
    for(int i = 1;i <= N;i++){
     cin >> W[i];
    }
    int ans = 1000000;
    for(int T = 1;T < N;T++){
        int right = 0;
        int left = 0;
    for(int i = 1;i <= N;i++){
        if(i <= T) left += W[i];
        else right += W[i];
    }
        int cnt = abs(left - right);
        if(ans > cnt) ans = cnt;
   
  }
    cout << ans << endl;
}

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

int main()
{

	int N, M;
	int num[3] = {-1,-1,-1};

	bool ans = true;

	cin >> N >> M;
	for (int i = 0; i < M; i++)
	{
		int s, c;
		cin >> s >> c;
		s -= 1;
		if(num[s] == -1){
			num[s] = c;
		}else if (num[s] != c){
			ans = false;
		}
	}

	if(N != 1){
		if(num[0] == 0){
			ans = false;
		}else if(num[0] == -1){
			num[0] = 1;
		}
	}
	for (int i = 0; i < N; i++)
	{
		if(num[i] == -1){
			num[i] = 0;
		}
	}
	
	int ansnum = 0;
	if(!ans){
		ansnum = -1;
	}else{
		for (int i = 0; i < N; i++)
		{
			ansnum = ansnum * 10 + num[i];
		}
	}

	cout << ansnum << endl ; 	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int main(void){
	int N, X;
	int res = 1, pos = 0;
	cin >> N >> X;
	for(int i = 0; i < N; i++){
		int L; 
		cin >> L;
		pos += L;
		if(pos <= X) res++;
	}

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 11//文字列の長さ

int main(void){
    int n,k;//nは文字列の長さ、kはk番目の文字を置き換えない
    int i;//iはループ用 
    char s[N],t;//sは与えられた文字列,tはk番目の文字の保存

    scanf("%d",&n);
    scanf("%s",s);
    scanf("%d",&k);

    t=s[k-1];
    for(i=0;i<n;i++){
        if(s[i]!=t)
        s[i]='*';
    }
    printf("%s",s);
    return 0;
    
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }


void compute() {

}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  rep(i,n) {
    if( i - 1 < 0 || s[i] != s[i-1] ) ++cnt;
  }
  cout << cnt << endl;
  compute();
  return 0;
}


Measured memory_bytes: 512
/*
* @Author: _dp95
* @Date:   2020-04-14 08:16:00
*/
#include "bits/stdc++.h"
using namespace std ;

#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll ;
typedef long double ldb ;

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl '\n'

#define all( x ) x.begin(),x.end() 
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

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

const int MAX = 2*1000*1000 + 10 ;
const ll INF = 1e18 ;
const int MOD = 1e9 + 7 ;

int has[MAX] ;

signed main( ){
  timesaver ;
  int n ;
  cin >> n ;
  for( int i = 0 ; i < n ; i++ ){
    int x ;
    cin >> x; 
    has[x]++ ;
  }
  int ans = 0 ;
  for( int i = 0 ; i < MAX ; i++ ){
    ans += (has[i]>0);
  }
  int tmp = 0 ;
  for( int i = 0 ; i < MAX ; i++ ){
    if( has[i] and ~has[i]&1 and tmp ){
      has[i]-- ;
      tmp-- ;
    }
    if( has[i] and ~has[i]&1 )
      tmp++ ;
  }
  cout << ans - tmp << nl ;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    ll N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;

    ll mi = min({A, B, C, D, E});

    cout << 4 + (N + mi - 1) / mi << endl;
}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

int main(){
    int X,Y,Z,K; cin>>X>>Y>>Z>>K;
    vector<ll> A(X),B(Y),C(Z);
    rep(i,X)cin>>A[i];
    rep(i,Y)cin>>B[i];
    rep(i,Z)cin>>C[i];
    sort(A.rbegin(),A.rend());
    sort(B.rbegin(),B.rend());
    sort(C.rbegin(),C.rend());
    vector<ll> R;
    rep(i,X){
        rep(j,Y){
            if((i+1)*(j+1)>K)continue;
            rep(k,Z){
                if((i+1)*(j+1)*(k+1)>K)continue;
                R.push_back(A[i]+B[j]+C[k]);
            }
        }
    }
    sort(R.rbegin(),R.rend());
    rep(i,K)cout<<R[i]<<endl;
}


Measured memory_bytes: 4236
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
	string s;
	cin >> s;
	bool ans = false;
	rep(i, s.size()) {
		if (s[i] == '7') {
			ans = true;
		}
	}
	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3624
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
   string s,t;
   cin >> s >> t;
   
   int count = 0;
   REP(i,3){
      if(s[i]==t[i]) count++;
      
   }
   
   cout << count << endl;
   
   
   
   return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define cy cout << "Yes" << endl
#define cn cout << "No" << endl
typedef long long ll;

void Main()
{
	int N, T, A;
  	cin >> N >> T >> A;
  	vector<int> H(N);
  	rep(i,N) cin >> H[i];
  	
  	auto kion = [&](int T, int x){
    	return T - x * 0.006;
    };
	
  	// rep(i,N) cout << kion(T, H[i]) << endl;
  
  	// kion(T, H[i]) が A に最も近いのは？ -> i+1 を答える
  	double temp = INT_MAX;
  	int tempi;
  	rep(i,N){
    	if(temp > abs(A - kion(T,H[i])) ){
          	temp = abs(A - kion(T,H[i]));
          	tempi = i;
        }
    }
	cout << tempi+1 << endl;
  
	return;	
}

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

Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
#include <map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

using namespace std;
 
class DisjointSet {
    public:
        vector<int> rank, p;
        DisjointSet() {}
        DisjointSet(int n){
            rank.resize(n, 0);
            p.resize(n, 0);
            for(int i = 0; i < n; i++){
                makeSet(i);
            }
        }
        
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }
        
        bool same(int x, int y){
            return findSet(x) == findSet(y);
        }
        
        int findSet(int x){
            if(x != p[x]){
                p[x] = findSet(p[x]);
            }
            
            return p[x];
        }
        
        void unite(int x, int y){
            link(findSet(x), findSet(y));
        }
        
        void link(int x, int y){
            if(rank[x] > rank[y]){
                p[y] = x;
            } else {
                p[x] = y;
                if(rank[x] == rank[y]){
                    rank[y]++;
                }
            }
        }
};

const int MAX_N = 200050;
const int MAX_K = 100050;

int N, K, L;
int p[MAX_K], q[MAX_K], r[MAX_K], s[MAX_K];
 
int main(void){
    cin >> N >> K >> L;

    for (int i = 1; i <= K; i++) {
        std::cin >> p[i] >> q[i];
    }
    for (int i = 1; i <= L; i++) {
        std::cin >> r[i] >> s[i];
    }
    
    DisjointSet ds1 = DisjointSet(N+1);
    DisjointSet ds2 = DisjointSet(N+1);
    
    for(int i = 1; i <= K; i++){
        if(!ds1.same(p[i], q[i])) ds1.unite(p[i], q[i]);
    }
    
    for(int i = 1; i <= L; i++){
        if(!ds2.same(r[i], s[i])) ds2.unite(r[i], s[i]);
    }
    
    vector<pair<int, int> > com(N+1);
    map<pair<int, int>, int> S;
    for(int i = 1; i <= N; i++){
        com[i].first = ds1.findSet(i);
        com[i].second = ds2.findSet(i);
        S[com[i]] += 1;
    }
    
    for(int i = 1; i <= N; i++){
        cout << S[com[i]] << " ";
    }
    cout << endl;
    
    return 0;
    
    
}


Measured memory_bytes: 18048
//=======================//
// coder: Andy - Tohrumi //
//=======================//

#include <bits/stdc++.h>

using namespace std;

#define fastio ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define mp make_pair
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(__typeof(b) i = a; i < b; i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i > b; i--)

typedef vector<int> vi;		typedef vector<ll> vl;
typedef pair<int, int> ii; 	typedef vector<ii> vii;

// code start here //

int dp[200005][26], pos[200005][26];
string s;

signed main() {
	fastio;
	cin >> s;
	int n = s.length();
	rep(i, 0, 26) 
	{
		dp[n][i] = 1;
		pos[n][i] = n;
	}
	Rep(i, n - 1, -1) {
		rep(j, 0, 26) {
			if((s[i] - 'a') == j) {
				pos[i][j] = i;
				dp[i][j] = 1 + dp[i + 1][0];
				rep(k, 1, 26) {
					dp[i][j] = min(dp[i+1][k] + 1, dp[i][j]);
				}
			}
			else {
				pos[i][j] = pos[i+1][j];
				dp[i][j] = dp[i + 1][j];
			}
		}
	}
	int len = *min_element(dp[0], dp[0] + 26);
	int run = 0;
	while (run < n)
	{
		for (int i = 0; i < 26; i++)
		{
			if (dp[run][i] == len)
			{
				len--;
				cout << (char)(i + 'a');
				run = pos[run][i];
				break;
			}
		}
		run++;
	}
}


Measured memory_bytes: 44356
n,m,x,y = map(int,input().split())
lstx = [int(i) for i in input().split()]
lsty = [int(i) for i in input().split()]

max_x = max(lstx)
min_y = min(lsty)

for i in range(1,y-x+1):
    z = x+i
    if max_x < z and min_y >= z : 
        ans = "No War"
        break
else:
    ans = "War"

print(ans)


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

int main() {
  int N;
  cin >> N;
  vector<int> x(N);
  vector<int> y(N);
  vector<int> h(N);
  for (int i = 0; i < N; i++) cin >> x.at(i) >> y.at(i) >> h.at(i);
  
  for (int Cx = 0; Cx <= 100; Cx++){
    for (int Cy = 0; Cy <= 100; Cy++){
      int H = 0;
      for (int i = 0; i < N; i++){
        if (h.at(i) > 0){
          H = h.at(i) + abs(x.at(i) - Cx) + abs(y.at(i) - Cy);
          break;
        }
      }
      
      bool flag = true;
      for (int i = 0; i < N; i++){
        if (h.at(i) == max(H - abs(x.at(i) - Cx) - abs(y.at(i) - Cy), 0)){
          continue;
        }
        else{
          flag = false;
          break;
        }
      }
      
      if (flag){
        cout << Cx << " " << Cy << " " << H << endl;
        return 0;
      }
    }
  }   
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <numeric>
#include <set>

#define MOD 1000000007
#define INF 2000000000
#define sp ' '
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define FOR(YY, yy) for(long long yy = 0; yy < YY; ++yy)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;
typedef vector<pair<int, pair<int, int> > > vpip;
typedef vector<bool> vb;
typedef priority_queue<int> pqi;


int N = 0;
vi A, maxA;

int main(int argc, char **argv)
{
    ios::sync_with_stdio(); cin.tie(0);
    cin >> N;
    maxA.assign(N+2, INF); A.assign(N+1, 0);
    for(int i = 1; i <= N-1; ++i) cin >> maxA[i];

    for(int i = 1; i <= N; ++i) A[i] = min(maxA[i], maxA[i-1]);
    int sum = accumulate(A.begin(), A.end(), 0);
    cout << sum << endl;



    return 0;
}

//cikisir



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

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

  int h,w,k;
  cin >> h >> w >> k;

  vector<vector<char>> board(h, vector<char> (w));
  rep(i,h) rep(j,w) cin >> board[i][j];

  int answer = 0;
  for (int bith = 0; bith < (1 << h); bith++) {
    for (int bitw = 0; bitw < (1 << w); bitw++) {
      int cnt = 0;

      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if(1 & bith >> i) continue;
          if(1 & bitw >> j) continue;

          if(board[i][j] == '#') cnt++;
        }
      }

      if(cnt == k) answer++;
    }
  }

  cout << answer << '\n';
}


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

using ll = long long;
using pll = pair<ll, ll>;

ll modpow(ll x, ll n, ll M) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) {
            res *= x;
            res %= M;
        }
        x *= x;
        x %= M;
        n >>= 1;
    }
    return res;
}

ll euler(ll x) {
    ll res = x;
    ll t = x;
    for(ll i=2; i*i<=x; ++i) {
        if(t % i == 0) {
            res = res / i * (i - 1);
        }
        while(t % i == 0) {
            t /= i;
        }
    }
    if(t > 1) {
        res = res / t * (t - 1);
    }
    return res;
}

int main() {
    ll N;
    cin >> N;
    if(N == 2) {
        cout << 1 << endl;
        return 0;
    }
    ll L = 1;
    ll T = N;
    for(ll i=2; i*i<=N; ++i) {
        if(N % (i*i) == 0) {
            cout << -1 << endl;
            return 0;
        }
        if(T % i == 0) {
            L = (L / __gcd(L, i-1) * (i-1));
            T /= i;
        }
    }
    if(T > 1) {
        L = L / __gcd(L, T-1) * (T-1);
    }
    if(__gcd(N, L) != 1) {
        cout << -1 << endl;
        return 0;
    }
    ll phi = euler(L);
    vector<ll> cand;
    for(int i=1; i*i<=phi; ++i) {
        if(phi % i == 0) {
            cand.push_back(i);
            cand.push_back(phi/i);
        }
    }
    sort(cand.begin(), cand.end());
    cand.erase(unique(cand.begin(), cand.end()), cand.end());
    for(int i=0; i<cand.size(); ++i) {
        if(modpow(N, cand[i], L) == 1) {
            cout << cand[i] << endl;
            return 0;
        }
    }
}


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

int main() {
  int N;
  cin >> N;
  string color = "Three";
  
  for (int i = 0; i < N; i++) {
    string a;
    cin >> a;
    
    if (a == "Y") {
      color = "Four";
      break;
    }
  }
  
  cout << color << endl;
  
}



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

#define ull unsigned long long

const int Mod(924844033);
int F[2003], G[2003][2], fac[2003];

int main()
{
	int n, K, tot = 0;
	scanf("%d%d", &n, &K);
	F[0] = 1;
	for(int c = 1; c <= K * 2 && c <= n; c++)
	{
		int m = (n - c) / (2 * K) + 1;
		for(int i = 0; i <= m; i++)
			G[i][0] = G[i][1] = 0;
		G[0][c <= K] = 1;
		for(int i = 1; i <= m; i++)
			for(int j = i; ~j; j--)
			{
				int x = G[j][0], y = G[j][1];
				G[j][0] = ((x + y) % Mod + G[j - 1][0]) % Mod;
				G[j][1] = (G[j - 1][0] + G[j - 1][1]) % Mod;
			}
		if((m - 1) * 2 * K + c + K > n)
			for(int i = 1; i <= m; i++)
				G[i][1] = 0;
		tot += m;
		for(int j = tot; j; j--)
			for(int i = 1; i <= m && i <= j; i++)
				F[j] = (F[j] + (ull) F[j - i] * (G[i][0] + G[i][1])) % Mod;
	}
	for(int i = fac[0] = 1; i <= n; i++)
		fac[i] = (ull) fac[i - 1] * i % Mod;
	int ans = fac[n];
	for(int i = 1; i <= n; i++)
	{
		int x = (ull) F[i] * fac[n - i] % Mod;
		if(i & 1) ans = (ans - x + Mod) % Mod;
		else ans = (ans + x) % Mod;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int a,b;
    cin>>a>>b;

    int c,d;
    cin>>c>>d;

    int x=iceil(a,d),y=iceil(c,b);

    if(x>=y)
        cout<<"Yes";
    else
        cout<<"No";
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 3600
#include <queue>
#include <vector>
#include <iostream>

#pragma warning(disable : 4996)

using namespace std;

int H, W, N, X1, Y1, X2, Y2; vector<vector<bool> > M;

const vector<int> dx = { 0, 1, 0, -1 };
const vector<int> dy = { -1, 0, 1, 0 };

int main()
{
	while (true)
	{
		scanf("%d", &W);
		scanf("%d", &H);
		
		if (H == 0 && W == 0) { break; }

		scanf("%d", &N);

		M = vector<vector<bool> >(H, vector<bool>(W, false));

		for (int i = 0; i < N; i++)
		{
			scanf("%d", &X1);
			scanf("%d", &Y1);
			scanf("%d", &X2);
			scanf("%d", &Y2);

			for (int j = Y1; j < Y2; j++)
			{
				for (int k = X1; k < X2; k++)
				{
					M[j][k] = true;
				}
			}
		}

		int ret = 0;

		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (!M[i][j])
				{
					M[i][j] = true;

					queue<pair<int, int> > que; que.push(make_pair(j, i));

					while (!que.empty())
					{
						int rx = que.front().first;
						int ry = que.front().second; que.pop();

						for (int dir = 0; dir < 4; dir++)
						{
							if (0 <= rx + dx[dir] && rx + dx[dir] < W && 0 <= ry + dy[dir] && ry + dy[dir] < H)
							{
								if (!M[ry + dy[dir]][rx + dx[dir]])
								{
									M[ry + dy[dir]][rx + dx[dir]] = true;

									que.push(make_pair(rx + dx[dir], ry + dy[dir]));
								}
							}
						}
					}

					ret++;
				}
			}
		}

		printf("%d\n", ret);
	}

	return 0;
}

Measured memory_bytes: 5276
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        hoge();
        //System.Console.ReadLine();
    }

    public static void hoge()
    {
        var vars = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        var count = 0;
        for(long i = vars[0]; i <= vars[1]; i++)
        {
            if(i % vars[2] == 0)
            {
                count++;
            }
        }

        System.Console.WriteLine(count);

    }

}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int N = 1e5+5;

int n, m;
int a[2*N];

int sim(int p) {
    int res = 0;
    for (int x = 0; ; ++x) {
        int i = p+x, j = 2*n-1-x;
        if (i > j) break;
        int s = a[i] + a[j];
        if (s < m) return -1;
        else res = max(res, s-m);
    }

    for (int x = 0; ; ++x) {
        int i = x, j = p-1-x;
        if (i > j) break;
        int s = a[i] + a[j];
        res = max(res, s);
    }

    return res;
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    FOR(i, 0, 2*n-1) {
        cin >> a[i];
    }

    sort(a, a+2*n);
    int lo = 0, hi = n;
    while (lo < hi) {
        int mid = (lo+hi)/2;

        //cout << lo << ' ' << hi << " :: " << 2*mid << " -> " << sim(2*mid) << '\n';
        if (sim(2*mid) != -1) hi = mid;
        else lo = mid+1;
    }

    //cout << hi << '\n';
    cout << sim(2*hi) << '\n';
}



Measured memory_bytes: 1024
N=int(input())
A=list(map(int,input().split()))
A.sort()
if A[0]==0:
    print('0')
    A.remove(0)
    exit()
prod=1
for i in A:
    prod=prod*i
    if prod>1e18:
        print('-1')
        exit()
else:
    print(prod)

Measured memory_bytes: 21596
package main

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

func main() {
	var n int
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([]int, n)
	m := make(map[int]bool)
	dup := make(map[int]bool)
	for i := range as {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
		if _, ok := m[as[i]]; ok {
			dup[as[i]] = true
		}
		m[as[i]] = true
	}
	sort.Sort(sort.IntSlice(as))
	var sum int
	ms := make([]int, 1e6+1)
	for i := range as {
		num := as[i]
		if ms[num] == 1 {
			continue
		}
		if _, ok := dup[as[i]]; !ok {
			sum++
		}
		for j := num; j <= 1e6; j += num {
			ms[j] = 1
		}
	}
	fmt.Println(sum)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 19068
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
template <class... T> void printd(T&&...){ }
#endif

int main(){
    int n, l, t;
    cin >> n >> l >> t;
    vector<int> ls, rs, poss;
    int pos0 = -1, idx0;
    for(int i=0;i<n;i++){
        int x, w;
        cin >> x >> w;
        if(w == 1){
            rs.push_back(x);
            if(pos0 == -1){
                idx0 = i;
                pos0 = ((x + (w == 1 ? 1 : -1) * t + 1ll * l * t) % l);
            }
        }else{
            ls.push_back(x);
        }
        // cout << (x + (w == 1 ? 1 : -1) * t) % l << '\n';
        poss.push_back((x + (w == 1 ? 1 : -1) * t + 1ll * l * t) % l);
    }
    if(rs.empty()){
        for(int i=0;i<n;i++){
            cout << poss[i] << '\n';
        }
        return 0;
    }
    prints(poss);
    int cols = t / l * 2 * ls.size();
    t %= l;
    for(int lpos : ls){
        int p0 = rs[0] + t,
            p1 = lpos - t;
        if(rs[0] > lpos){
            p1 += l;
        }
        if(p0 < p1){
        }else if(p0 >= p1 + l){
            cols += 2;
            prints(p0, p1, cols);
        }else{
            cols++;
        }
    }
    printd(cols);
    int antPos0 = (idx0 + cols) % n;
    sort(poss.begin(), poss.end());
    int idx = 0;
    while(poss[idx] != pos0){ idx++; }
    if(poss[(idx + 1) % n] == pos0){
        idx = (idx + 1) % n;
    }
    printd(idx, pos0);
    vector<int> anss(n);
    for(int i=0;i<n;i++){
        anss[antPos0] = poss[idx];
        antPos0 = (antPos0 + 1) % n;
        idx = (idx + 1) % n;
    }
    for(int i=0;i<n;i++){
        cout << anss[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 2676
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
int MOD=1000000007;
signed main(){
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    bool flag=true;
    int odd=0;
    rep(i,n){
        if(a[i]%2==1)odd++;
    }
    flag=odd%2==0;
    if(flag){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1152
//b.c B-1 Dimensional Woeld's Tale
#include<stdio.h>
#include<stdbool.h>

int arrmax(int n,int a[]){
    int max = a[0];
    for(int i=0;i<n;++i){
        if(a[i]>max){
            max = a[i];
        }
    }
    return max;
}

int arrmin(int n,int a[]){
    int min = a[0];
    for(int i=0;i<n;++i){
        if(a[i]<min){
            min = a[i];
        }
    }
    return min;
}

int main(void){
    int n,m,x,y;
    bool flag = false;
    scanf("%d %d %d %d",&n,&m,&x,&y);
    int x1[n],y1[m];
    for(int i=0;i<n;++i){
        scanf("%d",x1+i);
    }
    for(int i=0;i<m;++i){
        scanf("%d",y1+i);
    }

    for(int i=x+1;i<=y;++i){
        if(arrmax(n,x1)<i&&arrmin(m,y1)>=i){
            flag = true;
        }
    }

    if(flag){
        printf("No War\n");
    }else{
        printf("War\n");
    }
    return 0;
}


Measured memory_bytes: 128
from collections import deque

N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
q = deque()
done = [-1]*N
done[0] = 1
q.appendleft(0)
while q:
    now = q.pop()
    for to in G[now]:
        if done[to] != -1: continue
        done[to] = now+1
        q.appendleft(to)
print("Yes")
print(*done[1:], sep="\n")


Measured memory_bytes: 38536
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
using ll = long long;
using P = pair<int, int>;

const int mod = 998244353;
struct mint {
  ll x; 
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

mint f(int n){ 
  if(n == 0)return 1;
  mint x = f(n / 2); 
  x *= x; 
  if(n % 2 == 1)x *= 2;
  return x;
}

mint choose(int n, int a){
  mint x = 1, y = 1;
  for(int i = 0; i < a; ++i){
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

mint dp[3010][3010][3];

int main(){
  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  for(int i = 0; i < n; ++i){
  	cin >> a[i];
  }

  fill((mint*)dp, (mint*)dp + sizeof(dp) / sizeof(mint), 0);
  dp[0][0][0] = 1;
  for(int i = 0; i < n; ++i){
    for(int j = 0; j <= s; ++j){
      dp[i + 1][j][0] += dp[i][j][0];
      dp[i + 1][j][1] += dp[i][j][0] + dp[i][j][1];
      dp[i + 1][j][2] += dp[i][j][0] + dp[i][j][1] + dp[i][j][2];
      if(j + a[i] <= s){
        dp[i + 1][j + a[i]][1] += dp[i][j][0] + dp[i][j][1];
        dp[i + 1][j + a[i]][2] += dp[i][j][0] + dp[i][j][1];
      }
    }
  }

  cout << dp[n][s][2].x << endl;
  
  return 0;
}


Measured memory_bytes: 212736
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    string S;
    cin >> S;
    char s = S.at(S.size()-1);
    if(s=='s') cout << S << "es" << endl; 
    else cout << S<< "s" << endl;
    return 0;
}

Measured memory_bytes: 3628
/**-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*                                                               *-*
*-*                  Bismillahir Rahmanir Rahim                   *-*
*-*                                                               *-*
*-*                  Author: Ahsan Habib (comrade)                *-*
*-*                    Metropolitan University                    *-*
*-*                         Language: C++                         *-*
*-*                                                               *-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**/
#include<bits/stdc++.h>
#include<istream>
#include<cstdio>
#define pii          pair<ll,ll >
#include<string>
#define In freopen("ahsan.txt","r",stdin);
#define ll long long
#define ff first
#define ss second
#define NO cout<<"NO"<<endl
#define m1 cout<<"-1"<<endl
#define No cout<<"No"<<endl
#define cinarr0(n) for(int i = 0;i<n;i++)cin>>a[i];
#define cinarr1(n) for(int i = 1;i<=n;i++)cin>>a[i];
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define pb push_back
#define sorta(a) sort(a,a+n)
#define sortv(v)  sort(v.begin,v.end())
#define bug(a) cerr << #a << " : " << a << endl
#define all(v) (v.begin(), v.end())
#define   sz(x)       x.size()
#define fill(x, y) memset(x, y, sizeof(x))
const int mx = 1e6+5;
using namespace std;
ll a[200010],m,ans,i,t,k,ev=0,od=0,tt=0,n,cas = 1;
vector<int>vec[mx];
int ar[10000][10000];
vector<pii>v;
bool ok = true;
int main()
{

    // In;
    //ios::sync_with_stdio(false);
    //  cin.tie(0);
    string s1,s2;
    cin>>s1>>s2;
    int ans = 0;
    for(int i = 0 ; i <=s1.size() - s2.size(); i++)
    {
        int cnt = 0;
        for(int j = 0; j<s2.size(); j++)
        {
            if(s1[j+i]==s2[j])cnt++;
        }
        ans = max(ans,cnt);
    }
    cout<< s2.size() - ans<<endl;

    return 0;
}


Measured memory_bytes: 27052
from collections import deque
import operator

import sys

stack = deque()
operators = {
    '+': operator.add,
    '-': operator.sub,
    '*': operator.mul,
    '/': operator.truediv
}

for line in sys.stdin:
    for term in line.split():
        if term in operators:
            a, b = stack.pop(), stack.pop()
            stack.append(operators[term](b, a))
        else:
            stack.append(float(term))
    print(stack.pop())

Measured memory_bytes: 7660
S_list = list(input())

for i in range(0, len(S_list), 2):
    if S_list[i] == 'R' or S_list[i] == 'U' or S_list[i] == 'D':
        pass
    else:
        print('No')
        exit()

for i in range(1, len(S_list), 2):
    if S_list[i] == 'L' or S_list[i] == 'U' or S_list[i] == 'D':
        pass
    else:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 9036
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;

typedef long long ll;

void factorize(vector<ll> &p,vector<ll> &cnt,ll x) {
    p.clear(); cnt.clear();
    if(x <= 1) {
        p.push_back(1);
        cnt.push_back(1);
        return;
    }

    ll lim = (ll)sqrt(x);

    if(x%2 == 0) {
        p.push_back(2);
        cnt.push_back(0);
        while(x%2 == 0) {
            cnt[0]++;
            x /= 2;
        }
    }

    ll pp = 3;
    while(true) {
        if(x <= 1) break;
        if(pp > lim) {
            p.push_back(x);
            cnt.push_back(1);
            break;
        }
        if(x % pp == 0) {
            p.push_back(pp);
            cnt.push_back(0);
            while(x%pp == 0) {
                cnt[cnt.size()-1]++;
                x /= pp;
            }
        }
        pp += 2;
    }
    return;
}

int main() {
    int base;
    string a;
    while(cin>>base>>a, base) {
        unsigned long long m = 0;
        for(int i=0; i<a.length(); ++i) {
            m *= base;
            if(a[i] <= '9') m += a[i] - '0';
            else m += a[i] - 'A' + 10;
        }

        vector<ll> p,cnt;
        factorize(p,cnt,base);

        vector<ll> pp(p.size(), 0);
        for(int i=0; i<p.size(); ++i) {
            ll n = p[i];
            while(n <= m) {
                pp[i] += m/n;
                n *= p[i];
            }
        }

        ll ans = 1ll<<62;
        for(int i=0; i<p.size(); ++i) ans = min(ans, pp[i]/cnt[i]);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 936
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define nl cout<<"\n"
#define db(x) cout<<x<<" "
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define fk(a,b) for(int k=a;k<b;k++)
#define F first
#define S second
#define UM unordered_map<int,int>
#define MP map<int,int>
void fun(){
	ll n;
	cin>>n;
	cout<<n+n*n+n*n*n<<"\n";
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	// cin>>t;
	while(t--){
		fun();
	}
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w, h, c;
    cin >> w >> h >> c;
    cout << (w / __gcd(w, h)) * (h / __gcd(w, h)) * c << endl;
}



Measured memory_bytes: 3132
R,G,B,N=[int(i) for i in input().split(" ")]

count=0
for r in range(N//R+1):
    for g in range(N//G+1):
        _b=N-r*R-g*G
        if _b<0:
            break
        if _b%B==0:
            count+=1
print(count)


Measured memory_bytes: 2940
H,W = map(int,input().split())
l = [list(input()) for i in range(H)]
#print(H,W,l)


wlist = []
hlist = []
harray = []
for i in range(H):
    flag = 0
    for j in range(W):
        if l[i][j] == "#":
            flag = 1
    if flag == 1:
        hlist.append(i)
for i in hlist:
    harray.append(l[i])
H = len(harray)

for i in range(W):
    flag = 0
    for j in range(H):
        if harray[j][i] == "#":
            flag = 1
    if flag == 0:
        wlist.append(i)
for i in wlist:
    for j in range(H):
        harray[j][i] = "n"

for i in harray:
    for x in i:
        if x != "n":
            print(x,end="")
    print()

Measured memory_bytes: 43624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int N, T;
ll t[200100];

int main(void) {
	cin >> N >> T;
	rep(i, N) cin >> t[i];
	t[N] = INFF;

	ll ans = 0;
	rep(i, N) {
		if(t[i + 1] - t[i] >= T) ans += T;
		else ans += t[i + 1] - t[i];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1792