akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<string> num(0);
  vector<string> digit={"0","1","2","3","4","5","6","7","8","9"};
  for(int i=0; i<10; i++){
    for(int j=0; j<10; j++){
      for(int k=0; k<10; k++){
        string T;
        T += digit.at(i) + digit.at(j) + digit.at(k);
        num.push_back(T);
      }
    }
  }
  
  vector<vector<int>> cnt(10);
  for(int i=0; i<S.size(); i++){
    int x = S.at(i) - '0';
    cnt.at(x).push_back(i);
  }
  for(int i=0; i<10; i++){
    cnt.at(i).push_back(100000);
  }
  
  int ans = 0;
  vector<int>::iterator position;
  int idx_lower;
    
  for(int i=0; i<num.size(); i++){
    int y = -1;
    for(int j=0; j<3; j++){
      int z = num.at(i).at(j) - '0';
      position = upper_bound(cnt.at(z).begin(), cnt.at(z).end(), y);
      idx_lower = distance(cnt.at(z).begin(),position);
      y = cnt.at(z).at(idx_lower);
      if(y == 100000){
        break;
      }
    }
    if(y < 100000){
      ans++;
      //cout << num.at(i) << endl;
    }
  }
  cout << ans << endl;      
}

Measured memory_bytes: 640
import bisect
n = int(input())
l = sorted(list(map(int, input().split())))
s = 0
for i in range(0,n-2):
  a = l[i]
  for j in range(i+1,n-1):
    b = l[j]
    s += bisect.bisect_left(l,a+b)-j-1
print(s)

Measured memory_bytes: 3188
n,d=gets.chomp.split(" ").map{|s| s.to_i}
x=[]
c=0
for i in 0..n-1
  x[i]=gets.chomp.split(" ").map{|s| s.to_i}
end

for i in 0..n-1
  for j in i..n-1
    if i!=j
      a=[]
      for k in 0..d-1
        a[k]=(x[i][k]-x[j][k])**2
      end
      b=(a.inject(:+))**(1/2.0)
      if (b.to_i)==b
        c+=1
      end
    end
  end
end

puts c

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <deque>
using namespace std ;

int main(){
	int n,x ; cin >> n ;
	string s ;
	deque<int> dq ;
	for(int i=0;i<n;i++){
		cin >> s ;
		if(s=="insert"){
			cin >> x ;
			dq.push_front(x) ;
		}else if(s=="delete"){
			cin >> x ;
			deque<int> sub ;
			while(!dq.empty()){
				if(x==dq.front()){
					dq.pop_front() ;
					break ;
				}else{
					sub.push_back(dq.front()) ;
					dq.pop_front() ;
				}
			}
			while(!sub.empty()){
				dq.push_front(sub.back()) ;
				sub.pop_back() ;
			}
		}else if(s=="deleteFirst") dq.pop_front() ;
		else dq.pop_back() ;
	}
	while(!dq.empty()){
		cout << dq.front() ;
		dq.pop_front() ;
		if(dq.empty()) cout << endl ;
		else cout << " " ;
	}
}


Measured memory_bytes: 6988
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++) 

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int x;
    cin >> x;
    if (x < 1200) {
        cout << "ABC" << endl;
    } else {
        cout << "ARC" << endl;
    }
}

Measured memory_bytes: 256
import copy
def deleteStr(S, text):
    if len(S) < len(text):
        return S
    for i, letter in enumerate(text):
        if letter == S[i]:
            continue
        else:
            return S
    return S[len(text):]

def checkStr(S, text):
    if len(S) < len(text):
        return False
    for i, letter in enumerate(text):
        if letter == S[i]:
            continue
        else:
            return False
    return True

def main():
    S = input()

    for i in range(len(S)):
        S_len = len(S)
        if checkStr(S, 'dreamer'):
            if checkStr(S, 'dreamerase'):
                S = deleteStr(S, 'dream')
            else:
                S = deleteStr(S, 'dreamer')
        else:
            S = deleteStr(S, 'dream')

        if checkStr(S, 'eraser'):
            S = deleteStr(S, 'eraser')
        else:
            S = deleteStr(S, 'erase')

        if S_len == len(S):
            if S_len == 0:
                print('YES')
            else:
                print('NO')
            break


if __name__ == '__main__':
    main()

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n; cin>>n;
    if(n%1000==0) cout<<0<<endl;
    else cout<<1000-n%1000<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstdlib>
