akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// 読み込み
		Boolean flag1 = false;
		Boolean flag2 = false;
		Boolean flag3 = false;
		
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int N = S.length();

		// 条件1
		StringBuffer sb = new StringBuffer(S);
		sb.reverse();
		if(S.toString().equals(sb.toString())) {
			flag1 = true;
		}
		
		// 条件2
		String parse = S.substring(0, (N -1)/2);
		sb = new StringBuffer(parse);
		sb.reverse();
		if(parse.toString().equals(sb.toString())) {
			flag2 = true;
		}
		//System.out.println(parse + " " + sb);
	
		// 条件3
		parse = S.substring((N+3)/2-1, N);
		sb = new StringBuffer(parse);
		sb.reverse();
		if(parse.toString().equals(sb.toString())) {
			flag3 = true;
		}
		//System.out.println(parse + " " + sb);
		
		if(flag1 == true && flag2 == true && flag3 == true) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 24916
<?php
$input = trim(fgets(STDIN));

$length = strlen($input);
$g_count = 0;
$p_count = 0;
$point = 0;

for ($i=0; $i < $length; $i++) { 
	$aite = $input[$i];
	if ($i == 0) {
		$ore = "g";
		++$g_count;
	}else{
		if ($g_count === $p_count) {
			$ore = "g";
			++$g_count;
		}else{
			$ore = "p";
			++$p_count;
		}
	}
	if ($aite === "g" && $ore === "p") {
		++$point;
	} elseif ($aite === "p" && $ore === "g") {
		--$point;
	}
}
echo $point;

Measured memory_bytes: 4728
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  int b=0;
  rep(i,keta(a))
    b+=kurai(a,i+1);
  YesNo(a%b==0);
    
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}


const ll INF=1e18;
const int mx=200005;

ll mod_pow(ll x,ll n,ll m){
    if(n==0) return 1;
    ll res=mod_pow(x*x%m,n/2,m);
    if(n&1) res=res*x%m;
    return res;
}

ll modinv(ll n){
    return mod_pow(2,mod-2,mod);
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    V<ll> a(n);
    cinf(n,a);
    ll ans=0;
    rep(i,n) ans=(ans+a[i])%mod;
    ans=ans*ans%mod;
    rep(i,n){
        ll b=a[i]*a[i]%mod;
        ans-=b;
        if(ans<0) ans+=mod;
    }
    ans=ans*modinv(2)%mod;
    
    out(ans);
}


Measured memory_bytes: 4716
#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 n, k;
    cin >> n >> k;
    ll sol = 0;
    for (int b = k + 1; b <= n; ++b)
    {
        ll m = n;
        sol += (m / b) * (b - k);
        m %= b;
        m -= k - 1;
        sol += max(m, 0ll);
    }
    if (!k)
        sol -= n;
    cout << sol;
}


Measured memory_bytes: 256
import sys


class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x


N, M = map(int, input().split())
info = [tuple(map(int, s.split())) for s in sys.stdin.readlines()]

uf = UnionFind(N)
for a, b in info:
    a -= 1; b -= 1
    uf.union(a, b)

ans = min(uf.parents)

print(-ans)

