stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <cmath>

#include <cstdio>

#include <cstring>

#include <iostream>

#include <algorithm>

#define For(i, a, b) for (i = a; i <= b; i++)

#define Tree(u) for (int e = adj[u], v; e; e = nxt[e]) if ((v = go[e]) != fu)



inline int read()

{

	int res = 0; bool bo = 0; char c;

	while (((c = getchar()) < '0' || c > '9') && c != '-');

	if (c == '-') bo = 1; else res = c - 48;

	while ((c = getchar()) >= '0' && c <= '9')

		res = (res << 3) + (res << 1) + (c - 48);

	return bo ? ~res + 1 : res;

}



const int N = 3005, M = N << 1;



int n, a[N], ecnt, nxt[M], adj[N], go[M];

bool f[N];



void add_edge(int u, int v)

{

	nxt[++ecnt] = adj[u]; adj[u] = ecnt; go[ecnt] = v;

	nxt[++ecnt] = adj[v]; adj[v] = ecnt; go[ecnt] = u;

}



void dfs(int u, int fu)

{

	f[u] = 0;

	Tree(u)

	{

		dfs(v, u);

		if (a[v] < a[u]) f[u] |= !f[v];

	}

}



int main()

{

	int i, x, y;

	n = read();

	For (i, 1, n) a[i] = read();

	For (i, 1, n - 1)

		x = read(), y = read(), add_edge(x, y);

	For (i, 1, n) if (dfs(i, 0), f[i]) printf("%d ", i);

	std::cout << std::endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#if 0

#endif

#include <cstdio>

#include <algorithm>



inline int input() { int x; scanf("%d", &x); return x; }



const int maxn = 3030;

int head[maxn], nxt[maxn << 1], to[maxn << 1], hp;

bool vis[maxn], win[maxn];

int a[maxn];



inline void add(int u, int v) {

	nxt[++ hp] = head[u];

	head[u] = hp;

	to[hp] = v;

}



void dfs(int u) {

	vis[u] = true;

	for(int i = head[u]; i; i = nxt[i]) {

		if(not vis[to[i]])

			dfs(to[i]);

		if(not win[to[i]])

			win[u] = true;

	}

}



int main() {

	int n = input();

	for(int i = 1; i <= n; i ++)

		a[i] = input();

	for(int i = 1; i < n; i ++) {

		int u = input(), v = input();

		if(a[u] > a[v])

			add(u, v);

		else if(a[u] < a[v])

			add(v, u);

	}

	for(int u = 1; u <= n; u ++)

		if(not vis[u])

			dfs(u);

	for(int u = 1; u <= n; u ++)

		if(win[u])

			printf("%d ", u);

	puts("");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int a[3005],x,y,n;

vector<int>e[3005];

int dfs(int x,int fa)

{

    for(int i=0;i<e[x].size();i++) if(e[x][i]!=fa&&a[x]>a[e[x][i]]&&!dfs(e[x][i],x)) return 1;

    return 0;

}

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++) scanf("%d",&a[i]);

    for(int i=1;i<n;i++) scanf("%d%d",&x,&y),e[x].push_back(y),e[y].push_back(x);

    for(int i=1;i<=n;i++) if(dfs(i,0)) printf("%d ",i);

}

// Optimized solution to the same problem (faster):
#if 0

#endif

#include <cstdio>

#include <algorithm>



inline int input() { int x; scanf("%d", &x); return x; }



const int maxn = 3030;

int head[maxn], nxt[maxn << 1], to[maxn << 1], hp;

bool vis[maxn], win[maxn];

int a[maxn];



inline void add(int u, int v) {

	nxt[++ hp] = head[u];

	head[u] = hp;

	to[hp] = v;

}



void dfs(int u) {

	vis[u] = true;

	for(int i = head[u]; i; i = nxt[i]) {

		if(not vis[to[i]])

			dfs(to[i]);

		if(not win[to[i]])

			win[u] = true;

	}

}



int main() {

	int n = input();

	for(int i = 1; i <= n; i ++)

		a[i] = input();

	for(int i = 1; i < n; i ++) {

		int u = input(), v = input();

		if(a[u] > a[v])

			add(u, v);

		else if(a[u] < a[v])

			add(v, u);

	}

	for(int u = 1; u <= n; u ++)

		if(not vis[u])

			dfs(u);

	for(int u = 1; u <= n; u ++)

		if(win[u])

			printf("%d ", u);

	puts("");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdlib>

#include <cstdio>

#define N 3011

using namespace std;

struct apple{

	int v,nxt;

}edge[N*4];

int indexx[N],tot,n,val[N];

void addedge(int x,int y){

	edge[++tot].v=y;

	edge[tot].nxt=indexx[x];

	indexx[x]=tot;

}

int dfs(int u,int fa){

	int t=indexx[u],vv,sum=val[u];

	while(t){

		vv=edge[t].v;

		if(vv!=fa){

			int k=dfs(vv,u);

			if(!k && val[vv]<val[u]) return 1;

		}

		t=edge[t].nxt;

	}

	return 0;

}

int main(){

	int x,y;

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d",&val[i]);

	for(int i=1;i<n;i++){

		scanf("%d%d",&x,&y);

		addedge(x,y);

		addedge(y,x);

	}

	for(int i=1;i<=n;i++){

		int k=dfs(i,0);

		if(k ) printf("%d ",i);

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#if 0

#endif

#include <cstdio>

#include <algorithm>



inline int input() { int x; scanf("%d", &x); return x; }



const int maxn = 3030;

int head[maxn], nxt[maxn << 1], to[maxn << 1], hp;

bool vis[maxn], win[maxn];

int a[maxn];



inline void add(int u, int v) {

	nxt[++ hp] = head[u];

	head[u] = hp;

	to[hp] = v;

}



void dfs(int u) {

	vis[u] = true;

	for(int i = head[u]; i; i = nxt[i]) {

		if(not vis[to[i]])

			dfs(to[i]);

		if(not win[to[i]])

			win[u] = true;

	}

}



int main() {

	int n = input();

	for(int i = 1; i <= n; i ++)

		a[i] = input();

	for(int i = 1; i < n; i ++) {

		int u = input(), v = input();

		if(a[u] > a[v])

			add(u, v);

		else if(a[u] < a[v])

			add(v, u);

	}

	for(int u = 1; u <= n; u ++)

		if(not vis[u])

			dfs(u);

	for(int u = 1; u <= n; u ++)

		if(win[u])

			printf("%d ", u);

	puts("");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;

typedef pair<bool , bool> pii;

typedef pair<ll, ll> pll;



#define $ system("pause")

#define MOD ll(1e9 + 7)

#define MAXN 300010

#define inf (ll)1e18



template<typename T> inline T smin(T &a, const T &b) { return a > b ? a = b : a; }

template<typename T> inline T smax(T &a, const T &b) { return a < b ? a = b : a; }

inline void add(ll &l, const ll &r) { l = (l + r) % MOD; }

ll gcd(ll v, ll u) { return u ? gcd(u, v % u) : v; }

ll po(ll v, ll u) { return u ? (po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD) : 1; }



/*

int n, arr[MAXN];

int have[MAXN][20];

int pl[MAXN][20], pr[MAXN][20];

vector<int> p[MAXN];



int main() {

	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	for (int i = 2; i < MAXN; i++)

		if (p[i].empty()) {

			for (int j = i; j < MAXN; j += i)

				p[j].push_back(i);

		}



	cin >> n;

	for (int i = 1; i <= n; i++) {

		cin >> arr[i];

		int local = arr[i];

		for (auto e : p[arr[i]]) {

			int cnt = 0;

			while ((local % e) == 0) {

				cnt++;

				local /= e;

			}

			have[e][cnt]++;

		}

	}

	for (int i = 1; i < MAXN; i++) {

		pr[i][19] = have[i][19];

		for (int j = 18; j; j--) 

			pr[i][j] = pr[i][j + 1] + have[i][j];

		have[i][0] = n - pr[i][1];

		pr[i][0] = n;

		pl[i][0] = have[i][0];

		for (int j = 1; j < 20; j++)

			pl[i][j] = pl[i][j - 1] + have[i][j];



	}

	return 0;

}



*/



int n, arr[MAXN];

vector<int> adj[MAXN];



bool dfs(int v, int p = 0) {

	bool res = false;

	for (auto e : adj[v]) {

		if (e ^ p && arr[e] < arr[v]) {

			res |= !dfs(e, v);

		}

	}

	return res;

}



int main() {

	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n;

	for (int i = 1; i <= n; i++)

		cin >> arr[i];

	for (int i = 1; i < n; i++) {

		int u, v; cin >> u >> v;

		adj[u].push_back(v);

		adj[v].push_back(u);

	}

	for (int i = 1; i <= n; i++) {

		if (dfs(i))

			cout << i << ' ';

	}

	//$;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



const int MAXN = 3000 + 10;

int a[MAXN];

vector <int> adj[MAXN];



bool dfs(int v, int p = -1) {

	for (int i: adj[v])

		if (i != p) {

			if (a[i] >= a[v])

				continue;

			else if(!dfs(i, v))

				return true;

		}

	return false;

}



int main() {

	int n;

	cin >> n;

	for (int i = 0; i < n; i++)

		cin >> a[i];

	for (int i = 0; i < n - 1; i++) {

		int a, b;

		cin >> a >> b;

		a--, b--;

		adj[a].push_back(b);

		adj[b].push_back(a);

	}

	for (int i = 0; i < n; i++)

		if (dfs(i))

			cout << i + 1 << ' ';

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef int ll;

typedef long long int li;

const ll MAXN=2e5+51;

struct Edge{

	ll to,prev;

};

Edge ed[MAXN];

ll n,tot,from,to;

ll last[MAXN],x[MAXN],dp[MAXN];

inline ll read()

{

    register ll num=0,neg=1;

    register char ch=getchar();

    while(!isdigit(ch)&&ch!='-')

    {

        ch=getchar();

    }

    if(ch=='-')

    {

        neg=-1;

        ch=getchar();

    }

    while(isdigit(ch))

    {

        num=(num<<3)+(num<<1)+(ch-'0');

        ch=getchar();

    }

    return num*neg;

}

inline void addEdge(ll from,ll to)

{

	ed[++tot].prev=last[from];

	ed[tot].to=to;

	last[from]=tot;

}

inline void dfs(ll node,ll fa)

{

	dp[node]=0;

	for(register int i=last[node];i;i=ed[i].prev)

	{

		if(ed[i].to!=fa)

		{

			dfs(ed[i].to,node);

			if(!dp[ed[i].to]&&x[node]>x[ed[i].to])

			{

				dp[node]=1;

			}

		}

	}

}

int main()

{

	n=read();

	for(register int i=1;i<=n;i++)

	{

		x[i]=read();

	}

	for(register int i=1;i<n;i++)

	{

		from=read(),to=read();

		addEdge(from,to),addEdge(to,from);

	}

	for(register int i=1;i<=n;i++)

	{

		memset(dp,0,sizeof(dp)),dfs(i,0);

		if(dp[i])

		{

			printf("%d ",i);

		}

	}

}

// Optimized solution to the same problem (faster):
#include <cstdio>

typedef long long ll;

inline int rd(){

    int x=0,p=1;

    char a=getchar();

    while((a<48||a>57)&&a!='-')a=getchar();

    if(a=='-')p=-p,a=getchar();

    while(a>47&&a<58)x=(x<<1)+(x<<3)+(a&15),a=getchar();

    return x*p;

}

const int N=3002;

struct Edge{

	int to,next;

}edge[N<<1];

int head[N],cnt;

int n,a[N],f[N];

inline void add(int f,int t){

	edge[++cnt].next=head[f];

	edge[cnt].to=t;

	head[f]=cnt;

}

inline void dp(int u,int ft){

	f[u]=0;

	for(int i=head[u];i;i=edge[i].next){

		int v=edge[i].to;

		if(v==ft)continue;

		dp(v,u);

		if(f[v]==0&&a[u]>a[v])f[u]=1;

	}

}

int main(){

	n=rd();

	for(int i=1;i<=n;i++)a[i]=rd();

	for(int i=1;i<n;i++){

		int u=rd(),v=rd();

		add(u,v),add(v,u);

	}

	for(int i=1;i<=n;i++){

		dp(i,0);

		if(f[i])printf("%d ",i);

	}

	puts("");

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cmath>

//#define int long long

using namespace std;

const int maxn=5e5+1000;

typedef long long ll;

int n,m;

const int mod=998244353;

int fr[maxn],ans;

inline int ksm(int num,int t){

	int res=1;

	for(;t;t>>=1,num=1ll*num*num%mod){

		if(t&1)res=1ll*res*num%mod;

	}

	return res;

}

inline int c(int m,int n){

	return 1ll*fr[n]*ksm((1ll*fr[m]*fr[n-m])%mod,mod-2)%mod;	

}

int main(){

	ios::sync_with_stdio(0);

	cin>>n>>m;

	fr[0]=fr[1]=1;

	for(int i=2;i<maxn;i++)fr[i]=1ll*fr[i-1]*i%mod;	

	for(int i=0;i<=min(n,m);i++){

		ans=(ans+1ll*ksm(-1,i)*(1ll*c(i,n)*c(i,m)%mod*fr[i]%mod*ksm(m+1,n-i)%mod*ksm(n+1,m-i)%mod)%mod)%mod;	

	}

	ans=(ans%mod+mod)%mod;

	cout<<ans;

	return 0;

}//

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <iostream>

using namespace std;

const int N = 1e7 + 10, mod = 998244353;

int fac[N], inv[N], n, ans, m;

int qpow(int a, int b) {

    int c = 1;

    while(b) {

        if(b & 1) c = 1ll * c * a % mod;

        a = 1ll * a * a % mod;

        b >>= 1;

    } return c;

}

int C(int x, int y) {

    if(x < y) return 0;

    return 1ll * fac[x] * inv[y] % mod * inv[x - y] % mod;

}

int main() {

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

    if(n > m) swap(n, m);

    fac[0] = 1;

    for(int i = 1; i <= m; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;

    inv[m] = qpow(fac[m], mod - 2);

    for(int i = m; i >= 1; --i) inv[i - 1] = 1ll * inv[i] * i % mod;

    for(int i = 0, o = 1; i <= n; ++i, o = mod - o)

        ans += 1ll * C(n, i) * C(m, i) % mod * fac[i] % mod * qpow(m + 1, n - i) % mod * qpow(n + 1, m - i) % mod * o % mod,

        ans %= mod;

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

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define ll long long

using namespace std;

ll n,m,jc[1000010],ny[1000100],ans,p=998244353;

ll C(ll x,ll y){

	return jc[x]*ny[y]%p*ny[x-y]%p;

}

ll ksm(ll x,ll y){

	ll xlh=1;

	while(y){

		if(y&1)xlh=xlh*x%p;

		x=x*x%p;

		y/=2;

	}

	return xlh;

}

int main(){

	ll i,xlh;

	scanf("%lld%lld",&n,&m);

	if(n>m)swap(n,m);

	jc[0]=ny[0]=1;

	for(i=1;i<=m;i++)jc[i]=jc[i-1]*i%p,ny[i]=ksm(jc[i],p-2);

	for(i=0;i<=n;i++){

		xlh=C(n,i)*C(m,i)%p*jc[i]%p*ksm(n+1,m-i)%p*ksm(m+1,n-i)%p;

		if(i%2)ans=(ans-xlh+p)%p;

		 else ans=(ans+xlh)%p;

	}

	printf("%lld",ans);

}

/*

仔细想想不难，但感觉这种容斥确实非常奇怪。 

*/

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

#define ll long long

using namespace std;

const ll p=998244353;

ll n,m,ans,jc[1000010],ny[1000010];

ll ksm(ll x,ll y){

	ll xlh=1;

	while(y){

		if(y&1)xlh=xlh*x%p;

		x=x*x%p;

		y/=2;

	}

	return xlh;

}

ll C(ll x,ll y){

	return jc[x]*ny[y]%p*ny[x-y]%p;

}

int main(){

	ll i,op;

	scanf("%lld%lld",&n,&m);

	jc[0]=ny[0]=1;

	for(i=1;i<=max(n,m);i++)jc[i]=jc[i-1]*i%p,ny[i]=ksm(jc[i],p-2)%p;

	for(i=0;i<=min(n,m);i++){

		if(i%2)op=-1;

		 else op=1;

		ans=(ans+op*C(n,i)%p*C(m,i)%p*jc[i]%p*ksm(n+1,m-i)%p*ksm(m+1,n-i)%p+p)%p;

	}

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cmath>

//#define int long long

using namespace std;

const int maxn=5e5+1000;

typedef long long ll;

int n,m;

const int mod=998244353;

int fr[maxn],ans;

inline int ksm(int num,int t){

	int res=1;

	for(;t;t>>=1,num=1ll*num*num%mod){

		if(t&1)res=1ll*res*num%mod;

	}

	return res;

}

inline int c(int m,int n){

	return 1ll*fr[n]*ksm((1ll*fr[m]*fr[n-m])%mod,mod-2)%mod;	

}

int main(){

	ios::sync_with_stdio(0);

	cin>>n>>m;

	fr[0]=fr[1]=1;

	for(int i=2;i<maxn;i++)fr[i]=1ll*fr[i-1]*i%mod;	

	for(int i=0;i<=min(n,m);i++){

		ans=(ans+1ll*ksm(-1,i)*(1ll*c(i,n)*c(i,m)%mod*fr[i]%mod*ksm(m+1,n-i)%mod*ksm(n+1,m-i)%mod)%mod)%mod;	

	}

	ans=(ans%mod+mod)%mod;

	cout<<ans;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

#define re register int

#define F(x,y,z) for(re x=y;x<=z;x++)

#define FOR(x,y,z) for(re x=y;x>=z;x--)

typedef long long ll;

#define I inline void

#define IN inline int

const int Mod=998244353;

int n,m,ans,fac[505000],inv[505000],sum;

I add(int &x,int y){(x+=y)>=Mod?x-=Mod:0;}

IN Plus(int x,int y){(x+=y)>=Mod?x-=Mod:0;return x;}

IN C(int x,int y){return (ll)fac[x]*inv[y]%Mod*inv[x-y]%Mod;}

IN A(int x,int y){return (ll)fac[x]*inv[x-y]%Mod;}

IN Pow(int x,int y=Mod-2){

	re res=1;

	while(y){

		if(y&1)res=(ll)res*x%Mod;

		x=(ll)x*x%Mod;

		y>>=1;

	}

	return res;

}

int main(){

	ios::sync_with_stdio(false);cin.tie(0);

	cin>>n>>m;if(n>=m)swap(n,m);

	fac[0]=1;F(i,1,m)fac[i]=(ll)fac[i-1]*i%Mod;

	inv[m]=Pow(fac[m]);FOR(i,m-1,0)inv[i]=(ll)inv[i+1]*(i+1)%Mod;	

	sum=Pow(n+1,m-n);

	FOR(k,n,0){

		if(k&1)add(ans,Mod-(ll)C(n,k)*A(m,k)%Mod*sum%Mod);

		else add(ans,(ll)C(n,k)*A(m,k)%Mod*sum%Mod);

		sum=(ll)sum*(n+1)%Mod*(m+1)%Mod;

	}

	cout<<ans;

	return 0;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>

using namespace std;

int main() {

 

  int n;

  cin >> n;

  int a1[100005] = {};

  int m1 = 0;

  int p1 = 0;

  int a2[100005] = {};

  int m2 = 0;

  int p2 = 0;

  for (int i = 0; i < n; i++) {

    int tmp;

    cin >> tmp;

    if (i % 2 == 0) {

      a1[tmp]++;

      if (a1[tmp] > m1) {

        m1 = a1[tmp];

        p1 = tmp;

      }

    }

    if (i % 2 == 1) {

      a2[tmp]++;

      if (a2[tmp] > m2) {

        m2 = a2[tmp];

        p2 = tmp;

      }

    }

  }

  if (p1 == p2) {

    int M1 = 0;

    int M2 = 0;

    for (int i = 0; i <= 100000; i++) {

      if (i == p1) continue;

      M1 = max(M1, a1[i]);

      M2 = max(M2, a2[i]);

    }

    cout << n - max(m1 + M2, m2 + M1) << endl;

  }

  else {

    cout << n - m1 - m2 << endl;

  }

  return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

using namespace std;

const int MAXN=1e6+5;

int n;

int a[MAXN],num[MAXN];

struct rec{

	int x,pos;

};

rec c1[MAXN],c2[MAXN];

bool comp(const rec &x,const rec &y){

	return x.x>y.x;

}

int main(){

	scanf("%d",&n);

	for (int i=1;i<=n;++i){

		scanf("%d",&a[i]); num[i]=a[i];

	}

	sort(num+1,num+1+n);

	int nn=unique(num+1,num+1+n)-num-1;

	for (int i=1;i<=n;++i) a[i]=lower_bound(num+1,num+1+nn,a[i])-num;

	for (int i=1;i<=n;++i){

		c1[i].pos=i; c2[i].pos=i;

	}

	for (int i=1;i<=n;++i)

		if (i%2==1) ++c1[a[i]].x; else ++c2[a[i]].x;

	

	sort(c1+1,c1+1+n,comp); sort(c2+1,c2+1+n,comp);

	if (c1[1].pos==c2[1].pos) printf("%d",min(n-c1[1].x-c2[2].x,n-c1[2].x-c2[1].x)); else printf("%d",n-c1[1].x-c2[1].x);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cstring>

#define N 200005

using namespace std;

int n,a[N];

int mp1[N],mp2[N];

int mx=0,pos=0,mn=0;

int mx2=0,pos2=0,mn2=0;

int main(){

scanf("%d",&n);

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

for(int i=1;i<=n;i+=2){mp1[a[i]]++;if(mp1[a[i]]>mx)mx=mp1[a[i]],pos=a[i];else if(mp1[a[i]]>mn)mn=mp1[a[i]];}

for(int i=2;i<=n;i+=2){mp2[a[i]]++;if(mp2[a[i]]>mx2)mx2=mp2[a[i]],pos2=a[i];else if(mp2[a[i]]>mn2)mn2=mp2[a[i]];}

// cout<<mx<<" "<<pos<<" "<<mx2<<" "<<pos2<<endl;

if(pos!=pos2)  printf("%d\n",n-mx-mx2);

else   printf("%d\n",n-max(mx+mn2,mx2+mn));

return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

using namespace std;

const int MAXN=1e6+5;

int n;

int a[MAXN],num[MAXN];

struct rec{

	int x,pos;

};

rec c1[MAXN],c2[MAXN];

bool comp(const rec &x,const rec &y){

	return x.x>y.x;

}

int main(){

	scanf("%d",&n);

	for (int i=1;i<=n;++i){

		scanf("%d",&a[i]); num[i]=a[i];

	}

	sort(num+1,num+1+n);

	int nn=unique(num+1,num+1+n)-num-1;

	for (int i=1;i<=n;++i) a[i]=lower_bound(num+1,num+1+nn,a[i])-num;

	for (int i=1;i<=n;++i){

		c1[i].pos=i; c2[i].pos=i;

	}

	for (int i=1;i<=n;++i)

		if (i%2==1) ++c1[a[i]].x; else ++c2[a[i]].x;

	

	sort(c1+1,c1+1+n,comp); sort(c2+1,c2+1+n,comp);

	if (c1[1].pos==c2[1].pos) printf("%d",min(n-c1[1].x-c2[2].x,n-c1[2].x-c2[1].x)); else printf("%d",n-c1[1].x-c2[1].x);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int x[100005],y[100005];

int main()

{

    int j1=0,j2=0,o1=0,o2=0,a,b,c,d1=-1,d2=-1;

    cin>>a;

    for(b=0;b<a;b++)

    {

        scanf("%d",&c);

        if(b%2==0)

        {

            x[c]++;

            if(x[c]>j1)

            {

                if(c!=d2)

                {

                    j2=j1;

                    d2=c;

                }

                j1=x[c];



            }

            else if(x[c]>j2)

            {

                j2=x[c];

            }



        }

        else

        {

            y[c]++;

            if(y[c]>o1)

            {



                if(d1!=c)

                {

                    d1=c;

                    o2=o1;

                }

                o1=y[c];



            }

            else if(y[c]>o2)

            {

                o2=y[c];

            }

        }

    }

    if(d1==d2)

        cout<<min(a-j1-o2,a-j2-o1);

    else

        cout<<a-j1-o1;

    return 0;

}




// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

using namespace std;

const int MAXN=1e6+5;

int n;

int a[MAXN],num[MAXN];

struct rec{

	int x,pos;

};

rec c1[MAXN],c2[MAXN];

bool comp(const rec &x,const rec &y){

	return x.x>y.x;

}

int main(){

	scanf("%d",&n);

	for (int i=1;i<=n;++i){

		scanf("%d",&a[i]); num[i]=a[i];

	}

	sort(num+1,num+1+n);

	int nn=unique(num+1,num+1+n)-num-1;

	for (int i=1;i<=n;++i) a[i]=lower_bound(num+1,num+1+nn,a[i])-num;

	for (int i=1;i<=n;++i){

		c1[i].pos=i; c2[i].pos=i;

	}

	for (int i=1;i<=n;++i)

		if (i%2==1) ++c1[a[i]].x; else ++c2[a[i]].x;

	

	sort(c1+1,c1+1+n,comp); sort(c2+1,c2+1+n,comp);

	if (c1[1].pos==c2[1].pos) printf("%d",min(n-c1[1].x-c2[2].x,n-c1[2].x-c2[1].x)); else printf("%d",n-c1[1].x-c2[1].x);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



#define all(x) x.begin(), x.end()

using namespace std;



int main() {

    int N;

    cin >> N;

    vector<int> A(N), cnt1(100001), cnt2(100001);

    set<int> S;

    for (int i = 0; i < N; i++) {

        cin >> A[i];

        S.insert(A[i]);

        if (i & 1) {

            cnt2[A[i]]++;

        } else {

            cnt1[A[i]]++;

        }

    }

    if (S.size() == 1) {

        cout << N / 2 << endl;

        return 0;

    }

    if (max_element(all(cnt1)) - cnt1.begin() == max_element(all(cnt2)) - cnt2.begin()) {

        sort(all(cnt1), greater<int>());

        sort(all(cnt2), greater<int>());

        cout << min(N - (cnt1[0] + cnt2[1]), N - (cnt1[1] + cnt2[0])) << endl;

        return 0;

    }

    cout << N - (*max_element(all(cnt1)) + *max_element(all(cnt2))) << endl;



}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;

#define pb push_back

#define mp make_pair

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int,int> pii;

constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};

constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};



template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}



void solve() {

    int N;

    cin >> N;

    vector<int> A(N);

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



    if (N == 2) {

        if (A[0] == A[1]) cout << 1 << endl;

        else cout << 0 << endl;

        return;    

    }



    vector<int> c1(100001), c2(100001);

    for (int i = 0; i < N; i++) {

        if (i % 2 == 0) {

            c1[A[i]]++;

        } else {

            c2[A[i]]++;

        }

    }



    int m1 = max_element(all(c1)) - c1.begin();

    int m2 = max_element(all(c2)) - c2.begin();



    if (m1 != m2) {

        cout << N - c1[m1] - c2[m2] << endl;

        return;

    } else {

        sort(c1.rbegin(), c1.rend());

        sort(c2.rbegin(), c2.rend());

        if (c1[1] < c2[1]) {

            cout << N - c1[0] - c2[1] << endl;

        } else {

            cout << N - c2[0] - c1[1] << endl;

        }

    }

}



int main() {

    std::cin.tie(0);

    std::ios::sync_with_stdio(false);

    cout.setf(ios::fixed);

    cout.precision(16);

    solve();

    return 0;

}

// Fastest known solution for this problem: