akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#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(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
    fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e18;
const ll mod = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> s(n);
    REP(i, n)
    {
        cin >> a[i];
        if (i == 0)
            s[i] = a[i];
        else
            s[i] = s[i - 1] + a[i];
    }
    vector<vector<ll>> lb(n, vector<ll>(2)), rb(n, vector<ll>(2));
    int left = 0, right;
    ll tmp = INF;

    for (right = 1; right < n; right++)
    {
        tmp = abs(s[right] - s[left] * 2);
        while (left < right && abs(s[right] - s[left + 1] * 2) < tmp)
        {
            left++;
            tmp = abs(s[right] - s[left] * 2);
        }
        lb[right][0] = s[left];
        lb[right][1] = s[right] - s[left];
    }

    right = 1;
    tmp = INF;
    for (left = 1; left < n; left++)
    {
        tmp = abs(s[n - 1] - s[right] * 2 + s[left]);
        while (right < n - 2 && abs(s[n - 1] - s[right + 1] * 2 + s[left]) < tmp)
        {
            right++;
            tmp = abs(s[n - 1] - s[right] * 2 + s[left]);
        }
        rb[left][0] = s[n - 1] - s[right];
        rb[left][1] = s[right] - s[left];
        if (left == right)
            right++;
    }
    ll ans = INF;
    for (int i = 1; i < n - 1; i++)
    {
        ll M = max(max(rb[i][0], rb[i][1]), max(lb[i][0], lb[i][1]));
        ll m = min(min(rb[i][0], rb[i][1]), min(lb[i][0], lb[i][1]));
        ll dif = M - m;
        ans = min(dif, ans);
    }
    dump(ans);
}

Measured memory_bytes: 25216
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

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

void d_err() {
    cerr << endl;
}

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

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

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

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

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

struct Dijkstra {
    struct Edge {
        ll to;
        ll c;
    };

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

    int V;
    vector<vector<Edge>> e;
    vector<ll> d;
    vector<int> next;

    Dijkstra(int V): V(V) {
        e.resize(V);
        d.resize(V);
        next.resize(V);
    }

    void add_edge(int from, int to, ll cost) {
        e[from].pb({to, cost});
    }

    void operator()(ll s) {
        priority_queue<pp, vector<pp>, greater<>> q;

        REP(i, V) d[i] = INF;
        d[s] = 0;
        q.push({0, {s, -1}});

        while(!q.empty()) {
            auto n = q.top(); q.pop();
            ll v = n.se.fi;
            if (d[v] < n.fi) continue;

            next[v] = n.se.se;

            REP(i, e[v].size()) {
                Edge cur = e[v][i];
                ll cost = d[v] + cur.c;
                if (d[cur.to] > cost) {
                    d[cur.to] = cost;
                    q.push({cost, {cur.to, v}});
                }
            }
        }
    }
};

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

    Dijkstra dijkstra(N + 1);

    REP(i, M) {
        int a, b;
        cin >> a >> b;
        dijkstra.add_edge(a, b ,1);
        dijkstra.add_edge(b, a ,1);
    }

    dijkstra(1);

    print("Yes");
    FOR(i, 2, N+1) {
        print(dijkstra.next[i]);
    }
    
}


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

