2026 Spring UT CS104c Midterm #1
A. Factorial Frenzy
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You've studied how to count the number of 0 digits at the end of $$$n!$$$. But that was for numbers written in decimal. Real computer scientists think in binary! How many 0 digits are at the end of $$$n!$$$ when the result is expressed in binary?

Input

The only line of input contains a single integer $$$n$$$ $$$(1 \leq n \leq 10^6).$$$ (Note that this integer is written in decimal, not binary.)

Output

Print the number of 0 digits at the end of $$$n!$$$, when this integer is written in binary.

Examples
Input
1
Output
0
Input
8
Output
7
Input
1000000
Output
999993
Note

Factorials grow very quickly. Any solution that requires computing $$$n!$$$ as a first step will probably not work here!

B. Store Statistics
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Michael is the manager of a massive 24-hour supermarket. Using cameras at the doors, he has recorded the entry and exit times for $$$N$$$ customers.

He wants to calculate the following statistic: among $$$M$$$ minutes of the day, what is the median number of customers present in the store?

Input

The first line contains two integers, $$$N$$$ and $$$M$$$. Each of the following $$$N$$$ lines contains two integers, $$$t_{first}$$$ and $$$t_{last}$$$, representing the first and last minutes a customer spends in the store. The customer enters at the beginning of $$$t_{first}$$$ and leaves at the end of $$$t_{last}$$$.

  • $$$1 \leq N \leq 2 \cdot 10^5$$$
  • $$$1 \leq M \leq 2 \cdot 10^5$$$
  • $$$1 \leq t_{first} \leq t_{last} \leq M$$$
Output

Print the median number of customers present in the store. Your answer will be judged correct if it matches the judge solution with absolute or relative error at most $$$10^{-6}$$$.

Examples
Input
10 10
1 5
1 8
2 3
2 9
3 5
3 6
4 10
6 8
7 9
7 10
Output
5.5
Input
8 9
1 5
1 8
2 3
2 9
3 5
3 6
6 8
7 9
Output
4
Note

In the first input, the number of customers per minute is $$$[2, 4, 6, 6, 6, 5, 6, 6, 4, 2]$$$. The median of this list is $$$5.5$$$.

C. Group Movie Night
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

How often has this happened to you: you are trying to plan a group movie night, so you ask your friends if they'd like to join. "Well, I'm really busy with CS429 homework. But maybe if Cooper and Ava also come..."

You are given a list of friends, and for each friend, their dependencies. Each friend will attend the movie night if and only if all of their dependencies also attend.

You also have a list of best friends you definitely want there.

What is the minimum number of people you need to invite to the movie night so that your best friends attend?

Input

The first line of input contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$, the number of potential friends you could invite to the movie night. The next $$$n+1$$$ lines describe you and your friends. Each line begins with a string of between $$$2$$$ and $$$10$$$ ASCII uppercase and lowercase letters; this string is the name of one friend. Then follows an integer $$$k$$$ ($$$0 \leq k \leq n$$$), the number of people on that friend's list of dependencies. The line ends with $$$k$$$ space-separated strings, the names of the friends on the dependency list.

One row starts with the name You. The dependencies of You are the friends you want to be sure attend the movie night.

No two rows start with the same string. Every string in every dependency list is the name of somebody with a row in the input. Nobody is on their own dependency list, and the same name doesn't appear twice on any one dependency list.

Output

Print the minimum number of friends you need to invite (not including You) to guarantee that the people on You's dependency list show up.

Examples
Input
4
Brad 2 Cooper Ava
Cooper 0
Ava 2 Brad You
Annie 2 Brad Cooper
You 1 Brad
Output
3
Input
3
Yingying 2 You Luis
Luis 2 Yingying Mingyu
You 0
Mingyu 1 Luis
Output
0

D. Cubic Equation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given a cubic polynomial $$$$$$f(x) = x^3 + a x + b$$$$$$ it can be shown that if $$$a$$$ and $$$b$$$ are non-negative, then $$$f(x)$$$ has exactly one real root $$$f(r) = 0$$$. Find $$$r$$$.

Input

The only line of input contains two real numbers $$$a$$$ and $$$b$$$ $$$(0 \leq a,b \leq 10^9)$$$.

Output

Find the real root $$$r$$$ with $$$f(r) = 0$$$. It can be proved that exactly one such $$$r$$$ exists. Your answer will be judged correct if it matches the judge solution with absolute or relative error at most $$$10^{-6}$$$.

Examples
Input
0 0
Output
2.98023223876953125e-08
Input
3.14 1000000000.0
Output
-999.998953342059394344687461853
Input
6.0 7.0
Output
-0.9999999701976776123046875
Note

Hint 1: be sure to print your answer with lots of digits after the decimal point to make sure that it is within the absolute or relative error bounds.

Hint 2: be sure to use double-precision floating point numbers (not 32-bit floats).

E. Magikarp: Far From Home
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Magikarp likes to explore Karpville, but sometimes his phone runs out of battery when he is far from home. Karpville is made up of $$$n$$$ intersections and $$$m$$$ one-way streets, the $$$j$$$-th of which goes from intersection $$$u_j$$$ to intersection $$$v_j$$$ and takes $$$w_j$$$ minutes to drive.

Magikarp wonders, if he were to start at intersection $$$i$$$, what is the shortest amount of time (in minutes) it takes to reach his apartment, located at intersection $$$n$$$, if he is only allowed to drive? Help Magikarp answer this question for all intersections.

If Magikarp cannot drive back from some intersection, print $$$-1$$$ for that answer. Note that there can be multiple roads between the same pair of intersections.

Psst... the answers can exceed the size of a 32-bit integer!

Input

The first line of input contains $$$n$$$ and $$$m$$$ $$$(1\le n,m\le 2\cdot 10^5)$$$ — the number of intersections and the number of one-way streets, respectively.

The $$$j$$$-th of the next $$$m$$$ lines contains 3 integers $$$u_j$$$, $$$v_j$$$, and $$$w_j$$$ $$$(1\le u_j,v_j\le n, u_j\neq v_j, 0\le w_j\le 10^9)$$$ — the starting intersection, ending intersection, and distance (in minutes) for the $$$j$$$-th one-way road.

Output

Output $$$n$$$ lines, each containing a single integer. The $$$i$$$-th number should represent the shortest time (in minutes) it will take Magikarp to drive back to his apartment if he starts at intersection $$$i$$$, or $$$-1$$$ if this is impossible.

Examples
Input
3 3
1 2 1
2 3 2
1 3 5
Output
3
2
0
Input
6 9
1 2 1
2 1 0
5 2 0
3 2 4
4 5 3
3 4 2
3 5 7
5 6 2
5 6 0
Output
-1
-1
5
3
0
0