akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<n;i++)
#define ll long long

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b){
        cout << c << endl;
    }else if(b==c){
        cout << a << endl;
    }else if(c==a){
        cout << b << endl;
    }
}



Measured memory_bytes: 256
import java.util.*;

class F {
    static char[] statement;
    static int c;

    static class Ans {
        int value;
        int pos;

        Ans(int value, int pos) {
            this.value = value;
            this.pos = pos;
        }

        @Override
        public String toString() {
            return value + " " + pos;
        }
    }

    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int Q = sc.nextInt();
        for (int q = 0; q < Q; q++) {
            statement = sc.next().toCharArray();
            c = 0;
            System.out.println(expression(0, 99));
            if(statement[c] != '?')
                throw null;
        }
    }

    static Ans expression(int lo, int up) {
        switch (statement[c]) {
            case '^':
                return max(lo, up);
            case '_':
                return min(lo, up);
            default:
                return value(lo, up);
        }
    }

    static Ans value(int lo, int up) {
        final int i = statement[c] - '0';
        final int pos = i == 0 || i * 10 + 9 <= lo || i >= up ? c + 1 : c + 2;
        if (Character.isDigit(statement[c + 1])) {
            final int r = i * 10 + statement[c + 1] - '0';
            c += 2;
            return new Ans(r, pos);
        } else {
            c++;
            return new Ans(i, pos);
        }
    }

    static Ans min(int lo, int up) {
        c += 2;
        final Ans left = expression(lo, up);
        c++;
        final Ans right = expression(lo, Math.min(up, left.value));
        c++;
        return new Ans(Math.min(left.value, right.value), left.value <= lo ? left.pos : right.pos);
    }

    static Ans max(int lo, int up) {
        c += 2;
        final Ans left = expression(lo, up);
        c++;
        final Ans right = expression(Math.max(lo, left.value), up);
        c++;
        return new Ans(Math.max(left.value, right.value), left.value >= up ? left.pos : right.pos);
    }
}

public class Main {
    public static void main(String... args) {
        F.main();
    }
}

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

