A - Spoiler

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 150

問題文

英小文字と | のみからなる文字列 S が与えられます。S| をちょうど 2 個含むことが保証されます。

2 つの | の間にある文字および |S から削除した文字列を出力してください。

制約

  • S は英小文字および | のみからなる長さ 2 以上 100 以下の文字列
  • S| をちょうど 2 個含む

入力

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

S

出力

答えを出力せよ。


入力例 1

atcoder|beginner|contest

出力例 1

atcodercontest

2 つの | に挟まれた文字を全て削除して出力してください。


入力例 2

|spoiler|

出力例 2



全ての文字が削除されることもあります。


入力例 3

||xyz

出力例 3

xyz

Score: 150 points

Problem Statement

You are given a string S consisting of lowercase English letters and |. S is guaranteed to contain exactly two |s.

Remove the characters between the two |s, including the |s themselves, and print the resulting string.

Constraints

  • S is a string of length between 2 and 100, inclusive, consisting of lowercase English letters and |.
  • S contains exactly two |s.

Input

The input is given from Standard Input in the following format:

S

Output

Print the answer.


Sample Input 1

atcoder|beginner|contest

Sample Output 1

atcodercontest

Remove all the characters between the two |s and print the result.


Sample Input 2

|spoiler|

Sample Output 2



It is possible that all characters are removed.


Sample Input 3

||xyz

Sample Output 3

xyz
B - T-shirt

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

あるプログラミングコンテストでは、以下のルールに従って参加者に T シャツをプレゼントします。

  • 上位 A 位までの参加者は、必ず T シャツが貰える。
  • 加えて、上位 A+1 位から B 位までの参加者のうち C 人が一様ランダムに選ばれ、選ばれた参加者は T シャツを貰える。

コンテストには 1000 人が参加し、全ての参加者が相異なる順位を取りました。
このコンテストの参加者であるいろはちゃんは、X 位を取りました。
このとき、いろはちゃんが T シャツを貰える確率を求めてください。

制約

  • 入力はすべて整数
  • 1 \le A < B \le 1000
  • 1 \le C \le B-A
  • 1 \le X \le 1000

入力

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

A B C X

出力

答えを出力せよ。 なお、想定解との絶対誤差または相対誤差が 10^{−6} 以下であれば、正解として扱われる。


入力例 1

30 500 20 103

出力例 1

0.042553191489

いろはちゃんは 103 位を取りました。
31 位から 500 位までの 470 人の参加者の中から 20 人が一様ランダムに選ばれ、ここで選ばれるといろはちゃんは T シャツを貰えます。この確率は \frac{20}{470}=0.04255319\dots です。


入力例 2

50 500 100 1

出力例 2

1.000000000000

いろはちゃんは 1 位を取りました。この入力において、いろはちゃんは確実に T シャツを貰えます。


入力例 3

1 2 1 1000

出力例 3

0.000000000000

いろはちゃんは 1000 位を取りました。この入力において、いろはちゃんが T シャツを貰えることはありません。

Score : 100 points

Problem Statement

In a certain programming contest, T-shirts are awarded to participants according to the following rules.

  • All participants who ranked A-th or higher get a T-shirt.
  • Additionally, from the participants who ranked between (A+1)-th and B-th (inclusive), C participants chosen uniformly at random get a T-shirt.

There were 1000 participants in this contest, and all of them got different ranks.
Iroha-chan, who participated in this contest, ranked X-th.
Find the probability that she gets a T-shirt.

Constraints

  • All values in input are integers.
  • 1 \le A < B \le 1000
  • 1 \le C \le B-A
  • 1 \le X \le 1000

Input

Input is given from Standard Input in the following format:

A B C X

Output

Print the answer. Your output will be considered correct if the absolute or relative error from the judge's answer is at most 10^{−6}.


Sample Input 1

30 500 20 103

Sample Output 1

0.042553191489

Iroha-chan ranked 103-rd.
She will get a T-shirt if she is among the 20 participants chosen uniformly at random from the 470 participants who ranked between 31-st and 500-th, which happens with probability \frac{20}{470}=0.04255319\dots.


Sample Input 2

50 500 100 1

Sample Output 2

1.000000000000

Iroha-chan ranked 1-st. This time, she is guaranteed to get a T-shirt.


Sample Input 3

1 2 1 1000

Sample Output 3

0.000000000000

Iroha-chan ranked 1000-th. This time, she will never get a T-shirt.

C - Extended ABC

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

拡張 A 文字列、拡張 B 文字列、拡張 C 文字列および拡張 ABC 文字列を以下のように定義します。

  • 文字列 S が拡張 A 文字列であるとは、S のすべての文字が A であることをいいます。
  • 文字列 S が拡張 B 文字列であるとは、S のすべての文字が B であることをいいます。
  • 文字列 S が拡張 C 文字列であるとは、S のすべての文字が C であることをいいます。
  • 文字列 S が拡張 ABC 文字列であるとは、ある拡張 A 文字列 S _ A 、拡張 B 文字列 S _ B 、拡張 C 文字列 S _ C が存在して、S _ A,S _ B,S _ C をこの順に連結した文字列が S と等しいことをいいます。

例えば、ABCAAAABBBCCCCCCC などは拡張 ABC 文字列ですが、ABBAAACBBBCCCCCCCAAA などは拡張 ABC 文字列ではありません。 空文字列は拡張 A 文字列でも拡張 B 文字列でも拡張 C 文字列でもあることに注意してください。

A, B, C からなる文字列 S が与えられます。 S が拡張 ABC 文字列ならば Yes を、そうでなければ No を出力してください。

制約

  • SA, B, C からなる文字列
  • 1\leq|S|\leq 100\ (|S| は文字列 S の長さ)

入力

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

S

出力

S が拡張 ABC 文字列ならば Yes を、そうでなければ No を出力せよ。


入力例 1

AAABBBCCCCCCC

出力例 1

Yes

AAABBBCCCCCCC は長さ 3 の拡張 A 文字列 AAA 、長さ 3 の拡張 B 文字列 BBB 、長さ 7 の拡張 C 文字列 CCCCCCC をこの順に連結した文字列なので、拡張 ABC 文字列です。

よって、Yes を出力してください。


入力例 2

ACABABCBC

出力例 2

No

どのような拡張 A 文字列 S _ A, 拡張 B 文字列 S _ B, 拡張 C 文字列 S _ C についても、S _ A,S _ B,S _ C をこの順に連結した文字列が ACABABCBC と等しくなることはありません。

よって、No を出力してください。


入力例 3

A

出力例 3

Yes

入力例 4

ABBBBBBBBBBBBBCCCCCC

出力例 4

Yes

Score: 200 points

Problem Statement

We define Extended A strings, Extended B strings, Extended C strings, and Extended ABC strings as follows:

  • A string S is an Extended A string if all characters in S are A.
  • A string S is an Extended B string if all characters in S are B.
  • A string S is an Extended C string if all characters in S are C.
  • A string S is an Extended ABC string if there is an Extended A string S_A, an Extended B string S_B, and an Extended C string S_C such that the string obtained by concatenating S_A, S_B, S_C in this order equals S.

For example, ABC, A, and AAABBBCCCCCCC are Extended ABC strings, but ABBAAAC and BBBCCCCCCCAAA are not. Note that the empty string is an Extended A string, an Extended B string, and an Extended C string.

You are given a string S consisting of A, B, and C. If S is an Extended ABC string, print Yes; otherwise, print No.

Constraints

  • S is a string consisting of A, B, and C.
  • 1\leq|S|\leq 100 (|S| is the length of the string S.)

Input

The input is given from Standard Input in the following format:

S

Output

If S is an Extended ABC string, print Yes; otherwise, print No.


Sample Input 1

AAABBBCCCCCCC

Sample Output 1

Yes

AAABBBCCCCCCC is an Extended ABC string because it is a concatenation of an Extended A string of length 3, AAA, an Extended B string of length 3, BBB, and an Extended C string of length 7, CCCCCCC, in this order.

Thus, print Yes.


Sample Input 2

ACABABCBC

Sample Output 2

No

There is no triple of Extended A string S_A, Extended B string S_B, and Extended C string S_C such that the string obtained by concatenating S_A, S_B, and S_C in this order equals ACABABCBC.

Therefore, print No.


Sample Input 3

A

Sample Output 3

Yes

Sample Input 4

ABBBBBBBBBBBBBCCCCCC

Sample Output 4

Yes
D - Multi Test Cases

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

この問題は 1 つの入力ファイルに複数のテストケースが含まれる問題です。
はじめに整数 T が与えられます。T 個のテストケースについて次の問題を解いてください。

  • N 個の正整数 A_1, A_2, ..., A_N があります。このうち奇数は何個ありますか?

制約

  • 1 \leq T \leq 100
  • 1 \leq N \leq 100
  • 1 \leq A_i \leq 10^9
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。ここで \text{test}_ii 番目のテストケースを意味する。

T
\text{test}_1
\text{test}_2
\vdots
\text{test}_T

各テストケースは以下の形式で与えられる。

N
A_1 A_2 \dots A_N

出力

T 行出力せよ。i 行目には i 番目のテストケースに対する答えを出力せよ。


入力例 1

4
3
1 2 3
2
20 23
10
6 10 4 1 5 9 8 6 5 1
1
1000000000

出力例 1

2
1
5
0

この入力は 4 個のテストケースが含まれています。

入力の 2 行目と 3 行目が 1 番目のテストケースに対応する入力で、N = 3, A_1 = 1, A_2 = 2, A_3 = 3 になります。
A_1, A_2, A_3 のうち奇数は全部で 2 個なので 1 行目に 2 を出力します。

Score : 200 points

Problem Statement

In this problem, an input file contains multiple test cases.
You are first given an integer T. Solve the following problem for T test cases.

  • We have N positive integers A_1, A_2, ..., A_N. How many of them are odd?

Constraints

  • 1 \leq T \leq 100
  • 1 \leq N \leq 100
  • 1 \leq A_i \leq 10^9
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format, where \text{test}_i represents the i-th test case:

T
\text{test}_1
\text{test}_2
\vdots
\text{test}_T

Each test case is in the following format:

N
A_1 A_2 \dots A_N

Output

Print T lines. The i-th line should contain the answer for the i-th test case.


Sample Input 1

4
3
1 2 3
2
20 23
10
6 10 4 1 5 9 8 6 5 1
1
1000000000

Sample Output 1

2
1
5
0

This input contains four test cases.

The second and third lines correspond to the first test case, where N = 3, A_1 = 1, A_2 = 2, A_3 = 3.
We have two odd numbers in A_1, A_2, and A_3, so the first line should contain 2.

E - ABC conjecture

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

正の整数 N が与えられます。

A\leq B\leq C かつ ABC\leq N であるような正の整数の組 (A,B,C) の個数を求めてください。

なお、制約の条件下で答えは 2^{63} 未満であることが保証されます。

制約

  • 1 \leq N \leq 10^{11}
  • N は整数である

入力

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

N

出力

答えを出力せよ。


入力例 1

4

出力例 1

5

条件を満たす組は (1,1,1),(1,1,2),(1,1,3),(1,1,4),(1,2,2)5 つです。


入力例 2

100

出力例 2

323

入力例 3

100000000000

出力例 3

5745290566750

Score : 300 points

Problem Statement

You are given a positive integer N.

Find the number of triples of positive integers (A, B, C) such that A\leq B\leq C and ABC\leq N.

The Constraints guarantee that the answer is less than 2^{63}.

Constraints

  • 1 \leq N \leq 10^{11}
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

4

Sample Output 1

5

There are five such triples: (1,1,1),(1,1,2),(1,1,3),(1,1,4),(1,2,2).


Sample Input 2

100

Sample Output 2

323

Sample Input 3

100000000000

Sample Output 3

5745290566750
F - Separated Lunch

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

キーエンス本社に勤務する人数が増えてきたので、本社に存在する部署を 2 つのグループに分け、昼休みの時間帯を分けることにしました。

キーエンス本社には N 個の部署が存在し、i 番目 (1\leq i\leq N) の部署に所属する人数は K_i 人です。

それぞれの部署をグループ A, B のいずれか一方に割り当て、グループごとに同時に昼休みをとり、 かつグループ A, B の昼休みの時間が重ならないようにしたとき、同時に昼休みをとる最大人数としてあり得る最小の値を求めてください。
すなわち、グループ A に割り当てられた部署に所属する人数の合計とグループ B に割り当てられた部署に所属する人数の合計 のうち大きい方の値としてあり得る最小の値を求めてください。

制約

  • 2\leq N \leq 20
  • 1\leq K_i \leq 10^8
  • 入力はすべて整数

入力

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

N
K_1 K_2 \ldots K_N

出力

同時に昼休みを取る最大人数としてあり得る最小の値を出力せよ。


入力例 1

5
2 3 5 10 12

出力例 1

17

1,2,5 番目の部署をグループ A に、3,4 番目の部署をグループ B に割り当てたとき、 グループ A に割り当てられた部署に所属する人数の合計は 2+3+12=17 、 グループ B に割り当てられた部署に所属する人数の合計は 5+10=15 となり、 このとき同時に昼休みを取る最大人数は 17 となります。

一方で、グループ A,B それぞれに割り当てられた部署に所属する人数の合計がいずれも 16 以下になるように 部署を割り当てることはできないため、17 を出力します。


入力例 2

2
1 1

出力例 2

1

同一人数の部署が複数存在する可能性もあります。


入力例 3

6
22 25 26 45 22 31

出力例 3

89

例えば、1,4,5 番目の部署をグループ A に、2,3,6 番目の部署をグループ B に割り当てたとき同時に昼休みを取る最大人数は 89 となります。

Score : 300 points

Problem Statement

As KEYENCE headquarters have more and more workers, they decided to divide the departments in the headquarters into two groups and stagger their lunch breaks.

KEYENCE headquarters have N departments, and the number of people in the i-th department (1\leq i\leq N) is K_i.

When assigning each department to Group A or Group B, having each group take lunch breaks at the same time, and ensuring that the lunch break times of Group A and Group B do not overlap, find the minimum possible value of the maximum number of people taking a lunch break at the same time.
In other words, find the minimum possible value of the larger of the following: the total number of people in departments assigned to Group A, and the total number of people in departments assigned to Group B.

Constraints

  • 2 \leq N \leq 20
  • 1 \leq K_i \leq 10^8
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N
K_1 K_2 \ldots K_N

Output

Print the minimum possible value of the maximum number of people taking a lunch break at the same time.


Sample Input 1

5
2 3 5 10 12

Sample Output 1

17

When assigning departments 1, 2, and 5 to Group A, and departments 3 and 4 to Group B, Group A has a total of 2+3+12=17 people, and Group B has a total of 5+10=15 people. Thus, the maximum number of people taking a lunch break at the same time is 17.

It is impossible to assign the departments so that both groups have 16 or fewer people, so print 17.


Sample Input 2

2
1 1

Sample Output 2

1

Multiple departments may have the same number of people.


Sample Input 3

6
22 25 26 45 22 31

Sample Output 3

89

For example, when assigning departments 1, 4, and 5 to Group A, and departments 2, 3, and 6 to Group B, the maximum number of people taking a lunch break at the same time is 89.

G - Find by Query

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 400

問題文

