akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int64_t gcd(int64_t u, int64_t v) {
  while (v != 0) {
    int64_t r = u % v;
    u = v;
    v = r;
  }
  return u;
}

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

  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  x -= a[0];
  for (int i = 1; i < n; ++i) {
    a[i] -= a[0];
    if (a[i] < 0)
      a[i] = -a[i];
  }
  a.push_back(x);
  a[0] = 0;
  if (n == 1) {
    cout << abs(a[1]) << "\n";
    return 0;
  } else if (n == 2) {
    cout << abs(gcd(a[1], a[2])) << "\n";
    return 0;
  }

  int64_t ans = gcd(a[1], a[2]);
  for (int i = 3; i < n; ++i) {
    ans = gcd(ans, a[i]);
  }
  cout << ans << "\n";
}


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

int main() {
    int h, w, ans = 0; cin >> h >> w;
    char f[8][8]; rep(i, h) rep(j, w) { cin >> f[i][j]; if (f[i][j] == '#') ans++; }
    if (ans == h + w - 1) { cout << "Possible" << endl; }
    else { cout << "Impossible" << endl; }
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int,input().split()))
b = [(1 + p[i])/2 for i in range(n)]

ttl = sum(b[:k])
res = ttl
for i, v in enumerate(b[k:]):
    ttl += v - b[i]
    res = max(res, ttl)

print("{:.10f}".format(res))

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

using namespace std;
int a[100100];
bool vis[100100];

int main()
{
    int n,k,R,S,P;
    string s;
    cin >> n >> k >> R >> S >> P >> s;
    int Ans = 0;
    for(int i = 0;i<s.size();i++){
        if(s[i] == 'r' && (i - k < 0 || s[i - k] != 'r' || !vis[i - k]))
            Ans+=P , vis[i] = true;
        if(s[i] == 's' && (i - k < 0 || s[i - k] != 's' || !vis[i - k]))
            Ans+=R , vis[i] = true;
        if(s[i] == 'p' && (i - k < 0 || s[i - k] != 'p' || !vis[i - k]))
            Ans+=S , vis[i] = true;
    }
    cout << Ans;
    return 0;
}


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

#define MAXN 200010
#define X first
#define Y second

typedef long long ll;

int N;
int a[MAXN], f[MAXN][19], pos[MAXN];
int lg[MAXN], bin[MAXN];

vector<pair<int, int> > ans;

struct node
{
	int l, r; 
	pair<int, int> v;
	bool operator < (const node &t)const
	{
		return make_pair(a[v.first], a[v.second]) > make_pair(a[t.v.first], a[t.v.second]);	
	} 
};

priority_queue<node> Q;

int GetMin(int l, int r)
{
	int len = (r - l + 2) / 2;
	int k = lg[len];
	if ((r - l + 1) & 1)
		return pos[min(f[l][k], f[r - 2 * (bin[k] - 1)][k])];
	else return pos[min(f[l][k], f[r - 2 * (bin[k] - 1) - 1][k])]; 
}

node F(int l, int r)
{
	int ps1 = GetMin(l, r);
	int ps2 = GetMin(ps1 + 1, r);
	return (node){l, r, make_pair(ps1, ps2)};
}

void Solve(int l, int r)
{
	int ps1 = GetMin(l, r);
	int ps2 = GetMin(ps1 + 1, r);
	Q.push((node){l, r, make_pair(ps1, ps2)});
	pair<int, int> v;
	while (!Q.empty())
	{
		node t = Q.top();
		l = t.l, r = t.r, v = t.v;
		ans.push_back(make_pair(a[v.first], a[v.second]));
		Q.pop();
		if (l < v.first - 1) Q.push(F(l, v.first - 1));
		if (v.first + 1 < v.second - 1) Q.push(F(v.first + 1, v.second - 1));
		if (v.second + 1 <r) Q.push(F(v.second + 1, r));
	}
}

