UTPC Contest 9-16-2026 Div. 2 (Beginner)
A. Where Are We?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The University of Texas Programming Club has lost track of where it is after staring at grid diagrams for too long. Fortunately, the club remembers one essential fact: Texas is shaped exactly like a size-$$$1$$$ plus sign. In this problem, a size-$$$1$$$ plus sign consists of five cells: a center cell and the four cells that share a side with it.

You are given an $$$n \times m$$$ map describing UTPC and its surroundings. Every cell is either open or blocked off. Count the number of ways to place a size-$$$1$$$ plus sign on the grid, lying on only open cells. Two placements are considered different if their center cells are different.

Input

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$), the number of rows and columns of the map.

Each of the next $$$n$$$ lines contains a string of $$$m$$$ characters. A character "." represents an open cell, and a character "#" represents a blocked cell.

Output

Print one integer: the number of valid placements of Texas.

Examples
Input
3 3
...
...
...
Output
1
Input
4 5
.....
..#..
.....
.....
Output
2
Note

In the first example, the only valid placement is centered at row $$$2$$$, column $$$2$$$. It covers the center cell together with the cells directly above, below, to the left, and to the right.

In the second example, there are two valid placements. Their centers are at row $$$3$$$, column $$$2$$$ and row $$$3$$$, column $$$4$$$.

B. Kickoff Countdown (Easy)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

(The only difference between the easy and hard versions is the constraint on $$$n$$$.)

It's game day, and students are in DKR, eagerly watching the scoreboard clock counting down to kickoff. The countdown is displayed as $$$n$$$ mechanical flip-digit indicators, each showing a digit from $$$0-9$$$.

The clock is weird; when the display ticks down from $$$t$$$ to $$$t-1$$$, the digits do not flip all instantly. Instead, each digit that needs to change takes 1 second to flip. But digits can only be flipped once at a time.

So, for instance, if the clock ticks down from $$$\mathbf{67}$$$ to $$$\mathbf{66}$$$, it only takes 1 second, as only one digit changed. But if the clock ticks down from $$$\mathbf{900}$$$ to $$$\mathbf{899}$$$, it takes 3 seconds, as three digits changed.

Given how many seconds are currently displayed on the clock, the students are wondering how many actual seconds it will take until kickoff (when the clock has all digits showing $$$0$$$).

Input

The first line will contain $$$n$$$ $$$(1 \leq n \leq 6)$$$, the number of digits of the number.

The second line will be a string of $$$n$$$ digits, the current display on the clock. It is guaranteed that at least one digit is not zero.

Output

Print a single integer without leading zeros, the number of actual seconds left until kickoff.

Examples
Input
2
67
Output
73
Input
3
003
Output
3
Input
5
12345
Output
13715
Note

In the first example, there are 6 changes that take 2 seconds: $$$60$$$ to $$$59$$$, $$$50$$$ to $$$49$$$, $$$40$$$ to $$$39$$$, $$$30$$$ to $$$29$$$, $$$20$$$ to $$$19$$$, and $$$10$$$ to $$$09$$$. So, the total time is $$$2(6) + 1(67-6) = 73$$$.

C. Texas-Sized Nuggets
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Everything is bigger in Texas, so of course you want your chicken nuggets to be as big as it can be — but it still has to fit on your plate.

Your chicken nugget is described by $$$n$$$ points in the plane. The $$$i$$$-th point is at integer coordinates $$$(x_i, y_i)$$$ with $$$0 \le x_i, y_i \le 10^9$$$.

You are given an integer scaling factor $$$k$$$. Scaling the chicken nugget by $$$k$$$ moves every point $$$(x_i, y_i)$$$ to $$$(k \cdot x_i,\ k \cdot y_i)$$$. You may translate the chicken nugget after it is scaled, but you may not rotate it.

The plate is an axis-aligned square whose corners are $$$(0, 0)$$$ and $$$(m, m)$$$. The scaled chicken nugget fits on the plate if it is possible to translate it in such a way that every point lies inside the square or on its boundary.

Warning: you may need to use 64 bit integers for this problem!

Input

The first line contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le m \le 10^{18}$$$; $$$1 \le k \le 10^9$$$).

Each of the next $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$0 \le x_i, y_i \le 10^9$$$) — the coordinates of the $$$i$$$-th point. Points are not necessarily distinct.

Output

If the scaled chicken nuggy does not fit on the plate, print a single line containing -1.

Otherwise print the $$$n$$$ final points of the chicken nugget after scaling and possibly translating, one per line, each as two integers $$$k \cdot x_i$$$ and $$$k \cdot y_i$$$. The points may be printed in any order.

