let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    let line=buf.split('\n');
    let t=parseInt(line[0]);
    for(let i=1;i<=2*t;i+=2)
    {
        let s=line[i];
        let c=line[i+1];
        s.length-=1,c.length-=1;
        // console.log(s.length,c.length);
        let flag=false;
        if(s.length%2==0)
        {
            for(let j=0;j<s.length-1;j++)
            {
                if(s[j]===c[0])
                {
                    if(j%2==0)
                    {
                        flag=true;
                    }
                }
            }
        }
        if(flag) console.log("YES");
        else console.log("NO");
    }
})

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    // console.log(line);
    for(let i=1;i<=2*t;i+=2)
    {
        let s=line[i];
        let c=line[i+1];
        // console.log(s.length,c.length);
        let flag=false;
        if(s.length%2==1)
        {
            for(let j=0;j<s.length;j++)
            {
                if(s[j]===c[0])
                {
                    if(j%2==0)
                    {
                        flag=true;
                    }
                }
            }
        }
        if(flag) console.log("YES");
        else console.log("NO");
    }
})

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL} = require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    // console.log(line);
    for(let i=1;i<=2*t;i+=2)
    {
        let s=line[i];
        let c=line[i+1];
        // console.log(s.length,c.length);
        let flag=false;
        if(s.length%2==1)
        {
            for(let j=0;j<s.length;j++)
            {
                if(s[j]===c[0])
                {
                    if(j%2==0)
                    {
                        flag=true;
                    }
                }
            }
        }
        if(flag) console.log("YES");
        else console.log("NO");
    }
})

/*
** Template
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

const isOdd = (x) => { return x & 1 }
const isEven = (x) => { return !(x & 1) }

const getMiddle = s => s.substr(s.length - 1 >>> 1, (~s.length & 1) + 1)

const findAllIndicesOfChar = (str, char) => {
    str = str.split('')
    let indices = [];
    for (let i = 0; i < str.length; i++) {
        if (str[i] === char) indices.push(i);
    }
    return indices
}

const getResult = ( str, target ) => {

    let len = str.length

    let validLen = []
    for(let i = 5; i <= len; i+= 4) validLen.push(i)

    if( len === 1 ) return str === target ? 'YES'  : 'NO'

    let begin   = str.charAt(0)
    let end     = str.charAt(str.length-1)
    let midchar = getMiddle(str)

    if( begin === target || end === target ) return 'YES'
    // if( midchar === target ){
    //     return validLen.includes(len) ? 'YES' : 'NO'
    // }

    let indices = findAllIndicesOfChar( str, target )

    for(let i = 0; i < indices.length; i++){
        if( isEven(indices[i]) ) {
            return 'YES'
        }
    }

    return 'NO'
}

function main() {
    let testcases = parseInt( readline() )
    while( testcases-- ){

        let str     = readline()
        let target  = readline()
        console.log( getResult( str, target ) )
    }
}
//*/

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
   var t = lines[0];
	var k = 0;
	for(i = 1; i <= t * 2; i++){
	    if(i % 2 == 1){
	       	 k = lines[i].split('');
	    }else{
	        var e = lines[i];
	        var a = false;
	        for(j = 0; j < k.length; j++){
	            if(k[j] == e){
	                if(j % 2 === 0){
	                    a = true;
	                }else{
	                    continue;
	                }
	            }
	        }
	        if(a){
	           console.log('YES');
	        }else{
	            console.log('NO');
	        }
	    }
	}
});

let data = '';
process.stdin.on('data', c => data += c);

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let s = nl.line().split('').map((e,i) => (i%2 == 0)?e:'').join('');
		let c = nl.line();
		ans.push(s.search(c) != -1);

	}
	console.log(ans.map(e => e?"YES":"NO").join('\n'));
};

process.stdin.on('end', sol);

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', stdin => inputString += stdin);

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(s => s.trim());
    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let s = readline();
        let c = readline();

        let indexes = [];
        for (let i = 0; i < s.length; i++) {
            if (s[i] === c) indexes.push(i);
        }

        let no = true;
        for (let idx = 0; idx < indexes.length; idx++) {
            let i = indexes[idx];
            let rem = s.length - 1;
            if (i % 2 === 0 && rem % 2 === 0) {
                no = false;
                continue;
            }
        }

        output(no ? 'NO' : 'YES');
    }
}

'use strict'; /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}

module.exports = E;

const ra = ()=>readline().split(' ').map(a=>+a)

const EPS = 1e-6;

const calc = (s, c)=>{
  for (let i=0; i<s.length; i++)
    if (i%2==0 && s[i]==c)
      return true;
};

function main() {
    let T = +readline()
    while (T--){
      let s = readline();
      let c = readline();
      print(calc(s, c) ? 'YES' : 'NO');
    }
}

E.calc = calc;

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false,
});

let c = 0;
let str;

rl.on("line", (d) => {
  if (c === 0) {
    c++;
    return;
  }

  if (c % 2 === 1) {
    str = d;
    c++;
    return;
  }

  let ans = "NO";
  for (let i = 0; i < str.length; i++) {
    if (str[i] === d && i % 2 === 0) {
      ans = "YES";
    }
  }

  console.log(ans);
  c++;
});

rl.on("close", () => {});

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let t = -1;
let i = 0;

let input = [];

function check(str1, c) {
    for (let i = 2; i < str1.length - 2; ++i) {
        if ((str1[i] === c) && (i % 2 === 0) && ((str1.length - i) % 2 !== 0)) {
            return true;
        }
    }

    if ((str1[str1.length - 1] === c) || (str1[0] === c)) {
        return true;
    } else {
        return false;
    }
}

rl.on('line', (line) => {
    if (t === -1) {
        t = parseInt(line);
    } else {
        ++i;

        input.push(line);

        if (i === 2 * t) {
            rl.close();
        }
    }
}).on('close', () => {
    for (let i = 0; i < input.length; i += 2) {
        if (check(input[i], input[i + 1])) {
            process.stdout.write("YES\n");
        } else {
            process.stdout.write("NO\n");
        }
    }

});

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let ls = [];

function solve(){
    let i = 1;
    while (i < ls.length){
        const str = ls[i++];
        const c = ls[i++];
        let found = false;
        for (let j = 0; j < str.length; j++){
            if (str[j] == c && j % 2 == 0){
                found = true;
                break;
            }
        }
        console.log(found ? 'YES' : 'NO');
    }
}

rl.on('line', (l) => ls.push(l));
rl.on('close', () => solve());

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        solve();
    }
}
function solve() {
    let str = readLine();
    const c = readLine();
    for (let i = 0; i < str.length; i++) {
        if (i % 2 == 0 && str.charAt(i) === c) {
            console.log("YES");
            return;
        }
    }
    console.log("NO");
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const str = lines[l++]
        const c = lines[l++]
        output[i] = solve(str, c) ? 'YES' : 'NO'
    }
    console.log(output.join('\n'))
// })()
})

function solve(str, c) {
    for (let i = 0; i < str.length; i++) {
        if (str[i] === c && !(i & 1)) return true
    }
    return false
}

function solve() {
   const s = read();
   const c = read();
   for (let i = 0; i < s.length; i++) {
      if (s[i] === c && !(i & 1)) {
         write('YES');
         return;
      }
   }
   write('NO');
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function pDivCount(n) {
   let ans = 0;
   let i = 1;
   while(n > 1) {
      i++;
      while(n % i === 0) {
         ans++;
         n = Math.floor(n / i);
      }
   }
   return ans;
}

function gcd(a, b) {
   if (a === 0) {
      return b;
   }
   return gcd(b % a, a);
}

function lcm(a, b) {
   return Math.floor(a / gcd(a, b)) * b;
}

function init() {
   try {
      var T;
      T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e);
   }
}

function readArray(mapF) {
   var res = read().split(' ');
   if (mapF) {
      res = res.map(mapF);
   }
   return res;
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }
   MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\r\n');
}
init();

function write(value) {
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   if (isNode) {
      return MEMORY;
   }
   var res = [];
   var x;
   while (x = read()) {
      res.push(x);
   }
   return res;
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var s = next();
		var N = s.length;
		var c = next();
		var ok = false;
		for(var i = 0; i < N; i += 2){
			if(s[i] == c){
				ok = true;
				break;
			}
		}
		myout((ok) ? "YES" : "NO");
	}
}

T = readline ()
while(T--){

   s = readline().split('')
   c = readline()
   res = 'NO'

   for(i=0; i< s.length; i++){
      if(s[i] ===c){
         if(i % 2 == 0 && (s.length - i) %2 != 0){
            res = 'YES'
            break
         }
      }
   }

   print(res)
}

var t = readline();
for (var i = 0; i<t; i++) {
     var str = readline();
     var letter = readline();
   print(fn(str,letter));
}

function fn(str, letter) {
    if (str === letter) return "YES";
    var arr = str.split('');
    var result;
    if (arr.length <= 1) return "NO";
     for (var i=0; i < arr.length; i++) {
         if (arr[i] === letter && i%2 === 0) {
             result="YES";
             break;
         }
         else result="NO";
         }
         return result;
  }

var t = readline()
for (var i = 0; i<t; i++) {
     var str = readline()
     var letter = readline()
   print(fn(str,letter))
}

function fn(str, letter) {
    if (str === letter) return "YES"
    var arr = str.split('')
    var result;
    if (arr.length <= 1) return "NO"
     for (var i=0; i < arr.length; i++) {
         if (arr[i] === letter && i%2 === 0) {
             result="YES"
             break;
         }
         else result="NO"
         }
         return result
  }

