akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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 (b<a) { a=b; return 1; } return 0; }
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

const int mxN = 1e4 + 5;
V<> g[mxN];
int n;
V<> c;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    c.resize(n);
    rep(i, n) cin >> c[i];
    sort(rall(c));
    int ret = accumulate(c.begin()+1, c.end(), 0);
    cout << ret << endl;
    queue<int> q;
    q.push(0);
    V<> ans(n, -1);
    ans[0] = c[0];
    int i = 1;
    while(!q.empty()) {
        int p = q.front();
        q.pop();

        for(auto v : g[p]) {
            if(ans[v] == -1) {
                ans[v] = c[i];
                i++;
                q.push(v);
            }
        }

    }
    for(auto c : ans) {
        cout << c << " ";
    }
    cout << endl;
}

Measured memory_bytes: 4284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n), t(100002, 0);
  REP(i, n) { cin >> a[i]; }
  REP(i, n) {
    t[a[i]]++;
    if (a[i] - 1 >= 0) t[a[i] - 1]++;
    t[a[i] + 1]++;
  }
  cout << *max_element(ALL(t)) << endl;
  return 0;
}


Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const int MOD = 998244353;

int madd(int a, int b) {
	int res = a + (b < 0 ? b + MOD : b);
	return (res >= MOD ? res - MOD : res);
}

const int N = 10;
const int M = 1 << N;
int col[N][N];
int dp[M][M];
int alts[M * M][2*N+1];

bool check(int m0, int m1) {
	vector<int> rc(N, 0), cc(N, 0);
	for (int y = 0; y < N; ++y) {
		if (! (m0 & (1 << y))) rc[y] = 3;
	}
	for (int x = 0; x < N; ++x) {
		if (! (m1 & (1 << x))) cc[x] = 3;
	}
	for (int y = 0; y < N; ++y) {
		if (! (m0 & (1 << y))) continue;
		for (int x = 0; x < N; ++x) {
			if (! (m1 & (1 << x))) continue;
			rc[y] |= col[y][x];
			cc[x] |= col[y][x];
		}
	}
	bool works = true;
	for (auto v : rc) works &= (v == 3);
	for (auto v : cc) works &= (v == 3);
	return works;
}

// Calculate alternating sum over submasks
int altSum(int m0, int m1) {
	int m = m0 | (m1 << N);
	alts[m][2*N] = dp[m0][m1];
	for (int j = 2*N - 1; j >= 0; --j) {
		if (m & (1 << j)) {
			alts[m][j] = madd(alts[m][j+1], -alts[m ^ (1 << j)][j+1]);
		} else {
			alts[m][j] = alts[m][j+1];
		}
	}
	return alts[m][0];
}

// Set value of DP at mask m0 m1 val.
void setDP(int m0, int m1, int val) {
	dp[m0][m1] = val;
	altSum(m0, m1);
}

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

	int h, w;
	cin >> h >> w;
	for (int y = 0; y < h; ++y) {
		string row;
		cin >> row;
		for (int x = 0; x < w; ++x) col[y][x] = 1 + (row[x] == '#');
	}

	// If any operations are applied, then some rows or some columns must be completely black or white
	// Delete those columns and rows and solve recursively. We need to do inclusion-exclusion to not double-count solutions.
	// Where does the initial state of the grid matter? If in some subgrid we have no completely black or white columns or rows,
	// we can add one to the solution for that subgrid!
	// To calculate the answer sufficiently fast, we'll need to do some prefix sums.

	int h0 = 1 << h;
	int h1 = 1 << w;
	for (int m0 = 0; m0 < h0; ++m0) {
		setDP(m0, 0, 1);
	}
	for (int m1 = 0; m1 < h1; ++m1) {
		setDP(0, m1, 1);
	}

	for (int m0 = 0; m0 < h0; ++m0) {
		int rc = __builtin_popcount(m0);
		if (rc == 0) continue;
		for (int m1 = 0; m1 < h1; ++m1) {
			int cc = __builtin_popcount(m1);
			if (cc == 0) continue;

			int res = check(m0, m1);
			// Inclusion-exclusion, paint only multiple rows
			for (int s0 = m0;; s0 = (s0 - 1) & m0) {
				int pw = rc - __builtin_popcount(s0);
				if (pw > 1) {
					ll mult = (ll)(pw & 1 ? 1 : MOD - 1) * ((1 << pw) - 2) % MOD;
					res = (res + (ll)mult * dp[s0][m1]) % MOD;
				}
				if (s0 == 0) break;
			}
			// Inclusion-exclusion, paint only multiple columns
			for (int s1 = m1;; s1 = (s1 - 1) & m1) {
				int pw = cc - __builtin_popcount(s1);
				if (pw > 1) {
					ll mult = (ll)(pw & 1 ? 1 : MOD - 1) * ((1 << pw) - 2) % MOD;
					res = (res + (ll)mult * dp[m0][s1]) % MOD;
				}
				if (s1 == 0) break;
			}


			// Inclusion-exclusion, paint both rows and columns
			int add = MOD - altSum(m0, m1);
			add = madd(add, add);
			res = madd(res, add);

			setDP(m0, m1, res);
		}
	}
	cout << dp[h0-1][h1-1] << '\n';
}


