🏡 index : github.com/captn3m0/codechef.git

---
{"category_name":"easy","problem_code":"CRDFLP","problem_name":"Magical Flips","problemComponents":{"constraints":"- $1 \\leq T \\leq 10^4$\n- $1 \\leq N \\leq 10^5$\n- $0 \\leq A_i \\leq 2^{30} - 1$\n- $0 \\leq B_i \\leq 2^{30} - 1$\n- Sum of $N$ over all testcases does not exceeds $10^5$.\n","constraintsState":true,"subtasks":"","subtasksState":false,"inputFormat":"- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- Each test case contains three lines of input.\n- The first line contains a single integer $N$ - the number of cards.\n- The second line contains $N$ space-separated integers $A_1, A_2,..., A_N$ - the numbers on the front face of the cards\n- The third line contains $N$ space-separated integers $B_1, B_2,..., B_N$ - the numbers on the back face of the cards\n","inputFormatState":true,"outputFormat":"For each test case, print a single line containing two space-separated integers, first denoting the maximum bitwise AND possible and second denoting the minimum number of flips required to achieve it.\n","outputFormatState":true,"sampleTestCases":{"0":{"id":1,"input":"3\n3\n4 6 8\n2 1 2\n3\n0 2 0\n2 0 8\n3\n1 2 1\n2 3 6","output":"2 2\n0 0\n2 2","explanation":"**Test case $1$:** The maximum AND is obtained after flipping the first and third cards achieving a configuration of $[2, 6, 2]$ which yields a bitwise AND of $2$.\n\n**Test case $2$:** Every possible configuration of the cards yields a bitwise AND equal to $0$. So to ensure the minimum number of operations, Chef performs no flip.","isDeleted":false}}},"video_editorial_url":"https://youtu.be/Ne2-prlJZg4","languages_supported":{"0":"CPP14","1":"C","2":"JAVA","3":"PYTH 3.6","4":"CPP17","5":"PYTH","6":"PYP3","7":"CS2","8":"ADA","9":"PYPY","10":"TEXT","11":"PAS fpc","12":"NODEJS","13":"RUBY","14":"PHP","15":"GO","16":"HASK","17":"TCL","18":"PERL","19":"SCALA","20":"LUA","21":"kotlin","22":"BASH","23":"JS","24":"LISP sbcl","25":"rust","26":"PAS gpc","27":"BF","28":"CLOJ","29":"R","30":"D","31":"CAML","32":"FORT","33":"ASM","34":"swift","35":"FS","36":"WSPC","37":"LISP clisp","38":"SQL","39":"SCM guile","40":"PERL6","41":"ERL","42":"CLPS","43":"ICK","44":"NICE","45":"PRLG","46":"ICON","47":"COB","48":"SCM chicken","49":"PIKE","50":"SCM qobi","51":"ST","52":"SQLQ","53":"NEM"},"max_timelimit":0.5,"source_sizelimit":50000,"problem_author":"tejas10p","problem_tester":"","date_added":"26-08-2021","tags":{"0":"bitwise","1":"easy","2":"greedy","3":"start10","4":"tejas10p"},"problem_difficulty_level":"Unavailable","best_tag":"Bitwise And","editorial_url":"https://discuss.codechef.com/problems/CRDFLP","time":{"view_start_date":1630243800,"submit_start_date":1630243800,"visible_start_date":1630243800,"end_date":1735669800},"is_direct_submittable":false,"problemDiscussURL":"https://discuss.codechef.com/search?q=CRDFLP","is_proctored":false,"visitedContests":{},"layout":"problem"}
---
Chef found $N$ magical cards in his drawer. Each card has a number written on each of its faces. He places all the cards on the table in a front face-up manner.

Chef denotes the numbers on the front face by $A_1, A_2,..., A_N$ and on the back face by $B_1, B_2,..., B_N$. Chef can choose some (possibly zero or all) cards and flip them, then he will calculate the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of all the numbers currently in a face-up manner.

Now Chef wonders what is the *maximum* bitwise AND that he can achieve and what is the *minimum* number of cards he has to flip to achieve this value. Can you help him find it?

<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.</div></aside>