var tests =parseInt(readline());
for(var i=0 ; i<tests ; i++){
    var w  =readline();//abcde
    var c  =readline();//c
    if(c===w){
        print("YES")
    }
    else{
        var flg;
        for(var y=0 ; y<w.length ; y++){
            if(c === w[y] && y%2 === 0 ){
                flg = "YES";
                break;

            }
            else{
                flg="NO";
            }
        }
        print(flg)

    }

    }

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    let line=buf.split('\n');
    let t=parseInt(line[0]);
    for(let i=1;i<=2*t;i+=2)
    {
        let s=line[i];
        let c=line[i+1];
        s.length--;
        c.length--;
        let flag=false;
        if(s.length%2==1)
        {
            for(let j=0;j<s.length;j++)
            {
                if(s[j]===c)
                {
                    if(j%2==0)
                    {
                        flag=true;
                    }
                }
            }
        }
        if(flag) console.log("YES");
        else console.log("NO");
    }
})

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    let line=buf.split('\n');
    let t=parseInt(line[0]);
    for(let i=1;i<=2*t;i+=2)
    {
        let s=line[i];
        let c=line[i+1];
        let flag=false;
        if(s.length%2==1)
        {
            for(let j=0;j<s.length;j++)
            {
                if(s[j]===c)
                {
                    if(j%2==0)
                    {
                        flag=true;
                    }
                }
            }
        }
        if(flag) console.log("YES");
        else console.log("NO");
    }
})

/*
** Template
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

const isOdd = (x) => { return x & 1 }
const isEven = (x) => { return !(x & 1) }

const getMiddle = s => s.substr(s.length - 1 >>> 1, (~s.length & 1) + 1)

const findAllIndicesOfChar = (str, char) => {
    str = str.split('')
    let indices = [];
    for (let i = 0; i < str.length; i++) {
        if (str[i] === char) indices.push(i);
    }
    return indices
}

const getResult = ( str, target ) => {

    let len = str.length

    let validLen = []
    for(let i = 5; i <= len; i+= 4) validLen.push(i)

    if( len === 1 ) return str === target ? 'YES'  : 'NO'

    let begin   = str.charAt(0)
    let end     = str.charAt(str.length-1)
    let midchar = getMiddle(str)

    if( begin === target || end === target ) return 'YES'
    if( midchar === target ){
        return validLen.includes(len) ? 'YES' : 'NO'
    }

    let indices = findAllIndicesOfChar( str, target )

    for(let i = 0; i < indices.length; i++){
        if( isEven(indices[i]) ) {
            return 'YES'
        }
    }

    return 'NO'
}

function main() {
    let testcases = parseInt( readline() )
    while( testcases-- ){

        let str     = readline()
        let target  = readline()
        console.log( getResult( str, target ) )
    }
}
//*/

/*
** Template
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

const isOdd = (x) => { return x & 1 }
const isEven = (x) => { return !(x & 1) }

const getMiddle = s => s.substr(s.length - 1 >>> 1, (~s.length & 1) + 1)

const findAllIndicesOfChar = (str, char) => {
    str = str.split('')
    let indices = [];
    for (let i = 0; i < str.length; i++) {
        if (str[i] === char) indices.push(i);
    }
    return indices
}

const getResult = ( str, target ) => {

    let len = str.length

    if( len === 1 ) return str === target ? 'YES'  : 'NO'

    let begin   = str.charAt(0)
    let end     = str.charAt(str.length-1)
    let midchar = getMiddle(str)

    if( midchar === target || begin === target || end === target ) return 'YES'

    let indices = findAllIndicesOfChar( str, target )

    for(let i = 0; i < indices.length; i++){
        if( isEven(indices[i]) ) {
            return 'YES'
        }
    }

    return 'NO'
}

function main() {
    let testcases = parseInt( readline() )
    while( testcases-- ){

        let str     = readline()
        let target  = readline()
        console.log( getResult( str, target ) )
    }
}
//*/

/*
** Template
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

const getMiddle = s => s.substr(s.length - 1 >>> 1, (~s.length & 1) + 1)

const getResult = ( str, target ) => {

    let len = str.length

    if( len === 1 ) return 'NO'

    let midchar = getMiddle(str)

    return midchar === target ? 'YES' : 'NO'
}

function main() {
    let testcases = parseInt( readline() )
    while( testcases-- ){

        let str = readline()
        let target = readline()
        console.log( getResult( str, target ) )
    }
}
//*/

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
   var t = lines[0];
	for(i = 1; i <= t; i++) {
	    var a = lines[i];
        if(a < 20){
            console.log('YES');
            var ans = '';
            var b = 1;
            for(j = 0; j < a; j++){
                ans += b + ' ';
                b *= 3;
            }
            console.log(ans);
        }else{
            console.log('NO');
        }
	}
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = lines[2]
    var abc = ['a', 'b', 'c' ,'d', 'e', 'f' ,'g', 'h', 'i', 'j', 'k' ,'l', 'm','n', 'o', 'p','q', 'r', 's' ,'t' ,'u', 'v', 'w' ,'x', 'y', 'z']
   for(j = 1; j <= n * 2; j++){

       if(j % 2 == 1){
           e = lines[j + 1]
               var s = 0
var u = false
var r = false
           var a = lines[j].split('').map(String)
           for(k = 0 ; k < a.length; k++){
               if(a[k] != e){
                   s++
               }else {
                   s++
                   u = true
                   if(a[a.length - 1] == e){
                       r = true
                   }
                   break;
               }
           }
           if(s % 2 == 1 && u === true || r === true){
               console.log('YES')
           }else{
               console.log('NO')
           }
       }
   }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = lines[2]
    var s = 0
    var abc = ['a', 'b', 'c' ,'d', 'e', 'f' ,'g', 'h', 'i', 'j', 'k' ,'l', 'm','n', 'o', 'p','q', 'r', 's' ,'t' ,'u', 'v', 'w' ,'x', 'y', 'z']
   for(j = 1; j <= n * 2; j++){

       if(j % 2 == 1){
           e = lines[j + 1]
           var a = lines[j].split('').map(String)
           for(k = 0 ; k < a.length; k++){
               if(a[k] != e){
                   s++
               }else {
                   break;
               }
           }
           if(s % 2 == 1){
               console.log('YES')
           }else{
               console.log('NO')
           }
       }
   }
});

let data = '';
process.stdin.on('data', c => data += c);

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let s = nl.line().split('').map((e,i) => (i%2 == 0)?e:'').join('');
		let c = nl.line();
		ans.push(s.search(c) != -1);
		console.log(s);

	}
	console.log(ans.map(e => e?"YES":"NO").join('\n'));
};

process.stdin.on('end', sol);

let data = '';
process.stdin.on('data', c => data += c);

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let s = nl.line();
		let c = nl.line();
		let l = s.length;
		let ns = s.substring(0, 1) + (l>3?s.substring(2, l-2):"") + s.substring(l-1);
		ans.push(ns.search(c) != -1);

	}
	console.log(ans.map(e => e?"YES":"NO").join('\n'));
};

process.stdin.on('end', sol);

let data = '';
process.stdin.on('data', c => data += c);

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let s = nl.line();
		let c = nl.line();
		let l = s.length;
		let ns = s.substring(0, 1) + s.substring(2, l-2) + s.substring(l-1);
		ans.push(ns.search(c) != -1);

	}
	console.log(ans.map(e => e?"YES":"NO").join('\n'));
};

process.stdin.on('end', sol);

'use strict'; /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}

module.exports = E;

const ra = ()=>readline().split(' ').map(a=>+a)

const EPS = 1e-6;

const calc = (s, c)=>{
  if (s[0]==c)
    return true;
  if (s[s.length-1]==c)
    return true;
  return s.slice(2, s.length-2).includes(c)
};

function main() {
    let T = +readline()
    while (T--){
      let s = readline();
      let c = readline();
      print(calc(s, c) ? 'YES' : 'NO');
    }
}

E.calc = calc;


const create_multiset = () => {
  return {
    set: [],
    cardinality: 0,
    size: 0,
    add: function(value) {
      if (this.set[value])
        this.set[value]++;
      else {
        this.set[value] = 1;
        this.cardinality++;
      }
      this.size++;
    },
    delete: function(value) {
      if (this.set[value] > 1) {
        this.set[value]--;
        this.size--;
      } else if (this.set[value]) {
        this.set[value] = undefined;
        this.cardinality--;
        this.size--;
      }
    },
    has: function(value) {
      return (this.set[value] >= 1);
    },
    getCardinality: function() {
      return this.cardinality;
    },
    getSize: function() {
      return this.size;
    },
    getCountOf: function(value) {
      return this.set[value]? this.set[value]: 0
    },
    clear: function() {
      this.set = [];
      this.size = 0;
    }
  }
};

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(a => parseInt(a));
  var n = line1[0];
  var lefts = line1[1];
  var rights = line1[2];
  var l_socks = create_multiset();
  var r_socks = create_multiset();

  var colors = readline().split(' ').map(a => parseInt(a));
  colors.slice(0, lefts).forEach(item => l_socks.add(item));
  colors.slice(lefts, n)
    .forEach(item => {
      if (l_socks.has(item))
        l_socks.delete(item);
      else
        r_socks.add(item);
    });

  lefts = l_socks.getSize();
  rights = r_socks.getSize();

  if (lefts < rights) {
    var tt = lefts;
    lefts = rights;
    rights = tt;
    tt = l_socks;
    l_socks = r_socks;
    r_socks = tt;
  }

  var dollars_spent = 0;
  for (var color_index = 1; color_index <= n; color_index++){
    var d = lefts - rights;
    var lefts_this_color = l_socks.getCountOf(color_index);
    var ok_to_recolor = parseInt(lefts_this_color / 2);
    var min = Math.min(ok_to_recolor * 2, d);
    var recolor = parseInt(min / 2);
    dollars_spent += recolor;
    lefts -= recolor * 2;
  }

  dollars_spent += parseInt((lefts - rights) / 2);
  dollars_spent += parseInt((lefts + rights) / 2);

  print(dollars_spent);
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

