Universal Paperclips is an incremental game whose goal is to produce paperclips. At your disposal, you have a device that makes paperclips at the click of a button.
For this problem, we'll consider a simplified version of the game with two types of actions:
Initially, the player has zero paperclips, and each button click produces one paperclip. An upgrade costs $$$x$$$ paperclips. In all test cases, it's guaranteed that before every upgrade action, the player has at least $$$x$$$ paperclips.
Benny is coding a bot that plays this game. He programmed a fixed sequence of $$$n$$$ actions $$$S$$$, that bot executes cyclically. Every second, the bot makes another action: on the 1st second, the bot executes action $$$S_1$$$, on the 2nd — $$$S_2$$$, ..., on the $$$n$$$-th second it executes $$$S_n$$$, on the $$$n+1$$$-th second — $$$S_1$$$ again, and then the cycle repeats.
How many paperclips will Benny have after his bot runs for $$$t$$$ seconds?
The first line contains three integers $$$n$$$, $$$t$$$ and $$$x$$$ ($$$1 \le n \le 10^5$$$; $$$1 \le t \le 10^9$$$; $$$0 \le x \lt n$$$). The second line contains the string $$$S$$$ of length $$$n$$$, consisting of characters "C" and "U".
Output a single integer — the number of paperclips after $$$t$$$ seconds.
| Subtask | Points | Constraints |
| 1 | 33 | $$$t \le 10^5$$$ |
| 2 | 67 | No additional constraints |
10 15 2 CCCCCUUCCU
25
3 10 0 UUU
0
9 150 1 CCUCCCCUC
2023
Let's go through the first example.
The first five actions produce one paperclip each. Then, the two subsequent upgrades cost two paperclips, so you have only one paperclip left. But, the next two clicks produce three paperclips. The next upgrade costs two paperclips, again. Each one of the last five clicks adds four paperclips.
The final number of paperclips is $$$1 + 1 + 1 + 1 + 1 - 2 - 2 + 3 + 3 - 2 + 4 + 4 + 4 + 4 + 4 = 25$$$.
You are given an array of integers. You perform the following action exactly once: choose a non-empty subsegment of the array and order its elements in non-decreasing order.
How many different arrays can you obtain? A subsegment of an array is a collection of several consecutive elements.
The first line contains a single integer $$$n$$$ — the size of the array ($$$1 \le n \le 200\,000$$$).
The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ... $$$a_n$$$ — the contents of the array ($$$1 \le a_i \le 10^9$$$).
Output a single integer — the number of different arrays you can obtain by sorting a subsegment once.
| Subtask | Points | Constraints |
| 1 | 13 | $$$n \le 50$$$ |
| 2 | 26 | $$$n \le 3\,000$$$ |
| 3 | 22 | $$$1 \le a_i \le 2$$$ |
| 4 | 39 | No additional constraints |
7 3 1 4 1 5 9 2
8
4 1 2 3 4
1
Listed below are all eight achievable arrays in the first example. Square brackets indicate the sorted subsegment.
Consider a sequence of non-negative integers from $$$L$$$ to $$$R$$$ inclusive. Split this sequence into $$$n$$$ non-empty segments and calculate the bitwise "OR" of all numbers in each segment. Denote the result for the $$$i$$$-th segment as $$$f_i$$$.
You need to solve the inverse problem: given $$$f_1, f_2, \ldots, f_n$$$, find the number of ways first to select $$$L$$$ and $$$R$$$, and then split all numbers from $$$L$$$ to $$$R$$$ into $$$n$$$ non-empty segments, such that the results of calculating the bitwise "OR" in each segment are equal to $$$f_1, f_2, \ldots, f_n$$$ respectively.
The bitwise "OR" of two non-negative integers is calculated as follows: Write down both arguments in binary, then the $$$i$$$-th bit of the result equals $$$1$$$ iff at least one argument has $$$1$$$ at that place. For example, $$$(17 \mathbin{|} 13) = (10001_2 \mathbin{|} 01101_2) = 11101_2 = 29$$$.
The first line contains integer $$$n$$$ ($$$1 \le n \le 200\,000$$$). The second line contains $$$n$$$ integers $$$f_i$$$ ($$$0 \le f_i \lt 2^{60}$$$).
Output a single integer — the number of ways to choose a sequence of consecutive integers and then split it into $$$n$$$ segments. Because the answer can be huge, print it modulo $$$1\,000\,000\,007$$$.
| Subtask | Points | Constraints | |
| 1 | 16 | $$$n = 1$$$ | |
| 2 | 12 | $$$n \le 16$$$, $$$0 \le f_i | lt; 16$$$ |
| 3 | 13 | $$$n \le 256$$$, $$$0 \le f_i | lt; 256$$$ |
| 4 | 18 | $$$n \le 1024$$$, $$$0 \le f_i | lt; 1024$$$ |
| 5 | 24 | $$$n \le 30\,000$$$, $$$0 \le f_i | lt; 2^{30}$$$ |
| 6 | 17 | No additional constraints |
3 0 7 7
4
1 11
6
2 4 6
0
In the first example, there are four ways to split a sequence of consecutive integers into three parts such that their bitwise "OR"s are $$$0$$$, $$$7$$$ and $$$7$$$:
You are given a permutation. In one step, you can swap any two adjacent elements if their values differ by more than one.
Consider all permutations that can be obtained using these operations, starting from a given permutation. Define a distance between two permutations as the minimum number of these operations required to transform the first permutation into the second one.
Find the number of permutations that can be obtained and the sum of distances to all those permutations from the starting one.
The first line contains the integer $$$n$$$ ($$$1 \le n \le 100$$$) — the permutation size. The second line contains $$$n$$$ distinct integers $$$a_i$$$ ($$$1 \le a_i \le n$$$) — the starting permutation.
Output two integers, the number of obtainable permutations, and the sum of distances to those permutations. Calculate both numbers modulo $$$1\,000\,000\,007$$$.
| Subtask | Points | Constraints |
| 1 | 15 | $$$n \le 8$$$ |
| 2 | 20 | $$$n \le 15$$$ |
| 3 | 30 | $$$n \le 30$$$ |
| 4 | 20 | $$$n \le 50$$$ |
| 5 | 15 | No additional constraints |
4 3 1 4 2
5 5
5 1 2 3 4 5
1 0
6 5 3 1 2 4 6
61 218
In the first example, you can obtain the following permutations:
There are five permutations in total; the sum of distances also equals five.
In the second example, you can't perform any swap, so only one permutation is reachable with a distance of 0.