akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

ostream& operator << (ostream& os, const mint a) {
    os << a.x;

    return os;
}

const int NMAX = int(1e7);
ll fact[NMAX+1], finv[NMAX+1], inv[NMAX+1];

void comb_init(int N) {
    // init
    REP(i, 2) {
        fact[i] = 1;
        finv[i] = 1;
        inv[i] = 1;
    }

    FOR(i, 2, N+1) {
        fact[i] = fact[i-1] * i % MOD;
        inv[i] = MOD - MOD / i * inv[MOD % i] % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

mint comb(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;

    return mint(fact[n]) * finv[k] * finv[n-k];
}

mint perm(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;

    return mint(fact[n]) * finv[n-k];
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N, M;
    cin >> N >> M;

    comb_init(max(N, M));

    mint ans = 0;
    REP(i, N + 1) {
        mint t = comb(N, i) * perm(M, i) * perm(M - i, N - i).pow(2);
        if (i % 2) t *= -1;
        ans += t;
    }

    print(ans);
}


Measured memory_bytes: 15372
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
ll dp[110][110][310];
ll n, m;
pair<ll, ll> a[110];
ll func(ll here, ll ch, ll m)
{
	if (m < 0||ch<0)return -1234567890123;
	if (here == n + 1)return 0;
	ll &ret = dp[here][ch][m];
	if (ret != -1)return ret;
	ret = max(ret, func(here + 1, ch - 1, m - (a[here].first-a[1].first)) + a[here].second);
	ret = max(ret, func(here + 1, ch, m));
	return ret;
}
int main()
{
	memset(dp, -1, sizeof(dp));
	scanf("%lld %lld", &n, &m);
	ll xx = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%lld %lld", &a[i].first, &a[i].second);
	}
	ll dap = 0;
	for (int i = 0; i <= m / a[1].first; i++)
	{
		dap = max(dap, func(1, m / a[1].first - i,min( m%a[1].first + a[1].first*i,(ll)300)));
	}
	printf("%lld", dap);
}

Measured memory_bytes: 29440
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
        ($line:expr, $name:ident, $t:tt) => {
            let $name = value!($line, $t);
        };
    }

    macro_rules! values_def {
        ($lines:expr, $n:expr, $name:ident, $t:tt) => {
            let $name = {
                let mut vec = Vec::new();
                for i in 0..$n {
                    let mut next = $lines.next().unwrap().split_whitespace();
                    vec.push(value!(next, $t));
                }
                vec
            };
        };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:usize)(list:[i64]));
    let mut list = list;
    let mut count = 0;
    let mut c = 10000000;
    for i in 1..n {
        if list[i - 1] == list[i] {
            list[i] = c;
            c += 1;
            count += 1;
        }
    }
    count.to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "5\n1 1 2 2 2" => "2",
    test2: "3\n1 2 1" => "0",
    test3: "5\n1 1 1 1 1" => "2",
    test4: "14\n1 2 2 3 3 3 4 4 4 4 1 2 3 4" => "4",
}


Measured memory_bytes: 4352
import java.util.Scanner;
class Main {
 public static void main(String[] args){
  Scanner std = new Scanner(System.in);
  int a = std.nextInt();
  int b = std.nextInt();
  if(a < b) System.out.println("a < b");
  if(a > b) System.out.println("a > b");
  if(a == b) System.out.println("a == b");
 }
}

Measured memory_bytes: 17228
#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
#define double long double
#define pb push_back
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define diff(a,b) (a>b?a-b:b-a)
const int N=1e6+5;
int32_t main()
{
    IOS;
    int n;
    cin >> n;
    int a[n][3],dp[n][3];
    for(int i = 0;i < n; i++){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
        dp[i][0] = a[i][0];
        dp[i][1] = a[i][1];
        dp[i][2] = a[i][2];
    }
    for(int i = 1;i < n; i++){
        dp[i][0] = a[i][0] + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = a[i][1] + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = a[i][2] + max(dp[i-1][0],dp[i-1][1]); 
    }
    //     for(int i = 0;i < n; i++){
    //     cout << dp[i][0] <<" " <<  dp[i][1] <<" " <<  dp[i][2];
    //     cout << "\n";
    // }
    cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << "\n";
    return 0;
}

Measured memory_bytes: 8248
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

long long N, dp[1000005];