const MX = 2e5 + 1;

function main () {
	let T = rn();
	while (T--) {
		let [n, l, r] = rna();
		let c = rna();

		let ar1 = Array(n+1).fill(0);
		let ar2 = Array(n+1).fill(0);
		for (let i = 0 ; i < n; i++) {
			if (i < l)
				ar1[c[i]]++;
			else
				ar2[c[i]]++;
		}

		if (r > l)
			[ar1, ar2] = [ar2, ar1];
		//console.log(ar1,ar2)

		let k  = Math.abs((l-r)/2);
		let ans = 0;
		//console.log('k', k);
		for (let i = 1; i <= n; i++) {
			ar1[i] = Math.max(0, ar1[i] - ar2[i]);

			const mvs = Math.min(k, Math.floor(ar1[i] / 2));

			k -= mvs;
			ar1[i] = ar1[i] - 2 * mvs;

			ans += ar1[i] + mvs;
			//console.log('mvs', mvs)
		}

		console.log(ans);
	}
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		let [n, l, r] = rna();
		let c = rna();

		let ar1 = Array(n + 1).fill(0);
		let ar2 = Array(n + 1).fill(0);
		for (let i = 0; i < n; i++) {
			if (i < l)
				ar1[c[i]]++;
			else
				ar2[c[i]]++;
		}

		if (r > l)
			[ar1, ar2] = [ar2, ar1];

		let k = Math.abs((l - r) / 2);
		let ans = 0;
		for (let i = 1; i <= n; i++) {
			ar1[i] = Math.max(0, ar1[i] - ar2[i]);

			const mvs = Math.min(k, Math.floor(ar1[i] / 2));
			k -= mvs;
			ar1[i] -= 2 * mvs;

			ans += ar1[i] + mvs;
		}

		console.log(ans);
	}
}

const create_multiset = () => {
  return {
    set: [],
    cardinality: 0,
    size: 0,
    add: function(value) {
      if (this.set[value])
        this.set[value]++;
      else {
        this.set[value] = 1;
        this.cardinality++;
      }
      this.size++;
    },
    delete: function(value) {
      if (this.set[value] > 1) {
        this.set[value]--;
        this.size--;
      } else if (this.set[value]) {
        this.set[value] = undefined;
        this.cardinality--;
        this.size--;
      }
    },
    has: function(value) {
      return (this.set[value] >= 1);
    },
    getCardinality: function() {
      return this.cardinality;
    },
    getSize: function() {
      return this.size;
    },
    getCountOf: function(value) {
      return this.set[value]? this.set[value]: 0
    },
    clear: function() {
      this.set = [];
      this.size = 0;
    }
  }
};

var global = 1;
const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(a => parseInt(a));
  var n = line1[0];
  var lefts = line1[1];
  var rights = line1[2];
  var l_socks = create_multiset();
  var r_socks = create_multiset();

  var colors_s = readline();
  var colors = colors_s.split(' ').map(a => parseInt(a));
  colors.slice(0, lefts).forEach(item => l_socks.add(item));
  colors.slice(lefts, n)
    .forEach(item => {
      if (l_socks.has(item))
        l_socks.delete(item);
      else
        r_socks.add(item);
    });

  lefts = l_socks.getSize();
  rights = r_socks.getSize();
  n = lefts + rights;

  if (lefts < rights) {
    var tt = lefts;
    lefts = rights;
    rights = tt;
    tt = l_socks;
    l_socks = r_socks;
    r_socks = tt;
  }

  var dollars_spent = 0;
  for (var color_index = 1; color_index <= n; color_index++){
    var d = lefts - rights;
    var lefts_this_color = l_socks.getCountOf(color_index);
    var ok_to_recolor = parseInt(lefts_this_color / 2);
    var min = Math.min(ok_to_recolor * 2, d);
    var recolor = parseInt(min / 2);
    dollars_spent += recolor;
    lefts -= recolor * 2;
  }

  dollars_spent += parseInt((lefts - rights) / 2);
  dollars_spent += parseInt((lefts + rights) / 2);

  print(global === 279? `${line1}  ${colors_s}`: dollars_spent);
  global++;
}

const create_multiset = () => {
  return {
    set: [],
    cardinality: 0,
    size: 0,
    add: function(value) {
      if (this.set[value])
        this.set[value]++;
      else {
        this.set[value] = 1;
        this.cardinality++;
      }
      this.size++;
    },
    delete: function(value) {
      if (this.set[value] > 1) {
        this.set[value]--;
        this.size--;
      } else if (this.set[value]) {
        this.set[value] = undefined;
        this.cardinality--;
        this.size--;
      }
    },
    has: function(value) {
      return (this.set[value] >= 1);
    },
    getCardinality: function() {
      return this.cardinality;
    },
    getSize: function() {
      return this.size;
    },
    getCountOf: function(value) {
      return this.set[value]? this.set[value]: 0
    },
    clear: function() {
      this.set = [];
      this.size = 0;
    }
  }
};

var global = 1;
const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(a => parseInt(a));
  var n = line1[0];
  var lefts = line1[1];
  var rights = line1[2];
  var l_socks = create_multiset();
  var r_socks = create_multiset();

  var colors_s = readline();
  var colors = colors_s.split(' ').map(a => parseInt(a));
  colors.slice(0, lefts).forEach(item => l_socks.add(item));
  colors.slice(lefts, n)
    .forEach(item => {
      if (l_socks.has(item))
        l_socks.delete(item);
      else
        r_socks.add(item);
    });

  lefts = l_socks.getSize();
  rights = r_socks.getSize();
  n = lefts + rights;

  if (lefts < rights) {
    var tt = lefts;
    lefts = rights;
    rights = tt;
    tt = l_socks;
    l_socks = r_socks;
    r_socks = tt;
  }

  var dollars_spent = 0;
  for (var color_index = 1; color_index <= n; color_index++){
    var d = lefts - rights;
    var lefts_this_color = l_socks.getCountOf(color_index);
    var ok_to_recolor = parseInt(lefts_this_color / 2);
    var min = Math.min(ok_to_recolor * 2, d);
    var recolor = parseInt(min / 2);
    dollars_spent += recolor;
    lefts -= recolor * 2;
  }

  dollars_spent += parseInt((lefts - rights) / 2);
  dollars_spent += parseInt((lefts + rights) / 2);

  print(global === 279? line1: dollars_spent);
  global++;
}

const create_multiset = () => {
  return {
    set: [],
    cardinality: 0,
    size: 0,
    add: function(value) {
      if (this.set[value])
        this.set[value]++;
      else {
        this.set[value] = 1;
        this.cardinality++;
      }
      this.size++;
    },
    delete: function(value) {
      if (this.set[value] > 1) {
        this.set[value]--;
        this.size--;
      } else if (this.set[value]) {
        this.set[value] = undefined;
        this.cardinality--;
        this.size--;
      }
    },
    has: function(value) {
      return (this.set[value] >= 1);
    },
    getCardinality: function() {
      return this.cardinality;
    },
    getSize: function() {
      return this.size;
    },
    getCountOf: function(value) {
      return this.set[value]? this.set[value]: 0
    },
    clear: function() {
      this.set = [];
      this.size = 0;
    }
  }
};

var global = 1;
const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(a => parseInt(a));
  var n = line1[0];
  var lefts = line1[1];
  var rights = line1[2];
  var l_socks = create_multiset();
  var r_socks = create_multiset();

  var colors_s = readline();
  var colors = colors_s.split(' ').map(a => parseInt(a));
  colors.slice(0, lefts).forEach(item => l_socks.add(item));
  colors.slice(lefts, n)
    .forEach(item => {
      if (l_socks.has(item))
        l_socks.delete(item);
      else
        r_socks.add(item);
    });

  lefts = l_socks.getSize();
  rights = r_socks.getSize();
  n = lefts + rights;

  if (lefts < rights) {
    var tt = lefts;
    lefts = rights;
    rights = tt;
    tt = l_socks;
    l_socks = r_socks;
    r_socks = tt;
  }

  var dollars_spent = 0;
  for (var color_index = 1; color_index <= n; color_index++){
    var d = lefts - rights;
    var lefts_this_color = l_socks.getCountOf(color_index);
    var ok_to_recolor = parseInt(lefts_this_color / 2);
    var min = Math.min(ok_to_recolor * 2, d);
    var recolor = parseInt(min / 2);
    dollars_spent += recolor;
    lefts -= recolor * 2;
  }

  dollars_spent += parseInt((lefts - rights) / 2);
  dollars_spent += parseInt((lefts + rights) / 2);

  print(global === 279? line1 + colors_s: dollars_spent);
  global++;
}