#include<string.h>
#include<algorithm>
#define maxn 200005
using namespace std;
char s1[maxn],s2[maxn];
int t1,t2;
int c1[maxn],c2[maxn];
int main()
{
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	int n=strlen(s1+1);
	for(int i=1;i<=n;i++) c1[s1[i]-'a'+1]++;
	for(int i=1;i<=n;i++) c2[s2[i]-'a'+1]++;
	sort(c1+1,c1+27),sort(c2+1,c2+27);
	for(int i=1;i<=26;i++) if(c1[i]!=c2[i]){printf("No");return 0;}
	printf("Yes");
}

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

int f[2][(int)1e7];
vector<int> fj(int n) {
    vector<int> temp;
    temp.clear();
    for (int i=1; i<=n; i<<=1) temp.push_back(i), n-=i;
    if (n) temp.push_back(n);
    return temp;
}
vector<int> a;
int main() {
    int D, G;
    scanf("%d%d", &D, &G); G/=100;
    memset(f, 63, sizeof(f));
    int ans=INT_MAX;
    f[0][0]=0;
    for (int i=1; i<=D; i++) {
        int p, c;
        scanf("%d%d", &p, &c);
        c /= 100;
        a.clear();
        a = fj(p - 1);
        for (int j = 0; j <= G; j++) f[i % 2][j] = f[(i + 1) % 2][j];
        for (int k = 0; k < (int) a.size(); k++) {
            for (int j = G + i * a[k]; j >= G; j--)
                if (j >= i * a[k]) ans = min(ans, f[i % 2][j - i * a[k]] + a[k]);
            for (int j = G; j >= i * a[k]; j--)
                f[i % 2][j] = min(f[i % 2][j], f[i % 2][j - a[k] * i] + a[k]);
        }

        for (int j = G + i * p + c; j >= G; j--)
            if (j - (i * p + c) >= 0)
                ans = min(ans, f[(i + 1) % 2][j - (i * p + c)] + p);
        for (int j = G; j >= i * p + c; j--)
            f[i % 2][j] = min(f[i % 2][j], f[(i + 1) % 2][j - (i * p + c)] + p);

        //rep(j, G) if (f[i % 2][j] != f[i % 2][100000]) printf("%d %d\n", j, f[i % 2][j]);
        //printf("\n");
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 78336
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int foo[] = new int[n];
		for(int i=0;i<n;i++) {
			foo[i]=sc.nextInt();
		}
		int max=foo[0];
		int min=foo[0];
		long num=foo[0];
		for(int i=1;i<n;i++) {
			if(max<foo[i]) {
				max=foo[i];
			}
			if(min>foo[i]) {
				min=foo[i];
			}
			num+=foo[i];
		}
		System.out.println(min+" "+max+" "+num);
	}
}



Measured memory_bytes: 41936
a=gets.chomp.to_i
ary = []
a.times do |i|
  ary << gets.chomp.to_i
end
m = ary.max
idx = ary.index(m)
ary[idx] = ary[idx]/2
hoge = 0
ary.each { |a| hoge = hoge + a}
puts hoge

Measured memory_bytes: 1788
#include <stdio.h>
int getnotzero(int a[], int length);
int getzero(int a[], int start);
int main(void)
{
    int n;
    scanf("%d",&n);
    int garden[n+1];
    for(int i = 0; i < n + 1; i++)
    {
        garden[i] = 0;
    }

    for(int i = 0; i < n; i++)
    {
        scanf("%d",&garden[i]);
    }

    int count = 0;
    int start = getnotzero(garden, n);
    int end = getzero(garden, start);
    while(start != n)
    {
        while(start < end)
        {
            garden[start]--;
            start++;
        }
        count++;
        start = getnotzero(garden, n);
        end = getzero(garden, start);
    }

    printf("%d\n",count);
    return 0;
}