int main() {
	scanf("%lld", &N);
	long long sum = 1;
	dp[0] = 1;
	for (long long i = 1; i <= N; i++) {
		dp[i] = (((sum - ((i == 1) ? 0 : dp[i - 2])) % MOD) + MOD) % MOD;
		sum += dp[i];
		sum %= MOD;
	}
	long long ans = 0;
	// compute violations
	for (long long i = 0; i < N - 1; i++) {
		//long long leftnums = N - (N - i - 1);
		//leftnums *= (N - i - 1);
		//leftnums %= MOD;
		//leftnums += (N - i - 2) * (N - i + 1) / 2;
		//leftnums %= MOD;
		long long leftnums = dp[i];
		leftnums *= (N - 1);
		leftnums %= MOD;
		ans += (long long)(N - 1) * leftnums;
		ans %= MOD;
	}
	ans += dp[N];
	ans %= MOD;
	for (long long i = 0; i < N; i++) {
		ans += (long long)dp[i] * min(N - 1, ((N + 1) - (N - i)));
		ans %= MOD;
	}
	printf("%lld\n", ans);
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

#define INF LONG_LONG_MAX

vector<vi> adj;
vector<bool> reach;

void dfs(int v)
{
    reach[v] = true;
    for(auto u:adj[v]){
        if (reach[u]) continue;
        dfs(u);
    }
}

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    adj.resize(n);
    using edge = tuple<int,int,ll>;
    vector<edge> es;
    rep(i,m){
        ll a,b,c; cin>>a>>b>>c; a--; b--;
        adj[b].pb(a);
        es.emplace_back(a,b,c);
    }
    reach.resize(n,false);
    dfs(n-1);
    vll dist(n,-INF);
    dist[0] = 0;
    rep(i,n){
        rep(j,m){
            int from,to; ll c;
            tie(from,to,c) = es[j];
            if (dist[from]==-INF) continue;
            if (dist[to] < dist[from]+c){
                dist[to] = dist[from]+c;
                if (i==n-1 && reach[to]){
                    cout<<"inf\n";
                    return 0;
                }
            }
        }
    }
    cout<<dist[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define LL long long
#define MOD (LL)1000000007
#define pi acos(-1.0)
#define ULL unsigned long long
#define mem_1(str) memset(str,-1,sizeof(str))
#define mem0(str) memset(str,0,sizeof(str))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define INF 999999999
using namespace std;
LL num[300000];
LL id[300000];
LL sum[300000];
int m,idd[300000];;
inline int lowbit(int x)
{
	return x&(-x);
}
void add(int x)
{
    for(int i=x;i<=m;i+=lowbit(i))
    {
    	sum[i]++;
	}    
}
LL add2(int x)
{
    LL ans=0;
    for(int i=x;i>0;i-=lowbit(i))
    {
    	ans=ans+sum[i];
	}        
    return ans;
}
int main()
{
	mem0(id);
	mem0(num);
	mem0(sum);
	mem0(idd);
	int n,k; 
		LL ans=0;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		int a;
		scanf("%d",&a);
		id[i]=num[i]=num[i-1]+a-k;
		if(id[i]>=0) ans++;
	}
	sort(num+1,num+n+1);
	m=unique(num+1,num+n+1)-num-1;
	for(int i=1;i<=n;i++)
	{
		idd[i]=lower_bound(num+1,num+m+1,id[i])-num;
	}

	for(int i=1;i<=n;i++)
	{
		ans+=add2(idd[i]);
		add(idd[i]);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rall(v) v.begin(), v.end(), std::greater<int>()
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
using namespace std;

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

    int n, k, t;
    cin>>n>>k;
    vector<int> h;
    rep(i, n){
        cin>>t;
        h.pb(t);
    }
    sort(all(h));
    for(int i = 0; i < k; i++){
        if(i > n){
            break;
        }
        h[n-1-i] = 0;
    }
    long long sum = 0;
    rep(i, n){
        sum += h[i];
    }
    cout<<sum<<endl;
    return 0;
}

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

#define range 524289
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;


int main(int argc, char const *argv[])
{
	// #ifndef ONLINE_JUDGE
 //    	freopen("input.txt", "r", stdin);
 //    	freopen("output.txt", "w", stdout);
	// #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,l;
    cin>>n>>m>>l;
    cout<<max(0,l-(n-m))<<endl;
    return 0;
}


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


using namespace std;


int main (){
  
  
  int a,b,c,t;
  c=1;
  
  cin>>a;
  cin>>b;
  t=a;
  while(t<b){
    c++;
    t=t+a-1;
    
    }

  if(a>=b)c=1;
  if(b==1)c=0;
  cout<<c<<endl;
  
  
  
  
  
}


Measured memory_bytes: 256
m = gets.to_i
m.times do |i|
  res = []
  s = gets.chomp
  for j in (0...s.size) do
    l = s[0...j]
    r = s[j...s.size]
    revl = l.reverse
    revr = r.reverse
    res << revl + r
    res << l + revr
    res << revl + revr
    res << r + l  
    res << revr + l  
    res << r + revl  
    res << revr + revl  
  end
  p res.uniq.size
end

Measured memory_bytes: 9644
N = int(input())
A = [[x - 1 for x in list(map(int, input().split()))] for i in range(N)]

days = 0
cand = set(range(N))

while True:
    games = set() # その日に試合ができるプレイヤーの集合
    
    for p in cand:
        if A[p] != []:
            if A[ A[p][0] ][0] == p:
                games.add(p)
                games.add(A[p][0])
    
    if not games: # その日の試合が開催されない
        if any(A): # 未だ組み合わせ希望が残っている
            print(-1) # 大会の組み合わせ希望は実現不可能
            break
        else: # 大会が終了
            print(days)
            break
    else: #その日の試合が開催された
        for i in games:
            A[i].pop(0) # 大会の組み合わせ希望から、該当する試合を取り除く

    days += 1
    cand = games # 前日試合をした選手の中から、その日試合する選手を選択

Measured memory_bytes: 61660
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    nl = [[0 for _ in range(10)] for _ in range(10)]
    
    for i in range(1,N+1):
        s = str(i)
        if s[-1] != "0":
            nl[int(s[0])][int(s[-1])] += 1

    ans = 0
    for i in range(10):
        for j in range(10):
            ans += nl[i][j]*nl[j][i]
            
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] tmp = br.readLine().split(" ");
		int n        = Integer.parseInt(tmp[0]);
		double k     = Double.parseDouble(tmp[1]);
		int cnt      = 0;
		int min      = Integer.MAX_VALUE;
		String[] tm2 = br.readLine().split(" ");
		int[] list   = new int[n];


		cnt = 1 + (int)Math.ceil((n - k) / (k - 1.0)) ;


		System.out.println(cnt);
	}
}


