akhauriyash/Code-Regression huggingface dataset:
// マップやその他の非常に複雑なタプルは使用しないでください。そして、文字列
// で遊ぶとき、それを整数配列に変換します。それは不思議です。パニックになら
// ないでください。それに慣れているときは常に競争をしてください。評価が下がっ
// たときに強調しないでください、それは起こります。だから、冷静ですが重要なコード:)
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(lld i = 0; i < n; i+=1)
#define fod(i,n) for(lld i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
      FastIO
      lld n;
      cin >> n;
      lld A[4];
      memset(A, 0, sizeof(A));
      for(lld i = 0; i < n; i += 1){
      	string s;
      	cin >> s;
      	if (s == "AC") A[0]++;
      	if (s == "WA") A[1]++;
      	if (s == "TLE")A[2]++;
      	if (s == "RE") A[3]++;
      }
      cout << "AC x " << A[0] << "\n";
      cout << "WA x " << A[1] << "\n";
      cout << "TLE x " << A[2] << "\n";
      cout << "RE x " << A[3] << "\n";
      return 0;
}

Measured memory_bytes: 3608
s = input()
k = int(input())

if k == 1:
    print(s[0])
else:
    count = 0
    for i, v in enumerate(s, 1):
        if v == '1':
            count += 1
        else:
            tmp = v
            break

    if count >= k or count ==len(s) :
        print(1)
    else:
        print(tmp)

Measured memory_bytes: 9048
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

constexpr int Nmax = 102;
int N;
int va[Nmax], vi[Nmax], ti[Nmax];

lint dist(lint va, lint vi, lint vb, lint t) // 本来の4倍を出力
{
    lint vmax_2 = va + vb + t; // 本来の2倍
    if (vmax_2 > vi * 2) return vi * t * 4 - 2 * (vi - va) * (vi - va) - 2 * (vi - vb) * (vi - vb); // 本来の4倍
    lint t__2 = vmax_2 - va * 2; // 本来の2倍
    return ((va * 2 + vmax_2) * t__2 + (vb * 2 + vmax_2) * (t * 2 - t__2)) / 2; // 本来の4倍
}

int main()
{
    scanf("%d", &N);
    va[0] = va[N + 1] = vi[0] = vi[N + 1] = ti[0] = ti[N + 1] = 0;
    REP(i, N) scanf("%d", &ti[i + 1]);
    REP(i, N) scanf("%d", &vi[i + 1]);

    FOR(i, 1, N + 1) va[i] = min(min(vi[i], vi[i - 1]), va[i - 1] + ti[i - 1]);
    IFOR(i, 1, N + 1) va[i] = min(va[i], va[i + 1] + ti[i]);
    lint ans = 0;
    FOR(i, 1, N + 1) ans += dist(va[i], vi[i], va[i + 1], ti[i]);
    cout << setprecision(20) << ans / 4.0 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 1000000000000000000

int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<int>> a(H,vector<int>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>a.at(i).at(j);
    }
  }

  int i=0;
  int flow=0;
  vector<pair<int,int>> before,after;
  while(i<H){
    if(flow==0){
      for(int j=0;j<W;j++){
        if(a.at(i).at(j)%2==1){
          before.push_back(make_pair(i,j));
          if(j==W-1){
            if(i!=H-1){
              after.push_back(make_pair(i+1,j));
              a.at(i).at(j)--;
              a.at(i+1).at(j)++;
            }
          }else{
            after.push_back(make_pair(i,j+1));
            a.at(i).at(j)--;
            a.at(i).at(j+1)++;
          }
        }
      }
      flow=1;
    }else{
      for(int j=W-1;j>=0;j--){
        if(a.at(i).at(j)%2==1){
          before.push_back(make_pair(i,j));
          if(j==0){
            if(i!=H-1){
              after.push_back(make_pair(i+1,j));
              a.at(i+1).at(j)++;
            }
          }else{
            after.push_back(make_pair(i,j-1));
            a.at(i).at(j-1)++;
          }
        }
      }
      flow=0;
    }
    i++;
  }

  int N=after.size();
  cout<<N<<endl;
  for(int i=0;i<N;i++){
    cout<<before.at(i).first+1<<" "<<before.at(i).second+1<<" "<<after.at(i).first+1<<" "<<after.at(i).second+1<<endl;
  }
}


Measured memory_bytes: 5228
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define trace1(x)                  cerr<<#x<<": "<<x<<endl
#define trace2(x, y)               cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
int main() 
{
	ll k,n; 
	cin>>k>>n; 
	if(k*500>=n)
	cout<<"Yes";
	else 
		cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b) {ll res = 1; a = a % mod; while (b) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b /= 2;} return res;}
