A - Time Normalization

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

高橋君は、料理教室の予約管理システムを開発しています。このシステムでは、各予約の開始時刻を時と分の組で管理しています。

しかし、入力フォームの不具合により、分の値が 60 以上になっていたり、時の値が 24 以上になっていたりする不正なデータが登録されてしまうことがあります。例えば、2580 分のような時刻データが存在します。

高橋君は、これらの不正な時刻データを正規化するプログラムを作成することにしました。正規化とは、与えられた時刻データ(時 H、分 M)を、ある日の 00 分を基準としてちょうど (60H + M) 分が経過した時刻とみなし、「D 日後の hm 分」(ただし 0 \leq h \leq 230 \leq m \leq 59D \geq 0)の形に変換することです。

正規化の計算は以下の手順で行えます。手順 1、手順 2 の順に実行してください。

  1. 分の繰り上げ: 分の値 M60= 1 時間として時に繰り上げます。具体的には、繰り上げ後の時の値を H' = H + \lfloor M / 60 \rfloor、正規化後の分の値を m = M \bmod 60 とします。
  2. 時の繰り上げ: 手順 1 で得た時の値 H'24 時間 = 1 日として日数に繰り上げます。具体的には、正規化後の日数を D = \lfloor H' / 24 \rfloor、正規化後の時の値を h = H' \bmod 24 とします。

以上により、正規化後の日数 DD = 0 は基準日の当日を意味します)、時 h0 \leq h \leq 23)、分 m0 \leq m \leq 59)が定まります。

N 件の予約の開始時刻データが与えられるので、それぞれを正規化し、正規化後の日数 D、時 h、分 m を出力してください。

制約

  • 1 \leq N \leq 10^5
  • 0 \leq H_i \leq 10^9
  • 0 \leq M_i \leq 10^9
  • 入力はすべて整数である。

入力

N
H_1 M_1
H_2 M_2
\vdots
H_N M_N

1 行目には、予約の件数を表す整数 N が与えられます。続く N 行のうち i 行目 (1 \leq i \leq N) には、i 番目の予約の時を表す整数 H_i と分を表す整数 M_i が、スペース区切りで与えられます。

出力

N 行出力してください。i 行目には、i 番目の予約データ (H_i, M_i) に対して上記の正規化を行って得られる日数 D_i、時 h_i、分 m_i を、スペース区切りで出力してください。


入力例 1

3
10 30
25 80
0 90

出力例 1

0 10 30
1 2 20
0 1 30

入力例 2

4
23 59
24 0
0 1440
48 120

出力例 2

0 23 59
1 0 0
1 0 0
2 2 0

入力例 3

8
0 0
12 30
23 59
24 60
100 200
0 1500
50 0
47 61

出力例 3

0 0 0
0 12 30
0 23 59
1 1 0
4 7 20
1 1 0
2 2 0
2 0 1

入力例 4

15
0 0
1 0
0 1
23 59
24 0
24 1
0 60
25 80
100 100
999 999
10000 10000
123456 789012
1000000000 1000000000
999999999 999999999
500000000 500000000

出力例 4

0 0 0
0 1 0
0 0 1
0 23 59
1 0 0
1 0 1
0 1 0
1 2 20
4 5 40
42 7 39
423 14 40
5691 22 12
42361111 2 40
42361111 1 39
21180555 13 20

入力例 5

1
0 0

出力例 5

0 0 0

Score : 200 pts

Problem Statement

Takahashi is developing a reservation management system for a cooking class. In this system, the start time of each reservation is managed as a pair of hours and minutes.

However, due to a bug in the input form, invalid data may be registered where the minute value is 60 or greater, or the hour value is 24 or greater. For example, time data such as 25 hours 80 minutes may exist.

Takahashi decided to create a program to normalize these invalid time data. Normalization means treating the given time data (hours H, minutes M) as the time exactly (60H + M) minutes after 0 hours 0 minutes of a certain day, and converting it into the form "D days later, h hours m minutes" (where 0 \leq h \leq 23, 0 \leq m \leq 59, D \geq 0).

