akhauriyash/Code-Regression huggingface dataset:
h, w = map(int, input().split())
w += 2
h += 2
grid = ["#" * w]

dpx = [[0] * w for _ in range(h)]
dpy = [[0] * w for _ in range(h)]
for y in range(1, h - 1):
    grid.append("#" + input() + "#")
    for x in range(1, w):
        if grid[y][x] == '.':
            dpx[y][x] = dpx[y][x - 1] + 1
            dpy[y][x] = dpy[y - 1][x] + 1
    for x in range(w - 2, 0, -1):
        if dpx[y][x] != 0 and dpx[y][x + 1] != 0:
            dpx[y][x] = dpx[y][x + 1]

max_val = 0
for y in range(h - 2, 0, -1):
    for x in range(1, w - 1):
        if dpy[y][x] != 0 and dpy[y + 1][x] != 0:
            dpy[y][x] = dpy[y + 1][x]
        val = dpy[y][x] + dpx[y][x] - 1
        if max_val < val:
            max_val = val
print(max_val)

Measured memory_bytes: 142388
using System;

namespace arc070_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());
            int i;
            int sum = 0;
            for (i = 0; sum < x; i++)
            {
                sum += i;
            }
            Console.WriteLine(i - 1);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int t, d, l;
void solve() {
	int x, ans = 0, res = 1;
	for (int i = 1; i <= t; i++) {
		cin >> x;
		if (res < i)res = i;
		if (x >= l) {
			ans += min(t, i + d) - res;
			res = min(t, i + d);
		}
	}
	cout << ans << endl;
}
signed main() {
	while (cin >> t >> d >> l && t > 0)solve();
}


Measured memory_bytes: 3096
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map{it.toLong()}

    val B = Array(N + 1) {0L}
    val C = Array(N + 1) {0L}

    for (i in A.indices) {
        B[i + 1] = gcd(A[i], B[i])
    }
    for (i in A.indices.reversed()) {
        C[i] = gcd(C[i + 1], A[i])
    }

    var res = 0L
    for (i in A.indices) {
        res = Math.max(res, gcd(B[i], C[i + 1]))
    }
    println(res)
}

/**
 * Calculate the greatest common divisor of `x` and `y` with Euclidean algorithm
 */
tailrec fun gcd(x: Long, y: Long): Long = if (y == 0L) x else gcd(y, x % y)


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

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

  ll N; cin >> N;
  ll R; cin >> R;

  ll ans = R;
  if (N < 10) {
    ans += 100 * (10 - N);
  }

  cout << ans << '\n';
  return 0;
}

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

long long int F(long long int n1, long long int n2) {
  long long int digit1 = 1, digit2 = 1;
  while(n1/10 != 0) {
    digit1++;
    n1 /= 10;
  }
  while(n2/10 != 0) {
    digit2++;
    n2 /= 10;
  }
  return max(digit1, digit2);
}
    


int main () {
  long long int N;
  cin >> N;
  long long int ans;
  for (long long int i=1;i<=sqrt(N);i++) {
    if (i==1) {
      ans = F(1,N);
    }
    else if (N%i==0) {
      ans = min(ans,F(i,N/i));
    }
  }
  cout << ans << endl;
}


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

int main() {
	
	int a, b;
	cin >> a >> b;
	cout << (a - 1) * (b - 1) << endl;
	
	return 0;
}

Measured memory_bytes: 256
from collections import deque
from scipy.sparse.csgraph import floyd_warshall

def solve():
  h,w = (int(i) for i in input().split())
  maze = ["#"*(w+2)]
  for i in range(h):
    maze.append("#" + input() + "#")
  maze.append("#"*(w+2))

  dist = [(1,0),(0,1),(-1,0),(0,-1)]
  d = [[0]*500 for _ in range(500)]
  for y in range(1,h+1):
    for x in range(1,w+1):
      if maze[y][x] == ".":
        for dy,dx in dist:
          if maze[y+dy][x+dx] == ".":
            oldy = x + w*y
            inty = x+dx + w*(y+dy)
            d[inty][oldy] = 1
            d[oldy][inty] = 1
  ans = 0
  d = floyd_warshall(d)
  for i in range(500):
    for j in range(500):
      if d[i][j] < 10**15:
              ans = max(d[i][j],ans)
  print(int(ans))




solve()

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