ll invmod(ll a) {return power(a, mod - 2);}
int main(void)
{
	FIO
	int t = 1;
	// cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		int arr[n];
		for (int &i : arr)cin >> i;
		int ans = 0;
		int sum = arr[n - 1];
		for (int i = n - 2; i >= 0; i--) {
			ans += arr[i] * sum;
			sum += arr[i];
		}
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 3640
class UnionFindTree
	#シンプルシンプルなUnionFind
	attr_accessor :nodes
	def initialize(size)
		@nodes = Array.new(size)
		size.times do |i|
			@nodes[i] = -1
		end
		nodes = @nodes
	end
 
	def findParent(x)
		if @nodes[x] < 0 then 
			return x
		else
			return findParent(@nodes[x])
		end
	end
 
	def unite(x, y)
		xx = findParent(x)
		yy = findParent(y)
		return if xx == yy
 
		xx, yy = yy, xx if @nodes[xx] > @nodes[yy]
 
		@nodes[xx] += @nodes[yy]
		@nodes[yy] = xx
	end
 
	def same(x, y)
		return findParent(x) == findParent(y)
	end
end



n, m = gets.chomp.split.map(&:to_i)
arr = Array.new(n, -1)
cnt = 0
uft = UnionFindTree.new(n)
m.times do 
	a, b = gets.chomp.split.map{|c| c.to_i - 1}
	uft.unite(a, b)
end

hash = {}
n.times do |i|
	parent = uft.findParent(i)
	if hash.has_key?(parent)
		hash[parent] += 1
	else
		hash[parent] = 1
	end
end

puts hash.max{|(a,b), (c,d)| b<=>d}[1]




Measured memory_bytes: 26824
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        for(int price = b * 10; price < (b + 1) * 10; price++){
            if(price * 8 / 100 == a && price * 10 / 100 == b){
                System.out.println(price);
                return;
            }
        }
        System.out.println(-1);
    }
}

Measured memory_bytes: 35716
#include <stdio.h>
#include <iostream>

using namespace std;

#define SIZE 1000

class point
{
public:
	int n;
	int d[SIZE * 2 + 1];
	int minw;
};

#define SIZE2 (200000 / SIZE + 10)

point m[SIZE2];

int p[200000];

int N;

void atu()
{
	int now = 0;
	for(int i = 0; i < SIZE2; i++)
	{
		for(int ii = 0; ii < m[i].n; ii++)
		{
			p[now] = m[i].d[ii];
			now++;
		}
	}
}

int getm(int x,int a,int b)
{
	int w = 2000000000;
	for(int i = a; i <= b; i++)
	{
		w = min(w,m[x].d[i]);
	}
	return w;
}

void bun()
{
	for(int i = 0; i < SIZE2; i++)
	{
		m[i].n = 0;
	}
	int now = 0;
	for(int i = 0; i < SIZE2; i++)
	{
		for(int ii = 0; ii < SIZE; ii++)
		{
			if(now >= N)
			{
				m[i].n = ii;
				goto aa;
			}
			m[i].d[ii] = p[now];
			now++;
			m[i].n++;
		}
	}
aa:
	for(int i = 0; i < SIZE2; i++)
	{
		m[i].minw = getm(i,0,m[i].n - 1);
	}
}

pair<int,int> findw(int a)
{
	int now = 0;
	for(int i = 0; i < SIZE2; i++)
	{
		if(now + m[i].n > a)
		{
			return make_pair(i,a - now);
		}
		now += m[i].n;
	}
}

void insert(int a,int x)
{
	pair<int,int> w = findw(a);
	for(int i = m[w.first].n; i > w.second; i--)
	{
		m[w.first].d[i] = m[w.first].d[i - 1];
	}
	m[w.first].d[w.second] = x;
	m[w.first].n++;
	if(m[w.first].n > SIZE * 2 + 1)
	{
		atu();
		bun();
	}
	else
	{
		m[w.first].minw = getm(w.first,0,m[w.first].n - 1);
	}
}

int erase(int a)
{
	pair<int,int> ww = findw(a);
	int w = m[ww.first].d[ww.second];
	for(int i = ww.second; i < m[ww.first].n - 1; i++)
	{
		m[ww.first].d[i] = m[ww.first].d[i + 1];
	}
	m[ww.first].n--;
	m[ww.first].minw = getm(ww.first,0,m[ww.first].n - 1);
	return w;
}

void shift(int a,int b)
{
	int w = erase(b);
	insert(a,w);
}

int minw(int a,int b)
{
	pair<int,int> aw = findw(a);
	pair<int,int> bw = findw(b);
	int w;
	if(aw.first == bw.first)
	{
		w = getm(aw.first,aw.second,bw.second);
	}
	else
	{
		w = min(getm(aw.first,aw.second,m[aw.first].n - 1),getm(bw.first,0,bw.second));
		for(int i = aw.first + 1; i < bw.first; i++)
		{
			w = min(w,m[i].minw);
		}
	}
	return w;
}

void oki(int a,int x)
{
	pair<int,int> w = findw(a);
	m[w.first].d[w.second] = x;
	m[w.first].minw = getm(w.first,0,m[w.first].n - 1);
}