The normalization calculation can be performed by the following steps. Execute Step 1, then Step 2, in order.

  1. Carry-over of minutes: Carry over the minute value M into hours, using 60 minutes = 1 hour. Specifically, the hour value after carry-over is H' = H + \lfloor M / 60 \rfloor, and the normalized minute value is m = M \bmod 60.
  2. Carry-over of hours: Carry over the hour value H' obtained in Step 1 into days, using 24 hours = 1 day. Specifically, the normalized number of days is D = \lfloor H' / 24 \rfloor, and the normalized hour value is h = H' \bmod 24.

Through the above, the normalized number of days D (D = 0 means the reference day itself), hours h (0 \leq h \leq 23), and minutes m (0 \leq m \leq 59) are determined.

Given the start time data of N reservations, normalize each of them and output the normalized number of days D, hours h, and minutes m.

Constraints

  • 1 \leq N \leq 10^5
  • 0 \leq H_i \leq 10^9
  • 0 \leq M_i \leq 10^9
  • All input values are integers.

Input

N
H_1 M_1
H_2 M_2
\vdots
H_N M_N

The first line contains an integer N representing the number of reservations. Of the following N lines, the i-th line (1 \leq i \leq N) contains an integer H_i representing the hours and an integer M_i representing the minutes of the i-th reservation, separated by a space.

Output

Output N lines. On the i-th line, output the number of days D_i, hours h_i, and minutes m_i obtained by performing the above normalization on the i-th reservation data (H_i, M_i), separated by spaces.


Sample Input 1

3
10 30
25 80
0 90

Sample Output 1

0 10 30
1 2 20
0 1 30

Sample Input 2

4
23 59
24 0
0 1440
48 120

Sample Output 2

0 23 59
1 0 0
1 0 0
2 2 0

Sample Input 3

8
0 0
12 30
23 59
24 60
100 200
0 1500
50 0
47 61

Sample Output 3

0 0 0
0 12 30
0 23 59
1 1 0
4 7 20
1 1 0
2 2 0
2 0 1

Sample Input 4

15
0 0
1 0
0 1
23 59
24 0
24 1
0 60
25 80
100 100
999 999
10000 10000
123456 789012
1000000000 1000000000
999999999 999999999
500000000 500000000

Sample Output 4

0 0 0
0 1 0
0 0 1
0 23 59
1 0 0
1 0 1
0 1 0
1 2 20
4 5 40
42 7 39
423 14 40
5691 22 12
42361111 2 40
42361111 1 39
21180555 13 20

Sample Input 5

1
0 0

Sample Output 5

0 0 0
B - Choosing Snacks for a Field Trip

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

高橋君のクラスでは M 日間の合宿が予定されています。合宿の各日にはおやつの予算が決まっており、日 j1 \leq j \leq M )のおやつ予算は S_j 円です。

合宿に持っていくおやつは、お店に並んでいる N 種類の商品の中から 1 種類だけ選び、合宿期間中は毎日そのおやつを 1 つずつ購入して食べることになります。商品 i の価格は R_i 円です。

高橋君は、すべての日においておやつの価格が予算以下であるような商品を選びたいです。すなわち、すべての日 j について R_i \leq S_j が成り立つような商品 i を選びたいです。

このような条件を満たす商品の数を求めてください。

制約

  • 1 \leq N \leq 10^6
  • 1 \leq M \leq 10^6
  • 1 \leq R_i \leq 10^91 \leq i \leq N
  • 1 \leq S_j \leq 10^91 \leq j \leq M
  • 入力はすべて整数である

入力

N M
R_1 R_2 \ldots R_N
S_1 S_2 \ldots S_M
  • 1 行目には、商品の種類数を表す N と、合宿の日数を表す M が、スペース区切りで与えられる。
  • 2 行目には、各商品の価格を表す R_1, R_2, \ldots, R_N が、スペース区切りで与えられる。
  • 3 行目には、各日のおやつ予算を表す S_1, S_2, \ldots, S_M が、スペース区切りで与えられる。

出力

条件を満たす商品の数を 1 行で出力してください。


入力例 1

5 3
100 200 300 400 500
350 300 450

出力例 1

3

入力例 2

3 4
100 200 300
50 60 70 80

出力例 2

0

入力例 3