Measured memory_bytes: 45688
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const list = input.split(' ');

const a = Number(list[0]);

const b = Number(list[1]);

const c = Number(list[2]);

const d = Number(list[3]);

const abs = (x) => {
  return x > 0 ? x : -x;
};

var direct = (i, j) => {
  if (abs(i-j) <= d) {
    return true;
  } else {
    return false;
  }
};

var indirect = (i, j, k) => {
  if (direct(i, j) && direct(j, k)) {
    return true;
  } else {
    return false;
  }
};

if (direct(a,c) || indirect(a, b, c)) {
  console.log('Yes');
} else {
  console.log('No');
}


Measured memory_bytes: 7372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>


int main() {
	std::string s, t;

	std::cin >> s >> t;

	int count = 0;

	for (size_t i = 0; i < s.length(); i++)
	{
		if (s[i] == t[i]) {
			count++;
		}
	}

	std::cout << count << std::endl;

	return 0;
}

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

N=int(input().rstrip('\n'))
alpha = [chr(i) for i in range(ord('a'), ord('z')+1)]
res = []
rest = N
for i in range(N):
  N1 = rest % 26
  rest = rest//26
  if N1>0:
    res.append(alpha[N1-1])
  else:
    res.append('z')
    rest -= 1
  if rest == 0:
    break
print(''.join(res[::-1]))


Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}

