jiahuimbzuai/CoQuIR huggingface dataset:
//  [cpp]
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;
using ll = long long;
const ll INF = 1010101010;
ll n, m, a,b, add, ans=INF, A[101010], B[101010];
void solve() {
	if (B[0] < 0 && 0 <= B[m-1]) ans = min(ans, min(abs(B[0]), B[m-1]) * 2 + max(abs(B[0]), B[m-1]));
	else ans = min(ans, max(abs(B[0]), abs(B[m-1])));
}
int main() {
	cin >> n >> m;
	rep(i, n) cin >> A[i];
	rep(i, n - m + 1) {
		for (int j = 0; j < m; j++) {
			B[j] = A[i + j];
		}
		solve();
	}
	cout << ans << endl;
	return 0;
}
//  [cpp]
#include <iostream>
using namespace std;
int n,k,c,a,t1,t2,xp[100001],xn[100001],mini=2147483647;
int main()
{ cin>>n>>k;
  for(int i=1;i<=n;i++)
  { cin>>a;
    if(a>=0)
       xp[++xp[0]]=a;
    else
       xn[++xn[0]]=-a;
  }
  for(int i=0;i<=min(xp[0],k);i++)
  { if(k-i>xn[0])
       continue;
    a=0; t1=0;
    for(int j=1;j<=i;j++)
      t1+=xp[j]-a,a=xp[j];
    a=0; t2=0;
    for(int j=xn[0];j>=xn[0]-k+i+1;j--)
      t2+=xn[j]-a,a=xn[j];
    if(t1<t2)
       swap(t1,t2);
    t1+=t2*2;
    mini=min(mini,t1);
  }
  cout<<mini;
  return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


int main() {
    int N, K;  cin >> N >> K;
    vector<int> x(N);  rep(i, N) cin >> x[i];

    ll ans = INF;
    rep(i, N-K+1) {
        ll sum = 0;
        rep(j, K-1) {
            sum += x[i+j+1] - x[i+j];
        }
        sum += min(abs(x[i+K-1]), abs(x[i]));
        ans = min(ans, sum);
    }

    print(ans);
}
//  [c]
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int n, k;
    
    int i, j;
    
    long int fir = 1000000000;
    
    long int data[100000];
    long int sum[100000];
    long int kyo[100000];
    long int zet[100000];
    
    
    scanf("%d %d\n", &n, &k);
    
    for(i = 0; i < n; i++) {
        if(i == n - 1) {
            scanf("%ld", &data[i]);
        } else {
            scanf("%ld ", &data[i]);
        }
    }
    
    for(i = 0; i < 100000; i++) {
        sum[i] = 0;
        zet[i] = labs(data[i]);
        if(i < n - 1) {
            kyo[i] = labs(data[i + 1] - data[i]);
        }
    }
    
    for(i = 0; i < n - 1; i++) {
        //printf("%ld\n", kyo[i]);
    }
    
    
    
    for(i = 0; i < n - k + 1; i++) {
        for(j = i; j < i + k - 1; j++) {
            
            sum[i] += kyo[j];
            
        }
        
        if(zet[i]  <= zet[i + k - 1]) {
            sum[i] += zet[i];
        } else {
            sum[i] += zet[i + k - 1];
        }
        
        //printf("%d~%d:%ld\n", i, i + k - 1, sum[i]);
    }
    
    for(i = 0; i < n - k + 1; i++) {
        if(fir > sum[i]) {
            fir = sum[i];
        }
    }
    
    printf("%ld\n", fir);
    
    
    
    return 0;
}
//  [c]
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int min(int x,int y){
	return x<y? x: y;
}

int main(void){
	int N,K,ans=0,i,p=1e9;
	scanf("%d%d",&N,&K);
	int x[N],kouho[K];
	int set,left,right;
	for(i=0;i<N;i++){scanf("%d",&x[i]);}
	
	for(i=0;i<N-K+1;i++){
		set = 0;
		ans = 0;
		int j = i;
		while(set<K){//K個
			kouho[set] = x[j];
			set++;
			j++;
		}
		left = kouho[0];
		right = kouho[K-1];
		ans += min(abs(left),abs(right));
		ans += abs(right - left);
		if(ans<p) p = ans;
	}
	
	
	printf("%d",p);
	
	return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int getmin(int a,int b);

int main(){
    int n,k,r1,r2;
    scanf("%d %d",&n,&k);
    int x[n];
    int R[n];
    for(int i=0;i<n;i++){
        scanf("%d",&x[i]);
    }
    for(int j=0;j<n-k+1;j++){
        r1=abs(x[j])+abs(x[j]-x[k+j-1]);
        r2=abs(x[k+j-1])+abs(x[k+j-1]-x[j]);
        R[j]=getmin(r1,r2);
    }
    /*for(int i=0;i<n-k+1;i++){
        printf("R[%d]=%d ",i,R[i]);
    }
    printf("\n");*/
    for(int i=0;i<n-k+1;i++){
        for(int j=i+1;j<n-k+1;j++){
            if(R[i]>R[j]){
                int tmp=R[i];
                R[i]=R[j];
                R[j]=tmp;
            }
        }
    }
    /*for(int i=0;i<n-k+1;i++){
        printf("R[%d]=%d ",i,R[i]);
    }*/
    printf("%d",R[0]);
    return 0;
}

int getmin(int a,int b){
    int c;
    if(a>=b){
        c=b;
    }else{
        c=a;
    }
    return c;
}
//  [javascript]
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
N = l.shift() * 1
K = l.shift() * 1 
l = inp.shift().split(' ').map(x => x - 0)
n = []
p = []
for (i=0; i<N; i++) {
    if (l[i] < 0) {
        n.unshift(Math.abs(l[i]))
    } else {
        if (l[i] === 0) {
            K--
            N--
        } else {
            p.push(l[i])
        }
    }
}
if (K === 0) {
    console.log(0)
} else {
    min = Infinity
    if (n[K-1]) {
        if (n[K-1] < min) {
            min = n[K-1]
        }
    }
    if (p[K-1]) {
        if (p[K-1] < min) {
            min = p[K-1]
        }
    }
    c = Math.min(p.length, n.length)
    for (i=0;i<c;i++) {
        if (n[i] && p[K - i - 2]) {
            m = n[i] * 2 + p[K - i - 2]
            if (m < min) {
                min = m
            }
        }
        if (p[i] && n[K - i - 2]) {
            m = p[i] * 2 + n[K - i - 2]
            if (m < min) {
                min = m
            }
        }
    }
    console.log(min)    
}
//  [javascript]
'use strict'

const main = (input) => {
    input = input.split('\n')
    const N = parseInt(input[0].split(' ')[0])
    const K = parseInt(input[0].split(' ')[1])
    const arr = input[1].split(' ').map(v => parseInt(v))

    let dist = 100000000000
    // 通るべき点を調べ上げる
    for(let i = 0; i <= arr.length - K; i++){
        let left = arr[i]
        let right = arr[i + K - 1]
        // 左端からスタートするときの距離
        const a = Math.abs(left) + Math.abs(left - right)
        // 右端からスタートするときの距離
        const b = Math.abs(right) + Math.abs(right - left)
        const min = Math.min(a, b)
        if(dist > min){
            dist = min
        }
    }
    console.log(dist)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))