const create_multiset = () => {
  return {
    set: [],
    cardinality: 0,
    size: 0,
    add: function(value) {
      if (this.set[value])
        this.set[value]++;
      else {
        this.set[value] = 1;
        this.cardinality++;
      }
      this.size++;
    },
    delete: function(value) {
      if (this.set[value] > 1) {
        this.set[value]--;
        this.size--;
      } else if (this.set[value]) {
        this.set[value] = undefined;
        this.cardinality--;
        this.size--;
      }
    },
    has: function(value) {
      return (this.set[value] >= 1);
    },
    getCardinality: function() {
      return this.cardinality;
    },
    getSize: function() {
      return this.size;
    },
    getCountOf: function(value) {
      return this.set[value]? this.set[value]: 0
    },
    clear: function() {
      this.set = [];
      this.size = 0;
    }
  }
};

var global = 1;
const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(a => parseInt(a));
  var n = line1[0];
  var lefts = line1[1];
  var rights = line1[2];
  var l_socks = create_multiset();
  var r_socks = create_multiset();

  var colors = readline().split(' ').map(a => parseInt(a));
  colors.slice(0, lefts).forEach(item => l_socks.add(item));
  colors.slice(lefts, n)
    .forEach(item => {
      if (l_socks.has(item))
        l_socks.delete(item);
      else
        r_socks.add(item);
    });

  lefts = l_socks.getSize();
  rights = r_socks.getSize();
  n = lefts + rights;

  if (lefts < rights) {
    var tt = lefts;
    lefts = rights;
    rights = tt;
    tt = l_socks;
    l_socks = r_socks;
    r_socks = tt;
  }

  var dollars_spent = 0;
  for (var color_index = 1; color_index <= n; color_index++){
    var d = lefts - rights;
    var lefts_this_color = l_socks.getCountOf(color_index);
    var ok_to_recolor = parseInt(lefts_this_color / 2);
    var min = Math.min(ok_to_recolor * 2, d);
    var recolor = parseInt(min / 2);
    dollars_spent += recolor;
    lefts -= recolor * 2;
  }

  dollars_spent += parseInt((lefts - rights) / 2);
  dollars_spent += parseInt((lefts + rights) / 2);

  print(global === 279? '12312313': dollars_spent);
  global++;
}

const create_multiset = () => {
  return {
    set: [],
    cardinality: 0,
    size: 0,
    add: function(value) {
      if (this.set[value])
        this.set[value]++;
      else {
        this.set[value] = 1;
        this.cardinality++;
      }
      this.size++;
    },
    delete: function(value) {
      if (this.set[value] >= 1)
        this.size--;
      if (this.set[value] > 1)
        this.set[value]--;
      else if (this.set[value]) {
        this.set[value] = undefined;
        this.cardinality--;
      }
    },
    has: function(value) {
      return (this.set[value] >= 1);
    },
    getCardinality: function() {
      return this.cardinality;
    },
    getSize: function() {
      return this.size;
    },
    getCountOf: function(value) {
      return this.set[value]? this.set[value]: 0
    },
    clear: function() {
      this.set = [];
      this.size = 0;
    }
  }
};

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(a => parseInt(a));
  var n = line1[0];
  var lefts = line1[1];
  var rights = line1[2];
  var l_socks = create_multiset();
  var r_socks = create_multiset();

  var colors = readline().split(' ').map(a => parseInt(a));
  colors.slice(0, lefts).forEach(item => l_socks.add(item));
  colors.slice(lefts, n)
    .forEach(item => {
      if (l_socks.has(item))
        l_socks.delete(item);
      else
        r_socks.add(item);
    });

  lefts = l_socks.getSize();
  rights = r_socks.getSize();
  n = lefts + rights;

  if (lefts < rights) {
    var tt = lefts;
    lefts = rights;
    rights = tt;
    tt = l_socks;
    l_socks = r_socks;
    r_socks = tt;
  }

  var dollars_spent = 0;
  for (var color_index = 1; color_index <= n; color_index++){
    var d = lefts - rights;
    var lefts_this_color = l_socks.getCountOf(color_index);
    var ok_to_recolor = parseInt(lefts_this_color / 2);
    var min = Math.min(ok_to_recolor * 2, d);
    var recolor = parseInt(min / 2);
    dollars_spent += recolor;
    lefts -= recolor * 2;
  }

  dollars_spent += parseInt((lefts - rights) / 2);
  dollars_spent += parseInt((lefts + rights) / 2);

  print(dollars_spent);
}

const create_multiset = () => {
  return {
    set: [],
    cardinality: 0,
    size: 0,
    add: function(value) {
      if (this.set[value])
        this.set[value]++;
      else {
        this.set[value] = 1;
        this.cardinality++;
      }
      this.size++;
    },
    delete: function(value) {
      if (this.set[value] > 1) {
        this.set[value]--;
        this.size--;
      } else if (this.set[value]) {
        this.set[value] = undefined;
        this.cardinality--;
        this.size--;
      }
    },
    has: function(value) {
      return (this.set[value] && this.set[value] >= 1);
    },
    getCardinality: function() {
      return this.cardinality;
    },
    getSize: function() {
      return this.size;
    },
    getCountOf: function(value) {
      return this.set[value]? this.set[value]: 0
    },
    clear: function() {
      this.set = [];
      this.size = 0;
    }
  }
};

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(a => parseInt(a));
  var n = line1[0];
  var lefts = line1[1];
  var rights = line1[2];
  var l_socks = create_multiset();
  var r_socks = create_multiset();

  var colors = readline().split(' ').map(a => parseInt(a));
  colors.slice(0, lefts).forEach(item => l_socks.add(item));
  colors.slice(lefts, n)
    .forEach(item => {
      if (l_socks.has(item))
        l_socks.delete(item);
      else
        r_socks.add(item);
    });

  lefts = l_socks.getSize();
  rights = r_socks.getSize();
  n = lefts + rights;

  if (lefts < rights) {
    var tt = lefts;
    lefts = rights;
    rights = tt;
    tt = l_socks;
    l_socks = r_socks;
    r_socks = tt;
  }

  var dollars_spent = 0;
  for (var color_index = 1; color_index <= n; color_index++){
    var d = lefts - rights;
    var lefts_this_color = l_socks.getCountOf(color_index);
    var ok_to_recolor = parseInt(lefts_this_color / 2);
    var min = Math.min(ok_to_recolor * 2, d);
    var recolor = parseInt(min / 2);
    dollars_spent += recolor;
    lefts -= recolor * 2;
  }

  dollars_spent += parseInt((lefts - rights) / 2);
  dollars_spent += parseInt((lefts + rights) / 2);

  print(dollars_spent);
}

const create_multiset = () => {
  return {
    set: [],
    cardinality: 0,
    size: 0,
    add: function(value) {
      if (this.set[value])
        this.set[value]++;
      else {
        this.set[value] = 1;
        this.cardinality++;
      }
      this.size++;
    },
    delete: function(value) {
      if (this.set[value] > 1) {
        this.set[value]--;
        this.size--;
      } else if (this.set[value]) {
        this.set[value] = undefined;
        this.cardinality--;
        this.size--;
      }
    },
    has: function(value) {
      return (this.set[value] >= 1);
    },
    getCardinality: function() {
      return this.cardinality;
    },
    getSize: function() {
      return this.size;
    },
    getCountOf: function(value) {
      return this.set[value]? this.set[value]: 0
    },
    clear: function() {
      this.set = [];
      this.size = 0;
    }
  }
};

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(a => parseInt(a));
  var n = line1[0];
  var lefts = line1[1];
  var rights = line1[2];
  var l_socks = create_multiset();
  var r_socks = create_multiset();

  var colors = readline().split(' ').map(a => parseInt(a));
  colors.slice(0, lefts).forEach(item => l_socks.add(item));
  colors.slice(lefts, n)
    .forEach(item => {
      if (l_socks.has(item))
        l_socks.delete(item);
      else
        r_socks.add(item);
    });

  lefts = l_socks.getSize();
  rights = r_socks.getSize();
  n = lefts + rights;

  if (lefts < rights) {
    var tt = lefts;
    lefts = rights;
    rights = tt;
    tt = l_socks;
    l_socks = r_socks;
    r_socks = tt;
  }

  var dollars_spent = 0;
  for (var color_index = 1; color_index <= n; color_index++){
    var d = lefts - rights;
    var lefts_this_color = l_socks.getCountOf(color_index);
    var ok_to_recolor = parseInt(lefts_this_color / 2);
    var min = Math.min(ok_to_recolor * 2, d);
    var recolor = parseInt(min / 2);
    dollars_spent += recolor;
    lefts -= min;
  }

  dollars_spent += parseInt((lefts - rights) / 2);
  dollars_spent += parseInt((lefts + rights) / 2);

  print(dollars_spent);
}