int getnotzero(int a[], int length)
{
    int i = 0;
    while(i <= length)
    {
        if(a[i] != 0)
        {
            return i;
        }
        i++;
    }
    return length;
}
int getzero(int a[], int start)
{
    int i = start;
    while(1)
    {
        if(a[i] == 0)
        {
            return i;
        }
        i++;
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll x = a * c, y = a * d, z = b * c, w = b * d;
    cout << max({x, y, z, w});
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    vector<ll> a(3*n);
    for(auto&x:a){
        cin >> x;
    }
    sort(a.begin(),a.end());
    ll ret = 0;
    ll now = 3*n-1;
    for(i=0;i<n;i++){
        ret += a[now-1];
        now-=2;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 2560
import Data.Array
import Data.List
import Data.Int

divisor = 10^9+7

main = do
  (n:m:_) <- getLine >>= return . map read . words :: IO [Integer]
  xs <- getLine >>= return . map read . words :: IO [Integer]
  ys <- getLine >>= return . map read . words :: IO [Integer]

  let
    xs' = array (0,n-1) (zip [0..] xs)
    ys' = array (0,m-1) (zip [0..] ys)
    
    x = foldl1 (\x y -> (x+y) `mod` divisor) $ map (\i -> mod ((xs'!(fromIntegral $ n - 1 - i) - xs'!(fromIntegral i)) * (n -1 - 2*i)) divisor) [0..div (n-1) 2]
    y = foldl1 (\x y -> (x+y) `mod` divisor) $ map (\i -> mod ((ys'!(fromIntegral $ m - 1 - i) - ys'!(fromIntegral i)) * (m -1 - 2*i)) divisor) [0..div (m-1) 2]

  print $ (x * y) `mod` divisor
    


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
    {
        return a;
    }
    return gcd(b, a % b);
}

int main(int argc, char *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    ll icm = 1;
    rep(i, n)
    {
        ll a;
        cin >> a;
        icm = icm / gcd(icm, a) * a;
    }
    cout << icm << endl;

    return 0;
}

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

using namespace std;

struct change{
	int64_t maisu;
	int64_t value;
};

struct change changes[200000];

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

	for(int i = 0; i < n; ++i){
		changes[i].maisu = 1;
		cin >> changes[i].value;
	}

	for(int i = 0; i < m; ++i){
		cin >> changes[i+n].maisu >> changes[i+n].value;
	}

	sort(changes, changes+n+m, [](const change& x, const change& y){	return x.value > y.value;	});

	int64_t count = 0;
	int64_t ans = 0;

	for(int i = 0; i < n+m; ++i){
		if((count+changes[i].maisu) >= n){
			ans += changes[i].value * (n-count);
			break;
		}else{
			count += changes[i].maisu;
			ans += changes[i].value * changes[i].maisu;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3328
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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(a>b){a=b;return 1;}return 0;}

const ll mod=1e9+7;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> p(60);
    rep(i,60){
        if(i==0){
            p[i]=1;
            continue;
        }
        p[i]=p[i-1]*2;
        p[i]%=mod;
    }
    rep(i,n){
        cin >> a[i];
    }
    ll ans=0;
    rep(i,60){
        ll cnt1=0; //0の数
        ll cnt2=0; //1の数
        rep(j,n){
            if((a[j]>>i)%2==0){
                cnt1++;
            }
            else{
                cnt2++;
            }
        }
        ans+=(((cnt1*cnt2)%mod)*p[i])%mod;
        ans%=mod;
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 2688
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=200000+10;
int n,l,r,m;string str,buf;
main() {

    cin>>n;
        l=0;r=n;
        cout<<0<<endl;
        cin>>str;
        if(str=="Vacant") return 0;
        while(buf!="Vacant"){
            m=(l+r)/2;
            cout<<m<<endl;
            cin>>buf;
            if(m%2^str==buf){
                l=m;
            }
            else {
                r=m;
            }



        }



}


Measured memory_bytes: 852
div = 2019
if __name__ == '__main__':
    L, R = [int(i) for i in input().split()]
    if R - L > div - 1:
        R = L + div - 1
    number_ref = [num for num in range(L, R + 1, 1)]

    min_mod = 2018
    for idx, i in enumerate(number_ref):
        for j in number_ref[idx + 1:]:
            if (i * j) % div < min_mod:
                min_mod = (i * j) % div
    print(min_mod)

Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    string s;
    cin >> s;
    bool f = true;
    REP(i,a){
        if(s[i]>='0'&&s[i]<='9'){

        }else{
            f=false;
        }
    }
    if(s[a]!='-') f=false;
    REP(i,b){
        if(s[a+1+i]>='0'&&s[a+1+i]<='9'){

        }else{
            f=false;
        }
    }
    if(f){
        puts("Yes");
    }else{
        puts("No");
    }

    return 0;
}

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

string robot;

int main(void)
{
    int n, k, R, S, P, i, ans = 0;

	cin >> n >> k >> R >> S >> P >> robot;

    for (i = 0; i < robot.size(); i++)
	{
        int score;

        if (robot[i] == 'r')
			score = P;
		else if (robot[i] == 's')
            score = R;
		else
			score = S;

        if (i >= k && robot[i] == robot[i - k])
		{
			score = 0;
			robot[i] = 'X';
		}

		ans += score;
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

double dist(int x1, int x2, int y1, int y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int fact(int n) {
	if (n <= 1) {
		return 1;
	}

	return n * fact(n - 1);
}

int main() {

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

	int n;
	cin >> n;

	vector<int> perm(n);
	for (int i = 0; i < n; ++i) {
		perm[i] = i;
	}

	vector<pair<int, int> > towns(n);
	int x, y;
	for (int i = 0; i < n; ++i) {
		cin >> x >> y;
		towns[i] = {x, y};
	}

	double total = 0.0;
	do {
		double curr_length = 0.0;
		for (int i = 1; i < n; ++i) {
			curr_length += dist(towns[perm[i]].first, towns[perm[i - 1]].first,
							    towns[perm[i]].second, towns[perm[i - 1]].second);
		}

		total += curr_length;
	} while (next_permutation(perm.begin(), perm.end()));

	cout << setprecision(12) << total / fact(n) << "\n";

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> A(3);
  for(int i=0;i<3;i++){
    cin >> A.at(i);
  }
  if(count(A.begin(),A.end(),5) == 2 and count(A.begin(),A.end(),7)==1){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
    

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
using namespace std;

const double PI=acos(-1);

int main(){
    long a, b, c, k, d;
    cin >> a >> b >> c >> k;
    if(k%2 == 0){
        d = a - b;
    }else{
        d = b - a;
    }
    if(d > 1e18){
        cout << "Unfair" << endl;
    }else{
        cout << d << endl;
    }
    return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn =5*100001;
ll power(ll x, ll n) {
    ll res = 1;
    for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    }
    return res;
}
int main()
{
  
  IOS
  ll a,b;
  cin>>a>>b;
  ll g=(__gcd(a,b));
  ll ans=(a/g)*b;
  cout<<ans<<endl;
  


  

}
  


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int a,b; 
	cin>>a>>b;
	cout<<((a*b%2==0)?"No":"Yes")<<endl;
	return 0;
}

Measured memory_bytes: 256
K, X = map(int, input().split())
p = []
p.append(X)
a = X
b = X
for _ in range(K-1):
  a = a-1
  b = b+1
  p.append(a)
  p.append(b)
p.sort()
p_str = [str(n) for n in p]
print(' '.join(p_str))

Measured memory_bytes: 38256
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>

using namespace std;


class Amida
{
public:
	int h;
	int p;
	int q;

	Amida(int a,int b,int c)
		: h(a)
		, p(b)
		, q(c)
	{}

	bool operator<(const Amida & amida)const
	{
		return h > amida.h;
	}
};


bool solve()
{
	int n, m, a;
	cin >> n >> m >> a;
	if (n == 0 && m == 0 && a == 0)return false;

	list<Amida> amida;

	for (int i = 0; i < m; ++i)
	{
		int h, p, q;
		cin >> h >> p >> q;
		amida.emplace_back(h, p, q);
	}
	amida.sort();

	int ans = a;

	while(!amida.empty())
	{
		if (amida.front().p == a)
		{
			a = amida.front().q;
		}
		else if (amida.front().q == a)
		{
			a = amida.front().p;
		}

		amida.pop_front();
	}

	cout << a << endl;
}


int main()
{
	while(solve())
	{
	}
	


	return 0;
}


Measured memory_bytes: 3164
#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef unsigned long long ull;

int tmp_cost(int p){
  if( p==1)return 0;
  int ret=tmp_cost(p/2)+1+p%2;
  return ret;
}

ull expect(int p,int n,ull tar){
  ull ret=n;
  while(p--&&ret<tar)ret+=ret;
  return ret;
}

int ans;
bool solve(int cnt,int limit,int now,int tar,int num,int *made,bool *visited){
  if (cnt>limit)return false;
  if ( now>=tar*2)return false;//may not be need?
  
  if (now == tar ){
    ans=min(ans,cnt);
    return true;
  }
  if ( cnt==limit)return false;

  int findmax=0;
  REP(i,0,num)findmax=max(findmax,made[i]);
  if( expect(limit-cnt,findmax,(ull)tar)<(ull)tar){
    return false;
  }



  for(int i=num-1;i>=0;i--){
    //mul
    if ( visited[now+made[i]]==false){
      visited[now+made[i]]=true;
      made[num]=now+made[i];
      if (solve(cnt+1,limit,now+made[i],tar,num+1,made,visited)){
	visited[now+made[i]]=false;
	return true;
      }
      visited[now+made[i]]=false;
    }


    //div
    if( now-made[i]>0 && visited[now-made[i]]==false){
      visited[now-made[i]]=true;
      made[num]=now-made[i];
      if (solve(cnt+1,limit,now-made[i],tar,num+1,made,visited)){
	visited[now-made[i]]=false;
	return true;
      }
      visited[now-made[i]]=false;
    }


  }

  return false;
}

main(){
  int n;
  while(cin>>n&&n){
    int upper=tmp_cost(n);
    bool visited[5002]={false};
    int  made[30];
    visited[1]=true;
    visited[2]=true;
    made[0]=1;
    made[1]=2;
        
    
    int lower=0,tmp=1;
    while(tmp<n){
      tmp*=2;
      lower++;
    }
    
    REP(i,lower+1,upper){
      ans=i;
      if (solve(1,i,2,n,2,made,visited) ){
	upper=ans;
	break;
      }
    }
    cout << upper << endl;

  }
  return false;
}

Measured memory_bytes: 872
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ei13333
 */

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

class TaskB
{
public:
  void solve(istream &in, ostream &out)
  {
    string A, B;
    in >> A >> B;
    auto p = stoi(A + B);
    for(int i = 0; i * i <= p; i++) {
      if(i * i == p) {
        out << "Yes" << endl;
        return;
      }
    }
    out << "No" << endl;
  }
};


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

  TaskB solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);

}


Measured memory_bytes: 256
import math

n, a, b = map(int, input().split())
critical = a - b
h = []
for i in range(n):
    h.append(int(input()))

high = 10 ** 9
low = 0


def enough(mid):
    aoe = b * mid
    count = 0
    for hp in h:
        remain = hp - aoe
        if remain > 0:
            count += math.ceil(remain / critical)
    return count <= mid


while high - low > 1:
    mid = (low + high) // 2
    if enough(mid):
        high = mid
    else:
        low = mid
print(high)


Measured memory_bytes: 7192
n = int(input())
list_p = [int(i) for i in input().split()]
count = 0
for i in range(1, n - 1):
    if min(list_p[i - 1], list_p[i], list_p[i + 1]) !=list_p[i] and \
            max(list_p[i - 1], list_p[i], list_p[i + 1]) != list_p[i]:
        count += 1
print(count)

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

using namespace std;
const int MAXN=1e5+7;
struct Node
{
    int x,y,pos;
};
struct edge
{
    int u,v,w;
};
Node a[MAXN];
int n;
vector <edge> edges;
void Input()
{
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i].x>>a[i].y;
        a[i].pos=i;
    }
}
bool cmp1(Node a,Node b)
{
    return (a.x<b.x);
}
bool cmp2(Node a,Node b)
{
    return (a.y<b.y);
}
bool cmp3(edge a,edge b)
{
    return (a.w<b.w);
}
int par[MAXN];
void Init()
{
    memset(par,-1,sizeof(par));
    sort(a+1,a+1+n,cmp1);
    for(int i=1; i<n; i++)
        edges.push_back({a[i].pos,a[i+1].pos,abs(a[i].x-a[i+1].x)});
    sort(a+1,a+1+n,cmp2);
    for(int i=1; i<n; i++)
        edges.push_back({a[i].pos,a[i+1].pos,abs(a[i].y-a[i+1].y)});
    sort(edges.begin(),edges.end(),cmp3);
}
int root(int u)
{
    return par[u]<0 ? u : (par[u]=root(par[u]));
}
bool Merge(int u,int v)
{
    if((u=root(u))==(v=root(v)))
        return false ;
    if(par[u]>par[v])
        swap(u,v);
    //cerr<<par[u]<<" "<<par[v]<<'\n';
    par[u]+=par[v];
    par[v]=u;
    return true ;
}
void Output()
{
    int ans=0;
    for(int i=0;i<(int)edges.size();i++)
        if(Merge(edges[i].u,edges[i].v))
        ans+=edges[i].w;
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    Input();
    Init();
    Output();
    return 0;
}


Measured memory_bytes: 6516
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {
	
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	printf("%d", min(b, d) - max(a, c) > 0 ? min(b, d) - max(a, c) : 0);

	return 0;
}


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

#define times(n, i)      uptil(0, n, i)
#define upto(f, t, i)    for(decltype(t) _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(decltype(t) _##i = (t), i = (f); i < _##i; i++)
#define downto(f, t, i)  for(decltype(t) _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(decltype(t) _##i = (t), i = (f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

template<class T> T sum(const vector<T>& v) {
    T ans = T();
    for(const T& t : v) ans += t;
    return ans;
}

template<class T> T sum(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    T ans = T();
    for(typename vector<T>::iterator t = begin; t != end; t++) ans += *t;
    return ans;
}

template<class T> T min(const vector<T>& v) {
    return *min_element(v.begin(), v.end());
}

template<class T> T min(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *min_element(begin, end);
}

template<class T> T max(const vector<T>& v) {
    return *max_element(v.begin(), v.end());
}

template<class T> T max(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *max_element(begin, end);
}

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

    auto P = next<vector<int>>(5);
    for(int& p : P) if(p < 40) p = 40;
    cout << sum(P) / P.size() ln;

    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> even(100002, 0);
    vector<int> odd(100002, 0);
    REP(i, n)
    {
        cin >> v.at(i);
        if (i % 2 == 0)
            even.at(v.at(i))++;
        else
            odd.at(v.at(i))++;
    }

    int even1, even2, em1 = 0, em2 = 0, odd1, odd2, om1 = 0, om2 = 0;
    REP(i, 100002)
    {
        if (even.at(i) > em1)
        {
            even2 = even1;
            even1 = i;
            em2 = em1;
            em1 = even.at(i);
        }
        else if (even.at(i) > em2)
        {
            even2 = i;
            em2 = even.at(i);
        }

        if (odd.at(i) > om1)
        {
            odd2 = odd1;
            odd1 = i;
            om2 = om1;
            om1 = odd.at(i);
        }
        else if (odd.at(i) > om2)
        {
            odd2 = i;
            om2 = odd.at(i);
        }
    }

    if (even1 != odd1)
    {
        cout << n - em1 - om1;
    }
    else if (em1 + om2 > em2 + om1)
    {
        cout << n - em1 - om2;
    }
    else
        cout << n - em2 - om1;
}

Measured memory_bytes: 1408
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE FlexibleContexts #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import System.IO
import Data.Function
import Control.Monad.Primitive
import qualified Data.Vector.Primitive.Mutable as VPM
import qualified Data.Vector.Generic.Mutable as VGM
import Data.STRef
import Data.IORef

rInt :: StateT BSL.ByteString Maybe Int
rInt = StateT $ BSL.readInt . BSL.dropWhile (<'!')

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine
  es <- V.unfoldrN (n-1+m) (runStateT $ (,) <$> rInt <*> rInt)
    <$> BSL.getContents
  let cods = V.accumulate (flip (:)) (V.replicate (n+1) []) es
  parents <- VUM.replicate (n+1) (0::Int)
  visited <- VUM.replicate (n+1) False
  fixed <- VUM.replicate (n+1) False
  let dfs j = VUM.read visited j >>= \v -> unless v $ do
        VUM.write visited j True
        forM_ (cods V.! j) $ \c -> do
          f <- VUM.read fixed c
          unless f $ do
          VUM.write parents c j
          dfs c
        forM_ (cods V.! j) $ \c -> do
          VUM.write fixed c True
  forM_ [1..n] dfs
  forM_ [1..n] $ \i -> VUM.read parents i >>= print
  


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

using namespace std;

#define REP(i,m) for(ll i=0; i<m; i++)
#define FOR(i,n,m) for(ll i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	int x, y;
	cin >> x >> y;
	cout << abs(x-y) << endl;
	return 0;
} 



Measured memory_bytes: 3116
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    string s;
    cin>>s;
    int n=s.size();

    vector<long long> val(2019,0);
    long long fac=1;
    long long cur=0;
    ++val[cur];

    for(int i=0;i<n;++i){
        long long add=s[n-1-i]-'0';
        cur=(cur+add*fac)%2019;
        fac=(10*fac)%2019;
        ++val[cur];
    }

    long long res=0;
    for(int i=0;i<2019;++i){
        res+=val[i]*(val[i]-1)/2;
    }

    cout<<res<<endl;
}