この問題は インタラクティブな問題(あなたが作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。

ジャッジが 01 のみからなる長さ N の文字列 S = S_1S_2\ldots S_N を持っています。 文字列 S は、S_1 = 0 および S_N = 1 を満たします。

あなたには S の長さ N が与えられますが、S 自体は与えられません。 その代わり、あなたはジャッジに対して以下の質問を 20 回まで行うことができます。

  • 1 \leq i \leq N を満たす整数 i を選び、S_i の値を尋ねる。

1 \leq p \leq N-1 かつ S_p \neq S_{p+1} を満たす整数 p1 個出力してください。
なお、本問題の条件下でそのような整数 p が必ず存在することが示せます。

制約

  • 2 \leq N \leq 2 \times 10^5

入出力

最初に、文字列 S の長さ N を標準入力から受け取ってください。

N

次に、あなたはジャッジに対して問題文中の質問を 20 回まで繰り返すことができます。

質問は、以下の形式で標準出力に出力してください。 ここで、i1 \leq i \leq N を満たす整数でなければなりません。

? i

これに対する応答として、S_i の値が次の形式で標準入力から与えられます。

S_i

ここで、S_i0 または 1 です。

問題文中の条件を満たす整数 p を見つけたら、解答を以下の形式で出力してください。 その後、ただちにプログラムを終了してください。

! p

答えが複数ある場合、どれを出力しても正解とみなされます。

注意点

  • 出力を行うたびに、末尾に改行を入れて標準出力を flush してください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
  • 対話の途中で不正な出力を行った、あるいはプログラムが途中で終了した場合のジャッジ結果は不定です。
  • 解答を出力したらただちにプログラムを終了してください。そうしない場合、ジャッジ結果は不定です。
  • 文字列 S はあなたとジャッジの対話の開始時に固定され、あなたが行った質問などに応じて変更されることはありません。

入出力例

以下は、N = 7, S = 0010011 の場合の入出力例です。

入力 出力 説明
7 N が与えられます。
? 1 S_1 が何かをジャッジに質問します。
0 質問に対する答えとして S_1 = 0 がジャッジから返されます。
? 6 S_6 が何かをジャッジに質問します。
1 質問に対する答えとして S_6 = 1 がジャッジから返されます。
? 5 S_5 が何かをジャッジに質問します。
0 質問に対する答えとして S_5 = 0 がジャッジから返されます。
! 5 問題文中の条件を満たす整数 p として、p = 5 を解答します。

解答した p = 5 について、1 \leq p \leq N-1 かつ S_p \neq S_{p+1} が成り立ちます。 よって、この後ただちにプログラムを終了することで、正解と判定されます。

Score : 400 points

Problem Statement

This is an interactive task, where your program and the judge interact via Standard Input and Output.

The judge has a string of length N consisting of 0 and 1: S = S_1S_2\ldots S_N. Here, S_1 = 0 and S_N = 1.

You are given the length N of S, but not the contents of S. Instead, you can ask the judge at most 20 questions as follows.

  • Choose an integer i such that 1 \leq i \leq N and ask the value of S_i.

Print an integer p such that 1 \leq p \leq N-1 and S_p \neq S_{p+1}.
It can be shown that such p always exists under the settings of this problem.

Constraints

  • 2 \leq N \leq 2 \times 10^5

Input and Output

First, receive the length N of the string S from Standard Input:

N

Then, you get to ask the judge at most 20 questions as described in the problem statement.

Print each question to Standard Output in the following format, where i is an integer satisfying 1 \leq i \leq N:

? i

In response to this, the value of S_i will be given from Standard Input in the following format:

S_i

Here, S_i is 0 or 1.

When you find an integer p satisfying the condition in the problem statement, print it in the following format, and immediately quit the program:

! p

If multiple solutions exist, you may print any of them.

Notes

  • Print a newline and flush Standard Output at the end of each message. Otherwise, you may get a TLE verdict.
  • If there is malformed output during the interaction or your program quits prematurely, the verdict will be indeterminate.
  • After printing the answer, immediately quit the program. Otherwise, the verdict will be indeterminate.
  • The string S will be fixed at the start of the interaction and will not be changed according to your questions or other factors.

Sample Input and Output

In the following interaction, N = 7 and S = 0010011.

Input Output Description
7 N is given.
? 1 Ask the value of S_1.
0 The judge responds with S_1 = 0.
? 6 Ask the value of S_6.
1 The judge responds with S_6 = 1.
? 5 Ask the value of S_5.
0 The judge responds with S_5 = 0.
! 5 Present p = 5 as an integer satisfying the condition.

For the presented p = 5, we have 1 \leq p \leq N-1 and S_p \neq S_{p+1}. Thus, if the program immediately quits here, this case will be judged as correctly solved.

H - Count Arithmetic Subsequences

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 475

問題文

長さ N の数列 A=(A_1,A_2,\dots,A_N) が与えられます。各 k=1,2,\dots,N について、A の長さ k の(連続するとは限らない)部分列であって等差数列であるようなものの個数を 998244353 で割ったあまりを求めてください。ただし、2 つの部分列が列として同じでも、取り出す位置が異なるならば区別するものとします。

部分列とは 数列 A の部分列とは、A の要素を 0 個以上選んで削除し、残った要素を元の順序を保って並べた数列のことを指します。

制約

  • 1 \leq N \leq 80
  • 1 \leq A_i \leq 10^9
  • 入力はすべて整数

入力

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

N
A_1 A_2 \dots A_N

出力

k=1,2,\dots,N に対する答えを、この順に空白区切りで一行で出力せよ。


入力例 1

5
1 2 3 2 3

出力例 1

5 10 3 0 0
  • 長さ 1 の部分列は全部で 5 個あり、これらはすべて長さ 1 の等差数列です。
  • 長さ 2 の部分列は全部で 10 個あり、これらはすべて長さ 2 の等差数列です。
  • 長さ 3 の部分列であって等差数列であるものは、(A_1,A_2,A_3),(A_1,A_2,A_5),(A_1,A_4,A_5)3 つです。
  • 長さ 4 以上の部分列であって等差数列であるものは存在しません。

入力例 2

4
1 2 3 4

出力例 2

4 6 2 1

入力例 3

1
100

出力例 3

1

Score : 475 points

Problem Statement

You are given a sequence A = (A_1, A_2, \dots, A_N) of length N. For each k = 1, 2, \dots, N, find the number, modulo 998244353, of (not necessarily contiguous) subsequences of A of length k that are arithmetic sequences. Two subsequences are distinguished if they are taken from different positions, even if they are equal as sequences.

What is a subsequence? A subsequence of a sequence A is a sequence obtained by deleting zero or more elements from A and arranging the remaining elements without changing the order.

Constraints

  • 1 \leq N \leq 80
  • 1 \leq A_i \leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the answers for k = 1, 2, \dots, N in this order, in a single line, separated by spaces.


Sample Input 1

5
1 2 3 2 3

Sample Output 1

5 10 3 0 0
  • There are 5 subsequences of length 1, all of which are arithmetic sequences.
  • There are 10 subsequences of length 2, all of which are arithmetic sequences.
  • There are 3 subsequences of length 3 that are arithmetic sequences: (A_1, A_2, A_3), (A_1, A_2, A_5), and (A_1, A_4, A_5).
  • There are no arithmetic subsequences of length 4 or more.

Sample Input 2

4
1 2 3 4

Sample Output 2

4 6 2 1

Sample Input 3

1
100

Sample Output 3

1
I - Double Sum 2

実行時間制限: 4 sec / メモリ制限: 1024 MiB

配点 : 500

問題文

正整数 x に対して f(x) を「 x が偶数である間 x2 で割り続けたときの、最終的な x の値」として定義します。例えば f(4)=f(2)=f(1)=1f(12)=f(6)=f(3)=3 です。

長さ N の整数列 A=(A_1,A_2,\ldots, A_N) が与えられるので、 \displaystyle \sum_{i=1}^N \sum_{j=i}^N f(A_i+A_j) を求めてください。

制約

  • 1\le N\le 2\times 10^5
  • 1\le A_i\le 10^7
  • 入力は全て整数

入力

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

N
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

2
4 8

出力例 1

5

f(A_1+A_1)=f(8)=1f(A_1+A_2)=f(12)=3f(A_2+A_2)=f(16)=1 です。したがって、 1+3+1=5 を出力してください。


入力例 2

3
51 44 63

出力例 2

384

入力例 3

8
577752 258461 183221 889769 278633 577212 392309 326001

出力例 3

20241214

Score : 500 points

Problem Statement

For a positive integer x, define f(x) as follows: "While x is even, keep dividing it by 2. The final value of x after these divisions is f(x)." For example, f(4)=f(2)=f(1)=1, and f(12)=f(6)=f(3)=3.

Given an integer sequence A=(A_1,A_2,\ldots,A_N) of length N, find \displaystyle \sum_{i=1}^N \sum_{j=i}^N f(A_i+A_j).

Constraints

  • 1\le N\le 2\times 10^5
  • 1\le A_i\le 10^7
  • All input values are integers.

Input

The input is given in the following format from Standard Input:

N
A_1 A_2 \ldots A_N

Output

Print the answer.


Sample Input 1

2
4 8

Sample Output 1

5

f(A_1+A_1)=f(8)=1, f(A_1+A_2)=f(12)=3, f(A_2+A_2)=f(16)=1. Thus, Print 1+3+1=5.


Sample Input 2

3
51 44 63

Sample Output 2

384

Sample Input 3

8
577752 258461 183221 889769 278633 577212 392309 326001

Sample Output 3

20241214