const create_multiset = () => {
  return {
    set: [],
    cardinality: 0,
    size: 0,
    add: function(value) {
      if (this.set[value])
        this.set[value]++;
      else {
        this.set[value] = 1;
        this.cardinality++;
      }
      this.size++;
    },
    delete: function(value) {
      if (this.set[value] > 1) {
        this.set[value]--;
        this.size--;
      } else if (this.set[value]) {
        this.set[value] = undefined;
        this.cardinality--;
        this.size--;
      }
    },
    has: function(value) {
      return (this.set[value] >= 1);
    },
    getCardinality: function() {
      return this.cardinality;
    },
    getSize: function() {
      return this.size;
    },
    getCountOf: function(value) {
      return this.set[value]? this.set[value]: 0
    },
    clear: function() {
      this.set = [];
      this.size = 0;
    }
  }
};

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(a => parseInt(a));
  var n = line1[0];
  var lefts = line1[1];
  var rights = line1[2];
  var l_socks = create_multiset();
  var r_socks = create_multiset();

  var colors = readline().split(' ').map(a => parseInt(a));
  colors.slice(0, lefts).forEach(item => l_socks.add(item));
  colors.slice(lefts, n)
    .forEach(item => {
      if (l_socks.has(item))
        l_socks.delete(item);
      else
        r_socks.add(item);
    });

  lefts = l_socks.getSize();
  rights = r_socks.getSize();
  n = lefts + rights;

  if (lefts < rights) {
    var tt = lefts;
    lefts = rights;
    rights = tt;
    tt = l_socks;
    l_socks = r_socks;
    r_socks = tt;
  }

  var dollars_spent = 0;
  for (var color_index = 1; color_index <= n; color_index++) {
    var d = lefts - rights;
    var lefts_this_color = l_socks.getCountOf(color_index);
    var ok_to_recolor = parseInt(lefts_this_color / 2);
    var min = Math.min(ok_to_recolor * 2, d);
    dollars_spent += parseInt(min / 2);
    lefts -= min;
  }

  dollars_spent += parseInt((lefts - rights) / 2);
  dollars_spent += parseInt((lefts + rights) / 2);

  print(dollars_spent);
}

const create_multiset = () => {
  return {
    set: [],
    cardinality: 0,
    size: 0,
    add: function(value) {
      if (this.set[value])
        this.set[value]++;
      else {
        this.set[value] = 1;
        this.cardinality++;
      }
      this.size++;
    },
    delete: function(value) {
      if (this.set[value] > 1) {
        this.set[value]--;
        this.size--;
      } else if (this.set[value]) {
        this.set[value] = undefined;
        this.cardinality--;
        this.size--;
      }
    },
    has: function(value) {
      return (this.set[value] >= 1);
    },
    getCardinality: function() {
      return this.cardinality;
    },
    getSize: function() {
      return this.size;
    },
    getCountOf: function(value) {
      return this.set[value]? this.set[value]: 0
    },
    clear: function() {
      this.set = [];
      this.size = 0;
    }
  }
};

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(a => parseInt(a));
  var n = line1[0];
  var lefts = line1[1];
  var rights = line1[2];
  var l_socks = create_multiset();
  var r_socks = create_multiset();

  var colors = readline().split(' ').map(a => parseInt(a));
  colors.slice(0, lefts).forEach(item => l_socks.add(item));
  colors.slice(lefts, n)
    .forEach(item => {
      if (l_socks.has(item))
        l_socks.delete(item);
      else
        r_socks.add(item);
    });

  lefts = l_socks.getSize();
  rights = r_socks.getSize();
  n = lefts + rights;

  if (lefts < rights) {
    var tt = lefts;
    lefts = rights;
    rights = tt;
    tt = l_socks;
    l_socks = r_socks;
    r_socks = tt;
  }

  var dollars_spent = 0;
  for (var color_index = 1; color_index <= n; color_index++){
    var d = lefts - rights;
    var lefts_this_color = l_socks.getCountOf(color_index);
    var ok_to_recolor = parseInt(lefts_this_color / 2);
    var min = Math.min(ok_to_recolor * 2, d);
    var recolor = parseInt(min / 2);
    dollars_spent += recolor;
    lefts -= recolor * 2;
  }

  dollars_spent += parseInt((lefts - rights) / 2);
  dollars_spent += parseInt((lefts + rights) / 2);

  print(dollars_spent);
}

const create_multiset = () => {
  return {
    set: [],
    cardinality: 0,
    size: 0,
    add: function(value) {
      if (this.set[value])
        this.set[value]++;
      else {
        this.set[value] = 1;
        this.cardinality++;
      }
      this.size++;
    },
    delete: function(value) {
      if (this.set[value] > 1) {
        this.set[value]--;
        this.size--;
      } else if (this.set[value]) {
        this.set[value] = undefined;
        this.cardinality--;
        this.size--;
      }
    },
    has: function(value) {
      return (this.set[value] >= 1);
    },
    getCardinality: function() {
      return this.cardinality;
    },
    getSize: function() {
      return this.size;
    },
    getCountOf: function(value) {
      return this.set[value]? this.set[value]: 0
    },
    clear: function() {
      this.set = [];
      this.size = 0;
    }
  }
};

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(a => parseInt(a));
  var n = line1[0];
  var lefts = line1[1];
  var rights = line1[2];
  var l_socks = create_multiset();
  var r_socks = create_multiset();

  var colors = readline().split(' ').map(a => parseInt(a));
  colors.slice(0, lefts).forEach(item => l_socks.add(item));
  colors.slice(lefts, n)
    .forEach(item => {
      if (l_socks.has(item))
        l_socks.delete(item);
      else
        r_socks.add(item);
    });

  lefts = l_socks.getSize();
  rights = r_socks.getSize();
  n = lefts + rights;

  if (lefts < rights) {
    var tt = lefts;
    lefts = rights;
    rights = tt;
    tt = l_socks;
    l_socks = r_socks;
    r_socks = tt;
  }

  var dollars_spent = 0;
  var last_recolor_dif = 0;
  for (var color_index = 1; color_index <= n; color_index++){
    var d = lefts - rights - last_recolor_dif;
    var lefts_this_color = l_socks.getCountOf(color_index);
    var ok_to_recolor = parseInt(lefts_this_color / 2);
    var min = Math.min(ok_to_recolor * 2, d);
    var recolor = parseInt(min / 2);
    dollars_spent += recolor;
    lefts -= recolor;
    last_recolor_dif = recolor;
  }

  dollars_spent += parseInt((lefts - rights) / 2);
  dollars_spent += parseInt((lefts + rights) / 2);

  print(dollars_spent);
}

const create_multiset = () => {
  return {
    set: [],
    cardinality: 0,
    size: 0,
    add: function(value) {
      if (this.set[value])
        this.set[value]++;
      else {
        this.set[value] = 1;
        this.cardinality++;
      }
      this.size++;
    },
    delete: function(value) {
      if (this.set[value] > 1) {
        this.set[value]--;
        this.size--;
      } else if (this.set[value]) {
        this.set[value] = undefined;
        this.cardinality--;
        this.size--;
      }
    },
    has: function(value) {
      return (this.set[value] >= 1);
    },
    getCardinality: function() {
      return this.cardinality;
    },
    getSize: function() {
      return this.size;
    },
    getCountOf: function(value) {
      return this.set[value]? this.set[value]: 0
    },
    clear: function() {
      this.set = [];
      this.size = 0;
    }
  }
};

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var line1 = readline().split(' ').map(a => parseInt(a));
  var n = line1[0];
  var lefts = line1[1];
  var rights = line1[2];
  var l_socks = create_multiset();
  var r_socks = create_multiset();

  var colors = readline().split(' ').map(a => parseInt(a));
  colors.slice(0, lefts).forEach(item => l_socks.add(item));
  colors.slice(lefts, n)
    .forEach(item => {
      if (l_socks.has(item))
        l_socks.delete(item);
      else
        r_socks.add(item);
    });

  lefts = l_socks.getSize();
  rights = r_socks.getSize();
  n = lefts + rights;

  if (lefts < rights) {
    var tt = lefts;
    lefts = rights;
    rights = tt;
    tt = l_socks;
    l_socks = r_socks;
    r_socks = tt;
  }

  var dollars_spent = 0;

  for (var color_index = 1; color_index <= n; color_index++){
    var d = lefts - rights;
    var lefts_this_color = l_socks.getCountOf(color_index);
    var ok_to_recolor = parseInt(lefts_this_color / 2);
    var min = Math.min(ok_to_recolor * 2, d);
    var recolor = parseInt(min / 2);
    dollars_spent += recolor;
    lefts -= recolor;
  }

  dollars_spent += parseInt((lefts - rights) / 2);
  dollars_spent += parseInt((lefts + rights) / 2);

  print(dollars_spent);
}


