akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

struct edge{
  int to;
  int64_t w;
};

vector<vector<edge>> G(100010);
vector<int> color(100010, 0); // 1 or -1

int main(){
  int N; cin >> N;
  for(int i=0; i<N-1; i++){
    int u, v; int64_t w;
    cin >> u >> v >> w;
    
    edge e;
    e.to = v-1; e.w = w; G[u-1].push_back(e);
    e.to = u-1; e.w = w; G[v-1].push_back(e);
  }

  color[0] = 1;
  stack<int> s; s.push(0);
  while(!s.empty()){
    int cur = s.top(); s.pop();
    //cout << cur << endl;
    for(int i=0; i<G[cur].size(); i++){
      int next = G[cur][i].to; 
      if (color[next] == 0){
        if(G[cur][i].w % 2 == 0){
          color[next] = color[cur]; 
        } else {
          color[next] = -color[cur];
        }
        s.push(next);
      }
    }
  }

  for(int i=0; i<N; i++){
    cout << (color[i]+1)/2 << endl;;
  }
}

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

int main() {
  double a, b;
  
  cin >> a >> b;
  
  double x = (a + b) * 0.5;
  int X = x;
  double Y = x - X;
  int z = x + Y;
  
  cout << z << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  /*int N;
  cin>>N;
  long long A[100000];
  long long answer=1;
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(A[i]==0) answer=0;
  }
  if(answer==0) cout<<answer<<endl;
  else{
  for(int i=0;i<N;i++){
    answer=answer*A[i];
    if(answer>1000000000000000000){
      answer=-1;
      break;
    }
  }
  cout<<answer<<endl;
  }*/
  long long N;
  cin>>N;
  int div[1000001];
  for(int i=0;i<=1000000;i++){
    div[i]=0;
  }
  long long answer=0;
  long long i=2;
  while(i*i<=N&&N>1){
    if(N%i==0){
      int judge=1;
      while(N%i==0){
        N=N/i;
        div[i]++;
        if(div[i]==judge){
          div[i]=0;
          answer++;
          judge++;
        }
      }
    }
    i++;
    if(N!=1&&i*i>N){
      answer++;
    }
  }
  cout<<answer<<endl;
  
  return 0;
}

Measured memory_bytes: 7100
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 400010
#define ll long long
#define mod 1000000007
using namespace std;
int n,x,y;
int c[N],w[N],num[N],minw[N];
ll fac[N],inv[N];
ll ksm(ll a,ll b=mod-2)
{
	if(b==0) return 1;
	if(b==1) return a;
	ll q=ksm(a,b>>1);
	if(b&1) return q*q%mod*a%mod;
	return q*q%mod;
}
ll C(int a,int b){if(b>a || b<0) return 0;return fac[a]*inv[b]%mod*inv[a-b]%mod;}
int main()
{
	scanf("%d%d%d",&n,&x,&y);
	fac[0]=1;
	for(int i=1;i<=n;i++)fac[i]=fac[i-1]*i%mod;
	inv[n]=ksm(fac[n]);
	for(int i=n-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	for(int i=0;i<=n;i++) minw[i]=100000000;
	for(int i=1;i<=n;i++) scanf("%d%d",&c[i],&w[i]),minw[c[i]]=min(minw[c[i]],w[i]);
	int minid=0,sminid=0;
	for(int i=1;i<=n;i++)
	{
		if(minw[i]<=minw[minid])
		{
			sminid=minid;
			minid=i;
		}
		else if(minw[i]<=minw[sminid]) sminid=i;
	}
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(w[i]+minw[c[i]]<=x) w[i]=minw[c[i]];
		int omin=c[i]==minid?sminid:minid;
		if(minw[omin]+w[i]>y) continue;
		num[c[i]]++;
		cnt++;
	}
	ll ans=1;
	for(int i=1;i<=n;i++)
	if(num[i]) ans=ans*C(cnt,num[i])%mod,cnt-=num[i];
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 12032
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll a,b;
	cin >> a >> b;
	if(a>=13){
		cout << b;
		return 0;
	}
	if(a>=6){
		cout << b/2;
		return 0;
	}
	cout << 0;
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

i64 a, b, c, k, sum = 0;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> a >> b >> c >> k;
    i64 temp;
    temp = min(k, a);
    k -= temp;
    sum += temp;
    temp = min(k, b);
    k -= temp;
    temp = min(k, c);
    k -= temp;
    sum -= temp;
    cout << sum << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
 
int main(){
  int N;
  string S, T;
  cin >> N >> S >> T;
  for(int ii=0; ii<N; ii++){
    cout << S[ii] << T[ii];
  }
  cout << endl;
  return 0;
}
 

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int len = s.nextInt();
        String text = s.next();
        int len0 = text.length();
        if(len0>len){
            text = text.substring(0,len);
            System.out.println(text + "...");
        }else{
            System.out.println(text);
        }
    }
}

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

const int MOD=1e9+7;

int main(){
	int N;
	cin >> N;
	vector<vector<int>> match(N,vector<int>(N));
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			cin >> match[i][j];
		}
	}

	vector<int> dp(1<<N);
	dp[0] = 1;
	for(int bit=0; bit<(1<<N); bit++){
		int i = __builtin_popcount(bit);
		for(int j=0; j<N; j++){
			if((bit&(1<<j)) && match[i-1][j] ){
				dp[bit] = (dp[bit] + dp[bit^(1<<j)]) % MOD;
			}
		}
	}
	cout << dp[(1<<N)-1] << endl;
}



Measured memory_bytes: 11440
n = gets.chomp.to_i
hash = {}
n.times do
  a,b = gets.chomp.split(' ').map(&:to_i)
  hash[b] ? hash[b] += a : hash[b] = a
end

memo = 0
hash.sort.each do |arr|
  memo += arr[1]
  if (memo > arr[0])
    puts 'No'
    exit
  end
end
puts 'Yes'

Measured memory_bytes: 28536
#include <bits/stdc++.h>
#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, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  cout << n * n - a << endl;


  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include<functional>

#define INF 50001
using namespace std;


int main(){
    vector<int> money;
    int n,m,c;
    scanf("%d %d",&n,&m);
    int dp[m][n+1];

    for(int i = 0;i < m;i++){
        scanf("%d",&c);
        money.push_back(c);
    }
    sort(money.begin(),money.end());
    for(int i = 0; i < m;i++){
        c = money[i];
        for(int j = 0; j <= n;j++){
            if(i == 0) dp[i][j] = j/c;
            else{
                int cnt1 = INF;
                int cnt2 = dp[i-1][j];
                if(j - c >= 0) cnt1 = dp[i][j-c] + 1;
                dp[i][j] = min(cnt1,cnt2);
            }
        }
    }

    printf("%d\n",dp[m-1][n]);
    return 0;
}


Measured memory_bytes: 6700
#include <iostream>
#include <vector>
#include <math.h>
#include <queue>
#include <map>

int main(){

  int N;
  scanf("%d", &N);
  std::vector<int> H(N);
  for (int i=0; i<N; i++){
    scanf("%d", &H[i]);
  }

  for (int i=N-1; i>0; i--){
    if (H[i-1]>H[i]){
      if (H[i-1]>H[i]+1){
        printf("No\n");
        return 0;
      } else {
        H[i-1]--;
        //printf("H[%d] delete\n",i-1);
      }
    }
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;
typedef pair<string, int> PSi;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

class Trie{
#define N_alphabet 26
#define begin_alphabet 'a'
public:
    Trie *next[N_alphabet];
    int val = 0;
    bool exist = false;

    Trie(){
        fill(next, next + N_alphabet, (Trie *)0);
    }

    void insert(string &S, int i = 0){
        this->val += 1;
        if(i == S.size()){
            exist = true;
            return;
        }
        if(this->next[S[i] - begin_alphabet] == NULL)
            this->next[S[i] - begin_alphabet] = new Trie();
        this->next[S[i] - begin_alphabet]->insert(S, i + 1);
    }

    void makematrix(string &S, mat &compare, int &a, int i = 0){
        if(i == S.size()) return;
        if(this->exist) a += 1;
        int c = S[i] - begin_alphabet;
        REP(i, N_alphabet) if(this->next[i] != NULL) compare[c][i] += this->next[i]->val;
        this->next[c]->makematrix(S, compare, a, i + 1);
    }
};

signed main(){

    int N; cin >> N;
    vector<string> S(N);
    set<string> s;
    Trie trie;
    REP(i, N){
        cin >> S[i];
        trie.insert(S[i]);
    }

    int Q; cin >> Q;
    vector<vector<PSi>> query(N, vector<PSi>(0));
    int k;
    string per;
    REP(i, Q){
        cin >> k >> per;
        k--;
        query[k].push_back(PSi(per, i));
    }
    vec ans(Q);

    mat compare(26, vec(26, 0));
    REP(k, N){
        if(query[k].size() == 0) continue;
        REP(i, 26) REP(j, 26) compare[i][j] = 0;
        int a = 0;
        trie.makematrix(S[k], compare, a);
        REP(i, query[k].size()){
            int c = 0;
            per = query[k][i].first;
            REP(j1, 26) REP(j2, j1) c += compare[per[j1] - 'a'][per[j2] - 'a'];
            ans[query[k][i].second] = a + c + 1;
        }
    }
    REP(i, Q) cout << ans[i] << endl;
    
    return 0;
}

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

int main() {
	int count = 0;
	int h,w;
	cin >> h >> w;
	vector<vector<int>> data(h,vector<int>(w));
	for (int i=0;i<h;i++) {
		for (int j=0;j<w;j++) {
			data[i][j] = 0;
		}
	}
	int m,n;
	cin >> m >> n;
	for (int i=0;i<m;i++) {
		for(int j=0;j<w;j++) {
			data[i][j] += 1;
		}
	}
	for (int i=0;i<n;i++) {
		for(int j=0;j<h;j++) {
			data[j][i] += 1;
		}
	}
	for (int i=0;i<h;i++) {
		for(int j=0;j<w;j++) {
			if (data[i][j] == 0) {
				count++;
			}
		}
	}
	cout << count << endl;
}


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


void solve()
{
    int N;
    cin>>N;
    vector<ll> A(N);
    for(auto &a: A)
    {
        cin>>a;
    }
    int ans = 0;
    for(int i=0; i<N; ++i)
        for(int j=i+1; j<N; ++j)
            for(int k=j+1; k<N; ++k)
            {
                ll s = A[i]+A[j]+A[k];
                if(A[i]*2<s && A[j]*2<s && A[k]*2<s && A[i]!=A[j] && A[j]!=A[k] && A[k]!=A[i])
                {
                    //cerr<<A[i]<<" "<<A[j]<<" "<<A[k]<<" "<<s<<endl;
                    ++ans;
                }
            }
    cout<<ans<<endl;
}
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        solve();
 
		
	return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    int cnt=0;
    int cnt1=0;
    for(int i=1;i<n+1;i+=2){
        cnt=0;
        for(int j=1;j<i+1;j++){
            if(0==i%j) cnt++;
        }
        if(8==cnt){
            cnt1++;
        }
    }
    cout<<cnt1<<endl;
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;

const int INF = 1001001001;
const ll MOD = 1e9 + 7;

using namespace std;
using P = pair<int,int>;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

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

  int a[n];
  rep(i, n) {
      cin >> a[i];
  }
  
  int count = 0; int current_button = 1;
  rep(i, n) {
      count++;
      if (a[current_button-1] == 2) break;
      if (count == n) 
      {
          cout << -1 << endl; 
          return 0;
      }
      current_button = a[current_button-1];
  }
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll MOD = 1000000007LL;
ll inv(ll K) {
  ll A = MOD - 2;
  ll ret = 1;
  ll D = K;
  while (A > 0) {
    if (A % 2 == 1) {
      ret = (ret * D) % MOD;
    }
    D = (D * D) % MOD;
    A /= 2;
  }
  return ret;
}
ll FC[100005];
ll IFC[100005];
ll initFC(int N) {
  FC[0] = 1;
  for (ll i=1; i<=N; i++) {
    FC[i] = (FC[i-1] * i) % MOD;
  }
  IFC[N] = inv(FC[N]);
  for (ll i=N; i>=0; i--) {
    IFC[i-1] = (IFC[i] * i) % MOD;
  }
}

ll combFC(ll N, ll K) {
  ll ret = (FC[N] * IFC[K]) % MOD;
  ret = (ret * IFC[N-K]) % MOD;
  return ret;
}

ll modSum(ll& N, ll B) {
  N = (N + B % MOD + MOD) % MOD;
}

ll A[100005];
int main() {
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  initFC(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  sort(A, A+N);
  ll ret = 0;
  for (int i=N-1; i>=K-1; i--) {
    modSum(ret, A[i] * combFC(i, K-1));
  }
  for (int i=0; i<N-K+1; i++) {
    modSum(ret, -A[i] * combFC(N-i-1, K-1));
  }
  cout << ret << endl;
}

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

int main()
{
    int n;
    cin >> n;
    if(n == 2 || n == 3 || n == 5 || n ==7){
        cout << n << endl;
        return 0;
    }
    int sqn = sqrt(n) + 1;
    vector<int> p = {2};
    for(int i=2; i<sqn*2; i++){
        bool prime = true;
        for(int e: p){
            if(i % e == 0){
                prime = false;
                break;
            }
        }
        if(prime) p.push_back(i);
    }

    for(int i=n; i<4*n; i++){
        bool prime = true;
        for(int e:p){
            if(i % e == 0){
                prime = false;
                break;
            }
        }
        if(prime){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iomanip>
#include <time.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <vector>
#define mod 1000000007
#define ll long long
#define pi acos(-1)
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	if(a<=b)
		cout<<"unsafe";
	else
		cout<<"safe";
		
	return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>

int main() {
	long n;
	scanf("%ld", &n);
	long a = 1e9 + 7;
	long long ans = 1;
	for (long i = 1; i <= n; ++i) {
		ans = (ans * i) % a;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define LL long long
using namespace std;
const int MAXN = 200005;
vector< int >e[MAXN];
int n, c[MAXN], m, dep[MAXN], fa[MAXN];
bool flg[MAXN];
void ser(int u, int ff) {
	dep[u] = dep[fa[u]=ff] + 1;
	for(auto v : e[u]) if(v != ff) {
		if(!dep[v]) ser(v, u);
		else if(dep[v] < dep[u])
			for(int j = u; ; j = fa[j]) { flg[c[++m] = j] = 1; if(j == v) break; }
	}
}
int a[MAXN], tim, vis[MAXN];
void dfs(int u, int ff) {
	for(auto v : e[u]) if(v != ff && !flg[v]) dfs(v, u);
	++tim;
	for(auto v : e[u]) if(v != ff && !flg[v]) vis[a[v]] = tim;
	for(a[u] = 0; vis[a[u]] == tim; ++a[u]);
}
int main () {
	scanf("%d", &n);
	for(int i = 1, x; i <= n; ++i)
		scanf("%d", &x), e[x].pb(i), e[i].pb(x);
	ser(1, 0);
	bool flg = 1;
	for(int i = 1; i <= m; ++i) {
		dfs(c[i], 0);
		if(a[c[i]] != a[c[1]]) flg = 0;
	}
	if(!flg || !(m&1)) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
}

Measured memory_bytes: 24832
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(a) (a).begin(), (a).end()
#define OUT(x) out << (x) << endl;
#define M0(x) memset(x, 0, sizeof(x))
#define MINF(x) memset(x, 0x3f, sizeof(x))
#define MMINUS(a) memset(a, 0xff, sizeof(a))
#define ten(n) ((int)1e##n)

const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double EPS = 1.0 / LINF;
const char ENDL = '\n'; // for JetBrains IDE only supports yen

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 gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

using namespace std;

//===================================== template =========================================================

int main() {
    cin.tie(nullptr); ios_base::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    vector<ll> t(N), d(N); REP(i, N) cin >> t[i] >> d[i];
    vector<pair<ll, ll>> vec_pair(N); REP(i, N) vec_pair.emplace_back(d[i], t[i]);
    sort(ALL(vec_pair), greater<pair<ll, ll>>());

    ll kind = 0, sum = 0;
    vector<int> cnt(N+1, 0);
    vector<ll> max_taste(N+1, -1);
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> yobun;
    REP(i, K) {
        if (cnt[vec_pair[i].second] == 0) {
            kind++;
            max_taste[vec_pair[i].second] = vec_pair[i].first;
        }
        sum += vec_pair[i].first;
        cnt[vec_pair[i].second]++;
        if (cnt[vec_pair[i].second] >= 2) {
            if (max_taste[vec_pair[i].second] < vec_pair[i].first) {
                yobun.emplace(max_taste[vec_pair[i].second], vec_pair[i].second);
                max_taste[vec_pair[i].second] = vec_pair[i].first;
            } else {
                yobun.push(vec_pair[i]);
            }
        }
    }

    // cnt が複数のもののうち，一番小さいものと取替える
    priority_queue<ll> ans_pq;
    sum += kind * kind; ans_pq.push(sum);
    for (int i = K; i < N; i++) {
        if (!yobun.size()) break;
        if (cnt[vec_pair[i].second] == 0) {
            ll kind_up = (kind+1) * (kind+1) - kind * kind;
            ll taste_down = yobun.top().first - vec_pair[i].first;
            ll diff = kind_up - taste_down;
            ans_pq.push(sum += diff);
            kind++;
            cnt[yobun.top().second]--;
            cnt[vec_pair[i].second]++; // yobun は減る一方
            yobun.pop(); 
        }
    }

    cout << ans_pq.top() << endl;
}

Measured memory_bytes: 7652
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
    int n,m,sum=0,i;
    cin>>n>>m;
    int a[m];
    for(i=0;i<m;i++){
        cin>>a[i];
       sum=a[i]+sum;}
      if(sum<=n)
          cout<<n-sum;
         else if (sum>n)
         cout<<-1;
}


Measured memory_bytes: 3632
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
typedef pair<int,int> P;
int main(){
	string s;
	cin>>s;
	int ans=0;
	REP(i,s.size())if(s[i]=='1')ans++;
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
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(): return list(sys.stdin.readline())[:-1]
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,m,a):
    if m == 0:
        print(a)
        return
    l = LIR(m)
    l.sort(key = lambda x:-x[0])
    x = l[0][0]
    for h,p,q in l:
        if x < h:
            continue
        if p == a:
            x = h-1
            a = q
        elif q == a:
            x = h-1
            a = p
    print(a)
    return

#Solve
if __name__ == "__main__":
    while 1:
        n,m,a = LI()
        if n == m == a == 0:
            break
        solve(n,m,a)


Measured memory_bytes: 8216
#include <iostream>
#include <vector>
using namespace std;
typedef unsigned long long u64;

bool edge[8][8];

u64 dfs(int now, vector< bool > & path, int n)
{
  int p = 0;
  path[now] = true;
  bool full = true;
  for (int i = 0; i < n; ++i) {
    if (!path[i]) {
      full = false;
      break;
    }
  }
  if (full) {
    return 1;
  }
  for (int i = 0; i < n; ++i) {
    if (edge[now][i] && !path[i]) {
      vector< bool > c_path(path);
      p += dfs(i, c_path, n);
    }
  }
  return p;
}

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < 8; ++i) {
    for (int j = 0; j < 8; ++j) {
      edge[i][j] = false;
    }
  }
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    edge[a-1][b-1] = true;
    edge[b-1][a-1] = true;
  }
  int now = 0;
  vector< bool > path(8, false);
  cout << dfs(now, path, n) << endl;

  return 0;
}


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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  vector<int> b(n + 1);

  int count = 0;
  for (int i = 1; i < n + 1; i++) {
    int in;
    cin >> in;
    count += in;
    a[i] = count;
  }
  count = 0;
  for (int i = 1; i < n + 1; i++) {
    int in;
    cin >> in;
    count += in;
    b[i] = count;
  }

  int ma = 0;
  for (int i = 1; i < n + 1; i++) {
    ma = max(ma, a[i] + b[n] - b[i - 1]);
  }
  cout << ma << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 256
import itertools
n,m,x=map(int,input().split())
k=[list(map(int,input().split())) for i in [0]*n]
l=12*10**5+1
a=list(range(n))
for i in range(1,n+1):
    for v in itertools.combinations(a,i):
        s=0
        p=[0]*m
        for j in v:
            q=k[j]
            s+=q[0]
            for b in range(m):
                p[b]+=q[b+1]
        t=1
        for j in p:
            if j<x:
                t=0
        if t:
            l=min([s,l])
print(l) if l<12*10**5+1 else print(-1)

Measured memory_bytes: 9232
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;

signed main() {
	int n;
	cin >> n;
	vector<int> probs(n);
	for (auto&& e : probs) cin >> e;

	sort(probs.begin(), probs.end());
	
	cout << probs[n / 2] - probs[n / 2 - 1] << endl;


	return 0;
}



Measured memory_bytes: 640
#include <cstdio>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	int R;
	int M = -2000000001;
	int m = 2000000001;
    for (int i=0; i < n; i++) {
		scanf("%d", &R);
		M = max(M, R-m);
		m = min(m, R);
	}
	
    printf("%d\n", M);
}


Measured memory_bytes: 2760
#include <stdio.h>              /*入出力 */
#include <stdlib.h>             /*標準ライブラリ */
#include <string.h>             /*文字列 */
#include <math.h>               /*計算 */
#include <assert.h>             /*確認 */
#include <ctype.h>              /*文字操作 */
#include <stdbool.h>            /*bool型 */
#include <limits.h>             /*限界 */
//---------------------------------------------------
#define rep(i, n) for(int  i = 0; i < (n); i++)
#define ABS(a) (((a)>(0))?a:-(a))
#define LL long long
#define MOD 1000000007          //10^9+7(素数)
//---------------------------------------------------
//問題：https://atcoder.jp/contests/DP/tasks/DP_d
//参考：https://qiita.com/drken/items/dc53c683d6de8aeacf5a
//REしかでないので悲しい

//2数の最大値を返す関数
LL max(LL a, LL b)
{
    if (a < b) {
        a = b;
    }
    return a;
}

int main(void)
{
    LL n;                       //品物の総数を格納する変数
    LL W;                       //重さの最大値を格納する変数
    LL weight[110];             //i番目の品物の重さを格納する配列
    LL value[110];              //i番目の品物の重さを価値を格納する配列
    LL *DP[110]; //DP[i+1][w]:=i番目までの品物の中から重さがwを超えないように選んだ時の、価値の総和の最大値
    for (int i = 0; i < 110; i++) {
        DP[i] = (LL *)malloc(100010 * sizeof(LL *));
    }
    for (int i = 0; i < 110; i++) {
        for (int j = 0; j < 100010; j++) {
            DP[i][j] = 0;
        }
    }
    /*
       漸化式
       DP[i+1][w] = max(DP[i][w-weight[i]] + valie[i] , DP[i][w])  (w>= weight[i])
       = DP[i][w]                                       (w < weight[i])
       初期条件
       DP[0][w] = 0(w = 0...w)

       DP[i][w]の値が求まっていることを前提にDP[i+1][w]を考える
     */

    //入力
    scanf("%lld %lld", &n, &W);
    for (LL i = 0; i < n; i++) {
        scanf("%lld %lld ", &weight[i], &value[i]);
    }
    //初期化
    for (LL i = 0; i <= W; i++) {
        DP[0][i] = 0;
    }
    //処理部
    for (LL i = 0; i < n; i++) {
        for (LL j = 0; j <= W; j++) {
            if (j >= weight[i]) {
                DP[i + 1][j] = max(DP[i][j - weight[i]] + value[i], DP[i][j]);
            } else {
                DP[i + 1][j] = DP[i][j];
            }
        }
    }
    //出力
    printf("%lld\n", DP[n][W]);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll s;
	cin>>s;
	ll tmp=s;
	int len=0;
	while(tmp>0){
		++len;
		tmp/=10;
	}
	int ss[20];
	FORR(i, 0, len){
		ss[i]=s%10;
		s/=10;
	}
	ll ans=0;
	for(int i=0; i<1<<(len-1); ++i){
		ll tmp2=0;
		REP(j, len-1){
			tmp2=tmp2*10+ss[j];
			if(i>>j&1){
				ans+=tmp2;
				tmp2=0;
			}
		}
		ans+=tmp2*10+ss[len-1];
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int E = sc.nextInt();
        var arr = new int[] { A, B, C, D, E };
        var ceil = arr.Select(i => (int)Math.Ceiling(i / 10.0) * 10).ToArray();
        var ans = new List<decimal>();
        ans.Add(ceil[0] + ceil[1] + ceil[2] + ceil[3] + arr[4]);
        ans.Add(ceil[0] + ceil[1] + ceil[2] + ceil[4] + arr[3]);
        ans.Add(ceil[0] + ceil[1] + ceil[4] + ceil[3] + arr[2]);
        ans.Add(ceil[0] + ceil[4] + ceil[2] + ceil[3] + arr[1]);
        ans.Add(ceil[4] + ceil[1] + ceil[2] + ceil[3] + arr[0]);
        WriteLine(ans.Min());
    }
}


class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

int main() {
  string s,t;
  cin >> s >> t;
  cout << t+s << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;

string t = "CODEFESTIVAL2016";
int main(){
  string s;
  cin >> s;
  int ans = 0;
  REP(i,16){
    if( s[i] != t[i] )
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 764
def solve():
  H, W = map(int, input().split())
  S = [0]*(H+2)
  S[0] = '*'*(W+2)
  S[H+1] = '*'*(W+2)
  for h in range(1,H+1):
    S[h] = '*' + input() + '*'
  ans = [[0]*W for _ in range(H)]
  dh = [1,1,1,0,-1,-1,-1,0]
  dw = [1,0,-1,-1,-1,0,1,1]
  for h in range(1,H+1):
    for w in range(1,W+1):
      if S[h][w]=='#':
        ans[h-1][w-1]='#'
        continue
      for i in range(8):
        if S[h+dh[i]][w+dw[i]]=='#':
          ans[h-1][w-1] += 1
    ans[h-1] = ''.join(map(str,ans[h-1]))
  return ans
print(*solve(),sep='\n')

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

int ariProSum(const int &first, const int &n, const int &step) {
	int k = n / step;
	int last = first + (k - 1) * step;

	return (first + last) * k / 2;
}

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

	int n;

	cin >> n;

	Out(ariProSum(1, n, 1));
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <set>
#include <functional>

static int const MAX(1000000);

class Mod{
	const int n;
	public:
		Mod(const int _n):n(_n){}
		bool operator()(const int _src){
			return ! (_src % n);
		}
};

const std::vector<int> Eratosthenes(std::set<int>& src){
	std::vector<int> result;
	int cnt(0);
	while(!src.empty()){
	  int n(*src.begin());
		result.push_back(n);
		Mod mod(n);
		//std::set<int>::iterator it= std::remove_if( src.begin(), src.end(), mod );
		// n>(MAX/2) ? std::remove( src.begin(), src.end(), n ) :
		for(int i(n);i<MAX;i+=n)  {
		std::set<int>::iterator it= src.find(i);
		if(it!=src.end())
		   src.erase(it );
		}    
		//src.erase(it,src.end());
	}
	return result;
}


int main(int,char**){
	std::set<int> vec;
	int max_2(MAX-MAX/2-MAX/3-MAX/5+MAX/6+MAX/10+MAX/15-MAX/30+3);
	//	vec.reserve(max_2);
	for(int i(3);i<=MAX;i+=2){
		if(i!=3 && i%3==0) continue;
		if(i!=5 && i%5==0) continue;
		vec.insert(i);
	}
	std::vector<int> primes;
	primes.reserve(10000);
	primes =Eratosthenes(vec);
	int n;
	while(std::cin >>n){
		std::vector<int>::const_iterator const it= std::upper_bound(primes.begin(),primes.end(),n);
		int off=it -primes.begin();
		if(n>=2){ ++off; }
		std::cout << off <<std::endl;
	}
	return 0;
}

Measured memory_bytes: 7068
"use strict";

function main(arg) {
    const input = arg.split("\n")
    let N = Number(input[0])
    input.shift()
    let S = input
    //console.log(N)
    //console.log(S)
    
    let sums = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}
    for(let i=0;i < N; i++) {
        if(S[i]==='AC') {
            sums['AC'] ++
        } else if(S[i]==='WA') {
            sums['WA'] ++
            
        }else if(S[i]==='TLE') {
            sums['TLE'] ++
            
        }else if(S[i]==='RE') {
            sums['RE'] ++
            
        }
    }
    Object.keys(sums).forEach(x=>{
        console.log(`${x} x ${sums[x]}`)
    })


}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 37316
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();
        int C = sc.nextInt();

        System.out.println(solve(A, B, C));
    }

    private static int solve(int A, int B, int C) {
        return B/A < C ? B/A : C;
    }
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  vector<int> res(N, -1);
  res[0] = 0;
  queue<int> que;
  que.push(0);
  while (!que.empty()) {
    int q = que.front();
    que.pop();
    int u = q;
    for (int v : G[u]) {
      if (res[v] != -1) continue;
      res[v] = u;
      que.push(v);
    }
  }
  if (*min_element(res.begin(), res.end()) == -1) {
    cout << "No" << '\n';
  } else {
    cout << "Yes" << '\n';
    for (int i = 1; i < N; i++) {
      cout << res[i] + 1 << '\n';
    }
  }
  return 0;
}


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

using namespace std;

typedef long long LL;
#define N 300

const LL k=60;
LL n,a[N],f[80];
char s[N];

void ins(LL x){
	for (LL i=k;~i;--i){
		if (x>>i&1){
			if (!f[i]){f[i]=x; return;}
			else x^=f[i];
		}
	}
}

bool pd(LL x){
	for (LL i=k;~i;--i){
		if (x>>i&1){
			if (!f[i]) return 0;
			x^=f[i];
		}
	}
	return 1;
}

void solve(){
	scanf("%lld",&n);
	for (LL i=1;i<=n;++i) scanf("%lld",a+i);
	scanf("%s",s+1);
	memset(f,0,sizeof f);
	LL flag=0;
	for (LL i=n;i;--i){
		if (s[i]=='0') ins(a[i]);
		else if (!pd(a[i])){flag=1; break;}
	}
	printf("%lld\n",flag);
}

int main(){
	LL T; scanf("%lld",&T);
	while (T--) solve();
	
	return 0;
}
			

Measured memory_bytes: 3800
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

struct edge {
    int from;
    int to;
    int cost;
    edge(int _from, int _to, int _cost) : from(_from), to(_to), cost(_cost){};
};

vector<edge> ans;

// [add, add + L)のバイパスを作る
void bypass(int add, int L) {
    // cout << L << ":" << add << endl;

    if (L <= 0) return;
    for (int k = 19; k >= 0; --k) {
        if (L >= (1 << k)) {
            // [add, add + 2^k)を作る
            // k本の辺の後、つまり頂点k+1から20に辺を張る
            ans.push_back(edge(k + 1, 20, add));

            // [add + 2^k, add + L)を作る
            bypass(add + (1 << k), L - (1 << k));
            break;
        }
    }
    return;
}

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

    // 0の辺を全部張る
    for (int i = 1; i < 20; ++i) {
        ans.push_back(edge(i, i + 1, 0));
    }

    // 大まかにグラフを作る
    for (int k = 19; k >= 1; --k) {
        if (L >= (1 << k)) {
            // k本辺を張って[0, 2^k)を作る
            for (int i = 1; i <= k; ++i) {
                ans.push_back(edge(i, i + 1, 1 << (i - 1)));
            }

            // [2^k, L)を作る
            bypass(1 << k, L - (1 << k));
            break;
        }
    }

    cout << 20 << " " << ans.size() << endl;
    for (auto e : ans) {
        cout << e.from << " " << e.to << " " << e.cost << endl;
    }
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())

syou, amari = divmod(h, 2)
if w % 2 == 1:
    a = w // 2 + 1
    ans = (a + a - 1)* syou + a * amari
else:
    a = w / 2
    ans = (a + a)* syou + a * amari
if h == 1 or w == 1:
    print(1)
else:
    print(int(ans))

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int Q=1<<18;
struct dt{
    int x,y;
    void R()
    {scanf("%d%d",&x,&y);}
}a[Q];
bool operator<(dt a,dt b)
{return a.y==b.y?a.x<b.x:a.y<b.y;}
int main()
{
    int n,m,q;
    scanf("%d%d%d",&n,&m,&q);
    int ans=n;
    for(int i=1;i<=q;i++)
        a[i].R();
    sort(a+1,a+q+1);
    for(int i=1,mx=0;i<=q;i++){
		int mys=a[i].x+1-a[i].y;
		if(mys<=mx+1)mx=max(mx,mys);
		else ans=min(ans,a[i].x-1);
	}
    printf("%d",ans);
    return 0;
}

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

const int INF = 1001001001;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) cin >> S[i];
    int ans = 0;
    rep(Si, H)rep(Sj, W) {
        if (S[Si][Sj] == '#') continue;
        vector<vector<int>> dist(H, vector<int>(W, INF));
        queue<P> q;
        auto update = [&](int i, int j, int x) {
            if (dist[i][j] != INF) return;
            dist[i][j] = x;
            q.push(P(i, j));  // .emplace(i, j)
        };
        update(Si, Sj, 0);
        while (!q.empty()) {
            int i = q.front().first;
            int j = q.front().second; q.pop();
            rep(dir, 4) {
                int ni = i+di[dir], nj = j+dj[dir];
                if (ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
                if (S[ni][nj] == '#') continue;
                update(ni, nj, dist[i][j]+1);
            }
        }
        rep(i, H)rep(j, W) {
            if (dist[i][j] == INF) continue;
            ans = max(ans, dist[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e3+17;
string str;
int main(int argc ,char const *argv[])
{
   	 #ifdef GoodbyeMonkeyKing
    freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
    #endif	
    cin>>str;
    int ans = 0,st = str.length()/2;
    int src = str[st],c=1;
    if(str.length()&1) c = 0,ans=1;
    debug(st);
    for (int i = 1; st-i >-1; ++i)
    {
  		debug(st-i);
  		debug(st+i-c);
    	if(!((str[st-i]==str[st+i-c])&&(str[st+i-c]==src)))
    		break;
    	ans+=2;
    }
    debug(ans);
    cout<<(ans+str.length())/2<<endl;
    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

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

	int num; cin >> num;
	rep(i, num)
	{
		int mon = 0; cin >> mon;
		int yer = 0; cin >> yer;
		int dat = 0; cin >> dat;
		vector<int> ans(dat, 0);
		rep(j, dat)
		{
			int typ = 0; cin >> typ;
			double per = 0; cin >> per;
			int los = 0; cin >> los;
			int sum = mon, tmp = 0;
			rep(k, yer)
			{
				if (typ == 1){ sum += (int)(sum * per) - los; }
				else if (typ == 0)
				{
					tmp += (int)(sum * per);
					sum -= los;
				}
			}
			ans[j] = sum + tmp;
		}
		printf("%d\n", *max_element(all(ans)));
	}
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

const int INF = 1001001001;

int main(){
  int n;
  cin >> n;
  map<pair<int, int>, int> tr;
  vector<vector<int>> gr(n*(n-1)/2, vector<int>());
  vector<vector<int>> num(n, vector<int>(n-1));
  vector<int> deg(gr.size(), 0);
  int co = 0;
  rep(i, n){
    rep(j, n-1){
      int in;
      cin >> in;
      in--;
      pair<int, int> p(i, in);
      if(p.first > p.second) swap(p.first, p.second);
      if(tr.count(p) != 1){
        tr[p] = co;
        co++;
      }
      num.at(i).at(j) = tr[p];
    }
  }
  rep(i, n){
    int bf = num.at(i).at(0);
    rep2(j, 1, n-1){
      int now = num.at(i).at(j);
      gr.at(bf).push_back(now);
      deg.at(now)++;
      bf = now;
    }
  }

  queue<int> q;
  rep(i, deg.size()){
    if(deg.at(i) == 0)q.push(i);
  }
  vector<int> topo;
  while(!q.empty()){
    int fr = q.front(); q.pop();
    for(auto i : gr.at(fr)){
      deg.at(i)--;
      if(deg.at(i) == 0) q.push(i);
    }
    topo.push_back(fr);
  }
  if(topo.size() != deg.size()){
    cout << -1 << endl;
    return 0;
  }
  
  vector<int> dp(n*(n-1)/2, 1);
  for(auto i : topo){
    for(auto j : gr.at(i)){
      dp.at(j) = max(dp.at(j), dp.at(i)+1);
    }
  }
  int ans = 0;
  rep(i, dp.size()){
    ans = max(ans, dp.at(i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 68720
n = int(input())
s = input()

i = 0
j = 0
ans = 1
while i<n:
    if n-i>1 and s[i+1]==s[i]:
        if j == 0:
            ans *= 6
        elif j == 1:
            ans *= 2
        else:
            ans *= 3
        j = 2
        i+=2
    else:
        if j == 0:
            ans *= 3
        elif j == 1:
            ans *= 2
        j = 1
        i += 1
    ans %= 10**9+7

print(ans)

Measured memory_bytes: 38384
MOD = 10**9+7

n,k = map(int,input().split())

ans = 0
pre,suf = 0,0
for i in range(1,n+2):
    pre += i-1
    suf += n+1-i

    if i >= k:
        ans += suf-pre+1
        ans %= MOD

print(ans)


Measured memory_bytes: 9176