Measured memory_bytes: 3628
n = int(input())

def ind6(x):
    j = 0
    while 6 ** (j + 1) <= x:
        j += 1
    return j
def ind9(x):
    j = 0
    while 9 ** (j + 1) <= x:
        j += 1
    return j
    
ans = [1000] * 100001

for i in range(6):
    ans[i] = i 

for i in range(100001):
    if ans[i] == 1000:
        ans[i] = min(ans[i-1]+1,ans[i-6**ind6(i)]+1,ans[i-9**ind9(i)]+1)
print(ans[n])

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int n, m;
vector<int> edge[50];
bool check[50];
queue<int> ver;

void dfs(P x, int y){
  check[y] = true;
  for(int z : edge[y]){
    if((x.first==y&&x.second==z)||(x.first==z&&x.second==y)||check[z]) continue;
    ver.push(z);
  }
  while(!ver.empty()){
    int k = ver.front();
    ver.pop();
    dfs(x, k);
  }
}


int main(){
  cin >> n >> m;
  vector<P> p;
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--;b--;
    p.push_back(P(a, b));
    edge[a].push_back(b);edge[b].push_back(a);
  }
  int ans = 0;
  for(P x : p){
    fill(check, check+50, false);
    dfs(x, 0);
    bool flag = true;
    for(int i = 0; i < n; i++){
      if(!check[i]) flag = false;
    }
    if(!flag) ans++;
  }
  cout << ans <<endl;
}
    

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

using namespace std;

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

	int N;

	cin >> N;
	vector<int> doc(N);
	for (int i = 0; i < N; i++) {
		cin >> doc[i];
	}
	for (int x : doc) {
		if ((x % 2 == 0 && x % 3) && (x % 2 == 0 && x % 5)) {
			cout << "DENIED" << "\n";
			return 0;
		}
	}
	cout << "APPROVED" << "\n";
}


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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

int main() {
    lli n, m, c;
    cin3(n, m, c);
    lli b[m];
    ncin1(m, b);
    lli a[n][m];
    REP(i, 0, n) {
        REP(j, 0, m) {
            cin >> a[i][j];
        }
    }
    lli ans = 0;
    REP(i, 0, n) {
        lli total = c;
        REP(j, 0, m) {
            total += a[i][j] * b[j];
        }
        if (total > 0)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)

a = Array.new(n, 0)

k.times do
  d = gets
  gets.split.map(&:to_i).map{|x| x-1}.each do |i|
    a[i] += 1
  end
end

puts a.count{|x| x==0}


Measured memory_bytes: 14312
S = input()
Sa = list(S)
N = len(Sa)

kaibun1 = 0
for i in range(len(Sa)):
    if Sa[i] == Sa[-(i+1)]:
        kaibun1 += 1

kaibun = 0

if kaibun1 == len(Sa):
    kaibun += 1
        
del Sa[((len(Sa)+1)//2)-1:len(Sa)]


kaibun2 = 0
for i in range(len(Sa)):
    if Sa[i] == Sa[-(i+1)]:
        kaibun2 += 1
        
if kaibun2 == len(Sa):
    kaibun += 1

if kaibun == 2:
    print("Yes")
else:
    print("No")
    


Measured memory_bytes: 3064
#b faster
#m_i(k) = min(m_i(k-1), a_(i-k))
# http://agc004.contest.atcoder.jp/data/agc/004/editorial.pdf
n,x =  [int(i) for i in input().split()]
a   =  [int(i) for i in input().split()]
m   =  a[::]
a.extend(a)

min_cost = sum(a)

for k in range(n):
    #cost = x * k
    for i in range(n,2*n):
        m[i-n] = min(m[i-n], a[i-k])
        #cost += mini
    min_cost = min(min_cost, x*k + sum(m))
print(min_cost)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;

//READ THE PROBLEM!
//ll or int?

//Template contributed by GitHub user bqi343


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

	string s;
	cin >> s;

	set<char> used;
	F0R(i, s.size()) {
        if (!used.insert(s.at(i)).second) {
            cout << "no" << endl; return 0;
        }
	}

	cout << "yes" << endl; return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
 
int main() {
  int H,W,count=0;
  cin >> H >> W;
  char A[H+10][W+10];
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> A[i][j];
      if(A[i][j]=='#') count+=1;
    }
  }
  if(count==H+W-1) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int n;
	cin >> n;
	vector<int>a(n-1), b(n-1);
	vector<vector<int>>c(n);
	rep(i, n - 1) {
		int p, q;
		cin >> p >> q;
		p--, q--;
		a[i] = p; b[i] = q;
		c[p].push_back(q);
		c[q].push_back(p);
	}
	int m(0);
	rep(i, n) {
		int k = c[i].size();
		m = max(m, k);
	}
	cout << m << endl;
	queue<P>q;
	map<P, int>mp;
	q.push(P(0, -1));
	vector<bool>f(n, false);
	f[0] = true;
	while (!q.empty()) {
		auto p = q.front(); q.pop();
		int t = p.first; int co = p.second;
		int color = 1;
		if (co == color) {
			color++;
		}
		for (auto n : c[t]) {
			if (!f[n]) {
				f[n] = true;
			}
			else {
				continue;
			}
			P pp = make_pair(t, n);
			mp[pp] = color;
			q.push(P(n, color));
			color++;
			if (t >= n)swap(t, n);
			
			//cout << pp.first << " " << pp.second << endl;
			
			if (co == color) {
				color++;
			}
		}
	}
	rep(i, n - 1) {
		int aa = a[i]; int bb = b[i];
		if (aa >= bb)swap(aa, bb);
		P pp = make_pair(aa, bb);
		//cout << pp.first << " " << pp.second << endl;
		cout << mp[pp] << endl;
	}
	return 0;
}

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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const int mod = 1e9 +7;

#define MAX_N 51 // Fibonacci matrix, increase/decrease this value as needed
struct Matrix { int mat[MAX_N][MAX_N]; }; // we will return a 2D array

Matrix matMul(Matrix a, Matrix b) { // O(n^3)
    Matrix ans; int i, j, k;
    for (i = 0; i < MAX_N; i++)
        for (j = 0; j < MAX_N; j++)
            for (ans.mat[i][j] = k = 0; k < MAX_N; k++){
                ans.mat[i][j] += (1LL*a.mat[i][k] * b.mat[k][j])%mod ; // modulo arithmetic
                ans.mat[i][j]%=mod;
            }
    return ans;
}

Matrix matPow(Matrix base, ll p) { // O(n^3 log p)
    Matrix ans; int i, j;
    for (i = 0; i < MAX_N; i++) for (j = 0; j < MAX_N; j++)
        ans.mat[i][j] = (i == j); // prepare identity matrix
    while (p) { // iterative version of Divide & Conquer exponentiation
        if (p & 1) ans = matMul(ans, base); // if p is odd (last bit is on)
        base = matMul(base, base); // square the base
        p >>= 1; // divide p by 2
    }
    return ans;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<< setprecision(2)<< fixed;
    int n;
    ll k;
    cin>> n>> k;
    Matrix m = Matrix();
    forn(i,n){
        forn(j,n){
            cin>> m.mat[i][j];
        }
    }
    Matrix z = matPow(m,k);
    ll suma= 0;
    forn(i,n)
        forn(j,n){
            suma+= z.mat[i][j]%mod;
            suma%=mod;
        }
    cout<< suma<<el;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> sum, diff;
    ll x, y;
    rep(i, n) {
        cin >> x >> y;
        sum.push_back(x+y);
        diff.push_back(x-y);
    }
    cout << max(MAX(sum)-MIN(sum), MAX(diff)-MIN(diff)) << endl;
}

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

int main() {
  int n;
  scanf("%d", &n);
  int a[n], b[n], c[n];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) scanf("%d", &b[i]);
  for (int i = 0; i < n; i++) scanf("%d", &c[i]);
  sort(a, a+n);
  sort(b, b+n);
  sort(c, c+n);

  int *pos;
  long long idx_a, idx_c;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    pos = lower_bound(a, a + n, b[i]);
    idx_a = distance(a, pos);
    pos = upper_bound(c, c + n, b[i]);
    idx_c = distance(c, pos);
    ans += idx_a * (n-idx_c);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<map>
#define int long long
#define ll long long
using namespace std;
int a[222];
signed main() {
	int n,cnt=0,jj=10000000000;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n; i++) {
      while(a[i]%2==0){
        a[i]/=2;
        cnt++;
		}
      if(cnt<=jj){
        jj=cnt;
	}
      cnt=0;
    }
	cout << jj << endl;
	getchar(); getchar(); return 0;
}

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