int main()
{
	int q;
	scanf("%d%d",&N,&q);
	for(int i = 0; i < N; i++)
	{
		int w;
		scanf("%d",&w);
		p[i] = w;
	}
	bun();
	for(int i = 0; i < q; i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		if(a == 0)
		{
			shift(b,c);
		}
		else if(a == 1)
		{
			printf("%d\n",minw(b,c));
		}
		else
		{
			oki(b,c);
		}
	}
	return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int x;
    cin >> x;
    int sum = 0;
    REP(i,0,x+1) {
        sum += i;
        if (sum >= x) {
            cout << i << endl;
            return;
        }
     }
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
function isAddedValue( char )
	return Base.ifelse( Base.isequal(char, 'o'), 100, 0 )
end

function abc095_a()

	const val_base = 700

	# STEP.01
	# get the target order
	buffer = Base.readline( Base.STDIN )

	# STEP.02
	# count up the number of the topping
	val_total  = val_base
	val_total += Main.isAddedValue( buffer[1] )
	val_total += Main.isAddedValue( buffer[2] )
	val_total += Main.isAddedValue( buffer[3] )

	# STEP.03
	# output the result
	Base.println( Base.STDOUT, val_total )

	# STEP.TRUE_END
	return Base.nothing

end

#==================================================================================================#

Main.abc095_a()


Measured memory_bytes: 135156
#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>;

void dfs(int id, int gid, vector<vector<int> >& g, int group[]){
	group[id] = gid;
	for(int n : g[id]){
		if(group[n] < 0){
			group[n] = gid;
			dfs(n, gid, g, group);
		}
	}
	return;
}

int main(){
	int n, m; cin >> n >> m;
	int group[n];
	memset(group, -1, n*sizeof(int));
	vector<vector<int> > g(n, vector<int>());
	rep(i, m){
		int s, t; cin >> s >> t;
		g[s].push_back(t);
		g[t].push_back(s);
	}

	int gid = 0;
	rep(i, n) if(group[i] < 0) dfs(i, gid++, g, group);

	int q; cin >> q;
	rep(i, q){
		int s, t; cin >> s >> t;
		cout << ((group[s] == group[t]) ? "yes" : "no") << endl;
	}

	return 0;
}



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

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

  vector<int> a(N);
  for (int i = 0; i < N; i++)
  {
    cin >> a.at(i);
  }

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  int bob, alice = 0;
  for (int i = 0; i < N; i++)
  {
    if(i % 2 == 0){
      alice += a.at(i);
    }else{
      bob += a.at(i);
    }
  }
  
  int ans = alice - bob;
  cout  << ans << endl;
}


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

const int N = 500005;

struct info{
   int sum=0;
   string str;
}tree[N*4];

string arr;

string f(string ar,string fr)
{
    set<char>s;
    for(int i=0;i<ar.size();i++)s.insert(ar[i]);
    for(int i=0;i<fr.size();i++)s.insert(fr[i]);
    string sa="";
    for(set<char>::iterator it=s.begin();it!=s.end();it++)
    {
        sa+=*it;
    }
    return sa;
}




void build(int idx,int left,int right)
{
    if(left==right)
    {
        tree[idx].str=arr[left-1];
        tree[idx].sum=1;
        return ;
    }

    int mid=(left+right)/2;
    build(idx*2,left,mid);
    build(idx*2+1,mid+1,right);

    string s = f(tree[idx*2].str,tree[idx*2+1].str);
    tree[idx].str=s;
    tree[idx].sum=s.size();
}

void update(int idx,int left,int right,int pos,char c)
{
    if(pos<left||pos>right)return ;
    if(pos==left&&right==pos)
    {
        tree[idx].str=c;
        return ;
    }
    int mid=(left+right)/2;
    update(idx*2,left,mid,pos,c);
    update(idx*2+1,mid+1,right,pos,c);

     string s = f(tree[idx*2].str,tree[idx*2+1].str);
    tree[idx].str=s;
    tree[idx].sum=s.size();
}

string query(int idx,int left,int right,int l,int r)
{
    string g="";
    if(r<left||right<l)return g;
    if(l<=left&&right<=r)
    {
        return tree[idx].str;
    }
    int mid=(left+right)/2;
    string x=query(idx*2,left,mid,l,r);
    string y=query(idx*2+1,mid+1,right,l,r);
    return f(x,y);
}



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

 cin>>arr;

  build(1,1,n);

//  for(int i=1;i<=n;i++)cout<<tree[i].str<<" ";

  int m;
  cin>>m;
  while(m--)
  {
      int i;
      cin>>i;
      if(i==1)
      {
          int pos;
          char c;
          cin>>pos>>c;
          update(1,1,n,pos,c);
      }
      else
      {
          int l,r;
          cin>>l>>r;
         string gr=query(1,1,n,l,r);
         cout<<gr.size()<<"\n";
      }
  }
}


Measured memory_bytes: 80516
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n; cin >> n;
  if(n==0) {cout<<0<<endl;  return 0;}
  vector <int> num;
  while(n!=0){
      int a=n%(-2);
      if(a==-1){
          a=1;
          n=n/-2+1;
          num.push_back(a);
      }else{
          n=n/-2;
          num.push_back(a);
      }
  }
  reverse(num.begin(),num.end());
  for(int i=0;i<num.size();i++){
      cout<<num[i];
  }
}

Measured memory_bytes: 256
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll N, Q;
    string S;
    cin >> N >> S >> Q;

    while(Q--) {
        ll K;
        cin >> K;
        ll ans = 0;
        ll cnt_d = 0, cnt_m = 0;
        ll perm_DM = 0;
        for(ll i = 0; i < N; i++) {
            if(i - K >= 0) {
                char pre_c = S[i - K];
                if(pre_c == 'D') {
                    cnt_d--;
                    perm_DM -= cnt_m;
                }
                if(pre_c == 'M') cnt_m--;
            }
            char c = S[i];
            if(c == 'D') {
                cnt_d++;
            } else if(c == 'M') {
                cnt_m++;
                perm_DM += cnt_d;
            } else if(c == 'C') {
                ans += perm_DM;
            }
            DEBUG(make_tuple(i, K, cnt_d, cnt_m, perm_DM));
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1948
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#define f first
#define s second
using namespace std;
int main(){
  
  vector <pair<double,double> > p;
  int n,i,j;

  p.push_back(make_pair(0,0));
  p.push_back(make_pair(100,0));
  cin>>n;
  for(i=0;i<n;i++){
    for(j=0;p[j].f!=100;j+=4){
      p.insert(p.begin()+j+1,make_pair((p[j+1].f+p[j].f*2)/3,(p[j+1].s+p[j].s*2)/3));      
      p.insert(p.begin()+j+2,make_pair((p[j+2].f*2+p[j].f)/3,(p[j+2].s*2+p[j].s)/3));
      p.insert(p.begin()+j+2,make_pair((p[j+2].f-p[j+1].f)*cos(M_PI/3)-(p[j+2].s-p[j+1].s)*sin(M_PI/3)+p[j+1].f,(p[j+2].f-p[j+1].f)*sin(M_PI/3)+(p[j+2].s-p[j+1].s)*cos(M_PI/3)+p[j+1].s));
    }
  }
  for(i=0;i<p.size();i++) cout<<p[i].f<<" "<<p[i].s<<endl;
  return 0;
}



Measured memory_bytes: 3296
#include<bits/stdc++.h>
using namespace std;
void grp(int i,int id,vector<int> &g,vector<vector<int>> &f,int &cnt) {
  g.at(i)=id;
  cnt++;
  for(auto j : f.at(i)) if (g.at(j)==0) grp(j,id,g,f,cnt);
}
int main() {
  int n,m,k,i,a,b,cnt,id=1;
  cin>>n>>m>>k;
  vector<vector<int>> f(n+1,vector<int>(0));
  vector<int> g(n+1),ans(n+1),gn(1);
  for(i=0;i<m;i++) {
    cin>>a>>b;
    f.at(a).push_back(b);
    f.at(b).push_back(a);
  }
  for(i=1;i<=n;i++) if (g.at(i)==0) {
    cnt=0;
    grp(i,id,g,f,cnt);
    gn.push_back(cnt);
    id++;
  }
  for(i=1;i<=n;i++) ans.at(i)=gn.at(g.at(i))-1-f.at(i).size();
  for(i=0;i<k;i++) {
    cin>>a>>b;
    if(g.at(a)==g.at(b)) {
      ans.at(a)--;
      ans.at(b)--;
    }
  }
  for(i=1;i<=n;i++) {
    cout<<ans.at(i);
    if (i<n) cout<<' ';
    else cout<<endl;
  }
}

Measured memory_bytes: 8448
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
connections = [[] for _ in range(N)]
for a, b in AB:
    connections[a - 1].append(b - 1)
    connections[b - 1].append(a - 1)

markers = [-1] * N

queue = [0]
steps = [-1] * N
steps[0] = 0
while len(queue) >= 1:
    room = queue.pop(0)
    for r in connections[room]:
        if steps[r] >= 0:
            continue
        queue.append(r)
        steps[r] = steps[room] + 1
        markers[r] = str(room + 1)

print("Yes")
print("\n".join(markers[1:]))

Measured memory_bytes: 68736
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  vector<vector<P>>vec(n);
  
  int ans=0;
  rep(i,n){
    int a;
    cin >> a;
    rep(j,a){
      int x,y;
      cin >> x >> y;
      x--;
      vec[i].push_back(P(x,y));
    }
  }
  for(int bit=0;bit<(1<<n);bit++){
    bool ok=true;
    rep(i,n){
      if(!(bit&(1<<i)))continue;
      for(auto p:vec[i]){
        if(p.second && !(bit&(1<<p.first)))ok=false;
        if(!p.second && (bit&(1<<p.first)))ok=false;
      }
    }
    if(ok)ans=max(ans,__builtin_popcount(bit));
  }
  
  cout << ans << endl;
    
        
  return 0;     
}


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

int binary_search( int* a, int n , int v )
{
    int left = 0, right = n;

    if( a[n-1] < v )                            // 存在しない場合
        return n;

    while( left < right )
    {
        int mid = ( left + right ) / 2;
        if( a[mid] > v )
            right = mid;
        else if( a[mid] < v )
            left = mid + 1;                     // midではなくて、mid+1
        else
        {
            while( mid >= 0 && a[mid] == v )    //同じ数字が並んでいる場合、一番最初の要素を返す
                mid--;
            return mid + 1;
        }
    }

    if( a[left] < v )
        return left + 1;
    else
        return left;
}

int main()
{
    int n, q, v;

    cin >> n;

    int a[n];

    for( int i = 0; i < n; i++ )
        cin >> a[i];
    
    cin >> q;

    for( int i = 0; i < q; i++ )
    {
        cin >> v;
        cout << binary_search( a, n, v ) << endl;
    }

    return 0;
}


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

typedef long long ll;

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

	int h=0, b=0;
	rep(i,m){
		int t; cin >> t;
		if(t>x)b++;
		else h++;
	}

	int ans = min(h,b);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
*/
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
} 

// 最小公倍数
ll lcm(ll a, ll b) {
    return a/gcd(a, b)*b;
}
int main()
{
    ll A, B;
    cin >> A >> B;
    cout << lcm(A, B) << endl;
    return 0;
}

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

const int mod = 1000000007;
int main(){
    int n, m;
    cin >> n >> m;
    long long x[n], y[m];
    for(int i = 0; i < n; i++) cin >> x[i];
    for(int i = 0; i < m; i++) cin >> y[i];
    long long sum1 = 0, sum2 = 0;
    for(int k = 1; k <= n; k++){
        sum1 += (k - 1) * x[k-1] - (n - k) * x[k-1];
        sum1 %= mod;
    }
    for(int k = 1; k <= m; k++){
        sum2 += (k - 1) * y[k-1] - (m - k) * y[k-1];
        sum2 %= mod;
    }
    cout << (sum1 * sum2) % mod << endl;
    return 0;
}

Measured memory_bytes: 1792
N = int(input())

lst = [list(map(int, input().split())) for _ in range(N)]

max_1 = -float('inf')
min_1 = float('inf')

max_2 = -float('inf')
min_2 = float('inf')