int main()
{
    int n;
    bool a[4][13];
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 13; j++)
        {
            a[i][j] = false;
        }
    }
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        int rank;
        char suit;
        cin >> suit >> rank;

        if (suit == 'S')
        {
            a[0][rank-1] = true;
        }
        else if (suit == 'H')
        {
            a[1][rank-1] = true;
        }
        else if (suit == 'C')
        {
            a[2][rank-1] = true;
        }
        else if (suit == 'D')
        {
            a[3][rank-1] = true;
        }
    }

    for (int i = 0; i < 13; i++)
    {
        if(a[0][i] == false)
        {
            cout <<  "S " << i+1 << endl;
        }
    }
    for (int i = 0; i < 13; i++)
    {
        if(a[1][i] == false)
        {
            cout << "H " << i+1 << endl;
        }
    }
    for (int i = 0; i < 13; i++)
    {
        if(a[2][i] == false)
        {
            cout << "C " << i+1 << endl;
        }
    }
    for (int i = 0; i < 13; i++)
    {
        if(a[3][i] == false)
        {
            cout << "D " << i+1 << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3092
## 他の方と処理内容がほぼ同じなのに何でTLEになるか分からないので、他の方のコードでテスト
N = int(input())
a = list(map(int,input().split(' ')))
a.sort()
    

fathers = [a.pop()]
for _ in range(N):
    sons = list()
    b = list()
    
    for father in fathers:
        while a:
            x = a.pop()
            if father > x:
                sons.append(x)
                break
            else:
                b.append(x)
                
    a = a + b[::-1]
    fathers.extend(sons)
    fathers.sort(reverse = True)
    
    
    
if len(fathers) == 2**N:
    print('Yes')
else:
    print('No')

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

#define         eps         10e-9
#define         pi          2*acos(0)
#define         P1          1e9+7
#define         P2          1e9+9
#define         lli         long long int

using namespace std;

///ISNNJB

/**int fx[]={+1,-1,+0,+0};
int fy[]={+0,+0,+1,-1};
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};*/

int main() {
    /***freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    lli a,b,c,d,t,n,m,x,y,q,ctn,l1,l2;
    char ch;
    cin>>ch;
    if(ch>='A'&&ch<='Z')
        cout<<"A"<<endl;
    else
        cout<<"a"<<endl;


    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <stack>

using namespace std;


int main(){
	int n;

	while(1){
		cin >> n;
		if(n==0) break;

		int paz[n][5];

		for(int i=0 ; i<n ; i++){
			for(int j=0 ; j<5 ; j++){
				cin >> paz[i][j];
			}
		}

		/*
		for(int i=0 ; i<n ; i++){
			for(int j=0 ; j<5 ; j++){
				cout << paz[i][j];
			}
			cout << endl;
		}
		*/


		int end_flag = 0;
		int score = 0;

		while(1){
			if(end_flag == 1) break;


			//????????¨??????????????????
			int combo;
			end_flag = 1;
			for(int i=0 ; i<n ; i++){

				combo = 0;

				if(paz[i][0] != 0 && paz[i][0] == paz[i][1] && paz[i][1] == paz[i][2]){
					combo = 1;
					end_flag = 0;
				}else if(paz[i][1] != 0 && paz[i][1] == paz[i][2] && paz[i][2] == paz[i][3]){
					combo = 2;
					end_flag = 0;
				}else if(paz[i][2] != 0 && paz[i][2] == paz[i][3] && paz[i][3] == paz[i][4]){
					combo = 3;
					end_flag = 0;
				}



				//cout << combo << endl;

				if(combo == 1){
					if(paz[i][0] == paz[i][3] && paz[i][0] == paz[i][4]){
						for(int j=0 ; j<5 ; j++){
							score += paz[i][j];
							paz[i][j] = 0;
						}
					}else if(paz[i][0] == paz[i][3]){
						for(int j=0 ; j<4 ; j++){
							score += paz[i][j];
							paz[i][j] = 0;
						}
					}else{
						for(int j=0 ; j<3 ; j++){
							score += paz[i][j];
							paz[i][j] = 0;
						}
					}
				}else if(combo == 2){
					if(paz[i][1] == paz[i][4]){
						for(int j=1 ; j<5 ; j++){
							score += paz[i][j];
							paz[i][j] = 0;
						}
					}else{
						for(int j=1; j<4 ; j++){
							score += paz[i][j];
							paz[i][j] = 0;
						}
					}
				}else if(combo == 3){
					for(int j=2 ; j<5 ; j++){
						score += paz[i][j];
						paz[i][j]=0;
					}
				}

			}

			//????????¨????????°????¨????????????????0???????????¨????????????????????????
			/*
			for(int i=0 ; i<n ; i++){
				for(int j=0 ; j<5 ; j++){
					cout << paz[i][j];
				}
				cout << endl;
			}
			cout << endl;
			*/

			for(int k=0 ; k<n ; k++){
				for(int i=1 ; i<n ; i++){
					for(int j=0 ; j<5 ; j++){
						if(paz[i][j] == 0){
							paz[i][j] = paz[i-1][j];
							paz[i-1][j] = 0;
						}
					}
				}
			}


			/*
			for(int i=0 ; i<n ; i++){
				for(int j=0 ; j<5 ; j++){
					cout << paz[i][j];
				}
				cout << endl;
			}
			*/

		}

		cout << score << endl;

	}
	return 0;
}

Measured memory_bytes: 1160
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Abhilash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int arr[] = new int[n];
            int count = 0;
            int i = 11;
            while (i < 55555 && count < n) {
                if (isPrime(i)) {
                    arr[count] = i;
                    count += 1;
                }
                i += 10;
            }
            for (int j = 0; j < n; j++)
                out.print(arr[j] + " ");
        }

        private boolean isPrime(int n) {
            for (int i = 3; i * i <= n; i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, std::vector<long long> A){
  vector<long double> InvA;
  REP(N){
    InvA.push_back(1.0l/(long double)A[i]);
  }
  long double s=accumulate(InvA.begin(),InvA.end(),0.0l);
  cout<<setprecision(1000)<<1.0l/s<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI (3.14159265358979323846)
#define ld long double
#define int long long
#define MOD 1000000007
#define w(x) int x; cin >> x; while(x--)
#define F first
#define S second
#define PB push_back
     
const char nl = '\n';
const int N = 1e4 + 5;


void solve(){
 
    int n; cin >> n;

    pair <int, int> p[n];

    for(int i = 0; i < n; i++)
    {
        int x, y; cin >> x >> y;
        p[i] = {x, y};
    }

    int cnt = 0;

    for(int i = 0; i < n; i++)
    {
        if(p[i].F == p[i].S)
        {
            cnt++;
            if(cnt == 3)
            {
                cout << "Yes" << nl;
                return;
            }
        }
        else cnt = 0;
    }

    cout << "No" << nl;

}   


int32_t main(){
         
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
        
    int t = 1;
    //cin >> t;
    while(t--) 
        solve();

}

Measured memory_bytes: 3636
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		int N,K;
		Scanner sc = new Scanner(System.in);
		N=sc.nextInt();//何日間の予定を考えるか
		K=sc.nextInt();//何日間の予定が決まっているか
		int pasta[][]=new int[6][N];
		int pastaplan[]=new int[N];
		for(int i=0;i<K;i++){
			int day=sc.nextInt();//何日の予定が決まっているか
			pastaplan[day-1]=sc.nextInt();//その日のパスタは何か
		}
		if(pastaplan[0]==0){//もし１日目の予定が決まっていなければ
			pasta[1][0]=1;pasta[3][0]=1;pasta[5][0]=1;
			
		}else if(pastaplan[0]==1){
			pasta[1][0]=1;
		}else if(pastaplan[0]==2){
			pasta[3][0]=1;
		}else if(pastaplan[0]==3){
			pasta[5][0]=1;
		}
		for(int j=1;j<N;j++){
			if(pastaplan[j]==0){//j日の予定がきまってなければ
				pasta[0][j]=pasta[1][j-1];//２日連続の時には前日の１日目の値がそのままくる。
				pasta[2][j]=pasta[3][j-1];
				pasta[4][j]=pasta[5][j-1];
				pasta[1][j]=pasta[2][j-1]%10000+pasta[3][j-1]%10000+pasta[4][j-1]%10000+pasta[5][j-1]%10000;
				pasta[3][j]=pasta[0][j-1]%10000+pasta[1][j-1]%10000+pasta[4][j-1]%10000+pasta[5][j-1]%10000;
				pasta[5][j]=pasta[0][j-1]%10000+pasta[1][j-1]%10000+pasta[2][j-1]%10000+pasta[3][j-1]%10000;
			}else if(pastaplan[j]==1){//j日の予定がトマトだったら
				pasta[0][j]=pasta[1][j-1];
				pasta[1][j]=pasta[2][j-1]+pasta[3][j-1]+pasta[4][j-1]+pasta[5][j-1];
			}else if(pastaplan[j]==2){
				pasta[2][j]=pasta[3][j-1];
				pasta[3][j]=pasta[0][j-1]+pasta[1][j-1]+pasta[4][j-1]+pasta[5][j-1];
			}else{
				pasta[4][j]=pasta[5][j-1];
				pasta[5][j]=pasta[0][j-1]+pasta[1][j-1]+pasta[2][j-1]+pasta[3][j-1];
			}
		}
		int sum=pasta[0][N-1]%10000+pasta[1][N-1]%10000+pasta[2][N-1]%10000+pasta[3][N-1]%10000+pasta[4][N-1]%10000+pasta[5][N-1]%10000;
		System.out.println(sum%10000);
	}
}

Measured memory_bytes: 18132
/*
    HARSHAD VAGHASIYA

        @DAIICT
        
          H_M_Vaghasiya

            */
#include<bits/stdc++.h>
using namespace std;
#define FS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define INF 10000000000
#define ld long double
#define pb push_back
#define mp make_pair
#define pu push
#define vsz(v) cout<<v.size()<<endl; 
#define printv(v) for(ll i=0;i<v.size();i++)cout<<v[i]<<" "; cout<<endl;
#define printvpair(v) for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<endl;
#define sz size()
#define ff first
#define ss second
#define setpri(x) cout<<setprecision(x);
#define all(v) v.begin(),v.end()
ll gcd(ll a,ll b){return __gcd(a,b);}
ll fact(ll n){ll s=1; for(ll i=1;i<=n;i++)s*=i; return s;}
ll pow1(ll n,ll k,ll mm){
    if(k==0)return 1;
    if(k%2==0)return (pow1((n%mm)*(n%mm),k/2,mm))%mm;
    return ((n%mm)*(pow1((n%mm)*(n%mm),k/2,mm)%mm))%mm;
}
ll pow2(ll n,ll k,ll m){ll ans=1;
    while(k>0){if(k%2==1)ans=ans*n;
        n=n*n;k/=2;
    }return ans;
}
bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
	return a.first > b.first;
}
void solve(){
	FS;
    ll i,j,k,q,n,m,x,y,z;
	cin>>n;
	ll	odd=n/2;
	if(n%2==1)odd++;
	//cout<<odd<<endl;
	ld oo=odd;
	//cout<<oo<<endl;
	float nn=oo/n;
	//cout<<nn<<endl;
	//setprecision(10);
	printf("%.10f",nn);
}
int main(){
	ll i,j,k,n,m,x,y,z;
	n=1;
	//cin>>n;
	while(n--)solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <complex>
#include <fstream>
#include <cmath>

using namespace std;

int main(void){
    string s; int count = 0;
    cin >> s;
    for(int i=0;i<3;i++){
        if(s.at(i)=='1'){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())

original = [i + 1 for i in range(n)]
numbers = [i + 1 for i in range(n)]

count = [0 for i in range(n)]

while any(i % 2 == 0 for i in numbers):
    for j,number in enumerate(numbers):
        
        if number % 2 == 0 :
            numbers[j] = number / 2
            count[j] += 1

print (original[count.index(max(count))])

Measured memory_bytes: 3064
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

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

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

ll N, M, K, i, j, k, l, ans, cnt = 0;
ll a, b, c;
string s;
string RGB = {"RGB"};

int main(){
    //cin >> ;
    //cout << ans << endl;
    cin >> N;
    cin >> s;

    ll rgb[3] = {0, 0, 0}; 

    REP(i, N){
        if(s.at(i) == 'R'){
            rgb[0]++;
        }else if(s.at(i) == 'G'){
            rgb[1]++;

        }else{
            rgb[2]++;
        }
    }
    ans = rgb[0] * rgb[1] * rgb[2];

    REP(i, N - 2){
        FOR(j, i + 1, N - 2){
            set<char> se;
            se.insert(s.at(i));
            se.insert(s.at(j));
            if(j + (j - i) >= s.size()){
                continue;
            }
            se.insert(s.at(j + (j - i)));
            if(se.size() == 3){
                ans--;
            }
        }
    }
    



    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
n = gets.to_i
s = gets.chomp.split('')
num = min = s[1..-1].count('E')

(1..n).each do |i|
  num += 1 if s[i-1] == "W"
  num -= 1 if s[i] == "E"
  min = num if num < min
end
puts min

Measured memory_bytes: 28420
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

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

    if (n == 1) {
        cout << "Yes" << endl;
        return 0;
    }
    int max = 0;
    rep(i, n)
    {
        if (max - h[i] > 1) {
            cout << "No" << endl;
            return 0;
        }
        if (h[i] > max) max = h[i];
    }
    cout << "Yes" << endl;
}

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

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
    static long mod=1000000007;
    // static int dx[]={1,-1,0,0};
    // static int dy[]={0,0,1,-1};
    // static int dx[]={1,-1,0,0,1,1,-1,-1};
    // static int dy[]={0,0,1,-1,1,-1,1,-1};
    // PriorityQueue<Integer> que = new PriorityQueue<Integer>(); 
    //HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
    //ArrayList<Integer> lis = new ArrayList<Integer>();
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        int d[] = new int[n];
        for( int i=0; i<n; i++ ){
            d[i] = sc.nextInt();
        }
        for( int t=n-1; -1<t; t-=2 ){
            out.print(d[t]+" ");
        }
        for( int i=n%2==1?1:0; i<n; i+=2 ){
            out.print(d[i]);
            if(i+2<n)out.print(" ");
        }


        out.println();
        out.flush();
    }

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

    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
     
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }
}

