akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

main()
{ ll n,k,h[150000],dp[150000];
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
	cin>>h[i];
	dp[i]=1000000000;
}
dp[1]=0;
dp[0]=1000000000;
	
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=k and j<n;j++)
		if(i-j>0)
		dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
	}
cout<<dp[n];
}

Measured memory_bytes: 2304
//30
#include<iostream>
#include<set>
#include<string>
#include<algorithm>

using namespace std;

struct L{
  string s[10];
  string h;
  bool operator<(L a)const{
    return h<a.h;
  }
  void mh(){
    string ss;
    for(int i=0;i<4;i++){
      for(int j=0;j<2;j++){
	for(int i=0;i<5;i++){
	  swap(s[i*2],s[i*2+1]);
	}
	string t;
	for(int i=0;i<10;i++){
	  t+=s[i];
	}
	if(ss<t){
	  ss=t;
	}
      }
      string r[10];
      for(int i=0;i<5;i++){
	r[9-i*2]=s[i*2];
	reverse(r[9-i*2].begin(),r[9-i*2].end());
	r[i*2]=s[i*2+1];
      }
      copy(r,r+10,s);
    }
    h=ss;
  }
};

string s[10];
set<L> st;

void dfs(int d,int u,L c){
  if(d==10){
    c.mh();
    st.insert(c);
  }else{
    for(int i=0;i<10;i++){
      if(!(u>>i&1)){
	for(int k=0;k<2;k++){
	  reverse(s[i].begin(),s[i].end());
	  bool f=false;
	  for(int j=!(d&1);j<d;j+=2){
	    f|=c.s[j][d/2]==s[i][j/2];
	  }
	  if(!f){
	    L nc=c;
	    nc.s[d]=s[i];
	    dfs(d+1,u|1<<i,nc);
	  }
	}
      }
    }
  }
}

int main(){
  while(cin>>s[0],s[0]!="END"){
    for(int i=1;i<10;i++){
      cin>>s[i];
    }
    st.clear();
    dfs(0,0,L());
    cout<<st.size()/2<<endl;
  }
  return 0;
}