void mainsolve(){

	string alp = "abcdefghijklmnopqrstuvwxyz";
	char cc;
	cin >> cc;

	rep(i,26){
		if(cc == alp[i]){
			cout << alp[i+1] << endl;
			return;
		}
	}

	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

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

int main(){
  int n;
  cin >> n ;
  VI w(n);
  rep(i,n){
    cin >> w.at(i);
  }
  int sumall=0;
  int sumt=0;  
  int sumr;
  VI diff(n);
  rep(i,n){
    sumall+=w.at(i);
  }
  rep(i,n){
    sumt+=w.at(i);
    sumr=sumall-sumt;
    if(sumr>=sumt){
    diff.at(i)=sumr-sumt;
    }
    else if(sumr<sumt){
      diff.at(i)=sumt-sumr;
    }
  }
int ans;
  rep(i,n-1){
    if(diff.at(i)<=diff.at(i+1) && diff.at(i)<=diff.at(i-1)){
      ans=diff.at(i);
    }
  }
    cout << ans <<endl;
  
}

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

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

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

#define x1 gray_cat_x1
#define y1 gray_cat_y1

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

#define file "I1"

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

const int MAXN = 5e5 + 5, MAXLOG = 19, MAXSZ = 26;

char s[MAXN];
int nxt[MAXN][MAXSZ + 1];
int nxt_2i[MAXN][MAXLOG];

void calc_nxt(int n){
	REPN(i, 0, MAXSZ){
		nxt[n][i] = nxt[n + 1][i] = n + 1;
	}
	for(int i = n - 1; i >= 0; i--){
		int sym = s[i] - 'a';
		nxt[i][sym] = i + 1;
		REPN(j, sym + 1, MAXSZ){
			nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
		}
		REP(j, 0, sym){
			nxt[i][j] = nxt[nxt[i][MAXSZ]][j];
		}
	}
}

void calc_nxt_2i(int n){
	REP(i, 0, MAXLOG){
		nxt_2i[n][i] = nxt_2i[n + 1][i] = n + 1;
	}
	for(int i = n - 1; i >= 0; i--){
		nxt_2i[i][0] = nxt[i][MAXSZ];
		REP(j, 1, MAXLOG){
			nxt_2i[i][j] = nxt_2i[nxt_2i[i][j - 1]][j - 1];
		}
	}
}

bool get_ans(int l, int r){
	for(int i = MAXLOG - 1; i >= 0; i--){
		if (nxt_2i[l][i] <= r){
			l = nxt_2i[l][i];
		}
	}
	return l == r;
}

void solve(){
	scanf("%s", &s[0]);
	int n = strlen(s);
	calc_nxt(n);
	calc_nxt_2i(n);
	int q;
	scanf("%d", &q);
	while(q--){
		int l, r;
		scanf("%d%d", &l, &r);
		l--;
		if (get_ans(l, r)){
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	}
}   

int main(){

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


Measured memory_bytes: 91008
//hinagata.cpp
//作成日
//更新日
//目的
//手段
/*includes*/
#include <bits/stdc++.h>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPi(i,a,b) for(ll i=(a);i<(b);i++)
#define REPRi(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

bool comp(pair<int,int> A,pair<int,int> B){
    if(A.second!=B.second){
        return A.second<B.second;
    }else{
        return A.first>B.first;
    }
}

int main(){
    ll N;
    cin>>N;
    vector<pair<ll,ll>> W(N);
    REP(i,N){
        ll X,L;
        cin>>X>>L;
        W[i].first=X-L;
        W[i].second=X+L;
    }
    //inputend
    sort(ALL(W),comp);
    //sort
    ll time=W[0].second;
    ll count=1;
    REPi(i,1,N){
        if(time<=W[i].first){
            count+=1;
            time=W[i].second;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,M,ans=1,i;cin>>N>>M;
  REP(i,M)ans*=2;
  cout<<(100*N+1800*M)*ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <unordered_map>
#define inputarr(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define prllarr(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" ";
#define pb push_back
#define ll long long
#define mod 1000000007
#define foi ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define in(n) scanf("%lld",&n);
#define in2(x,y) scanf("%lld %lld",&(x),&(y));
#define in3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z));
#define out(n) printf("%lld\n",n);
#define out2(x,y) printf("%lld %lld\n",x,y);
#define test(t)  ll t; in(t);while(t--)
#define set(arr,n,s) for(ll i=0;i<n;i++){arr[i]=s;}


ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1){res=(res*x)%p;} y=y>>1;x=(x*x)%p;}return res;}
ll modInverse(ll a,ll p){return power(a,p-2,p);}//used with feemat little

ll gcd(ll x,ll y){if(x==0 || y==0){return max(y,x);}return gcd(y%x,x);}
ll gcdExtended(ll a,ll b,ll &x,ll &y){if(a==0){x=0;y=1;return b;}ll x1,y1;ll gcd = gcdExtended(b%a,a,x1,y1);x=y1-(b/a)*x1;y=x1;return gcd;}//o(log(b))
;
void prac(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
   #endif 
}
ll arr[403];
ll dp[405][405];
int main() 
{
  	// prac();
    ll n;
    in(n)
    for(ll i=1;i<=n;i++){
        in(arr[i])
    }
    arr[0]=0;
    for(ll i=1;i<=n;i++){
        arr[i]+=arr[i-1];
    }
 
    for(ll i=0;i<=400;i++){
        for(ll j=0;j<=400;j++){
            dp[i][j]=1e18;
        }
    }
    for(ll i=1;i<=n;i++){
        dp[i][i]=0;
    }
    for(ll len=2;len<=n;len++){
        for(ll i=1;i<=n;i++){
            ll end=i+len-1;
            if(end>n)break;
            for(ll k=i;k<end;k++){
                dp[i][end]=min(dp[i][k]+dp[k+1][end]+arr[end]-arr[i-1],dp[i][end]);
            }
        }
    }
    // for(ll i=0;i<=n;i++){
    //  for(ll j=0;j<=n;j++){
    //      cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
    //  }
    // }
    cout<<dp[1][n]<<endl;
    

   
}



/*error-----
convert every int to long long eg-1LL
create array with proper analysis of problem constrain
check mod also
*/






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

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  vector<int> T(N);
  for(int i=0; i<N; i++){
    cin >> S.at(i) >> T.at(i);
  }
  string X;
  cin >> X;
  int P;
  for(int i=0; i<N; i++){
    if(S.at(i)==X){
      P=i;
    }
  }
  int Ans=0;
  for(int i=P+1; i<N; i++){
    Ans+=T.at(i);
  }
  cout << Ans << endl;
}

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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll N, K;
int main() {
	cin >> N >> K;
	if(K==1){
		p(0);
	}else{
		p(N-K);
	}

	return 0;
}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll V[55];
ll dp[55][55];

ll comb(ll n, ll r)
{
    if (n == r)
        return dp[n][r] = 1;
    if (r == 0)
        return dp[n][r] = 1;
    if (r == 1)
        return dp[n][r] = n;
    if (dp[n][r])
        return dp[n][r];
    return dp[n][r] = comb(n - 1, r) + comb(n - 1, r - 1);
}

int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    REP(i, N)
    {
        cin >> V[i];
    }
    sort(V, V + N, [](ll a, ll b) { return a > b; });
    vector<pll> v;
    double max = 0;
    ll x = 0, y = 0;
    FOR(i, B + 1, A)
    {
        ll sum = 0;
        ll n = 0;
        REP(j, i)
        {
            sum += V[j];
            if (j > 0 && V[j - 1] == V[j])
                n++;
            else
                n = 1;
        }
        //! V[i-1]と同じ物の数
        ll m = 0;
        REP(j, N)
        {
            if (V[i - 1] == V[j])
                m++;
        }
        v.push_back(pll(sum, comb(m, n)));
        double k = (double)sum / (double)i;
        if (max < k)
        {
            max = k;
            x = sum;
            y = i;
        }
    }

    ll c = 0;
    REP(i, v.size())
    {
        if (x * (A + i) == y * (v[i].first))
            c += v[i].second;
    }
    cout << OF64 << max << endl;
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

    private void print(ArrayList<Integer> arrayMid){
        StringBuilder Mid = new StringBuilder();
        for(int i = 0; i < arrayMid.size(); i ++){
           Mid.append(arrayMid.get(i) + " ");
        }
        System.out.print(Mid);
   }

   private void Even(int K, int N){
       ArrayList<Integer> arrayMid = new ArrayList<Integer>(N);
       arrayMid.add(0, K / 2);
       for(int i = 1; i < N; i ++) arrayMid.add(i, K);
       print(arrayMid);
   }

   private void Odd(int K, int N){
       ArrayList<Integer> arrayMid = new ArrayList<Integer>(N);
       for(int i = 0; i < N; i ++) arrayMid.add(i, (K + 1) / 2);    
       for(int i = 0; i < N / 2; i ++){
           if(arrayMid.get(arrayMid.size() - 1) == 1) arrayMid.remove(arrayMid.size() - 1);
           else{
               arrayMid.set((arrayMid.size() - 1), arrayMid.get(arrayMid.size() - 1) - 1);
               for(int j = arrayMid.size(); j < N; j++) arrayMid.add(j, K);
           }
       }
       print(arrayMid);
   }

   private void Judge(int K, int N){
       if(K % 2 == 0) Even(K, N);
       else Odd(K, N);
   }

   public static void main(String [] args){
       Scanner input = new Scanner(System.in);
       int[] in = new int[2];
       for(int i = 0; i < 2; i++){
           in[i] = input.nextInt();
       }
       Main myEncyclopedia = new Main();
       myEncyclopedia.Judge(in[0], in[1]);
       input.close();
   }
}


Measured memory_bytes: 71932
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <queue>
#include <algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef pair<int,int> P;
const int inf=1<<30;
const double pi=acos(-1);

int V,E;
vector<vector<int> > G,dp;

int func(int S,int v){
	if(dp[S][v]!=inf) return dp[S][v];
	if(S==(1<<V)-1&&v==0) return dp[S][v]=0;
	int tmp=inf-1;
	for(int i=0;i<V;i++){
		if(G[v][i]==inf) continue;
		if(!(S>>i&1)) tmp=min(tmp,func(S|1<<i,i)+G[v][i]);
	}
	return dp[S][v]=tmp;
}

int main(){
	cin>>V>>E;
	G=vector<vector<int> >(V,vector<int>(V,inf));
	for(int i=0;i<E;i++){
		int s,t,d;
		cin>>s>>t>>d;
		G[s][t]=d;
	}
	dp=vector<vector<int> >(1<<V,vector<int>(V,inf));
	int ans=func(0,0);
	if(ans==inf-1) cout<<-1<<endl;
	else cout<<ans<<endl;
}

Measured memory_bytes: 7608
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 200000000
#define mod 1000000007
#define INF2 1000000000000000000


int dp[1010][(1 << 12)];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    rep(i, 1010) rep(j, (1 << 12)) dp[i][j] = INF;
    dp[0][0] = 0;
    int a[1010], b[1010];
    int c[1010][12];
    rep(i, M) {
        cin >> a[i] >> b[i];
        rep(j, b[i]) {
            cin >> c[i][j];
            c[i][j]--;
        }
    }
    rep(i, M) {
        int key = 0;
        rep(j, b[i]) {
            key |= (1 << c[i][j]);
        }
        rep(bit, (1 << N)) dp[i + 1][bit] = dp[i][bit];
        rep(bit, (1 << N)) {
            int set = bit | key;
            dp[i + 1][set] = min(dp[i + 1][set], dp[i][bit] + a[i]);
        }
    }
    if(dp[M][(1 << N) - 1] == INF) dp[M][(1 << N) - 1]  = -1;
    cout << dp[M][(1 << N) - 1] << endl;

    return 0;
}


Measured memory_bytes: 19836
n=int(input())
l1=[str(x) for x in input()]
l2=[str(x) for x in input()]

if l1[0]==l2[0]:
    pat=3
    typ='lon'
else:
    pat=6
    typ='lat'
for i in range(1,n):
    if l1[i]!=l1[i-1]:
        if typ=='lon':
            if l1[i]==l2[i]:
                pat *= 2
            else:
                pat *= 2
                typ='lat'
        else:
            if l1[i]==l2[i]:
                typ='lon'
            else:
                pat *= 3
print(pat%(10**9+7))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

const int N = 1e5 + 5;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll a, b, k;
	cin >> a >> b >> k;
	ll g = min(k, a);
	a -= g;
	k -= g;
	g = min(k, b);
	b -= g;
	cout << a << " " << b << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1e9 + 7

template < typename T >
void printVector (const vector < T > & vec) {
	for (const T x : vec) {
		cout << x << " ";
	}
	cout << endl;
}

template < typename T >
void printMatrix (const vector < vector < T > > & mat) {
	for (const vector < T > vec : mat) {
		printVector (vec);
	}
	cout << endl;
}

const ll INF = 1e18L + 5;

template < typename T >
void min_self (T& a, T b) {
	a = min (a, b);
}

template < typename T >
void max_self (T& a, T b) {
	a = max (a, b);
}