12 8
120 500 450 300 800 450 100 700 600 250 449 451
1000 900 450 800 700 600 500 550

出力例 3

7

入力例 4

30 20
1500 999 1000 1001 750 2000 50 300 1200 980 1100 1020 999 100 5000 250 875 1000 1 450 650 700 800 900 10000 1050 990 995 996 997
2000 1500 1200 1100 1050 1000 1300 1400 1600 1700 1800 1900 1250 1150 1080 1020 1010 1005 1000 3000

出力例 4

21

入力例 5

1 1
1000000000
1000000000

出力例 5

1

Score : 300 pts

Problem Statement

Takahashi's class has a training camp planned for M days. Each day of the camp has a fixed snack budget, and the snack budget for day j (1 \leq j \leq M) is S_j yen.

For the snacks to bring to the camp, he must choose exactly 1 type of product from the N types of products available at the store, and during the camp he will purchase and eat one of that snack each day. The price of product i is R_i yen.

Takahashi wants to choose a product such that the price of the snack is within the budget on every day. In other words, he wants to choose a product i such that R_i \leq S_j holds for every day j.

Find the number of products that satisfy this condition.

Constraints

  • 1 \leq N \leq 10^6
  • 1 \leq M \leq 10^6
  • 1 \leq R_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq S_j \leq 10^9 (1 \leq j \leq M)
  • All input values are integers

Input

N M
R_1 R_2 \ldots R_N
S_1 S_2 \ldots S_M
  • The first line contains N, the number of product types, and M, the number of days of the camp, separated by a space.
  • The second line contains the prices of each product R_1, R_2, \ldots, R_N, separated by spaces.
  • The third line contains the snack budget for each day S_1, S_2, \ldots, S_M, separated by spaces.

Output

Print the number of products that satisfy the condition on a single line.


Sample Input 1

5 3
100 200 300 400 500
350 300 450

Sample Output 1

3

Sample Input 2

3 4
100 200 300
50 60 70 80

Sample Output 2

0

Sample Input 3

12 8
120 500 450 300 800 450 100 700 600 250 449 451
1000 900 450 800 700 600 500 550

Sample Output 3

7

Sample Input 4

30 20
1500 999 1000 1001 750 2000 50 300 1200 980 1100 1020 999 100 5000 250 875 1000 1 450 650 700 800 900 10000 1050 990 995 996 997
2000 1500 1200 1100 1050 1000 1300 1400 1600 1700 1800 1900 1250 1150 1080 1020 1010 1005 1000 3000

Sample Output 4

21

Sample Input 5

1 1
1000000000
1000000000

Sample Output 5

1
C - Collecting Gems

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 366

問題文

高橋君は一本道の商店街で開催される宝石集めイベントに参加しています。商店街には左から順に N 個のお店が一列に並んでおり、i 番目 (1 \leq i \leq N) のお店には A_i 個の宝石が置かれています。

高橋君は最初、お店 S にいます。イベントのルールとして、高橋君はちょうど K 回の移動を行わなければなりません。1 回の移動では、現在いるお店から隣接するお店へ 1 つ移動します。すなわち、現在お店 p (1 \leq p \leq N) にいるとき、p-1 \geq 1 ならばお店 p-1 へ、p+1 \leq N ならばお店 p+1 へ移動できます。お店 1 より左やお店 N より右へ出ることはできません。同じお店を何度訪れてもかまいません。

高橋君は、訪れたお店(開始地点であるお店 S を含む)ごとに、そこに置かれている A_i 個の宝石を獲得できます。ただし、同じお店を複数回訪れた場合でも、宝石を獲得できるのは最初の 1 回のみです。

高橋君がちょうど K 回の移動を行うとき、獲得できる宝石の合計個数の最大値を求めてください。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq S \leq N
  • 1 \leq K \leq 10^9
  • 0 \leq A_i \leq 10^9
  • 入力はすべて整数である

入力

N S K
A_1 A_2 \ldots A_N
  • 1 行目には、お店の数を表す整数 N 、高橋君の初期位置を表す整数 S 、移動回数を表す整数 K が、スペース区切りで与えられる。
  • 2 行目には、各お店に置かれている宝石の個数を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。

出力

高橋君が獲得できる宝石の合計個数の最大値を 1 行で出力せよ。


入力例 1

5 3 2
10 20 30 40 50

出力例 1

120

入力例 2

4 1 3
5 100 1 10

出力例 2

116

入力例 3

12 6 8
3 15 8 20 7 50 6 12 30 4 25 10

出力例 3

144

入力例 4

30 17 25
12 0 45 23 78 5 90 34 11 67 8 56 100 3 29 74 41 62 18 95 7 36 84 21 50 69 14 88 2 31

出力例 4

922

入力例 5

2 1 1000000000
1000000000 0

出力例 5

1000000000

Score : 366 pts

Problem Statement

Takahashi is participating in a gem collecting event held on a straight shopping street. There are N shops lined up in a row from left to right on the street, and the i-th shop (1 \leq i \leq N) has A_i gems placed in it.

Takahashi starts at shop S. According to the event rules, Takahashi must make exactly K moves. In one move, he moves from his current shop to an adjacent shop. That is, when he is currently at shop p (1 \leq p \leq N), he can move to shop p-1 if p-1 \geq 1, or to shop p+1 if p+1 \leq N. He cannot go to the left of shop 1 or to the right of shop N. He may visit the same shop multiple times.

For each shop Takahashi visits (including shop S where he starts), he can collect the A_i gems placed there. However, even if he visits the same shop multiple times, he can only collect the gems on the first visit.

Determine the maximum total number of gems Takahashi can collect when he makes exactly K moves.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq S \leq N
  • 1 \leq K \leq 10^9
  • 0 \leq A_i \leq 10^9
  • All inputs are integers

Input

N S K
A_1 A_2 \ldots A_N
  • The first line contains an integer N representing the number of shops, an integer S representing Takahashi's initial position, and an integer K representing the number of moves, separated by spaces.
  • The second line contains integers A_1, A_2, \ldots, A_N representing the number of gems placed in each shop, separated by spaces.

Output

Print the maximum total number of gems Takahashi can collect in one line.


Sample Input 1

5 3 2
10 20 30 40 50

Sample Output 1

120

Sample Input 2

4 1 3
5 100 1 10

Sample Output 2

116

Sample Input 3

12 6 8
3 15 8 20 7 50 6 12 30 4 25 10

Sample Output 3

144

Sample Input 4

30 17 25
12 0 45 23 78 5 90 34 11 67 8 56 100 3 29 74 41 62 18 95 7 36 84 21 50 69 14 88 2 31

Sample Output 4

922

Sample Input 5

2 1 1000000000
1000000000 0

Sample Output 5

1000000000
D - Selection of Research Topic

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

高橋君は大学の研究室に所属しており、今学期取り組む研究テーマを選ぼうとしています。研究室には N 個の研究テーマの候補があり、各テーマには 1 から N までの番号が付けられています。研究テーマ i に取り組むには、実験機材や資料の準備として C_i の費用がかかり、取り組んだ際に得られる学術的成果の価値は P_i と見積もられています。

研究テーマの間には M 個の前提関係が存在します。j 番目の前提関係は組 (U_j, V_j) で表され、研究テーマ U_j に取り組むならば研究テーマ V_j にも取り組まなければならないという制約を意味します(逆は必ずしも成り立ちません)。なお、前提関係は循環を含む場合があります。例えば、研究テーマ AB を前提とし、BA を前提とするような状況もあり得ます。この場合、AB はどちらか一方だけを選ぶことはできず、両方選ぶか両方選ばないかのいずれかになります。

高橋君は、取り組む研究テーマの集合 SS \subseteq \{1, 2, \ldots, N\})を選びます。S は前提関係をすべて満たしている必要があります。すなわち、すべての j = 1, 2, \ldots, M について、研究テーマ U_jS に含まれるならば研究テーマ V_jS に含まれていなければなりません。S は空集合でも構いません。

高橋君の目標は、選んだ研究テーマから得られる成果の価値の合計から費用の合計を引いた値、すなわち

\sum_{i \in S} (P_i - C_i)

を最大化することです。S が空集合の場合、この値は 0 とします。

この最大値を求めてください。

