vgel/INTELLECT-2-RL-Dataset-Code-Only huggingface dataset:
Title: Road to Post Office

Time Limit: None seconds

Memory Limit: None megabytes

Problem Description:
Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to *d* kilometers.

Vasiliy's car is not new — it breaks after driven every *k* kilometers and Vasiliy needs *t* seconds to repair it. After repairing his car Vasiliy can drive again (but after *k* kilometers it will break again, and so on). In the beginning of the trip the car is just from repair station.

To drive one kilometer on car Vasiliy spends *a* seconds, to walk one kilometer on foot he needs *b* seconds (*a*<=&lt;<=*b*).

Your task is to find minimal time after which Vasiliy will be able to reach the post office. Consider that in every moment of time Vasiliy can left his car and start to go on foot.

Input Specification:
The first line contains 5 positive integers *d*,<=*k*,<=*a*,<=*b*,<=*t* (1<=≤<=*d*<=≤<=1012; 1<=≤<=*k*,<=*a*,<=*b*,<=*t*<=≤<=106; *a*<=&lt;<=*b*), where:
 -  *d* — the distance from home to the post office; -  *k* — the distance, which car is able to drive before breaking; -  *a* — the time, which Vasiliy spends to drive 1 kilometer on his car; -  *b* — the time, which Vasiliy spends to walk 1 kilometer on foot; -  *t* — the time, which Vasiliy spends to repair his car.

Output Specification:
Print the minimal time after which Vasiliy will be able to reach the post office.

Demo Input:
['5 2 1 4 10\n', '5 2 1 4 5\n']

Demo Output:
['14\n', '13\n']

Note:
In the first example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds) and then to walk on foot 3 kilometers (in 12 seconds). So the answer equals to 14 seconds.

In the second example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds), then repair his car (in 5 seconds) and drive 2 kilometers more on the car (in 2 seconds). After that he needs to walk on foot 1 kilometer (in 4 seconds). So the answer equals to 13 seconds.

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
Gerald’s job is to welcome the teams for this year’s NWERC at the airport in Linköping. One of his duties is to stand at the luggage carousel and collect all the knapsacks that the teams are bringing. Gerald is a lazy person, so he just stands at the same position of the carousel and waits for bags to pass by so he can pick them up. 

The baggage carousel consists of $s$ luggage slots, numbered in ascending order from $0$ to $s-1$. Since the baggage carousel is cyclic, luggage slots $s-1$ and $0$ also lie side by side. The carousel turns in such a way that if Gerald stands in front of slot $i$ at some point in time, he will stand in front of slot $(i+1) \bmod s$ one time unit later.

In the beginning Gerald prepares a huge baggage cart at some position and stands there to wait for luggage. When a knapsack arrives in front of Gerald, he needs $t$ time units to take it and put it on the baggage cart. After these $t$ time units he is ready to pick up another knapsack. As long as there are remaining knapsacks on the luggage carousel, Gerald always takes the next one to arrive at his position as soon as he is ready after putting away the previous one.

Now Gerald wonders about the effect of his choice of position on the time it will take him to finish this task. It is up to you to help Gerald calculate the minimum, maximum, and average time to pick up all knapsacks, taken over all $s$ possible slots, which can appear in front of Gerald after preparation. Time starts when he has prepared the baggage cart at some slot of the baggage carousel and ends after he has put the last knapsack on the cart.

-----Input-----
The input consists of:
 - one line with three integers $n$ ($1\le n\le 2000$), $s$ ($1\le s\le 10^7$) and $t$ ($1\le t \le 10^7$), where $n$ is the number of knapsacks to pick up, $s$ is the number of slots of the carousel, and $t$ is the number of time units Gerald needs to pick up a knapsack from the carousel and put it on the cart;
 - one line with $n$ integers $k_1, \ldots , k_ n$ ($0 \le k_ i \le s-1$ for $1 \le i \le n$), the slots of the knapsacks.

There may be several knapsacks stacked on top of each other in the same slot, but Gerald can still only pick up one knapsack at a time.

-----Output-----
Output three lines of output containing the minimum, maximum, and average time to pick up all the luggage, over all $s$ positions. The average time should be output as a reduced fraction in the form $p/q$.

-----Examples-----
Sample Input 1:
7 10 10000000
0 0 0 0 0 0 1
Sample Output 1:
70000001
70000009
350000027/5

Sample Input 2:
10 10 3
0 0 2 2 4 4 6 6 8 8
Sample Output 2:
39
40
79/2

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
You have been hired by Addictive Coin Machines to help design the next hit in their line of eye-catching, coin-guzzling, just-one-more-try Pachinko machines for casinos around the world.

