akhauriyash/Code-Regression huggingface dataset:
x,y,a,b,c = map(int,input().split())
A = sorted( list(map(int,input().split())) ,reverse=True)[:x]
B = sorted( list(map(int,input().split())) ,reverse=True)[:y]
C = sorted( list(map(int,input().split())) ,reverse=True)[:x+y]

ans = 0

la = x-1
lb = y-1

for cc in C:
  if la>=0 and lb>=0:
    if A[la]<B[lb]:
      if A[la]< cc:
        A[la] = cc
        la -= 1
    else:
      if B[lb]< cc:
        B[lb] = cc
        lb -= 1
  elif la>=0:
    if A[la]< cc:
      A[la] = cc
      la -= 1
  else:
    if B[lb]< cc:
      B[lb] = cc
      lb -= 1
print(sum(A)+sum(B))
    
  



Measured memory_bytes: 22192
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

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

ll N, L;

ll Grundy(ll x){
    ll ret = 1;
    if(x == 0){
        return 0;
    }

    while(x % 2 == 0){
        ret *= 2;
        x /= 2;
    }
    return ret;
}

class Trie{
public:
    Trie *zero, *one;
    ll depth;

    Trie(ll d){
        zero = nullptr;
        one = nullptr;
        depth = d;
    }

    void make_zero(){
        if(zero==nullptr){
            zero = new Trie(depth+1);
        }
    }

    void make_one(){
        if(one==nullptr){
            one = new Trie(depth+1);
        }
    }
};

ll solve(Trie t){
    ll ans = 0;
    if(t.zero==nullptr){
        ans^=Grundy(L-t.depth);
    }
    else{
        ans^=solve(*t.zero);
    }

    if(t.one==nullptr){
        ans^=Grundy(L-t.depth);
    }
    else{
        ans^=solve(*t.one);
    }

    return ans;
}


int main(){
    cin >> N >> L;
    Trie t = Trie(0);
    for(int i = 0; i < N; i++){
        string s;
        cin >> s;
        Trie *it = (&t);
        for(int j = 0; j < s.size(); j++){
            if(s[j] == '0'){
                it->make_zero();
                it = it->zero;
            }
            else{
                it->make_one();
                it = it->one;
            }
        }
    }

    if(solve(t) > 0){
        cout << "Alice" << endl;
    }
    else{
        cout << "Bob" << endl;
    }


    return 0;

}


Measured memory_bytes: 9728
using System;
using System.Collections.Generic;

namespace cswork {
    class Program {
        static void Main (string[] args) {
            // Contest166.Q4 ();

            long x = ReadInt ();

            bool hasDetect = false;
            for (int a = 0; !hasDetect; a++) {

                bool minusFlag = true;

                for (int b = 0; !hasDetect; b++) {
                    if (minusFlag) {
                        long ans1 = (long) Math.Pow (a, 5) - (long) Math.Pow (b, 5);

                        if (ans1 < 0) {
                            minusFlag = false;
                        }

                        if (ans1 == x) {
                            Write (a + " " + b);
                            hasDetect = true;
                        }
                    }

                    long ans2 = (long) Math.Pow (a, 5) - (long) Math.Pow (-b, 5);

                    if (ans2 == x) {
                        Write (a + " " + (-b));
                        hasDetect = true;
                    }

                    if (ans2 > x && !minusFlag) {
                        break;
                    }
                }
            }
            Exit ();
        }

        public static void Write (string str) {
            Console.WriteLine (str);
        }

        public static void Write (int i) {
            Console.WriteLine (i);
        }

        public static void Write (double d) {
            Console.WriteLine (d);
        }

        public static string Read () {
            return Console.ReadLine ();
        }

        public static int ReadInt () {
            return int.Parse (Console.ReadLine ());
        }

        public static long ReadLong () {
            return long.Parse (Console.ReadLine ());
        }

        public static double ReadDouble () {
            return double.Parse (Console.ReadLine ());
        }

        public static void Exit () { }

        public static List<string> GetList (string str, string delim) {
            return new List<string> (str.Split (delim));
        }

        public static List<int> GetListInt (string str, string delim) {
            List<string> list = new List<string> (str.Split (delim));
            return list.ConvertAll (x => int.Parse (x));
        }
    }
}

Measured memory_bytes: 27852
def readinput():
    n=int(input())
    c=list(input())
    return n,c

def findR(ir,c):
    i=ir
    while (i>=0 and c[i]=='W'):
        i-=1
    return i

def findW(iw,c):
    i=iw
    while(i<n and c[i]=='R'):
        i+=1
    return i

def main(n,c):
    iw=0
    iw=findW(iw,c)
    if iw==n:
        return 0
    ir=n-1
    ir=findR(ir,c)
    if ir==-1:
        return 0
    count=0
    while(iw<ir):
        #print(iw,ir)
        count+=1
        ir=findR(ir-1,c)
        iw=findW(iw+1,c)
    return count

