akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n;
        cin >> n;
        int a[n];
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        int k = 1;
        for(int i = 0; i < n; i++){
            if(a[i] == k){
                k++;
            }
        }
        k--;
        int ans = n - k;
        if(ans == n){
            ans = -1;
        }
        cout << ans << '\n';
    }
}

Measured memory_bytes: 33024
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(int n){
    cout << "Yes" << endl;
}

void no (int n){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

int main() {
    int n, m, x; cin >> n >> m >> x;
    int ansl = 0;
    int ansr = 0;
    rep(i,m){
        int a; cin >> a;
        if (a < x) ansl++;
        if (a > x) ansr++;
    }
    cout << min(ansl,ansr) << endl;
}

Measured memory_bytes: 3608
use proconio::input;

fn main() {
    input! {
        n: usize,
        x: [usize; n],
    }
    let mut sort_x = x.clone();
    sort_x.sort();

    for nx in &x {
        match sort_x.binary_search(nx) {
            Ok(index) => {
                //println!("index {}", index);
                if index < n / 2 {
                    println!("{}", sort_x[n / 2]);
                } else {
                    println!("{}", sort_x[n / 2 - 1]);
                }
            }
            Err(_) => panic!(),
        }
    }
}


Measured memory_bytes: 7740
#include <stdio.h>

int main(){
	int a, b, as, bs, n;
	scanf("%d", &n);
	while(n != 0){
		as = 0;
		bs = 0;
		for(int i = 0; i < n; i++){
			scanf("%d %d", &a, &b);
			if(a > b){
				as += a + b;
			}else if(a < b){
				bs += a + b;
			}else{
				as += a;
				bs += b;
			}
		}
		printf("%d %d\n", as, bs);
		scanf("%d", &n);
	}
	return 0;
}

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

int main() {
  int n, s = 0;
  cin >> n;
  vector<int> a(n + 2);
  for(int i = 0; i < n + 2; i++) {
    if(i) {
      if(i == n + 1)
        a.at(i) = 0;
      else
        cin >> a.at(i);
      s += abs(a.at(i) - a.at(i - 1));
    } else
      a.at(i) = 0;
  }
  for(int i = 1; i < n + 1; i++) {
    cout << s + abs(a.at(i + 1) - a.at(i - 1)) - abs(a.at(i) - a.at(i - 1)) -
                abs(a.at(i) - a.at(i + 1))
         << endl;
  }
}

Measured memory_bytes: 1664
use std::io::*;
use std::iter;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn main() {
    let v = read_vec::<usize>();
    let (h,w) = (v[0],v[1]);
    let mut s: Vec<Vec<char>> = (0..h).map(|_| read::<String>().chars().collect()).collect();

    for i in 0..h {
        s[i].insert(0,'.');
        s[i].push('.')
    }
    s.insert(0,iter::repeat('.').take(w+2).collect());
    s.push(iter::repeat('.').take(w+2).collect());    

    for i in 1..h-1 {
        for j in 1..w-1 {
            if s[i][j] == '.' {
                continue;
            }
            if s[i-1][j] == '.' && s[i][j-1] == '.' && s[i+1][j] == '.' && s[i][j+1] == '.' {
                println!("No");
                return;
            }
        }
    }
    println!("Yes");
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>

int map[17][17];

int route(int x, int y)
{
	int n;
	
	if (x == 1 && y == 1){
		return (1);
	}
	
	if (x == 1){
		if (map[y - 1][x] == -1){
			return (0);
		}
		else {
			return (route(x, y - 1));
		}
	}

	if (y == 1){
		if (map[y][x - 1] == -1){
			return (0);
		}
		else {
			return (route(x - 1, y));
		}
	}

	n = 0;
	if (map[y - 1][x] != -1){
		n += route(x, y - 1);
	}
	if (map[y][x - 1] != -1){
		n += route(x - 1, y);
	}
	
	return (n);
}

int main(void)
{
	int a, b;
	int n;
	int m;
	int x, y;
	int i;
	
	while (1){
		scanf("%d%d", &a, &b);
		if (a == 0 && b == 0){
			break;
		}

		memset(map, 0, sizeof(map));
		scanf("%d", &n);
		for (i= 0; i < n; i++){
			scanf("%d%d", &x, &y);
			map[y][x] = -1;
		}
		
		printf("%d\n", route(a, b));
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <stdio.h>

int main(void)
{
    int a, b, c;
    
    scanf("%d%d%d", &a, &b, &c);
    
    if (a < b && b < c){
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    
    return (0);
}



Measured memory_bytes: 2104
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	char a[H][W];
	bool Height[H]; 
	bool Weight[W];
	rep(i, H) Height[i] = false;
	rep(i, W) Weight[i] = false;
	rep(i, H) rep(j, W) cin >> a[i][j];
	rep(i, H) {
		rep(j, W) {
			if (a[i][j] != '.') {
				Height[i] = true;
				Weight[j] = true;
			}
		}
	}
	rep(i, H) {
		rep(j, W) {
			if (Height[i] && Weight[j]) {
				cout << a[i][j];
			}
		}
		if (Height[i]) cout << endl;
	}


    return 0;
}


Measured memory_bytes: 256
from itertools import combinations
from itertools import permutations


def f(x, lst, rem):
    d = abs(x - min(lst))
    min_lst = min(lst)
    tpl = None
    for v in range(1, len(lst) - rem + 2):
        for t in combinations(lst, v):
            if abs(x - sum(t)) + 10 * (v - 1) < d:
                d = abs(x - sum(t)) + 10 * (v - 1)
                tpl = t
    if tpl is None:
        lst.remove(min_lst)
    else:
        for v in tpl:
            lst.remove(v)
    return d, lst


def main():
    N, A, B, C = map(int, input().split())
    *L, = [int(input()) for i in range(N)]

    ans = int(1e9+7)
    for ABC in permutations((A, B, C), 3):
        lst = L[:]
        accum = 0
        for i, v in enumerate(ABC):
            d, lst = f(v, lst, 3 - i)
            accum += d
        ans = min(ans, accum)
    print(ans)


main()


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

using namespace std;

#define rep(i, a, b)  for(int i = (a); i < (b); i++)
#define rrep(i, a, b) for(int i = (a); i > (b); i--)
#define sq(x) ((x) * (x))
#define bit(x) bitset<32>(x)
#define vsort(v)  sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<llint>())
#define debug(x) cout << #x << " " << (x) << endl
#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


template<typename Tn> Tn __lcm(Tn a, Tn b)
{
    return a / __gcd(a, b) * b;
}

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

int main()
{
    int n, m;
    ci >> n >> m;

    int li, ri;
    int l = 1, r = n;
    rep(i, 0, m) {
	ci >> li >> ri;
	l = max(l, li);
	r = min(r, ri);
    }

    if(r - l + 1 > 0) co << r - l + 1 << en;
    else co << 0 << en;
  
    return 0;
}


Measured memory_bytes: 256
//int -> ll
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
typedef long long ll;
#define x first
#define y second
#define REP(i,sss,eee) for(int i=sss;i<=eee;++i)
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
#define N 1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
/*****************default********************/
vi inp;
int lnds(vi &v){//Longest nondecreasing Sequence
	int n=v.size();
	if(n==0){return 0;}
	vi tail;tail.resize(n,0);
	int len=1;
	tail[0]=v[0];
	REP(i,1,n-1){
		if(v[i]>=tail[len-1]){
			tail[len++]=v[i];
		}
		else{
			auto it=upper_bound(tail.begin(),tail.begin()+len,v[i]);
			(*it)=v[i];
		}
	}
	return len;
}
int main(){
    speed
	int n;cin>>n;
	inp.resize(n);
	for(int i=0;i<n;++i){cin>>inp[i];}
	for(int i=0;i<n;++i){inp[i]=(1000000000-inp[i]);}
	cout<<lnds(inp)<<"\n";
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	string s,t;
	int i,j,k,start,tj=0;
	bool flag,ans;
	cin>>s;
	cin>>t;
	for(i=s.size()-t.size();i>=0;i--)
	{
		ans=false;
		if(s[i]==t[0] || s[i]=='?')
		{
			flag=true;
			for(j=1;j<t.size();j++)
			{
				if(s[i+j]!='?' && s[i+j]!=t[j])
				{
					flag=false;
					break;
				}
			}
			if(flag) 
			{
				ans=true;
				start=i;
				break;
			}
		}
	}
	if(ans)
	{
		for(i=0;i<start;i++)
		{
			if(s[i]=='?') cout<<'a';
			else cout<<s[i];
		}
		cout<<t;
		for(i=start+t.size();i<s.size();i++)
		{
			if(s[i]!='?') cout<<s[i];
			else cout<<'a';
		}
		cout<<endl;
	}
	else 
	{
		cout<<"UNRESTORABLE"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
	int i, N, M;
	int long long kaijo = 1, s;

 
	scanf("%d %d", &N, &M);
 

	s = 1000000007;
	if(N == M - 1 || N == M + 1) {
		for (i = 1; i <= N; i++) {
			kaijo *= i;
			if(kaijo >= s) {
				kaijo %= s;
			}
  		}

		for (i = 1; i <= M; i++) {
			kaijo *= i;
			if(kaijo >= s) {
				kaijo %= s;
			}
  		}

		if(kaijo >= s) {
			kaijo %= s;
		}

		printf("%lld", kaijo);
	}

	else if(N == M) {
		for (i = 1; i <= N; i++) {
			kaijo *= i;
			if(kaijo >= s) {
				kaijo %= s;
			}
  		}

		for (i = 1; i <= M; i++) {
			kaijo *= i;
			if(kaijo >= s) {
				kaijo %= s;
			}
  		}
		kaijo *= 2;

		if(kaijo >= s) {
			kaijo %= s;
		}

		printf("%lld", kaijo);
	}

	else {
		printf("0");
	}
 
}

Measured memory_bytes: 128
#include<stdio.h>

int main() {

int a[200],b[200],i=0,count=0,c,count_waru=0;

while((scanf("%d%d",&a[i],&b[i]))!=EOF){
i++;
count++;
}

for(i=0;i<count;i++){
c=a[i]+b[i];

while(c!=0){
c/=10;
count_waru++;
}
printf("%d\n",count_waru);
count_waru=0;
}

return 0;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int main(){
  int N, M, i, min, max, ans;
  cin >> N >> M;
  int L[M], R[M];
  for(i=0; i<M; i++) cin >> L[i] >> R[i];
  for(i=0; i<M; i++){
    if(i == 0){
      min = L[i]; max = R[i];
    }else{
      if(min < L[i]) min = L[i];
      if(max > R[i]) max = R[i];
    }
  }
  ans = max - min + 1;
  if(ans < 0) ans = 0;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import scala.io.Source.stdin

object Main extends App {
  def gcd(m:Long,n:Long):Long = if(n==0) m else gcd(n, m % n)

  println {
    {
      for(s <- stdin.getLines.map(_.split(" ").map(_.toLong))) yield {
          val g = gcd(s(0),s(1))
          g + " " + (s(0)/g)*s(1)
      }
    }.mkString("\n")
  }
}

Measured memory_bytes: 43896
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << '\n';
        return 0;
}

Measured memory_bytes: 256
using System;

namespace _0148
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                string now = Console.ReadLine();
                if(now==null)
                {
                    break;
                }
                int N = int.Parse(now);
                string output = (N % 39).ToString();
                if(output.Length==1)
                {
                    if(output=="0")
                    {
                        Console.WriteLine("3C39");
                    }
                    else
                    {
                        Console.WriteLine("3C0" + output);
                    }
                }
                else
                {
                    Console.WriteLine("3C" + output);
                }
            }
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9020
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define range_for(i, b, e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define pb push_back
# define len(x) ((int)(x).size())
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
# define LINT_MAX (LONG_LONG_MAX)
# define cauto const auto
using namespace std;
using lint = long long;
template <class Type> inline constexpr bool InRange(const Type& x, const Type& i, const Type& a) { return (i <= x) && (x <= a); }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a<b) { a=b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Integer>bool IsOdd(Integer &n) { return n & 1; }
template<class Integer>bool IsEven(Integer &n) { return !(n & 1); }
int ctoi(const char c) { return ('0' <= c && c <= '9') ? (c - '0') : -1; }
string YesNo(bool b) { return b ? "Yes" : "No"; }
string YESNO(bool b) { return b ? "YES" : "NO"; }
string yesno(bool b) { return b ? "yes" : "no"; }
static const lint MOD9 = (lint)1e9+7;
int dy[4] = {0, 1, 0, -1};
int dx[4] = {1, 0, -1, 0};

// 整数の桁数を返す ( log(N) )
template <class Integer> Integer GetDigit(Integer n) {
    Integer d = 0;
    while (n) {
        n /= 10;
        d++;
    }
    return d;
}

// 素数かどうかを返す ( O(sqrt(N)) )
template <class Integer>
constexpr bool IsPrime(const Integer n) noexcept {
    if (n < 4) return n == 2 || n == 3;
    if (n % 2 == 0 || n % 3 == 0 || (n % 6 != 1 && n % 6 != 5)) return false;
    for (Integer i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;
}


int main()
{
    string N; cin >> N;
    cout << YesNo(count(ALL(N), '7')) << endl;

    return 0;
}



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

int main()
{
	ll N, M;
	cin >> N >> M;
	vector<ll> a(M), b(M), c(M);
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--; c[i] *= -1;
	}
	vector<ll> cost(N, INF);
	cost[0] = 0;
	bool flag = true;
	for (int i = 0; i < N; i++) {
		bool tmp = true;
		for (int j = 0; j < M; j++) {
			if (cost[a[j]] != INF && cost[b[j]] > cost[a[j]] + c[j]) {
				tmp = false;
				cost[b[j]] = cost[a[j]] + c[j];
			}
		}
		if (tmp) {
			flag = false;
			break;
		}
	}
	assert(cost[N - 1] != INF);
	if (flag) {
		ll res = cost[N - 1];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < M; j++) {
				if (cost[a[j]] != INF && cost[b[j]] > cost[a[j]] + c[j]) {
					cost[b[j]] = cost[a[j]] + c[j];
				}
			}
		}
		if (cost[N - 1] == res) {
			cout << -res << endl;
		}
		else {
			cout << "inf" << endl;
		}
	}
	else {
		cout << -cost[N - 1] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;


int main() {
	int n = 0, k = 0, ans = 0;
	cin >> n >> k;
	vector<int> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	for (int i = 0; i < k; i++) {
		ans += A[i];
	}
	cout << ans;


}




Measured memory_bytes: 3172
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("5");
            WillReturn.Add("1 3 5 4 2");
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("9");
            WillReturn.Add("9 6 3 2 5 8 7 4 1");
            //5
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] PArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();

        int Answer = 0;
        int UB = PArr.GetUpperBound(0);
        for (int I = 0; I <= UB; I++) {
            var PList = new List<int>();
            for (int J = I; J <= I + 2 && J <= UB; J++) {
                PList.Add(PArr[J]);
            }
            if (PList.Count == 3) {
                if (PList[0] < PList[1] && PList[1] < PList[2]) {
                    Answer++;
                }
                else if (PList[0] > PList[1] && PList[1] > PList[2]) {
                    Answer++;
                }
            }
        }
        Console.WriteLine(Answer);
    }
}


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

using namespace std;

const int N = 1e5+7, inf = 1e9;

#define pii pair<int,int>
#define fi first
#define se second

vector<int> g[N], ans(N);
vector<pii> range(N, {-inf, inf}), edge;
int n, k;

pii merge(pii x, pii y){
	if(x > y) swap(x, y);
	return {max(x.fi, y.fi), min(x.se, y.se)};
}

void dfs(int p, int u){
	for(auto v: g[u]){
		if(v != p){
			dfs(u, v);
			range[u] = merge(range[u], {range[v].fi - 1, range[v].se + 1});
		}
	}
}

void build(int p, int u){
	for(auto v: g[u]){
		if(v != p){
			if(range[v].fi <= ans[u] - 1 && ans[u] - 1 <= range[v].se) ans[v] = ans[u] - 1;
			else ans[v] = ans[u] + 1;
			build(u, v);
		}
	}
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> n;
	for(int i = 0; i < n - 1; ++i){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v), g[v].push_back(u);
		edge.push_back({u,v});
	}
	cin >> k;
	
	for(int i = 0; i < k; ++i){
		int v, x;
		cin >> v >> x;
		range[v] = {x, x};
	}
	dfs(1,1);
	for(int i = 1; i <= n; ++i)
		if(range[i].fi > range[i].se) 
			cout << "No", exit(0);
	
	ans[1] = range[1].fi;
	dfs(1,1);
	build(1,1);
	
	bool ok = true;
	for(int i = 1; i <= n; ++i)
		ok &= (range[i].fi <= ans[i] && ans[i] <= range[i].se);
	
	for(auto e: edge) ok &= (abs(ans[e.fi] - ans[e.se]) == 1);
	
	if(!ok) cout << "No";
	else{
		cout << "Yes" << endl;
		for(int i = 1; i <= n; ++i) cout << ans[i] << endl;
	}
}

Measured memory_bytes: 16716
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n;
    cin >> n;
    lli maxv = 0;
    vi h(n, 0);
    vi cnt(n, 0);
    rep(i, n){
        cin >> h[i];
        if(i != 0 && h[i]<=h[i-1]) cnt[i] = cnt[i-1]+1;
        else cnt[i] = 0;
        chmax(maxv, cnt[i]);
    }
    cout << maxv << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

int dp[200010][2][3];
signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n;
    cin >> n;
    vi v;
    rep(i, 200010)
        rep(j, 2)
            rep(k, 3)
                dp[i][j][k] = -INF;
    rep(i, n)
    {
        int t;
        cin >> t;
        v.emplace_back(t);
    }
    if (n % 2 == 0)
    {
        dp[0][0][0] = -INF;
        dp[0][0][1] = 0;
        dp[0][0][2] = -INF;
        dp[0][1][0] = -INF;
        dp[0][1][1] = -INF;
        dp[0][1][2] = -INF;
    }
    else
    {
        dp[0][0][0] = -INF;
        dp[0][0][1] = -INF;
        dp[0][0][2] = 0;
        dp[0][1][0] = -INF;
        dp[0][1][1] = -INF;
        dp[0][1][2] = -INF;
    }
    rep(i, n)
    {
        dp[i + 1][0][0] = max(dp[i][0][1], dp[i][1][0]);
        dp[i + 1][0][1] = max(dp[i][0][2], dp[i][1][1]);
        dp[i + 1][0][2] = dp[i][1][2];
        if (dp[i][0][0] != -INF)
            dp[i + 1][1][0] = dp[i][0][0] + v[i];
        if (dp[i][0][1] != -INF)
            dp[i + 1][1][1] = dp[i][0][1] + v[i];
        if (dp[i][0][2] != -INF)
            dp[i + 1][1][2] = dp[i][0][2] + v[i];
    }

    int ans = -INF;
    ans = max(ans, dp[n][0][0]);
    ans = max(ans, dp[n][0][1]);
    // ans = max(ans, dp[n][0][2]);
    ans = max(ans, dp[n][1][0]);
    ans = max(ans, dp[n][1][1]);
    // ans = max(ans, dp[n][1][2]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 14736
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;

#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define vpii vector<pair<ll,ll>>
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll fact(ll n){
	
    ll res = 1; 
    for (ll i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
  
int nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 


ll ston(string s) 
{ 
    stringstream geek(s); 
    ll x = 0; 
    geek >> x; 
    
  
    return x; 
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol(const vector<int>& v1, 
               const vector<int>& v2){ 
 return v1[0] < v2[0]; } 

 ll degit(ll n)
 {
 	ll t=0;
 	while(n>0)
 	{
 		t++;
 		n/=10; 	}
 		return t;
 }

void solve()
{
	ll x,y;
	cin>>x>>y;
	if(y%2!=0)
	{
		cout<<"No";
		return;
	}
	if(y>=x*2 && y<=x*4)
	{
		cout<<"Yes";
		return;
	}
	cout<<"No";
	
	return;
}

int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

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

    int ans;
    if(b >= a){
        ans = a;
    }
    else{
        ans = a-1;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    for(int i = 0; i + k < n; ++i){
        if(a[i + k] > a[i]) cout << "Yes\n";
        else    cout << "No\n";
    }
}

Measured memory_bytes: 3984
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll o = n/(a+b);
    ll r = n%(a+b);
    ll v = a*o;
    if(r < a){
        v += r;
    } else {
        v += a;
    }
    cout << v << "\n";    
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;

int N;
map<int, int> ans;

bool ok(int y, int x, vector<string> &v){
  if(y < 0 || x < 0 || y >= N || x >= v[y].size()) return false;
  return true;
}

int check(int y, int x, vector<string> &v){
  int t = 1, b = 1, l = 1, r = 1, my, mx;
  while(ok(y, x + 1, v) && v[y][x + 1] == '*') { ++t; v[y][++x] = ' '; }
  FOR(py, -1, 2) FOR(px, -1, 2) if(ok(y + py, x + px, v) && v[y + py][x + px] == '*') { my = py, mx = px; }
  while(ok(y + my, x + mx, v) && v[y + my][x + mx] == '*') { ++r; x += mx; y += my; v[y][x] = ' '; }
  while(ok(y, x - 1, v) && v[y][x - 1] == '*') { ++b; v[y][--x] = ' '; }
  FOR(py, -1, 2) FOR(px, -1, 2) if(ok(y + py, x + my, v) && y + py >= 0 && x + px >= 0 && y + py < N && x + px < v[y + py].size() && v[y + py][x + px] == '*') { my = py, mx = px; }
  while(ok(y + my, x + mx, v) && v[y + my][x + mx] == '*') { ++l; x += mx; y += my; v[y][x] = ' '; }
  if(t == b && l == r) return t * r;
  return (t + b) * l / 2;
}

int main() {
  int f = 0;
  while(cin >>N && N){
    if(f++) cout <<"----------" <<endl;
    ans = map<int, int>();
    vector<string> v(N);
    getline(cin, v[0]);
    REP(i, N) getline(cin, v[i]);
    REP(i, N){
      REP(j, v[i].size()){
        if(v[i][j] == ' ') continue;
        int r = check(i, j, v);
        ans[r] += 1;
      }
    }
    for(auto i : ans) cout <<i.first <<" " <<i.second <<endl; 
  }
}

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

const int MAX_N = 100000;
int main() {
    int N;
    pair<int, int> itv[MAX_N];
    cin >> N;

    for(int i = 0; i < N; i++) {
        cin >> itv[i].first;
        itv[i].second = i + 1;
    }

    sort(itv, itv + N);
    for(int i = 0; i < N; i++) {
        cout << itv[i].second << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    while(test--)
    {
        int n; cin>>n;
        cout<<((n/500)*1000) + ((n-(n/500)*500)/5)*5;
    }
    return 0;
}

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

int main(){
	string s;
	cin >> s;
    int n = s.length();
	for(int i = 0; i < (n-1)/2; i++) {
    	if(s[i] != s[n-1-i] || s[i] != s[(n-1)/2-i-1] || s[i+(n+3)/2-1] != s[n-1-i]) {
         	cout << "No" << endl;	
          return 0; 
        }
    }
	cout << "Yes" << endl;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

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

using ll = long long;

int main(){
    ll N, W;
    std::cin >> N >> W;

    ll w[N], v[N];
    for(ll i=0; i<N; ++i){
        std::cin >> w[i] >> v[i];
    }

    ll dp[N+1][W+1];
    for(ll i=0; i<N+1; ++i){
        for(ll j=0; j<W+1; ++j){
            dp[i][j]=0;
        }
    }
    for(ll i=0; i<N; ++i){
        for(ll j=0; j<W+1; ++j){
            if(j-w[i]>=0){
                chmax(dp[i+1][j], dp[i][j-w[i]]+v[i]);
            }
            chmax(dp[i+1][j], dp[i][j]);
        }
    }

    std::cout << dp[N][W];
    return 0;
}


Measured memory_bytes: 79104
# -*- coding: utf-8 -*-
import math
import bisect
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

pos_p = 1
pos_q = 1
cnt = n-1

for i in range(n):
    tmp_p = p[i:]
    tmp_p.sort()
    tmp_rank = bisect.bisect_left(tmp_p, p[i])
    pos_p += math.factorial(cnt) * tmp_rank

    tmp_q = q[i:]
    tmp_q.sort()
    tmp_rank = bisect.bisect_left(tmp_q, q[i])
    pos_q += math.factorial(cnt) * tmp_rank

    cnt -= 1

print(abs(pos_p-pos_q))


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  vector<ll> sum(n);
  for (ll i = 0; i < m; ++i) {
    ll a, b;
    cin >> a >> b;
    a--; b--;
    sum[a]++;
    sum[b]++;
  }

  for (ll i = 0; i < n; ++i) {
    if (sum[i]%2 == 0) continue;
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  
  return 0;
}


Measured memory_bytes: 1024
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 100100
#define PI 3.141592653589793238
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
void solve(){
    ll a[6];
    ll idx=0;
    for(ll i=1;i<=5;i++)
    {
        cin>>a[i];
        if(a[i]==0)
            idx=i;
    }
    cout<<idx<<endl;
}
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

//    cin.tie(NULL);cout.tie(NULL);
//    ll t;cin>>t;while(t--)
    solve();
    return 0;
}


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

namespace AtTest.HCPC2019_29
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            List<int[]> vals = new List<int[]>();
            for(int i = 1; i <= 150;i++)
            {
                for(int j = i+1; j <= 150;j++)
                {
                    int val = i * i + j * j;
                    vals.Add(new int[3] { val, i, j });
                }
            }
            vals = vals.OrderBy(a => a[1]).ToList();
            vals = vals.OrderBy(a => a[0]).ToList();
            while (true)
            {
                int[] hw = ReadInts();
                int h = hw[0];
                int w = hw[1];
                if (h == 0) break;
                int tar = h * h + w * w;
                for(int i = 0; i < vals.Count; i++)
                {
                    if ((tar == vals[i][0] && h < vals[i][1])
                        || tar < vals[i][0])
                    {
                        WriteLine(vals[i][1] + " " + vals[i][2]);
                        break;
                    }
                }
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



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

int main() {
    long long a, b, c, k;
    cin >> a >> b >> c >> k;
    long long res = 0;

    if (k <= a)
        res = k;
    else if (k <= a + b)
        res = a;
    else
        res = a - (k - a - b);

    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
ll mod=pow(10,9)+7;

struct Combination{
    vec n,n_rev;

    Combination(int N){
        n.resize(N+1);
        n_rev.resize(N+1);
        n[0]=1;n_rev[1]=1;
        for(int i=1;i<=N;i++){
            n[i]=((ll)i*n[i-1])%mod;
        }
        for(int i=2;i<=N;i++){
            n_rev[i]=matpow(n[i],mod-2);
        }
    }

    //累乗(aのk乗)
    ll matpow(ll a,int k){
        ll dp=1,mt=a;
        while(k>0){
            if(k & 1)dp=(dp*mt)%mod;
            mt=(mt*mt)%mod;
            k/=2;
        }
        return dp;
    }

    ll comb(int N,int r){  
        if(r==0 || N==r)return 1;
        return (((n[N]*n_rev[r])%mod)*n_rev[N-r])%mod;
    }
};

int main(){
    int H,W,A,B;cin>>H>>W>>A>>B;
    ll ans=0;
    Combination Comb(max(H-A+B-1,W+A-B-1));
    int i=H-A-1,j=B;
    while(i>=0 && j<=W-1){
        ans+=(Comb.comb(i+j,i)*Comb.comb(H+W-2-i-j,H-i-1))%mod;
        ans=ans%mod;
        i--;j++;
    }
    cout<<ans<<endl;
    return 0;
}

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


int main(){

	char s[4];

	scanf("%s", s);

	int n = strlen(s);

	bool ok = true ; 

	for(int i =0 ; i + 1 < n; i ++ ){

		if(s[i] == s[i + 1]){
			ok = false;
		}
	}

	if(ok == false){
		printf("Bad");
	}else printf("Good");

	return 0;
}

Measured memory_bytes: 256
n = int(input())
list_a = list(map(int,input().split()))
list_b = list(map(int,input().split()))
ans1 = sum(list_a)
dum1 = 0
for i in range(n-1,-1,-1):
    dum1 = list_a[i+1] - list_b[i]
    list_a[i+1] = dum1
    if list_a[i+1] < 0:
        list_a[i+1] = 0
    if dum1 < 0:
        list_a[i] = list_a[i] + dum1
        if list_a[i] < 0:
            list_a[i] = 0
ans2 = sum(list_a)
#print(list_a)
print(ans1-ans2)

Measured memory_bytes: 82020
import bisect
N, M, K = map(int, input().split())
bookA = list(map(int, input().split()))
bookB = list(map(int, input().split()))

sumA = [0]*(N+1)
sumB = [0]*(M+1)
maxA = N+1
for i in range(N):
    sumA[i+1] = sumA[i] + bookA[i]
    if sumA[i+1] > K:
        maxA = i+1
        break

maxB = M+1
for i in range(M):
    sumB[i+1] = sumB[i] + bookB[i]
    if sumB[i+1] > K:
        maxB = i+1
        break

pos1 = bisect.bisect_right(sumA, K, 0, maxA)-1
pos2 = bisect.bisect_right(sumB, K, 0, maxB)-1
ans = pos1
if pos2 > ans: ans = pos2
for i in range(1, maxB):
    ss = K - sumB[i]
    pos3 = bisect.bisect_right(sumA, ss, 0, maxA) + i-1
    if ans < pos3:
        ans = pos3

print(ans)


Measured memory_bytes: 40560
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    while (k--)
    {
        int r;
        cin >> r;
        n -= r;
    }
    if (n < 0)
        cout << -1;
    else
        cout << n;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Hello
{
    static void Main()
    {
        var mn = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = mn[0], m = mn[1];
        Toshi[] toshis = new Toshi[n];
        for (int i = 0; i < toshis.Length; i++)
        {
            toshis[i] = new Toshi(i + 1);
        }
        foreach (var i in Enumerable.Range(0, m))
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = ab[0], b = ab[1];
            bool[] f = new bool[2] {false,false };
            foreach (var j in Enumerable.Range(0, n))
            {
                if (toshis[j].id == a)
                {
                    toshis[j].Add(b);
                    f[0] = true;
                }
                else if (toshis[j].id == b)
                {
                    toshis[j].Add(a);
                    f[1] = true;
                }
                if (f.All(e => e)) break;
            }
        }
        foreach (var toshi in toshis)
        {
            Console.WriteLine(toshi.douroN);
        }
    }

    public class Toshi
    {
        public int douroN = 0;
        public int id = 0;
        public List<int> connectionToshiList;
        public Toshi(int id)
        {
            this.id = id;
            connectionToshiList = new List<int>();
        }

        public void Add(int toshiId)
        {
            var tmp=connectionToshiList.FirstOrDefault(e => e == toshiId);
            douroN++;
            if (tmp == toshiId) return;
            connectionToshiList.Add(toshiId);
        }
    }
}

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

int main()
{
	int a, b, h, m; cin >> a >> b >> h >> m;
	printf("%.10f\n", sqrt(a*a + b*b - 2*a*b*cos((h*30 - m*5.5)*M_PI/180)));
}



Measured memory_bytes: 4120
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

		final int n = sc.nextInt();
		final int m = sc.nextInt();
		
		int[][] matrix = new int[n][m];
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				matrix[i][j] = sc.nextInt();
			}
		}
		
		int[] vector = new int[m];
		for(int i = 0; i < m; i++){
			vector[i] = sc.nextInt();
		}
		
		for(int i = 0; i < n; i++){
			int sum = 0;
			
			for(int j = 0; j < m; j++){
				sum += matrix[i][j] * vector[j];
			}
			
			System.out.println(sum);
		}
		
		
		
		
	}

}

Measured memory_bytes: 31868
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        ll a, b;
        cin >> a >> b;
        if(a > b){
            ll t = a;
            a = b;
            b = t;
        }
        if(a == b){
            cout << 2*a-2 << endl;
            continue;
        }
        else if(a+1 == b){
            cout << a+b-3 << endl;
            continue;
        }
        ll ret = sqrt(a*b);
        if(ret * ret == a*b){
            ret--;
        }
        if(ret*(ret+1) < a*b){
            cout << ret-1+ret << endl;
        }
        else{
            cout << ret*2-2 << endl;
        }
    }



    return 0;
}


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

int n;
string s;
vector <string> all;

void dfs(int now, int t) {
	if (now == n) {
		all.push_back(s);
		return ;
	}
	for (int i = 0; i <= t; i++) {
		s.push_back(char('a' + i));
		dfs(now + 1, max(i + 1, t));
		s.pop_back();
	}
}

int main () {
	scanf("%d", &n);
	dfs(0, 0);
	sort(all.begin(), all.end());
	for (int i = 0; i < all.size(); i++) {
		printf("%s\n", all[i].c_str());
	}
	return 0;
}


Measured memory_bytes: 9588
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set> 
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
#include <complex>
#define assem99 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define ld long double
#define ii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<ii>
#define point complex<double>
#define rep(i,a,b) for(int i=a; i<b; i++)
#define F first
#define S second
#define sz(a) (int)(a).size()
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
int x[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
int y[] = { -1, 0, 1, 0, 1, -1, -1, 1 };
const int MOD = 1e9 + 7, N = 1e5 + 5;
const double pi = acos(-1);
using namespace std;

ll fact[N], inv[N];
ll fp(ll b, ll p)
{
	if (p == 0)
		return 1;
	ll ans = fp(b, p / 2);
	ans = (ans * ans) % MOD;

	if (p % 2 != 0)
		ans = (ans *(b % MOD)) % MOD;
	return ans;
}

void calc(ll n)
{
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++)
	{
		fact[i] = (i * fact[i - 1]) % MOD;
		inv[i] = fp(fact[i], MOD - 2);
	}
}

ll ncr(ll n, ll r)
{
	return ((fact[n] * inv[r]) % MOD * inv[n - r]) % MOD;
}

int main()
{
	assem99;
	calc(N - 1);
	ll n, k; cin >> n >> k;
	rep(i, 1, k + 1)
	{
		if (n - k + 1 >= i)
		{
			ll ans = ncr(n - k + 1, i) % MOD;
			ans *= (ncr(k - 1, i - 1) % MOD) ;
			ans %= MOD;
			cout << ans << endl;
		}
		else cout << "0" << endl;
	}

	return 0;
}

Measured memory_bytes: 1792
import Control.Monad.ST
import Data.Char


readInt :: IO Int
readInt = read <$> getLine :: IO Int

readIntSplit :: IO [Int]
readIntSplit = map read . words <$> getLine :: IO [Int]

readStr :: IO String
readStr = getLine

readStrSplit :: IO [String]
readStrSplit = map read . words <$> getLine

solve :: Int -> Int -> Int -> Int
solve n k x
  | n <= k^x-1 = x
  | otherwise = solve n k (x+1)

main :: IO ()
main = do
  [n, k] <- readIntSplit
  print $ solve n k 1

Measured memory_bytes: 508