Examples
Input
3 10 2
5 5
6 7
5 8
Output
0 0
2 4
0 6
Input
2 5 3
0 0
2 2
Output
-1
Note

In the first sample, $$$k = 2$$$, so the points scale to $$$(10, 10)$$$, $$$(12, 14)$$$, and $$$(10, 16)$$$. As they stand they poke off the $$$10 \times 10$$$ billboard, but the scaled logo is only $$$2$$$ wide and $$$6$$$ tall, so shifting it by $$$(-10, -10)$$$ places it at $$$(0, 0)$$$, $$$(2, 4)$$$, $$$(0, 6)$$$ — entirely on the billboard.

In the second sample, $$$k = 3$$$ scales the logo to a $$$6 \times 6$$$ span, which is wider than the side length $$$5$$$, so no translation can make it fit and the answer is -1.

D. Spinnin' On It (Easy)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The difference between the versions is the constraint on $$$N$$$.

Although the Red River Rivalry is in Dallas nowadays, Akshaj decided to use the game as motivation to explore the state his new university would (yet again) thrash. While taking a unique route he stumbles upon the Great Prairie Wind Farm. The wind farm contains $$$N$$$ turbines in a row, where the $$$i$$$th turbine has rotation period $$$a_i$$$ seconds.

Akshaj wants to take a picture of these turbines, but he can only do so when they are all aligned in their "neutral" state. A picture is represented by a contiguous subsegment of the turbines, and if Akshaj has to wait longer than $$$T$$$ seconds for alignment he will opt to not take this photograph. Note that at $$$t=0$$$ all of the turbines are aligned at their "neutral" state, but Akshaj must take the photograph at a positive time $$$t \gt 0$$$.

Akshaj wants to make sure he has enough storage, and thus needs to know both how many pictures he can take and their total size. Can you help him out?

Input

The first line contains two integers: $$$N$$$ ($$$1 \le N \le 5000$$$) and $$$T$$$ ($$$1 \le T \le 10^6$$$), the number of turbines and the max time he will wait. The second line contains $$$N$$$ space-separated integers ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the rotation period of the $$$i$$$th turbine.

Output

Your output should be two space-separate integers $$$C$$$ and $$$S$$$. $$$C$$$ should be the number of pictures he can take, and $$$S$$$ should be the sum of the lengths of all pictures he can take.

Example
Input
4 3
2 4 1 3
Output
4 5
Note

In the sample test case, the possible pictures he can take (represented by the periods themselves and not the indices) are $$$[2]$$$, $$$[1]$$$, $$$[1,3]$$$, and $$$[3]$$$. The pictures below should help (courtesy of querying Astra with a rough sketch), where the black blade must be pointed directly up to be neutral.

$$$^\dagger$$$Like most things I write, the title of this problem was Kpop-inspired.

E. Speed at Terry Black's
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

On his tour across America, IShowSpeed (aka Darren Watkins Jr.) makes a stop at the legendary Terry Black's Barbecue, a staple of Austin.

The restaurant has $$$n$$$ $$$(1 \le n \le 10^5)$$$ tables arranged in a row, each with either a beef rib on top of it or not. More formally, let $$$s$$$ be a binary string of length $$$n$$$, where $$$s_i = 1$$$ if table $$$i$$$ has a beef rib, and $$$s_i = 0$$$ if table $$$i$$$ does not have a beef rib.

Speed is allowed to make exactly $$$2$$$ runs through the dining area. On each run, he chooses a contiguous range of exactly $$$k$$$ $$$(1 \le k \le n \le 10^5)$$$ tables and eats every rib on those tables. After a run, all ribs on the chosen tables have been eaten, so those tables contain no ribs for any future run. The two ranges are allowed to overlap, but a rib can only be eaten once, so any table included in both ranges contributes at most one rib to Speed's total.

Speed is very hungry after doing backflips and traveling around Austin all day, so he wants to maximize the number of beef ribs he eats. Help Speed figure out the maximum amount of beef ribs he can eat if he chooses where to make his runs optimally.

Input

The first line contains integers $$$n, k$$$ $$$(1 \le k \le n \le 10^5)$$$, the total number of tables and the number of tables Speed goes through in a run respectively.

The second line contains $$$s$$$, a binary string of length $$$n$$$, representing which tables contain dino ribs

Output

Output a single number, the total number of ribs Speed can eat if he chooses where to make his runs optimally.

Example
Input
11 3
01110100110
Output
5
Note

In the first test case, the answer is 5 as you can choose the two runs of size 3 ($$$k = 3$$$) as follows (the brackets here encapsulate where the runs are chosen)

$$$0[111]010[011]0$$$

Clearly, the sum of 1s in these two intervals is 5.

Note that in this case the intervals are disjoint, but this is not a requirement.