for a, b in lst:
    max_1 = max(max_1, a - b)
    min_1 = min(min_1, a - b)

    max_2 = max(max_2, a + b)
    min_2 = min(min_2, a + b)


ans = max(max_1 - min_1, max_2 - min_2)

print(ans)




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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

#define INF 1e9
#define MOD 1000000007
#define rep(i, a, n) for (int i = a; i < (n); i++)
#define each(x, v) for (auto& x: (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl

void solve();
void in(){} template<class T, class... U> void in(T &t, U &...u){ cin >> t; in(u...); }
int main() { cin.tie(0); ios::sync_with_stdio(0); solve(); }

void solve() {
  int H, N;
  in(H, N);
  vi A(N), B(N);
  rep(i, 0, N) {
    in(A[i], B[i]);
  }

  vi dp(H + 1, 0);
  rep(i, 1, H + 1) {
    dp[i] = INF;
    rep(j, 0, N) {
      dp[i] = min(dp[i], B[j] + dp[max(i - A[j], 0)]);
    }
  }

  print(dp[H]);
}


Measured memory_bytes: 256
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let mut sc = Scanner::new();
    let n = sc.next_usize();

    if n % 2 == 1 {
        println!("0");
        return;
    }

    let mut ans = 0;
    for m in 1.. {
        if 2 * 5usize.pow(m) > n {
            break;
        }

        ans += n / (2 * 5usize.pow(m));
    }

    println!("{}", ans);
}

pub struct Scanner {
    buf: std::collections::VecDeque<String>,
}

impl Scanner {
    pub fn new() -> Self {
        Self {
            buf: std::collections::VecDeque::new(),
        }
    }

    fn scan_line(&mut self) {
        let mut flag = 0;
        while self.buf.is_empty() {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            let mut iter = s.split_whitespace().peekable();
            if iter.peek().is_none() {
                if flag >= 5 {
                    panic!("There is no input!");
                }
                flag += 1;
                continue;
            }

            for si in iter {
                self.buf.push_back(si.to_string());
            }
        }
    }

    pub fn next<T: std::str::FromStr>(&mut self) -> T {
        self.scan_line();
        self.buf
            .pop_front()
            .unwrap()
            .parse()
            .unwrap_or_else(|_| panic!("Couldn't parse!"))
    }

    pub fn next_usize(&mut self) -> usize {
        self.next()
    }

    pub fn next_isize(&mut self) -> isize {
        self.next()
    }

    pub fn next_chars(&mut self) -> Vec<char> {
        self.next::<String>().chars().collect()
    }

    pub fn next_string(&mut self) -> String {
        self.next()
    }

    pub fn next_char(&mut self) -> char {
        self.next()
    }

    pub fn next_float(&mut self) -> f64 {
        self.next()
    }
}


Measured memory_bytes: 2148
#include <iostream>
#include <vector>
#include <cstring>
#include <stack>

std::vector<int> graph[8];
int n, m;

std::vector<int> arrived;
int solve(int x) {
	if (arrived.size() == n - 1)
		return 1;

	int ret = 0;
	arrived.push_back(x);
	for (auto&& e : graph[x]) {
		if ([e]() {
			for (auto&& v : arrived)
				if (v == e)
					return false;

			return true;
		}()) {
			ret += solve(e);
		}
	}
	arrived.pop_back();

	return ret;
}

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

	arrived.reserve(m);

	for (int i = 0; i < m; ++i) {
		int a, b;
		std::cin >> a >> b;
		--a, --b;

		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	std::cout << solve(0) << std::endl;
}

Measured memory_bytes: 256
/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-11-10 14:46:33
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

bool ok(string S)
{
  string T = S;
  reverse(T.begin(), T.end());
  return (S == T);
}

int main()
{
  int A, B;
  cin >> A >> B;
  int ans = 0;
  for (auto i = A; i <= B; i++)
  {
    if (ok(to_string(i)))
    {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long  
using namespace std;
#define  inf 1e18+18
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mod 1000000007
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const int maxn=40000;
#define  pq priority_queue
#define  ff first
#define  ss second 
#define pb  push_back
#define lb lower_bound
int main()
{
	int i,j,k,l,m,n;
	string s;
	cin>>s;
	if(s[0]==s[1]&&s[1]==s[2]&&s[0]=='R')
		cout<<3;
	else if(s[0]==s[1]&&s[0]=='R'||s[1]=='R'&&s[1]==s[2])
		cout<<2;
	else if(s[0]=='R'||s[1]=='R'||s[2]=='R')
		cout<<1;
	else
		cout<<0;

}

Measured memory_bytes: 3564
#include<stdio.h>
int main(){
  int A[100],k,i,n,minj,chg,j,count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<=n-2;i++){
    minj=i;
    for(j=i;j<=n-1;j++){
      if(A[j]<A[minj]){
	minj=j;
        
      }
    }
    if(A[i]!=A[minj])count++;
    chg=A[i];
    A[i]=A[minj];
    A[minj]=chg;
    }
 
   for(i=0;i<n;i++){
      if(i==n-1)printf("%d\n",A[i]);
      else printf("%d ",A[i]);
    }
    printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B,ans=0;
  cin >> A >> B;
  for(int i=A;i<=B;i++){
    if(i/10000==i%10 && i/1000%10==i%100/10) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	S, T := getString(), getString()
	A, B := getInt(), getInt()
	U := getString()

	if S == U {
		A--
	}
	if T == U {
		B--
	}
	out(A, B)
}


Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 104
#define INF 1e9+7

using namespace std;

ll n,m;
char ar[N][N];
ll dp[N][N];

ll isblack(ll i,ll j)
{
    return (ar[i][j]=='#');
}

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

    cin >> n >> m;

    rep(i,0,n)
    {
        rep(j,0,m)
        {
            cin >> ar[i][j];
        }
    }

    dp[0][0] = isblack(0,0);

    rep(i,1,n)
    {
        if(isblack(i,0))
            dp[i][0] = dp[i-1][0]+!isblack(i-1,0);
        else
            dp[i][0] = dp[i-1][0];
    }

    rep(j,1,m)
    {
        if(isblack(0,j))
            dp[0][j] = dp[0][j-1]+!isblack(0,j-1);
        else
            dp[0][j] = dp[0][j-1];
    }

    rep(i,1,n)
    {
        rep(j,1,m)
        {
            if(isblack(i,j))
            {
                dp[i][j] = min(dp[i-1][j]+!isblack(i-1,j),dp[i][j-1]+!isblack(i,j-1));
            }
            else
            {
                dp[i][j] = min(dp[i-1][j],dp[i][j-1]);
            }
        }
    }

    cout << dp[n-1][m-1];
    return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solve());
            return;
        }

        private static string solve()
        {
            var age = int.Parse(Console.ReadLine());
            return (age == 3 || age == 5 || age == 7) ? "YES" : "NO";
        }
    }
}


Measured memory_bytes: 11092
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<queue>
#include<bitset>
#include<map>
#include<set>

#define maxn 55
#define maxm 125005
#define INF 0x3f3f3f3f
#define MOD 1000000007

using namespace std;

inline int getint()
{
	int num=0,flag=1;char c;
	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();
	return num*flag;
}

int n,X,d;
int fa[maxn];
struct node{
	long long v;
	int w,id;
}a[maxn];
inline bool cmp(node a,node b){return a.w*b.v>b.w*a.v;}
long long dp[maxm];

int main()
{
	n=getint(),X=getint(),d=getint();
	a[1].v=getint();
	for(int i=2;i<=n;i++)a[i].v=getint(),fa[i]=getint();
	for(int i=1;i<=n;i++)a[i].id=i,a[i].w=1;
	for(int i=n;i>1;i--)a[fa[i]].v+=a[i].v,a[fa[i]].w+=a[i].w;
	int L=min(n,d);
	memset(dp,INF,sizeof dp),dp[0]=0;
	for(int i=1;i<=n;i++)
	{
		int x=L;
		for(int j=0;(1<<j)<=x;j++)
		{
			int w=a[i].w<<j;
			long long v=a[i].v<<j;
			for(int k=maxm-1;k>=w;k--)dp[k]=min(dp[k],dp[k-w]+v);
			x-=1<<j;
		}
		if(x)
		{
			int w=a[i].w*x;
			long long v=a[i].v*x;
			for(int j=maxm-1;j>=w;j--)dp[j]=min(dp[j],dp[j-w]+v);
		}
	}
	sort(a+1,a+n+1,cmp);
	while(a[n].id!=1)n--;
	long long ans=0;
	for(int i=0;i<maxm;i++)
	{
		if(dp[i]>X)continue;
		long long w=i,v=dp[i];
		for(int j=1;j<n;j++)
		{
			long long c=min(1ll*d-L,(X-v)/a[j].v);
			w+=c*a[j].w,v+=c*a[j].v;
		}
		long long c=(X-v)/a[n].v;
		w+=c*a[n].w,v+=c*a[n].v;
		ans=max(ans,w);
	}
	printf("%lld\n",ans);
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]) == typeid(INF) and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  int N, M;
  cin >> N >> M;
  int X, Y;
  cin >> X >> Y;

  vector<int> x(N);
  rep(i, 0, N) { cin >> x[i]; }
  vector<int> y(M);
  rep(i, 0, M) { cin >> y[i]; }
  vector<pii> v;
  rep(i, 0, N) { v.emplace_back(x[i], 0); }
  rep(i, 0, M) { v.emplace_back(y[i], 1); }
  sort(all(v));
  dump(v);

  int c = 0;
  rep(i, 0, N) {
    if (v[i].se == 0)
      c++;
  }
  string ans;

  ans = "War";
  if (c == N) {
    rep(z, v[N - 1].fi+1, v[N].fi + 1) {
      if (X < z and z <= Y)
        ans = "No War";
    }
  }
  cout << ans << endl;

  return 0;
}


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

const int N=400005;
int n,k,a[N];

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=k;i++) a[0]+=a[i];
	printf("%d\n",a[0]);
}

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

using namespace std;

const int N = 6969;

int n, k, h[N];
vector <int> g[N];

void dfs (int u, int pr = -1, int far = 0) {
  h[u] = far;
  for (int v : g[u]) if (v ^ pr) dfs(v, u, far + 1);
}

