N = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
arr1.sort()
arr2.sort()
max1 = N-1
max2 = N-1
A = 0
B = 0
turn = 0
while(max1>=0 or max2>=0):
  if turn == 0:
    if arr1[max1]>=arr2[max2]:
      if max1>=0:
        A+=arr1[max1]
        max1-=1
      else:
        max2-=1
    else:
      if max2>=0:
        max2-=1
      else:
        A+=arr1[max1]
        max1-=1
  else:
    if arr1[max1]<=arr2[max2]:
      if max2>=0:
        B+=arr2[max2]
        max2-=1
      else:
        max1-=1
    else:
      if max1>=0:
        max1-=1
      else:
        B+=arr2[max2]
        max2-=1
  if turn == 0:
    turn = 1
  else:
    turn = 0
print(A-B)

#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 7;
const int M = 4e6 + 7;
const int lim = 1e6;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
multiset<long long> ms;
priority_queue<int> pq;
int a[N], b[N];
int main() {
  int n;
  long long aa = 0, bb = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + n);
  int ak = n, bk = n;
  while (n--) {
    if (a[ak] > b[bk])
      aa += a[ak], ak--;
    else
      bk--;
    if (b[bk] > a[ak])
      bb += b[bk], bk--;
    else
      ak--;
  }
  printf("%lld\n", aa - bb);
  return 0;
}


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

public class ChessTourney {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[2*n];
		for(int i = 0 ; i < 2*n ; i++)
			a[i] = scan.nextInt();
		Arrays.sort(a);
		System.out.println(a[n-1] < a[n]?"YES":"NO");
	}
}

YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES NO YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES

#include <bits/stdc++.h>
using namespace std;
int N = 1e5;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  int i;
  vector<int> a(2 * n);
  for (int i = 0; i < 2 * n; i++) {
    cin >> a[i];
  }
  long long l = 0, r = (2 * n - 1);
  long long mid = (l + r) / 2;
  long long left = mid, right = mid + 1;
  bool ok = true;
  sort(a.begin(), a.end());
  for (int i = 0; i < n && left >= 0 && right < 2 * n; i++) {
    if (a[left] == a[right]) {
      cout << "NO"
           << "\n";
      ok = false;
      return 0;
    } else {
      left--;
      right++;
    }
  }
  if (ok) {
    cout << "YES"
         << "\n";
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int base = 1e9;
const int MAX = 2e5;
const long double EPS = 1e-10;
const long double PI = acos(-1.);
int n;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  if (n % 2) {
    cout << 7;
    n -= 3;
  }
  while (n) {
    cout << 1;
    n -= 2;
  }
  return 0;
}


import java.util.*;
public final class VanyaExams
{
	public static void main(String arg[])
	{
	Scanner br=new Scanner(System.in);
	int n=br.nextInt();  //no of exams
	long r=br.nextLong(); 		//maximum grade
	long avg=br.nextLong();		//needed average
	long tot=n*avg;			//total grade needed to achive avg
	long  p=0;
	Grade a[]=new Grade[n];
	Sorting s=new Sorting();
	for(int i=0;i<n;i++)
	{	long g=br.nextLong();
	long e=br.nextLong();
		a[i]=new Grade(g,e);

		p=p+g; 		//computing initial total grade he achieved
	}
	a=(Grade[])s.mergeSort(a);
	long u=tot-p;  //remaining needed grade to achieve
int i=0;
long etw=0;  //no essays to write
	while(u>0)
	{

		//System.out.println(a[i].gr+"   "+ a[i].es);
		long t=r-a[i].gr;
		if(u>=t)
		{
		etw=etw+a[i].es*t;
		u=u-t;}
	else{
		etw=etw+u*a[i].es;
		u=0;
	}

		i++;

	}
	System.out.println(etw);

	}

}
class Grade implements Comparable<Grade>
{
	long gr ,es;
	public int compareTo(Grade g)
	{
		if(this.es>g.es)
			return 1;
		else if(this.es<g.es)
			return -1;
		return 0;
	}
	public Grade(long g,long e)
	{this.gr=g;
		this.es=e;
	}

}

class Sorting
{
	private static Comparable[] aux; // auxiliary array for merges
	public static Comparable[] merge(Comparable[] a, int lo, int mid, int hi)
{ // Merge a[lo..mid] with a[mid+1..hi].
int i = lo, j = mid+1;
for (int k = lo; k <= hi; k++) // Copy a[lo..hi] to aux[lo..hi].
aux[k] = a[k];
for (int k = lo; k <= hi; k++) // Merge back to a[lo..hi].
if (i > mid) a[k] = aux[j++];
else if (j > hi ) a[k] = aux[i++];
else if (less(aux[j], aux[i])) a[k] = aux[j++];
else a[k] = aux[i++];
return a;
}

public static Comparable[] mergeSort(Comparable[] a)
{//client will call this method
aux = new Comparable[a.length]; // Allocate space just once.
mergeSort(a, 0, a.length - 1);
return a;
}
private static Comparable[] mergeSort(Comparable[] a, int lo, int hi)
{ // Sort a[lo..hi].
if (hi <= lo) return a;
int mid = lo + (hi - lo)/2;
mergeSort(a, lo, mid); // Sort left half.
mergeSort(a, mid+1, hi); // Sort right half.
merge(a, lo, mid, hi); // Merge results (code on page 271).
return a;
}
private static boolean less(Comparable v, Comparable w)
{ return v.compareTo(w) < 0; }
private static void exch(Comparable[] a, int i, int j)
{ Comparable t = a[i]; a[i] = a[j]; a[j] = t; }

}

