akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;

int c[200020], cum[200020];
void solve() {
	int N; cin >> N;
	REP(i, N-1) {
		int u, v; cin >> u >> v;
		u--, v--;
		if (u > v)swap(u, v);
		c[u] += N - v;
	}
	REP(i, N) {
		cum[i + 1] = cum[i] + c[i];
	}
	ll ans = 0;
	REP(i, N) {
		ans += (N - i)*(N - i + 1) / 2;
		ans -= (cum[N] - cum[i]);
	}
	print(ans);
}



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;
	//cin >> q;
	//while (q--)
	solve();
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#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 SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char *argv[])
{
	string s,t;
	cin >> s >> t;
	SORT(s);
	sort(RALL(t));
	if (s < t) {cout << "Yes" << endl;}
	else {cout << "No" << endl;}
	return 0;
}


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

using namespace std;

using ll = long long;

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

    ll a, b, k;

    cin >> a >> b >> k;
    set<ll> item;
    for (int x = a; x < a + k; ++x)
        if (x <= b) item.insert(x);
    for (int x = b - k + 1; x <= b; ++x)
        if (a <= x) item.insert(x);

    for (auto x : item)
        cout << x << '\n';

    return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<int> t(N+1), x(N+1), y(N+1);
	t[0] = x[0] = y[0] = 0;

	for (int i = 1; i <= N; i++) cin >> t[i] >> x[i] >> y[i];

	bool flag = true;
	for (int i = 1; i <= N; i++) {
		if ((t[i] - t[i-1]) < (abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]))) {
			flag = false;
			break;
		}
		if ((t[i] - t[i - 1]) % 2 == 0) {
			if ((abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1])) % 2 != 0) {
				flag = false;
				break;
			}
		}
		else {
			if ((abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1])) % 2 == 0) {
				flag = false;
				break;
			}
		}
	}
	cout << ((flag) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int mod=1e9+7;
int n;
vector<int>a,b;

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x,y;
        scanf("%d%d",&x,&y);

        a.push_back(x+y);
        b.push_back(x-y);
    }

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    printf("%d\n",max(a[n-1]-a[0],b[n-1]-b[0]));

    return 0;
}


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

int main() {
  int x;
  cin >> x;
  vector<bool> ok(x+1);
  ok[1] = true;
  for(int b = 2; b <= 32; b++) {
    int v = b*b;
    while(v <= x) {
      ok[v] = true;
      v *= b;
    }
  }
  for(int i = x; i >= 1; i--) {
    if(ok[i]) {
      cout << i << endl;
      return 0;
    }
  }
}

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

int main(){
  int i,j,cnt=0;
  int n,l;
  cin>>n>>l;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  bool flg=1;
  for(i=0;i<n-1;i++){
    if(a[i]+a[i+1]>=l){
      flg=0;
      cnt=i+1;
      break;
    }
  }
  if(flg){
    cout<<"Impossible"<<endl;
    return 0;
  }
  cout<<"Possible"<<endl;
  for(i=1;i<cnt;i++){
    cout<<i<<endl;
  }
  for(i=n-1;i>cnt;i--){
    cout<<i<<endl;
  }
  cout<<cnt<<endl;
}

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

using namespace std;

int n , m ;
set < int > fst , lst;

int main( int argc , char * argv[] ){
	scanf( "%d%d" , & n , & m );
	for(int i = 1 ; i <= m ; ++ i){
		int u , v;
		scanf( "%d%d" , & u , & v );
		if( u == 1 )
			fst.insert( v );
		if( v == n )
			lst.insert( u );
	}
	int ok = 0;
	for(auto && it : fst)
		if( lst.count( it ))
			ok = 1;
	if( ok )
		puts( "POSSIBLE" );
	else
		puts( "IMPOSSIBLE" );
	return 0;
}

Measured memory_bytes: 9728
#include <stdio.h>
long long n, a, b;
int main() {
	scanf("%lld", &n);
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			a = i;
			b = n / i;
		}
	}
	a = 0;
	while (b) {
		b /= 10;
		a++;
	}
	printf("%lld\n", a);
}