//  [go]
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Thu Dec  6 02:18:23 2018
//
package main

import (
	"fmt"
	"sort"
)

var N, K int

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func timeMin(first []int, second []int) int {
	timeMin := 1000000000
	for i := 1; i <= K; i++ {
		if i <= len(first) && K-i <= len(second) {
			var time int
			if K-i-1 < 0 {
				time = first[i-1]
			} else {
				time = 2*first[i-1] + second[K-i-1]
			}

			timeMin = min(time, timeMin)
		}
	}

	return timeMin
}

func main() {
	fmt.Scan(&N, &K)

	var left, right []int
	for i := 0; i < N; i++ {
		var x int
		fmt.Scan(&x)
		if x < 0 {
			left = append(left, -x)
		} else {
			right = append(right, x)
		}
	}
	sort.Ints(left)

	fmt.Println(min(timeMin(left, right), timeMin(right, left)))
}
//  [go]
package main

import (
	"fmt"
	"math"
)

func main() {
	// 入力の受け取り
	var N, K int
	fmt.Scanf("%d%d", &N, &K)
	xs := make([]int, N)

	for i := 0; i < N; i++ {
		var c int
		fmt.Scanf("%d", &c)
		xs[i] = c
	}

	allPosi := xs[0] >= 0
	allNega := xs[len(xs)-1] < 0

	// 処理
	minDist := math.MaxInt64

	if allPosi {
		minDist = xs[K-1]
	} else if allNega {
		minDist = abs(xs[len(xs)-K])
	} else {
		for l := 0; l < N-K+1; l++ {
			r := l + K - 1
			dist := abs(xs[l]-xs[r]) + min(abs(xs[l]), abs(xs[r]))
			minDist = min(minDist, dist)
		}

	}
	fmt.Printf("%d", minDist)
}

func min(x int, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

func abs(x int) int {
	if x < 0 {
		return -x
	} else {
		return x
	}
}
//  [go]
// きりみんちゃんの配信からきました
// 左右をとる+-1のしゃくとり、左がマイナスかつ右がプラスの場合には「左に行った後折り返す」vs「右に行ったあと折り返す」が発生する
// ゼロ含む場合マジでなんなんだよ
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n)
	includeZero := false
	zeroIdx := -1
	for i := 0; i < n; i++ {
		var j int
		fmt.Scan(&j)
		a[i] = j
		if j == 0 {
			includeZero = true
			zeroIdx = i
		}
	}
	if includeZero && n > 1 {
		if zeroIdx != 0 && zeroIdx != n-1 {
			if abs(a[zeroIdx-1]) < abs(a[zeroIdx+1]) {
				a[zeroIdx] = a[zeroIdx-1]
			} else {
				a[zeroIdx] = a[zeroIdx+1]
			}
			// a[zeroIdx] = min(a[zeroIdx-1], a[zeroIdx+1])
			// } else {
			// 	a[zeroIdx] = a[zeroIdx+1]
		}
	}
	ans := 10000000000000000
	r := 0
	tmp := 0
	for l := 0; l <= n-k; l++ {
		for r < n && r-l < k {
			tmp += a[r]
			r += 1
		}
		if a[r-1] <= 0 {
			tmp = a[l] * -1
		} else if a[l] >= 0 {
			tmp = a[r-1]
		} else if a[l] < 0 {
			tmp = min(a[l]*-2+a[r-1], a[r-1]*2+a[l]*-1)
		}
		// fmt.Println(a[l:r], tmp)
		ans = min(ans, tmp)
		tmp -= a[l]
	}
	fmt.Println(ans)
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}
//  [ruby]
n, k = gets.split.map(&:to_i)
candles = gets.split.map(&:to_i)
min = nil

# 座標0以上に存在してるろうそくを取得
candles_0_right = candles.map { |position| position >= 0 ? position : nil }.compact
# 座標0以下に存在してるろうそくを取得
candles_0_left  = candles.map { |position| position <= 0 ? position : nil }.compact.reverse

# まず右に行って、途中で左に折り返すパターン
k.step(1, -1) do |i| # i = 3, 2, 1 (折り返すまでに右側から取得する個数)
  current = 0 # 現時点での座標、スタート時には0
  time = 0 # 移動に費やした時間

  # 座標0以上に存在しているろうそくの個数が、取得したい個数よりも少ない場合は諦める
  next if i > candles_0_right.count

  # 右側からi個取得したあとの座標を更新し、移動時間に足し込む
  time += (candles_0_right[i-1] - current).abs
  current = candles_0_right[i-1]

  # ここから折り返し、k-i個を取得する
  if k - i > 0
    # 座標0以下に存在しているろうそくの個数が、取得したい個数よりも少ない場合は諦める
    next if k - i > candles_0_left.count

    # 左側からk-i個取得した場合の移動時間を計算する
    time += (candles_0_left[k-i-1] - current).abs
  end
  min = [min, time].compact.min
end

# 逆パターン
k.step(1, -1) do |i|
  current = 0
  time = 0
  next if i > candles_0_left.count
  time += (candles_0_left[i-1] - current).abs
  current = candles_0_left[i-1]
  if k - i > 0
    next if k - i > candles_0_right.count
    time += (candles_0_right[k-i-1] - current).abs
  end
  min = [min, time].compact.min
end

puts min
//  [ruby]
io = STDIN
n,$k=io.gets.split.map(&:to_i)
ar = io.gets.split.map(&:to_i)
plus =ar.select{|x|x>=0}
minus =ar.select{|x|x<0}.map{|x|-x}.reverse
def calc2(pct,mct,plus,minus)
  min=[plus[pct-1],minus[mct-1]].min
  max=[plus[pct-1],minus[mct-1]].max
  min*2 + max