template < typename T >
void add_self (T & a, T b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

template < typename T >
void sub_self (T & a, T b) {
	a -= b;
	if (a < 0) {
		a += MOD;
	}
}

int main() {
	int N;
	scanf ("%d", &N);
	vector < int > a (N);
	for (int & x : a) scanf ("%d", & x);
	vector < ll > sums (N, 0);
	sums[0] = a[0];
	for (int i = 1; i < N; i++) {
		sums[i] = sums[i - 1] + a[i];
	}
	vector < vector < ll > > dp (N, vector < ll > (N, INF));
	for (int i = 0; i < N; i++) dp[i][i] = 0;
	for (int len = 2; len <= N; len++) {
		for (int i = 0; i <= N - len; i++) {
			int j = i + len - 1;
			if (len == 2) {
				dp[i][j] = (ll) a[i] + (ll) a[j];
				continue;
			}
			for (int k = i; k < j; k++) {
				dp[i][j] = min (dp[i][j], dp[i][k] + dp[k + 1][j] + sums[j] - sums[i] + a[i]);
			}
		}
	}
	printf ("%lld\n", dp[0][N - 1]);
	return 0;
}



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

int main(){
    int n,k;
    cin >> n >> k;
    ll ans = k;
    rep(i,n-1){
        ans *= k-1;
    }
    cout << ans << endl;
    return 0;
}


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

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

    int sum = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                sum += gcd(gcd(a, b), c);
            }
        }
    }

    cout << sum << endl;

    return 0;
}


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

bool solve() {
  int N; cin >> N;
  using P = pair<int, int>;
  vector<P> A(N);
  rep(i, 0, N) {
    int a, b;
    cin >> a >> b;
    A[i] = {b, a};
  }
  sort(A.begin(), A.end());
  ll now = 0;
  rep(i, 0, N) {
    now += A[i].second;
    if(now > A[i].first) return false;
  }
  return true;
}

int main() {
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)


int main(){
    int n,m;
    cin >> n >> m;
    int q;
    cin >> q;
    vector<int>a(q);
    vector<vector<int> > v(m+1);
    rep(i,q){
        cin >> a[i];
    }
    reverse(a.begin(),a.end());
    rep(i,q){
        v[a[i]].push_back(i);
    }
    rep(i,m+1){
        v[i].push_back(q);
    }
    vector<int>b(n,-1);
    vector<int>flag(m+1);
    int s = 1;
    bool f = 0;
    bool ok = 1;
    for(int i=0;i<q;i++){
        if(f){
            int k = a[i];
            if(flag[k])continue;
            for(int i=s;i<=m;i++){
                if(!flag[i]){
                    s = i;
                    break;
                }
            }
            if(s!=k){
                // cerr << s << " " << k << endl;
                // cerr << "Test" << endl;
                ok = 0;
            }
            flag[k] = true;
        }else{
            int k = a[i];
            if(flag[k]){
                continue;
            }
            int id = i-1;
            rep(zz,n){
                int t = *lower_bound(v[k].begin(),v[k].end(),max(id+1,b[zz]+1));
                //cerr << zz << " " << t << endl;
                if(t!=q){
                    b[zz] = t;
                    id = t;
                }else{
                    f = 1;
                    break;
                }
            }
            if(f){
                for(int i=s;i<=m;i++){
                    if(!flag[i]){
                        s = i;
                        break;
                    }
                }
                if(s!=k){
                    ok = 0;
                }

            }
            flag[k] = 1;
        }
    }
    if(ok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 7288
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

const int MAXN = 1e5+10;
ll fact_[MAXN];

ll fact(ll n) {
	if(n == 0) return fact_[n] = 1;
	if(n == 1) return fact_[n] = 1;
	if(fact_[n] != 0) return fact_[n];
	return fact_[n] = (n * fact(n-1)) % MOD;
}

//aのb乗
ll powMod(ll a, ll b) {
	ll res = 1;
	while(b > 0) {
		if(b & 1) res = res * a % MOD;
		if(res==0) res = MOD;
		a = a * a % MOD;
		if(a==0) a = MOD;
		b >>= 1;
	}
	return res;
}

ll comb(ll a, ll b){
	if(a == 0 || b == 0) return 1;
	return (((fact(a)*powMod(fact(b),MOD-2))%MOD)*powMod(fact(a-b),MOD-2))%MOD;
}

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N+1);
	map<ll,ll> mp;
	for(int i=0;i<=N;i++) {
		cin >> A[i];
		mp[A[i]]++;
	}
	ll two = 0;
	for(auto m : mp) {
		if(m.second == 2)
			two = m.first;
	}
	ll posA[2], j = 0;
	for(ll i=0;i<=N;i++) {
		if(A[i] == two) {
			posA[j] = i;
			j++;
		}
	}
	ll L = posA[0], R = N - posA[1];
	for(ll k=1;k<=N+1;k++) {
		ll ans = comb(N+1, k) + MOD;
		if(L + R >= k-1) ans -= comb(L + R, k-1);
		ans %= MOD;
		cout << ans << endl;
	}
}

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	string S;
	cin >>S;
	int l=S.size()/2;
	int s=0;
	for (int i=0; i<l; i++)
		if (S.at(i)!=S.at(S.size()-1-i))
			s++;
	cout <<s <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iterator>