#define N 100
#define INF INT_MAX
#define MY_NIL -2

int n;
int a[N][N]={0};

void dijkstra();

int main(){
  int i,j,k,u,v,c;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d %d",&u,&k);
    for(j=0; j<k; j++){
      scanf("%d %d",&v,&c);
      a[u][v]=c;
    }
  }
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      if(a[i][j]==0){
	a[i][j]=INF;
      }
    }
  }
  dijkstra(0);
  return 0;
}

void dijkstra(int s){
  int i,u,min;
  int d[N],pi[N];
  char color[N]={0};
  for(i=0; i<n; i++){
    d[i]=INF;
    pi[i]=MY_NIL;
  }
  d[s]=0;
  while(1){
    min=INF;
    for(i=0; i<n; i++){
      if(color[i]!='B' && d[i]<min){
	min=d[i];
	u=i;
      }
    }
    if(min==INF){
      break;
    }
    color[u]='B';
    for(i=0; i<n; i++){
      if(color[i]!='B' && d[u]+a[u][i]<d[i] && a[u][i]!=INF){
	pi[i]=u;
	d[i]=d[u]+a[u][i];
      }
    }
  }
  for(i=0; i<n; i++){
    printf("%d %d\n",i,d[i]);
  }
}



Measured memory_bytes: 2104