Measured memory_bytes: 1248
#include<iostream>
#include<string>
using namespace std;
int main()
{
    unsigned int a, b, i, sbef = 0, saft = 0;
    string s;
    cin >> a >> b >> s;
    for(i = 0; i < s.size(); i++){
        if(s[i] == '-') break;
        sbef += 1;
    }
    for(i = i + 1; i < s.size(); i++){
        if(s[i] == '-'){
            cout << "No" << endl;
            return 0;
        }
        saft += 1;
    }
    cout << (sbef == a && saft == b ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import math
def main():

    N = int(input())
    c = input()

    red = 0
    white = 0
    for i in range(N):
        if c[i] == "R": red += 1
        else: white += 1

    count = 0
    for i in range(red):
         if c[i] == "W": count += 1

    return count



if __name__ == '__main__':
    print(main())


Measured memory_bytes: 67716
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int n; cin >> n;
	int sum = 0;
	vector<int> a(n), b(n), c(n - 1);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	for (int i = 0; i < n-1; i++) cin >> c[i];

	for (int i = 0; i < n; i++)
	{
		sum += b[a[i]-1];
		if ((i > 0) && (a[i] == a[i - 1] + 1)) sum += c[a[i]-2];
	}

	cout << sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll MOD = 1000000007;
template <class T>
ll mod_pow(ll a, ll n, T mod) {
    mod = (ll)mod;
    ll res = 1, p = a % mod;
    while (n) {
        if (n & 1) res = res * p % mod;
        p = p * p % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, k;
    cin >> n >> m >> k;

    vector<ll> fact(n * m);
    fact[0] = 1;
    for (ll i = 1; i < n * m; ++i) {
        fact[i] = (fact[i - 1] * i) % MOD;
    }

    ll ans = 0;
    rep(i, m) { (ans += i * (m - i) * n * n) %= MOD; }
    rep(i, n) { (ans += i * (n - i) * m * m) %= MOD; }
    (ans *= fact[n * m - 2]) %= MOD;
    (ans *= mod_pow(fact[n * m - k], MOD - 2, MOD)) %= MOD;
    (ans *= mod_pow(fact[k - 2], MOD - 2, MOD)) %= MOD;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int n,m,tot,ha,ans=0x77777777;
int pri[50],cnt[50];
void dfs(int now,int cj){
	if(now>tot){
		if(ans>cj&&cj>=n)ans=cj;
		return;
	}
	dfs(now+1,cj);
	for(int i=1;i<=cnt[now];i++)
	cj*=pri[now],dfs(now+1,cj);
}
int main(){
	scanf("%d%d",&n,&m);ha=m;
	for(int i=2;i*i<=m;i++)
	if(m%i==0){
		pri[++tot]=i;
		while(m%i==0)m/=i,cnt[tot]++;
	}
	if(m!=1)pri[++tot]=m,cnt[tot]=1;
	dfs(1,1);
	printf("%d\n",ha/ans);
}

Measured memory_bytes: 256
n =  int(input())
cnt = 0
p = [int(i) for i in input().split()]
for i in range(1,n-1):
	if (p[i] < p[i-1] and p[i] > p[i+1]) or (p[i] > p[i-1] and p[i] < p[i+1]):
		cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int A, B, C; cin >> A >> B >> C;
  int ans = min(B/A, C);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
while True:
    m,f,r=map(int,input().split())
#    print(m,f,r)
    if(m,f,r)==(-1,-1,-1):
        break
    if m==-1 or f==-1 or m+f<30:
        print('F')
    elif m+f>=80:
        print('A')
    elif 65<=m+f<80:
        print('B')
    elif 50<=m+f<65 or r>=50:
        print('C')
    elif 30<=m+f<50:
        print('D')


Measured memory_bytes: 5596
#include <functional>
#include <cstring>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<int> adj[n];
    while (m--) {
        int a, b; cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    int q; cin >> q;
    int v[q], d[q], c[q];
    for (int i = 0; i < q; i++) cin >> v[i] >> d[i] >> c[i];
    int col[n][11], time[n][11];
    memset(col, 0, sizeof(col));
    memset(time, 0, sizeof(time));
    function<void(int, int, int, int)> dfs = [&](int v, int d, int c, int t) {
        col[v][d] = c;
        time[v][d] = t;
        if (d == 0) return;
        for (int u : adj[v]) if (col[u][d-1] == 0) dfs(u, d-1, c, t);
    };
    for (int i = q-1; i >= 0; i--)
        if (col[v[i]-1][d[i]] == 0) dfs(v[i]-1, d[i], c[i], i);
    for (int i = 0; i < n; i++) {
        int ans = 0, t = -1;
        for (int d = 0; d <= 10; d++)
            if (t < time[i][d] && col[i][d] > 0) {
                t = time[i][d];
                ans = col[i][d];
            }
        cout << ans << endl;
    }
}


Measured memory_bytes: 16248
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;


int main () {

  ll ans = 1; // APPROVED

  ll N;
  cin >> N;
  ll temp;
  REP(i, 0, N) {
    cin >> temp;
    if ( temp % 2 == 0 ) {
      if ( (temp % 3 == 0) or (temp % 5 == 0) ) {
        // do nothing
      }
      else {
        ans = 0; // DENIED
      }
    }
  }

  if (ans == 1) {
    cout << "APPROVED" << endl;
  }
  else {
    cout << "DENIED" << endl;
  }

  return 0;
}


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

#define MX_N 100000
#define LL long long

const LL M=1e9+7;

int n;
LL dp[MX_N+5][2];
vector<int> graph[MX_N+5];
bool visited[MX_N+5];

void dfs( int v )
{
    visited[v]=true;
    dp[v][0]=dp[v][1]=1;

    for( auto &u : graph[v] )
    {
        if( !visited[u] )
        {
            dfs(u);
            dp[v][0]=( dp[v][0]*( (dp[u][0]+dp[u][1]) )%M )%M;
            dp[v][1]=( dp[v][1]*dp[u][0] )%M;
        }
    }
}

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

    cin>>n;
    for( int i=1; i<n; i++ )
    {
        int a, b; cin>>a>>b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    dfs(1);

    cout<<(dp[1][0]+dp[1][1])%M<<"\n";
}


Measured memory_bytes: 11520
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();		
		String s = sc.next();
        long r = 0;
        long g = 0;
        long b = 0;
        for(int i=0;i<a;i++){if(s.charAt(i)=='R'){r++;}
                             if(s.charAt(i)=='G'){g++;}
                             if(s.charAt(i)=='B'){b++;}
                            }
        long ans = r*g*b;
        if(a>1){for(int i=0;i<a-1;i++){char c = s.charAt(i);
               for(int j=i+1;j<a;j++){char d = s.charAt(j);
               if(2*j-i<a && s.charAt(2*j-i)!= c && s.charAt(2*j-i)!= d && c!=d){ans--;}                                                                                                                          
                                     }                                       
                                      }                                                                     
               }                                  
		System.out.println(ans);
	}
}


Measured memory_bytes: 37028
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int pre[100005];
int pos[100005];


signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
	if(fopen("INPUT.txt","r"))
	{
	freopen ("INPUT.txt" , "r" , stdin);
	freopen ("OUTPUT.txt" , "w" , stdout);
	}
#endif  

	int n,k;
	cin>>n>>k;
	int a[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		pre[i]=pre[i-1]+a[i];
		pos[i]=pos[i-1]+max(a[i],0LL);
	}
	int mx=0;
	for(int i=k;i<=n;i++)
	{
		mx=max(mx,pos[i-k]+pos[n]-pos[i]);
		mx=max(mx,pos[i-k]+pos[n]-pos[i]+pre[i]-pre[i-k]);
	}
	cout<<mx;
}


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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
//void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(void){
    
    int n, k;
    cin >> n >> k;

    int a[n], ans = 0;
    FOR(i, n){
        cin >> a[i];
        if(a[i] >= k) ans++;
    }

    cout << ans;
    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,x=100,i,y=0,z=100;
	scanf("%lld",&n);
	for(i=0;;i++)
	{ 	
		x=z/100;
		y++;
		z+=x;	
		if(z>=n)
		break;
		//printf("%lld\n",z);
	}
	printf("%lld\n",y);
} 

