akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define forn(i,_n) for(int i=0;i<=(_n);++i)
#define forab(i,_a,_b) for(int i=(_a);i<=(_b);++i)
#define forrn(i,_n) for(int i=n-1;i>=0;--i)
#define forrab(i,_a,_b) for(int i=_a;i>=b;--i)
#define tcase int t;cin>>t;while(t--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);

typedef vector<int>vi;
typedef pair<int,int>ii;
typedef vector<ii>vii;
typedef set<int>si;
typedef map<string,int>msi;
typedef map<int,int>mii;
int mod=pow(10,9)+7;
int dc(const int n){
	int x=n;
	int c=0;
	while(x>0){
		x/=10;
		++c;
	}
	return c;
}
int n;
void solve(){
	cin>>n;
	int i=1;
	int count=0;
	int cn=dc(n);
	int ci=1;
	while(cn!=ci){

		if(ci&1){
			count+=pow(10,ci)-pow(10,ci-1);
		}
        ci+=1;
	}
	if(cn&1)
		count+=n-int32_t(pow(10,ci-1))+1;
	cout<<count<<endl;
	return;
}
int32_t main(){
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	//	freopen("output.txt","w",stdout);
	//#endif
	fastio
	solve();
	return 0;
}


Measured memory_bytes: 256
lines = $stdin.read
array = lines.split("\n")

#
# :u ノードのインデックス
# :k u の出次数
# :v u に隣接する頂点の番号
# :w 隣接する頂点への重み
# ---
# :visited 深さ優先探索用
# ---
# 閉路の判定のため深さ優先探索も実装してみる
#   深さ優先探索で親ノードへの戻り辺があれば、それは閉路である。トポロジカルソートでも検出できる。
#   Wikipedia - 閉路 より
#
INF  = Float::INFINITY
Node = Struct.new(:u, :k, :v, :w, :visited)

class Graph
  attr :nodes, :dist
  def initialize(n)
    @nodes = Array.new(n){ Node.new }
    @nodes = @nodes.map.with_index do |node,idx|
      node.u = idx
      node
    end
    @dist = Array.new(n).map{Array.new(n, 0)}
  end

  def add_graph_edge(u, v, w)
    #puts "#{u} -> #{v} (#{w})"
    if @nodes[u].v.nil?
      @nodes[u].v = [v]
      @nodes[u].w = {v=>w}
    elsif @nodes[u].v.is_a?(Array)
      @nodes[u].v << v
      @nodes[u].w = {v=>w}.merge(@nodes[u].w)
    else
      @nodes[u].v = [@nodes[u].v, v]
      @nodes[u].w = {v=>w}.merge(@nodes[u].w)
    end
    @nodes[u].k = if @nodes[u].v.is_a?(Array)
                    @nodes[u].v.length
                  else
                    1
                  end
  end

  def warshall_floyd()
    # initialize
    for i in 0...@nodes.length
      for j in 0...@nodes.length
        @dist[i][j] = if not @nodes[i].w.nil? and @nodes[i].w.has_key?(j)
                        @nodes[i].w[j]
                      else
                        INF
                      end
      end
      @dist[i][i] = 0
    end

    # calc
    for k in 0...@nodes.length
      for i in 0...@nodes.length
        for j in 0...@nodes.length
          if @dist[i][k] != INF and @dist[k][j] != INF
            @dist[i][j] = [@dist[i][j], @dist[i][k] + @dist[k][j]].min
          end
        end
      end
    end
  end

  def has_negative_cycle?()
    ans = false
    for v in 0...V
      ans = true if @dist[v][v] < 0
    end
    ans
  end
end

V,E = array[0].split(" ").map(&:to_i)
graph = Graph.new(V)

array[1..E].each do |s|
  s,t,d = s.split(" ").map(&:to_i)
  graph.add_graph_edge(s,t,d)
end

# execute WarshallFloyd !
graph.warshall_floyd()

if graph.has_negative_cycle?
  puts "NEGATIVE CYCLE"
else
  graph.dist.each do |d|
    puts d.map{|d| if d == INF; "INF" else d end}.join(" ")
  end
end



Measured memory_bytes: 9632
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	if (n == 0) return 1;
	if (n % 2) return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
	return (modpow(x * x % mod, n / 2) + mod) % mod;
}

int fact_memo[114514];
int fact(int n) {
	int ans = 1;
	if (fact_memo[n]) return fact_memo[n];
	rep(i, n) {
		ans *= (i + 1);
		if (mod <= ans) ans %= mod;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

int n;
int a[114514];
int s[114514];
int ans[114514];
int sum1, sum2;
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		sum1 += a[i];
	}
	rep(i, n) {
		s[i] = a[i] - a[(i + 1) % n];
	}
	rep(i, n) {
		if (i == 0) ans[i] = 1;
		else ans[2 * i % n] = ans[2 * (i - 1) % n] - s[2 * (i - 1) % n];
	}
	rep(i, n) {
		ans[i] *= 2;
		sum2 += ans[i];
	}
	rep(i, n) {
		cout << ans[i] - (sum2 - sum1) / n << " ";
	}
	cend;
}

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

