`{"id":"40b930dc-794a-4b5b-9110-5de34b4208de","name":"Sum Of Bit Differences Of All Pairs","description":"1. You are given an array of n numbers.\r\n2. You have to find the sum of bit differences in all pairs that can be formed from n numbers.\r\n3. Bit difference of two numbers is defined as the count of different bits at same positions in binary representations of two numbers.","inputFormat":"A number n\r\na1\r\na2..\r\nn numbers","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= n &lt;= 10^9\r\n1 &lt;= arr[i] &lt;= 10^9","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\nlong solution(vector<int>&arr){\n \n}\nint main (){\n int n;\n cin>>n;\n vector<int>arr;\n for(int i = 0 ; i <n; i++){\n int x;\n cin>>x;\n arr.push_back(x);\n }\n cout<<solution(arr)<<endl;\n}\n"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static long solution(int[] arr){\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[] args){\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for(int i = 0 ; i < arr.length; i++){\r\n arr[i] = scn.nextInt();\r\n }\r\n System.out.println(solution(arr));\r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"3\r\n1 2 3","sampleOutput":"8","questionVideo":"https://www.youtube.com/embed/L_fIn5TM3mM?end=147","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f3e3dbef-d2b7-4f6d-b357-2ef3738e6c91","name":"Bit Manipulation For Intermediate","slug":"bit-manipulation-for-intermediate-9995","type":0},{"id":"86edffa9-923f-477f-8e62-a9fdb0a00374","name":"Sum Of Bit Differences Of All Pairs","slug":"sum-of-bit-differences-of-all-pairs","type":1}],"next":{"id":"dec513e4-b49c-44f7-a149-749cd70a4245","name":"Sum of bit Differences of All Pairs MCQ","type":0,"slug":"sum-of-bit-differences-of-all-pairs-mcq"},"prev":{"id":"8a9d0672-9142-4bcb-8e2e-573ca84de2c4","name":"Swap All Odd And Even Bits","type":3,"slug":"swap-all-odd-and-even-bits"}}}`

# Sum Of Bit Differences Of All Pairs

1. You are given an array of n numbers. 2. You have to find the sum of bit differences in all pairs that can be formed from n numbers. 3. Bit difference of two numbers is defined as the count of different bits at same positions in binary representations of two numbers.

`{"id":"40b930dc-794a-4b5b-9110-5de34b4208de","name":"Sum Of Bit Differences Of All Pairs","description":"1. You are given an array of n numbers.\r\n2. You have to find the sum of bit differences in all pairs that can be formed from n numbers.\r\n3. Bit difference of two numbers is defined as the count of different bits at same positions in binary representations of two numbers.","inputFormat":"A number n\r\na1\r\na2..\r\nn numbers","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= n &lt;= 10^9\r\n1 &lt;= arr[i] &lt;= 10^9","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\nlong solution(vector<int>&arr){\n \n}\nint main (){\n int n;\n cin>>n;\n vector<int>arr;\n for(int i = 0 ; i <n; i++){\n int x;\n cin>>x;\n arr.push_back(x);\n }\n cout<<solution(arr)<<endl;\n}\n"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static long solution(int[] arr){\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[] args){\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for(int i = 0 ; i < arr.length; i++){\r\n arr[i] = scn.nextInt();\r\n }\r\n System.out.println(solution(arr));\r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"3\r\n1 2 3","sampleOutput":"8","questionVideo":"https://www.youtube.com/embed/L_fIn5TM3mM?end=147","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f3e3dbef-d2b7-4f6d-b357-2ef3738e6c91","name":"Bit Manipulation For Intermediate","slug":"bit-manipulation-for-intermediate-9995","type":0},{"id":"86edffa9-923f-477f-8e62-a9fdb0a00374","name":"Sum Of Bit Differences Of All Pairs","slug":"sum-of-bit-differences-of-all-pairs","type":1}],"next":{"id":"dec513e4-b49c-44f7-a149-749cd70a4245","name":"Sum of bit Differences of All Pairs MCQ","type":0,"slug":"sum-of-bit-differences-of-all-pairs-mcq"},"prev":{"id":"8a9d0672-9142-4bcb-8e2e-573ca84de2c4","name":"Swap All Odd And Even Bits","type":3,"slug":"swap-all-odd-and-even-bits"}}}` Editor

# Sum Of Bit Differences Of All Pairs

easy

1. You are given an array of n numbers. 2. You have to find the sum of bit differences in all pairs that can be formed from n numbers. 3. Bit difference of two numbers is defined as the count of different bits at same positions in binary representations of two numbers.

## Constraints

1 <= n <= 10^9 1 <= arr[i] <= 10^9

## Format

### Input

A number n a1 a2.. n numbers

### Output

Check the sample ouput and question video.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}3 1 2 3```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}8`

Question Video

Discussions

Show Discussion

Related Resources 