(function () {
    var read = {
        number: function () {
            return +readline();
        },
        arr: function (divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function (divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    }

    var n = read.number();
    var arr = [];
    var count = 0;
    for(var i = 0; i < n; i++) {
        arr[i] = read.arr('');
        arr[i].forEach(item => {
            if(item === '.') {
                count++;
            }
        });
    }

    if(count % 5 !== 0) {
        print('NO');
        return;
    }

    for(var i = 1; i < n - 1; i++) {
        for(var j = 1; j < n - 1; j++) {
            if(arr[i][j] === '.' && arr[i][j-1] === '.' && arr[i][j+1] === '.' && arr[i - 1][j] === '.' && arr[i+1][j] === '.') {
                arr[i][j] = '#';
                arr[i][j - 1] = '#';
                arr[i][j + 1] = '#';
                arr[i - 1][j] = '#';
                arr[i + 1][j] = '#';
            }
        }
    }

    var count = 0;
    for(var i = 0; i < n; i++) {
        arr[i].forEach(item => {
            if(item === '.') {
                count++;
            }
        });
    }
    if(count) {
        print('NO');
    }
    else {
        print('YES');
    }
}());

var n = parseInt(readline());
var board = new Array(n).fill('');
for(var i=0;i<n;i++) {
    board[i] = readline().split('').map(c=> (c==='#' ? false:true))
}
var countToFill = 0;
board.forEach((b, i) => {
    board[i].forEach((cell, j) => {
        countToFill+= cell? 1:0;
    })
});

var canFit = (x, y) => (
    x-1 >= 0 &&
    y-1>=0 &&
    x+1<board.length &&
    y+1<board[x].length &&
    board[x][y] &&
    board[x+1][y] &&
    board[x-1][y] &&
    board[x][y+1] &&
    board[x][y-1]
);
var canAnyFit = (x, y) => (
    canFit(x, y) ||
    canFit(x+1, y) ||
    canFit(x-1, y) ||
    canFit(x, y-1) ||
    canFit(x, y+1)
);

var res = (countToFill===0) || (countToFill%5 === 0);
// board.forEach((b, i) => ( board[i].forEach((c, j) => {
//     if (board[i][j]) {
//         res = res && canAnyFit(i,j)
//     }
// } )));
// print(res ? 'YES':'NO')

var fill = (x, y, c) => (
    board[x][y] =
    board[x+1][y] =
    board[x-1][y] =
    board[x][y+1] =
    board[x][y-1] = c //#
);
var fit = (x, y) => (fill(x, y, false)) //#
var unfit = (x, y) => (fill(x, y, true)) //.

// var q = [{
//     pos: 0,
//     count: countToFill
// }];
// while(q.length>0) {
//     var cur = q.shift();
//     var x = Math.floor(cur.pos/board.length);
//     var y = cur.pos%board.length;

//     print('pos', cur.pos)

//     var count = cur.count;
//     if (count === 0) {
//         print('YES')
//         break;
//     }
//     if (canFit(x, y-1)) {
//         fit(x, y-1);
//         count-=5;
//     } else if (canFit(x-1, y)) {
//         fit(x-1, y);
//         count-=5;
//     } else if (canFit(x, y)) {
//         fit(x, y);
//         count-=5;
//     } else if (canFit(x+1, y)) {
//         fit(x+1, y);
//         count-=5;
//     } else if (canFit(x, y+1)) {
//         fit(x, y+1);
//         count-=5;
//     }
//     q.push({
//         pos: cur.pos+1,
//         count: count
//     })
// }

var vis = {}, memo = {};
function sol(pos, count) {

    var x = Math.floor(pos/board.length);
    var y = pos%board.length;
    var v = x*board.length*board.length + y*board.length + count;
    if (count === 0) {
        //print('YES');
        return memo[v]=true;
    }
    if (pos>board.length*board.length) {

        return memo[v] = false;
    }

    //if (vis[v]) return false;
    vis[v] = true;

    if (canFit(x, y)) {

//        print('fitting in ', x, y);

        fit(x, y);
        if(sol(pos+1, count-5)) {
            return memo[v]=true;
        }
        unfit(x, y);
    } else if(sol(pos+1, count)) {
        return memo[v]=true;
    }
    return memo[v]=false;
}

if (!res) {
    print('NO')
} else {
    print(sol(0,countToFill) ? 'YES':'NO')
}

var lines = parseInt(readline());

var matrix = []
for (var i = 0; i < lines; i++){
  matrix.push(readline().split(''));
}

// var matrix = [
// ['#', '#', '.', '#'],
// ['#', '.', '.', '.'],
// ['#', '#', '.', '#'],
// ['#', '#', '#', '#']]

function isFull() {
  for (var i = 0; i < matrix.length; i++) {
    for (var j = 0; j < matrix.length; j++) {
      if (matrix[i][j] === '.')
        return false;
    }
  }
  return true;
}

function checkInsertion(row, col) {
  return (
    matrix[row][col] === '.' &&
    matrix[row+1][col] === '.' &&
    matrix[row][col+1] === '.' &&
    matrix[row][col-1] === '.' &&
    matrix[row-1][col] === '.'
  );
}

function insert(row, col) {
  matrix[row][col] = '#';
  matrix[row+1][col] = '#';
  matrix[row][col+1] = '#';
  matrix[row][col-1] = '#';
  matrix[row-1][col] = '#';
}

function foo() {
  for (var row = 1; row < matrix.length - 1; row++) {
    for (var col = 1; col < matrix.length - 1; col++) {
      if (checkInsertion(row, col)) {
        insert(row, col);
        if (isFull())
          return write('YES')
      }
    }
  }

  write('NO')
}

foo();


var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	const n = rn();
	const p = [];
	for (let i = 0; i < n; i++) {
		p[i] = rna();
	}

	p.sort((x, y) => x[1] - y[1]);

	let total = 0;
	for (const [a, b] of p) {
		total += a;
	}

	const regbuy = items => buy(items, 2);
	const disbuy = items => buy(items, 1);
	const buy = (items, price) => {
		bought += items;
		rem -= items;
		spent += items * price;
	}

	let bought = 0, rem = total, spent = 0, i = 0;
	while (rem) {
		let [cur, fordisc] = p[i++];
		fordisc = Math.max(0, fordisc - bought);

		if (fordisc == 0) {
			disbuy(Math.min(rem, cur));
		} else {
			regbuy(Math.min(rem, fordisc));
			disbuy(Math.min(rem, cur));
		}
	}

	const ans = spent;
	console.log(ans);
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	const n = rn();
	const p = [];
	for (let i = 0; i < n; i++) {
		p[i] = rna();
	}

	p.sort((x, y) => x[1] - y[1]);

	let total = 0;
	for (const [a, b] of p) {
		total += a;
	}

	const regbuy = items => buy(items, 2);
	const disbuy = items => buy(items, 1);
	const buy = (items, price) => {
		bought += items;
		rem -= items;
		spent += items * price;
	}

	let bought = 0, rem = total, spent = 0, i = 0;
	while (rem) {
		let [must, should] = p[i++];
		should = Math.max(0, should - bought);
		if (should) {
			regbuy(Math.min(rem, should));
		}
		disbuy(Math.min(rem, must));
	}

	const ans = spent;
	console.log(ans);
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	const n = rn();
	const p = [];
	for (let i = 0; i < n; i++) {
		p[i] = rna();
	}

	p.sort((x, y) => x[1] - y[1]);

	let total = 0;
	for (let i = 0; i < n; i++) {
		total += p[i][0];
	}

	let bought = 0, rem = total;
	let spent = 0;
	let i = 0;
	while (rem) {
		//console.log(p[i], {rem, bought, spent})
		const [need, minr] = p[i++];
		const reqfrd = Math.max(minr - bought, 0);

		if (reqfrd == 0) {
			const discbuy = Math.min(rem, need);
			buy(discbuy, 1);
		} else {
			const regbuy = Math.min(rem, reqfrd);
			buy(regbuy, 2);

			const discbuy = Math.min(rem, need);
			buy(discbuy, 1);
			//console.log({i, regbuy, discbuy})
		}
	}

	function buy (items, price) {
		bought += items;
		rem -= items;
		spent += items * price;
	}

	const ans = spent;
	console.log(ans);
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var l = 0;
    var n = +lines[l++];
    var arr = lines.slice(l, l + n).map(str => str.split(' ').map(Number));
    console.log(solve(n, arr))
});

function solve(n, arr) {
    arr.sort((a, b) => a[1] - b[1])

    let i = 0
    let j = arr.length - 1
    let all = 0
    let pay = 0
    while (i <= j) {
        const [total, limit] = arr[i]
        while (all < limit && j > i) {
            const able = arr[j][0]
            let cost
            if (all + able < limit) {
                cost = able
                arr[j][0] -= cost
                j--
            } else {
                cost = limit - all
                arr[j][0] -= cost
            }
            all += cost
            pay += 2 * cost
        }
// console.log(arr, pay, all)
        if (all < limit) {
            const f = Math.min(total, limit - all)
            pay += f * 2
            all += f
            arr[i][0] -= f
            break
        } else {
            pay += total
            all += total
            arr[i][0] = 0
            i++
        }
    }
    if (i >= n) return pay
    // i == j
    if (all >= arr[i][1]) {
        pay += arr[i][0]
    } else {
        pay += 2 * arr[i][0]
    }
    return pay
}

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
// import * as readline from 'readline'
// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
// const ask = (query: string) => new Promise<string>((resolve) => rl.question(query, resolve))
// // Don't forget `rl.close()`.
const INT = Math.floor;
Array.prototype.last = function () {
    return this.length === 0 ? undefined : this[this.length - 1];
};
Array.prototype.isEmpty = function () {
    return this.length === 0;
};
const less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);
const greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);
const bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));
const bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));
const bigIntAbs = (arg) => (arg < 0 ? -arg : arg);
function read_stdin() {
    return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');
}
class Input {
    constructor(str) {
        this.index = 0;
        this.inputs = (str ? str : read_stdin()).split(/\s+/);
    }
    number() {
        return Number(this.inputs[this.index++]);
    }
    numbers(n) {
        return this.inputs.slice(this.index, (this.index += n)).map(Number);
    }
    bigint() {
        return BigInt(this.inputs[this.index++]);
    }
    bigints(n) {
        return this.inputs.slice(this.index, (this.index += n)).map(BigInt);
    }
    word() {
        return this.inputs[this.index++];
    }
    words(n) {
        return this.inputs.slice(this.index, (this.index += n));
    }
}
function array(len, init) {
    return Array(len).fill(init);
}
function array2(h, w, init) {
    return array(h, 0).map(() => array(w, init));
}
function main() {
    const input = new Input();
    const N = input.number();
    const products = Array(N);
    for (let i = 0; i < N; i++) {
        const a = input.number();
        const b = input.number();
        products[i] = { a, b };
    }
    products.sort((x, y) => x.b - y.b);
    let head = 0;
    let tail = N - 1;
    let sum = 0;
    let count = 0;
    while (head <= tail) {
        // console.log({ head, tail })
        const p_head = products[head];
        let c = p_head.b - count;
        // console.log({ p_head, count, c })
        if (c > 0) {
            while (head <= tail) {
                // console.log({ head, tail, c })
                const p_tail = products[tail];
                if (p_tail.a > c) {
                    p_tail.a -= c;
                    count += c;
                    sum += 2 * c;
                    break;
                }
                else if (p_tail.a === c) {
                    p_tail.a -= c;
                    count += c;
                    sum += 2 * c;
                    tail--;
                    break;
                }
                else {
                    c -= p_tail.a;
                    count += p_tail.a;
                    sum += 2 * p_tail.a;
                    p_tail.a = 0;
                    tail--;
                }
            }
        }
        // console.log({ p_head })
        if (p_head.a > 0) {
            if (p_head.b <= count) {
                sum += p_head.a;
            }
            else {
                sum += 2 * p_head.a;
            }
            count += p_head.a;
        }
        head++;
    }
    console.log(sum);
}
main();
//# sourceMappingURL=aoj.js.map

