C - X: Yet Another Die Game

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 300

問題文

すぬけくんは 6 面サイコロで遊ぶことにしました。 サイコロは 1 から 6 までの整数がそれぞれの面に書かれており、向かい合う面に書かれた数の和はどれも 7 です。

すぬけくんはサイコロの好きな面が上向きになるように置いたのち何回か以下の操作を行います。

  • 操作:サイコロを手前、奥、左、右のどれかの方向に 90° だけ回転させる。その後、上を向いている面に書かれた数を y として y 点得る。

例えば、図のように 1 と書かれた面が上を向いており、手前側の面に 5 が、右側の面に 4 が書かれている状況を考えます。
図に示されるように右方向に回転させることで 3 と書かれた面が上を向くようにすることが可能です。 その他、左方向に回転させた場合は 4 と書かれた面が、手前方向に回転させた場合は 2 と書かれた面が、奥方向に回転させた場合は 5 と書かれた面が上を向くようにすることが可能です。

864abc2e4a08c26015ffd007a30aab03.png

すぬけくんが合計で x 点以上得るために必要な最小の操作回数を求めなさい。

制約

  • 1 ≦ x ≦ 10^{15}
  • x は整数

入力

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

x

出力

答えを出力せよ。


入力例 1

7

出力例 1

2

入力例 2

149696127901

出力例 2

27217477801

Score : 300 points

Problem Statement

Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.

Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:

  • Operation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.

For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure. If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward. Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.

864abc2e4a08c26015ffd007a30aab03.png

Find the minimum number of operation Snuke needs to perform in order to score at least x points in total.

Constraints

  • 1 ≦ x ≦ 10^{15}
  • x is an integer.

Input

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

x

Output

Print the answer.


Sample Input 1

7

Sample Output 1

2

Sample Input 2

149696127901

Sample Output 2

27217477801
D - Card Eater

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 400

問題文

すぬけくんはカードゲームで遊ぶことにしました。 N 枚からなるカードの山があり、上から i 枚目のカードには整数 A_i が書かれています。

すぬけくんはこのカードの山に対し 0 回以上、以下の操作を行い、残ったカードに書かれた値が互いに異なるようにしたいです。最大で何枚のカードを残すことが可能か求めなさい。なお、N は奇数であり、少なくとも 1 枚のカードを残すことが可能であることが保証されます。

操作:カードの山から任意の 3 枚のカードを抜き出す。抜き出したカードのうち書かれた値が最大であるようなカード 1 枚と最小であるようなカード 1 枚の合計 2 枚を選んで食べる。その後残った 1 枚をカードの山に戻す。

制約

  • 3 ≦ N ≦ 10^{5}
  • N は奇数
  • 1 ≦ A_i ≦ 10^{5}
  • A_i は整数

入力

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

N
A_1 A_2 A_3 ... A_{N}

出力

答えを出力せよ。


入力例 1

5
1 2 1 3 7

出力例 1

3

操作を 1 回行って 1,1,2 を取り出すというのが最適な操作手順の 1 つです。最大値である 2 と書かれたカードで最小値である 1 と書かれたカードがそれぞれ 1 枚ずつ食べられ、残った 1 と書かれたカードがカードの山に戻されます。カードの山に残っているカードは 1,3,7 となり、これらは互いに異なります。


入力例 2

15
1 3 5 2 1 3 2 8 8 6 2 6 11 1 1

出力例 2

7

Score : 400 points

Problem Statement

Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written.

He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept.

Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.

Constraints

  • 3 ≦ N ≦ 10^{5}
  • N is odd.
  • 1 ≦ A_i ≦ 10^{5}
  • A_i is an integer.

Input

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

N
A_1 A_2 A_3 ... A_{N}

Output

Print the answer.


Sample Input 1

5
1 2 1 3 7

Sample Output 1

3

One optimal solution is to perform the operation once, taking out two cards with 1 and one card with 2. One card with 1 and another with 2 will be eaten, and the remaining card with 1 will be returned to deck. Then, the values written on the remaining cards in the deck will be pairwise distinct: 1, 3 and 7.


Sample Input 2

15
1 3 5 2 1 3 2 8 8 6 2 6 11 1 1

Sample Output 2

7
E - Snuke Line

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 700

問題文

すぬけくんは鉄道会社を運営するゲームで遊ぶことにしました。すぬけ鉄道には M+1 個の駅があり、 0 から M までの番号がついています。 すぬけ鉄道の列車は駅 0 から d 駅ごとに停車します。 例えば d = 3 のとき駅 0,駅 3,駅 6,駅 9, ... に停車します。

すぬけ鉄道が走っている地域には N 種類の名産品があり、種類 i の名産品は 駅 l_i,駅 l_i+1,駅 l_i+2, ..., 駅 r_i のいずれかに列車が停車したとき購入することが可能です。

列車が停車する間隔 d1, 2, 3, ..., MM 種類が存在しています。 M 種類の列車それぞれについて、その列車に駅 0 で乗車した場合に購入可能な名産品の種類数を求めなさい。 なお、列車から別の列車への乗り換えは許されないものとします。

