Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 266 点
問題文
高橋君はカードゲームで遊んでいます。
テーブルの上に N 枚のカードが一列に並べられています。左から i 番目のカードを「カード i」と呼び、カード i には攻撃力 A_i が書かれています。
高橋君は、i = 1, 2, \ldots, N-1 の順に、各 i についてちょうど一度ずつ以下の処理を行います。ここで処理の対象は、テーブル上で物理的に隣接しているカードではなく、番号が i と i+1 であるカードのペアです。カードの番号はテーブルから取り除かれた後も変わりません。
- カード i とカード i+1 のうち少なくとも一方がすでにテーブルから取り除かれている場合は、何もしない。
- カード i とカード i+1 がともにテーブルに残っている場合、両者のその時点での攻撃力を比較する。
- 攻撃力が等しい場合は、何もしない。
- 攻撃力が異なる場合は、攻撃力が大きい方のカードがもう一方を吸収する。具体的には、攻撃力 X のカードが攻撃力 Y(X > Y)のカードを吸収すると、次のことが起こる。
- 吸収された側(攻撃力 Y)のカードはテーブルから取り除かれ、以降の処理ではテーブルに残っていないものとして扱われる。
- 吸収した側のカードはそのままの番号でテーブルに残り、攻撃力が X + \lfloor Y / 2 \rfloor に更新される。ここで \lfloor \cdot \rfloor は床関数(小数点以下切り捨て)を表す。この更新された攻撃力が、以降の処理で用いられる。
なお、カードの攻撃力は吸収によって変化しうるため、各処理の時点での最新の攻撃力が比較に用いられることに注意してください。
i = N-1 までの処理がすべて終了した後、テーブルに残っているカードの枚数を求めてください。
制約
- 1 \leq N \leq 10^6
- 1 \leq A_i \leq 10^9
- 入力はすべて整数である。
入力
N A_1 A_2 \ldots A_N
- 1 行目には、カードの枚数を表す整数 N が与えられる。
- 2 行目には、各カードの攻撃力を表す N 個の整数 A_1, A_2, \ldots, A_N がスペース区切りで与えられる。
出力
すべての処理が終了した後にテーブルに残っているカードの枚数を 1 行で出力せよ。
入力例 1
5 3 1 4 1 5
出力例 1
3
入力例 2
4 2 2 2 2
出力例 2
4
入力例 3
10 5 3 8 6 2 7 1 9 4 10
出力例 3
5
入力例 4
20 100 37 85 12 99 44 67 23 78 56 91 33 72 15 88 41 63 29 50 1000000000
出力例 4
10
入力例 5
1 1
出力例 5
1
Score : 266 pts
Problem Statement
Takahashi is playing a card game.
N cards are arranged in a row on the table. The i-th card from the left is called "card i", and card i has an attack power of A_i written on it.
Takahashi performs the following operation exactly once for each i, in the order i = 1, 2, \ldots, N-1. Note that the operation targets the pair of cards with numbers i and i+1, not cards that are physically adjacent on the table. A card's number does not change even after it is removed from the table.
- If at least one of card i and card i+1 has already been removed from the table, do nothing.
- If both card i and card i+1 remain on the table, compare their current attack powers.
- If their attack powers are equal, do nothing.
- If their attack powers differ, the card with the higher attack power absorbs the other. Specifically, when a card with attack power X absorbs a card with attack power Y (X > Y), the following occurs:
- The absorbed card (with attack power Y) is removed from the table and is treated as no longer on the table in subsequent operations.
- The absorbing card remains on the table with the same number, and its attack power is updated to X + \lfloor Y / 2 \rfloor, where \lfloor \cdot \rfloor denotes the floor function (rounding down to the nearest integer). This updated attack power is used in subsequent operations.
Note that since a card's attack power can change through absorption, the latest attack power at the time of each operation is used for comparison.
After all operations up to i = N-1 have been completed, find the number of cards remaining on the table.
Constraints
- 1 \leq N \leq 10^6
- 1 \leq A_i \leq 10^9
- All input values are integers.
Input
N A_1 A_2 \ldots A_N
- The first line contains an integer N representing the number of cards.
- The second line contains N integers A_1, A_2, \ldots, A_N separated by spaces, representing the attack power of each card.
Output
Print in one line the number of cards remaining on the table after all operations have been completed.
Sample Input 1
5 3 1 4 1 5
Sample Output 1
3
Sample Input 2
4 2 2 2 2
Sample Output 2
4
Sample Input 3
10 5 3 8 6 2 7 1 9 4 10
Sample Output 3
5
Sample Input 4
20 100 37 85 12 99 44 67 23 78 56 91 33 72 15 88 41 63 29 50 1000000000
Sample Output 4
10
Sample Input 5
1 1
Sample Output 5
1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は大学の奨学金選考委員会の担当者として、今年度の奨学金受給者を決定する作業を任されています。
今年の奨学金には N 人の学生が応募しており、それぞれの学生には 1 から N までの番号が付けられています。選考では M 科目の成績(点数)が評価対象となっており、学生 i の科目 j における成績は S_{i,j} 点です。
また、各科目 j にはそれぞれ最低基準点 T_j が設定されています。奨学金の受給者は以下の手順で決定されます。
ステップ 1:基準通過者の決定
学生 i が すべての 科目 j (1 \leq j \leq M) について S_{i,j} \geq T_j を満たすとき、その学生を「基準通過者」と呼びます。
ステップ 2:受給者の決定
基準通過者の人数に応じて、以下のように受給者を決定します。ここで K は選考の基準人数として与えられる正の整数です。
- 基準通過者が K 人以下の場合、基準通過者全員を受給者とします。特に、基準通過者が 0 人の場合、受給者は 0 人です。
- 基準通過者が K 人より多い場合、次のようにして受給者を選びます。各基準通過者 i について、全科目の成績の合計点 \displaystyle P_i = \sum_{j=1}^{M} S_{i,j} を求めます。基準通過者全員の P_i の値を降順にソートしたとき、大きい方から K 番目の値をボーダーライン B とします(基準通過者は K 人より多いので、K 番目の値は必ず存在します)。P_i \geq B であるような基準通過者全員を受給者とします。
> 注意: ボーダーライン B と同じ合計点を持つ基準通過者が複数いる場合、受給者の人数は K 人を超えることがあります。
高橋君の代わりに、受給者の学生番号を求めてください。
制約
- 1 \leq N \leq 10^5
- 1 \leq M \leq 10
- 1 \leq K \leq N
- 0 \leq T_j \leq 1000 (1 \leq j \leq M)
- 0 \leq S_{i,j} \leq 1000 (1 \leq i \leq N, 1 \leq j \leq M)
- 入力はすべて整数である。
入力
N M K
T_1 T_2 \ldots T_M
S_{1,1} S_{1,2} \ldots S_{1,M}
S_{2,1} S_{2,2} \ldots S_{2,M}
\vdots
S_{N,1} S_{N,2} \ldots S_{N,M}
- 1 行目には、応募した学生の人数を表す整数 N、科目の数を表す整数 M、選考の基準人数を表す整数 K が、スペース区切りで与えられる。
- 2 行目には、各科目の最低基準点を表す整数 T_1, T_2, \ldots, T_M が、スペース区切りで与えられる。
- 3 行目から N + 2 行目までの N 行では、各学生の成績が与えられる。
- 2 + i 行目には、学生 i の各科目の成績を表す整数 S_{i,1}, S_{i,2}, \ldots, S_{i,M} がスペース区切りで与えられる。
出力
受給者の学生番号を昇順に、1 行に 1 つずつ出力してください。受給者が 0 人の場合は何も出力しないでください(空出力)。
入力例 1
5 3 2 50 60 55 80 70 60 40 80 70 90 65 80 55 60 55 70 75 90
出力例 1
3 5
入力例 2
8 2 3 30 30 50 50 80 90 40 60 70 80 20 90 60 90 90 80 35 65
出力例 2
2 4 6 7
入力例 3
10 4 5 70 65 60 75 80 70 65 80 50 90 80 70 75 68 62 90 60 65 70 80 90 80 75 85 72 66 61 76 30 40 50 60 85 70 60 80 70 65 60 74 95 85 80 90
出力例 3
1 3 5 8 10
Score : 300 pts
Problem Statement
Takahashi has been assigned the task of determining this year's scholarship recipients as a member of the university's scholarship selection committee.
This year, N students have applied for the scholarship, and each student is assigned a number from 1 to N. The selection evaluates grades (scores) in M subjects, where student i's score in subject j is S_{i,j} points.
Additionally, each subject j has a minimum threshold score T_j. The scholarship recipients are determined by the following procedure.
Step 1: Determining Qualifying Students
Student i is called a "qualifying student" if they satisfy S_{i,j} \geq T_j for all subjects j (1 \leq j \leq M).
Step 2: Determining Recipients
Recipients are determined based on the number of qualifying students as follows. Here, K is a positive integer given as the selection quota.
- If the number of qualifying students is K or fewer, all qualifying students become recipients. In particular, if there are 0 qualifying students, then there are 0 recipients.
- If the number of qualifying students is more than K, recipients are selected as follows. For each qualifying student i, compute the total score across all subjects \displaystyle P_i = \sum_{j=1}^{M} S_{i,j}. Sort the P_i values of all qualifying students in descending order, and let the K-th value from the top be the borderline B (since there are more than K qualifying students, the K-th value always exists). All qualifying students with P_i \geq B become recipients.
> Note: If multiple qualifying students have the same total score as the borderline B, the number of recipients may exceed K.
On behalf of Takahashi, determine the student numbers of the recipients.
Constraints
- 1 \leq N \leq 10^5
- 1 \leq M \leq 10
- 1 \leq K \leq N
- 0 \leq T_j \leq 1000 (1 \leq j \leq M)
- 0 \leq S_{i,j} \leq 1000 (1 \leq i \leq N, 1 \leq j \leq M)
- All input values are integers.
Input
N M K
T_1 T_2 \ldots T_M
S_{1,1} S_{1,2} \ldots S_{1,M}
S_{2,1} S_{2,2} \ldots S_{2,M}
\vdots
S_{N,1} S_{N,2} \ldots S_{N,M}
- The first line contains three space-separated integers: N representing the number of applicant students, M representing the number of subjects, and K representing the selection quota.
- The second line contains space-separated integers T_1, T_2, \ldots, T_M representing the minimum threshold scores for each subject.
- The following N lines (from line 3 to line N + 2) give each student's scores.
- The (2 + i)-th line contains space-separated integers S_{i,1}, S_{i,2}, \ldots, S_{i,M} representing student i's scores in each subject.
Output
Output the student numbers of the recipients in ascending order, one per line. If there are 0 recipients, output nothing (empty output).
Sample Input 1
5 3 2 50 60 55 80 70 60 40 80 70 90 65 80 55 60 55 70 75 90
Sample Output 1
3 5
Sample Input 2
8 2 3 30 30 50 50 80 90 40 60 70 80 20 90 60 90 90 80 35 65
Sample Output 2
2 4 6 7
Sample Input 3
10 4 5 70 65 60 75 80 70 65 80 50 90 80 70 75 68 62 90 60 65 70 80 90 80 75 85 72 66 61 76 30 40 50 60 85 70 60 80 70 65 60 74 95 85 80 90
Sample Output 3
1 3 5 8 10
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 366 点
問題文
高橋君は果樹園を経営しており、N 本の果物の木を一列に植えています。各木には番号 1 から N が付けられており、木 i には A_i 個の果物が実っています。
この果樹園の木は不思議な性質を持っており、何度収穫しても実っている果物の数は減りません。
各木の収穫ポイント P_i は初め 0 です。ある木に対して 1 回収穫を行うと、その木の収穫ポイントにその木に実っている果物の個数が加算されます。例えば、5 個の果物が実っている木に対して 3 回収穫を行うと、その木の収穫ポイントは 5 \times 3 = 15 になります。
収穫の季節になり、高橋君は M 日間かけて収穫作業を行います。
- j 日目には、番号 L_j から R_j までのすべての木(木 L_j, L_j + 1, \ldots, R_j)に対して 1 回ずつ収穫を行います。
すべての収穫作業が終わった後、各木の収穫ポイント P_1, P_2, \ldots, P_N を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq L_j \leq R_j \leq N
- 入力はすべて整数
- 答えは 64 ビット符号付き整数の範囲に収まる
入力
N M A_1 A_2 \cdots A_N L_1 R_1 L_2 R_2 \vdots L_M R_M
- 1 行目には、木の本数を表す N と、収穫作業を行う日数を表す M が、スペース区切りで与えられる。
- 2 行目には、各木に実っている果物の個数を表す A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
- 3 行目から M 行では、各日の収穫対象範囲が与えられる。
- 2 + j 行目では、j 日目に収穫する木の範囲の左端 L_j と右端 R_j が、スペース区切りで与えられる。
出力
P_1 P_2 \cdots P_N
各木の収穫ポイント P_1, P_2, \ldots, P_N を、スペース区切りで 1 行に出力してください。
入力例 1
5 3 3 1 4 1 5 1 3 2 4 3 5
出力例 1
3 2 12 2 5
入力例 2
7 5 10 20 30 40 50 60 70 1 7 2 5 3 3 1 4 5 7
出力例 2
20 60 120 120 150 120 140
入力例 3
10 8 100 200 300 400 500 600 700 800 900 1000 1 5 3 8 6 10 2 4 1 10 5 5 7 9 1 3
出力例 3
300 800 1500 1600 2000 1800 2800 3200 2700 2000
Score : 366 pts
Problem Statement
Takahashi manages an orchard and has planted N fruit trees in a row. Each tree is numbered from 1 to N, and tree i bears A_i fruits.
The trees in this orchard have a mysterious property: no matter how many times they are harvested, the number of fruits on them does not decrease.
The harvest points P_i of each tree are initially 0. When a tree is harvested once, the number of fruits on that tree is added to its harvest points. For example, if a tree bearing 5 fruits is harvested 3 times, its harvest points become 5 \times 3 = 15.
The harvest season has arrived, and Takahashi will carry out harvesting over M days.
- On day j, he harvests once from every tree numbered from L_j to R_j (trees L_j, L_j + 1, \ldots, R_j).
After all harvesting is complete, determine the harvest points P_1, P_2, \ldots, P_N of each tree.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq L_j \leq R_j \leq N
- All inputs are integers
- The answers fit within the range of a 64-bit signed integer
Input
N M A_1 A_2 \cdots A_N L_1 R_1 L_2 R_2 \vdots L_M R_M
- The first line contains N, the number of trees, and M, the number of days of harvesting, separated by a space.
- The second line contains A_1, A_2, \ldots, A_N, the number of fruits on each tree, separated by spaces.
- The following M lines give the harvest range for each day.
- The (2 + j)-th line contains the left endpoint L_j and right endpoint R_j of the range of trees to harvest on day j, separated by a space.
Output
P_1 P_2 \cdots P_N
Output the harvest points P_1, P_2, \ldots, P_N of each tree on a single line, separated by spaces.
Sample Input 1
5 3 3 1 4 1 5 1 3 2 4 3 5
Sample Output 1
3 2 12 2 5
Sample Input 2
7 5 10 20 30 40 50 60 70 1 7 2 5 3 3 1 4 5 7
Sample Output 2
20 60 120 120 150 120 140
Sample Input 3
10 8 100 200 300 400 500 600 700 800 900 1000 1 5 3 8 6 10 2 4 1 10 5 5 7 9 1 3
Sample Output 3
300 800 1500 1600 2000 1800 2800 3200 2700 2000
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
高橋君は健康のために、毎日の食事で野菜と果物をバランスよく摂ることを心がけています。N 日間の食事記録をまとめたところ、長さ N の文字列 S が得られました。S の i 文字目は i 日目の食事内容を表し、次のいずれかです。
V: 野菜のみを摂ったF: 果物のみを摂ったB: 野菜と果物の両方を摂ったN: どちらも摂らなかった
i 日目の 野菜スコア v_i と 果物スコア f_i を、食事内容に応じて次のように定めます。
| 文字 | 野菜スコア v_i | 果物スコア f_i |
|---|---|---|
V |
1 | 0 |
F |
0 | 1 |
B |
1 | 1 |
N |
0 | 0 |
1 \leq l \leq r \leq N を満たす整数の組 (l, r) に対して、l 日目から r 日目までの区間における野菜スコアの合計 \displaystyle\sum_{i=l}^{r} v_i と果物スコアの合計 \displaystyle\sum_{i=l}^{r} f_i が等しいとき、その区間を バランス期間 と呼びます。両方の合計がともに 0 である場合もバランス期間に含まれます。
バランス期間となる組 (l, r) の個数を求めてください。
制約
- 1 \leq N \leq 10^6
- S は長さ N の文字列であり、各文字は
V,F,B,Nのいずれかである
入力
N S
- 1 行目には、日数を表す整数 N が与えられる。
- 2 行目には、食事記録を表す長さ N の文字列 S が与えられる。
出力
バランス期間の個数を 1 行に出力せよ。
入力例 1
5 VFBNN
出力例 1
10
入力例 2
4 BNNF
出力例 2
6
入力例 3
12 VFBNVFBNVFBN
出力例 3
48
入力例 4
32 VVFFBBNNVVFFBBNNVVFFBBNNVVFFBBNN
出力例 4
244
入力例 5
1 N
出力例 5
1
Score : 400 pts
Problem Statement
Takahashi is trying to eat vegetables and fruits in a balanced way every day for his health. After summarizing his meal records over N days, he obtained a string S of length N. The i-th character of S represents the meal content on day i, and is one of the following:
V: Ate only vegetablesF: Ate only fruitsB: Ate both vegetables and fruitsN: Ate neither
The vegetable score v_i and fruit score f_i for day i are defined according to the meal content as follows:
| Character | Vegetable score v_i | Fruit score f_i |
|---|---|---|
V |
1 | 0 |
F |
0 | 1 |
B |
1 | 1 |
N |
0 | 0 |
For a pair of integers (l, r) satisfying 1 \leq l \leq r \leq N, if the total vegetable score \displaystyle\sum_{i=l}^{r} v_i and the total fruit score \displaystyle\sum_{i=l}^{r} f_i over the interval from day l to day r are equal, then that interval is called a balanced period. This includes the case where both totals are 0.
Find the number of pairs (l, r) that form a balanced period.
Constraints
- 1 \leq N \leq 10^6
- S is a string of length N, and each character is one of
V,F,B,N
Input
N S
- The first line contains an integer N representing the number of days.
- The second line contains a string S of length N representing the meal records.
Output
Print the number of balanced periods on one line.
Sample Input 1
5 VFBNN
Sample Output 1
10
Sample Input 2
4 BNNF
Sample Output 2
6
Sample Input 3
12 VFBNVFBNVFBN
Sample Output 3
48
Sample Input 4
32 VVFFBBNNVVFFBBNNVVFFBBNNVVFFBBNN
Sample Output 4
244
Sample Input 5
1 N
Sample Output 5
1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 466 点
問題文
高橋君の会社では、社員の管理体制が木構造の組織図で表されています。
社員は 1 から N までの番号で表されます。社員 1 は社長であり、組織図の最上位(根)に位置します。
各社員 i( 2 \le i \le N )には直属の上司がちょうど 1 人いて、その番号は P_i です。
この情報により、社員 1 を根とする N 頂点の根付き木が定まります。
社員 a から直属の上司をたどることを 0 回以上繰り返して社員 b に到達できるとき、社員 b を社員 a の 上司 と呼びます。
特に、各社員は自分自身の上司でもあります。また、社員 1 は全社員の上司です。
根付き木において、ある頂点の 深さ とは、根からその頂点までのパスに含まれる辺の数のことをいいます。根(社員 1)の深さは 0 です。
Q 個の問い合わせが与えられます。
k 番目の問い合わせでは社員の番号 X_k と Y_k が与えられるので、社員 X_k と社員 Y_k の両方の上司である社員のうち、深さが最も大きい社員の番号を求めてください。このような社員はちょうど 1 人存在することが証明できます。
なお、社員 X_k が社員 Y_k の上司である場合は答えは X_k であり、社員 Y_k が社員 X_k の上司である場合は答えは Y_k です( X_k = Y_k の場合を含みます)。
制約
- 2 \leq N \leq 3 \times 10^5
- 1 \leq Q \leq 5 \times 10^4
- 1 \leq P_i < i ( 2 \leq i \leq N )
- 1 \leq X_k, Y_k \leq N ( 1 \leq k \leq Q )
- 入力はすべて整数である
入力
N Q P_2 P_3 \ldots P_N X_1 Y_1 X_2 Y_2 \vdots X_Q Y_Q
- 1 行目には、社員数を表す整数 N と、問い合わせ数を表す整数 Q が、スペース区切りで与えられる。
- 2 行目には、N-1 個の整数 P_2, P_3, \ldots, P_N がスペース区切りで与えられる。P_i は社員 i の直属の上司の番号を表す。
- 3 行目から Q+2 行目まで、各問い合わせが与えられる。
- 2 + k 行目には、 k 番目の問い合わせとして、整数 X_k と Y_k がスペース区切りで与えられる。
出力
Q 行出力せよ。
k 行目には、 k 番目の問い合わせに対する答えを整数で出力せよ。
入力例 1
7 5 1 1 2 2 3 3 4 5 4 6 6 7 2 7 3 3
出力例 1
2 1 3 1 3
入力例 2
6 5 1 1 1 1 1 2 3 1 4 5 5 6 2 3 1
出力例 2
1 1 5 1 1
入力例 3
15 8 1 1 2 2 3 3 4 4 5 6 6 7 10 10 8 9 8 14 11 12 14 15 13 15 10 14 2 12 6 13
出力例 3
4 2 6 10 1 10 1 3
入力例 4
25 14 1 1 1 2 2 3 3 4 4 5 5 6 7 7 8 9 10 10 11 13 14 16 18 21 20 12 20 25 22 23 24 19 17 23 14 15 21 6 18 24 1 25 11 12 5 6 8 16 17 18 2 25
出力例 4
5 2 3 10 1 7 6 18 1 5 2 8 4 2
入力例 5
2 4 1 1 1 1 2 2 2 2 1
出力例 5
1 1 2 1
Score : 466 pts
Problem Statement
In Takahashi's company, the management structure of employees is represented by an organizational chart in the form of a tree structure.
Employees are numbered from 1 to N. Employee 1 is the president and is positioned at the top (root) of the organizational chart.
Each employee i (2 \le i \le N) has exactly one direct superior, whose number is P_i.
This information defines a rooted tree with N vertices, rooted at employee 1.
If employee b can be reached from employee a by following direct superiors zero or more times, then employee b is called a superior of employee a.
In particular, each employee is also a superior of themselves. Additionally, employee 1 is a superior of all employees.
In a rooted tree, the depth of a vertex is the number of edges on the path from the root to that vertex. The depth of the root (employee 1) is 0.
You are given Q queries.
In the k-th query, employee numbers X_k and Y_k are given. Find the employee number of the employee who is a superior of both employee X_k and employee Y_k and has the greatest depth. It can be proven that exactly one such employee exists.
Note that if employee X_k is a superior of employee Y_k, the answer is X_k, and if employee Y_k is a superior of employee X_k, the answer is Y_k (including the case where X_k = Y_k).
Constraints
- 2 \leq N \leq 3 \times 10^5
- 1 \leq Q \leq 5 \times 10^4
- 1 \leq P_i < i (2 \leq i \leq N)
- 1 \leq X_k, Y_k \leq N (1 \leq k \leq Q)
- All input values are integers
Input
N Q P_2 P_3 \ldots P_N X_1 Y_1 X_2 Y_2 \vdots X_Q Y_Q
- The first line contains an integer N representing the number of employees and an integer Q representing the number of queries, separated by a space.
- The second line contains N-1 integers P_2, P_3, \ldots, P_N separated by spaces. P_i represents the employee number of the direct superior of employee i.
- From the 3rd line to the (Q+2)-th line, each query is given.
- The (2 + k)-th line contains integers X_k and Y_k separated by a space, representing the k-th query.
Output
Print Q lines.
On the k-th line, print the answer to the k-th query as an integer.
Sample Input 1
7 5 1 1 2 2 3 3 4 5 4 6 6 7 2 7 3 3
Sample Output 1
2 1 3 1 3
Sample Input 2
6 5 1 1 1 1 1 2 3 1 4 5 5 6 2 3 1
Sample Output 2
1 1 5 1 1
Sample Input 3
15 8 1 1 2 2 3 3 4 4 5 6 6 7 10 10 8 9 8 14 11 12 14 15 13 15 10 14 2 12 6 13
Sample Output 3
4 2 6 10 1 10 1 3
Sample Input 4
25 14 1 1 1 2 2 3 3 4 4 5 5 6 7 7 8 9 10 10 11 13 14 16 18 21 20 12 20 25 22 23 24 19 17 23 14 15 21 6 18 24 1 25 11 12 5 6 8 16 17 18 2 25
Sample Output 4
5 2 3 10 1 7 6 18 1 5 2 8 4 2
Sample Input 5
2 4 1 1 1 1 2 2 2 2 1
Sample Output 5
1 1 2 1