int main(){
  int n, i, j, k;
  cin >> n;

  for(i=0; n>=100; i++){
    n -= 100;
  }
  for(j=0; n>=10; j++){
    n -= 10;
  }
  for(k=0; n>=1; k++){
    n -= 1;
  }

  if(i==7 || j==7 || k==7){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3568
n = gets.to_i
hs = gets.chomp.split.map(&:to_i)
dp = Array.new(n,10**18)
dp[0] = 0
(0..n-1).each do |i|
  dp[i+1] = [dp[i+1],dp[i] + (hs[i] - hs[i+1]).abs].min if i+1 < n
  dp[i+2] = [dp[i+2],dp[i] + (hs[i] - hs[i+2]).abs].min if i+2 < n
end
puts dp[n-1]

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


int main(){
    int n;
    cin>>n;
    int arr[n];
    int dp[n];
    dp[0]=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    dp[1]= abs(arr[1]-arr[0]);
    //cout<<dp[1]<<" ";
    //int ans= abs(arr[0]-arr[1]);
    for(int i=2;i<n;i++){

        dp[i]= min((abs(arr[i]-arr[i-1])+dp[i-1]),(abs(arr[i]-arr[i-2])+dp[i-2]));
        //cout<<dp[i]<<" ";
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

ll ans = 0;
ll n, m, q;
vector < pair< pair<ll,ll>, pair<ll,ll> > > v;

void solve(ll pos, vector <ll> seq)
{
    if(pos != n) {
        f(i,seq[pos-1],m) seq.pb(i), solve(pos+1,seq), seq.pop_back();
        return;
    }
    ll this_ans = 0;
    f(i,0,q-1) {
        ll a = v[i].ff.ff, b = v[i].ff.ss, c = v[i].ss.ff, d = v[i].ss.ss;
        a--; b--;
        if(seq[b] - seq[a] == c) this_ans += d;
    }
    ans = max(ans, this_ans);
}

int main()
{
    // Fast_IO();
    cin >> n >> m >> q;
    f(i,1,q) {
        ll a, b, c, d; cin >> a >> b >> c >> d;
        v.pb(mp(mp(a,b),mp(c,d)));
    }
    f(i,1,m) solve(1,vector<ll>(1,i));
    cout << ans;
    return 0;
}

Measured memory_bytes: 3640
#include<queue>
#include<string>
#include<iostream>

using namespace std;

int main ()
{
	string cmd;
	priority_queue<int> Q;
	while(cin>>cmd&&cmd!="end"){
		if(cmd=="insert"){
			int n;
			cin>>n;
			Q.push(n);
		} else if(cmd=="extract"){
			int max=Q.top();
			Q.pop();
			cout<<max<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 6924
#include <iostream>
#include <string>

using namespace std;
int main (){
    int a,b;
    cin >> a >>b ;
    string s;
    cin >> s;
    bool jud=1;
    if(s.size()!=a+b+1) jud=0;
    if(jud){
        for (int i = 0; i < a; i++){
            if(s[i]-'0'<0 || s[i]-'9'>0) jud=0;
        }
        if(s[a]!='-') jud=0;
        for (int i = a+1; i < a+b+1; i++)
        {
            if(s[i]-'0'<0 || s[i]-'9'>0) jud=0;
        }
    }
    if(jud) cout << "Yes\n";
    else    cout << "No\n";
}

Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	int res = n / 2 + n % 2;
	cout << res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int total = 0;
		int i;
		for(i = 1 ; i <= X ; i++) {
			total += i;
			if(total >= X) {
				break;
			}
		}
		System.out.println(i);
	}
}


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

using namespace std;
int main()

{

int sevencnt = 0, fivecnt = 0;
	int num[3];
		for (int i = 0; i < 3; i++)
		{
			cin >> num[i];
		}
 
	for (int i = 0; i < 3; i++)
	{
		if (num[i] == 7)
		{
			sevencnt++;
		}
		else if (num [i] == 5)
		{
			fivecnt++;
		}
	}
 
	if (fivecnt == 2 && sevencnt == 1)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
    
    
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int main(void)
{
    int i,a,b,ans;
    string s,t;
    bool c = true;

    cin >> s >> t;

    for(i=0;i<s.size();i++){
        if(s[i] != t[i]){
            c = false;
        }
    }

    if(s.size()+1 != t.size()){
        c = false;
    }

    if(c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main() {
  long A,B,K;
  cin >> A >> B >> K;
 
    if (A>=K) {
      A=A-K;}
    else {
      K=K-A;
      A=A-A;
      if (B>=K) {
        B=B-K;}
      else {
        B=B-B;}
        
    }
    
  cout << A << " " << B <<endl;
      
    
}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    for _ in range(k):
        imos = [0]*(n+1)
        finish = True
        for i, brightness in enumerate(a):
            if finish and brightness != n:
                finish = False
            begin = max(i - brightness, 0)
            end = i + brightness
            imos[begin] += 1
            if end < n:
                imos[end + 1] -= 1
        if finish:
            break
        for i in range(n-1):
            imos[i+1] += imos[i]
        a = imos[:-1]
    print(*a, sep=" ")


if __name__ == "__main__":
    main()


Measured memory_bytes: 155156
#include<cstdio>
using namespace std;
int main(){
  int n,a,flag;
  char s[101],t[101];
  scanf("%d",&n);
  scanf("%s",s);
  scanf("%s",t);
  a=n;
  for(int i=0;i<n;i++){
    flag=1;
    for(int j=0;j+i<n;j++)
      if(s[i+j]!=t[j]){
        flag=0;
      }
    if(flag){
      a=i;
      break;
    }
  }
  printf("%d\n",n+a);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector< int > a(n);
    int ans = 0;
    int tmp = 1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == tmp) {
            tmp++;
        } else {
            ans++;
        }
    }
    cout << (ans == n ? -1 : ans) << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

int n, x, y;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++) {
		int num;
		cin >> num;
		if(num % 4 == 0) x++;
		else if(num % 2 == 0) y++;
	}
	cout << (2 * x + max(1, y) >= n ? "Yes" : "No");
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int i_a = 0;
        int i_b = 0;
        int i_c = 0;

        char next = 'a';
        String ans = "";

        while(true){
            if(next == 'a') {
                if(i_a == S_a.length()) {
                    ans = "A";
                    break;
                } else {
                    next = S_a.charAt(i_a);
                    i_a++;
                }
            } else if(next == 'b') {
                if(i_b == S_b.length()) {
                    ans = "B";
                    break;
                } else {
                    next = S_b.charAt(i_b);
                    i_b++;
                }
            } else {
                if(i_c == S_c.length()) {
                    ans = "C";
                    break;
                } else{
                    next = S_c.charAt(i_c);
                    i_c++;
                }
            }
        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 23380
use std::io::stdin;

#[allow(dead_code)]
fn input_ints() -> Vec<i32> {
    let mut st = String::new();
    match stdin().read_line(&mut st) {
        Ok(_) => st.split_whitespace().map(|s| s.parse().unwrap()).collect(),
        Err(_) => "".split_whitespace().map(|s| s.parse().unwrap()).collect(),
    }
}

#[allow(dead_code)]
fn input_strs() -> Vec<String> {
    let mut st = String::new();
    match stdin().read_line(&mut st) {
        Ok(_) => st.split_whitespace().map(|s| s.to_string()).collect(),
        Err(_) => "".split_whitespace().map(|s| s.to_string()).collect(),
    }
}

fn sum(v: &Vec<i32>) -> i32 {
    let mut s = 0;
    for i in v {
        s += *i;
    }
    s
}

#[allow(unused_variables)]
fn solve(){
    let n = input_ints()[0];
    let ts = input_ints();
    let m = input_ints()[0];

    let total: i32 = sum(&ts);

    for i in 0..m {
        let pair = input_ints();
        let idx = pair[0] as usize;
        println!("{}", total - (ts[idx-1] - pair[1]));
    }
}

fn main() {
    solve();
}


Measured memory_bytes: 380
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int[] s, h, c, d;
    int i, a;
    String str;

    n = sc.nextInt();
    s = new int[13];
    h = new int[13];
    c = new int[13];
    d = new int[13];

    for(i = 0;i < n;i++){
      str = sc.next();
      a = sc.nextInt();
      if("S".equals(str)){
        s[a - 1] = 1;
      }else if("H".equals(str)){
        h[a - 1] = 1;
      }else if("C".equals(str)){
        c[a - 1] = 1;
      }else{
        d[a - 1] = 1;
      }
    }

    for(i = 0;i < 13;i++){
      if(s[i] != 1){
        System.out.println("S " + (i + 1));
      }
    }
    for(i = 0;i < 13;i++){
      if(h[i] != 1){
        System.out.println("H " + (i + 1));
      }
    }
    for(i = 0;i < 13;i++){
      if(c[i] != 1){
        System.out.println("C " + (i + 1));
      }
    }
    for(i = 0;i < 13;i++){
      if(d[i] != 1){
        System.out.println("D " + (i + 1));
      }
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

}

Measured memory_bytes: 18104
x, n = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp.split(" ").map(&:to_i)
arr = [*(-200)..200]
arr = arr.map(&:to_i)
#p arr
s.each do |i|
    arr.delete(i)
end
ar = []
abs = 1000
arr.each do |i|
    if (i - x).abs < abs
        ar << i
    end
    abs = [(i - x).abs,abs].min
end
puts ar.pop

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

int main(){
    int X, x, c;
    cin >> X;
    x = X;
    c = 0;
    while (x > 0){
        c = c + x % 10;
        x = x / 10;
    }
    string a = "No";
    if (X % c == 0) a = "Yes";
    cout << a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-') ch = getchar();
	if(ch == '-') flag = -1,ch = getchar();
	while(isdigit(ch)) x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

int main() {

	int a = read(),b = read(),c = read();
	printf("%d\n",min(c,a + b + 1) + b);
	return 0;
}

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

const int mxN = 2e5;
int n, k, a[mxN];

int check(int x)
{
    int amt = 0;
    // for (int i = 0; i < n; i++)
    // {
    //     amt = a[i] / x;
    //     if (a[i] % x) amt++;
    // }

    for (int i = 0; i < n; i++) amt += (a[i] - 1) / x;

    return amt > k;
}

int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    int pos = 0, mx = 1e9;
    for (int i = mx; i >= 1; i /= 2)
    {
        while(check(pos + i)) pos += i;
    }

    cout << pos + 1 << "\n";
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;
typedef unordered_map<int,int> uoii;
typedef unordered_map<string,int> uosi;

const int MOD = 1e9+7;

const int INF = 1e10;




int32_t main()
{
    IOS
    int n;
    string s;
    int p;
    cin>>n>>p>>s;
    map<int,int>mp;
    int ans=0;;
    if(p==2||p==5){
        for(int i=0;i<n;i++){
            if((s[i]-'0')%p==0){
                ans+=i+1;
            }
        }
    }else{
        int m=0;
        int ten=1;
        mp[0]++;
        for(int i=n-1;i>=0;i--){
            m+=(s[i]-'0')*ten;
            m%=p;
            ten*=10;
            ten%=p;
            ans+=mp[m];
            mp[m]++; 
        }
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 1044
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mx=3002;
ll dp[mx][mx];
//bool vis[mx][mx];
ll arr[mx];
ll solve(ll n){

    for(ll L=n;L>0;L--){
        for(ll R=L;R<=n;R++){
            if(L==R){
                dp[L][R]=arr[L];
            }else{
                dp[L][R]=max(arr[L]-dp[L+1][R],arr[R]-dp[L][R-1]);
            }
        }
    }
    return dp[1][n];

}


int main(){
    int n;
    cin>>n;
        for(int i=1;i<=n;i++){
            cin>>arr[i];
        }
        cout<<solve(n);

}


Measured memory_bytes: 70016
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::min;

fn dfs(
    n: usize,
    a: i64,
    b: i64,
    c: i64,
    i: usize,
    ai: i64,
    bi: i64,
    ci: i64,
    takes: &Vec<i64>,
) -> i64 {
    if i == n {
        if min(ai, min(bi, ci)) > 0 {
            return (a - ai).abs() + (b - bi).abs() + (c - ci).abs() - 30;
        }
        return std::i64::MAX / 10;
    }

    let ar = dfs(n, a, b, c, i + 1, ai + takes[i], bi, ci, takes) + 10;
    let br = dfs(n, a, b, c, i + 1, ai, bi + takes[i], ci, takes) + 10;
    let cr = dfs(n, a, b, c, i + 1, ai, bi, ci + takes[i], takes) + 10;
    let dr = dfs(n, a, b, c, i + 1, ai, bi, ci, takes);

    return min(min(ar, br), min(cr, dr));
}

fn main() {
    let n: usize = read();
    let a: i64 = read();
    let b: i64 = read();
    let c: i64 = read();
    let mut takes: Vec<i64> = vec![];

    for _ in 0..n {
        takes.push(read());
    }

    let result = dfs(n, a, b, c, 0, 0, 0, 0, &takes);
    println!("{}", result);
}


Measured memory_bytes: 2140
//There was and will always be only one Chester. RIP legend
//--------------------Life is beautiful--------------------
#include<bits/stdc++.h>
using namespace std;
#define Nilesh ios_base::sync_with_stdio(false);
int main()
{
	Nilesh
	int n;
	cin>>n;
	int a[n],pre_a[n],b[n],pre_b[n];
	int bharo[n+1];
	int k=0;
	int sum=0;
	for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        pre_a[i]=sum;
    }
    sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
        sum+=b[i];
        pre_b[i]=sum;
    }
    bharo[k++]=a[0]+sum;
    /*for(int i=0;i<n;i++)
    {
        cout<<pre_a[i]<<" ";
    }
    cout<<"\n";
    for(int i=0;i<n;i++)
        cout<<pre_b[i]<<" ";*/
    for(int i=1;i<n-1;i++)
    {
        bharo[k++]=pre_a[i]+pre_b[n-1]-pre_b[i-1];
        //cout<<pre_a[i]+pre_b[n-1]-pre_b[i-1]<<" ";
    }
    //cout<<endl;
    bharo[k++]=b[n-1]+pre_a[n-1];

    cout<<*max_element(bharo,bharo+k);


}


Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long n;
long a;
int main(){
    scanf("%ld%ld", &n, &a);
    printf("%ld\n", n*n - a);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

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

  double lth = (M_PI / 2.1);
  double rth = 0.0;
  double cth;
  if ((a*a*b) <= (2*x)) {

    while (true) {
      cth = (lth+rth) / 2.0;
      double vol = a * a * a * tan(cth) / 2.0;
      if (abs(vol - (a*a*b-x)) < 0.00000000001) {
        break;
      } else if (vol > (a*a*b-x)) {
        lth = cth;
      } else {
        rth = cth;
      }
    }

  } else {

    while (true) {
      cth = (lth+rth) / 2.0;
      double vol = a * b * b * tan(cth) / 2.0;
      if (abs(vol - x) < 0.00000000001) {
        cth = (M_PI / 2.0) - cth;
        break;
      } else if (vol > x) {
        lth = cth;
      } else {
        rth = cth;
      }
    }

  }

  printf("%.10f\n", 180.0*cth/M_PI);

  return 0;
}


Measured memory_bytes: 256
# 2020/08/02
# AtCoder Beginner Contest 174 - B

# Input
n, d = map(int,input().split())
ans = 0

# Calc
for i in range(n):
    x, y = map(int,input().split())
    if (x ** 2 + y ** 2) ** (1/2) <= d:
        ans = ans + 1

# Output
print(ans)


Measured memory_bytes: 9624
#include<stdio.h>
int main () {
  int i, temp, a, minj, j, k = 0;
  int A[100];

  scanf("%d\n", &a);

  for (i = 0; i < a; i++) {
    scanf("%d", &A[i]);
  }

  for (i = 0; i < a - 1; i++) {
    minj = i;
    for (j = i; j < a; j++) {
      if (A[j] < A[minj]) {
        minj = j;
      }
    }
    temp = A[i];
    A[i] = A[minj];
    A[minj] = temp;

    if (i != minj) {
      k++;
    }
  }

  for (i = 0; i < a; i++) {
    if (i > 0) {
      printf(" ");
    }
    printf("%d", A[i]);
  }

  printf("\n");
  printf("%d\n", k);

  return 0;
}

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

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

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= (N - i); j++) {
      int total = i * 1000 + j * 5000 + (N - i - j) * 10000;
      if (total == Y) {
                cout << N-i-j << " " << j<< " " <<  i<< endl;
        return 0;
      }
    }
  }

  cout << -1 << " " << -1 << " " <<  -1<< endl;  

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<LL> C(N-1);
    vector<LL> S(N-1);
    vector<LL> F(N-1);
    rep(i,N-1)cin >> C[i] >> S[i] >> F[i];
    vector<LL> ans(N,0);
    LL t;
    rep(i,N-1){
        t = S[i];
        for(int j = i;j<N-1;j++){
            if(t >= S[j]){
                if((t-S[j]) % F[j] == 0){
                    t += C[j];
                }
                else{
                    t += F[j] - (t % F[j]) + C[j];
                }
            }
            else{
                t = S[j] + C[j];
            }
        }
        ans[i] = t;
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <climits>

//find out the use of the below
#include <list>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-100
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
bool vis[100005];
vector<int> g[100005];
int n, k;
long long finres = 1;
const int rt = 1;//root
const int mod = (int)1e9+7;




void dfs(int u) {
    int prev; 
    if (u == rt){
        prev = k;
        finres = (finres*k)%mod;
    } else {
        prev = k-1;
    }
    vis[u] = 1;
    for (int v : g[u]){
        if (vis[v])
            continue;
        vis[v] = 1;
        prev--;
        finres = (finres*prev)%mod;
        dfs(v);
    }
    
}

    
int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt","w", stdout);
    cin >> n >> k; 
    for (int i = 0; i < n-1; ++i){
        int a, b;
        scanf("%d %d", &a, &b);
        g[a].pb(b);
        g[b].pb(a);
    }
    
    dfs(1);
        cout << finres;
    return 0;
}
/* BEFORE submitting, check for:
 *  1. Integer overflow
 *  2. Float/Double precision errors
 *  3. Array index out of bounds
 *  4. Edge cases.(n=1, n=max, etc.)
 *  5. Time complexity. No TLEs
 */



Measured memory_bytes: 9344
from collections import deque
def sol():
    n,m=map(int,input().split())
    d={}
    for i in range(m):
        u,v=map(int,input().split())
        if u in d:
            d[u].append(v)
        else:
            d[u]=[v]
    s,t=map(int,input().split())
    ans=chk=0
    w=deque([0,s])
    #tmp=[0]*(n+1)
    tmp=[[0,0,0] for i in range(n+1)]
    ans=1
    n+=n//2
    n*=2
    while n:
        x=w.pop()
        if x==0:
            ans+=1
            n-=1
            w.appendleft(0)
        elif x in d:
            for j in d[x]:
                if ans%3==0 and j==t:
                    print(ans//3)
                    exit()
                if tmp[j][ans%3]==0:
                    w.appendleft(j)
                    tmp[j][ans%3]=1
    print(-1)

if __name__=="__main__":
    sol()


Measured memory_bytes: 78296
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

bool compare(tuple<int, string, int> a, tuple<int, string, int> b) {
    string s = get<1>(a);
    if (get<1>(a) != get<1>(b)) {
        return get<1>(a) < get<1>(b);
    } else {
        return get<2>(a) > get<2>(b);
    }
}

int main() {
    int n;
    cin >> n;
    vector<tuple<int, string, int>> res(n);
    for (int i = 0; i < n; ++i) {
        string s;
        int p;
        cin >> s >> p;
        res[i] = make_tuple(i + 1, s, p);
    }

    sort(res.begin(), res.end(), compare);

    for (int i = 0; i < n; ++i) {
        cout << get<0>(res[i]) << endl;
    }

    return 0;
}


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

typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const int MAX_N = 1e6 + 1;

int N;
string S;

int memo[MAX_N];

bool check(int p, int q)
{
  memset(memo, 0, sizeof(memo));
  memo[0] = p;
  memo[1] = q;

  FOR(si, 1, N - 1) {
    /*
    cout << si << endl;
    REP(j, N) {
      cout << (memo[j] > 0 ? 'W' : 'S');
    }
    cout << endl;
    */
    if (memo[si] == 0) {
      if (S[si] == 'o') {
	memo[(si + 1) % N] = memo[si - 1];
      } else {
	memo[(si + 1) % N] = (memo[si - 1] + 1) % 2;
      }
    } else {
      if (S[si] != 'o') {
	memo[(si + 1) % N] = memo[si - 1];
      } else {
	memo[(si + 1) % N] = (memo[si - 1] + 1) % 2;
      }
    }
  }

  bool res = true;
  if (memo[0] == 0) {
    if (S[0] == 'o') res &= (memo[N - 1] == memo[1]);
    else             res &= (memo[N - 1] != memo[1]);
  } else {
    if (S[0] != 'o') res &= (memo[N - 1] == memo[1]);
    else             res &= (memo[N - 1] != memo[1]);
  }

  if (memo[N - 1] == 0) {
    if (S[N - 1] == 'o') res &= (memo[N - 2] == memo[0]);
    else                 res &= (memo[N - 2] != memo[0]);
  } else {
    if (S[N - 1] != 'o') res &= (memo[N - 2] == memo[0]);
    else                 res &= (memo[N - 2] != memo[0]);
  }

  return res;
}

int main()
{
  cin >> N >> S;

  REP(i, (1 << 2)) {
    int p = i & 1;
    int q = (i >> 1) & 1;
    // cout << p << q << endl;
    if (check(p, q)) {
      
      REP(j, N) {
	// cout << memo[j];
	cout << (memo[j] > 0 ? 'W' : 'S');
      }
      cout << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}


Measured memory_bytes: 4480
import math

L, N = (int(i) for i in input().split())
X = [int(input()) for _ in range(N)]
X.insert(0, 0)

X_r = [L - i for i in reversed(X)]
X_r.insert(0, 0)
X_r.pop()

def lsum(l):
    s = 0
    for i in l:
        s += i
        yield s

X_sum = list(lsum(X))
X_r_sum = list(lsum(X_r))

def f_l(p, n):
    N_tmp = N - n
    a = N_tmp // 2
    if N_tmp == 0:
        return 0
    elif N_tmp % 2 == 0:
        return 2 * X_sum[a] + X_r_sum[a + n] + X_r_sum[a + n - 1] - 2 * X_r_sum[n] + p
    else:
        return X_sum[a+1] + X_sum[a] + 2 * X_r_sum[a + n] - 2 * X_r_sum[n] + p


def f_r(p, n):
    N_tmp = N - n
    a = N_tmp // 2
    if N_tmp == 0:
        return 0
    elif N_tmp % 2 == 0:
        return 2 * X_r_sum[a] + X_sum[a + n] + X_sum[a + n - 1] - 2 * X_sum[n] + p
    else:
        return X_r_sum[a+1] + X_r_sum[a] + 2 * X_sum[a + n] - 2 * X_sum[n] + p

max_l = max(X[i] + f_r(X[i], i) for i in range(1, N+1))
max_r = max(X_r[i] + f_l(X_r[i], i) for i in range(1, N+1))

print(max(max_l, max_r))


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

int main(){
  int N , l , r;
  int S = 0;
  cin >> N;
  
  for( int i = 0 ; i < N ; ++i ){
    cin >> l >> r;
    
    S += r - l + 1;
  }
  
  cout << S << endl;
}

Measured memory_bytes: 256
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define int long long int
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=0;i<n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s[li];
vector<int> v;
vector<string> vv;

main(void){
	fio();
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
		vv.pb(s[i]);
	}
	int bas=0;
	sort(vv.begin(),vv.end());
	FOR{
		flag=0;
		//~ cout<<vv[i]<<" "<<vv[bas]<<endl;
		//~ if(s[bas])
		if(vv[i]!=vv[bas]){v.pb(i-bas);bas=i;flag=1;}
	}
	if(flag==0)
		v.pb(n-bas);
	for(int i=0;i<(int)v.size();i++){
		//~ cout<<v[i]<<endl;
		cev+=(v[i]*(v[i]-1))/2;
	}
	cout<<cev<<endl;
	return 0;
}


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

class Point {
public:
  double x;
  double y;
  Point(double x = 0, double y = 0) : x(x), y(y) {}
  Point operator +(Point p) { return Point(x+p.x, y+p.y); }
  Point operator -(Point p) { return Point(x-p.x, y-p.y); }
  Point operator *(double a) { return Point(x*a, y*a); }
};
typedef Point Vector;

double dot(Vector a, Vector b) {
  return a.x*b.x + a.y*b.y;
}

double cross(Vector a, Vector b) {
  return a.x*b.y - a.y*b.x;
}

double norm(Vector v) {
  return v.x*v.x + v.y*v.y;
}

double abs(Vector v) {
  return sqrt(norm(v));
}

class Segment {
public:
  Point p1;
  Point p2;
  Segment(Point p1=Point(0,0), Point p2=Point(0,0)) : p1(p1), p2(p2) {}
};
typedef Segment Line;

Point project(Segment s, Point p) {
  Vector base = s.p2 - s.p1;
  double t = dot(p - s.p1, base)/norm(base);
  return s.p1 + base*t;
}

int ccw(Point p0, Point p1, Point p2) {
  Vector a = p1 - p0;
  Vector b = p2 - p0;
  if(cross(a, b) > 0) return 1;
  if(cross(a, b) < 0) return -1;
  if(dot(a, b) < 0) return 2;
  if(norm(a) < norm(b)) return -2;
  return 0;
}

bool isIntersect(Point p1, Point p2, Point p3, Point p4) {
  return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
	  ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}

bool isIntersect(Segment s1, Segment s2) {
  return isIntersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

Point getCrossPoint(Segment s1, Segment s2) {
  Vector base = s2.p2 - s2.p1;
  double d1 = abs(cross(base, s1.p1 - s2.p1));
  double d2 = abs(cross(base, s1.p2 - s2.p1));
  double t = d1/(d1+d2);
  return s1.p1 + (s1.p2-s1.p1)*t;
}

int main() {
  while(1) {
    Segment s[3];
    cin >> s[0].p1.x >> s[0].p1.y >> s[0].p2.x >> s[0].p2.y;
    if(s[0].p1.x == 0 && s[0].p1.y == 0 &&
       s[0].p2.x == 0 && s[0].p2.y == 0    ) break;
    for(int i = 1; i < 3; i++) {
      cin >> s[i].p1.x >> s[i].p1.y >> s[i].p2.x >> s[i].p2.y;
    }

    double S = -1;
    bool flag = true;
    for(int i = 0; i < 3; i++) {
      if(!isIntersect(s[i], s[(i+1)%3])) {
	flag = false;
	break;
      }
    }
    if(flag) {
    Point p[3];
    for(int i = 0; i < 3; i++) {
      p[i] = getCrossPoint(s[i], s[(i+1)%3]);
    }
    
    S = abs(p[1] - p[0]) * abs(project(Segment(p[0], p[1]), p[2]) - p[2]) / 2;
    }

    if(S >= 1900000) cout << "dai-kichi" << endl;
    else if(S >= 1000000) cout << "chu-kichi" << endl;
    else if(S >= 100000) cout << "kichi" << endl;
    else if(S > 0) cout << "syo-kichi" << endl;
    else cout << "kyo" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let mut v = read_vec::<u32>();
    v.sort();
    println!("{}", v[2]-v[0]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,p,i,r=2e18+1,r1,p1,q,sum=0,r2=2e18+1;
   cin>>n;
   p=sqrt(n);
   for(i=1; i<=p; i++)
   {
       if(n%i==0 && (i+(n/i))<r2)
       {
           r2=(i+(n/i));
       }
   }
   cout<<(r2)-2;
    }


Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>
#include <fstream>
#include <ctime>

using namespace std;
using ll = long long;

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

template<typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct ToUpper {
    char operator()(char c) { return toupper(c); }
};

struct ToLower {
    char operator()(char c) { return tolower(c); }
};

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

    string S;
    cin >> S;

    int ans = 0;
    int len = S.length();
    string tmp = "";
    FOR(i, 0, len) {
        if (tmp.length() > 1) {
            tmp = S[i];
            ans++;
        }
        else if (tmp[0] == S[i]) {
            tmp += S[i];
            i++;
            if (i >= len)break;
            ans++;
        }
        else {
            tmp = S[i];
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 720
n = gets.to_s.to_i

g = Array.new(n){ [] }
(n-1).times do |i|
  a, b = gets.to_s.split.map{|t| t.to_i - 1 }
  g[a] << [b, i]
  g[b] << [a, i]
end

q = [[0, -1, -1]]

ans = Array.new(n-1)
while q[0]
  v, parent, parent_color = q.pop
  color = 0
  g[v].each do |(u, i)|
    next if u == parent
    # p [v, color] if i == 0
    color += 1
    color += 1 if color == parent_color
    # p [v, color] if i == 0
    ans[i] = color
    q << [u, v, color]
  end
end
# puts "ans"
puts ans.max, ans

Measured memory_bytes: 27900
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  int a;
  cin >> a;
  string s;
  cin >> s;
  if (a >= 3200)
    cout << s << endl;
  else
    cout << "red" << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};

int main () {
    int x; cin >> x;
    for (int i = 0; i <= 7; i++) {
        if (400 + 200 * i <= x && x < 600 + 200*i) cout << 8-i << endl;
    }

    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld double 
#define  pb push_back
#define  ff(n) for(i=0; i<n; i++)
#define mo 10000
ll max(ll a,ll b){return (a>b)?a:b;}
int main()
{
    ll n,m=0,i,x,y,k=0,j;
    cin>>n>>k;
    cout<<n*k<<endl;

}


Measured memory_bytes: 3636
MOD = 10**9+7
ONE = '1'.freeze
def inv(x)
    res = 1 # 逆元をどんどんかけるやつ
    beki = x # 逆元を計算したい値のMOD化でのべき乗
    (MOD - 2).to_s(2).reverse.chars do |digest|
        res = (beki * res) % MOD if digest == ONE
        beki = (beki * beki) % MOD
    end
    res
end

str = gets.split
N,K = str[0].to_i, str[1].to_i
a = Array.new(N)
str = gets.split
for i in 0...N do
    a[i] = str[i].to_i
end
a.sort!

answer = 0
s = 1
for i in K..N do
    b = (a[-i] * s) % MOD
    answer -= b
    answer += MOD
    answer %= MOD
    s *= i
    s *= inv(i-K+1)
    s %= MOD
end
a.reverse!
s = 1
for i in K..N do
    b = (a[-i] * s) % MOD
    answer += b
    answer %= MOD
    s *= i
    s *= inv(i-K+1)
    s %= MOD
end
puts answer

Measured memory_bytes: 11292
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	for(int i=1;i<=20000;i++){
		int a1=i*0.08;
		int a2=i*0.1;
		if(a1==a && a2==b){
			cout<<i;
			return 0;
		}
	} 
	cout<<-1;
	return 0;
} 

Measured memory_bytes: 256
n,m=map(int,input().split())
sc=[]
for _ in range(m):
  s,c=map(int,input().split())
  sc.append([s,c])
for i in range(1000):
  j=list(str(i))
  if len(j)==n:
    for k in range(m):
      s,c=sc[k]
      if j[s-1]!=str(c):
          break
    else:
      print(i)
      exit()
print(-1)

Measured memory_bytes: 9024
// Created by  Ambesh kumar
#include "bits/stdc++.h"

//I already compile this file in my computer system to save the time
//if get the compiler error then you should change this header to
// #include "bits/stdc++.h"  ---> #include <bits/stdc++.h>

using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0, lim - 1);
	return uid(rang);
}
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=================================================================================================================================//

vi g[N];
int a[N];






void solve() {
	int i = 0, j, n, m, k;

	cin >> n ;

	ll arr[n];

	fo(i, n)
	cin >> arr[i];

	ll t[n + 3];

	t[0] = 0;
	t[1] = abs(arr[0] - arr[1]);

	Fo(i, 2, n )
	{

		t[i] = min(t[i - 1] + abs(arr[i] - arr[i - 1]), t[i - 2] + abs(arr[i ] - arr[i - 2]));

		//deb2(t[i], i);
	}



	cout << t[n - 1] << '\n' ;

}







int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());

	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}







Measured memory_bytes: 12240
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

    static List<String> list_ = new LinkedList<String>();

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        list_.add(scan.next());
        int totalQueryCount = Integer.parseInt(scan.next());

        boolean isReverse = false;
        for (int i = 0; i < totalQueryCount; i++) {
            int query1 = Integer.parseInt(scan.next());
            if (query1 == 1) {
                if (isReverse) {
                    isReverse = false;
                } else {
                    isReverse = true;
                }
            } else {
                int query2 = Integer.parseInt(scan.next());
                String query3 = scan.next();
                if (query2 == 1) {
                    t2f1(query3, isReverse);
                } else {
                    t2f2(query3, isReverse);
                }
            }
        }

        StringBuilder builder = new StringBuilder();
        for (String s : list_) {
            builder.append(s);
        }

        if (isReverse) {
            builder.reverse();
        }

        System.out.println(builder.toString());
        scan.close();
    }

    public static void t2f1(String input, boolean isReverse) {
        if (!isReverse) {
            list_.add(0, input);
        } else {
            list_.add(input);
        }
    }

    public static void t2f2(String input, boolean isReverse) {
        if (!isReverse) {
            list_.add(input);
        } else {
            list_.add(0, input);
        }
    }

}


Measured memory_bytes: 103232
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;

struct Card{char suit,value;};

void trace(struct Card a[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i>0) cout<<' ';
    cout<<a[i].suit<<a[i].value;
  }
  cout<<endl;
}

void selectionsort(struct Card a[],int n){
  for(int i=0;i<n;i++){
    int minj=i;
    for(int j=i;j<n;j++){
      if(a[j].value<a[minj].value) minj=j;
    }
    swap(a[i],a[minj]);
  }
}

void bubblesort(struct Card a[],int n){
  for(int i=0;i<n;i++){
    for(int j=n-1;j>=i+1;j--){
      if(a[j].value<a[j-1].value) swap(a[j],a[j-1]);
    }
  }
}

bool isStable(struct Card c1[], struct Card c2[],int n){
  for(int i=0;i<n;i++){
    if(c1[i].suit!=c2[i].suit) return false;
  }
  return true;
}

int main() {
  int n;
  cin>>n;
  Card c1[n],c2[n];
  for(int i=0;i<n;i++) cin>>c1[i].suit>>c1[i].value;
  for(int i=0;i<n;i++) c2[i]=c1[i];
  bubblesort(c1,n);
  selectionsort(c2,n);
  trace(c1,n);
  cout<<"Stable"<<endl;
  trace(c2,n);
  if(isStable(c1,c2,n)) cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
  return 0;
}



Measured memory_bytes: 3112