akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

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

const int MAXN = 101, MAXL = 101, INF = 110000 ;
long long d[MAXN][MAXL];

struct edge{int to, dist, enemy;};

int n, m, l, a, b, dist, e;

typedef pair<int, int> pp;
typedef pair<int, pp> ppp;

int main()
{
    while(cin >> n >> m >> l && n)
    {
        rep(i,n)rep(j,l + 1)d[i][j] = 1100000 ;
        vector<edge> g[MAXN];
        REP(m)
        {
            cin >> a >> b >> dist >> e;
            a--; b--;
            g[a].push_back((edge){b, dist, e});
            g[b].push_back((edge){a, dist, e});
        }

        priority_queue<ppp, vector<ppp>, greater<ppp> > que;
        que.push(ppp(0, pp( -l , 0)));
        d[0][l] = 0;
        int ans = 1000;

        //cout << d[1][l] << endl;

        while(!que.empty())
        {
            ppp p = que.top(); que.pop();
            int nowe = p.first, nowl = -p.second.first, now = p.second.second;
            //cout << "e:" << nowe << "  l:" << nowl << "  now:" << now << endl;
            if(now == n -1 ){ans = nowe; break;}
            
            REP(g[now].size())
            {
                edge ed = g[now][i];
                //cout << "to:" << ed.to << " dist:" << ed.dist << " enemy:" << ed.enemy << endl;
                //cout << "d[ed.to]:"<< d[ed.to][nowl] << endl;
                if(nowl - ed.dist >= 0 && nowe < d[ed.to][nowl - ed.dist] )
                {
                    d[ed.to][nowl - ed.dist] = nowe;
                    que.push(ppp(nowe, pp(ed.dist - nowl, ed.to)));
                }
                if(nowe + ed.enemy < d[ed.to][nowl])
                {
                    d[ed.to][nowl] = nowe + ed.enemy;
                    que.push(ppp(nowe + ed.enemy, pp(-nowl, ed.to)));
                }
            }
        }

        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1120
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define mod 1000000007
using namespace std;

int h,w;
vector<vector<int> > dp;
vector<vector<char> > wall;

int fun(int i,int j){
	if(i==0 && j==0)
		return 1;
	if(wall[i][j]=='#')
		return 0;
	if(dp[i][j]!=-1)
		return dp[i][j];
	int a=0;
	if(i>0)
		a=(a+fun(i-1,j))%mod;
	if(j>0)
		a=(a+fun(i,j-1))%mod;
	return dp[i][j]=a;
}

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);cout.tie(NULL);
	
	cin>>h>>w;
	
	dp.assign(h,vector<int> (w,-1));
	wall.assign(h,vector<char> (w));
	for (int i = 0; i < h; ++i)
	{
		for(int j=0;j<w;++j)
		cin>>wall[i][j];
	}
	cout<<fun(h-1,w-1);
	// cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
	return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	ll n, k;
	cin >> n >> k;
	n %= k;
	n = min(n, k - n);
	cout << n << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int main(){

    int x,y;
    cin>>x>>y;

    if(x>=1&&x<=9&&y>=1&&y<=9){
        cout<<x*y<<endl;
    }else{
        cout<<-1<<endl;
    }

    return 0;

}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll n,m,v,p;
vll a;

bool isOk(ll mid){
  if(mid<p) return true;
  ll point=a[mid]+m;
  if(a[p-1]>point) return false;
  ll total=(p-1)*m+(n-mid)*m;
  irep(i,p-1,mid){
    total+=min(m,point-a[i]);
  }
  return total>=m*v;
  
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>m>>v>>p;
  a.resize(n);
  rep(i,n) cin>>a[i];
  sort(a.rbegin(),a.rend());
  
  ll ok=0, ng=n;
  while(abs(ok-ng)>1){
    ll mid=(ok+ng)/2;
    if(isOk(mid)) ok=mid;
    else ng=mid;
  }
  cout<<ok+1<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<string> two = {"SS", "SW", "WS", "WW"};
    string ans = "";
    rep(i,4){
        string tmp = two[i];
        bool isOK = false;
        for(int i = 1; i < n; ++i){
            if(s[i]=='o'){
                if(tmp[i]=='S') tmp += (tmp[i-1] == 'S' ? 'S' : 'W');
                else tmp += (tmp[i-1] == 'S' ? 'W' : 'S');
            }else{
                if(tmp[i]=='S') tmp += (tmp[i-1] == 'S' ? 'W' : 'S');
                else tmp += (tmp[i-1] == 'S' ? 'S' : 'W');
            }
        }
        if(tmp[n] == tmp[0]){
            if(s[0] == 'o'){
                if(tmp[0]=='S' && tmp[n-1] == tmp[1]) isOK = true;
                else if (tmp[0]=='W' && tmp[n-1] != tmp[1]) isOK = true;
            }else{
                if(tmp[0]=='S' && tmp[n-1] != tmp[1]) isOK = true;
                else if (tmp[0]=='W' && tmp[n-1] == tmp[1]) isOK = true;
            }
        }
        if(isOK) {
            tmp.pop_back();
            ans = tmp;
            cout << ans << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<size_t I,class H,class...T>struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template<class H,class...T>struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class...T>istream&operator>>(istream&i,tuple<T...>&t){t=TupleReaderWriter<sizeof...(T),T...>::r(i);return i;}
template<class...T>ostream&operator<<(ostream&o,tuple<T...>&t){string delim=" ";TupleReaderWriter<sizeof...(T)-1,T...>::w(o,t,delim);return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    const int INF = 2.1e9;
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(N);
    for(auto &x : A) cin >> x;
    int ans = INF;
    rev_priority_queue<int> q0, q1;
    for(auto y : A) {
        auto assign = [&]() -> void {
            while (q1.size() >= K) {
                q0.push(q1.top()), q1.pop();
            }
            while (q1.size()) q1.pop();
        };
        for (auto z : A) {
            if(z < y) assign();
            else q1.push(z);
        }
        assign();
        if(q0.size() >= Q) {
            for(int i = 0; i < Q - 1; i++) q0.pop();
            int x = q0.top();
            ans = min(ans, x - y);
        }
        while(q0.size()) q0.pop();
    }
    cout << ans << endl;
}



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

int main() {
  int n, k;
  cin >> n >> k;
  
  vector<int> a(n);
  for(int i=0; i<n; i++) {
    cin >> a.at(i);
  }
  
  int count = 0;
  for(int i=0; i<n; i++) {
    if(a.at(i) >= k)
      count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, S; cin >> N >> S;
	vector<int> a(N); rep(i, 0, N) { cin >> a[i]; }
	int r(0), l(0), sum(0);
	int ans(INF);
	while (r < N) {
		while (r < N&&sum < S) {
			sum += a[r++];
		}
		if (sum >= S)chmin(ans, r - l);
		while (l < r&&sum >= S) {
			chmin(ans, r - l);
			sum -= a[l++];
		}
	}
	cout << (ans==INF?0:ans) << endl;
	return 0;
}

Measured memory_bytes: 3364
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
Mon = 0
for i in range(N):
    a1 = A[i]
    a2 = A[i+1]
    b = B[i]
    mst = a1 + a2
    if b >= mst:
        Mon += mst
        A[i+1] = 0
    else:
        Mon += b
        if a1 <= b:
            A[i+1] = A[i+1] - (b-a1)
print(Mon)

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

const long long lim = 1e18;

int main() {
  int n;
  cin >> n;
  long long a[n];
  for ( int i = 0; i < n; i++ ) {
    cin >> a[i];
  }
  long long mlt = 1;
  for ( int i = 0; i < n; i++ ) {
    if ( a[i] == 0 ) { mlt = 0; break; }
    mlt = ( mlt == -1 || a[i] > lim / mlt ) ? -1 : mlt * a[i];
  }
  cout << mlt << endl;
  return 0;
}


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

using namespace std;

int main() {
	long long m = 1000000007;
	
	int n;
	cin >> n;
	
	long long ans = 1;
	for(int i = 1; i <= n; i++) {
		ans = (ans * i) % m;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
import math

def main():
    N, L  = list(map(int, input().split(" ")))
    minimum = abs(L-1+1)
    argmin = 1
    for i in range(2, N+1):
        value = abs(L-1+i)
        if value < minimum:
            minimum = value
            argmin = i
    ans = (N-1)*(L-1) + N*(N+1)/2 - argmin
    print(int(ans))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
using System;
using System.Diagnostics;
using System.Collections.Generic;

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;

    void calc()
    {
        if (calc2()) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }

    bool calc2()
    {
        int N = cin.nextInt();
        string[] st = new string[N];
        for (int i = 0; i < N; i++)
        {
            st[i] = cin.next();
        }

        Dictionary<string, int> dic = new Dictionary<string, int>();
        char pre = st[0][0];
        foreach (var s in st)
        {
            if (dic.ContainsKey(s)) return false;
            dic[s] = 1;
            if (pre != s[0]) return false;
            pre = s[s.Length - 1];
        }

        return true;
    }


}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}




Measured memory_bytes: 11104
N = int(input())
H = list(map(int, input().split()))
if H[0] > 0:
  H[0] -= 1
if N == 1:
  ans = 'Yes'
else:
  for i in range(N-1):
    if H[i] == H[i+1]:
      pass
    elif H[i] < H[i+1]:
      H[i+1] -= 1
    else:
      ans = 'No'
      break
  else:
    ans = 'Yes'
print(ans)

Measured memory_bytes: 15020
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const long long SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

//↑template↑


int a, b;
vector<ll>v(a);
ll dp(ll a, ll b, ll c);
vector<vector<vector<ll>>>m;

int main() {
	cin >> a >> b;
	v.resize(a);
	for (int i = 0; i < a; ++i) { cin >> v[i]; }
	m.resize(a, vector<std::vector<ll>>(a, std::vector<ll>(b + 1, -1)));
	cout << dp(0, a - 1, b) << endl;
}


ll dp(ll a, ll b, ll c) {
	if (b < a || c < 0) { return -INF; }
	if (c == 0) { return 0; }
	if (a == b) { return max(0ll, v[a]); }
	if (m[a][b][c] != -1) { return m[a][b][c]; }

	ll aa = dp(a + 1, b, c - 1) + v[a], bb = dp(a + 1, b, c - 2), cc = dp(a, b - 1, c - 1) + v[b], dd = dp(a, b - 1, c - 2);

	return m[a][b][c] = max({ aa,bb,cc,dd,0ll });
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    int r, n;
    while (cin >> r >> n, r || n)
    {
        map<int, int> ma;
        for (int i = 0; i < n; i++)
        {
            int lx, rx, h;
            cin >> lx >> rx >> h;
            for (int j = lx; j < rx; j++)
            {
                ma[j] = max(ma[j], h);
            }
        }
        map<int, ld> mi;
        mi[-r] = ma[-r];
        mi[r] = ma[r - 1];
        for (int i = -r + 1; i <= r - 1; i++)
        {
            mi[i] = min(ma[i - 1], ma[i]);
        }
        ld last = 0;
        while (true)
        {
            bool check = true;
            last += 0.001;
            for (int i = -r; i <= r; i++)
            {
                ld pos = -r + last + sqrt(r * r - i * i);
                if (pos > mi[i] + EPS)
                    check = false;
            }
            if (check)
                continue;
            last -= 0.001;
            break;
        }
        cout << last << endl;
    }
}



Measured memory_bytes: 3236
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,M;
ll indegree[100010];
vector<ll> edgeList[100010];
vector<ll> rEdgeList[100010];
ll order[100010];
int main(){
    cin>>N>>M;
	for(ll i=0;i<N-1+M;i++){
		ll a,b;cin>>a>>b;a--;b--;
		edgeList[a].push_back(b);
		rEdgeList[b].push_back(a);
		indegree[b]++;
	}
	ll nowOrder=0;
	queue<ll> q;
	for(ll i=0;i<N;i++) if(indegree[i]==0) q.push(i);
	while(!q.empty()){
		ll now=q.front();q.pop();
		order[now]=nowOrder;
		nowOrder++;
		for(auto v:edgeList[now]){
			indegree[v]--;
			if(indegree[v]==0) q.push(v);
		}
	}
	for(ll i=0;i<N;i++){
		ll parent;
		if(order[i]==0)parent=-1;
		ll nowMaxOrder=-1;
		for(auto v:rEdgeList[i]){
			if(nowMaxOrder<order[v]){
				parent=v;
				nowMaxOrder=order[v];
			}
		}
		cout<<parent+1<<endl;
	}
    return 0;
}

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

long long N, M;

bool can(long long m){
	if(M < 2*m){
		return false;
	}
	if(N + (M-2*m)/2 < m){
		return false;
	}
	return true;
}

int main(){
	cin >> N >> M;
	long long s = 0, e = 1e13;
	while(s + 1 < e){
		long long m = (s + e)/2;
		if(can(m)){
			s = m;
		}else{
			e = m;
		}
	}
	cout << s << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 400400;
int sz[maxn], id[maxn], has[maxn], tin[maxn], tout[maxn], T = 1, nxt[maxn], to[maxn][26], cnt = 1;
void insert(char s[], int x){
	int cur = 0;
	for(int i = 0; s[i]; i++){
		int v = s[i] - 'a';
		if(to[cur][v] == 0) to[cur][v] = cnt++;
		cur = to[cur][v];
	}
	sz[cur] = 1;
	has[cur] = 1;
	nxt[cur] = cur;
	id[x] = cur;
}
void dfs(int root){
	tin[root] = T++;
	int sons = 0;
	for(int i = 0; i < 26; i++) if(to[root][i] != 0){
		dfs(to[root][i]);
		sons++;
		sz[root] += sz[to[root][i]];
		nxt[root] = nxt[to[root][i]];
	}
	if(sons != 1 || has[root])
		nxt[root] = root;
	tout[root] = T++;
}
bool is_anc(int u, int v){
	return tin[u] <= tin[v] && tout[v] <= tout[u];
}
char s[maxn];
int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		scanf("%s", s);
		insert(s, i);
	}
	dfs(0);
	int q;
	cin >> q;
	while(q--){
		int k; cin >> k;
		string s; cin >> s;
		vector<int> vals;
		for(int j = 0; j < 26; j++) vals.push_back(s[j] - 'a');
		k = id[k];
		int res = 1, cur = 0;
		while(cur != k){
			if(has[cur])
				res++;
			for(int v : vals){
				int u = to[cur][v];
				if(u != 0){
					if(is_anc(u, k)){
						cur = nxt[u];
						break;
					} else {
						res += sz[u];
					}
				}
			}
		}
		printf("%d\n", res);
	}
	return 0;
}


Measured memory_bytes: 69632
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (k : x : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  putStrLn $ if x <= 500 * k then "Yes" else "No"

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
import sys
input = sys.stdin.readline

N, u, v = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

u -= 1
v -= 1

def bfs1():
    q = [v]
    d = 0
    D = [-1]*N
    D[v] = 0
    while q:
        qq = []
        d += 1
        for p in q:
            for np in graph[p]:
                if D[np] == -1:
                    D[np] = d
                    qq.append(np)
        q = qq
    return D

D = bfs1()
dis = D[u]
canuse = [True]*N
for i in range(N):
    if D[i] <= dis//2:
        canuse[i] = False

def bfs2():
    q = [u]
    d = 0
    D = [-1]*N
    D[u] = 0
    while q:
        qq = []
        d += 1
        for p in q:
            for np in graph[p]:
                if D[np] == -1 and canuse[np]:
                    D[np] = d
                    qq.append(np)
        q = qq
    return D


D2 = bfs2()
ans = 0
for i in range(N):
    if len(graph[i]) == 1 and D2[i] != -1:
        ans = max(D[i]-1, ans)
print(ans)

Measured memory_bytes: 59680
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <cmath>
#include <numeric>
#include <stack>
#include <iomanip>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

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

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr 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 };

namespace {
    template<typename T> bool chmax(T& a, T b) { if (a <= b) { a = b; return true; } return false; }
    template<typename T> bool chmin(T& a, T b) { if (a >= b) { a = b; return true; } return false; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
    };

    // 2次元用の標準入出力
    template<typename T>
    struct inpn {
        std::size_t szi, szj;
        inpn(std::size_t _szi, std::size_t _szj) : szi(_szi), szj(_szj) {}
        operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i)
                for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j];
            return a;
        }
    };

    inp inp1; // input one
}

int main() {

    string s = inp1;

    if (s == "ABC") Cout("ARC");
    else Cout("ABC");

    return 0;
}

Measured memory_bytes: 3624
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

const int N=1e5+1;
void solve() {
    cini(n);
    vi f(N);
    int ans=0;
    for(int i=0; i<n; i++) {
        cini(aux);
        f[aux]++;
        ans+=aux;
    }

    cini(q);
    for(int i=0; i<q; i++) {
        cini(b);
        cini(c);
        int d=c-b;
        ans+=f[b]*d;
        f[c]+=f[b];
        f[b]=0;
        cout<<ans<<endl;
    }
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


Measured memory_bytes: 3972
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    if n == 1:
        print("Hello World")
    else:
        print(II()+II())
    return

#B
def B():
    n, t = LI()
    ans = inf
    for i in range(n):
        c, ti = LI()
        if ti <= t:
            ans = min(ans, c)
    if ans == inf:
        print("TLE")
        return
    print(ans)
    return

#C
def C():
    n = II()
    xyh = LIR(n)
    xyh.sort(key = lambda x:x[2], reverse = True)
    x1, y1, h1 = xyh[0]
    del xyh[0]
    for x in range(101):
        for y in range(101):
            h = abs(x - x1) + abs(y - y1) + h1
            flg = True
            for xn, yn, hn in xyh:
                if max(h - abs(x - xn) - abs(y - yn), 0) == hn:
                    continue
                flg = False
                break
            if flg:
                print(x, y, h)
                return 
    return

#D
def D():
    n, m = LI()
    ans = 1
    for i in range(1,int(math.sqrt(m)+1)):
        if m % i == 0:
            a = m // i
            #print(i,a)
            if a * n <= m:
                ans = max(ans, a)
            if i * n <= m:
                ans = max(ans, i)
    print(ans)
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 38640
def main():
    n,m = map(int,input().split())
    a = ['' for _ in range(n)]
    b = ['' for _ in range(m)]

    for i in range(n):
        a[i] = input()
    for i in range(m):
        b[i] = input()

    for i in range(n-m+1):
        for j in range(n-m+1):
            same = True
            for y in range(m):
                for x in range(m):
                    if a[i+y][j+x] != b[y][x]:
                        same = False

            if same:
                return 'Yes'

    return 'No'

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


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

int main()
{
    int N, L;
    cin >> N >> L;
    vector<string> v(N);
    for (int i = 0; i < N; i++)
    {
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < N; i++)
    {
        cout << v.at(i);
    }
}


Measured memory_bytes: 3676
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

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

const int maxn = 1e6 + 5;
const int maxn2 = 2e5 + 5;
int a[maxn2], b[maxn], vis[maxn];

int main()
{
    int n;
    cin >> n;
    memset(b, 0, sizeof b);
    memset(vis, 0, sizeof vis);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++)
    {
        if (vis[a[i]]) 
        {
            b[a[i]] = 1;
            continue;
        }
        for (int j = 2; j * a[i] <= 1000000; j++)
        {
            b[j * a[i]] = 1;
        }
        vis[a[i]] = 1;
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += b[a[i]] == 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
ll v[20001], dp[2][1010];
ll a[2][1010],b[2][1010];
int main(){
	ll n,m,k;	cin>>n>>m>>k;
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	fill((ll*)dp, (ll*)(dp+2), INF);
	fill((ll*)b, (ll*)(b+2), INF);
	dp[0][0]=k;	a[0][0]=b[0][0]=v[0];
	for(int i=1;i<n;i++){
		for(int j=0;j<m;j++){
			if(dp[0][j]==INF)continue;
			//その箱に追加する場合
			if(j+1<m){
				dp[1][j+1]=dp[0][j];
				a[1][j+1]=max((ll)a[0][j],v[i]);
				b[1][j+1]=min((ll)b[0][j],v[i]);
			}
			//新しく箱を作る場合
			ll num=k+dp[0][j];
			num+=(a[0][j]-b[0][j])*(j+1);
			dp[1][0]=min(dp[1][0],num);
			a[1][0]=b[1][0]=v[i];
		}
		for(int j=0;j<m;j++){
			dp[0][j]=dp[1][j];	dp[1][j]=INF;
			a[0][j]=a[1][j];	a[1][j]=0;
			b[0][j]=b[1][j];	b[1][j]=INF;
		}
	}
	ll ans=INF;
	for(int i=0;i<m;i++){
		//ll num=dp[0][i];
		ll num=dp[0][i]+(a[0][i]-b[0][i])*(i+1);
		ans=min(ans,num);
	}
	cout<<ans<<endl;
	return 0;
}


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

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
const int MX = 200005;

ll n, m, k;
ll np[MX], mp[MX];

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> n >> m >> k;
	// NO SORT
	vector<ll> a(n), b(m);
	for (int i = 0; i < n; ++i) {
		cin >> a[i]; 
		np[i + 1] = a[i] + np[i];
	}
	
	for (int i = 0; i < m; ++i) {
		cin >> b[i];
		mp[i + 1] = b[i] + mp[i];
	}
	
	ll ans = 0;
	for (ll l = 0, r = 0; l <= n; ++l) {
		ll t = np[l];
		while (r < m && t + mp[r + 1] <= k) ++r;
		while (r > 0 && t + mp[r] > k) --r;
			
		if (t + mp[r] <= k) ans = max(ans, l + r);
	} 
	
	cout << ans;
}


Measured memory_bytes: 9536
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long m = sc.nextLong();
    long ans = 1;
    for(long i = 1; (i * i) <= m; i++) {
      if((m % i) == 0) {
        long t = m / i;
        if(t >= n) ans = Math.max(ans, i);
        if(i >= n) ans = Math.max(ans, t);
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

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

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n, k;
    cin >> n >> k;
    int ans = mod;
    rep(i, 1 << n) {
        int fin = 1;
        rep(j, n) {
            if (i & (1 << j)) {
                fin *= 2;
            } else {
                fin += k;
            }
        }
        ans = min(ans, fin);
    }
    cout << ans << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

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

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


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

#include <atcoder/all>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

using namespace atcoder;

int n, m;
char c[55][55];
int dist[55][55][55][55];

void bfs(int sx, int sy) {
    rep(x, n) rep(y, m) dist[sx][sy][x][y] = mod;
    dist[sx][sy][sx][sy] = 0;
    queue<pii> que;
    que.emplace(sx, sy);
    while (!que.empty()) {
        auto [x, y] = que.front();
        que.pop();
        rep(dx, 2) rep(dy, 2) if (dx ^ dy) {
            int nx = x + dx, ny = y + dy;
            if (0 <= nx && nx < n && 0 <= ny && ny < m && c[nx][ny] != '#') {
                if (chmin(dist[sx][sy][nx][ny], dist[sx][sy][x][y] + 1))
                    que.emplace(nx, ny);
            }
        }
    }
}

int main() {
    scanf("%d%d", &n, &m);
    rep(i, n) rep(j, m) scanf(" %c", &c[i][j]);
    map<pii, int> stone_idx, grid_idx;
    int source, sink;
    {
        int cur = 0;
        rep(i, n) rep(j, m) if (c[i][j] == 'o') stone_idx[{i, j}] = cur++;
        rep(i, n) rep(j, m) grid_idx[{i, j}] = cur++;
        source = cur++;
        sink = cur++;
    }
    for (auto p : stone_idx) bfs(p.fi.fi, p.fi.se);
    mcf_graph<int, int> gr(sink + 1);
    rep(i, stone_idx.size()) gr.add_edge(source, i, 1, 0);
    for (auto p : grid_idx) gr.add_edge(p.se, sink, 1, 0);
    for (auto p : stone_idx) {
        auto [a, b] = p.fi;
        rep(x, n) rep(y, m) if (dist[a][b][x][y] < mod) {
            gr.add_edge(p.se, grid_idx[{x, y}], 1, 100 - dist[a][b][x][y]);
        }
    }
    printf("%d\n", 100 * stone_idx.size() - gr.flow(source, sink).se);
}

Measured memory_bytes: 8960
#include <stdio.h>

long long int merge_sort(int N, int a[]){
  int pivot=N/2;
  long long int merge=0;
  int left=0,right=0;
  int b[100001];
  if(N==1) return 0;
  for(int i=0;i<N;i++) b[i]=a[i];
  merge+=merge_sort(pivot,b);
  merge+=merge_sort(N-pivot,b+pivot);
  b[N+1]=b[pivot-1];
  while(left<pivot && right<N-pivot)
    if(b[left]<=b[right+pivot]){
      a[left+right]=b[left];
      left++;
    } else {
      a[left+right]=b[pivot+right];
      right++;
      merge+=pivot-left;
    }
  while(left<pivot){
      a[left+right]=b[left];
      left++;
  }
  while(right<N-pivot) {
      a[left+right]=b[pivot+right];
      right++;
      merge+=pivot-left;
    }
  return merge;
}

int main(){
  // input
  int N;
  int a[100000];
  // binary_search
  int left=1,right=1000000000,pivot;
  // element_number
  int b[100000];
  int S[100001];
  long long int inverse;
  
  // input
  scanf("%d",&N);
  for(int i=0;i<N;i++)
    scanf("%d",&a[i]);

  // binary_search
   while(right-left){
    pivot=(left+right+1)/2;
    // element_number
    for(int i=0;i<N;i++) b[i]=(a[i]>=pivot)*2-1;
    S[0]=0; for(int i=0;i<N;i++) S[i+1]=S[i]+b[i];
    //  for(int i=0;i<=N;i++) printf(" %d",S[i]); printf("\n");
    inverse = (long long int)N*(N+1)/2-merge_sort(N+1,S);
    //    printf("[%10d %10d] pivot %10d inverse %10d\n",left,right,pivot,inverse);
    if(inverse >= ((long long int)N*(N+1)/2+1)/2)
      left =pivot;
    else
      right=pivot-1;
  }
    
  printf("%d\n",left);
  
  return 0;
}


Measured memory_bytes: 2176
use std::io::stdin;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let mut line = buf.split_whitespace();
    let n: u64 = line.next().unwrap().parse().unwrap();
    let blue: u64 = line.next().unwrap().parse().unwrap();
    let red: u64 = line.next().unwrap().parse().unwrap();

    println!("{}", solve(n, blue, red));
}

fn solve(n: u64, blue: u64, red: u64) -> u64{
    let quotient = n / (blue + red);
    let surplus = n % (blue + red);
    return  match surplus {
        surplus if surplus >= blue => quotient * blue + blue,
        surplus if surplus < blue => quotient * blue + surplus,
        _ => unreachable!()
    }
}

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

#define int long long

signed main() {
    int D, N;
    
    cin >> D >> N;
    
    int ans = N;
  
    if(ans == 100){
        ans += 1;
    }
    
    for(int i = 0; i < D; ++i){
        ans *= 100;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <tuple>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;
const long MOD = 1e9 + 7;
#define ll int64_t
string S;
long N;

string ls = "";
string rs = "";

ll ans = 0;


map< pair<string, string>, ll > hashmap3;


void dfs(int pos, bool isleft) {

  if (pos > N - 1) {
    hashmap3[make_pair(ls, rs)] += 1;

    if (isleft == true) {
      if (pos > 0)ls.erase(ls.end() - 1);
    } else {
      if (pos > 0)rs.erase(rs.end() - 1);
    }
    return;
  }

  ls += S[pos];
  dfs( (pos + 1 ), true);

  rs += S[pos];
  dfs((pos + 1 ), false);


  if (isleft == true) {
    if (pos > 0)ls.erase(ls.end() - 1);
  } else {
    if (pos > 0)rs.erase(rs.end() - 1);
  }



}


void dfs2(int pos, bool isleft) {

  if (pos > N - 1) {
    if (hashmap3[make_pair(rs, ls)] >0){
      ans+=hashmap3[make_pair(rs, ls)];
    }

    if (isleft == true) {
      if (pos > 0)ls.erase(ls.end() - 1);
    } else {
      if (pos > 0)rs.erase(rs.end() - 1);
    }
    return;
  }

  ls += S[pos];
  dfs2( (pos + 1 ), true);


  rs += S[pos];
  dfs2((pos + 1 ), false);

  if (isleft == true) {
    if (pos > 0)ls.erase(ls.end() - 1);
  } else {
    if (pos > 0)rs.erase(rs.end() - 1);
  }

}




int main()
{


  cin >> N;
  cin >> S;


  dfs(0, false);
  ls = "";
  rs = "";
  S = S.substr(N, 2 * N );
  reverse(S.begin(), S.end());

  dfs2(0, false);

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 84480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    long double a,b,c;
    cin >> a >> b >> c;
    long double t = sqrtl(a*b);
    if(a+b+2*t<c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define setbit(s, i) (s|=(1LL<<(i)))
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "B"
int k;
int a[100001];
int main(){
    #ifdef Kanikou
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Kanikou
    read(k);
    FOR(i, 1, k) read(a[i]);
    ll l=2, r=2;
    DFOR(i, k, 1){
        ll low;
        if(l%a[i]==0) low=l;
        else low=l-l%a[i]+a[i];
        ll high=r-r%a[i];
        if(low>high){
            puts("-1");
            return 0;
        }
        low/=a[i];
        high/=a[i];
        l=low*a[i];
        r=high*a[i]+a[i]-1;
    }
    write(l);
    putchar(' ');
    write(r);
}

Measured memory_bytes: 640
#E
N,P=map(int,input().split())
S=input()
ans=0
if P in (2,5):
    for i,s in enumerate(S):
        if int(s)%P==0:
            ans+=i+1
else:
    cnt=[0 for _ in range(P)]
    CS=0
    PLC=1
    for s in S[::-1]:
        tmp=(int(s)*PLC)%P
        CS=(CS+tmp)%P
        cnt[CS]+=1
        PLC=(PLC*10)%P
        # print(CS)
        # print(cnt)
    for c in cnt:
        ans+=c*(c-1)//2
    ans+=cnt[0]
print(ans)


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

using namespace std;

int main(){
  int n,num,q,b,m,e;
  vector<int> a;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num;
    a.push_back(num);
  }

  cin >> q;
  for (int i = 0; i < q; i++){
    cin >> b;
    cin >> m;
    cin >> e;
    rotate(a.begin()+b,a.begin()+m,a.begin()+e);
  }
  for (int i = 0; i < n; i++){
    if (i != n - 1){
      cout << a[i] << " ";
    }else{
      cout << a[i] << endl;
    }
  }

  return 0;
}



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

int main() {
    int long long n; cin >> n;
    vector<int> a(n+1); for (int i=1; i<=n; ++i) cin >> a[i];
    vector<int> ans(n+1);
    for (int i=n; i>=1; --i) {   // 後ろから見ていく
        int sum = 0;
        for (int j=i; j<=n; j+=i) {
            sum += ans[j];
        }
        if (sum%2 != a[i]) ans[i]++;
    }
    int m = 0;
    for (int i=1; i<=n; ++i) {
        m += ans[i];
    }
    cout << m << endl;
    for (int i=1; i<=n; ++i) {
        if (ans[i] == 1) cout << i << " ";
    }
    return 0;
}

Measured memory_bytes: 2432
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
int INF = numeric_limits<int>::max() / 2;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 1;
	for(int i = 1;i < n;i++){
		if(a[i] != a[i-1]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  if(a <= c && c <= b){
    cout << "Yes\n";
  }
  else
  {
    cout << "No\n";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

ll s[55],p[55];
ll N,X;

ll dfs(ll a,ll b){
  if(a==0)return 1;
  if(b==1)return 0;
  if(b<=s[a-1]+1) return dfs(a-1,b-1);
  if(b==s[a-1]+2) return p[a-1]+1;
  if(b==s[a-1]*2+3) return p[a];
  else return p[a-1]+1+dfs(a-1,b-2-s[a-1]);
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> X;
  s[0]=1LL,p[0]=1LL;
  for(int i=0;i<N;i++){
    s[i+1]=s[i]*2+3;
    p[i+1]=p[i]*2+1;
  }

  cout << dfs(N,X) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

ll v[51];

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

    int n = 50;
    rep(i, 50) v[i] = 49 + k / 50;

    k %= 50;

    rep(i, k) {
        v[i] += n+1;
        rep(j, n) {
            v[j]--;
        }
    }

    cout << n << endl;
    rep(i, n) {
        cout << v[i];
        if (i != n - 1) cout << " ";
    }
    cout << endl;

    return 0;
}

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

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if((a < b) && (a < c) && (b < c)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {
	
	int d, t, s;
	cin >> d >> t >> s;
	if (d <= t * s)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3620