if __name__=='__main__':
    n,c=readinput()
    ans=main(n,c)
    print(ans)


Measured memory_bytes: 10816
#include<iostream>
#include<math.h>
#include<algorithm>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)

using namespace std;

int main(){
	int n, max_a = 0, min_a = 1000000001;
	cin >> n;
	int a[n];
	REP(i,n){
		cin >> a[i];
		if(a[i] > max_a) max_a = a[i];
		if(a[i] < min_a) min_a = a[i];
	}
	cout << max_a - min_a << endl;
	return 0;
}


Measured memory_bytes: 384
// https://atcoder.jp/contests/abc132/tasks/abc132_b
#include <cstdio>

int N;
int a[21];

int main(int argc, char *argv[])
{
    scanf("%d", &N);
    for(int i=0;i<N;i++)
        scanf("%d", &a[i]);

    int cnt = 0;
    for(int i=1;i<N-1;i++) {
        if ((a[i-1] < a[i] && a[i] < a[i+1])
            || (a[i-1] > a[i] && a[i] > a[i+1]))
            cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}


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

#include <iostream>

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define FOR(i, a, b) for(int i = a;i < b;++i)
#define FORR(i, a, b) for(int i = b;i >= a;--i)
#define ALL(x) (x).begin(),(x).end()
#define INF 999999999
using namespace std;
#define lint long long

int main()
{
  lint N; cin >> N;
  lint a[N];
  REP(i,N) cin >> a[i];
 
  int flag = 0;
  int count = 0;
  int j = 1;
  REP(i,N){
    if(a[i] == j){
      flag = 1;
      ++j;
    }else{
      ++count; 
    }
    
  }
  if(flag){
    cout << count;
  }else{
    cout << -1;
  }
  return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i)
    {
        long long at;
        cin >> at;
        A[i] = at;
    }
    
    // i + A[i] = X && j - A[j] = X となる組(i, j) (i < j) の個数を求める
    map<long long, long long> L; // L[X] : i + A[i] = X となるiの個数 
    map<long long, long long> R; // R[X] : j - A[j] = X となるjの個数
    for (int i = 0; i < N; ++i)
    {
        long long leftval = i + A[i];
        ++L[leftval];
        long long rightval = i - A[i];
        if (rightval >= 0) ++R[rightval];
    }

    long long ans = 0;
    for (auto itr = L.begin(); itr != L.end(); ++itr)
    {
        long long ind = itr->first;
        ans += L[ind] * R[ind];
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int n,ans=0;
    string s1="",s2="",t;
    cin>>n;
    for(int i=0;i<n;i++)
        {
            cin>>t;
            s1+=t;
        }
    for(int i=0;i<n;i++)
        {
            cin>>t;
            s2+=t;
        }
    if(s1<s2)
        swap(s1,s2);
    while(s2!=s1)
    {
        ++ans;
        next_permutation(s2.begin(),s2.end());
    }
    cout<<ans;
}



Measured memory_bytes: 3632
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int a,b,k,i,j;
	scanf("%d %d %d",&a,&b,&k);
	if(b-a+1>=k*2)	{
		for(i=a;i<a+k;i++)	printf("%d\n",i);
		for(i=b-k+1;i<=b;i++)	printf("%d\n",i);
	}
	else {
		for(i=a;i<=b;i++)	printf("%d\n",i);
	}
	return 0;
}

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

int main() {
    int a, b; scanf("%d%d", &a, &b);
    if (a+b % 2) {
        printf("%d", (a+b+1)/2);  // Odd
    } else {
        printf("%d", (a+b)/2);  // Even
    }
    return 0;
}


Measured memory_bytes: 256
import numpy as np
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
asum = np.cumsum(a)
bsum = np.cumsum(list(reversed(b)))
v = []
for i in range(n):
    v.append(asum[i] + bsum[n - i - 1])