Measured memory_bytes: 90368
n=int(input())
l=list(map(int,input().split()))

d={}
sm=0
for i in range(n):
  sm+=l[i]
  if l[i] not in d:
    d[l[i]]=1
  else:
    d[l[i]]+=1

q=int(input())
for i in range(q):
  a,b=map(int,input().split())
  dif=b-a
  if a not in d:
    d[a]=0
  sm+=(dif*d[a])
  print(sm)
  if b not in d:
    d[b]=0
  d[b]+=d[a]
  d[a]=0


Measured memory_bytes: 23800
#include <stdio.h>
#include <stdlib.h>
#define N 100
#define INF 10000000


int matrixChainOrder(int*,int);

int main(){

  int i,j,n;
  int p[N];

  scanf("%d",&n);

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

  printf("%d\n",matrixChainOrder(p,n));

  return 0;
}

int matrixChainOrder(int *p, int n){
  int i, j, k, l,  m[N][N], q;
  for(i = 1; i <= n; i++)
    m[i][i] = 0;
  for(l = 2; l <= n; l++){
    for(i = 1; i <= n-l+1; i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k = i; k < j; k++){
    q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
    if(m[i][j] > q) m[i][j] = q;
      }
    }
  }
  return m[i-1][j];
}

Measured memory_bytes: 632
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007ll //998244353ll
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    string s;
    cin>>s;
    int n=s.size();
    if(s[n-1]=='s')
    {
        s+='e';
        s+='s';
    }
    else
    s+='s';
    cout<<s;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cmath>

using namespace std;

int main() {
  string s;
  int q;
  cin >> s;
  scanf("%d", &q);
  
  bool rev = false;
  for (int i = 0; i < q; i++) {
    int t, f;
    char c;
    cin >> t;
    if (t == 1) {
      // reverse(s.begin(), s.end());
      rev = !rev;
    } else if (t == 2) {
      cin >> f >> c;
      if (f == 1) {
        if (!rev) {
          s.insert(0, 1, c);
        } else {
          s += c;
        }
      } else if (f == 2) {
        if (!rev) {
          s += c;
        } else {
          s.insert(0, 1, c);
        }
      }
    }
  }

  if (rev) {
    reverse(s.begin(), s.end());
  }

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    set<char> s;
    rep(i,0,4) {
        char x;
        cin >> x;
        s.insert(x);
    }
    cout << (sz(s) == 2 ? "Yes" : "No") << endl;
    return (0^_^0);
}



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

