akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> H(N+1),A(M),B(M);
    for(ll i=1; i<=N; i++){
        cin >> H.at(i);
    }
    vector<ll> bridge(N+1,0);

    for(ll i=0; i<M; i++){
        cin >> A.at(i) >> B.at(i);
        if(H.at(B.at(i))>bridge.at(A.at(i))) bridge.at(A.at(i)) = (H.at(B.at(i)));
        if(H.at(A.at(i))>bridge.at(B.at(i))) bridge.at(B.at(i)) = (H.at(A.at(i)));
    }
    ll sum=0;
    for(ll i=1; i<=N; i++){
        ll c=H.at(i);
        ll d=bridge.at(i);
        if(c>d) sum++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 6424
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
	
	io
	ll n,k;
	cin>>n>>k;
	long double res=0.0;	
	std::vector<ll> ress;
	rep(i,1,n+1)
	{
		ll curr=1,res1=i;
		while(1)
		{
			if(res1>=k)
				break;
			curr*=2;
			res1*=2;			
		}
		ress.pb(curr);		
	}
	sort(all(ress));
	ll s=0;
	for(auto i:ress)
	{
		ll z=(ress[ress.size()-1]/i);		
		s+=z;
	}
	ll s2=(n*ress[ress.size()-1]);
	res=(1.0*s)/s2;	
	cout<<fixed<<setprecision(27)<<res;

	
}

Measured memory_bytes: 1400
#include <cstdio>

int main() {
    long long int n;
    char k[11];
    long long int table[5] {0,0,0,0,0};

    scanf("%lld", &n);

    for (int i = 0; i < n; i++){
        scanf("%s", k);
        switch(k[0]) {
            case 'M':
            table[0]++;
            break;

            case 'A':
            table[1]++;
            break;

            case 'R':
            table[2]++;
            break;

            case 'C':
            table[3]++;
            break;

            case 'H':
            table[4]++;
            break;

            default:
            break;
        }
    }

    long long ret = table[0] * table[1] * table[2]
        + table[0] * table[1] * table[3]
        + table[0] * table[1] * table[4]
        + table[0] * table[2] * table[3]
        + table[0] * table[2] * table[4]
        + table[0] * table[3] * table[4]
        + table[1] * table[2] * table[3]
        + table[1] * table[2] * table[4]
        + table[1] * table[3] * table[4]
        + table[2] * table[3] * table[4];

    printf("%lld\n", ret);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <list>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;
template <class T>
using Vec = std::vector<T>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {std::make_pair(1, 0), std::make_pair(-1, 0), std::make_pair(0, 1), std::make_pair(0, -1)};
constexpr char BR = '\n';

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())



template <class T> inline int argmin(std::vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(std::vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int BitI(int k){return 1 << k;}
inline lli BitL(int k){return 1L << k;}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





int main(void){
  int n; scanf("%d\n", &n);
  int res = 0, mx = -1, now;
  REP(_, n){
    scanf("%d", &now);
    if(mx <= now){
      res++;
      mx = now;
    }
  }
  printf("%d\n", res);
  return 0;
}

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

using namespace std;

int main()
{
    int n, m;
    long long int h[100010];
    int a[100010], b[100010];
    long long int ans = 0;
    long long int top[100010] = {};
    cin >> n >> m;


    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        if (h[a[i]-1] > h[b[i]-1]) {
            top[b[i]-1] = -1;
        }
        else if (h[a[i]-1] < h[b[i]-1]) {
            top[a[i]-1] = -1;
        }
        else {
            top[a[i]-1] = -1;
            top[b[i]-1] = -1;
        }

    }

    for (int i = 0; i < n; i++) {
        if (top[i] != -1) {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 5980
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    ll r = a % b;
    while (r) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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

int main() {
    int a, b;
    cin >> a >> b;

    cout << lcm(a, b);

    return 0;
}


Measured memory_bytes: 256
def B(N, L):
    if N < 3:
        return 0

    answer = 0

    for i in range(0, N - 2):
        if L[i] < 1:
            continue
        for j in range(1, N - 1):
            if i >= j or L[i] == L[j]:
                continue
            for k in range(2, N):
                if i >= k or j >= k or L[i] == L[k] or L[j] == L[k]:
                    continue
                if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[k] + L[i] > L[j]:
                    answer += 1

    return answer
  
  
N = int(input())
L = [int(n) for n in input().split(' ')]
print(B(N, L))

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

constexpr int mod = 1e9+7;
int n, m;
vector<int> a, dp;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	dp.resize(n+1, 0);
	a.resize(n+1, 0);
	for(int i=0; i<m; ++i){
		int t; cin >> t;
		a[t] = 1;
	}
	dp[0] = 1;
	for(int i=1; i<=n; ++i){
		if(a[i] == 0){
			dp[i] = dp[i-1] + dp[i-2];
			dp[i] %= mod;
		}
	}
	cout << dp[n] << "\n";
}

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

int main() {
  char s;
  cin >> s;
  if(s <= 'Z'){
    cout << "A";
  }
  else{
    cout << "a";
  }
  return 0;
}




Measured memory_bytes: 3616
#include <stdio.h>

int main()
{
  int a[1000000]={0},n,i,j,v,m,k,count=0,g[100]={0};

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  i=0;
  g[0]=1;

  while(1){
    if(g[i]>n){
      m=i;
      break;
    }else{
      g[i+1]=3*g[i]+i;
      i++;
    }
  }

  for(i=0;i<m;i++){
    for(j=g[m-1-i];j<n;j++){
      v=a[j];
      k=j-g[m-1-i];
      while(k>=0&&a[k]>v){
	a[k+g[m-i-1]]=a[k];
	k=k-g[m-i-1];
	count++;
      }
      a[k+g[m-i-1]]=v;
    }
  }

  printf("\n%d\n",m);

  for(i=0;i<m;i++){
    if(i==m-1) printf("%d\n",g[m-i-1]);
    else printf("%d ",g[m-i-1]);
  }

  printf("%d\n",count);

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

  return 0;
}

Measured memory_bytes: 6648
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n);i>=(j);i--)
using ll=long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF=1LL<<60;

int n;

int main(){
    cin>>n;
    vector<int> x(n),y(n);
    rep(i,0,n){
        cin>>x[i];
        y[i]=x[i];
    }
    sort(y.begin(),y.end());
    int num=(1+n)/2-1;
    rep(i,0,n){
        if(x[i]<=y[num]) cout<<y[num+1]<<"\n";
        else if(x[i]>=y[num+1]) cout<<y[num]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 8e5 + 5 ; 
const int P = 200003 ; 
int n, m, R[N], g[N], ord[N], fc[N], f[N], c[N], tt[N], limit, L, num, cnt, ans[N] ; 
void Init( int x ) {
	limit = 1, L = 0 ; 
	while( limit <= x ) limit <<= 1, ++ L ;
	rep( i, 0, limit ) R[i] = ( R[i >> 1] >> 1 ) | ( ( i & 1 ) << ( L - 1 ) ) ;
}
const double Pi = acos( -1.0 ) ;
struct Complex {
	double x, y ; 
	Complex( double xx = 0, double yy = 0 ) { x = xx, y = yy ; }
} F[N], Q[N], C[N], A1[N], A2[N], B1[N], B2[N] ; 
Complex operator * ( Complex x, Complex y ) { return Complex( x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x ) ; }
Complex operator + ( Complex x, Complex y ) { return Complex( x.x + y.x, x.y + y.y ) ; }
Complex operator - ( Complex x, Complex y ) { return Complex( x.x - y.x, x.y - y.y ) ; }
Complex operator / ( Complex x, double y ) { return Complex(x.x / y, x.y / y ) ; }
void FFT( Complex *a, int type ) {
	for( int i = 0; i < limit; ++ i ) if( R[i] > i ) swap( a[R[i]], a[i] ) ;
	for( int k = 1; k < limit; k <<= 1 ) {
		Complex Dw = Complex( cos( Pi / k ), type * sin( Pi / k ) );	
		for( int i = 0; i < limit; i += ( k << 1 ) ) {
			Complex w = Complex( 1, 0 ) ;
			for( int j = i; j < i + k; ++ j, w = w * Dw ) {
				Complex Ny = w * a[j + k], Nx = a[j] ;
				a[j + k] = Nx - Ny,	a[j] = Nx + Ny ; 
			} 
		}
	}	
	if( type != 1 ) rep( i, 0, limit ) a[i] = a[i] / (double)limit ;
}
signed main()
{
	n = gi() ; 
	rep( i, 1, n ) c[i] = gi() ; 
	int gg = 2, ff = 1 ; cnt = 400 ; 
	for( re int i = 0; i < P - 1; ++ i ) {
		ord[ff] = i, fc[i] = ff, ff = ff * 2 % P ; 
	}
	int Ans = 0 ; 
	rep( i, 1, n ) if(c[i]) tt[ord[c[i]]] ++, Ans -= c[i] * c[i] % P ; 
	rep( i, 0, P ) A1[i].x = tt[i] / cnt, A2[i].x = tt[i] % cnt ; 
	rep( i, 0, P ) B1[i].x = tt[i] / cnt, B2[i].x = tt[i] % cnt ; 
	Init( 2 * P + 5 ), FFT( A1, 1 ), FFT( A2, 1 ), FFT( B1, 1 ), FFT( B2, 1 ) ; 
	num = cnt * cnt % P ; 
	rep( i, 0, limit ) F[i] = A1[i] * B1[i], Q[i] = ( A1[i] * B2[i] + A2[i] * B1[i] ), C[i] = A2[i] * B2[i] ; 
	FFT( F, -1 ), FFT( Q, -1 ), FFT( C, -1 ) ;
	rep( i, 0, limit ) {
		ans[i] = ( (int)(F[i].x + 0.5) * num + ( (int)(Q[i].x + 0.5) * cnt ) + (int)(C[i].x + 0.5) ) ; 
		Ans += ans[i] * fc[i % (P - 1)] ;
	}
	cout << Ans / 2 << endl ; 
	return 0;
}


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

int main(void) {
  int N, M;
  cin >> N >> M;
  if (M == N) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 110, M = 1010;

int a, b;
char g[N][N];

int main()
{
	cin >> a >> b;
	a -- , b -- ;
	
	for (int i = 1; i <= 100; i ++ )
		for (int j = 1; j <= 100; j ++ )
			g[i][j] = i <= 50 ? '#' : '.';
			
	for (int i = 1; a && i <= 49; i += 2)
		for (int j = 1; a && j <= 100; j += 2)
			g[i][j] = '.', a -- ;
			
	for (int i = 52; b && i <= 100; i += 2)
		for (int j = 1; b && j <= 100; j += 2)
			g[i][j] = '#', b -- ;
	
	puts("100 100");
	for (int i = 1; i <= 100; i ++ ) puts(g[i] + 1);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long long int l[n+1];
    l[0]=2;
    l[1]=1;
    for(int i=2;i<=n;i++)l[i]=l[i-1]+l[i-2];
    cout << l[n];
}

Measured memory_bytes: 3652
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<int> color(9, 0);
    rep(i, n) {
        int a;
        cin >> a;
        if (a < 400) {
            ++color[0];
        }
        else if (a < 800) {
            ++color[1];
        }
        else if (a < 1200) {
            ++color[2];
        }
        else if (a < 1600) {
            ++color[3];
        }
        else if (a < 2000) {
            ++color[4];
        }
        else if (a < 2400) {
            ++color[5];
        }
        else if (a < 2800) {
            ++color[6];
        }
        else if (a < 3200) {
            ++color[7];
        }
        else {
            ++color[8];
        }
    }
    int ans = 0;
    rep(i, 8) {
        if (color[i]) ++ans;
    }
    if (ans == 0) {
        cout << 1 << " ";
    }
    else {
        cout << ans << " ";
    }
    cout << ans + color[8] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    int a,b,c;
    cin>>a>>b>>c;
    cout<<((a+b)>=c?"Yes":"No");
    return 0;
}


Measured memory_bytes: 256
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let n: usize = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.parse().unwrap()
    };

    let v: Vec<char> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.chars().collect()
    };

    let mut count = 0;
    for i in 0..(n - 2) {
        if v[i] == 'A' && v[i + 1] == 'B' && v[i + 2] == 'C' {
            count += 1;
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define pb push_back
unordered_map<ll,std::vector<ll>> graph;
unordered_map<ll,ll> vis,dp;
ll level = 0;

ll dfs(ll s,ll l)
{
    level = max(level,l);
    ll ans = 0;
    
    for(ll i=0;i<graph[s].size();i++){
        
        if(vis[graph[s][i]]==0){
            vis[graph[s][i]]=1;
            ans += 1 + dfs(graph[s][i],l+1);
        }
    }
    
    return dp[s] = ans;
        
}

void bfs(ll s,ll k)
{
    queue<pair<ll,ll>> pq;
    
    pq.push({s,0});
    // ll level = 0;
    vector<vector<pair<ll,ll>>> v(level+10);
    
    vis.clear();
    vis[1] = 1;
    
    
    while(!pq.empty())
    {
        auto s = pq.front();
        pq.pop();
        v[s.ss].push_back({dp[s.ff],s.ff});
        // vis[s.ff] = 0;
        for(ll i=0;i<graph[s.ff].size();i++){
            if(vis[graph[s.ff][i]]==0){
                vis[graph[s.ff][i]]=1;
                pq.push({graph[s.ff][i],s.ss+1});
            }
        }
    }
    
    ll ans = 0;
    vector<ll> a;
    
    
    for(ll i=level;i>=0;i--){
        for(ll j=0;j<v[i].size();j++)
        {
            // st.insert({v[i][j].ff,v[i][j].ss});
            a.push_back(i - v[i][j].ff);
        } 
    }
    
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    
    for(ll i:a){
        ans += i;
        k--;
        if(k==0){
            break;
        }
    }
    cout<<ans;
    
}

void solve()
{
    string s;cin>>s;
    if(s[0]=='7' or s[1]=='7' or s[2] == '7')   cout<<"Yes\n";
    else    cout<<"No\n";
    
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    // ll t;cin>>t;while(t--)
    {
        solve();
    }
    
	return 0;
}


Measured memory_bytes: 3560
def warshall_floyd(G):
    import copy
    ret = copy.deepcopy(G)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                ret[i][j] = min(ret[i][j], ret[i][k] + ret[k][j])
    return ret


N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
W, ans = warshall_floyd(A), 0
if A == W:
    for i in range(N):
        for j in range(N):
            if sum([A[i][j] == A[i][k] + A[k][j] for k in range(N) if k != i and k != j]) == 0:
                ans += A[i][j]
    print(ans // 2)
else:
    print(-1)


Measured memory_bytes: 58332
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 100005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
const int K = 26;

struct Vertex {
    int next[K];
    int leaf;
    int value;
    Vertex() {
        fill(begin(next), end(next), -1);
        leaf = 0;
        value = 0;
    }
};

vector<Vertex> trie(1);
void add_string(string const& s) {
    int v = 0;
    for (char ch : s) {
        int c = ch - 'a';
        if (trie[v].next[c] == -1) {
            trie[v].next[c] = trie.size();
            trie.emplace_back();
        }
        v = trie[v].next[c];
        trie[v].value++;
    }
    trie[v].leaf++;
}
string s[N];
ll pre[N],pre1[N][26][26],priority[26];
void solve()
{
    ll n,q;
    cin >> n;
    for(ll i=0;i<n;i++)
    {
        cin >> s[i];
        add_string(s[i]);
    }
    for(ll i=0;i<n;i++)
    {
        ll v = 0;
        ll sum = 0;
        for(ll j=0;j<s[i].size();j++)
        {
            sum += trie[v].leaf;
            for(ll k=0;k<26;k++)
            {
                ll n_v = trie[v].next[k];
                if(n_v!=-1)
                {
                    pre1[i][k][s[i][j]-'a'] += trie[n_v].value;
                }
            }
            v = trie[v].next[s[i][j]-'a'];
        }
        pre[i] = sum;
    }
    cin >> q;
    while(q--)
    {
        ll k;
        cin >> k;
        string t;
        cin >> t;
        k--;
        for(ll i=0;i<26;i++)
        {
            priority[t[i]-'a'] = i;
        }
        ll ans = pre[k]+1;
        for(ll i=0;i<26;i++)
        {
            for(ll j=0;j<26;j++)
            { 
                if(priority[i]<priority[j])    ans += pre1[k][i][j];
            }
        }
        cout<<ans<<"\n";
    }
}

int main()
{
    FAST;
    ll t = 1;
   // cin >> t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 283772
package main

import "fmt"

type pair struct {
	x float64
	y string
}

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]pair, n)
	for i := range p {
		fmt.Scan(&p[i].x, &p[i].y)
	}
	fmt.Println(yen(p))
}

func yen(p []pair) float64 {
	var sum float64
	for _, v := range p {
		if v.y == "BTC" {
			sum += v.x * 380000.0
		} else {
			sum += v.x
		}
	}
	return sum
}


Measured memory_bytes: 512
#include<stdio.h>
#define M 5000000

int H,A[M+1];
void maxheap(int i);

int main(){
  int i;
  
  scanf("%d",&H);

  for(i=1;i<=H;i++) scanf("%d",&A[i]);
  for(i=H/2;i>=1;i--) maxheap(i);
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}
  
    
void maxheap(int i){
  int left,right,saidai,x;
  left=2*i;
  right=2*i+1;

  if(left<=H && A[left] > A[i])
    saidai=left;
  else saidai=i;

  if(right<=H && A[right] > A[saidai])
    saidai=right;

  if(saidai!=i){
    x=A[i];
    A[i]=A[saidai];
    A[saidai]=x;
    maxheap(saidai);
  }
}



Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

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

struct P{
    int x, y;

    double size(){
        return std::sqrt(this->x * this->x + this->y * this->y);
    }

    P operator+(const P& p) const{
        return P{this->x + p.x, this->y + p.y};
    }
    P operator-(const P& p) const{
        return P{this->x - p.x, this->y - p.y};
    }
};

std::vector<P> pillars;
int isUsed[3000][3000];

bool ascending_P(const P& lp, const P& rp){
        if(lp.x != rp.x){
            return lp.x < rp.x;
        }
        return lp.y < rp.y;
}

P rotate_90(P p){
    return P{-p.y, p.x};
}

bool isWithinRange(P p){
    return 0 <= p.x && p.x <= 5000 && 0 <= p.y && p.y <= 5000;
}

bool canCreateSite(P p, P v){
    REP(i, 4){
        if(isWithinRange(p) && std::binary_search(pillars.begin(), pillars.end(), p, ascending_P)){
            p = p + v;
            v = rotate_90(v);
        }else{
            return false;
        }
    }

    return true;
}

int main(){
    int n;
    while(std::cin >> n, n){
        pillars.clear();

        REP(i, n){
            REP(j, n){
                isUsed[i][j] = 0;
            }
        }


        REP(i, n){
            int x, y;
            std::cin >> x >> y;
            pillars.push_back(P{x, y});
        }

        std::sort(pillars.begin(), pillars.end(), ascending_P);

        int res = 0;
        REP(i, n){
            FOR(j, i+1, n){
                if(isUsed[i][j] || isUsed[j][i]){
                    continue;
                }

                isUsed[i][j] = 1;
                P a = pillars[i], b = pillars[j], v = b-a;
                int S = v.x * v.x + v.y * v.y;

                if(canCreateSite(a, b-a)){
                    res = std::max(S, res);
                }else if(canCreateSite(b, a-b)){
                    res = std::max(S, res);
                }
            }
        }

        std::cout << res << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 36428
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <memory.h>
#include <set>
#include <cmath>
#define fio ios::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
priority_queue<double> pq;
int n;
int main(void) {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		double x; scanf("%lf", &x);
		pq.push(-x);
	}
	while (pq.size() != 1) {
		double x = pq.top(); pq.pop();
		double y = pq.top(); pq.pop();
		pq.push((x + y) / 2);
	}
	printf("%lf\n", -pq.top());
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <list>
#include <numeric>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/

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

	int a, b;
	cin >> a >> b;
	int ans;
	if (a >= 13)ans = b;
	else if (a >= 6) ans = b / 2;
	else ans = 0;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
def inpl(): return [int(i) for i in input().split()]
import heapq
from itertools import permutations

N, M, R = inpl()
r = inpl()
for i in range(R):
    r[i] -= 1
inf = float('inf')
Q = [[inf] * N for _ in range(N)]
path = [[0] * N for _ in range(N)]

for i in range(M):
    A,B,C = inpl()
    path[A-1][B-1] = path[B-1][A-1] = C

for i in r:
    decided = [False for _ in range(N)]
    H = []
    ctr = 0
    Q[i][i] = 0
    heapq.heappush(H,(0,i))
    while ctr != N:
        while True:
            k = heapq.heappop(H)
            k = k[1]
            if not decided[k]:
                decided[k] = True
                ctr += 1
                break
        for j in range(N):
            if path[k][j] == 0:
                continue
            if decided[j]:
                continue
            Q[i][j] = min(Q[i][k] + path[k][j], Q[i][j])
            heapq.heappush(H,(Q[i][j],j))

Ans = inf
for i in permutations(r):
    ans = 0
    for j in range(R-1):
        ans += Q[i[j]][i[j+1]]
    Ans = min(Ans,ans) 
        
print(Ans)

Measured memory_bytes: 5492
#include <bits/stdc++.h>
 
using namespace std;
 
int d[100020];
int k;
 
int resi(int h[], int i, int n)
{   
    if(i == n-1)
        return 0;
    
    
    int min1 = INT_MAX;
 
    for(int j = 1; j <= k; j++)
    {
        if(i+j > n-1)
        {
            continue;
        }
        if(d[i+j] == -1)
        {
            d[i+j] = resi(h, i+j, n);
        }
        min1 = min(min1, d[i+j] + abs(h[i]-h[i+j]));
        //cout << "i:   " << i<< " j:   " << j << " POM1 :" << d[i+j] + abs(h[i]-h[i+j]) << endl;
    }
 
    return d[i]=min1;
 
}
 
int main()
{
    int n;
 
    cin >> n >> k;
 
    int h[100020];
    
    for(int i = 0; i < n; i++)
    {
        cin >> h[i];
        d[i] = -1;
    }
 
 
    cout << resi(h,0,n) << endl;
 
 
    // for(int i = 0; i < n; i ++)
    //     cout << "d"<< i<< " "  << d[i] << endl;
 
    return 0;
}

Measured memory_bytes: 10368
/*


*/
#include <cstdio>
#include <cctype>
#include <algorithm>
#define MAXIN 300000
#define gc() (SS==TT&&(TT=(SS=IN)+fread(IN,1,MAXIN,stdin),SS==TT)?EOF:*SS++)
typedef long long LL;
const int N=1e5+5;

int n,A[N];
char IN[MAXIN],*SS=IN,*TT=IN;

inline int read()
{
	int now=0;register char c=gc();
	for(;!isdigit(c);c=gc());
	for(;isdigit(c);now=now*10+c-48,c=gc());
	return now;
}
bool DFS(bool now)
{
	int s=0,fg=0;
	for(int i=1; i<=n; ++i) A[i]==1&&(fg=1), s+=A[i]&1;
	if((n-s)&1) return now;
	if(fg||s>1) return now^1;
	for(int i=1; i<=n; ++i)
		if(A[i]&1) {--A[i]; break;}
	int g=A[1];
	for(int i=2; i<=n; ++i) g=std::__gcd(g,A[i]);
	for(int i=1; i<=n; ++i) A[i]/=g;
	return DFS(now^1);
}

int main()
{
	const int n=read(); ::n=n;
	for(int i=1; i<=n; ++i) A[i]=read();
	puts(DFS(1)?"First":"Second");

	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
	long N,m1=0,m2=0,i,temp;
	vector<long> A;
	cin>>N;
	for(i=0;i<N;i++){
		cin>>temp;
		A.push_back(temp);
		if(temp>m1){
			m2=m1;
			m1=temp;
		}else if(temp>m2){
			m2=temp;
		}
	}
	for(i=0;i<N;i++){
		if(A.at(i)==m1){
			cout<<m2<<endl;
		}else{
			cout<<m1<<endl;
		}
	}
}

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

int a[101];
int main(){
    int n;
    cin>>n;
    rep(i,n) cin>>a[i];
    int cnt=0;
    rep(i,n){
        int t=min_element(a+i,a+n)-a;
        if(i!=t) swap(a[i],a[t]),++cnt;
    }
    rep(i,n)cout<<a[i]<<(i==n-1?"":" ");
    cout<<endl;
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
int main()
{
    int a,b;
    cin>>a>>b;
    int ans=a;
    int i=2;
    if(b==1){
        cout<<0<<endl;
        return 0;
    }
    for(i=2;i<=20;i++){
        if(ans<b) ans+=a-1;
        else break;
    }
    cout<<i-1<<endl;
    return 0;
}


Measured memory_bytes: 256
def calc(list1,list2):
    for l in list2:
        list1[l] += 1
    return list1

n = int(input())
h = list(map(int,input().split()))
f = [0]*n
ans = 0

for i in range(min(h)):
    f = [x+1 for x in f]
    ans += 1

while sum(f) != sum(h):
    flag = False
    tmp = []
    for i in range(n):
        if i == n-1 and h[i] != f[i]:
            tmp.append(i)
            f = calc(f,tmp)
            ans+=1
        elif h[i] == f[i] and flag:
            f = calc(f,tmp)
            ans+=1
            break
        elif h[i] != f[i]:
            flag = True
            tmp.append(i)
else:
    print(ans)

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

char s[12345];

int main(){

	scanf("%s", s);

	int len = strlen(s);
	long long ans=0;
	for(int t=0;t < 1 << (len -1); t++){
		long long num = s[0] - '0';
		for(int i=0;i<len-1;i++){
			if(t & (1 << i)) {
			 	ans += num;
				num = 0;
			}
			num = num * 10 + s[i + 1] - '0';
		}
		ans += num;
	}
	cout<<ans<<'\n';

	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <chrono>
#include <queue>
#include <string>
#include <cassert>
#include <bitset>
#include <stack> 

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 998244353
#define BASE 77747
#define PI acos(-1.0)
#define MAXLEN 29

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef vector <ll> vll;

int dp[100000];
vector <int> g[100000];
int n, m;

int rec(int cur) {
	if (dp[cur] != -1) return dp[cur];
	dp[cur] = 0;
	for (int i = 0; i < g[cur].size(); i++) 
		dp[cur] = max(dp[cur], rec(g[cur][i]) + 1);
	return dp[cur];
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--;
		b--;
		g[a].push_back(b);
	}
	for (int i = 0; i < n; i++) dp[i] = -1;
	int ans = -1;
	for (int i = 0; i < n; i++) {
		ans = max(ans, rec(i));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8192
loop {
    n, m  = gets.split.map &:to_i
    break if n == 0
    board = (1..n).map{ gets.to_i }
    dice = (1..m).map{ gets.to_i }
    x = 0
    k = 0
    loop {
        x += dice[k]
        k += 1
        break if x >= n - 1
        x += board[x]
        break if x >= n - 1
    }
    puts k
}

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

using namespace std;

int cnt[3];
int temp[3];

int main() 
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	
	cin >> s;
	
	for(int i=0;i<s.length();i++)
	{
		cnt[s[i]-'a'] += 1;
	}
	memcpy(temp,cnt,sizeof(cnt));
	
	for(int j=0;j<3;j++)
	{
		memcpy(cnt,temp,sizeof(temp));
		bool ok = true;
		for(int i=0;i<s.length();i++)
		{
			if(cnt[(i + j)%3]==0)
			{
				ok = false;
				break;
			}
			cnt[(i + j)%3]-=1;
		}
		
		if(ok)
		{
			cout << "YES" << '\n';
			return 0;
		}
	}
	
	cout << "NO" << '\n';
	
	return 0;
}

Measured memory_bytes: 512
import static java.lang.Math.*;
import static java.util.Arrays.*;

import java.util.*;
import java.io.*;

public class Main {
	int n, k, m;
	ArrayList<Integer> ps;
	int N = 1120;
	int mem[][][];
	
	void run() {
		Scanner sc = new Scanner(System.in);
		prime();
		for(;;) {
			n = sc.nextInt(); k = sc.nextInt();
			if((n|k) == 0) break;
			mem = new int[n+1][k+1][m+1];
			for(int[][] a: mem) for(int[] b: a) fill(b, -1);
			System.out.println(solve(0, 0, 0));
		}
	}
	
	int solve(int sum, int num, int i) {
		if( i == m+1 || sum > n || num > k ) return 0;
		if( mem[sum][num][i] >= 0 ) return mem[sum][num][i];
		if( k == num ) {
			if( sum == n ) return mem[sum][num][i] = 1;
		}
		
//		debug(sum, num, i);
		int cnt = 0;
		for(int j=i;j<m && sum+ps.get(j)<=n;j++) cnt += solve(sum+ps.get(j), num+1, j+1);
		return mem[sum][num][i] = cnt;
	}
	
	void prime() {
		boolean[] p = new boolean[N+1];
		ps = new ArrayList<Integer>();
		for(int i=2;i<=N;i++) if(!p[i]) {
			for(int j=2*i;j<=N;j+=i) p[j] = true;
			ps.add(i);
		}
		m = ps.size(); 
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 200840
using System;
using System.Collections.Generic;
class Program
    {
    	static void Main(string[] args)
    	{
            string[] input = Console.ReadLine().Split(' ');
            int x = int.Parse(input[0]), y = int.Parse(input[1]), z = int.Parse(input[2]);
            Console.WriteLine((x - z) / (y + z));
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 11092
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

void Yes(void) {
  cout << "YES" << endl;
  exit(0);
}
void No(void) {
  cout << "NO" << endl;
  exit(0);
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n;
  cin >> n;
  int even = 0, odd = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a % 2 == 0) {
      even++;
    } else {
      odd++;
    }
  }
  if (odd % 2 == 1) {
    No();
  } else {
    even += odd / 2;
    if (even != 1 || even != 2) {
      Yes();
    } else {
      No();
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n; cin >> n; bool Y = false;
	for (int i = 0; i < n; i++) {
		char ch; cin >> ch;
		if (ch == 'Y')Y = true;
	}
	cout << (Y ? "Four\n" : "Three\n");
}

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

int main(){
	int a,b,k;
	cin >> a >> b >> k;
	REP(i,k){
		if(i % 2 == 0){
			if(a % 2 == 1)a -= 1;
			a /= 2;
			b += a;
		}else{
			if(b % 2 == 1)b -= 1;
			b /= 2;
			a += b;
		}
	}
	cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#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.at(i);
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  int j=0;
  for(int i=0;i<N;i++){
    if(i%2==0)
      j+=A.at(i);
    else
      j-=A.at(i);
  }
  cout << j << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 200009
#define MOD 1000000007
#define INF 1000000000
using Graph=vector<vector<int>>;

int main(){
  int N,M,X;
  cin>>N>>M>>X;
  vector<int> C(N);
  vector<vector<int>> A(N,vector<int>(M));
  for(int i=0;i<N;i++){
    cin>>C.at(i);
    for(int j=0;j<M;j++){
      cin>>A.at(i).at(j);
    }
  }

  bool flag=false;
  int ans=INF;
  for(int i=0;i<(1<<N);i++){
    int bit=i;
    int cost=0;
    vector<int> understand(M,0);
    for(int j=0;j<N;j++){
      if(bit%2==1){
        cost+=C.at(j);
        for(int k=0;k<M;k++){
          understand.at(k)+=A.at(j).at(k);
        }
      }
      bit>>=1;
    }
    bool sub=true;
    for(int k=0;k<M;k++){
      if(understand.at(k)<X){
        sub=false;
      }
    }
    if(sub){
      flag=true;
      ans=min(ans,cost);
    }
  }
  if(flag){
    cout<<ans<<endl;
  }else{
    cout<<-1<<endl;
  }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define UNWORDS(vec, str) for(int i = 0; i < (vec).size(); ++i) cout << (i ? str : "") << (vec)[i]
#define UNLINES(vec) for(int i = 0; i < (vec).size(); ++i) cout << (vec)[i] << endl
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin, (x).end()
using namespace std;

int main(){
	int n, k, p;
	
	cin >> n;
	REP(i, n){
		cin >> k >> p;
		cout << (k - 1) % p + 1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define ri rd<int>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; --i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++i)
const int maxS = 1048579;
const int maxN = 23;

template<class T> T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return f ? x : -x;
}

int n, m;
char str[maxS];
int mas[maxN];
int ln[maxS];
int* f[maxN][maxN];

inline int lb(int x) {
	return x & -x;
}

void print(int s, int len) {
	per (i, len-1, 0) printf("%d", s >> i & 1);
}

int main() {

	n = ri(), m = ri();
	rep (i, 0, n) mas[i] = (1 << i) - 1;
	rep (i, 1, mas[n]) ln[i] = ln[i >> 1] + 1;
	rep (i, 0, n) { 
		rep (j, 0, i) f[i][j] = new int[mas[i]+1];
		scanf("%s", str);
		rep (s, 0, mas[i]) if (str[s] == '1') ++f[i][i][s];
	}
	per (i, n, 0) per (j, i, 1) rep (s, 0, mas[i]) {
		f[i][j-1][s] += f[i][j][s];
		f[i-j][0][s>>j] += f[i][j][s];
		if ((s & mas[j]) == 0 || (s & mas[j]) == mas[j]) continue;
		int d = s >> (j-1) & 1, t;
		if (d == 0) { 
			t = s & mas[j];
			f[i-(j-ln[t])][ln[t]-1][((s & (~mas[j])) >> (j-ln[t])) | t] += f[i][j][s];
		//	print(s, i); printf(" %d -> ", j);
		//	print((((s & (~mas[j])) >> (j-ln[t])) | t), i-(j-ln[t])); printf(" %d\n", ln[t]-1);
		}
		else {
			int p = ln[(~s) & mas[j]];
			t = (s & mas[p]);
			f[i-(j-p)][p-1][((s & (~mas[j])) >> (j-p)) | t] += f[i][j][s];
		//	print(s, i); printf(" %d -> ", j);
		//	print((((s & (~mas[j])) >> (j-p)) | t), i-(j-p)); printf(" %d\n", p-1);
		}
	}
	per (i, n, 0) rep (s, 0, mas[i])
		if (f[i][0][s] >= m) {
			print(s, i);
			puts("");
			exit(0);
		}

	return 0;
}


Measured memory_bytes: 169728
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc_164b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] kazu = Console.ReadLine().Split(' ');
            int Ta_HP = int.Parse(kazu[0]);
            int Ta_AT = int.Parse(kazu[1]);
            int Ao_HP = int.Parse(kazu[2]);
            int Ao_AT = int.Parse(kazu[3]);

            while(Ta_HP > 0 && Ao_HP > 0)
            {
                Ao_HP -= Ta_AT;

                if(Ao_HP > 0)
                {
                    Ta_HP -= Ao_AT;
                }
            }

            if(Ta_HP > 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

            Console.Read();
        }
    }
}


Measured memory_bytes: 27524
from collections import defaultdict
from itertools import combinations, permutations
from operator import itemgetter
n, a, b, c, *L = map(int, open(0).read().split())
L.sort()
A = [a, b, c]
dicts = [defaultdict(lambda: 10**5) for _ in range(3)]
for i in range(n-2):
    for x in combinations(enumerate(L), i+1):
        k = tuple(i for i, l in x)
        v = sum(l for i, l in x)
        for d, x in zip(dicts, A):
            d[k] = min(d[k], abs(x-v) + 10*i)
scores = [sorted(d.items(), key=itemgetter(1)) for d in dicts]

ans = 10**5
for p1, p2, p3 in permutations(range(3)):
    k1, v1 = scores[p1][0]
    k1 = set(k1)
    for k2, v2 in scores[p2]:
        k2 = set(k2)
        if len(k1 & k2) == 0:
            break
    for k3, v3 in scores[p3]:
        k3 = set(k3)
        if len(k1 & k3) + len(k2 & k3) == 0:
            break
    ans = min(ans, sum([v1, v2, v3]))
print(ans)

Measured memory_bytes: 3436
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890

const int maxn = 2e5 + 10;


//initialization here
//


//
//initialization finish


// your function is here
//



//
// your function finished



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

	// your code is here
	//
	string s; cin >> s;

	while (s.size())
	{
		if (s.substr(0, 5) == "dream")
		{
			s.erase(0,5);
			if (s.substr(0, 2) == "er" && s.substr(0, 5) != "erase")s.erase(0, 2);
			continue;
		}

		if (s.substr(0, 5) == "erase")
		{
			s.erase(0, 5);
			if (s.substr(0, 1) == "r")s.erase(0, 1);
			continue;
		}

		NO;
		return 0;
	}

	YES;
	//
	// your code finished

	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<double> v(n);
  rep(i, n) cin >> v[i];

  priority_queue<double, vector<double>, greater<double> > pq;
  rep(i, n) pq.push(v[i]);

  rep(i, n-1){
    double sum = 0;
    sum += pq.top();
    pq.pop();
    sum += pq.top();
    pq.pop();
    pq.push(sum/2);
  }

  cout << pq.top() << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++) 
#define rep(i, a) loop(i, 0, a)
using namespace std;
const int MOD = 1000000007;
const int inf = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
//g++ -std==c++14
//setprecision(10)
int main(){
    long long n;
    cin >> n;
    int va = sqrt(n);
    for(int i = va + 1; i >= 1; i--){
        if(n % i == 0){
            cout << to_string(n / i).size() << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 384
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int main()
{
	int n, w;
	cin >> n >> w;
	vector<pair<ll, ll>> r(n);
	rep(i, n) {
		ll ww, v;
		cin >> ww >> v;
		r[i] = pair<ll, ll>(ww, v);
	}
	vector<vector<ll>> dp(110, vector<ll>(100010, 0));
	rep(i, n) {
		rep(j, w + 1) {
			if (j - r[i].first >= 0) {
				chmax(dp[i + 1][j], dp[i][j - r[i].first] + r[i].second);
			}
			chmax(dp[i + 1][j], dp[i][j]);
		}
	}
	ll ans = 0;
	rep(i, w + 1) {
		ans = max(dp[n][i], ans);
	}
	cout << ans << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}

Measured memory_bytes: 90368
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 800000000
#define MAX 1000

int main(){
  int  N,K;
  cin>>N>>K;
  vector<ll> A(N),sum(N+1,0);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    sum.at(i+1)=sum.at(i)+A.at(i);
  }
  for(int i=0;i<=N;i++){
    sum.at(i)-=i;
    sum.at(i)%=K;
  }
  map<int,ll> m;
  for(int i=0;i<=N;i++){
    if(m.count(sum.at(i))==0){
      m[sum.at(i)]=0;
    }
    m[sum.at(i)]++;
  }
  map<int,ll> count;
  for(auto x:m){
    count[x.first]=0;
  }
  for(int i=0;i<=min(K-2,N);i++){
    count[sum.at(i)]++;
  }

  ll ans=0;
  for(int i=0;i<=N;i++){
    if(i+K-1<=N){
      count[sum.at(i+K-1)]++;
    }
    ans+=count[sum.at(i)]-1;
    count[sum.at(i)]--;
  }
  cout<<ans<<endl;

}


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

int main(){
	int a,b,c,d;
  	cin >> a >> b >> c >> d;
  	a = max(a,c);
  	b = min(b,d);
  	if(b-a < 0) b = a;
	cout << b-a << endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n;
	string s;
	cin >> n >> s;

	if (n%2) cout << "No" << endl;
	else if (s.substr(0, n/2)==s.substr(n/2, n/2)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
let g=print_newline;;let rec f()=Scanf.scanf"%d %d
"(fun h w->if h<>0&&w<>0then(for i=1to h do let b=ref(i mod 2=0)in for j=1to w do print_char(if!b then '.'else '#');b:=not!b;done;g()done;f(g())));;f()

Measured memory_bytes: 2248
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<string>
#include<vector>
using namespace std;
#define REP(i, b, e) for ( int i = b; i < (int)e; i++ )
#define rep(i, n) REP(i, 0, n)
static const int MAX = 1000;
static const int INFTY = (1<<20);

int H, W, N;
char G[MAX][MAX];
pair<int, int> C[11];

int bfs(int sy, int sx, int ty, int tx){
  queue<pair<int, int> > Q;
  int d[MAX][MAX];
  rep(i, H) rep(j, W) d[i][j] = INFTY;
  Q.push(make_pair(sy, sx));
  d[sy][sx] = 0;
  pair<int, int> u, v;
  static const int dy[4] = {0, -1, 0, 1};
  static const int dx[4] = {1, 0, -1, 0};
  int ny, nx;
  while(!Q.empty()){
    u = Q.front(); Q.pop();
    if ( u.first == ty && u.second == tx ) return d[u.first][u.second];
    rep(r, 4){
      ny = u.first + dy[r];
      nx = u.second + dx[r];
      if ( ny < 0 || nx < 0 || ny >= H || nx >= W ) continue;
	   if ( d[ny][nx] != INFTY ) continue;
	   if ( G[ny][nx] == 'X' ) continue;
	   d[ny][nx] = d[u.first][u.second] + 1;
	   Q.push(make_pair(ny, nx));
    }
  }
    return -1;

}
main(){
  cin >> H >> W >> N;
  rep(i, H) rep(j, W){
    cin >> G[i][j];
    if ( G[i][j] == 'S' ) C[0] = make_pair(i, j);
    if ( '1' <= G[i][j] && G[i][j] <= '9' ) C[G[i][j]-'0'] = make_pair(i, j);
  }
  int sum = 0;
  rep(i, N) {
    int tmp = bfs(C[i].first, C[i].second, C[i+1].first, C[i+1].second);
    sum += tmp;
  }
  cout << sum << endl;

}

Measured memory_bytes: 5756