Measured memory_bytes: 3724
import copy
H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]
c_b = []
ans = 0

for i in range(2 ** H):
    for j in range(2 ** W):
        c_c = copy.deepcopy(c)
        for k in range(H):
            if (i >> k) & 1:
                c_c[k] = ["r" for _ in range(W)]
        for l in range(W):
            if (j >> l) & 1:
                for u in range(H):
                    c_c[u][l] = "r"
        cnt = 0
        for k in range(H):
            cnt += c_c[k].count("#")
        if cnt == K:
            ans += 1
print(ans)

Measured memory_bytes: 72820
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;  
using namespace std;

typedef long long ll;

typedef tree<
pair <int, int>,
null_type,
less<pair <int, int>>,
rb_tree_tag,
tree_order_statistics_node_update>
os;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

int main() {
  int n; cin >> n;
  vector <int> a(n);
  for(auto &x : a) cin >> x;
  cout << accumulate(a.begin(), a.end(), 0) - n << '\n';
}


Measured memory_bytes: 256
n = int(input())
res = n

for i in range(n + 1):
  cc = 0
  t = i  # 6^pでi円引き出し
  while t > 0:
    cc += t % 6
    t //= 6
  t = n - i  # 9^pで残り引き出し
  while t > 0:
    cc += t % 9
    t //= 9
  if res > cc:
    res = cc
print(res)


Measured memory_bytes: 2940
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,ans=10000000000000000,tmp;
  cin >> n;
  ll a[n],sum[n];
  fill(sum,sum+n,0);
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum[i] = a[i];
    if(i!=0){
      sum[i]+=sum[i-1];
    }
  }
  for(int i=0;i<n-1;i++){
    tmp = abs(sum[n-1]-2*sum[i]);
    ans = min(tmp,ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sct(tc) scanf("%lld",&tc)
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define scs(ch) scanf("%s", ch)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define PI 3.14159265358979323846264338327950L

int main()
{
	double a,b,h,m,h_a,m_a,angle,degree,rad,ans;
	scanf("%lf %lf %lf %lf",&a,&b,&h,&m);
    h_a=(h*60+m)*0.5;
    m_a=6*m;
    angle=abs(h_a-m_a);
    degree=min((360-angle),angle);
    rad=(PI*degree)/180;
    ans=sqrt(a*a+b*b-2*a*b*cos(rad));
    printf("%.20lf\n",ans);
}

Measured memory_bytes: 4260
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	int n=s.size();
	int m=t.size();
	vector<vector<int>>dp(n+1,vector<int>(m+1,0));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i-1]==t[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	// cout<<dp[n][m]<<endl;
	int i=n,j=m;
	string res="";
	while(i>0 && j>0){
		if(s[i-1]==t[j-1]){
			res+=s[i-1];
			i--;
			j--;
		}else{
			if(dp[i][j-1]>dp[i-1][j]){
				j--;
			}else{
				i--;
			}
		}
	}
	reverse(res.begin(),res.end());
	cout<<res;
	return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define all(a) a.begin(),a.end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	//cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);

    ll N; cin >> N;
    int sum = 0;
    rep(i,8) {
        ll k = 1;
        int j = i;
        while(j--) k *= 10; 
        sum += (N / k) % 10;
    }
    if(N % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 384
//url:
//problem name: 

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int A,B,H,M;
    cin >> A>>B>>H>>M;
    double pi = acos(-1);
    double d_H = 30 * H + 0.5 * M;
    double d_M = 6 * M;
    double ans = sqrt(A*A+B*B-2*A*B*cos(abs(d_M-d_H)*pi/180));
    printf("%.20f\n",ans);
}


Measured memory_bytes: 4240
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, i, ans=0;
    double price;
    cin >> n;
    for(i=1;i<=50000;i++){
        price=i*1.08;
        if(floor(price)==n){
            ans=i;
            break;
        }
    }
    if(ans==0) cout << ":(" <<endl;
    else cout << ans <<endl;
    return 0;
}

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

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var abn = Console.ReadLine().Split();
            var a = long.Parse(abn[0]);
            var b = long.Parse(abn[1]);
            var n = long.Parse(abn[2]);

            if(n <= b - 1)
            {
                Console.WriteLine(a * n / b);
            }
            else
            {
                Console.WriteLine(a * (b - 1) / b);
            }
        }
    }
}