#include <iostream>
#include <sstream>
#include <bitset>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <time.h>
#include <limits>
#include <math.h>
#include <climits>
#include <numeric>
#include <utility>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <functional>


using namespace std;
const double pi=acos(-1.0);
#define boost  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define sl(n) scanf("%lld",&n)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<ll, ll>
#define f(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define rf(i,a,b) for(ll i = (ll)(a); i > (ll)(b); i--)
#define ms(a,b) memset((a),(b),sizeof(a))
#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a<b)?(a):(b))
#define vec(g1) int temp;cin>>temp;g1,push_back(temp);
#define abs(x) ((x<0)?(-(x)):(x))
#define MAX 1000005
#define inf LLONG_MAX
#define MIN INT_MIN
//typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int mod = 1e9 + 7 ;
ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
ll powmod(ll a,ll b) {ll res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
// ll fac[200005];
// ll inverse(ll n){return powmod(n, mod-2);}
// ll nCr(ll n, ll r){return (fac[n] * inverse(fac[r]) % mod * inverse(fac[n-r]) % mod) % mod;}

/**.................................................................................................................................*/
int main(){
	boost;
     map<char,int>m1;
     f(i,0,4){
     	char x;
     	cin>>x;
     	m1[x]++;	
     }
     if(m1.size()==2)cout<<"Yes"<<endl;
     else cout<<"No"<<endl;
 	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

beaten_monster_num = 0

for i in range(n):
    if a[i] <= b[i]:
        if a[i+1] >= b[i] - a[i]:
            beaten_monster_num += b[i]
            a[i+1] -= b[i] - a[i]
        else:
            beaten_monster_num += a[i] + a[i+1]
            a[i+1] = 0
    else:
        beaten_monster_num += b[i]

print(int(beaten_monster_num))


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m;
    cin >> n >> m;
    vi h(n);
    rep(i, n) cin >> h[i];
    vector<bool> ok(n, true);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        if (h[a] <= h[b]) ok[a] = false;
        if (h[b] <= h[a]) ok[b] = false;
    }
    int ans = 0;
    rep(i, n) {
        if (ok[i]) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3768
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
 
using namespace std;
 
#define pai 3.14159265359
#define mod 1000000007

int main()
{
    string s;
    cin >> s;
    vector<bool> ischecked(4, false);
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'N') ischecked[0] = true;
        else if(s[i] == 'W') ischecked[1] = true;
        else if(s[i] == 'S') ischecked[2] = true;
        else if(s[i] == 'E') ischecked[3] = true;
    }
    if((ischecked[0] && !ischecked[2]) || (!ischecked[0] && ischecked[2]) || (ischecked[1] && !ischecked[3]) || (!ischecked[1] && ischecked[3])) cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

int main() {
	// your code goes here
	int n,S[14]={},H[14]={},C[14]={},D[14]={};
	cin>>n;
	char m;
	int a;

	for(int i=1 ; i<=n ; i++){
		cin>>m>>a;
		if(m=='S'){S[a]=1;}
		if(m=='H'){H[a]=1;}
		if(m=='C'){C[a]=1;}
		if(m=='D'){D[a]=1;}
	}
	    
	for( int i=1 ; i<=13 ; i++){
		if(S[i]==0){cout<<"S "<<i<<endl;}
	}
	
	for( int i=1 ; i<=13 ; i++){
		if(H[i]==0){cout<<"H "<<i<<endl;}
	}
	
	for( int i=1 ; i<=13 ; i++){
		if(C[i]==0){cout<<"C "<<i<<endl;}
	}
	for( int i=1 ; i<=13 ; i++){
		if(D[i]==0){cout<<"D "<<i<<endl;}
	}
	
	return 0;
}

Measured memory_bytes: 3116
import math
count=0
n,d=map(int,input().split())
for i in range(n):
  p1,p2=map(int,input().split())
  d1=math.sqrt((p1*p1)+(p2*p2))
  d2=float(d1)
  if d>=d2:
    count+=1

  else:
    pass
print(count)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;scanf("%d%d",&n,&m);
    vector<int> c(m);
    for(int i=0;i<m;i++)scanf("%d",&c[i]);
    sort(c.begin(),c.end());
    vector<int> dp(n+1);
    for(int i=0;i<n+1;i++)dp[i]=i;
    for(int i=1;i<m;i++){
        vector<int> ndp(n+1);
        for(int j=0;j<n+1;j++){
            if(j<c[i])ndp[j]=dp[j];
            else ndp[j]=min(dp[j],min(dp[j-c[i]]+1,ndp[j-c[i]]+1));
        }
        dp=ndp;
    }
    printf("%d\n",dp[n]);
    return 0;
}