Measured memory_bytes: 1736
{-# LANGUAGE BangPatterns #-}
import Control.Applicative((<$>))
import Control.Monad
import Data.Map ((!))
import qualified Data.Map as M
import qualified Data.List as L
import Data.Maybe (catMaybes)
-- import qualified Data.Char as C
-- import qualified Data.IntSet as I
import Debug.Trace
--------------------------------------------
readInt    = read :: String -> Int
getInt     = readInt <$> getLine
getIntList = map readInt . words <$> getLine
int2bin 0 =  []
int2bin n =  n `mod` 2 : int2bin (n `div` 2)
----------------------------------------------
 
main :: IO ()
main = do
  s <- getLine
  putStrLn $ map fst $ filter (\(_,b) -> odd b) $ zip s [1..]

Measured memory_bytes: 6396
# your code goes here
#allocation
def ca(n,k,w,b):
    cn=0
    m=0
    l=0
    #print(k)
    while l <n and cn<=k:
        d=0
        #print(l)
        while d<b and l<n:
          #  print(l)
            d+=w[l]
            l+=1
          #  print(l)
        if d>b:
    #        d-=w[l]
            l-=1
        cn+=1
 #       print(l)
#        print(n)
#        print(cn)
    #    print(k)
    if cn>k:
        return 1
    else:
        return -1
  #  print(d)
def bs(n,k,w,Mx,U):
    while Mx+1<U:
        t=U-Mx
        t//=2
        t+=Mx
 #       print(t)
        if ca(n,k,w,t)==-1:
            U=t
        else:
            Mx=t
  #      print(Mx)
    if ca(n,k,w,Mx)==-1:
        return Mx
    else:
        return U
n,k=(int(i) for i in input().split())
w=[int(input())]
#print(w)
Mx=w[0]
for i in range(1,n):
    w.append(int(input()))
    if w[i]>Mx:
        Mx=w[i]
a=n//k
if n%k!=0:
    a+=1
U=a*Mx
#print(w)
Mx=bs(n,k,w,Mx,U)
print(Mx)

Measured memory_bytes: 11400
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
pay=[]
pay.append(min(a)+min(b))
for i in range(M):
  X,Y,C=map(int,input().split())
  pay.append(a[X-1]+b[Y-1]-C)
print(min(pay))

Measured memory_bytes: 18648
N,K=map(int,input().split())
A=list(map(int,input().split()))
dp=[0]*41
bp=[0]*41
for i in range(N):
  o=len(bin(A[i]))
  for j in range(o-2):
    if (A[i]>>j)&1==1:
      dp[j]+=1
ans=0
count=0
for i in range(len(dp)-1,-1,-1):
  bp[i]=N-dp[i]
  if dp[i]<bp[i] and count+pow(2,i)<=K:
    count+=pow(2,i)
ans=0
for i in range(N):
  ans+=(count^A[i])
print(ans)

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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a), greater<int>());
    auto comPair = [](const P &firstElof, const P &secondElof) {
        int m1 = min(firstElof.first, firstElof.second);
        int m2 = min(secondElof.first, secondElof.second);
        return m1 < m2;
    };
    priority_queue<P, vector<P>, decltype(comPair)> que(comPair);

    ll ans = a[0];
    que.emplace(a[0], a[1]);
    que.emplace(a[0], a[1]);
    repeat(i, 2, n) {
        auto p = que.top();
        que.pop();

        ans += min(p.first, p.second);

        que.emplace(p.first, a[i]);
        que.emplace(p.second, a[i]);
    }
    out(ans);
    return 0;
}

Measured memory_bytes: 6104
class Dice:
        num =[ -1 for x in range(6) ]
        def roll(self, d):
                if   d == "N":
                        b = self.num[0]
                        self.num[0] = self.num[1]
                        self.num[1] = self.num[5]
                        self.num[5] = self.num[4]
                        self.num[4] = b
                elif d == "S":
                        b = self.num[0]
                        self.num[0] = self.num[4]
                        self.num[4] = self.num[5]
                        self.num[5] = self.num[1]
                        self.num[1] = b
                elif d == "W":
                        b = self.num[3]
                        self.num[3] = self.num[0]
                        self.num[0] = self.num[2]
                        self.num[2] = self.num[5]
                        self.num[5] = b
                elif d == "E":
                        b = self.num[3]
                        self.num[3] = self.num[5]
                        self.num[5] = self.num[2]
                        self.num[2] = self.num[0]
                        self.num[0] = b
        
        def __init__(self, lst):
                self.num = lst
        
        def print_num(self, m):
                print(self.num[m])

