akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define Impossible { cout << "NO\n"; return 0; }

using namespace std;

const int Nmax = 1<<18;

int N, n, i, j, x;
int L[Nmax], R[Nmax], A[Nmax];
bool used[Nmax];
vector<int> open[Nmax];
priority_queue< pair<int,int> > heap;

int reversed(int x)
{
    int i, y = 0;
    for(i=0; i<n; ++i)
        y = (y<<1) | ((x&(1<<i))>0);
    return y;
}

int main()
{
//    freopen("input", "r", stdin);
//    freopen("output", "w", stdout);
    cin.sync_with_stdio(false);

    cin >> n;
    N = (1<<n);

    for(i=0; i<N; ++i) L[i] = 0, R[i] = N-1;

    for(i=0; i<N; ++i)
    {
        cin >> A[i];
        --A[i];
        if(A[i] == -1) continue;

        L[i] = R[i] = A[i];
        used[A[i]] = 1;
    }

    for(i=0; i<N; ++i)
        for(j=0; j<n; ++j)
            if(!(i & (1<<j)))
            {
                x = i ^ (1<<j);
                L[x] = max(L[x], L[i] + 1);
            }

    for(i=N-1; i>=0; --i)
        for(j=0; j<n; ++j)
            if(i & (1<<j))
            {
                x = i ^ (1<<j);
                R[x] = min(R[x], R[i] - 1);
            }

    for(i=0; i<N; ++i)
    {
        if(L[i] > N-1 || R[i] < 0 || L[i] > R[i]) Impossible;
        open[R[i]].push_back(i);
    }

    for(i=N-1; i>=0; --i)
    {
        for(auto it : open[i])
            heap.push({ L[it], it + (A[it] != -1 ? N : 0) });

        if(heap.empty()) Impossible;

        if(heap.top().second < N)
        {
            A[heap.top().second] = i;
            if(L[heap.top().second] > i) Impossible;
        }

        heap.pop();
    }

    cout << "YES\n";
    for(i=0; i<N; ++i)
        cout << A[reversed(i)] + 1 << ' ';

    return 0;
}


Measured memory_bytes: 19584
# -*- coding: utf-8 -*-


def main():
    s = input()
    r = [0] * len(s)
    rl_point = -1
    st = [0, 0]
    st_point = 0

    s_bp = s + 'R'
    for i in range(len(s)):
        c = s_bp[i]
        nc = s_bp[i + 1]
        if c == 'R' and nc == 'R':
            # st に値を貯める
            st[st_point] += 1
            st_point = (st_point + 1) % 2
        elif c == 'R' and nc == 'L':
            rl_point = i
            r[rl_point] = 1 + st[st_point]
            r[rl_point + 1] = st[(st_point + 1) % 2]
            st_point = (st_point + 1) % 2
        elif c == 'L' and nc == 'R':
            r[rl_point + (i - rl_point) % 2] += 1
            # 初期化
            rl_point = -1
            st = [0, 0]
            st_point = 0
        elif c == 'L' and nc == 'L':
            r[rl_point + (i - rl_point) % 2] += 1
        else:
            pass

        prev = c

    print(' '.join(map(str, r)), flush=True)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10596
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,i,ki,x;
	scanf("%d",&n);
	ki=0;
	for(i=0;i<n;i++)	{
		scanf("%d",&x);
		if(x%2==1)	ki++;
	}
	if(ki%2==1)	printf("NO\n");
	else printf("YES\n");
	return 0;
}

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

A = X
i = 1
sigma = X
A_list = [None, X]
A_sigma = [None, X]
A_index = {X: 1}
cycled = False
while i < N:
    A = A*A % M
    i += 1
    sigma += A

    if cycled: continue

    A_list.append(A)
    A_sigma.append(sigma)
    if A not in A_index:
        A_index[A] = i
    else:
        cycle_len = i - A_index[A]
        cycles = (N-i) // cycle_len
        sigma += (sigma - A_sigma[A_index[A]]) * cycles
        i += cycles * cycle_len
        cycled = True

print(sigma)


Measured memory_bytes: 80180
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll A, B;
    string good = "Yay!";
    string bad = ":(";

    cin >> A >> B;

    if (A <= 8 && B <= 8) cout << good << endl;
    else cout << bad << endl;

    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    cout << pow(n, 3) << endl;
    return 0;
}


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

#define EPS 1e-6
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using namespace std; 

using ll = long long;
using ii = pair<int,int>;

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

  ll a, b; cin >> a >> b;
  if ((a + b) & 1) cout << "IMPOSSIBLE" << ende;
  else cout << (a+b) / 2 << ende;

  return 0;
}


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

int main()
{
  ll int l,r;
  cin>>l>>r;
  if(abs(r-l)>2020)
  {
    cout<<"0";
    return 0;
  }
  l=l%2019;
  r=r%2019;
  if(l>r) 
    swap(l,r);
  int ans=1e6;
  for(int i=l;i<=r;i++)
  {
    for(int j=i+1;j<=r;j++)
    {
      ans=min(ans,(i*j)%2019);
    }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int san = 0;
        int cho = 0;
        int ei = 0;
        int don = 0;
        String line;

        while((line = br.readLine()) != null){
            String[] input = line.split(" " , 3);
            int[] sides = new int[3];
            
            for(int i = 0; i < 3; i++)  sides[i] = Integer.parseInt(input[i]);

            boolean isTriangle = (sides[0]+sides[1]>sides[2]) && (sides[1]+sides[2]>sides[0]) && (sides[2]+sides[0]>sides[1]);

            if(isTriangle){
                san++;
                Arrays.sort(sides);
                for(int i = 0; i < 3; i++)  sides[i] = sides[i] * sides[i];

                if(sides[0] + sides[1] < sides[2])      don++;
                else if(sides[0] + sides[1] > sides[2]) ei++;
                else cho++;

            }else{
                break;
            }

        }

        System.out.println(san + " " + cho + " " + ei + " " + don);
    }
}

Measured memory_bytes: 24496
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;
lint p=1e9+7;
lint pow2[200001];

lint pow_mod(lint a,lint b,lint p){
  if(b==0)return 1;
  if(b%2==0){
    lint d=pow_mod(a,b/2,p);
    return (d*d)%p;
  }else{
    return (a*pow_mod(a,b-1,p))%p;
  }
}

//x / a mod p=x * inv_mod(a,p) 
lint inv_mod(lint a,lint p){
  return pow_mod(a,p-2,p);//(a^(p-2))mod p
}

int main(){
  pow2[0]=1;
  FOR(i,1,2e5+1)pow2[i]=(pow2[i-1]*2)%p;
  int N;
  cin>>N;
  vector<int> c[N];
  REP(i,N-1){
    int A,B;
    cin>>A>>B;
    A--;B--;
    c[A].push_back(B);
    c[B].push_back(A);
  }
  stack<int> s;
  vector<int> k[N];
  bool d[N];
  REP(i,N)d[i]=false;
  s.push(0);
  while(!s.empty()){
    int now=s.top();
    d[now]=true;
    // cerr<<now<<endl;
    if(c[now].empty()){
      s.pop();
      int sum=1;
      for(auto e:k[now])sum+=e;
      if(!s.empty())k[s.top()].push_back(sum);
    }else{
      int next=c[now].back();
      if(d[next]){
          c[now].pop_back();
          continue;
      }
      s.push(next);
      c[now].pop_back();
    }
  }
  FOR(i,1,N){
    int sum=N-1;
    for(auto e:k[i])sum-=e;
    k[i].push_back(sum);
  }
  // REP(i,N){
  //   for(auto e:k[i])cerr<<e<<" ";
  //   cerr<<endl;
  // }
  lint ans=0;
  REP(i,N)if(k[i].size()>1){
    lint temp=pow2[N-1];
    temp-=1;
    for(auto e:k[i]){
      temp+=p;
      temp-=pow2[e]-1;
      temp%=p;
    }
    // cerr<<temp<<endl;
    ans+=temp;
    ans%=p;
  }
  cout<<(ans*inv_mod(pow2[N],p))%p<<endl;
  return 0;
}


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

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 n;
    cin >> n;
    vector<ll> ans(n,0);
    rep(i,n-1){
        ll tmp;
        cin >> tmp;
        tmp --;
        ans[tmp]++;
    }

    rep(i,n){
        cout << ans[i] << endl;
    }
}  



Measured memory_bytes: 4840
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

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

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

const ll mod = 1e9 + 7;
const ll IMF = 1LL << 60;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//





//入力
string s,t;

//DPテーブル
int dp[3100][3100] = {0};

int main(){
        cin >> s >> t;

        for(int i = 0; i < s.size(); i++){
                for(int j = 0; j < t.size(); j++){
                        if(s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j] + 1);
                        chmax(dp[i+1][j+1], dp[i+1][j]);
                        chmax(dp[i+1][j+1], dp[i][j+1]);
                }
        }

        //復元
        string res = "";
        int i = (int)s.size(), j = (int)t.size();
        while(i > 0 && j > 0)
        {
                if(dp[i][j] == dp[i-1][j]){
                        --i;
                }

                else if(dp[i][j] == dp[i][j-1]){
                        --j;
                }

                else{
                        res = s[i-1] + res;
                        --i, --j;
                }
        }

        cout << res << endl;
}













































Measured memory_bytes: 37120
#include <iostream>
using namespace std;
typedef long long ll;
int main( void )
{
  ios::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  ll ret = 1900 * M + 100 * (N-M);
  for( ll i=0; i<M; i++ ) ret *= 2;
  cout << ret << endl;
}

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

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

  string str;
  cin>>str;

  int i=0,j=n-1,count=0;

  while(i<=j)
  {
     if(str[i] == 'W')
     {
       if(str[j] == 'R')
       {
         swap(str[i],str[j]);
         count++;
         i++;
         j--;
       }
       else
         j--;
     }
     else
       i++;
  }

  cout<<count;
}


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

int main(){
  string s,t; cin>>s>>t;
  int count1=t.size(),count2;
  for(int i=0;i<s.size()-t.size()+1;i++){
    count2=0;
    string sub;
    sub=s.substr(i,t.size());
    for(int j=0;j<t.size();j++){
      if(sub[j]!=t[j])
        count2++;
    }
    if(count1>count2)
      count1=count2;
  }
  cout<<count1<<endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<cmath>
using namespace std;

int ans[100000];

void solve6() {
	string str;

	int N, M;
	string s;
	
	int *S;
	int len = 0;
	cin >> N >> M>>s;
	N++;
	S = new int[N];
	
	
	for (int i = 0;i < N;i++)S[i] = (int)(s[i])-48;

	

	for (int i = 0;i < N / 2+1 ;i++) {
		int tmp = S[i];
		S[i] = S[N - 1 - i];
		S[N - 1 - i] = tmp;
	}
	for (int i = 0;i < 100000;i++)ans[i] = -1;
	
	int x = 0;
	bool flag = true;
	while (flag) {
		for (int i = M;i > 0;i--) {
			if (x + i < N) {
				if (S[x + i] == 0) {
					ans[len] = i;
					x += i;
					len++;
					break;
				}
			}
			if (i == 1) {
				
				flag = false;
			}
		}
		

		
		if (x == N - 1) {
			
			break;
		}
	}
	if (flag) {
		for (int i = len - 1;i >= 0;i--)cout << ans[i] << " ";
	}
	else {
		cout << -1 << endl;
	}
	
}

int main() {

	solve6();
}

Measured memory_bytes: 1408
using System;
using System.Linq;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		Console.ReadLine();
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
		int[] intArray = input
			.Select(int.Parse)
			.ToArray();
      	Array.Sort(intArray);
      	var target = intArray[intArray.Length - 1];
      	var num = 1;
      	var total = 0;
      	for (var i = intArray.Length - 2; i >= 0; i--) {
          if (target == intArray[i]) {
            num++;
          } else {
            if (target > num) {
              total += num;
            } else if (target < num) {
              total += num - target;
            }
            num = 1;
            target = intArray[i];
          }
        }
      	if (target > num) {
          total += num;
        } else if (target < num) {
          total += num - target;
        }
      		
      
		//出力
		Console.WriteLine(total);
	}
}

Measured memory_bytes: 30300
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
#if DEBUG
            ReadLine();
#endif
        }

        void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;

            int a = cin.ReadInt;
            int b = cin.ReadInt;

            int[] p = cin.ReadIntArray(n);


            int[] ans = new int[3]; 
            foreach(int pnt in p)
            {
                if(pnt <= a)
                {
                    ans[0]++;
                }
                else if(a  < pnt && pnt <= b)
                {
                    ans[1]++;
                }
                else
                {
                    ans[2]++;
                }
            }

            Console.WriteLine(ans.Min());

        }

        class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;

            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }

            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }

            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


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

