akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}


signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    set<long double>s;
    for(int i=0;i<=3000 && i*100*c<=f*e;i++)
    {
        for(int j=0;j<=3000 && j*100*d<=f*e;j++)
        {
            int x=i*c+j*d;
            if((i+j)*e<=f*e)
            {
                s.insert(i*c+j*d);
            }
        }
    }
    long double mx=0;
    int ans1=100*a;
    int ans2=0;
    for(int i=0;i*100<=f;i++)
    {
        for(int j=0;j*100<=f;j++)
        {
            if(i+j==0)
                continue;
            int vol=i*a*100+j*b*100;
            auto k=s.lower_bound(f-vol+1);
            if(k==s.begin())
                continue;
            k--;
            long double z=vol*e;
            z/=100.0;
            auto t=s.lower_bound(floor(z)+1);
            if(t==s.begin())
                continue;
            t--;
            int tt=min(*k,*t);
            if(mx<(100*tt)/((tt+vol)*1.0))
            {
                mx=(100*tt)/((tt+vol)*1.0);
                ans1=vol;
                ans2=tt;
            }
        }
    }

    cout<<ans1+ans2<<" "<<ans2;

} 
    


Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2;

  int x = x2-x1;
  int y = y2-y1;
  int x3 = x2 - y;
  int y3 = y2 + x;
  int x4 = x1 - y;
  int y4 = y1 + x;
  cout << x3 << " " << y3 << " ";
  cout << x4 << " " << y4 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b;
	char c;	   do{
	cin >>a>>c>>b;
	if(c=='?') break;
	if(c=='+')cout <<a+b<<endl;
	if(c=='-')cout <<a-b<<endl;
	if(c=='*')cout <<a*b<<endl;
	if(c=='/')cout <<a/b<<endl;
	}while(true);
	return 0;
}

Measured memory_bytes: 3068
//部分集合問題
//1<=N,M<=12で計算量は2^12=4096通りなので全探索できる
//1~4096のforループを作って2進数に変換
//ビット演算を使う 1<<nで2^nを表す
using System;
using System.Collections;
using System.Collections.Generic;

public class Program
{
    static void Main()
    {
        string[] In1 = Console.ReadLine().Split(' ');
        int n = int.Parse(In1[0]);
        int m = int.Parse(In1[1]);
        int x = int.Parse(In1[2]);
        int[] C = new int[n];
        int[,] L = new int[n, m];
        string[] In2;
        for (int i = 0; i < n; i++)
        {
            In2 = Console.ReadLine().Split(' ');
            C[i] = int.Parse(In2[0]);
            for (int j = 0; j < m; j++)
            {
                L[i, j] = int.Parse(In2[j+1]);
            }
        }
        int min = Int32.MaxValue;
        for(int i=0; i<(int)Math.Pow(2,n); i++)
        {
            int cost = 0;
            int[] D = new int[m];//その組み合わせの時の習熟度
            for(int j=0; j < n; j++)
            {
                //ここまでで0~2^n(10進)までの二進数生成
                if (((i >> j) & 1)==1)
                {
                    cost += C[j];
                    for(int k=0; k < m; k++)
                    {
                        D[k] += L[j, k];
                    }
                }
            }
            //習熟度が条件を満たすかチェック
            bool ok = true;
            for (int l = 0; l < m; l++)
            {
                if (D[l] < x) { ok = false; break; }
            }
            if (ok)
            {
                if (min > cost) min = cost;
            }
        }
        if (min == Int32.MaxValue) Console.WriteLine(-1);
        else Console.WriteLine(min);
    }
}

//public class Program
//{
//    static void Main()
//    {
//        string[] In1 = Console.ReadLine().Split(' ');
//        int n = int.Parse(In1[0]);
//        int m = int.Parse(In1[1]);
//        int x = int.Parse(In1[2]);
//        int[,] L = new int[n, m + 1];//一列目は値段、二列目以降は理解度
//        string[] In2;
//        for(int i=0; i < n; i++)
//        {
//            In2= Console.ReadLine().Split(' ');
//            for (int j = 0; j <= m; j++)
//            {
//                L[i, j] = int.Parse(In2[j]);
//            }
//        }
//        //全探索
//        List<int, bool> WhichBuy = new <int, bool>(,);
//        for(int i = 0; i < (int)Math.Pow(2, m); i++)
//        {
//            WhichBuy= ChangeBin(i);

//        }
//    }
//    static List<bool> ChangeBin(int x)
//    {
//        Queue<int> q = new Queue<int>();
//        while (x != 0)
//        {
//            q.Enqueue(x % 2);
//            x /= 2;
//        }
//        List<bool> L = new List<bool>();
//        while (q.Count != 0)
//        {
//            switch (q.Dequeue())
//            {
//                case 0:
//                    L.Add(false);
//                    break;
//                case 1:
//                    L.Add(true);
//                    break;
//            }
//        }
//        return L;
//    }
//} 


