A - Four Digits

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

0 以上 9999 以下の整数 N が与えられます。

N の先頭に必要なだけ 0 をつけ、4 桁の文字列にしたものを出力してください。

制約

  • 0 \leq N \leq 9999
  • N は整数

入力

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

N

出力

答えを出力せよ。


入力例 1

321

出力例 1

0321

3213 桁なので、先頭に 10 をつけると 4 桁になります。


入力例 2

7777

出力例 2

7777

入力例 3

1

出力例 3

0001

Score : 100 points

Problem Statement

You are given an integer N between 0 and 9999 (inclusive).

Print it as a four-digit string after appending to it the necessary number of leading zeros.

Constraints

  • 0 \leq N \leq 9999
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

321

Sample Output 1

0321

321 has three digits, so we need to add one leading zero to it to make it have four digits.


Sample Input 2

7777

Sample Output 2

7777

Sample Input 3

1

Sample Output 3

0001
B - Welcome to AtCoder Land

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

高橋君は AtCoder Land を目指しています。 目の前に看板が置かれているので、ここが AtCoder Land であるかどうか判定したいです。

文字列 S,T が空白区切りで与えられます。 S= AtCoder かつ T= Land であるかどうか判定してください。

制約

  • S,T は英大小文字からなる長さ 1 以上 10 以下の文字列

入力

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

S T

出力

S= AtCoder かつ T= Land であるならば Yes を、そうでないならば No を出力せよ。


入力例 1

AtCoder Land

出力例 1

Yes

S= AtCoder かつ T= Land です。


入力例 2

CodeQUEEN Land

出力例 2

No

S= AtCoder ではありません。


入力例 3

aTcodeR lANd

出力例 3

No

大文字と小文字は区別します。

Score : 100 points

Problem Statement

Takahashi is heading to AtCoder Land. There is a signboard in front of him, and he wants to determine whether it says AtCoder Land.

You are given two strings S and T separated by a space. Determine whether S= AtCoder and T= Land.

Constraints

  • S and T are strings consisting of uppercase and lowercase English letters, with lengths between 1 and 10, inclusive.

Input

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

S T

Output

If S= AtCoder and T= Land, print Yes; otherwise, print No.


Sample Input 1

AtCoder Land

Sample Output 1

Yes

S= AtCoder and T= Land.


Sample Input 2

CodeQUEEN Land

Sample Output 2

No

S is not AtCoder.


Sample Input 3

aTcodeR lANd

Sample Output 3

No

Uppercase and lowercase letters are distinguished.

C - Next

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

N 個の整数 A_1, A_2, \ldots, A_N が与えられます。 このうち最大でない整数の中で最大である整数を求めてください。

ただし、この問題の制約下で答えは必ず存在します。

制約

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq 100
  • A_1, A_2, \ldots, A_N がすべて等しいということはない
  • 入力値はすべて整数

入力

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

N
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

5
2 1 3 3 2

出力例 1

2

2,1,3,3,2 の中で最大である整数は 3 です。

2,1,3,3,2 の中で 3 でない整数は 2,1,23 つであり、これらの中で最大である整数は 2 です。


入力例 2

4
4 3 2 1

出力例 2

3

入力例 3

8
22 22 18 16 22 18 18 22

出力例 3

18

Score : 200 points

Problem Statement

You are given N integers A_1, A_2, \ldots, A_N. Find the largest among those integers that are not the largest.

The constraints of this problem guarantee that the answer exists.

Constraints

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq 100
  • It is not the case that all A_1, A_2, \ldots, A_N are equal.
  • All input values are integers.

Input

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

N
A_1 A_2 \ldots A_N

Output

Print the answer.


Sample Input 1

5
2 1 3 3 2

Sample Output 1

2

The largest integer among 2,1,3,3,2 is 3.

The integers that are not 3 among 2,1,3,3,2 are 2,1,2, among which the largest is 2.


Sample Input 2

4
4 3 2 1

Sample Output 2

3

Sample Input 3

8
22 22 18 16 22 18 18 22

Sample Output 3

18
D - cat 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

N 種類の文字列 S _ 1,S _ 2,\ldots,S _ N が与えられます。

あなたは、次の操作を 1 度だけ行います。

  • 相異なる整数 i,j\ (1\le i\le N,1\le j\le N) を選び、S _ iS _ j をこの順で連結する。

この操作で連結した結果の文字列としてありえるものは何通りあるか求めてください。

選んだ (i,j) が異なっても、連結した文字列が同じ場合は 1 通りと数えることに注意してください。

制約

  • 2\le N\le100
  • N は整数
  • S _ i は英小文字からなる長さ 1 以上 10 以下の文字列
  • S _ i\ne S _ j\ (1\le i\lt j\le N)

入力

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

N
S _ 1
S _ 2
\vdots
S _ N

出力

操作の結果できる文字列が何通りあるかを出力せよ。


入力例 1

4
at
atco
coder
der

出力例 1

11

できる文字列は、atatco, atcoat, atcoder, atcocoder, atder, coderat, coderatco, coderder, derat, deratco, dercoder11 通りです。

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


入力例 2

5
a
aa
aaa
aaaa
aaaaa

出力例 2

7

できる文字列は、aaa, aaaa, aaaaa, aaaaaa, aaaaaaa, aaaaaaaa, aaaaaaaaa7 通りです。

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