制約

  • 1 ≦ N ≦ 3 × 10^{5}
  • 1 ≦ M ≦ 10^{5}
  • 1 ≦ l_i ≦ r_i ≦ M

入力

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

N M
l_1 r_1
:
l_{N} r_{N}

出力

答えを M 行に出力せよ。 i 行目では i 駅ごとに停車する列車に乗った場合に購入可能な名産品の種類数を出力せよ。


入力例 1

3 3
1 2
2 3
3 3

出力例 1

3
2
2
  • 1 駅ごとに停車する列車に乗った場合、種類 1,2,33 種類の名産品を購入することが可能です。
  • 2 駅ごとに停車する列車に乗った場合、種類 1,22 種類の名産品を購入することが可能です。
  • 3 駅ごとに停車する列車に乗った場合、種類 2,32 種類の名産品を購入することが可能です。

入力例 2

7 9
1 7
5 9
5 7
5 9
1 1
6 8
3 4

出力例 2

7
6
6
5
4
5
5
3
2

Score : 700 points

Problem Statement

Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for each train. For example, if d = 3, the train stops at station 0, 3, 6, 9, and so forth.

There are N kinds of souvenirs sold in areas around Snuke Line. The i-th kind of souvenirs can be purchased when the train stops at one of the following stations: stations l_i, l_i+1, l_i+2, ..., r_i.

There are M values of d, the interval between two stops, for trains on Snuke Line: 1, 2, 3, ..., M. For each of these M values, find the number of the kinds of souvenirs that can be purchased if one takes a train with that value of d at station 0. Here, assume that it is not allowed to change trains.

Constraints

  • 1 ≦ N ≦ 3 × 10^{5}
  • 1 ≦ M ≦ 10^{5}
  • 1 ≦ l_i ≦ r_i ≦ M

Input

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

N M
l_1 r_1
:
l_{N} r_{N}

Output

Print the answer in M lines. The i-th line should contain the maximum number of the kinds of souvenirs that can be purchased if one takes a train stopping every i-th station.


Sample Input 1

3 3
1 2
2 3
3 3

Sample Output 1

3
2
2
  • If one takes a train stopping every station, three kinds of souvenirs can be purchased: kind 1, 2 and 3.
  • If one takes a train stopping every second station, two kinds of souvenirs can be purchased: kind 1 and 2.
  • If one takes a train stopping every third station, two kinds of souvenirs can be purchased: kind 2 and 3.

Sample Input 2

7 9
1 7
5 9
5 7
5 9
1 1
6 8
3 4

Sample Output 2

7
6
6
5
4
5
5
3
2
F - Solitaire

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 1200

問題文

すぬけくんは N 枚のカードとデック(両端キュー)で遊ぶことにしました。 カードには 1,2,3...,N の数が書かれており、デックははじめ空です。

すぬけくんは 1,2,3,...,N が書かれたカードをこの順に、それぞれデックの先頭あるいは末尾に挿入します。 その後、すぬけくんはデックの先頭あるいは末尾からカードを取り出して食べる、という操作を N 回行います。

食べたカードに書かれていた数を食べた順番に並べて数列を作ることにします。このようにして作ることが可能な数列のうち、K 番目の要素が 1 であるようなものの個数を 10^{9} + 7 で割った余りを求めなさい。

制約

  • 1 ≦ K ≦ N ≦ 2{,}000

入力

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

N K

出力

答えを出力せよ。


入力例 1

2 1

出力例 1

1

条件を満たす並びは 1,21 通りです。例えば以下のようにして、この並びを構成することが可能です。

  • 1,2 のどちらもカードの山の一番下に挿入する
  • カードの山の一番上からカードを取り出して食べることを 2 回行う

入力例 2

17 2

出力例 2

262144

入力例 3

2000 1000

出力例 3

674286644

Score : 1200 points

Problem Statement

Snuke has decided to play with N cards and a deque (that is, a double-ended queue). Each card shows an integer from 1 through N, and the deque is initially empty.

Snuke will insert the cards at the beginning or the end of the deque one at a time, in order from 1 to N. Then, he will perform the following action N times: take out the card from the beginning or the end of the deque and eat it.

Afterwards, we will construct an integer sequence by arranging the integers written on the eaten cards, in the order they are eaten. Among the sequences that can be obtained in this way, find the number of the sequences such that the K-th element is 1. Print the answer modulo 10^{9} + 7.

Constraints

  • 1 ≦ K ≦ N ≦ 2{,}000

Input

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

N K

Output

Print the answer modulo 10^{9} + 7.


Sample Input 1

2 1

Sample Output 1

1

There is one sequence satisfying the condition: 1,2. One possible way to obtain this sequence is the following:

  • Insert both cards, 1 and 2, at the end of the deque.
  • Eat the card at the beginning of the deque twice.

Sample Input 2

17 2

Sample Output 2

262144

Sample Input 3

2000 1000

Sample Output 3

674286644