Measured memory_bytes: 27980
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
            for (int i = 0; i <= m; ++i) {
                for (int j = 0; j <= n; ++j) {
                    if (i * n + j * m - 2 * i * j == k) {
                        out.println("Yes");
                        return;
                    }
                }
            }
            out.println("No");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    if(s[0]=='a' and s[1]=='b' and s[2]=='c')
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <queue>
#include <functional> 

using namespace std;
typedef long long ll;

vector<vector<pair<ll, ll > > > G;
vector<ll > ans;

//経由地点からの距離
vector<ll > dis;

void dfs(ll idx, ll from = -1){
 
    for(ll i = 0; i < G[idx].size(); i++){
        //次の行き先は？
        ll to = G[idx][i].first;
        //同じだったらもう処理しない
        //頂点に戻ってきたら
        //後戻りを許さない
        if(to == from){
            continue;
        }

        dis[to] += dis[idx] + G[idx][i].second;
 
        dfs(to, idx);
 
    }
}


int main(){
    ll N;
    cin >> N;
    
    //初期化
    G.assign(N, vector<pair<ll, ll > >());
    dis.assign(N, 0);
 
    //グラフ入力
    for(ll i = 0; i < N-1; i++){
        ll u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        //双方向に貼りましょうね
        G[u].push_back(make_pair(v, w));
        G[v].push_back(make_pair(u, w));
    }

    ll Q, K;
    cin >> Q >> K;
    //ここでRE吐いてしまった．．．答えはQ個分なのに最初はN個にしてた
    //あほばかまぬけ
    ans.assign(Q, 0);
    //経由地点からdfs
    dfs(K-1);

    //確認
    /*
    for(ll i = 0; i < N; i++){
        cout << dis[i] << endl;
    }
    */
    
    for(ll i = 0; i < Q; i++){
        ll x, y;
        cin >> x >> y;
        ans[i] =  dis[x-1] + dis[y-1];
        //cout << dis[x-1] + dis[y-1] << endl;
    }

    for(ll i = 0; i < Q; i++){
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 15104
#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 endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n;
    cin >> n;

    int cnt[26] = {0};
    string s;
    cin >> s;
    rep(j, s.size()){
        cnt[s[j]-'a']++;
    }

    rep(i, n-1){
        string t;
        cin >> t;

        int tmp[26] = {0};
        rep(j, t.size()){
            tmp[t[j]-'a']++;
        }

        rep(j, 26){
            cnt[j] = min(cnt[j], tmp[j]);
        }
    }

    rep(i, 26){
        char c = 'a' + i;
        rep(j, cnt[i]){
            cout << c;
        }
    }
    cout << endl;


    return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

h,w,k = inpl()
s = [list(input()) for _ in range(h)]
res = INF
for yoko in itertools.product([0,1], repeat=(h-1)):
    # 0:uncut 1:cut
    ln = sum(yoko)
    gr = [[] for _ in range(ln+1)] 
    gr[0].append(0)
    ind = 0
    for i in range(1,h):
        if yoko[i-1]: ind += 1
        gr[ind].append(i)
    possible = True
    for x in range(w):
        for ind in range(ln+1):
            cnt = 0
            for y in gr[ind]:
                if s[y][x] == '1':
                    cnt += 1
            if cnt > k:
                possible = False
                break
        if not possible:
            break
    else:
        cutcnt = 0
        now = [0] * (ln+1)
        for x in range(w):
            for ind in range(ln+1):
                for y in gr[ind]:
                    if s[y][x] == '1':
                        now[ind] += 1
            if max(now) > k:
                now = [0] * (ln+1)
                cutcnt += 1
                for ind in range(ln+1):
                    for y in gr[ind]:
                        if s[y][x] == '1':
                            now[ind] += 1
        res = min(res, cutcnt + ln)
print(res)

Measured memory_bytes: 80208
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;

struct UF {
	vector<int> v;
	UF(int n) : v(n, -1) {}
	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int main() {
	vector<p_ii>all;
	int n, k, l;
	cin >> n >> k >> l;
	int i, j;
	struct UF s(n), t(n);
	for (i = 0; i < k; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		s.unite(a, b);
	}
	for (i = 0; i < l; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		t.unite(a, b);
	}
	for (i = 0; i < n; i++)all.push_back({ s.find(i),t.find(i) });
	sort(all.begin(), all.end());

	for (i = 0; i < n; i++) {
		p_ii tmp = { s.find(i), t.find(i) };
		int ans = upper_bound(all.begin(), all.end(), tmp) - lower_bound(all.begin(), all.end(), tmp);
		if (i != 0)printf(" ");
		printf("%d", ans);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<n;++i)
#define Sort(a) sort(a.begin(),a.end())
const int INF = 1e9+7;

int main(){
  string s;
  cin >> s;
  int n=0;
  rep(i,4){
    if(s.at(i)=='+'){
      ++n;
    }else{
      --n;
    }
  }
  cout << n;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD ((int)(1e9+7))

using namespace std;

string s;
int d;
int mem[10004][105][2];

int go(int ind,int r,int l)
{
	//cout << ind << " " << r << " " <<l << endl;
	if(ind>=s.size()) return r==0;
	if(mem[ind][r][l]!=-1) return mem[ind][r][l];
	mem[ind][r][l]=0;
	for(int i='0';i<=(l?'9':s[ind]);i++)
	{
		mem[ind][r][l]+=go(ind+1,(r+(i-'0'))%d,(i<s[ind])|l);
		mem[ind][r][l]%=MOD;
	}
	return mem[ind][r][l];
}

int main()
{
	cin >> s >> d;
	memset(mem,-1,sizeof mem);
	cout << (go(0,0,0)+MOD-1)%MOD << endl;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t / 2;
    } else {
        return modpow(m, n - 1) * m;
    }
}

int main() {
    int n, ans = 0;
    cin >> n;
    map<int, int> pair;
    vector<int> as(n + 1);
    for (int i = 1; i <= n; i++){
        cin >> as[i];
    }
    for (int i = 1; i <= n; i++){
        pair[i] = as[i];
    }
    for (int i = 1; i <= n; i++){
        if (i == pair[pair[i]]){
            ans++;
        }
    }
    cout << ans / 2 << endl;
}

Measured memory_bytes: 5376
#include <cstdio>
#include <algorithm>

int main() {
  int n;
  scanf("%d", &n);
  int dp0 = 0;
  int dp1 = 0;
  int prevLow = 0;
  int prevHigh = 0;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    int twos = 0;
    while ((1LL << (twos + 1)) <= x) {
      ++twos;
    }
    int low = twos;
    int high = twos;
    if ((1 << twos) != x) {
      high++;
    }
    int next0 = std::min(dp0 + std::max(0, high - prevLow), dp1 + std::max(0, high - prevHigh));
    int next1 = std::min(dp0 + std::max(0, low - prevLow) + high - low, dp1 + std::max(0, low - prevHigh) + high - low);
    dp0 = next0;
    dp1 = next1;
    prevLow = low;
    prevHigh = high; 
  }
  printf("%d\n", std::min(dp0, dp1));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;
    rep (bit, 0, 1 << (n - 1)) {
        ll sum = 0;
        string ss = "";
        rep (i, 0, n) {
            ss += s[i];
            if (bit & 1 << i) {
                sum += stoll (ss);
                ss = "";
            }
        }
        sum += stoll (ss);
        // cout << sum << "\n";
        ans += sum;
    }
    cout << ans << "\n";
}

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

using namespace std;

typedef long long ll;

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

	long double a, b, c;
	cin >> a >> b >> c;

	long double eps = 1e-14;
	if(sqrt(a) + sqrt(b) + eps < sqrt(c) ){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
l.sort()
import bisect
# insert_index = bisect.bisect_left(list,x)
ans=0
for i in range(n):
	for j in range(i+1,n):
		idx = bisect.bisect_left(l,l[i]+l[j])
		ans += idx-j-1

print(ans)

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

string in;

int pattern[7][7]={
	{7,8,18,0,1,2,3},
	{8,9,0,1,10,3,4},
	{18,0,17,2,3,16,5},
	{0,1,2,3,4,5,6},
	{1,10,3,4,11,6,12},
	{2,3,16,5,6,15,14},
	{3,4,5,6,12,14,13}
};


inline bool check(int mask){
	const int split=(1<<7)-1;
	int orginal=in[mask&split]-'0';
	int bit=0;
	rep(i,7){
		int cur=0;
		rep(j,7) if(mask&(1<<pattern[i][j])) cur|=(1<<j);
		int flip=in[cur]-'0';
		bit|=(flip<<pattern[i][3]);
	}
	int next=in[bit]-'0';
	if(orginal!=next)
			return false;
	return true;
}

int main(void){
	while(cin >> in){
		if(in=="#")
			break;
		bool ok=true;
		rep(mask,1<<19){
			if(check(mask))
				continue;
			ok=false;
			break;
		}
		if(ok)
			puts("yes");
		else
			puts("no");
	}
	return 0;
}
//  h g f
// i 2 5 e
//7 0 3 6 d
// 8 1 4 c
//  9 a b

Measured memory_bytes: 1168
N = int(input())
A = list(map(int,input().split()))

zero = 0
minus = 0
ans = 0

for i in range(N) :
    if A[i] == 0 :
        zero = 1
    elif A[i] < 0 :
        minus += 1
        A[i] *= -1

if zero or (minus % 2 == 0) :
    ans = sum(A)
else :
    ans = sum(A) - min(A) * 2

print(ans)
    

Measured memory_bytes: 64752
while True:
    R, N = map(int, input().split())
    if not (R | N):
        break
    geta = 20
    buildings = [0] * (geta * 2)
    for _ in range(N):
        xl, xr, h = map(int, input().split())
        for i in range(xl + geta, xr + geta):
            buildings[i] = max(buildings[i], h)

    left, right = 0, 20
    for _ in range(100):
        mid = (left + right) / 2
        flag = True
        for i in range(-R + geta, R + geta):
            if i < geta:
                y = pow(R * R - (i - geta + 1) * (i - geta + 1), 0.5)
                flag &= buildings[i] >= y - R + mid
            else:
                y = pow(R * R - (i - geta) * (i - geta), 0.5)
                flag &= buildings[i] >= y - R + mid
        if flag:
            left = mid
        else:
            right = mid
    print("{:.20f}".format(left))

Measured memory_bytes: 7740
def dot(a, b):
  return a.real * b.real + a.imag * b.imag

def cross(a,b):
  return a.real * b.imag - a.imag * b.real

n=int(input())
vs=[complex(*map(int,input().split())) for i in range(n)]
edges=[(p0,p1) for p0,p1 in zip(vs,vs[1:]+[vs[0]])]

q=int(input())

while q:
  q -= 1
  p = complex(*map(int,input().split()))
  count=0
  for p0,p1 in edges:
    a=p0-p
    b=p1-p
    if a.imag>b.imag:
      a,b=b,a
    crs=cross(a,b)
    if a.imag <= 0 and 0 < b.imag and crs < 0:
      count+=1
    if crs == 0 and dot(a,b) <= 0:
      print(1)
      break
  else:
    print(2 if count %2 else 0)



Measured memory_bytes: 5684
import java.util.*;

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

  		int n = sc.nextInt();
      	long nums[] = new long[n];
      	long ans = 1;
      	boolean con = true;
      	long zero = 0; 
      	long limit = 1000000000;
      	limit *= 1000000000;
      	for(int i = 0;i < n; i++) {
          nums[i] = sc.nextLong();
          if(nums[i] == 0) ans = 0; 
        }
      
      	if(ans != 0) {
          ans = nums[0];
          limit /= nums[0];
        }
           
      	for(int i = 1;i < n && ans != 0; i++) {
          	if(nums[i] > limit) con = false;
          	if(con){
              ans *= nums[i];
              limit /= nums[i];
            }
        }
      
      	if(con) System.out.println(ans);
      	else System.out.println("-1");
        
	}
}


Measured memory_bytes: 61780
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<pair<int,int>> ans;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    ans.push_back(make_pair(a,i+1));
  }
  sort(ans.begin(),ans.end());
  for(int i=0;i<n;i++){
    if(i==n-1){
      cout<<ans[i].second;
      return 0;
    }
    cout<<ans[i].second<<' ';
  }
  return 0;
}

Measured memory_bytes: 4332
#include<stdio.h>


int main(){

    int x , y, n,k, m,count=0,z;

    scanf("%d %d %d %d %d",&x,&y,&n,&m,&k);

    z=n-x;

    count=z*60;

    count+=m-y;

    count-=k;

    printf("%d",count);

    return 0;
}

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60;
const int MAX_N = 200005;

ll a[MAX_N],b[MAX_N];

int main(){
  int N; cin >> N;
  rep(i,N) scanf("%lld",a+i);
  rep(i,N) scanf("%lld",b+i);
  ll pls,mns; pls = mns = 0LL;
  rep(i,N){
    if(a[i]>b[i]) pls += a[i] - b[i];
    else mns += (b[i] - a[i]) /2; 
  }
  if(pls<=mns) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(){
    int A,B,C;
    scanf("%d%d%d", &A, &B, &C);
    if( A == B ){
        printf("%d\n", C);
    }
    if( A == C ){
        printf("%d\n", B);
    }
    if( B == C ){
        printf("%d\n", A);
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;


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

	ll n;	cin >> n;

	vector <ll> v(n);
	map <ll, ll> m;
	ll final = 0;

	for (auto &i: v)	cin >> i;

	ll sum = 0;	m[0]++;

	for (int i = 0; i < n; i++) {
		sum += v[i];
		m[sum]++;
	}

	for (auto &i: m)
		if (i.ss)
			final += i.ss * (i.ss - 1) / 2;

	cout << final << endl;

	return 0;
}

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

int selectionSort(int A[], int N) {
  int sw = 0;
  for (int i = 0; i < N; i++) {
    int minj = i;
    for (int j = i; j < N; j++) {
      if (A[j] < A[minj]) minj = j;
    }
    int temp = A[i];
    A[i] = A[minj];
    A[minj] = temp;
    if (i != minj) sw++;
  }
  return sw;
}

int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  int sw = selectionSort(A, N);
  for (int i = 0; i < N; i++) {
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
  return 0;
}



Measured memory_bytes: 3096
#include<iostream>
#include<vector>
#include<queue>
#include<string>

using namespace std;

void printv(vector<int> v){
	for (int i = 0; i < v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

vector<int> subvec(vector<int> vec,int a,int b){
	vector<int> ret(b);
	for (int i = 0; i < b; i++){
		ret[i] = vec[i+a];
	}
	return ret;
}


int main(){
	while(1){
		int n; cin >> n;
		int r; cin >> r;
		if (n == 0 and r == 0) break;
		vector<int> str(n);

		for (int i = n; i > 0; i--){
				str[n-i] = i;
		}
		for (int i = 0; i < r; i++){
			vector<int> tmp;
			int p,c; cin >> p >> c;
			vector<int> str1 = subvec(str,0,p-1);
			vector<int> str2 = subvec(str,p-1,c);
			vector<int> str3 = subvec(str,p+c-1,str.size()-p-c+1);

			copy(str2.begin(),str2.end(),back_inserter(tmp));
			copy(str1.begin(),str1.end(),back_inserter(tmp));
			copy(str3.begin(),str3.end(),back_inserter(tmp));
			str = tmp;
		}
		cout << str[0] << endl;
	}		
	return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A, B, C;
	cin >> A >> B >> C;
	swap(A, B);
	swap(A, C);
	cout << A <<" "<< B <<" "<< C << endl;

	return 0;
}

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n);
    map<int, int> app;
    fori(i, 0, n) {
        cin >> v[i];
        app[v[i]]++;
    }
    sort(v.begin(), v.end());
    int ans = 0;
    ford(i, v.size() - 1, 0) {
        if(app[v[i]] == 0) {
            continue;
        }
        app[v[i]]--;
        ford(j, 30, 0) {
            int target = 1 << j;
            if(target < v[i]) {
                break;
            }
            int need = target - v[i];
            if(app[need] > 0) {
                ans++;
                app[need]--;
                break;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 29824
N = int(input())
Alph = [chr(i) for i in range(97, 97+26)]
keta = 1
allz = 26**keta
ans = ""
bifallz = 0
27

while N > allz:
    keta += 1
    bifallz = allz
    allz += 26**keta
    
N = N - (bifallz + 1)

for k in range(keta):
    ans += Alph[N%26]
    N = N//26

print(ans[::-1])

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

using namespace std;

#define MAX_N 100005
#define MAX_M 100005

int N, M;
int A[MAX_M], B[MAX_M];

int dp[MAX_N];

int main()
{

  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    dp[A[i]]++; dp[B[i]]--;
  }

  for (int i = 0; i <= N; i++) {
    dp[i+1] += dp[i];
  }

  for (int i = 0; i <= N; i++) {
    if(dp[i] % 2 == 1){
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;

  return 0;
}


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

int main() {
  int h, w, m, bomb = 0;;
  scanf("%d %d %d", &h, &w, &m);
  set<pair<int, int>> s;
  vector<int> hde(h, 0);
  vector<int> wde(w, 0);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    hde[x - 1]++;
    wde[y - 1]++;
    s.insert(make_pair(x - 1, y - 1));
  }
  int hhin = -1, whin = -1;
  vector<int> hmax,  wmax;
  for (int i = 0; i < h; i++) {
    if(hhin < hde[i]) {
      hhin = hde[i];
      hmax = {i};
    }else if(hhin == hde[i]) {
      hmax.push_back(i);
    }
  }
  for (int i = 0; i < w; i++) {
    if(whin < wde[i]) {
      whin = wde[i];
      wmax = {i};
    }else if(whin == wde[i]) {
      wmax.push_back(i);
    }
  }
  bomb = hhin + whin;
  bool flag = false;
  for (int i = 0; i < hmax.size(); i++) {
    for (int j = 0; j < wmax.size(); j++) {
      if(!s.count(make_pair(hmax[i], wmax[j]))) {
        flag = true;
        break;
      }
    }
  }
  if(!flag) bomb--;//爆破予告ではない(hmax, wmax)が存在しない
  cout << bomb;
}

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

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

int main() {
    double ans = 0;
    int n;
    double a[1001];
    cin >> n;
    REP(i, n){
        cin >> a[i];
    }
    REP(i, n){
        ans += 1 / a[i];
    }

    cout << setprecision(10) << 1/ans << endl;
}

Measured memory_bytes: 256
N = int(input())
a = [int(i) for i in input().split()]
count = 0
for i in range(N):
    minj = i
    for j in range(i,N):
        if a[j] < a[minj]:
            minj = j
    if i != minj:
        count += 1
        a[i], a[minj] = a[minj], a[i]
print(" ".join(map(str, a)))
print(count)

Measured memory_bytes: 7748
#include <iostream>
#define N 123457*2

using namespace std;

int main(void){
	int n,i,j,f,first,last;
	int prime[N]={0};
	prime[0]=2;
	for (i=3;i<=N;i++){
		for(j=0;prime[j];j++) if(i%prime[j] == 0) break;
		if(!prime[j])prime[j]=i;
	}
	while(cin>>n,n){
		for(j=0;;j++) if(n < prime[j]){first=j; break;}
	        for(j=0;;j++) if(2*n < prime[j]){last=j; break;}
	      	cout<<last-first<<endl;
	}
	return 0;
}

Measured memory_bytes: 1716
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  string o;
  string e;
  cin >> o >> e;
  REP(i,e.size()){
    cout << o[i];
    cout << e[i];
  }
  if(o.size() - e.size()) cout << *o.rbegin() << endl;
  else cout << endl;
  return 0;
}

Measured memory_bytes: 3580
#include<iostream>
using namespace std;
int main() {
	int n; cin >> n;
	bool b00l[1001] = {};
	int a = 0, b = 0, c = 0;
	for (int i = 0; i < n; i++) {
		cin >> c;
		b00l[c] = true;
		b00l[b * 10 + c] = true;
		b00l[a * 100 + b * 10 + c] = true;
		a = b;
		b = c;
	}
	for (int i = 0; i < 1000; i++) {
		if (!b00l[i]) { cout << i << endl; return 0; }
	}
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

struct edge{int to, cap, rev;};

vector<edge> G[60001];
bool used[60001];

void add_edge(int from,int to,int cap){
    G[from].push_back((edge){to,cap,(int)G[to].size()});
    G[to].push_back((edge){from,0,(int)G[from].size()-1});
    swap(from,to);
    G[from].push_back((edge){to,cap,(int)G[to].size()});
    G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

int dfs(int v,int t,int f){
    if(v==t)return f;
    used[v]=true;
    for(int i=0;i<G[v].size();i++){
        edge &e = G[v][i];
        if(!used[e.to]&&e.cap>0){
            int d = dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s,int t){
    int flow = 0;
    while(true){
        memset(used,false,sizeof(used));
        int f = dfs(s,t,10000000);
        if(f==0)return flow;
        flow +=f;
    }
}

int main(){

    int H,W;cin>>H>>W;

    //0~HW-1 :  横軸から集める点
    //HW~2*HW-1:縦軸から集める点
    //2*HW + 0~H-1,H~H+W:　軸で集める点
    //i*W + j　→ i to 2*HW+i(cap=inf) , HW+j to 2*HW+H+j, i to HW+j(cap=1)
    vector<int> st;

    int inf = 10000;
    REP(i,H){
        REP(j,W){
            char c;cin>>c;
            if(c=='o'){
                add_edge(i*W+j,2*H*W+i,inf);
                add_edge(H*W+i*W+j,2*H*W+H+j,inf);
                add_edge(i*W+j,H*W+i*W+j,1);

            }else if(c=='S'||c=='T'){
                st.push_back(i*W+j);
                add_edge(i*W+j,2*H*W+i,inf);
                add_edge(H*W+i*W+j,2*H*W+H+j,inf);
                add_edge(i*W+j,H*W+i*W+j,inf);
            }
        }
    }


    int ans = max_flow(st[0],st[1]);


    if(ans>=inf)ans=-1;
    cout<<ans<<endl;




    return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (a + b > c + d) {
    cout << "Left" << endl;
  }
  else if (a + b == c + d) {
    cout << "Balanced" << endl;
  }
   else cout << "Right" << endl;
}

Measured memory_bytes: 3592
// In The Name Of God
#include <bits/stdc++.h>

#define sqr(A) ((A) * (A))
#define X first
#define Y second
#define MP make_pair
#define bsz  __builtin_popcount
#define all(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 1e5 + 20;
ll n, k, ans = LINF, a[N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - k + 1; i++) {
		if (a[i] > 0)
			ans = min(ans, a[i + k - 1]);
		if (a[i + k - 1] <= 0)
			ans = min(ans, abs(a[i]));
		if (a[i] < 0 && 0 < a[i + k - 1])
			ans = min({ans, 2LL * abs(a[i]) + a[i + k - 1], 2LL * a[i + k - 1] + abs(a[i])});
	}
	cout << ans << endl;
}












































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

using namespace std;
typedef long long ll;

int main(){
  int x1,x2,y1,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3 = y1 - y2 + x2;
  int y3 = y2 + x2 - x1;
  int x4 = x1 - x2 + x3;
  int y4 = y1 - y2 + y3;
  cout << x3 << " " << y3 << " " << x4 << " " <<  y4 << endl;
}


Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		System.out.println(a + b + c - Math.max(a, Math.max(b, c)));
	}

}


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

int digit(int n)
{
    int res;
    for (res = 0; n; n /= 10, ++res);
    return res;
}

int main()
{
    int x;
    scanf("%d", &x);
    int ans = 0;
    for (int i = 1; i <= x; ++i)
        ans += digit(i) & 1;
    printf("%d", ans);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

// array pointer = *a, num of element = n, key key
int lower_bound(int *a, int n, int key){
    int ng, mid, ok;
    ng = -1, ok = n-1;
    while (abs(ok - ng) > 1){
        mid = (ok + ng) / 2;
        if (key <= a[mid]){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    if (a[ok] >= key)return ok;
    return n;
}

//greatest common divisor
unsigned long gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}

unsigned long lcm(unsigned long x, unsigned long y){
    unsigned long g = gcd(x, y);
    return x*y/g;

}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}




/*unsigned long long pascal[100][100] = {0};
void make_pascal(void){
    for (int i = 0; i < 100; i++){
        pascal[i][0] = 1;
    }
    pascal[1][1] = 1;
    for (int i = 2; i < 100; i++){
        for (int j = 1; j < 100; j++){
           pascal[i][j] = (pascal[i-1][j-1]+pascal[i-1][j]) % mod;
        }
    }
}*/
long long mod = 1000000007;

//x ^ n
long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % mod;
        x = x * x % mod;
    }
    return res;
}

/*int struct_ascending_compare(const void *p, const void *q) {
    return ((structname*)p)->member - ((strcutname*)q)->member;
}*/

int main(void){
    long long a, b, x;
    scanf("%lld %lld %lld", &a, &b, &x);
    long long l;
    long long u;

    u = b/x;

    if (a % x){
        l = a/x;
    }else{
        l = a/x-1;
    }

    printf("%lld\n", u - l);

    return 0;

    


}


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

int main() {
	
	int n, w;
	cin >> n >> w;
	
	long long wt[n], v[n];
	for(int i=0; i<n; ++i)
	    cin >> wt[i] >> v[i];
	
	long long maxValue[n+1][w+1];
	for(int i=0; i<=w; ++i)
	    maxValue[0][i] = 0;
	for(int i=0; i<=n; ++i)
	    maxValue[i][0] = 0;
	
	for(int i=1; i<=n; ++i)
	{
	    for(int j=1; j<=w; ++j)
	    {
	        maxValue[i][j] = maxValue[i-1][j];
	        if (j >= wt[i-1])
	        {
	            maxValue[i][j] = max(maxValue[i][j], maxValue[i-1][j-wt[i-1]] + v[i-1]);
	        }
	    }
	}
	
	cout << maxValue[n][w];
	
	return 0;
}


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

using namespace std;



int main(){
    int a,b;
    cin >> a >> b;
    int ans=0;
    for (int i=a;i<=b;i++){
        bool ok = true;
        stringstream ss;
        ss << i;
        string front= ss.str();
        for (int j=0;j<front.length();j++){
            if ((front[j] != front[front.length()-j-1])) ok = false;
        }
        if (ok) ans += 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<Edge>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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;}

int main(){
  ll N,mx=0;
  cin>>N;
  Graph G(N);
  REP(i,N-1){
    ll A,B;
    cin>>A>>B;
    A--,B--;
    G[A].emplace_back(B,i);
    G[B].emplace_back(A,i);
  }
  
  REP(i,N) chmax(mx,(ll)G[i].size());
  co(mx);
  
  vector<ll> ans(N-1,-1);
  vector<ll> dist(N,-1);
  dist[0]=0;
  queue<pair<ll,ll>> Q; // (頂点,直前の色)
  Q.push({0ll,-1ll});
  
  while(!Q.empty()){
    auto p=Q.front();
    Q.pop();
    ll v=p.first,c=p.second;
    ll color=1;
    if(color==c) color++;
    FORE(e,G[v]){
      if(dist[e.first]==-1){
        dist[e.first]=dist[v]+1;
        Q.push({e.first,color});
        ans[e.second]=color;
        ++color;
        if(color==c) color++;
      }
    }
  }
  
  REP(i,N-1) co(ans[i]);
  return 0;
}

Measured memory_bytes: 12268
#include <iostream>
#include <cmath>
#include <string>
#include <stack>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

typedef long long llong;


int main() {
	int N, h[100], p[100], c;
	c = 0;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> h[i];
		p[i] = 0;
	}

	int left, right;
	left = 0;
	right = N-1;
	while(true) {
		//cout << left << endl;
		if(right == left and p[right] == h[right]) break;
		if(p[left] == h[left]){
			left++;
			continue;
		}
		for (int k = left; k <= right; ++k) {
			if (p[k] < h[k]) {
				p[k]++;
			} else {
				break;
			}
		}

		c++;

	}
/*
	for (int j = 0; j < N; ++j) {
		cout << p[j] << endl;
	}*/

	cout << c << endl;

	return 0;
}



Measured memory_bytes: 256
MOD = 1_000_000_007
def calc_combi(n,k):
    frac=1
    denomi=1
    for i in range(n-k+1,n+1):
        frac=frac*i%MOD
    for i in range(1,k+1):
        denomi=denomi*i%MOD
    return frac*pow(denomi,MOD-2,MOD)

n, a, b = map(int,input().rstrip().split())
nca = calc_combi(n,a)
ncb = calc_combi(n,b)
print((pow(2,n,MOD)-1-nca-ncb)%MOD)

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

template <typename T>
struct graph {
  int n;
  vector<vector<pair<int, T>>> node;
  graph(int m) {
    n = m;
    node.resize(n);
  }
  void add_edge(int s, int t, T cost=1) {
    node[s].push_back(pair<int, T>(t, cost));
  }
  vector<T> dijkstra(int s, T init=INF) {
    vector<T> d(n, init);
    d[s] = 0;
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>> > pq;
    pq.push(pair<T, int>(0, s));
    while (!pq.empty()) {
      pair<T, int> p = pq.top(); pq.pop();
      int pos = p.second;
      for (auto e : node[pos]) {
        if (d[pos] + e.second < d[e.first]) {
          d[e.first] = d[pos] + e.second;
          pq.push(pair<T, int>(d[e.first], e.first));
        }
      }
    }
    return d;
  }
};

int main(){
  int n,x,y;
  cin>>n>>x>>y;
  graph<int>g(n);
  rep(i,n-1){
    g.add_edge(i,i+1);
    g.add_edge(i+1,i);
  }
  x--;y--;
  g.add_edge(x,y);
  g.add_edge(y,x);
  vector<int>cnt(n);
  rep(i,n){
    vector<int>d=g.dijkstra(i);
    rep(j,n)cnt[d[j]]++;
  }
  rep2(i,1,n){
    cout<<cnt[i]/2<<endl;
  }
  return(0);
}


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

using namespace std;

int main() {
    int i,N,rods;
    int rod[60];
    int maxlength = 0;
    int length = 0;

    cin >> N >> rods;
    for(i = 0; i < N; i++){
        cin >> rod[i];
    }

    sort(rod,rod+N,greater<int>());

    for(i = 0; i < rods;i++){
        length += rod[i];
    }
    
    if(maxlength <= length) {
        maxlength = length;
    }
    cout << maxlength << endl;

    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        string[] line = System.Console.ReadLine().Trim().Split(' ');
        int n = int.Parse(line[0]);
        int m = int.Parse(line[1]);

        //mの約数を調べる

        List<int> list = new List<int>();

        for(int i = 1; i<= Math.Sqrt(m);i++)
        {
            if(m%i == 0)
            {
                list.Add(i);
                if (i!= m/1)
                {
                    list.Add(m / i);
                }
            }
        }

        //m/nより小さく、最大となる整数を探す
        int rlt = 1;
        foreach(int i in list)
        {
            if(i<= m/n && i > rlt)
            {
                rlt = i;
            }
        }

        System.Console.WriteLine(rlt.ToString());

    }
}


Measured memory_bytes: 13268
a=[int(x) for x in input().split()]
#print(a)
ans1=a[0]*a[2]
ans2=a[0]*a[3]
ans3=a[1]*a[2]
ans4=a[1]*a[3]
if(ans1>ans2):
    b=ans1
else:
    b=ans2
if(b<ans3):
    b=ans3
if(b<ans4):
    b=ans4
print(b)

Measured memory_bytes: 9184
def ans(n):
  if n==1:
    return [['0','1'],['0','0']]
  else:
    l=[['0' for i in range(2**n)] for j in range(2**n)]
    ans2=ans(n-1)
    for i in range(2**n):
      for j in range(2**n):
        if i<2**(n-1) and j<2**(n-1):
          l[i][j]=ans2[i][j]
        elif i<2**(n-1) and j>=2**(n-1):
          l[i][j]=str(n)
        elif i>=2**(n-1) and j<2**(n-1):
          l[i][j]='0'
        else:
          l[i][j]=ans2[i-2**(n-1)][j-2**(n-1)]
    return l
import math
n=int(input())
N=math.ceil(math.log(n,2))
ans=ans(N)
for i in range(n-1):
  print(' '.join(ans[i][i+1:n]))

Measured memory_bytes: 10680