Advertisement
Guest User

pepsicola

a guest
Aug 27th, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class pepsicola {
  5. private static InputReader in;
  6. private static PrintWriter out;
  7. public static int mod = 1000000007;
  8. public static long exp(long b, long e) {
  9. long r = 1;
  10. while (e > 0) {
  11. if (e % 2 == 1) r = r * b % mod;
  12. b = b * b % mod;
  13. e >>= 1;
  14. }
  15. return r;
  16. }
  17. public static int MAXL = 17;
  18.  
  19. public static void main(String[] args) throws IOException {
  20. in = new InputReader(System.in);
  21. out = new PrintWriter(System.out, true);
  22. int n = in.nextInt();
  23. int[] freq = new int[1 << MAXL];
  24. for (int i = 0; i < n; i++)
  25. freq[in.nextInt()]++;
  26.  
  27. for (int i = 0; i < MAXL; i++) {
  28. for (int j = 0; j < freq.length; j++) {
  29. if ((j & (1 << i)) != 0) {
  30. freq[j] += freq[j ^ (1 << i)];
  31. }
  32. }
  33. }
  34. long[] ans = new long[1 << MAXL];
  35. for (int i = 0; i < freq.length; i++)
  36. ans[i] = exp(2, freq[i]);
  37.  
  38. for (int i = 0; i < MAXL; i++) {
  39. for (int j = 0; j < freq.length; j++) {
  40. if ((j & (1 << i)) != 0) {
  41. ans[j] = (ans[j] + mod - ans[j ^ (1 << i)]) % mod;
  42. }
  43. }
  44. }
  45. long sum = 0;
  46. for (int i = 0; i < ans.length; i++) {
  47. sum = (sum + ans[i] * exp(i, 3)) % mod;
  48. }
  49. out.println(sum);
  50. out.close();
  51. System.exit(0);
  52. }
  53.  
  54. static class InputReader {
  55. public BufferedReader reader;
  56. public StringTokenizer tokenizer;
  57.  
  58. public InputReader(InputStream stream) {
  59. reader = new BufferedReader(new InputStreamReader(stream), 32768);
  60. tokenizer = null;
  61. }
  62.  
  63. public String next() {
  64. while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  65. try {
  66. tokenizer = new StringTokenizer(reader.readLine());
  67. } catch (IOException e) {
  68. throw new RuntimeException(e);
  69. }
  70. }
  71. return tokenizer.nextToken();
  72. }
  73.  
  74. public int nextInt() {
  75. return Integer.parseInt(next());
  76. }
  77. }
  78.  
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement