akhauriyash/Code-Regression huggingface dataset:
s = input()
t = input()
len_t = len(t)
max_c = len(t)
for i in range(len(s) - len_t + 1):
    a = 0
    for j in range(i , i + len_t):
        if t[j - i] != s[j]:
            a += 1
            
    # print(a)
    max_c = min(a, max_c)
print(max_c)
  

Measured memory_bytes: 9120
/* Oh, Lady Moon, shine down a little people magic if you will */

#include <iostream>

#include <vector>

#include <algorithm>

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

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

#define rip(i,a,b) for(int i=(int)a; i>=(int)b; i--)

#define pb push_back

#define mp make_pair

#define fst first

#define snd second

#define sz(x) int(x.size())

#define all(v) (v).begin(), (v).end()

#define trace(x) cerr << #x << ": " << x <<endl;

int const MOD = 1e9+7;

using namespace std;



typedef long long int lli;

typedef pair<lli, lli> ii;

typedef vector<int> vi;

typedef vector<ii> vii;


lli dp[22][1<<22];


int main(){

    fastio;
    int A[25][25];

	int n; cin>>n;
	rep(i, 0, n) rep(j, 0, n) cin>>A[i][j];
	rep(i, 0, n) if(A[0][i]) dp[0][1<<i]=A[0][i];
	rep(i, 1, n) rep(j, 0, n) if(A[i][j]) rep(k, 0, 1<<n) if(!((1<<j)&k)){
		dp[i][k|1<<j] = (dp[i][k|1<<j] + dp[i-1][k])%MOD;
	}
	cout<<dp[n-1][(1<<n)-1]<<endl;

    return 0;

}

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

using namespace std;

typedef long long ll;
int main(){
    ll n , t; cin >> n >> t;
    vector<ll> ta(n); for(ll i = 0 ; i < n ; i ++) cin >> ta[i];
    
    ll ans = t;
    for(ll i = 0 ; i < n - 1; i ++){
        ans += min(t , ta[i + 1] - ta[i]);
    }
    
    cout << ans << endl;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
typedef long long ll;
using namespace std;

int main(){

    int n, a, b; cin >> n >> a >> b;
    cout << min(a, b) << ' ';
    cout << max(a + b - n, 0) << endl;

}

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

int main(){
  string S;
  cin >> S;
  while(true){
    S.erase(S.end()-1);
    int len=S.size();
    if(len%2==0){
      if(S.substr(0, len/2)==S.substr(len/2,len/2)){
        cout << len << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LOCAL
#pragma region Macros
typedef long long ll;
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; string S; cin >> N >> S;
    vector<vector<int>> sum(2,vector<int>(N+1,0));
    for (int i=0;i<N;++i){
        sum[0][i+1]=sum[0][i];
        sum[1][i+1]=sum[1][i];
        ++sum[(S[i]=='R')][i+1];
    }
    int ans=N;
    for (int i=0;i<=N;++i){
        chmin(ans,max(sum[0][i],sum[1][N]-sum[1][i]));
    }
    cout << ans << '\n';
}

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

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

lldo n;

int main() {
	cin >> n;
	cout << ceil(n / 2) << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N ;
  int sum=0;

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

 }
  
     cout<< sum <<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
ll gcd(ll a,ll b){
	if(b==0)
	return a;
	return gcd(b,a%b);
}
string toBin(ll a) {
	string res = "";
	while (a) {
		res += char((a & 1) + '0');
		a >>= 1;
	}
	reverse(res.begin(), res.end());
	return res;
}
const int mod = 1e9+7;
ll expo(ll base,ll pow){
    ll ans = 1;
    while(pow!=0){
        if(pow&1==1){
            ans = ans*base;
            ans = ans%mod;
        }
        base *= base;
        base%=mod;
        pow/=2;
    }
    return ans;
}
ll inv(ll x){
    return expo(x,mod-2);
}
bool isPal(string ss){
    int len = ss.length();
    for(int i = 0 ; i<len/2 ; i++){
	int comp = len-i-1;
	if(ss[i]!=ss[comp])
		return false;
	}
    return true;
}
double pi = 3.141592653589793238462643;
double error = 0.0000001;
/* -------Template ends here-------- */

const int M = 100001;
char red[501][501] , blue[501][501] , mat[501][501];
int main(){
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    int n , m;
    si(n);  si(m);
    for(int i = 0 ; i<n ; i++){
        for(int j = 0 ; j<m ; j++){
            cin>>mat[i][j];
            red[i][j] = mat[i][j];
            blue[i][j] = mat[i][j];
        }
    }
    for(int i = 0 ; i<n ; i++){
        red[i][0] = '#';
        blue[i][m - 1] = '#';
    }
    for(int i = 0 ; i<n ; i++){
        if(i%2 == 0){
            for(int j = 0 ; j<m - 1 ; j++){
                red[i][j] = '#';
            }
        }
        else{
            for(int j = 1 ; j<m ; j++){
                blue[i][j] = '#';
            }
        }
    }


    for(int i = 0 ; i<n ; i++){
        for(int j = 0 ; j<m ; j++){
            cout<<red[i][j]<<"";
        }
        cout<<endl;
    }

    cout<<endl;

    for(int i = 0 ; i<n ; i++){
        for(int j = 0 ; j<m ; j++){
            cout<<blue[i][j]<<"";
        }
        cout<<endl;
    }













}














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

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



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

using namespace std;

int main(void)
{
	int a,b,c,d,e,k;

	cin>>a>>b>>c>>d>>e>>k;

	if((e-a)<=k) cout<<"Yay!"<<endl;
	else cout<<":("<<endl;

	return 0;
}


Measured memory_bytes: 256
def main():
    from itertools import product

    N = int(input())

    g = []
    for _ in range(N):
        a = int(input())
        t = []
        for _ in range(a):
            x, y = map(int, input().split())
            x -= 1
            t.append((x, y))
        g.append(t)

    def is_ok(prd):
        for j, bl in enumerate(prd):
            if bl:
                for x, y in g[j]:
                    if prd[x] != y:
                        return False
        return True

    ans = 0
    for prd in product([0, 1], repeat=N):
        *prd, = prd  # list化
        if is_ok(prd):
            ans = max(ans, prd.count(1))
    print(ans)


if __name__ == '__main__':
    main()

# bit演算しようとしてはまった


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 
const int mod = 1e9 + 7, mxn = 1e5 + 1;

int solve(){
	int a;
	cin>> a;
	int ans = a + a*a + a*a*a;
	cout<< ans<< "\n";
	return 0;
}
 
int main()
{
    fast;
    int t = 1;
    //cin>> t;
    while(t--){  
        solve();
    }
    return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*  inv[1] = 1; // inv is ll
    for(int i=2; i<=mxn; ++i)
        inv[i]=mod-mod/i*inv[mod%i]%mod;*/
        
// lower bound   >=  
// upper bound   >
// vector<int>().swap(vec); //free memory from vec


Measured memory_bytes: 3648
N = int(input())
ans = [0]*(N+1)
MAX = 101
for x in range(1, MAX):
    for y in range(1, MAX):
        for z in range(1,MAX):
            temp = (x+y+z)**2 - x*y - y*z - z*x
            if temp <= N :
                ans[temp] +=1 

for i in range(1,N+1):
    print(ans[i])

Measured memory_bytes: 9244
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,M;
  cin>>N;
  int T[N];
  REP(i,N)cin>>T[i];
  cin>>M;
  int P[M];
  int X[M];
  REP(i,M)cin>>P[i]>>X[i];
  int sum=0;
  REP(i,N)sum+=T[i];
  REP(i,M){
    cout<<sum-T[P[i]-1]+X[i]<<endl;
  }
  return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

vi g[MAXN];
vi sorted;
int ind[MAXN];
int used[MAXN];
int ans[MAXN];

void dfs(int s) {
	used[s] = 1;
	REP(i, 0, SZ(g[s])) {
		int to = g[s][i];
		if (!used[to]) {
			dfs(to);
		}
	}
	sorted.pb(s);
}

void solve(){
	int n, m, a, b;
	scanf("%d%d", &n, &m);
	m += n - 1;
	REP(i, 0, m) {
		scanf("%d%d", &a, &b);
		g[a].pb(b);
	}
	REPN(i, 1, n) {
		if (!used[i]) {
			dfs(i);
		}
	}
	REP(i, 0, n) {
		ind[sorted[i]] = i;
	}
	REPN(i, 1, n) {
		ans[i] = INF;
	}
	REPN(i, 1, n) {
		/*REPN(j, 1, n) {
			printf("%d ", ans[j]);
		}
		putchar('\n');*/
		REP(j, 0, SZ(g[i])) {
			int to = g[i][j];
			ans[to] = min(ans[to], ind[i]);
		}
	}
	REPN(i, 1, n) {
		if (ans[i] == INF) {
			printf("0\n");
		} else {
			printf("%d\n", sorted[ans[i]]);
		}
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 13812
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#include<typeinfo>
#define R(i, n) for(int i = 0;i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", &a[i])
#define SAL(i, n, a) R(i, n) scanf("%lld", &a[i])
#define SC(a) scanf("%c", &a)
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
#define PY printf("YES")
#define PN printf("NO")
#define Py printf("Yes")
#define Pn printf("No")
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;
const double PI = acos(-1);

int N;

ll safeInput(ll a) {
	if (a != 0)return 1000000000000000000LL / a;
	else return 0;
}

int main(){
	S(N);
	ll a = 1;
	bool f = true;
	R(i, N) {
		ll n;
		SL(n);
		if (n == 0) {
			P(0);
			return 0;
		}
		if (n <= safeInput(a)) a *= n;
		else f = false;
	}
	if (f) PL(a);
	else P(-1);
} 

Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <string>
#include <map>
#include <algorithm>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <ctime>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define ff first
#define ss second

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, mod = 1e9 + 7;
  	cin >> n;
  	ll v1 = 1, v2 = 1, v3 = 1;
  	for (int i = 1; i <= n; i++) {
    	v1 *= 9;
      	v1 %= mod;
      	v2 *= 8;
      	v2 %= mod;
      	v3 *= 10;
      	v3 %= mod;
    }
  	v1 *= 2;
  	v1 %= mod;
  	ll ans = v1 - v2;
  	ans = v3 - ans;
  	if (ans < 0)
    	ans += mod;
 	cout << ans;
    return 0;
}

Measured memory_bytes: 3620
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
 public static void main(String[] args){
	 int n;
	 int k = new java.util.Scanner(System.in).nextInt();
	 String str;
	 Pattern p = Pattern.compile("3");
	
	 for(n=1;n<=k;n++){
		 str  = String.valueOf(n);
		 Matcher m = p.matcher(str);
		 if(n%3==0||m.find()){
			 System.out.print(" "+n);
		 }
		
	 }
	 System.out.println();
 }
}

Measured memory_bytes: 31396
#include<stdio.h>
signed main(void)
{
  int X,N,a,left=0,right=100,P[102]={};
  if(scanf("%d %d",&X,&N)>0)
  {
    if(N==0)return printf("%d\n",X),0;
    for(int i=0;i<102;i++){P[i]=i;}
    while(N--){if(scanf("%d",&a)==1){P[a]=102;}}
    for(int i=X;i>=0;i--){if(P[i]==102){continue;}left=i;break;}
    for(int i=X;i<102;i++){if(P[i]==102){continue;}right=i;break;}
    return printf("%d\n",(X-left<=right-X)?left:right),0;
  }
}

Measured memory_bytes: 1736
n, k = gets.split.map(&:to_i)
h = n.times.map{gets.to_i}
h.sort!
d = 9999999999
for i in 0..(n-k)
  d = h[i+k-1] - h[i] if d > h[i+k-1] - h[i]
end
puts d

Measured memory_bytes: 4016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<ll,ll> pi;
#define inf 1000000000000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define ss second
#define pb push_back
#define mp make_pair

int a, b, c, d;


int main(){

ios::sync_with_stdio(0);
cin.tie(0);

cin >> a >> b >> c >> d;

a= min(a, b);
c= min(d, c);

cout << a +c << endl;



return 0;
}


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

using namespace std;

#define int long long



main(){


	vector <int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k; cin >> k;

	cout << a[k - 1] << endl;
	


	return 0;
}

Measured memory_bytes: 256
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi 3.1415926535
# define eps 1e-3
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline int Scan() {
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
const int N=100005;
//Code begin...

int a[N];

int main ()
{
    int n, ans=0;
    scanf("%d",&n);
    FOR(i,1,n) scanf("%d",a+i);
    int flag=0, num=0;
    FOR(i,1,n) {
        if (flag==0) {
            if (num==0) ++ans;
            if (num==0||a[i]==a[i-1]) num=a[i];
            else if (a[i]>a[i-1]) num=a[i], flag=1;
            else num=a[i], flag=-1;
        }
        else if (flag==-1) {
            if (a[i]<=a[i-1]) num=a[i];
            else ++ans, num=a[i], flag=0;
        }
        else {
            if (a[i]>=a[i-1]) num=a[i];
            else ++ans, num=a[i], flag=0;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
import scala.io.StdIn._
object Main extends App {

  val Array(n, k) = readLine.trim.split(' ').map(_.toInt)
  val books = Array.fill(10){Nil: List[Int]}
  for (_ ← 0 until n) {
    val Array(c, g) = readLine.trim.split(' ').map(_.toInt)
    books(g - 1) ::= c
  }
  for (i ← books.indices) books(i) = books(i).sorted(Ordering.Int.reverse)
  val bonus = books.map{_.size}
  val maxPrice = Array.fill(k + 1){0L}
  for (g ← books.indices) {
    for (i ← maxPrice.indices.reverse) {
      var t = 1
      var sum = 0
      for (p ← books(g) if i + t < maxPrice.length) {
        sum += p
        if (maxPrice(i + t) < maxPrice(i) + sum + (t - 1) * t) {
          maxPrice(i + t) = maxPrice(i) + sum + (t - 1) * t
        }
        t += 1
      }
    }
  }
  println(maxPrice.max)
}


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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  int n;

  scanf("%d",&n);

  int a[n];
  int l = 1000;
  int u = -1000;
  REP (i, n) {
    scanf("%d",&a[i]);
    l = min(l, a[i]);
    u = max(u, a[i]);
  }

  int ans = 1000000000;
  FOR(i, l, u + 1) {
    int acc = 0;
    REP (j, n) {
      acc += (a[j] - i) * (a[j] - i);
    }
    ans = min(ans, acc);
  }
  printf("%d\n",ans);
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;


  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  printf(" %d",u->key);
 if(u->left!=NIL)preorder(u->left);
  if(u->right!=NIL)preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }

  return 0;
}

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

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

	vector<vector<int>> A( n, vector<int>( m ) );
	for( int i = 0; i < n; ++i ) {
		for( auto& v: A[i] ) { cin >> v; }
	}

	vector<int> b( m );
	for( auto& v: b ) { cin >> v; }

	vector<int> result( n );

	for( int i = 0; i < n; ++i ) {
		for( int j = 0; j < m; ++j ) {
			result[i] += A[i][j] * b[j];
		}
	}

	for( auto& v: result ) { cout << v << endl; }
}



Measured memory_bytes: 3164
let e = "EQUAL" and g = "GREATER" and l = "LESS"

let f s1 s2 =
  let rec aux i =
    if s1 = s2 then e
    else if s1.[i] > s2.[i] then g
    else if s1.[i] < s2.[i] then l
    else aux (i + i)
  in
  aux 0

let () =
  let a = read_line () and b = read_line () in
  ( if String.length a > String.length b then g
    else if String.length a < String.length b then l
    else if a = b then e
    else f a b )
  |> print_endline

Measured memory_bytes: 384
N,X,Y = map(int, input().split())


ans = [0] * (N)
for i in range(1, N):
    for j in range(i+1, N+1):
        #ans[j-i] += 1
        if (j - i) > abs(X - i) + abs(j - Y) + 1:
            ans[abs(X - i) + abs(j - Y) + 1] += 1
        else:
            ans[j-i] += 1
           # ans[j-i] -= 1

        #print("--", i,j, ans)


print(*ans[1:], sep="\n")

Measured memory_bytes: 3444
n=int(input())
a=list(map(int, input().split()))
q=int(input())
bc=[]

for i in range (q):
    bc.append(list(map(int, input().split())))
num=[0]*(10**5+1)
for i in range(n):
    x=a[i]
    num[x]+=1

kk=0
for l in range(10**5+1):
    kk+=l*num[l]

for k in range (q):
    b=bc[k][0]
    c=bc[k][1]
    kk+=c*num[b]-b*num[b]
    num[c]+=num[b]
    num[b]=0
    print(kk)


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  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
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

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

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


  for(int i = 1; i <= 1000; ++i) {
    if(i*(i+1)/2 == n) {
      cout << "Yes" << endl;
      int k = i+1;
      int s = i;
      cout << k << endl;
      int count = 1;
      vector<vector<int>> ans(k);
      rep(i, k) {
        rep(j, s-i) {
          ans[i].push_back(count);
          ans[i+j+1].push_back(count);
          ++count;
        }
      }
      rep(i, k) {
        cout << s << " ";
        line_out(ans[i]);
      }
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 4104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++)
    cin>>A[i];
  int max1=0;
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++)
      max1=max(max1,abs(A[i]-A[j]));
  }
  cout<<max1<<endl;
      
}
 
  


Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

char S[100];
char youbi[10][10]={
    "SUN","MON","TUE","WED","THU","FRI","SAT" 
};
signed main(){
    scanf("%s",&S);
    int ans=0;
    rep(i,7){
         //printf("%s\n",youbi[i]);
        if(strcmp(youbi[i],S)==0){
            printf("%lld\n",7-i);
        }
    }
    return 0;
}


Measured memory_bytes: 128
program main
   implicit none
   integer(8):: n,han(97:122)=0,i,ans=1
   character(100000)::s
   read(*,*)n
   read(*,*)s
   do i=1,n
      han(iachar(s(i:i)))=han(iachar(s(i:i)))+1
   enddo
   do i=97,122
      ans=mod(ans*(han(i)+1),10**9+7)
   enddo
   ans=ans-1
   write(*,*)ans
end program main


Measured memory_bytes: 700
n = int(input())
p = list(map(int, input().split()))
p_min = [10 ** 18 for _ in range(n)]

p_min = p[0]
count = 1
for i, p_i in enumerate(p):
    if 0 == i:
        continue
    p_min = min(p_i, p_min)
    if p_i == p_min:
        count += 1
print(count)


Measured memory_bytes: 24744
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;

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

int main(){
    set<int> sts;
    set<int, greater<int> > stl;

    int N, K;
    cin >> N >> K;
    int p[210000];

    for(int i = 0; i < N; i++){
        cin >> p[i];
    }

    int res = 0;
    for(int i = 0; i < K; i++){
        sts.insert(p[i]);
        stl.insert(p[i]);
    }

    int sign[210000];
    fill(sign, sign+210000, 0);
    for(int i = 0; i < N-1; i++){
        if(p[i] < p[i+1]){
            sign[i] = 1;
        }
    }

    int x = 0;
    int s = 0;
    for(int i = 0; i < K-1; i++){
        s += sign[i];
    }
    if(s == K-1){
        x++;
    }
    else{
        res++;
    }

    for(int i = 1; i < N-K+1; i++){
        sts.insert(p[i+K-1]);
        stl.insert(p[i+K-1]);

        s -= sign[i-1];
        s += sign[i+K-2];
        if(p[i-1] <= *(sts.begin()) && p[i+K-1] >= *(stl.begin())){
            res += 0;
        }
        else if(s == K-1){
            x++;
        }
        else{
            res++;
//            cout << i << endl;
        }
        sts.erase(p[i-1]);
        stl.erase(p[i-1]);
    }

    if(x >= 1){
        res++;
    }
    cout << res << endl;


    return 0;
}


Measured memory_bytes: 20736
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MAX 300005
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1'000'000'000'000'000'000ll;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}

const int MAXN=305;
ll arr[MAXN][MAXN];
int main()
{
	fast();
	ll n,m,l,i,j,k,a,b,w;
	cin>>n>>m>>l;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
		{
			if(i==j)
				arr[i][j]=0;
			else
				arr[i][j]=INF64;
		}
	while(m--)
	{
		cin>>a>>b>>w;
		arr[a][b]=w;
		arr[b][a]=w;
	}
	for(k=1;k<=n;k++)
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				arr[i][j]=min(arr[i][j],arr[i][k]+arr[k][j]);
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
		{
			if(i==j)
				arr[i][j]=0;
			else
			{
				if(arr[i][j]>l)
					arr[i][j]=INF64;
				else
					arr[i][j]=1;
			}
		}
	for(k=1;k<=n;k++)
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				arr[i][j]=min(arr[i][j],arr[i][k]+arr[k][j]);
	ll q;
	cin>>q;
	while(q--)
	{
		ll x,y;
		cin>>x>>y;
		if(arr[x][y]==INF64)
			cout<<"-1"<<endl;
		else
			cout<<arr[x][y]-1<<endl;
	}
}

Measured memory_bytes: 1408
import sys
input = sys.stdin.readline
n = int(input())
v = input().split()
c = input().split()
s = []
for i in range(n):
    v[i] = int(v[i])
    c[i] = int(c[i])
    s.append(v[i] - c[i])
s.sort(reverse=True)
l = 0
sum = 0
while (l < n and s[l] > 0):
    sum += s[l]
    l += 1
print(sum)

Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    unordered_map<string,ll> mp;
    set<string> st;
    ll n;
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
        st.insert(s);
    }
    ll ans=0;
    for(auto t:st)
    {
        ans+=((mp[t]*(mp[t]-1))/2);
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 20004
import collections

def simu(s,i):
    temp = s
    counter = 0
    while len(collections.Counter(temp)) != 1:
        another = []
        for k in range(len(temp)-1):
            if temp[k] == i or temp[k+1] == i:
                another.append(i)
            else:
                another.append(temp[k])
        temp = another
        counter += 1
    return counter

s = list(input())
c = collections.Counter(s)
mini = 10000
for i in c:
    a = simu(s,i)
    if mini > a:
        mini = a
print(mini)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, C; cin >> N >> M >> C;
  int cnt = 0;
  int sum = 0;
  vector<vector<int>> A(N, vector<int>(M));
  vector<int> B(M);
  
  for(int i = 0; i < M; ++i) cin >> B.at(i);
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < M; ++j){
      cin >> A.at(i).at(j);
      sum += A.at(i).at(j) * B.at(j);
    }
    
    if(sum + C > 0) cnt++;
    sum = 0;
  }
  
  cout << cnt << endl;
  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(){
    int num, i;
    long long max=-1000000, min=1000000, fig[10000], sum=0;
        cin >> num;
    for(i=0; i<num; i++){
        cin >> fig[i]; 
    }
    for(i=0; i<num; i++){
        sum += fig[i];
        if(fig[i]>max)
            max = fig[i];
        if(fig[i]<min)
            min = fig[i];
    }
    cout << min << ' ' << max << ' ' << sum << endl;
    return 0; 
}

Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <list>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
int main(){
    vector<int> hoge, fuga;
    int n,temp;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> temp;
        hoge.push_back(temp);
        fuga.push_back(temp);
    }
    sort(fuga.begin(), fuga.end(), greater<int>());
    for(int i=0;i<n;i++){
        if(hoge.at(i)==fuga.at(0)) cout << fuga.at(1) << endl;
        else cout << fuga.at(0) << endl;
    }
}

Measured memory_bytes: 3436
#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<functional>

#define REP(i,n) for(int i=0;i<n;i++)
#define ll long long int

using namespace std;

int to_int(string s) {
  return atoi(s.c_str());
}

int main() {
  ll n;
  cin >> n;
  if (n%2 == 0) {
    cout << n << endl;
  } else {
    cout << n*2 << endl;
  }
}


Measured memory_bytes: 256
import sys
from collections import defaultdict

class UnionFind(object):
  def __init__(self,n):
    self.table=[-1]*N

  def find(self,x):
    parent=self.table[x]
    if parent<0:
      return x
    else:
      root=self.find(parent)
      self.table[x]=root
      return root

  def union(self,a,b):
    root1=self.find(a)
    root2=self.find(b)
    if root1<root2:
      self.table[root1]+=self.table[root2]
      self.table[root2]=root1
    else:
      self.table[root2]+=self.table[root1]
      self.table[root1]=root2

N,M=map(int,input().split())
A=[int(i) for i in input().split()]
uf=UnionFind(N)
for i in range(M):
  x,y=map(int,input().split())
  uf.union(x,y)
groups=defaultdict(list)
for j in range(N):
  groups[uf.find(j)].append(A[j])

groups = [sorted(g, reverse=True) for g in groups.values()]

if len(groups) == 1:
  print(0)
  sys.exit()

ans=0
cnt=[]
for group in groups:
  ans+=group.pop()
  cnt+=group

if len(groups)-2 > len(cnt):
  print("Impossible")
else:
  cnt.sort()
  ans+=sum(cnt[:len(groups)-2])
  print(ans)


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

int main()
{
    int N, M;
    cin >> N >> M;
    string S;
    cin >> S;

    vector<int> index_next0(N+1, -1);
    int tmp = N;
    for(int i=N; i>=0; i--){
        if(S[i]=='0') tmp = i;
        index_next0[i] = tmp;
    }

    stack<int> s;
    int itr = N;
    s.push(itr);
    while(true){
        int itr0 = itr - M;
        if(itr0 <= 0) break;
        itr0 = index_next0[itr0];
        if(itr <= itr0){
            cout<<"-1"<<endl;
            return 0;
        }
        s.push(itr0);
        itr = itr0;
    }
    tmp = 0;
    while(!s.empty()){
        auto v = s.top(); s.pop();
        cout<<(v - tmp)<<" ";
        tmp = v;
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 1356
#include <stdio.h>
#define MAX_N 100000
#define NIL -1

typedef struct node_ {
    int parent;
    int left;
    int right;
} Node;

Node T[MAX_N];

int getDepth(int u) {
    int d = 0;
    while (T[u].parent != NIL) {
        u = T[u].parent;
        d++;
    }
    return d;
}

void print(int u) {
    int i;
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("depth = %d, ", getDepth(u));

    if (T[u].parent == NIL) {
        printf("root, ");
    } else if (T[u].left == NIL) {
        printf("leaf, ");
    } else {
        printf("internal node, ");
    }

    int c = T[u].left;
    printf("[");
    for (i = 0; c != NIL; i++) {
        if (i) printf(", ");
        printf("%d", c);
        c = T[c].right;
    }
    printf("]\n");
}

int main(void) {
    int i, j, n;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        T[i].parent = NIL;
        T[i].left = NIL;
        T[i].right = NIL;
    }

    for (i = 0; i < n; i++) {
        int id, k, left;
        scanf("%d %d", &id, &k);
        for (j = 0; j < k; j++) {
            int c;
            scanf("%d", &c);
            if (j == 0) T[id].left = c;
            else T[left].right = c;
            left = c;
            T[c].parent = id;
        }
    }

    for (i = 0; i < n; i++) {
        print(i);
    }

    return 0;
}

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

int over(int j,int k)
{
	int count=0;
	while(j < k)
	{
		j *= 2;
		count++;
    }
    return count;
}
int main()
{
      int n,k;
      cin >> n >> k;
  
      double ans = 0.;
  
      for(int j = 1; j <= n;j++)
      {
		  int y = over(j,k);
		  int value = n * pow(2, y);
		  ans += (double)(1)/value;
	  }
	  cout << setprecision(15) << ans << endl;
}


Measured memory_bytes: 256
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-11;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 11100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	int a;scanf("%d",&a);
	printf("%d\n",(1000-a%1000)%1000);
}