F. Texas-Sized Number
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

One day, Johnny thought of a non-negative integer $$$n$$$, but unfortunately, he thinks the number is too small.

To make the number bigger, Johnny decides to make the number a Texas-Sized Number. To find the Texas-Sized Number of $$$n$$$, Johnny must calculate $$$$$$n + 10 \cdot n + 100 \cdot n + 1000 \cdot n + ... + 10^{10^{10}} \cdot n.$$$$$$

However, because this number takes too long to calculate, Johnny is only interested in the most common digit in the Texas-Sized Number of $$$n$$$. Can you help him find this digit?

Input

The first line contains one non-negative integer $$$n$$$ — the number that Johnny thought of. This integer can be up to $$$10^5$$$ digits long.

Output

Output a single integer — the most common digit in the Texas-Sized Number of $$$n$$$. If there is a tie, output any most common digit.

Examples
Input
0
Output
0
Input
12
Output
3

G. Texas Two Step
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Cowboy Dance, Jenne Magafan, 1941.

At a Texas dance hall, $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) dancers are practicing the two-step. The dancers are numbered from $$$1$$$ to $$$n$$$, and each begins facing either left or right.

Dancer $$$i$$$ is a little particular: they only feel comfortable if at least $$$i$$$ remaining dancers, including themself, are facing the same direction.

The dance proceeds in beats. At the beginning of each beat, every remaining dancer counts how many dancers are facing the same direction as them.

If dancer $$$i$$$ sees fewer than $$$i$$$ dancers facing their direction, they get self-conscious. The first time this happens, they turn around, hoping to fit in better with the other side. If it happens again after they have already turned once, they give up and leave the dance floor.

All dancers make their decisions using the configuration at the beginning of the beat, and all actions happen simultaneously.

The dance ends when a beat passes in which nobody turns around or leaves.

Find the number of dancers remaining on the dance floor.

Input

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$)—the number of dancers.

The second line contains a string $$$s$$$ of length $$$n$$$, consisting only of the characters L and R.

The $$$i$$$-th character of $$$s$$$ describes the initial direction of dancer $$$i$$$. If $$$s_i$$$ is L, dancer $$$i$$$ initially faces left; otherwise, dancer $$$i$$$ initially faces right.

Output

Print a single integer—the number of dancers remaining when the dance ends.

Example
Input
5
LLRLR
Output
3
Note

Initially, dancers $$$3$$$, $$$4$$$, and $$$5$$$ are uncomfortable, so they turn around.

On the next beat, dancers $$$4$$$ and $$$5$$$ are uncomfortable again and leave the dance floor.

The remaining dancers $$$1$$$, $$$2$$$, and $$$3$$$ are all comfortable, so the dance ends with $$$3$$$ dancers remaining.

H. Kickoff Countdown (Hard)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

(The only difference between the easy and hard versions is the constraint on $$$n$$$.)

It's game day, and students are in DKR, eagerly watching the scoreboard clock counting down to kickoff. The countdown is displayed as $$$n$$$ mechanical flip-digit indicators, each showing a digit from $$$0-9$$$.

The clock is weird; when the display ticks down from $$$t$$$ to $$$t-1$$$, the digits do not flip all instantly. Instead, each digit that needs to change takes 1 second to flip. But digits can only be flipped once at a time.

So, for instance, if the clock ticks down from $$$\mathbf{67}$$$ to $$$\mathbf{66}$$$, it only takes 1 second, as only one digit changed. But if the clock ticks down from $$$\mathbf{900}$$$ to $$$\mathbf{899}$$$, it takes 3 seconds, as three digits changed.

Given how many seconds are currently displayed on the clock, the students are wondering how many actual seconds it will take until kickoff (when the clock has all digits showing $$$0$$$).

Input

The first line will contain $$$n$$$ $$$(1 \leq n \leq 10^5)$$$, the number of digits of the number.

The second line will be a string of $$$n$$$ digits, the current display on the clock. It is guaranteed that at least one digit is not zero.

Output

Print a single integer without leading zeros, the number of actual seconds left until kickoff. Note that this number can be huge.

Examples
Input
2
67
Output
73
Input
3
003
Output
3
Input
5
12345
Output
13715
Input
1
1
Output
1
Input
30
116605222020078348307278321906
Output
129561357800087053674753690995
Note

In the first example, there are 6 changes that take 2 seconds: $$$60$$$ to $$$59$$$, $$$50$$$ to $$$49$$$, $$$40$$$ to $$$39$$$, $$$30$$$ to $$$29$$$, $$$20$$$ to $$$19$$$, and $$$10$$$ to $$$09$$$. So, the total time is $$$2(6) + 1(67-6) = 73$$$.