制約

  • 1 \leq N \leq 15
  • 0 \leq M \leq \frac{N(N-1)}{2}
  • 1 \leq P_i \leq 10001 \leq i \leq N
  • 1 \leq C_i \leq 10001 \leq i \leq N
  • 1 \leq U_j, V_j \leq N1 \leq j \leq M
  • U_j \neq V_j1 \leq j \leq M
  • 前提関係に重複はない。すなわち、(U_j, V_j) の組はすべて異なる。ただし、ある j, k について (U_j, V_j) = (V_k, U_k) となること(すなわち逆向きの関係が同時に存在すること)はあり得る。
  • 前提関係は循環を含みうる。すなわち、前提関係によって定まる有向グラフが非巡回であるとは限らない。
  • 入力はすべて整数である。

入力

N M
P_1 C_1
P_2 C_2
\vdots
P_N C_N
U_1 V_1
U_2 V_2
\vdots
U_M V_M
  • 1 行目には、研究テーマの数 N と前提関係の数 M が、スペース区切りで与えられる。
  • 続く N 行のうち i 行目(1 \leq i \leq N)には、研究テーマ i の成果の価値 P_i と費用 C_i がスペース区切りで与えられる。
  • 続く M 行のうち j 行目(1 \leq j \leq M)には、j 番目の前提関係を表す U_jV_j がスペース区切りで与えられる。これは研究テーマ U_j に取り組むならば研究テーマ V_j にも取り組まなければならないことを意味する。

出力

前提関係をすべて満たす研究テーマの集合 S を選んだときの、\sum_{i \in S} (P_i - C_i) の最大値を 1 行で出力せよ。


入力例 1

3 1
10 3
5 8
8 2
1 2

出力例 1

10

入力例 2

2 1
1 5
2 6
1 2

出力例 2

0

入力例 3

6 5
20 13
15 19
18 14
10 13
25 10
8 20
1 2
2 1
3 4
5 6
6 5

出力例 3

7

入力例 4

10 12
50 30
40 45
30 10
25 40
60 20
35 50
20 15
45 25
10 30
55 35
1 2
2 3
3 1
4 5
5 6
6 4
7 8
8 9
9 7
10 1
4 7
8 10

出力例 4

70

入力例 5

1 0
5 3

出力例 5

2

Score : 400 pts

Problem Statement

Takahashi belongs to a university research lab and is trying to choose research topics to work on this semester. The lab has N candidate research topics, each numbered from 1 to N. Working on research topic i requires a cost of C_i for preparing experimental equipment and materials, and the value of academic results obtained from working on it is estimated to be P_i.

There are M prerequisite relationships among the research topics. The j-th prerequisite relationship is represented by the pair (U_j, V_j), meaning that if you work on research topic U_j, you must also work on research topic V_j (the converse does not necessarily hold). Note that prerequisite relationships may contain cycles. For example, a situation where research topic A requires B as a prerequisite and B requires A as a prerequisite is possible. In this case, you cannot choose only one of A and B; you must either choose both or choose neither.

Takahashi selects a set S (S \subseteq \{1, 2, \ldots, N\}) of research topics to work on. S must satisfy all prerequisite relationships. That is, for all j = 1, 2, \ldots, M, if research topic U_j is included in S, then research topic V_j must also be included in S. S may be the empty set.

Takahashi's goal is to maximize the total value of results obtained from the chosen research topics minus the total cost, namely

\sum_{i \in S} (P_i - C_i)

If S is the empty set, this value is 0.

Find this maximum value.

Constraints

  • 1 \leq N \leq 15
  • 0 \leq M \leq \frac{N(N-1)}{2}
  • 1 \leq P_i \leq 1000 (1 \leq i \leq N)
  • 1 \leq C_i \leq 1000 (1 \leq i \leq N)
  • 1 \leq U_j, V_j \leq N (1 \leq j \leq M)
  • U_j \neq V_j (1 \leq j \leq M)
  • There are no duplicate prerequisite relationships. That is, all pairs (U_j, V_j) are distinct. However, it is possible that (U_j, V_j) = (V_k, U_k) for some j, k (i.e., reverse relationships may coexist).
  • Prerequisite relationships may contain cycles. That is, the directed graph defined by the prerequisite relationships is not necessarily acyclic.
  • All inputs are integers.