Measured memory_bytes: 3464
def solve():
    N, K, *h = map(int, open(0).read().split())
    h += [h[-1]] * K
    
    dp = [10 ** 10] * (N + K)
    dp[0] = 0
    for i in range(N - 1):
        for j in range(1, K + 1):
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
    print(dp[N - 1])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 59948
#include<stdio.h>
#define N 101

int main()
{
  int n,sum[N][N],a,b,c,d,e,f,g;

  scanf("%d",&n);
  
  for(a=0;a<n+1;a++){
    for(b=0;b<n+1;b++){
      sum[a][b]=0;
    }
  }
  for(a=0;a<n;a++){
    scanf("%d %d ",&c,&d);
    for(b=0;b<d;b++){
      scanf("%d",&e);
      sum[c -1][e-1]=1;
    }
  }
  for(a=0;a<n;a++)
    {
      for(b=0;b<n;b++)
	{
	  printf("%d",sum[a][b]);
	  if(b!=n-1)
	    {
	      printf(" ");
	    }
	}
      printf("\n");
    }
  return 0;
}

	



Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(20)

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 998244353;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

void dijkstra(const vector<vector<edge2> > &G, int s, INTV &dist/*, INTV &prev*/){
  int E = G.size();
  dist.assign(E, VERYBIG); dist[s] = 0;
  // prev.assign(E, -1);
  priority_queue<INTP, vector<INTP>, greater<INTP> > que;
  que.push({0, s}); // {dist, index}
  while(!que.empty()){
    INTP p = que.top(); que.pop();
    int v = p.second;
    if(dist[v] < p.first) continue;
    REP(i, G[v].size()){
      edge2 e = G[v][i];
      if(dist[e.to] > dist[v]+e.cost){
        dist[e.to] = dist[v]+e.cost;
        // prev[e.to] = v;
        que.push({dist[e.to], e.to});
      }
    }
  }
}

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

  int N, M; cin >> N >> M;
  vector<vector<edge2> > graph(N);
  REP(i, M){
    int l, r, c; cin >> l >> r >> c; l--; r--;
    graph[l].pb({r, c});
  }
  REP(i, N-1){
    graph[i+1].pb({i, 0});
  }
  INTV dist;
  dijkstra(graph, 0, dist);
  cout << (dist[N-1]==VERYBIG ? -1 : dist[N-1]) << endl;
}


Measured memory_bytes: 9336
use warnings;
use strict;

my @sa = split //, <>;
chomp $sa[-1];
my @sb = split //, <>;
chomp $sb[-1];
my @sc = split //, <>;
chomp $sc[-1];

my $flag = 'a';
my $ans = 'd';
while(1) {
	if($flag eq 'a') {
		$flag = shift(@sa);
	} elsif($flag eq 'b') {
		$flag = shift(@sb);
	} else {
		$flag = shift(@sc);
	}
	if($#sa == -1) {
		$ans = 'a';
		last;
	} elsif($#sb == -1) {
		$ans = 'b';
		last;
	} elsif($#sc == -1) {
		$ans = 'c';
		last;
	}
}
if($ans eq 'a') {
	print "A\n";
} elsif($ans eq 'b') {
	print "B\n";
} else {
	print "C\n";
}

exit;

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(100000)

def ii(): return int(input())
def iis(): return input().split()
def imi(): return map(int,iis())
def iil(): return list(imi())

s,t = input().split()
a,b = imi()
u = {s:a,t:b}
u[input()] -= 1
print(u[s], u[t])

Measured memory_bytes: 3060