akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{int p, l, r;};

struct Node T[MAX];
int n;
int D[MAX],H[MAX];

int getDepth(int u){
  int d=0;
  while(1){
    u=T[u].p;
    if(u==NIL)break;
    d++;
  }
  return d;
}

int getSibling(int u){
  if (T[u].p==NIL)return NIL;
  if (T[T[u].p].l!=u&&T[T[u].p].l!=NIL) return T[T[u].p].l;
  if (T[T[u].p].r!=u&&T[T[u].p].r!=NIL) return T[T[u].p].r;
  return NIL;
}

void print(int u){
  printf("node %d: ", u);

  printf("parent = %d, ", T[u].p);
  printf("sibling = %d, ", getSibling(u));
  int deg=0;
  if (T[u].l != NIL)deg++;
  if (T[u].r != NIL)deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if (T[u].p==NIL){
    printf("root\n");
  } else if (T[u].l==NIL&&T[u].r==NIL){
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}

main(){
  int i, v, l, r;
  scanf("%d", &n);

  for (i=0;i<n;i++){
    T[i].p=NIL;
  }

  for (i=0;i<n;i++){
    scanf("%d %d %d", &v, &l, &r);
    T[v].l=l;
    T[v].r=r;
    if (l!=NIL)T[l].p=v;
    if (r!=NIL)T[r].p=v;
  }

  for(i=0;i<n;i++){
    D[i]=getDepth(i);
    H[i]=0;
  }

  for(i=0;i<n;i++){
    if (T[i].l==NIL&&T[i].r==NIL){ // is leaf
      H[i]=0;
      int p=T[i].p;
      int c=1;
      while(1){
	if (p==NIL)break;
	if (H[p]<c)H[p]=c;
	c++;
	p=T[p].p;
      }
    }
  }

  for(i=0;i<n;i++)print(i);
  return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

bool fn_is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

bool isOK(int index, int key, vector<ll>& a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key, vector<ll>& a) {
    int ng = -1;
    int ok = a.size();

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key, a)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main()
{
    int a, b, c; cin >> a >> b >> c;
    int d = a * 100 + b * 10 + c;
    if (d % 4 == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}


Measured memory_bytes: 3548
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	sort.Ints(a)
	for i := 0; i+1 < n; i++ {
		if a[i+1] == a[i] {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}


Measured memory_bytes: 7296
import itertools
import bisect
N = int(input())
right = 0
left = 0
length = 0
for i in range(34):
    if N in [0,1]:
        break
    if (-2) ** i + left <= N and N <= (-2) ** i + right:
        length = i + 1
        break
    if i % 2 == 0:
        right += (-2) ** i
    else:
        left += (-2) ** i
ans = []
def bi(arr):
    if len(ans) >= length:
        return
    if (length-len(ans)) % 2 == 0:
        if bisect.bisect_right(arr,N) > len(arr)//2:
            ans.append(0)
            bi(arr[len(arr)//2:])
        else:
            ans.append(1)
            bi(arr[:len(arr)//2])
    else:
        if bisect.bisect_right(arr,N) > len(arr)//2:
            ans.append(1)
            bi(arr[len(arr)//2:])
        else:
            ans.append(0)
            bi(arr[:len(arr)//2])

if N == 0:
    print(0)
elif N == 1:
    print(1)
else:
    ans.append(1)
    bi(range((-2) ** (length-1) + left , (-2) ** (length-1) + right +1))
    ans = map(str, ans)
    print("".join(ans))

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  int A[N], B[N], C[N-1];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < N - 1; i++) {
    cin >> C[i];
  }
  int s = 0;
  for (int i = 0; i < N; i++) {
    s += B[i];
  }
  for (int i = 0; i < N - 1;i++) {
    if (A[i] + 1 == A[i+1]) {
      s += C[A[i]-1];
    }
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
I=N=9**9
d=[[],[],[],[]]
for t in[*open(0)][1:]:
  *z,u=t.split()
  d[ord(u)%5]+=[*map(int,z)],
f=lambda x,y:x
g=lambda x,y:y
h=lambda x,y:x+y
i=lambda x,y:x-y
for*A,f,g in(3,0,f,g),(1,2,g,f),(0,2,h,i),(1,3,h,i),(1,0,i,h),(3,2,i,h):
  n=p=-I
  for x,y,r in sorted((f(x,y),g(x,y),Q)for Q,P in enumerate(A)for x,y in d[P]):
    if r:n,p=x,y
    elif x==n:N=min(N,y-p)
print(N%I*5or'SAFE')

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

namespace AtCorder
{
	public class Program
	{
		const long MOD = 1000000007;
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = cin.Int();
			}

			SortedList<int, long> sl = new SortedList<int, long>(n);
			sl.Add(a[n - 1], 1);
			for (int i = n - 2; i >= 0; --i) {
				if (sl.Keys[sl.Keys.Count() - 1] <= a[i]) {
					if (sl.ContainsKey(a[i])){
						sl[a[i]] += 1;
					} else {
						sl.Add(a[i], 1);
					}
				} else {
					int index = BinarySearch(sl, a[i]);
					int key = sl.Keys[index];
					long num = sl[key];
					if (num == 1) {
						sl.Remove(key);
						if (sl.ContainsKey(a[i])) {
							sl[a[i]] += num;
						} else {
							sl.Add(a[i], num);
						}
					} else {
						sl[key] -= 1;
						if (sl.ContainsKey(a[i])) {
							sl[a[i]] += 1;
						} else {
							sl.Add(a[i], 1);
						}
					}
				}
			}

			long ans = sl.Values.Sum();
			Console.WriteLine(ans);
		}

		static int BinarySearch(SortedList<int, long> sl, int ai)
		{
			int left = -1;
			int right = sl.Count();

			while (right - left > 1) {
				int mid = left + (right - left) / 2;

				if (sl.Keys[mid] > ai) {
					right = mid;
				} else {
					left = mid;
				}
			}

			return right;
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;
		
		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 19028
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int[] sum = new int[n];

        for (int i = 0; i < n; i++)
            sum[i] = (i == 0 ? 0 : sum[i - 1]) + scanner.nextInt();
        for (int i = 0; i < n; i++)
            for (int i1 = 0, temp = scanner.nextInt(); i1 <= i; i1++)
                sum[i1] += temp;

        int ans = sum[0];
        for (int i = 1; i < n; i++)
            ans = Math.max(ans, sum[i]);
        System.out.println(ans);
    }
}

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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if ((A <= C) && (C <= B)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

int main() {
  string o,e;
  cin >> o >> e;
  for(int i = 0;i < e.size();i++){
    cout << o[i] << e[i];
  }
  if(o.size() > e.size()) cout << o[o.size()-1];
  cout << ""<< endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
using pl=pair<ll,ll>;

signed main(){
	ll n; cin>>n;
	vector<pl> v(n);
	rep(i,0,n)cin>>v[i].second>>v[i].first;
	sort(all(v));
	ll cnt=0;
	rep(i,0,n){
		cnt+=v[i].second;
		if(cnt>v[i].first){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define mod 1000000007
#define pb push_back

using namespace std;

using ll = long long;
using ld = long double;

const ll inf = LONG_LONG_MAX;

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1){
            res = (res * a)%mod;
        }
        a = (a * a)%mod;
        b >>= 1;
    }
    return (res%mod);
}

signed main(){
	ll t;
	//cin >> t;
	t = 1;
	while(t--){
		ll n,k;
		cin >> n >> k;

		vector<ll>h(n+1);

		for(ll i=1;i<=n;i++){
			cin >> h[i];
		}

		vector<ll>adj[n+1];

		for(ll i=1;i<=k;i++){
			ll a,b;
			cin >> a >> b;

			adj[a].pb(b);
			adj[b].pb(a);
		}

		ll ans = 0;

		for(ll i=1;i<=n;i++){
			ll x = h[i];

			ll cnt = 0;
			//cout << x ;
			for(ll j=0;j<adj[i].size();j++){
				if(x > h[adj[i][j]]){
					cnt++;
				}
				//cout << adj[i][j] << " ";
			}
			//cout << "\n";
			if(cnt == adj[i].size()){
				ans++;
			}
			//cout << ans << "\n";
		}

		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 9792
N, M = map(int, input().split())
dp = [0] * (N+1)
for i in range(M):
    l, r = map(int, input().split())
    dp[l-1] += 1
    dp[r] -= 1

for i in range(N):
    dp[i+1] += dp[i]

ans = 0
for i in range(N):
    if dp[i] == M:
        ans += 1

print(ans)

Measured memory_bytes: 12796
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < (int)(n) ; i++)

long long w[100010];
void solve(long long N, vector<long long> A, vector<long long> B, vector<long long> C){
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	sort(C.begin(),C.end());
	for(int i = 0 ; i < B.size() ; i++){
		w[i] = lower_bound(A.begin(),A.end(),B[i]) - A.begin() + (i>0?w[i-1]:0);
	}
	long long ans = 0;
	for(int i = 0 ; i < C.size() ; i++){
		int idx = lower_bound(B.begin(),B.end(),C[i]) - B.begin();
		if(idx > 0){
			ans += w[idx-1];
		}
	}
	cout << ans << endl;
	
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> B(N-1+1);
	vector<long long> C(N-1+1);
	vector<long long> A(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&B[i]);
	}
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&C[i]);
	}
	solve(N, A, B, C);
	return 0;
}



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

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }


        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var L = new long[N + 1];
            L[0] = 2;
            L[1] = 1;
            for(int i = 2; i <= N; i++)
            {
                L[i] = L[i - 1] + L[i - 2];
            }
            WriteLine(L[N]);
        }


        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
    cin>>s;
    int len=s.size(); 
    for(int i=0;i<=len;i++)
    {
        if(s[i]=='C') 
        {
            for(int j=i;j<=len;j++)
            {
                if(s[j]=='F')
                {
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"No"<<endl; 
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		int output = 0;
		
		for(int i = 0; i<n; i++) {
			int x= sc.nextInt();
			int y = sc.nextInt();
			
			if(Math.sqrt(Math.pow(x, 2) + Math.pow(y , 2)) <= d) {
				output++;
			}
		}
		
		System.out.println(output);

	}
}


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

using ll = long long int;

const ll MAX_N = (ll)(200 + 5);
const ll INF = (ll)(1<<29);

struct edge {ll from, to, cost;};

ll n, m, r;
ll town[8];
ll path[MAX_N][MAX_N];

vector<edge> es;
ll ans;

void shortest_path(ll s) {
  path[s][s] = 0;
  while (true) {
    bool update = false;
    for (ll i = 0; i < es.size(); ++i) {
      edge e = es[i];
      if (path[s][e.from] != INF && path[s][e.to] > path[s][e.from] + e.cost) {
        path[s][e.to] = path[s][e.from] + e.cost;
        update = true;
      }
    }
    if (!update) break;
  }
}

int main(void) {
  // Here your code !
  scanf("%lld %lld %lld", &n, &m, &r);
  for (ll i = 0; i < r; ++i) {scanf("%lld", &(town[i]));}
  for (ll i = 0; i < m; ++i) {
    ll a, b, c;
    scanf("%lld %lld %lld", &a, &b, &c);
    edge tmp_f = edge {a, b, c};
    edge tmp_b = edge {b, a, c};
    es.push_back(tmp_f);
    es.push_back(tmp_b);
  }

  for (ll i = 1; i <= n; ++i) for (ll j = 1; j <=n; ++j) {
    path[i][j] = INF;
  }

  for (ll i = 1; i <= n; ++i) {
    shortest_path(i);
  }

  sort(town, town + r);
  
  ans = INF;
  do {
    ll cur_ans = 0;
    for (ll i = 0; i < r - 1; ++i) {
      cur_ans += path[town[i]][town[i + 1]];
    }
    ans = min(ans, cur_ans);
    // Do something
  } while (next_permutation(town, town + r));

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

  return 0;
}


Measured memory_bytes: 1912
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i32,
        b: i32
    }
    println!("{}", if std::cmp::max(a, b) > 9 {-1} else {a * b});
}


Measured memory_bytes: 4352
N = int(input())
Pp = input()

P = []
H = []
n=1

for i in range(N):
    P = int(Pp.split()[i])
    H.append(P-n)
    n+=1


R = H.count(0)

if N-R < 3:
    print('YES')

else:
    print('NO')



Measured memory_bytes: 3060
import java.util.*;
class Main{
	public static void main(String args[]){
		Scanner s = new Scanner(System.in);
		String indata;
		int a[] = new  int[3];
		int store;
		for(int i=0;i<3;i++){
			indata=s.next();
			a[i]=Integer.parseInt(indata);
		}
		int flag;
		while(true){
			flag=0;
			for(int i=0;i<2;i++){
				if(a[i]>a[i+1]){
					store=a[i];
					a[i]=a[i+1];
					a[i+1]=store;
					flag=1;
				}
			}if(flag==0)break;
		}
		System.out.println(a[0]+" "+a[1]+" "+a[2]);
	}
}

Measured memory_bytes: 26024
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int num(string card) {
	switch(card[0]) {
	case 'A':
		return 14;
	case 'T':
		return 10;
	case 'J':
		return 11;
	case 'Q':
		return 12;
	case 'K':
		return 13;
	default:
		return card[0]-'0';
	}
}

char suit(string card) {
	return card[1];
}

int main() {
	char trump;
	while(cin >> trump, trump != '#') {
		vector<vs> card(4, vs(13));
		REP(i, 4) {
			REP(j, 13) {
				cin >> card[i][j];
			}
		}

		int ns = 0, ew = 0;
		int d = 0;
		REP(i, 13) {
			int best = -1, tbest = -1, twinner = -1, winner = -1;
			char ts = suit(card[d][i]);
			REP(j, 4) {
				char s = suit(card[j][i]);
				int n = num(card[j][i]);
				if(s == trump) {
					if(tbest < n) {
						tbest = n;
						twinner = j;
					}
				} else if(ts == s) {
					if(best < n) {
						best = n;
						winner = j;
					}
				}
			}
			if(twinner != -1) {
				if(twinner%2) {
					ew++;
				} else {
					ns++;
				}
				d = twinner;
			} else {
				if(winner%2) {
					ew++;
				} else {
					ns++;
				}
				d = winner;
			}
		}

		if(ns < ew) {
			cout << "EW " << ew-6 << endl;
		} else {
			cout << "NS " << ns-6 << endl;
		}
	}

	return 0;
}

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

typedef long long ll;

int n, m;
vector<pair<int, int>> e[100005];

ll x[1000005];
bool vis[1000005];

bool ok = true;

void solve(int v) {
	vis[v] = true;
	for (auto p : e[v]) {
		int y = p.first;
		int d = p.second;

		if (vis[y]) {
			if (x[v] + d != x[y]) {
				ok = false;
			}
		} else {
			x[y] = x[v] + d;
			solve(y);
		}
		
	}
}

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

	cin >> n >> m;
	for (int i=1; i<=m; i++) {
		int l, r, d;
		cin >> l >> r >> d;
		e[l].push_back({r, d});
		e[r].push_back({l, -d});
	}

	for (int i=1; i<=n; i++) {
		if (!vis[i]) {
			solve(i);
		}
	}

	cout << (ok ? "Yes" : "No") << '\n';
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
void bulk(){}template<class H,class...T>void bulk(H&h,T&...t){cin>>h;bulk(t...);}
#define get(...) int __VA_ARGS__; bulk(__VA_ARGS__);

int main(){
	get(n);
	n*=2;
	vi p(n);
	rep(i,n)cin>>p[i];
	sort(all(p));
	int ans=0;
	rep(i,n/2){
	    ans+=min(p[i*2],p[i*2+1]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        int ans = 0;
        for (int i = 1; i <= N; i++) {
            int s = 0;
            int n = i;
            while (n > 0) {
                s += n % 10;
                n /= 10;
            }
            if (A <= s && s <= B) ans += i;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

map<int,int> tval;
set<pii> s;

int main(){
	int q;
	cin >> q;
	priority_queue<int, vector<int>, greater<int>> high;
	priority_queue<int> low;
	ll lsum=0,hsum=0,bsum=0;
	while(q--){
		int t,a,b;
		cin >> t;
		if(t == 2){
			ll med = (low.size()>=high.size()?low.top():high.top());
			ll val = low.size() * med - lsum + hsum - high.size() * med;
			cout << med << " " << val + bsum << '\n';
		}
		else{
			cin >> a >> b;
			bsum += b;
			ll med = (low.size() + high.size() != 0?(low.size()>=high.size()?low.top():high.top()):0);
			if(a <= med){
				low.push(a);
				lsum+=a;
			}
			else{
				high.push(a);
				hsum+=a;
			}

			if(low.size() >= high.size() + 2){
				high.push(low.top());	
				lsum-=low.top();
				hsum+=low.top();
				low.pop();
			}
			if(low.size() + 2 <= high.size()){
				low.push(high.top());	
				hsum-=high.top();
				lsum+=high.top();
				high.pop();
			}
		}
	}
}


Measured memory_bytes: 3452
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000
using ll = long long;
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef long double ld;
const ld eps = 1.0e-12; // 許容される誤差
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10;
	}
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */
ld mysqrtl(ld x)
{
	ld a = sqrtl((double)x); // 近似値
	do {
		a = (a + x / a) / 2.0L;
	} while (fabsl(x - a * a) > eps);
	return a;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);

}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//平方根を求める。sqrtより精度が高い。
//epsを変えて誤差を調整する。
int main(void) {
	Rapid_pleaseAC_fast;
	llint ans = 0, n = 0,  count = 0, sum = 0;
    llint  k,time=1;
	bool check = false;
	string ss, sss;
	vector<llint> array;
	vector<bool> bo;
	rep(i, 5) {
		cin >> n;
		if (n == 0)cout << i + 1 << endl;
	}
	
	please AC;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int nax = 16;
int x[nax], y[nax], p[nax];
int n;
ll d[nax][2][1 << nax];

ll res[nax];
/// mimimum distance distance (x or y) to nearest line
/// denote that line pass through point in mask

inline void upd_min (ll &a, ll b) {
    a = min(a, b);
}

int main () {
    scanf("%d", &n);

    for (int i = 0 ; i < n ; ++ i)
        scanf("%d %d %d", x + i, y + i, p + i);

    for (int i = 0 ; i < n ; ++ i) {
        ll base = 1LL * p[i] * min(abs(x[i]) , abs(y[i]));
        for (int msk = 0 ; msk < (1 << n); ++ msk) {
            d[i][0][msk] = d[i][1][msk] = base;
            for (int j = 0 ; j < n ; ++ j) {
                if (msk >> j & 1) {
                    upd_min(d[i][0][msk], 1LL * p[i] * abs(x[j] - x[i]));
                    upd_min(d[i][1][msk], 1LL * p[i] * abs(y[j] - y[i]));
                }
            }
        }
    }

    fill(res, res + nax, LLONG_MAX);

    for (int m = 0 ; m < (1 << n) ; ++ m) {
        ll cur = LLONG_MAX;
        for (int sub = m; ; sub = (sub - 1) & m) {
            ll sum = 0;
            for (int k = 0 ; k < n ; ++ k)
                sum += min(d[k][0][sub], d[k][1][m ^ sub]);
            cur = min(cur, sum);
            if (sub == 0) break;
        }
        int pcnt = __builtin_popcount(m);
        res[pcnt] = min(res[pcnt], cur);
    }


    for (int i = 0 ; i <= n ; ++ i)
        printf("%lld\n", res[i]);


}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 11576
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define fin(ans) cout << (ans) << endl
const int INF = 1<<30;
const ll MOD = 1000000007;

int main() {
  int n,ans=0;
  cin >> n;
  for(int i = 1; i <= n; i++){
      if(i%2!=0){
          int a=0;
          for(int j = 1; j <= i; j++){
              if(i%j==0) a++;
          }
          if(a==8) ans++;
      }
      
  }
  cout << ans << endl;
  
}

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

int main() {
	int N;
	cin >> N;
	vector<int>b(N);
	rep(i, N) {
		cin >> b.at(i);
	}
	sort(b.begin(), b.end());
	N /= 2;
	cout << b.at(N) - b.at(N - 1) << endl;
}

Measured memory_bytes: 640
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> h = vector<ll>(n);
	rep(i, n) {
		cin >> h[i];
	}
	vector<ll> dp = vector<ll>(n + 1);
	rep (i, n + 1) {
		dp[i] = INF;
	}
	dp[0] = 0;
	rep(i, n) {
		for (int j = i + 1; j < min(n, i + k + 1); j++) {
			dp[j] = min(dp[j],dp[i] + abs(h[i] - h[j]));
		}
	}
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)
#define adiii \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);  \
  cout.tie(NULL);									
 
ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}
ll gcd(ll a,ll b) {if (b == 0) return a;return gcd(b, a % b);}
 
ll binpow(ll a, ll b) {ll res = 1;while (b > 0) {if (b & 1) res = res * a;a = a * a;b >>= 1;}return res;}
 
 
 
int main(){
	adiii
	ll n,tw;
	cin>>n>>tw;
	vector <ll> w(n+1),v(n+1);
	rep(i,1,n+1) cin>>w[i]>>v[i];
	ll t=0;
	rep(i,1,n+1) t+=v[i];
	vector <ll> dp(t+1,inf);
	dp[0] = 0;
	rep(i,1,n+1){
		rrep(j,t-v[i],0){
			dp[j+v[i]] = min(dp[j+v[i]],dp[j] + w[i]); 
		}
	}
	ll ans=0;
	rep(i,0,t+1){
		//cout<<dp[i]<<" ";
		if(dp[i]<=tw) ans = i;
	}
	cout<<ans<<endl;
}


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

typedef long long ll;
typedef vector<ll> vec;

int main() {
    int N;
    cin >> N;
    vec A(N+1), B(N);
    rep(i, N+1) cin >> A[i];
    rep(i, N) cin >> B[i];
    
    ll cnt = 0;
    
    if (B[0] >= A[0]) {
        cnt += A[0];
        B[0] -= A[0];
    } else {
        cnt += B[0];
        B[0] = 0;
    }
    
    if (B[N-1] >= A[N]) {
        cnt += A[N];
        B[N-1] -= A[N];
    } else {
        cnt += B[N-1];
        B[N-1] = 0;
    }
    
    for (int i=0; i<N; i++) {
        if (i != 0) {
            if (B[i] >= A[i]) {
                cnt += A[i];
                B[i] -= A[i];
            } else {
                cnt += B[i];
                B[i] = 0;
            }
        }
        
        if (i != N-1) {
            if (B[i] >= A[i+1]) {
                cnt += A[i+1];
                A[i+1] = 0;
            } else {
                cnt += B[i];
                A[i+1] -= B[i];
            }
        }
        
    }
    
    cout << cnt << endl;
    
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B,N,M,Q,ii,f,max,MAX;
  f=0;
  max=0;
  MAX=0;
  int a[100],b[100],c[100],d[100],An[20];
  cin >> N >> M >> Q;
  for(int i = 1; i <= Q; i++) {
    cin >> a[i];
    cin >> b[i];
    cin >> c[i];
    cin >> d[i];
  }
  for(int i = 0; i<=11; i++){
    An[i]=1;
  }
  while(An[0]==1){
    max=0;
    for(int i = 1; i <= Q; i++) {
      A=a[i];
      B=b[i];
      if(An[B]-An[A]==c[i]){
        max=max+d[i];
      }
    }
    
    ii=N;
    f=0;
    while(f==0){
      if(An[ii]!=M){
        An[ii]++;
        for(int iii = ii+1; iii <= 11; iii++) {
          An[iii]=An[iii-1];
        }
        f=1;
      }else{
        ii=ii-1;
      }
    }
    if(MAX<max){
      MAX=max;
    }
  }
  cout << MAX << endl;
  return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include <map>
#include <utility>
#include <algorithm>
#include <functional>
#include<string>

using namespace std;

int main() {
	int a, s, d, f, g, h, j, k;
	cin >> a >> s >> d >> f >> g >> h >> j >> k;
	if (a + s + d + f > g + h + j + k) {
		cout << a + s + d + f << endl;
	}
	else {
		cout << g + h + j + k << endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


pair<int, int> E[200002];
int H[100001];
bool D[100001];
bool kotae;
bool dfs(int A) {
	if (D[A]) return 0;
	D[A] = true;
	int goukei = 0;
	for (int i = H[A]; i; i = E[i].second) {
		goukei += dfs(E[i].first);
	}
	if (goukei > 1) kotae = true;
	return goukei ^ 1;
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	for (int i = 1; i < N + N - 2; i += 2) {
		int a = getint(), b = getint();
		
		E[i] = mp(b, H[a]);
		H[a] = i;
		E[i + 1] = mp(a, H[b]);
		H[b] = i + 1;
	}

	if (dfs(1)) kotae = true;

	if (kotae) co("First");
	else co("Second");

	Would you please return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,j=0,c=0;
    cin>>n;
    double ans=0;
    vector<pair<ll,ll> >v;
    map<pair<ll,ll> ,ll>m;
    for(int i=1;i<=n;i++)
    {
      ll x,y;
      cin>>x>>y;
      v.pb(mp(x,y));
      m[{x,y}]=i+1;
    }
    sort(v.begin(),v.end());
    
    do{
      c++;
      /*for(auto t:v)
        {
          cout<<m[{t.fi,t.se}]<<" ";
        }
        cout<<endl;*/

     
      double temp=0;
      for(int j=1;j<n;j++)
      {
          double x1,x2,y1,y2;
          x1=v[j-1].fi;
          y1=v[j-1].se;
          x2=v[j].fi;
          y2=v[j].se;
          temp+=(sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) ));
      }
      ans+=temp;
    } while(next_permutation(begin(v),end(v)));
      
//cerr<<"c = "<<c<<endl;
//cerr<<"ans = "<<ans<<endl;
ll fac=1;
for(int i=1;i<=n;i++)
{
  fac*=i;
  //cerr<<fac<<endl;
}
//cerr<<"fac = "<<fac<<endl;
double fin=ans/double(fac);
cout<<fixed<<setprecision(8)<<fin<<endl;

    
}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N,Q;
  cin >> N >> Q;
  ll S[N],T[N],X[N];
  vector<ll> vect;
  vect.push_back(-Mod * 1000LL);
  vect.push_back(Mod * 1000LL);
  for (int i = 0; i < N; i++) {
    cin >> S[i] >> T[i] >> X[i];
    vect.push_back(S[i]-X[i]);
    vect.push_back(T[i]-X[i]);
  }
  sort(vect.begin(),vect.end());
  vector<ll> vec;
  for (int i = 1; i < (int)vect.size(); i++) {
    if (vect[i-1] != vect[i]) {
      vec.push_back(vect[i-1]);
    }
  }
  vec.push_back(Mod * 1000LL);
  int sz = vec.size();
  vector<ll> ans(sz);
  vector<ll> L[sz];
  vector<ll> R[sz];
  for (int i = 0; i < N; i++) {
    int l = lower_bound(vec.begin(),vec.end(),S[i]-X[i]) - vec.begin();
    int r = lower_bound(vec.begin(),vec.end(),T[i]-X[i]) - vec.begin();
    L[l].push_back(i);
    R[r].push_back(i);
  }
  multiset<ll> Set;
  for (int i = 0; i < sz; i++) {
    for (int j = 0; j < (int)L[i].size(); j++) {
      Set.insert(X[L[i][j]]);
    }
    for (int j = 0; j < (int)R[i].size(); j++) {
      auto itr = Set.lower_bound(X[R[i][j]]);
      Set.erase(itr);
    }
    if (Set.empty()) {
      ans[i] = -1;
    } else {
      auto itr = Set.begin();
      ans[i] = *itr;
    }
  }

  for (int i = 0; i < Q; i++) {
    ll D;
    cin >> D;
    int w = lower_bound(vec.begin(),vec.end(),D) - vec.begin();
    if (vec[w] != D) {
      w--;
    }
    cout << ans[w] << endl;
  }
  return 0;
}

Measured memory_bytes: 57828
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
ll ans=0;
int n,m,q;
vector <pair <pii,pii> > b;
void solve(vi a,int cur)
{
if (cur==0)
{
    for (int i=1;i<=m;i++)
        solve({i},cur+1);
    return;
}
if (cur==n)
{
    ll sum=0;
    for (int i=0;i<q;i++)
    {
        if (a[b[i].fi.se]-a[b[i].fi.fi]==b[i].se.fi)
            sum+=b[i].se.se;
    }
    ans=max(ans,sum);
    return;
}
int x=a[(int)(a.size())-1];
for (int i=x;i<=m;i++)
{
    vi b=a;
    b.pb(i);
    solve(b,cur+1);
}
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("a.in","r",stdin);
#endif
    cin>>n>>m>>q;
    for (int i=0;i<q;i++)
    {
        int x,y,z,f;
        cin>>x>>y>>z>>f;
        x--,y--;
        b.pb({{x,y},{z,f}});
    }
    solve({},0);
    cout<<ans;




}

Measured memory_bytes: 3664
n = int(input())
a = list(map(int,input().split()))
cnt={}
for i in range(min(a)-1,max(a)+2):
    cnt[i]=0
for i in a:
    if i in cnt:
        cnt[i]+=1
M=0
for i in a:
    if M < cnt[i-1]+cnt[i]+cnt[i+1]:
        M = cnt[i-1]+cnt[i]+cnt[i+1]
print(M)

Measured memory_bytes: 61548
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
long long int mini(long long int a, long long int b) {
	if (a > b)return b;
	else return a;
}
int main() {
	long long int N, ans = 0;
	long long int M, c = 0;
	cin >> N >> M;
	vector<pair<int,int>>A(N);
	for (int i = 0; i < N; i++)cin >> A[i].first >> A[i].second;
	sort(A.begin(), A.end());
	int i = 0;
	while (c<M) {
		ans += A[i].first*mini(M-c,A[i].second);
		c += A[i].second;
		i++;
	}
	cout << ans;
}

Measured memory_bytes: 1024
/*
 * atcoder/abc110_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int N;
string S, T;
char pair1[200];
char pair2[200];
int counter1[200] = {0};
int counter2[200] = {0};

void solve() {
  cin >> S >> T;
  N = S.size();
  loop(n,0,200) pair1[n] = pair2[n] = ' ';
  loop(n,0,N) counter1[S[n]]++;
  loop(n,0,N) counter2[T[n]]++;
  loop(n,0,N) {
    char s = S[n];
    char t = T[n];
    if (counter1[s] > 1) {
      if (pair1[s] != ' ' and pair1[s] != t) {
        cout << "No" << endl;
        return;
      }

      pair1[s] = t;
    }

    if (counter2[t] > 1) {
      if (pair2[t] != ' ' and pair2[t] != s) {
        cout << "No" << endl;
        return;
      }

      pair2[t] = s;
    }
  }
  cout << "Yes" << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


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

typedef long long ll;

int main() {
  string s;
  cin >> s;

  set<char> chs;
  for(int i=0; i<s.length(); i++){
    chs.insert(s[i]);
  }

  bool flag=true;
  for(int i=0; i<(int)s.length()-1; i++){
    if(s[i]!=s[i+1]) flag=false;
  }
  if(flag){
    cout << 0 << endl;
    return 0;
  }

  int ans=1e9;
  for(auto itr=chs.begin(); itr!=chs.end(); itr++){
    char ch = *itr;
    //cout <<" "<< ch << endl;
    int t=s.length(), tt=t-1;
    string T=s, TT;
    while(1){

      for(int i=0; i<tt; i++){
        if(T[i]==ch || T[i+1]==ch){
          if(T[i]==ch) TT.push_back(T[i]);
          else if(T[i+1]==ch) TT.push_back(T[i+1]);
        }
        else {
          TT.push_back(T[i]);
        }
      }
      bool f=true;
      for(int i=0; i<tt-1; i++){
        if(TT[i]!=TT[i+1]) f=false;
      }
      if(f){
        ans = min(ans, (int)s.length()-(int)TT.length());
        break;
      }

      t--;
      tt--;
      T = TT;
      TT.clear();
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256