function gcd(x, y) {
   if (y === 0) {
      return x;
   }
   return gcd(y, x % y);
}

function div(a, b) {
   return Math.floor(a / b);
}

function solve() {
   var n = Number(read());
   var arr = [];
   for (var i = 0; i < n; i++) {
      arr.push(readArray(BigInt));
   }
   arr.sort((a, b) => {
      if (a[1] > b[1]) {
         return 1;
      }
      if (a[1] < b[1]) {
         return -1;
      }
      return 0;
   });
   var counter = 0n;
   var ans = 0n;
   var l = 0;
   var r = n - 1;
   while (l <= r) {
      var la = arr[l][0];
      var lb = arr[l][1];
      var ra = arr[r][0];

      if (counter >= lb) {
         ans += la;
         counter += la;
         arr[l][0] = 0n;
         l++;
         continue;
      }

      var needForSale = lb - counter;
      if (needForSale >= ra) {
         ans += 2n * ra;
         counter += ra;
         arr[r][0] = 0n;
         r--;
         continue;
      }

      counter += needForSale;
      ans += 2n * needForSale;
      arr[r][0] -= needForSale;
   }
   write(ans);
   /*
   for (var i = 0; i < n; i++) {
      var a = arr[i][0];
      var b = arr[i][1];
      if (counter >= b) {
         counter += a;
         ans += a;
         continue;
      }
      var nextCounter = counter + a;
      if (nextCounter < b) {
         counter = nextCounter;
         ans += a * 2n;
         continue;
      }
      // counter < b <= nextCounter
      ans += (b - counter - 1n) * 2n + (nextCounter - b + 1n);
      counter = nextCounter;
   }
   write(ans);
   */
}

function init() {
   var T;
   T = 1;
   //T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

const lib = require('readline');
const rl = lib.createInterface({
    input: process.stdin,
    output: process.stdout
});

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => ((await getLineGen.next()).value);
})();

let solve = async () => {
    n = parseInt((await getLine()));
    const t = new Array(n);
    for(let i = 0; i < n; i++) {
        let ai, bi;
        [ai, bi] = (await getLine()).split(' ').map(num => BigInt(num));
        t[i] = {
            a: ai,
            b: bi
        };
    }
    let cmpt = (a,b) => {
       let diff = a.b - b.b;
       let zeroBig = BigInt(0);
       if (diff < zeroBig)
           return -1;
       else if (diff > zeroBig)
           return 1;
       else
           return 0;
    }
    t.sort(cmpt);
    let bought = BigInt(0);
    let sum = BigInt(0);
    let last = t.length - 1;
    let first = 0
    while (first <= last) {
        if (t[first].b > bought) {
            while (first <= last) {
               if (t[last].a + bought <= t[first].b){
                  sum += BigInt(2) * t[last].a;
                  bought += t[last].a;
                  last--;
               }
               else {
                   t[last].a -= (t[first].b - bought);
                   sum += t[first].a + BigInt(2) * (t[first].b - bought);
                   bought += t[first].b - bought + t[first].a;
                   first++;
                   break;
               }
            }
        }
        else {
            bought += t[first].a;
            sum += t[first].a;
            first++;
        }
    }
    console.log(sum.toString());
}

solve();

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var l = 0;
    var n = +lines[l++];
    var arr = lines.slice(l, l + n).map(str => str.split(' ').map(Number));
    console.log(solve(n, arr))
});

function solve(n, arr) {
    arr.sort((a, b) => a[1] - b[1])

    let i = 0
    let j = arr.length - 1
    let all = 0
    let pay = 0
    while (i < j) {
        const [total, limit] = arr[i]
        while (all < limit && j > i) {
            const able = arr[j][0]
            let cost
            if (all + able < limit) {
                cost = able
                arr[j][0] -= cost
                j--
            } else {
                cost = limit - all
                arr[j][0] -= cost
            }
            all += cost
            pay += 2 * cost
        }
// console.log(arr, pay, all)
        if (all < limit) {
            const f = Math.min(total, limit - all)
            pay += f * 2
            all += f
            arr[i][0] -= f
            break
        } else {
            pay += total
            all += total
            arr[i][0] = 0
            i++
        }
    }
    // i == j
    if (all >= arr[i][1]) {
        pay += arr[i][0]
    } else {
        pay += 2 * arr[i][0]
    }
    return pay
}

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
// import * as readline from 'readline'
// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
// const ask = (query: string) => new Promise<string>((resolve) => rl.question(query, resolve))
// // Don't forget `rl.close()`.
const INT = Math.floor;
Array.prototype.last = function () {
    return this.length === 0 ? undefined : this[this.length - 1];
};
Array.prototype.isEmpty = function () {
    return this.length === 0;
};
const less = (a, b) => (a == b ? 0 : a < b ? -1 : 1);
const greater = (a, b) => (a == b ? 0 : a < b ? 1 : -1);
const bigIntMax = (...args) => args.reduce((m, e) => (e > m ? e : m));
const bigIntMin = (...args) => args.reduce((m, e) => (e < m ? e : m));
const bigIntAbs = (arg) => (arg < 0 ? -arg : arg);
function read_stdin() {
    return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8');
}
class Input {
    constructor(str) {
        this.index = 0;
        this.inputs = (str ? str : read_stdin()).split(/\s+/);
    }
    number() {
        return Number(this.inputs[this.index++]);
    }
    numbers(n) {
        return this.inputs.slice(this.index, (this.index += n)).map(Number);
    }
    bigint() {
        return BigInt(this.inputs[this.index++]);
    }
    bigints(n) {
        return this.inputs.slice(this.index, (this.index += n)).map(BigInt);
    }
    word() {
        return this.inputs[this.index++];
    }
    words(n) {
        return this.inputs.slice(this.index, (this.index += n));
    }
}
function array(len, init) {
    return Array(len).fill(init);
}
function array2(h, w, init) {
    return array(h, 0).map(() => array(w, init));
}
function main() {
    const input = new Input();
    const N = input.number();
    const products = Array(N);
    for (let i = 0; i < N; i++) {
        const a = input.number();
        const b = input.number();
        products[i] = { a, b };
    }
    products.sort((x, y) => x.b - y.b);
    let head = 0;
    let tail = N - 1;
    let sum = 0;
    let count = 0;
    while (head <= tail) {
        // console.log({ head, tail })
        const p_head = products[head];
        let c = p_head.b - count;
        // console.log({ p_head, count, c })
        if (c > 0) {
            while (head <= tail) {
                // console.log({ head, tail, c })
                const p_tail = products[tail];
                if (p_tail.a > c) {
                    p_tail.a -= c;
                    count += c;
                    sum += 2 * c;
                    break;
                }
                else if (p_tail.a === c) {
                    p_tail.a -= c;
                    count += c;
                    sum += 2 * c;
                    tail--;
                    break;
                }
                else {
                    c -= p_tail.a;
                    count += p_tail.a;
                    sum += 2 * p_tail.a;
                    tail--;
                }
            }
        }
        // console.log({ p_head })
        if (p_head.a > 0) {
            if (p_head.b <= count) {
                sum += p_head.a;
            }
            else {
                sum += 2 * p_head.a;
            }
            count += p_head.a;
        }
        head++;
    }
    console.log(sum);
}
main();
//# sourceMappingURL=aoj.js.map


const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

var n, t, ans = 2, cont = [], indicator = 0, temp = [];

rl.on('line', (input) => {
    if (indicator == 0) {
        temp = input.split(' ').map(item => parseInt(item));
        n = temp[0];
        t = temp[1];
        indicator++;
    }
    else {
        temp = input.split(' ').map(item => parseFloat(item));
        let center = temp[0];
        let len = temp[1];
        cont.push([center - len / 2, center + len / 2]);
    }

}).on('close', () => {
    cont.sort((obj1, obj2) => { return obj1[0] - obj2[0] });
    for (let i = 0; i < n - 1; i++) {
        let gap = cont[i + 1][0] - cont[i][1];
        if (gap > t)
            ans += 2;
        else if (gap == t)
            ans++;
    }
    console.log(ans);
});

