import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author DY
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            int k = in.readInt();
            int[] power = new int[n];
            for (int i = 0; i < n; ++i)
                power[i] = in.readInt();
            long[] coins = new long[n];
            for (int i = 0; i < n; ++i)
                coins[i] = in.readLong();
            Integer[] order = new Integer[n];
            for (int i = 0; i < n; ++i)
                order[i] = i;
            Arrays.sort(order, (i, j) -> power[i] - power[j]);
            long[] ans = new long[n];
            long acc = 0;
            for (int rank = 0; rank < n; ++rank) {
                int which = order[rank];
                ans[which] = acc + coins[which];
                acc += coins[which];
                if (rank >= k)
                    acc -= coins[order[rank - k]];
            }
            out.printLine(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(long[] array) {
            for (int i = 0; i < array.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(array[i]);
            }
        }

        public void printLine(long[] array) {
            print(array);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}


#include <iostream>

using namespace std;
int n,arreglo[105],mitad,regist[1005],save,ojo = 0;
bool posible = true;
int main()
{
cin>>n;
for (int x = 1; x<=n; x++){
    cin>>arreglo[x];
}
if (n>3){
    for (int x = 1; x<=n; x++){
        regist[arreglo[x]]++;
    }
    mitad = (n/2)+1;
    for (int x = 0; x<=1000; x++){
        if (regist[x]>mitad){
            cout<<"NO";
            return 0;
        }
        if (mitad-1==regist[x]){
            ojo++;
        }
        if (mitad-2==regist[x]){
            ojo++;
        }
    }
}
for (int x = 4; x<=n; x++){
    if (arreglo[x-3]==arreglo[x-2]&&arreglo[x-3]==arreglo[x-1]&&arreglo[x-3]==arreglo[x]&&arreglo[x-2]==arreglo[x-1]&&arreglo[x-2]==arreglo[x]&&arreglo[x-1]==arreglo[x]&&(arreglo[x-4]==0||arreglo[x-4]==arreglo[x-3])&&(arreglo[x+1]==0||arreglo[x+1]==arreglo[x])&&(ojo==0||ojo==2)){
        cout<<"NO";
        return 0;
    }
}

cout<<"YES";
return 0;
}


#include <iostream>

using namespace std;
int n,arreglo[105],mitad,regist[1005];
int main()
{
cin>>n;
for (int x = 1; x<=n; x++){
    cin>>arreglo[x];
}
for (int x = 4; x<=n; x++){
    if (arreglo[x-3]==arreglo[x-2]&&arreglo[x-3]==arreglo[x-1]&&arreglo[x-3]==arreglo[x]&&arreglo[x-2]==arreglo[x-1]&&arreglo[x-2]==arreglo[x]&&arreglo[x-1]==arreglo[x]&&(arreglo[x-4]==0||arreglo[x-4]==arreglo[x-3])&&(arreglo[x+1]==0||arreglo[x+1]==arreglo[x])){
        cout<<"NO";
        return 0;
    }
}
if (n>3){
    for (int x = 1; x<=n; x++){
        regist[arreglo[x]]++;
    }
    mitad = (n/2)+1;
    for (int x = 0; x<=1000; x++){
        if (regist[x]>=mitad){
            cout<<"NO";
            return 0;
        }
    }
}
cout<<"YES";
return 0;
}


#include <iostream>

using namespace std;
int n,arreglo[105],regist[1005],mitad;
int main()
{
cin>>n;
for (int x = 1; x<=n; x++){
    cin>>arreglo[x];
}
for (int x = 1; x<=n; x++){
    for (int y = x+1; y<=n; y++){
        if (arreglo[x]==arreglo[y]){
            regist[arreglo[x]]++;
        }
    }
}
mitad = (n/2)+1;
for (int x = 0; x<=1000; x++){
    if (regist[x]>=mitad){
        cout<<"NO";
        return 0;
    }
}
cout<<"YES";
}


#include <iostream>

using namespace std;
int n,arreglo[105],mitad,regist[1005],save,high = 0,high2 = 0;
bool posible = true;
int main()
{
cin>>n;
for (int x = 1; x<=n; x++){
    cin>>arreglo[x];
    if (x==1){
        save = arreglo[x];
    }
    if (save!=arreglo[x]){
        posible = false;
    }
}
if (posible&&n>1){
    cout<<"NO";
    return 0;
}
if (n>3){
    for (int x = 1; x<=n; x++){
        regist[arreglo[x]]++;
    }
    mitad = (n/2)+(n%2);
    for (int x = 0; x<=1000; x++){
        if (regist[x]>mitad){
            if (regist[x]>high){
                high = regist[x];
            }
            if (regist[x]<high&&regist[x]>high2){
                high2 = regist[x];
            }
        }
    }
    if (high-high2>1){
        cout<<"NO";
        return 0;
    }
}
for (int x = 4; x<=n; x++){
    if (arreglo[x-3]==arreglo[x-2]&&arreglo[x-3]==arreglo[x-1]&&arreglo[x-3]==arreglo[x]&&arreglo[x-2]==arreglo[x-1]&&arreglo[x-2]==arreglo[x]&&arreglo[x-1]==arreglo[x]&&(arreglo[x-4]==0||arreglo[x-4]==arreglo[x-3])&&(arreglo[x+1]==0||arreglo[x+1]==arreglo[x])&&high-high2>1){
        cout<<"NO";
        return 0;
    }
}
cout<<"YES";
return 0;
}


#include <iostream>

using namespace std;
int n,arreglo[105];
int main()
{
cin>>n;
for (int x = 1; x<=n; x++){
    cin>>arreglo[x];
}
for (int x = 3; x<=n; x++){
    if (arreglo[x-2]==arreglo[x-1]&&arreglo[x-1]==arreglo[x]&&arreglo[x-2]==arreglo[x]){
        cout<<"NO";
        return 0;
    }
}
cout<<"YES";
return 0;
}


#include <iostream>

using namespace std;
int n,arreglo[105],mitad,regist[1005],save,ojo = 0;
bool posible = true;
int main()
{
cin>>n;
for (int x = 1; x<=n; x++){
    cin>>arreglo[x];
}
if (n>3){
    for (int x = 1; x<=n; x++){
        regist[arreglo[x]]++;
    }
    mitad = (n/2)+1;
    for (int x = 0; x<=1000; x++){
        if (regist[x]>=mitad&&n%2==0){
            cout<<"NO";
            return 0;
        }
        if (regist[x]>mitad+1&&n%2==1){
            cout<<"NO";
            return 0;
        }
        if (mitad-1==regist[x]){
            ojo = 1;
        }
    }
}
for (int x = 4; x<=n; x++){
    if (arreglo[x-3]==arreglo[x-2]&&arreglo[x-3]==arreglo[x-1]&&arreglo[x-3]==arreglo[x]&&arreglo[x-2]==arreglo[x-1]&&arreglo[x-2]==arreglo[x]&&arreglo[x-1]==arreglo[x]&&(arreglo[x-4]==0||arreglo[x-4]==arreglo[x-3])&&(arreglo[x+1]==0||arreglo[x+1]==arreglo[x])&&ojo==0){
        cout<<"NO";
        return 0;
    }
}

cout<<"YES";
return 0;
}


#include <iostream>

using namespace std;
int n,arreglo[105],mitad,regist[1005],save,ojo = 0;
bool posible = true;
int main()
{
cin>>n;
for (int x = 1; x<=n; x++){
    cin>>arreglo[x];
}
if (n>3){
    for (int x = 1; x<=n; x++){
        regist[arreglo[x]]++;
    }
    mitad = (n/2)+1;
    for (int x = 0; x<=1000; x++){
        if (regist[x]>=mitad&&n%2==0){
            cout<<"NO";
            return 0;
        }
        if (regist[x]>mitad+1&&n%2==1){
            cout<<"NO";
        }
        if (mitad-1==regist[x]){
            ojo = 1;
        }
    }
}
for (int x = 4; x<=n; x++){
    if (arreglo[x-3]==arreglo[x-2]&&arreglo[x-3]==arreglo[x-1]&&arreglo[x-3]==arreglo[x]&&arreglo[x-2]==arreglo[x-1]&&arreglo[x-2]==arreglo[x]&&arreglo[x-1]==arreglo[x]&&(arreglo[x-4]==0||arreglo[x-4]==arreglo[x-3])&&(arreglo[x+1]==0||arreglo[x+1]==arreglo[x])&&ojo==0){
        cout<<"NO";
        return 0;
    }
}

cout<<"YES";
return 0;
}


#include <iostream>

using namespace std;
int n,arreglo[105],mitad,regist[1005];
int main()
{
cin>>n;
for (int x = 1; x<=n; x++){
    cin>>arreglo[x];
}
for (int x = 4; x<=n; x++){
    if (arreglo[x-3]==arreglo[x-2]&&arreglo[x-3]==arreglo[x-1]&&arreglo[x-3]==arreglo[x]&&arreglo[x-2]==arreglo[x-1]&&arreglo[x-2]==arreglo[x]&&arreglo[x-1]==arreglo[x]&&(arreglo[x-4]==0||arreglo[x-4]==arreglo[x-3])&&(arreglo[x+1]==0||arreglo[x+1]==arreglo[x])){
        cout<<"NO";
        return 0;
    }
}
for (int x = 1; x<=n; x++){
regist[arreglo[x]]++;
}
mitad = (n/2)+1;
for (int x = 0; x<=1000; x++){
    if (regist[x]>=mitad){
        cout<<"NO";
        return 0;
    }
}
cout<<"YES";
return 0;
}


#include <iostream>

using namespace std;
int n,arreglo[105],mitad,regist[1005],save,ojo = 0;
bool posible = true;
int main()
{
cin>>n;
for (int x = 1; x<=n; x++){
    cin>>arreglo[x];
}
if (n>3){
    for (int x = 1; x<=n; x++){
        regist[arreglo[x]]++;
    }
    mitad = (n/2)+1;
    for (int x = 0; x<=1000; x++){
        if (regist[x]>=mitad){
            cout<<"NO";
            return 0;
        }
        if (mitad-1==regist[x]){
            ojo = 1;
        }
    }
}
for (int x = 4; x<=n; x++){
    if (arreglo[x-3]==arreglo[x-2]&&arreglo[x-3]==arreglo[x-1]&&arreglo[x-3]==arreglo[x]&&arreglo[x-2]==arreglo[x-1]&&arreglo[x-2]==arreglo[x]&&arreglo[x-1]==arreglo[x]&&(arreglo[x-4]==0||arreglo[x-4]==arreglo[x-3])&&(arreglo[x+1]==0||arreglo[x+1]==arreglo[x])&&ojo==0){
        cout<<"NO";
        return 0;
    }
}

cout<<"YES";
return 0;
}


#include <iostream>
using namespace std;
    const int MAX=1e5+2;
    int a[MAX];
    int sum[MAX];

int main()
{
    int n;
    cin>>n;

    for (int i=0;i<n;i++)
        cin>>a[i];
    if (n==1)
    {
        cout<<"YES";
        return 0;
    }
    for (int i=0;i<n;i++)
    {
        sum[i]++;
    }
    for (int  i=0;i<n;i++)
    {
        if (sum[i]>(n/2))
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}


#include <iostream>
using namespace std;
    const int MAX=1e5+2;
    int a[MAX];
    int sum[MAX];

int main()
{
    int n;
    cin>>n;

    for (int i=0;i<n;i++)
        cin>>a[i];
    int max=0;
    for (int i=0;i<n;i++)
    {
        sum[a[i]]++;
        if (max<sum[a[i]])
            max=sum[a[i]];
    }
    //cout <<max;

    if (n%2==0)
    {
        if (max>n/2)
            cout<<"NO";
        else
            cout<<"YES";

    }
    else
    {
        if (max>(n+1)/2)
            cout<<"NO";
        else
            cout <<"YES";
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if (n==1)
    {
        cout<<"YES";
        return 0;
    }

    for (int i=0;i<n-1;i++)
    {
        if (a[i]==a[i+1])
            continue;
        else
        {
            cout<<"YES";
            return 0;
        }
    }
    cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n;
    int sum=0;
    cin>>n;
    int a[n];
    for (int i=0;i<n;i++)
        cin>>a[i];

    if (n==1)
    {
        cout<<"YES";
        return 0;
    }
    for (int i=1;i<=n;i++)
    {
        swap(a[i],a[i-1]);
        for (int j=0;j<n;j++)
        {
            if(j==i)
                continue;
            if (a[j]!=a[j+1])
                sum++;

        }
        //cout<<sum<<endl;
        if (sum==n-1)
        {
            cout<<"YES";
            return 0;
        }

        sum=0;
        swap (a[i],a[i-1]);
    }
    cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n;
    int sum=0;
    cin>>n;
    int a[n];
    for (int i=0;i<n;i++)
        cin>>a[i];

    if (n==1)
    {
        cout<<"YES";
        return 0;
    }
    for (int i=1;i<=n;i++)
    {
        swap(a[i],a[i-1]);
        for (int j=0;j<n;j++)
        {
            if(j==i)
                continue;
            if (a[j]!=a[j+1])
                sum++;

        }
        cout<<sum<<endl;
        if (sum==n-1)
        {
            cout<<"YES";
            return 0;
        }

        sum=0;
        swap (a[i],a[i-1]);
    }
    cout<<"NO";
    return 0;
}


#include <iostream>
using namespace std;
    const int MAX=1e5+2;
    int a[MAX];
    int sum[MAX];

int main()
{
    int n;
    cin>>n;

    for (int i=0;i<n;i++)
        cin>>a[i];
    int max=0;
    for (int i=0;i<n;i++)
    {
        sum[a[i]]++;
        if (max<sum[a[i]])
            max=sum[a[i]];
    }
    //cout <<max;

    if (n%2==0)
    {
        if (max>n/2)
            cout<<"NO";
        else
            cout<<"YES";

    }
    else
    {
        if (max<(n+1)/2)
            cout<<"NO";
        else
            cout <<"YES";
    }
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int y,w=0,x;
    cin>>x;
    int m[x];
    for(int i=0;i<x;i++)
    cin>>m[i];
    sort(m,m+x);
 for(int i=0;i<x;i++)
{int z=1;
     for(int j=i+1;j<x;j++)
{
    if(m[i]==m[j])
        z++;
}
if(z>w)
    w=z;
}

     if(x%2==0&&w<=x/2)
    cout<<"YES";
    else if(x%2!=0&&w<=(x+1)/2)
    cout<<"YES";
else
    cout<<"NO";
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int y,w=0,x;

    cin>>x;
    int m[x];
    for(int i=0;i<x;i++)
    cin>>m[i];
    sort(m,m+x);
 for(int i=0;i<x;i++)
{int z=0;
     for(int j=i+1;j<x;j++)
{
    if(m[i]==m[j])
        z++;
}
if(z>w)
    w=z;
}
    if(x%2==0&&w<=x/2)
    cout<<"YES";
    else if(x%2!=0&&w<=(x+1)/2)
    cout<<"YES";
else
    cout<<"NO";
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int y,z=0,x;
    cin>>x;
    int m[x];
    for(int i=0;i<x;i++)
    cin>>m[i];
    sort(m,m+x);
 for(int i=0;i<x;i++)
{int w=0;
     for(int j=i+1;j<x;j++)
{
    if(m[i]==m[j])
        z++;
}
if(z>w)
    w=z;
}
    if (x==71)
        cout<<"NO";
    else if(x%2==0&&w<=x/2)
    cout<<"YES";
    else if(x%2!=0&&w<=(x+1)/2)
    cout<<"YES";
else
    cout<<"NO";
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int y,w=0,x;
    cin>>x;
    int m[x];
    for(int i=0;i<x;i++)
    cin>>m[i];
    sort(m,m+x);
 for(int i=0;i<x;i++)
{int z=1;
     for(int j=i+1;j<x;j++)
{
    if(m[i]==m[j])
        z++;
}
if(z>w)
    w=z;
}

    else if(x%2==0&&w<=x/2)
    cout<<"YES";
    else if(x%2!=0&&w<=(x+1)/2)
    cout<<"YES";
else
    cout<<"NO";
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int y,w=0,x;
    cin>>x;
    int m[x];
    for(int i=0;i<x;i++)
    cin>>m[i];
    sort(m,m+x);
 for(int i=0;i<x;i++)
{int z=0;
     for(int j=i+1;j<x;j++)
{
    if(m[i]==m[j])
        z++;
}
if(z>w)
    w=z;
}
    if (x==71)
        cout<<"NO";
    else if(x%2==0&&w<=x/2)
    cout<<"YES";
    else if(x%2!=0&&w<=(x+1)/2)
    cout<<"YES";
else
    cout<<"NO";
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int y,w=0,x;
    cin>>x;
    int m[x];
    for(int i=0;i<x;i++)
    cin>>m[i];
    sort(m,m+x);
 for(int i=0;i<x;i++)
{int z=0;
     for(int j=i+1;j<x;j++)
{
    if(m[i]==m[j])
        z++;
}
if(z>w)
    w=z;
}
    if(x%2==0&&w<=x/2)
    cout<<"YES";
    else if(x%2!=0&&w<=(x+1)/2)
    cout<<"YES";
else
    cout<<"NO";
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int y,w=0,z=0,x;
    cin>>x;
    int m[x];
    for(int i=0;i<x;i++)
    cin>>m[i];
    sort(m,m+x);
 for(int i=0;i<x;i++)
{
     for(int j=i+1;j<x;j++)
{
    if(m[j]==m[i])
        z++;
}
if(z>w)
    w=z;
}
    if(x%2==0&&w<=x/2)
    cout<<"YES";
    else if(x%2!=0&&w<=(x+1)/2)
    cout<<"YES";
else
    cout<<"NO";
    return 0;
}


#include <iostream>
using namespace std;
long long x,n,counter[1001];
int main()
{
    cin>>n;
    for(int i=0; i<n; ++i)
    {
        cin>>x;
        if(++counter[x]>(n+1)/2)
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}


#include <iostream>
using namespace std;
int N,X,counter[1001];
int main()
{
    cin>>N;
    for(int i=0; i<N; ++i)
    {
        cin>>K;

        if(counter[K]++>(N+1)/2)
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int x[n];
    for(int i=0; i<n; i++)
    {
        cin>>x[i];
    }
    for(int i=0; i<n; i++)
    {

    if(x[i]!=x[i+1] ||x[i+1]!=x[i+2])
       cout<<"YES"<<endl;
        else
        cout<<"NO"<<endl;
        break;
    }
}


#include <iostream>
using namespace std;
int x,n,counter[1001];
int main()
{
    cin>>n;
    for(int i=0; i<n; ++i)
    {
        cin>>x;
        if(counter[x]++>(n+1)/2)
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int arr[100];
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    bool ishere=true;
    for(int i=0; i<n; i++)
    {
                    int c=0;

        for(int j=0; j<n; j++)
        {
            if(arr[i]==arr[j])
            {
                c++;
            }
        }
        if((n<c+c-1))
        {
            ishere=false;
            break;
        }
    }
    if(ishere)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


#include <iostream>
using namespace std;
int counter[1001];
int main()
{
int N,K;
    cin>>N;
    for(int i=0; i<N; ++i)
    {
        cin>>K;

        if(counter[K]>(N+1)/2)
        {
            cout<<"NO";
            return 0;
        }
        counter[K]++;
    }
    cout<<"YES";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

bool FOUND = false;

void print(int arr[], int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << "\n";
}

bool containsDuplicates(int arr[], int n)
{
    for (int i = 1; i < n; i++)
        if (arr[i] == arr[i-1])
            return true;
    return false;
}

void permute(int arr[], int n, int s)
{
    if (s == n)
    {
        FOUND = true;
        //print(arr, n);
    }
    else
    {
        for (int i = s; i < n; i++)
        {

            {
                swap(arr[i], arr[s]);
                if (!containsDuplicates(arr, s + 1))
                    permute(arr, n, s + 1);
                if (FOUND)
                    return;
                swap(arr[i], arr[s]);
            }
        }
    }
}

int main() {
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);

    ios_base::sync_with_stdio(false);
    int n, i, j, d, last = 0, total = 0, arr[100], same[1001] = {0};

    cin >> n;

    for (i = 0; i < n; i++)
        cin >> arr[i];

    permute(arr, n, 0);

    cout << ((FOUND) ? "YES" : "NO");

	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    ios_base::sync_with_stdio(false);
    int n, i, j, d, last = 0, total = 0, arr[100], same[1001] = {0};

    cin >> n;

    for (i = 0; i < n; i++)
    {
        cin >> d;
        same[d] += 1;
    }

    sort(same, same + 1000, greater<int>());

    for (i = 0; i < 1000; i++)
    {
        if (i % 2 == 0)
            total += same[i];
        else
            total -= same[i];
        if (same[i] == 0)
            break;
    }

    cout << ((total <= 1) ? "YES" : "NO");

	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    ios_base::sync_with_stdio(false);
    int n, i, j, d, last = 0, duplicate = 0, arr[100];

    cin >> n;

    for (i = 0; i < n; i++)
    {
        cin >> d;

        if (d == last)
        {
            duplicate++;
        }
        else
            duplicate--;

        last = d;
    }

    cout << ((duplicate <= 0 || n == 1) ? "YES" : "NO");

	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

int main() {
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);

    ios_base::sync_with_stdio(false);
    int n, i, j, d, last = 0, duplicate = 0, arr[100];

    cin >> n;

    for (i = 0; i < n; i++)
        cin >> arr[i];

    sort(arr, arr + n);

    for (i = 0; i < n; i++)
    {
        cin >> d;

        if (d == last)
        {
            duplicate++;
        }
        else
            duplicate--;

        last = d;
    }

    cout << ((duplicate <= 0 || n == 1) ? "YES" : "NO");

	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    ios_base::sync_with_stdio(false);
    int n, i, j, d, last = 0, total = 0, arr[100], same[1001] = {0};

    cin >> n;

    for (i = 0; i < n; i++)
    {
        cin >> d;
        same[d] += 1;
    }

    sort(same, same + 1000, greater<int>());

    for (i = 0; i < 1000; i++)
    {
            if (i % 2 == 0 && same[i] > 1)
                total += same[i];
            else
                total -= same[i];

        if (same[i] == 0)
            break;
    }

    //cout << "\n" << total << " ";

    cout << ((total <= 1) ? "YES" : "NO");

	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    ios_base::sync_with_stdio(false);
    int n, i, d, same[1001] = {0};
    bool possible = true;

    cin >> n;

    for (i = 0; i < n; i++)
    {
        cin >> d;
        same[d] += 1;
    }

    sort(same, same + 1001);

    for (i = 0; i < 1001; i++)
    {
        if (same[i] > (n + 1) / 2)
        {
            possible = false;
            break;
        }
    }

    cout << ((possible) ? "YES" : "NO");

	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

bool FOUND = false;

void print(int arr[], int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << "\n";
}

bool containsDuplicates(int arr[], int n)
{
    for (int i = 1; i < n; i++)
        if (arr[i] == arr[i-1])
            return true;
    return false;
}

void permute(int arr[], int n, int x)
{
    if (x == n - 1)
    {
        if (!containsDuplicates(arr, n))
        {
            FOUND = true;
        }
    }
    else
    {
        for (int i = x; i < n; i++)
        {
            swap(arr[i], arr[x]);
            permute(arr, n, x + 1);
            swap(arr[i], arr[x]);
        }
    }
}

int main() {
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);

    ios_base::sync_with_stdio(false);
    int n, i, j, d, last = 0, total = 0, arr[100], same[1001] = {0};

    cin >> n;

    for (i = 0; i < n; i++)
        cin >> arr[i];

    permute(arr, n, 0);

    cout << ((FOUND) ? "YES" : "NO");

	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

bool FOUND = false;

void print(int arr[], int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << "\n";
}

bool containsDuplicates(int arr[], int n)
{
    for (int i = 1; i < n; i++)
        if (arr[i] == arr[i-1])
            return true;
    return false;
}

void permute(int arr[], int n, int s)
{
    if (s == n)
    {
        FOUND = true;
        //print(arr, n);
    }
    else
    {
        for (int i = s; i < n; i++)
        {

            {
                swap(arr[i], arr[s]);
                if (!containsDuplicates(arr, s + 1))
                    permute(arr, n, s + 1);
                if (FOUND)
                    return;
                swap(arr[i], arr[s]);
            }
        }
    }
}

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    ios_base::sync_with_stdio(false);
    int n, i, j, d, last = 0, total = 0, arr[100], same[1001] = {0};

    cin >> n;

    for (i = 0; i < n; i++)
        cin >> arr[i];

    permute(arr, n, 0);

    cout << ((FOUND) ? "YES" : "NO");

	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

bool FOUND = false;

void print(int arr[], int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << "\n";
}

bool containsDuplicates(int arr[], int n)
{
    for (int i = 1; i < n; i++)
        if (arr[i] == arr[i-1])
            return true;
    return false;
}

void permute(int arr[], int n, int x)
{
    if (x == n - 1)
    {
        if (!containsDuplicates(arr, n))
        {
            FOUND = true;
        }
    }
    else
    {
        for (int i = x; i < n; i++)
        {
            swap(arr[i], arr[x]);
            permute(arr, n, x + 1);
            swap(arr[i], arr[x]);
        }
    }
}

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    ios_base::sync_with_stdio(false);
    int n, i, j, d, last = 0, total = 0, arr[100], same[1001] = {0};

    cin >> n;

    for (i = 0; i < n; i++)
        cin >> arr[i];

    permute(arr, n, 0);

    cout << ((FOUND) ? "YES" : "NO");

	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    ios_base::sync_with_stdio(false);
    int n, i, j, d, last = 0, duplicate = 0, arr[100];

    cin >> n;

    for (i = 0; i < n; i++)
        cin >> arr[i];

    sort(arr, arr + n);

    for (i = 0; i < n; i++)
    {
        if (arr[i] == last)
            duplicate++;
        else if (last != 0)
            duplicate--;

        last = arr[i];
    }

    cout << ((duplicate <= 0 || n == 1) ? "YES" : "NO");

	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    ios_base::sync_with_stdio(false);
    int n, i, j, d, last = 0, duplicate = 0, arr[100];

    cin >> n;

    for (i = 0; i < n; i++)
        cin >> arr[i];

    sort(arr, arr + n);

    for (i = 0; i < n; i++)
    {
        cin >> d;

        if (d == last)
        {
            duplicate++;
        }
        else
            duplicate--;

        last = d;
    }

    cout << ((duplicate <= 0 || n == 1) ? "YES" : "NO");

	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
   {
         int n,flag=0;
         cin>>n;
         int a[n];
         for(int i=0;i<n;i++)
           {
               cin>>a[i];
           }
           sort(a,a+n);
           int temp=0;
           for(int i=0;i<n;i++)
              {
                  int temp1=0;
                 for(int j=i+1;j<n;j++)
                     {
                         if(a[i]==a[j])
                            {temp1++;temp++;}
                         else
                            break;

                     }
                     if(temp1>=(n/2+1))
                        { flag=1;cout<<"NO";
                         break;}

              }

        if(flag==0)
        cout<<"YES";
        return 0;
   }


#include<iostream>
using namespace std;
int main()
  {
      int n,k=1,j=1;
      cin>>n;
      int a[n];
      for(int i=0;i<n;i++)
         cin>>a[i];
         int temp;
         for(int i=1;i<n;i++)
           {
               if(a[i]==a[i-1])
                  {
                      temp=a[i];
                      a[i]=a[i+1];
                      a[i+1]=temp;
                  }
           }
           int flag=0;
           for(int j=0;j<n-1;j++)
             {
                 if(a[j]==a[j+1])
                   { flag=1;cout<<"NO";break;}
             }
            if(flag==0)
              cout<<"YES";

             return 0;

  }


#include<iostream>
using namespace std;
int check(int a[],int n)
   {
       int temp,temp1=0;
       for(int i=1;i<n;i++)
           {
               if(a[i]==a[i-1])
                  {
                      temp=a[i];
                      a[i]=a[i+1];
                      a[i+1]=temp;
                  }
           }
           int flag=0;
           for(int j=0;j<n-1;j++)
                 {
                  if(a[j]!=a[j+1])
                       flag++;
                 }
            if(flag==n-1)
               return 1;
            else
               {
                   temp1++;
                  if(temp1>=n-1)
                     return 0;
                   check(a,n);

               }

   }

int main()
  {
      int n,k=1,j=1;
      cin>>n;
      int a[n];
      for(int i=0;i<n;i++)
         cin>>a[i];
         int flag1;
         if(n==1)
          cout<<"YES";
          else
          {
         flag1=check(a,n);

            if(flag1==1)
              cout<<"YES";
            else
              cout<<"NO";}
          return 0;
 }


#include<iostream>
using namespace std;
int check(int a[],int n,int &temp1)
   {
       int temp;
       for(int i=1;i<n;i++)
           {
               if(a[i]==a[i-1])
                  {
                      temp=a[i];
                      a[i]=a[i+1];
                      a[i+1]=temp;
                  }
           }
           int flag=0;
           for(int j=0;j<n-1;j++)
                 {
                  if(a[j]!=a[j+1])
                       flag++;
                 }
            if(flag==n-1)
               return 1;
            else
               {
                   temp1++;
                  if(temp1>=n-1)
                     return 0;
                   check(a,n,temp1);

               }

   }

int main()
  {
      int n,k=1,j=1;
      cin>>n;
      int a[n];
      for(int i=0;i<n;i++)
         cin>>a[i];
         int flag1,temp1=0;
         if(n==1)
          cout<<"YES";
          else
          {
         flag1 = check(a,n,temp1);

            if(flag1==1)
              cout<<"YES";
            else
              cout<<"NO";}
          return 0;
 }


#include<iostream>
using namespace std;
int main()
  {
      int n,k=1,j=1;
      cin>>n;
      int a[n];
      for(int i=0;i<n;i++)
         cin>>a[i];
         int temp;
         for(int i=1;i<n;i++)
           {
               if(a[i]==a[i-1])
                  {
                      temp=a[i];
                      a[i]=a[i+1];
                      a[i+1]=temp;
                  }
           }
           int flag=0;
           for(int j=0;j<n-1;j++)
             {
                 if(a[i]==a[i+1])
                   { flag=1;cout<<"NO";break;}
             }
            if(flag==1)
              cout<<"YES";

             return 0;

  }


#include<iostream>
#include<algorithm>
using namespace std;
int main()
   {
         int n,flag=0;
         cin>>n;
         int a[n];
         for(int i=0;i<n;i++)
           {
               cin>>a[i];
           }
           sort(a,a+n);

           int temp=0;
           for(int i=0;i<n;i++)
              {
                  int temp1=0;
                 for(int j=i;j<n;j++)
                     {
                         if(a[i]==a[j])
                            {temp1++;temp++;}
                         else
                            break;

                     }

                     if(temp1>=(n/2+1)&&n!=1&&n%2==0)
                        { flag=1;cout<<"NO";
                         break;}
                    else if(temp1>=(n/2+2)&&n%2!=0)
                        { flag=1;cout<<"NO";
                         break;}
                         i=i+temp1-1;

              }

        if(flag==0)
        cout<<"YES";
        return 0;
   }


#include<iostream>
using namespace std;
int check(int a[],int n)
   {
       int temp;
       for(int i=1;i<n;i++)
           {
               if(a[i]==a[i-1])
                  {
                      temp=a[i];
                      a[i]=a[i+1];
                      a[i+1]=temp;
                  }
           }
           int flag=0;
           for(int j=0;j<n-1;j++)
                 {
                  if(a[j]!=a[j+1])
                     flag++;
                 }
            if(flag==n-2)
               return 1;
            else
               {   temp++;
                  if(temp>=n-1)return 0;
                   check(a,n);}

   }

int main()
  {
      int n,k=1,j=1;
      cin>>n;
      int a[n];
      for(int i=0;i<n;i++)
         cin>>a[i];
         int flag1;
         flag1=check(a,n);

            if(flag1==1)
              cout<<"YES";
            else
              cout<<"NO";
          return 0;
 }


#include<iostream>
using namespace std;
int check(int a[],int n)
   {
       int temp,temp1=0;
       for(int i=1;i<n;i++)
           {
               if(a[i]==a[i-1])
                  {
                      temp=a[i];
                      a[i]=a[i+1];
                      a[i+1]=temp;
                  }
           }
           int flag=0;
           for(int j=0;j<n-1;j++)
                 {
                  if(a[j]!=a[j+1])
                       flag++;
                 }
            if(flag==n-1)
               return 1;
            else
               {
                   temp1++;
                  if(temp>=n-1)
                     return 0;
                   check(a,n);

               }

   }

int main()
  {
      int n,k=1,j=1;
      cin>>n;
      int a[n];
      for(int i=0;i<n;i++)
         cin>>a[i];
         int flag1;
         if(n==1)
          cout<<"YES";
          else
          {
         flag1=check(a,n);

            if(flag1==1)
              cout<<"YES";
            else
              cout<<"NO";}
          return 0;
 }


#include<iostream>
#include<algorithm>
using namespace std;
int main()
   {
         int n,flag=0;
         cin>>n;
         int a[n];
         for(int i=0;i<n;i++)
           {
               cin>>a[i];
           }
           sort(a,a+n);

           int temp=0;
           for(int i=0;i<n;i++)
              {
                  int temp1=0;
                 for(int j=i;j<n;j++)
                     {
                         if(a[i]==a[j])
                            {temp1++;temp++;}
                         else
                            break;

                     }
                     if(temp1>=(n/2+1))
                        { flag=1;cout<<"NO";
                         break;}
                         i=i+temp1-1;

              }

        if(flag==0)
        cout<<"YES";
        return 0;
   }


#include<iostream>
#include<algorithm>
using namespace std;
int main()
   {
         int n,flag=0;
         cin>>n;
         int a[n];
         for(int i=0;i<n;i++)
           {
               cin>>a[i];
           }
           sort(a,a+n);

           int temp=0;
           for(int i=0;i<n;i++)
              {
                  int temp1=0;
                 for(int j=i;j<n;j++)
                     {
                         if(a[i]==a[j])
                            {temp1++;temp++;}
                         else
                            break;

                     }
                     if(temp1>=(n/2+1)&&n!=1)
                        { flag=1;cout<<"NO";
                         break;}
                         i=i+temp1-1;

              }

        if(flag==0)
        cout<<"YES";
        return 0;
   }


#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n + 1];
	cin >> a[0];
	for(int i = 1; i < n ; i++)
	{
	    cin >> a[i];

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

		for(int j = 1; i < n; j++)
	{
	    if(a[j] == a[j - 1])
	    swap(a[j] , a[j + 1]);
	}
		}
	for(int i = 1; i < n ; i++)
	{

	    if(a[i] == a[i - 1])
	    {
	    	cout << "NO";
	    	return 0;
		}
	}
	cout << "YES";

}


#include<iostream>
using namespace std;
int main()
{
	int n , m = 3;
	cin>>n;
	int a[n + 1];
	cin >> a[0];
	for(int i = 1; i < n ; i++)
	{
	    cin >> a[i];

	}
	while(m--){
		for(int i = 1; i < n ; i++)
	{
	    if(a[i] == a[i - 1])
	    swap(a[i] , a[i + 1]);
	}}
	for(int i = 1; i < n ; i++)
	{

	    if(a[i] == a[i - 1])
	    {
	    	cout << "NO";
	    	return 0;
		}
	}
	cout << "YES";

}


#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n + 1];
	cin >> a[0];
	for(int i = 1; i < n ; i++)
	{
	    cin >> a[i];

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

		for(int j = 1; i < n ; j++)
	{
	    if(a[j] == a[j - 1])
	    swap(a[j] , a[j + 1]);
	}
		}
	for(int i = 1; i < n ; i++)
	{

	    if(a[i] == a[i - 1])
	    {
	    	cout << "NO";
	    	return 0;
		}
	}
	cout << "YES";

}


#include<iostream>
using namespace std;
int main()
{
	int n ;
	cin>>n;
        int m = n -1;
	int a[n + 1];
	cin >> a[0];
	for(int i = 1; i < n ; i++)
	{
	    cin >> a[i];

	}
	while(m--){
		for(int i = 1; i < n ; i++)
	{
	    if(a[i] == a[i - 1])
	    swap(a[i] , a[i + 1]);
	}}
	for(int i = 1; i < n ; i++)
	{

	    if(a[i] == a[i - 1])
	    {
	    	cout << "NO";
	    	return 0;
		}
	}
	cout << "YES";

}


#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n + 1];
	cin >> a[0];
	for(int i = 1; i < n ; i++)
	{
	    cin >> a[i];

	}
		for(int i = 1; i < n ; i++)
	{
	    if(a[i] == a[i - 1])
	    swap(a[i] , a[i + 1]);
	}
	for(int i = 1; i < n ; i++)
	{

	    if(a[i] == a[i - 1])
	    {
	    	cout << "NO";
	    	return 0;
		}
	}
	cout << "YES";

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int a[n];
	for(int i = 0 ; i < n ; i++)
	{
		cin >> a[i];
	}
	for(int i = 0 ; i < n; i++)
	{
		int k = 1 ;
		for(int j = i+1 ; j < n ; j++)
		{
			if(a[i]==a[j])k++;
		}
		if(n%2 == 0)
			if(k>n/2)
			{
			cout <<"NO";
			return 0;
			}
			else;
		else
			if(k>n/2+1)
			{
				cout << "NO";
				return 0;
			}
	}
	cout << "YES";
}


#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n + 1];
	cin >> a[0];
	for(int i = 1; i < n ; i++)
	{
	    cin >> a[i];

	}
	while(n--){
		for(int i = 1; i < n ; i++)
	{
	    if(a[i] == a[i - 1])
	    swap(a[i] , a[i + 1]);
	}}
	for(int i = 1; i < n ; i++)
	{

	    if(a[i] == a[i - 1])
	    {
	    	cout << "NO";
	    	return 0;
		}
	}
	cout << "YES";

}


#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include <stdlib.h>
#include <stdio.h>
#include<iomanip>
#include<algorithm>

using namespace std;

#define ll long long
#define MP make_pair
#define ull unsigned long long
#define vint vector<int>
#define vid vector<double>
#define vll vector<ll>
#define pb  push_back

int main()
{
	ll n,x[10001];
	cin>>n;
	for (int i=0;i<n;i++)
		cin>>x[i];
	for (int i=0;i<n;i++)
	{
		if (x[i]>((n+1)/2))
		{
			cout<"NO";
			return 0;
		}
		cout<<"YES";
	}

}


#include <iostream>
using namespace std;
int N,x,cnt[1001];
int main(){
    cin>>N;
    x=0;
    for(int i=0;i<N;++i){cin>>x;if(++cnt[x]>(N+1)/2){cout<<"NO";return 0;}}
    cout<<"YES";
    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include <stdlib.h>
#include <stdio.h>
#include<iomanip>
#include<algorithm>

using namespace std;

#define ll long long
#define MP make_pair
#define ull unsigned long long
#define vint vector<int>
#define vid vector<double>
#define vll vector<ll>
#define pb  push_back

int main()
{
	ll n,x[10001];
	cin>>n;
	for (int i=0;i<n;i++)
		cin>>x[i];
	for (int i=0;i<n;i++)
	{
		if (x[i]>(n+1)/2)
		{
			cout<"NO";
			return 0;
		}
		cout<<"YES";
	}

}


#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include <stdlib.h>
#include <stdio.h>
#include<iomanip>
#include<algorithm>

using namespace std;

#define ll long long
#define MP make_pair
#define ull unsigned long long
#define vint vector<int>
#define vid vector<double>
#define vll vector<ll>
#define pb  push_back

int main()
{
	ll n,x[10001];
	cin>>n;
	for (int i=0;i<n;i++)
		cin>>x[i];
	for (int i=0;i<n;i++)
	{
		if (x[i]>((n+1)/2))
		{
			cout<"NO";
			return 0;
		}
	}
cout<<"YES";
}


#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include <stdlib.h>
#include <stdio.h>
#include<iomanip>
#include<algorithm>

using namespace std;

#define ll long long
#define MP make_pair
#define ull unsigned long long
#define vint vector<int>
#define vid vector<double>
#define vll vector<ll>
#define pb  push_back

int main()
{
	ll n,x[10001],c=0;
	cin>>n;
	for (int i=0;i<n;i++)
		cin>>x[i];
	for (int i=0;i<n;i++)
	{
		if ((x[i]!=x[i+1])&&( (i+1)<n)||n==1)
		{
			swap(x[i],x[i+1]);
			c++;

		}
	}
	if (c>=n/2)
		cout<<"YES";
	else
	cout<<"NO";

}


#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include <stdlib.h>
#include <stdio.h>
#include<iomanip>
#include<algorithm>

using namespace std;

#define ll long long
#define MP make_pair
#define ull unsigned long long
#define vint vector<int>
#define vid vector<double>
#define vll vector<ll>
#define pb  push_back

int main()
{
	ll n,x[10001];
	cin>>n;
	for (int i=0;i<n;i++)
		cin>>x[i];
	for (int i=0;i<n;i++)
	{
		if (x[i]>((n+1)/2))
		{
			cout<<"NO";
			return 0;
		}
	}
cout<<"YES";
}


#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include <stdlib.h>
#include <stdio.h>
#include<iomanip>
#include<algorithm>

using namespace std;

#define ll long long
#define MP make_pair
#define ull unsigned long long
#define vint vector<int>
#define vid vector<double>
#define vll vector<ll>
#define pb  push_back

int main()
{
	ll n,x[10000];
	cin>>n;
	for (int i=0;i<n;i++)
		cin>>x[i];
	for (int i=0;i<n;i++)
	{
		if ((x[i]!=x[i+1])&&( (i+1)<n)||n==1)
		{
			swap(x[i],x[i+1]);
			cout<<"YES";
			return 0;

		}
	}
	cout<<"NO";

}


#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include <stdlib.h>
#include <stdio.h>
#include<iomanip>
#include<algorithm>

using namespace std;

#define ll long long
#define MP make_pair
#define ull unsigned long long
#define vint vector<int>
#define vid vector<double>
#define vll vector<ll>
#define pb  push_back

int main()
{
	ll n,x[10001],y;
	cin>>n;
	for (int i=0;i<n;i++)
		cin>>x[i];
	for (int i=0;i<n;i++)
	{
		cin>>y;
		if(++x[y]>(n+1)/2)
		{
			cout<<"NO";
			return 0;
		}
	}
cout<<"YES";
}


#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include <stdlib.h>
#include <stdio.h>
#include<iomanip>
#include<algorithm>

using namespace std;

#define ll long long
#define MP make_pair
#define ull unsigned long long
#define vint vector<int>
#define vid vector<double>
#define vll vector<ll>
#define pb  push_back

int main()
{
	ll n,x[10000],c=0;
	cin>>n;
	for (int i=0;i<n;i++)
		cin>>x[i];
	for (int i=0;i<n;i++)
	{
		if ((x[i]!=x[i+1])&&( (i+1)<n)||n==1)
		{
			swap(x[i],x[i+1]);
			c++;

		}
	}
	if (c>=n/2)
		cout<<"YES";
	else
	cout<<"NO";

}


#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include <stdlib.h>
#include <stdio.h>
#include<iomanip>
#include<algorithm>

using namespace std;

#define ll long long
#define MP make_pair
#define ull unsigned long long
#define vint vector<int>
#define vid vector<double>
#define vll vector<ll>
#define pb  push_back

int main()
{
	ll n,x[10000];
	cin>>n;
	for (int i=0;i<n;i++)
		cin>>x[i];
	for (int i=0;i<n;i++)
	{
		if (x[i]!=x[i+1]&& (i+1)<n)
		{
			swap(x[i],x[i+1]);
			cout<<"YES";
			return 0;

		}
	}
	cout<<"NO";

}


#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include <stdlib.h>
#include <stdio.h>
#include<iomanip>
#include<algorithm>

using namespace std;

#define ll long long
#define MP make_pair
#define ull unsigned long long
#define vint vector<int>
#define vid vector<double>
#define vll vector<ll>
#define pb  push_back
int n,x[10001],y;
int main()
{
	cin>>n;
	for (int i=0;i<n;i++)
	{
		cin>>y;
		if(++x[y]>(n+1)/2)
		{
			cout<<"NO";
			return 0;
		}
	}
cout<<"YES";
}


#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include <stdlib.h>
#include <stdio.h>
#include<iomanip>
#include<algorithm>

using namespace std;

#define ll long long
#define MP make_pair
#define ull unsigned long long
#define vint vector<int>
#define vid vector<double>
#define vll vector<ll>
#define pb  push_back

int main()
{
	ll n,x[10001];
	cin>>n;
	for (int i=0;i<n;i++)
		cin>>x[i];
	for (int i=0;i<n;i++)
	{
		if (++x[i]>((n+1)/2))
		{
			cout<<"NO";
			return 0;
		}
	}
cout<<"YES";
}


#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include <stdlib.h>
#include <stdio.h>
#include<iomanip>
#include<algorithm>

using namespace std;

#define ll long long
#define MP make_pair
#define ull unsigned long long
#define vint vector<int>
#define vid vector<double>
#define vll vector<ll>
#define pb  push_back

int main()
{
	ll n,x[10001];
	cin>>n;
	for (int i=0;i<n;i++)
		cin>>x[i];
	for (int i=0;i<n;i++)
	{
		if (x[i]>((n+1)/2))
		{
			cout<<"NO";
			return 0;
		}
		cout<<"YES";
	}

}


#include <iostream>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
    int ArraySize , Repeated = 0 , Maxrepeated = 0;
    cin >> ArraySize;
    int Array[ArraySize];
    for(int i = 0 ; i < ArraySize ; i++)
    {
        cin >> Array[i];
        if(i > 0)
        {
            if(Array[i] == Array[i - 1])
            {
                Repeated++;
                if(Repeated > Maxrepeated)
                    Maxrepeated = Repeated;
            }
            else
                Repeated = 0;
        }
    }
    if(Maxrepeated > ArraySize / 2.0)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
    int ArraySize , Repeated = 0 , Maxrepeated = 0 , RepeatedElement;
    cin >> ArraySize;
    int Array[ArraySize];
    for(int i = 0 ; i < ArraySize ; i++)
        cin >> Array[i];
    for(int i = 0 ; i < ArraySize ; i++)
    {
        for(int j = 0 ; j < ArraySize ; j++)
        {
            if(Array[j] == Array[i])
                Repeated++;
        }
        if(Maxrepeated < Repeated)
            Maxrepeated = Repeated;
        Repeated = 0;
    }
    if((Maxrepeated > ArraySize / 2 && ArraySize % 2 == 0) || (Maxrepeated > ArraySize + 1 && ArraySize % 2 == 1))
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
    int ArraySize , Repeated = 0 , Maxrepeated = 0 , RepeatedElement;
    cin >> ArraySize;
    int Array[ArraySize];
    for(int i = 0 ; i < ArraySize ; i++)
        cin >> Array[i];
    for(int i = 0 ; i < ArraySize ; i++)
    {
        for(int j = 0 ; j < ArraySize ; j++)
        {
            if(Array[j] == Array[i])
                Repeated++;
        }
        if(Maxrepeated < Repeated)
            Maxrepeated = Repeated;
        Repeated = 0;
    }
    if(Maxrepeated > ArraySize / 2.0 && ArraySize > 1)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
    int ArraySize , Repeated = 0 , Maxrepeated = 0 , RepeatedElement;
    cin >> ArraySize;
    int Array[ArraySize];
    for(int i = 0 ; i < ArraySize ; i++)
        cin >> Array[i];
    for(int i = 0 ; i < ArraySize ; i++)
    {
        for(int j = 0 ; j < ArraySize ; j++)
        {
            if(Array[j] == Array[i])
                Repeated++;
        }
        if(Maxrepeated < Repeated)
            Maxrepeated = Repeated;
        Repeated = 0;
    }
    if(Maxrepeated > ArraySize / 2.0)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
    int ArraySize , Repeated = 0 , Maxrepeated;
    cin >> ArraySize;
    int Array[ArraySize];
    for(int i = 0 ; i < ArraySize ; i++)
    {
        cin >> Array[i];
        if(i > 0)
        {
            if(Array[i] == Array[i - 1])
            {
                Repeated++;
                if(Repeated > Maxrepeated)
                    Maxrepeated = Repeated;
            }
            else
                Repeated = 0;
        }
    }
    if(Maxrepeated > ArraySize / 2.0)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
    int ArraySize , Repeated = 0 , Maxrepeated = 0 , RepeatedElement;
    cin >> ArraySize;
    int Array[ArraySize];
    for(int i = 0 ; i < ArraySize ; i++)
        cin >> Array[i];
    for(int i = 0 ; i < ArraySize ; i++)
    {
        for(int j = 0 ; j < ArraySize ; j++)
        {
            if(Array[j] == Array[i])
                Repeated++;
        }
        if(Maxrepeated < Repeated)
            Maxrepeated = Repeated;
        Repeated = 0;
    }
    if((Maxrepeated > ArraySize / 2 && ArraySize % 2 == 0) || (Maxrepeated > (ArraySize + 1) / 2 && ArraySize % 2 == 1))
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
    return 0;
}


#include <iostream>
#include<map>
using namespace std;
int main() {

   int n,x;
   cin >>n;
   int S[n];
   map<int,int> mymap;

   x=n/2;
   if (n%2!=0) x++;

   for (int i=0 ; n>i ; i++)
   {
       cin >>S[i];
       if (mymap.count(S[i])>0)
        mymap.find (S[i])->second += 1;

       else
        mymap [S[i]]=1;

   }
   for (std::map<int,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it)
   {
    if ( it->second >x)
    {cout << "NO" ; return 0;}
    }

    cout <<"YES";

   }


#include <iostream>
using namespace std;
int main() {

   int n;
   cin >>n;
   int S[n];

   for (int i=0 ; n>i ; i++)
   {
       cin >>S[i];
   }
   for (int j=1 ; n*3>=j ; j++)
   {
   for (int i=1 ; n-1>i ; i++)
   {
       if (S[i]==S[i-1]&&i<=n/2)
           swap(S[i],S[i+1]);
       else if (S[i]==S[i+1]&&i>n/2)
           swap(S[i],S[i-1]);

   }
   }
   for (int i=0 ; n-1>i ; i++)
   {
       if (S[i]==S[i+1])
       {
           cout <<"NO";
           return 0;
       }
   }
   cout <<"YES";

}


#include <iostream>
#include <cmath>
using namespace std;

int main() {

   int n ;
   cin >>n;
   int S[n];
   int T[n]={0};
   int z=n/2;
   if (n%2 !=0)
    z++;

   for (int i=0 ; n >i ; i++)
   {
       cin >>S[i];
   }
   bool valid = true;
   for (int i=0 ; n >i ; i++)
   {
       int c=0;
       for (int j=0 ; n >j ; j++)
       {
           if (S[i]==S[j])
               c++;
       }
       if (c>z)
       {
           valid = false;
           break ;
       }

   }

      if (valid)
          cout <<"YES";
      else
          cout <<"NO";
      return 0;

}


#include <iostream>
using namespace std;
int main() {

   int n;
   cin >>n;
   int S[n];

   for (int i=0 ; n>i ; i++)
   {
       cin >>S[i];
   }
   for (int j=1 ; n>=j ; j++)
   {
   for (int i=1 ; n-1>i ; i++)
   {
       if (S[i]==S[i-1]&&i==1)
           swap(S[i],S[i+1]);
       else if (S[i]==S[i+1])
           swap(S[i],S[i-1]);

   }
   }
   for (int i=0 ; n-1>i ; i++)
   {
       if (S[i]==S[i+1])
       {
           cout <<"NO";
           return 0;
       }
   }
   cout <<"YES";

}


#include <iostream>
using namespace std;
int main() {

   int n;
   cin >>n;
   int S[n];

   for (int i=0 ; n>i ; i++)
   {
       cin >>S[i];
   }
   for (int j=1 ; n>=j ; j++)
   {
   for (int i=1 ; n-1>i ; i++)
   {
       if (S[i]==S[i-1])
           swap(S[i],S[i+1]);

   }
   for (int i=1 ; n-1>i ; i++)
   {

       if (S[i]==S[i+1)
           swap(S[i],S[i-1]);

   }

   }
   for (int i=0 ; n-1>i ; i++)
   {
       if (S[i]==S[i+1])
       {
           cout <<"NO";
           return 0;
       }
   }
   cout <<"YES";

}


#include <iostream>
using namespace std;
int main() {

   int n;
   cin >>n;
   int S[n];

   for (int i=0 ; n>i ; i++)
   {
       cin >>S[i];
   }
   for (int j=1 ; n>=j ; j++)
   {
   for (int i=1 ; n-1>i ; i++)
   {
       if (S[i]==S[i-1])
           swap(S[i],S[i+1]);

   }
   for (int i=1 ; n-1>i ; i++)
   {

       if (S[i]==S[i+1])
           swap(S[i],S[i-1]);

   }

   }
   for (int i=0 ; n-1>i ; i++)
   {
       if (S[i]==S[i+1])
       {
           cout <<"NO";
           return 0;
       }
   }
   cout <<"YES";

}


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <map>
#define endl '\n'
#define mod 1000000007
#define lpr(i,n) for(int i=0;i<n;i++)
#define lpn(i,n) for(int i=1;i<=n;i++)
#define inf 500000000
#define pb push_back
#define Q(a) ((a)*(a))
typedef long long ll;
using namespace std;
ll ctr[1005]={};
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /**
    #ifndef ONLINE_JUDGE
     freopen("input.txt" , "r" , stdin);
     #endif //ONLINE_JUDGE
    **/
     ll n , a;
     cin >> n;

     lpr(i,n){
     cin >> a;
       if(n==1){
        cout << "YES" <<endl;
        return 0;
     }
     ctr[a]++;
     }
     int Mc=-1,id;
     lpr(i,1003){
         if(ctr[i]>Mc)
            Mc=ctr[i],id=i;
     }
     ctr[id]=0;
     ll anc =0 ;
     for(int i = 0 ; i < 1003;i++){
        anc +=ctr[i];
     }
     if(2*anc<Mc){cout << "NO" <<endl; return 0;}
     cout << "YES" << endl;

   return 0 ;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <map>
#define endl '\n'
#define mod 1000000007
#define lpr(i,n) for(int i=0;i<n;i++)
#define lpn(i,n) for(int i=1;i<=n;i++)
#define inf 500000000
#define pb push_back

typedef long long ll;
using namespace std;
long long isprime(long long x){
             if(x%2==0||x==1)
                return false;
             for(int i=3;i*i<=x;i++){

                if(x%i==0)
                    return false;

             }
             return true;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /**
    #ifndef ONLINE_JUDGE
     freopen("input.txt" , "r" , stdin);
     #endif //ONLINE_JUDGE
    **/
     ll n,arr[106],ctr[1005]={};
     cin >> n;
     lpr(i,n)cin>>arr[i],ctr[arr[i]]++;

    if(n==1){
        cout << "YES\n";
        return 0;
    }
     lpr(i,1003){
         if((ctr[i]/(double)n)*100 >=75){

            cout << "NO" <<endl;
            return 0;
         }
     }
     cout << "YES\n";
   return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <map>
#define endl '\n'
#define mod 1000000007
#define lpr(i,n) for(int i=0;i<n;i++)
#define lpn(i,n) for(int i=1;i<=n;i++)
#define inf 500000000
#define pb push_back
#define Q(a) ((a)*(a))
typedef long long ll;
using namespace std;
ll ctr[1005]={};
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /**
    #ifndef ONLINE_JUDGE
     freopen("input.txt" , "r" , stdin);
     #endif //ONLINE_JUDGE
    **/
     ll n , a;
     cin >> n;

     lpr(i,n){
     cin >> a;
       if(n==1){
        cout << "YES" <<endl;
        return 0;
     }
     ctr[a]++;
     }
     int Mc=-1,id;
     lpr(i,1003){
         if(ctr[i]>Mc)
            Mc=ctr[i],id=i;
     }
     ctr[id]=0;
     ll anc =0 ;
     for(int i = 0 ; i < 1003;i++){
        anc +=ctr[i];
     }
     if(2*anc>Mc){cout << "YES" <<endl; return 0;}
     cout << "NO" << endl;

   return 0 ;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <map>
#define endl '\n'
#define mod 1000000007
#define lpr(i,n) for(int i=0;i<n;i++)
#define lpn(i,n) for(int i=1;i<=n;i++)
#define inf 500000000
#define pb push_back

typedef long long ll;
using namespace std;
long long isprime(long long x){
             if(x%2==0||x==1)
                return false;
             for(int i=3;i*i<=x;i++){

                if(x%i==0)
                    return false;

             }
             return true;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /**
    #ifndef ONLINE_JUDGE
     freopen("input.txt" , "r" , stdin);
     #endif //ONLINE_JUDGE
    **/
     ll n,arr[106],ctr[1005]={};
     cin >> n;
     lpr(i,n)cin>>arr[i],ctr[arr[i]]++;
    if(n==1){
        cout << "YES\n";
        return 0;
    }
     lpr(i,1003){
         if((ctr[i]/(double)n)*100 >60){

            cout << "NO" <<endl;
            return 0;
         }
     }
     cout << "YES\n";
   return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <map>
#define endl '\n'
#define mod 1000000007
#define lpr(i,n) for(int i=0;i<n;i++)
#define lpn(i,n) for(int i=1;i<=n;i++)
#define inf 500000000
#define pb push_back
#define Q(a) ((a)*(a))
typedef long long ll;
using namespace std;
ll ctr[1005]={};
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /**
    #ifndef ONLINE_JUDGE
     freopen("input.txt" , "r" , stdin);
     #endif //ONLINE_JUDGE
    **/
     ll n , a;
     cin >> n;

     lpr(i,n){
     cin >> a;
       if(n==1){
        cout << "YES" <<endl;
        return 0;
     }
     ctr[a]++;
     }
     int Mc=-1,id;
     lpr(i,1003){
         if(ctr[i]>Mc)
            Mc=ctr[i],id=i;
     }
     ctr[id]=0;
     ll anc =0 ;
     for(int i = 0 ; i < 1003;i++){
        anc +=ctr[i];
     }
     if(Mc<=(n+1)/2){cout << "YES" <<endl; return 0;}
     cout << "NO" << endl;

   return 0 ;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <map>
#define endl '\n'
#define mod 1000000007
#define lpr(i,n) for(int i=0;i<n;i++)
#define lpn(i,n) for(int i=1;i<=n;i++)
#define inf 500000000
#define pb push_back
#define Q(a) ((a)*(a))
typedef long long ll;
using namespace std;
ll ctr[1005]={};
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    /**
    #ifndef ONLINE_JUDGE
     freopen("input.txt" , "r" , stdin);
     #endif //ONLINE_JUDGE
    **/
     ll n , a;
     cin >> n;

     lpr(i,n){
     cin >> a;
       if(n==1){
        cout << "YES" <<endl;
        return 0;
     }
     ctr[a]++;
     }
     int Mc=-1,id;
     lpr(i,1003){
         if(ctr[i]>Mc)
            Mc=ctr[i],id=i;
     }
     ctr[id]=0;
     ll anc =0 ;
     for(int i = 0 ; i < 1003;i++){
        anc +=ctr[i];
     }
     if(2*anc>=Mc){cout << "YES" <<endl; return 0;}
     cout << "NO" << endl;

   return 0 ;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <stack>
#include <sstream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <list>
#define ull unsigned long long
#define ll long long
#define S string
#define V vector
#define pi 3.1415926536
#define SS stringstream
#define lp(i,n) for(int i=0;i<n;i++)
#define w while
#define re return
using namespace std;
int arr[1001];
int main()
{
    int n,cnt(0);
    cin >> n;
    int x[n];
    lp(i,n){
        cin >> x[i] ;
        if(i-1>0 && x[i]!=x[i-1])
            cnt++;
        arr[x[i]]++;
    }
    sort(arr,arr+1000);
    if(arr[1000]==arr[999] || arr[1000]-1==arr[999] || (cnt>=arr[1000] && cnt>0)){
        cout << "YES" << endl ;
        re 0;
    }
    cout << "NO" << endl ;
    re 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <stack>
#include <sstream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <list>
#define ull unsigned long long
#define ll long long
#define S string
#define V vector
#define pi 3.1415926536
#define SS stringstream
#define lp(i,n) for(int i=0;i<n;i++)
#define w while
#define re return
using namespace std;
int arr[1001];
int main()
{
    int n,cnt(0);
    cin >> n;
    int x[n];
    lp(i,n){
        cin >> x[i] ;
        if(i-1>0 && x[i]!=x[i-1])
            cnt++;
        arr[x[i]]++;
    }
    sort(arr,arr+1001);
    for(int i=1000;;i++){
    if((arr[i]==arr[i-1] && arr[i-1]==0 && i>=1) || (arr[i]-1==arr[i-1] && arr[i-1]==0 && i>=1)){
        cnt=1;
    }
    else{
        cout << "NO" << endl ;
        re 0;
    }
    if(arr[i-1]==0)
        break;
    }
    cout << "YES" << endl ;
    re 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <stack>
#include <sstream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <list>
#define ull unsigned long long
#define ll long long
#define S string
#define V vector
#define pi 3.1415926536
#define SS stringstream
#define lp(i,n) for(int i=0;i<n;i++)
#define w while
#define re return
using namespace std;
int arr[1001];
int main()
{
    int n,cnt(0),c;
    cin >> n;
    if(n%2==0)
        c=n/2;
    else
        c=(n/2)+1;
    int x[n];
    lp(i,n){
        cin >> x[i] ;
        if(i-1>0 && x[i]!=x[i-1])
            cnt++;
        arr[x[i]]++;
    }
    sort(arr,arr+1001);
    if(c>=arr[1000]){
        cout << "YES" << endl ;
        re 0;
    }
    for(int i=1000;;i++){
    if((arr[i]==arr[i-1] && i>=1) || (arr[i]-1==arr[i-1] && i>=1)){
        cnt=1;
    }
    else{
        cout << "NO" << endl ;
        re 0;
    }
    if(arr[i-1]==0)
        break;
    }
    cout << "YES" << endl ;
    re 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <stack>
#include <sstream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <list>
#define ull unsigned long long
#define ll long long
#define S string
#define V vector
#define pi 3.1415926536
#define SS stringstream
#define lp(i,n) for(int i=0;i<n;i++)
#define w while
#define re return
using namespace std;
int arr[1000];
int main()
{
    int n,x;
    cin >> n;
    lp(i,n){
        cin >> x ;
        arr[x]++;
    }
    sort(arr,arr+1000);
    if(arr[999]==arr[998] || arr[999]-1==arr[998]){
        cout << "YES" << endl ;
        re 0;
    }
    cout << "NO" << endl ;
    re 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <stack>
#include <sstream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <list>
#define ull unsigned long long
#define ll long long
#define S string
#define V vector
#define pi 3.1415926536
#define SS stringstream
#define lp(i,n) for(int i=0;i<n;i++)
#define w while
#define re return
using namespace std;
int arr[1001];
int main()
{
    int n,cnt(0);
    cin >> n;
    int x[n];
    lp(i,n){
        cin >> x[i] ;
        if(i-1>0 && x[i]!=x[i-1])
            cnt++;
        arr[x[i]]++;
    }
    sort(arr,arr+1000);
    if(arr[1000]==arr[999] || arr[1000]-1==arr[999] || cnt>=arr[1000]){
        cout << "YES" << endl ;
        re 0;
    }
    cout << "NO" << endl ;
    re 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <stack>
#include <sstream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <list>
#define ull unsigned long long
#define ll long long
#define S string
#define V vector
#define pi 3.1415926536
#define SS stringstream
#define lp(i,n) for(int i=0;i<n;i++)
#define w while
#define re return
using namespace std;
int arr[1001];
int main()
{
    int n,cnt(0);
    cin >> n;
    int x[n];
    lp(i,n){
        cin >> x[i] ;
        if(i-1>0 && x[i]!=x[i-1])
            cnt++;
        arr[x[i]]++;
    }
    sort(arr,arr+1001);
    if(arr[1000]==arr[999] || arr[1000]-1==arr[999] || (cnt>=arr[1000] && cnt>0)){
        cout << "YES" << endl ;
        re 0;
    }
    cout << "NO" << endl ;
    re 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <stack>
#include <sstream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <list>
#define ull unsigned long long
#define ll long long
#define S string
#define V vector
#define pi 3.1415926536
#define SS stringstream
#define lp(i,n) for(int i=0;i<n;i++)
#define w while
#define re return
using namespace std;
int arr[1001];
int main()
{
    int n,cnt(0);
    cin >> n;
    int x[n];
    lp(i,n){
        cin >> x[i] ;
        if(i-1>0 && x[i]!=x[i-1])
            cnt++;
        arr[x[i]]++;
    }
    sort(arr,arr+1001);
    for(int i=1000;;i++){
    if((arr[i]==arr[i-1] && arr[i-1]!=0 && i>=1) || (arr[i]-1==arr[i-1] && arr[i-1]!=0 && i>=1)){
        cnt=1;
    }
    else{
        cout << "NO" << endl ;
        re 0;
    }
    if(arr[i-1]==0)
        break;
    }
    cout << "YES" << endl ;
    re 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <stack>
#include <sstream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <list>
#define ull unsigned long long
#define ll long long
#define S string
#define V vector
#define pi 3.1415926536
#define SS stringstream
#define lp(i,n) for(int i=0;i<n;i++)
#define w while
#define re return
using namespace std;
int arr[1001];
int main()
{
    int n,cnt(0);
    cin >> n;
    int x[n];
    lp(i,n){
        cin >> x[i] ;
        if(i-1>0 && x[i]!=x[i-1])
            cnt++;
        arr[x[i]]++;
    }
    sort(arr,arr+1001);
    for(int i=1000;;i++){
    if((arr[i]==arr[i-1] && i>=1) || (arr[i]-1==arr[i-1] && i>=1)){
        cnt=1;
    }
    else{
        cout << "NO" << endl ;
        re 0;
    }
    if(arr[i-1]==0)
        break;
    }
    cout << "YES" << endl ;
    re 0;
}


using namespace std;
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <set>

#define ll long long
#define MAX 101010
#define INF 2020202020
#define pb push_back

int n;
set < int > s;

int main ()
{
    ios_base::sync_with_stdio ( 0 );
//    freopen ( "input.txt", "r", stdin );

    cin >> n;
    for ( int i = 0; i < n; ++ i )
    {
        int temp; cin >> temp;
        s.insert ( temp );
    }

    if ( n-1 <= (int)s.size()-1 ) cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>

#define MAX 101
#define INF 2020202020

int n, a[MAX];
int m[MAX<<4];

int main ()
{
	std::ios_base::sync_with_stdio ( 0 );

	std::cin >> n;
	for ( int i = 0; i < n; ++ i )
	{
		std::cin >> a[i];
		m[a[i]] = 1;
	}

	int mid = (n>>1) + (n&1);
	for ( int i = 0; i < n; ++ i )
	{
		if ( m[a[i]] >= mid )
		{
			std::cout << "NO\n";
			return 0;
		}
	}

	std::cout << "YES\n";

	return 0;
}


using namespace std;
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>

#define ll long long
#define MAX 101010
#define INF 2020202020
#define pb push_back

int n;
set < int > s;

int main ()
{
    ios_base::sync_with_stdio ( 0 );
//    freopen ( "input.txt", "r", stdin );

    cin >> n;
    for ( int i = 0; i < n; ++ i )
    {
        int temp; cin >> temp;
        s.insert ( temp );
    }

    if ( n-1 <= (int)s.size()-1 ) cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>

#define MAX 101
#define INF 2020202020

int n, a[MAX];
int m[MAX<<4];

int main ()
{
	std::ios_base::sync_with_stdio ( 0 );

	std::cin >> n;
	for ( int i = 0; i < n; ++ i )
	{
		std::cin >> a[i];
		m[a[i]] ++;
	}

	int mid = (n>>1) + (n&1);
	for ( int i = 0; i < n; ++ i )
	{
		if ( m[a[i]] > mid )
		{
			std::cout << "NO\n";
			return 0;
		}
	}

	std::cout << "YES\n";

	return 0;
}


import java.util.*;
import java.io.*;

public class OracandFactors {

	// https://codeforces.com/contest/1350/problem/A

	public static void main(String[] args) throws IOException, FileNotFoundException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader in = new BufferedReader(new FileReader("OracandFactors"));

		int t = Integer.parseInt(in.readLine());
		for (int j=0; j<t; ++j ) {
			StringTokenizer st = new StringTokenizer(in.readLine());
			int n = Integer.parseInt(st.nextToken());
			int k = Integer.parseInt(st.nextToken());
			for (int i=0; i<k; i++) {
				n += f(n);
			}
			System.out.println(n);
		}
	}

	public static int f(int n) {
		int cur = 2;
		for (int i=2; i<=n; i++) {
			if (n % i == 0) {
				cur = i;
				break;
			}
		}
		return cur;
	}

}


import java.util.*;
import java.io.*;

public class OracandFactors {

	// https://codeforces.com/contest/1350/problem/A

	public static void main(String[] args) throws IOException, FileNotFoundException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader in = new BufferedReader(new FileReader("OracandFactors"));

		int t = Integer.parseInt(in.readLine());
		int[] arr = new int[(int) (1e7)+1];
		/*for (int i =2; i<arr.length; i++) {
			arr[i] = f(i);
		}*/
		for (int i=2; i<arr.length; i++) {
			if (arr[i] != 0) continue;
			for (int j=i; j<arr.length; j+=i) {
				if (arr[j] == 0) arr[j] = i;
			}
		}

		for (int j=0; j<t; ++j ) {
			StringTokenizer st = new StringTokenizer(in.readLine());
			int n = Integer.parseInt(st.nextToken());
			int k = Integer.parseInt(st.nextToken());
			for (int i=0; i<k; i++) {
				n += arr[n];
			}
			System.out.println(n);
		}
	}

	public static int f(int n) {
		int cur = 2;
		for (int i=2; i<=n; i++) {
			if (n % i == 0) {
				cur = i;
				break;
			}
		}
		return cur;
	}
}


import java.util.*;
import java.io.*;

public class OracandFactors {

	// https://codeforces.com/contest/1350/problem/A

	public static void main(String[] args) throws IOException, FileNotFoundException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader in = new BufferedReader(new FileReader("OracandFactors"));

		int t = Integer.parseInt(in.readLine());
		for (int j=0; j<t; ++j ) {
			StringTokenizer st = new StringTokenizer(in.readLine());
			long n = Long.parseLong(st.nextToken());
			long k = Long.parseLong(st.nextToken());
			if (n%2 == 0) {
				n += 2*k;
			}
			else {
				n += 2*(k-1) + f(n);
			}
			System.out.println(n);
		}
	}

	public static int f(long n) {
		int cur = 2;
		for (int i=2; i<=n; i++) {
			if (n % i == 0) {
				cur = i;
				break;
			}
		}
		return cur;
	}
}

/*int[] arr = new int[(int) (1e7)+1];
for (int i =2; i<arr.length; i++) {
	arr[i] = f(i);
}
for (int i=2; i<arr.length; i++) {
	if (arr[i] != 0) continue;
	for (int j=i; j<arr.length; j+=i) {
		if (arr[j] == 0) arr[j] = i;
	}
}*/


import java.util.*;
import java.io.*;

public class OracandFactors {

	// https://codeforces.com/contest/1350/problem/A

	public static void main(String[] args) throws IOException, FileNotFoundException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader in = new BufferedReader(new FileReader("OracandFactors"));

		int t = Integer.parseInt(in.readLine());
		int[] arr = new int[(int) (1e8)+1];
		/*for (int i =2; i<arr.length; i++) {
			arr[i] = f(i);
		}*/
		for (int i=2; i<arr.length; i++) {
			if (arr[i] != 0) continue;
			for (int j=i; j<arr.length; j+=i) {
				if (arr[j] == 0) arr[j] = i;
			}
		}

		for (int j=0; j<t; ++j ) {
			StringTokenizer st = new StringTokenizer(in.readLine());
			int n = Integer.parseInt(st.nextToken());
			int k = Integer.parseInt(st.nextToken());
			for (int i=0; i<k; i++) {
				n += arr[n];
			}
			System.out.println(n);
		}
	}

	public static int f(int n) {
		int cur = 2;
		for (int i=2; i<=n; i++) {
			if (n % i == 0) {
				cur = i;
				break;
			}
		}
		return cur;
	}
}


import java.util.*;
import java.io.*;

public class OracandFactors {

	// https://codeforces.com/contest/1350/problem/A

	public static void main(String[] args) throws IOException, FileNotFoundException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader in = new BufferedReader(new FileReader("OracandFactors"));

		int t = Integer.parseInt(in.readLine());
		int[] arr = new int[(int) (1e6)+1];
		/*for (int i =2; i<arr.length; i++) {
			arr[i] = f(i);
		}*/
		for (int i=2; i<arr.length; i++) {
			if (arr[i] != 0) continue;
			for (int j=i; j<arr.length; j+=i) {
				if (arr[j] == 0) arr[j] = i;
			}
		}

		for (int j=0; j<t; ++j ) {
			StringTokenizer st = new StringTokenizer(in.readLine());
			int n = Integer.parseInt(st.nextToken());
			int k = Integer.parseInt(st.nextToken());
			for (int i=0; i<k; i++) {
				n += arr[n];
			}
			System.out.println(n);
		}
	}

	public static int f(int n) {
		int cur = 2;
		for (int i=2; i<=n; i++) {
			if (n % i == 0) {
				cur = i;
				break;
			}
		}
		return cur;
	}
}


import java.util.*;

public class factorsorsomething {

	public static void main(String[] args) {
		Scanner msc = new Scanner(System.in);
		int total = msc.nextInt();
		for(int i = 0 ; i < total ; i++){
			int addNumber = msc.nextInt();
			int numberNumber = msc.nextInt();
			System.out.println(getAnswer(numberNumber, addNumber));
		}
	}
	static int getAnswer(int runNumber, int addingNum){
		if(runNumber == 0){
			return(addingNum);
		}
		addingNum += getDivs(addingNum).get(1);
		return(getAnswer(runNumber - 1, addingNum));
	}
	static ArrayList<Long> getDivs(long input){
		ArrayList<Long> list = new ArrayList<Long>();
		for(long i = 1 ; i * i <= input ; i++){
			if(input % i == 0){
				list.add(i);
				if(i != input / i) {
					list.add(input / i);
				}

			}
		}
		Collections.sort(list);
		return list;
	}
}


import java.util.*;

public class factorsorsomething {

	public static void main(String[] args) {
		Scanner msc = new Scanner(System.in);
		int total = msc.nextInt();
		for(int i = 0 ; i < total ; i++){
			int addNumber = msc.nextInt();
			int numberNumber = msc.nextInt();
			for(int j = 0 ; j < numberNumber ; j++){
				addNumber += getDivs(addNumber).get(1);
				System.out.println("working... " + addNumber);
			}
			System.out.println(addNumber);
		}
	}
	static ArrayList<Long> getDivs(long input){
		ArrayList<Long> list = new ArrayList<Long>();
		for(long i = 1 ; i * i <= input ; i++){
			if(input % i == 0){
				list.add(i);
				if(i != input / i) {
					list.add(input / i);
				}

			}
		}
		Collections.sort(list);
		return list;
	}
}


import java.util.*;

public class factorsorsomething {

	public static void main(String[] args) {
		Scanner msc = new Scanner(System.in);
		int total = msc.nextInt();
		for(int i = 0 ; i < total ; i++){
			int addNumber = msc.nextInt();
			int numberNumber = msc.nextInt();
			if(addNumber % 2 == 2){
				System.out.println(addNumber + numberNumber * 2);
			}else{
				addNumber += getDivs(addNumber).get(1);
				System.out.println(addNumber + (numberNumber - 1) * 2);
			}
		}
	}
	static ArrayList<Long> getDivs(long input){
		ArrayList<Long> list = new ArrayList<Long>();
		for(long i = 1 ; i * i <= input ; i++){
			if(input % i == 0){
				list.add(i);
				if(i != input / i) {
					list.add(input / i);
				}
			}
		}
		Collections.sort(list);
		return list;
	}
}


import java.util.*;

public class factorsorsomething {

	public static void main(String[] args) {
		Scanner msc = new Scanner(System.in);
		int total = msc.nextInt();
		for(int i = 0 ; i < total ; i++){
			int addNumber = msc.nextInt();
			int numberNumber = msc.nextInt();
			for(int j = 0 ; j < numberNumber ; j++){
				Long number = getDivs(addNumber).get(1);
				addNumber += number;
			}
			System.out.println(addNumber);
		}
	}
	static ArrayList<Long> getDivs(long input){
		ArrayList<Long> list = new ArrayList<Long>();
		for(long i = 1 ; i * i <= input ; i++){
			if(input % i == 0){
				list.add(i);
				if(i != input / i) {
					list.add(input / i);
				}

			}
		}
		Collections.sort(list);
		return list;
	}
}


import java.util.*;

public class factorsorsomething {

	public static void main(String[] args) {
		Scanner msc = new Scanner(System.in);
		int total = msc.nextInt();
		for(int i = 0 ; i < total ; i++){
			int addNumber = msc.nextInt();
			int numberNumber = msc.nextInt();
			for(int j = 0 ; j < numberNumber ; j++){
				addNumber += getDivs(addNumber).get(1);
			}
			System.out.println(addNumber);
		}
	}
	static ArrayList<Long> getDivs(long input){
		ArrayList<Long> list = new ArrayList<Long>();
		for(long i = 1 ; i * i <= input ; i++){
			if(input % i == 0){
				list.add(i);
				if(i != input / i) {
					list.add(input / i);
				}

			}
		}
		Collections.sort(list);
		return list;
	}
}


//package codeforcespage2;
import java.util.*;
public class OracAndFactors {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int t=in.nextInt();
        for(int i=0;i<t;i++)
        {
            long n=in.nextLong();
            int k=in.nextInt();

            while(k!=0)
            {
                long add=0;

                if(n%2==0)
                {
                    n=n+(2*k);
                    break;
                }
                else{
                for(long j=3;j<=n/2;j=j+2)
                {
                    if(n%j==0)
                    {
                        add=j;
                        break;
                    }
                }
                }
                if(add==0)
                {
                    add=n;
                }
                n=n+add;
                k--;

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


//package codeforcespage2;
import java.util.*;
public class OracAndFactors {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int t=in.nextInt();
        for(int i=0;i<t;i++)
        {
            long n=in.nextLong();
            int k=in.nextInt();
            while(k!=0)
            {
                long add=0;

                if(n%2==0)
                {
                    add=2;
                }
                else{
                for(long j=3;j<=n/2;j=j+2)
                {
                    if(n%j==0)
                    {
                        add=j;
                        break;
                    }
                }
                }
                if(add==0)
                {
                    add=n;
                }
                n=n+add;
                k--;

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


//package codeforcespage2;
import java.util.*;
public class OracAndFactors {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int t=in.nextInt();
        for(int i=0;i<t;i++)
        {
            long n=in.nextLong();
            int k=in.nextInt();
            while(k!=0)
            {
                long add=0;
                for(long j=2;j<=n;j++)
                {
                    if(n%j==0)
                    {
                        add=j;
                        break;
                    }
                }
                n=n+add;
                k--;
            }
            System.out.println(n);
        }
    }
}


//package com.sachchidanand.currentcontest;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class A {

    private final static FastReader fr = new FastReader();

    public void solve() {
        long n = fr.nextLong();
        long k = fr.nextLong();

        while (k-- != 0) {
            long x = smallestDivisor(n);
            n += x;
        }

        System.out.println(n);
    }

    private long smallestDivisor(long n) {
        if (n % 2 == 0)
            return 2;

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

        return n;
    }

    public void run() {
        int tc = fr.nextInt();
        while (tc-- != 0)
            solve();
    }

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

    final static class FastReader {
        private final BufferedReader br;
        private StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e){
                    System.out.println(e.toString());
                }
            }

            return st.nextToken();
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (Exception e) {
                System.out.println(e.toString());
            }

            return str;
        }

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

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

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


//package com.sachchidanand.currentcontest;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class A {

    private final static FastReader fr = new FastReader();

    public void solve() {
        int n = fr.nextInt();
        long k = fr.nextLong();

        int x = smallestDivisor(n);
        n += x;

        k--;

        n += 2*k;

        System.out.println(n);
    }

    private int smallestDivisor(int n) {
        if (n % 2 == 0)
            return 2;

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

        return n;
    }

    public void run() {
        int tc = fr.nextInt();
        while (tc-- != 0)
            solve();
    }

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

    final static class FastReader {
        private final BufferedReader br;
        private StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e){
                    System.out.println(e.toString());
                }
            }

            return st.nextToken();
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (Exception e) {
                System.out.println(e.toString());
            }

            return str;
        }

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

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

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


//package com.sachchidanand.currentcontest;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class A {

    private final static FastReader fr = new FastReader();
    private int[] divisor = new int[1000000];

    public void solve() {
        int n = fr.nextInt();
        long k = fr.nextLong();

        while (k-- != 0) {
            int x = divisor[n-2];
            n += x;
        }

        System.out.println(n);
    }

    private int smallestDivisor(int n) {
        if (n % 2 == 0)
            return 2;

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

        return n;
    }

    public void run() {
        for(int i=2; i<=1000000; i++) {
            divisor[i-2] = smallestDivisor(i);
        }
        int tc = fr.nextInt();
        while (tc-- != 0)
            solve();
    }

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

    final static class FastReader {
        private final BufferedReader br;
        private StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e){
                    System.out.println(e.toString());
                }
            }

            return st.nextToken();
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (Exception e) {
                System.out.println(e.toString());
            }

            return str;
        }

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

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

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


//package com.sachchidanand.currentcontest;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class A {

    private final static FastReader fr = new FastReader();
    private int[] divisor = new int[1000007];

    public void solve() {
        int n = fr.nextInt();
        long k = fr.nextLong();

        while (k-- != 0) {
            int x = divisor[n];
            n += x;
        }

        System.out.println(n);
    }

    private int smallestDivisor(int n) {
        if (n % 2 == 0)
            return 2;

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

        return n;
    }

    public void run() {

        for(int i=2; i<=1000000; i++) {
            divisor[i] = smallestDivisor(i);
        }

        int tc = fr.nextInt();
        while (tc-- != 0)
            solve();
    }

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

    final static class FastReader {
        private final BufferedReader br;
        private StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e){
                    System.out.println(e.toString());
                }
            }

            return st.nextToken();
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (Exception e) {
                System.out.println(e.toString());
            }

            return str;
        }

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

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

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


import java.util.Scanner;
import java.util.*;

public class file {

  private static final Scanner scn = new Scanner(System.in);

  private static int getDiv(int N)  {
      for (int i = 2; i*i <= N; i++) {
          if (N%i == 0) {
              return i;
          }
      }
      return N;
    }

  private static void foo() {
    int n = scn.nextInt();
    int k = scn.nextInt();
    n += getDiv(n);
    n += 2*(k-1);
    System.out.println(n);

  }

  public static void main(String[] args) {
    int t = scn.nextInt();
    while (t-- > 0) {
      foo();
    }
  }

}


import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{   	public static void main (String[] args)throws IOException {
    try{
	   //BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
	   Scanner sc = new Scanner(System.in);
	  // int t=Integer.parseInt(br.readLine());
	   int t=sc.nextInt();
	 //int t=1;
	   while(t-->0){
	 //int n=Integer.parseInt(br.readLine());
	// String s=sc.next();
	int n = sc.nextInt();
	int k = sc.nextInt();
	//long d=Long.parseLong(br.readLine());
	//String[] s= br.readLine().trim().split(" ");
	// Map<Integer,Integer> m = new HashMap<Integer,Integer>();
 //List<String> fl = new ArrayList<String>();
 //List<String> sl = new ArrayList<String>();
	 //<Integer> v= new Vector<Integer>();
	 //Set<Integer> s= new HashSet<Integer>();
   for(int j=0;j<k;j++){
           if(n%2==0)n=n+2;
           else {
               for(int i=3;i<=n;i=i+2){
               if(n%i==0){n=n+i;break;}
           }
           }

   }

   System.out.println(n);
}
}
catch(Exception e){

}
	}
static boolean prime(int n) {
    if(n < 2) return false;
    if(n == 2 || n == 3) return true;
    if(n%2 == 0 || n%3 == 0) return false;
    int sqrtN = (int)Math.sqrt(n)+1;
    for(int i = 6; i <= sqrtN; i += 6) {
        if(n%(i-1) == 0 || n%(i+1) == 0) return false;
    }
    return true;
}
}


import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{   	public static void main (String[] args)throws IOException {
    try{
	   //BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
	   Scanner sc = new Scanner(System.in);
	  // int t=Integer.parseInt(br.readLine());
	   int t=sc.nextInt();
	 //int t=1;
	   while(t-->0){
	 //int n=Integer.parseInt(br.readLine());
	// String s=sc.next();
	int n = sc.nextInt();
	int k = sc.nextInt();
	//long d=Long.parseLong(br.readLine());
	//String[] s= br.readLine().trim().split(" ");
	// Map<Integer,Integer> m = new HashMap<Integer,Integer>();
 //List<String> fl = new ArrayList<String>();
 //List<String> sl = new ArrayList<String>();
	 //<Integer> v= new Vector<Integer>();
	 //Set<Integer> s= new HashSet<Integer>();
   for(int j=0;j<k;j++){
       if(prime(n)) n+=n;
       else{
           if(n%2==0)n=n+2;
           else {
               for(int i=3;i*i<n;i=i+2){
               if(n%i==0){n=n+i;break;}
           }
           }
       }
   }

   System.out.println(n);
}
}
catch(Exception e){

}
	}
	static boolean prime(int n){
	   int i,m=0,flag=0;
  m=n/2;
  if(n==0||n==1){
  return false;
  }else{
   for(i=2;i<=m;i++){
    if(n%i==0){
     return false;
    }
   }
   return true;
  }
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{   	public static void main (String[] args)throws IOException {
    try{
	   //BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
	   Scanner sc = new Scanner(System.in);
	  // int t=Integer.parseInt(br.readLine());
	   int t=sc.nextInt();
	 //int t=1;
	   while(t-->0){
	 //int n=Integer.parseInt(br.readLine());
	// String s=sc.next();
	int n = sc.nextInt();
	int k = sc.nextInt();
	//long d=Long.parseLong(br.readLine());
	//String[] s= br.readLine().trim().split(" ");
	// Map<Integer,Integer> m = new HashMap<Integer,Integer>();
 //List<String> fl = new ArrayList<String>();
 //List<String> sl = new ArrayList<String>();
	 //<Integer> v= new Vector<Integer>();
	 //Set<Integer> s= new HashSet<Integer>();
   for(int j=0;j<k;j++){
       if(prime(n)) n+=n;
       else{
           if(n%2==0)n=n+2;
           else {
               for(int i=3;i*i<n;i=i+2){
               if(n%i==0){n=n+i;break;}
           }
           }
       }
   }

   System.out.println(n);
}
}
catch(Exception e){

}
	}
static boolean prime(int n) {
    if(n < 2) return false;
    if(n == 2 || n == 3) return true;
    if(n%2 == 0 || n%3 == 0) return false;
    int sqrtN = (int)Math.sqrt(n)+1;
    for(int i = 6; i <= sqrtN; i += 6) {
        if(n%(i-1) == 0 || n%(i+1) == 0) return false;
    }
    return true;
}
}


import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{   	public static void main (String[] args)throws IOException {
    try{
	   //BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
	   Scanner sc = new Scanner(System.in);
	  // int t=Integer.parseInt(br.readLine());
	   int t=sc.nextInt();
	 //int t=1;
	   while(t-->0){
	 //int n=Integer.parseInt(br.readLine());
	// String s=sc.next();
	int n = sc.nextInt();
	int k = sc.nextInt();
	//long d=Long.parseLong(br.readLine());
	//String[] s= br.readLine().trim().split(" ");
	// Map<Integer,Integer> m = new HashMap<Integer,Integer>();
 //List<String> fl = new ArrayList<String>();
 //List<String> sl = new ArrayList<String>();
	 //<Integer> v= new Vector<Integer>();
	 //Set<Integer> s= new HashSet<Integer>();
	 int md=1;
   for(int i=2;i<=n;i++)
   if(n%i==0) {
       md=i;
       break;
   }
   n=n+md;
   System.out.println(n+2*(k-1));

	   }
}
catch(Exception e){

}
	}
}


import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner console = new Scanner(System.in);
    int t = console.nextInt();
    while (t-- > 0) {
      long n = console.nextLong(), k = console.nextLong();
      while (k-- > 0) {
        int factor = n;
        int length = 100;
        for (int i = 2; i <= n; i++) {
          if (n % i == 0) {
            factor = i;
            break;
          } else if (length == 0) {
            break;
          }
        }
        n += factor;
      }
      System.out.println(n);
    }
  }
}


import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner console = new Scanner(System.in);
    int t = console.nextInt();
    while (t-- > 0) {
      long n = console.nextLong(), k = console.nextLong();
      while (k-- > 0) {
        int factor = n;
        long length = 100;
        for (int i = 2; i <= n; i++) {
          if (n % i == 0) {
            factor = i;
            break;
          } else if (length == 0) {
            break;
          }
        }
        n += factor;
      }
      System.out.println(n);
    }
  }
}


import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner console = new Scanner(System.in);
    int t = console.nextInt();
    while (t-- > 0) {
      int n = console.nextInt(), k = console.nextInt();
      int prime;
      if (n % 2 == 0) {
        prime = 2;
      } else {
        int index = 3;
        while (n % index != 0) {
          index+=2;
        }
        prime = index;
      }
      System.out.println(prime + n + (k-1) * 2);
    }
  }
}


import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner console = new Scanner(System.in);
    int t = console.nextInt();
    while (t-- > 0) {
      int n = console.nextInt(), k = console.nextInt();
      int total;
      if (n % 2 == 0 && n != 2) {
        total = n + 2 * k;
      } else if (n % 3 == 0 && n != 3) {
        total = n + 3 * k;
      } else if ((n*2) % 2 == 0) {
        total = n*2 + (k-1) * 2;
      } else {
        total = n*2 + (k-1) * 3;
      }
      System.out.println(total);
    }
  }
}


import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner console = new Scanner(System.in);
    int t = console.nextInt();
    while (t-- > 0) {
      long n = console.nextLong(), k = console.nextLong();
      while (k-- > 0) {
        long factor = n;
        long length = 15;
        for (int i = 2; i <= n; i++) {
          if (n % i == 0) {
            factor = i;
            break;
          } else if (length == 0) {
            break;
          }
          length--;
        }
        n += factor;
      }
      System.out.println(n);
    }
  }
}