int main() {
  int64_t n,k;
  cin>>n>>k;
  int64_t x=n%k,y;
  y=abs(x-k);
  int64_t ans=min(x,y);
  cout<<ans<<endl; 
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,m ;
	cin >> n >> m ;
	ll ans = 0 ;
	for(ll i=1;i*i<=m;i++){
		if(m%i!=0) continue ;
		if(i>=n){
			cout << m/i << endl ;
			return 0 ;
		}
		if(m/i>=n) ans = i ;
	}
	cout << ans << endl ;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

vector<ll> v;
int nxt[111111][22];
int pre[111111][22];
int n,q;
ll L;

int main(){
	
	cin >> n;
	REP(i,n){
		int tmp;cin >> tmp;
		v.EB(tmp);
	}
	cin >> L;
	
	REP(i,n){
		if(i == n-1)nxt[i][0] = n;
		else {
			nxt[i][0] = (upper_bound(ALL(v),v[i] + L) - v.begin()) - 1;
		}
		
		if(i == 0)pre[i][0] = -1;
		else {
			pre[i][0] = (lower_bound(ALL(v),v[i] - L) - v.begin());
		}
	}
	
	REP(i,21){
		REP(j,n){
			if(nxt[j][i] == n)nxt[j][i+1] = n;
			else nxt[j][i+1] = nxt[nxt[j][i]][i];
			if(pre[j][i] == -1)pre[j][i+1] = -1;
			else pre[j][i+1] = pre[pre[j][i]][i];
		}
	}
		
	cin >> q;
	REP(seica,q){
		int a,b;cin >> a >> b;
		a--;b--;
		ll ans = 0;
		ll now = a;
		if(a < b){
			while(now < b)for(int i = 21;i >= 0;i--){
				//cout << i << " " << now << " " << nxt[now][i] << " " << (1<<i) << " " << ans << endl;
				if(i == 0 || nxt[now][i] <= b){
					ans += (1 << i);
					now = nxt[now][i];
				}
				if(now == b)break;
			}
		}
		else {
			while(now > b)for(int i = 21;i >= 0;i--){
				//cout << i << " " << now << " " << pre[now][i] << " " << (1<<i) << " " << ans << endl;
				if(i == 0 || pre[now][i] >= b){
					ans += (1 << i);
					now = pre[now][i];
				}
				if(now == b)break;
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 20212
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val ss = (1..N).map { readLine()!! }
    val M = readLine()!!.toInt()
    val ts = (1..M).map { readLine()!! }
    val all = mutableSetOf<String>()
    all.addAll(ss)
    all.addAll(ts)

    val ans = all.map {
        ss.count { x -> x==it } - ts.count { x -> x==it }
    }.max()!!
    println(if (ans>0) ans else 0)
}

Measured memory_bytes: 35956
using System;

public class my
{
	public static void Main()
	{
		var n = my.GetInt();
		
		for(int i = 0; i<n; i++) {
			var d = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
			
			var x1 = d[0];
			var y1 = d[1];
			var x2 = d[2];
			var y2 = d[3];
			var x3 = d[4];
			var y3 = d[5];
			
			var A =  Math.Pow((x2-x3),2) + Math.Pow((y2-y3),2);
			var B =  Math.Pow((x3-x1),2) + Math.Pow((y3-y1),2);
			var C =  Math.Pow((x1-x2),2) + Math.Pow((y1-y2),2);
			var D = 2*(A*B+B*C+C*A)-A*A-B*B-C*C;
			var E = A*(B+C-A);
			var F = B*(C+A-B);
			var G = C*(A+B-C);
			
			var px = (E*x1+F*x2+G*x3)/D;
			var py = (E*y1+F*y2+G*y3)/D;
			
			var a = Math.Sqrt(A);
			var b = Math.Sqrt(B);
			var c = Math.Sqrt(C);
			
			var r = a*b*c/ Math.Sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c)) ;
			
			Console.WriteLine(string.Format("{0:F3} {1:F3} {2:F3}", px, py, r));
		}
	}

	private static int GetInt()
	{
		return int.Parse(Console.ReadLine());
	}

}

Measured memory_bytes: 9248
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int a[26]={0};
  string s;
  cin >> s;
  for(int i=0; i<s.size(); i++) {
    a[s[i]-'a']++;
  }
  for(int i=0; i<26; i++) {
    if(a[i]%2==0) {
      continue;
    }
    else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

using namespace std;

int INF=1e9;

bool solve(int n){
    int n_rev=0,m=n;
    while(m>0){
        n_rev*=10;
        n_rev+=(m%10);
        m/=10;
    }
    return n==n_rev;
}

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

    int a,b;
    cin>>a>>b;
    int sum[100000]={};
    for(int i=1;i<100000;i++){
        if(solve(i))sum[i]=1;
        sum[i]+=sum[i-1];
    }
    int ans=sum[b]-sum[a-1];
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

const int N=2e5+5, INF=1e9;
int p[N],q[N],c[N];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector<PII> pairs; // (station, company)
    for(int i=0; i<n; i++) pairs.emplace_back(i,-1);

    REP(i,m) {
        cin >> p[i] >> q[i] >> c[i];
        p[i]--; q[i]--;
        pairs.emplace_back(p[i],c[i]);
        pairs.emplace_back(q[i],c[i]);
    }

    // coordinate compression
    sort_uniq(pairs);
    int z=pairs.size();
    map<PII,int> pairs2index;
    for(int i=0; i<z; i++) pairs2index[pairs[i]]=i;

    // make graph
    vector<vector<PII>> e(z); // station_i->(station_j, cost)
    
    // enter station, exit station
    for(int i=0; i<z; i++) {
        if ( pairs[i].second==-1 ) continue;
        int station=pairs[i].first;
        int out=pairs2index[make_pair(station,-1)];
        e[i].emplace_back(out,0); // 從station出站
        e[out].emplace_back(i,1); // 從station進站(轉乘)
    }

    // 同色線移動
    for(int i=0; i<m; i++) {
        int a=pairs2index[make_pair(p[i],c[i])];
        int b=pairs2index[make_pair(q[i],c[i])];
        e[a].emplace_back(b,0);
        e[b].emplace_back(a,0);
    }

    int start=pairs2index[make_pair(0,-1)];
    int goal=pairs2index[make_pair(n-1,-1)];
    vector<int> dist(z,INF);
    dist[start]=0;

    // 01-BFS
    deque<int> que;
    que.push_back(start);
    while(que.size()) {
        int u=que.front(); que.pop_front();
        for(auto& p:e[u]) {
            int v=p.first, cost=p.second;
            if ( dist[v]>dist[u]+cost ) {
                dist[v]=dist[u]+cost;
                if ( cost==0 ) que.push_front(v);
                else que.push_back(v);
            }
        }
    }
    cout << ( dist[goal]<INF? dist[goal] : -1 ) << '\n';
    return 0;
}

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

int main() {
  ll n,m;
  cin >> n >> m;
  vector<pair<ll,ll>> g(m);
  rep(i,m){
    ll a,b;
    cin >> a >> b;
    a--;
    b--;
    g[i] = make_pair(a,b);
  }

  sort(g.begin(),g.end());
  
  vector<ll> start,goal;
  
  rep(i,m){
    if(g[i].first == 0){
      start.push_back(g[i].second);
    }
    if(g[i].second == n-1){
      goal.push_back(g[i].first);
    }
  }
  
  sort(start.begin(),start.end());
  sort(goal.begin(),goal.end());
  
  ll s=start.size(),t=goal.size();
  rep(i,s){
    ll x = start[i];
    if(binary_search(goal.begin(),goal.end(),x)){
      cout << "POSSIBLE" << endl;
      return(0);
    }
  }
  
  cout << "IMPOSSIBLE" << endl;
  
  return(0);
}


Measured memory_bytes: 8768
#![allow(unused_imports)]
#![allow(unused_variables)]
use proconio::input;
use proconio::marker::*;
use std::cmp::{min, max};
use std::collections::{HashSet, HashMap, BinaryHeap};

fn main() {
    input! {
        n: usize,
        m: usize,
        h: [usize; n],
    }
    let mut e: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..m {
        input! {
            a: Usize1,
            b: Usize1,
        }
        e[a].push(b);
        e[b].push(a);
    }
    let mut ans = 0;
    for i in 0..n{
        if e[i].iter().all(|b| h[*b] < h[i]){
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 10660
#include <stdio.h>
int main(void){
    int W, a, b, ans = 0, cnt = 0;
    
    scanf("%d %d %d", &W, &a, &b);
    
    if((b > a && W + a >= b) || (a > b && W + b >= a)){
        cnt = cnt + 1;
    }else if(b > a){
        ans = b - (W + a);
    }else if(a > b){
        ans = a - (W + b);
    }
    if(cnt >= 1){
        printf("0\n");
    }else{
        printf("%d\n", ans);
    }
}


Measured memory_bytes: 1684
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std; using ll=long long;

struct SCC {
    int n; int group_id=0;
    vector<vector<int>> v, v2, v3, v4;
    vector<int> u, gi, t;
    vector<int> an;
    SCC(int _n) : n(_n) {
        v.resize(n); v2.resize(n);
        u.resize(n); gi.assign(n, -1);
    }
    void ae(int a, int b) {
        v[a].push_back(b);
        v2[b].push_back(a);
    }
    void dfs(int id) {
        if (u[id]) return;
        u[id] = true;
        for(int x : v[id]) dfs(x);
        t.push_back(id);
    }
    void rdfs(int id, int group_id) {
        if (gi[id] != -1) return;
        gi[id] = group_id;
        for(int x : v2[id]) rdfs(x, group_id);
    }

    void doo() {
        for(int i=0;i<n;i++) dfs(i);
        reverse(t.begin(), t.end());
        for(int x : t) {
            if (gi[x] == -1) {
                rdfs(x, group_id++);
            }
        }
    }
    void doo2() {
        int se[group_id]={};
        v3.resize(group_id);
        for(int i=0;i<n;i++) {
            for(int x : v[i]) {
                //cout << i << " " << x << " " << gi[i] << " " << gi[x] << endl;
                if (gi[i] != gi[x]) {
                    v3[gi[i]].push_back(gi[x]);
                    se[gi[x]]++;
                }
            }
        }
        /*
        for(int x : se) {
            cout<<x<<" ";
        } cout<<endl;*/
        v4.resize(group_id);
        for(int i=0;i<n;i++) {
            v4[gi[i]].push_back(i);
        }
        queue<int> que;
        for(int i=0;i<group_id;i++) {
            if (se[i] == 0) que.push(i);
        }
        while(!que.empty()) {
            int tp = que.front(); que.pop();
            for(int x : v3[tp]) {
                se[x]--;
                if (se[x] == 0) que.push(x);
            }
            an.push_back(tp);
        }
    }
    void answer() {
        cout<<group_id<<endl;
        for(int i=0;i<group_id;i++) {
            cout<<v4[i].size()<<" ";
            for(int x : v4[i]) {
                cout<<x<<" ";
            } cout<<endl;
        }
    }
    void print() {
        for(int x : t) {
            cout<<x<<" ";
        } cout<<endl;
        for(int i=0;i<n;i++) {
            cout<<gi[i]<<" ";
        } cout<<endl;
    }
};

int main() {
    int n,m; cin>>n>>m;
    SCC s(n);
    for(int i=0;i<m;i++) {
        int a,b; cin>>a>>b;
        s.ae(a,b);
    }//cout<<endl;
    //s.print();
    s.doo();
    //s.print();
    s.doo2();
    s.answer();
}

Measured memory_bytes: 108400
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, B: "List[int]"):
    ans = B[-1]
    pre = 0
    for i in range(N-2, 0, -1):
        ans += min(B[i], B[i-1])
    ans += B[0]
    print(ans)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    B = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, B)


if __name__ == '__main__':
    main()


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

int main(){
string f;
  cin>>f;
  string t="CODEFESTIVAL2016";
  int ans=0;
  for(int i=0;i<16;i++){
    if(f.at(i)!=t.at(i)){
      ans++;
    }
  }
  cout<<ans<<endl;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = max(0, c - (a - b));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let n: u32 = buf.trim().parse().unwrap();
    
    let ans = if n%2==0 {
        0.5
    } else {
        (n/2+1) as f64 / n as f64 
    };
    println!("{}",ans);
}

Measured memory_bytes: 4352
N, M = map(int, input().split())

ab_list = []
for _ in range(M):
    ab_list.append(list(map(int, input().split())))

cnt = 0
def func(position, hist):
    global cnt
    hist = hist[:]
    if len(hist) == N:
        cnt += 1
    for ab in ab_list:
        if position in ab:
            next_position = [x for x in ab if x != position][0]
            if next_position not in hist:
                func(next_position, hist+[position])

func(1,[0])
print(cnt)

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N, M; cin >> N >> M;
  int result = N*(N-1)/2 + M*(M-1)/2;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Output
template<class T, class S> std::ostream& operator <<(std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator <<(std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec << std::endl; }
  os << "--------" << std::endl;
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}

void solve()
{
  ll N;
  std::cin >> N;
  std::map< ll, ll > mp;
  for (ll i = 0; i < N; i++) {
    ll a;
    std::cin >> a;
    mp[a]++;
  }

  ll M = 1e6+10;
  std::vector<bool> vj(M, true);
  for (auto p : mp) {
    ll x = p.first;
    for (ll i = x * 2; i < M; i += x) {
      vj[i] = false;
    }
  }

  ll ans = 0LL;
  for (auto p : mp) {
    if (p.second == 1 && vj[p.first] == true) ans++;
  }

  print(ans);
  return;
}

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

  solve();
  return 0;
}



Measured memory_bytes: 16108
#include<iostream>
#include <map>
#include <algorithm>
typedef long long ll;
using namespace std;
map<int,int> p;
bool prime[10000];
ll com[6];
int t[6] = {1,2,4,14,24,74};
int main() {
  int n;
  cin >> n;
  for(int i = 2; i <= 10000; i++) {
    if(prime[i]) continue;
    for(int j = i + i; j <= 1000; j += i) {
      prime[j] = true;
    }
  }

  for(int i = 2; i <= n; i++) {
    int tmp = i;
    for(int j = 2; j <= 1000; j++) {
      if(prime[j]) continue;
      while(tmp % j == 0) {
	tmp /= j;
	p[j]++;
      }
      if(tmp == 1) break;
    }
  }

  ll ans = 0;
  
  for(int j = 0; j < 6; j++) {
    for(auto itr = p.begin(); itr != p.end(); ++itr) {
      int tmp = itr->second;
      if(t[j] <= tmp) com[j]++;
    }
  }



  /*  for(int i = 0; i < 6; i++) {
    cout << com[i] << endl;
    }*/
  ans += (com[2] * (com[2] - 1)) / 2 * (com[1] - 2);
  ans += (com[4] * (com[1] - 1));
  ans += (com[3] * (com[2] - 1));
  ans += com[5];;
  cout << ans << endl;
}
      
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=(1ull<<63)-1;
const int inf=(1ull<<31)-1;
ll n;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	cin>>n;
	cout<<(n*(n-1)>>1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int H,W;
  cin >> H >> W;
  vector<vector<char>> a(H,vector<char>(W));
  rep(i,H)
  {
    rep(j,W)
    {
      cin >> a[i][j];
    }
  }
  rep(i,W+2)
  {
    if(i!=W+1)
    {
      cout << "#";
    }
    else
    {
      cout << "#" << endl;
    }
  }
  rep(i,H)
  {
    rep(j,W)
    {
      if(j==0)
      {
        cout << "#" ;
      }
      cout << a[i][j];
      if(j==W-1)
      {
        cout << "#" << endl;
      }
      
    }
  }
  rep(i,W+2)
  {
    if(i!=W+1)
    {
      cout << "#";
    }
    else
    {
      cout << "#" << endl;
    }
  }  
  return 0;
}


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

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
const int MAXN = 1e5;

int prime[MAXN] = {0};
bool is_prime[MAXN+1] = {false};

void seive()
{
    for(int i = 0; i < MAXN+1  ; i++)
    {
        is_prime[i] = true;
    }

    is_prime[0] = false;
    is_prime[1] = false;

    for(int i = 2; i < MAXN+1; i++)
    {
        if (is_prime[i])
        {
            for(int j = 2 * i; j < MAXN+1 ; j += i)
            {
                is_prime[j] = false;
            }
        }
    }
}

void count()
{
    for(int i = 0; i < MAXN+1; i++)
    {
        if (i % 2 == 0)
        {
            prime[i] = prime[i-1];
        }else
        {
            prime[i] = prime[i-1];
            if (is_prime[i] && is_prime[(i+1)/2])
            {
                prime[i]++;
            }
        }
    }
}

int main()
{
    int q;
    int l[MAXN] = {0}, r[MAXN] = {0};
    seive();
    count();

    cin >> q;
    for(int i = 0; i < q; i++)
    {
        cin >> l[i] >> r[i];
    }

    for(int i = 0; i < q; i++)
    {
        int L = prime[l[i]-1], R = prime[r[i]] ;

        cout << R - L << endl;
    }

    // printf("\n");

    // for(int i = 0; i < 20; i++)
    // {
    //     cout << i;
    //     cout << " " << prime[i] << endl;
    // }

    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define faster() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const long long int infLL = 9000000000000000000;
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(a) (a).begin(),(a).end()
#define mx_int_prime 999999937
const int inf = 2000000000;
const double PI = acos(-1);
const double eps = 1e-9;
typedef long double ld;
#define MOD 1000000007
typedef long long ll;
const int mx=2e5+125;
ll p[mx],a[mx],b[mx];
#define PB push_back
#define endl '\n'
#define S second
#define F first
int main()
{
    faster();
    ll n,m;
    cin>>n>>m;
    vector<int>v(n,0);
    vector<bool>ans(n,0);
    int c=0,c2=0;
    for(int i=0; i<m; i++)
    {
        int p;
        string s;
        cin>>p>>s;
        p--;
        if(s=="AC")
        {
            if(!ans[p])
            {
                c++;
                c2+=v[p];
                ans[p]=1;
            }
        }
        else
        {
            v[p]++;
        }

    }
    cout<<c<<" "<<c2<<endl;

    return  0;
}


Measured memory_bytes: 3704
using System.Collections.Generic;
using static System.Console;

class C
{
	static void Main()
	{
		var n = int.Parse(ReadLine());
		var s = ReadLine();

		var rs = new List<int>();
		int t = 0, o = 0;
		for (var i = 0; i < s.Length; i++)
		{
			if (s[i] == 'W' ^ t % 2 == 0)
			{
				if (o == n) { WriteLine(0); return; }
				t++;
				o++;
			}
			else
			{
				if (t == 0) { WriteLine(0); return; }
				t--;
				rs.Add(i);
			}
		}

		var r = 1L;
		for (var i = 0; i < n; i++) r = r * (rs[i] - 2 * i) * (i + 1) % 1000000007;
		WriteLine(r);
	}
}


Measured memory_bytes: 13208
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
    cin>>a;
    b=a;
    for(int i=0;i<a.size()/2;++i)swap(a[a.size()-1-i],a[i]);
    for(int i=0;i<a.size();++i)
    {
        if(a[i]=='b')a[i]='d';
        else if(a[i]=='d')a[i]='b';
        else if(a[i]=='p')a[i]='q';
        else if(a[i]=='q')a[i]='p';
    }
    if(a==b) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 512
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47492
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll inf=1e18;
const ll mod=1e9+7;
const ll maxn=1e5;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
char solve1(char a,char b){
    for(int i=0;i<26;i++){
        char x=i+'a';
        if(x!=a and x!=b)return x;
    }
    return 'X';
}
char solve2(char a, char b,char c){
    for(int i=0;i<26;i++){
        char x=i+'a';
        if(x!=a and x!=b and x!=c)return x; 
    }
    return 'X';
}
int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    ll n;
    cin>>n;
    string A[n];
    map<string,ll>m;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        m[s]++;
    }
    ll ans=0;
    for(auto &i:m){
        ans+=(i.second*(i.second-1))/2;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 12032
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    ll n, k; cin >> n >> k;
    cout << min(n%k, k-n%k) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
 
  long int n,m;
  scanf("%ld %ld",&n,&m);
  
  long int i,x,y,count = 0;
  m*=m;
  
  for( i = 0; i<n;i++){
  	scanf("%ld %ld",&x,&y);
    if(x*x +y*y <=m){
    count++;
    }
  	
  
  }
 
  
  printf("%ld",count);
 
}

Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,p;
    cin>>n>>m;
   p=m/2;
   if(p<=n)
        cout<<p<<endl;
   else if(n<p)
   {
       cout<<(n+((p-n)/2))<<endl;
   }
    return 0;

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

ll R,C,N;
bool online(ll x,ll y){
    if (x==0||x==R||y==0||y==C) return true;
    return false;
}

int main(){
    cin >> R >> C >> N;
    vector<vector<Pll>> clockwise(4);
    rep(i,N){
        vector<ll> x(2),y(2);
        cin >> x[0] >> y[0] >> x[1] >> y[1];
        if (online(x[0],y[0])&&online(x[1],y[1])){
            rep(j,2){
                if (y[j]==0) clockwise[0].push_back(Pll(x[j],i));
                else if (y[j]==C) clockwise[2].push_back(Pll(x[j],i));
                else if (x[j]==R) clockwise[1].push_back(Pll(y[j],i));
                else if (x[j]==0) clockwise[3].push_back(Pll(y[j],i));
            }
        }
    }
    rep(i,4){
        sort(clockwise[i].begin(),clockwise[i].end());
        if (i>1) reverse(clockwise[i].begin(),clockwise[i].end());
    }
    stack<ll> s;
    vector<bool> packed(N,false);
    bool can=true;
    rep(i,4){
        for (auto p:clockwise[i]){
            ll now=p.second;
            if (!packed[now]){
                s.push(now);
                packed[now]=true;
            }
            else {
                if (s.top()==now) s.pop();
                else can=false;
            }
        }
    }
    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

const int MAX_N = 50;
ll dp[MAX_N+1]; // dp[i] := レベルiバーガーの枚数

ll rec(ll N, ll X){
    if(N == 0) return 1;

    if(X == 1) return 0;
    else if(X <  (dp[N] + 1) / 2)return rec(N-1, X-1);
    else if(X == (dp[N]+1)/2) return rec(N-1, dp[N-1]) + 1;
    else if(X < dp[N]) return rec(N-1, dp[N-1]) + 1 + rec(N-1, X - (dp[N]+1)/2);
    else return 2 * rec(N-1, dp[N-1]) + 1;
}

int main(){
    ll N, X;cin >> N >> X;
    for(int i = 0; i <= N; i++){
        if(i == 0)dp[i] = 1;
        else dp[i] = 2 * dp[i-1] + 3;
    }
    cout << rec(N, X) << endl;
}

Measured memory_bytes: 256
# coding: utf-8
from collections import Counter
n = int(input())
s = [input() for i in range(n)]
res = dict(Counter(s))
res = sorted(res.items())
# print(res)
res = sorted(res, key=lambda x: x[1], reverse=True)
tmp = res[0][1]
for i,j in res:
    if tmp > j:
        break
    print(i)


Measured memory_bytes: 44268
/*input
5 2 2
ccccc
*/
#include <bits/stdc++.h>
using namespace std;

char s[100004];
int main() {
  int a, n, b, pass = 0, foreign = 0;
  scanf("%d%d%d\n", &n, &a, &b);
  scanf("%s", s);
  int m = strlen(s);
  for (int i = 0; i < m; ++i)
  {
    switch(s[i]) {
      case 'a':
        if (pass < a + b) {
          printf("Yes\n");
          pass++;
        } else {
          printf("No\n");
        }
        break;

      case 'b':
        if (pass < a + b && foreign < b) {
          printf("Yes\n");
          pass++;
          foreign++;
        } else {
          printf("No\n");
        }
        break;

      case 'c':
        printf("No\n");
        break;
    }
  }
  return 0;
}

Measured memory_bytes: 768
import numpy as np
import sys

input = sys.stdin.readline

alp = "abcdefghijklmnopqrstuvwxyz"
alp = list(alp)

w = sorted(input())
w = w[1:]

#print(w)
cnt = 1
for i in range(1,len(w)):
#    print( w[i],cnt)
    if w[i] ==w[i-1] :
        cnt +=1
    else:
        if cnt%2 == 1:
            print("No")
            exit()
        else:
            cnt = 1

if len(w) == 1:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 17972
#include <iostream>
#include <string>
#include <vector>
#include <utility>
using ll=long long;
using namespace std;

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

    int keta=1;
    int tmp=0;
    for(int i=0;i<K;i++){
        tmp+=keta*7;
        tmp%=K;
        if(tmp==0){
            cout<<i+1<<endl;
            return 0;
        }
        keta*=10;
        keta%=K;
    }
    cout<<-1<<endl;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    string s;
    cin >> s;
    s[5] = ' ';
    s[13] = ' ';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	A := ReadInts(N)

	sum := 0
	for _, ai := range A {
		sum += ai
	}

	restSum := 0
	for i := 1; i < N; i += 2 {
		restSum += A[i]
	}

	x := sum - 2*(restSum)
	ans := make([]int, 0)
	ans = append(ans, x)

	for i := 0; i < N-1; i++ {
		x = 2*A[i] - x
		ans = append(ans, x)
	}

	for i := 0; i < N; i++ {
		fmt.Printf("%d ", ans[i])
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 7792
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <numeric>
#include <map>
#include <utility>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
int main(void){
    int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
    cin>>a>>b;
    cout<<(a%b?a:-1)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int ans = 0;
    rep(i, n){
        int tmp = i+1;
        int sum = 0;
        while(tmp > 0){
            sum += tmp % 10;
            tmp /= 10;
        }
        if(sum >= a && sum <= b) ans += i + 1;
    }

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

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

class Dice {
public:
	int u, f, r, l, b, d;

	Dice(int uu, int ff, int rr, int ll, int bb, int dd) {
		u = uu;
		f = ff;
		r = rr;
		l = ll;
		b = bb;
		d = dd;
	}

	void move(char dir) {
		int tmp;

		if (dir == 'N') {
			tmp = u;
			u = f;
			f = d;
			d = b;
			b = tmp;
		}
		else if (dir == 'W') {
			tmp = u;
			u = r;
			r = d;
			d = l;
			l = tmp;
		}
		else if (dir == 'R') {
			tmp = r;
			r = f;
			f = l;
			l = b;
			b = tmp;
		}
	}

	bool isequall(Dice d1, Dice d2) {
		for (int i = 0;i < 6;i++) {
			for (int j = 0;j < 4;j++) {
				if (d1.u == d2.u && d1.f == d2.f && d1.r == d2.r && d1.l == d2.l && d1.b == d2.b && d1.d == d2.d) {
					return true;
				}
				d1.move('R');
			}
			if (i % 2 == 0) {
				d1.move('W');
			}
			else {
				d1.move('N');
			}
		}
		return false;
	}
};


int main()
{
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	Dice dice1(a, b, c, d, e, f);
	cin >> a >> b >> c >> d >> e >> f;
	Dice dice2(a, b, c, d, e, f);

	if (dice1.isequall(dice1, dice2)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

    return 0;
}



Measured memory_bytes: 3096
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
score = 0
for i in range(n-1):
    if a[i]+1 == a[i+1]:
        score += c[a[i]-1]
print(score+sum(b))

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

using ll = long long;
using cd = complex<double>;

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

    int n;
    string s;
    cin >> n >> s;

    vector<int> prefix_black(n  +1, 0);

    for(int i = 0; i < n; ++i)
        prefix_black[i + 1] = prefix_black[i] + (s[i] == '#' ? 1 : 0);

    int ret = prefix_black.back();

    for(int i = 0; i < n; ++i)
        ret = min(ret, prefix_black[i] + (n - i) - (prefix_black.back() - prefix_black[i]));

    cout << ret << endl;


    return 0;
}



Measured memory_bytes: 1428
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n;
  cin >>n;
  ll c[n-1],s[n-1],f[n-1];
  for(ll i=0;i<n-1;i++) cin >>c[i]>>s[i]>>f[i];
  for(ll i=0;i<n-1;i++){
    ll t=s[i]+c[i];
   for(ll j=i+1;j<n-1;j++){
     if(t>=s[j]){
     if(t%f[j]==0) t+=c[j];
     else t+=((f[j]-t%f[j])+c[j]);
     }
     else t+=(s[j]-t+c[j]);
   }
   cout <<t<<endl;
  }
  cout <<0<<endl;

}


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

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

  int ans = 0;

  if (n < 10){
    ans += 100*(10 - n);
    cout << ans + r << endl;
  }
  else {
    cout << r << endl;
  }
  
}



Measured memory_bytes: 256
N,K = map(int,input().split())
A = [int(i) for i in input().split()]
S = sum(A)

def searchPrimeNum(N):
    max = int(N**0.5)
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

plis = searchPrimeNum(40000)

lis = []
for p in plis:
    if S%p == 0:
        lis.append([p,1])
        S = S//p
        while S%p == 0:
            lis[-1][1] += 1
            S = S//p
    if S == 1:
        break
if S != 1:
    lis.append([S,1])

yakulis =[1]
for l in lis:
    for j in range(len(yakulis)):
        for k in range(l[1]):
            n = yakulis[j]
            yakulis.append(l[0]**(k+1)*n)
yakulis.sort(reverse=True)

s = True
for r in yakulis:
    B = [i%r for i in A]
    B.sort()
    le = -1
    ri = N
    while ri-le > 1:
        mid = (le+ri)//2
        pl = sum(B[:mid+1])
        mi = r*(N-1-mid) - sum(B[mid+1:])
        if pl > mi:
            ri = mid
        else:
            le = mid
    k = sum(B[:le+1])
    if k <= K:
        s = False
        print(r)
        break
if s:
    print(1)

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


int main(){
    ll A, B;
    string S;
    cin >> A >> B >> S;
    if(S[A] != '-' || S.size() != A + B + 1){
        cout << "No" << endl;
        return 0;
    }

    for(int i = 0; i < S.size(); i++){
        if(i != A && S[i] == '-'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long


typedef int Weight;
struct Edge{
    int from, to;
    Weight weight;
    int rev;     // 無向グラフの対の辺
    Edge(int from, int to, Weight weight) :
            from(from), to(to), weight(weight) { }
    Edge(int from, int to, Weight weight, int rev) :
            from(from), to(to), weight(weight), rev(rev){ }
};
bool operator < (const Edge &a, const Edge &b){
    if(a.weight != b.weight) return a.weight > b.weight;
    if(a.from != b.from) return a.from > b.from;
    return  a.to > b.to;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void addFlowEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, 0, g[a].size() - 1));
}
void addUndirectedEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, c, g[a].size() - 1));
}

void recur(const Graph &g, int v, int u, map<vector<int>, int> &mp, int m) {
    vector<int> se;
    se.push_back(u); se.push_back(v);
    sort(ALL(se));
    int c;
    if (u == -1) {
        c = -1;
    } else {
        c = mp[se];
    }

    int cnt = 1;
    for (auto e: g[v]) {
        if (e.to == u) continue;
        if (cnt == c) ++cnt;
        vector<int> w;
        w.push_back(e.from); w.push_back(e.to);
        sort(ALL(w));
        mp[w] = cnt++;
        recur(g, e.to, e.from, mp, m);
    }
}

void solve(long long N, std::vector<long long> a, std::vector<long long> b){
    Graph g(N);
    for (int i = 0; i < a.size(); ++i) {
        a[i]--; b[i]--;
        addUndirectedEdge(g, a[i], b[i], 0LL);
    }

    int res = 0;
    for (int i = 0; i < N; ++i) {
        res = max(res, (int)g[i].size());
    }

    map<vector<int>, int> mp;

    recur(g, 0, -1, mp, res);

    cout << res << endl;
    for (int i = 0; i < a.size(); ++i) {
        vector<int> e;
        e.push_back(a[i]); e.push_back(b[i]);
        sort(ALL(e));
        cout << mp[e] << endl;
    }
}

signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N-1);
    std::vector<long long> b(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    solve(N, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 32000
#include <stdio.h>

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>

int64_t solve(int64_t t)
{
	int64_t x = t;
	int64_t c = 0;

	while (x != 0)
	{
		x = x % std::bitset<64>(x).count();
		++c;
	}
	return c + 1;
}

int main()
{
	int64_t ta = solve(0b10110111001011011001110);
	int64_t tb = solve(0b01110111001011011001110);
	int64_t tc = solve(0b00010111001011011001110);
	int64_t td = solve(0b00100111001011011001110);
	int64_t te = solve(0b00111111001011011001110);

	int64_t N;
	std::cin >> N;
	std::vector<char> V(N);
	int64_t s = 0;
	for (int64_t n = 0; n < N; ++n)
	{
		char c;
		std::cin >> c;
		if (c == '1') {
			++s;
			V[n] = 1;
		}
		else {
			V[n] = 0;
		}
	}

	std::reverse(V.begin(), V.end());

	std::vector<int64_t> V2_1(N);
	int64_t s1 = 0;
	if (s != N)
	{
		int64_t c = 1;
		V2_1[0] = c;
		for (int64_t n = 1; n < N; ++n)
		{
			c = (c * 2) % (s + 1);
			V2_1[n] = c;
		}

		for (int64_t n = 0; n < N; ++n)
		{
			if (V[n] == 1) {
				s1 += V2_1[n];
			}
		}
	}

	std::vector<int64_t> V2_2(N);
	int64_t s2 = 0;
	if (s != 1 && s != 0)
	{
		{
			int64_t c = 1;
			V2_2[0] = c;
			for (int64_t n = 1; n < N; ++n)
			{
				c = (c * 2) % (s - 1);
				V2_2[n] = c;
			}

			for (int64_t n = 0; n < N; ++n)
			{
				if (V[n] == 1) {
					s2 += V2_2[n];
				}
			}
		}
	}

	for (int64_t n = N-1; n >= 0; --n)
	{
		if (V[n] == 0) {
			std::cout << solve((s1 + s + 1 + V2_1[n]) % (s + 1) ) << std::endl;
		}
		else {
			std::cout << ((s == 1) ? 0 : (solve(((s2 + s - 1 - V2_2[n]) % (s - 1))))) << std::endl;
		}
	}

	return 0;
}


Measured memory_bytes: 6668
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<bitset>

using namespace std;

/************************************************/

int main(void) {
	double n;
	cin >> n;
	int i;
	for (i = 0; i <= sqrt(n); i++) {
	}
	cout << (i - 1)*(i - 1);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<utility>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
//#define t ll t;cin>>t;while(t--)
#define nn cout<<endl;
#define ff(a,n) for(ll i=a;i<n;i++)
#define fr(x, a) for(auto &x:a)
#define cY cout<<"YES\n"
#define cN cout<<"NO\n"
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
#define sc second
#define fs first
#define c(a) cout<<a<<endl

void solve()
{
	ll a,b,c,d; cin>>a>>b>>c>>d;
	cout<<max(b*d,max(a*d,max(a*c,b*c)));
}

int main()
{
	solve();
}
/*
-1000000000 0 -1000000000 0



*/


Measured memory_bytes: 3624
x=input().split()
count=0
m=int(x[0])
n=list(x[1])
if len(n)==1:
    count=0
else:
    for d in range(2):
        n[d]=int(n[d])
    for i in range(4,m+1):
        for j in range(2,n[0]+1):
                for k in range(2,10):
                    if i==j*k:
                        count+=1
                        if j==n[0] and k>n[1]:
                            count-=1
print(count)

Measured memory_bytes: 3064
#include <stdio.h>

int N(int n){
  return n*(n+1)*(n+2)/6;
}

main(){
  int i,j,n,fx[1000000],d=1,min,fy[1000000],nn=1;

  while(1){
    scanf("%d",&n);
    if(n==0) break;
    
    
    fx[0] = 0;
    fy[0] = 0;
    for(i=nn;i<=n;i++){
      if(i == N(d+1)) d++;
      
      min = -1;
      for(j=1;j<=d;j++){
	if(min == -1 || fx[i-N(j)]+1 < min) min = fx[i-N(j)]+1;
      }
      fx[i] = min;
      
      min = -1;
      for(j=1;j<=d;j++){
	if(N(j)%2 == 0) continue;
	else if(min == -1 || fy[i-N(j)]+1 < min) min = fy[i-N(j)]+1;
      }
      fy[i] = min;
    }
    
    
    if(nn < n) nn = n;
    
    printf("%d %d\n",fx[n],fy[n]);
    
  }
  return 0;
}

Measured memory_bytes: 7972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  float t, x;
  cin >> t >> x;
  cout << t/x << endl;
}


Measured memory_bytes: 764
#include <stdio.h>
#include <queue>

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

constexpr int inf = 2e9;
constexpr int MAX_SIZE = 1000;
constexpr int V_MAX_SIZE = MAX_SIZE * (MAX_SIZE - 1) / 2;
int Allocation[MAX_SIZE][MAX_SIZE];
int In[V_MAX_SIZE];
int Priority[V_MAX_SIZE];
std::queue<int> Q[V_MAX_SIZE];

int main(void){

    int n; scanf("%d", &n); int v_number = 0;
    REP(x, n){
        Allocation[x][x] = -1;
        FOR(y, x+1, n){
            Allocation[x][y] = v_number;
            Allocation[y][x] = v_number;
            v_number++;
        }
    }
    REP(x, v_number) {In[x] = 0; Priority[x] = -1;}

    REP(x, n){
        int pv; scanf("%d", &pv); pv = Allocation[x][pv-1];
        FOR(y, 2, n){
            int v; scanf("%d", &v); v--;
            v = Allocation[x][v];
            Q[v].push(pv); In[pv]++;
            pv = v;
        }
    }
    std::queue<int> theQ;
    REP(x, v_number) if(In[x] == 0) {theQ.push(x); Priority[x] = 0;}
    while(not theQ.empty()){
        int v = theQ.front(); theQ.pop();
        while(not Q[v].empty()){
            int nv = Q[v].front(); Q[v].pop();
            if(Priority[nv] == -1 and (--In[nv]) == 0){
                Priority[nv] = Priority[v] + 1;
                theQ.push(nv);
            }
        }
    }
    int mx = -1;
    REP(x, v_number){
        if(Priority[x] == -1){
            puts("-1");
            return 0;
        }
        if(mx < Priority[x]) mx = Priority[x];
    }
    printf("%d\n", mx + 1);
    return 0;
}


Measured memory_bytes: 343680
#include<stdio.h>
int wmx(int a,int b)
{
    if(a>b)
        return b;
    else return a;
}
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int x=wmx(a+b,b+c);
    int xx=wmx(x,a+c);
    printf("%d\n",xx);
    return 0;
}


Measured memory_bytes: 128