入力例 3

10
armiearggc
ukupaunpiy
cogzmjmiob
rtwbvmtruq
qapfzsitbl
vhkihnipny
ybonzypnsn
esxvgoudra
usngxmaqpt
yfseonwhgp

出力例 3

90

Score : 200 points

Problem Statement

You are given N types of strings S_1,S_2,\ldots,S_N.

You perform the following operation once:

  • Choose distinct integers i and j\ (1\le i\le N,1\le j\le N) and concatenate S_i and S_j in this order.

How many different strings can be obtained as a result of this operation?

If different choices of (i,j) result in the same concatenated string, it is counted as one string.

Constraints

  • 2\le N\le100
  • N is an integer.
  • S_i is a string of length between 1 and 10, inclusive, consisting of lowercase English letters.
  • S_i\ne S_j\ (1\le i\lt j\le N)

Input

The input is given from standard input in the following format:

N
S_1
S_2
\vdots
S_N

Output

Print the number of different strings that can be obtained from the operation.


Sample Input 1

4
at
atco
coder
der

Sample Output 1

11

The possible strings are atatco, atcoat, atcoder, atcocoder, atder, coderat, coderatco, coderder, derat, deratco, dercoder, which are 11 strings.

Thus, print 11.


Sample Input 2

5
a
aa
aaa
aaaa
aaaaa

Sample Output 2

7

The possible strings are aaa, aaaa, aaaaa, aaaaaa, aaaaaaa, aaaaaaaa, aaaaaaaaa, which are 7 strings.

Thus, print 7.


Sample Input 3

10
armiearggc
ukupaunpiy
cogzmjmiob
rtwbvmtruq
qapfzsitbl
vhkihnipny
ybonzypnsn
esxvgoudra
usngxmaqpt
yfseonwhgp

Sample Output 3

90
E - Various Kagamimochi

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

N 個の餅が小さいほうから順に並んでいます。 i 番目 (1\leq i\leq N) の餅の大きさは A _ i です。

2 つの餅 A,B の大きさをそれぞれ a,b としたとき、ab の半分以下であるとき、かつそのときに限り、餅 A を餅 B の上に乗せて鏡餅を 1 つ作ることができます。

N 個の餅から 2 つの餅を選び、一方をもう一方の上に乗せることで鏡餅を 1 つ作ります。

何種類の鏡餅を作ることができるか求めてください。

ただし、鏡餅を構成する餅の大きさが同じでも、少なくとも一方が異なる餅であれば別の種類の鏡餅として数えます。

制約

  • 2\leq N\leq 5\times 10 ^ 5
  • 1\leq A _ i\leq 10 ^ 9\ (1\leq i\leq N)
  • A _ i\leq A _ {i+1}\ (1\leq i\lt N)
  • 入力はすべて整数

入力

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

N
A _ 1 A _ 2 \cdots A _ N

出力

作ることができる鏡餅の種類数を出力せよ。


入力例 1

6
2 3 4 4 7 10

出力例 1

8

与えられた餅の大きさは以下のようになっています。

このとき、以下の 8 種類の鏡餅を作ることができます。

大きさ 4 の餅の上に大きさ 2 の餅を乗せた鏡餅や、大きさ 10 の餅の上に大きさ 4 の餅を乗せた鏡餅は 2 種類あることに注意してください。


入力例 2

3
387 388 389

出力例 2

0

鏡餅を 1 種類も作ることができない場合もあります。


入力例 3

32
1 2 4 5 8 10 12 16 19 25 33 40 50 64 87 101 149 175 202 211 278 314 355 405 412 420 442 481 512 582 600 641

出力例 3

388

Score : 300 points

Problem Statement

There are N mochi (rice cakes) arranged in ascending order of size. The size of the i-th mochi (1 \leq i \leq N) is A_i.

Given two mochi A and B, with sizes a and b respectively, you can make one kagamimochi (a stacked rice cake) by placing mochi A on top of mochi B if and only if a is at most half of b.

You choose two mochi out of the N mochi, and place one on top of the other to form one kagamimochi.

Find how many different kinds of kagamimochi can be made.

Two kagamimochi are distinguished if at least one of the mochi is different, even if the sizes of the mochi are the same.

Constraints

  • 2 \leq N \leq 5 \times 10^5
  • 1 \leq A_i \leq 10^9 \ (1 \leq i \leq N)
  • A_i \leq A_{i+1} \ (1 \leq i < N)
  • All input values are integers.

Input

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

N
A_1 A_2 \cdots A_N

Output

Print the number of different kinds of kagamimochi that can be made.


Sample Input 1

6
2 3 4 4 7 10

Sample Output 1

8

The sizes of the given mochi are as follows:

In this case, you can make the following eight kinds of kagamimochi:

Note that there are two kinds of kagamimochi where a mochi of size 4 is topped by a mochi of size 2, and two kinds where a mochi of size 10 is topped by a mochi of size 4.


Sample Input 2

3
387 388 389

Sample Output 2

0

It is possible that you cannot make any kagamimochi.


Sample Input 3

32
1 2 4 5 8 10 12 16 19 25 33 40 50 64 87 101 149 175 202 211 278 314 355 405 412 420 442 481 512 582 600 641

Sample Output 3

388