int main(void){
  set<char> right;
  const string right_hand = "yuiophjklnm";
  for(size_t i = 0; i < right_hand.length(); i++)
    right.insert(right_hand[i]);

  while(true){
    string input;
    cin >> input;
    if(input == "#"){ break; }

    int count = 0;
    bool flag = true;
    for(size_t i = 0; i < input.length(); i++){
      bool now = right.count(input[i]);
      if(i != 0 && flag != now){ ++count; }
      flag = now;
    }
    cout << count << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,std::pair<P,P>> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int X, Y;
int tx, ty, kx, ky;
int map[50][50], d[50][50][50][50];

int main(){
    while(scanf("%d %d", &X, &Y), X || Y){
        scanf("%d %d %d %d", &tx, &ty, &kx, &ky);
        tx -= 1; ty -= 1; kx -= 1; ky -= 1;

        REP(i, Y){
            REP(j, X){
                scanf("%d", &map[i][j]);
            }
        }

        REP(i, X){
            REP(j, Y){
                REP(k, X){
                    REP(l, Y){
                        d[i][j][k][l] = INF;
                    }
                }
            }
        }

        std::queue<State> q;
        d[tx][ty][kx][ky] = 0;
        q.push(mp(0, mp(mp(tx, ty), mp(kx, ky))));

        int res = INF;
        while(!q.empty()){
            State s = q.front(); q.pop();
            int t = s.first, x1 = s.second.first.first, y1 = s.second.first.second,
                x2 = s.second.second.first, y2 = s.second.second.second;

            if(t >= 100){continue;}
            if(x1 == x2 && y1 == y2){res = std::min(res, t); continue;}
            if(t > d[x1][y1][x2][y2]){continue;}

            REP(i, 4){
                int nx1 = x1 + dx[i], ny1 = y1 + dy[i],
                    nx2 = x2 - dx[i], ny2 = y2 - dy[i];

                if(X <= nx1 || nx1 < 0 || Y <= ny1 || ny1 < 0 ||
                   map[ny1][nx1] == 1){
                    nx1 = x1; ny1 = y1;
                }

                if(X <= nx2 || nx2 < 0 || Y <= ny2 || ny2 < 0 ||
                   map[ny2][nx2] == 1){
                    nx2 = x2; ny2 = y2;
                }

                if(t + 1 < d[nx1][ny1][nx2][ny2]){
                    d[nx1][ny1][nx2][ny2] = t + 1;
                    q.push(mp(d[nx1][ny1][nx2][ny2], mp(mp(nx1, ny1), mp(nx2, ny2))));
                }
            }
        }

        if(res == INF){
            puts("NA");
        }else{
            printf("%d\n", res);
        }
    }
}

Measured memory_bytes: 26724
#include<stdio.h>
#include<algorithm>
int main() {
	
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int N;

	scanf("%d", &N);
	if (N % 2 == 0) {
		printf("%d", N);
	}
	else {
		printf("%d", N * 2);
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    int n,h;
    cin >> n >> h;
    int a[n];
    int b[n];
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    int asize = n-1;
    int bsize = n-1;
    int ans = 0;

    while(h>0){
        if (a[asize] >= b[bsize] || bsize == -1){
            int c = h/a[asize];
            if (h%a[asize] == 0) ans += c;
            else ans += c+1;
            h = 0;
        }
            
        else{
            h -= b[bsize];
            ans += 1;
        	bsize -= 1;
           
        }
            

    }

    cout << ans << endl;
    
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

const int N = 5001;
const int K = 5001;

bool needed(const vint &a, int n, int k, int t) {
  static bool dp[N][K];
  REP(i,n+1) REP(j,k+1) dp[i][j] = false;
  dp[0][0] = true;
  REP(i,n) REP(j,k) {
    if (i != t && j + a[i] < k) dp[i+1][j+a[i]] = dp[i+1][j+a[i]] || dp[i][j];
    dp[i+1][j] = dp[i+1][j] || dp[i][j];
  }
  FOR(j,max(0,k-a[t]),k) if (dp[n][j]) return true;
  return false;
}

int main() {
  int n, k;
  while (cin >> n >> k) {
    vint a(n);
    REP(i,n) cin >> a[i];
    sort(ALL(a));
    int result = 0;
    if (needed(a, n, k, 0)) { cout << 0 << endl; continue; }
    if (!needed(a, n, k, n - 1)) { cout << n << endl; continue;}

    int lb = 0, ub = n - 1;
    while (lb + 1 < ub) {
      int mid = (lb + ub) / 2;
      if (needed(a, n, k, mid)) ub = mid;
      else lb = mid;
    }
    cout << ub << endl;
  }
}


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

int main(){
    int n;
    std::cin >> n;

    std::vector<std::string> w(n);
    bool flg = false;
    std::cin >> w.at(0);
    for(int i = 1; i < n; ++i){
        std::cin >> w.at(i);
        if(*(w.at(i - 1).end() - 1) != *w.at(i).begin()){
            break;
        }else if(1 != std::count(w.begin(), w.end(), w.at(i))){
            break;
        }else if(i == n -1){
            flg = true;
        }
    }

    if(flg){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }

    return 0;
}


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

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

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

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

ll C[15][15];
//! iを1に変えるのに必要な魔力の最小値
ll T[15];

struct Node
{
    Node(ll c, int i)
        : cost(c), i(i)
    {
    }
    ll cost;
    int i;
};

int main()
{
    int H, W;
    cin >> H >> W;
    REP(i, 10)
    {
        REP(j, 10)
        {
            cin >> C[i][j];
        }
        T[i] = INF;
    }

    priority_queue<Node, vector<Node>, function<bool(Node, Node)>> q([](Node a, Node b) { return a.cost > b.cost; });
    q.push(Node(0, 1));
    while (!q.empty())
    {
        Node t = q.top();
        q.pop();
        if (T[t.i] <= t.cost)
            continue;
        T[t.i] = t.cost;
        REP(i, 10)
        {
            if (T[i] <= t.cost + C[i][t.i])
                continue;
            q.push(Node(t.cost + C[i][t.i], i));
        }
    }

    ll sum = 0;
    REP(h, H)
    {
        REP(w, W)
        {
            int a;
            cin >> a;
            if (a == -1)
                continue;
            sum += T[a];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    # N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    N, M = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    # h_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([]))

    if N >= 2:
        n = N * (N - 1) / 2
    else:
        n = 0

    if M >= 2:
        m = M * (M - 1) / 2
    else:
        m = 0

    print(int(n + m))


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 1"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4 3"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """1 1"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """13 3"""
        output = """81"""
        self.assertIO(input, output)

    def test_入力例_5(self):
        input = """0 3"""
        output = """3"""
        self.assertIO(input, output)


Measured memory_bytes: 5668
#include<iostream>

using namespace std;

int main(int argc,char** argv){
  int N,X;
  cin >> N >> X;
  int min;
  cin >> min;
  int sum = min;
  int num = 0;
  for(int i = 0; i<N-1;i++){
    int tmp;
    cin >> tmp;
    sum += tmp;
    if(min > tmp){
      min = tmp;
    }
  }
  num = (X - sum)/min;
  cout << N + num << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int tb[999984];
int f(int p){
	return tb[p>999982?999983:p<0?0:p];
}
int main(){
	int s = 0,i,j,p,m,n;
	for( i = 2; i < 1000; i++ )
		for( j = i * i; j < 999984; j += i )
			tb[j] = 1;
	for( i = 2; i < 999984; i++ )
		tb[i] = s += !tb[i];
	for(;scanf("%d",&n),n;){
		s = 0;
		for(; n--;){
			scanf("%d%d",&p,&m);
			s += f(p+m)-f(p-m-1)-1;
		}
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 4248
import operator

while True:
    m = int(input())
    if not m:
        break
    target = [tuple(map(int, input().split())) for _ in range(m)]
    bx, by = min(target)
    target = {(x - bx, y - by) for x, y in target}
    max_tx = max(map(operator.itemgetter(0), target))

    n = int(input())
    sky = {tuple(map(int, input().split())) for _ in range(n)}
    max_sx = max(map(operator.itemgetter(0), sky))

    lim_x = max_sx - max_tx

    for x, y in sky:
        if x > lim_x:
            continue
        for tx, ty in target:
            if (x + tx, y + ty) not in sky:
                break
        else:
            print(x - bx, y - by)
            break

Measured memory_bytes: 8240
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string s;
    cin >> s;
    if(s.length() < 4){
        cout << "No" << endl;
        return 0;
    }
    if(s.substr(0,4)=="YAKI")cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
using namespace std;

int main(){
  string a;
  cin >> a;
  cout << "ABC"+a << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
using namespace std;
#define N (1000000000+7)
#define M 998244353
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
ll A(ll x){
    if(x>=0)return x;
    else return -x;
}
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

ll c[27];
ll s[400][27];
ll last[400][27];
ll score[27];

int main(void){
	int D;
	cin>>D;
	for(int i=1;i<=26;i++)cin>>c[i];
	for(int i=1;i<=D;i++){
		for(int j=1;j<=26;j++){
			cin>>s[i][j];
		}
	}
	vector<ll>mx(D+1,0);
	for(int d=1;d<=D;d++){
		ll S = 0;
		for(int i=1;i<=26;i++){
			if(S<s[d][i]){
				mx[d]=i;
				S = s[d][i];
			}
		}
	}
	ll ans=0;
	random_device rnd;
	mt19937 mt(rnd());
	uniform_int_distribution<> rand26(1,26),randday(1,D);
	for(ll d=1;d<=D;d++){
		for(int i=1;i<=26;i++){
            last[d][i]=last[d-1][i];
            if(i==mx[d])last[d][mx[d]]=d;
        }
		ans+=s[d][mx[d]];
		for(ll j=1;j<=26;j++){
            ans-=c[j]*(d-last[d][j]);
		}
	}
	for(ll qu=0;qu<2000000;qu++){
		ll d = randday(mt);
		ll q = rand26(mt);
		//cout<<d<<" "<<q<<endl;
		ll tmp = ans;
		tmp+=s[d][q]-s[d][mx[d]];
        ll old1 = last[d][mx[d]];
        ll new1 = last[d-1][mx[d]];
        ll old2 = last[d][q];
        ll new2 = d;
        for(ll i=d;i<=D;i++){
            tmp+=c[mx[d]]*(i-last[i][mx[d]]);
            if(last[i][mx[d]]==old1)last[i][mx[d]]=new1;
            tmp-=c[mx[d]]*(i-last[i][mx[d]]);
        }
        for(ll i=d;i<=D;i++){
            tmp+=c[q]*(i-last[i][q]);
            if(last[i][q]==old2)last[i][q]=new2;
            tmp-=c[q]*(i-last[i][q]);
        }
		if(ans<tmp){
			ans = tmp;
			mx[d]=q;
		} 
		else{
			for(ll i=d;i<=D;i++){
				if(last[i][mx[d]]==new1)last[i][mx[d]]=old1;
			}
			for(ll i=d;i<=D;i++){
				if(last[i][q]==new2)last[i][q]=old2;
			}
		}
	}
	for(int i=1;i<=D;i++)cout<<mx[i]<<endl;
    return 0;
}

Measured memory_bytes: 3792
n = int(input())
if n%2 ==1:
  print(0)
  exit()

nums = [10**i for i in range(1,19)]
#fives = [10*5**i for i in range(1,30)]
fives = []
for i in range(1,30):
  for j in range(1,19):
    t = 10**j*5**i
    if t <=n:
      fives.append(t)
a = 0
for i in nums:
  a += n//i
  #print(a,i)

for i in fives:
  a += (1+n//i)//2
  #print(a,i)

print(a)

Measured memory_bytes: 38256
class KMP():
    def __init__(self, pattern):
        self.pattern = pattern
        self.n = len(pattern)
        self.create_table()

    def create_table(self):
        table = [-1]*(self.n+1)
        j = -1
        for i in range(self.n):
            while j >= 0 and self.pattern[i] != self.pattern[j]:
                j = table[j]
            j += 1
            table[i+1] = j
        self.table = table

    def match(self,s):
        n = len(s)
        j = 0
        ret = [0]*n
        for i in range(n):
            while j >= 0 and (j == self.n or s[i] != self.pattern[j]):
                j = self.table[j]
            j += 1
            if j == self.n:
                # スタート地点が重なることもあるから、+=ではなく=1にする
                # 複数あることは絶対にないので
                ret[(i-self.n+1)%n] = 1 
        return ret

def main():
    s = input()
    t = input()
    n = len(s)
    m = len(t)
    # 最大は, (n-1)+m 
    # kn >= (n-1)+m
    # k >= 1 +(m-1)/n
    k = 1 - (-(m-1)//n)
    si = s*k
    a = KMP(t)
    b = a.match(si)
    edges = [[] for i in range(n)]
    for i in range(n):
        if b[i]:
            edges[i].append((i+m)%n)
    # loopを見つける
    # start地点をすべて試す
    # 進む方向、戻る方向について別々に求める
    visited = [0]*n
    loop = False
    ans = 0
    for i in range(n):
        # 他のパスから辿られている場合
        if visited[i]:
            continue
        visited[i] = 1
        # →に進む
        cur = i
        right = 0
        while b[cur]:
            nxt = (cur + m) % n
            if visited[nxt]:
                loop = True
                break
            visited[nxt] = 1
            cur = nxt
            right += 1
        cur = i
        left = 0
        while b[(cur-m)%n]:
            nxt = (cur-m) % n
            if visited[nxt]:
                loop = True
                break
            visited[nxt] = 1
            cur = nxt
            left += 1
        if not loop:
            ans = max(ans, right+left)
        else:
            ans = -1
            break
    print(ans)

if __name__ == "__main__":
    main()

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;

#define pb push_back
#define ff first
#define ss second
#define SIZE 1000001
#define INF int(2e9 + 9)
#define BIG_INF ll(4e18 + 9)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define _sz(v) int((v).size())
#define sqr(x) (x) * (x)
#define cube(x) (x) * (x) * (x)

//#pragma GCC optimize("Ofast")

ll binpow(ll a, ll b, ll mod = BIG_INF)
{
    ll res = 1;
    while(b)
    {
        if(b & 1)
            res *= a;
        a *= a;
        b >>= 1;
        a %= mod;
        res %= mod;
    }
    res %= mod;
    return res;
}




int T = 1, n, a, b, c, d;
string s;

bool used[SIZE];




void solve()
{
    cin >> a >> b >> c >> d;


    int lst = 0;

    while(a > 0 && c > 0)
    {
        if(!lst)
        {
            c -= b;
        }else
        {
            a -= d;
        }
        lst ^= 1;
    }

    if(a <= 0)
    {
        cout << "No\n";
    }else cout << "Yes\n";
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

//    cin >> T;

    while(T--)
    {
        solve();
    }




    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

bool vis[4];

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    vis[a]=vis[b]=1;
    for (int i=1;i<=3;i++) if (!vis[i]) printf("%d\n",i);
    return 0;
}


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

int main(void){
    int x1,x2,y1,y2;

    cin >> x1 >> y1 >> x2 >> y2;

    int dx = x1-x2;
    int dy = y1-y2;

    cout << x2 + dy <<" "<< y2 - dx <<" "<< x1 + dy <<" "<< y1 - dx << endl;

}


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

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(q);
  for(int i = 0; i < q; i++) cin >> a.at(i);
  
  vector<int> ans(n);
  for(int i = 0; i < q; i++){
    ans.at(a.at(i) - 1)++;
  }
  int b = q - k + 1;
  
  for(int i = 0; i < n; i++){
    if(ans.at(i) >= b) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


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

int main() {
    int n,r;

    cin >> n >> r;

    if (n < 10) {
        r += 100 * (10-n);
    }

    cout << r << endl;
}


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



int main(void)
{
    int a, b;
    cin >> a >> b;

    int s = a-1;
    int t = b-1;
    int ans = (t + s-1) / s;

    cout << ans << endl;

    return 0;
}

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

vector<pair<int,int> > v,V;
int a[1011][1011],d[4][2],n,m;
char s[1010];

int main()
{
	scanf("%d%d",&n,&m);
	memset(a,0,sizeof(a));
	for (int i=1; i<=n; i++)
	{
		scanf("%s",s);
		for (int j=0; j<m; j++) a[i][j+1]=(s[j]=='.');
	}
	d[0][0]=d[1][0]=d[2][1]=d[3][1]=0;
	d[0][1]=d[2][0]=1,d[1][1]=d[3][0]=-1;
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++)
			if (!a[i][j]) v.push_back(make_pair(i,j));
	for (int ans=-1; ; ans++)
	{
		int siz=v.size();
		if (!siz) return printf("%d\n",ans),0;
		V.clear();
		for (int i=0; i<siz; i++)
		{
			int x=v[i].first,y=v[i].second;
			for (int j=0; j<4; j++)
				if (a[x+d[j][0]][y+d[j][1]]) a[x+d[j][0]][y+d[j][1]]=0,V.push_back(make_pair(x+d[j][0],y+d[j][1]));
		}
		v=V;
	}
	return 0;
}

Measured memory_bytes: 18408
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;

int main()
{
	int N;
	while(~scanf("%d",&N))
	{   
	    int max=0;
		for(int i=0;i<=sqrt(N);i++)
		{
			if(i*i>=max)
			max=i*i;
			else
			break;
		}
		printf("%d\n",max);
	}
}

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

int T[500001];
int n;

void maxHeapify(int i)
{
    int l = i * 2;
    int r = i * 2 + 1;
    int largest;
    if (l <= n && T[l] > T[i])
    {
        largest = l;
    }
    else
    {
        largest = i;
    }
    if (r <= n && T[r] > T[largest])
    {
        largest = r;
    }

    if (largest != i)
    {
        swap(T[i], T[largest]);
        maxHeapify(largest);
    }
}

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

    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> T[i];
    }

    for (int i = n / 2; i >= 1; i--)
    {
        maxHeapify(i);
    }

    for (int i = 1; i <= n; i++)
    {
        cout << ' ' << T[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 5120
a, b, k = map(int, input().split())
s = set()
for i in range(a, a+k):
    if i > b:
        break
    s.add(i)

for i in range(b-k+1, b+1):
    if i < a:
        continue
    s.add(i)

for i in sorted(s):
    print(i)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)


#define SZ(x) ((int)(x).size())


typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
struct Vec{
    double x, y;
};

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>
T min(T a, T b)
{
    if (a < b) return a;
    return b;
}

template<class T>
T max(T a, T b)
{
    if (a > b) return a;
    return b;
}

using namespace std;

int main()
{
    int N, M, num = 0;
    cin >> N >> M;
    vector <int> cs(N + 1, -1);
    bool bi=false;
    rep(i, M){
        int c, s;
        cin >> c >> s;
        if ((N != 1 && c == 1 && s == 0) || (cs[c] != s && cs[c] != -1)){
            bi = true;
        }
        cs[c] = s;
    }
    if (bi) {
        cout << -1 << endl;
        return 0;
    }
    repi(i, 1, N+1) {
        if (cs[i] == -1) continue;
        num += pow(10, N - i) * cs[i];
    }
    if (M == 0){
        num = 0;
    }
    if (num < pow(10, N - 1) && N > 1){
        num += pow(10, N - 1);
    }
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 3760
n = int(input())
a = []
c = []
for i in range(n):
    x1,y1=[int(i) for i in input().split()]
    a.append([x1,y1])
for i in range(n):
    x1,y1=[int(i) for i in input().split()]
    c.append([x1,y1])
a = sorted(a,key=lambda x:-x[1])
c = sorted(c,key=lambda x:x[0])
ans = 0
for i in range(n):
  e = c[i]
  for j in range(len(a)):
    if (e[0] > a[j][0] and e[1] > a[j][1]):
      a.pop(j)
      ans += 1
      break
print(ans)

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = sum(b)

for i in range(n-1):
    if a[i] + 1 == a[i + 1]:
        ans += c[a[i]-1]
print(ans)


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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

ll inp[100010];
ll n;
ll dp[100010][2];
ll solve(int ind, int lst){

    if(ind==n) return 0;

    if(dp[ind][lst]!=-1) return dp[ind][lst];

    ll ans = 0;

    if(lst==0){
        if(inp[ind]%2){
            ans=max(ans,inp[ind]/2+solve(ind+1,1));
        }
        else{
            ans=max(ans,inp[ind]/2+solve(ind+1,0));
            if(inp[ind]!=0) ans=max(ans,inp[ind]/2-1+solve(ind+1,1));
        }
    }
    else{
        if(inp[ind]!=0){
            if(inp[ind]%2){
                ans=max(ans,inp[ind]/2+1+solve(ind+1,0));
                ans=max(ans,inp[ind]/2+solve(ind+1,1));
            }
            else{
                ans=max(ans,inp[ind]/2+solve(ind+1,0));
                ans=max(ans,inp[ind]/2+solve(ind+1,1));
            }
        }
        else{
            ans=max(ans,solve(ind+1,0));
        }
    }
    dp[ind][lst]=ans;
    return ans;

}

int main(){
    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>inp[i];
    }
    cout<<solve(0,0)<<endl;
}


Measured memory_bytes: 8832
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionD
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            var a = Console.ReadLine();
            var b = Console.ReadLine();

            var flag = false;
            var aa = new Dictionary<char, char>();
            var bb = new Dictionary<char, char>();

            for (int i = 0; i < a.Length; i++) {
                if (aa.ContainsKey(a[i])) {
                    if (aa[a[i]] != b[i]) {
                        flag = true;
                    }
                } else {
                    aa.Add(a[i], b[i]);
                }

                if (bb.ContainsKey(b[i])) {
                    if (bb[b[i]] != a[i]) {
                        flag = true;
                    }
                } else {
                    bb.Add(b[i], a[i]);
                }
            }

            Console.WriteLine(flag ? "No" : "Yes");

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 14688
n = int(input())
p = list(map(int,input().split()))
count = 0
memo = {}
for i in range(n):
  if p[i]==i+1:
    count=count+1
    continue
  else:
    if count == 0:
      continue
    else:
      if count not in memo:
        memo[count]= 1
      else:
        memo[count]+=1
  count = 0
  
if count not in memo:
  memo[count]= 1
else:
  memo[count]+=1

ans = 0 
for i in memo:
  if i ==1:
    ans = ans+memo[i]
  else:
    ans = ans+memo[i]*(i//2+i%2)
print(ans)

Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define MOD 1000000007
#define INF 9223372036854775807

signed main()
{
int x=0,y=0,z=0,w=0,n=0,m=0;
std::cin >> x;
std::vector<int> v(x);
rep(i,x){
  std::cin >> v[i];
  m+=v[i];
}
std::cin >> y;
rep(i,y){
  std::cin >> z>>w;
  std::cout << m-v[z-1]+w << '\n';
}

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> cnt(9,0);
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]<3600) cnt[a[i]/400]++;
    else cnt[8]++;
  }
  int min=0;
  for(int i=0;i<8;i++){
    if(cnt[i]!=0) min++;
  }
  if(min==0) {
    min++;
    cnt[8]--;
  }
  int max=min;
  max+=cnt[8];
  cout<<min<<" "<<max;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#include <sstream>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const int INF=0x7ffffff;
const int magic=348;

//int a[1048];
int a,b,c,d;

int main()
{
	int i;
	cin>>a>>b>>c>>d;
	int s1=a,e1=b,s2=c,e2=d;
	int l=max(s1,s2),r=min(e1,e2);
	if (r-l>=0) cout<<r-l<<endl; else cout<<0<<endl;
	return 0;
}

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

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

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

#define x1 gray_cat_x1
#define y1 gray_cat_y1

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

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

const int MAXN = 2e5 + 5;

char s[MAXN];

void solve(){
	int n, l;
	scanf("%d", &n);
	int ans = 0, a = 0, b = 0, c = 0;
	REP(i, 0, n) {
		scanf("%s", &s[0]);
		l = strlen(s);
		REP(i, 1, l) {
			if (s[i - 1] == 'A' && s[i] == 'B') {
				ans++;
			}
		}
		if (s[0] == 'B' && s[l - 1] == 'A') {
			c++;
		} else if (s[0] == 'B') {
			b++;
		} else if (s[l - 1] == 'A') {
			a++;
		}
	}
	if (a == 0 && b == 0) {
		ans += max(0, c - 1);
	} else {
		ans += min(a, b) + c;
	}
	cout << ans << endl;
}   

int main(){

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


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


int main() {
    string n;
    cin >> n;

    if (n[0] == '7' || n[1] == '7' || n[2] == '7') {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    

    return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <cassert>
#include <cstdio>
#include <cstring>

using namespace std;

//const char* INSERT       = "insert";
//const char* DELETE       = "delete";
//const char* DELETE_FIRST = "deleteFirst";
//const char* DELETE_LAST  = "deleteLast";

struct Node {
    int val;
    Node *next;
    Node *prev;
};

Node *head, *tail;

vector<Node*> cache;

int main(void) {

    int n;
    cin >> n;

    head = new Node;
    head->val = -1;

    tail = new Node;
    tail->val = -1;
    tail->next = head;
    tail->prev = head;

    head->next = tail;
    head->prev = tail;

    char command[12];
    for (int i = 0; i < n; ++i) {
        cin >> command;
        if (command[0] == 'i') {
//        if (strncmp(command, INSERT, 6) == 0) {
            int x;
            cin >> x;
            Node *newnode;
            if (cache.size() > 0) {
                newnode = cache.back();
                cache.pop_back();
            }
            else {
                newnode = new Node;
            }
            newnode->val = x;
            newnode->next = head->next;
            newnode->prev = head;
            head->next->prev = newnode;
            head->next = newnode;
        }
        else if (strlen(command) == 6) {
//        else if (strncmp(command, DELETE, 6) == 0) {
            int x;
            cin >> x;
            Node *node = head->next;
            while (node != tail) {
                if (node->val == x) {
                    node->next->prev = node->prev;
                    node->prev->next = node->next;
                    cache.push_back(node);
                    break;
                }
                node = node->next;
            }
        }
        else if (command[6] == 'F') {
//        else if (strncmp(command, DELETE_FIRST, 11) == 0) {
            Node *node = head->next;
            node->next->prev = head;
            head->next = node->next;
            cache.push_back(node);
        }
        else {
//        else if (strncmp(command, DELETE_LAST, 10) == 0) {
            Node *node = tail->prev;
            tail->prev = node->prev;
            node->prev->next = tail;
            cache.push_back(node);
        }
    }

    Node *node = head->next;
    if (node != tail) {
        printf("%d", node->val);
        node = node->next;
        while (node != tail) {
            printf(" %d", node->val);
            node = node->next;
        }
    }
    printf("\n");

    delete head;
    delete tail;

    return 0;
}

Measured memory_bytes: 41148
def reconstruction(l, r):
    global i
    if l >= r:
        return
    c = PRE[i]
    i += 1
    m = IN.index(c)
    reconstruction(l, m)
    reconstruction(m + 1, r)
    POST.append(c)


if __name__ == "__main__":
    n = int(input())
    PRE = list(map(int, input().split()))
    IN = list(map(int, input().split()))
    POST = []
    i = 0
    reconstruction(0, n)
    print(" ".join(map(str, POST)))

Measured memory_bytes: 7772
N, M, C = [int(nmc) for nmc in input().split()]
B = [int(b) for b in input().split()]
ans = 0
for n in range(N):
    A = [int(a) for a in input().split()]
    S = 0
    for m in range(M):
        S += A[m] * B[m]
    S += C
    if S > 0:
        ans += 1
print(ans)

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

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

  int x, a, b;
  cin >> x >> a >> b;

  int c = b - a;
  if (c <= 0) cout << "delicious\n";
  else if (c > x) cout << "dangerous\n";
  else cout << "safe\n";

  return (0);
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <queue>


using namespace std;

using ll = long long;

ll MaxN = 1e5+1;

struct ST {
  vector<ll> t;
  
  ST() {
    t.assign(MaxN*4+19, 0);
  }

  void update(ll root, ll value, ll l, ll r, ll ql, ll qr) {
    if (ql > qr) return;
    if (ql <= l && qr >= r) { t[root] += value; return;}

    ll m = (l + r) / 2;
    // cout << value << endl;

    update(root*2, value, l, m, ql, min(m, qr) );
    update(root*2+1, value, m+1, r, max(m+1, ql), qr);
  }

  ll  query(ll root, ll l, ll r, ll pos ) {
    if (r < l) return 0;

    if (l==r && l== pos) { return t[root]; }

    ll m = (l+r)/ 2;

    return t[root] + 
    ((pos <= m)? (query(root*2, l, m, pos)): (query(root*2+1, m+1, r, pos)));
  }
};

int main() {
  ll N, M;
  cin >> N >> M;
  ST tree;
  for(auto i=0; i<M;i++) {
    ll l, r;
    cin >> l >> r;
    // cout << l << "  " << r << endl;
    tree.update(1, 1, 0, MaxN, l, r);
  };

  ll cc = 0;
  for(auto i=1; i<=N;i++) {
  //  cout <<  tree.query(1, 0, MaxN, i) << endl;
   if( tree.query(1, 0, MaxN, i) == M) cc++;
  }

  cout << cc << endl;

  return 0;
}


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

int main()
{
        set<char> S;
        ll N;
        cin >> N;
        for (int i = 0; i < N; ++i) {
                char c;
                cin >> c;
                S.insert(c);
        }
        if (S.size() == 3) {
                cout << "Three" << endl;
        }
        else cout << "Four" << endl;


}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll K, A, B;
    cin >> K >> A >> B;
    if (A >= B) {
        cout << 1 + K << endl;
        return 0;
    }

    //A枚まで増やす
    if (K <= A - 1) {
        //そこまでで終わってしまう
        cout << 1 + K << endl;
        return 0;
    }

    ll remain = K - (A - 1);
    ll half = remain / 2;
    ll ans = max(1 + K, A + half * (B - A) + (remain % 2));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int WHITE = 0;
int GRAY = 1;
int BLACK = 2;

#define MAX 100000

int color[MAX];
vector<int> G[MAX];
int reach[MAX];

void find_route(int s) {
  queue<int> S;

  S.push(s);
  color[s] = GRAY;

  reach[s] = s;

  while(!S.empty()){
    int v = S.front(); S.pop();

    for (int i = 0; i < (int)G[v].size(); i++) {
      int u = G[v][i];

      if(color[u] == WHITE) {
        color[u] = GRAY;
        reach[u] = s;
        S.push(u);
      }
    }
  }
}

int main() {
  for(int i = 0; i < MAX; i++) color[i] = WHITE;
  for (int i = 0; i < MAX; i++) reach[i] = -1;

  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;

    G[u].push_back(v);
    G[v].push_back(u);
  }

  for(int i = 0; i < MAX; i++) {
    if(color[i] != GRAY) {
      find_route(i);
    }
  }

  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int s, t;
    cin >> s >> t;

    if(reach[s] != -1 && reach[s] == reach[t]) {
      cout << "yes";
    } else {
      cout << "no";
    }
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 9404
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
#define PI 3.14159265359
//#define gc() getchar_unlocked();
using namespace std;
clock_t start_time,end_time;

inline float ellapse(){ return (clock()-start_time)*1.0/CLOCKS_PER_SEC; }
//inline int read_int() {register char c = gc();while(c<'0' || c>'9') c = gc();int ret = 0; while(c>='0' && c<='9') {ret = 10 * ret + c - 48; c = gc();}return ret;}
long long int gcd( long long int a , long long int b )
{
    return b == 0 ? a : gcd( b , a%b );
}

long long power( long long a , long long b )
{
    long long ret = 1 ;
    while( b ) {
        if( b%2 == 1 ) ret = ( ret * a ) % mod  ;
        a = (a * a) % mod ;
        b /= 2 ;
    }
    return ret ;
}


#define N 100010
int hashe[ N ] ;

int main()
{

    int n , x , ans = 0 ;
    cin >> n ;

    for( int i = 0 ; i < n ; i++ ) {
      cin >> x ;
      hashe[ x + 1 ]++ ;
    }

    for( int i = 1 ; i < N - 1 ; i++ ) ans = max( ans , hashe[ i - 1 ] + hashe[ i ] + hashe[ i + 1 ] ) ;
    cout << ans ;
    return 0 ;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
  static int a, b, c;

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

    a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt();

    int sum = a + b + c;
    if(sum % 2 == 1){
      System.out.println("No");
      return;
    }
    int d = sum / 2;
    if(a == d || b == d || c == d ||
      (a + b) == d || (a + c) == d ||
      (b + c) == d
      ){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 9812
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <random>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define rep(i, j, k) for(int i = j; i <= k; ++ i)
#define per(i, j, k) for(int i = j; i >= k; -- i)
using namespace std;

#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back

typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned uint;
typedef unsigned long long ull;

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

unsigned seed = chrono::system_clock::now().time_since_epoch().count();
mt19937 Rand(seed);
uniform_int_distribution<ll> range(0, 1ll << 32);
inline void ucin() {
   ios::sync_with_stdio(0); cin.tie(0);
}

const int N = 4e5 + 10;
const int mod = 1e9 + 7;

int qpow(int a, int b) {
   int ans = 1;
   for(; b >= 1; b >>= 1, a = (ll) a * a % mod)
      if(b & 1) ans = (ll) ans * a % mod;
   return ans;
}
int n, f[N], c, a2, a3, pw2[N], pw3[N];
char s[N];
int main() {
   scanf("%d%s", &n, s + 1);
   rep(i, 1, n) c += s[i] == '1';
   f[0] = 0;
   rep(i, 1, n + 1) {
      int c = __builtin_popcount(i);
      f[i] = f[i % c] + 1;
   }
   pw2[0] = pw3[0] = 1;
   rep(i, 1, n) {
      if(c - 1 >= 1) {
         a2 = (a2 * 2 + s[i] - '0') % (c - 1);
         pw2[i] = (pw2[i - 1] << 1) % (c - 1);
      }
      if(c + 1 >= 1) {
         a3 = (a3 * 2 + s[i] - '0') % (c + 1);
         pw3[i] = (pw3[i - 1] << 1) % (c + 1);
      }
   }
   rep(i, 1, n) {
      if(s[i] == '1') {
         int p = c - 1;
         if(p == 0) puts("0");
         else {
            printf("%d\n", 1 + f[((a2 - pw2[n - i]) % p + p) % p]);
         }
      } else {
         int p = c + 1;
         if(p == 0) puts("0");
         else {
            printf("%d\n", 1 + f[((a3 + pw3[n - i]) % p + p) % p]);
         }
      }
   }
   return 0;
} 


Measured memory_bytes: 5776
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int n = in.i();
        int[] a = in.ii();
        out.println(Math.min(solve(a, 1), solve(a, -1)));
    }

    static long solve(int[] a, int b) {
        long s = 0;
        long r = 0;
        for (int i = 0; i < a.length; i++) {
            long x = s + a[i];
            if (b * x > 0) {
                s = x;
            } else {
                s = b;
                r += Math.abs(x) + 1;
            }
            b = -b;
        }
        return r;
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
    }
}


Measured memory_bytes: 37824
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力

lists=list(map(int,input().split()))
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

#cがa以上かつb以下
if lists[0]<=lists[2] and lists[1]>=lists[2]:
        print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
N, M = map(int, input().split())

if N % 2 == 1:
    for m in range(1, M + 1):
        print(m, N - m + 1)

count = 1
if N % 2 == 0:
    for m in range(1, M + 1):

        if m <= (N // 2 - 1) // 2:
            start = m
            end = N // 2 - m
            print(start, end)
        else:
            start = N // 2 + count
            end = N - count + 1
            print(start, end)
            count += 1


Measured memory_bytes: 69484