Playing a Pachinko machine involves launching balls into a rectangular grid filled with pegs, obstacles, and targets. The ball bounces around the grid until it eventually hits one of the targets. The player earns a certain number of points depending on which target is hit.

The grid pattern for the next Pachinko machine has already been designed, but point values for the targets have not been assigned. These must be set so that like all casino machines, the machine is profitable but not too profitable. Thus it is important to figure out the probability of a ball hitting any particular target. That’s your job!

For simplicity, the grid is modeled as a tall rectangle filled with mostly-open spaces (each represented by ‘.’), impassable obstacles (each represented by ‘X’), and targets (each represented by ‘T’).

A ball is launched randomly with uniform probability into one of the mostly-open spaces on the top row of the grid. From that point on, collisions with pegs cause the ball to randomly bounce up, down, left, or right, with various given probabilities. For simplicity, assume these probabilities are the same for every space in the grid. If the ball bounces into an obstacle or attempts to move off the grid, it won’t actually move from its current space. When the ball moves into a target it is removed from play.

You can safely assume that the average number of spaces visited by a ball before hitting a target will not exceed $10^{9}$. It would not make for a very enjoyable game if the ball just bounces forever!

For each target, calculate the probability that it is the one hit by a launched ball.

-----Input-----
The input consists of a single test case. The first line contains integers $w$ and $h$, which are the width and height of the Pachinko grid ($1 \leq w \leq 20$ and $2 \leq h \leq 10000$). The next line contains four non-negative integers $u$, $d$, $l$, and $r$, which sum to 100 and are the percentage probabilities of the ball bouncing up, down, left, or right from any open space.

Each of the next $h$ lines contains $w$ characters, each of which is ‘.’, ‘X’, or ‘T’. These lines describe the Pachinko grid. The first line, which describes the top row of the grid, contains at least one ‘.’ and no ‘T’s.

-----Output-----
Display one line for each ‘T’ in the grid, in order from top to bottom, breaking ties left to right. For each target, display the probability that a launched ball will hit it. Give the answer with an absolute error of at most $10^{-6}$.

-----Examples-----
Sample Input:
3 2
20 20 20 40
X.X
T.T
Sample Output:
0.333333333
0.666666667

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic check.

Web-developers of the company Q assume that a password is complex enough, if it meets all of the following conditions:  the password length is at least 5 characters;  the password contains at least one large English letter;  the password contains at least one small English letter;  the password contains at least one digit. 

You are given a password. Please implement the automatic check of its complexity for company Q.


-----Input-----

The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_".


-----Output-----

If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes).


-----Examples-----
Input
abacaba

Output
Too weak

Input
X12345

Output
Too weak

Input
CONTEST_is_STARTED!!11

Output
Correct

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.

Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that:   this list contains all Jinotega's flights in this year (in arbitrary order),  Jinotega has only flown from his hometown to a snooker contest and back,  after each competition Jinotega flies back home (though they may attend a competition in one place several times),  and finally, at the beginning of the year Jinotega was at home. 

Please help them to determine Jinotega's location!


-----Input-----

In the first line of input there is a single integer n: the number of Jinotega's flights (1 ≤ n ≤ 100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next n lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport.

It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement.


-----Output-----

If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".


-----Examples-----
Input
4
SVO
SVO->CDG
LHR->SVO
SVO->LHR
CDG->SVO

Output
home

Input
3
SVO
SVO->HKT
HKT->SVO
SVO->RAP

Output
contest



-----Note-----

In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
Mutual Recursion allows us to take the fun of regular recursion (where a function calls itself until a terminating condition) and apply it to multiple functions calling each other! 

Let's use the Hofstadter Female and Male sequences to demonstrate this technique. You'll want to create two functions `F` and `M` such that the following equations are true: 

```
F(0) = 1
M(0) = 0
F(n) = n - M(F(n - 1))
M(n) = n - F(M(n - 1))
```

Don't worry about negative numbers, `n` will always be greater than or equal to zero.

~~~if:php,csharp
You *do* have to worry about performance though, mutual recursion uses up a lot of stack space (and is highly inefficient) so you may have to find a way to make your solution consume less stack space (and time).  Good luck :)
~~~

Hofstadter Wikipedia Reference http://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter_Female_and_Male_sequences

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
Tired of playing Counter strike at every fest, well we can't do anything about it but we can sure give you a new game to play regardless of the fact that it ain't anything like GTA V or Mad Max but it sure can get you one step closer to glory you are entitled for.   

So the rules are simple we would provide you with first(A) and second(B) number of the series and the rest you have to figure out by the given formula. To simplify it we will give you the first and second number of the series and will ask you to calculate the Nth number of that series.  

To calculate I(n+2) =(I(n+1))^2 +I(n) 
So, if the first two terms of the series are 0 and 1: 
the third term = 1^2 + 0 = 1
fourth term = 1^2 + 1 = 2 
fifth term = 2^2 + 1 = 5 
... And so on.

Input format:
Three spaced integer. First is A, second is B and third is Nth number you’ve to calculate.

Output format:
One integer i.e the Nth number of the series when the first and second number of the series A and B are given.

Constraints:
A ≥ 0
B ≥ 0
0 < N < 9,223,372,036,854,775,807

SAMPLE INPUT
0 1 5

SAMPLE OUTPUT
5

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef is attending math classes. On each day, the teacher gives him homework. Yesterday, the teacher gave Chef a sequence of positive integers and asked him to find the maximum product of two different elements of this sequence. This homework was easy for Chef, since he knew that he should select the biggest two numbers.

However, today, the homework is a little bit different. Again, Chef has a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$, but he should find two different elements of this sequence such that the sum of digits (in base $10$) of their product is maximum possible.

Chef thought, mistakenly, that he can still select the two largest elements and compute the sum of digits of their product. Show him that he is wrong by finding the correct answer ― the maximum possible sum of digits of a product of two different elements of the sequence $A$.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains a single integer $N$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.

------  Output ------
For each test case, print a single line containing one integer ― the maximum sum of digits.

------  Constraints ------
$1 ≤ T ≤ 100$
$2 ≤ N ≤ 100$
$1 ≤ A_{i} ≤ 10^{4}$ for each valid $i$

------  Subtasks ------
Subtask #1 (100 points): original constraints

----- Sample Input 1 ------ 
3

2

2 8

3 

8 2 8

3

9 10 11
----- Sample Output 1 ------ 
7

10

18
----- explanation 1 ------ 
Example case 1: The only two numbers Chef can choose are $2$ and $8$. Their product is $16$ and the sum of digits of $16$ is $7$.

Example case 2: Chef can choose $8$ and $8$; their product is $64$. Note that it is allowed to choose two different elements with the same value.

Example case 3: Chef can choose $9$ and $11$. Their product is $99$ and the sum of its digits is $18$. Note that choosing $10$ and $11$ will result in a larger product ($110$), but the sum of its digits is just $2$.

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
There are N apple trees in a row. People say that one of them will bear golden apples.
We want to deploy some number of inspectors so that each of these trees will be inspected.
Each inspector will be deployed under one of the trees. For convenience, we will assign numbers from 1 through N to the trees. An inspector deployed under the i-th tree (1 \leq i \leq N) will inspect the trees with numbers between i-D and i+D (inclusive).
Find the minimum number of inspectors that we need to deploy to achieve the objective.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 20
 - 1 \leq D \leq 20

-----Input-----
Input is given from Standard Input in the following format:
N D

-----Output-----
Print the minimum number of inspectors that we need to deploy to achieve the objective.

-----Sample Input-----
6 2

-----Sample Output-----
2

We can achieve the objective by, for example, placing an inspector under Tree 3 and Tree 4.

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
Title: Power Substring

Time Limit: None seconds

Memory Limit: None megabytes

Problem Description:
You are given *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*.

For every *a**i* you need to find a positive integer *k**i* such that the decimal notation of 2*k**i* contains the decimal notation of *a**i* as a substring among its last *min*(100,<=*length*(2*k**i*)) digits. Here *length*(*m*) is the length of the decimal notation of *m*.

Note that you don't have to minimize *k**i*. The decimal notations in this problem do not contain leading zeros.

Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2<=000) — the number of integers *a**i*.

Each of the next *n* lines contains a positive integer *a**i* (1<=≤<=*a**i*<=&lt;<=1011).

Output Specification:
Print *n* lines. The *i*-th of them should contain a positive integer *k**i* such that the last *min*(100,<=*length*(2*k**i*)) digits of 2*k**i* contain the decimal notation of *a**i* as a substring. Integers *k**i* must satisfy 1<=≤<=*k**i*<=≤<=1050.

It can be shown that the answer always exists under the given constraints. If there are multiple answers, print any of them.

Demo Input:
['2\n8\n2\n', '2\n3\n4857\n']

Demo Output:
['3\n1\n', '5\n20\n']

Note:
none

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
Given a binary grid of n*m. Find the distance of the nearest 1 in the grid for each cell.
The distance is calculated as |i_{1}  - i_{2}| + |j_{1} - j_{2}|, where i_{1}, j_{1} are the row number and column number of the current cell, and i_{2}, j_{2} are the row number and column number of the nearest cell having value 1. There should be atleast one 1 in the grid.
 
