UTPC Contest 01-27-23 Div. 2 (Beginner)
A. Printing Papers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Michael owns a paper printing business and has a supplier who sells $$$n$$$ papers a week. However, Michael can only purchase papers in quantities that are powers of two. Given this information, output the maximum number of papers that Michael can purchase each week. Note that Michael can only make a single purchase.

Input

The first and only line of input will contain $$$n$$$ ($$$1 \leq n \leq 10^5$$$).

Output

Output the maximum number of papers that Michael can purchase in a single week.

Examples
Input
5
Output
4
Input
1
Output
1

B. Watch Your Sugar!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Thomas is looking forward to spending Valentine's Day with his girlfriend! His girlfriend of 5 years, Alice, has gifted Thomas a box of chocolates every year in their relationship. Thomas believes that this year is no exception. This year, however, Thomas has adopted a new, low-carb diet. This diet requires that he eats no more than $$$s$$$ grams of sugar every day.

Given $$$n$$$ integers, where each integer represents the grams of sugar in one of the chocolates, what is the maximum number of chocolates that Thomas can consume without going over his carbohydrate/sugar limit?

Input

The first line of input represents $$$n$$$ ($$$1 \leq n \leq 100$$$), the number of chocolates in the gifted box. The next line of input, $$$s$$$ ($$$0 \leq s \leq 10^4$$$), represents Thomas' sugar limit. The last line, containing $$$n$$$ integers, represents the grams of sugar in each chocolate in the box. Each chocolate can have $$$x$$$ ($$$1 \leq x \leq 5,000$$$) grams of sugar .

Output

Print a single number, the maximum number of chocolates that Thomas can consume without going over his sugar limit.

C. Flush-tastic Throwing Challenge
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The Thomas Crapper Company is hosting an office Olympics event and they want to see which employees have the best aim and accuracy when it comes to throwing an unspecified object. The main event of the office Olympics is the "Flush-tastic Throwing Challenge".

In this event, each of the $$$n$$$ employees will be asked to throw an object at a designated toilet bowl placed in the office. The company wants to know how many employees are able to successfully throw the object into the toilet bowl.

This toilet bowl is perfectly circular with center ($$$c_x$$$, $$$c_y$$$) and radius $$$r$$$. Additionally, the company has recorded that the $$$i$$$-th employee throws to the coordinate ($$$x_i$$$, $$$y_i$$$). A throw is successful if it lands within or exactly on the circular bowl.

Given the location of the employee's throws as well as the center and radius of the toilet bowl, determine the number of employees who are able to successfully throw the unspecified object into the toilet bowl.

Input

The first line of input will contain four integers, $$$n, c_x, c_y, r$$$. Where ($$$1 \leq n \leq 10^5$$$), $$$(-10^9 \leq c_x, c_y \leq 10^9)$$$, and $$$(1 \leq r \leq 10^9)$$$.

The next $$$n$$$ lines will each contain two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^9 \leq x_i, y_i \leq 10^9$$$).

Output

A single integer, the number of employees who are able to successfully throw the unspecified object into the toilet bowl.

Example
Input
4 1 2 5
0 0
-2 -2
5 6
3 3
Output
3

D. Speedy Stamping
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Another event in Crapper and Co.'s office olympics is the stamp race, which works the following way. Each employee has four stamps – one marked T (for Thomas), one marked C (for Crapper), one marked TC (for Thomas Crapper), and one marked CC (for Crapper and Co).

Thomas has prepared a desired string composed of only T's and C's. The employee who writes out the desired string the fastest, given only the four stamps, is declared the winner.

Thomas pays his employees minimum wage and does not particularly care who wins the race. However, he is curious as to what strategies his employees will employ. Can you determine how many ways the given string can be created using only the four stamps?

(The order in which stamps are employed does not matter, only which stamp is used for each letter.)

Input

The first line contains a single string $$$S$$$, composed of uppercase T's and C's, representing the target string to be stamped. ($$$1 \le |S| \le 10^6$$$)

Output

Output a single integer, denoting the number of ways the target string can be created using only the four stamps. Because this number can be very large, output it modulo $$$10^9 + 7$$$.

Example
Input
TCC
Output
3
Note

In the first test case, we can generate the string "TCC" in exactly three ways:

  • [T][C][C]
  • [TC][C]
  • [T][CC]

E. Brainless Brainstorming
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Michael has $$$N$$$ meeting slots numbered $$$1$$$ through $$$N$$$ ($$$1 \leq N \leq 1000$$$) on Brainstorming day. He would like to invite three of his employees, Jim, Dwight, and Kevin into his office to discuss ideas. During each time slot $$$i$$$, each employee will discuss a different number of ideas, denoted $$$a_i, b_i$$$, and $$$c_i$$$ ($$$0 \leq a_i, b_i, c_i \leq 1000$$$).

Michael can only invite at most one employee into his office during each meeting slot. In addition, Michael cannot have meetings during two consecutive meeting slots since he will get a headache. What is the maximum total number of ideas that can be discussed throughout the day?

Input

A single integer $$$N$$$ representing the number of meeting slots ($$$1 \leq N \leq 10^3$$$).

Then, there will be three lines, each with $$$N$$$ integers. These lines represent $$$a_i, b_i$$$, and $$$c_i$$$, respectively.

Output

A single integer representing the maximum total number of ideas that can be discussed.

Example
Input
5
3 0 3 1 2
3 1 4 4 4
1 2 1 4 4
Output
11

F. Toilet Orders
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Thomas is browsing his favorite catalog of toilet parts and is eager to order toilet bowls and toilet lids for his company, Thomas Crapper And Co in London. Together, one toilet bowl and one toilet lid make one toilet. The catalog knows that Thomas can potentially order many parts so they list their total supply in print. Specifically, Thomas knows that the catalog has $$$b$$$ bowls and $$$l$$$ lids. Due to complex supply and demand economics, Thomas has determined that it is most profitable for him to manufacture exactly $$$g$$$ new toilets, where $$$g$$$ is the greatest common divisor of $$$b$$$ and $$$l$$$. So, he will buy $$$g$$$ new bowls and $$$g$$$ new lids (which together make $$$g$$$ new toilets). For accounting purposes, Thomas wants to record how many new toilets $$$g$$$ were made by listing the prime factors of $$$g$$$ (in increasing order), along with their multiplicities (how many times a prime factor $$$p$$$ evenly divides $$$g$$$). Can you help Thomas?

Input

The first line of input will contain $$$T$$$ $$$(1 \leq T \leq 100)$$$, the number of test cases to follow. The next $$$T$$$ lines of input will contain $$$b$$$ $$$(2 \leq b \leq 10^{12})$$$ bowls and $$$l$$$ $$$(2 \leq l \leq 10^{12})$$$ separated by a single space.

Output

For each test case, output a list of the $$$k$$$ distinct prime factors (along with their multiplicities) of $$$g$$$ in increasing order, where $$$g$$$ is the total number of new toilets that Thomas will make. Note that if $$$g = 1$$$ then no prime factors should be outputted. Among each test case, the $$$i$$$-th line of output should contain the $$$i$$$-th smallest distinct prime factor $$$p_i$$$ of $$$g$$$, followed by a single space, followed by the multiplicity of $$$p_i$$$ in $$$g$$$. End every test case by printing a "0". And repeat for all test cases.

Examples
Input
1
360 240
Output
2 3
3 1
5 1
0
Input
2
83 24
15 25
Output
0
5 1
0
Note

For the first sample test case, see how the greatest common divisor of $$$360$$$ and $$$240$$$ is $$$120 = 2^3 * 3 * 5$$$.

For the second sample test case, see how the gcd of 83 and 24 is 1, and hence no prime factors were printed. The gcd of 15 and 25 is 5, and 5 is prime and has multiplicity one in 5.

IMPORTANT TIP: IF WRITING IN PYTHON AND YOU GET TIME LIMIT EXCEEDED, REMEMBER TO SELECT PYPY WHILE SUBMITTING

G. Crappy Typing
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

One of the most anticipated events of the Office Olympics is speed typing. Employees compete by taking a typing test. There are $$$N$$$ employees participating, and since there are limited computers, employees must wait in line to take the test.

In preparation for the event, Manager Michael needs to set up $$$M$$$ computers, which can accommodate $$$M$$$ employees taking the test simultaneously. From last year's competition data, Michael estimates that the $$$i$$$-th employee will take $$$t_i$$$ time to finish the test. At the beginning of the contest, the first $$$M$$$ employees in line will start at an arbitrary computer. The moment an employee finishes the test, the next employee in line will take their place at the same computer. The contest ends when the $$$N$$$-th employee in line finishes the test.

To ensure that the next event can start on time, the entire typing contest must end within $$$D$$$ total time units or less. As Michael is lazy, please help him find the smallest possible value of $$$M$$$ that will ensure the contest finishes within $$$D$$$ total time units or less.

Input

The first line of input contains two integers $$$N, D$$$ ($$$1 \leq N \leq 10^5, 1 \leq D \leq 10^9$$$) as described above.

The next line of input contains $$$N$$$ integers separated by spaces. The $$$i^{th}$$$ integer denotes $$$t_i$$$ ($$$1 \leq t_i \leq 10^4$$$).

It is guaranteed that $$$M$$$ exists with the given input.

Output

Output a single line containing $$$M$$$, the minimum number of computers required.

Examples
Input
6 151
56 94 95 33 62 28
Output
3
Input
9 83
10 47 53 9 83 33 15 24 28
Output
5

H. Crapper's Collapse Catastrophe
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Crapper and Co. is moving into a new office building. The front-desk (and the first floor) is located at room $$$0$$$. Rooms on even floors will each lead to $$$a$$$ rooms above it. Similarly, odd rooms will lead to $$$b$$$ rooms in the same fashion.

As you, the newest employee, are moving into your office at room $$$x$$$, an earthquake strikes, causing the building to begin to collapse. Before you inevitably die, you call the CEO Thomas to meet him, who is in his office at room $$$y$$$. As the benevolent CEO, Thomas agrees, but doesn't know where to meet you. Knowing that the building is collapsing, you calculate meeting location $$$m$$$ which minimizes the sum of your downwards travel distances (you can only travel this way because the tower is collapsing, so it doesn't make sense to go up) so you can finally meet the CEO. You call the CEO to meet at room $$$m$$$, and the two of you finally meet before the room collapses.

Input

The first and only line of input contains four integers $$$a, b, x, y$$$ $$$(2\leq a, b\leq 10^9, 0\leq x, y\leq 10^9)$$$.

Output

The room number of your meeting location $$$m$$$.

Example
Input
2 3 11 12
Output
4
Note

For the example input, the office building roughly looks like the following:

I. Drunk Coworker
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You enter into the office only to be greeted by your drunk coworker, Thomas Crapper!

You try to avoid him as he stumbles across the room. His path can roughly be approximated by a quadratic function $$$f$$$ on the Cartesian Coordinate system. Since he is drunk, his eyesight is blurry, so at any point he can only see $$$k$$$ meters above and below him. To avoid a potential disaster, please find the total area of all the regions you can stand in order to not be spotted by your drunk coworker.

Input

The first line contains a sequence of three real numbers $$$a_2, a_1, a_0$$$ ($$$-100000 \leq a_2, a_1, a_0 \leq 100000$$$), the coefficients of the polynomial $$$f = a_2x^2 + a_1x + a_0$$$.

The second line contains a positive real number $$$k$$$ ($$$0 \leq k \leq 100$$$), the radius of his line of sight.

The last line contains four real numbers $$$x_1, y_1, x_2, y_2$$$ ($$$-100000 \leq x_1,y_1,x_2,y_2 \leq 100000$$$) for $$$x_1 \lt x_2$$$, $$$y_1 \lt y_2$$$, where $$$(x_1,y_1)$$$ and $$$(x_2,y_2)$$$ indicate the coordinates of the lower left-hand corner and upper right-hand corner of the room respectively.

Output

Output a real number that is the total area you can stand as to not be spotted by your drunk coworker.

Your answer is considered correct if its absolute error doesn't exceed $$$10^{−6}$$$.

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

You can assume that Thomas completely enters and exits from some part of the room.