PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000066. Chu trình ngắn nhất qua các bit (Shortest Cycle)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chu trình ngắn nhất qua các bit (Shortest Cycle)

Shortest Cycle

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Create an undirected graph on n given nonnegative integers; vertices i and j are adjacent exactly when their bitwise AND is nonzero. Find the length of the shortest simple cycle, or -1 if none exists.

Input

First n; then n nonnegative integers a_i.

Output

Print the number of edges of the shortest simple cycle, or -1.

Subtasks

  • Subtask 1 (40 points): 3≤n≤12, 0≤ai<2203\le n\le 12,\ 0\le a_i<2^{20}. Every array element is a nonnegative integer. The graph is the simple graph induced by the pairwise bitwise AND.
  • Subtask 2 (60 points): 3≤n≤105, 0≤ai<2603\le n\le 10^5,\ 0\le a_i<2^{60}. Every array element is a nonnegative integer. The graph is the simple graph induced by the pairwise bitwise AND.

Examples

Input

3
3 6 5

Output

3

Explanation

3&6=2, 6&5=4, 3&5=1. Every pair is adjacent, forming a triangle of length 3.