end
def calc(ar,plus,minus)
  ans=Float::INFINITY
  (0..plus.size).each do |pct|
    mct=$k-pct
    if mct <= minus.size
      ans=[ans,calc2(pct,mct,plus,minus)].min
    end
  end
  ans
end
if plus ==[]
  puts minus[$k-1]
elsif minus ==[]
  puts plus[$k-1]
else
  puts calc(ar,plus,minus)
end
//  [ruby]
n, k = gets.split.map(&:to_i)
left = gets.split.map(&:to_i)
right = []

while !left.empty? && left[-1] > 0
    right.push(left.pop)
end

right = right.reverse()
left = left.reverse().map{|n| -n}

puts (k + 1).times.map{|count|
    if count > left.size || k - count > right.size
        300000000
    else
        l = left[count - 1]
        r = right[k - count -1]
        l = 0 if l == nil
        r = 0 if r == nil
        [l, r].min() * 2 + [l, r].max()
    end
}.min()
//  [rust]
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let mut N: usize = read();
    let mut K: usize = read();
    let mut minuses = vec![];
    let mut pluses = vec![];
    for _ in 0..N {
        let val: i32 = read();
        match val.cmp(&0) {
            std::cmp::Ordering::Equal => {
                N -= 1;
                K -= 1;
            }
            std::cmp::Ordering::Less => {
                minuses.push(-val as u64);
            }
            std::cmp::Ordering::Greater => {
                pluses.push(val as u64);
            }
        }
    }
    if K == 0 {
        println!("0");
        return;
    }
    minuses.reverse();
    let mut ans = std::u64::MAX;
    for (one, another) in &[(&minuses, &pluses), (&pluses, &minuses)] {
        for (i, &v) in one.iter().enumerate() {
            if K == i + 1 {
                ans = std::cmp::min(ans, v);
                break;
            }
            if K - i - 1 > another.len() {
                continue;
            }
            // dbg!(K, i, v, K - i - 2, another[K - i - 2]);
            ans = std::cmp::min(ans, v * 2 + another[K - i - 2]);
        }
    }
    println!("{}", ans);
}
//  [python]
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [[] for i in range(M)]
for i in range(M):
    AB[i] = list(map(int, input().split()))

cnt = 0
memo_loser = []
for bridge in AB:
    

    value = min(H[bridge[0]-1], H[bridge[1]-1])
    if value == H[bridge[0]-1] and not bridge[0] in memo_loser:
        memo_loser.append(bridge[0])
    if value == H[bridge[1] - 1] and not bridge[1] in memo_loser:
        memo_loser.append(bridge[1])
print(N - len(memo_loser))
//  [python]
N,M=list(map(int,input().split()))
H=list(map(int,input().split()))

bad=[]
for i in range(M):
	A,B=list(map(int,input().split()))
	if (H[A-1]<=H[B-1])and(A-1 not in bad): bad.append(A-1)
	if (H[A-1]>=H[B-1])and(B-1 not in bad): bad.append(B-1)

print(N-len(bad))
//  [python]
n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = []
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] < h[b-1]:
        if not a-1 in ans:
            ans.append(a-1)
    elif h[a-1] > h[b-1]:
        if not b-1 in ans:
            ans.append(b-1)
    else:
        if not a-1 in ans:
            ans.append(a-1)
        if not b-1 in ans:
            ans.append(b-1)
print(n-len(ans))
//  [java]
import java.util.*;
import java.util.ArrayList;

public class Main {

	public static class SparseGraph {
		private int n, m;
		private boolean directed;
		private ArrayList<ArrayList<Weight>> g;

		SparseGraph(int n, boolean directed) {
			this.n = n;
			this.m = 0;
			this.g = new ArrayList<>();
			this.directed = directed;
			for (int i = 0; i < n; i++) {
				g.add(i, new ArrayList<>());
			}
		}

		private void checkOutOfRange(int v) {
			if (v > n || v < 0) {
				throw new IllegalArgumentException("v is out of range");
			}
		}

		public int V() {
			return this.n;
		}

		public int E() {
			return this.m;
		}

		public void addEdge(int v, Weight weight) {
			if (this.hasEdge(v, weight)) {
				return;
			}
			g.get(v).add(weight);
			if (!directed) {
				int b = weight.getB();
				g.get(b).add(new Weight(b, v, (-1)*weight.getWeight()));
			}
			m++;
		}

		public boolean hasEdge(int v, Weight weight) {
			return g.get(v).contains(weight);
		}

		public List<Weight> adj(int v) {
			return g.get(v);
		}
	}

	private static List<Long> getStrings(Scanner sc, int num) {
		List<Long> stringList = new ArrayList<>();
		while(num>0) {
			long nextInt = sc.nextLong();
			stringList.add(nextInt);
			num--;
		}
		return stringList;
	}