Measured memory_bytes: 50264
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, s: String, t: String);

    let ss: Vec<char> = s.chars().collect();
    let tt: Vec<char> = t.chars().collect();

    let mut st: String = "".to_string();
    for i in 0..n {
        st.push(ss[i]);
        st.push(tt[i]);
    }

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


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int a, b;
    cin >> a >> b;
    
    if( a < b ) {
        for( int i = 0; i < b; ++i ) cout << a;

    } else {
        for( int i = 0; i < a; ++i ) cout << b;

    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<int> A(N+1);
    vector<int> B(N+1);
    vector<int> C(N);
    for(int i=1;i<=N;i++){
        cin >> A[i];
    }
    for(int i=1;i<=N;i++){
        cin >> B[i];
    }
    for(int i=1;i<N;i++){
        cin >> C[i];
    }
    ll ans = 0;
    int before = -1;
    for(int i=1;i<=N;i++){
        ans+=B[A[i]];
        if(A[i]==(before+1)){
            ans+=C[before];
        }
        before = A[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define double long double
#define pb push_back
const int INF = (int)1e18 + 18;
const int maxn = (int) 1e6 + 6;
using namespace std;

int n;
double sum = 0;
vector<double> a;

signed main(){
  cin >> n;
  
  for(int i = 0; i < n; i++){
    int inp; cin >> inp;
    sum += (double) 1 / inp;
  }
  
  cout << (double) 1 / sum << endl;
  
  
    return 0;
}

Measured memory_bytes: 256
//tanzim bin nasir
#include<bits/stdc++.h>
typedef long long ll;
#define ff first
#define ss second
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
int gcd(int a,int b)
{
    if(b==0)
    return a;
    else
    gcd(b,a%b);
}
ll lcd(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
ll a[200005],n,k;
bool check(ll x)
{
    ll temp=0;
    for(int i=0;i<n;i++)
    {
        temp+=(a[i]-1)/x;
    }
    if(temp>k)
    return false;
    return true;
}
int main()
{
     ll l=1,r=0;
     cin>>n>>k;
     for(int i=0;i<n;i++)
     {
        cin>>a[i];
        r=max(r,a[i]);
     }
     ll ans;
     while(l<=r)
     {
         ll mid=(l+r)/2;
         if(check(mid))
         {
             ans=mid;
             r=mid-1;
         }
         else
         l=mid+1;
     }
     cout<<ans<<endl;
}


Measured memory_bytes: 5124
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=5e5+5;
const int mod=998244353;
int inv[N],jc[N],jcn[N],n,k,ans;
int C(int x,int y){
	if(x<0||y<0||x<y)return 0;
	return 1ll*jc[x]*jcn[y]%mod*jcn[x-y]%mod;
}
int main(){
	inv[1]=jc[0]=jcn[0]=1;
	for(int i=2;i<N;++i)inv[i]=1ll*inv[mod%i]*(mod-mod/i)%mod;
	for(int i=1;i<N;++i)jc[i]=1ll*jc[i-1]*i%mod,jcn[i]=1ll*jcn[i-1]*inv[i]%mod;
	scanf("%d%d",&n,&k);
	for(int r=n,b=k-n;r<=k;++r,--b){
		int t=r-n+1;
		if(r>b)
			ans=(0ll+ans+C(k,r)+mod-C(k,r+t))%mod;
		else if(r==b)
			ans=(0ll+ans+C(k-1,r-1)+mod-C(k-1,r+t))%mod;
	}
	printf("%d\n",ans);
	return 0;
}


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

int main()
{
    long long int A, B;

    cin >> A >> B;

    //ユークリッドの互除法を用いて最大公約数を求める
    long long int x = A * B;
 
  /* 自然数 a > b を確認・入替 */
  if(A<B){
    long long int tmp = A;
    A = B;
    B = tmp;
  }
 
  /* ユークリッドの互除法 */
  long long int r = A % B;
  while(r!=0){
    A = B;
    B = r;
    r = A % B;
  }

  long long int gcd = B;
  long long int lcm = x / gcd;

  cout << lcm << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long L = sc.nextLong();
		long R = sc.nextLong();

		long ans = 2018;

		R = Math.min(R, L + 2019);

		for (long i=L; i<=R; i++) {
			for (long j=i+1; j<=R; j++){
				ans = Math.min(ans, (i*j)% 2019);
			}
		}

		System.out.println(ans);
	}


}

Measured memory_bytes: 21844
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::Ordering;
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

impl<T: Copy> Copy for Rev<T> {}

fn main() {
    input! {
        s: chars,
        t: chars,
    }
    let mut ans = 0;
    for i in 0..3 {
        if s[i] == t[i] {
            ans += 1;
        }
    }

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


Measured memory_bytes: 4352
#include "stdio.h"
#include <stdlib.h>
#include <math.h>

#define FOR(i, a, b) for(int i=a; i<=b; i++)

int N;

int main(void){
	int tmpt, tmpy, tmpx;
	int pret=0, prey=0, prex=0;
	int dis, tdiff;
	int false_flag = 0;

	scanf("%d", &N);

	FOR(i, 0, N-1){
		scanf("%d%d%d", &tmpt, &tmpx, &tmpy);
		tdiff = abs(tmpt - pret);
		dis = abs(tmpy-prey) + abs (tmpx-prex);
		pret = tmpt;
		prey = tmpy;
		prex = tmpx;

		if(tdiff<dis) false_flag = 1;
		else if((tdiff%2!=0&&dis%2==0)||(tdiff%2==0&&dis%2!=0)) false_flag = 1;
	}

	if(false_flag) printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=5010;
const ll mod=1e9+7;


int main(){
  int n; cin >> n;
  vector<ll> a(3*n),bs(3*n),cs(3*n);
  
  priority_queue<int, vector<int>, greater<int>> bq; //syozyun
  priority_queue<int> cq; //kozyun
  ll bsum=0,csum=0;
  rep(i,3*n){
    cin >> a[i];
    if(i<n){bq.emplace(a[i]); bsum += a[i];}
    if(2*n<=i){cq.emplace(a[i]); csum += a[i];}    
  }

  bs[n-1] = bsum; cs[2*n] = csum;
  for(int i=n; i<2*n; i++){
    bq.emplace(a[i]);
    int mini=bq.top();  bq.pop();
    bsum = bsum - mini + a[i];
    bs[i] = bsum;
    
    int j = 3*n-i-1;
    cq.emplace(a[j]);
    int maxi=cq.top();  cq.pop();
    csum = csum - maxi + a[j];
    cs[j] = csum;
  }
  ll ans = bs[n-1]-cs[n];
  for(int i=n; i<2*n+1; i++){
    ans = max(ans,bs[i-1]-cs[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8440
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v, w;

bool sol()
{
    map<int, int, greater<int>> tb;
    for(int i = 1; i != (int) v.size(); ++i)
    {
        if(tb.find(v[i]) == tb.end())
        {
            tb[v[i]] = 0;
        }
        ++tb[v[i]];
    }
    w.push_back(v[0]);
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < (1LL << i); ++j)
        {
            auto it = tb.upper_bound(w[j]);
            if(it == tb.end())
            {
                return false;
            }
            w.push_back((*it).first);
            --(*it).second;
            if((*it).second == 0)
            {
                tb.erase(it);
            }
        }
        sort(w.begin(), w.end(), greater<int>());
    }
    return true;
}

int main(){
    cin >> n;
    v.resize((1 << n));
    for(int i = 0; i != (1 << n); ++i)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end(), greater<int>());
    if(sol())
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }   
    
}

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

int main() {

  int n;  
  vector<string> blue;
  vector<int> blueM;

  cin >> n;
  for (int i=0; i<n; i++) {
    string s;
    cin >> s;
    if ( i == 0 ) {
      blue = {s};        
      blueM = {1};
    } else {
      int x = blue.size();
      for (int j=0; j<x; j++) {
        if( s == blue.at(j) ) {
          blueM.at(j) += 1;
          break;
        } else if ( j == x - 1 ){
          blue.push_back(s);
          blueM.push_back(1);
        }
      }      
    }  
  }

  int m;  
  vector<string> red;
  vector<int> redM;

  cin >> m;
  for (int i=0; i<m; i++) {
    string s;
    cin >> s;
    if ( i == 0 ) {
      red = {s};        
      redM = {1};
    } else {
      int x = red.size();
      for (int j=0; j<x; j++) {
        if( s == red.at(j) ) {
          redM.at(j) += 1;
          break;
        } else if ( j == x - 1 ){
          red.push_back(s);
          redM.push_back(1);
        }
      }      
    }  
  }
  
  int A = 0;
  for (int i=0; i<blue.size(); i++) {
  
    string s = blue.at(i);
    int a = blueM.at(i);

    for (int j=0; j<red.size(); j++) {
      if( s == red.at(j) ){
        a -= redM.at(j);
        break;
      }
    }
    if ( A < a) A = a;
  }
  cout << A << endl;
}
 


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

int main(){
    string s;
    cin >> s;
    int n = s.length() -1;
    long long Ans = 0;
    if(n == 0){
        Ans = stoll(s);
    }
    for(int bit=0;bit<(1<<n);bit++){
        int start = 0;
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
                Ans += stoll(s.substr(start, i-start+1));
                start = i+1;
            }
            if(i == n-1){
                Ans += stoll(s.substr(start, n-start+1));
            }
        }
    }
    
    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define MOD 1000000007
#define INF 1e9
typedef long long ll;

vector<int> S(100010);


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

	rep(i,M){ int t; cin >> t; S[t]=INF; }

	S[0] = 1;
	for(int i=0; i<N; i++){
		if(S[i]==INF)continue;
		for(int j=i+1; j<=min(N,i+2); j++){
			if(S[j]==INF)continue;
			S[j] = (S[j]+S[i])%MOD;
		}
	}

	cout << S[N] << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;

const int MAXN = (200 + 10) * 2;

class no_solution : public std::exception
{
public:
	const char * what(void) const noexcept
	{
		return "no solution reachable";
	}
};

namespace disjointSet
{
int fa[MAXN];

void init()
{
	memset(fa, 0x00, sizeof fa);
}

int find(int x)
{
	if(fa[x])
		return fa[x] = find(fa[x]);
	return x;
}

void merge(int x, int y)
{
	x = find(x), y = find(y);
	if(x != y)
		fa[x] = y;
}

}

bool loop[MAXN];
int inDeg[MAXN], outDeg[MAXN];
int N, H;

void solve()
{
	for(int i = 0; i <= 2 * H; i++)
	{
		if(i > H)
			if(inDeg[i] > outDeg[i])
				throw no_solution();
		if(i < H)
			if(outDeg[i] > inDeg[i])
				throw no_solution();

		bool found = false, isLoop = loop[i];

		for(int j = 0; j <= 2 * H; j++)
			if(found)
				break;
			else
				if(disjointSet::find(i) == disjointSet::find(j))
				{
					if(i != j)
						isLoop = true;
					if(inDeg[j] != outDeg[j])
						found = true;
				}

		if(!found && isLoop)
			throw no_solution();
	}
}

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

	cin >> N >> H ;
	for(int i = 1; i <= N; i++)
	{
		int a, b, c, d, L, R;
		cin >> a >> b >> c >> d;
		L = c ? H - c : H + a;
		R = d ? H + d : H - b;
		disjointSet::merge(L, R);
		inDeg[R]++, outDeg[L]++;

		if(L == R)
			loop[L] = true;
	}


	try
	{
		solve();
		cout << "YES" << endl;
	}
	catch(std::exception & x)
	{
		cout << "NO" << endl ;
	}

	return 0;
}



Measured memory_bytes: 512
import sys
l = sys.stdin.readline().strip()
N, M, X = map(int, l.split())
A = []
C = []
for i in range(N):
    l = sys.stdin.readline().strip()
    a = list(map(int, l.split()))
    C.append(a[0])
    A.append(a[1:])

price = float("INF")
for i in range(2**N):
    bits = bin(i)[2:]
    while len(bits) < N:
        bits = '0' + bits
    bits = list(bits)
    good = True
    for j in range(M):
        crt = 0
        for k, b in enumerate(bits):
            if b == '1':
                crt += A[k][j]
        if crt < X:
            good = False
            break
    if good:
        p = 0
        for k,b in enumerate(bits):
            if b == '1':
                p += C[k]
        if p < price:
            price = p

if price == float("INF"):
    print(-1)
else:
    print(price)

Measured memory_bytes: 68576
#include <stdio.h>

int main (void){
 int n,b,d,Ans=-2147483648;
 scanf("%d",&n);
 scanf("%d",&b);

  for(int i=1;i<n;i++){
 scanf("%d",&d);
 if(d-b>Ans){
 Ans=d-b;
}
if(d-b<0){
b=d;
}

}
printf("%d\n",Ans);

return 0;

}

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

int main(){
  string S;
  cin >> S;
  
  if(S[0] == 'A'){
    int x = 0;
    for(int i=2; i<(S.size()-1); i++){
      if(S[i] == 'C'){
        x++;
      }
    }
    if(x == 1){
      int cnt = 0;
      for(int i=0; i<S.size(); i++){
        if(islower(S[i])) cnt++;
      }
      if((S.size()-2) == cnt){
        cout << "AC" << endl;
        return 0;
      }
    }
                                  
  }
  
  cout << "WA" << endl;
  return 0;
}




Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
 
#include <bits/stdc++.h>
 
#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}
 
using namespace std;                                                                                  
 
mt19937 mrand(random_device{}()); 
const ll mod = 1e9 + 7;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
 
typedef pair < int , int > pii ;                                            
typedef pair < long long  , long long > pll ;
const int N = 2e5 + 123, K = 2e9 + 1 , L = 3e5;

int n, k, m;
int a[N];
string s;
int pr[N];
int sf[N];
main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		pr[i] = pr[i - 1] + abs(a[i] - a[i - 1]);
	}    
	for(int i = n;  i > 0 ; i--){
		sf[i] = sf[i + 1] + abs(a[i] - a[i + 1]);
	}
	for(int i = 1; i <= n; i++){
		cout << pr[i-1] + sf[i + 1] + abs(a[i - 1] - a[i + 1]) << '\n';
	}


}
 


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
long long x,a[100005],f[100005],ans[100005];
int cnt,n,q;
void xyy(long long d,long long w){
	int cat=upper_bound(a+1,a+cnt+1,d)-a-1;
	if(!cat) ans[1]+=w,ans[d+1]-=w;
	else f[cat]+=d/a[cat]*w,xyy(d%a[cat],w);
}
int main(){
	scanf("%d%d",&n,&q);
	a[++cnt]=n;
	while(q--){
		scanf("%lld",&x);
		while(cnt&&a[cnt]>=x) cnt--;
		a[++cnt]=x;
	}
	f[cnt]=1;
	for(int i=cnt;i>=2;i--) f[i-1]+=a[i]/a[i-1]*f[i],xyy(a[i]%a[i-1],f[i]);
	ans[1]+=f[1];ans[a[1]+1]-=f[1];
	for(int i=1;i<=n;i++) printf("%lld\n",ans[i]+=ans[i-1]);
}

Measured memory_bytes: 6156
import java.util.Arrays;
import java.util.Scanner;

class Main {
	int N, M;
	int[] X, Y;
	int[] pow2 = new int[30];

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

	void run() {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long mi = A * (N - 1) + B;
		long ma = B * (N - 1) + A;
		if (ma - mi + 1 > 0) {
			System.out.println(ma - mi + 1);
		}else{
			System.out.println(0);
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

Measured memory_bytes: 23124
import queue

N = int(input())
edge = [set([]) for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].add(b)
    edge[b].add(a)
c = list(map(int, input().split()))
c.sort()
q = queue.Queue()
for i in range(N):
    if len(edge[i]) == 1:
        q.put(i)
ans = [0] * N
i = 0
while not q.empty():
    j = q.get()
    ans[j] = c[i]
    i += 1
    if len(edge[j]) == 0:
        continue
    k = list(edge[j])[0]
    edge[k].remove(j)
    if len(edge[k]) == 1:
        q.put(k)
print(sum(c[:-1]))
for i in ans:
    print(i, end = " ")
print()

Measured memory_bytes: 56148
#include<bits/stdc++.h>
      using namespace std;
      #include <ext/pb_ds/assoc_container.hpp>
      #include <ext/pb_ds/tree_policy.hpp>
      using namespace __gnu_pbds;
      #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
      #define ll long long
      #define int long long
      #define ld long double
      #define pb push_back
      #define f(i,a,b) for(int i=a;i<b;i++)
      #define fd(i,a,b) for(int i=a-1;i>=b;i--)
      #define pf push_front
      #define ppf pop_front
      #define ppb pop_back
      #define fi first
      #define se second
      #define take(a,n) f(i,0,n)cin>>a[i];
      #define show(a,n) f(i,0,n){cout<<a[i]<<" ";}
      #define ashow(a)  for(auto i:a)cout<<i<<" ";
      #define khtm     cout<<endl;
      #define all(s) s.begin(),s.end()
      #define len(a) a.length()
      #define INF 1e18
      #define MAXN 2000009
      #define PMOD 998244353
      const double pi=3.14159265358979323;
      const int mod=1e9+7;
      void btao(int n){
        if(n)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
      }
      bool isPrime(int n) 
  { 
      // Corner cases 
      if (n <= 1) 
          return false; 
      if (n <= 3) 
          return true; 
    
      // This is checked so that we can skip 
      // middle five numbers in below loop 
      if (n % 2 == 0 || n % 3 == 0) 
          return false; 
    
      for (int i = 5; i * i <= n; i = i + 6) 
          if (n % i == 0 || n % (i + 2) == 0) 
              return false; 
    
      return true; 
  } 
  int spf[MAXN];
  void sieve()
        {
            spf[1] = 1;
            for (int i=2; i<MAXN; i++)
                spf[i] = i;
            for (int i=4; i<MAXN; i+=2)
                spf[i] = 2;
            for (int i=3; i*i<MAXN; i++)
            {
                if (spf[i] == i)
                {
                    for (int j=i*i; j<MAXN; j+=i)
                        if (spf[j]==j)
                            spf[j] = i;
                }
            }
        }
 
  int lcm(int a,int b){
      return a*b/__gcd(a,b);
  }
  int aa[300005];
  int n,k,nr,nb,ng;
  int ans=INF;
  int cnt=0;
  int vis[100005]={};
  // string s;
       signed main() {

          ios_base::sync_with_stdio(false);
          cin.tie(NULL);  
          cout.tie(0);  
       // -------------------------------------Code starts here--------------------------------------------------------------------- 
      int t=1;
      // cin>>t;
      while(t--)
      {
        

          int x=1,y=0;
          int mx=-1,mi=INF,mn=INF;
          int tb,ta,tm=0;
        
            string s,r;
            cin>>s>>r;
            f(i,0,len(s))
            if(s[i]!=r[i])y++;
            cout<<y<<endl;
          }
   }

Measured memory_bytes: 3840
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
struct UnionFind {
private:
    ll N;
    vector<ll> parent;
    vector<ll> num;
    vector<ll> diff_weight;

public:
    UnionFind(ll n){
        N = n;
        rep(i,0,N) parent.push_back(i);
        rep(i,0,N) num.push_back(1);
        rep(i,0,N) diff_weight.push_back(0);
    }
    ll root(ll x){
        if(x == parent[x]){
            return x;
        }else{
            ll r = root(parent[x]);
            diff_weight[x] += diff_weight[parent[x]];
            return parent[x] = r;
        }
    }
    void unite(ll a, ll b, ll w = 0){
        w += weight(a); w -= weight(b);
        a = root(a); b = root(b);
        if(a == b) return;
        parent[b] = a;
        ll sum = num[a] + num[b];
        num[a] = sum;
        num[b] = sum;
        diff_weight[b] = w;
    }

    bool same(ll a, ll b){ return root(a) == root(b);}
    ll sz(ll x){ return num[x];}

    ll weight(ll x){
        root(x);
        return diff_weight[x];
    }

    ll diff(ll a, ll b){
        return weight(b) - weight(a);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll a[55], b[55];
    rep(i,0,N) cin >> a[i];
    rep(i,0,N) cin >> b[i];
    rep(i,0,N){
        if(a[i] != b[i] && (a[i] - 1)/2 < b[i]){
            print(-1);
            return 0;
        }
    }
    vector<ll> res;
    rrep(val,50,1){
        bool ok = true;
        vector<ll> use;
        rep(i,1,val) use.push_back(i);
        rep(i,0,res.size()) use.push_back(res[i]);
        vector<ll> tree[55];
        ll dist[55][55];
        rep(i,0,51){
            rep(j,0,51){
                if(i == j) dist[i][j] = 0;
                else dist[i][j] = INF;
            }
        }
        rep(i,0,51){
            for(auto &e: use){
                ll after = i % e;
                dist[i][after] = 0;
            }
        }
        rep(k,0,51){
            rep(i,0,51){
                rep(j,0,51){
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
        rep(i,0,N){
            if(dist[a[i]][b[i]] != 0) ok = false;
        }
        if(not ok) res.push_back(val);
    }
    ll ans = 0;
    for(auto &e: res) ans += pow(2, e);
    print(ans);



    
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
inline void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  long long M, N, res;
  rd(N);
  rd(M);
  res =min_L(N, M/2);
  N -= res;
  M -= 2*res;
  res += M / 4;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190829-1

// --- original code ---
// {
//   ll N, M, res;
//   rd(N, M);
//   res = min(N, M/2);
//   N -= res;
//   M -= 2res;
//   res += M / 4;
//   wt(res);
// }


Measured memory_bytes: 256
//header{{{
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#include <boost/sort/spreadsort/spreadsort.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
//#include <boost/graph/graph_utility.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
//using namespace boost::multiprecision;
//using namespace boost::math;

typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS,
        boost::no_property, boost::property<boost::edge_weight_t, int> > Graph;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define bsort boost::sort::spreadsort::spreadsort
#define int int_fast64_t
using pii = pair<int,int>;

constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
template <class Func>

class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}
 
    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};
 
template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;

template <typename T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using Umap = gp_hash_table<K, V>;
using Trie = trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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

struct negrightshift {
    inline int operator() (const int &x, const unsigned offset) {
        return -(x >> offset);
    }
};
//}}}


signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    int n;
    cin >> n;

    vector<int> a(n);

    rep(i,n){
        cin >> a[i];
    }

    int preh = 0;
    int res = 0;

    rep(i,n){
        if(preh > a[i]){
            res += preh - a[i];
        }else{
            preh = a[i];
        }
    }

    cout << res << '\n';

    return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

vector<int> v;

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

    for(int i=0;i<3;++i){
        int j;
        std::cin >> j;

        v.emplace_back(j);
    }

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    std::cout << v.size() << std::endl;
}


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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N; string S;
    cin >> N >> S;

    int res = 0;
    int dp[N+1][N+1] {};
    for (int i = N-1; i >= 0; --i) {
        for (int j = N-1; j > i; --j) {
            if (S[i] == S[j]) {
                dp[i][j] = max(dp[i][j], dp[i+1][j+1] + 1);
            }
            res = max(res, min(dp[i][j], j-i));
        }
    }
    cout << res << endl;
    return 0;

}



Measured memory_bytes: 97920
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char[] pin = sc.next().toCharArray();
    if (pin[0] == pin[1]) {
      System.out.println("Bad");
      return;
    }
    if (pin[1] == pin[2]) {
      System.out.println("Bad");
      return;
    }
    if (pin[2] == pin[3]) {
      System.out.println("Bad");
      return;
    }
    System.out.println("Good");
  }

}

Measured memory_bytes: 21844
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		int n = sc.nextInt();
		long[] num = new long[9];
		int[] ups = new int[32];
		for (int u = 0; u < n; u++) {
			for (int i = 0; i < 9; i++)
				num[i] = Long.decode("0x"+sc.next());
			Arrays.fill(ups, 0);
			long m = 0;
			int c;
			long k = 0;
			for (int i = 0; i < 32; i++) {
				c = 0;
				for (int j = 0; j < 8; j++) {
					if (((num[j] >> i) & 1) == 1) {
						c++;
					}
				}
				int t;
				if ((((m>>i)+c) & 1) != ((num[8] >> i) & 1)) {
					k += (1L<<i);
					t = 1;
				} else {
					t = 0;
				}
				for (int j = 0; j < 8; j++) {
					m += ((((num[j] >> i) & 1)^t)<<i);
				}
			}
			out.println(Long.toHexString(k));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

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

using namespace std;

using ll = long long;

int main() {

    int N;
    cin >> N;
    vector<ll> xs;
    for (int i = 1; i <= N; i++) {
        if (i % 3 == 0 || i % 5 == 0 || (i % 3 == 0 and i % 5 == 0))
            continue;
        else
            xs.push_back(i);
    }
    ll sum = 0;
    for (auto &i : xs)
        sum += i;
    cout << sum << '\n';
    return 0;
}


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

int Na,s[10];

int N_len(int Na){
    for(int i=1;i<=10;i++){
        s[i-1]=Na%10;
        Na=Na/10;
        if(Na==0) return i;
    }
    return 0;
}

int main(){
    int N;
    cin>>N;
    int S_N=0,Na=N;
    for(int i=0;i<N_len(Na);i++){
        S_N+=s[i];
    }
    if(N%S_N==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
var
    s:ansistring;
    len,i,cnt,tot,t:longint;
begin
    readln(s);len:=length(s);
    if (s[1]='0') or (s[len]='1') then
        begin
            writeln(-1);
            exit;
        end;
    dec(len);
    for i:=1 to len div 2 do
        if s[i]<>s[len-i+1] then 
            begin
                writeln(-1);
                exit;
            end;
    for i:=1 to len do
        if s[i]='1' then inc(cnt);
    for i:=1 to cnt do
        writeln(i,' ',i+1);
    tot:=cnt+2;t:=0;
    for i:=1 to len do
        if s[i]='0' then 
            begin 
                writeln(cnt-i+t+2,' ',tot);
                inc(t);inc(tot);
            end;
end.

Measured memory_bytes: 1408
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){

            String plusMinus = sc.next();
            int ans = 0;

            for(int i = 0; i < plusMinus.length(); i++){
                String str = plusMinus.substring(i, i + 1);
                if(str.equals("+")) ans++;
                else ans--;
            }

            System.out.println(ans);

        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

Measured memory_bytes: 19924
function Main (K) {
  K = parseInt(K, 10);
  var ans = 0;
  for (var a = 1; a <= K; a++) {
    for (var b = 1; b <= K; b++) {
      for (var c = 1; c <= K; c++) {
        ans += gcd(a, b, c);
      }
    }
  }
  console.log(ans);
  function gcd() {
    var f = (a, b) => b ? f(b, a % b) : a
    var ans = arguments[0]
    for (var i = 1; i < arguments.length; i++) {
        ans = f(ans, arguments[i]); 
    }
    return ans 
  }
}

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

Measured memory_bytes: 34612
from collections import defaultdict
import sys
sys.setrecursionlimit(10**5)
def solve():
    N = int(input())
    G = defaultdict(list)

    for i in range(N-1):
        a, b = map(int,input().split())
        a -= 1
        b -= 1
        G[a].append((b,i))
        G[b].append((a,i))
    
    res = [0] * (N-1)
    dfs(0,-1,-1,G,res)
    print(max(res))
    print(*res, sep='\n')
    
def dfs(v,p,pc,G,res):
    next_c = 1
    for next_v, num in G[v]:
        if next_v == p:
            continue
        if next_c == pc:
            next_c += 1
        
        res[num] = next_c
        dfs(next_v,v,next_c,G,res)
        
        next_c += 1

if __name__ == '__main__':
    solve()

Measured memory_bytes: 112856
import bisect
n = int(input())
a = []
for i in range(n):
    temp = int(input())
    a.append(temp)
a.reverse()
b = [a[0]]
counter = 1
for i in range(1,n):
    if a[i] >= b[-1]:
        counter += 1
        b.append(a[i])
    else:
        ind = bisect.bisect_right(b,a[i])
        b[ind] = a[i]
print(counter)

Measured memory_bytes: 7840
n=int(input())
a=[int(i) for i in input().split()]
a.sort()

r=0
b=[]
for i in a:
  r+=i
  b.append(r)
ans=1

  
b.sort(reverse=True)
a.sort(reverse=True)

for i in range(1,n):
  if b[i] * 2 >=a[i-1]:
    ans+=1
  else:
    break

print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main()
{
    int N;
    string S;
    int count = 0;
    cin >> N >> S;
    rep(i, N - 2)
    {
        if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C')
        {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<cstdio>

#define MAXN 100000
int N,L,A[MAXN+5];

int main(){
    scanf("%d%d",&N,&L);
    for(int i=1;i<=N;i++)
        scanf("%d",A+i);
    for(int i=1;i<N;i++){
        if(A[i+1]+A[i]>=L){
            puts("Possible");
            for(int j=1;j<i;j++)
                printf("%d\n",j);
            for(int j=N-1;j>=i;j--)
                printf("%d\n",j);
            return 0;
        }
    }
    puts("Impossible");
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int C[202020];
int col[202020],R[202020];
ll dp[202020];

int main(){
  int N; cin>>N;
  int n=0;
  for(int i=1;i<=N;i++){
    int c; cin>>c;
    if(C[n]!=c) C[++n]=c;
  }
  for(int i=n;i>=1;i--){
    if(col[C[i]]!=0) R[i]=col[C[i]];
    col[C[i]]=i;
  }
  dp[0]=1;
  for(int i=1;i<=n;i++){
    (dp[i]+=dp[i-1])%=MOD;
    if(R[i]!=0) (dp[R[i]]+=dp[i])%=MOD;
  }
  cout<<dp[n]<<endl;
  return 0;
}


Measured memory_bytes: 4096
#include<iostream>
using namespace std;
int a[7]={0,0,9,0,909,0,90909};
int main()
{
	int n,m,cnt=0;
	cin>>n;
	m=n;
	while(m!=0)
	{
		cnt++;
		m/=10;
	}
	if(cnt==2)
		cout<<9;
	if(cnt==4)
		cout<<909;
	if(cnt==6)
		cout<<90909;
	if(cnt==1)
		cout<<n;
	if(cnt==3)
		cout<<9+n-(100-1);
	if(cnt==5)
		cout<<909+n-(10000-1);
}

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

using ll = long long;
#define repi(n) for (int i = 0; i < (n); i++)
#define repj(n) for (int j = 0; j < (n); j++)
#define repk(n) for (int k = 0; j < (n); k++)
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define repr(i, a, b) for (auto i = (a); i < (b); i++)
#define repv(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = max((t), (v)))
#define updatemin(t, v) (t = min((t), (v)))
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}

map<string, ll> m;
int main() {
  int n;
  cin >> n;
  ll re = 0;
  repi(n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    ll v = m[s];
    re -= v * (v - 1) / 2;
    re += (v + 1) * v / 2;
    m[s] = v + 1;
  }
  cout << re << endl;
}


Measured memory_bytes: 11136
#include <stdio.h>

int min(int a,int b,int c){
	if(a<b){
		if(a<c){
			return a;
		}else{
			return c;
		}
	}else{
		if(b<c){
			return b;
		}else{
			return c;
		}
	}
}

int main(void){
	int n,a,b,count[3]={0},p;
	scanf("%d\n%d %d",&n,&a,&b);
	for(int i=0;i<n;i++){
		scanf("%d",&p);
		if(p<=a) count[0]++;
		else if(p<=b) count[1]++;
		else  count[2]++;
	}
	printf("%d\n", min(count[0],count[1],count[2]));
	return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 1e5+10;

ll n, start;
ll x[MAXN];

ll gcd(ll a, ll b) {
  return b == 0 ? a : gcd(b, a % b);
}

void solve() {
  x[n] = start;
  sort(x, x + n + 1);
  ll ans = x[n] - x[0];
  for (int i=0;i<n;i++) {
    ans = gcd(ans, x[i+1] - x[i]);
  }
  cout << ans << endl;
}

int main() {
  cin >> n >> start;
  for (int i=0;i<n;i++) {
    cin >> x[i];
  }
  solve();
}


Measured memory_bytes: 1024