int main() {
  string c[12]={"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
  int T;
  cin >> T;
  while(T--) {
    int n,m;
    cin >> n >> m;
    string s[n],t[m];
    for(int i=0; i<n; i++) cin >> s[i];
    for(int i=0; i<m; i++) cin >> t[i];
    bool ck=0;
    for(int k=1; k<3; k++) {
      int x=n-k;
      for(int i=m-1; i>=0; i--) {
	if(x<0 || x>=n) {x=1<<29;break;}
	int p;
	for(p=0; p<12; p++) if(c[p]==s[x]) break;
	if(t[i]==c[p]) x--;
	else if(t[i]==c[(p+1)%12]) x-=2;
	else if(t[i]==c[(p+11)%12]) x++;
	else {x=1<<29;break;}
      }
      if(x==-1) ck=1;
    }
    if(ck) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 6680
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll N;
    scanf("%lld", &N);
    printf("%lld\n", N/3);
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int n;
    cin>>n;
    ll ans=0;
    int t=-inf;
    rep(i,n){
        int a;
        cin>>a;
        if(a>=t){
            t=a;
        }
        else{
            ans+=(t-a);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

int main()
{
    int n;
    cin>>n;
    vector<int> a(n+1);
    vector<int> b(n);
    for(int i=0;i<=n;i++){
        cin>>a.at(i);
    }
    for(int i=0;i<n;i++){
        cin>>b.at(i);
    }
    ll count=0;
    for(int i=0;i<n;i++){
        if(a.at(i)>=b.at(i)){
            count+=b.at(i);
        }
        else{
            count+=a.at(i);
            b.at(i)-=a.at(i);
            if(a.at(i+1)>=b.at(i)){
                count+=b.at(i);
                a.at(i+1)-=b.at(i);
            }
            else{
                count+=a.at(i+1);
                a.at(i+1)=0;
            }
        }
    }
    cout<<count<<endl;

}

Measured memory_bytes: 1024
n = int(input())
li = list(map(int,input().split()))

ans = 0
cnt = 0
temp = -1

for i in range(len(li)):
    if  temp == li[i]:
        cnt += 1
        continue
    else:
        temp = li[i]
        ans += cnt//2
        cnt = 1
else:
    ans += cnt//2
    
        
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#define fs first
#define se second

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<ld, ld> pdd;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    llong x, y;
    cin >> x >> y;
    if (x % 3 != y % 3) {
        if ((x + 2) % 3 == y % 3) --x;
        else --y;
    }
    if (x != y) printf("Alice\n");
    else printf("Brown\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int idx_a = s.find("A");
    int idx_z = s.rfind("Z");
    cout << idx_z - idx_a + 1 << endl;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
#define N 200005
#define M 2000
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N

using namespace std;
queue< int > q;
int dis[N];
int vis[N];
vector< vector< int > > adj(N);
int n,m;
int pa[N];
void bfs(int x){
    for(int i=0;i<n;i++)
        dis[i]=n+2;
    dis[x] = 0;
    q.push(0);
    while(!q.empty()){
        int x = q.front();
        q.pop();
        if(vis[x])continue;
        vis[x] = 1;
        for(auto ch:adj[x]){
            if(vis[ch])continue;
            if(dis[ch]>dis[x]+1){
                q.push(ch);
                pa[ch]= x;
                dis[ch] = dis[x]+1;
            }
        }
    }
}
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
     cin>>n>>m;
     for(int i=0;i<m;i++){
         int u,v;
         cin>>u>>v;;
         u--; v--;
         adj[u].pb(v);
         adj[v].pb(u);
     }
     bfs(0);
     for(int i=0;i<n;i++)
     if(!vis[i]){
         cout<<"No";return 0;
     }
     cout<<"Yes\n";
     for(int i=1;i<n;i++)
        cout<<pa[i]+1<<"\n";
}


Measured memory_bytes: 16876
#include "bits/stdc++.h"
using namespace std;
#define OUT(x)                cout << #x << " = " << x << endl; 
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v)            for (auto i : v)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
#define pb(x)                 push_back(x)
#define bp(x)                 __builtin_popcount(x)
#define mp(x, y)              make_pair((x), (y))
#define fi                    first
#define se                    second
#define setp(x)               setprecision(x)
#define mset(m, v)            memset(m, v, sizeof(m))
#define sz(x)                 (int)(x.size())
static const int INF        = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD        = 1000000007;
static const double PI      = 3.14159265358979;

//#define int                   long long

typedef vector<double>        vd;
typedef vector<string>        vs;
typedef vector<bool>          vb;
typedef vector<int>           vi;
typedef pair<int, int>        pii;
typedef vector<pii>           vpii;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int _x; scanf("%d", &_x); return _x; }
long long lin() {long long _x; scanf("%lld", &_x); return _x; };

template<class T>
class BinaryIndexedTree {
private:
	vector<T> nodes;
	int p;
 
public:
	BinaryIndexedTree(int n) : nodes(n + 1), p(1 << (int)log2(n)) {}
 
	void add(int index, T value) {
		for (int i = index + 1; i < nodes.size(); i += i & -i) {
			nodes[i] += value;
		}
	}
 
	T sum(int index) {
		T s = 0;
		for (int i = index; i > 0; i &= i - 1) {
			s += nodes[i];
		}
		return s;
	}
 
	T sum(int l, int r) {
		return sum(r) - sum(l);
	}
 
	int lowerBound(int k) {
		if (k == 0) {
			return 0;
		}
		int v = 0;
		for (int i = p; i > 0; i >>= 1) {
			if (v + i < nodes.size() && nodes[v + i] < k) {
				k -= nodes[v + i];
				v += i;
			}
		}
		return v + 1;
	}
};

signed main() { 
        int n, m;
        cin >> n >> m;
        BinaryIndexedTree<int> bit(m + 10);
        vi l(n), r(n);
        vi a[101010];
        rep(i, n) {
                cin >> l[i] >> r[i];
                r[i] ++;
                a[r[i] - l[i]].pb(i);
        }
        int len = n;
        rer(i, 1, m) {
                each(j, a[i]) {
                        bit.add(l[j], 1);
                        bit.add(r[j], -1);
                        len --;
                }
                int ans = len;
                for (int j = 0; j <= m; j += i) {
                        ans += bit.sum(j + 1);
                }
                cout << ans << endl;
        }
        return 0;
}               


Measured memory_bytes: 9088
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;


int main() {
    string s;
    int a;
    vector<pair<pair<string,int>,int>> v;
    int n;
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>s>>a;
        v.push_back({{s,-a},i});
    }
    sort(v.begin(),v.end());
    for(auto e:v){
        cout<<e.second+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
require 'set'

n, m, tax = gets.strip.split.map(&:to_i)
abc = readlines.map {|line| line.strip.split.map(&:to_i) }
abc = abc.map {|a, b, c| [a, b, -1*(c-tax)] }

# get adjuscent list
graph = Array.new(n+1) { [] }
r_graph = Array.new(n+1) { [] }
abc.each do |a, b, c|
  graph[a] << b
  r_graph[b] << a
end

# build from_1 from_n
def reachable(s, g)
  q=[s]
  visited = Set.new()
  until q.empty?
    from = q.shift
#    next if visited.include?(from)
    visited.add(from)
    g[from].each do |to|
      next if visited.include?(to)
      visited.add(to)
      q.push(to)
    end
  end

  visited
end

from_1 = reachable(1, graph)
from_n = reachable(n, r_graph)
av = from_1 & from_n
edges=abc.select {|a, b, c| av.include?(a) && av.include?(b) }

#p av
#p edges

# b-f method
updated = false
INF= 10**12
dist = Array.new(n+1, INF)
dist[1]=0
n.times do
  updated = false
  edges.each do |a, b, c|
    next if dist[a]==INF || dist[b] <= dist[a] + c

    dist[b] = dist[a] + c
    updated = true
  end
  break unless updated
end

if updated
  p -1
  exit
end

# answer
p [0, -dist[n]].max




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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

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

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

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

int main(){
    bool flag=false;
    ll mx=0,mn=0,free=0;

    int n;
    cin >>n;
    map<int,int>col;

    rep(i,n){
        int rate;
        cin >>rate;
        int c=rate/400;
        
        if(c < 8 && col[c] != 1){
            col[c]=1;
            ++mn;
        }else if(c >= 8){
            free++;
        }
    }
    if(mn==0 && free!=0){
        mn=1;
        mx=free;
    }else{
        mx = mn+free;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<mn << " "<<mx<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
const int up=1000*1000;
int n[up];
bool comp[up];
int main() {
	int r=0;
	for(LL i=2;i<up;i++){
		if(comp[i]==false){
			r++;
			for(LL j=i*i;j<up;j+=i){
				comp[j]=true;
			}
		}
		n[i]=r;
	}
	int k;
	while(cin >> k)
	{
		cout << n[k] << endl;
	}
}

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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int A, B, T;
    cin >> A >> B >> T;
    cout << (T / A) * B;
}

Measured memory_bytes: 256
#include <cstdio>
int a[10];
int ans[10];
bool get;
void dfs(int x,int sum){
	if(x==4){
		if(sum==7){
			get=1;
		}
		return;
	}
	if(get){
		return;
	}
	ans[x]=-1;
	dfs(x+1,sum-a[x+1]);
	if(get){
		return;
	}
	ans[x]=1;
	dfs(x+1,sum+a[x+1]);
	if(get){
		return;
	}
	ans[x]=0;
}
int main(){
	for(int i=1;i<=4;i++){
		scanf("%1d",&a[i]);
	}
	dfs(1,a[1]);
	for(int i=1;i<4;i++){
		printf("%d%c",a[i],(ans[i]==-1?'-':'+'));
	}
	printf("%d=%d\n",a[4],7);
	return 0;
}


Measured memory_bytes: 128
/*input
30
*/

#include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e5 + 4;

char s[N];
int cnt[2];

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

  int x; cin >> x;
  cout << ((x < 30) ? "No" : "Yes") << endl;

  return 0;
}

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

int main() {
  string n;
  cin >> n;
  
  for(int i = 0; i < 3; i++){
    if(n.at(i)=='7'){
      cout << "Yes" << endl;
      break;
    }
    else if(i==2 && n.at(i) != '7'){
      cout << "No" << endl;
    }
    else{
      continue;
    }
    
  }
    

}

Measured memory_bytes: 3628
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,T,*ab = map(int, read().split())

    AB = []
    for a, b in zip(*[iter(ab)]*2):
        AB.append((a, b))

    AB.sort()
    
    dp = [[0] * (T+1) for _ in range(N+1)]

    ans = 0
    for i in range(N):
        w_i, v_i = AB[i]
        for j in range(T):
            if j < w_i:
                dp[i+1][j] = dp[i][j]
            else:
                dp[i+1][j] = max(dp[i][j - w_i] + v_i, dp[i][j])
        
        ans = max(ans, dp[i][T-1] + v_i)
    
    print(ans)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 112732
from collections import defaultdict
from itertools import count



def bellman_ford(edges, start_node, node_size):
    INF = float("inf")
    cost_table = [INF] * node_size
    cost_table[start_node] = 0
    for i in range(node_size):
        for f, t, c in edges:
            if cost_table[f] != INF and cost_table[f] + c < cost_table[t]:
                cost_table[t] = cost_table[f] + c

    negative = [False] * node_size
    for i in range(node_size):
        for f, t, c in edges:
            if cost_table[f] != INF and cost_table[f] + c < cost_table[t]:
                cost_table[t] = cost_table[f] + c
                negative[t] = True

            if negative[f]:
                negative[t] = True

    if negative[-1]:
        return "inf"
    else:
        return -cost_table[-1]



def main():
    N, M = map(int, input().split())
    edges = []
    for _ in range(M):
        a, b, c = map(int, input().split())
        edges.append((a - 1, b - 1, -c))
    print(bellman_ford(edges, 0, N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    int x,a,b;
    cin >> x >> a >> b;
    if(abs(x-a)>abs(x-b)){
        cout << "B" << endl;
    }else{
        cout << "A" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  char c;
  cin >> c;
  if ((c == 'a')||(c == 'i')||(c == 'u')||(c == 'e')||(c == 'o')){
    cout << "vowel" <<endl;
  }
  else{
    cout << "consonant" <<endl;
  }
}

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

void check(unsigned long *a, unsigned long *b, int n)
{
/*
for( int loop = 0; loop < n+1; loop ++ ) {
    cerr << a[loop];
  }
  cerr << endl;
  
  for( int loop = 0; loop < n; loop ++ ) {
    cerr << b[loop];
  }
  cerr << endl;
*/
}  

int main(void)
{
  int n;
  
  cin >> n;
  
  unsigned long a[n+1];
  unsigned long b[n];
  unsigned long long all = 0;
  
  for( int loop = 0; loop < n+1; loop ++ ) {
    cin >> a[loop];
  }
  
  for( int loop = 0; loop < n; loop ++ ) {
    cin >> b[loop];
  }

  check(a,b,n);
  for( int loop = 0; loop < n; loop ++ ) {
    if ( a[loop] >= b[loop]) {
      all += b[loop];
      a[loop] -= b[loop];
      b[loop] = 0;
  check(a,b,n);
    }
    else {
      all += a[loop];
      b[loop] -= a[loop];
      a[loop] = 0;
  check(a,b,n);

      if ( a[loop+1] >= b[loop]) {
        all += b[loop];
        a[loop+1] -= b[loop];
        b[loop] = 0;
  check(a,b,n);
      }
      else {
        all += a[loop+1];
        b[loop] -= a[loop+1];
        a[loop+1] = 0;
  check(a,b,n);
      }
    }
        
  }
  
  check(a,b,n);
  cout << all << endl;
  
  return 0;
}
  
  
  

Measured memory_bytes: 1792
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
string st1;
int len;
int main()
{
cin>>st1;
cout<<st1[0];
for(int i=1; i<st1.size()-1; i++)len++;
cout<<len<<st1[st1.size()-1]<<endl;
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int isPrime(int n, int x) {
  int i;
    if (x == 2) {
      return 1;
    }

    if (x < 2 || x % 2 == 0) {
      return 0;
    }

    i = 3;

    while (i <= sqrt(x)) {
      if (x % i == 0) {
        return 0;
      }
      i = i + 2;
    }
    return 1;
}

int main(void) {
  int i, n, a[100000], count = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (isPrime(n, a[i]) == 1) {
      count++;
    }
  }
  printf("%d\n", count);
  return 0;
}



Measured memory_bytes: 2060
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main (){

  double x1,y1,x2,y2,d;

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

  d=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);

  printf("%0.8f\n",sqrt(d));

  return 0;

}

Measured memory_bytes: 1240
s=input()
a=int(s[0:2])
b=int(s[2:])
if 1<=a<=12 and 1<=b<=12:
    print('AMBIGUOUS')
elif 1<=b<=12:
    print('YYMM')
elif 1<=a<=12:
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 8888
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
ll a,b,c,sum;int res;
int main(){
	scanf("%lld%lld%lld",&a,&b,&c);
	sum=a+b+c;
	while(true){
		if((a&1)|(b&1)|(c&1))return printf("%d\n",res),0;
		a=(sum-a)>>1,b=(sum-b)>>1,c=(sum-c)>>1;
		if(++res>1e6)return puts("-1"),0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <map>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> A(n);
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
        sum += A[i];
    }
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        if (sum <= A[i]*4*m)
        {
            count++;
        }
    }
    if (count >= m)
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    
    
}

Measured memory_bytes: 3600
#include <stdio.h>
int main(void){
    // Your code here!
    int logc , bonus , goal;
    int result = 0;
    int max;
    int week;
    scanf( "%d %d %d" , &logc , &bonus , &goal );
    
    max = logc * 7 + bonus;
    
    if( bonus != 0 ){
        if( goal > max ){
            week = goal / max;
            goal -= ( max * week );
            result = week * 7;
            //printf( "%d %d %d \n" , max, goal , result );
        }
    }
    
    if( goal >= logc * 7 ){
        goal -= max;
        result += 7;
        //printf( "%d %d %d \n" , max, goal , result );
    }
    
    while( goal > 0 ){
        goal -= logc;
        result++;
    }
    
    printf( "%d\n" , result );
}



Measured memory_bytes: 2112
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> P;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    int n,l;
    cin>>n>>l;
    vector<string> v;
    rep(i,n){
        string s;
        cin>>s;
        v.pb(s);
    }
    sort(all(v));
    rep(i,n){
        cout<<v[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
N,K=map(int, raw_input().split())

torisu=(N-1)*(N-2)/2

if torisu<K:
	print -1
	quit()

print N-1+(torisu-K)

for i in range(2,N+1):
	print 1, i

cnt=0
for i in range(2,N+1):
	for j in range(i+1,N+1):
		if cnt==torisu-K:
			quit()
		print i,j
		cnt+=1


Measured memory_bytes: 33260
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
string str;
int h,w;
char a[105][105];
int reached[105][105];
int sum;
int i,j;
 
void search(int x,int y, char z)
{
     if(y<0 || w<=y || x<0 || h<=x || a[x][y]!=z)return;
     if(reached[x][y])return;
     reached[x][y]=1;
     search(x+1,y,z);
     search(x-1,y,z);
     search(x,y+1,z);
     search(x,y-1,z);  
}

int main()
{
 
  while(1){

    cin>>h>>w;
    if(h==0 && w==0)break;

    for(i=0;i<h;i++)
      for(j=0;j<w;j++)
	reached[i][j]=0;

    sum=0;

    for(i=0;i<h;i++){
      cin>>str;
      for(j=0;j<w;j++)
	a[i][j]=str[j];
    }

    for(i=0;i<h;i++)
      for(j=0;j<w;j++)
	if(reached[i][j]==0 && a[i][j]=='@'){
	  search(i,j,'@');
	  sum++;
	}
    for(i=0;i<h;i++)
      for(j=0;j<w;j++)
	if(reached[i][j]==0 && a[i][j]=='#'){
	  search(i,j,'#');
	  sum++;
	}
    for(i=0;i<h;i++)
      for(j=0;j<w;j++)
	if(reached[i][j]==0 && a[i][j]=='*'){
	  search(i,j,'*');
	  sum++;
	}

    cout<<sum<<endl;
  }//endwhile

}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()
#define size_of(a) (int)a.size()

// uniof-find
struct UnionFind {
private:
	vector< int > data;
	
public:
	UnionFind(int _size) : data(_size, -1) {}
	
	bool unionSet(int _x, int _y) {
		_x = root(_x); _y = root(_y);
		if (_x != _y) {
			if (data[_y] < data[_x]) swap(_x, _y);
			data[_x] += data[_y]; data[_y] = _x;
		}
		return _x != _y;
	}
	
	bool sameSet(int _x, int _y) { return root(_x) == root(_y); }
	
	int root(int _x) { return data[_x] < 0 ? _x : data[_x] = root(data[_x]); }
	
	int size(int _x) { return -data[root(_x)]; }
};

// minimum spanning tree --- with union-find
struct MST {
private:
	typedef int cost_type;
	
	struct MS_Edge {
		int from, to; cost_type cost; bool can, use;
		MS_Edge(int _from, int _to, cost_type _cost, bool _can, bool _use)
		 : from(_from), to(_to), cost(_cost), can(_can), use(_use) {}
		bool operator < (const MS_Edge& _a) const { return this->cost < _a.cost; }
	};
	
	int V;
	vector< MS_Edge > edges;
	
public:
	MST(int _n) : V(_n) {}
	
	void add_edge(int _from, int _to, cost_type _cost, bool can) {
		edges.push_back(MS_Edge(_from, _to, _cost, can, 0));
	}
	
	void solve() {		
		sort(allof(edges));
		
		int C = get_min_cost(1);
		
		int ans1 = 0, ans2 = 0;
		
		int e_size = size_of(edges);
		for_(i,0,e_size) {
			if (edges[i].use) {
				edges[i].can = false;
				
				int CC = get_min_cost(0);
				
				if (CC > C) {
					++ans1;
					ans2 += edges[i].cost;
				}
				
				edges[i].can = true;
			}
		}
		
		cout << ans1 << " " << ans2 << endl;
	}
	
	cost_type get_min_cost(bool f) {		
		UnionFind uf(V);
		cost_type res = cost_type();
		int e_size = size_of(edges), cnt = 0;
		
		for_(i,0,e_size) {
			MS_Edge &e = edges[i];
			if (e.can && !uf.sameSet(e.from, e.to)) {
				uf.unionSet(e.from, e.to);
				res += e.cost;
				if (f) e.use = true;
				++cnt;
			}
		}
		
		return cnt == V - 1 ? res : 1e9;
	}
};

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

	MST mst(N);
	
	for_(i,0,M) {
		int a, b, c; cin >> a >> b >> c;
		--a; --b;
		mst.add_edge(a, b, c, 1);
	}
	
	mst.solve();
	
	return 0;
}

Measured memory_bytes: 2052
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		final int N = sc.nextInt();
		final int K = sc.nextInt();
		final int Q = sc.nextInt();
		final int[] A = nextIntArray(sc, Q);

		sc.close();

		long[] point = new long[N + 1];
		Arrays.fill(point, K - Q);

		for (int i = 0; i < A.length; i++) {
			point[A[i]]++;
		}

		StringBuilder ans = new StringBuilder();
		for (int i = 1; i <= N; i++) {
			if (point[i] <= 0) {
				ans.append("No\n");
			} else {
				ans.append("Yes\n");
			}
		}

		out.print(ans.toString());

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 52472
import java.util.Scanner;



public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		//
		//        int a = scan.nextInt();
		//        int b = scan.nextInt();
		//        int c = scan.nextInt();

		String s = scan.next();
		char[] c = s.toCharArray();

		int cunt = 0;

	//	for (int i = 0; i < c.length; i++) {
			if (c[0] == '1') // looking for 'a' only
				cunt++;
			if (c[1] == '1')
				cunt++;
			if (c[2] == '1') {
				cunt++;
			}
		//}
		System.out.println(cunt);

	}
}

Measured memory_bytes: 21844
from collections import defaultdict
from typing import Dict


class Players(object):
    def __init__(self):
        self.players: Dict[int, "Player"] = {}
        self.reservation = defaultdict(list)
        self.square = None
        self.goal = []

    def set_goal(self, x, y):
        self.goal.append((x, y))

    def add(self, player: "Player"):
        self.players[len(self.players)] = player

    def search_all(self):
        for i, player in self.players.items():
            x, y, d = player.search(self.square)
            self.reservation[(x, y)].append(((d-2)%4, i))
        for k, v in self.reservation.items():
            if len(v) == 1:
                continue
            self.reservation[k] = [min(v)]

    def move_all(self):
        for (x, y), l in self.reservation.items():
            _id = l[0][1]
            _x, _y = self.players[_id].pos
            self.players[_id].move(x, y)
            self.square[_y][_x], self.square[y][x] = ".", "o"

        self.reservation.clear()
        for i, player in self.players.copy().items():
            x, y = player.pos
            if (x, y) in self.goal:
                del self.players[i]
                self.square[y][x] = "."

    @property
    def is_finished(self):
        return len(self.players) == 0


class Player(object):
    dir_dict = {"E": 0, "N": 1, "W": 2, "S": 3}
    dir_diff = ((1, 0), (0, -1), (-1, 0), (0, 1))

    def __init__(self, x, y, direction):
        self.x = x
        self.y = y
        self.dir = self.dir_dict[direction]

    def search(self, square):
        for i in range(self.dir-1, self.dir+3):
            dx, dy = self.dir_diff[i % 4]
            if square[self.y+dy][self.x+dx] in (".", "X"):
                self.dir = i % 4
                return self.x+dx, self.y+dy, self.dir
        else:
            return self.x, self.y, self.dir

    def move(self, x, y):
        self.x, self.y = x, y

    @property
    def pos(self):
        return self.x, self.y


while True:
    W, H = map(int, input().split())
    if W == 0:
        break
    square = []
    players = Players()
    for y in range(H):
        square.append(list(input()))
        for x, c in enumerate(square[-1]):
            if c in "ENWS":
                players.add(Player(x, y, c))
            elif c == "X":
                players.set_goal(x, y)
    players.square = square

    for i in range(1, 121):
        players.search_all()
        players.move_all()
        if players.is_finished:
            print(i)
            break
    else:
        print("NA")


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define inf int(1e9)
#define half_inf int(1e5)
#define ll_inf ll(1e9)*ll(1e9)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int mod = 1000000007;


void solve() {
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    if (abs(a - b) % 2 != 0) cout << "Borys" << endl;
    else cout << "Alice" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>

using namespace std;
int main(){
    char b;
    cin >> b;

    if(b == 'A'){
        b = 'T';
    }else if(b == 'T'){
        b = 'A';
    }else if(b == 'C'){
        b ='G';
    }else if(b == 'G'){
        b ='C';
    }
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long x,y;
int main(){
    scanf("%lld %lld",&x,&y);
    if(x%y==0)return 0*puts("-1");
    for(long long i=1;;i++){
        if((x*i)%y!=0){
            return 0*printf("%lld\n",x*i);
        }
    }
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    string v=s+t;
    for(int i=0;i<n;i++){
        cout<<v[i]<<v[i+n];
    }
    cout<<endl;
}


Measured memory_bytes: 256