1252 - GROUP

Tạo bởi: CLB Olympic Tin học HUTECH

Mô tả yêu cầu

The XYZ class has N students numbered from 1 to N. Each student is represented by two positive integers a_i and b_i, where b_i represents the skill level of the i student. There are 60 subjects taught in the class. Student i is good at subject j if the j^{th} bit of the binary representation of a_i is 1, otherwise it is 0.

Student i feels superior to student j if and only if there is at least one subject that i is good at but j is not. In other words, when a_i and a_j are represented in binary form, there exists a position k where the k^{th} bit of a_i is 1 and the k^{th} bit of a_j is 0. Two students may both feel superior to another student.

The homeroom teacher wants to select a group of students to participate in a competition. The group is formed if there are at least 2 members and no member in the group feels superior to all other members. The teacher wants to select the group with the highest total skill level of the students. Help the teacher find the maximum total skill level. If it is not possible to form a group, output 0.

Dữ liệu vào

  • The first line contains an integer N, (1 \leq N \leq 5000).
  • The next line contains N integers. The ith integer represents a_i (0 \leq a_i < 2^{60}).
  • The last line contains N integers. The i_{th} integer represents b_i (1 \leq b_i \leq 10^5).

Dữ liệu ra

Giới hạn

  • Subtask 1 (50% of tests): 1 \leq N \leq 1000
  • Subtask 2 (50% of tests): There are no additional constraints.

Ví dụ

Dữ liệu vào Sao chép
4
3 2 3 6
2 8 5 10
Dữ liệu ra Sao chép
15
Đăng nhập để làm bài
Thông tin
Giới hạn thời gian 1 giây
Giới hạn bộ nhớ 128 MB