akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    ll N, K;
    cin >> N >> K;

    vec<ll> P(N);
    rep(i, N) cin >> P[i], --P[i];

    vec<ll> C(N);
    rep(i, N) cin >> C[i];

    ll ans = -1e18 - 9;
    rep(i, N) {
        ll now = i;
        ll smS = 0;
        vec<ll> sm;
        while (1) {
            smS += C[now];
            sm.push_back(smS);
            now = P[now];
            if (now == i) break;
        }
        rep(j, sm.size()) {
            ll tmp     = -1e18 - 9;
            ll zan     = K - (j + 1);
            if(zan < 0) break;
            ll roopCnt = zan / sm.size();
            ll roopSm  = smS * roopCnt;
            tmp        = max({tmp, sm[j], sm[j] + roopSm});
            ans        = max(ans, tmp);
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3820
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	scan(N);
	prin((1000-N%1000)%1000);
	return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>

int main(){
    int w,h,i,j;
    while(1){
        scanf("%d%d",&h,&w);
        if(w==0&&h==0) break;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if(i%2==0){
                    if(j%2==0){
                        printf("#");
                    }else{
                        printf(".");
                    }
                }else {
                    if(j%2==0){
                        printf(".");
                    }else{
                        printf("#");
                    }
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
#define FOR(i,n) for(int i=0; i<int(n); i++)
#define FOR1(i,m,n) for(int i=int(m); i<int(n); i++)

typedef struct _Node {
    int id;
    bool flag = false;
    vector<struct _Node*> next;
} Node;

const int MAXN = 1e5;
int n, m;
int a[MAXN], b[MAXN];
vector<Node> nodes;

void _get_path(int start, deque<int> &path, int front) {
    Node *node = &nodes[start];
    Node *prev = nullptr;

    if (front == 1)
        path.push_front(start);
    else
        path.push_back(start);

    nodes[start].flag = true;

    while (node != prev) {
        prev = node;
        for (auto p : node->next) {
            if (p->flag == false) {
                if (front == 1)
                    path.push_front(p->id);
                else
                    path.push_back(p->id);
                p->flag = true;
                node = p;
                break;
            }
        }
    }
}

void get_path(int start, deque<int> &path) {
    int id;
    path.push_back(start);
    nodes[start].flag = true;

    int count = 0;
    deque<int> subpath[2];
    for (auto p : nodes[start].next) {
        if (p->flag == false) {
            _get_path(p->id, path, count);
            count++;
            if (count >= 2) break;
        }
    }

    return;
}

int main(int argc, char *argv[])
{
    cin >> n >> m;

    FOR(i,n) {
        Node node;
        node.id = i;
        nodes.push_back(node);
    }

    FOR(i,m) {
        int a, b;
        cin >> a >> b;
        nodes[a-1].next.push_back(&nodes[b-1]);
        nodes[b-1].next.push_back(&nodes[a-1]);
    }

    deque<int> path;
    FOR(i,n) {
        if (nodes[i].next.size() != 0) {
            get_path(i, path);
            break;
        }
    }

    printf("%d\n", path.size());
    for(auto v : path) printf("%d ", v+1);
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 8044
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int a ,b;
  cin >> a >> b;
  rep(i,20000){
    int l = 0.08*i;
    int r = 0.1*i;
    if(l == a  && r == b){
      cout<<i<<endl;
      return 0;
    }
    
  }
  cout<<"-1"<<endl;
  return 0;
}

Measured memory_bytes: 256
/*
AOJ0134
@kankichi573
*/
#include <stdio.h>
main()
{
        int i,n,p;
        long long sum=0;

        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
                scanf("%d",&p);
                sum += p;
        }
        printf("%d\n",(int)(sum/n));
        return(0);
}

Measured memory_bytes: 592
n,m = map(int, input().split())
e = [set() for _ in range(n)]
for _ in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    e[u].add(v)
    e[v].add(u)

def dfs():
    col = [-1]*n
    col[0] = 0
    q = [0]
    while len(q)>0:
        v = q.pop()
        c = col[v]
        for u in e[v]:
            if col[u]<0:
                col[u] = (c+1)%2
                q.append(u)
            else:
                if c==col[u]:
                    return False
    return True

if not dfs():
    print(n*(n-1)//2 - m)
    exit()

visited = [False]*n
visited[0] = True
num = [0,0]
q = [(0,0)]
while len(q)>0:
    u,d = q.pop()
    num[d%2] += 1
    for v in e[u]:
        if visited[v]:
            continue
        q.append((v,d+1))
        visited[v] = True

print(num[0]*num[1]-m)

Measured memory_bytes: 40736
#include <iostream>
using namespace std;
int main(){
  int n;
  int l[10];
  int i;
  cin >> n;
  for (i=0;i<n;i++){
    cin >> l[i];
  }
  int sum=0;
  int max=0;
  for (i=0;i<n;i++){
    if (max < l[i]){
      max = l[i];
    }
    sum = sum + l[i];
  }
  sum = sum - max;
  if (sum > max){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a, b;

    scanf("%d %d", &a, &b);
    if(a + b == 15){
        printf("+\n");
    }
    else if(a * b == 15){
        printf("*\n");
    }
    else{
        printf("x\n");
    }

    return 0;
}

Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: i32 = read();
    let mut result = 0;
    for x in 1..n+1 {
        let x = x.to_string();
        let len = x.chars().count();
        if len % 2 != 0 {
            result += 1;
        }
    }

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

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 1e6 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

bool la2[N];
int n, m, a;
ll mem[N];

ll dp(int step) {
  if(step == n)
    return 1;
  if(step > n)
    return 0;
  ll& ret = mem[step];
  if(~ret)
    return ret;
  ret = 0;
  if(!la2[step + 1])
    ret = ((ret % MOD) + (dp(step + 1) % MOD)) % MOD;
  if(!la2[step + 2])
    ret = ((ret % MOD) + (dp(step + 2) % MOD)) % MOD;
  return ret;
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a;
    la2[a] = 1;
  }
  memset(mem, -1, sizeof mem);
  cout << dp(0);
  return 0;
}


Measured memory_bytes: 11520
#include <bits/stdc++.h>
#define Int int64_t
#define pb push_back
using namespace std;

Int find(Int n) 
{ 
    Int count = 0; 
    for (Int i = 5; n / i >= 1; i *= 5) 
        count += n / i; 
  
    return count; 
} 
int main()
{
  Int N;cin>>N;
  if(N&1){
      cout<<0<<"\n";
      return 0;
  }
  cout<<find(N/2)<<"\n";
  
  
   
   
}

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

int main(){
    int H, W;
    cin >> H >> W;
    string s;
    for(int i=0;i<H+2;i++){
        if(i!=0 && i!=H+1){
            cin >> s;
        }
        for(int j=0;j<W+2;j++){
            if(i==0 || i==H+1 || j==0 || j==W+1){
                cout << '#';
            }else{
                cout << s[j-1];
            }
        }
        cout << endl;
    }
    return 0;
}

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

int main(){
    string S;
    cin >> S;
    int ans = 0;
    for(int i = 0; i < (int)S.size()/2; i++){
       // cout << S[i] << " " << S[S.size()-i-1] << endl;
        if(S[i] == S[S.size()-i-1]){
            continue;
        }else{
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

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

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

let main() =
    let n = read int
    (n + 2 - 1) / 2 |> puts
    ()

// -----------------------------------------------------------------------------------------------------
main()
writer.Dispose()


Measured memory_bytes: 13268
require 'set'
n = gets.to_i

xy = n.times.map{ gets.split.map(&:to_i) }
min = n
combis = 0.step(n-1).to_a.combination(2)

combis.each.map do |c1|
  dx1 = xy[c1[0]][0] - xy[c1[1]][0]
  dy1 = xy[c1[0]][1] - xy[c1[1]][1]
  cnt = combis.count do |c2|
    dx2 = xy[c2[0]][0] - xy[c2[1]][0]
    dy2 = xy[c2[0]][1] - xy[c2[1]][1]
    (dx1 == dx2 && dy1 == dy2) || (dx1 == -dx2 && dy1 == -dy2)
  end
  min = (n - cnt) if (n - cnt) < min
end

p min


Measured memory_bytes: 1916
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String row1 = sc.next();
        String row2 = sc.next();

        String reverse = row1.charAt(2) + "" + row1.charAt(1)+ ""  + row1.charAt(0);

        if ( reverse.equals(row2)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<set>
#include<vector>
using namespace std;
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	set<pair<int,int> >pos;
	int xx[n+1];
	int yy[m+1];
	vector<int>x;
	vector<int>y;
	int maxx=0;
	int maxy=0;
	for(int i=1;i<=n;++i)
		xx[i]=0;
	for(int i=1;i<=m;++i)
		yy[i]=0;
	for(int i=1;i<=k;++i){
		int a,b;
		cin>>a>>b;
		pos.insert(make_pair(a,b));
		++xx[a];
		++yy[b];
		if(xx[a]>maxx){
			maxx=xx[a];
			x.clear();
			x.push_back(a);
		}
		else if(xx[a]==maxx)
			x.push_back(a);
		if(yy[b]>maxy){
			maxy=yy[b];
			y.clear();
			y.push_back(b);
		}
		else if(yy[b]==maxy)
			y.push_back(b);
	}
	for(int i=0;i<x.size();++i)
		for(int j=0;j<y.size();++j)
			if(pos.count(make_pair(x[i],y[j]))==0){
				cout<<maxx+maxy<<endl;
				return 0;
			}
	cout<<maxx+maxy-1<<endl;
	return 0;
}

Measured memory_bytes: 21904
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}


 main()

{
    fast
    int n,k,x,mx=0;
    cin>>n>>k;
    int g=0;
    f(i,1,n)
    {
        cin>>x;
        mx=max(mx,x);
        g=__gcd(x,g);
    }
    if(k%g==0 && k<=mx)
    {
        cout<<"POSSIBLE"<<endl;
    }
    else
    {
        cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}


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

int main()
{
  int a, b;
  string s;
  cin >> a >> b >> s;
  if(s[a] == '-'){
    sort(s.begin(), s.end());
    if(s[1] != '-'){
      cout << "Yes" << endl;
      return(0);
    }
  }
  cout << "No" << endl;
}

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

#define ll long long
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int n;
int t[100009];
int x[100009];
int y[100009];

int main() {
   cin >> n;
   int cx = 0, cy = 0;
   bool ok = true;
   for (int i = 0; i < n; i++) {
      int d = cx + cy;
      cin >> t[i] >> x[i] >> y[i];
      int dif = abs(d-x[i]-y[i]);
      if (dif <= t[i]) {
         if (t[i]%2==0 && dif%2==0) {

         } else if (t[i]%2!=0 && dif%2!=0) {

         } else {
            ok = false;
         }
      } else {
         ok = false;
      }
   }

   if (ok) {
      puts("Yes");
   } else {
      puts("No");
   }

   return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;

ll N, M, X, C[12], A[12][12], ans=1000000000;

void dfs(vector<ll> v, ll id) {
    if(id==N) {
        ll S[12]={0}, minv=0, flag=0;
        for(int i=0;i<N;i++) {
            if(v[i]==1) {
                for(int j=0;j<M;j++) {
                    S[j] += A[i][j];
                }
                minv += C[i];
            }
        }                
        for(int j=0;j<M;j++) {
            if(S[j]<X) flag=1;
            //cout << " " << S[j];
        }
        //cout << endl;
        //cout << flag << endl;
        if(flag==0) ans = min(ans, minv);
        
        return;
    }
    dfs(v, id+1);
    v[id] = 1;
    dfs(v, id+1);
}

signed main(){
    cin >> N >> M >> X;
    for(int i=0;i<N;i++) {
        cin >> C[i];
        for(int j=0;j<M;j++) {
            cin >> A[i][j];
        }
    }
    vector<ll> vemp(N,0);
    dfs(vemp, 0);
    if(ans>=1000000000) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

long long gcd(long long c,long long d){
  if(c==d)return c;
  long long e=max(c,d),f=min(c,d);
  if(f==0)return e;
  return gcd(e%f,f);
}

int main() {
  long long a,b,c,d,e;
  cin>>a>>b>>c>>d;
  e=c*d/gcd(c,d);
  long long c_=b/c-(a-1)/c,d_=b/d-(a-1)/d,e_=b/e-(a-1)/e;
  cout<<b-a+1-c_-d_+e_;
  
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let s = i.read_line();
    let r = if solve(s) { "YES" } else { "NO" };
    writeln!(o, "{}", r).unwrap();
}
fn solve(s: &str) -> bool {
    let s = s.as_bytes();
    let b_len = 8;
    let mut b = [false; 8];
    let t: [&[u8]; 4] = [b"dream", b"dreamer", b"erase", b"eraser"];
    b[0] = true;

    for i in 0..s.len() {
        let s = &s[i..];
        let i = i % b_len;
        if !b[i] {
            continue;
        }
        for &t in &t {
            if s.starts_with(t) {
                b[(i + t.len()) % b_len] = true;
            }
        }
        b[i] = false;
    }
    b[s.len() % b_len]
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }
        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
char s[200005];
int dp[200005][4];
int d;
int x;
int y;
int ans;
int main() {
	for (int i = 0; i < 200005; i++) {
		s[i] = '1';
	}
	scanf("%s", s);
	for (int i = 0; i < 200005; i++) {
		if (s[i] != '1')d = i;
	}
	dp[0][0] = 1;
	for (int i = 1; i < d; i++) {
		for (int j = 0; j < 4; j++) {
			if (i >= j) {
				if (i == j)dp[i][j] = 1;
				else {
					x = 0;
					for (int k = 0; k < 4; k++) {
						if (k + j < i) {
							if (k == j) {
								y = 0;
								for (int l = 0; l <= k; l++) {
									if (s[i - l] != s[i - l - j - 1])y = 1;
								}
								if (y && dp[i - j - 1][k] > x)x = dp[i - j - 1][k];
							}
							else {
								if (dp[i - j - 1][k] > x)x = dp[i - j - 1][k];
							}
						}
					}
					dp[i][j] = x + 1;
				}
			}
		}
	}
	for (int i = 0; i < 4; i++) {
		if (dp[d - 1][i] > ans)ans = dp[d - 1][i];
	}
	printf("%d\n", ans);
}

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

using namespace std;

const long long INF = 1e13;

int h,w,i,j,k;
long long dp[305][305],cost[305][305];
char s[305][305];

int main(){
	scanf("%d%d", &h, &w);
	for(i = 0; i < h; i++)
	scanf("%s", s[i]);
	
	long long res = 0;
	
	for(i = 0; i < w - 1; i++){
		memset(cost, 0, sizeof(cost));
		memset(dp, 0, sizeof(dp));
		
		for(j = 1; j <= h; j++){
			for(k = 1; k <= h; k++){
				if(j - 1 >= 0 && k - 1 >= 0)
				cost[j][k] = cost[j - 1][k - 1];
				cost[j][k] += (s[j - 1][i] == s[k - 1][i + 1]);
				dp[j][k] = INF;
			}
		}
		
		for(j = 1; j <= h; j++){
			for(k = 1; k <= h; k++){
				dp[j][k] = min(dp[j][k], dp[j - 1][k]);
				dp[j][k] = min(dp[j][k], dp[j][k - 1]);
				dp[j][k] += cost[j][k];
			}
		}
		
		res += dp[h][h];
	}
	
	printf("%lld\n", res);
}


Measured memory_bytes: 1792
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;

const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf

#define sf scanf

#define ALL(x) x.begin(),x.end()
#define pb push_back

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
int ext_gcd(int a, int b, int & x, int & y) {
    //for finding modular inverse
    //if its return 1 ,then a has a mod inverse x mod b.
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = ext_gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
void solve(){

}

int main()

{
    IOS;
    /*#ifndef ONLINE_JUDGE
        freopen ("data.in","r",stdin);
        freopen ("data.out","w",stdout);
    #endif*/
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double x1,y1,x2,y2;
    double mindeg=m*6;
    double hdeg=(h*60+m)*.5;
    //if(hdeg==0) hdeg=360;
   // if(mindeg==0) mindeg=360;
    double A=abs(mindeg-hdeg);
    //cout<<A<<endl;
    A=(A*PI)/180;
    double ans=sq(a)+sq(b)-2*a*b*cos(A);
    cout<<fixed<<setprecision(9)<<sqrt(ans)<<endl;

     return 0;

}
///Alhamdulillah



Measured memory_bytes: 4208
//https://codeforces.com/contest/1293/problem/C
//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()

#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en

#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second

#define pll pair<lli, lli>
#define pii pair<int, int>
#define pil pair<int, lli>

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)

#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)

#define bset(a, p) ((a) | (1ll << (p)))
#define bchk(a, p) ((a) & (1ll << (p)))
#define bxor(a, p) ((a) ^ (1ll << (p)));
#define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a))
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/

#define lb lower_bound
#define ub upper_bound
#define er equal_range

#define findnot find_first_not_of

#define maxe *max_element
#define mine *min_element

#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements sbtriectly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD funcions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli modi(lli a, lli m) { return power(a, m - 2, m); }
/*CODE BEGINS*/
int main()
{
    kira;
    lli k,n;
    cin>>n>>k;
    lli a[n];
    forz(i,n)cin>>a[i];
    sort(a,a+n);
    lli m=n-k;
    lli ans=0;
    forz(i,m)ans+=a[i];
    p1(ans);
    return 0;
}

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

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  ll x[n];
  ll c[n];
  rep(i, n){
    cin >> x[i];
    c[i] = x[i];
  } 
  sort(x, x+n);
  rep(i, n){
    if(c[i] <= x[n/2-1]) cout << x[n/2] << "\n";
    else  cout << x[n/2-1] << "\n";
  }
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }


int main() {
    int k; cin >> k;
    if(k % 2 == 0 || k % 5 == 0) {
        cout << -1 << endl;
        return 0;
    }
    int ans = 0;
    int pre = 0;
    while(1) {
        ans++;
        ll now = pre*10 + 7;
        if(now % k == 0) break;
        pre = now % k;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;
  
int main(){

  int n;
  cin >> n;
  
  vector<int> a,b,c;
  int x;
  
  REP(i,n){
    cin >> x; a.push_back(x);
  }
  REP(i,n){
    cin >> x; b.push_back(x);
  }
  REP(i,n){
    cin >> x; c.push_back(x);
  }
  
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  
  vector<ll> set(n+2,0);

  REP(i,n){
    set[i+1] += lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    set[i+2] = set[i+1];
  }
  
 // REP(i,n+1)
   // debug(set[i]);
  
  ll ans = 0;
  REP(i,n){
    int x = lower_bound(b.begin(), b.end(), c[i]) - b.begin();
    ans += set[x];
  }

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

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

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0;i < N;i++) {
		cin >> A[i];
	}
	int res = 0;
	sort(A.begin(), A.end());
	res = A[N - 1] - A[0];
		cout << res << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	int a,b; char op; cin >> a >> op >> b;
	if (op == '+') {
		cout << a + b << endl;
	}
	else {
		cout << a - b << endl;
	}
	return 0;
}

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

struct str
{
    int x,y;
};

int dx[4]= {1,-1,0,0};
int dy[4]= {0,0,1,-1};
string st[MAX];
int n,m,visit[MAX][MAX],ans=0,turn[MAX][MAX];
deque<str>q;

void bfs()
{

    while(!q.empty())
    {
        str s=q.front();
        q.pop_front();
        int t=turn[s.x][s.y];
        ans=max(ans,t);
        for(int i=0; i<4; i++)
        {
            int x=s.x+dx[i];
            int y=s.y+dy[i];
            if(x>=0 && y>=0 && x<n && y<m)
            {
                if(visit[x][y]==0)
                {
                    turn[x][y]=t+1;
                    visit[x][y]=1;
                    q.push_back({x,y});
                }
            }
        }

    }

}

int main()
{

    int i,j;
    cin >> n >> m;
    for(i=0; i<n; i++)
    {
        cin >> st[i];
        for(j=0; j<st[i].size(); j++)
        {
            if(st[i][j]=='#')
            {
                q.push_back({i,j});
                visit[i][j]=1;
                turn[i][j]=0;
            }
        }
    }
    bfs();
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 17424
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
const int inf = numeric_limits<int>::max();

typedef long long ll;

int mp = inf;
int a,b,c,n;
int bamb[8];
int cnt = 0;

void calc(vector<int> v)
{
    int abc[4] = {0};
    int temp_mp = 0;
    for(int i=0; i<v.size(); i++){
        if (v[i] != 3){
            if (abc[v[i]] != 0) temp_mp+=10;
            abc[v[i]] += bamb[i];
        }
    }
    if (abc[0] != 0 && abc[1] !=0 && abc[2] != 0){
    temp_mp += abs(abc[0]-a) + abs(abc[1]-b) + abs(abc[2]-c);
    mp = min(temp_mp, mp);
    }
}

void dfs(int depth, vector<int> v)
{
    if (depth == n) calc(v);
    else{
        for(int i=0; i<4; i++){
        v[depth] = i;
        dfs(depth+1, v);
        }
    }
}
int main()
{
    cin >> n >> a >> b >> c;
    vector<int> v(n);
    rep(i,n) cin >> bamb[i];
    dfs(0, v);
    cout << mp << endl;
    return 0;
}

Measured memory_bytes: 256
/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		double d = scan.nextInt();
		int count = 0;
		
		while(n-- >0){
			int x = scan.nextInt();
			int y = scan.nextInt();
			double dis = Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
			if(dis<=d){
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 60604
#include <stdio.h>
#include <string.h>

int main(){
	char str[15];
	char str2[15] = {0};
	int x = 0, ctr = 0, j = 0;
	scanf("%s", str);
	
	for(int i =0;i < strlen(str);i++){
		if(str[i] == '0'){
			str2[j++] = '0';
			ctr++;
		}
	    else if(str[i] == '1'){
			str2[j++] = '1';
			ctr++;
		}
        else{
			if(ctr > 0){
			j--;
			str2[j] = '\0';
			ctr--;
		}
		}
	}
	printf("%s", str2);
	return 0;
	}
	

Measured memory_bytes: 1728
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;
const ll num[4] = {-1, 0, 1, 0};

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<ll> vec(n);
    rep(i, 0, n) cin >> vec[i];
    vector<ll> dairi(n);
    rep(i, 0, n) dairi[i] = vec[i];
    ll i = 0;
    while (dairi[0] % 2 == 0)
    {
        rep(i, 0, n)
        {
            if (dairi[i] % 2 == 1)
            {
                cout << 0 << endl;
                return 0;
            }
            dairi[i] /= 2;
        }
    }
    rep(i, 0, n)
    {
        if (dairi[i] % 2 == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    ll tmp = vec[0] / 2;
    rep(i, 0, n - 1)
    {
        tmp = tmp * ((vec[i + 1] / 2) / __gcd(tmp, vec[i + 1] / 2));
        if (tmp > m)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = (m / tmp + 1) / 2;
    cout << ans << endl;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

const int MOD = 1e9 + 7;

///********FILE READ AND WRITE*************************\\\

#define INPUT(x)                freopen(x,"r",stdin)
#define OUTPUT(x)               freopen (x,"w",stdout)

///----------------------------------------------------\\\

#define pb                      push_back
#define endl                    '\n'
#define LCM(a,b)                (a/__gcd(a,b))*b
#define GCD(a,b)                __gcd(a,b)
#define SP(x,y)                 fixed<<setprecision((y))<<(x)
#define PI                      acos(-1.0)
#define distance(x1,y1,x2,y2)   sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))

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


///**********************************************************************************\\\


int main()
{
    taratari

    int n;
    cin>>n;

    int ans=0;
    int i=1;

    while(ans<=n)
    {
        ans=1000*i;
        i++;
        if(ans==n)
        {
            break;
        }
    }

    cout<<ans-n;

    return 0;

}



Measured memory_bytes: 3608
A = []

for _ in range(3):
    lis=list(map(int,input().split()))
    A.append(lis)

N = int(input())
ans=[]
for _ in range(N):
    b=int(input())
    for i in range(3):
        if(b in A[i]):
            ans.append([i+1,A[i].index(b)+1])
            break
tate=False
if(ans == []):
    print("No")
else:
    counter1=[0,0,0]
    counter2=[0,0,0]
    counter3=0
    counter4=0
    two=False
    for a in ans:
        if(a[0]==1):
            counter1[0]+=1
        elif(a[0] == 2):
            counter1[1]+=1
        elif(a[0] == 3):
            counter1[2]+=1

        if(a[1] == 1):
            counter2[0]+=1
        elif(a[1] == 2):
            counter2[1]+=1
        elif(a[1] == 3):
            counter2[2]+=1
        if(a[0] == a[1] ):
            counter3+=1
        if((a[0] == 1 and a[1] == 3) or (a[1]==1 and a[0]==3)):
            counter4+=1
        if(a[0] == 2 and a[1] == 2):
            two=True
    if(3 in counter1 or 3 in counter2 or counter3 >=3 or (two==True and  counter4==2)):
        print("Yes")
    else:
        print("No")





Measured memory_bytes: 3064
import math

n = int(raw_input())

def func(i, ox1, oy1, ox2, oy2):
    if i != n:
        nx1 = ox1 + (ox2 - ox1) / 3
        ny1 = oy1 + (oy2 - oy1) / 3
        nx2 = ox1 + (ox2 - ox1) * 2 / 3
        ny2 = oy1 + (oy2 - oy1) * 2 / 3
        if nx1 < nx2:
            if ny1 == ny2:
                nx3 = nx1 + (nx2 - nx1) / 2
                ny3 = ny1 + (nx2 - nx1) * math.sqrt(3) / 2
            elif ny1 < ny2:
                nx3 = ox1
                ny3 = ny2
            elif ny1 > ny2:
                nx3 = ox2
                ny3 = ny1
        elif nx1 > nx2:
            if ny1 == ny2:
                nx3 = nx1 + (nx2 - nx1) / 2
                ny3 = ny1 - (nx1 - nx2) * math.sqrt(3) / 2
            elif ny1 < ny2:
                nx3 = ox2
                ny3 = ny1
            elif ny1 > ny2:
                nx3 = ox1
                ny3 = ny2
        func(i+1, ox1, oy1, nx1, ny1)
        func(i+1, nx1, ny1, nx3, ny3)
        func(i+1, nx3, ny3, nx2, ny2)
        func(i+1, nx2, ny2, ox2, oy2)
    elif i == n:
        print(str(ox1) + str(" ") +  str(oy1))

func(0, 0.0, 0.0, 100.0, 0.0)
print(str(100) + str(" ") + str(0))

Measured memory_bytes: 6528
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=5e5+5;
char s[N];int nxt[N][35],to[N][25],n,q;
int main(){
	scanf("%s",s+1),n=strlen(s+1);
	fp(i,0,26)nxt[n][i]=nxt[n+1][i]=n+1;
	fp(i,0,19)to[n][i]=to[n+1][i]=n+1;
	fd(i,n-1,0){
		R int c=s[i+1]-'a';
		nxt[i][c]=i+1;
		fp(j,c+1,26)nxt[i][j]=nxt[nxt[i][j-1]][j-1];
		fp(j,0,c-1)nxt[i][j]=nxt[nxt[i][26]][j];
		to[i][0]=nxt[i][26];
	}
	fp(j,1,19)fp(i,0,n-1)to[i][j]=to[to[i][j-1]][j-1];
	scanf("%d",&q);
	for(int l,r,pos;q;--q){
		scanf("%d%d",&l,&r);
		pos=--l;
		fd(j,19,0)if(to[pos][j]<=r)pos=to[pos][j];
		puts(pos==r?"Yes":"No");
	}
	return 0;
}

Measured memory_bytes: 118272
#include <bits/stdc++.h>
using namespace std;
#define DEBUG 0
#define nl          '\n'
#define fori(n)			for(int i = 0; i < n; ++i) 
#define forj(n)			for(int j = 0; j < n; ++j)
#define fork(n)			for(int k = 0; k < n; ++k)
#define forl(n)			for(int l = 0; l < n; ++l)
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define ppb push_back
typedef long long ll;typedef pair<int,int> pii;typedef vector<bool> vbool;
typedef vector<int> vint;typedef vector<ll> vll;typedef long double ld;
typedef vector<vector<int>> vvi; typedef vector<vbool> vvb;

const ll N = 1000001;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;

ll dp[N][2];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s; cin >> s;
	dp[0][0] = s[0]-'0';
	dp[0][1] = 10-(s[0]-'0')+1;
	for(int i = 1; i < s.size(); i++) {
		int c = s[i]-'0';
		dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + c;
		dp[i][1] = min(dp[i-1][0]+11-c, dp[i-1][1]+9-c);
	}
	cout << min(dp[s.size()-1][0], dp[s.size()-1][1]) << nl;

	#if DEBUG
	cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << " s" << nl;
	#endif
	return 0;
}


Measured memory_bytes: 16924
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = 1e9 + 7;

int n, m, bos[200009], a, b, cnt[200009];

int gun(int x)
{
	if (bos[x] != x)
		bos[x] = gun(bos[x]);
	return bos[x];
}

void fun(int x, int y)
{
	x = gun(x);
	y = gun(y);
	if (x > y) swap(x, y);
	bos[y] = x;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		bos[i] = i;
	}
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		fun(a, b);
	}
	for (int i = 1; i <= n; i++) {
		gun(i);
		cnt[bos[i]]++;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, cnt[i]);
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 5084
#include <iostream>
using namespace std;
struct node{
	int key;
	node *left = NULL;
	node *right = NULL;
	node(int k, node*l = NULL, node*r = NULL) : key(k), left(l), right(r) {}
};
node *Tree;

void insert(node z)
{
	node *y = NULL;
	node *x = Tree;
	while(x != NULL){
		y = x;
		if(z.key < x->key)
			x = x->left;
		else
			x = x->right;
	}
	if(y == NULL)
		Tree = new node(z.key);
	else if(z.key < y->key)
		y->left = new node(z.key);
	else
		y->right = new node(z.key);
}

void midprint(node *root)
{
	if(root == NULL) return;
	midprint(root->left);
	cout << " " << root->key;
	midprint(root->right);
}

void preprint(node *root)
{
	if(root == NULL) return;
	cout << " " << root->key ;
	preprint(root->left);
	preprint(root->right);
}

void find(int k)
{
	node *x = Tree;
	while(x != NULL){
		if(k == x->key){
			cout << "yes" << endl;
			return ;
		}
		if(k < x->key)
			x = x->left;
		else
			x = x->right;
	}
	cout << "no" << endl;
	return;
}


void print(node *root)
{
	midprint(root);
	cout << endl;
	preprint(root);
	cout << endl;
}

int main()
{
	int n;
	cin >> n;
	while(n--){
		string s;
		cin >> s;
		if(s[0] == 'i'){
			int k;
			cin >> k;
			node leaf(k);
			insert(leaf);
		}
		else if(s[0] == 'p')
			print(Tree);
		else if(s[0] == 'f'){
			int k;
			cin >> k;
			find(k);
		}
	}
	return 0;
}

Measured memory_bytes: 15656
#include <bits/stdc++.h>
#define INF 1e9
#define N 510
#define MAX_V N
using namespace std;
typedef map<int,int> M;
M g[N];
bool used[MAX_V];      //DFS??§?????§??????????????????????????°

int dfs(int v,int t,int f){
  if(v == t)return f;
  used[v]=true;
  
  for(M::iterator it=g[v].begin();it!=g[v].end() ;it++){
    int to=it->first;
    int &cap=it->second;
    if(!used[to] && cap > 0){
      int d = dfs(to ,t , min(f,cap));
      if(d > 0){
	cap -= d;
	g[to][v]+=d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0)return flow;
    flow += f;
  }
}

bool check(int s,int t){
  memset(used,0,sizeof(used));
  return dfs(s,t,1);
}

int main(){
  int n,m,q;
  cin>>n>>m>>q;
  for(int i=0,a,b;i<m;i++){
    cin>>a>>b;a--,b--;
    g[a][b]=g[b][a]=1;
  }
  
  int flow=max_flow(0,n-1);
  while(q--){
    int op,a,b;
    cin>>op>>a>>b;a--,b--;
    if(op==1) g[a][b]=g[b][a]=1,flow+=max_flow(0,n-1);
    if(op==2){
      if(!g[a][b]||!g[b][a]){
	if(!g[b][a])swap(a,b);
	if(!check(a,b))flow--,check(a,0),check(n-1,b);
      }
      g[a][b]=g[b][a]=0;
    }
    cout <<flow<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 5060
// abc149_b
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  ll a,b,k;
  cin>>a>>b>>k;
  if (a>=k) {
    cout<<a-k<<" "<<b<<endl;
  } else {
    if(b-k+a>0) {
      cout<<0<<" "<<b-k+a<<endl;
    } else {
      cout<<0<<" "<<0<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 924844033
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000




int main(){
	
	int N,K;
	cin>>N>>K;
	
	vector<int> a(N);
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	
	vector<bool> first_win(K+1);
	
	for(int i=0;i<=K;i++){
		first_win[i] = false;
		for(int j=0;j<N;j++){
			if(i-a[j]<0)continue;
			if(first_win[i-a[j]]==false)first_win[i]=true;
		}
	}
	
	if(first_win.back()){
		cout<<"First"<<endl;
	}
	else{
		cout<<"Second"<<endl;
	}
	
    return 0;
}


Measured memory_bytes: 256
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * (W+1) for i in range(N+1)]

for i in range(1,N+1):
    w, v = WV[i-1]
    for j in range(1, W+1):
        if j-w < 0:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i][j-1], dp[i-1][j-w]+v, dp[i-1][j])

ret = 0
for i in dp:
    ret = max(ret, i[-1])
print(ret)

Measured memory_bytes: 119772