int main()
{
	//freopen("in.in", "r", stdin);
	//freopen("out.out", "w", stdout);
	
	for (int i = 0; i <= 18; ++i)
		bin[i] = 1 << i, lg[bin[i]] = i;
	for (int i = 2; i < MAXN; ++i)
		if (!lg[i]) lg[i] = lg[i - 1];
	
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i)
		scanf("%d", &a[i]), f[i][0] = a[i], pos[a[i]] = i;
	
	for (int j = 1, h = 2; h <= N; ++j, h <<= 1)
		for (int i = 1; i + 2 * (h - 1) <= N; ++i)
			f[i][j] = min(f[i][j - 1], f[i + h][j - 1]);
	Solve(1, N);
	
	for (int i = 0; i < ans.size(); ++i)
	{
		if (i) putchar(' ');
		printf("%d %d", ans[i].first, ans[i].second);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 20212
#include <iostream>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  char A[50][50], B[50][50];
  auto cursor = [](int x){return [&](int &i, int &j){i++; if(i>=x){j+=1; i=0;}};};
  auto nextM = cursor(M), nextNM = cursor(N-M);  
  for(int i=0; i<N; ++i) scanf("%s", &A[i][0]);
  for(int i=0; i<M; ++i) scanf("%s", &B[i][0]);
  bool ok = false;
  for(int Ax=0, Ay=0; !ok && Ay<=N-M; nextNM(Ax, Ay))
  {
    ok = true;
    for(int i = 0, j = 0; j < M; nextM(i, j))
      if(A[Ax+i][Ay+j] != B[i][j])
      {
        ok = false;
        break;
      }
  }
  if(ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

int main(void) {

	string s;
	cin >> s;

	cout << count(s.begin(), s.end(), '+') * 2 - 4 << endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REPR(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define FOR(i, x, n) for (int i = x; i < (int)(n); ++i)
#define ALL(n) begin(n), end(n)
#define ll long long
#define INF 1e9
int main() {
    int n;
    cin >> n;
    vector<int> k(n);
    REP(i, n) cin >> k[i];
    sort(ALL(k));
    reverse(ALL(k));
    ll ans = 0;
    // ans = n * (n - 1) * (n - 2) / 6;
    REP(i, n - 2) {
        FOR(j, i + 1, n - 1) {
            FOR(z, j + 1, n) {
                if (k[i] != k[j] && k[i] != k[z] && k[j] != k[z] &&
                    k[i] < k[j] + k[z])
                    ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int N,M;
  cin >> N >> M;
  vector<vector<int>> G(N+M);
  for(int i=0; i<N; i++){
    int k;
    cin >> k;
    for(int j=0; j<k; j++){
      int a;
      cin >> a;
      a--;
      a += N;
      G[a].push_back(i);
      G[i].push_back(a);
    }
  }
  queue<int> que;
  que.push(0);
  vector<bool> dist(N+M,false);
  while(que.size()){
    int v = que.front();
    que.pop();
    for(auto nv:G[v]){
      if(dist[nv]) continue;
      dist[nv] = true;
      que.push(nv);
    }
  }
  bool can = true;
  for(int i=0; i<N; i++){
    if(!dist[i]) can = false;
  }
  if(can){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 8824
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 1 << 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
G = [[] for _ in range(n)]
for _ in range(m):
    l, r, c = LI()
    G[l - 1] += [(r - 1, c)]


for i in range(n - 1):
    G[i + 1] += [(i, 0)]


def dijkstra(G, s=0):
    hq = [(0, s)]
    dist = [INF] * n
    dist[s] = 0
    checked = [0] * n
    while hq:
        min_dist, u = heappop(hq)
        if checked[u]:
            continue
        checked[u] = 1
        for v, c in G[u]:
            if checked[v]:
                continue
            elif dist[u] + c < dist[v]:
                dist[v] = dist[u] + c
                heappush(hq, (dist[u] + c, v))
    return dist


ans = dijkstra(G)[-1]
if ans == INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 79008
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
using vi = vector<int>;
#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
struct Graph {
  vector<vector<int>> edge;
  Graph(int n = 0) { resize(n); }
  void resize(int n) { edge.resize(n, vector<int>()); }
  void addEdge(int from, int to) { edge[from].push_back(to); }
  vector<int>& operator[](int from) { return edge[from]; }
};

int main() {
  int in(N); int in(M);
  Graph G(N);

  vi input(N, 0);
  rep(i, M) {
    int x, y; cin >> x >> y;
    --x, --y;
    G.addEdge(x, y);
    ++input[y];
  }
  stack<int> st;
  rep(i, N) if (input[i] == 0) st.push(i);

  vi sorted;
  while (!st.empty()) {
    int p = st.top(); st.pop();
    sorted.push_back(p);
    for (int to:G[p])
      if (--input[to] == 0)
        st.push(to);
  }

  vi dp(N, 0);
  rep(i, N) {
    int from = sorted[i];
    for (int to:G[from])
      dp[to] = max(dp[to], dp[from] + 1);
  }
  int ans = 0;
  rep(i, N) ans = max(ans, dp[i]);

  cout << ans << endl;

  return 0;
}


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

int main()
{
    double a,b;

    scanf("%lf%lf",&a,&b);

    if(a>=1 && a<=100 && b>=1 && b<=100){
        printf("%.10lf\n",a/b);
    }

    return 0;
}


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

bool issqaure(int n){
    int s = sqrt(n);
    return ((s * s) == n);
}
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++){
      cin >> a[i];
  }
  int ans = 0;
  for(int i = 1; i < n - 1; i++){
      int mi = min({a[i-1], a[i], a[i+1]});
      int ma = max({a[i-1], a[i], a[i+1]});
      if(a[i] > mi && a[i] < ma){
          ans++;
      }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
//#define int long long

struct Point {
	int x, y;

	double dis(Point a, Point b) {
		return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y) * (a.y - b.y));
	}
};



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

	int K, S;
	int cnt = 0;
	cin >> K >> S;

	for (int i = 0; i <= K; i++)
	{
		for (int j = 0; j <= K; j++)
		{
			int J = S - (i + j);
			if (J >= 0 && J <= K) {
				cnt++;
			}
		}
	}
	
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
int fibonacci(int *, int);

int main(){
  int f[45];
  int n, i;

  scanf("%d", &n);
  for(i = 0; i < 45; i++) f[i] = 0;
  printf("%d\n",fibonacci(f, n));

  return 0;
}

int fibonacci(int *f, int n){
  
  if(n == 0 || n == 1){
    return f[n] = 1;
  }
  else if(f[n] != 0) return f[n];
  else return f[n] = fibonacci(f, n - 2) + fibonacci(f, n - 1);
}

Measured memory_bytes: 596
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<string>
#include<cmath>
#include<cassert>
#include<cstdint>
#include<map>
using namespace std;

typedef int64_t i64;typedef int32_t i32;
typedef int16_t i16;typedef int8_t i8;
typedef uint64_t ui64;typedef uint32_t ui32;
typedef uint16_t ui16;typedef uint8_t ui8;

typedef i64 int__;
#define rep(i,j) for(int__ i=0;i<j;i++)
#define repeat(i,j,k) for(int__ i=(j);i<(k);i++)
#define all(v) begin(v),end(v)

const i32 INF=1<<30;//10E10

vector<int> isprime;

//n??\???????´???°??????
void primefactorize(i64 n){
  isprime.resize(n+1,1);
  isprime[0]=isprime[1]=0;
  rep(i,n+1){
    if(isprime[i]==0)continue;
    i64 j=2;
    while(i*j<=n)isprime[i*j++]=0;
  }
}

int main()
{
  primefactorize(123456*2+1);
  repeat(i,1,isprime.size())isprime[i]+=isprime[i-1];

  while(true){
    i64 n;
    cin>>n;
    if(n==0)break;
    cout<<isprime[2*n]-isprime[n]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 2056
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std; 
int main()
{
double a,b,c,d,e,f;
while(cin>>a>>b>>c>>d>>e>>f)
{
printf("%.3f %.3f\n", (b*f - c*e)/(b*d - a*e) + 0.0001, (a*f - c*d)/(a*e - b*d) + 0.0001);
}
return 0;
}

Measured memory_bytes: 1240
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
using namespace std;
int main()
{
	int n, h[100],i,j;
	bool f = false;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> h[i];
	}
	for (i = 0;; i++,f=0) {
		for (j = 0; j < n; j++) {
			if (h[j]) {
				h[j]--;
				f = 1;
			}
			else if(f)
				break;
		}
		if (j == n && !f) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int N = 3000;
double dp[N][N],p[N];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++) cin>>p[i+1];
		dp[0][0]=1;
	for(ll i=0;i<=n;i++)
	{
		for(ll j=0;j<=i;j++)
		{
			if(i==0 and j==0)
				dp[i][j]=1;
			else if(!i)
				dp[i][j]=0;
			else if(!j)
				dp[i][j]=dp[i-1][j]*(1-p[i]);
			else
				dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i]);
		}
	}
	double ans =0;
	for(ll i=n/2+1;i<=n;i++)
		ans+=dp[n][i];
	printf("%.10lf\n",ans);
	return 0;
}


Measured memory_bytes: 68992
#include <iostream>
#include <climits>
#define INF 100000000
using namespace std;
int main(){
    int N,A,B;
    cin >> N >> A >> B;
    string s;
    cin >> s;

    int countALL = 1, countB = 1;
    for(int i=0;i<s.size();i++){
        if(s[i]=='a'){
            if(countALL <= A+B){
                cout << "Yes" << endl;
                countALL++;
            }else{
                cout << "No" << endl;
            }
        }else if(s[i]=='b'){
            if(countALL <= A+B && countB <= B){
                cout << "Yes" << endl;
                countALL++;
                countB++;
            }else{
                cout << "No" << endl;
            }
        }else{
            cout << "No" << endl;
        }
    }
}

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

/*
任意の頂点について、
・その頂点と繋がっている全ての頂点について、それぞれ色が異なる
*/

ll p[100010];
//p[i]=nPi= n* (n-1) * (n-2) * ... * (n-i+1)
void cal(ll x){
    rep(i,100010){
        p[i]=0;
    }
    ll tmp=1;
    p[0]=1;
    for(ll i = 1; i<=x; i++){
        tmp = (tmp * (x-i+1)) % MOD;
        p[i]=tmp;
    }
}

void solve(){
    ll n,k;
    cin >> n >> k;
    vector<ll> ch[n+10];
    ll chn[n+10];
    rep(i,n+10){
        chn[i]=0;
    }
    vector<ll> pa[n+10];
    rep(i,n-1){
        ll a,b;
        cin >> a >> b;
        ch[a].emplace_back(b);
        chn[a]++;     
        ch[b].emplace_back(a);
        chn[b]++;
    }
    rep(i,n+10){
        chn[i]--;
    }
    ll ans=k; //親に塗る
    cal(k-1);
    chn[1]++;
    ans = (ans * p[chn[1]])%MOD;

    /*
    rep(i,n){
        cout << chn[i+1] << endl; 
    }
    */
    /*
    rep(i,k){
        cout << p[i] << endl;
    }
    */
    
    

    cal(k-2);
    stack<ll> st;
    st.push(1);
    bool visited[n+10];
    rep(i,n+1){
        visited[i]=false;
    }
    visited[1]=true;
    while(!st.empty()){
        ll tmp = st.top();
        st.pop();
        for(ll i:ch[tmp]){
            if(!visited[i]){
                //cout << i << " " << chn[i] << endl;
                //cout << i << " " << ans << " " << p[chn[i]] << endl;
                ans = (ans * p[chn[i]])%MOD;
                st.push(i);
                visited[i]=true;
            }
        }
    }

    cout << ans << endl;

}

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

Measured memory_bytes: 11380
#include <bits/stdc++.h>
using namespace std;
int A[110];
int main(){
    int n;
    scanf("%d",&n);
    for(int i = 0; i < 2*n; i++) scanf("%d",&A[i]);
    sort(A,A+2*n);
    int res = 0;
    for(int i = 0; i < 2*n; i+=2){
        res += A[i];
    }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#define mod 1000000007
typedef long long ll;
using namespace std;

map<int,int> mp;
void primeFactorize(int n){
    if(n%2==0){
        while(n%2==0){
            mp[2]++;
            n = n / 2;
        }
    }
    for(ll i=3;i*i<=n;i+=2){
        while(n%i==0){
            mp[i]++;
            n = n / i;
        }
    }
    if(n!=1) mp[n]++; 
}

int main(){
  int N; cin >> N;
  for(int i=N;i>=1;i--) primeFactorize(i);
  ll ans = 1;
  for(auto c:mp) ans = ans * (c.second + 1) % mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

vector<int> cul_day(vector<int> cs,vector<int> ss,vector<int> t, int nd){
	vector<int> lasts(26,nd);
	rep(i, nd){
		lasts[t[i]]=nd-i-1;
	}
	rep(i,26){
		cout << lasts[i] << " ";
		ss[i] -= cs[i]*(1+lasts[i]);
	}
	cout << endl;
	return ss;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);
  int n;
  cin >> n;
  int c0=0, c1=0, c2=0, c3=0;
  rep(i, n){
	  string s;
	  cin >> s;
	  if(s == "AC"){
		  c0++;
	  }else if(s == "WA"){
		  c1++;
	  }else if(s == "TLE"){
		  c2++;
	  }else{
		  c3++;
	  }
  }
  cout << "AC x " << c0 << endl;
  cout << "WA x " << c1 << endl;
  cout << "TLE x " << c2 << endl;
  cout << "RE x " << c3 << endl;
  return 0;
}


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

#define f first
#define s second
#define ll long long
#define pb push_back
#define mp make_pair
#define inp(x) cin>>x
#define print(x) cout<<x
#define pii pair<int,int>
#define pll pair<ll,ll>
#define gcd(a,b) __gcd(a,b)
#define reset(d,val) memset(d,val,sizeof(d))
#define sort(v) sort(v.begin(),v.end())
#define sort_arr(arr,i,f) sort(arr+i,arr+f)
#define pq priority_queue<int,vector<int>,greater<int> >
#define pq1 priority_queue<pll,vector<pll>,greater<pll> >

const int mod = 1e9+7;

int dp[3002][3002];

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t;
	cin>>s>>t;
	int n = s.length(),m = t.length();
	for (int i = 0; i < n; ++i)
	{
		for(int j=0;j<m;j++){
			if(s[i]==t[j]) {
				dp[i+1][j+1] = 1+dp[i][j];
			}
			else {
				dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
			}
		}
	}
	int i = n,j=m;
	string s1 = "";
	while(i>0 && j>0) {
		if(s[i-1]==t[j-1]) {
			s1 += s[i-1];
			i--,j--;
		}
		else if(dp[i][j]==dp[i-1][j]) {
			//s1 += s[i-1];
			i--;
		}
		else j--;
	}
	reverse(s1.begin(),s1.end());
	cout<<s1;
	return 0;
}


Measured memory_bytes: 35456
#include<bits/stdc++.h>
#define lson l, mid, i<<1
#define rson mid+1, r, i<<1|1
#define PII pair<int, int>
#define Size(x) (int)(x.size())
using namespace std;
typedef long long LL;
const int MOD = 1e9+7;
const auto INF = 0x3f3f3f3f;
const int N = 2e5+5;

int a[N];
int b[N];

int main() {
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
        scanf("%d", &a[i]);
    int m;
    scanf("%d", &m);
    for(int i=1; i<=m; i++)
        scanf("%d", &b[i]);
    sort(a+1, a+1+n);
    sort(b+1, b+1+m);
    int j = 1, i;
    for(i=1; i<=m && j <= n; i++) {
        while(j <= n && a[j] != b[i])
            j++;
        if(j > n)
            break;
        j++;
    }
    if(i == m+1)
        printf("YES\n");
    else
        printf("NO\n");
}





Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

vector<i64> strongly_connected_components(const vector<vector<i64>>& g) {
  i64 n = g.size();
  vector<vector<i64>> rg(n);
  for(int i = 0;i < n;i++) {
    for(auto j: g[i]) {
      rg[j].push_back(i);
    }
  }

  vector<bool> vis(n,false);
  vector<i64> vs;
  vector<i64> res(n,-1);
  function<void(int)> dfs = [&](int v) {
    vis[v] = true;
    for(auto& t : g[v]) {
      if(!vis[t]) dfs(t);
    }
    vs.push_back(v);
  };

  function<void(int,int)> rdfs = [&](int v,int k) {
    vis[v] = true;
    res[v] = k;
    for(auto to : rg[v]) {
      if(!vis[to]) rdfs(to,k);
    }
  };

  for(int i = 0;i < n;i++) {
    if(!vis[i]) dfs(i);
  }

  vis.assign(n,false);
  int k = 0;
  for(int i = n - 1;i >= 0;i--) {
    if(!vis[vs[i]]) rdfs(vs[i] , k++);
  }
  return res;
}

int main() {
  i64 N;
  cin >> N;
  vector<i64> A(N), B(N);
  rep(i,0,N) {
    cin >> A[i];
  }
  rep(i,0,N)  {
    cin >> B[i];
  }
  vector<i64> idx(N);
  iota(all(idx), 0);
  sort(all(idx), [&](i64 i, i64 j) { return B[i] < B[j]; });
  {
    auto a = A;
    auto b = B;
    rep(i,0,N) {
      A[i] = a[idx[i]];
      B[i] = b[idx[i]];
    }
  }
  iota(all(idx), 0);
  sort(all(idx), [&](i64 i, i64 j) { return A[i] < A[j]; });

  vector<vector<i64>> G(N);
  rep(i,0,N) {
    if(A[idx[i]] > B[i]) {
      cout << "No" << endl;
      return 0;
    }
    G[idx[i]].push_back(i);
  }
  auto ans = strongly_connected_components(G);
  std::set<i64> st;
  for(auto x: ans) st.insert(x);
  if(st.size() > 1) {
    cout << "Yes" << endl;
    return 0;
  }
  rep(i,0,N - 1) {
    if(A[idx[i + 1]] <= B[i]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 22248
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        h: usize, w: usize,
        s: [Chars; h]
    }

    let mut visited = vec![vec![false; w]; h];
    let mut ans = 0usize;
    for y in 0..h {
        for x in 0..w {
            if visited[y][x] {
                continue;
            }
            let mut black = 0;
            let mut white = 0;
            let mut que = Vec::new();
            que.push((x, y));
            visited[y][x] = true;
            while let Some((x1, y1)) = que.pop() {
                if s[y1][x1] == '#' {
                    black += 1;
                } else {
                    white += 1;
                }
                let d = [(0, 1), (1, 0), (-1, 0), (0, -1)];
                for &(dx, dy) in &d {
                    let x2 = clamp(x1 as isize + dx, 0, w as isize - 1) as usize;
                    let y2 = clamp(y1 as isize + dy, 0, h as isize - 1) as usize;
                    if visited[y2][x2] || s[y1][x1] == s[y2][x2] {
                        continue;
                    }
                    visited[y2][x2] = true;
                    que.push((x2, y2));
                }
            }
            ans += black * white;
        }
    }
    println!("{}", ans);
}


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

using namespace std;

int main(){
    string s;
    cin >> s;
    bool flag = true;
    for (int i = 0; i < s.size(); i++){
        if (i % 2 == 0 && s[i] == 'L'){
            flag = false;
        } else if (i % 2 != 0 && s[i] == 'R'){
            flag = false;
        }
    }
    if (flag) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
class in{struct myIterator{int it;const bool rev;explicit constexpr myIterator(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(myIterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const myIterator i,n;public:explicit constexpr in(int n):i(0),n(n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const myIterator& begin(){return i;}const myIterator& end(){return n;}};

#include <bits/stdc++.h>
using namespace std;

bool topologicalSort(const vector<vector<int>>& adj, vector<int>& ord) {
    int N = adj.size();
    vector<int> deg(N);//??\?¬???°
    for(int i = 0; i < N; ++i)
      for(int nv : adj[i])
        ++deg[nv];
    ord.assign(N, -1);
    int t = 0;

    bool isOnly = true;
    for(int v = 0; v < N; ++v) 
      if(deg[v] == 0)
        ord[t++] = v;
    isOnly &= t == 1;
    for(int h = 0; h < t; ++h) {
        int v = ord[h];
        int upd = 0;
        for(int nv : adj[v]) {
            --deg[nv];
            if(deg[nv] == 0)
              ord[t++] = nv, ++upd;
        }
        isOnly &= upd < 2;
    }
    return isOnly;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> adj(n);
    for(int _ : in(m)) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        adj[u].emplace_back(v);
    }
    vector<int> ord;
    bool only = topologicalSort(adj, ord);
    for(int x : ord) cout << x + 1 << endl;
    cout << !only << endl;
    return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
const int maxn=1e6+10;
ll a[2005];
ll s[2005];
const int mod=1e9+7;
int main() {
	int n;
	cin>>n;
	a[0]=0;a[1]=0;a[2]=0;
	s[0]=0;s[1]=0;s[2]=0;
	for(int i=3;i<=n;i++) {
		a[i]=(s[i-3]+1)%mod;
		s[i]=s[i-1]+a[i];
		s[i]=s[i]%mod;
	}
	cout<<a[n]<<endl;
}

Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#include<functional>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.20f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define cotu cout
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b){if(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,k; cin >> n >> k;
    ll a[200100];
    reps(i,1,n) cin >> a[i];

    map<ll,ll> mp;
    
    ll now = 1;
    ll cnt = 0;
    while(mp.count(now) == 0){
        mp[now] = cnt;
        cnt++;
        now = a[now];
    }
    ll start = mp[now];
    ll T = cnt - start;

    ll ans = 1;
    if(k <= start){
      rep(i,0,k) ans = a[ans];
      cout << ans << endl;
        return 0;
    }

    rep(i,0,start) ans = a[ans];
    k -= start;
    k %= T;
    rep(i,0,k) ans = a[ans];

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

Measured memory_bytes: 17508
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


N, A, B = LI()
ans = 0
for i in range(1, int(N)+1):
    si = str(i)
    sum = 0
    for sii in si:
        sum += int(sii)
    if A <= sum <= B:
        ans += i
print(ans)


Measured memory_bytes: 39920
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N, C;
    cin >> N >> C;
    int D[31][31];
    for(int i=1; i<=C; i++){
        for(int j=1; j<=C; j++){
            cin >> D[i][j];
        }
    }
    vector<int> c0(C+1), c1(C+1), c2(C+1);
    int c;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            cin >> c;
            if((i+j)%3==0){
                c0[c]++;
            }else if((i+j)%3==1){
                c1[c]++;
            }else{
                c2[c]++;
            }
        }
    }
    long long ans=10e9;
    for(int i=1; i<=C; i++){
        for(int j=i+1; j<=C; j++){
            for(int k=j+1; k<=C; k++){
                vector<int> v;
                v.push_back(i);
                v.push_back(j);
                v.push_back(k);
                sort(v.begin(), v.end());
                do {
                        long long cost=0;
                    for(int l=1; l<=C; l++){
                        cost +=c0[l] * D[l][v[0]];
                        cost +=c1[l] * D[l][v[1]];
                        cost +=c2[l] * D[l][v[2]];
                    }
                        ans = min(cost, ans);
                    // for(int i = 0; i < 3; i++) {
                    // cout << v[i];
                    // if(i + 1 == 3) cout << endl;
                    // else cout << ' ';
                    // }
                } while(next_permutation(v.begin(), v.end()));
            }
        }
    }
    cout << ans << endl;


    // for(int i=0; i<c0.size(); i++){
    //     cout << c0[i] << endl;
    // }

    // for(int i=0; i<c1.size(); i++){
    //     cout << c1[i] << endl;
    // }

    // for(int i=0; i<c2.size(); i++){
    //     cout << c2[i] << endl;
    // }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
    long long int n, m, d;

    cin >> n >> m >> d;

    double ans = (double)(n-d) / n;
    ans *= (m-1);
    ans /= n;

    if (d != 0) ans *= 2;

    printf("%.25f\n", ans);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n,w; cin>>n>>w;
	ll wa[n],va[n];
	for(int i=0;i<n;i++) cin>>wa[i]>>va[i];
	ll dp[n+1][w+1];
	memset(dp,0,sizeof dp);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=w;j++){
			if(j>=wa[i-1]){
				dp[i][j]=max(dp[i-1][j-wa[i-1]]+va[i-1],dp[i-1][j]);
			}else{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 79104
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <math.h>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#pragma GCC optimize ("-O3")
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
#define tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define ll long long int
ll max(ll a, ll b) {  return a > b ? a : b; }
ll gcd(ll a, ll b) { if (a == 0) return b; return b == 0 ? a : gcd(b, a % b);}
#define case(i) cout<<"Case #"<<i<<": ";
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) { cerr << "[ " << *it << " = " << a << " ]"; err(++it, args...); }
#define pii pair <ll , ll >
#define pb push_back
#define PRECISION 10
const ll inf = 1e16;
const int MAXN = 100001;
const int LOGN = 22;
const int MAXBIT = 61;
const int DIGITSIZE = 19;
ll mod = 1e9 + 7;
ll MOD = 998244353;
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
bool take_test_cases = false;
bool print_case_no = false;

void getac(int T) {
    string s;
    cin>>s;
    if(s[1]=='R'){
        s[1]='B';
    }
    else{
        s[1]='R';
    }
    cout<<s;
}
int  main()
{

    fastio;
    int t = 1;
    if (take_test_cases) cin >> t;
    int t_t = 1;
    while (t--) {
        if (print_case_no)
        case (t_t);
        getac(t_t);
        t_t++;
    }
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
 
 int mod=1000000007;
void solve()
{
   long long int n,k;
   cin >> n >> k;
   long long total=0;
   for (;k<=n+1;k++)
    {
        long long l_sum=((k-1)*(k))/2;
        long long r_sum=((n*(n+1))/2-((n-k)*(n-k+1))/2);
        total+=r_sum-l_sum+1;
        total%=mod;
        
    }
    cout << total << endl;
 
}
int main()
{
    fast_io;
    int t;
    //cin >> t;
t=1;
    for (int tt=1;tt<=t;tt++)
    {
        solve();
        
 
    }
 
    
    return 0;
}
 


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

int main(){
  int N;
  cin >> N;
  vector<int64_t>a(N);
  vector<int64_t>b(N);
  for(int i=0;i<N;i++)
    cin >> a.at(i) >> b.at(i);
  int64_t ans=0;
  for(int i=N-1;i>=0;i--){
    if((a.at(i)+ans)%b.at(i)!=0)
      ans+=b.at(i)-(a.at(i)+ans)%b.at(i);
    //cout << ans << endl;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4844
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;

//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#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 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

using namespace std;
int main(void){

    string s;
    cin >> s;
    ll ans = 0;
    ll c = 0;
    for(ll i=0;i<(ll)s.length();i++){
      if( s[i] == 'W'){
        ans += i-c;
        c++;
      }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3764
n, m = gets.split.map(&:to_i)

graph = Hash.new { |h, k| h[k] = [] }

m.times do
  a, b = gets.split.map(&:to_i)
  graph[a].push(b)
  graph[b].push(a)
end

dist = Array.new(n + 1, -1)
dist[1] = 0

que = []
que.push(1)

puts "Yes"
ans = Array.new(n - 2, -1)

until que.empty?
  v = que.shift

  graph[v].each do |nv|
    next if dist[nv] != -1

    dist[nv] = dist[v] + 1
    que.push(nv)
    ans[nv - 2] = v
  end
end

puts ans


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

using namespace std;

const int H = 1000 + 7;

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef pair<ll,ll> pll;

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  --a; --b; --c; --d;
  string s;
  cin >> s;

  int p = b - 1;
  bool dots = false;
  while(p + 2 <= d) {
    //cout << s[p] << s[p + 1] << s[p + 2] << endl;
    if(s[p] == '.' && s[p + 1] == '.' && s[p + 2] == '.') {
      dots = true;
    }
    ++p;
  }

  bool stat = true;
  while(b < d) {
    //cout << b << " ";
    if(b + 1 < n && s[b + 1] == '.') ++b;
    else if(b + 2 < n && s[b + 2] == '.') b += 2;
    else {
      stat = false;
      break;
    }
    //cout << b << endl;
  }
  if(b == d) s[b] = '#';
  while(a < c) {
    if(a + 1 < n && s[a + 1] == '.') ++a;
    else if(a + 2 < n && s[a + 2] == '.') a += 2;
    else {
      stat = false;
      break;
    }
  }
  if((stat && a == c && b == d) || dots) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}
/*
 && ((i > 0 && s[i - 1][j] == '#') || (i < h - 1 && s[i + 1][j] == '#') || (j > 0 && s[i][j - 1] == '#') || (j < w - 1 && s[i][j + 1] == '#'))
*/


Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<double,P> PP;
struct edge { int to; int cost; };
string ans[] = { "NA","MMYY","YYMM","AMBIGUOUS" };
signed main() {
	string s; cin >> s;
	int a = (s[0] - '0') * 10 + (s[1] - '0');
	int b = (s[2] - '0') * 10 + (s[3] - '0');
	int flg = 0;
	if (1 <= a&&a <= 12)flg++;
	if (1 <= b&&b <= 12)flg += 2;
	cout << ans[flg] << endl;
}

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

int main()
{
  int ndays, nwork, interval;
  cin >> ndays >> nwork >> interval;
  string s;
  cin >> s;
  vector<int> max_works(s.size());
  int works = 0;
  int last = INT_MAX;
  for (int i = s.size()-1; 0 <= i; i--) {
    max_works.at(i) = works;
    if (s.at(i) == 'o' && interval < last - i) {
      works++;
      last = i;
    }
  }

  works = 0;
  last = -1e9;
  vector<int> res;
  for (int i = 0; i < ndays; i++) {
    if (s.at(i) == 'x') {
      continue;
    }
    if (works + max_works.at(i) < nwork) {
      res.push_back(i+1);
    }
    if (interval < i - last) {
      works++;
      last = i;
    }
  }
  for (auto x : res) {
    cout << x << '\n';
  }
  return 0;
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)

int mp[1000009];
int main()
{
    LL n;
    cin>>n;
    for(LL i=1; i*i<=n; i++)
    {
        for(LL j=2*i; j<=n; j+=i)
        {
            if(i*i==j)
                mp[j]++;
            else if(i<=j/i)
                mp[j]+=2;
        }
    }
//for(int i=1;i<=n;i++)
//    cout<<mp[i]<<endl;
    LL ans=0;
    for(LL i=1; i<n; i++)
    {
        ans+=mp[i];
    }
    cout<<ans+1;
}


Measured memory_bytes: 7464
s = input()
n = len(s)
v = [0]*(n+1)

for i in range(n):
  if s[i] == "<":
    v[i+1] = v[i] + 1

for j in range(n):
  if s[-j-1] == ">":
    if v[-j-2] <= v[-j-1]:
      v[-j-2] = v[-j-1] + 1

print(sum(v))

Measured memory_bytes: 23376
import java.io.*;
import java.util.*;

class Solver {
  public int gcd(int a, int b) {
    return a % b == 0 ? b : gcd(b, a%b);
  }
  
  public long solve(int n, int m, char[] s, char[] t) {
    int g = gcd(n, m);
    long lcm = (long)n * (long)m / g;
    HashMap<Long, Character> map = new HashMap<>();
    for (int i = 0; i < n; i++) {
      map.put(i * lcm / n, s[i]);
    }
    for (int j = 0; j < m; j++) {
      long index = j * lcm / m;
      Character c = map.get(index);
      if (c != null && c != t[j]) {
        return -1;
      }
    }
    return lcm;
  }
}

public class Main {
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int m = reader.nextInt();
    char[] s = reader.next().toCharArray();
    char[] t = reader.next().toCharArray();
    out.println(new Solver().solve(n, m, s, t));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public int[] nextIntArray(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLongArray(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
}

class Algorithm {
  private static void swap(Object[] list, int a, int b) {
    Object tmp = list[a];
    list[a] = list[b];
    list[b] = tmp;
  }
  
  public static <T extends Comparable<? super T>> boolean nextPermutation(T[] ts) {
    int rightMostAscendingOrderIndex = ts.length - 2;
    while (rightMostAscendingOrderIndex >= 0 &&
        ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostAscendingOrderIndex + 1]) >= 0) {
      rightMostAscendingOrderIndex--;
    }
    if (rightMostAscendingOrderIndex < 0) {
      return false;
    }
    
    int rightMostGreatorIndex = ts.length - 1;
    while (ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostGreatorIndex]) >= 0) {
      rightMostGreatorIndex--;
    }
    
    swap(ts, rightMostAscendingOrderIndex, rightMostGreatorIndex);
    for (int i = 0; i < (ts.length - rightMostAscendingOrderIndex - 1) / 2; i++) {
      swap(ts, rightMostAscendingOrderIndex + 1 + i, ts.length - 1 - i);
    }
    return true;
  }
}



Measured memory_bytes: 31572
#include<iostream>
using namespace std;
int main(){
	string w;
	cin >> w;
	char c[26]={};
	for(int i=0;i<w.size();i++){
		c[w[i]-'a']++;
	}
	bool ans=true;
	for(int i=0;i<26;i++){
		if(c[i]%2) ans=false;
	}
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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


int main() {
  string S; cin >> S;
  
  string s = "";
  int ans = 0;
  int now = 0;
  
  rep(i, S.size()) {
    string ss = S.substr(now, i-now+1);
    if(s != ss) {
      s = ss;
      ans++;
      now = i+1;
    }
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 640