	private static List<Ab> getEdge(Scanner sc, int num) {
		List<Ab> stringList = new ArrayList<>();
		while(num>0) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			stringList.add(new Ab(a ,b));
			num--;
		}
		return stringList;
	}

	private static class Weight{
		private int a;
		private int b;
		private long weight;

		public Weight(int a, int b, long weight) {
			this.a = a;
			this.b = b;
			this.weight = weight;
		}

		public int getA() {
			return a;
		}

		public void setA(int a) {
			this.a = a;
		}

		public int getB() {
			return b;
		}

		public void setB(int b) {
			this.b = b;
		}

		public long getWeight() {
			return weight;
		}

		public void setWeight(long weight) {
			this.weight = weight;
		}
	}

	private static class Ab{
		private int a;
		private int b;

		public Ab(int a, int b) {
			this.a = a;
			this.b = b;
		}

		public int getA() {
			return a;
		}

		public void setA(int a) {
			this.a = a;
		}

		public int getB() {
			return b;
		}

		public void setB(int b) {
			this.b = b;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		List<Long> hs = getStrings(sc, n);
		List<Ab> abs = getEdge(sc, m);
		SparseGraph sparseGraph = new SparseGraph(n+1, false);
		for (int i = 0; i < abs.size(); i++) {
			int aindex = abs.get(i).a;
			int bindex = abs.get(i).b;
			sparseGraph.addEdge(abs.get(i).a, new Weight(aindex, bindex, hs.get(bindex-1)- hs.get(aindex-1)));
		}
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			List<Weight> list = sparseGraph.adj(i);
			if (list.isEmpty()) {
				sum++;
				continue;
			} else {
				boolean flag = false;
				for (int j = 0; j < list.size(); j++) {
					if (list.get(j).getWeight() >= 0) {
						flag = true;
						break;
					}
				}
				if (!flag) {
					sum++;
				}

			}
		}
		System.out.println(sum);
	}

}
//  [java]
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		int M = Integer.parseInt(sc.get());
		int[] H = new int[N];
		Arrays.setAll(H, $ -> Integer.parseInt(sc.get()));

		var ROADS = new BitSet[N];
		for (int i = 0; i < M; i++) {
			int A = Integer.parseInt(sc.get()) - 1;
			int B = Integer.parseInt(sc.get()) - 1;
			var fromA = ROADS[A];
			if (fromA == null) fromA = ROADS[A] = new BitSet();
			var fromB = ROADS[B];
			if (fromB == null) fromB = ROADS[B] = new BitSet();
			fromA.set(B);
			fromB.set(A);
		}

		int count = 0;
		tower:
		for (int i = 0; i < N; i++) {
			var roads = ROADS[i];
			if (roads == null) {
				count += 1;
				continue;
			}
			var height = H[i];
			var iterator = roads.stream().iterator();
			while (iterator.hasNext()) {
				int next = iterator.nextInt();
				if (height <= H[next]) continue tower;
			}
			count += 1;
		}
		System.out.println(count);
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M, i, j;
  cin >> N >> M;
  vector<int> vec(N);
  vector<int> vec2;
  vec2.insert(vec2.begin()+0, -1);
  int z = 1;
  for(i = 0; i < N; i++){
    int a;
    cin >> a;
    vec[i] = a;
  }
  for(i = 0; i < M; i++){
    int b, c;
    cin >> b >> c;
    if(vec[b-1] < vec[c-1]){
      for(j = 0; j < z; j++){
        if(vec2[j] == b){
          break;
        }
      }
      if(j == z){
        vec2.insert(vec2.begin()+0, b);
        z++;
      }
    }else if(vec[b-1] > vec[c-1]){
      for(j = 0; j < z; j++){
        if(vec2[j] == c){
          break;
        }
      }
      if(j == z){
        vec2.insert(vec2.begin()+0, c);
        z++;
      }
    }else{
      for(j = 0; j < z; j++){
        if(vec2[j] == b){
          break;
        }
      }
      if(j == z){
        vec2.insert(vec2.begin()+0, b);
        z++;
      }
      for(j = 0; j < z; j++){
        if(vec2[j] == c){
          break;
        }
      }
      if(j == z){
        vec2.insert(vec2.begin()+0, c);
        z++;
      }
    }
  }
  
  cout << N - z + 1 << endl;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,c=0;
    cin>>n>>m;
    int h[n+1];
    int f[n+1]={};
    for(int i=1;i<n+1;i++)
        cin>>h[i];
    vector<int> r[n+1]; 
    for(int i=1;i<=m;i++)
    {
        int ai,bi;
        cin>>ai>>bi;
        if(!count(r[ai].begin(),r[ai].end(),bi))
        {
            r[ai].push_back(bi);
            if(h[ai]<=h[bi])
                f[ai]++;
        }
        if(!count(r[bi].begin(),r[bi].end(),ai))
        {
            r[bi].push_back(ai);
            if(h[bi]<=h[ai])
                f[bi]++;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(!f[i])
            c++;
    }
    cout<<c;
    return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>

int comp(const void *p1,const void *p2);

typedef struct{
	int ti;
	int tj;
} observatories;

int main(void){
	int n,m,i,now,flg,ans;
	int *h;
	observatories*obs;
	scanf("%d%d",&n,&m);
	h=(int *)calloc(n,sizeof(int));
	obs=(observatories *)calloc(2*m,sizeof(observatories));
	for(i=0;i<n;i++) scanf("%d",&h[i]);
	for(i=0;i<m;i++){
		scanf("%d%d",&obs[i].ti,&obs[i].tj);
		obs[m+i].ti=obs[i].tj;
		obs[m+i].tj=obs[i].ti;
	}
	
	qsort(obs,2*m,sizeof(observatories),comp);
	/*
	putchar('\n');
	for(i=0;i<2*m;i++){
		printf("%d %d\n",obs[i].ti,obs[i].tj);
	}*/
	flg=0;
	ans=0;
	i=0;
	
	for(now=1;now<=n;now++){
		//printf("now: %d,ans: %d\n",now,ans);
		for(;obs[i].ti==now && i<2*m;i++){
			//printf("now-1: %d, obs.ti: %d, obs.tj: %d\n",now, obs[i].ti,obs[i].tj);
			if(h[now-1]<=h[obs[i].tj-1]){
				flg=1;
			}
		}
		if(flg==0){
				ans++;
		}
		flg=0;
	}
	printf("%d\n",ans);
	free(obs);
	free(h);
	return 0;
}

int comp(const void *p1,const void *p2){
	const observatories *n1, *n2;
	n1=(const observatories *)p1;
	n2=(const observatories *)p2;
	if(n1->ti==n2->ti){
		return n1->tj-n2->tj;
	}else{
		return n1->ti-n2->ti;
	}
}
//  [c]
#include <stdio.h>
#include <stdlib.h>

int N, M;
int H[114514];

int ec[114514];
int* es[114514];

void ae(int f, int t) {
	es[f] = realloc(es[f], sizeof(*es[f]) * (ec[f] + 1));
	if (es[f] == NULL) exit(2);
	es[f][ec[f]++] = t;
}

int main(void) {
	int i, j;
	int count = 0;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 1; i <= N; i++) {
		if (scanf("%d", &H[i]) != 1) return 1;
	}
	for (i = 0; i < M; i++) {
		int A, B;
		if (scanf("%d%d", &A, &B) != 2) return 1;
		ae(A, B);
		ae(B, A);
	}
	for (i = 1; i <= N; i++) {
		int yes = 1;
		for (j = 0; j < ec[i]; j++) {
			if (H[i] <= H[es[i][j]]) yes = 0;
		}
		if (yes) count++;
	}
	printf("%d\n", count);
	return 0;
}
//  [javascript]
"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    const [n, m] = input[0].split(" ").map(el => parseInt(el));
    const hs = input[1].split(" ").map(el => parseInt(el));
    hs.unshift(0) // dummy
    let tmp = {}
    for (let i = 2; i < input.length; i++) {
        let [a, b] = input[i].split(" ").map(el => parseInt(el))
        if (!tmp[a]) tmp[a] = {}
        tmp[a][b] = true
        if (!tmp[b]) tmp[b] = {}
        tmp[b][a] = true
    }
    const numIsolated = n - Object.keys(tmp).length
    let num = 0
    for(let i of Object.keys(tmp)){
        const baseHight = hs[i]
        let ret = true
        for(let otherKey of Object.keys(tmp[i])){
            if(baseHight <= hs[otherKey]){
                ret = false
                break
            }
        }
        if(ret){
            num++
        } 
    }
    console.log(num + numIsolated)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]