print(max(v))

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int H, N;
    cin >> H >> N;
    vector <int> A, B;
    rep(i, N){int a, b; cin >> a >> b; A.push_back(a); B.push_back(b);}

    int a_max = *max_element(A.begin(), A.end());
    vector <ll> dp; // dp[H] is final goal, but cost for dp[H + 1], dp[H + 2], ..., dp[H + a_max - 1] might be sometimes smaller
    rep(i, H + a_max){
        if (i == 0){dp.push_back(0); continue;}
        ll min_cost = MOD;
        rep(j, N){
            if (i - A.at(j) >= 0){
                if (min_cost > (B.at(j) + dp.at(i - A.at(j)))){
                    min_cost = B.at(j) + dp.at(i - A.at(j));
                }
            }
        }
        dp.push_back(min_cost);
    }
    ll ans = MOD;
    for(int i = H; i <= H + a_max - 1; i++){
        if (dp.at(i) < ans){ans = dp.at(i);}
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 512
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

//func nextString() string {
//	sc.Scan()
//	return sc.Text()
//}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

//func nextUint64() uint64 {
//	sc.Scan()
//	i, e := strconv.ParseUint(sc.Text(), 10, 64)
//	if e != nil {
//		panic(e)
//	}
//	return i
//}

func pow2(x int) int {
	ans := 1
	if x == 0 {
		// do nothing
	} else {
		for i := 0; i < x; i++ {
			ans *= 2
		}
	}
	return ans
}

func main() {
	a := nextInt()
	b := nextInt()
	c := nextInt()
	k := nextInt()
	ans := false

	for x := 0; x < 7; x++ {
		bb := b * pow2(x)
		cc := c * pow2(k - x)
		if a < bb && bb < cc {
			ans = true
			break
		}
	}

	if (ans) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1808
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <numeric>

using namespace std;

int main(){
   int a,b;
   cin>>a>>b;
   int ab;
   if(b<10)ab=10*a+b;
   else if(10<=b && b<100)ab=100*a+b;
   else ab=1000*a+b;
   for(int i=1;i*i<=ab;i++){
      if(i*i==ab){
         cout<<"Yes"<<endl;
         return 0;
      }
   }
   cout<<"No"<<endl;
}

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

int main(){
	int n,k;
  	double m = 0.0;
	cin >>n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		m += a[i];
    }
  	m = m / (double)n;
  	double t = 10000.0;
	for(int i = 0; i < n; i++) {
		if(t > abs(m - (double)(a[i])) ) {
          	t = abs(m - (double)(a[i]));
          	k = i;
        }
    }
  	cout << k << endl;
	
}


Measured memory_bytes: 256
S=input()
X=S.replace("x","")
N=len(X)
M=len(S)
for i in range(N):
    if X[i]!=X[-i-1]:
        print(-1)
        exit()
T=""
for i in range(M):
    if S[i]!="x":
        T=T+"o"
    else:
        T=T+"x"
U=[len(i) for i in T.split("o")]
ans=0
K=len(U)
for i in range(K):
    ans+=abs(U[i]-U[-i-1])
    tmp=max(U[i],U[-i-1])
    U[i]=tmp
    U[-1-i]=tmp
print(ans)

    

Measured memory_bytes: 4964
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		String[] W = new String[N];
		for (int i = 0; i < N; i++)
			W[i] = sc.next();
		boolean flag = false;

		for (int i = 0; i < N - 1; i++) {
			if (W[i].charAt(W[i].length() - 1) != W[i + 1].charAt(0))
				flag = true;
		}
		Arrays.sort(W);
		for (int i = 0; i < N - 1; i++) {
			if (W[i].equals(W[i + 1]))
				flag = true;
		}

		if (flag)
			System.out.println("No");
		else
			System.out.println("Yes");

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 21332
import numpy as np

N, M = input().split()
N = int(N)
M = int(M)

if N >= M:
    print(0)
else:
    X_m = np.array(sorted(list(map(lambda x: int(x), input().split()))))
    X_m_sub = np.array(X_m[1:]-X_m[:-1])
    
    pos_option = X_m_sub.argsort()
    
    for n in range(N-1):
        X_m_sub[pos_option[-(n+1)]] = 0
    
    print(X_m_sub.sum())

Measured memory_bytes: 23020
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
int main(){

  int N,D;
  cin>>N>>D;
  vector<vector<int>>X(N,vector<int>(D));
  for(int i=0;i<=N-1;i++){
  
    for(int j=0;j<=D-1;j++){
    
      cin>>X[i][j];
    }
  }
  int ansint=0;
  double ansdouble=0;
  int distance=0;
  int ans=0;
  for(int i=0;i<=N-2;i++){
  
    for(int j=i+1;j<=N-1;j++){
    
      distance=0;
      for(int k=0;k<=D-1;k++){
      
        distance+=(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
      }
      ansdouble=sqrt((double)distance);
      ansint=(int)(ansdouble);
      if((double)(ansint)==ansdouble){
        ans++;
      }
    }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3556
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;

const long long MOD = 1000000007;

int main(){
    long long N;
    cin >> N;
    long long cnt = 0;
    for(long long B = N - 1; B >= 1; B--){
        if(N % B != 0) cnt += N / B;
        else cnt += N / B - 1;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3608
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}
const MODULO: usize = 1_000_000_000 + 7;
fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();

    let mut ans = 0;

    for i in 0..60 {
        let mut count = 0;
        for j in 0..n {
            if a[j]>>i & 1 == 1 {
                count += 1;
            }
        }
        let mut a = (count * (n - count)) % MODULO;
        a *= ((2 as f64).powf(i as f64) as usize) % MODULO;
        ans += a % MODULO;
    }
    
    println!("{}", ans % MODULO);
}

Measured memory_bytes: 15608
from functools import reduce
from fractions import gcd
N, K = map(int, input().split())
X = sorted(list(map(int, input().split())) + [K])
# print(X)
S = [X[i+1] - X[i] for i in range(N)]
# print(S)
D = reduce(gcd, S, S[0])
print(D)


Measured memory_bytes: 16308
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    cout << (n - 2) * 180 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include <string.h>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
const ll mod=1e9+7;

int main(void){
    ll X,A;
    cin>>X>>A;
    if(X<A) cout<<0<<endl;
    else cout<<10<<endl;
    return 0;
}


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

int n;  int frq[10][10];

string s;

int main()
{
	
	cin>>n; long long sum=0;
	
	for( int i=1;i<=n;i++)
	{
		s= to_string(i);
		int l= s.size();
		
		if( s[l-1]!='0') //if last is zero first should be zero..but 01 is 1..so discard it
		{  
			int x= s[0]   - '0';
			int y= s[l-1] - '0';
			
			 // cout<<x<<" "<<y <<" 1st"<<endl;
			
			frq[x][y]++ ;  //to store first digit ans last digit occurence
		}
		
	}
	
	/* cout<<"freqarray"<<endl;
		
		for( int i=1;i<=9;i++)
		{   
		    cout<<"row"<<i<<"--> ";
			for( int j=1;j<=9;j++)
			cout<< frq[i][j]<<" ";
			cout<<endl;
		}
		
		*/
	
		//multiply a[i][j]*a[j][i] ...for i ,j how many element occurs
		
		for( int i=1;i<=9;i++)
		{
			for( int j=1;j<=9;j++)
			sum= sum + frq[i][j]*frq[j][i];  //total element
		}
		
		cout<<sum<<endl;
	}


Measured memory_bytes: 3768
n,m=map(int,input().split())
h=list(map(int,input().split()))
nex=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    nex[a-1].append(h[b-1])
    nex[b-1].append(h[a-1])
ans=0
for j in range(n):
    if nex[j]==[]:
        ans+=1
    else:
        if h[j]>max(nex[j]):
            ans+=1
print(ans)

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

int main(void){
  int a, b;
  cin >> a >> b;
  if(a >= 13){
    cout << b << endl;
  } else if(a >= 6 && a <= 12){
    cout << b/2 << endl;
  } else{
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<set>
#include<vector>
using namespace std;
#define PI acos(-1.0)
#define pppp cout<<endl;
#define EPS 1e-8
#define LL long long
#define ULL unsigned long long     //1844674407370955161
#define INT_INF 0x3f3f3f3f      //1061109567
#define LL_INF 0x3f3f3f3f3f3f3f3f //4557430888798830399
// ios::sync_with_stdio(false);
// 那么cin, 就不能跟C的 scanf，sscanf, getchar, fgets之类的一起使用了。
const int dr[]= {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[]= {-1, 1, 0, 0, -1, 1, -1, 1};
int read()//输入外挂
{
    int ret=0, flag=0;
    char ch;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        ret = ch - '0';
    while((ch=getchar())>='0'&&ch<='9')
        ret=ret*10+(ch-'0');
    return flag ? -ret : ret;
}
const LL mod = 1e9+7;


int p[1005], c[1005];
const LL N =1e6+10;
LL prime[N];
LL num_prime=0;  //prime存放着小于N的素数
int is_not_prime[N];        // is_not_prime[i]如果i不是素数，则为1
int Prime()
{
    is_not_prime[0]=1;
    is_not_prime[1]=1;
    for(LL  i=2 ; i<N ; i ++)
    {
        if(!is_not_prime[i])
            prime[num_prime++]=i;
        for(LL  j = 0 ; j<num_prime && i*prime[j]<N ; j ++)
        {
            is_not_prime[i*prime[j]]=1;
            if(!(i%prime[j]))
                break;
        }
    }
    return 0;
}
set<int> sett;
void Dec(LL x)
{
    for(int i=0; prime[i]*prime[i]<=x&&i<num_prime; i++)
    {
        if(x%prime[i]==0)
        {
            int num=0;
            while(x%prime[i]==0)
            {
                num++;
                x/=prime[i];
            }
            sett.insert(prime[i]);
            c[prime[i]]+=num;
        }
    }
    if(x>1)
    {
        sett.insert(x);
        c[x]+=1;
    }
}

int main()
{
    Prime();
    LL n;
    scanf("%lld",&n);
    for(int i=2; i<=n; i++)
        Dec(i);
    LL ans=1;
    set<int>::iterator it;
    for(it=sett.begin(); it!=sett.end(); it++)
        ans=(ans%mod*(c[*it]+1)%mod)%mod;
    printf("%lld\n",ans);
    return 0;
}


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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(int _##i = (t), i = (f); i <  _##i; i++)
#define downto(f, t, i)  for(int _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(int _##i = (t), i = (f); i >  _##i; i--)
typedef long double ld;
#define long long long

#if defined(EBUG) && !defined(ONLINE_JUDGE)
    #define debug true
    #define ln << endl
#else
    #define debug false
    #define ln << '\n'
#endif
#define tb << '\t'
#define sp << ' '

const int MOD = 1e9+7;

signed main() { // long: 64bit
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }

    int N, M; scanf("%d%d",&N,&M);
    vector<long> s1(M, 0), s0(M, 0);
    int B;
    long g = 0;
    times(N, i) {
        int A; scanf("%d",&A); --A;
        if(i && A != B) {
            int x = (B + 2) % M, y = (A + 1) % M;
            s1[x]++;
            s0[x] -= x;
            s1[y]--;
            if(x <= y) {
                s0[y] += x;
            } else {
                s1[0]++;
                s0[0] += M - x;
                s0[y] -= M - x;
            }
            g += (A - B + M) % M;
            if(debug) {
                cout << i sp << x sp << y ln;
                times(M, i) cout << s1[i] tb; cout ln;
                times(M, i) cout << s0[i] tb; cout ln;
            }
        }
        B = A;
    }
    uptil(1, M, i) {
        s1[i] += s1[i-1];
        s0[i] += s0[i-1];
    }
    if(debug) {
        times(M, i) cout << s1[i] tb; cout ln;
        times(M, i) cout << s0[i] tb; cout ln;
    }

    long ans = LLONG_MAX / 2;
    times(M, i) {
        if(debug) cout << i sp << g - s1[i] * (i+1) - s0[i] ln;
        ans = min(ans, g - s1[i] * (i+1) - s0[i]);
    }
    cout << ans ln;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin>> a >> b >> c;
    if(a<=100&&a>=1&&b<=100&&b>=1&&c<=100&&c>=1)
    {
    if(b-a==c-b) cout<< "YES";
    else cout<< "NO";
    return 0;
    }
    else return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    string s; cin >> s;
    int n = s.length();
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        if (s[i] != s[i + 1]) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	int N;
	cin >> N;
	int prev = -1;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int x;
		cin >> x;
		if (x == prev) {
			ans++;
			prev = -1;
		} else prev = x;
	}
	
	cout << ans << "\n";
	
	return 0;
}


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

#define X first
#define Y second
#define ll long long
#define mP make_pair
#define pB push_back 

int dp[10][500];

int main(){
	int n;
	cin >> n;
	int a[2][n + 10];
	for(int i = 0 ; i < 2 ; ++i){
		for(int j = 0 ; j < n ; ++j){
			cin >> a[i][j];
		}
	}

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

	dp[1][0] = dp[0][0] + a[1][0];

	for(int i = 1 ; i < n ; ++i){
		dp[1][i] = max(dp[0][i] , dp[1][i - 1]) + a[1][i];
	}

	cout << dp[1][n - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<string>
#include<cstdio>
#include<stack>
#include<cmath>
#include<bitset>
#include<memory>
#include<utility>
using namespace std;
#define FOR(i,m,n) for(i=m;i<n;i++)
#define CLR(a,b) memset(a,b,sizeof(a))
#define ROF(i,m,n) for(i=m;i>=n;i--)
#define BUG cout<<"debug"<<endl;
#define RT return
#define BK break
#define HEAP priority_queue
#define SP " "
#define lowf(a,b,c) lower_bound(a,b,c)
#define upf(a,b,c) upper_bound(a,b,c)
typedef long long LL;
typedef vector<int> VI;
const int INF = 2147483647;
const int NEN = -INF - 1;
const LL LINF = 9223372036854775807;
LL gcd(LL a, LL b)
{
	return b ? gcd(b, a%b):a;
}
int main()
{
	LL a, b,c;
	while (cin >> a >> b)
	{
		c = gcd(a, b);
		cout << c << " " << a*b / c << endl;
	}
    return 0;
}



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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X;
  cin >> X;
  
  if ( X == 25){
    cout << "Christmas" << endl;
  }
  else if ( X == 24){
    cout << "Christmas Eve" << endl;
  }
  else if ( X == 23){
    cout << "Christmas Eve Eve" << endl;
  }
  else if ( X == 22){
    cout << "Christmas Eve Eve Eve" << endl;
  }
}

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

using namespace std;

class range {
private:
  struct Iterator {
    int val;
    int operator*() {return val;}
    bool operator!=(Iterator &itr) {return val < itr.val;}
    void operator++() {++val;}
  };
  Iterator i, n;
public:
  range(int n) : i({0}), n({n}) {}
  range(int i, int n) : i({i}), n({n}) {}
  Iterator &begin() {return i;}
  Iterator &end() {return n;}
};

template<class T> T at(vector<T> v, int i) {return v[(i % (int)v.size() + v.size()) % v.size()];}

#include <sstream>

template<class A, class B> B convert(A a) {
  stringstream ss;
  ss << a;
  B b;
  ss >> b;
  return b;
}

int n, m, c[10];

const string INF = "999999";

string solve() {
  if (n == 0) {
    if (m >= 0) return "";
    return INF;
  }
  string res = INF;
  for (int i : range(10)) if (c[i] > 0) {
    --n;
    m -= c[i];
    string r = solve();
    if (r != INF) res = min(res, convert<int, string>(i) + r);
    m += c[i];
    ++n;
  }
  return res;
}

int main() {
  cin >> n >> m;
  for (int i : range(10)) cin >> c[i];
  string res = solve();
  if (res == INF) cout << "NA" << endl;
  else cout << res << endl;
}


Measured memory_bytes: 1236
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

// vector 操作  vector<int> data(10,5) 5が10個　data(10) 要素数10
// v.size(), v.empty(), v.insert(itr,値), v.erase(itr) (first,last),
// sort(itr), find(all(x),値),reverse(itr),accumulate(itr,0) 積算,
//v.swap
// stringも同じ itrがただの数字になる
// s.substr(n,m)n番目以降m文字取り出す　erase(n,m)も  s.find
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

// map 操作  map<string,int> mp キー=string 値=int型  pair< , >型
// 代入:mp["abc"]=123  mp.erase(キー)
// itr = mp.begin()のとき　itr->first = key, itr->second = val
// mp.find(key) itrを返す
typedef pair<int,int> P;  //q(p.first,p.second)で定義できる？

// lcm( , ) gcd( , ) 最大公約数　最小公倍数


int main (){
    ll int n,k; 
    cin >> n >> k;

    velli h(n);
    REP(i,n){
        cin >> h[i];
    }
    if(k>=n) cout << 0;
    else{
    sort(all(h));
    REP(i,k){
        h.pb2;
    }
    ll int ans=0;
    REP(i,h.size()){
        ans += h[i];
    }
    cout << ans;
    }
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    int A, B, K; cin >> A >> B >> K;
    REP(i, K){
        if(i % 2){
            A += B / 2; B /= 2;
        }else{
            B += A / 2; A /= 2;
        }
    }
    cout << A << " " << B << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void dfs(int, int, int);
int arr[10];
bool flag;
int main() {
  int n;
  cin >> n;
  while (n--) {
    for (int i = 0; i < 10; i++)
      cin >> arr[i];
    dfs(0, 0, 0);
    if (flag)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
    flag = false;
  }
  return 0;
}

void dfs(int sta1, int sta2, int index) {
  if (index == 10) {
    flag = true;
    return;
  }
  if (sta1 < arr[index]) {
    sta1 = arr[index];
    dfs(arr[index], sta2, index + 1);
  }
  if (sta2 < arr[index]) {
    sta2 = arr[index];
    dfs(sta1, sta2, index + 1);
  }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int n;cin>>n;
    string ans="Yes";
    int tx=0,ty=0,tt=0,t,x,y;
    for(int i=0;i<n;i++){
        cin>>t>>x>>y;
        if(abs(tx-x)+abs(ty-y)>t-tt){
            ans="No";break;
        }
        if((x+y)%2!=t%2){
            ans="No";break;
        }
        tx=x;ty=y;tt=t;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include <utility>
#include <queue>
#include <string>
#include <stack>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;

int main (void){
    int n, a, b;
    cin >> n >> a >> b;
    int k[n];
    for (int i = 0; i < n; i ++){
        cin >> k[i];
        
    }
    
    int count_1, count_2, count_3;
    count_1 = 0;
    count_2 = 0;
    count_3 = 0;
    
    for(int i = 0; i < n; i++){
        if(k[i] <= a){
            count_1++;
            
        }else if(k[i] > b){
            count_3++;
            
        }else{
            count_2 ++;
            
        }
    }
    cout << min({count_1,count_2,count_3}) << endl;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62




if __name__ == '__main__':
    a = input()
    if a.islower():
        print("a")
    else:
        print("A")



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

using namespace std;

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

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int n;
  cin >> n;
  int i;
  cin >> i;
  cout << n - i + 1 << endl;
}


Measured memory_bytes: 256
K = int(input())
id = 1
cnt = 7
while cnt < K:
    cnt = cnt * 10 + 7
    id += 1

visited = [0] * K
while True:
    remz = (cnt % K)
    if remz == 0:
        break
    visited[remz] += 1
    if visited[remz] > 1:
        id = -1
        break
    cnt = remz * 10 + 7
    id += 1

print(id)


Measured memory_bytes: 71360
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;
typedef long long int64;



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

  int x;
  cin>>x;

  vector<int> primelist;
  bool is_on_list[200000];
  for(int i=0;i<200000;i++){
    is_on_list[i]=true;
  }
  is_on_list[0]=false;
  is_on_list[1]=true;
  for(int start=2;start<=sqrt(200000);start++){
    if(!is_on_list[start]) continue;
    primelist.push_back(start);
    for(int tgt=start;tgt<=200000;tgt+=start){
      is_on_list[tgt]=false;
    }
  }
  for(int i=2;i<200000;i++){
    if(is_on_list[i]){
      primelist.push_back(i);
    }
  }

  std::sort(primelist.begin(), primelist.end());

  for(int i=0;i<primelist.size();i++){
    if(x<=primelist[i]){
      cout<<primelist[i]<<endl;
      return 0;
    }
  }







  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
const int MOD = 1e9+7;
vi alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z'};

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    if (K <= A) cout << K << endl;
    else if (K <= A + B) cout << A << endl;
    else cout << A - K + (A + B) << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define f(i,a,b) for(long long i=a;i<b;i++)
typedef long long ll;
using namespace std;

int main(){
	ll n,ans=0;cin>>n;
	if(n&1){
		cout<<"0\n";
		return 0;
	}
	ll p=10;
	while(n/p>0){
		ans+=n/p;p*=5;
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;
ll MOD = 1000000007;

int main()
{
    string s;
    cin >> s;
    ll N = s.length();
    ll P = 0;
    rep(i, N) {
        if (s[i] == 'p') P++;
    }
    cout << N / 2 - P << endl;
    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
using namespace std;
int a[100010];
int main() {
	int n, cnt = 0, sum, j;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) 
		scanf("%d", &a[i]);
	sort(a+1, a+1+n);
	for(int i = 1; i <= n;) {
		j = i, sum = 0;
		while(a[j] == a[i] && j <= n) {
			j ++;
			sum ++;
		}
		if(sum & 1) cnt ++;
		i = j;
	}
	printf("%d\n", cnt);
	return 0;
} 

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

using namespace std;

int main(){
  
  string S[100];
  int N;
  int L;
  
  cin>>N>>L;
  
  for(int i=0;i<N;i++){
   
    cin>>S[i];
    
  }
  
  sort(S,S+N);
  
   for(int i=0;i<N;i++){
   
    cout<<S[i];
    
  }
  
  
  return 0;
}


Measured memory_bytes: 256
/**
*    created: 14.06.2020 20:53:33
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int inf =1000000000;

int main() {
    rep(i,5){
        int x;
        cin >> x;
        if(x==0){
            cout << i+1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
using ld = long double;
const ld eps = 1e-9;

vector<pair<ld, int>>ps;

ld getdis(pair<ld, int>&f, pair<ld, int>&t) {
	return sqrt((f.first - t.first)*(f.first - t.first) + (f.second - t.second)*(f.second - t.second));
}
ld getdis(int from, int to) {
	return getdis(ps[from], ps[to]);
}

struct aa{
	int a;
	int b;
	ld time;
};
class Compare {
public:
	//aa?????????????????¶
	bool operator()(const aa&l, const aa&r) {
		return l.time> r.time;
	}
};
vector<int> getsta(const int now) {
	vector<int>sta;
	{

		int s;
		if (now == 0)s = -1;
		else if (ps[now - 1].second  < ps[now].second)s = 0;
		else if (ps[now - 1].second == ps[now].second)s = 1;
		else s = 2;
		sta.push_back(s);
	}
	sta.push_back(1);
	{

		int s;
		if (now == ps.size()-1)s = -1;
		else if (ps[now + 1].second < ps[now].second)s = 0;
		else if (ps[now  +1].second == ps[now].second)s = 1;
		else s = 2;
		sta.push_back(s);
	}
	return sta;
}
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		ps.clear();
		{
			set<int>ys;
			vector<pair<ld, int>>or_ps;
			for (int i = 0; i < N; ++i) {
				int x, y; cin >> x >> y;
				or_ps.emplace_back(x, y);
				ys.emplace(y);
			}
			for (int i = 0; i < N - 1; ++i) {
				ps.emplace_back(or_ps[i]);
				for (auto y : ys) {
					if ((or_ps[i].second < y&&y < or_ps[i + 1].second) || (or_ps[i + 1].second < y&&y<or_ps[i].second)) {
						ld x = or_ps[i].first + (or_ps[i + 1].first - or_ps[i].first)*(ld(y - or_ps[i].second) / (or_ps[i + 1].second - or_ps[i].second));
						ps.emplace_back(ld(x), y);
					}
				}
			}
			ps.emplace_back(or_ps[N - 1]);
			sort(ps.begin(), ps.end());
		}
		priority_queue<aa, vector<aa>, Compare>que;
		que.push(aa{ 0, int(ps.size()) - 1, 0});
		map<pair<int, int>, ld>memo;
		memo[make_pair(0, ps.size()-1)] = 0;
		ld ans = 0;
		while (!que.empty()) {
			aa atop(que.top());
			que.pop();
			const int nowa = atop.a;
			const int nowb = atop.b;
			const ld nowtime = atop.time;
			if (nowa == nowb) {
				ans = nowtime;
				break;
			}
			vector<int>astatus, bstatus;
			astatus = getsta(nowa);
			bstatus = getsta(nowb);
			for (int i = 0; i < 3; ++i) {
				if (astatus[i] == -1)continue; 
				for (int j = 0; j < 3; ++j) {
					if (bstatus[j] == -1)continue;
					if (astatus[i] == bstatus[j]) {
						const int nexta = nowa + i - 1;
						const int nextb = nowb + j - 1;
						const ld nexttime = nowtime + getdis(nowa, nexta) + getdis(nowb, nextb);
						auto it = memo.find(make_pair(nexta, nextb));
						if (it == memo.end() || it->second>nexttime+eps) {
							memo[make_pair(nexta, nextb)] = nexttime;
							que.push(aa{ nexta,nextb,nexttime });
						}
					}
					
				}
			}
		}
		cout <<fixed<<setprecision(22)<< ans << endl;
		
	}
	return 0;
}

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

int main() {
	long long s;
	long long si,mi,a,b;
	cin>>s;
	si=3;
	mi=1000;
	for(long long i=10000;i<=10000000000;i*=10){
		si++;
		if(s<i){
			a=i;
			break;
		}
	}
	for(long long i=1;i<(a/100);i*=10){
		b=s/i-s/(i*1000)*1000;
		if(abs(b-753)<mi){
			mi=abs(b-753);
		}
	}
	cout<<mi<<endl;
}

Measured memory_bytes: 256
#include <vector>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <map>
#include <unordered_map>
#include <ctime>
#include <cassert>
#include <cstring>
#include <sys/time.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[]){
  int n;
  cin >> n;
  vector <int> l;
  for(int i=0;i<n;i++){
    int ll;
    cin >> ll;
    l.push_back(ll);
  }
  sort(l.begin(),l.end());
  int t = 0;
  for(int i=0;i<n-2;i++){
    int a = l[i];
    for(int j=i+1;j<n-1;j++){
      int b = l[j];
      for(int k=j+1;k<n;k++){
        int c = l[k];
        if(c>=a+b){
          break;
        }
        if(a<b+c&&b<c+a&&c<a+b){
          t++;
        }
      }
    }
  }
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <fstream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <bitset>
#include <ctime>
#include <set>
#include <cmath>
#include <unordered_map>
#include <iomanip>
#include <map>
#include <stack>
#include <vector>
#include <bitset>
#include <functional>
#include <iostream>

using namespace std;

#define FOR(i, a, n) for (int i = a; i <= n; ++i)
#define FORN(a, n) for (int i = a; i < n; ++i)
#define ROF(i, n, a) for (int i = n; i >= a; i--)
#define ROFN(n, a) for (int i = n - 1; i >= a; i--)
#define FIT(i, v) for (auto &i : v)
#define pb push_back
#define mp make_pair
#define mt make_touple
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define log log2

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const long long mod = 1000000007;
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; }

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);

	vector<int> v1 = { 1, 3, 5, 7, 8, 10, 12 };
	vector<int> v2 = { 4, 6, 9, 11 };
	
	int x, y;
	cin >> x >> y;
	if (x == 2 && y == 2) {
		cout << "Yes";
		return 0;
	}

	int ok = 0;

	for (int i = 0; i < v1.size(); ++i) {
		if (x == v1[i]) {
			ok++;
		}
		if (y == v1[i]) {
			ok++;
		}
	}

	if (ok == 2) {
		cout << "Yes";
		return 0;
	}
	ok = 0;

	for (int i = 0; i < v2.size(); ++i) {
		if (x == v2[i]) {
			ok++;
		}
		if (y == v2[i]) {
			ok++;
		}
	}
	if (ok == 2) {
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  int A, B;
  cin >> A >> B;
  cout << max(A+B, max(A-B, A*B)) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<char,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;


int main(){
    int x,y,z,k;cin >> x >> y >> z >> k;
    vector<LL> a(x),b(y),c(z);
    for (int i = 0; i < x; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < y; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < z; i++) {
        cin >> c[i];
    }
    vector<LL> s;
    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            s.pb(a[i]+b[j]);
        }
    }
    sort(ALL(s));
    LL l=0,r=30000000001;
    while(abs(r-l)>1){
        LL mid = (r+l)/2;
        int sum = 0;
        for (int i = 0; i < z; i++) {
            sum += s.size()-(lower_bound(ALL(s),mid-c[i])-s.begin());
        }
        if(sum>=k) l = mid;
        else r = mid;
    }
    vector<LL> ans;
    for (int i = z-1; i >= 0; i--) {
        for (int j = s.size()-1; j >= 0; j--) {
            if(s[j]+c[i]<l) break;
            ans.pb(s[j]+c[i]);
        }
    }
    sort(RALL(ans));
    for (int i = 0; i < k; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


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

int main()

{
    int ar[11];
    int i,j;
    for(i=0;i<10;i++)
        scanf("%d",&ar[i]);
    sort(ar, ar+10);
    for(j=9;j>6;j--){
        printf("%d\n",ar[j]);
    }

    return 0;
}

Measured memory_bytes: 1204