lst = list(map(int, input().split()))
buff = input()

dice = Dice(lst)

for c in buff:
        dice.roll(c)

dice.print_num(0)



Measured memory_bytes: 5616
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
const int maxn = 1<<18;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	ll pa = 0, pb = 0, a = 0, b = 0, n, t = 1;
	cin >> n;
	while(n--) {
		cin >> a >> b;
		t = max({(pa+a-1)/a, (pb+b-1)/b, 1ll});
		tie(pa, pb) = tuple<ll, ll>{t*a, t*b};
	}
	cout << pa+pb;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream> 
#include<vector>
using namespace std;
int main(){
	
	int n,a,v;
	vector<int> v1;
	scanf("%d",&n);
	int i = 0;
	while(i < n)
	{
		scanf("%d",&a);
		if(a == 0){
			scanf("%d",&v);
			v1.push_back(v);
		}
		else if(a == 1)
		{
			scanf("%d",&v);
			printf("%d\n",v1[v]);
		}
		else{
			v1.pop_back();
		}
		i++;
	}
	return 0; 
}


Measured memory_bytes: 3872
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var ar = Array.ConvertAll(ReadLine().Split(' '), double.Parse);
        var ave = (double)ar.Sum() / num;
        var min = 10000d;
        var mini = -1;
        for(var i = 0; i < num; i++)
        {
            if (min > Abs(ave - ar[i])){
                min = Abs(ave-ar[i]);
                mini = i;
            }
        }
        WriteLine(mini);
    }

    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


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

int main() {
	// your code goes here
	int c=0,n,x;
	while(cin >> n >> x){
		if(n==0&&x==0) break;
		for(int i=1;i<=n-2;i++){
			int a1=i;
			for(int j=i+1;j<=n-1;j++){
				int a2=j;
				for(int k=j+1;k<=n;k++){
					int a3=k;
					if(a1+a2+a3==x){
						c++;
					}  
				}
			}
		}
		cout<< c <<endl;
		c=0;
	}
	

	return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1000000007;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecb vector<bool>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, size_t second_itr) {
	std::string tmp;
	for (size_t i = first_itr; i < second_itr + 1; i++) {
		tmp.push_back(str.at(i));
	}
	return tmp;
}


int main() {
	int a, b, c; cin >> a >> b >> c;
	cout << c << " " << a << " " << b << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,y,n;
  cin >> x >> y;
  if(2*x>y){
    cout << "No" << endl;
    return 0;
  }
  if(y%2==1){
    cout << "No" << endl;
    return 0;
  }
  n=x*4;
  if(n<y){
    cout << "No" << endl;
    return 0;
  }
  else{
    cout << "Yes" << endl;
    return 0;
  } 
}

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