function Main(input) {
    input = input.trim();
    input = input.split("\n")
    input = input.map(e => e.split(" ").map(f => parseInt(f)))

    var tenbou = []

    input[1].forEach(e => {
        tenbou.push({
            h: e,
            childlen: [],
            parents: []
        })
    })

    var input2 = input.slice(2)

    input2.forEach(e => {
        var ten1 = tenbou[e[0] - 1]
        var ten2 = tenbou[e[1] - 1]

        if(ten1.h<ten2.h){
            tenbou[e[0] - 1].parents.push(ten2)
            tenbou[e[1] - 1].childlen.push(ten1)
        }else if(ten1.h==ten2.h){
            tenbou[e[0] - 1].parents.push(ten2)
            tenbou[e[1] - 1].parents.push(ten1)
        }else{
            tenbou[e[0] - 1].childlen.push(ten2)
            tenbou[e[1] - 1].parents.push(ten1)
        }

    })

    var count =0;

    tenbou.forEach(e=>{
        if(e.parents.length ==0)count++;
    })


    console.log(count)

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
const Main = (input) => {
    array = input.split('\n')
    NM = array.shift().split(' ').map(item => parseInt(item))
    H = array.shift().split(' ').map(item => parseInt(item))
    array.pop() // lastが邪魔
    A = array.map(item => item.split(' ').map(value => parseInt(value)))
    // console.log('NM: ', NM)
    // console.log('H: ', H)
    // console.log('A: ', A)
    console.log(F(NM[0], NM[1], H, A))
}

const F = (N, M, H, A) => {
    road = []
    for (i = 0; i <= N; i++) {
        road.push([])
    }
    for (i = 0; i < M; i++) {
        road[A[i][0]].push(A[i][1])
        road[A[i][1]].push(A[i][0])
    }
    count = 0
    // console.log('road: ', road)
    for (i = 1; i <= N; i++) {
        // console.log('i: ', i, road[i])
        if (road[i].length == 0) {
            count++
            continue
        }
        max = 0
        road[i].forEach(item => {
            if (H[item - 1] > max) max = H[item - 1]
        });
        if (max < H[i - 1]) count++
    }
    return count
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"fmt"
)

func main() {
	var N, M int
	fmt.Scanf("%d %d", &N, &M)

	H := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &H[i])
	}

	var A, B int
	J := make([][]int, N)
	for i := 0; i < M; i++ {
		fmt.Scanf("%d %d", &A, &B)
		J[A-1] = append(J[A-1], B)
		J[B-1] = append(J[B-1], A)
	}

	var count, flag int
	for i := 0; i < N; i++ {
		flag = 0
		for k := 0; k < len(J[i]); k++ {
			if H[i] <= H[(J[i][k]-1)] {
				flag = 1
				break
			}
		}
		if flag == 0 {
			count++
		}
	}

	fmt.Println(count)
}
//  [go]
package main

import (
	"fmt"
	"sync"
)

type graph struct {
	path []int
	height int
	// flag bool // pathに存在するもので自分より高いものがあればtrue
}
var graphs []graph
var wg sync.WaitGroup
var count int
func main() {
	var N,M int
	fmt.Scan(&N,&M)
	graphs = make([]graph,N)
	for i:= 0; i<N; i++ {
		var h int
		fmt.Scan(&h)
		graphs[i].height = h
		graphs[i].path = []int{}
		// graphs[i].flag = false
	}
	for i:= 0; i<M; i++ {
		var a,b int
		fmt.Scan(&a,&b)
		graphs[a-1].path = append(graphs[a-1].path,b-1)
		graphs[b-1].path = append(graphs[b-1].path,a-1)
	}
	count = 0
	for i:=0; i<N; i++ {
		wg.Add(1)
		go goFor(i)
	}
	wg.Wait()
	fmt.Println(count)
}

func goFor (i int) {
	paths := graphs[i].path
	height := graphs[i].height
	bestHeight := true // 一番高いのならtrue
	for _, value := range paths {
		if height <= graphs[value].height {
			bestHeight = false
			break
		}
	}
	if bestHeight {
		// fmt.Println(graphs[i],"ベスト")
		count++
	}
	defer wg.Done()
}
//  [go]
package main

import (
	"fmt"
	"sync"
)

type graph struct {
	path []int
	height int
	// flag bool // pathに存在するもので自分より高いものがあればtrue
}
var graphs []graph
func main() {
	var N,M int
	fmt.Scan(&N,&M)
	graphs = make([]graph,N)
	for i:= 0; i<N; i++ {
		var h int
		fmt.Scan(&h)
		graphs[i].height = h
		graphs[i].path = []int{}
		// graphs[i].flag = false
	}
	for i:= 0; i<M; i++ {
		var a,b int
		fmt.Scan(&a,&b)
		graphs[a-1].path = append(graphs[a-1].path,b-1)
		graphs[b-1].path = append(graphs[b-1].path,a-1)
	}
	count := 0
	var wg sync.WaitGroup
	for i:=0; i<N; i++ {
		wg.Add(1)
		go func(i int) {
			paths := graphs[i].path
			height := graphs[i].height
			bestHeight := true // 一番高いのならtrue
			for _, value := range paths {
				if height <= graphs[value].height {
					bestHeight = false
					break
				}
			}
			if bestHeight {
				// fmt.Println(graphs[i],"ベスト")
				count++
			}
			defer wg.Done()
		}(i)
	}
	wg.Wait()
	fmt.Println(count)
}
//  [ruby]
N, M = gets.chomp.split.map(&:to_i)
H  = gets.chomp.split

dropOutList = Hash.new

M.times do
  A, B = gets.chomp.split.map(&:to_i)
  if (H[A-1].to_i >= H[B-1].to_i)
  	dropOutList[B] = true
  end	
  if (H[A-1].to_i <= H[B-1].to_i)
  	dropOutList[A] = true
  end
end

