akhauriyash/Code-Regression huggingface dataset:
use std::io::prelude::*;
use std::io;

fn main() {
    let mut stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_to_string(&mut buf).unwrap();
    let a: i32 = buf.trim()[..].parse().unwrap();
    if a == 3 || a == 5 || a == 7 {
        println!("YES");
    } else {
        println!("NO");
    }
}

Measured memory_bytes: 4352
#include <stdio.h>
int a,b,c,ans;
int main() {
 scanf("%d %d %d",&a,&b,&c);
 ans=b/a;
 if(ans>c)
  {printf("%d",c);} 
 else{printf("%d",ans);}
  
  
  
  
  
  
  
  return 0;
}

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

string solve(int n){
	string res;
	while( n != 0 ){
		int m = n % -10, next = n / -10;
		if( m < 0 ){
			m += 10;
			next++;
		}
		res.push_back('0' + m);
		n = next;
	}
	reverse(res.begin(), res.end());
	return res;
}

int main(){
	int n;
	while( cin >> n , n ) cout << solve(n) << endl;;
}

Measured memory_bytes: 1192
L = list(map(int, input().split()))

A = L[0]
B = L[1]
C = L[2]

if L.count(A) == 1 and L.count(B) == 1 and L.count(C) == 1:
  	print("No")
elif L.count(A) == 2 or L.count(B) == 2 or L.count(C) == 2:
  	print("Yes")
else:
  	print("No")
 

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include"custom_header.h"
#else
#define openfile 
#endif
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define ll long long
#define ld long double
#define fo(i,v,e) for(v=i;v<e;v++)
#define rfo(i,v,e) for(v=i;v>e;v--)
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define vl vector<ll>
#define sz(x) (ll)x.size()
#define vvl vector<vl>
#define vpl vector<pll>
const ll mod = 1000000007;
void solve()
{
    ll n,m,i,j,x,y,k;cin>>n>>m>>k;
    vl cc(m,0),rc(n,0);set<pll,greater<pll>> cnt;
    vector<set<int>> row(n);
    fo(0,i,k)
    {
        cin>>x>>y;
        x--;y--;
        cc[y]++;rc[x]++;
        row[x].insert(y);
    }
    fo(0,i,m)
    {
        cnt.insert({cc[i],i});
    }
    ll ans = 0;
    fo(0,i,n)
    {
        ll temp = 0;
        for(auto x:cnt)
        {
            if(row[i].find(x.second)==row[i].end())
            {
                temp = max(temp,x.first+rc[i]);
                break;
            }
            else
            {
                temp = max(temp,x.first+rc[i]-1);
            }
        }
        ans = max(ans,temp);
    }
    cout<<ans<<endl;
}
int main()
{
    //openfile;fastio;
    ll T = 1; 
    // cin>>T;
    while(T--)
    {solve();}
}