Measured memory_bytes: 27524
n = input()
K = int(input())
dp = [[[0]*(2) for _ in range(4)] for _ in range(105)]

dp[0][0][0]=1

for i in range(len(n)):
    for j in range(4):
        for k in range(2):
            nd=int(n[i])
            for d in range(10):
                ni=i+1
                nj=j
                nk=k
                if d:
                    nj+=1
                if nj>K:
                    continue
                if nk==0:
                    if d>nd:
                        continue
                    if d<nd:
                        nk=1
                dp[ni][nj][nk] += dp[i][j][k]

ans = dp[len(n)][K][0] + dp[len(n)][K][1]
print(ans)



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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;


class FermatCombination {
private:
	long long factrial[201010]; //階乗を保持
	long long inverse[201010];  //逆元を保持

public:
	FermatCombination(int size);
	long long combine(int n, int k);
	long long fast_pow(long long x, int n);
};

FermatCombination::FermatCombination(int size) {

	factrial[0] = 1;
	inverse[0] = 1;

	for (int i = 1; i <= size; i++) {
		factrial[i] = (factrial[i - 1] * i) % MOD;  // 階乗を求める
		inverse[i] = fast_pow(factrial[i], (int)MOD - 2) % MOD; // フェルマーの小定理で逆元を求める
	}
}

long long FermatCombination::combine(int n, int k) {
	return factrial[n] * inverse[k] % MOD * inverse[n - k] % MOD;
}

long long FermatCombination::fast_pow(long long x, int n) { // x^n 計算量O(logn)
	long long ans = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x % MOD;
		}
		x = x * x % MOD; // 一周する度にx, x^2, x^4, x^8となる
		n >>= 1;         // 桁をずらす n = n >> 1
	}
	return ans;
}


int main(){
    ll H,W,A,B;
    cin >> H >> W >> A >> B;
    
    FermatCombination fc(H+W);     // 初期化と nCi % mod の計算
    vector<ll> memory;

    ll y=H-A-1;
    REP(x,B,W){
        memory.push_back(fc.combine(x+y,x));
    }

    ll ans=0;
    y=A-1;
    RREP(x,0,W-B){
        ans=(ans+(memory[W-B-1-x]*fc.combine(x+y,x))%MOD)%MOD;
    }
    P(ans);

    return 0;
}

Measured memory_bytes: 4472
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    S = 0
    for a in A:
        S ^= a
    B = []
    for a in A:
        B.append(a^S)
    print(*B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 114528
#include <iostream>
#include <cmath>
using namespace std;
int a[100001],b[100001],s[100001];
int main()
{
	int i,j;
	for (i=2;i<=100000;i++)   a[i]=1;
	for (i=2; i<=int(sqrt(100000)); i++)
	    if (a[i]==1)
	        for (j=i+i;j<=100000;j+=i) a[j]=0;
	b[1]=0;
	b[2]=0;
	for (i=3; i<=100000; i++)
         if (a[i]==1&&a[(i+1)/2]==1)  b[i]=1;
	for (i=1;i<=100000;i++)
		s[i]=s[i-1]+b[i];
	int q,L,r;
    cin>>q;
	for (i=1; i<=q; i++)
	{
    	cin >>L>>r;
    	cout <<s[r]-s[L-1]<<endl;
    }
	return 0;	
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

int main(){
	int n, a, b;
	int fNum=-1, sNum=-1; 
	std::vector<int> pList;

	std::cin>>n>>a>>b;
	pList.resize(n);

	for(int i=0; i<n; i++)
		std::cin>>pList[i];

	std::sort(pList.begin(), pList.end());

	for(int i=0; i<n; i++){
		if(pList[i]>a && fNum==-1)
			fNum=i;

		if(pList[i]>b && sNum==-1)
			sNum=i;
	}

	if(fNum==-1 || sNum==-1){
		std::cout<<0<<std::endl;
		return 0;
	}

	std::cout<<std::min(fNum, std::min(sNum-fNum, n-sNum))<<std::endl;

	return 0;
	
	
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long 
#define mod 1000000007
#define max 10000000

int main () {
  ll n;
  cin >> n;
  ll a[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll two[61];
  for (ll i = 0; i <= 60; i++) two[i] = 0;
  for (ll i = 0; i < n; i++) {
    ll sub = a[i];
    ll itr = 0;
    while (sub != 0) {
      if (sub % 2 == 1) {
        two[itr]++;
      }
      sub = (sub >> 1);
      itr++;
    }
  }
  ll sub = 1;
  ll ans = 0;
  for (ll i = 0; i <= 60; i++) {
    ll subsub = ((two[i] % mod)  * ((n - two[i]) % mod)) % mod;
    subsub = ((subsub % mod) * (sub % mod)) % mod;
    ans = (ans + subsub) % mod;
    sub = sub * 2;
  }
  cout << ans << endl;
}

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

using namespace std;

int main(void){

    int a, b, c ,d;
    string temp;

    cin >> temp;
    a = stoi(temp.substr(0, 1));
    b = stoi(temp.substr(1, 1));
    c = stoi(temp.substr(2, 1));
    d = stoi(temp.substr(3, 1));
//    cout << a << " " << b << " " << c << " " << d << endl;
    

    for(int i=0; i<2; i++) {
        for(int j=0; j<2; j++) {
            for(int k=0; k<2; k++) {
                int t_a = a, t_b = b, t_c = c, t_d = d;
                if(i) t_b = -b;
                if(j) t_c = -c;
                if(k) t_d = -d;
                if(t_a+t_b+t_c+t_d==7) {
                    string s;
                    s += to_string(t_a);
                    if(!i) s += "+";
                    s += to_string(t_b);
                    if(!j) s += "+";
                    s += to_string(t_c);
                    if(!k) s += "+";
                    s += to_string(t_d);
                    s += "=7";
                    cout << s << endl;
                    return 0;
                }
            }
        }
    }

    return 0;
    
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

struct node {
    ll w, v;
};

ll const MAX_N = 101;
ll const MAX_V = 1001;

int main() {
    INIT;

    ll N, W;
    cin >> N >> W;

    vector<node> a;
    rep(i, N) {
        node p;
        cin >> p.w >> p.v;
        a.push_back(p);
    }

    vector<vector<ll>> dp(101, vector<ll>(MAX_N * MAX_V + 1, INF));
    dp[0][0] = 0;

    rep(i, N) {
        rep(j, MAX_N * MAX_V + 1) {
            if (j < a[i].v) {
                dp[i + 1][j] = dp[i][j];
            } else {
                dp[i + 1][j] = min(dp[i][j], dp[i][j - a[i].v] + a[i].w);
            }
        }
    }

    // rep(i, N + 1) {
    //     rep(j, MAX_V) {
    //         if (dp[i][j] == INF) continue;
    //         cout << "(" << j << ": " << dp[i][j] << ") ";
    //     }
    //     cout << endl;
    // }

    ll res = 0;
    rep(i, MAX_N * MAX_V + 1) {
        if (dp[N][i] <= W) res = i;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 83980
K=int(input())
S=[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]

print(S[K-1])

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int K, N;
  cin >> K >> N;
  vector <int> A(N);
  rep(i,N){
    cin >> A[i];
  }
  int sa = 0;  //A_iとA_i+1の距離の差の最大値
  for (int i = 0; i < N - 1; i++){
    sa = max(sa, (A[i + 1] - A[i]));
  }
  sa = max(sa, (A[0] + K - A[N - 1]));
  cout << K - sa << endl;
  return 0;
}


Measured memory_bytes: 4000
n,m,x=map(int,input().split())
z=[]
for _ in range(n):
    z.append(list(map(int,input().split())))
Nedan=[]

def all(l):
    for v in l:
        if v<x:
            return False
    return True

D=[[] for _ in range(2**n)]
for x1 in range(2**n):
    w=x1
    for y in range(n):
        D[x1].append(w%2)
        w//=2

for i in range(2**n):
    r=[0]*m
    by=0
    for p in range(n):
        if D[i][p]:

            for j in range(m):
                r[j]+=z[p][1:][j]
            by+=z[p][0]

    if all(r):
        Nedan.append(by)
print(-1 if Nedan==[] else min(Nedan))

Measured memory_bytes: 9908
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-9, pi = acos(-1.0);
namespace std {
    bool operator<(const Point &lhs, const Point &rhs) {
        if (lhs.real() < rhs.real() - eps) return true;
        if (lhs.real() > rhs.real() + eps) return false;
        return lhs.imag() < rhs.imag();
    }
}
Point input_point() {ld x, y; cin >> x >> y; return Point(x, y);} // ????????\???
bool eq(ld a, ld b) {return (abs(a - b) < eps);} // ????????????????????????
ld dot(Point a, Point b) {return real(conj(a) * b);} // ??????
ld cross(Point a, Point b) {return imag(conj(a) * b);} // ??????

// ??´????????????
class Line {
public:
    Point a, b;
    Line() : a(Point(0, 0)), b(Point(0, 0)) {}
    Line(Point a, Point b) : a(a), b(b) {}
    Point operator[](const int _num) {
        if (_num == 0)return a;
        else if (_num == 1)return b;
        else assert(false);
    }
};

// ????????????
class Circle {
public:
    Point p;
    ld r;
    Circle() : p(Point(0, 0)), r(0) {}
    Circle(Point p, ld r) : p(p), r(r) {}
};

// ??´?????¨??´????????????
Point is_ll(Line s, Line t) {
    Point sv = s.b - s.a, tv = t.b - t.a;
    assert(cross(sv, tv) != 0);
    return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    int q; cin >> q;
    for(int i = 0;i<q;i++){
        Line s1(input_point(),input_point()), s2(input_point(),input_point());
        Point ret = is_ll(s1,s2);
        cout << fixed << setprecision(10) << ret.real() << " " << ret.imag() << endl;
    }
    return 0;
}

Measured memory_bytes: 3312
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

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

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int mod = (int)1e9 + 7;
const int mod1 = (int)1e9 + 9;                                                                  

vector<pair<int, int>> vv[20];

char s[55];

int pw[20];

ll ans;

int n;

void pre() {
    pw[0] = 1;

    for (int i = 1; i < 20; ++i) {
        pw[i] = (pw[i - 1] << 1);
    }
}

bool bit(int x, int p) {
    return x & pw[p];
}

pair<int, int> h(string s) {
    pair<int, int> ret = mp(0, 0);

    for (int i = 0; i < s.size(); ++i) {
        int cur = s[i] - 'a' + 1;
        ret.fi = (ret.fi * 29ll + cur) % mod;
        ret.se = (ret.se * 31ll + cur) % mod1;
    }

    return ret;
}

void solve() {                   
    scanf("%d %s", &n, s);
    string sc, tc;
                  
    for (int m = 0; m < pw[n]; ++m) {
        sc.clear();
        tc.clear();

        for (int i = 0; i < n; ++i) {
            if (bit(m, i)) {
                sc.pb(s[i + n]);                
            }
            else {
                tc.pb(s[i + n]);
            }
        }

        reverse(all(tc));
        vv[sc.size()].pb(h(tc + sc));          
    }

    for (int i = 0; i < 20; ++i) {
        sort(all(vv[i]));
    }

    for (int m = 0; m < pw[n]; ++m) {
        sc.clear();
        tc.clear();

        for (int i = 0; i < n; ++i) {
            if (bit(m, i)) {
                sc.pb(s[i]);
            }
            else {
                tc.pb(s[i]);
            }
        }
        
        reverse(all(tc));
        auto it = equal_range(all(vv[tc.size()]), h(sc + tc));
        ans += (it.se - it.fi);        
    }    
         
    printf("%lld\n", ans);
}

int main() {    
    int tt = 1;

    pre();

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 2652
defmodule Main do
  def main do
    s=IO.gets("") |> String.trim()
    t=IO.gets("") |> String.trim()
    IO.puts(check(s,t))
    end

    def check(s,t) do
      if s=="" do
        0
      else
        {sh, st}=String.split_at(s,1)
        {th, tt}=String.split_at(t,1)
        if sh==th do
          check(st,tt)
        else
          check(st,tt)+1
        end
      end
    end
end


Measured memory_bytes: 69052
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
 
public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		char[][] maze = new char[n][m];
		boolean[][] visited = new boolean[n][m];
		int[][] dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
		int white = 0;
		
		for (int i = 0; i < n; i++) {
			String s = sc.next();
			for (int j = 0; j < m; j++) {
				char c = s.charAt(j);
				maze[i][j] = c;
				if (c == '.') { white++;}
			}
		}
		
		int step = 1;
		Queue<Point> q = new LinkedList<>();
		q.offer(new Point(0,0,1));
		
		while (!q.isEmpty()) {
			int size = q.size();
			// System.out.println(size);
			for (int i = 0; i < size; i++) {
				Point p = q.poll();
				int x = p.x;
				int y = p.y;
				
				visited[x][y] = true;
				
				if (x == (n - 1) && y == (m - 1)) {
					System.out.println(white - step);
					System.exit(0);
				}
				
				for (int[] dir: dirs) {
					int dx = x + dir[0];
					int dy = y + dir[1];
					
					if ((0 <= dx) && (dx <n) && 
						(0 <= dy) && (dy < m) && 
						maze[dx][dy] == '.' && 
						!visited[dx][dy]) {
						visited[dx][dy] = true;
						q.offer(new Point(dx, dy, step));
					}
				}
			}
			step++;
		}
		System.out.println(-1);
		
	}
	
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}

class Point {
	public int x;
	public int y;
	public int step;
	public Point(int x, int y, int step) {
		this.x = x;
		this.y = y;
	}
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000LL
#define ulinf 10000000000000000000ull
#define MOD1 1000000007LL
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n,v[100005],cnt[2][100005],res=iinf;
pii mn,sm;
int main(){
    // inputting start
    // 数据结构记得初始化！ n，m别写反！
    int i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;++i) scanf("%d",v+i);
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
    // 数据结构记得初始化！ n，m别写反！
    for(i=0;i<n;++i){
		++cnt[i&1][v[i]];
	}
	mn=sm=mpr(-1,-1);
	for(i=0;i<=100002;++i){
		if(cnt[0][i]>mn.first){
			sm=mn;
			mn=mpr(cnt[0][i],i);
		}
		else if(cnt[0][i]>sm.first){
			sm=mpr(cnt[0][i],i);
		}
	}
	for(i=0;i<=100002;++i){
		if(i==mn.second){
			UMIN(res,n-cnt[1][i]-sm.first);
		}
		else{
			UMIN(res,n-cnt[1][i]-mn.first);
		}
	}
	printf("%d\n",res);
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

pii p[ N ];
multiset <int> day[ N ];

int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        int n , m;
        cin >> n >> m;
        for( int i = 1; i <= n; i++ ) {
                 cin >> p[i].first >> p[i].second;
        }
        sort( p + 1 ,  p + n + 1 );
        int idx = 1;
        LL ans = 0;
        multiset <int> can;
        for( int i = 1; i <= m; i++ ) {
                while( idx <= n && p[idx].first <= i ) {
                        can.insert( p[idx].second );
                        idx++;
                }
                //for( auto x : can ) cout << x << " "; cout << endl;
                if( can.empty() ) continue;
                auto it = can.end(); --it;
                ans += (*it);
                can.erase( it );
        }
        cout << ans << endl;
        return 0;
}










Measured memory_bytes: 10368
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define reps(i, a, b) for(int i = (a); i < (b); i++)
#define pb push_back
#define ps push
#define mp make_pair
#define CLR(x,t) memset(x,t,sizeof x)
#define LEN(X) strlen(X)
#define F first
#define S second
#define Debug(x) cout<<#x<<"="<<x<<endl;


const double euler_r = 0.57721566490153286060651209;
const double pi = 3.141592653589793238462643383279;
const double E = 2.7182818284590452353602874713526;
const int inf = ~0U >> 1;
const int MOD = int (1e9) + 7;
const double EPS = 1e-6;

typedef long long LL;

int n, k;
int a[1010];

int main() {
	ios::sync_with_stdio (false);
    cin.tie (0);
    cin >> n >> k;
    for (int i = 1; i <= k; i++) a[i] = 1;
    n -= k;
    a[1] += n;
    cout << a[1] - a[k] << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>

template <class Integer>
auto boost_irange(Integer last) { return boost::irange(static_cast<Integer>(0), last); }
template <class Integer>
auto boost_irange(Integer first, Integer last) { return boost::irange(first, last); }

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { cout << std::endl; }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << val << ' ';
            return *this;
        }
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy operator<<(T&& val)
    {
        cout << val << ' ';
        return {};
    }
};

int main()
{
    input in;
    output out;

    int N = in.read<int>();
    double rec = 0;
    in.online<int>(N, [&](int x) { rec += 1. / x; });
    out << 1. / rec;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(int argc,char* argv)
{
	int a, b, seki;
	scanf("%d",&a);
	scanf("%d",&b);
	seki = a*b;
	if(seki%2 == 0){
		printf("Even\n");
	}
	else{
		printf("Odd\n");
	}
	return(0);
}

Measured memory_bytes: 128
n, m = map(int, input().split())
l = [tuple(map(int, input().split())) for i in range(m)]
c = [[] for _ in range(n+1)]
for x in l:
    c[x[0]].append(x[1])
    c[x[1]].append(x[0])
if set(c[1])&set(c[n]):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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

#define PB          push_back
#define PF          push_front
#define MP          make_pair
#define FI          first
#define SE          second
#define SIZE( A )   int( ( A ).size( ) )
#define ALL( A )    ( A ).begin( ), ( A ).end( )
#define ALLR( A )   ( A ).rbegin( ), ( A ).rend( )

using namespace std;

typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         lf;
typedef pair< int, int >    pii;
typedef pair< ll, ll >      pll;
typedef vector< bool >      vb;
typedef vector< lf >        vd;
typedef vector< ll >        vll;
typedef vector< int >       vi;
typedef vector< pii >       vpii;

const int MAXN = int( 2e5 )+10;
const int MOD  = int( 360 );
const int oo   = INT_MAX;
const int A    = 26;

string s;
int nxt[ A ][ MAXN ];
int dp[ MAXN ];
string ans;

void precalc() {
  int sz = SIZE(s);
  for( int i = 0; i < A; ++i ) {
    nxt[ i ][ sz ] = -1;
  }
  for( int i = sz-1; i >= 0; --i ) {
    for( int j = 0; j < A; ++j ) {
      nxt[ j ][ i ] = nxt[ j ][ i+1 ];
    }
    nxt[ s[i]-'a' ][ i ] = i+1;
  }
}

void solve() {
  int sz = SIZE(s);
  for( int i = sz; i >= 0; --i ) {
    dp[ i ] = oo;
    for( int j = 0; j < A; ++j ) {
      if( nxt[ j ][ i ] == -1 ) dp[ i ] = 1;
      else dp[ i ] = min( dp[i], dp[ nxt[ j ][ i ] ]+1 );
    }
  }
}

void get_ans( int cur ) {
  for( int i = 0; i < A; ++i ) {
    if( nxt[ i ][ cur ] == -1 ) {
      ans.PB( 'a'+i );
      return;
    }
    else if( dp[ cur ] == dp[ nxt[ i ][ cur ] ]+1 ) {
      ans.PB( 'a'+i );
      return get_ans( nxt[ i ][ cur ] );
    }
  }
}

int main( ) {

  #ifdef LOCAL
    freopen( "input", "r", stdin );
    //freopen( "output", "w", stdout );
  #else
    //freopen( "input", "r", stdin );
    //freopen( "output", "w", stdout );
    ios_base::sync_with_stdio( 0 );
    cin.tie( 0 );
  #endif

  while( cin >> s ) {
    precalc();
    solve();
    ans = "";
    get_ans( 0 );
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 21652
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 05/23/20 20:47:37
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int INF = 1e9;
constexpr int dir[4][2] = {
    {1,0},
    {-1,0},
    {0,1},
    {0,-1}
};

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

  int n; cin>>n;

  vector<vector<int>> H(n, vector<int>(n));
  vector<vector<bool>> exist(n, vector<bool>(n, true));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      H[i][j] = min({
        i,n-1-i,
        j,n-1-j
      });
    }
  }

  int ans = 0;
  for (int i = 0; i < n*n; i++) {
    int p; cin>>p; p--;
    int row = p/n;
    int col = p%n;
    ans += H[row][col];
    exist[row][col] = false;

    deque<pair<int,int>> qs;
    qs.emplace_back(row, col);
    while (not qs.empty()) {
      auto [r,c] = qs.front(); qs.pop_front();
      auto h = H[r][c] + (exist[r][c] ? 1 : 0);
      for (auto d:dir) {
        auto nr = r+d[0];
        auto nc = c+d[1];
        if (nr < 0 or nr >= n or nc < 0 or nc >= n)
          continue;
        if (h >= H[nr][nc])
          continue;
        H[nr][nc] = h;
        if (exist[nr][nc]) {
          qs.emplace_back(nr,nc);
        } else {
          qs.emplace_front(nr,nc);
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5660
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define INF_LL 1e18
#define INF 1e9

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

using namespace std;

using ll = long long;
using PII = pair<int, int>;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

class SegTree{
	vector<ll> dat;
	int n;
public:
	SegTree(int _n){
		n = 1;
		while(n < _n) n *= 2;
		REP(i, n){
			dat.push_back(0);
		}
	}
};

int main(void){
	ll N, x;
	ll res = INF_LL;
	ll a[2002];
	ll min_a[2002];
	cin >> N >> x;
	REP(i, N){
		cin >> a[i];
		min_a[i] = a[i];
	}

	REP(i, N){
		ll cnt = 0;
		REP(j, N){
			min_a[j] = min(min_a[j], a[(j-i+N)%N]);
			cnt += min_a[j];
		}
		cnt += x*i;
		res = min(res, cnt);
	}
	cout << res << endl;
}


Measured memory_bytes: 256
n = int(input())

INF = float("inf")

dp = [INF]*100010
dp[0] = 0

pow6 = [6**i for i in range(7)]
pow9 = [9**i for i in range(6)]

for i in range(1,n+1):
    for p6 in pow6:
        dp[i] = min(dp[i],dp[i-p6]+1)
    for p9 in pow9:
        dp[i] = min(dp[i],dp[i-p9]+1)
print(dp[n])

Measured memory_bytes: 9604
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
int n;
int a , b;
vector < int > v[N];
int dfs(int node , int parent){
	int curor = 0;
	int two = 0;
	for(int next : v[node]){
		if(next == parent){
			continue;
		}
		int tmp = dfs(next , node);
		two |= tmp & curor;
		curor |= tmp;
	}
	two |= two >> 8;
	two |= two >> 4;
	two |= two >> 2;
	two |= two >> 1;
	int allowed = (~two) & (~curor);
	int me = allowed & -allowed;
	return (curor | me) & (~(me - 1));
}
int main(){
	scanf("%d" , &n);
	for(int i = 1 ; i < n ; ++i){
		scanf("%d %d" , &a , &b);
		v[a].emplace_back(b);
		v[b].emplace_back(a);
	}
	int ans = dfs(1 , 0);
	for(int i = 16 ; ; --i){
		if((ans >> i) & 1){
			printf("%d\n" , i);
			break;
		}
	}
}

Measured memory_bytes: 10240
D, N = map(int, input().split())
if D == 0:
    if N == 100:
        print(101)
    else:
        print(N)
elif D == 1:
    if N == 100:
        print(10100)
    else:
        print(100 * N)
else:
    if N == 100:
        print(1010000)
    else:
        print(10000 * N)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

int main(){
	int n;
	while(cin >> n) {
		int l,r,tot=0;
		rep(i,0,n) {
			cin >> l >> r;
			tot += r - l + 1;
		}
		cout << tot << endl;
	}
    return 0;
}


Measured memory_bytes: 256