print N - dropOutList.length
//  [ruby]
require 'set'

def main
    n,m = gets.chomp.split(" ").map(&:to_i)
    hs = gets.chomp.split(" ").map(&:to_i)
    hs = [0] + hs
    to = Array.new(n+1).map{Array.new()}
    (1..n).each do |i|
        to[i].push [i, hs[i]]
    end
    m.times do
        a,b = gets.chomp.split(" ").map(&:to_i)
        to[a].push [b, hs[b]]
        to[b].push [a, hs[a]]
    end
    (1..n).each do |i|
        to[i].sort_by!{ |x| x[1] }
    end

    ans = 0
    (1..n).each do |i|
        if to[i][-1][0] == i
            ans += 1
        end
    end
    puts ans
end

main

## イディオムなど
# until s.empty? do
#
## 配列のインデックス
# s[0,6] # 0番目から6文字
# s[0..6] # 0番目から6番目まで
# s[5..-1] # 5番目から最後まで
#
## 全探索
# [0, 1].repeated_permutation(n) do |combination| # bit全探索
# array.combination(i) do |selected| # array から要素が i 個である部分列を全部抽出
#
## 無向グラフの幅優先探索(BFS)
# to = Array.new(n).map{Array.new()} # ある頂点と繋がる頂点のリスト
# m.times do
#     a,b = gets.chomp.split(" ").map(&:to_i)
#     to[a].push b
#     to[b].push a
# end
# q = Queue.new # BFS は queue
# ds = Array.new(n, -1)
# pre = Array.new(n, -1)
#
## その他
# a1 = Marshal.load(Marshal.dump(a2)) # 深いコピー
# matrix = Array.new(n).map{Array.new()} # 二次元配列の初期化
#
//  [ruby]
require 'set'
class Peek
  attr_accessor :paths, :height

  def initialize(height)
    self.height = height
    self.paths = Set.new
  end

  def is_good?
    return true if paths.empty?
    height > paths.map(&:height).max
  end
end
H, M = gets.chomp.split.map(&:to_i)
peeks = gets.chomp.split.map(&:to_i).each_with_object([nil]) do |h, pks|
    pks << Peek.new(h)
  end

M.times do
  a, b = gets.chomp.split.map(&:to_i)
  peeks[a].paths.add peeks[b]
  peeks[b].paths.add peeks[a]
end
peeks.shift
puts peeks.count(&:is_good?)
//  [rust]
#[allow(dead_code)]
fn main() {
    let (n, m) = i::u2();
    let h = i::uv(n);
    let ab = i::uv2(m);

    let mut s = vec![HashSet::new(); n + 1];
    for i in 0..m {
        let (a, b) = ab[i];
        s[a].insert(b);
        s[b].insert(a);
    }

    let mut count = 0;
    'case: for i in 1..=n {
        let height = h[i - 1];
        for &k in &s[i] {
            let target = h[k - 1];
            if height <= target {
                continue 'case;
            }
        }
        count += 1;
    }
    println!("{}", count);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}
//  [rust]
use text_io::*;
use std::process::exit;

fn main(){
    let mut n:usize = read!();
    let mut m:usize = read!();
    let mut g:Vec<usize> = Vec::new();
    let mut v:Vec<usize> = Vec::new();
    for i in 0..n {
        let c:usize = read!();
        v.push(c);
        g.push(1);
    }
    for i in 0..m {
        let mut x:usize = read!();
        let mut y:usize = read!();
        if v[x-1]<=v[y-1] {
            g[x-1] = 0;
        }
        if v[y-1]<=v[x-1] {
            g[y-1] = 0;
        }
    }
    let mut mm:usize = 0;
    for i in 0..n {
        mm+=g[i];
    }
    println!("{}",mm);
}
//  [swift]
let nl = readLine()!.split(separator: " ").map { Int($0)! }
let n = nl[0], m = nl[1]
let hn = readLine()!.split(separator: " ").map { Int($0)! }
var ab = [[Int]](repeating: [Int](), count: n)

for _ in 0..<m {
  let abj = readLine()!.split(separator: " ").map { Int($0)! }
  ab[abj[0] - 1] = ab[abj[0] - 1] + [abj[1]]
  ab[abj[1] - 1] = ab[abj[1] - 1] + [abj[0]]
}
var cn = 0
for i in 0..<n {
  if let max = ab[i].max(by: { hn[$0 - 1] < hn[$1 - 1] }) {
    if hn[max - 1] < hn[i] {
      cn += 1
    }
  } else {
    cn += 1
  }
}
print(cn)
//  [swift]
let (n,m) = cin.pair
let h = cin.array
var ok = Array(1...n).map { _ in 1 }
Array(1...m).forEach { _ in 
    var (a,b) = cin.pair
    a -= 1
    b -= 1
    if h[a] > h[b] {
        ok[b] = 0
    } else if h[a] < h[b] {
        ok[a] = 0
    } else {
        ok[a] = 0
        ok[b] = 0
    }
}

print(ok.sum)

// MARK: #### 以下、ライブラリ ####

import Foundation
#if os(Linux)
    import Glibc
#else
    import Darwin.C
#endif

enum cin {
    // 123
    static var int: Int { Int(readLine()!)! }
    // 12 23
    static var pair: (Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!) }
    // 12 23 34
    static var triple: (Int, Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!, Int(line[2])!) }
    // AtCoder
    static var str: String { readLine()! }
    // At Coder
    static var arrayStr: [String] { str.components(separatedBy: " ") }
    // 1 2 3 4
    static var array: [Int] { str.components(separatedBy: " ").map { Int($0)! } }
    // 1
    // 2
    // 3
    static func v_array(count: Int) -> [Int] { (0..<count).map { _ in int } }
}

extension Int {
    // 123 -> [1, 2, 3]
    var digits: [Int] { Array(String(self)).map { Int(String($0))! } }
}

extension Array where Element == Int {
    // [2, 1, 3, 2] -> 8
    var sum: Int { self.reduce(0, +) }
    // [2, 1, 3, 2] -> [1, 2, 2, 3]
    var orderBy: [Int] { sorted() }
    // [2, 1, 3, 2] -> [3, 2, 2, 1]
    var orderByDesc: [Int] { sorted(by: { $0 > $1 }) }
    // [2, 1, 3, 2] -> [2, 1, 3]
    var distinct: [Int] { Array(Set(self)) }
}

precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence }
infix operator ^^ : PowerPrecedence
func ^^ (radix: Int, power: Int) -> Int {
    return Int(pow(Double(radix), Double(power)))
}