int main() {
  int n;
  int total = 0;
  cin >> n;
  vector<int> b(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> b.at(i);
  }
  for (int i = 1; i < n - 1; i++) {
    total += min(b.at(i - 1), b.at(i));
  }
  total += b.at(0);
  total += b.at(n - 2);
  cout << total << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;




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

    int n;
    cin>>n;
    string s;
    cin>>s;
    string ans="";

    int co=0;
    for(int i=0;i<n;i++){
        if(s[i]=='(')co++;
        else {
            co--;
            if(co<0){
                ans+='(';
                co++;
            }
        }
    }
    ans+=s;
    rep(i,co)ans+=')';
    fin(ans);

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
import java.util.*;import java.io.*;import java.math.*;

public class Main
{

    public static void process()throws IOException
    {
        long n=nl(),k=nl();
        long res=0l;
        while(n!=0){
            res++;
            n/=k;
        }
        pn(res);
    }


    static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new AnotherReader();
        boolean oj = true;

       // oj = System.getProperty("ONLINE_JUDGE") != null;
        if(!oj) sc=new AnotherReader(100);

        long s = System.currentTimeMillis();
        int t=1;
        while(t-->0)
            process();
        out.flush();
        if(!oj)
            System.out.println(System.currentTimeMillis()-s+"ms");
        System.out.close();  
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);System.out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    static boolean multipleTC=false;



/////////////////////////////////////////////////////////////////////////////////////////////////////////

    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
    
    
    

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

using namespace std;
#define ll long long

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

signed main()
{
	int n;
	cin >> n;
	int res = 0;
	for(int i = 1; i < n+1; i+=2) {
		int cnt = 0;
		reps(j, 1, i+1) {
			if (i % j == 0) cnt++;
		}
		if (cnt == 8) {
			res++;
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int n;
    cin>>n;
    vi as(n), bs(n);
    cin>>as>>bs;

    vvi dp(1<<n, vi(n, INF));
    rep(i, n) {
        if (i % 2) dp[1<<i][i] = i;
        else dp[1<<i][i] = i;
    }
    rep(i, 1<<n) rep(j, n) {
        if (dp[i][j] == INF) continue;
        int p = pcnt(i);
        int cnt = 0;
        int prev;
        if (j % 2 - (p - 1) % 2) prev = bs[j];
        else prev = as[j];
        rep(k, n) {
            if (i>>k&1) continue;
            if (k % 2 - p % 2) {    // blue
                if (prev <= bs[k]) chmin(dp[i | 1<<k][k], dp[i][j] + cnt);
            }
            else {
                if (prev <= as[k]) chmin(dp[i | 1<<k][k], dp[i][j] + cnt);
            }
            cnt++;
        }
    }
    int ans = INF;
    rep(i, n) chmin(ans, dp[(1<<n) - 1][i]);
    if (ans != INF) cout<<ans<<endl;
    else cout<<-1<<endl;
}

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

int main()
{
    int t;
    cin>>t;
    while(t--){
        long long a,b;
        cin>>a>>b;
        long long sum = a*b;
        long long ss = (long long)sqrt(sum);
        if(a==b||abs(a-b)==1){
            a  = min(a,b);
            cout<<2*a-2<<endl;
        }else{
            if(ss*ss==a*b) ss--;
            if(ss*(ss+1)>=a*b){
                cout<<2*ss-2<<endl;
            }else{
                cout<<2*ss-1<<endl;
            }
        }
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException{
		Main mainObj = new Main();
		mainObj.solve();
	}
	
	public void solve() throws IOException{
		FastScanner fs = new FastScanner();
		String s = fs.next();
		if(s.charAt(2) == s.charAt(3)  && s.charAt(4) == s.charAt(5)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

	public class FastScanner {
		
		BufferedReader reader;
		private StringTokenizer st;
		
		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		
		public String next() throws IOException {
			if(st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}
		
		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}
		
		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}
		
		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		
		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for(int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}
		
		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for(int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}
		
		public void close() throws IOException {
			reader.close();
		}
	}
}


Measured memory_bytes: 21332
// vim: set fdm=marker:
// {{{
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <utility>

using namespace std ;

typedef long long ll ;

// }}}


char query(int loc) {
    cout << loc << endl;
    string s;
    cin >> s;
    if(s[0] == 'V')
        exit(0);
    return s[0];
}

int main()
{
    int N;
    cin >> N;
    char l = query(0);
    char r = query(N-1);
    int lb = 0, ub = N-1;
    while(true) {
        int mid = (lb+ub)/2;
        char m = query(mid);
        if(0 == (mid-lb)%2) {
            if(l != m)
                ub = mid;
            else {
                lb = mid;
            }
        }
        else {
            if(l == m)
                ub = mid;
            else {
                lb = mid;
                l = m;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 852
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
using namespace std;
using ll = long long;
ll MOD = 1e9+7;


int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        ans += s[i] == '1';
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
using namespace std;
int main(void){
    // Your code here!
    long long N;
    long long M;
    long long A_sum = 0;
    cin >> N >> M;
    vector<long long> A(M);
    for (int i=0; i<M; i++){
        cin >> A[i];
        A_sum += A[i];
    }
    if(N < M){
        cout << "-1" << endl;
        return 0;
    }
    if(N < A_sum){
        cout << "-1" << endl;
        return 0;
    }
    cout << N - A_sum << endl;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		double sum = 0;
		for(int i=1; i<=n; i++) {
			double a = sc.nextDouble();
			sum += (1/a);
		}
		System.out.println(1/sum);
	}
}

Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int par[10000];

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

void unite(int x, int y) {
    par[find(x)] = find(y);
}

int x[10000], y[10000];

double length(double a, double b) {
    return sqrt(a * a + b * b);
}

int main(void) {
    int i, n, m;
    cin >> n >> m;
    REP (i,n) cin >> x[i] >> y[i];
    priority_queue<pair<double,pair<int,int>>> que;
    double ans = 0;
    REP (i,m) {
        int p, q;
        cin >> p >> q;
        p--; q--;
        double len = length(x[p]-x[q],y[p]-y[q]);
        que.push({len,{p,q}});
        ans += len;
    }
    REP (i,n) par[i] = i;
    while (!que.empty()) {
        auto p = que.top(); que.pop();
        double len = p.first;
        int a = p.second.first;
        int b = p.second.second;
        if (find(a) != find(b)) {
            unite(a,b);
            ans -= len;
        }
    }
    cout << fixed << setprecision(4);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3548
N=int(input())
d={}
for _ in range(N):
    x=input()
    if x in d.keys():
        d[x]+=1
    else:
        d.update({x:1})
        
s=max(d.values())
moji=[]
for i in d.items():
    if i[1]==s:
        moji.append(i[0])
for i in sorted(moji):
    print(i)
    

Measured memory_bytes: 32988
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int pa[3], ju[2],sum=0;
	for (int i = 0; i < 3; i++) {
		cin >> pa[i];
	}for (int i = 0; i < 2; i++) {
		cin >> ju[i];
	}
	sort(pa, pa + 3);
	sort(ju, ju + 2);

	sum = pa[0] + ju[0] - 50;
	
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int n,i,j;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while (cin >> n >> i >> j, n) {
    i--; j--;
    string ans;
    while (n > 0) {
      if ((i % 2 == 0) ^ (j % 2 == 0)) {
        ans = "R" + ans;
      } else {
        ans = "L" + ans;
      }
      if (i < POW(n-1)) {
        i = POW(n-1)-1-i;
      } else {
        i = i - POW(n-1);
      }
      j >>= 1;
      n--;
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3128
#include <iostream>
#include <map>

int main() {
    int n;
    std::cin >> n;
    std::map<int, int> ap;

    for (int i = 0; i < n; i++) {
        int a;
        std::cin >> a;
        if (ap[a] == 1) {
            std::cout << "NO" << std::endl;
            return 0;
        }
        ap[a]++;
    }

    std::cout << "YES" << std::endl;
    return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>

int main(void) {
	int n,i;
	scanf("%d",&n);
	double A[n],B,ans;
	for(i=0;i<n;i++){
		scanf("%lf",&A[i]);
		B=(double)B+(1.0/(double)A[i]);
	}
	
	ans=(double)(1.0/B);
	printf("%lf",ans);


}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef vector< pii > vii;

#define ll          long long
#define ff          first
#define ss          second
#define pb          push_back
#define mkp         make_pair
#define sz          size()

#define forf(a,b,c)    for(int i=a;i<=b;i+=c)
#define forr(a,b,c)    for(int i=a;i>=b;i-=c)
#define all(a)      a.begin(),a.end()
#define mem(a,b)    memset(a,b,sizeof(a))
#define pi          2*acos(0.0)
#define End         return 0;
#define nl endl

#define scan1(a)    scanf("%d",&a)
#define scan2(a,b)  scanf("%d %d",&a,&b)
#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define scanl(a)    scanf("%lld",&a)
#define scanll(a,b) scanf("%lld %lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define print1(a)    printf("%d",a)
#define print2(a,b)  printf("%d %d",a,b)
#define print3(a,b,c)  printf("%d %d %d",a,b,c)
#define printl(a)    printf("%lld",a)
#define printll(a,b) printf("%lld %lld",a,b)
#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)

#define MAXN        100000007
#define INF 0x3f3f3f3f
bool mark[100005];vi prime;
void seive(ll N){for(int i=2;i<=N;i++){if(mark[i]==false){prime.pb(i);for(int j=i+i;j<N;j+=i)mark[j]=true;}}}
//freopen("input.txt", "r", stdin);

int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   int a,b,res=0,current=1;
   cin>>a>>b;
   int k=1;
   while(k<b){
    k+=a;
    k--;
    res++;
   }
   cout<<res<<endl;
}


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

using namespace std;

int main()
{
	long long A,B,C,K,sum;
	cin>>A>>B>>C>>K;
	sum=0;
	if(K<=A)
	{
		sum+=K;
	}
	if(K>A && K<=A+B)
	{
		sum+=A;
	}
	if(K>A+B && K<=A+B+C)
	{
		sum+=A;
		sum-=(K-(A+B));
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <algorithm>
#define N 4010
#define P 924844033

using namespace std;

int n,k,t;
int a[N];
int vis[N][2];
long long fac[N],g[N];
long long Ans;
long long f[N][N][2];

int main(){
  scanf("%d%d",&n,&k);
  for(int i=1;i<=n;i++)
    for(int j=0;j<2;j++)
      if(!vis[i][j]){
	int x=i,y=j,len=0;
	while(x<=n){
	  vis[x][y]=1;
	  len++;
	  x+=k; y^=1;
	}
	a[t+=len]=1;
      }
  f[1][0][0]=1;
  for(int i=1;i<=t;i++)
    for(int j=0;j<=n;j++){
      f[i+1][j][0]=(f[i][j][0]+f[i][j][1])%P;
      if(!a[i]) f[i+1][j+1][1]=f[i][j][0];
    }
  for(int i=1;i<=n;i++) g[i]=(f[t][i][0]+f[t][i][1])%P;
  fac[0]=1;
  for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%P;
  Ans=fac[n];
  for(int i=1,j=-1;i<=n;i++,j=-j) Ans=(Ans+P+j*g[i]*fac[n-i])%P;
  printf("%lld\n",Ans);
  return 0;
}


Measured memory_bytes: 249728
#include<iostream>
#include<cmath>
using namespace std;
int main(){
long a,b,c,d;
cin>>a>>b>>c>>d;
long long k=max(a*c,a*d);
long long j=max(b*c,b*d);
long long val=max(k,j);
cout<<val;


return 0;
}


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

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()

const int MAXN = 2 * 105000;

int n;
int color[MAXN];
vector<int> g[MAXN];
int sum[MAXN];
long long rem[MAXN];
int sz[MAXN];

void dfs(int v, int par = -1) {
    int curSum = sum[color[v]];
    sz[v] = 1;

    for (int to : g[v]) {
        if (to == par)
            continue;

        sum[color[v]] = 0;
        dfs(to, v);
        sz[v] += sz[to];

        if (color[to] != color[v]) {
            int num = sz[to] - sum[color[v]];
            rem[color[v]] += 1ll * num * (num + 1) / 2;
        }
    }

    sum[color[v]] = curSum + sz[v];
}

int main() {

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &color[i]);
        color[i]--;
    }

    for (int i = 0; i < n - 1; i++) {
        int from, to;
        scanf("%d %d", &from, &to);
        from--; to--;
        g[from].push_back(to);
        g[to].push_back(from);
    }

    dfs(0);
    for (int i = 0; i < n; i++) {
        if (color[0] == i) continue;

        int num = sz[0] - sum[i];
        rem[i] += 1ll * num * (num + 1) / 2;
    }

    for (int i = 0; i < n; i++) 
        printf("%lld\n", 1ll * n * (n + 1) / 2 - rem[i]);

    return 0;
}


Measured memory_bytes: 34428
def partial_sum(arr)
  s = 0
  arr.map do |elt|
    s += elt
  end
end

n = gets.to_i
row1 = gets.split.map(&:to_i)
row2 = gets.split.map(&:to_i)

cs1 = partial_sum(row1)
cs2 = partial_sum(row2.reverse).reverse
puts cs1.zip(cs2).map { |a,b| a+b }.max


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = INT32_MAX;
const ll INFL = INT64_MAX;
const int mod = 1e9 + 7;

template <typename T>
void print_vec(vector<T> v) {
  for (T i : v) cout << i << " ";
  cout << endl;
}

int main() {
  int a, p;
  cin >> a >> p;
  a *= 3;
  int ans = (a + p) / 2;
  cout << ans << endl;
  return 0;
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 N;
  cin >> N;
  i64 n = N;
  vector<tuple<i64, int>> fs;
  for (i64 i = 2; i * i <= N; ++i) {
    if (n % i != 0) continue;
    int cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    fs.emplace_back(i, cnt);
    if (n == 1) break;
  }
  if (n > 1) {
    fs.emplace_back(n, 1);
  }
  i64 ans = 0;
  for (auto [p, k] : fs) {
    for (int i = 1;; ++i) {
      if (i > k) break;
      ++ans;
      k -= i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3676
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n, a, b, ans;
    int[] nums;
    int max = Integer.MAX_VALUE;
    
    void run(){
	while(sc.hasNext()){
	    n = sc.nextInt();
	    a = sc.nextInt();
	    b = sc.nextInt();
	    ans = 0;
	    if(n==0) break;

	    nums = new int[n+1];
	    Arrays.fill(nums, max);
	    nums[0] = 0;

	    // aとbそれぞれ回す
	    for(int i=0; i<nums.length; i++)
		if(nums[i]!=max && i+a<nums.length)
		    nums[i+a] = nums[i]+a;
	    for(int i=0; i<nums.length; i++)
		if(nums[i]!=max && i+b<nums.length)
		    nums[i+b] = nums[i]+b;

	    // maxの箇所を数える
	    for(int i=0; i<nums.length; i++)
		if(nums[i]==max) ans++;

	    System.out.println(ans);
	}
    }
}

Measured memory_bytes: 37648
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main () {
    int a, b; cin >> a >> b;
    cout << a*b << endl;

    return 0;
}

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

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define FORR(i, a, b) for (long long i = (a); i >= (b); i--)
#define REPR(i, N) for (long long i = n; i >= 0; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ALL(s) (s).begin(), (s).end()
#define pb(a) push_back(a)

#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

int main()
{
    ll N;
    ll ans = 1;
    cin >> N;
    FOR(i,1,N+1){
        ans = ans * i % INF; 
    }
    cout << ans << endl;
}


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

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

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

int main() {
    //cout.precision(10);
    int n;
    ll first;
    ll x[100500];
    cin >> n;
    cin >> first;
    for(int i = 1; i <= n; i++){
        cin >> x[i];
    }
    ll ans = abs(first - x[1]);
    for(int i = 2; i <= n; i++){
        ans = gcd(ans, abs(first - x[i]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

double calcs(double a, double b, double c){
	double s = (a+b+c)/2;
	return sqrt(s*(s-a)*(s-b)*(s-c));
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(8);
	double a, l, x;
	while(cin >> a >> l >> x){
		cout << calcs(a, l, l) + calcs(l, (l+x)/2, (l+x)/2)*2 << endl;
	}

	return 0;
}

Measured memory_bytes: 1280
def Z_algo(S):
    n = len(S)
    LCP = [0] * n
    c = 0  # 最も末尾側までLCPを求めたインデックス
    for i in range(1, n):
        # i番目からのLCPが以前計算したcからのLCPに含まれている場合
        if i + LCP[i - c] < c + LCP[c]:
            LCP[i] = LCP[i - c]
        else:
            j = max(0, c + LCP[c] - i)
            while i + j < n and S[j] == S[i + j]:
                j += 1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP


n = int(input())
s = input()
ans = 0
for i in range(n):
    lcp = Z_algo(s[i:])
    for j, p in enumerate(lcp):
        tmp = min(j, p)
        ans = max(ans, tmp)
print(ans)


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

int main(){
    int N;
    string S;
    int Q;
    cin >> N >> S >> Q;
    
    for (int i = 0; i < Q; i++) {
        int k;
        cin >> k;
        ll dn = 0, mn = 0, dmn = 0;
        ll ans = 0;
        for (int j = 0; j < N; j++) {
            if (j >= k) {
                if (S[j-k] == 'D') {
                    dn--;
                    dmn -= mn;
                }
                else if (S[j-k] == 'M') mn--;
            }
            if (S[j] == 'D') dn++;
            else if (S[j] == 'M') {
                mn++;
                dmn += dn;
            }
            else if (S[j] == 'C') ans += dmn;
        }
        cout << ans << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1412
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1.01e9;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

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

void add(int & x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int sum(int x, int y) {
  add(x, y);
  return x;
}

int mult(int x, int y) {
  return (ll) x * y % mod;
}

int power(int x, ll p) {
  int res = 1;
  while (p) {
    if (p & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
    p >>= 1;
  }
  return res;
}

int inv(int x) {
  return power(x, mod - 2);
}

void precalc() {
}

const int maxn = 5e5 + 100;
const int maxc = 26;

int n;
int q;
char s[maxn];
int a[maxn];
vector<vector<pair<int, int> > > qs;

bool read() {
  if (scanf("%s", s) < 1) {
    return false;
  }
  n = strlen(s);
  scanf("%d", &q);
  qs.clear();
  qs.resize(n);
  for (int i = 0; i < q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    qs[l].pb(mp(r, i));
  }
  return true;
}

int dp[maxn][30];

vector<vector<int> > tree;

int used[maxn];
int used2[maxn];
int ans[maxn];

void dfs(int v) {
  if (used2[v]) {
    return;
  }
  used2[v] = 1;
  used[v] = 1;
  if (v < n) {
    for (auto i : qs[v]) {
      if (used[i.first]) {
        ans[i.second] = 1;
      } else {
        ans[i.second] = 0;
      }
    }
  }
  for (auto to : tree[v]) {
    dfs(to);
  }
  used[v] = 0;
}

void solve() {
  for (int i = 0; i < n; i++) {
    a[i] = (int) (s[i] - 'a') + 1;
  }
  for (int i = 0; i <= maxc; i++) {
    dp[n][i] = inf;
  }
  tree.clear();
  tree.resize(n + 1);
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j <= maxc; j++) {
      dp[i][j] = inf;
    }
    dp[i][a[i]] = i + 1;
    int cur = i + 1;
    int val = a[i];
    while (val && cur < inf) {
      cur = dp[cur][val];
      val++;
      if (val > maxc) {
        val = 0;
      }
      dp[i][val] = cur;
    }
    if (val == 0 && cur < inf) {
      for (int j = 1; j < a[i]; j++) {
        dp[i][j] = dp[cur][j];
      }
    }
    if (dp[i][0] < inf) {
      tree[dp[i][0]].pb(i);
    }
    /*for (int j = 0; j <= maxc; j++) {
      printf("%d%c", dp[i][j], " \n"[j == maxc]);
    }*/
  }
  memset(used2, 0, sizeof(used2));
  for (int i = n; i >= 0; i--) {
    dfs(i);
  }
  for (int i = 0; i < q; i++) {
    printf(ans[i] ? "Yes\n" : "No\n");
  }
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time: %.3f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}



Measured memory_bytes: 115712
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Markup;

namespace AlgoTest1
{

    class Program
    {
        static void Main(string[] args)
        {
            Int32[] FirstParams = Console.ReadLine().Split().Select(i => Int32.Parse(i)).ToArray();

            double Ax = 0;
            double Ay = FirstParams[0];

            double Bx = 0;
            double By = FirstParams[1];

            double DegH = 360.0 / 12 * FirstParams[2] + 360.0 / 12 / 60 * FirstParams[3];
            double DegM = 360.0 / 60 * FirstParams[3];


            double iAx = Ax * Math.Cos(DegH * Math.PI / 180) - Ay * Math.Sin(DegH * Math.PI / 180);
            double iAy = Ax * Math.Sin(DegH * Math.PI / 180) + Ay * Math.Cos(DegH * Math.PI / 180);
            double iBx = Bx * Math.Cos(DegM * Math.PI / 180) - By * Math.Sin(DegM * Math.PI / 180);
            double iBy = Bx * Math.Sin(DegM * Math.PI / 180) + By * Math.Cos(DegM * Math.PI / 180);

            double DiffX = iAx - iBx;
            double DiffY = iAy - iBy;

            double Ans = Math.Sqrt(Math.Pow(DiffX, 2) + Math.Pow(DiffY, 2));
            Console.WriteLine(Ans);
        }
    }
}

Measured memory_bytes: 28676
#include <stdio.h>

#define Mod 1000000007

long long pow2(long long k)
{
	static long long ans[200001] = {1, 2};
	if (ans[k] != 0) return ans[k];
	
	long long i;
	for (i = 1; i * 2 <= k; i *= 2) ans[i*2] = ans[i] * ans[i] % Mod;
	ans[k] = ans[i] * pow2(k - i) % Mod;
	return ans[k];
}

void merge_sort(int x[], int n)
{
	static int y[200001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, C[200001];
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d", &(C[i]));
	merge_sort(C, N);
	if (N == 1) {
		printf("%d\n", C[0] * 2 % Mod);
		fflush(stdout);
		return 0;
	}
	
	long long ans = 0;
	for (i = N - 1; i >= 0; i--) ans = (ans + pow2(N - 2) * (N - i + 1) % Mod * C[i]) % Mod;
	printf("%lld\n", ans * pow2(N) % Mod);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3388
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

double E(int i){//i面サイコロの期待値
  return (1+i)/2.0;
}

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

  double sum = 0;
  queue<double> sumq;
  int buf;
  for(int i=0; i<K; i++){
    cin>>buf;
    sumq.push(E(buf));
    sum += E(buf);
  }
  double ans = sum;

  double Ef;
  for(int i=K; i<N; i++){
    cin>>buf;
    Ef = sumq.front();sumq.pop();
    sum += (E(buf) - Ef);
    sumq.push(E(buf));
    ans = max(ans, sum);
  }

  //cout<<ans<<endl;
  printf("%lf\n", ans);
}

Measured memory_bytes: 1920
#include<stdio.h>
#include<string>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>

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

int main(){
    int n;
    char ss[30005]={};
    int s[30005]={};
    scanf("%d%s",&n,ss);
    REP(i,n)s[i]=ss[i]-'0';
    int front[30005][10];
    int back[30005][10];

    front[0][s[0]]=1;
    for(int i=1;i<n;i++){
        REP(j,10)front[i][j]=front[i-1][j];
        front[i][s[i]]=1;
    }

    back[n-1][s[n-1]]=1;
    for(int i=n-2;i>=0;i--){
        REP(j,10)back[i][j]=back[i+1][j];
        back[i][s[i]]=1;
    }

    int mat[11][11][11]={};
    for(int i=1;i<n-1;i++){
        for(int x=0;x<10;x++){
            for(int y=0;y<10;y++){
                if(front[i-1][x]==1 && back[i+1][y]==1)mat[x][s[i]][y]=1;
            }
        }
    }

    int ans=0;
    REP(x,10)REP(y,10)REP(z,10)if(mat[x][y][z]){
        ans++;
        //printf("%d%d%d\n",x,y,z);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2688
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kidman
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll

const int md = 1000000007;
const int INF = 1<<30;

class CMaximalValue {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n; in >> n;
        vi b(n-1); in >> b;

        vi a(n);

        a[0] = b[0];
        a[n-1] = b[n-2];

        rep(i,n-2){
            a[i+1] = min(b[i],b[i+1]);
        }

        int cnt = 0;
        rep(i,n) cnt += a[i];

        out << cnt << endl;
	}
};


int main() {
	CMaximalValue solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256