Example 1:
Input: grid = {{0,1,1,0},{1,1,0,0},{0,0,1,1}}
Output: {{1,0,0,1},{0,0,1,1},{1,1,0,0}}
Explanation: The grid is-
0 1 1 0 
1 1 0 0 
0 0 1 1 
0's at (0,0), (0,3), (1,2), (1,3), (2,0) and
(2,1) are at a distance of 1 from 1's at (0,1),
(0,2), (0,2), (2,3), (1,0) and (1,1)
respectively.
Example 2:
Input: grid = {{1,0,1},{1,1,0},{1,0,0}}
Output: {{0,1,0},{0,0,1},{0,1,2}}
Explanation: The grid is-
1 0 1
1 1 0
1 0 0
0's at (0,1), (1,2), (2,1) and (2,2) are at a 
distance of 1, 1, 1 and 2 from 1's at (0,0),
(0,2), (2,0) and (1,1) respectively.
 
Yout Task:
You don't need to read or print anything, Your task is to complete the function nearest() which takes the grid as an input parameter and returns a matrix of the same dimensions where the value at index (i, j) in the resultant matrix signifies the minimum distance of 1 in the matrix from grid[i][j].
 
Expected Time Complexity: O(n*m)
Expected Auxiliary Space: O(n*m)
Constraints:
1 ≤ n, m ≤ 500

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
Let's consider a random permutation p_{1}, p_{2}, ..., p_{N} of numbers 1, 2, ..., N and calculate the value F=(X_{2}+...+X_{N-1})^{K}, where X_{i} equals 1 if one of the following two conditions holds: p_{i-1} < p_{i} > p_{i+1} or p_{i-1} > p_{i} < p_{i+1} and X_{i} equals 0 otherwise. What is the expected value of F?

Input Format: 

The first line contains two integers K and N.

Output Format: 

Print the expected value of F as an irreducible fraction p / q. Follow sample input for more clarification.

Constraints: 

1000 <= N <= 10^{9} 

1 <= K <= 5

Sample input  

1 1000

Sample Output  

1996 / 3

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
You still have partial information about the score during the historic football match. You are given a set of pairs $(a_i, b_i)$, indicating that at some point during the match the score was "$a_i$: $b_i$". It is known that if the current score is «$x$:$y$», then after the goal it will change to "$x+1$:$y$" or "$x$:$y+1$". What is the largest number of times a draw could appear on the scoreboard?

The pairs "$a_i$:$b_i$" are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match.


-----Input-----

The first line contains a single integer $n$ ($1 \le n \le 10000$) — the number of known moments in the match.

Each of the next $n$ lines contains integers $a_i$ and $b_i$ ($0 \le a_i, b_i \le 10^9$), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team).

All moments are given in chronological order, that is, sequences $x_i$ and $y_j$ are non-decreasing. The last score denotes the final result of the match.


-----Output-----

Print the maximum number of moments of time, during which the score was a draw. The starting moment of the match (with a score 0:0) is also counted.


-----Examples-----
Input
3
2 0
3 1
3 4

Output
2

Input
3
0 0
0 0
0 0

Output
1

Input
1
5 4

Output
5



-----Note-----

In the example one of the possible score sequences leading to the maximum number of draws is as follows: 0:0, 1:0, 2:0, 2:1, 3:1, 3:2, 3:3, 3:4.

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
You are given a string S. Find the number of different substrings in S.

Input
One line containing a string S consisting of lowercase Latin letters.

Output
Output one integer - answer to the question.

Constraints
1 ≤ length of S ≤ 1200

SAMPLE INPUT
abc

SAMPLE OUTPUT
6

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.
Title: Simple Subset

Time Limit: None seconds

Memory Limit: None megabytes

Problem Description:
A tuple of positive integers {*x*1,<=*x*2,<=...,<=*x**k*} is called simple if for all pairs of positive integers (*i*,<=<=*j*) (1<=<=≤<=*i*<=<=&lt;<=<=*j*<=≤<=*k*), *x**i*<=<=+<=<=*x**j* is a prime.

You are given an array *a* with *n* positive integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (not necessary distinct). You want to find a simple subset of the array *a* with the maximum size.

A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.

Let's define a subset of the array *a* as a tuple that can be obtained from *a* by removing some (possibly all) elements of it.

Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of integers in the array *a*.

The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array *a*.

Output Specification:
On the first line print integer *m* — the maximum possible size of simple subset of *a*.

On the second line print *m* integers *b**l* — the elements of the simple subset of the array *a* with the maximum size.

If there is more than one solution you can print any of them. You can print the elements of the subset in any order.

Demo Input:
['2\n2 3\n', '2\n2 2\n', '3\n2 1 1\n', '2\n83 14\n']

Demo Output:
['2\n3 2\n', '1\n2\n', '3\n1 1 2\n', '2\n14 83\n']

Note:
none

Write Python code to solve the problem. Present the code in 
```python
Your code
```
at the end.