F - Spices Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500500

問題文

スパイス屋には、スパイス 11 、スパイス 22\ldots 、スパイス 2N12^N-12N12^N-1 種類のスパイスがそれぞれ 11 個ずつ売られています。 i=1,2,,2N1i = 1, 2, \ldots, 2^N-1 について、スパイス ii の値段は cic_i 円です。 高橋君はそれらを好きなだけ買うことができます。

高橋君は帰宅後、買ったスパイスのうち 11 つ以上を選び、それらを組み合わせてカレーを作る予定です。
高橋君がスパイス A1A_1 、スパイス A2A_2\ldots、スパイス AkA_kkk 個のスパイスを組み合わせると、完成するカレーの辛さは A1A2AkA_1 \oplus A_2 \oplus \cdots \oplus A_k になります。 ここで、\oplus はビットごとの排他的論理和を表します。

高橋君は、作るカレーの辛さを帰宅後の気分で決めたいので、とりあえず 11 以上 2N12^N-1 以下の任意の整数の辛さのカレーを作れるように、購入するスパイスの組み合わせを決定します。高橋君が支払う金額としてあり得る最小値を出力してください。

制約

  • 2N162 \leq N \leq 16
  • 1ci1091 \leq c_i \leq 10^9
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

NN
c1c_1 c2c_2 \ldots c2N1c_{2^N-1}

出力

高橋君が支払う金額としてあり得る最小値を出力せよ。


入力例 1Copy

Copy
2
4 5 3

出力例 1Copy

Copy
7

高橋君がスパイス 11 とスパイス 33 を買うと、下記の通り、11 以上 33 以下の任意の整数の辛さのカレーを作ることができます。

  • 辛さ 11 のカレーを作るには、スパイス 11 のみを使い、
  • 辛さ 22 のカレーを作るには、スパイス 11 とスパイス 33 を組み合わせ、
  • 辛さ 33 のカレーを作るには、スパイス 33 のみを使えば良いです。

このとき高橋君が支払う金額は c1+c3=4+3=7c_1 + c_3 = 4 + 3 = 7 円であり、これが高橋君が支払う金額としてあり得る最小値です。


入力例 2Copy

Copy
4
9 7 9 7 10 4 3 9 4 8 10 5 6 3 8

出力例 2Copy

Copy
15

Score : 500500 points

Problem Statement

The shop supaisu-ya sells 2N12^N-1 kinds of spices: Spice 11, Spice 22, \ldots, Spice 2N12^N-1. One pack of each spice is in stock. For each i=1,2,,2N1i = 1, 2, \ldots, 2^N-1, Spice ii costs cic_i yen. Takahashi can buy any of these spices.

He plans to make curry after getting home by choosing one or more of the bought spices and mixing them.
If kk spices, Spice A1A_1, Spice A2A_2, \ldots, Spice AkA_k, are mixed, the hotness of the resulting curry is A1A2AkA_1 \oplus A_2 \oplus \cdots \oplus A_k, where \oplus denotes the bitwise XOR.

Takahashi wants to decide the hotness of the curry based on his feeling after getting home. For now, he will buy a set of spices that allows him to make curry of any hotness from 11 through 2N12^N-1. Print the minimum possible amount of money Takahashi pays.

Constraints

  • 2N162 \leq N \leq 16
  • 1ci1091 \leq c_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN
c1c_1 c2c_2 \ldots c2N1c_{2^N-1}

Output

Print the minimum possible amount of money Takahashi pays.


Sample Input 1Copy

Copy
2
4 5 3

Sample Output 1Copy

Copy
7

If Takahashi buys Spice 11 and 33, he can make curry of any hotness from 11 through 33, as follows.

  • To make curry of hotness 11, use just Spice 11.
  • To make curry of hotness 22, mix Spice 11 and Spice 33.
  • To make curry of hotness 33, use just Spice 33.

Here, Takahashi pays c1+c3=4+3=7c_1 + c_3 = 4 + 3 = 7 yen, which is the minimum possible amount he pays.


Sample Input 2Copy

Copy
4
9 7 9 7 10 4 3 9 4 8 10 5 6 3 8

Sample Output 2Copy

Copy
15


2025-04-14 (Mon)
11:23:58 +00:00