#include <bits/stdc++.h>
using namespace std;
struct node {
  long long a;
  int b;
};
struct node node_arr[100010];
int sort_b(struct node n1, struct node n2) {
  if (n1.b < n2.b) return -1;
  return 0;
}
void solveTestCase() {
  int n;
  scanf("%d", &n);
  ;
  long long r, avg;
  scanf("%I64d", &r);
  ;
  scanf("%I64d", &avg);
  ;
  long long available = 0;
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &node_arr[i].a);
    ;
    scanf("%d", &node_arr[i].b);
    ;
    available += node_arr[i].a;
  }
  sort(node_arr, node_arr + n, sort_b);
  long long total = n * avg;
  if (available >= total) {
    printf("%d\n", 0);
    ;
    return;
  }
  total -= available;
  long long req;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (node_arr[i].a == r) {
      continue;
    }
    req = min(total, r - node_arr[i].a);
    ans += (req * node_arr[i].b);
    total -= req;
  }
  printf("%I64d\n", ans);
  ;
}
int main() {
  solveTestCase();
  return 0;
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

	InputStreamReader  inp = new InputStreamReader(System.in);
	BufferedReader in = new BufferedReader(inp);
	boolean test = false;

	String[] inData = { "1 0 2 0 1",
		"3",
		"XL",
		"XXL",
		"M",
		};

	static int id = -1;
	public String readLine() throws IOException {
		id++;
		if(test)
			return inData[id];
		else
			return in.readLine();
	}

	public Main() throws Throwable {

		lookup.put("S", 0);
		lookup.put("M", 1);
		lookup.put("L", 2);
		lookup.put("XL", 3);
		lookup.put("XXL", 4);

		backLook.put(0,"S");
		backLook.put(1,"M");
		backLook.put(2,"L");
		backLook.put(3,"XL");
		backLook.put(4,"XXL");

		String[] split = readLine().split(" ");

		Integer[] stock = new Integer[]{Integer.valueOf(split[0]),Integer.valueOf(split[1]),Integer.valueOf(split[2]),Integer.valueOf(split[3]),Integer.valueOf(split[4])};
		List<String> requests = new ArrayList<String>();

		Integer folks = Integer.valueOf(readLine());
		for (int i = 0; i < folks; i++) {
			requests.add(readLine());
		}

		for (int i = 0; i < requests.size(); i++) {
			System.out.println(getBestShirt(requests.get(i), stock));
		}
	}

//	public int gcd(int a, int b)
//	{
//	   if (b==0) return a;
//	   return gcd(b,a%b);
//	}

	HashMap<String, Integer> lookup = new HashMap<String, Integer>();
	HashMap<Integer, String> backLook = new HashMap<Integer, String>();

	private String getBestShirt(String string, Integer[] stock) {

		int target = lookup.get(string);
		int offset = 0;
		while(true){

			if(target+offset >= 0 && target+offset< stock.length && stock[target+offset] > 0){
				stock[target+offset] --;
				return backLook.get(target+offset);
			}

			if(offset < 0){
				offset *= (-1);
				offset ++;
			} else if(offset > 0){
				offset *= -1;
			}else {
				offset ++;
			}
		}
	}

	public static void main(String[] args) throws Throwable {
		new Main();
	}
}

13 0 2 4 41
20
S
XXL
XXL
L
XXL
M
L
M
XXL
M
XXL
L
XXL
XL
M
XL
XL
L
L
M

44 314 100 272 270
10
XXL
XL
XXL
XXL
S
S
S
S
L
L

3 1 1 4 1
10
XL
L
L
XXL
XXL
XL
L
XXL
S
M

S
XXL
XXL
L
XXL
L
XL
S
XXL
S
XXL
XL
XXL
XL
S
XL
XXL
XXL
XXL
S

#include <bits/stdc++.h>
using namespace std;
int a[5], t;
string e[5] = {"S", "M", "L", "XL", "XXL"}, s;
int p() {
  if (s == "S") return 0;
  if (s == "M") return 1;
  if (s == "L") return 2;
  if (s == "XL") return 3;
  if (s == "XXL") return 4;
}
int main() {
  for (int i = (0); i < (5); i++) cin >> a[i];
  cin >> t;
  while (t--) {
    cin >> s;
    int x = p();
    for (int i = (0); i < (5); i++) {
      if (x + i < 5 && a[x + i] > 0) {
        x += i;
        break;
      }
      if (x - i >= 0 && a[x - i] > 0) {
        x -= i;
        break;
      }
    }
    cout << e[x] << endl;
    a[x]--;
  }
  return 0;
}


import java.util.Scanner;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Arrays;

public class A448 implements Runnable {
	private Scanner in = new Scanner(System.in);
	private PrintWriter out = new PrintWriter(System.out);
	private int cup [];
	private int medal [];
	private int shelve;

	int cupSum = 0;
	int medalSum = 0;
	private String ans = "NO";

	public static void main(String[] args) {
		new Thread(new A448()).start();
	}

	private void read() {

		cup = new int[3];
		medal = new int[3];

		for(int i = 0; i < 3; i++){
			cup[i] = in.nextInt();
			cupSum += cup[i];
		}

		for(int i = 0; i < 3; i++){
			medal[i] = in.nextInt();
			medalSum += medal[i];
		}

		shelve = in.nextInt();
	}

	private void solve() {

		if(cupSum > 5){
			shelve = shelve - (int) Math.ceil((double)cupSum / 5);
		} else if(cupSum > 0){
			shelve = shelve - 1;
		}

		if(medalSum > 10){
			shelve = shelve - (int) Math.ceil((double)medalSum / 10);
		} else if(medalSum > 0){
			shelve = shelve - 1;
		}

		if(shelve >= 0) {
			ans = "YES";
		}

	}

	private void write() {

			out.println(ans);

	}

	public void run() {
		read();
		solve();
		write();
		out.close();
	}
}

NO YES NO NO YES NO NO NO YES NO YES NO YES NO YES NO YES NO NO NO NO NO YES NO NO NO NO NO YES YES YES NO YES NO NO NO YES NO YES YES YES YES NO NO NO NO NO NO NO NO

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a1, a2, a3;
  int b1, b2, b3, n;
  cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3 >> n;
  int numb = a1 + a2 + a3;
  int numb1 = b1 + b2 + b3;
  numb = numb + 4;
  int req = numb / 5;
  numb1 = numb1 + 9;
  int req2 = numb1 / 10;
  if (req + req2 <= n)
    cout << "YES";
  else
    cout << "NO";
}


n = int(input())
s = list(input())
o = 0
#s.reverse()

# while s.count("B") > 0:
#   while s[-1] == "R":
#     s.pop()
#   s[-1] = "R"
#   while len(s) < n:
#     s.append("B")
#   o += 1
#   print(s)

try:
  index = s.index("B")
  o += pow(2, index)
  while True:
    index = s.index("B", index + 1)
    o += pow(2, index)
except:
  print(o)

#include <bits/stdc++.h>
using namespace std;
long long lookup[51];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long init = 1;
  for (int i = 0; i < 51; i++) {
    lookup[i] = init;
    init *= 2;
  }
  int n;
  cin >> n;
  long long out = 0;
  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    if (c == 'B') out += (lookup[i]);
  }
  cout << out;
  return 0;
}


n = int(input())
A = [int(i) for i in input().split()]

def mergesort(l):
	l = list(l)
	if len(l) <= 1:
		return l,0
	left,linv = mergesort(l[:len(l) // 2])
	right,rinv = mergesort(l[len(l) // 2:])
	lefti = 0
	righti = 0
	i = 0
	numinversions = 0
	while True:
		if i >= len(l):
			break
		if lefti >= len(left):
			l[i] = right[righti]
			righti += 1
		elif righti >= len(right):
			l[i] = left[lefti]
			lefti += 1
			numinversions += len(right)
		elif left[lefti] > right[righti]:
			l[i] = right[righti]
			righti += 1
		else:
			l[i] = left[lefti]
			lefti += 1
			numinversions += righti
		i += 1
	return (l,numinversions + linv + rinv)

res = mergesort(A)

n = res[1]

if n % 2 == 0:
	print(2*n)
else:
	print(2*n-1)

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

public class D {
    public static void main(String[] args) throws Exception {
        InputStreamReader input = new InputStreamReader(System.in);
        BufferedReader read = new BufferedReader(input);

        int N = Integer.parseInt(read.readLine());
        StringTokenizer token = new StringTokenizer(read.readLine());
        int P[] = new int[N];
        for (int i = 0; i < N; ++i) {
            P[i] = Integer.parseInt(token.nextToken());
        }
        int inv = 0;
        for (int i = 1; i < N; ++i) {
            int j = i;
            while (j > 0 && P[j-1] > P[j]) {
                int tmp = P[j-1];
                P[j-1] = P[j];
                P[j] = tmp;
                j--;
                inv++;
            }
        }
        int ret = 4 * (inv/2) + (inv % 2);
        System.out.println("" + ret);
    }
}


import java.io.*;

public class tmo {
	public static void main(String[] args) throws IOException {
		StreamTokenizer in = new StreamTokenizer(new BufferedReader(
				new InputStreamReader(System.in)));
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		in.nextToken();
		int n = (int) in.nval;
		in.nextToken();
		int k = (int) in.nval;
		int[] a = new int[n];
//		int maxa = 0;
//		int mina = 10000000;
		for (int i = 0; i < n; i++) {
			in.nextToken();
			a[i] = (int) in.nval;
//			if (a[i] > maxa)
//				maxa = a[i];
//			if (a[i] < mina)
//				mina = a[i];
		}
//		int r = maxa - mina + 1;
		int p = k * (k + 1) / 2;
		int[] delta = new int[1000001];
		int[] test = new int[1000000 + 1];
		for (int i = 0; i < (n - 1); i++)
			for (int j = i + 1; j < n; j++)
				delta[Math.abs(a[i] - a[j])]++;
		for (int i = 1;; i++) {
			int ch = 0;
			for (int j = i; j <= 1000000; j += i) {
				ch += delta[j];
				if (ch > p)
					break;
			}
			if (ch <= p) {
				if (ch <= 1) {
					out.println(i);
					break;
				} else {
					ch = 0;
					for (int l = 0; l < n; l++)
						if (test[a[l] % i] == i)
							ch++;
						else
							test[a[l] % i] = i;
					if (ch <= k) {
						out.println(i);
						break;
					}
				}
			}
		}
		out.flush();
	}
}

#include <bits/stdc++.h>
using namespace std;
int num[5010], cnt[1000010];
int vi[1000010];
int main() {
  int n, k, kk, mlen;
  while (scanf("%d%d", &n, &k) == 2) {
    kk = k * (k + 1) / 2;
    mlen = 0;
    for (int i = 0; i < n; ++i) scanf("%d", &num[i]);
    sort(num, num + n);
    for (int i = 0; i < n; ++i)
      for (int j = i + 1; j < n; ++j)
        ++cnt[num[j] - num[i]], mlen = max(mlen, num[j] - num[i]);
    for (int i = 1; i < 1000010; ++i) {
      int sum = 0;
      for (int j = i; j <= mlen && sum <= kk; j += i) sum += cnt[j];
      if (sum > kk) continue;
      sum = 0;
      for (int j = 0; j < n && sum <= k; ++j) {
        if (vi[num[j] % i] == i) ++sum;
        vi[num[j] % i] = i;
      }
      if (sum <= k) {
        printf("%d\n", i);
        break;
      }
    }
  }
  return 0;
}


import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception
{
    input.init(System.in);
    PrintWriter out = new PrintWriter(System.out);
    int x  =0;
    for(int i = 0, n = input.nextInt(); i<n; i++) x += input.next().indexOf('+') >= 0 ? 1 : -1;
    out.println(x);

    out.close();
}
public static class input {
  static BufferedReader reader;
  static StringTokenizer tokenizer;
  static void init(InputStream input) {
      reader = new BufferedReader(
                   new InputStreamReader(input) );
      tokenizer = new StringTokenizer("");
  }

  static String next() throws IOException {
      while ( ! tokenizer.hasMoreTokens() ) {
          tokenizer = new StringTokenizer(
                 reader.readLine() );
      }
      return tokenizer.nextToken();
  }

  static int nextInt() throws IOException {
      return Integer.parseInt( next() );
  }

  static double nextDouble() throws IOException {
      return Double.parseDouble( next() );
  }
  static long nextLong() throws IOException {
      return Long.parseLong( next() );
  }
}
}

#include <bits/stdc++.h>
int n, a;
char s[3];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    for (int j = 0; j < 3; j++) {
      if (s[j] == '+') {
        a++;
        break;
      } else if (s[j] == '-') {
        a--;
        break;
      }
    }
  }
  printf("%d", a);
  return 0;
}


import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Task {

	private static final boolean readFromFile = false;
	private static final String fileInputName = "input.txt",
								fileOutputName = "output.txt";

	public static void main(String args[]){
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FileOutputStream fileOutputStream;
		FileInputStream fileInputStream;
		if (readFromFile){
			try{
				fileInputStream = new FileInputStream(new File(fileInputName));
				fileOutputStream = new FileOutputStream(new File(fileOutputName));
			}catch (FileNotFoundException e){
				throw new RuntimeException(e);
			}
		}
		PrintWriter out = new PrintWriter((readFromFile)?fileOutputStream:outputStream);
		InputReader in = new InputReader((readFromFile)?fileInputStream:inputStream);

		Solver s = new Solver(in,out);
		s.solve();

		out.close();
	}
}

class Solver{
	private InputReader in;
	private PrintWriter out;
	private static final Random rnd = new Random();
	int getRandom(int prom){
		return Math.abs(rnd.nextInt())%prom;
	}

	public void solve(){
		int n = in.nextInt(),
			a[] = new int[n+1],
			b[] = new int[n+1];
		for (int i=0;i<n;i++)
			a[i] = in.nextInt();
		for (int i=0;i<n;i++){
			int c = in.nextInt();
			b[c] = i+1;
		}
		for (int i=0;i<n;i++)
			a[i] = b[a[i]];
		int ans = 1;
		while (ans<n && a[ans]>a[ans-1])
			ans++;
		out.println(n-ans);
	}

	Solver(InputReader in, PrintWriter out){
		this.in=in;
		this.out=out;
	}
}

class InputReader{
	private BufferedReader buf;
	private StringTokenizer tok;

	InputReader(InputStream in){
		tok = null;
		buf = new BufferedReader(new InputStreamReader(in));
	}

	InputReader(FileInputStream in){
		tok = null;
		buf = new BufferedReader(new InputStreamReader(in));
	}

	public String next(){
		while (tok==null || !tok.hasMoreTokens()){
			try{
				tok = new StringTokenizer(buf.readLine());
			}catch (IOException e){
				throw new RuntimeException(e);
			}
		}
		return tok.nextToken();
	}

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

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

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

	public float nextFloat(){
		return Float.parseFloat(next());
	}

	public String nextLine(){
		try{
			return buf.readLine();
		}catch (IOException e){
			return null;
		}
	}

}

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200 * 1000 + 100;
int n, a[MAXN], b[MAXN], p[MAXN], x;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    p[a[i]] = i;
  }
  for (int i = 0; i < n; ++i) cin >> b[i];
  for (int i = 0; i < n; ++i) a[p[b[i]]] = i;
  x = 1;
  while (x < n && a[x] > a[x - 1]) x++;
  cout << n - x << endl;
  return 0;
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class ECompatibleNumbers {
        int n;
        int[] arr;
        int[] memo;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            n = sc.nextInt();
            arr = new int[n];
            memo = new int[1 << 22];
            Arrays.fill(memo, -1);
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
                memo[arr[i]] = arr[i];
            }
            for (int i = 0; i < 22; i++)
                for (int j = 0; j < 1 << 22; j++)
                    if (memo[j] == -1 && (j & 1 << i) != 0)
                        memo[j] = memo[j ^ 1 << i];
            for (int x : arr)
                pw.print(memo[((1 << 22) - 1) ^ x] + " ");
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

    }
}

#include <bits/stdc++.h>
using namespace std;
const int maxn = (1 << 23);
bool mark[maxn];
int a[maxn], in_sub[maxn];
queue<int> q;
int tilda(int x) { return (1 << 22) - 1 - x; }
void reverse_bfs() {
  while (q.size()) {
    int tmp = q.front();
    for (int i = 0; i < 22; i++)
      if (!(tmp & (1 << i))) {
        int par = tmp | (1 << i);
        if (in_sub[par] == 0) in_sub[par] = in_sub[tmp];
        if (!mark[par]) {
          mark[par] = true;
          q.push(par);
        }
      }
    q.pop();
  }
}
int main() {
  int n;
  scanf(" %d", &n);
  for (int i = 1; i <= n; i++) {
    scanf(" %d", &a[i]);
    q.push(a[i]);
    mark[a[i]] = true;
    in_sub[a[i]] = a[i];
  }
  reverse_bfs();
  for (int i = 1; i <= n; i++) {
    if (in_sub[tilda(a[i])])
      printf("%d ", in_sub[tilda(a[i])]);
    else
      printf("-1 ");
  }
  printf("\n");
  return 0;
}


n,k,x =list(map(int ,input().split()))
arr = list(map(int ,input().split()))
arr.sort()
groups =1
re = []

for i in range(n-1):
    diff = arr[i+1]-arr[i]
    if diff>x :

      if x==0:
        groups+=1
        continue
      if diff%x==0:
        diff = diff//x -1
      else:
        diff =diff//x
      re.append(diff)
      groups+=1
re.sort()

for i in range(len(re)):
    k-=re[i]
    if k>=0:
      groups-=1
    else:
      break

print(groups)

#include<bits/stdc++.h>
using namespace std;
int main() {
	unsigned long long int i, n, k, j, x, gcount = 0;
	//double x;

	cin>>n>>k>>x;
	vector<unsigned long long int> a(n), b;
	for(int i=0;i<n;i++)
		cin>>a[i];

	sort(a.begin(), a.end());

	for(int i=1;i<n;i++) {
		if(a[i]-a[i-1]>x) {
			gcount++;
			b.push_back(((a[i]-a[i-1]+x-1)/x)-1);
		}
	}
	gcount++;
	//cout<<gcount<<endl;
	sort(b.begin(), b.end());

	/*for(i=0;i<b.size();i++)
		cout<<b[i]<<" ";
	cout<<endl;*/

	for(i=0;i<b.size();i++) {
		if(b[i]<=k)
			k-=b[i];
		else
			break;
	}
	cout<<gcount-i<<endl;

}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, l, m, n, d, i, c;
  cin >> k >> l >> m >> n >> d;
  i = 0;
  c = 0;
  while (i < d) {
    if ((i + 1) % k != 0 and (i + 1) % l != 0 and (i + 1) % m != 0 and
        (i + 1) % n != 0) {
      ++c;
    }
    ++i;
  }
  cout << (d - c);
  return 0;
}

kill=[]
for i in range(4):
    a=int(input())
    kill.append(a)
d=int(input())
count=0
for i in range(1,d+1):
    for j in kill:
        if i%j==0:
            count+=1
            break
        else:
            count+=0

print(count)


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

public class Lv1100_Dungeon {

	public static void main(String[] args) {
		InputReader rd = new InputReader(System.in);
		int testcases = rd.nextInt();
		StringBuilder stb = new StringBuilder();
		for (; testcases > 0; testcases--) {
			int[] demons = new int[3];
			long total = 0;
			for (int i = 0; i < demons.length; i++) {
				demons[i] = rd.nextInt();
				total += demons[i];
			}
			Arrays.sort(demons);
			if (total % 9 == 0) {
				long avarage = total / 9;
				if (demons[0] < avarage) {
					stb.append("NO\n");
				} else {
					stb.append("YES\n");
				}
			} else {
				stb.append("NO\n");
			}

		}
		System.out.println(stb);
	}

	static class InputReader {
		StringTokenizer tokenizer;
		BufferedReader reader;
		String token;
		String temp;

		public InputReader(InputStream stream) {
			tokenizer = null;
			reader = new BufferedReader(new InputStreamReader(stream));
		}

		public InputReader(FileInputStream stream) {
			tokenizer = null;
			reader = new BufferedReader(new InputStreamReader(stream));
		}

		public String nextLine() throws IOException {
			return reader.readLine();
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					if (temp != null) {
						tokenizer = new StringTokenizer(temp);
						temp = null;
					} else {
						tokenizer = new StringTokenizer(reader.readLine());
					}
				} catch (IOException e) {
				}
			}
			return tokenizer.nextToken();
		}

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

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

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

def zip_sorted(a,b):

	# sorted  by a
	a,b = zip(*sorted(zip(a,b)))
	# sorted by b
	sorted(zip(a, b), key=lambda x: x[1])

	return a,b

import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
S = lambda : list(map(str,input()))

t,=I()
for t1 in range(t):
	a   = I()
	if sum(a)%9==0:
		if min(a)>=int(sum(a)/9):
			print('yes')
		else:
			print('no')
	else:
		print('no')


import java.util.*;
public class dk{
public static void main(String[] args){
		Scanner scn=new Scanner(System.in);
		int mT=scn.nextInt();
		int mtcs=0;
		int arr[]=new int[5];
		StringBuilder res=new StringBuilder();
		A: while (mtcs++ < mT) {
			long ma = scn.nextLong(), mb = scn.nextLong(), c = scn.nextLong();
			if (ma >= c) {
				res.append("-1 ");
			} else
				res.append("1 ");
			if (c / mb >= ma)
				res.append("-1\n");
			else
				res.append(mb + "\n");
		}
		System.out.println(res);

	}
	}

import sys
input = sys.stdin.readline

def main():
    t = int(input())
    for _ in range(t):
        A, B, C = [int(x) for x in input().split()]

        ans1 = -1
        ans2 = -1

        if A < C:
            ans1 = 1

        if A * B > C:
            ans2 = B

        print(ans1, ans2)

if __name__ == '__main__':
    main()


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class r473E {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            long n = in.nl() - 1;
            int highest = Long.numberOfTrailingZeros(Long.highestOneBit(n));
            long ans = 0;
            long cnt = 0;
            for (int bit = 0; bit <= highest; bit++) {
                long w = 1L << bit;
                long many = n >> bit + 1;
                if (((many << bit + 1) | w) <= n)
                    many++;
                //System.out.println("w = " + w);
                //System.out.println("many = " + many);
                ans += many * w;
                cnt += many;
            }
            if (cnt != n)
                throw new RuntimeException("only deleted " + cnt);
            out.println(ans);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public long nl() {
            return Long.parseLong(ns());
        }

    }
}

import math

n = int(input())

ans = 0
cur = 1

while cur < n:
    cnt = math.ceil((n-cur)/(cur << 1))
    ans += cnt*cur
    cur <<= 1

print(ans)


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Solution{

	static final int N = (int)1e5+10;

    public static void main(String[] args) throws IOException {

    	FastScanner fs = new FastScanner();
    	PrintWriter out = new PrintWriter(System.out);

    	int tt = 1;
    	while(tt-->0) {

    		int n = fs.nextInt(), x = fs.nextInt();

    		int[] cnt = new int[20];
    		ArrayList<Integer> list = new ArrayList<Integer>();

    		for(int i=1;i<n;i++) {
    			list.add(i);
    			for(int j=0;j<18;j++) {
    				if((i&(1<<j))!=0) {
    					cnt[j]++;
    				}
    			}
    		}

    		int num = 0;
    		for(int j=0;j<18;j++) {
    			if((x&(1<<j))!=0) {
    				if(cnt[j]%2==0) {
    					num += (1<<j);
    				}
    			}
    			else {
    				if(cnt[j]%2!=0) {
    					num += (1<<j);
    				}
    			}
    		}

    		boolean bool = false;
    		for(int i=0;i<n-1;i++) {
    			if(list.get(i)==num) {
    				bool = true;
    				if(i>0) {
    					list.set(i-1, list.get(i-1)+(1<<17));
    				}
    				else if(i<n-2) {
    					list.set(i+1, list.get(i+1)+(1<<17));
    				}
    				else {
    					out.println("No");
    					out.flush();
    					return;
    				}
    			}
    		}
    		if(bool)
    			num += (1<<17);

    		out.println("Yes");
    		for(int i: list) {
    			out.print(i+" ");
    		}
    		out.println(num);

    	}

    	out.close();

    }

    static final Random random=new Random();

    static void ruffleSort(int[] a) {
    	int n=a.length;//shuffle, then sort
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); int temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }

    static class FastScanner{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");

    	public String next(){
    		while(!st.hasMoreElements()){
    			try{
    				st = new StringTokenizer(br.readLine());
    			} catch(IOException e){
    				e.printStackTrace();
    			}
    		}
    		return st.nextToken();
    	}

    	public String nextLine() throws IOException {
    		return br.readLine();
    	}

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

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

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

    	public char nextChar() {
    		return next().toCharArray()[0];
    	}
    }

}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int count = 0;
  for (int i = 0; i < n; i++) {
    int elements;
    cin >> elements;
    if (elements % 2 != 0) {
      count++;
    }
  }
  string res = (count == 0) ? "Second" : "First";
  cout << res;
  return 0;
}

First First Second Second Second Second First First First Second First First First First First First Second Second First First First First Second Second First First Second First Second First First First Second First First First Second First Second First Second First First Second First First Second First First

/* package codechef; // don't place package name! */

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 Main
{

	public static void main (String[] args) throws java.lang.Exception
	{
	  Scanner sc=new Scanner(System.in);
	  try{
	       int n=sc.nextInt();
	       long a[]=new long[n];
	       for(int i=0;i<n;i++){
	           a[i]=sc.nextLong();
	       }
	       int c=0;
	       for(int i=0;i<n;i++){
	           if(a[i]%2!=0){
	               c++;
	           }
	       }
	       if(c>=1){
	           System.out.println("First");
	       }
	       else{
	           System.out.println("Second");
	       }
	  }
	  catch(Exception e){
	      return;
	  }
	}
}


import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Scanner;

public class _0294BuyingAHouse {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int k=sc.nextInt();
		int[] arr = new int[n];
		int minIndex=0;
		m--;
		for(int i=0;i<n;i++) {
			arr[i]=sc.nextInt();
		}
		int left=m;
		int right=m;
		while(left-1>=0 || right+1<n) {
			if(left-1>=0) {
				if(arr[left-1]!=0 &&arr[left-1]<=k) {
					minIndex=left-1;
					break;
				}
			}
			if(right+1<n) {
				if(arr[right+1]!=0 &&arr[right+1]<=k) {
					minIndex=right+1;
					break;
				}
			}
			left--;
			right++;
		}
		System.out.println(Math.abs(m-minIndex)*10);
	}

}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k, a, jwb = 0, jwbn = 0;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    if (a <= k && a > 0) {
      if (jwbn == 0) {
        jwbn = i;
        jwb = a;
      } else if (abs(m - i) < abs(m - jwbn)) {
        jwbn = i;
        jwb = a;
      }
    }
  }
  cout << abs(jwbn - m) * 10 << endl;
  return 0;
}


#include <bits/stdc++.h>
int main() {
  unsigned long long n, i, c = 0;
  scanf("%llu", &n);
  if (n < 2520) {
    printf("0\n");
  } else {
    printf("%llu\n", n / 2520);
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, num, x, y, ans;
  while (~scanf("%d", &n)) {
    priority_queue<int, vector<int>, greater<int> > q;
    ans = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &num);
      q.push(num);
    }
    for (;;) {
      if (q.size() == 1) {
        ans++;
        break;
      }
      x = q.top();
      q.pop();
      y = q.top();
      if (x != y) {
        ans++;
      }
      if (x == y) {
        q.pop();
        q.push(++x);
      }
    }
    printf("%d\n", ans);
  }
}

9
1 1 1 1 2 2 3 3 3
```

Each sample input is a string in the format "

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.StringTokenizer;

	public class Main {

		public static void main(String[] args) throws  IOException {
			/* Your class should be named Main.
	 			* Read input as specified in the question.
	 			* Print output as specified in the question.
			*/

			// Write your code here
			HashMap <Integer,Integer> map = new HashMap<>();
			Scanner in =new Scanner(System.in);
			BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
			int n =Integer.parseInt(br.readLine());
			String a =br.readLine();
			StringTokenizer st =new StringTokenizer(a);

			for(int i =0;i<n;i++)
			{
				int val=Integer.parseInt(st.nextToken());

				insert(map,val);
			}
			//ArrayList <Integer> ar =new ArrayList<>(map.keySet());
			int count=0;
			for(Entry<Integer, Integer> i: map.entrySet()) {
				count+=i.getValue();
			}
			System.out.println(count);
			in.close();
	}
	static void insert(HashMap <Integer,Integer> map,int a) {
			if(map.containsKey(a))
			{
				insert(map, a+1);
				map.remove(a);
			}
			else {
				map.put(a, 1);
			}

	}
}


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

public class ContestPiA {

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(bf.readLine());
        int []a = new int [n];
        StringTokenizer ns = new StringTokenizer(bf.readLine());
        for(int i=0;i<a.length;i++)
            a[i]=Integer.parseInt(ns.nextToken());

        int x=Math.abs(a[0]-a[1]);
        int y=Math.abs(a[0]-a[a.length-1]);
        System.out.println(x + " "+y);
        for (int i=1;i<a.length-1;i++){
            int max=0,min=0;
            int x1=Math.abs(a[i]-a[i+1]);
            int x2=Math.abs(a[i]-a[i-1]);
            if(x1<x2)
                min=x1;
            else
                min=x2;
            int y1 = Math.abs(a[i]-a[a.length-1]);
            int y2 = Math.abs(a[i]-a[0]);
            if(y1>y2)
                max=y1;
            else
                max=y2;

            System.out.println(min + " "+ max);

        }
        x=Math.abs(a[a.length-2]-a[a.length-1]);
        y=Math.abs(a[0]-a[a.length-1]);
        System.out.println(x + " "+y);
    }
}


import java.util.Scanner;

public class temp {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] a = new int[n];

		long sum = 0;
		for (int i =0 ; i<n ; i++){
			a[i] = s.nextInt();
			sum = sum + a[i];
		}
        long sumt = sum/3;
        if (sum%3!=0)
            System.out.print(0);
        else{
            long ans = 0;
            int count = 0;
            long sumtemp = 0;
            int[] endcount = new int[n];
            for (int i =n-1 ; i>=0 ; i--){
                sumtemp += a[i];
                if (sumtemp==sumt){
                    count++;
                }
                endcount[i] = count;
            }

            sumtemp = 0;
            for (int i =0 ; i<n-2 ; i++){
                sumtemp += a[i];
                if (sumtemp == sumt){
                    ans += endcount[i+2];
                }
            }
            System.out.print(ans);
        }
	}

}

def NoW(xs):
    if sum(xs) % 3 != 0:
        return 0
    else:
        part = sum(xs) // 3
        ci = ret = 0
        acum = xs[0]
        for i, x in enumerate(xs[1:]):
            if acum == 2*part:
                # print("2. x=",x)
                ret += ci
            if acum == part:
                # print("1. x=",x)
                ci += 1
            acum += x

        return ret

input()
xs = list(map(int, input().split()))
print(NoW(xs))


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskC {
        static String[][] ans;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            String curr;
            int ones = 0, zeros = 0, zo = 0, oz = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    curr = in.next();
                    if (curr.equals("00")) zeros++;
                    else if (curr.equals("11")) ones++;
                    else if (curr.equals("10")) oz++;
                    else zo++;
                }
            }

            int mx = zo + oz;
            zo = mx / 2;
            oz = mx - zo;

            ans = new String[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (ones != 0) {
                        ans[i][j] = "11";
                        ones--;
                    } else if (oz != 0) {
                        ans[i][j] = "10";
                        oz--;
                    } else if (zeros != 0) {
                        ans[i][j] = "00";
                        zeros--;
                    } else {
                        ans[i][j] = "01";
                        zo--;
                    }
                    out.print(ans[i][j] + " ");
                }
                out.println();
            }

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}

n, m = map(int, input().split())
doubles, singles = 0, 0
for r in range(n):
    for s in input().split():
        if s == '11':
            doubles += 1
        elif s != '00':
            singles += 1
lines = {
    'zero': ' '.join(m * [ '00' ]),
    'double': ' '.join(m * [ '11' ]),
    'single_0': ' '.join(m * [ '01' ]),
    'single_1': ' '.join(m * [ '10' ])
}
zeros = n * m - doubles - singles
while doubles >= m:
    print(lines['double'])
    doubles -= m
while singles >= 2 * m:
    print(lines['single_0'])
    print(lines['single_1'])
    singles -= 2 * m
while zeros >= m:
    print(lines['zero'])
    zeros -= m

x = doubles + singles + zeros
tail = [ m * [ '00' ] for r in range(x // m) ]
height = len(tail)
r, c = 0, 0
while singles + doubles > 0:
    if tail[r][c] == '00':
        if doubles > 0:
            tail[r][c] = '11'
            doubles -= 1
        else:
            tail[r][c] = '01'
            singles -= 1
            if singles > 0 and r + 1 < height:
                tail[r + 1][c] = '10'
                singles -= 1
    c += 1
    if c == m:
        c = 0
        r += 1
for row in tail:
    print(' '.join(row))