const readline = require("readline");

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

function addToArray(items, a, b) {
  var len = items.length;

  for (var i = 0; i < len; i++) {
    if (items[i] == a) {
      items[i] = b;
      return items;
    }
    if (items[i] == b) {
      items[i] = a;
      return items;
    }
  }

  var newArray = [len + 1];

  for (var i = 0; i < len; i++) {
    newArray[i] = items[i];
  }
  newArray[len] = a;
  newArray[len + 1] = b;

  return newArray;
}

function bubbleSort(cont) {
  var swapped,
    len = cont.length;
  if (len === 1) return;

  do {
    swapped = false;
    for (var i = 1; i < len; i++) {
      if (cont[i - 1] > cont[i]) {
        var b = cont[i];
        cont[i] = cont[i - 1];
        cont[i - 1] = b;
        swapped = true;
      }
    }
  } while (swapped);
  return;
}

var array = [];
var mycont = [];
var n = -1;
var t = 0;
var counter = 2;
var coordinat = 0;
var check = false;

rl.on("line", input => {
  if (n == -1) {
    array = input.split(" ");
    n = parseInt(array[0]);
    t = parseInt(array[1]);
  } else if (n != 1) {
    array = input.split(" ");
    var x = parseInt(array[0]);
    var a = parseInt(array[1]);
    mycont = addToArray(mycont, x - a / 2, x + a / 2);

    n--;
  } else if (n == 1) {
    array = input.split(" ");
    var x = parseInt(array[0]);
    var a = parseInt(array[1]);
    mycont = addToArray(mycont, x - a / 2, x + a / 2);

    bubbleSort(mycont);

    for (var i = 2; i < mycont.length - 1; i += 2) {
      if (mycont[i] - mycont[i - 1] == t) counter++;
      else if (mycont[i] - mycont[i - 1] > t) counter += 2;
    }
  }
}).on("close", () => {
  console.log(counter);
});

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

var n, t, pos, len, indicator = 0,ans = 2,
    cont = [],
    temp = [];

rl.on('line', (input) => {
    if (indicator == 0) {
        temp = input.split(' ').map(item => parseInt(item));
        n = temp[0];
        t = temp[1];
        indicator++;
    } else if (indicator < n) {
        temp = input.split(' ').map(item => parseInt(item));
        pos = temp[0];
        len = temp[1];
        cont.push([pos - len / 2, pos + len / 2]);
        indicator++;
    } else {
        temp = input.split(' ').map(item => parseInt(item));
        pos = temp[0];
        len = temp[1];
        cont.push([pos - len / 2, pos + len / 2]);
        /*our calculations here*/
        cont.sort((a,b) => {return a[0]-b[0]});
        for(i=0;i<cont.length-1;i++){
            var gap = cont[i+1][0] - cont[i][1];
            if(gap > t)
                ans+=2;
            else if(gap == t)
                ans++;

        }
        console.log(ans);
        rl.close();
    }

});

'use strict'

let lll = readline().split(' ')
let N = +lll[0]
let T = +lll[1]

let hoss = []

while (lll = readline()) {
  lll = lll.split(' ')
  let x = +lll[0]
  let a = +lll[1]
  hoss.push([x - a / 2, x + a / 2])
}

let pos = 0

hoss = hoss.sort((a, b) => a[0] - b[0])

hoss.forEach((h, i) => {
  let ph = hoss[i - 1] || [-Infinity, -Infinity]
  let nh = hoss[i + 1] || [Infinity, Infinity]
  if (h[0] - ph[1] >= T) pos++
  if (nh[0] - h[1] > T) pos++
})

print(pos)

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var n, t, cont = [], indicator = 0, temp = [];
rl.on('line', (input) => {
    if (indicator == 0) {
        temp = input.split(' ').map(item => parseInt(item));
        n = temp[0], t = temp[1];
        indicator++;
    }
    else {
        temp = input.split(' ').map(item => parseFloat(item));
        let houseCenter = temp[0];
        let houseLen = temp[1];
        let arr = [houseCenter - houseLen / 2, houseCenter + houseLen / 2];
        cont.push(arr);
    }

}).on('close', function () {
    let ans = 2;
    cont.sort(function (obj1, obj2) {
        return obj1[0] - obj2[0];
        /*
        if(obj1[0] > obj2[0]) return 1;
        return -1;
        */
    });
    // console.log(cont);
    for (let i = 0; i < n - 1; i++) {
        let gap = cont[i + 1][0] - cont[i][1];
        if (gap > t) ans += 2;
        else if (gap == t) ans++;
    }
    console.log(ans);
});

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

var n, t, indicator = 0, cont = [], temp = [];
rl.on('line', (input) => {
    if (indicator == 0) {
        temp = input.split(' ').map(item => parseInt(item));
        n = temp[0];
        t = temp[1];
        indicator++;
    }
    else {
        temp = input.split(' ').map(item => parseInt(item));
        let center = temp[0], len = temp[1];
        cont.push([center - len / 2, center + len / 2])
    }
}).on('close', () => {
    //sort array using comparator
    cont.sort((arr1, arr2) => {
        return arr1[0] - arr2[0];
    })

    //console.log(cont);
    let ans = 2;
    for (let i = 0; i < n - 1; i++) {
        let gap = cont[i + 1][0] - cont[i][1];
        if (gap > t) ans += 2;
        else if (gap == t) ans++;
    }
    console.log(ans);
});

const readline = require("readline");

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

function addToArray(items, a) {
  var len = items.length;

  for (var i = 0; i < len; i++) {
    if (items[i] == a) return items;
  }

  var newArray = [len];

  for (var i = 0; i < len; i++) {
    newArray[i] = items[i];
  }
  newArray[len] = a;

  return newArray;
}

function bubbleSort(cont) {
  var swapped,
    len = cont.length;
  if (len === 1) return;

  do {
    swapped = false;
    for (var i = 1; i < len; i++) {
      if (cont[i - 1] > cont[i]) {
        var b = cont[i];
        cont[i] = cont[i - 1];
        cont[i - 1] = b;
        swapped = true;
      }
    }
  } while (swapped);
  return;
}

var array = [];
var mycont = [];
var n = -1;
var t = 0;
var counter = 2;
var coordinat = 0;
var check = false;

rl.on("line", input => {
  if (n == -1) {
    array = input.split(" ");
    n = parseInt(array[0]);
    t = parseInt(array[1]);
  } else if (n != 1) {
    array = input.split(" ");
    var x = parseInt(array[0]);
    var a = parseInt(array[1]);
    mycont = addToArray(mycont, x - a / 2);
    mycont = addToArray(mycont, x + a / 2);
    n--;
  } else if (n == 1) {
    array = input.split(" ");
    var x = parseInt(array[0]);
    var a = parseInt(array[1]);
    mycont = addToArray(mycont, x - a / 2);
    mycont = addToArray(mycont, x + a / 2);

    bubbleSort(mycont);
    for (var i = 1; i < mycont.length; i += 2) {
      if (mycont[i + 1] - mycont[i] == t) counter++;
      else if (mycont[i + 1] - mycont[i] > t) counter += 2;
    }

  }
}).on("close", () => {
  console.log(counter);
  //console.log(sleep2);
});

const readline = require("readline");

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

var array = [];
var n = -1;
var t = 0;
var counter = 2;
var coordinat = 0;
var check = false;

rl.on("line", input => {
  if (n++ == -1) {
    array = input.split(" ");
    t = parseInt(array[1]);
  } else {
    array = input.split(" ");
    var x = parseInt(array[0]);
    var a = parseInt(array[1]);
    if (check) {
      if (x - a / 2 - coordinat > t) counter += 2;
      else if (x - a / 2 - coordinat == t) counter++;
    }

    coordinat = x + a / 2;

    check = true;
  }

}).on("close", () => {
    console.log(counter);

  });;

const readline = require("readline");

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

function addToArray(items, a) {
  var len = items.length;

  for (var i = 0; i < len; i++) {
    if (items[i] == a) return items;
  }

  var newArray = [len];

  for (var i = 0; i < len; i++) {
    newArray[i] = items[i];
  }
  newArray[len] = a;

  return newArray;
}

function bubbleSort(cont) {
  var swapped,
    len = cont.length;
  if (len === 1) return;

  do {
    swapped = false;
    for (var i = 1; i < len; i++) {
      if (cont[i - 1] > cont[i]) {
        var b = cont[i];
        cont[i] = cont[i - 1];
        cont[i - 1] = b;
        swapped = true;
      }
    }
  } while (swapped);
  return;
}

var array = [];
var mycont = [];
var n = -1;
var t = 0;
var counter = 2;
var coordinat = 0;
var check = false;

rl.on("line", input => {
  if (n == -1) {
    array = input.split(" ");
    n = parseInt(array[0]);
    t = parseInt(array[1]);
  } else if (n != 0) {
    array = input.split(" ");
    var x = parseInt(array[0]);
    var a = parseInt(array[1]);
    mycont = addToArray(mycont, x - a / 2);
    mycont = addToArray(mycont, x + a / 2);
    n--;
  } else if (n == 0) {
    bubbleSort(mycont);
    for (var i = 1; i < mycont.length; i += 2) {
      if (mycont[i + 1] - mycont[i] == t) counter++;
      else if (mycont[i + 1] - mycont[i] > t) counter += 2;
    }

    console.log(counter);
    rl.close();
  }
});