Measured memory_bytes: 1736
#include <stdio.h>
#define MAX 100000

int A[MAX],n;

int par(int,int);

int main ()
{
  int i,q;

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

  q=par(0,n-1);

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

  return 0;
}

int par(int p,int r)
{
  int x,i,j,t;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++)
    {
      if(A[j]<=x)
	{
	  i++;
	  t=A[i];A[i]=A[j];A[j]=t;
	}
    }
  t=A[i+1];A[i+1]=A[r];A[r];A[r]=t;
  return i+1;
}




Measured memory_bytes: 2108
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define MSG(x) std::cout << #x << " : " << x << "\n";
using namespace std;
using lint = long long;
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; }

int main()
{
    int N, D;
    cin >> N >> D;

    if (N % ((2*D)+1) == 0)
        cout << N / ((2*D)+1) << endl;
    else
        cout << N / ((2*D)+1) + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define rrep(i,n) for (ll i = (n)-1; i >=0; --i)
#define ALL(a) a.begin(),a.end()
#define pb push_back
#define dame { puts("-1"); return 0;}
#define show(x) cerr<<#x<<" = "<<x<<endl;

using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<ll, ll>;

typedef vector<ll> vl;
typedef vector<pi> vp;
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 (a>b) { a=b; return 1; } return 0; }


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const ll mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  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;
  }

  // for prime mod
  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;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);