int main() {
  cin >> n >> k;
  for (int i = 1, u, v; i < n; ++i) {
    cin >> u >> v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  int ans = n;
  if (k & 1) {
    for (int u = 1; u <= n; ++u) for (int v : g[u]) {
      dfs(u, v); dfs(v, u);
      int cur = 0;
      for (int i = 1; i <= n; ++i) {
        if (h[i] > k / 2) ++cur;
      }
      ans = min(ans, cur);
    }
  } else {
    for (int cen = 1; cen <= n; ++cen) {
      dfs(cen);
      int cur = 0;
      for (int i = 1; i <= n; ++i) {
        if (h[i] > k / 2) ++cur;
      }
      ans = min(ans, cur);
    }
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sort(a) sort(a.begin(),a.end())
vector<bool>visited;
vector<vector<int>>l;
vector<int>color;
long long mod=1000000007;
int isprime(ll n)
{
    ll i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
            return 0;
    }
    return 1;

}
int isperfectsq(ll n)
{


    long double x;
    x=(long double)(sqrt((long double )(n)));
    ll y=sqrt(n);
    if(x==y)
        return 1;
        else
            return 0;
}


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


    int n;
    cin>>n;
    string s;
    cin>>s;
    int i;
    int cnt=0;
    int w=0;
    for(i=0;i<n;i++)
    {
        if(s[i]=='W')
            w++;
    }
    if(w==0)
    {
        cout<<0;
        return 0;
    }
    for(i=n-1;i>=0;i--)
    {
        if(s[i]=='R'&&cnt<i&&w>0)
           {
               cnt++;
           }
           w--;

    }
    cout<<cnt<<endl;


}










Measured memory_bytes: 3700
from collections import deque
n = int(input())
G = [[] for _ in range(n)]
for i in range(n):
    u, k, *vs = map(int, input().split())
    u -= 1
    vs = list(map(lambda x: x - 1, vs))
    for v in vs:
        G[u].append(v)

dist = [-1] * n
dist[0] = 0
que = deque([0])

while len(que) > 0:
    now_v = que.popleft()
    now_dist = dist[now_v]
    next_vs = G[now_v]
    for next_v in next_vs:
        if dist[next_v] == -1:
            dist[next_v] = now_dist + 1
            que.append(next_v)

for i, x in enumerate(dist):
    print(i + 1, x)


Measured memory_bytes: 6044
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {
	vector<int> vec; int n; cin >> n; int c_1 = 5; int c_2 = 7;
	cout << n << ":" << flush;
	while (n % 2 == 0) { vec.push_back(2); n = n / 2; }
	while (n % 3 == 0) { vec.push_back(3); n = n / 3; }
	while (n != 1) {
		while (n % c_1 == 0) { vec.push_back(c_1); n = n / c_1; }
		while (n % c_2 == 0) { vec.push_back(c_2); n = n / c_2; }
		c_1 = c_1 + 6; c_2 = c_2 + 6;
	}
	for (int i = 0; i < vec.size(); i++) cout << " " << vec[i] << flush;
	cout << endl;
	return 0;
}


Measured memory_bytes: 3160
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 2e5 + 10;
int p[N] , n , du[N] , sg[N];
vi son[N];

int main(){
    scanf("%d",&n);
    rep(i,1,n+1) scanf("%d",p + i) , du[p[i]]++;
    vi q;
    rep(i,1,n+1) if(!du[i]) q.pb(i);
    rep(ii,0,sz(q)){
        int c=q[ii];
        vi&v=son[c];
        sort(all(v));
        v.erase(unique(all(v)),v.end());
        int&t=sg[c]=0;
        while(t<sz(v)&&v[t]==t) ++t;
        son[p[c]].pb(t);
        if(!--du[p[c]]) q.pb(p[c]);
    }
    rep(i,1,n+1) if(du[i]) {
        vector<pii> cir;
        for(int s=i;s!=i||!sz(cir);s=p[s]){
            vi&v=son[s];
            sort(all(v));
            v.erase(unique(all(v)),v.end());
            int t=0;
            while(t<sz(v)&&v[t]==t) ++t;
            v.insert(v.begin()+t,t);
            int u=t;
            while(u<sz(v)&&v[u]==u) ++u;
            cir.pb(mp(t,u));
        }
        auto check = [&](int x){
            int s=x;
            rep(i,1,sz(cir)) {
                if(x==cir[i].fi) x=cir[i].se;
                else x=cir[i].fi;
            }
            if(x==cir[0].fi) x=cir[0].se;
            else x=cir[0].fi;
            return s==x;
        };
        if(check(cir[0].fi) || check(cir[0].se)) puts("POSSIBLE");
        else puts("IMPOSSIBLE");
        break;
    }
    return 0;
}


Measured memory_bytes: 13936
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdio>

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define each(it,c) for(__typeof(c.begin()) it=c.begin(); it!=c.end(); it++)
#define INF 1<<30
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int, int> > vp;
typedef map<int,int> mpii;
typedef priority_queue<int, vi, greater<int> > pqi;

typedef long long ll;

int MOD = 1000000007;
vi fact;
vi inv;

ll modpow(ll x, ll n){
	ll ret = 1;
	while(n){
		if(n&1) ret = ret*x%MOD;
		x = x*x%MOD;
		n >>= 1;
	}
	return ret;
}

void init_(int lim){
	fact.resize(lim);
	inv.resize(lim);
	fact[0] = 1;
	inv[0] = 1;
	REP(i,1,lim){
		fact[i] = (fact[i-1]*(ll)i)%MOD;
		inv[i] = modpow(fact[i],MOD-2)%MOD;
	}
}
ll nCr(ll n,ll r){
	ll ret = fact[n];
	ret = (ret * inv[r])%MOD;
	ret = (ret * inv[n-r])%MOD;
	return ret;
}

int main(){
	int h,w,a,b; cin>>h>>w>>a>>b;
	init_(h+w);

	ll ans = 0ll;
	for(int i=h-a-1, j=b; 0<=i && j<w; i--,j++){
		//cout<<nCr(i+j,j)<<" "<<nCr((h-i-1)+(w-j-1),w-j-1)<<endl;
		ans += ( nCr(i+j,j) * nCr((h-i-1)+(w-j-1),w-j-1) ) % MOD;
	}
	ans = (ans%MOD+MOD)%MOD;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,W = LI()
    g = LIR(n)
    dp = [0]*(W+1)
    for i in range(n):
        v,w = g[i]
        for j in range(W):
            nj = j+w
            if nj <= W:
                nd = dp[j]+v
                if dp[nj] < nd:
                    dp[nj] = nd
    print(dp[W])
    return

#Solve
if __name__ == "__main__":
    solve()



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

long long k,cnt,i;
string s;
int main(){
	cin>>s;scanf("%lld",&k);
	if (s[0]!='1'){printf("%c",s[0]);return 0;}
	long long len=s.length();
	for (i=0;i<len;i++) if (s[i]!='1') break;else cnt++;
	if (cnt>=k) printf("1");else printf("%c",s[i]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

char dp[18000][18000];
int pa[200][200], pb[18000], pc[18000];

int H, W, logsc[277], p1[200][200], p2[200][200]; char c[200][200];

void init() {
	int K = max(H, W), cnts = 0;
	for (int i = 1; i <= K; i++) {
		for (int j = i; j <= K; j++) {
			cnts++;
			pa[i][j] = cnts;
			pb[cnts] = i;
			pc[cnts] = j;
		}
	}
	for (int i = 1; i <= 8; i++) {
		for (int j = (1 << (i - 1)) + 1; j <= (1 << i); j++) logsc[j] = i;
	}
}

bool ranged(int lx, int ly, int rx, int ry) {
	int v1 = p1[lx - 1][ly - 1] + p1[rx][ry] - p1[lx - 1][ry] - p1[rx][ly - 1];
	int v2 = p2[lx - 1][ly - 1] + p2[rx][ry] - p2[lx - 1][ry] - p2[rx][ly - 1];
	if (v1 == 0 || v2 == 0) return true;
	return false;
}

char dfs(int lx, int ly, int rx, int ry) {
	int la = pa[lx][rx], lb = pa[ly][ry];
	if (dp[la][lb] >= 1) return dp[la][lb] - 1;
	if (ranged(lx, ly, rx, ry) == true) { dp[la][lb] = 1; return 0; }

	// X 軸方向に分割
	int cx = lx; char ans1 = 127;
	for (int i = logsc[rx - lx + 1] - 1; i >= 0; i--) {
		int ex = cx + (1 << i) - 1;

		bool flag = false;
		if (ex >= rx) { flag = true; }
		else {
			char v1 = dfs(lx, ly, ex, ry);
			char v2 = dfs(ex + 1, ly, rx, ry);

			if (v1 > v2) flag = true;
			ans1 = min(ans1, max(v1, v2));
			if (v1 == v2) break;
		}
		if (flag == false) cx += (1 << i);
	}

	// Y 軸方向に分割
	int cy = ly; char ans2 = 127;
	for (int i = logsc[ry - ly + 1]; i >= 0; i--) {
		int ey = cy + (1 << i) - 1;

		bool flag = false;
		if (ey >= ry) { flag = true; }
		else {
			char v1 = dfs(lx, ly, rx, ey);
			char v2 = dfs(lx, ey + 1, rx, ry);

			if (v1 > v2) flag = true;
			ans2 = min(ans2, max(v1, v2));
			if (v1 == v2) break;
		}
		if (flag == false) cy += (1 << i);
	}

	dp[la][lb] = min(ans1, ans2) + 2;
	return min(ans1, ans2) + 1;
}

int main() {
	cin >> H >> W; init();
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> c[i][j];
			if (c[i][j] == '.') p1[i][j] = 1;
			if (c[i][j] == '#') p2[i][j] = 1;
		}
	}

	for (int i = 1; i <= H; i++) { for (int j = 1; j <= W; j++) p1[i][j] += p1[i][j - 1]; }
	for (int i = 1; i <= H; i++) { for (int j = 1; j <= W; j++) p1[i][j] += p1[i - 1][j]; }
	for (int i = 1; i <= H; i++) { for (int j = 1; j <= W; j++) p2[i][j] += p2[i][j - 1]; }
	for (int i = 1; i <= H; i++) { for (int j = 1; j <= W; j++) p2[i][j] += p2[i - 1][j]; }

	cout << (int)dfs(1, 1, H, W) << endl;
	return 0;
}

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

int main(){
    int n;
    cin>>n;
    int pos[n+1];
    for(int i=0;i<n;i++){
        int p;
        cin>>p;
        pos[p]=i+1;
    }
    ll ans=0;
    multiset<int> se;
    se.insert(pos[n]);
    se.insert(0);
    se.insert(n+1);
    se.insert(0);
    se.insert(n+1);
    for(int i=n-1;i>0;i--){
        auto it=se.lower_bound(pos[i]);
        --it;
        --it;
        int a=*it;
        ++it;
        int b=*it;
        ++it;
        int c=*it;
        ++it;
        int d=*it;
        ans+=(ll)i*(b-a)*(c-pos[i])+(ll)i*(d-c)*(pos[i]-b);
        se.insert(pos[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
 
ifstream in ("test.in" );
ofstream out("test.out");
 
const int DIM = 2e5 + 5;
 
long long psm[DIM];
 
int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    int n;
    cin >> n;
    
    for (int i = 1; i <= n; ++i) {
        cin >> psm[i];
        psm[i] += psm[i - 1];
    }
    
    long long ans = numeric_limits<long long> :: max() / 2;
    for (int i = 1; i < n; ++i)
        ans = min(ans, abs(psm[i] - (psm[n] - psm[i])));
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 1792