class XY {
    int x,y,d;
    XY(int x, int y, int d) {
        this.x=x;
        this.y=y;
        this.d=d;
    } 
}

class P implements Comparable<P>{
    int diff,id1,id2;
    P(int diff, int id1,int id2) {
        this.diff=diff;
        this.id1=id1;
        this.id2=id2;
    } 
      
    public int compareTo(P p){
        return diff - p.diff;
    } 
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 52704
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;

const ll MAX_N = 1e5 + 5;
ll n, m, sum;
ll Arr[MAX_N];
pii q[MAX_N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	for (ll i = 0; i < n; i++)
		cin >> Arr[i];

	sort(Arr, Arr + n);
	ll ind = 0;
	for (ll i = 0; i < m; i++)
		cin >> q[i].second >> q[i].first;
	
	sort(q, q + m);
	reverse(q, q + m);
	for (ll i = 0; i < m; i++) {
		while (ind < n && Arr[ind] < q[i].first && q[i].second) {
			Arr[ind] = q[i].first;
			ind++;
			q[i].second--;
		}
	}

	for (ll i = 0; i < n; i++)
		sum += Arr[i];

	cout << sum << "\n";
	return 0;
}

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


int main() {
    char c;
    cin >> c;
    vector<char> s={'a','i','u','e','o'};
    bool flag=false;
    for (int i=0;i<5;i++) {
        if (c==s[i]) flag=true;
    }
    if (flag) cout << "vowel" << endl;
    else cout << "consonant" << endl;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long X){
    rep(A,0,1e3) {
        ll B = pow(abs((ll)pow(A, 5) - X), 0.2);
        if ((ll)pow(A, 5) - (ll)pow(B, 5) == X) {
            cout << A << " " << B << endl;
            return;
        } else if ((ll)pow(A, 5) - (ll)pow(-B, 5) == X) {
            cout << A << " " << -B << endl;
            return;
        }
    }
    assert(false);
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 4156
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, x, y, z; cin >> n >> x >> y >> z;
  int sum = x + y + z;
  // dp[i][j] = 数列の i 番目 (1-based) まで見たときに
  //            その直前の数の状態が j となっている場合の数 (XYZを含む場合を除く)
  // 1 -> 1
  // 2 -> 01
  // 3 -> 001 と表す
  vector<vector<long long> > dp(n + 1, vector<long long>(1 << sum, 0));
  dp[0][0] = 1;
  REP(i, n) REP(j, 1 << sum) if (dp[i][j] > 0) {
    FOR(k, 1, 11) {
      long long bit = j;
      bit <<= k;
      bit += (1 << (k - 1));
      bit &= (1 << sum) - 1;
      // bit が XYZを含む形になってはいけない
      if (!(bit >> (sum - 1) & 1) || !(bit >> (sum - x - 1) & 1) || !(bit >> (sum - x - y - 1) & 1)) {
        (dp[i + 1][bit] += dp[i][j]) %= MOD;
      }
    }
  }
  // 余事象を考える
  long long ans = 1;
  REP(i, n) (ans *= 10) %= MOD;
  REP(j, 1 << sum) (ans -= dp[n][j]) %= MOD;
  if (ans < 0) ans += MOD;
  cout << ans << '\n';
  return 0;
}


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

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