int main() {
  ll h,w,a,b;
  cin >> h>>w>>a>>b;

  rep(i, b){
    string l = "";
    rep(j, a) l += '0';
    rep(j, w-a) l += '1';
    cout << l << endl;
  }
  rep(i, h-b){
    string l = "";
    rep(j, a) l += '1';
    rep(j, w-a) l += '0';
    cout << l << endl;
  }
  
  //cout << l+1 << endl;
  return 0;
}


Measured memory_bytes: 4352
n, w = [int(i) for i in input().split()]
V, W = zip(*[[int(i) for i in input().split()] for j in range(n)])

dp = [[0]*(w+1) for i in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if W[i] <= j:
            dp[i+1][j] = max(dp[i][j], dp[i][j-W[i]]+V[i])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[n][w])


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

using namespace std;
typedef long long ll;

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; }

bool compare2(pair<ll, ll> a, pair<ll, ll> b)
{
  if(a.second != b.second)
    return a.second < b.second;
  else
    return a.first < b.first;
}

int main()
{
  int N;
  cin >> N;
  vector<pair<ll, ll>> p(N);
  for(int i=0; i<N; i++)
    {
      ll a, b;
      cin >> a >> b;
      p[i] = make_pair(a, b);
    }


  sort(p.begin(), p.end(), compare2);

  ll t=0;
  for(int i=0; i<N; i++)
    {
      t+=p[i].first;
      if(t>p[i].second)
	{
	  cout << "No" << endl;
	  return 0;
	}
    }
  cout << "Yes" << endl;
  
  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 3328