akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int N,K;
  cin>>N>>K;
  vector<int> A(N);
  rep(i,N) cin>>A[i];

  rep(k,K){
    vector<int> imos(N+1,0);
    for(int i=0;i<N;i++){
      imos[max(0,i-A[i])]++;
      imos[min(N,i+A[i]+1)]--;
    }
    for(int i=1;i<=N;i++) imos[i]+=imos[i-1];
    
    rep(i,N) A[i]=imos[i];

    bool all=true;
    rep(i,N) if(A[i]!=N) all=false;
    if(all){
      for(int i=0;i<N;i++) cout<<N<<" ";
      cout<<endl;
      return 0;
    }
  }

  for(int i=0;i<N;i++) cout<<A[i]<<" ";
  cout<<endl;

  return 0;
}


Measured memory_bytes: 4976
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int n,JOI=0,IOI=0;
  char s[10000];
  while(scanf("%s",s)!=EOF){
    n=strlen(s);
    for(int i=0;i<n;i++){
      if(s[i]=='J'){
	if(s[i+1]=='O'){
	  if(s[i+2]=='I'){
	    JOI++;
	  }
	}
      }
      else if(s[i]=='I'){
	if(s[i+1]=='O'){
	  if(s[i+2]=='I'){
	    IOI++;
	  }
	}
      }
    }
    cout << JOI << endl << IOI << endl;
    JOI=0;
    IOI=0;
  }
  return (0);
}

Measured memory_bytes: 1168
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <list>
#include <cmath>
#include <stack>
#include <queue>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

const int mod = 1000000007;
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 {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= 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 {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		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];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

int main()
{
	int a, b;
	cin >> a >> b;
	cout << (a - 2 * b >= 0 ? a - 2 * b : 0);
}


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

const ll MOD = 1e9+7;

ll powmod(ll x, ll n){
  ll ret = 1;

  while (n>0){
    if ((n&1) == 1){
      ret *= x;
      ret %= MOD;
    }
    x*=x;
    x%=MOD;
    n>>=1;
  }

  return ret;
}

int main(void){
  ll n, ans;
  cin >> n;

  ans = powmod(10,n);
  ans -= powmod(9,n);
  ans -= powmod(9,n);
  ans += powmod(8,n);
  ans %= MOD;
  ans = (ans+MOD)%MOD;

  cout << ans;
}

Measured memory_bytes: 3552
#import
#import math
#import numpy as np
N = int(input())
XY= [list(map(int, input().split())) for _ in range(N)]

pmaxint = -10**10
pminint = 10**10
mmaxint = -10**10
mminint = 10**10

for x, y in XY:
    t1 = x + y
    t2 = x - y
    if t1 > pmaxint:
        pmaxint = t1
    if t1 < pminint:
        pminint = t1
    
    if t2 > mmaxint:
        mmaxint = t2
    if t2 < mminint:
        mminint = t2

print(max(abs(pmaxint - pminint), abs(mmaxint - mminint)))

Measured memory_bytes: 45404
n = int(input())
a = [int(i) for i in input().split()]
b = [] #i=n-1からi=0まで逆向き

for i in reversed(range(n)):
  if i>=n//2:
    b.append(a[i])
  else:
    #k＊番号の箱の合計、番号はi+1
    temp = [b[n-k*(i+1)] for k in range(2,n//(i+1)+1)]
    b.append((sum(temp)-a[i])%2)

b.reverse()
print(b.count(1))
for i in range(n):
  if b[i]==1:
    print(i+1, end=" ")

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

using namespace std;

const int kN = 1e5+7;
const int kM = 998244353;

int n, ans = 1;
string s;
int a[4], b[4];

inline int GetId(char c) {
    if (c == 'R') return 0;
    if (c == 'G') return 1;
    if (c == 'B') return 2;
}

int main()
{
    cin >> n >> s;
    a[0] =  n;
    for (int i = 0, p, q; i < s.length(); ++i) {
        p = GetId(s[i]);
        q = 0;
        ++b[p];
        // b[j] < b[p], then j has in a group
        for (int j = 0; j < 3; ++j) {
            if (b[j] > b[p]) {
                ++q;
            }
        }
        ++b[p];
        ans = int(1ll*ans*a[q]%kM);
        // the sizeof this group is q+1
        a[q]--;
        a[q+1]++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  for(int i = 0;i < n;i++){
    int a;
    cin >> a;
    if(a%2 == 0){
      if(a%3 != 0 && a%5 != 0){
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B;
  cin>>A>>B;
  if(A==1){
  A+=13;
  }
  if(B==1){
  B+=13;
  }
  if(A>B){
  cout<<"Alice"<<endl;
  }
  else if(A<B){
    cout<<"Bob"<<endl;
  }
  else{
  cout<<"Draw"<<endl;
  }
}


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

using namespace std;

int main(){
	long long a,b,n;
	cin>>a>>b>>n;
	long long x=b>n ? n : b-1;

	cout<<floor(a*x/b)-a*floor(x/b)<<endl;

	return 0;
}


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

int main(){
	int k;
	cin >> k;
	int ans;
	if(k%2 == 0){
		ans = (k/2) * (k/2);
	}else{
		ans = (k/2) * (k/2 + 1);
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 256
n = int(input())

V = 0
for i in range(1,n+1):
    V += i*(n-(i-1))

E = 0
for _ in range(n-1):
  u,v = map(int,input().split())
  if u > v:
    u,v = v,u
  E += u*(n-(v-1))

print(V-E)

Measured memory_bytes: 9152
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	static void solve(){//Here is the main function
  int N = nextInt();
  long output = 2;
  for(int i = 0; i < N; i++){
    output = output + 1 + output + 1;
  }
  myout(output);
	}
	//Method addition frame start



	//Method addition frame end

	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
}


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

string S,T;

int main() {
    cin>>S>>T;
    bool isTrue = true;
    for(int i=0; i<S.length(); i++)
    {
        if(S[i]!=T[i]){
            isTrue = false;
            break;
        }
    }
    if(isTrue)cout<<"Yes";
    else cout<<"No";

    return 0;
}


Measured memory_bytes: 3040
#include<iostream>
using namespace std;
int main(void){
    int A,B,C,D,E,K;
    cin >> A >> B >> C >> D >> E >> K;
    if(E-A <= K){
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<string> vec(n);
  for(int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int s = 0;
  for(int i = 0; i < n - 1; i++) {
    if(vec.at(i) == vec.at(i + 1)) {
      s++;
    }
  }
  if(s > 0) {
    cout << "NO" << endl;
  }
  else {
    cout << "YES" << endl;
  }
}


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

int main(){

    long long A, B;
    int K;
    cin >> A >> B >> K;

    if(B - K + 1 <= A + K - 1){
        for(long long i = A; i <= B; i++){
            cout << i << endl;
        }
    }else{
        for(int i = 0; i < K; i++){
            cout << A + i << endl;
        }
        for(int i = K - 1; i >= 0; i--){
            cout << B - i << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#999
l = []
inp = input()
for i in range(len(inp)):
    if inp[i] == "1":
        l.append("9")
    elif inp[i] == "9":
        l.append("1")
    else:
        l.append(inp[i])

for i in range(len(l)):
    print(l[i], end='')


Measured memory_bytes: 3060
local n = io.read("*n")
local t, k = {}, {}
for i = 1, n do
  t[i] = io.read("*n")
  k[i] = t[i]
end
table.sort(k)
local mid1, mid2 = k[n // 2], k[n // 2 + 1]
for i = 1, n do
  if(t[i] <= mid1) then print(mid2) else print(mid1) end
end


Measured memory_bytes: 10588
from collections import deque


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


def d(s):
    ret = [10 ** 18] * n
    ret[s] = 0
    q = deque()
    q.append(s)
    while len(q):
        now = q.popleft()
        for to in g[now]:
            if ret[to] < 10 ** 18:
                continue
            ret[to] = ret[now] + 1
            q.append(to)
    return ret


# print(d(n-1))

fennec = d(0)
snuke = d(n - 1)
cnt = 0
for i in range(n):
    if fennec[i] <= snuke[i]:
        cnt += 1
    else:
        cnt -= 1
if cnt > 0:
    print("Fennec")
else:
    print("Snuke")


Measured memory_bytes: 29360
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		if (a - c <= d && a - c >= -d) {
			System.out.println("Yes");
		} else if (-d <= a - b && a - b <= d && -d <= b - c && b - c <= d) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    ll a, b, k;
    cin >> a >> b >> k;
    
    ll d = min(a, k);
    a -= d;
    k -= d;
    
    d = min(b, k);
    b -= d;
    cout << a << " " << b << endl;
}


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

int main()
{
   int a, b;
   char op;

   int n = 0, ans[100000] = {};
   while (1) {
       cin >> a >> op >> b;
       if (op == '?') break;
       switch (op) {
           case '+' : ans[n] = a + b; break;
           case '-' : ans[n] = a - b; break;
           case '*' : ans[n] = a * b; break;
           case '/' : ans[n] = a / b; break;
           default : break;
       }
       n++;
   }

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

   return 0;
}

Measured memory_bytes: 3436
using System;
using System.IO;
using System.Linq;

public class A{
    public static void Main(){
        string[] input = Console.ReadLine().Split();
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        if (a<=5){
            Console.Write(0);
        }
        else if (a<=12){
            Console.Write(b/2);
        }
        else {
            Console.Write(b);
        }

    }
}


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



int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin>>n;
  int k;
  cin>>k;
  long long int h[100005];
  for(int i=0;i<n;i++){
    cin>>h[i];

  }
  sort(h,h+n);
  long long int s[100005];
  for(int i=0;i<n-k+1;i++){
    s[i]=h[i+k-1]-h[i];
  }
  sort(s,s+n-k+1);
  cout<<s[0];
  

  
  }




Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <string>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/




int main(void) {
  ll i, j, k;
  
  ll A, B, Q;
  cin >> A >> B >> Q;
  ll s[MAX], t[MAX];
  
  for(i=1; i<=A; i++) cin >> s[i]; s[0]=-INF; s[A+1]=INF;
  for(i=1; i<=B; i++) cin >> t[i]; t[0]=-INF; t[B+1]=INF;
  
  for(ll _=0; _<Q; _++) {
    ll x;
    cin >> x;
    
    ll ps=lower_bound(s, s+A+2, x)-s;
    ll pt=lower_bound(t, t+B+2, x)-t;
    
    ll d[]={s[ps]-x, t[pt]-x, x-s[ps-1], x-t[pt-1]};
    
    ll t1=min(max(d[0], d[1]), max(d[2], d[3]));
    ll t2=min(d[0]+d[3]+min(d[0], d[3]), d[1]+d[2]+min(d[1], d[2]));
    
    pt(min(t1, t2));
  }
  
}



Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    vector<int> V(3);
    char tmp1, tmp2;
    string S;
    bool flag=true;
    
    // cin >> A >> B >>C;

    // if(A<=C && C<=B)
    // 	puts("Yes");
    // else
    // 	puts("No");

    vector<int> group = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    int a, b;
    cin >> a >> b;
    if (group[a] == group [b])
	cout << "Yes" << endl;
    else
	cout << "No" << endl;
   
 

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(A+B==C || B+C==A || C+A==B)
    // 	puts("Yes");
    // else
    // 	puts("No");
}


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

int main(){
    int A, B, C;
    cin >> A >> B >> C;

    if(A < B && B < C){
        cout << C * 10 + B + A << endl;
    }
    if(A < C && C < B){
        cout << B * 10 + C + A << endl;
    }
    if(B < A && A < C){
        cout << C * 10 + A + B << endl;
    }
    if(B < C && C < A){
        cout << A * 10 + C + B << endl;
    }
    if(C < A && A < B){
        cout << B * 10 + A + C << endl;
    }
    if(C < B && B < A){
        cout << A * 10 + B + C << endl;
    }
    if(A == B && B == C){
        cout << A * 10 + B + C << endl;
    }
    
    if(A == C && C < B){
        cout << B * 10 + A + C << endl;
    }
    if(A == C && C > B){
        cout << A * 10 + C + B << endl;
    }
    if(B == C && C < A){
        cout << A * 10 + B + C << endl;
    }
    if(B == C && C > A){
        cout << C * 10 + B + A << endl;
    }
    if(A == B && B < C){
        cout << C * 10 + B + A << endl;
    }
    if(A == B && B > C){
        cout << A * 10 + B + C << endl;
    }
    return 0;
}


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

int main() {
  int N; cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++) cin >> P.at(i);
  int ans = 0;
  int tmp = P.at(0);
  for (int i = 0; i < N; i++) {
    if (P.at(i) <= tmp) ans++;
    tmp = min(tmp, P.at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using std::min; using std::max;
using std::swap; using std::sort;
using std::unique; using std::lower_bound;
typedef long long ll;
     
template<typename T>
void read(T &x) {
	int flag = 1; x = 0; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= flag;
}
#if __cplusplus >= 201103l
template<typename T, typename... V>
void read(T &x, V&... v) { read(x), read(v...); }
#endif
     
const int _ = 1e5 + 20, Inf = 1e5 + 10;
int n, a[_], sum[_];
int c[_ << 1];
void add(int x) { for(; x <= (Inf << 1); x += x & -x) ++c[x]; }
ll que(int x) { ll y = 0; for(; x; x -= x & -x) y += c[x]; return y; }
     
bool check(int mid) {
	for(int i = 1; i <= (Inf << 1); ++i) c[i] = 0;
	for(int i = 1; i <= n; ++i)
		sum[i] = sum[i - 1] + (a[i] <= mid ? -1 : 1);
	ll pair = 0;
	for(int i = 0; i <= n; ++i) {
		add(sum[i] + Inf);
		pair += i + 1 - que(sum[i] + Inf);
	}
	return pair > 1ll * n * (n + 1) / 4;
}
     
int main () {
	read(n); int l = 0, r = 0;
	for(int i = 1; i <= n; ++i)
		read(a[i]), r = max(r, a[i]);
	while(l <= r) {
		int mid = (l + r) >> 1;
		if(check(mid)) r = mid - 1;
		else l = mid + 1;
	}
	return printf("%d\n", l), 0;
} 


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;

string s[5];

int32_t main()
{
	IOS;
	for(int i=0;i<=2;i++)
	{
		cin>>s[i];
		reverse(s[i].begin(), s[i].end());
	}
	int player=0;
	while(s[player].size())
	{
		int nplayer=s[player].back()-'a';
		s[player].pop_back();
		player=nplayer;
	}
	cout<<(char)(player+'A');
	return 0;
}


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

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
const long long MAX = (ll)170 * 80;

long long GCD (long long C, long long D) {
   while (1) {
      if (C == 0 || D == 0) break;
      if (D>C) D -= (D/C)*C;
      else C -= (C/D)*D;
   }
   return max(C,D);
}


int main(void) {
   ll N;
   cin>>N;
   vector<ll> A(N);
   rep(i,0,N) cin>>A[i];
   vector<ll> BG(N);
   vector<ll> CG(N);
   BG[0] = A[0];
   rep(i,0,N-1) {
      BG[i+1] = GCD(BG[i],A[i+1]);
   }
   CG[N-1] = A[N-1];
   for (int i = N-2;i>=0;i--) {
      CG[i] = GCD(CG[i+1],A[i]);
   }
   ll ans = 0;
   chmax(ans,CG[1]);
   chmax(ans,BG[N-2]);
   rep(i,0,N-2) {
      // cout<<BG[i]<<" "<<CG[i+1]<<endl;
      chmax(ans,GCD(BG[i],CG[i+2]));
   }
   cout<<ans<<endl;

   
   return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
# define ll long long
# define ld long double
# define pb push_back
#define F first
#define S second
 
// #define loop(i,n) for(int i=0;i<n;i++)
// #define loops(i,s,n) for(int i=s;i<=n;i++)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
 
  
    // for(int i=0;i<n;i++){  
        
    //     int x,y;
    //     cin>>x>>y;
        
    //     v.pb({x,y});         //make pair in vector
    // }
 
using namespace std;

#define P 1000000007


int main()
{ fast;
set<string>s1;

ll n;
cin>>n;
for(ll i=0;i<n;i++)
{ string s;
  cin>>s;
  s1.insert(s);  }

cout<<s1.size()<<"\n";

}


Measured memory_bytes: 19248
import java.util.ArrayList;
import java.util.Scanner;

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

		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		
		int N = sc.nextInt();
		ArrayList<Integer> nums = new ArrayList<>();

		for(int i = 0; i < N; i++) {
			nums.add(sc.nextInt());
		}

		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				if(nums.contains((A[i][j]))){
					A[i][j] = -1;
				}
			}
		}

		boolean ans = false;
		
		// horizontal
		for(int i = 0; i < 3; i++) {
			if(A[i][0]==-1 && A[i][1]==-1 && A[i][2]==-1) {
				ans = true;
			}
		}

		// vertical
		for(int j = 0; j < 3; j++) {
			if(A[0][j]==-1 && A[1][j]==-1 && A[2][j]==-1) {
				ans = true;
			}
		}
		
		// diagonal
		if(A[0][0]==-1 && A[1][1]==-1 && A[2][2]==-1) {
			ans = true;
		}
		if(A[0][2]==-1 && A[1][1]==-1 && A[2][0]==-1) {
			ans = true;
		}
		
		if(ans) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
		sc.close();
	}
	
}

Measured memory_bytes: 21844
n,k,q = map(int,input().split())
point = {}
for i in range(1,n+1):
    point[i] = 0
for j in range(q):
    point[int(input())] += 1
for l in range(1,n+1):
    if k - q + point[l] > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 19416
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n)cin >> a[i];
  map<ll, int> mp;
  rep(i, n){
    mp[a[i]]++;
  }
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  int res = 0;
  for(int i = int(a.size()) - 1; i >= 0; i--){
    ll curr = 1;
    while(curr <= a[i])curr *= 2;
    if(curr == a[i] * 2){
      res += (mp[a[i]] / 2);
      mp[a[i]] -= (mp[a[i]] / 2) * 2;
    }else{
      res += min(mp[a[i]], mp[curr - a[i]]);
      mp[curr - a[i]] -= min(mp[a[i]], mp[curr - a[i]]);
      mp[a[i]] -= min(mp[a[i]], mp[curr - a[i]]);
    }
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 26752
#include<bits/stdc++.h>
//#include<iostream>
using namespace std;
 
typedef long long ll;
const int N = 55;
 
int n;
vector<int> adj[N];
int par[N];
int lvl[N];
 
int m;
int cu[N],cv[N];
 
void dfs(int x,int p){
	for(int y:adj[x]){
		if(y == p)continue;
		par[y] = x;
		lvl[y] = lvl[x]+1;
		dfs(y,x);
	}
}
 
//set<pair<int,int> > vstd;
bool vstd[100000];
vector<int> dv;
int sz = 0;
void process(int x){
	int a = cu[x],b = cv[x];
	while(lvl[a] < lvl[b]){
		int t = par[b];
		//vstd.insert({min(t,b),max(t,b)});
		int hnhn = min(t,b)*100+max(t,b);
		if(!vstd[hnhn]){
			vstd[hnhn] = true;
			sz++;
			dv.push_back(hnhn);
		}
		b = t;
	}
	while(lvl[b] < lvl[a]){
		int t = par[a];
		//vstd.insert({min(t,a),max(t,a)});
		int hnhn = min(t,a)*100+max(t,a);
		if(!vstd[hnhn]){
			vstd[hnhn] = true;
			sz++;
			dv.push_back(hnhn);
		}
		a = t;
	}
	while(a != b){
		int t = par[b];
		//vstd.insert({min(t,b),max(t,b)});
		int hnhn = min(t,b)*100+max(t,b);
		if(!vstd[hnhn]){
			vstd[hnhn] = true;
			sz++;
			dv.push_back(hnhn);
		}
		b = t;
		t = par[a];
		//vstd.insert({min(t,a),max(t,a)});
		hnhn = min(t,a)*100+max(t,a);
		if(!vstd[hnhn]){
			vstd[hnhn] = true;
			sz++;
			dv.push_back(hnhn);
		}
		a = t;
	}
}
 
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin>>n;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>cu[i]>>cv[i];
	}
	
	dfs(1,1);
	ll ans = 0;
	for(int i=1;i<(1<<m);i++){
		ll ret = 0;
		int cnt = 0;
		//vstd.clear();
		sz = 0;
		for(int x:dv)vstd[x] = false;
		dv.clear();
		for(int j=0;j<m;j++){
			if(i&(1<<j)){
				cnt++;
				process(j);
			}
		}
		ret += (1ll<<(n-1-sz));
		//cout<<i<<" "<<cnt<<" "<<ret<<endl;
		if(cnt & 1){
			ans += ret;
		}else{
			ans -= ret;
		}
	}
	
	cout<<(1ll<<(n-1))-ans;
	
	return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			long n = in.nextLong();
			long a = in.nextLong(), b = in.nextLong(), c = in.nextLong(), d = in.nextLong();

			long sa = Math.abs(b-a);
			for (int k = 0; k <= n-1; k++) {
				if (k*c-(n-1-k)*d <= sa && sa <= k*d-(n-1-k)*c) {
					out.println("YES");
					return;
				}
			}
			out.println("NO");
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 22996
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };




int main(){
	int a,b,c;
  	cin >> a >> b >> c;
  	if(a == b && b == c)cout << "Yes" << endl;
  	else cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 256
L = int(input())
n = L.bit_length()
ans = []
for i in range(1,n):
  ans.append((i,i+1,0))
  ans.append((i,i+1,2**(n-i-1)))
binL = bin(L)
for i in range(1,n):
  if binL[i+2] == "1":
    mask = int(binL[:i+2],2)<<(n-i)
    ans.append((1,i+1,L&mask))
print(n,len(ans))
for edge in ans:
  print(*edge)

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

using namespace std;
typedef long long ll;

const int N = 1004;

int n, a[N];
int k, sz, b;
ll v[N*N], t[N*N];

int main(){

    scanf("%d %d", &n, &k);

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

    for(int i = 0; i < n; i++){
        ll sum = 0;
        for(int j = i; j < n; j++) v[sz++] = (sum += a[j]);
    }

    for(int i = 40; i >= 0; i--){
        b = 0;
        for(int j = 0; j < sz; j++) if(v[j] & (1LL << i))
            t[b++] = v[j];
        if(b >= k){
            for(int j = 0; j < b; j++) v[j] = t[j];
            sz = b;
        }
    }

    ll ans = v[0];

    for(int i = 0; i < sz; i++) ans &= v[i];

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


Measured memory_bytes: 7296
import java.util.*;

public class Main {
	int n;
	int[] b = new int[180];
	int[] c = new int[45];
	int[] d = new int[1000000];
	int[] e = new int[1000000];
	ArrayDeque<Integer> list = new ArrayDeque<Integer>();
	
	public void init(){
		int sum=0;
		for(int i=1;i<=180;i++){
			b[i-1]=(i*(i+1)*(i+2))/6;
			if(b[i-1]%2==1){
				c[sum]=b[i-1];
				sum++;
			}
		}
	}
	
	public void funcA(){
		list.offer(0);
		int z=1;
		int i=0;
		while(z<1000000){
			i++;
			int x = list.size();
			for(int j=0;j<x;j++){
				int y = list.poll();
				for(int k=0;k<180;k++){
					int sum = y + b[k];
					if(sum<1000000 && d[sum]==0){
						d[sum]=i;
						list.offer(sum);
						z++;
					}
				}	
			}
		}
	}
	
	public void funcB(){
		list.clear();
		list.offer(0);
		int z=1;
		int i=0;
		while(z<1000000){
			i++;
			int x = list.size();
			for(int j=0;j<x;j++){
				int y = list.poll();
				for(int k=0;k<45;k++){
					int sum = y + c[k];
					if(sum<1000000 && e[sum]==0){
						e[sum]=i;
						list.offer(sum);
						z++;
					}
				}	
			}
		}
	}
	
	public void print(){
		System.out.println(d[n] + " " + e[n]);
	}
	
	public static void main(String[] args) {
		Main C = new Main();
		Scanner sc = new Scanner(System.in);
		C.init();
		C.funcA();
		C.funcB();
		int exit=0;
		while(exit==0){
			C.n = sc.nextInt();
			if(C.n==0)exit=1;
			if(exit==0){	
				C.print();
			}
		}
	}
	
}

Measured memory_bytes: 79240
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;

const int SIZE = 100000+10;
vector<int> vec[SIZE];
int step[SIZE];
queue<int> que;
int N;
int size_1 = 0;
bool vis[SIZE];
int sz[SIZE];

void BFS()
{
	
	while( que.size() ){
		int now = que.front();que.pop();
		for(int i:vec[now]){
			if( step[i] == -1 ){
				//printf("* %d\n",i);
				step[i] = step[now]+1;
				que.push(i);
				size_1++ ;
			}
		}
	}
}


int DFS(int now)
{
	int size = 0;
	vis[now] = true;
	
	for( int i:vec[now] ){
		if( !vis[i] ){
			size += DFS(i);
		}
	}
	return sz[now] = size+1;
}

int count(int fix)
{
	int now = N;
	for(int i=step[N];i>fix;i--){
		for(int next:vec[now]){
			if( step[next] == i-1 ){
				now = next;
				break;
			}
		}
	}
//	printf("now = %d\n",now);
	return sz[now];
}

inline void init()
{
	for(int i=0;i<SIZE;i++)
		step[i] = -1,vis[i] = false;
}
int main (void)
{
	init();
	
	scanf("%d",&N);
	for(int i=1;i<N;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		vec[a].pb(b);
		vec[b].pb(a);		
	}
	que.push(1);
	step[1] = 0;
	BFS();
	
	int cnt = step[N]/2 + 1;
	DFS(1);
	
	size_1 = sz[1] - count( cnt );
	
//	printf("%d\n",size_1);
	
	
	size_1 > N/2? puts("Fennec") : puts("Snuke");
	
	return 0;
}



/*
7
1 2
2 3
2 4
1 7
5 7
6 7

6
1 2
2 5
2 3
3 4
3 6

8
1 2
2 3
3 4
4 8
4 5
3 6
6 7

*/









Measured memory_bytes: 11264
#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 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 <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();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    VL A(N+1),B(N);
    REP(i,N+1) cin >> A[i];
    REP(i,N) cin >> B[i];
    LL ans = 0;
    REP(i,N){
        if(B[i] >= A[i]){
            ans += A[i];
            B[i] -= A[i];

            if(B[i] >= A[i+1]){
                ans += A[i+1];
                A[i+1] = 0;
            }
            else{
                ans += B[i];
                A[i+1] -= B[i];
            }
        }
        else{
            ans += B[i];
        }

    }
    cout << ans << endl;

}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<int,P> PP;
struct edge { int to, cor; };
int w[105], v[105];
int dp[101][100005];
signed main() {
	int n, W; cin >> n >> W;
	rep(i, n)cin >> w[i] >> v[i];

	rep(i, n + 1)rep(j, 100005)dp[i][j] = inf;
	dp[0][0] = 0;

	rep(i, n) {
		rep(j, 100004) {
			if (j < v[i])dp[i + 1][j] = dp[i][j];
			else dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
		}
	}

	for (int j = 100004; j >= 0; j--) {
		if (dp[n][j] <= W) {
			cout << j << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 79104
#include<stdio.h>
int main()
{
    int W,H,i,j;
    for(i=1;;i++)
    {
        scanf("%d%d",&H,&W);
        if(H==0 && W==0){break;}
        for(i=1;i<=H;i++)
        {
            for(j=1;j<=W;j++)
            {
                printf("#");
            }
            printf("\n");
        }
         printf("\n");

    }



    return 0;
}




Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d); 
if(b>c && d>a)
	cout<<min(b,d)-max(a,c);
	else
	cout<<0;
 return 0;
}

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

using ld = long double;
using point = complex<ld>;
using polygon = vector<point>;

constexpr ld eps = 1e-8;

ld dot(point const& a, point const& b) {
    return std::real(std::conj(a) * b);
}
ld cross(point const& a, point const& b) {
    return std::imag(std::conj(a) * b);
}

int ccw(point a, point b, point c) {
    b -= a; c -= a;
    if(cross(b, c) > eps) return 1;            // a -> b -> c : counterclockwise
    if(cross(b, c) < -eps) return -1;          // a -> b -> c : clockwise
    if(dot(b, c) < 0) return 2;                // c -> a -> b : line
    if(std::norm(b) < std::norm(c)) return -2; // a -> b -> c : line
    return 0;                                  // a -> c -> b : line
}

polygon convex_hull(std::vector<point> ps) {
    std::sort(std::begin(ps), std::end(ps),
              [](point const& p1, point const& p2) {
                  return std::real(p1) < std::real(p2)
                                         || (std::real(p1) <= std::real(p2) && std::imag(p1) < std::imag(p2));
              });
    const int n = ps.size();
    int k = 0;
    polygon qs(2 * n);
    for(int i = 0; i < n; ++i) {
        while(k > 1 && ccw(qs[k - 2], qs[k - 1], ps[i]) <= 0) k--;
        qs[k++] = ps[i];
    }
    for(int i = n - 2, t = k; i >= 0; --i) {
        while(k > t && ccw(qs[k - 2], qs[k - 1], ps[i]) <= 0) k--;
        qs[k++] = ps[i];
    }
    qs.resize(k - 1);
    return qs;
}

class union_find {
public:
    union_find(int n) : par(n, -1) {}
    int root(int x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
    bool unite(int x, int y) {
        x = root(x), y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
private:
    vector<int> par;
};

struct edge {
    int u, v;
    ld cost;
    bool operator<(const edge& other) const {
        return cost < other.cost;
    }
};

int main() {
    int v, r;
    cin >> v >> r;
    vector<point> ps(v);
    for(int i = 0; i < v; ++i) {
        ld x, y;
        cin >> x >> y;
        ps[i] = point(x, y);
    }
    vector<edge> es;
    for(int i = 0; i < r; ++i) {
        int s, t;
        cin >> s >> t;
        es.push_back(edge{s - 1, t - 1, abs(ps[s - 1] - ps[t - 1])});
    }
    sort(begin(es), end(es));
    auto hull = convex_hull(ps);
    ld ans = 0;
    const int n = hull.size();
    union_find uf(v);
    for(int i = 0; i < n; ++i) {
        ans += abs(hull[i] - hull[(i + 1) % n]);
        int s = 0, t = 0;
        for(int j = 0; j < v; ++j) {
            if(abs(hull[i] - ps[j]) < eps) s = j;
            if(abs(hull[(i + 1) % n] - ps[j]) < eps) t = j;
        }
        uf.unite(s, t);
    }
    for(auto& e : es) {
        if(uf.unite(e.u, e.v)) {
            ans += e.cost;
        }
    }
    cout << fixed << setprecision(10) << ans << endl;
}



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


vector<pair<ll, int> > F;

void factorx(ll x){
    for (ll i = 2; i*i <= x; i++){
        if(x % i != 0){
            continue;
        } else {
            F.emplace_back(i, 0);
            while(x % i == 0){
                F.back().second++;
                x /= i;
            }
        }
    }
    if(x != 1){
        F.emplace_back(x, 1);
    }
    return;
}

int main() {
    ll A, B; cin >> A >> B;
    ll g = __gcd(A, B);
    factorx(g);
    int ans = F.size() + 1;
    /*rep(i, F.size()){
        cout << F[i].first << " " << F[i].second << endl;
    }*/
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace AOJ.Volume1
{
    public class AizuChicken
    {
        public static int Main()
        {
            while (true)
            {
                var input = Console.ReadLine();
                if (input == "0") { break; }

                var sp = input.Split(' ');
                int must = int.Parse(sp[0]);
                int cost = int.Parse(sp[1]);
                int pr_aizu = int.Parse(sp[2]);
                int pr_normal = int.Parse(sp[3]);
                int max = int.Parse(sp[4]);

                bool success = false;
                for (int aizu = max; aizu >= 1; aizu--)
                {
                    if (pr_aizu * aizu > cost) { continue; }
                    int tmp_c = cost - pr_aizu * aizu;
                    int normal = tmp_c / pr_normal;
                    if (aizu + normal >= must)
                    {
                        success = true;
                        Console.WriteLine(aizu + " " + normal);
                        break;
                    }
                }
                if (!success) { Console.WriteLine("NA"); }
            }

            return 0;
        }
    }
}

Measured memory_bytes: 9068
#include <iostream>
#include <cstdio>
#include <map>
#include <queue>


using namespace std;

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

typedef pair<int, int> PII;

int w, h, maps[102][102];
int dx[2][6] = { { 0, 1, 0, -1, -1, -1 },{ 1, 1, 1, 0, -1, 0 } };
int dy[6] = { -1, 0, 1, 1, 0, -1 };

inline bool check(int x, int y) {
	return x >= 0 && x < w && y >= 0 && y < h;
}

int main() {
	cin >> w >> h;
	REP(i, h) REP(j, w) scanf("%d", &maps[i + 1][j + 1]);
	w += 2; h += 2;
	
	queue<PII> q;
	q.push(MP(0, 0));

	while (!q.empty()) {
		PII now = q.front(); q.pop();
		int x = now.first, y = now.second;
		if (maps[y][x] == 2) continue;
		maps[y][x] = 2;
		REP(i, 6) {
			int nx = x + dx[y % 2][i];
			int ny = y + dy[i];
			if (check(nx, ny) && maps[ny][nx] == 0) q.push(MP(nx, ny));
		}

	}

	int ans = 0;
	FOR(i, 1, h - 1) FOR(j, 1, w - 1) if (maps[i][j] == 1) {
		REP(k, 6) {
			int nx = j + dx[i % 2][k];
			int ny = i + dy[k];
			if (check(nx, ny) && maps[ny][nx] == 2) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1312
import java.util.*;
public class Main {
	int n, ans;

	int dfs(int pos, int sum, int before) {
		int ret = 0;
		if(pos < 0) return(0);
		if(pos == 0 && sum == ans) return(1);
		if(before > 9 || sum > ans) return(0);
		for(int r =before; r< 10; r++) {
			ret += dfs(pos - 1, sum + r, r + 1);
		}

		return(ret);
	}

	void doIt()  {
		Scanner stdIn = new Scanner(System.in);

		while(true) {
			n = stdIn.nextInt();
			ans =stdIn.nextInt();
			if(n + ans == 0) break;

			System.out.println(dfs(n, 0, 0));
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().doIt();
	}

}

Measured memory_bytes: 18232
use std::io::stdin;
use std::mem::swap;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let hands: Vec<i32> = buf.trim().split_whitespace().map(|iter| iter.parse::<i32>().unwrap()).collect();
    let hands = [hands[0], hands[1], hands[2]];
    println!("{}", solve(hands));
}

fn solve(mut hand: [i32; 3]) -> i32{
    let mut temp_hand = [0; 3];
    let mut counter = 0;
    loop {
        if hand[0] % 2 != 0 || hand[1] % 2 != 0|| hand[2] % 2 != 0 {
            return counter;
        }
        if hand[0] == hand[1] && hand[1] == hand[2]{
            return -1;
        }

        temp_hand[0] = hand[1] / 2 + hand[2] / 2;
        temp_hand[1] = hand[2] / 2 + hand[0] / 2;
        temp_hand[2] = hand[0] / 2 + hand[1] / 2;
        hand = [0, 0, 0];
        swap(&mut hand, &mut temp_hand);
        counter += 1;
    }
}

Measured memory_bytes: 4352
/**
 *    author:  math2do
 *    created: 21.11.2019 17:48:29
**/

#include <bits/stdc++.h>

using namespace std;

const int N = (int) 1e5 + 1;
int dp[N];

class Graph {
private:
  int V;
  int E;
  vector <vector <int>> adj;
public:
  Graph(int n, int m);
  inline void addEdge(int src, int dst);
  int solve(int u);
};

Graph::Graph(int n, int m) {
  this->V = n;
  this->E = m;
  adj.resize(n);
}

inline void Graph::addEdge(int src, int dst) {
  adj[src].push_back(dst);
}

int Graph::solve(int u) {
  if (dp[u] != -1) return dp[u];
  int ans = 0;  
  for (int v : adj[u]) {
    ans = max(ans, 1 + solve(v));
  }
  return dp[u] = ans; 
} 

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  #ifdef LOCAL
    freopen("longest_path.in", "rt", stdin);
  #endif
  int V, E;
  cin >> V >> E;
  Graph g(V, E);
  for (int i = 0; i < E; i++) {
    int s, t;
    cin >> s >> t;
    s--; t--;
    g.addEdge(s, t);
  }
  memset(dp, -1, N * sizeof(int));

  int ans = 0;
  for (int i = 0; i < V; i++) {
    ans = max(ans, g.solve(i));
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
ll INF = 1e18;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> a(X), b(Y), c(Z), ab, abc;
    REP(i, X){
        cin >> a[i];
    }
    REP(i, Y){
        cin >> b[i];
    }
    REP(i, Z){
        cin >> c[i];
    }
    sort(a.begin(), a.end(), std::greater<ll>());
    sort(b.begin(), b.end(), std::greater<ll>());
    sort(c.begin(), c.end(), std::greater<ll>());
    REP(i, min(K, X)){
        REP(j, min(K, Y)){
            ab.push_back(a[i]+b[j]);
        }
    }
    sort(ab.begin(), ab.end(), std::greater<ll>());
    REP(i, min(X*Y,K)){
        REP(j, min(Z,K)){
            abc.push_back(ab[i]+c[j]);
        }
    }
    sort(abc.begin(), abc.end(), std::greater<ll>());
    REP(i, K){
        cout << abc[i] << endl;
    }
    return 0;
    
}


Measured memory_bytes: 43180