実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 266 点
問題文
高橋君は、N 台のサーバーを経由してデータを送信する暗号化システムを設計しています。
このシステムでは、N 台のサーバーが一列に接続されており、左から順に 1, 2, \ldots, N の番号が付けられています。各サーバー i(1 \leq i \leq N)には暗号化キー A_i(非負整数)が設定されています。
データ送信に先立ち、各サーバーが実際に使用する暗号化キー B_i が以下のルールで決まります。B_i の値は元の暗号化キー A_1, A_2, \ldots, A_N のみに基づいて決定され、すべてのサーバーについて同時に確定します。
- サーバー j(2 \leq j \leq N-1)が次の条件を満たすとき、サーバー j を「挟まれた異常サーバー」と呼びます:A_{j-1} = A_{j+1} かつ A_{j-1} \neq A_j が成り立つ。すなわち、両隣のサーバーの暗号化キーが等しく、かつ自身の暗号化キーがそれらと異なる場合です。
- 「挟まれた異常サーバー」と判定されたサーバー j については B_j = 0 とします。
- それ以外のサーバー j(サーバー 1、サーバー N、および上記の条件を満たさないサーバー)については B_j = A_j とします。
次に、非負整数のデータ X が以下のルールで左から右へ送信されます。ここで D_0 = X とし、各サーバー i(i = 1, 2, \ldots, N の順に)は、データ D_{i-1} を受け取り、D_i = D_{i-1} \oplus B_i(\oplus はビットごとの排他的論理和)を計算します。サーバー 1 が受け取るデータ D_0 は高橋君から送信されたデータ X そのものであり、サーバー N が計算した D_N が最終的な出力データです。
高橋君がサーバー 1 に送信するデータ X と、各サーバーの暗号化キーが与えられたとき、最終的な出力データ D_N を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq X \leq 10^9
- 0 \leq A_i \leq 10^9(1 \leq i \leq N)
- 入力は全て整数
入力
N X A_1 A_2 \ldots A_N
- 1 行目には、サーバーの台数を表す整数 N と、高橋君が最初に送信するデータを表す非負整数 X が、スペース区切りで与えられる。
- 2 行目には、各サーバー i(1 \leq i \leq N)の暗号化キーを表す非負整数 A_i が、スペース区切りで N 個与えられる。
出力
最終的な出力データを 1 行で出力せよ。
入力例 1
5 10 1 2 1 3 3
出力例 1
10
入力例 2
3 5 7 7 7
出力例 2
2
入力例 3
8 123 8 1 8 3 3 5 7 5
出力例 3
123
入力例 4
20 999999999 0 1000000000 0 5 5 7 8 7 3 3 3 9 1 9 4 6 4 2 2 2
出力例 4
999999998
入力例 5
1 0 0
出力例 5
0
Score : 266 pts
Problem Statement
Takahashi is designing an encryption system that transmits data through N servers.
In this system, N servers are connected in a line, numbered 1, 2, \ldots, N from left to right. Each server i (1 \leq i \leq N) has an encryption key A_i (a non-negative integer) assigned to it.
Prior to data transmission, the encryption key B_i that each server actually uses is determined by the following rules. The value of B_i is determined solely based on the original encryption keys A_1, A_2, \ldots, A_N, and is finalized simultaneously for all servers.
- A server j (2 \leq j \leq N-1) is called a "sandwiched anomalous server" if it satisfies the following condition: A_{j-1} = A_{j+1} and A_{j-1} \neq A_j. In other words, the encryption keys of both neighboring servers are equal, and its own encryption key differs from theirs.
- For a server j that is determined to be a "sandwiched anomalous server", B_j = 0.
- For all other servers j (server 1, server N, and servers that do not satisfy the above condition), B_j = A_j.
Next, non-negative integer data X is transmitted from left to right according to the following rules. Let D_0 = X, and each server i (in order i = 1, 2, \ldots, N) receives data D_{i-1} and computes D_i = D_{i-1} \oplus B_i (\oplus denotes the bitwise exclusive OR). The data D_0 received by server 1 is the data X sent by Takahashi, and D_N computed by server N is the final output data.
Given the data X that Takahashi sends to server 1 and the encryption key of each server, find the final output data D_N.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq X \leq 10^9
- 0 \leq A_i \leq 10^9 (1 \leq i \leq N)
- All input values are integers
Input
N X A_1 A_2 \ldots A_N
- The first line contains an integer N representing the number of servers and a non-negative integer X representing the data Takahashi initially sends, separated by a space.
- The second line contains N non-negative integers A_i representing the encryption key of each server i (1 \leq i \leq N), separated by spaces.
Output
Print the final output data on a single line.
Sample Input 1
5 10 1 2 1 3 3
Sample Output 1
10
Sample Input 2
3 5 7 7 7
Sample Output 2
2
Sample Input 3
8 123 8 1 8 3 3 5 7 5
Sample Output 3
123
Sample Input 4
20 999999999 0 1000000000 0 5 5 7 8 7 3 3 3 9 1 9 4 6 4 2 2 2
Sample Output 4
999999998
Sample Input 5
1 0 0
Sample Output 5
0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 333 点
問題文
高橋君は図書館の蔵書検索システムを開発しています。この図書館には N 個の本棚があり、i 番目の本棚(1 \leq i \leq N)には K_i 冊の本が置かれています。i 番目の本棚の j 冊目の本のタイトルを S_{i,j} と表します。タイトルはすべて英小文字のみからなる文字列です。
この検索システムでは、利用者が検索クエリとして文字列を入力すると、そのクエリに関連する本が置かれている本棚を探し出します。利用者は本のタイトルを正確に覚えていないことが多く、タイトルの中から何文字かを(連続していなくてもよいので)順番通りに拾って入力し、検索することがあります。そこで、このシステムでは部分列(subsequence)による検索が採用されています。
ここで、文字列 T が文字列 S の 部分列 であるとは、S から 0 文字以上の文字を取り除いて(残った文字の順序は変えずに)T を得ることができることを言います。例えば、ace は abcde の部分列ですが、aec は abcde の部分列ではありません。
i 番目の本棚がクエリ文字列 T に ヒット するとは、T が S_{i,1}, S_{i,2}, \ldots, S_{i,K_i} のうち少なくとも 1 つの部分列であることを意味します。すなわち、その本棚に少なくとも 1 冊、タイトルが T を部分列として含む本が存在するということです。
Q 個の検索クエリが与えられます。j 番目のクエリの文字列を T_j とします。各クエリについて、クエリ T_j にヒットする本棚の数を求めてください。
制約
- 1 \leq N \leq 100
- 1 \leq K_i \leq 5000
- 1 \leq \displaystyle\sum_{i=1}^{N} K_i \leq 5000
- 各タイトル S_{i,j} の長さは 1 以上 1000 以下である
- \displaystyle\sum_{i=1}^{N}\sum_{j=1}^{K_i} |S_{i,j}| \leq 10^5
- 1 \leq Q \leq 200
- 各クエリ T_j の長さは 1 以上 1000 以下である
- \displaystyle\sum_{j=1}^{Q} |T_j| \leq 10^5
- S_{i,j} および T_j は英小文字のみからなる文字列である
ここで |X| は文字列 X の長さを表す。
入力
N
K_1 S_{1,1} S_{1,2} \ldots S_{1,K_1}
K_2 S_{2,1} S_{2,2} \ldots S_{2,K_2}
\vdots
K_N S_{N,1} S_{N,2} \ldots S_{N,K_N}
Q
T_1
T_2
\vdots
T_Q
- 1 行目には、本棚の数を表す整数 N が与えられる。
- 2 行目から N+1 行目まで、i+1 行目(1 \leq i \leq N)には、i 番目の本棚に置かれている本の冊数 K_i と、それぞれの本のタイトル S_{i,1}, S_{i,2}, \ldots, S_{i,K_i} がスペース区切りで与えられる。
- N+2 行目には、検索クエリの個数を表す整数 Q が与えられる。
- N+3 行目から N+Q+2 行目まで、j 番目のクエリ(1 \leq j \leq Q)に対応する行には、検索クエリの文字列 T_j が与えられる。
出力
Q 行出力せよ。j 行目(1 \leq j \leq Q)には、クエリ T_j にヒットする本棚の数を出力せよ。
入力例 1
2 2 algorithm data 2 string graph 3 ag ri zz
出力例 1
1 2 0
入力例 2
3 1 programming 2 problem process 2 apple application 4 po pin pp rm
出力例 2
3 2 1 2
入力例 3
5 3 binary search tree 2 dynamic programming 1 graph 2 stack queue 3 linked list array 5 ar ra i zzz ee
出力例 3
2 3 3 0 2
Score : 333 pts
Problem Statement
Takahashi is developing a book search system for a library. The library has N bookshelves, and the i-th bookshelf (1 \leq i \leq N) contains K_i books. The title of the j-th book on the i-th bookshelf is denoted by S_{i,j}. All titles are strings consisting only of lowercase English letters.
In this search system, when a user inputs a string as a search query, the system finds bookshelves that contain books related to the query. Since users often do not remember the exact title of a book, they may pick some characters from the title in order (not necessarily consecutive) and input them as a search. Therefore, this system adopts search by subsequence.
Here, a string T is a subsequence of a string S if T can be obtained by removing 0 or more characters from S (without changing the order of the remaining characters). For example, ace is a subsequence of abcde, but aec is not a subsequence of abcde.
The i-th bookshelf hits a query string T if T is a subsequence of at least one of S_{i,1}, S_{i,2}, \ldots, S_{i,K_i}. In other words, there exists at least one book on that bookshelf whose title contains T as a subsequence.
You are given Q search queries. Let T_j be the string of the j-th query. For each query, find the number of bookshelves that hit the query T_j.
Constraints
- 1 \leq N \leq 100
- 1 \leq K_i \leq 5000
- 1 \leq \displaystyle\sum_{i=1}^{N} K_i \leq 5000
- The length of each title S_{i,j} is between 1 and 1000, inclusive
- \displaystyle\sum_{i=1}^{N}\sum_{j=1}^{K_i} |S_{i,j}| \leq 10^5
- 1 \leq Q \leq 200
- The length of each query T_j is between 1 and 1000, inclusive
- \displaystyle\sum_{j=1}^{Q} |T_j| \leq 10^5
- S_{i,j} and T_j are strings consisting only of lowercase English letters
Here, |X| denotes the length of string X.
Input
N
K_1 S_{1,1} S_{1,2} \ldots S_{1,K_1}
K_2 S_{2,1} S_{2,2} \ldots S_{2,K_2}
\vdots
K_N S_{N,1} S_{N,2} \ldots S_{N,K_N}
Q
T_1
T_2
\vdots
T_Q
- The first line contains an integer N, the number of bookshelves.
- From the 2nd line to the (N+1)-th line, the (i+1)-th line (1 \leq i \leq N) contains the number of books K_i on the i-th bookshelf, followed by the titles S_{i,1}, S_{i,2}, \ldots, S_{i,K_i}, separated by spaces.
- The (N+2)-th line contains an integer Q, the number of search queries.
- From the (N+3)-th line to the (N+Q+2)-th line, the line corresponding to the j-th query (1 \leq j \leq Q) contains the search query string T_j.
Output
Output Q lines. The j-th line (1 \leq j \leq Q) should contain the number of bookshelves that hit the query T_j.
Sample Input 1
2 2 algorithm data 2 string graph 3 ag ri zz
Sample Output 1
1 2 0
Sample Input 2
3 1 programming 2 problem process 2 apple application 4 po pin pp rm
Sample Output 2
3 2 1 2
Sample Input 3
5 3 binary search tree 2 dynamic programming 1 graph 2 stack queue 3 linked list array 5 ar ra i zzz ee
Sample Output 3
2 3 3 0 2
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 366 点
問題文
高橋君は N 個の株式銘柄に投資しています。i 番目の銘柄の現在の評価額は L_i 円です。
高橋君はこれから K 回の投資チャンスを順番に使います。各回では、N 個の銘柄から好きな銘柄を 1 つ選び、その銘柄の現在の評価額を 2 倍にします。このとき、同じ銘柄を複数回選ぶこともできます。
K 回の投資チャンスをすべて使い終えた後の、N 個の銘柄の評価額の合計が最大となるように各回の銘柄を選ぶとき、その最大値を求めてください。
答えは非常に大きくなる可能性があるため、最大値を 10^9 + 7 で割った余りを出力してください。ただし、余りを取る操作は最大値を求めた後に行うものとします。すなわち、途中で余りを取った結果に基づいて大小を比較するのではなく、真の値としての最大値を求めたうえで、その値を 10^9 + 7 で割った余りを出力してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K \leq 10^{18}
- 1 \leq L_i \leq 10^9
- 入力はすべて整数である。
入力
N K L_1 L_2 \ldots L_N
- 1 行目には、銘柄の数を表す整数 N と、投資チャンスの回数を表す整数 K が、スペース区切りで与えられる。
- 2 行目には、各銘柄の現在の評価額を表す整数 L_1, L_2, \ldots, L_N が、スペース区切りで与えられる。
出力
K 回の投資チャンスをすべて使い終えた後の評価額の合計の最大値を 10^9 + 7 で割った余りを、1 行で出力せよ。
入力例 1
3 2 3 1 2
出力例 1
15
入力例 2
5 10 4 8 2 5 1
出力例 2
8204
入力例 3
4 1000000000000000000 1000000000 999999999 999999998 999999997
出力例 3
963666195
Score : 366 pts
Problem Statement
Takahashi is investing in N stock issues. The current valuation of the i-th stock is L_i yen.
Takahashi will use K investment chances one by one in order. In each chance, he chooses any one of the N stocks and doubles its current valuation. He may choose the same stock multiple times.
Determine the maximum possible total valuation of all N stocks after all K investment chances have been used, when he chooses the stock in each chance to maximize this total.
Since the answer can be extremely large, output the maximum value modulo 10^9 + 7. Note that the modulo operation is applied only after determining the true maximum value. That is, you should not compare values based on intermediate results taken modulo 10^9 + 7; instead, find the maximum value as a true (unmodded) number, and then output that value modulo 10^9 + 7.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K \leq 10^{18}
- 1 \leq L_i \leq 10^9
- All input values are integers.
Input
N K L_1 L_2 \ldots L_N
- The first line contains an integer N representing the number of stocks and an integer K representing the number of investment chances, separated by a space.
- The second line contains integers L_1, L_2, \ldots, L_N representing the current valuations of each stock, separated by spaces.
Output
Output in one line the maximum total valuation after all K investment chances have been used, modulo 10^9 + 7.
Sample Input 1
3 2 3 1 2
Sample Output 1
15
Sample Input 2
5 10 4 8 2 5 1
Sample Output 2
8204
Sample Input 3
4 1000000000000000000 1000000000 999999999 999999998 999999997
Sample Output 3
963666195
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
高橋君は庭に花壇を作ろうとしています。
園芸店には N 種類の花の苗が売られており、それぞれの花には 1 から N までの番号が付けられています。高橋君は各花の見た目を確認し、花 i に対して美しさ S_i を評価しました(美しさは負の値になることもあります)。
高橋君はこの N 種類の花の中からいくつかを選んで花壇に植えます。ただし、選べる花の種類数は 0 以上 K 以下です。各花について「選んで 1 つ植える」か「選ばない」かのいずれかを決めます。
また、高橋君の住む街では M 個のガーデニングコンテストが開催されます。コンテスト j の参加条件は、番号が L_j 以上 R_j 以下の花のうち少なくとも 1 種類が花壇に植えられていることです。参加条件を満たしたコンテストには必ずすべて参加しなければならず(参加を辞退することはできません)、コンテスト j に参加すると賞金 P_j を得られます。
高橋君は植える花の集合をうまく選ぶことで、(選んだ花の美しさの合計)+(参加するすべてのコンテストの賞金の合計)を最大化したいと考えています。
この値の最大値を求めてください。なお、1 種類も花を選ばないことも許され、その場合は美しさの合計および賞金の合計はいずれも 0 となります。
制約
- 1 \leq N \leq 15
- 1 \leq K \leq N
- 1 \leq M \leq 15
- -1000 \leq S_i \leq 1000 (1 \leq i \leq N)
- 1 \leq L_j \leq R_j \leq N (1 \leq j \leq M)
- 1 \leq P_j \leq 1000 (1 \leq j \leq M)
- 入力はすべて整数である
入力
N K M S_1 S_2 \ldots S_N L_1 R_1 P_1 L_2 R_2 P_2 \vdots L_M R_M P_M
- 1 行目には、花の種類数を表す N 、花壇に植える花の最大種類数を表す K 、コンテストの個数を表す M が、スペース区切りで与えられる。
- 2 行目には、各花の美しさを表す S_1, S_2, \ldots, S_N が、スペース区切りで与えられる。
- 3 行目から M 行にわたり、各コンテストの情報が与えられる。
- 2 + j 行目では、コンテスト j の参加条件となる花の番号の範囲の左端 L_j 、右端 R_j 、および参加時に得られる賞金 P_j が、スペース区切りで与えられる。
出力
(選んだ花の美しさの合計)+(参加するすべてのコンテストの賞金の合計)の最大値を 1 行で出力せよ。
入力例 1
3 2 1 5 3 -2 1 2 10
出力例 1
18
入力例 2
3 1 2 -10 -10 -10 1 1 3 2 3 2
出力例 2
0
入力例 3
6 3 4 10 -5 8 -3 7 -1 1 3 15 2 5 20 4 6 10 1 6 5
出力例 3
75
入力例 4
10 5 8 100 -50 80 -30 70 -10 60 -40 90 -20 1 3 200 2 5 150 4 7 180 6 10 120 1 5 100 3 8 90 5 10 110 1 10 50
出力例 4
1400
入力例 5
1 1 1 -1000 1 1 1
出力例 5
0
Score : 400 pts
Problem Statement
Takahashi is trying to create a flower bed in his garden.
A gardening shop sells seedlings of N types of flowers, each numbered from 1 to N. Takahashi examined the appearance of each flower and assigned a beauty value S_i to flower i (beauty values can be negative).
Takahashi will select some of these N types of flowers to plant in the flower bed. However, the number of types of flowers he can select is between 0 and K, inclusive. For each flower, he decides either to "select it and plant one" or "not select it."
Additionally, M gardening contests are held in the town where Takahashi lives. The participation condition for contest j is that at least one type of flower with a number between L_j and R_j (inclusive) is planted in the flower bed. He must participate in all contests whose conditions are satisfied (he cannot decline participation), and by participating in contest j, he receives a prize of P_j.
Takahashi wants to choose the set of flowers to plant in order to maximize (the sum of beauty values of the selected flowers) + (the sum of prizes from all contests he participates in).
Find the maximum value of this quantity. Note that it is allowed to select no flowers at all, in which case both the sum of beauty values and the sum of prizes are 0.
Constraints
- 1 \leq N \leq 15
- 1 \leq K \leq N
- 1 \leq M \leq 15
- -1000 \leq S_i \leq 1000 (1 \leq i \leq N)
- 1 \leq L_j \leq R_j \leq N (1 \leq j \leq M)
- 1 \leq P_j \leq 1000 (1 \leq j \leq M)
- All input values are integers
Input
N K M S_1 S_2 \ldots S_N L_1 R_1 P_1 L_2 R_2 P_2 \vdots L_M R_M P_M
- The first line contains N, the number of types of flowers, K, the maximum number of types of flowers that can be planted in the flower bed, and M, the number of contests, separated by spaces.
- The second line contains the beauty values of each flower S_1, S_2, \ldots, S_N, separated by spaces.
- The following M lines provide information about each contest.
- The (2 + j)-th line contains the left endpoint L_j and right endpoint R_j of the range of flower numbers that form the participation condition for contest j, and the prize P_j received upon participation, separated by spaces.
Output
Output the maximum value of (the sum of beauty values of the selected flowers) + (the sum of prizes from all contests participated in) on a single line.
Sample Input 1
3 2 1 5 3 -2 1 2 10
Sample Output 1
18
Sample Input 2
3 1 2 -10 -10 -10 1 1 3 2 3 2
Sample Output 2
0
Sample Input 3
6 3 4 10 -5 8 -3 7 -1 1 3 15 2 5 20 4 6 10 1 6 5
Sample Output 3
75
Sample Input 4
10 5 8 100 -50 80 -30 70 -10 60 -40 90 -20 1 3 200 2 5 150 4 7 180 6 10 120 1 5 100 3 8 90 5 10 110 1 10 50
Sample Output 4
1400
Sample Input 5
1 1 1 -1000 1 1 1
Sample Output 5
0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 466 点
問題文
高橋君は N 人のランナーが参加するマラソン大会の実況を担当しています。
ランナーたちは一直線の無限に長いコース上を、同じ方向に向かって走っています。スタート地点からの距離が大きいほど前方であるとします。最初(時刻 0)において、ランナー i(1 \leq i \leq N)はスタート地点から P_i メートルの位置にいます。各ランナーはその後ずっと一定の速度で走り続け、ランナー i の速度は毎秒 V_i メートルです。すなわち、時刻 t 秒におけるランナー i の位置はスタート地点から P_i + V_i \times t メートルの地点です。
高橋君は、レース中に「追い抜き」が何回発生するかを数えて実況に活かしたいと考えています。「追い抜き」とは次のように定義されます。2 人の異なるランナーの組 \{i, j\} について、時刻 0 においてランナー i がランナー j より後方にいる(すなわち P_i < P_j)にもかかわらず、ある時刻 t > 0 においてランナー i がランナー j より前方にいる(すなわち P_i + V_i \times t > P_j + V_j \times t)とき、これを 1 回の追い抜きと数えます。
すべてのランナーの初期位置は互いに異なり、すべてのランナーの速度も互いに異なります。このことから、どの 2 人のランナーの組についても追い抜きは高々 1 回しか発生しません。具体的には、初期位置が後方のランナーの速度が前方のランナーの速度より大きいときに限り、ちょうど 1 回の追い抜きが発生します。
時刻 0 から無限の未来までに発生する追い抜きの総回数を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq P_i \leq 10^9
- 1 \leq V_i \leq 10^9
- P_i \neq P_j (i \neq j)
- V_i \neq V_j (i \neq j)
- 入力はすべて整数
入力
N P_1 V_1 P_2 V_2 \vdots P_N V_N
- 1 行目には、ランナーの人数を表す整数 N が与えられる。
- 続く N 行の i 行目(1 \leq i \leq N)には、ランナー i の初期位置 P_i(メートル)と速度 V_i(メートル毎秒)が空白区切りで与えられる。
出力
追い抜きの総回数を 1 行で出力してください。
入力例 1
3 1 3 2 1 3 2
出力例 1
2
入力例 2
5 10 5 30 1 20 4 50 2 40 3
出力例 2
8
入力例 3
8 100 80 200 30 150 90 400 10 300 50 250 70 500 20 350 60
出力例 3
22
Score : 466 pts
Problem Statement
Takahashi is commentating a marathon with N runners participating.
The runners are running along an infinitely long straight course, all in the same direction. The greater the distance from the starting point, the further ahead a runner is considered to be. Initially (at time 0), runner i (1 \leq i \leq N) is at a position P_i meters from the starting point. Each runner continues running at a constant speed thereafter, and the speed of runner i is V_i meters per second. That is, at time t seconds, the position of runner i is P_i + V_i \times t meters from the starting point.
Takahashi wants to count how many "overtakes" occur during the race to use in his commentary. An "overtake" is defined as follows: for a pair of two distinct runners \{i, j\}, if runner i is behind runner j at time 0 (i.e., P_i < P_j), yet at some time t > 0 runner i is ahead of runner j (i.e., P_i + V_i \times t > P_j + V_j \times t), this counts as one overtake.
All runners have distinct initial positions, and all runners have distinct speeds. Because of this, for any pair of two runners, at most one overtake can occur. Specifically, exactly one overtake occurs if and only if the runner who starts further behind has a greater speed than the runner who starts further ahead.
Find the total number of overtakes that occur from time 0 to the infinite future.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq P_i \leq 10^9
- 1 \leq V_i \leq 10^9
- P_i \neq P_j (i \neq j)
- V_i \neq V_j (i \neq j)
- All input values are integers
Input
N P_1 V_1 P_2 V_2 \vdots P_N V_N
- The first line contains an integer N, the number of runners.
- The following N lines each contain, on the i-th line (1 \leq i \leq N), the initial position P_i (in meters) and the speed V_i (in meters per second) of runner i, separated by a space.
Output
Output the total number of overtakes in one line.
Sample Input 1
3 1 3 2 1 3 2
Sample Output 1
2
Sample Input 2
5 10 5 30 1 20 4 50 2 40 3
Sample Output 2
8
Sample Input 3
8 100 80 200 30 150 90 400 10 300 50 250 70 500 20 350 60
Sample Output 3
22