#define rep(i, n) for(int i=0; i < (n); ++i)
#define ll long long

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; }}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; }}

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

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k; cin >> n >> k;
    int ans = 0;
    rep(i,n) {
        int h; cin >> h;
        if (h >= k) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std; 

int main(){ 
  int n,m,x;
  cin>>n>>m>>x;
  int c[13][13]={0};
  for(int i=0;i<n+1;++i){
    for(int j=0;j<m+1;++j){
      cin>>c[i][j];
    }
  }
  int64_t ans=100000000000;
  
  for(int a=0;a<2;a++){
    for(int b=0;b<2;b++){
      for(int c1=0 ;c1 <2;c1 ++){
        for(int d=0 ;d <2;d ++){
          for(int e=0 ;e <2;e ++){
            for(int f=0 ;f <2;f ++){
              for(int g=0 ;g <2;g ++){
                for(int h=0 ;h <2;h ++){
                  for(int i1=0 ;i1 <2;i1 ++){
                    for(int j=0 ;j <2;j ++){
                      for(int k=0 ;k <2;k ++){
                        for(int l=0 ;l <2;l ++){
                          for(int i=1;i<=m;i++){
                          if(c[0][i]*a +c[1][i]*b +c[2][i]*c1 +c[3][i]*d +c[4][i]*e +c[5][i]*f +c[6][i]*g +c[7][i]*h+c[8][i]*i1 +c[9][i]*j+c[10][i]*k +c[11][i]*l<x ){
                        break;
                          }
                            if(i==m){
                              if(ans>c[0][0]*a +c[1][0]*b +c[2][0]*c1 +c[3][0]*d +c[4][0]*e +c[5][0]*f +c[6][0]*g +c[7][0]*h+c[8][0]*i1 +c[9][0]*j+c[10][0]*k +c[11][0]*l){
                          ans=c[0][0]*a +c[1][0]*b +c[2][0]*c1 +c[3][0]*d +c[4][0]*e +c[5][0]*f +c[6][0]*g +c[7][0]*h+c[8][0]*i1 +c[9][0]*j+c[10][0]*k +c[11][0]*l;

                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  }
    }
  }

  if(ans==100000000000){
    cout<<-1;
  }
  else cout<<ans;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()
#define INF 2000000000

int a, b, c, k;

int solve(int x, int A, int B, int C) {
    if (x == k) return A+B+C;
    return max(max(solve(x+1, A*2, B, C), solve(x+1, A, B*2, C)), solve(x+1, A, B, C*2));
}

int main() {
    scanf("%d %d %d %d", &a, &b, &c, &k);
    printf("%d\n", solve(0, a, b, c));
}

Measured memory_bytes: 256
#include<iostream>
#include<tuple>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int N; cin >> N;
  vector<tuple<string,int,int>> a;
  for(int i = 0; i < N; i++){
    string s; int p;
    cin >> s >> p;
    p = -p; int j = i + 1;
    a.push_back(tie(s,p,j));}
    
    sort(a.begin(),a.end()); //文字列について辞書式に、被った時は満足度についてソート
    
    for(int i = 0; i < N ; i++){
      cout << get<2>(a[i]) << endl;}
    
    return 0;
  }


Measured memory_bytes: 256
/*for better*/
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
#define fr(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
#define M 998244353
using namespace std;

int main()
{
    fast; 
    ll n,h[100005],dp[100005],i,k,j;
    cin>>n>>k;
    f(i,0,n)
    	cin>>h[i];
    dp[0]=0;
    f(i,1,n)
    {
    	dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
    	for(j=2;j<k+1 && i-j>=0;j++)
    		dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]),dp[i]);
    }
    cout<<dp[n-1];
}


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

using namespace std;

int main(void)
{
	int n, scoreOfTaro = 0, scoreOfHanako = 0;
	string cardOfTaro, CardofHanako;
	int i;

	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> cardOfTaro >> CardofHanako;
		if (cardOfTaro > CardofHanako)
		{
			scoreOfTaro += 3;
			continue;
		}
		if (cardOfTaro < CardofHanako)
		{
			scoreOfHanako += 3;
			continue;
		}
		scoreOfTaro += 1;
		scoreOfHanako += 1;
	}

	cout << scoreOfTaro << " " << scoreOfHanako << endl;

	return 0;

}


Measured memory_bytes: 3240
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define fi first
#define se second
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define v(T) vector<T>
#define p(T, N) pair<T, N>
#define tp(A, B, C) tuple<A, B, C>
#define ii p(int, int)
#define vi v(int)
#define vii v(p(int, int))
#define vvi v(v(int))
#define vl v(long long)
#define vll v(p(long long, long long))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define qsortsi(v) sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b){return a.se < b.se;})
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define pt(a, b, c) emplace_back(make_tuple(a, b, c))
#define elif else if
#define fori(i, n) for(ll i = 0; i < n; ++i)
#define foris(i, a, b) for(ll i = a; i < b; ++i)
#define forise(i, a, b) for(ll i = a; i <= b; ++i)
#define ford(i, n) for(ll i = n; i >= 0; --i)
#define fords(i, a, b) for(ll i = a; i >= b; --i)
#define fordse(i, a, b) for(ll i = a; i > b; --i)
#define fora(i, a) for (auto &i: a)
#define rev(a) reverse(a.begin(), a.end())
#define revf(a, b, c) (reverse(a.begin() + b, a.begin() + c))
#define digits(i) (int)((log(i)/(log(10))+1)
#define umap unordered_map
#define uset unordered_set
#define pq(T) priority_queue<T>
#define rpq(T) priority_queue<T, vector<T>, greater<T> >
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
const int mod = 1000000007;



int main() {
  io();
  
  ull a, b, k;
  cin >> a >> b >> k;
  
  if(k <= a) {
  	a -= k;
    k = 0;
  }
  else {
  	k -= a;
    a = 0;
  }
  
  if(k <= b) {
    b -= k;
  }
  else {
  	b = 0;
  }
  cout << a << " " << b;
  
  return 0;
}

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

using namespace std;

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

    long long A[n];
    for(int i=0; i<n; i++) cin >> A[i];


    for(int i=0; i<n; i++) {
        if(A[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    long long b = A[0];
    for(int i=1; i<n; i++) {
        long long pre = b;
        b *= A[i];
        if(b > 1000000000000000000 || b < pre) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << b << endl;

    return 0;
}


Measured memory_bytes: 4416
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    string N; cin>> N;
    int sum = 0;
    rep(i, N.size()){
        sum += N[i] - '0';
    }

    int N2 = (N[0] - '0') + 9 * (N.size() - 1);
    if(sum < N2) N2--;
    cout<< N2 << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1001001001;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll memo[100000];
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/

int main(){
    ll N;
    cin >> N;
    map<ll,ll> num;
    ll n;
    rep(i,N){
        cin >> n;
        num[n]++;
    }
    ll ans = 0;
    for(auto x : num)ans++;
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
	string s1,s2;
	cin >> s1 >> s2;
	cout << (s1[0] == s2[s2.length() - 1] && s2[0] == s1[s1.length() - 1] && s1[1] == s2[1] ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
nu = gets.to_i - 1
inst = nu
ar = []
count = 0
for i in 0..19
  if nu == 1
    ar.push(1)
    count += 1
    break
  elsif nu % 2 == 0
    ar.push(0)
    nu /= 2
  else
    ar.push(1)
    count += 1
    nu /= 2
  end
end
leng = ar.length
if count == leng
  puts "#{count + 1} #{count*2}"
  for i in 1..count
    puts "#{i} #{i + 1} 0"
  end
  for i in 1..count
    puts "#{i} #{i + 1} #{2**(count - i)}"
  end
  exit
end

check = 0
check2 = 0
for i in 0..leng - 2
  if (ar[0] == 0 && i == 0) || (ar[0] == 1 && ar[1] == 0 && i == 0)
    check += 1
  elsif i != 0 && ar[i] == 1
    check += 1
  end
  if ar[i] == 1 && check2 == i
    check2 += 1
  end
end
check3 = 0
if check2 >= 2
  check3 = check2 - 2
else
  check3 = 0
end

count2 = 0
puts "#{leng} #{(leng - 1)*2 + check - check3}"
for i in 1..leng - 1
  puts "#{i} #{i + 1} #{2**(leng - 1 - i)}"
end
for i in 1..leng - 1
  puts "#{i} #{i + 1} 0"
end
for i in 2..leng
  if check2 >= 2 && check2 == leng + 1 - i
    for j in 1..i - 1
      if ar[-j] == 1
        count2 += 2**(leng - j)
      end
    end
    puts "1 #{i - 1} #{count2}"
    break
  elsif (ar[-i] == 1) && (i != leng)
    for j in 1..i - 1
      if ar[-j] == 1
        count2 += 2**(leng - j)
      end
    end
    puts "1 #{i} #{count2}"
  elsif (i == leng && ar[0] == 1 && ar[1] == 0)
    for j in 1..i - 1
      if ar[-j] == 1
        count2 += 2**(leng - j)
      end
    end
    puts "1 #{leng - 1} #{inst - 1}"
  elsif (i == leng && ar[0] == 0)
    puts "1 #{leng} #{inst}"
  end
  count2 = 0
end


Measured memory_bytes: 1916
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll>> PP;

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second

struct edge { ll to, cost, com; };
map<P, vector<edge>>mp;
map<P, ll>mpp;
int n, m, p, q, r;

void dijkstra() {
	mpp[P(1, 0)] = 0;
	std::priority_queue<PP, std::vector<PP>, std::greater<PP>>pq;
	pq.push(PP(mpp[P(1, 0)], P(1, 0)));
	while (!pq.empty()) {
		PP a = pq.top();
		pq.pop();
		ll cost = a.fr, now = a.sc.fr, com = a.sc.sc;
		if (mpp[P(now, com)] < cost)continue;
		for (int k = 0;k < mp[P(now,com)].size();k++) {
			edge e = mp[P(now,com)][k];
			if (mpp[P(e.to,e.com)] <= cost + e.cost)continue;
			mpp[P(e.to,e.com)] = cost + e.cost;
			pq.push(PP(mpp[P(e.to, e.com)], P(e.to, e.com)));
		}
	}
	return;
}

int main() {
	cin >> n >> m;
	for (int i = 0;i < m;i++) {
		cin >> p >> q >> r;
		mp[P(p, r)].pb(edge{ q,0,r });
		mp[P(q, r)].pb(edge{ p,0,r });
		mp[P(p, 0)].pb(edge{ p,1,r });
		mp[P(p, r)].pb(edge{ p,0,0 });
		mp[P(q, 0)].pb(edge{ q,1,r });
		mp[P(q, r)].pb(edge{ q,0,0 });

		mpp[P(p, r)] = INF2;
		mpp[P(q,r)] = INF2;
		mpp[P(p, 0)] = INF2;
		mpp[P(q, 0)] = INF2;
	}
	dijkstra();
	if (mpp[P(n, 0)] == INF2 || mpp[P(n, 0)] == 0)cout << -1 << endl;
	else cout << mpp[P(n, 0)] << endl;
	return 0;
}

Measured memory_bytes: 115120
N = int(input())
Si = [input() for _ in range(N)]
old = Si[0][-1]

if len(Si) != len(set(Si)):
    print('No')
    quit()

for i in range(1, N):
    if Si[i][0] != old:
        print('No')
        quit()
    old = Si[i][-1]

print('Yes')

Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s,k;
    cin>>s>>k;
    int n,m;
    n=s.size();
    m=k.size();
    if(n-m==0)
    {
         for(int i=0;i<m;i++)
            cout<<s[i]<<k[i];
        cout<<endl;
    }
    else
    {
        for(int i=0;i<m;i++)
            cout<<s[i]<<k[i];
        cout<<s[m]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef long long ll;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define swap(a,b) {ll tp=a;a=b;b=tp;}
const ll MOD = 1000000007;

int my_lower_bound(int *p, int trg, int n){
    if(p[0] >= trg) return 0;
    int left = 0, right = n-1;
    while(right - left > 1){
        int mid = (right + left)/2;
        if(p[mid] < trg) left = mid;
        else right = mid;
    }
    return right;
}

int my_upper_bound(int *p, int trg, int n){
    if(p[n-1] <= trg) return n;
    int left = 0, right = n-1;
    while(right - left > 1){
        int mid = (right + left)/2;
        if(p[mid] > trg) right = mid;
        else left = mid;
    }
    return right;
}

int main(){
    int S[100007], T[50007];
    int n; scanf("%d", &n);
    rep(i,n) scanf("%d", S+i);
    int q; scanf("%d", &q);
    rep(i,q) scanf("%d", T+i);

    int ans = 0;
    rep(i,q){
        if(my_upper_bound(S, T[i], n) - my_lower_bound(S, T[i], n)) ans++;
    }
    
    printf("%d\n", ans);
    return 0;
}


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

int main(void) {
    int n;
    scanf("%d", &n);
    long long int a[n];
    long long int former = 0; // 切れ目よりも前の部分の長さ
    long long int latter = 0; // 切れ目よりも後の部分の長さ
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        latter += a[i];
    }

    int sum = 0;

    int i = 0;
    long long int min = latter;   // formerとlatterの差の最小値
    int mem;
    while (former != latter && i < n) {
        former += a[i];
        latter -= a[i];
        if (min > llabs(former - latter)) {
            min = llabs(former - latter);
        }
        i++;
    }

    printf("%lld\n", min);

    return 0;
}


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

struct UnionFind
{
    vector<int> par; //par[i] は iの親

    UnionFind(int N) : par(N){ //par[i] = i として初期化
        for(int i = 0; i < N; i++) par.at(i) = i;
    }
    //根を見つける
    int root(int x){
        if(par.at(x) == x) return x;
        return par.at(x) = root(par.at(x));
    }
    //根をくっつける
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par.at(rx) = ry;
    }
    //木が同じか判定
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int N, M; cin >> N >> M;
    vector<int> P(N);
    for(int i = 0; i < N; i++){
        cin >> P.at(i);
    }
    UnionFind tree(N);
    for(int i = 0; i < M; i++){
        int x, y; cin >> x >> y;
        x--; y--;
        tree.unite(x, y);
    }
    //iとP[i]が同じ木に属するならスワップしてi = P[i] - 1とできる
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(tree.same(i, P.at(i) - 1)) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{

    ll n;
    cin>>n;
     ll a[n]={0};
    ll dp[n]={0};
    ll k;
    cin>>k;

    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    dp[0]=0;
    for(int i=1;i<k && i<n;i++){
            ll mini=1e18;
            for(int j=0;j<i;j++){
                mini=min(mini,dp[j]+abs(a[j]-a[i]));
            }
            dp[i]=mini;



    }
    for(int i=k;i<n;i++){
        ll mini=1e18;
        for(int j=i-k;j<i;j++){
            mini=min(mini,dp[j]+abs(a[j]-a[i]));
        }
        dp[i]=mini;
    }

    cout<<dp[n-1];
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
int main () {
    int cnt=0;
    string N, M;
    cin >> N >> M;
    N+=N;
    for (int i=0;i<M.size();i++){
        string x;
        for (int j=0;j<M.size();j++)
            x+=N[i+j];
        if (x==M)
            cnt++;
    }
    cnt ? cout << "Yes" : cout << "No";
    return 0;
}

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

using static Input;
using static Util;
class Program
{
    static string S;
    static void INPUT()
    {
        S = NextString();
    }

    static void OUT()
    {
        var a = S.Any(__ => __ == 'A');
        var b = S.Any(__ => __ == 'B');
        Console.WriteLine(a && b ? "Yes" : "No");
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

struct edge{
    int to, num;
    edge(int to, int num): to(to), num(num){}

};

vector<vector<edge>> g;
vector<int> color;



signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N; cin >> N;
    g.resize(N);
    color.resize(N);
    VI deg(N);
    REP(i,N-1){
        int a,b; cin >> a >> b;
        a--; b--;
        deg[a]++;
        deg[b]++;

        g[a].eb(b,i);
        g[b].eb(a,i);
    }
    int dmax = -1;
    int st = -1;
    REP(i,N){
        if(deg[i] > dmax){
            dmax = deg[i];
            st = i;
        }
    }
    cout << dmax << endl;

    queue<tuple<int,int,int>> q;
    q.push(make_tuple(st,-1,-1));
    while(!q.empty()){
        auto t = q.front(); q.pop();
        int t1,t2,t3;
        tie(t1,t2,t3) = t;

        //cout << t1 << " " << t2 << " " << t3 << endl;

        int cur = 1;
        REP(i,deg[t1]){
            int num = g[t1][i].num;
            int to = g[t1][i].to;
            if(to == t3) continue;
            if(cur != t2){
                color[num] = cur;
                q.push(make_tuple(to,cur,t1));
                cur++;
            }else{
                cur++;
                color[num] = cur;
                q.push(make_tuple(to,cur,t1));
                cur++;
            }
        }
    }
    REP(i,N-1){
        cout << color[i] << endl;
    }



}



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

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean[][] judg = new boolean[n+1][n+1];

        for(int i=0;i<n+1;i++){
            Arrays.fill(judg[i],false);
        }

        for(int i=0;i<n;i++){
            int u = sc.nextInt();
            int k = sc.nextInt();
            for(int j=0;j<k;j++){
                int v = sc.nextInt();
                judg[u][v] = true;
            }
        }

        int[] d = new int[n+1];
        int[] f = new int[n+1];
        int count = 0;

        for(int i=1;i<=n;i++){
            count = func(judg,d,f,i,count);
        }

        for(int i=1;i<=n;i++){
            System.out.println(i+" "+d[i]+" "+f[i]);
        }
    }

    static int func(boolean[][] judge,int[] d,int[] f,int now,int count){
        if(d[now]!=0){
            return count;
        }
        d[now] = ++count;
        for(int i=1;i<judge.length;i++){
            if(judge[now][i]){
                count = func(judge,d,f,i,count);
            }
        }
        f[now] = ++count;
        return count;
    }
}

Measured memory_bytes: 20656
#include <stdio.h>

int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    if (a==b&&a==c){
        printf("No\n");
        return 0;
    }
    else if (a!=b&&a!=c&&b!=c){
        printf("No\n");
        return 0;
    }
    else{
        printf("Yes\n");
        return 0;
    }

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
    using namespace std;
     
    #define MP make_pair
    #define PB push_back
    #define ALL(x)      (x).begin(),(x).end()
    #define REP(i,n)    for(int i=0;i<(n);i++)
    #define REP1(i,n)   for(int i=1;i<(n);i++)
    #define REP2(i,d,n) for(int i=(d);i<(n);i++)
    #define RREP(i,n)   for(int i=(n);i>=0;i--)
    #define CLR(a)      memset((a),0,sizeof(a))
    #define MCLR(a)     memset((a),-1,sizeof(a))
    #define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
     
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef vector<int> VI;
    typedef vector<VI > VVI;
    typedef vector<string> VS;
    typedef vector<LL> VLL;
    typedef pair<int,int> PII;
     
    const int INF = 0x3f3f3f3f;
    const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
    const double EPS = 1e-9;
     
    const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
     
    int main() {
        int A,B;
        cin >> A >> B;
        LL ans = B;
        REP1(i, A) {
            ans *= (B-1);
        }
        cout << ans << endl;
    }

Measured memory_bytes: 256
Alice=0
Bob=0
N=int(input())
list=input().split()
list= [int(a) for a in list]

for i in range(N):
  max=0
  tmp=0
  for j in list:
    if max<j:
      max=j
      key=tmp
    tmp+=1
  if i%2==0:#Aliceの番
    Alice+=max
  else:
    Bob+=max
  del list[key]
print(Alice-Bob)

Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> vs(n);
    for (int i = 0; i < n; i++)
    {
        auto& v = vs[i];
        cin >> v.first;
        v.second = i + 1;
    }
    sort(vs.begin(), vs.end());
    for (int i = 0; i < n; i++)
    {
        if (i > 0)
            cout << " ";
        cout << vs[i].second;
    }
    cout << endl;
}


Measured memory_bytes: 1664
n = int(input())
a = list(map(int,input().split()))
cnt = [0]*((10**6) + 1)

#重複対策
for elem in a:
    cnt[elem] += 1

#個数が1個のリスト
unique = []

for i in range((10**6) + 1):
    #iが複数ないならばリストに追加
    if cnt[i] == 1:
        unique.append(i)

#cntを初期化
cnt = [0] * ((10**6) + 1)

#本当のユニーク
a = list(set(a))

for elem in a:
    for m in range(elem * 2,(10**6)+1,elem):
        cnt[m] = 1

ans = 0
#それぞれの数の個数が1個しかないリストを回す(重複対策してるため)
for elem in unique:
    if cnt[elem] == 0:
        ans += 1
print(ans)

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    string s, t;
    cin >> s >> t;

    vvi dp(s.size()+1, vi(t.size()+1, 0));

    rep(i, s.size()) {
        rep(j, t.size()) {
            if (s[i] == t[j]) 
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1);
            dp[i+1][j+1] = max({dp[i+1][j+1],
                    dp[i][j+1], dp[i+1][j]});
        }
    }
    /*
    rep(i, dp.size()) {
        rep(j, dp[i].size()) {
            std::cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
    //cout << endl;

    int p1 = s.size(), p2 = t.size();
    string ans;
    while (p1 != 0 && p2 != 0) {
        //cout << p1 << " " << p2 << endl;
        if (dp[p1][p2] == dp[p1-1][p2]) p1--;
        else if (dp[p1][p2] == dp[p1][p2-1]) p2--;
        else {
            ans.pb(s[p1-1]);
            p1--; p2--;
        }
    }
    //cout << p1 << " " << p2 << endl;
    reverse(all(ans));

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 70784