Input

N M
P_1 C_1
P_2 C_2
\vdots
P_N C_N
U_1 V_1
U_2 V_2
\vdots
U_M V_M
  • The first line contains the number of research topics N and the number of prerequisite relationships M, separated by a space.
  • In the following N lines, the i-th line (1 \leq i \leq N) contains the result value P_i and cost C_i of research topic i, separated by a space.
  • In the following M lines, the j-th line (1 \leq j \leq M) contains U_j and V_j representing the j-th prerequisite relationship, separated by a space. This means that if you work on research topic U_j, you must also work on research topic V_j.

Output

Output in a single line the maximum value of \sum_{i \in S} (P_i - C_i) when choosing a set S of research topics that satisfies all prerequisite relationships.


Sample Input 1

3 1
10 3
5 8
8 2
1 2

Sample Output 1

10

Sample Input 2

2 1
1 5
2 6
1 2

Sample Output 2

0

Sample Input 3

6 5
20 13
15 19
18 14
10 13
25 10
8 20
1 2
2 1
3 4
5 6
6 5

Sample Output 3

7

Sample Input 4

10 12
50 30
40 45
30 10
25 40
60 20
35 50
20 15
45 25
10 30
55 35
1 2
2 3
3 1
4 5
5 6
6 4
7 8
8 9
9 7
10 1
4 7
8 10

Sample Output 4

70

Sample Input 5

1 0
5 3

Sample Output 5

2
E - Product of Digits and Multiples

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 433

問題文

高橋君は、 1 から N までの整数について調べています。

正の整数 k を十進法で表記したとき、各桁の数字をすべて掛け合わせた値を k の「桁積」と呼ぶことにします。例えば、 123 の桁積は 1 \times 2 \times 3 = 6205 の桁積は 2 \times 0 \times 5 = 09 の桁積は 9 です。

高橋君は、 1 以上 N 以下の整数のうち、桁積が 0 でなく、かつその桁積が M の倍数であるものの個数を知りたがっています。高橋君に代わって、この個数を求めてください。

なお、 0 はどんな正の整数の倍数でもないものとします(すなわち、桁積が 0 のものは常に数えません)。

制約

  • 1 \leq N \leq 10^{18}
  • 1 \leq M \leq 500
  • N および M は整数である

入力

N M

調べる範囲の上限 N と、桁積が倍数であるかを判定する基準の値 M が、スペース区切りで 1 行に与えられる。

出力

1 以上 N 以下の整数のうち、桁積が 0 でなく、かつ桁積が M の倍数であるものの個数を 1 行で出力せよ。


入力例 1

25 6

出力例 1

3

入力例 2

20 7

出力例 2

2

入力例 3

12345 36

出力例 3

2767

入力例 4

987654321012345678 420

出力例 4

127763436760690150

入力例 5

1 1

出力例 5

1

Score : 433 pts

Problem Statement

Takahashi is investigating integers from 1 to N.

When a positive integer k is written in decimal notation, the product of all its digits is called the "digit product" of k. For example, the digit product of 123 is 1 \times 2 \times 3 = 6, the digit product of 205 is 2 \times 0 \times 5 = 0, and the digit product of 9 is 9.

Takahashi wants to know the number of integers between 1 and N (inclusive) whose digit product is not 0 and whose digit product is a multiple of M. Find this count on behalf of Takahashi.

Note that 0 is not a multiple of any positive integer (that is, integers whose digit product is 0 are never counted).

Constraints

  • 1 \leq N \leq 10^{18}
  • 1 \leq M \leq 500
  • N and M are integers

Input

N M

The upper limit N of the range to investigate and the value M used to determine whether the digit product is a multiple are given on a single line, separated by a space.

Output

Output in one line the number of integers between 1 and N (inclusive) whose digit product is not 0 and whose digit product is a multiple of M.


Sample Input 1

25 6

Sample Output 1

3

Sample Input 2

20 7

Sample Output 2

2

Sample Input 3

12345 36

Sample Output 3

2767

Sample Input 4

987654321012345678 420

Sample Output 4

127763436760690150

Sample Input 5

1 1

Sample Output 5

1