extension String {
    // e.g. cin.line.regex(match: "^(dream|dreamer|erase|eraser)*$")
    func regex(match pattern: String) -> Bool {
        let regex = try! NSRegularExpression(pattern: pattern)
        return regex.firstMatch(in: self, range: NSRange(location: 0, length: self.count)) != nil
    }
    // "ABC"[1] -> "B"
    subscript(i: Int) -> Character {
        get {
            self[index(at: i)]
        }
        set(char) {
            var characters = Array(self)
            characters[i] = char
            self = String(characters)
        }
    }
    func index(at offset: Int) -> String.Index { index(startIndex, offsetBy: offset) }
    // "ABC".swapAt(0, 1) -> "BAC"
    mutating func swapAt(_ index1: Int, _ index2: Int) {
        var characters = Array(self)
        characters.swapAt(index1, index2)
        self = String(characters)
    }
}
//  [swift]
import Foundation

private func readString() -> String {
    readLine()!
}

private func readStringArray() -> [String] {
    readString().components(separatedBy: " ")
}

private func readInt() -> Int {
    Int(readString())!
}

private func readIntArray() -> [Int] {
    readStringArray().map { Int($0)! }
}

private func readStringTupple() -> (String, String) {
    let array = readStringArray()
    return (array[0], array[1])
}

private func readStringTupple() -> (String, String, String) {
    let array = readStringArray()
    return (array[0], array[1], array[2])
}

private func readIntTupple() -> (Int, Int) {
    let array = readIntArray()
    return (array[0], array[1])
}

private func readIntTupple() -> (Int, Int, Int) {
    let array = readIntArray()
    return (array[0], array[1], array[2])
}

/*＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿
 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
 ￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣*/

let (n, m) = readIntTupple()
let h = [0] + readIntArray()
var mh = [Int](repeating: 0, count: n + 1)
for _ in 0..<m {
    let (a, b) = readIntTupple()
    mh[a] = max(h[b], mh[a])
    mh[b] = max(h[a], mh[b])
}
var ans = 0
for i in 1..<n+1 {
    ans += mh[i] < h[i] ? 1 : 0
}
print(ans)

/*＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿
〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣*/
//  [typescript]
const lines: string[] = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});
reader.on("line", function (line: string) {
  lines.push(line);
});

reader.on("close", function () {
  const rule = lines.shift().split(" ").map(Number);
  const tenNum = rule[0];
  const roadNum = rule[1];
  const heightArray = lines.shift().split(" ").map(Number);

  const roadArrays: any = lines.map((line) => {
    return line.split(" ").map((int) => parseInt(int));
  });
  const connect = new Array(tenNum).map((ele) => [0]);

  for (let i = 0; i < roadArrays.length; i++) {
    connect[roadArrays[i][0] - 1]
      ? connect[roadArrays[i][0] - 1].push(roadArrays[i][1])
      : (connect[roadArrays[i][0] - 1] = [roadArrays[i][1]]);
    connect[roadArrays[i][1] - 1]
      ? connect[roadArrays[i][1] - 1].push(roadArrays[i][0])
      : (connect[roadArrays[i][1] - 1] = [roadArrays[i][0]]);
  }

  let count = 0;
  for (let i = 0; i < connect.length; i++) {
    if (!connect[i]) {
      count++;
      continue;
    }
    let judge = true;
    connect[i].forEach((element) => {
      heightArray[i] > heightArray[element - 1] ? "" : (judge = false);
    });
    judge ? count++ : "";
  }
  console.log(count);
});
//  [typescript]

interface ITenbodai {
  id: number;
  height: number;
  otherPlaceHeight: number[];
}
const mainCalc = (input: string) => {
  inputParser(input)
}

const inputParser = (input: string) => {
  const tmp = input.split('\n');
  const [nStr, mStr] = tmp[0].split(' ')
  tmp.shift();
  const tenbodai = tmp[0].split(' ').map((v, i) => {
    return {
      h: +v,
      th: [0],
      num: 0,
    }
  });
  tmp.shift();
  tmp.forEach(value => {
    const [a, b] = value.split(' ')
    if (a == null || b == null) return;
    const p = tenbodai[+a - 1]
    const n = tenbodai[+b - 1]
    if (p == null || n == null) return;
    p.th.push(n.h);
    n.th.push(p.h);
  });
  let count = 0;

  tenbodai.forEach((tb) => {
    const list = tb.th.filter(h => h >= tb.h);
    if (list.length == 0) {
      count ++;
    }
  })
  console.log(count);
}
// tenbodaiList.forEach((tenbodai) => {
//   const otherHightList = tenbodai.otherPlaceHeight
//     .filter(value => {
//       if (tenbodai.height <= value) {
//         return true;
//       }
//       return false;
//     });
//   if (otherHightList.length <= 0) {
//     count ++;
//   }
// });
// test
//const Q1 = `4 3
//1 2 3 4
//1 3
//2 3
//2 4
//`;
//
//const Q2 = `6 5
//8 6 9 1 2 1
//1 3
//4 2
//4 3
//4 6
//4 6
//`;
//
//mainCalc(Q1);
//mainCalc(Q2);
mainCalc(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [python]
N=int(input())
A = list(map(int, input().split()))
A.sort()
sa = []
for i in range(N-1):
    diff = A[i+1]-A[i]
    if diff > 0:
        sa.append(diff)
sa.sort()

if len(sa)>=2:
    score = sa[1] - sa[0]
    if score <= 0:
        print(sa[0])
    else:
        dai = max(score, sa[0])
        sho = min(score, sa[0])
        while dai-sho > 0:
            dai, sho = sho, dai-sho
            if dai <= sho:
                dai, sho = sho, dai
        print(dai-sho if dai-sho > 0 else sho)
elif len(sa) == 1:
    dai = max(A[0], sa[0])
    sho = min(A[0], sa[0])
    while dai-sho > 0:
        dai, sho = sho, dai-sho
        if dai <= sho:
            dai, sho = sho, dai
    print(dai-sho if dai-sho > 0 else sho)
else:
    print(A[0])
//  [python]
from queue import PriorityQueue
N = int(input())
A = map(int, input().split())
q = PriorityQueue()
for a in A:
    q.put(-a)
x = -q.get()
while not q.empty():
    y = -q.get()
    if y == 0:
        break
    q.put(-(x % y))
    x = y
print(x)
//  [java]

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	public static void dame_mons(ArrayList<Integer> mons,int a_index,int b_index) {
		if(mons.size() < 2) {
			return;
		}
		int a = mons.get(a_index);
		int b = mons.get(b_index);
		mons.set(b_index, b % a);
		if(b % a == 0) {
			mons.remove(b_index);
			dame_mons(mons,0,1);
		}else {
			dame_mons(mons,b_index,a_index);
		}
		
	}
	public static int game_mons(ArrayList<Integer> mons) {
		mons.sort((a,b) -> Integer.compare(a, b));
		dame_mons(mons,0,1);
		
		return mons.get(0); 
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc  = new Scanner(System.in);
		int N = sc.nextInt();
		int result;
		ArrayList<Integer> mons = new ArrayList<Integer>();
		for(int i = 0; i < N; i++) {
			mons.add(sc.nextInt());
		}
		
		result = game_mons(mons);
		System.out.println(result);
		
		sc.close();
	}

}
//  [java]
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i=0; i<n; i++) list.add(sc.nextInt());
        Collections.sort(list);

        while (1 < list.size()) {
            for (int i=1; i<list.size(); i++) {
                int tmp = list.get(i);
                tmp %= list.get(0);
                if (tmp == 0) {
                    list.remove(i);
                    i--;
                } else {
                    list.set(i, tmp);
                }
            }
            Collections.sort(list);
//            System.out.println(list);
        }

        System.out.println(list.get(0));

    }

}
//  [java]


import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
	    ArrayList<Integer> a=new ArrayList<>();
	    
	    if(n==1){
	    	System.out.println(sc.nextInt());
			System.exit(0);
	    }
		
	    for(int i=0;i<n;i++){
	    	a.add(sc.nextInt());
	    }
	    Collections.sort(a);
	    
	    if(a.get(a.size()-1)==0){
	    	System.out.println(0);
			System.exit(0);
	    }
	    
	    int ans=0;
	    
	    while(true){
	    	if(a.size()==1){
	    		ans=a.get(0);
	    		break;
	    	}
	    	a=func(a);
	    }
	   System.out.println(ans);
	
	}
	
	private static ArrayList<Integer> func(ArrayList<Integer> A){
		ArrayList<Integer> a=A;
		int min=0;
		for(int i=0;i<a.size();i++){
	    	if(a.get(i)==0){
	    		a.remove(i);
	    		i--;
	    	}else{
	    		if(min!=0){
	    			a.set(i,a.get(i)%min);
	    			if(a.get(i)==1){
	    				System.out.println(1);
	    				System.exit(0);
	    			}
	    		}else{
	    			min=a.get(i);
	    		}
	    	}
	    }
		Collections.sort(a);
		return a;
	}
		
		
}
//  [cpp]
#include<bits/stdc++.h>
using ll = long long;
using  INT = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define ALL(x) x.begin(),x.end()

#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)1e9+7 //10^9+7:合同式の法
#define PI 3.141592653589

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)

using namespace std;
/*........................................DEFINE FUNCTIONS.........................................*/


/*....................................DEFINE GLOBAL VARIABLES .....................................*/

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



/*.........................................kemkemG0................................................*/
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int N;
	cin >> N;

	VI A(N);
	REP(i, N)cin >> A[i];

	sort(ALL(A));
	int m = A[0];

	int mm=m;

	REP(i, N) {
		(A[i] % m != 0) ? chmin(m, A[i] % m) : 1;
	}

	if(mm==m){cout<<mm<<endl; return 0;}


	REP(aa, m + 2) {
		REP(i, N) {
			(A[i] % m != 0) ? chmin(m, A[i] % m) : 1;
		}
	}

	cout << m << endl;


















	return 0;
}
//  [cpp]
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
  int N,mn,count,ans;
  cin >> N;
  int A[N];
  int B[N];
  mn=1000000000;
  ans=0;
  for(int i=0; i<N; ++i){
    cin >> A[i];
    mn=min(mn,A[i]);
  }
  for(int i=1; i<N; ++i){
    B[i]=abs(A[i]-A[i-1]);
    if(B[i]==0) B[i]=A[i];
    mn=min(mn,B[i]);
  }
  for(int i=mn; i>=1; --i){
    count=0;
    for(int j=0; j<N; ++j){
      if(A[j]%i != 0) count += 1;
    }
    if(count==0){
      ans=i;
      break;
    }
  }
  cout << ans << endl;
}
//  [cpp]
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


long long gcd(long long a, long long b) {
    long long maxv = max(a,b);
    long long minv = min(a,b);

    if(maxv % minv == 0) return minv;
    else return gcd(maxv - minv, minv);
}
int main() {
    int N;
    cin >> N;

    vector<long long> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    long long cur = gcd(A[0], A[1]);
    for(int i = 2; i < N; i++) {
        cur = gcd(A[i], cur);
    }

    cout << cur << endl;
}
//  [c]
#include <stdio.h>

int A[100000];

int GCD(int N, int m, int c){
  int i, j;
  if(m % 2 != c) m--; 
  for(i = m;i > 1;i -= 2){
    if(m % i != 0) continue;
    for(j = 0;j < N;j++) if(A[j] % i != 0) break;
    if(j == N) return i;
  }
  return 1;
}

void Do(int N){
  int i, m, c;
  m = 1e9;
  c = 0;
  for(i = 0;i < N;i++){
    scanf("%d", &A[i]);
    if(A[i] % 2 != 0) c = 1;
    if(m > A[i]) m = A[i];
  }
  printf("%d\n", GCD(N, m, c));
}

int main(void){
  int N;
  scanf("%d", &N);
  Do(N);
  return 0;
}
//  [c]
#include <stdio.h>

int main(void){
    int N = 0;
    int A[100000] = {0};
    scanf("%ld", &N);
    for(int i = 0; i < N; i++){
        scanf("%ld", &A[i]);
    }
    int last = 0; 
    while(1){
        int min = 1000000000; int minno = 0;
        int flag = 0;
        for(int i = 0; i < N; i++){
            if(min > A[i]){
                min = A[i];
                minno = i;
            }
        }

        for(int i = 0; i < N; i++){
            if(A[i] % min != 0){
                flag = 1;
                break;
            }
        }

        if(flag == 0){
            last = min;
            break;
        }else {
            for(int j = 0; j < N; j++){
                if(j == minno){

                }else if(A[j] == min){

                }else {
                    A[j] -= min;
                }
            }
        }
    }
    printf("%d\n", last);
    return 0;
}