 string s;
 cin >> s;
 bool ok = ((s[2]==s[3]) && (s[4]==s[5]));
 cout << (ok ? "Yes\n" : "No\n");

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int x = 0;
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'I')
        {
            x++;
        }
        else
        {
            x--;
        }
        ans = max(ans, x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int w,a,b;
  int table = 0;
  int min = 999999, max = 0;

  scanf("%d%d%d", &w, &a, &b);

  if(a <= b) {
    min = a;
    max = b;
  }
  if(a >= b){
    min = b;
    max = a;
  }

  table = (min+w);

  if(table < max){
    printf("%d", max-table);
  }
  else if(table >= max){
    printf("0");
  }

  return 0;
}

Measured memory_bytes: 128
from fractions import gcd

a,b,c,d = map(int, input().split())

lcm = int(c * d / gcd(c, d))

bb = int((b // c) + (b // d) - (b // lcm))

aa = int(((a-1) // c) + ((a-1) // d) - ((a-1) // lcm))

print((b-a) - int(bb-aa) + 1)

Measured memory_bytes: 5304
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		if (K==1) {
			System.out.println(0);
		} else {
			System.out.println(N-K);
		}
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    long long N=S.size();
    if(N<=4){
        cout<<0<<endl;
    }
    else{
      vector<int>TEN(N+1);
      TEN.at(0)=1;
      for(long long i=1;i<N+1;i++){
          TEN.at(i)=(TEN.at(i-1)*10)%2019;
      }
      vector<int>A(N);
      A.at(0)=S.at(N-1)-'0';
      for(long long i=1;i<N;i++){
          int B=S.at(N-1-i)-'0';
          A.at(i)=(A.at(i-1)+(B*TEN.at(i)))%2019;
      }
      vector<long long>list(2019,0);
      for(long long i=0;i<N;i++){
          list.at(A.at(i))=list.at(A.at(i))+1;
      }
      long long sum=0;
      for(long long i=0;i<2019;i++){
          sum=sum+((list.at(i)*(list.at(i)-1))/2);
      }
      cout<<sum+list.at(0)<<endl;
    }
}

Measured memory_bytes: 5236
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair

void solve()
{
    string s, t;
    cin >> s >> t;
    
    string res = s;
    
    int m = (int) s.length();
    
    for(int step = 0; step < m; step++)
    {
        for(int i = 0; i < m; i++)
        {
            res[i] = s[(i + step) % m];
        }
        
        if(t == res)
        {
            cout << "Yes";
            return;
        }
    }
    
    cout << "No";
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    //freopen("file.in", "r", stdin);freopen("file.out", "w", stdout);
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>

using namespace std;

int main() {
	string str = { 0 };
	cin >> str;
	int i = 0;

	str += '\n';


	while (str[i]!='\n') {
		if (str[i] == 'B') {
			if (i == 0) {
				str.erase(str.begin());
				continue;
			}
			str.erase(str.begin() + i-1);
			str.erase(str.begin() + i-1);
			i--;
		}
		else i++;
	}
	cout << str ;

	return 0;
}

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

Measured memory_bytes: 3640
#include <stdio.h>
int main(){
  int a,b,c,ans;
  scanf("%d%d%d",&a,&b,&c);
  if	 (a==b && b==c && c==a){ ans = 1; }
  else if(a!=b && b!=c && c!=a){ ans = 3; }
  else						   { ans = 2; }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>

using namespace std;

int main()
{
    int a, b, temp, i;
    for(i=1; i<=3000; i++)
    {
        cin >> a >> b;
        
        if(a==0 && b==0)
            break;
            
        if(a > b)
        {
            temp = a;
            a = b;
            b = temp;
        }

    cout << a << " " << b << endl;
    }
}


Measured memory_bytes: 3116
#!/usr/bin/env python2
from __future__ import division, print_function

import os
import sys
from atexit import register
from io import BytesIO

range = xrange

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')

n = int(input())
p = [float(i) for i in input().split()]

dp = [0.0] * (n + 1)
dp[0], dp[1] = 1 - p[0], p[0]

for i in range(1, n):
    _dp = [0.0] * (n + 1)
    _dp[0] = (1 - p[i]) * dp[0]
    for j in range(1, n + 1):
        _dp[j] = (p[i] * dp[j - 1]) + ((1 - p[i]) * dp[j])
    dp = _dp

print(sum(dp[(n + 1) // 2:]))


Measured memory_bytes: 33896
H, W, A, B = map(int, input().split())
ans = []
for i in range(H - B):
  line = ["1" if j <= A - 1 else "0" for j in range(W) ]
  ans.append(line)
for i in range(H - B, H):
  line = ["0" if j <= A - 1 else "1" for j in range(W)]
  ans.append(line)
for i in ans:
  print("".join(i))

Measured memory_bytes: 50908
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize
    }
    let mut ans = n_dig(n);
    for i in 1..n {
        if i * i > n {
            break;
        }
        if n % i == 0 {
            ans = n_dig(n / i);
        }
    }
    println!("{}", ans);
}

fn n_dig(n: usize) -> usize {
    let mut d = 1;
    while 10usize.pow(d) <= n  {
        d += 1;
    }
    d as usize
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

template<typename A>
void UNIQUE(vector< A > &a,int mode=0){
    if(mode==0){ sort(ALL(a),greater< A >());}else{ sort(ALL(a));}
    a.erase(unique(ALL(a)),a.en());
}

int main(){
    int N;
    cin>>N;
    Vs W(N);
    REP(i,N) cin>>W[i];

    Vs WW = W;
    UNIQUE(WW);
    if(W.size() != WW.size()){
        cout<<"No"<<endl;
        return 0;
    }

    REP(i,N-1){
        if(W[i][W[i].size()-1] != W[i+1][0]){
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define ll long long
using namespace std;
ll n,p,a[105],c[55][55],sum,cnt1,cnt2,ans1,ans2;
int main()
{
	scanf("%lld%lld",&n,&p);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]),sum+=a[i];
		if(a[i]&1) cnt1++;
		else cnt2++;
	}
	c[0][0]=c[1][0]=c[1][1]=1;
	for(int i=2;i<=n;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=i;j++) c[i][j]=c[i-1][j]+c[i-1][j-1];
	}
	if((sum&1)==p)
		for(int i=0;i<=cnt1;i+=2) ans1+=c[cnt1][i];
	else for(int i=1;i<=cnt1;i+=2) ans1+=c[cnt1][i];
	for(int i=0;i<=cnt2;i++) ans2+=c[cnt2][i];
	printf("%lld\n",ans1*ans2);
	return 0;
}

Measured memory_bytes: 128
import math
from collections import deque
from collections import defaultdict
import itertools as it

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	if len(res)==0:
		res = [n]
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	data = [2]
	#data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	ans = [x for x in data if x!=0]
	#ans = data[:]
	return ans

n,l = readInts()
s = []
for i in range(n):
	s.append(input())

s.sort()

print("".join(s))

Measured memory_bytes: 3444
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define null (-1)
using namespace std;
struct node{int fa,se;};
int n;
int color[100000];
vector<int> a[100000];
void dft(int s,int d){

	stack<int> sd;
	sd.push(s);
  color[s]=d;
	while(!sd.empty()){
		int qw=sd.top();sd.pop();
		for(int i=0;i<a[qw].size();i++){
			int wq=a[qw][i];
			if(color[wq]==null){
			color[wq]=d;
				sd.push(wq);
			}
		}
	}
}
void colors(){
int i,j=1;
	for(i=0;i<n;i++){
	color[i]=null;
}
	for(i=0;i<n;i++){
	if(color[i]==null) 
	dft(i,j++);
    
    }
}
main(){
	int i,j,m,q,fo,fs;
 node g[100000];
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++){
		cin>>fo>>fs;
		a[fo].push_back(fs);
		a[fs].push_back(fo);
	}
  cin>>q;
	for(i=0;i<q;i++){
		scanf("%d %d",&fo,&fs);	
     g[i].fa=fo;
      g[i].se=fs;
	}
	colors();
 for(i=0;i<q;i++){
	if(color[g[i].fa]==color[g[i].se])
		printf("yes\n");
		else
		printf("no\n");
 }
	return 0;
}



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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(a, b) << " " << max(0, a + b - n) << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;

char a;

int main(){
    cin>>a;

    rep(i,26){
        if(a=='a'+i){
            cout<<'a'<<endl;
            return 0;
        }
    }

    cout<<'A'<<endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  string S;
  cin >> S;
  int N = S.length();
  int sum0=0;
  int sum1=0;
  for (int i=0;i<N;i++){
    if(i%2==0){
      if(S[i]=='0') ++sum0;
      else ++sum1;
    }else{
      if(S[i]=='0') ++sum1;
      else ++sum0;
    }
  }
  cout << N-max(sum0,sum1) << endl;
}


Measured memory_bytes: 3272
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14
int gcd(int a, int b){
	return (b == 0 ? a : gcd(b, a % b));
}

signed main(){
	int n, x;
	cin >> n >> x;

	if(x > n - x)
		x = n - x;

	int sa = gcd(n, x);
	cout << n + n - sa + n - sa - sa << endl;
}


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

int main () {
  int N , T , A ;
  cin >> N >> T >> A ;
  int H[N] ;
  for(int i = 0 ; i < N ; i++ ) cin >> H[i] ;
  int p = T - A ;
  int ans = -1 ;
  double a ;
  double pre =100000000000;
  for(int i = 0 ; i < N ; i++ ){
    a = abs(p - H[i] * 0.006) ;
    pre = min(pre,a) ;
    if(pre==a) ans = i ;
  }
  cout << ans + 1 << endl ;
}

Measured memory_bytes: 256
import java.util.Scanner;

//Search
public class Main{

	static int c;
	static int[] a;

	static int comp(int k, int x){
		c++;
		return a[k]-x;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			a = new int[n];
			for(int i=0;i<n;i++)a[i]=sc.nextInt();
			int x = sc.nextInt();
			c = 0;
			int l = 0;
			int r = n-1;
			int k = (l+r)/2;
			while(l<=r){
//				System.out.println("K: " + k + " L:" + l + " R:" + r);
				int com = comp(k, x);
				if(r<=l)break;
				if(com<0)l=k+1;
				else if(com>0)r=k-1;
				else break;
				k=(l+r)/2;
			}
			System.out.println(c);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
//#define int long long
using namespace std;
using graph=vector<vector<int>>;

vector<bool> visited;
int ans=0;
int num=0;
int N,M;
graph G;
void dfs(int v){
	visited[v]=true;
	num++;
	if(num==N){
		ans++;
	}else{
		for(auto nv : G[v]){
			if(visited[nv])continue;
			else dfs(nv);
		}
	}
	num--;
	visited[v]=false;
}

signed main(){
	cin>>N>>M;
	G.assign(N,vector<int>(0));
	for(int i=0;i<M;i++){
		int a,b; cin>>a>>b; a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	visited.assign(N,false);
	dfs(0);
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
N =26

D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(0,D,1)]

last = [-1]*(N)
manzoku = 0

for i in range(0,D,1):
    maximum = 0
    maximum_index = 0
    for j in range(0,26,1):
        if s[i][j]+c[j]*(i-last[j]) > maximum:
            maximum = s[i][j]+c[j]*(i-last[j])
            maximum_index = j
    last[maximum_index] = i

    print(maximum_index+1)

Measured memory_bytes: 68520
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
const int INFI=2147483647;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


int main() {
  int n; cin >>n;
  cout <<n/3600 <<":" <<n/60%60 <<":" <<n%60 <<endl;
}



Measured memory_bytes: 3112
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<math.h>

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

int main() {
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n)cin >> a[i];
	int cnt = 0;
	bool flag = true;
	while (flag) {
		rep(i, n) {
			if (a[i] % 2 == 0) {
				a[i] /= 2;
			}
			else {
				flag = false;
			}
		}
		cnt++;
	}
	cout << cnt-1 << endl;
	return 0;
}

Measured memory_bytes: 256