Measured memory_bytes: 54732
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, A, B;
  while (cin >> N >> A >> B) {
    cout << min(A * N, B) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import itertools

n = int(input())

in_str = []
for _ in range(n):
    i = input()
    in_str.append(''.join(sorted(i)))


def cmb(n, r):
    """
    組み合わせ数
    https://qiita.com/derodero24/items/91b6468e66923a87f39f
    :param n:
    :param r:
    :return:
    """
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


if __name__ == '__main__':
    count = 0
    for k, g in itertools.groupby(sorted(in_str)):
        n = sum(1 for _ in g)
        if n == 1:
            continue
        count += cmb(n, 2)
    print(count)


Measured memory_bytes: 11508
#include <stdio.h>

#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void)
{
    int i, j;
	int s;
    int n[6], g[3], c[3];
    int ans;
    while (1){
        s = 0;
        for (i = 0; i < 6; i++){
            scanf("%d", &n[i]);
            s += n[i];
        }
        
        if (s == 0){
            break;
        }
        
        for (i = 0; i < 3; i++){
            g[i] = n[i] + n[i + 3];
        }
		
		ans = 0;
		
		for (i = 0; i < 3; i++){
			for (j = 0; j < 3; j++){
				c[j] = g[j] - i;
				if (c[j] < 0){
					c[j] = -999999;
				}
			}
			ans = max(ans, i + c[0] / 3 + c[1] / 3 + c[2] / 3);
		}
		
		printf("%d\n", ans);
    }
    
    return (0);
}

Measured memory_bytes: 600
// template.cpp

// Defines.
//#define DEBUG
#define NUMBER_OF_DIGITS 12

// Includes.
#include <bits/stdc++.h>

#ifdef DEBUG
#include <chrono>
#endif

// Usings.
using namespace std;

// Main function.
int main()
{
#ifdef DEBUG
	chrono::system_clock::time_point start, end;
	
	start = chrono::system_clock::now();
#endif
	
	// settings.
	ios::sync_with_stdio(false);
	
	cout << fixed;
	cout << setprecision(NUMBER_OF_DIGITS);
	
	// logic.
	int n;
	cin >> n;
	
	vector<tuple<double, double>> points;
	for (int i = 0; i < n; i++)
	{
		double x, y;
		cin >> x >> y;
		points.emplace_back(x, y);
	}
	
	map<tuple<int, int>, double> distance;
	for (int i = 0; i < n; i++)
	{
		for (int j = (i + 1); j < n; j++)
		{
			distance[make_tuple(i, j)] = pow(pow((get<0>(points[i]) - get<0>(points[j])), 2.0) + pow((get<1>(points[i]) - get<1>(points[j])), 2.0), 0.5);
		}
	}
	
	vector<int> order;
	for (int i = 0; i < n; i++)
	{
		order.push_back(i);
	}
	
	double total = 0.0;
	int counter = 0;
	do
	{
		counter++;
		
		for (int i = 1; i < n; i++)
		{
			if (order[i - 1] < order[i])
			{
				total += distance[make_tuple(order[i - 1], order[i])];
			}
			else
			{
				total += distance[make_tuple(order[i], order[i - 1])];
			}
		}
	}
	while (next_permutation(order.begin(), order.end()));
	
	cout << (total / (double)counter) << endl;
	
#ifdef DEBUG
	end = chrono::system_clock::now();
	
	double elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	cout << elapsed << "[ms]" << endl;
#endif
	
	return 0;
}


Measured memory_bytes: 4280
#
import sys
import math
import numpy as np
import itertools


# ひとつ入力
n = int(input())

# リストに入れる
h = [int(i) for i in input().split()] 

highest = 0
answer = 0

for i in range(n):
    if h[i] >= highest:
        answer += 1
        highest = h[i]
    
print(answer)




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

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807

using namespace std;

long long GCD(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (b == 0) return a;
	else return GCD(b, a % b);
}
bool sosuu_check(int num) {
	int i;
	for (i = 2; i <= sqrt(num); ++i) {
		if (num%i == 0)
			return false;
	}
	return (num < 2) ? false : true;
}
int main() {
	int A,B,C,MAX, p, r, ans = 0;
	cin >> A >> B >> C;
	MAX = max(A, max(B, C));
	ans = 3 * MAX - A - B - C;
	ans = ans % 2 ? ans / 2 + 2 : ans / 2;
	cout << ans << 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;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
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<int> a(N);
    vector<int> b(N);
    vector<int> c(N);
    rep(i,N)cin >> a[i] >> b[i] >> c[i];

    vector<vector<int>> dp(N+1,vector<int> (3,0));
    rep(i,N) rep(j,3) rep(k,3){
        if(j == k)continue;
            int tmp;
        if(j == 0)tmp = a[i];
        if(j == 1)tmp = b[i];
        if(j == 2)tmp = c[i];
        chmax(dp[i+1][j],dp[i][k] + tmp);
    }
    int ans = dp[N][0];
    ans = max(ans,dp[N][1]);
    ans = max(ans,dp[N][2]);
    cout << ans << endl;
}

// tmp をループ内で宣言したらTLEなった。

Measured memory_bytes: 6912
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

#define FOR(i, l, r) for (i = (l); i < r; i++ )

using namespace std;
typedef long long ll;

#define MAX_N (100010)
#define NIL (-1)

typedef struct {
    int par;
    int l_c;			// left child
    int r_s;			// right sibling
    int dep;			// depth
} Node;

Node tree[MAX_N];

int get_depth( int id ) {
    if ( id == NIL ) return -1;
    if ( tree[id].dep != -1 ) return tree[id].dep;
    else {
	int r_s = tree[id].r_s;
	tree[id].dep = 1 + get_depth( tree[id].par );

	while ( r_s != NIL ) {
	    tree[r_s].dep = tree[id].dep;
	    r_s = tree[r_s].r_s;
	}

	return tree[id].dep;
    }
}

void output( int id ) {
    char type[100];
    vector<int> children;
    int cur_chi = tree[id].l_c;

    if ( tree[id].par == NIL ) sprintf( type, "root" );
    else if ( tree[id].l_c == NIL ) sprintf( type, "leaf" );
    else sprintf( type, "internal node" );
	
    while ( cur_chi != NIL ) {
	children.push_back( cur_chi );
	cur_chi = tree[cur_chi].r_s;
    }

    printf("node %d: ", id);
    printf("parent = %d, ", tree[id].par );
    printf("depth = %d, ", tree[id].dep );
    printf("%s, ", type );
    printf("[");

    for ( int i = 0; i < children.size(); i++ ) {
	printf("%d", children[i]);
	if ( i < children.size() - 1 ) printf(", ");
    }
    printf("]\n");

    return;
}

int main()
{
    int n;
    scanf("%d", &n);
    for ( int i = 0; i < n; i++ ) {
	tree[i].par = tree[i].l_c = tree[i].r_s = NIL; 
	tree[i].dep = -1;
    }

    for ( int i = 0; i < n; i++ ) {
	int id;
	int k;
	int pre_chi = NIL;
	scanf("%d %d", &id, &k);

	// k??????child
	for ( int j = 0; j < k; j++ ) {
	    int chi;
	    scanf("%d", &chi);
	    // ????????????id
	    tree[chi].par = id;

	    if ( j == 0 ) {	// ?????????
		tree[id].l_c = chi;
	    }
	    else if ( j < k ) { // ????????????
		tree[pre_chi].r_s = chi;
	    }
	    pre_chi = chi;
	}
    }
    int root = NIL;
    // root???????????????
    {
	int cur = 0;
	while ( true ) {
	    if ( tree[cur].par == NIL ) {
		root = cur;
		break;
	    }
	    cur = tree[cur].par;
	}
    }

    // ?????????????????±???????±???????
    for ( int i = 0; i < n; i++ ) {
	if ( tree[i].dep == -1 ) get_depth( i );
    }

    for ( int i = 0; i < n; i++ ) {
	output(i);
    }
    
    return 0;
}

Measured memory_bytes: 4912
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        n: usize,
        d: i64,
        p: [(i64, i64); n],
    }

    let d2 = d * d;

    println!(
        "{}",
        p.into_iter().filter(|(x, y)| x * x + y * y <= d2).count()
    );
}


Measured memory_bytes: 7772
#include<bits/stdc++.h>
using namespace std;
int a[1010];
int main()
{
	int n, m;
	scanf("%d",&n);
	int i;
	for(i=0; i<n; i++) scanf("%d",&a[i]);
	scanf("%d",&m);
	while(m--)
	{
		int l, r, x;
		scanf("%d%d%d",&l,&r,&x);
		printf("%d\n",count(a+l, a+r, x));
	}
	return 0;
}


Measured memory_bytes: 3216
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}
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() {
    string S;
    int N, A, B;
    cin >> N >> A >> B >> S;
    map<char, int> a;
    map<char, int> b;
    int count = 0;
    rep(i, 0, N) {
        if (S[i] == 'a') {
            if (count < A+B) {
                cout << "Yes" << endl;
                ++count;
            } else {
                cout << "No" << endl;
            }
            a[S[i]]++;
        } else if (S[i] == 'b') {
            b['b']++;
            if (count < A+B && b['b'] <= B) {
                cout << "Yes" << endl;
                ++count;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <climits>

int a[200000];
int L[100001];
int R[100001];

long long merge(int left, int mid, int right){
    long long c = 0;
    int i;
    for(i=0;i<mid-left;i++)L[i]=a[i+left];
    for(i=0;i<right-mid;i++)R[i]=a[i+mid];
    L[mid-left] = INT_MAX;
    R[right-mid] = INT_MAX;
    int j = 0;
    int k = 0;
    for(i=left;i<right;i++){
        if(R[k]<L[j]){
            c += mid+k-i;
            a[i] = R[k];
            k++;
        }else{
            a[i] = L[j];
            j++;
        }
    }
    return c;
}

long long mergeSort(int left, int right){
    if(right-left<=1)return 0;
    int mid = (left + right)/2;
    long long c1 = mergeSort(left,mid);
    long long c2 = mergeSort(mid,right);
    long long c3 = merge(left,mid,right);
    return c1 + c2 + c3;
}

int main(){
    int i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",a+i);
    printf("%lld\n", mergeSort(0,n));
    return 0;
}



Measured memory_bytes: 4300
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
typedef pair<long long ,long long> P;
long long sum[500001],s1[500001],s2[500001];
P pp[500000];
int main(void)
{
	int n,i,j;
	long long mx,mn,smx;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%lld %lld",&pp[i].first,&pp[i].second);
	sort(pp,pp+n);
	sum[0]=0;
	for(i=0;i<n;i++)	sum[i+1]=sum[i]+pp[i].second;
	for(i=1;i<=n;i++)	s1[i]=sum[i]-pp[i-1].first;
	for(i=0;i<n;i++)	s2[i]=sum[i]-pp[i].first;
	mx=s1[n];	smx=mx-s2[n-1];
	for(i=n-2;i>=0;i--)	{
		mx=max(mx,s1[i+1]);
		smx=max(smx,mx-s2[i]);
	}
	printf("%lld\n",smx);
	return 0;
}


Measured memory_bytes: 22292
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    bool h = false; 
    cin >> N;

    vector <int> data(N);
    vector <int> data_sorted(N);
    
    for(int i=0; i<N; i++){
        cin >> data[i];
    }

    data_sorted = data;
    sort(data_sorted.begin(),data_sorted.end());

    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            int tmp;
            vector <int> tmp_ha(N);
            tmp_ha = data;

            tmp = tmp_ha[i];
            tmp_ha[i] = tmp_ha[j];
            tmp_ha[j] = tmp;

            if(tmp_ha == data_sorted){
                cout << "YES" << endl;
                h = true;
                break;
            }
        }
        if(h==true) break;
    }

    if(h==false){
        cout << "NO" <<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for(int i=0;i<n;++i)
#define EPS 1e-9
typedef complex<double> Point;
typedef vector<Point> VP;
typedef pair<Point, Point> Line;
#define X real()
#define Y imag()

#define EQ(n,m) (abs((n)-(m)) < EPS)

namespace std {
  bool operator<(const Point a, const Point b) {
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
}

double dot(Point a, Point b) {
  return a.X*b.X + a.Y*b.Y;
}

// ?????????cross(a,b) = |a||b|sin??
double cross(Point a, Point b) {
  return a.X*b.Y - a.Y*b.X;
}

int ccw(Point a, Point b, Point c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}

bool isecSS(Point a1, Point a2, Point b1, Point b2) {
  return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
  ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}

Point crosspointLL(Point a1, Point a2, Point b1, Point b2) {
  double d1 = cross(b2-b1, b1-a1);
  double d2 = cross(b2-b1, a2-a1);
  if (EQ(d1, 0) && EQ(d2, 0)) return a1;  // same line
  assert(!EQ(d2, 0)); // ???????????????
  return a1 + d1/d2 * (a2-a1);
}


int main(void){
    int n;
    while(cin>>n,n){
        vector<Line> ls(n);
        int crosscnt=0;
        rep(i,n){
            double p1x,p1y,p2x,p2y;
            cin>>p1x>>p1y>>p2x>>p2y;
            ls[i] = {{p1x,p1y},{p2x,p2y}};
            set<Point> cp;
            rep(j,i){
                if(isecSS(ls[i].first,ls[i].second,ls[j].first,ls[j].second)){
                    Point p = crosspointLL(ls[i].first,ls[i].second,ls[j].first,ls[j].second);
                    if(p.X>-100 && p.X<100 && p.Y>-100 && p.Y<100) cp.insert(p);
                }
            }
            crosscnt += (int)cp.size();
        }
        cout<<n+crosscnt+1<<endl;
    }

    return 0;
}

Measured memory_bytes: 3300
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define vl vector
#define pb push_back
#define ff first
#define ss second
using namespace std;

int main()
{
    ll n,m,i,a=0,b=0,k,t,j;
    string s;
    cin>>s;
    string s1,s2;
    if(s.size()%2)
    {
        n=s.size()/2;
        s1=s.substr(0,n);
        s2=s.substr(n+1,n);
    }
    else
    {
        n=s.size()/2;
        s1=s.substr(0,n);
        s2=s.substr(n,n);
    }
    reverse(s2.begin(),s2.end());
    ll ans=0;
    for(i=0;i<s2.size();i++) if(s1[i]!=s2[i]) ans++;
    cout<<ans;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,cnt=0,xx=0;
    cin>>t;
    int arr[t+1];
    for(int i=1;i<=t;i++)
    {
        cin>>arr[i];
    }
    for(int i=1;i<=t;i++)
    {
        xx=i^arr[i];
        if(xx>0)
        {
            cnt++;
        }
    }
    if(cnt>2)
    {
        cout<<"NO"<<endl;
    }
    else
    {
        cout<<"YES"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  long long N; cin>>N;
  long long ans=0;
  for(long long m=1;m*m<N;m++){
    if(N%m==0){
      if(m>1){
        if(N/(m-1)==N%(m-1)){
          ans+=(m-1);
        }
      }
      if(N/(N/m-1)==N%(N/m-1)){
        ans+=(N/m-1);
      }
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque

n = int(input())

tree = defaultdict(list)

edges = []
for _ in range(n-1):
	a, b = map(int, input().split())
	tree[a].append(b)
	tree[b].append(a)
	edges.append((a, b))

I = dict()
que = deque([1])
color = [None]*(n+1)
color[1] = 0
max_val = 0
used = {1, }
while que:
	u= que.popleft()
	max_val = max(max_val, len(tree[u]))
	next_color = 1
	for v in tree[u]:
		if v in used: continue
		if color[u] == next_color:
			next_color += 1
		color[v] = I[(u, v)] = I[(v, u)] = next_color
		next_color += 1
		que.append(v)
		used.add(v)
print(max_val)
for edge in edges:
	print(I[edge])

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll INF=1000000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}

//a,b x
int main(){
    string s; cin>>s;
    vector<ll>N(26,0);
    vector<ll>N2(26,0);
    rep(i,s.sz){
        ll tmp=s[i]-'a';
        N[tmp]++;
    }
    if(s.sz!=26){
        rep(i,26){
            if(N[i]==0){
                s+='a'+i;
                break;
            }
        }
        cout<<s;
    }
    else{
        ll i=25;
        while(i>=1){
            ll tmp=s[i]-'a';
            N2[tmp]++;
            if(s[i-1]<s[i]) break;

            i--;
        }

        if(i==0){
            cout<<"-1";
            return 0;
        }

        i--;
        rep(j,i) cout<<s[j];
        
        rep(j,26){
            if(s[i]-'a'<j && N2[j]!=0){
                cout<<(char)(j+'a');
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        vector<int> num;
        for(int i=1;i<n;i++)num.push_back(i*i%n);
        sort(num.begin(),num.end());
        num.erase(unique(num.begin(),num.end()),num.end());
        int ans[10001]={};
        for(int i=0;i<num.size();i++){
            for(int j=0,k;j<num.size();j++){
                k=num[i]-num[j];
                if(k<0)k+=n;
                if(k>n/2)k=n-k;
                ans[k]++;
            }
        }
        for(int i=1;i<=n/2;i++)cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 1364
/*
  #問題：
  


  #分析：
  #オブジェクト：
  
  #条件：
  

  #要求：
  

  #解法：
  
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
#include <initializer_list>
#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;


const unsigned int BIT_FLAG_0 = (1<<0);
const unsigned int BIT_FLAG_1 = (1<<1);
const unsigned int BIT_FLAG_2 = (1<<2);
const unsigned int BIT_FLAG_3 = (1<<3);
const unsigned int BIT_FLAG_4 = (1<<4);
const unsigned int BIT_FLAG_5 = (1<<5);
const unsigned int BIT_FLAG_6 = (1<<6);
const unsigned int BIT_FLAG_7 = (1<<7);


#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;

using Bint = mp::cpp_int;



int main(void){
  int cnt=0, maxx=0;
  string S;
  cin>>S;

  for(auto c:S){
    if(c=='A'||c=='T'||c=='C'||c=='G') {cnt++; maxx=max(maxx,cnt);}
    else {cnt=0;}
  }
  cout<<maxx<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define N 200007
#ifdef WIN32
#define L_L "%I64d"
#else
#define L_L "%lld"
#endif
#define IL inline
#define REP(a,b,c) for(a=b;a<=c;a++)
#define PER(a,b,c) for(a=b;a>=c;a--)
using namespace std;
typedef long long lol;
int n,rmi[N],rma[N];lol ans;
IL int rd(){
	int res=0;char c;while((c=getchar())<'0'||c>'9');
	while(c>='0'&&c<='9')res=res*10+c-'0',c=getchar();return res;
}
struct nd{
	int x,y;
	IL void init(){x=rd(),y=rd();if(x>y)swap(x,y);}
	IL bool operator < (const nd &b) const{return x<b.x||(x==b.x && y<b.y);}
}a[N];
int main(){
	n=rd();int i,mi=1e9,ma=1,s;
	REP(i,1,n)a[i].init(),ma=max(ma,a[i].y),mi=min(mi,a[i].y);
	sort(a+1,a+1+n);ans=1LL*(ma-mi)*(a[n].x-a[1].x);
	s=ma-a[1].x,mi=1e9,ma=1;rmi[n+1]=1e9,rma[n+1]=1;
	PER(i,n,1)rmi[i]=min(rmi[i+1],a[i].x),rma[i]=max(rma[i+1],a[i].x);
	REP(i,1,n){
		mi=min(mi,a[i].y),ma=max(ma,a[i].y);
		ans=min(ans,1LL*s*(max(ma,rma[i+1])-min(mi,rmi[i+1])));
	}
	printf(L_L,ans);
  return 0;
}

Measured memory_bytes: 3328
#0197
while True:
    c = 0
    a = 0
    b = 0
    x , y = map(int,input().split())
    if x == y == 0:
        break
    if x < y:
        a = x
        x = y
        y = a
    
    while True:
        b = x%y
        x = y
        y = b
        c += 1
        if y == 0:
            break
    print(x,c)


Measured memory_bytes: 5608
// Problem : C - *3 or /2
// Contest : AtCoder - AtCoder Beginner Contest 100
// URL : https://atcoder.jp/contests/abc100/tasks/abc100_c?lang=en
// Memory Limit : 1000 MB
// Time Limit : 2000 ms
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)n;i++)
#define ll long long
#define mod 1000000007
int main(){
	int n;
	cin>>n;
	int arr[n];
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	for(int i=0;i<n;i++){
		ll n=arr[i];
		while(n%2==0){
			n/=2;
			sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
}


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(vec) (vec).begin(),(vec).end()
#define int long long

int gcd(int x,int y){
    if(y==0)return abs(x);
    return gcd(y,x%y);
}

signed main(){
    int a,b;cin>>a>>b;
    cout<<a/gcd(a,b)*b<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n;
	int a[100];
	int i;
	int counter=0;
	int max=0;
	
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[n]);
			if(a[n]==1)
				counter++;//1が入力された回数を記録
			
			else{
				if(counter>max)
					max=counter;
				counter=0;
			}
	}
	
	if(counter>max)
		max=counter;
	printf("%d\n",max+1);
}


Measured memory_bytes: 2080
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (N, W) = Read2Longs();
            //1-indexで考える
            var w = new long[N + 1];
            var v = new long[N + 1];
            for (int i = 1; i <= N; i++)
            {
                (w[i], v[i]) = Read2Longs();
            }

            // i 番目までの品物から重さが sumW を超えないように選んだときの、価値の総和の最大値
            var dp = new long[N + 1, W + 1];
            for (int i = 1; i <= N; i++)
            {
                for (int sumW = 0; sumW <= W; sumW++)
                {
                    var notChoiceValue = dp[i - 1, sumW];
                    // i番目の品物を選ぶことができない
                    if (sumW < w[i])
                    {
                        dp[i, sumW] = notChoiceValue;
                        continue;
                    }

                    var choiceValue = dp[i - 1, sumW - w[i]] + v[i];

                    // i 番目を選んだ場合と選ばなかった場合の比較
                    dp[i, sumW] = Math.Max(choiceValue, notChoiceValue);
                }
            }

            return dp[N, W];
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 106104
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,a,b,c,d,n;
map<pair<int,int>,int>dp;
int dfs(pair<int,int>x)
{
	if(x.first<0)
		return 9e18;
	if(x.first==0)
		return 0;
	if(dp.find(x)!=dp.end())
		return dp[x];
	dp[x]=9e18;
	if(9e18/d>=x.first)
		dp[x]=d*x.first;
	if(x.first%2==0)
		dp[x]=min(dp[x],dfs(make_pair(x.first/2,1))+a);
	if(x.first%3==0)
		dp[x]=min(dp[x],dfs(make_pair(x.first/3,1))+b);
	if(x.first%5==0)
		dp[x]=min(dp[x],dfs(make_pair(x.first/5,1))+c);
	if(x.second)
	{
		dp[x]=min(dp[x],dfs(make_pair(x.first-1,0))+d);
		dp[x]=min(dp[x],dfs(make_pair(x.first-2,0))+d*2);
		dp[x]=min(dp[x],dfs(make_pair(x.first+1,0))+d);
		dp[x]=min(dp[x],dfs(make_pair(x.first+2,0))+d*2);
	}
	//cout<<x.first<<' '<<dp[x]<<endl;
	return dp[x];
}
signed main()
{
	ios::sync_with_stdio(false);
	cin>>t;
	while(t--)
	{
		dp.clear();
		cin>>n>>a>>b>>c>>d;
		cout<<dfs(make_pair(n,1))<<endl;
	}
	return 0;
}

Measured memory_bytes: 8116
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, x);
    println!("{}", 10 - x / 200);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

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

	vector<bool> p(n + 1, false);
	vector<int> w(n + 1, 0);
	int wa = 0;
	int ac = 0;
	for (int i = 0; i < m; ++i) {
		int pi;
		string si;

		cin >> pi >> si;

		if (p[pi]) {
			continue;
		}

		if (si == "AC") {
			p[pi] = true;
			++ac;
			wa += w[pi];
		} else {
			++w[pi];
		}
	}

	cout << ac << " " << wa;
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int dp[1 << 20] = {};
const ll MOD = 1e9+7;
ll fac[MAX_N];

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

    

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

    rep(i,20) rep(b, 1 << 20) if(0 == (b & (1 << i))) dp[b] += dp[b | (1 << i)];

    rep(i,MAX_N){
        if(i == 0){
            fac[i] = 1;
        }else{
            fac[i] = fac[i-1] * 2 % MOD;
        }
    }

    ll ans = 0;

    rep(i,1 << 20){
        if(__builtin_popcount(i) % 2 == 1){
            ans += MOD - (fac[dp[i]] - 1);
        }else{
            ans += fac[dp[i]] - 1;
        }
        ans %= MOD;
    }

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



Measured memory_bytes: 9124
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
struct BIT {
  int n;
  vector<int> xs;
  BIT (int n) : n(n) {
    xs.resize(n+1);
  }
  void add(int i, int v) {
    for (int x=i+1; x<=n; x+=x&-x) xs[x] += v;
  }
  int sum(int i) {
    int s = 0;
    for (int x=i+1; x>0; x-=x&-x) s += xs[x];
    return s;
  }
  int sum(int a, int b) {
    return sum(b) - sum(a-1);
  }
};


int N;
int A[100000];
int B[100000];
long long f(int X) {
  rep(i, N) B[i] = (A[i] >= X)?1:-1;
  BIT bit(2*N+1);
  bit.add(N, 1);
  int v = N;
  long long sum = 0;
  rep(r, N) {
    v += B[r];
    sum += bit.sum(v);
    bit.add(v, 1);
  }
  //cout<<"f("<<X<<")="<<sum<<"\n";
  return sum;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  vector<int> values;
  rep(i, N) cin >> A[i], values.pb(A[i]);
  sort(all(values)); uniq(values);
  int lo = 0, hi = values.size();
  while(hi-lo>1) {
    int mid=(lo+hi)/2;
    if (2LL*f(values[mid]) >= (1LL*N*(N+1))/2) lo = mid;
    else hi = mid;
  }
  cout << values[lo] << "\n";
  return 0;
}


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

using Matrix = vector< vector<int> >;
const int INF = 1 << 30;
int W, H, ans = 0;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
 
void dfs(Matrix mat, int turn, int pos_x, int pos_y) {
    if(turn > 10) return;
    for(int k=0; k<4; k++) {
        int nx = pos_x, ny = pos_y;
        int px = nx + dx[k], py = ny + dy[k];
        if(px < 0 || px >= H || py < 0 || py >= W) continue;
        if(mat[px][py] == 1) continue;
 
        while(1) {
            nx += dx[k], ny += dy[k];
            if(nx < 0 || nx >= H || ny < 0 || ny >= W) {
                // out of range
                break;
            }
            else if(mat[nx][ny] == 3) {
                // goal
                ans = min(ans, turn);
                break;
            }
            else if(mat[nx][ny] == 1) {
                // obstacle
                mat[nx][ny] = 0;
                dfs(mat, turn+1, nx-dx[k], ny-dy[k]);
                mat[nx][ny] = 1;
                break;
            }
        }
    }
}
 
int main() {
    while(cin >> W >> H, W) {
        ans = INF;
        Matrix mat(H, vector<int>(W));
 
        int x = 0, y = 0;
        for(int i=0; i<H; i++) {
            for(int j=0; j<W; j++) {
                cin >> mat[i][j];
                if(mat[i][j] == 2) {
                    x = i, y = j;
                }
            }
        }
 
        dfs(mat, 1, x, y);
        cout << (ans == INF ? -1 : ans) << endl;
    }
    return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rt return
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n,k;
ll a[maxn];
int bit[100];
int main()
{
   	gbtb;
   	cin>>n>>k;
   	repd(i,1,n)
   	{
   		cin>>a[i];
   	}
   	repd(i,1,n)
   	{
   		for(int j=60;j>=0;j--)
   		{
   			int f=(bool)(a[i]&(1ll<<j));
   			bit[j]+=f;
   		}
   	}
   	int sm=0;
   	ll x=0ll;
   	for(int j=60;j>=0;j--)
   	{
   		int f=(bool)(k&(1ll<<j));
   		if(f)
   		{
   			if(bit[j]<=(n/2))
   			{
   				x+=(1ll<<j);
   			}else
   			{
   				sm=1;
   			}
   		}else
   		{
   			if(sm)
   			{
   				if(bit[j]<=(n/2))
	   			{
	   				x+=(1ll<<j);
	   			}
   			}
   		}
   	}
   	ll ans=0ll;
   	repd(i,1,n)
   	{
   		ans=ans+((x^a[i]));
   	}
   	cout<<ans<<endl;
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
a = [e for e in a if e % 2 == 0 ]
cnt = 0
for i in a:
    if not (i % 3 ==0) and not (i % 5 ==0):
        cnt = 1
        break
if cnt:
    print("DENIED")
else:
    print("APPROVED")

Measured memory_bytes: 9152
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;
/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int N,A,B,C;
vector<int> L;
int rec(int i,int a,int b,int c){
  if(i==N){
    if(!a || !b || !c) return INF;
    return abs(a-A) + abs(b-B)+abs(c-C);//A,B,Cにするコスト
  }
  int res = rec(i+1,a,b,c);

  chmin(res,rec(i+1,a+L[i],b,c)+(a?10:0));
  chmin(res,rec(i+1,a,b+L[i],c)+(b?10:0));
  chmin(res,rec(i+1,a,b,c+L[i])+(c?10:0));
  return res;
}


int main(){
  cin >> N >> A >> B >> C;
  L.resize(N);
  for(int i=0;i<N;i++) cin >> L[i];
  cout << rec(0,0,0,0) << endl;
}

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

int main() {
	// your code goes here
	ll k;
	cin>>k;
	ll sum=0;
	for(ll i=1;i<=k;i++)
	{
	    if(i%3==0 && i%5==0)
	    continue;
	    if(i%3!=0 && i%5==0)
	    continue;
	    if(i%5!=0 && i%3==0)
	    continue;
	    sum+=i;
	}
	cout<<sum;
	
	
	return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#include "bits/stdc++.h"

typedef std::vector<std::vector<long long>> Matrix;

Matrix add(Matrix a, Matrix b) {
	int n = a.size(), m = a[0].size();
	assert(a.size() == b.size() && a[0].size() == b[0].size());
	Matrix res(n, std::vector<long long>(m, 0));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			res[i][j] = a[i][j] + b[i][j];
		}
	}
	return res;
}

Matrix mult(Matrix  a, Matrix b) {//a:n*m matrix,b:m*l matrix
	int n = a.size(), m = a[0].size(), l = b[0].size();
	Matrix res(n, std::vector<long long>(l, 0));
	for (int i = 0; i < n; ++i) {
		for (int k = 0; k < m; ++k) {
			for (int j = 0; j < l; ++j) {
				res[i][j] += a[i][k] * b[k][j] % MOD;
				res[i][j] %= MOD;
			}
		}
	}
	return res;
}

Matrix pow(Matrix a, ll n) {
	Matrix  e(a.size(), std::vector<long long>(a.size(), 0));
	for (int i = 0; i < a.size(); ++i) {
		e[i][i] = 1;
	}
	while (n >= 1) {
		if (n & 1) e = mult(e, a);
		a = mult(a, a);
		n /= 2;
	}
	return e;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; ll k;
	cin >> n >> k;
	vvl a(n, vl(n));
	REP(i, n)REP(j, n)cin >> a[i][j];
	Matrix m = pow(a, k);
	ll ans = 0;
	REP(i, n)REP(j, n)ans = (ans + m[i][j]) % MOD;
	cout << ans << endl;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;

namespace abc096_d
{
    class Program
    {
        static List<int> prime = new List<int>();
        static void makeprime()
        {
            for (int i = 2; i <= 55555; i++)
            {
                bool flag = true;
                foreach (var x in prime)
                {
                    if (i % x == 0) flag = false;
                }
                if (flag) prime.Add(i);
            }
        }
        static void Main(string[] args)
        {
            makeprime();
            int n = int.Parse(Console.ReadLine());
            int[] ret = new int[n];
            int x = 0;
            for (int i = 0; i < n; i++)
            {
                while (prime[x] % 5 != 2) x++;
                ret[i] = prime[x];
                x++;
            }
            Console.WriteLine(string.Join(" ", ret));
        }
    }
}

Measured memory_bytes: 11348
#include <cstdio>
#include <algorithm>
using namespace std;
struct edge { int u, v, cost; };
struct unionfind {
    int par[100], rank[100];
    unionfind(int n) {
        for (int i=0; i<n; i++) {
            par[i]=i;
            rank[i]=0;
        }
    }
    int find(int x) {
        if (x==par[x]) {
            return x;
        } else {
            return par[x]=find(par[x]);
        }
    }
    void unite(int x, int y) {
        x=find(x);
        y=find(y);
        if (x==y) return;
        if (rank[x]<rank[y]) {
            par[x]=y;
        } else {
            par[y]=x;
            if (rank[x]==rank[y]) rank[x]++;
        }
    }
    bool same(int x, int y) {
        return find(x)==find(y);
    }
};
bool comp(const edge& a, const edge& b) {
    return a.cost<b.cost;
}
edge es[10000];
int main() {
    int n, m;
    while (scanf("%d",&n)) {
        if (!n) break;
        scanf("%d",&m);
        unionfind uf(n);
        for (int i=0; i<m; i++) {
            int a, b, d; scanf("%d%*c%d%*c%d",&a,&b,&d);
            es[i]=(edge){a,b,d/100-1};
        }
        sort(es, es+m, comp);
        int res=0;
        for (int i=0; i<m; i++) {
            edge e=es[i];
            if (!uf.same(e.u,e.v)) {
                uf.unite(e.u,e.v);
                res+=e.cost;
            }
        }
        printf("%d\n",res);
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ;i++)

using namespace std;
using p=pair<int,int>;
typedef long long ll;

int main() {
  int h,w,k;
  cin >> h >> w >> k;
  vector<string>s(h);
  rep(i,h){
    cin >> s[i];
  }
  int ans=0;
  rep(is,1<<h)rep(js,1<<w) {
    int cnt = 0;
    rep(i,h)rep(j,w){
      if(is>>i&1) continue;
      if(js>>j&1)continue;
      if(s[i][j]=='#') cnt++;
    }
    if(cnt==k)ans++;
  }
  cout << ans << endl;
  
  
 
  return 0;

}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

map<char,int> m = {{'r',0}, {'m',1}, {'y',2}, {'b',3}, {'g',4}, {'c',5}};

/*
  2
1 0 4
  3
  5
*/
// ??????[0][1]
// [???][??????] -> ???
int dice[6][6] ={
  {-1, 3, 1, 4, 2,-1},
  { 2,-1, 5, 0,-1, 3},
  { 4, 0,-1,-1, 5, 1},
  { 1, 5,-1,-1, 0, 4},
  { 3,-1, 0, 5,-1, 2},
  {-1, 2, 4, 1, 3,-1}
};

bool visited[30][30][6][6][6];

int main(){
  int w,d;
  while(cin>>w>>d, w|d){
    vector<string> vec(d);
    rep(i,d) cin>>vec[i];
    string query;
    cin>>query;

    int sx=-1,sy=-1;
    rep(i,d)rep(j,w) if(vec[i][j]=='#'){
      sx=i; sy=j;
      vec[i][j] = 'w';
    }

    const int dx[] = {1,-1,0,0}, dy[]={0,0,1,-1};
    function<pair<int,int>(int,int)> df[] = { // return <top,front>
      [&](int t, int f){return mp(5-f, t);},
      [&](int t, int f){return mp(f, 5-t);},
      [&](int t, int f){return mp(5-dice[t][f], f);},
      [&](int t, int f){return mp(dice[t][f], f);}
    };

    fill(visited[0][0][0][0], visited[30][0][0][0], false);

    int ans = INF;

    using state = tuple<int,int,int,int,int,int>;
    // <s,y,top,front,level>
    queue<state> q;
    q.push((state){sx,sy,0,1,0,0});
    visited[sx][sy][0][1][0] = true;
    while(!q.empty()){
      int x,y,t,f,l,dist;
      tie(x,y,t,f,l,dist) = q.front(); q.pop();

      rep(k,4){
        int nx = x + dx[k], ny = y + dy[k];
        auto p = df[k](t,f);
        if(nx<0 || ny<0 || nx>=d || ny>=w || vec[nx][ny]=='k') continue;

        int nl = l;
        if(vec[nx][ny]!='w'){
          if(vec[nx][ny] == query[l] && p.fi == m[query[l]]) nl++;
          else continue;
          if(nl == 6){
            ans = min(ans, dist+1);
            continue;
          }
        }

        if(visited[nx][ny][p.fi][p.se][nl]) continue;

        visited[nx][ny][p.fi][p.se][nl] = true;
        q.push((state){nx, ny, p.fi, p.se, nl, dist+1}); //dbg(nx,ny,p.fi,p.se,nl,dist);
      }
    }

    if(ans>=INF) cout <<"unreachable"<<endl;
    else cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3356