context
stringlengths 88
7.54k
| groundtruth
stringlengths 9
28.8k
| groundtruth_language
stringclasses 3
values | type
stringclasses 2
values | code_test_cases
listlengths 1
565
⌀ | dataset
stringclasses 6
values | code_language
stringclasses 1
value | difficulty
float64 0
1
⌀ | mid
stringlengths 32
32
|
---|---|---|---|---|---|---|---|---|
Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2v - 1 for some integer v (v ≥ 0).
Help Ivan, find the required quantity of numbers.
Input
The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an.
Output
Print a single integer — the answer to the problem.
Examples
Input
4
0 1 1 1
Output
0
Input
1
3
Output
3
Note
In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7.
In the second sample you need to add numbers 20, 21, 22.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n = int(input())
a = list(map(int, input().split()))
s = set()
for i in a:
j = i
while j in s:
s.remove(j)
j += 1
s.add(j)
print(max(s)-len(s)+1)
|
python
|
code_algorithm
|
[
{
"input": "1\n3\n",
"output": "3\n"
},
{
"input": "4\n0 1 1 1\n",
"output": "0\n"
},
{
"input": "1\n2000000000\n",
"output": "2000000000\n"
},
{
"input": "26\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\n",
"output": "5\n"
},
{
"input": "1\n0\n",
"output": "0\n"
},
{
"input": "1\n1\n",
"output": "1\n"
}
] |
code_contests
|
python
| 0 |
996972fd97f33ca42cebd7a646799e84
|
Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.
For another exercise, Pasha needs exactly <image> hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well?
Input
The first line contains integer n (2 ≤ n ≤ 200; n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting.
Output
In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them.
Examples
Input
4
xxXx
Output
1
XxXx
Input
2
XX
Output
1
xX
Input
6
xXXxXx
Output
0
xXXxXx
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n = int(input())
s = str(input())
half = n//2
sit = s.count('x')
stand = s.count('X')
ans = max(sit, stand) - half
t = ans
while ans!=0:
if sit>stand:
temp = s.index('x')
s = s[:temp] + 'X' + s[temp+1:]
sit = sit-1
stand = stand +1
ans = ans -1
else:
temp = s.index('X')
s = s[:temp] + 'x' + s[temp+1:]
sit = sit+1
stand = stand - 1
ans = ans -1
print(t)
print(s)
|
python
|
code_algorithm
|
[
{
"input": "2\nXX\n",
"output": "1\nxX\n"
},
{
"input": "6\nxXXxXx\n",
"output": "0\nxXXxXx\n"
},
{
"input": "4\nxxXx\n",
"output": "1\nXxXx\n"
},
{
"input": "4\nXXXX\n",
"output": "2\nxxXX\n"
},
{
"input": "200\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n",
"output": "100\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
},
{
"input": "104\nxxXxXxxXXXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX\n",
"output": "4\nxxxxxxxxxXxxXxXxxXXXxxxXxxXXXxxXXXxXxXxXXxxXxxxxxXXXXxXXXXxXXXxxxXxxxxxxxXxxXxXXxxXXXXxXXXxxXXXXXXXXXxXX\n"
},
{
"input": "4\nxxxx\n",
"output": "2\nXXxx\n"
},
{
"input": "4\nXXxx\n",
"output": "0\nXXxx\n"
},
{
"input": "198\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n",
"output": "99\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
},
{
"input": "4\nxxxX\n",
"output": "1\nXxxX\n"
},
{
"input": "4\nxxXX\n",
"output": "0\nxxXX\n"
},
{
"input": "2\nxX\n",
"output": "0\nxX\n"
},
{
"input": "30\nXXxXxxXXXXxxXXxxXXxxxxXxxXXXxx\n",
"output": "0\nXXxXx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XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n",
"output": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
},
{
"input": "6\nxXXxXX\n",
"output": "1\nxxXxXX\n"
},
{
"input": "4\nxXxx\n",
"output": "1\nXXxx\n"
},
{
"input": "4\nXXxX\n",
"output": "1\nxXxX\n"
},
{
"input": "200\nxxXXxxXXxXxxXxxXxXxxXxXxXxXxxxxxXXxXXxxXXXXxXXXxXXxXxXxxxxXxxXXXxxxXxXxxxXxxXXxXxXxxxxxxxXxxXxXxxXxXXXxxXxXXXXxxXxxxXxXXXXXXxXxXXxxxxXxxxXxxxXxXXXxXxXXXXxXXxxxXxXXxxXXxxxXxXxXXxXXXxXxXxxxXXxxxxXXxXXXX\n",
"output": "4\nXXXXXXXXxXxxXxxXxXxxXxXxXxXxxxxxXXxXXxxXXXXxXXXxXXxXxXxxxxXxxXXXxxxXxXxxxXxxXXxXxXxxxxxxxXxxXxXxxXxXXXxxXxXXXXxxXxxxXxXXXXXXxXxXXxxxxXxxxXxxxXxXXXxXxXXXXxXXxxxXxXXxxXXxxxXxXxXXxXXXxXxXxxxXXxxxxXXxXXXX\n"
},
{
"input": "4\nXxXx\n",
"output": "0\nXxXx\n"
},
{
"input": "4\nXxXX\n",
"output": "1\nxxXX\n"
},
{
"input": "4\nxXXX\n",
"output": "1\nxxXX\n"
},
{
"input": "4\nXxxx\n",
"output": "1\nXXxx\n"
},
{
"input": "78\nxxxXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXxxxxXxxXXXxxxxxxxxXXXXxXxXXxXXXxXX\n",
"output": "3\nXXXXxxXxXxxXxxxxxXxXXXxXXXXxxxxxXxXXXxxXxXXXxxxxXxxXXXxxxxxxxxXXXXxXxXXxXXXxXX\n"
},
{
"input": "2\nxx\n",
"output": "1\nXx\n"
}
] |
code_contests
|
python
| 0.2 |
339099d9184a0c98c5f75d2adf924c86
|
One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n. Let's assume that Misha chose number m, and Andrew chose number a.
Then, by using a random generator they choose a random integer c in the range between 1 and n (any integer from 1 to n is chosen with the same probability), after which the winner is the player, whose number was closer to c. The boys agreed that if m and a are located on the same distance from c, Misha wins.
Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and number n. You need to determine which value of a Andrew must choose, so that the probability of his victory is the highest possible.
More formally, you need to find such integer a (1 ≤ a ≤ n), that the probability that <image> is maximal, where c is the equiprobably chosen integer from 1 to n (inclusive).
Input
The first line contains two integers n and m (1 ≤ m ≤ n ≤ 109) — the range of numbers in the game, and the number selected by Misha respectively.
Output
Print a single number — such value a, that probability that Andrew wins is the highest. If there are multiple such values, print the minimum of them.
Examples
Input
3 1
Output
2
Input
4 3
Output
2
Note
In the first sample test: Andrew wins if c is equal to 2 or 3. The probability that Andrew wins is 2 / 3. If Andrew chooses a = 3, the probability of winning will be 1 / 3. If a = 1, the probability of winning is 0.
In the second sample test: Andrew wins if c is equal to 1 and 2. The probability that Andrew wins is 1 / 2. For other choices of a the probability of winning is less.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n,m = map(int, input().split())
p = [m+int(m<n),m-int(m>1)]
print(p[n-m<=m-1])
|
python
|
code_algorithm
|
[
{
"input": "3 1\n",
"output": "2\n"
},
{
"input": "4 3\n",
"output": "2\n"
},
{
"input": "692501734 346250868\n",
"output": "346250867\n"
},
{
"input": "616075979 207073797\n",
"output": "207073798\n"
},
{
"input": "296647497 148323750\n",
"output": "148323749\n"
},
{
"input": "401241775 170032078\n",
"output": "170032079\n"
},
{
"input": "4 2\n",
"output": "3\n"
},
{
"input": "541904957 459371829\n",
"output": "459371828\n"
},
{
"input": "5 3\n",
"output": "2\n"
},
{
"input": "3 2\n",
"output": "1\n"
},
{
"input": "971573366 216791157\n",
"output": "216791158\n"
},
{
"input": "5 1\n",
"output": "2\n"
},
{
"input": "12412523 125123\n",
"output": "125124\n"
},
{
"input": "619189108 309594555\n",
"output": "309594554\n"
},
{
"input": "746085224 373042613\n",
"output": "373042612\n"
},
{
"input": "404354904 202177453\n",
"output": "202177452\n"
},
{
"input": "100 51\n",
"output": "50\n"
},
{
"input": "189520699 94760350\n",
"output": "94760349\n"
},
{
"input": "2 2\n",
"output": "1\n"
},
{
"input": "51 1\n",
"output": "2\n"
},
{
"input": "81813292 40906647\n",
"output": "40906646\n"
},
{
"input": "186407570 160453970\n",
"output": "160453969\n"
},
{
"input": "262833325 131416663\n",
"output": "131416662\n"
},
{
"input": "2 1\n",
"output": "2\n"
},
{
"input": "1000000000 1000000000\n",
"output": "999999999\n"
},
{
"input": "925779379 720443954\n",
"output": "720443953\n"
},
{
"input": "7 4\n",
"output": "3\n"
},
{
"input": "355447788 85890184\n",
"output": "85890185\n"
},
{
"input": "570281992 291648263\n",
"output": "291648262\n"
},
{
"input": "4 1\n",
"output": "2\n"
},
{
"input": "54645723 432423\n",
"output": "432424\n"
},
{
"input": "5 4\n",
"output": "3\n"
},
{
"input": "477667530 238833766\n",
"output": "238833765\n"
},
{
"input": "1000000000 100000000\n",
"output": "100000001\n"
},
{
"input": "726315905 363157953\n",
"output": "363157952\n"
},
{
"input": "907335939 453667970\n",
"output": "453667969\n"
},
{
"input": "511481701 255740851\n",
"output": "255740850\n"
},
{
"input": "756739161 125332525\n",
"output": "125332526\n"
},
{
"input": "3 3\n",
"output": "2\n"
},
{
"input": "496110970 201868357\n",
"output": "201868358\n"
},
{
"input": "5 2\n",
"output": "3\n"
},
{
"input": "1000000000 500000000\n",
"output": "500000001\n"
},
{
"input": "5 5\n",
"output": "4\n"
},
{
"input": "20 13\n",
"output": "12\n"
},
{
"input": "140613583 93171580\n",
"output": "93171579\n"
},
{
"input": "1 1\n",
"output": "1\n"
},
{
"input": "1000000000 1\n",
"output": "2\n"
},
{
"input": "4 4\n",
"output": "3\n"
},
{
"input": "10 5\n",
"output": "6\n"
},
{
"input": "100 49\n",
"output": "50\n"
},
{
"input": "1000000000 123124\n",
"output": "123125\n"
},
{
"input": "100 50\n",
"output": "51\n"
},
{
"input": "7 3\n",
"output": "4\n"
},
{
"input": "710945175 173165570\n",
"output": "173165571\n"
}
] |
code_contests
|
python
| 0.1 |
fe15a7752a1eccadbf3736e7ac220543
|
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.
Output
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream.
2. Carrier brings 5 more, so now they have 12 packs.
3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
6. Kid asks for 20 packs and receives them. There are 22 packs remaining.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
x, y = input().split(" ")
a = x,y
a = list(a)
for i in range(len(a)):
a[i]=int(a[i])
count=0
num =a[1]
for i in range(a[0]):
z,f = input().split(" ")
char=z
inp=int(f)
if char == '+':
num = num + inp
elif char == '-':
num = num - inp
if num < 0:
count+=1
num = num+inp
print(num,count)
|
python
|
code_algorithm
|
[
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"output": "22 1\n"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n",
"output": "3 2\n"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n",
"output": "7000000000 0\n"
},
{
"input": "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100\n",
"output": "700 0\n"
},
{
"input": "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46\n",
"output": "46 0\n"
},
{
"input": "1 10\n+ 10\n",
"output": "20 0\n"
},
{
"input": "1 0\n- 526403222\n",
"output": "0 1\n"
},
{
"input": "1 0\n+ 1\n",
"output": "1 0\n"
},
{
"input": "1 0\n- 5\n",
"output": "0 1\n"
},
{
"input": "1 897986543\n- 371188251\n",
"output": "526798292 0\n"
},
{
"input": "1 3\n- 5\n",
"output": "3 1\n"
},
{
"input": "1 0\n+ 5\n",
"output": "5 0\n"
},
{
"input": "1 0\n- 1\n",
"output": "0 1\n"
}
] |
code_contests
|
python
| 1 |
0055c0522279c13cae624545d4cc1b2a
|
Stepan has n pens. Every day he uses them, and on the i-th day he uses the pen number i. On the (n + 1)-th day again he uses the pen number 1, on the (n + 2)-th — he uses the pen number 2 and so on.
On every working day (from Monday to Saturday, inclusive) Stepan spends exactly 1 milliliter of ink of the pen he uses that day. On Sunday Stepan has a day of rest, he does not stend the ink of the pen he uses that day.
Stepan knows the current volume of ink in each of his pens. Now it's the Monday morning and Stepan is going to use the pen number 1 today. Your task is to determine which pen will run out of ink before all the rest (that is, there will be no ink left in it), if Stepan will use the pens according to the conditions described above.
Input
The first line contains the integer n (1 ≤ n ≤ 50 000) — the number of pens Stepan has.
The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is equal to the number of milliliters of ink which the pen number i currently has.
Output
Print the index of the pen which will run out of ink before all (it means that there will be no ink left in it), if Stepan will use pens according to the conditions described above.
Pens are numbered in the order they are given in input data. The numeration begins from one.
Note that the answer is always unambiguous, since several pens can not end at the same time.
Examples
Input
3
3 3 3
Output
2
Input
5
5 4 5 4 4
Output
5
Note
In the first test Stepan uses ink of pens as follows:
1. on the day number 1 (Monday) Stepan will use the pen number 1, after that there will be 2 milliliters of ink in it;
2. on the day number 2 (Tuesday) Stepan will use the pen number 2, after that there will be 2 milliliters of ink in it;
3. on the day number 3 (Wednesday) Stepan will use the pen number 3, after that there will be 2 milliliters of ink in it;
4. on the day number 4 (Thursday) Stepan will use the pen number 1, after that there will be 1 milliliters of ink in it;
5. on the day number 5 (Friday) Stepan will use the pen number 2, after that there will be 1 milliliters of ink in it;
6. on the day number 6 (Saturday) Stepan will use the pen number 3, after that there will be 1 milliliters of ink in it;
7. on the day number 7 (Sunday) Stepan will use the pen number 1, but it is a day of rest so he will not waste ink of this pen in it;
8. on the day number 8 (Monday) Stepan will use the pen number 2, after that this pen will run out of ink.
So, the first pen which will not have ink is the pen number 2.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import sys
def Min(x, y):
if x > y:
return y
else:
return x
def Gcd(x, y):
if x == 0:
return y
else:
return Gcd(y % x, x)
def Lcm(x, y):
return x * y // Gcd(x, y)
n = int(input())
a = [int(i) for i in input().split()]
d = [int(0) for i in range(0, n)]
ok = 0
cur = 0
len = Lcm(7, n)
for i in range(0, 7 * n):
if a[i % n] == 0 :
print(i % n + 1)
ok = 1
break
if cur != 6:
a[i % n] -= 1
d[i % n] += 1
cur = (cur + 1) % 7
if ok == 0:
k = 10**20
for i in range(0, n):
a[i] += d[i]
if d[i] == 0: continue
if a[i] % d[i] > 0:
k = Min(k, a[i] // d[i])
else:
k = Min(k, a[i] // d[i] - 1)
if k == 10**20:
k = 0
for i in range(0, n):
a[i] -= k * d[i]
iter = 0
cur = 0
while True:
if a[iter] == 0:
print(iter % n + 1)
break
else:
if cur != 6:
a[iter] -= 1
cur = (cur + 1) % 7
iter = (iter + 1) % n
|
python
|
code_algorithm
|
[
{
"input": "5\n5 4 5 4 4\n",
"output": "5\n"
},
{
"input": "3\n3 3 3\n",
"output": "2\n"
},
{
"input": "2\n1000000000 1000000000\n",
"output": "2\n"
},
{
"input": "3\n999999999 1000000000 1000000000\n",
"output": "1\n"
},
{
"input": "4\n1000000000 1000000000 1000000000 1000000000\n",
"output": "1\n"
},
{
"input": "8\n1000000000 999999999 1000000000 999999999 1000000000 999999999 999999999 999999999\n",
"output": "2\n"
},
{
"input": "7\n10 10 10 10 10 10 10\n",
"output": "1\n"
},
{
"input": "2\n999999999 999999999\n",
"output": "1\n"
},
{
"input": "21\n996 995 996 996 996 996 995 996 996 995 996 996 995 996 995 995 995 995 996 996 996\n",
"output": "2\n"
},
{
"input": "5\n999999999 1000000000 999999999 1000000000 999999999\n",
"output": "1\n"
},
{
"input": "8\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "1\n"
},
{
"input": "1\n1\n",
"output": "1\n"
},
{
"input": "28\n2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033\n",
"output": "1\n"
},
{
"input": "1\n2\n",
"output": "1\n"
},
{
"input": "1\n1123\n",
"output": "1\n"
},
{
"input": "7\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "1\n"
},
{
"input": "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "1\n"
},
{
"input": "6\n1000000000 999999999 999999999 999999999 1000000000 1000000000\n",
"output": "3\n"
},
{
"input": "3\n1000000000 1000000000 1000000000\n",
"output": "2\n"
},
{
"input": "6\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "4\n"
},
{
"input": "4\n999999999 999999999 999999999 999999999\n",
"output": "1\n"
},
{
"input": "7\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1\n",
"output": "1\n"
},
{
"input": "28\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "1\n"
},
{
"input": "28\n2033 2033 2034 2033 2034 2034 2033 2034 2033 2034 2033 2034 2034 2033 2033 2034 2034 2033 2034 2034 2034 2033 2034 2033 2034 2034 2034 2034\n",
"output": "1\n"
},
{
"input": "1\n1000000000\n",
"output": "1\n"
},
{
"input": "7\n1000000000 1000000000 1000000000 1000000000 999999999 999999999 999999999\n",
"output": "5\n"
}
] |
code_contests
|
python
| 0 |
4c7060b585c5655435b870308d0319f3
|
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yyoouu".
Polycarp decided to automate the process of correcting such errors. He decided to write a plug-in to the text editor that will remove pairs of identical consecutive letters (if there are any in the text). Of course, this is not exactly what Polycarp needs, but he's got to start from something!
Help Polycarp and write the main plug-in module. Your program should remove from a string all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, the program should remove them as well. Technically, its work should be equivalent to the following: while the string contains a pair of consecutive identical letters, the pair should be deleted. Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result.
Input
The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters.
Output
Print the given string after it is processed. It is guaranteed that the result will contain at least one character.
Examples
Input
hhoowaaaareyyoouu
Output
wre
Input
reallazy
Output
rezy
Input
abacabaabacabaa
Output
a
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
from collections import deque
def plugin(s):
# stack for characters to check
string_stack = deque()
# input string in a list
arr_s = [c for c in s]
# for each character, append to stack. if
for c in arr_s:
string_stack.append(c)
if len(string_stack) > 1:
if string_stack[-1] == string_stack[-2]:
string_stack.pop()
string_stack.pop()
return ''.join(string_stack)
print(plugin(input()))
|
python
|
code_algorithm
|
[
{
"input": "hhoowaaaareyyoouu\n",
"output": "wre\n"
},
{
"input": "reallazy\n",
"output": "rezy\n"
},
{
"input": "abacabaabacabaa\n",
"output": "a\n"
},
{
"input": "xraccabccbry\n",
"output": "xy\n"
},
{
"input": "abb\n",
"output": "a\n"
},
{
"input": "a\n",
"output": "a\n"
},
{
"input": "aab\n",
"output": "b\n"
},
{
"input": "babbbbabbabbbababbabbbbbbabaabaababaaabbbbbabbbbaaaaabbaaabbaabaabbbbabbbababbabaaabbababaaababbbaaa\n",
"output": "babababababababababababa\n"
},
{
"input": "ab\n",
"output": "ab\n"
},
{
"input": "babbbbbababa\n",
"output": "babababa\n"
},
{
"input": "gfj\n",
"output": "gfj\n"
},
{
"input": "b\n",
"output": "b\n"
},
{
"input": "aba\n",
"output": "aba\n"
},
{
"input": "il\n",
"output": "il\n"
}
] |
code_contests
|
python
| 0.8 |
caa1ed040d2fcc4be110524e1ce553cd
|
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types.
* speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type);
* overtake is allowed: this sign means that after some car meets it, it can overtake any other car;
* no speed limit: this sign cancels speed limit if any (car can move with arbitrary speed after this sign);
* no overtake allowed: some car can't overtake any other car after this sign.
Polycarp goes past the signs consequentially, each new sign cancels the action of all the previous signs of it's kind (speed limit/overtake). It is possible that two or more "no overtake allowed" signs go one after another with zero "overtake is allowed" signs between them. It works with "no speed limit" and "overtake is allowed" signs as well.
In the beginning of the ride overtake is allowed and there is no speed limit.
You are given the sequence of events in chronological order — events which happened to Polycarp during the ride. There are events of following types:
1. Polycarp changes the speed of his car to specified (this event comes with a positive integer number);
2. Polycarp's car overtakes the other car;
3. Polycarp's car goes past the "speed limit" sign (this sign comes with a positive integer);
4. Polycarp's car goes past the "overtake is allowed" sign;
5. Polycarp's car goes past the "no speed limit";
6. Polycarp's car goes past the "no overtake allowed";
It is guaranteed that the first event in chronological order is the event of type 1 (Polycarp changed the speed of his car to specified).
After the exam Polycarp can justify his rule violations by telling the driving instructor that he just didn't notice some of the signs. What is the minimal number of signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view?
Input
The first line contains one integer number n (1 ≤ n ≤ 2·105) — number of events.
Each of the next n lines starts with integer t (1 ≤ t ≤ 6) — the type of the event.
An integer s (1 ≤ s ≤ 300) follows in the query of the first and the third type (if it is the query of first type, then it's new speed of Polycarp's car, if it is the query of third type, then it's new speed limit).
It is guaranteed that the first event in chronological order is the event of type 1 (Polycarp changed the speed of his car to specified).
Output
Print the minimal number of road signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view.
Examples
Input
11
1 100
3 70
4
2
3 120
5
3 120
6
1 150
4
3 300
Output
2
Input
5
1 100
3 200
2
4
5
Output
0
Input
7
1 20
2
6
4
6
6
2
Output
2
Note
In the first example Polycarp should say he didn't notice the "speed limit" sign with the limit of 70 and the second "speed limit" sign with the limit of 120.
In the second example Polycarp didn't make any rule violation.
In the third example Polycarp should say he didn't notice both "no overtake allowed" that came after "overtake is allowed" sign.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n = int(input())
events = []
for i in range(n):
events.append(list(map(lambda s: int(s), input().split())))
max_speeds = []
overtaking_forbidden = 0
current_speed = 0
ignores = 0
for event in events:
if event[0] == 1:
current_speed = event[1]
while max_speeds and current_speed > max_speeds[-1]:
max_speeds.pop()
ignores += 1
elif event[0] == 2:
ignores += overtaking_forbidden
overtaking_forbidden = 0
elif event[0] == 3:
if current_speed > event[1]:
ignores += 1
else:
max_speeds.append(event[1])
elif event[0] == 4:
overtaking_forbidden = 0
elif event[0] == 5:
max_speeds = []
elif event[0] == 6:
overtaking_forbidden += 1
print(ignores)
|
python
|
code_algorithm
|
[
{
"input": "7\n1 20\n2\n6\n4\n6\n6\n2\n",
"output": "2\n"
},
{
"input": "11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300\n",
"output": "2\n"
},
{
"input": "5\n1 100\n3 200\n2\n4\n5\n",
"output": "0\n"
},
{
"input": "10\n1 37\n6\n5\n2\n5\n6\n5\n2\n4\n2\n",
"output": "2\n"
},
{
"input": "10\n1 5\n4\n5\n4\n1 21\n6\n1 10\n1 1\n2\n3 1\n",
"output": "1\n"
},
{
"input": "1\n1 100\n",
"output": "0\n"
},
{
"input": "2\n1 100\n2\n",
"output": "0\n"
}
] |
code_contests
|
python
| 0 |
bf5ab34a8cf1cdb6f0b5d2a8f0505612
|
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.
A number x is said to be a perfect square if there exists an integer y such that x = y2.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array.
The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array.
It is guaranteed that at least one element of the array is not a perfect square.
Output
Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists.
Examples
Input
2
4 2
Output
2
Input
8
1 2 4 8 16 32 64 576
Output
32
Note
In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n = int(input())
a = [int(i) for i in input().split()]
p = []
i = 0
while(True):
p.append(i*i)
i += 1
if(p[-1] > 1000000):
break
m = -99999999
for i in a:
if i not in p:
m = max(i,m)
print(m)
|
python
|
code_algorithm
|
[
{
"input": "2\n4 2\n",
"output": "2\n"
},
{
"input": "8\n1 2 4 8 16 32 64 576\n",
"output": "32\n"
},
{
"input": "2\n370881 659345\n",
"output": "659345\n"
},
{
"input": "5\n804610 765625 2916 381050 93025\n",
"output": "804610\n"
},
{
"input": "1\n-1000000\n",
"output": "-1000000\n"
},
{
"input": "2\n-1 0\n",
"output": "-1\n"
},
{
"input": "2\n99999 3\n",
"output": "99999\n"
},
{
"input": "53\n280988 756430 -515570 -248578 170649 -21608 642677 216770 827291 589500 940901 216097 -118956 -919104 -319264 -761585 289479 499613 588276 883036 480518 -323196 -274570 -406556 -381484 -956025 702135 -445274 -783543 136593 153664 897473 352651 737974 -21123 -284944 501734 898033 604429 624138 40804 248782 -786059 -304592 -209210 -312904 419820 -328648 -47331 -919227 -280955 104827 877304\n",
"output": "940901\n"
},
{
"input": "2\n15 131073\n",
"output": "131073\n"
},
{
"input": "1\n-917455\n",
"output": "-917455\n"
},
{
"input": "71\n908209 289 44521 240100 680625 274576 212521 91809 506944 499849 3844 15376 592900 58081 240100 984064 732736 257049 600625 180625 130321 580644 261121 75625 46225 853776 485809 700569 817216 268324 293764 528529 25921 399424 175561 99856 295936 20736 611524 13924 470596 574564 5329 15376 676 431649 145161 697225 41616 550564 514089 9409 227529 1681 839056 3721 552049 465124 38809 197136 659344 214369 998001 44944 3844 186624 362404 -766506 739600 10816 299209\n",
"output": "-766506\n"
},
{
"input": "30\n192721 -950059 -734656 625 247009 -423468 318096 622521 678976 777924 1444 748303 27556 62001 795664 89401 221841 -483208 467856 477109 196 -461813 831744 772641 574564 -519370 861184 67600 -717966 -259259\n",
"output": "748303\n"
},
{
"input": "3\n-1 -4 -9\n",
"output": "-1\n"
},
{
"input": "1\n-1\n",
"output": "-1\n"
},
{
"input": "1\n-439\n",
"output": "-439\n"
},
{
"input": "2\n0 -5\n",
"output": "-5\n"
},
{
"input": "3\n1 1 -1\n",
"output": "-1\n"
},
{
"input": "2\n-5 0\n",
"output": "-5\n"
},
{
"input": "15\n256 -227055 427717 827239 462070 66049 987533 -175306 -552810 -867915 -408251 -693957 -972981 -245827 896904\n",
"output": "987533\n"
},
{
"input": "16\n-882343 -791322 0 -986738 -415891 -823354 -840236 -552554 -760908 -331993 -549078 -863759 -913261 -937429 -257875 -602322\n",
"output": "-257875\n"
},
{
"input": "2\n4 5\n",
"output": "5\n"
},
{
"input": "2\n-1000000 1000000\n",
"output": "-1000000\n"
},
{
"input": "3\n-1 -2 -3\n",
"output": "-1\n"
},
{
"input": "2\n-524272 -1000000\n",
"output": "-524272\n"
},
{
"input": "1\n2\n",
"output": "2\n"
},
{
"input": "2\n3 4\n",
"output": "3\n"
},
{
"input": "35\n-871271 -169147 -590893 -400197 -476793 0 -15745 -890852 -124052 -631140 -238569 -597194 -147909 -928925 -587628 -569656 -581425 -963116 -665954 -506797 -196044 -309770 -701921 -926257 -152426 -991371 -624235 -557143 -689886 -59804 -549134 -107407 -182016 -24153 -607462\n",
"output": "-15745\n"
},
{
"input": "2\n131073 1\n",
"output": "131073\n"
},
{
"input": "3\n-1 -2 0\n",
"output": "-1\n"
},
{
"input": "3\n-1 1 0\n",
"output": "-1\n"
},
{
"input": "5\n984065 842724 127449 525625 573049\n",
"output": "984065\n"
},
{
"input": "2\n226505 477482\n",
"output": "477482\n"
},
{
"input": "2\n999999 1000000\n",
"output": "999999\n"
},
{
"input": "5\n918375 169764 598796 76602 538757\n",
"output": "918375\n"
},
{
"input": "35\n628849 962361 436921 944784 444889 29241 -514806 171396 685584 -823202 -929730 6982 198025 783225 552049 -957165 782287 -659167 -414846 695556 -336330 41616 963781 71289 119639 952576 -346713 178929 232324 121802 393266 841 649636 179555 998001\n",
"output": "963781\n"
}
] |
code_contests
|
python
| 0.5 |
aebf843dbae055f32c4a67c9e51e24e1
|
Polycarp has created his own training plan to prepare for the programming contests. He will train for n days, all days are numbered from 1 to n, beginning from the first.
On the i-th day Polycarp will necessarily solve a_i problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.
Determine the index of day when Polycarp will celebrate the equator.
Input
The first line contains a single integer n (1 ≤ n ≤ 200 000) — the number of days to prepare for the programming contests.
The second line contains a sequence a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10 000), where a_i equals to the number of problems, which Polycarp will solve on the i-th day.
Output
Print the index of the day when Polycarp will celebrate the equator.
Examples
Input
4
1 3 2 1
Output
2
Input
6
2 2 2 2 2 2
Output
3
Note
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve 4 out of 7 scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve 6 out of 12 scheduled problems on six days of the training.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n=int(input())
l=list(map(int,input().split()))
s=sum(l)/2
#print(s)
i=0;
curr=0
while(curr<s):
curr+=l[i]
i+=1
print(i)
|
python
|
code_algorithm
|
[
{
"input": "6\n2 2 2 2 2 2\n",
"output": "3\n"
},
{
"input": "4\n1 3 2 1\n",
"output": "2\n"
},
{
"input": "6\n1 1 1 1 1 2\n",
"output": "4\n"
},
{
"input": "2\n1 3\n",
"output": "2\n"
},
{
"input": "6\n3 3 3 2 4 4\n",
"output": "4\n"
},
{
"input": "2\n2 3\n",
"output": "2\n"
},
{
"input": "6\n7 3 10 7 3 11\n",
"output": "4\n"
},
{
"input": "5\n1 1 1 1 1\n",
"output": "3\n"
},
{
"input": "3\n2 1 2\n",
"output": "2\n"
},
{
"input": "4\n1 8 7 3\n",
"output": "3\n"
},
{
"input": "4\n3 2 3 3\n",
"output": "3\n"
},
{
"input": "2\n5 6\n",
"output": "2\n"
},
{
"input": "5\n1 1 1 1 3\n",
"output": "4\n"
},
{
"input": "2\n9 10\n",
"output": "2\n"
},
{
"input": "5\n2 2 2 4 3\n",
"output": "4\n"
},
{
"input": "5\n1 2 1 2 1\n",
"output": "3\n"
},
{
"input": "3\n3 2 2\n",
"output": "2\n"
},
{
"input": "4\n2 2 3 2\n",
"output": "3\n"
},
{
"input": "4\n3 2 1 5\n",
"output": "3\n"
},
{
"input": "69\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "35\n"
},
{
"input": "5\n2 2 3 4 4\n",
"output": "4\n"
},
{
"input": "3\n3 3 1\n",
"output": "2\n"
},
{
"input": "6\n1 1 1 1 1 4\n",
"output": "5\n"
},
{
"input": "4\n2 3 3 3\n",
"output": "3\n"
},
{
"input": "4\n1 1 1 2\n",
"output": "3\n"
},
{
"input": "6\n2 2 2 2 2 3\n",
"output": "4\n"
},
{
"input": "4\n2 1 1 1\n",
"output": "2\n"
},
{
"input": "3\n2 3 6\n",
"output": "3\n"
},
{
"input": "4\n4 2 2 1\n",
"output": "2\n"
},
{
"input": "5\n1 2 4 3 5\n",
"output": "4\n"
},
{
"input": "4\n3 4 3 5\n",
"output": "3\n"
},
{
"input": "3\n1 2 4\n",
"output": "3\n"
},
{
"input": "5\n3 1 2 5 2\n",
"output": "4\n"
},
{
"input": "4\n1 3 1 6\n",
"output": "4\n"
},
{
"input": "2\n1 2\n",
"output": "2\n"
},
{
"input": "3\n2 2 1\n",
"output": "2\n"
},
{
"input": "4\n2 2 1 4\n",
"output": "3\n"
},
{
"input": "3\n2 1 4\n",
"output": "3\n"
},
{
"input": "6\n4 2 1 2 3 1\n",
"output": "3\n"
},
{
"input": "4\n1 4 5 1\n",
"output": "3\n"
},
{
"input": "3\n6 5 2\n",
"output": "2\n"
},
{
"input": "3\n32 10 23\n",
"output": "2\n"
},
{
"input": "3\n3 1 3\n",
"output": "2\n"
},
{
"input": "4\n2 3 2 4\n",
"output": "3\n"
},
{
"input": "2\n6 7\n",
"output": "2\n"
},
{
"input": "2\n3 4\n",
"output": "2\n"
},
{
"input": "4\n1 1 3 6\n",
"output": "4\n"
},
{
"input": "7\n1 1 1 1 1 1 1\n",
"output": "4\n"
},
{
"input": "5\n1 2 4 8 16\n",
"output": "5\n"
},
{
"input": "6\n1 3 5 1 7 4\n",
"output": "5\n"
},
{
"input": "5\n2 2 1 2 2\n",
"output": "3\n"
},
{
"input": "3\n100 100 1\n",
"output": "2\n"
},
{
"input": "6\n1 2 1 1 1 1\n",
"output": "3\n"
},
{
"input": "4\n2 6 1 10\n",
"output": "4\n"
},
{
"input": "5\n1 1 1 1 5\n",
"output": "5\n"
},
{
"input": "4\n1 1 2 5\n",
"output": "4\n"
},
{
"input": "4\n5 2 2 2\n",
"output": "2\n"
},
{
"input": "4\n2 1 1 3\n",
"output": "3\n"
},
{
"input": "4\n2 2 2 3\n",
"output": "3\n"
},
{
"input": "3\n4 3 2\n",
"output": "2\n"
},
{
"input": "5\n1 1 2 2 3\n",
"output": "4\n"
},
{
"input": "5\n2 2 2 2 1\n",
"output": "3\n"
},
{
"input": "4\n1 2 3 1\n",
"output": "3\n"
},
{
"input": "2\n4 5\n",
"output": "2\n"
},
{
"input": "1\n10000\n",
"output": "1\n"
},
{
"input": "4\n7 1 3 4\n",
"output": "2\n"
},
{
"input": "4\n1 3 4 1\n",
"output": "3\n"
},
{
"input": "5\n9 5 3 4 8\n",
"output": "3\n"
},
{
"input": "4\n1 2 1 3\n",
"output": "3\n"
},
{
"input": "4\n1 4 2 4\n",
"output": "3\n"
},
{
"input": "3\n1 1 1\n",
"output": "2\n"
},
{
"input": "4\n3 1 1 2\n",
"output": "2\n"
},
{
"input": "4\n1 2 2 2\n",
"output": "3\n"
},
{
"input": "5\n1 2 5 4 5\n",
"output": "4\n"
},
{
"input": "3\n2 2 5\n",
"output": "3\n"
},
{
"input": "3\n1 3 5\n",
"output": "3\n"
},
{
"input": "3\n1 1 3\n",
"output": "3\n"
},
{
"input": "4\n2 1 2 2\n",
"output": "3\n"
},
{
"input": "4\n1 2 3 7\n",
"output": "4\n"
},
{
"input": "5\n3 4 1 4 5\n",
"output": "4\n"
},
{
"input": "5\n3 4 5 1 2\n",
"output": "3\n"
},
{
"input": "3\n2 4 7\n",
"output": "3\n"
},
{
"input": "6\n1 1 4 1 1 5\n",
"output": "4\n"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 8\n",
"output": "9\n"
},
{
"input": "4\n3 3 4 3\n",
"output": "3\n"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1\n",
"output": "6\n"
},
{
"input": "4\n1 4 3 3\n",
"output": "3\n"
},
{
"input": "1\n1\n",
"output": "1\n"
},
{
"input": "3\n3 1 5\n",
"output": "3\n"
},
{
"input": "4\n1 1 1 4\n",
"output": "4\n"
},
{
"input": "5\n1 2 4 4 4\n",
"output": "4\n"
},
{
"input": "5\n1 3 3 1 1\n",
"output": "3\n"
},
{
"input": "4\n1 1 2 1\n",
"output": "3\n"
},
{
"input": "5\n1 1 1 2 2\n",
"output": "4\n"
},
{
"input": "3\n1 4 6\n",
"output": "3\n"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1\n",
"output": "5\n"
},
{
"input": "4\n1 3 2 3\n",
"output": "3\n"
},
{
"input": "3\n1 1 5\n",
"output": "3\n"
},
{
"input": "3\n2 1 1\n",
"output": "1\n"
}
] |
code_contests
|
python
| 0.1 |
4a1f0ab0f2926d0c4943c210293a177b
|
This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive.
Once upon a time in a far away kingdom lived the King. The King had a beautiful daughter, Victoria. They lived happily, but not happily ever after: one day a vicious dragon attacked the kingdom and stole Victoria. The King was full of grief, yet he gathered his noble knights and promised half of his kingdom and Victoria's hand in marriage to the one who will save the girl from the infernal beast.
Having travelled for some time, the knights found the dragon's lair and all of them rushed there to save Victoria. Each knight spat on the dragon once and, as the dragon had quite a fragile and frail heart, his heart broke and poor beast died. As for the noble knights, they got Victoria right to the King and started brawling as each one wanted the girl's hand in marriage.
The problem was that all the noble knights were equally noble and equally handsome, and Victoria didn't want to marry any of them anyway. Then the King (and he was a very wise man and didn't want to hurt anybody's feelings) decided to find out who will get his daughter randomly, i.e. tossing a coin. However, there turned out to be n noble knights and the coin only has two sides. The good thing is that when a coin is tossed, the coin falls on each side with equal probability. The King got interested how to pick one noble knight using this coin so that all knights had equal probability of being chosen (the probability in that case should always be equal to 1 / n). First the King wants to know the expected number of times he will need to toss a coin to determine the winner. Besides, while tossing the coin, the King should follow the optimal tossing strategy (i.e. the strategy that minimizes the expected number of tosses). Help the King in this challenging task.
Input
The first line contains a single integer n from the problem's statement (1 ≤ n ≤ 10000).
Output
Print the sought expected number of tosses as an irreducible fraction in the following form: "a/b" (without the quotes) without leading zeroes.
Examples
Input
2
Output
1/1
Input
3
Output
8/3
Input
4
Output
2/1
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
from fractions import *
n,L=int(input()),0
while (n%2==0):n,L=n//2,L+1
if (n==1):print('%d/1'%L)
else:
s,t=1,1
for i in range(n):
t=t*2%n
s*=2
if (t==1):
m=i+1
break
r,t,i,ans=s,s*n,L,0
while (r>1):
i,t=i+1,t//2
if (r-t>0):
r,ans=r-t,ans+i*t
print((Fraction(ans,s)+Fraction(m,s))/(1-Fraction(1,s)))
|
python
|
code_algorithm
|
[
{
"input": "2\n",
"output": "1/1\n"
},
{
"input": "3\n",
"output": "8/3\n"
},
{
"input": "4\n",
"output": "2/1\n"
},
{
"input": "9556\n",
"output": "61105610582596188064013632976018238169594847263124154642386689594807697097885447064570207703083797375229286491941164437689434529990291086697099939303795410031817348526076989232509267027565641811597218817018817025267674646870116016782259903322684685324891049798873702815116504349778081974046190242424181610803910534907237209386333892868457625884598750479036332/4139057561631190052420042715397268145091328063809781231185874234711716512317727312355164552220203407039993009382683073987640607521830928131007598529502095515543149872994228577135740359740397866323669967408427049574842712804865521444685714847605280429022880715321979321806389083601610908845490570307126892922112190564007539156785460626278585200940747870441409\n"
},
{
"input": "9859\n",
"output": "97375564875859552710857257263475485245872015150154159409742126964779182762643082446089319960510145599477278715485258439846460300625068332427651118034416501442686377626793456360113581501157759087688960055802143216287038684355484042396762264359960403926704844149909425763766341457216806367693536067206432651075198691127588916420476804076478746658658023803466680068762064908145889385697518113114359392346598640883967611367897988991624393548051091664507952791730942125971565547106392956691209669780229555235202438855255794019000921171549420192999015238112509496532316750570319815809655206552721206293067341273639421021965567073260870827807392294831930629646379401978966733087112069358716912846766412303196634451076031066079956837629059177170048030972622525029555337583764651631049334455610692138052593093947511364692321205405385002454933574475419016360524655415844182022437368453118181570693029677857477506665909191395707456794665378068881663661605928129286724609088224972033263553402215822565698200814687889578567152857719719092867521377534941657609474679845672885532933976895375591415049759550178150185246432147540404349497656619717599874838652250947951177310462729418401362305425416426586758305028116511635937540760865154551702859543508608294300521944993342492698120674763653834888118184019182478585368460360033050972822901924636673968468405685748843065150057388284549646737772327988070397810180542766311272621109742146466204069612665219252089658629990789090591243706759175949093962008/6646700628514403311471896743397300436332555330937165010732719027837713954215391230313006059698837210258138125041572866405233275288926528075035715903050487152579968721636703542575087447433874784011341173605843592712366867464551290043424713528068465939734903510810873784556280347565108849556006793033896058659418631622035528034645047400542901074603278385383354754857709815915021324211447265160350251229593002838457215812149153747562284211667786478039901868553705175094205368626149685829390255087710259716499035805282120904477243226297245473185288668226400238540581998766906264507279615185674949927280423733706427411295149669923085185162949911996032663245212759411608521436270634603469390153876467527983973009617504991693479244010110831403932408175434250448523111391917158293179538249489193891571460588346598883145633988383757562811628759602804814556767097994329230167559745956458779802311515910156930121326321000807571024851412644754028052002500677482303476276329778032540782560537010053994894075430493367168014042331312193665532505313106527943685330069133416923785034092280330871685301400959810603780663108378946734197550863598233222351106072308281847541184932866996257623319033304206461887329800804826333050477795571534690816878016295466310312101574369032547477017194842135479513667489219494086143589875348942771771852787692773803792971237190674015543915678839180738347649724324416991273290383522161552450821357227584404443488918493903636670490093097384582622626303913196367789657657\n"
},
{
"input": "721\n",
"output": "24323770714557246/2251799813685247\n"
},
{
"input": "9949\n",
"output": "30771945768974312829849286149718032439798677467423493967010334358283994984326026515504661301394540080141512302827338824723593201789481739830982595229625700583149586238955431037653778739309457671890129351276923685142834902559798917246250215421521527437619966091451717584873598334082323796428001565577186322128798336073715122147162994673808366455578086459869026609967714613554824824759058832899783907543792360923791441961728662642435663487942507846671256543700983615951249949208724967800869867388054589031851260302269048408876735464545077279886559546809841455560742265338090287549868226487740814828047510635070623293003545071913364258117360949495583083158833097103857044434279928869747427297854639426953768566959891591203122862851297692620246536344125431027520526966343015915582695313902053937737605214941486508347934274945698807835217128834978971566963674180680330348426256461353890985386815655822602029905923905821026891198095526938372914444181903627938094196468774691975665647890550812376683751593905633065125611092957601442907415902644417519682901059153440286626841355350656757754077474910571424577932014202554351172899008539276212598195566148386803283414780184354222934329064815395828988176783012436153939221036332468551883344836802385258800011254159939415282139047054155201180580357201111671543663885937215403704436525087738509669353351862725364108467051762959998292239822805587007389198288780422715556343928293849868727893528481926649471509098886000214133618311655761794432794819144278520611314/2104739892690518553309455017769556244714403413511128897687327989722964420680265892383589038724767456014984893924465270083609280557483126794337796952227352908716377285895726069985002273993666575392685803959240373262064326038551986753208943247122477492965063535803060781979048064432512218363568944479517226783944750093987235698524362358647309556477616386510411676499309749332531381237162073573221177134517220239232861938282924059678332139188490738557186919435363048815821553632972277017322717437995569914300549640953672499562326398555404438240737181738320282706293441180398162726147059796782693569470160760140774337483534168241795984189626521404877580971816798389149476625721556291121992741942677675296965918687927473569482384058810935115262649386369992511259614038884705095632090478521832146758218051298214283210470295696576869734952976211016365306133993819097015363491687473819879776312850467592349301880297452193370638486783468483172335849930338140479761974767896985979428568709385301326081047303152723543522214229898929905953376294524100600956089149497679894409271817382310743421156370753358446447228174902325396969393126293985010978064558407022476380230661716093665265409338696852391176942119985203709662844145192019854379349306927459908671425530548272821364000403220805106940414514470465019829199892250163872861563267221111218547482541798387173921775791567366427703104289177035407737401314179898002891110788289964230373210504115220736031760314395093885988774780636600868883194732465061084790785\n"
},
{
"input": "659\n",
"output": "11506864999305980525685467247724160971763964558240405270397991163704744844086671519176045618744739064/1093625362391505962186251113558810682676584715446606218212885303204976499599687961611756588511526913\n"
},
{
"input": "9992\n",
"output": "882713207347291313029281/60446290980731458735309\n"
},
{
"input": "1108\n",
"output": "829108303866668/70368744177665\n"
},
{
"input": "5\n",
"output": "18/5\n"
},
{
"input": "9941\n",
"output": "384853449965821966704972732966307410533754716673001872990644754365090705756559909905259906468556983837473030874407257670396254711587695297525843978796573345385105966534793732922560851527360127165003492854386049121963401202049881466162284067795049692605928261294087682986229601310196379407661027753366447296128334837195369728352306910364221724819790584234590499773230968446949449654139435810921574651200199324826389837566367344938559238192678820640156721227690796296835372410818703029961426437218612250923546166131087887183128506236914642265107372940583059256790238734873109550064606852454241895688532803264957771260552966093023026993324786723535480684212796655647178515320455962010444291723038825881485337386595953872058254168410359964399040839348392327614519090725780698083807461735099275217105332435035753958774263103832408352846440135520908788781982960980537030064122924914534253061986335785798932585118262145429733521285255543276010510520192751011713072317121752117777795703412147228931454823584324564303527450001365318783625485155921101661017155244139248803962776096262658198375191699627453070323264267286645773802280627801063123133551237542788441825414046345338526837487440831294887788650949450267282162592637307013507372887692529215654653541232042283216484427420262459679041403322783917834492903078518685769388196722883649292951071615901964473014159404289255892968209177423128684793429579384323572081016759500108948811565542981757113040677115518347788350471128322691656105081491299216747682/26309248658631481916368187722119453058930042668889111221091599871537055258503323654794862984059593200187311174055815876045116006968539084929222461902841911358954716073696575874812528424920832192408572549490504665775804075481899834415111790589030968662063294197538259774738100805406402729544611805993965334799309376174840446231554529483091369455970204831380145956241371866656642265464525919665264714181465252990410774228536550745979151739856134231964836492942038110197769420412153462716533967974944623928756870511920906244529079981942555478009214771729003533828668014754977034076838247459783669618377009501759679218544177103022449802370331517560969762147709979864368457821519453639024909274283470941212073983599093419618529800735136688940783117329624906390745175486058813695401130981522901834477725641227678540130878696207210871686912202637704566326674922738712692043646093422748497203910630844904366273503718152417132981084793356039654198124129226755997024684598712324742857108867316266576013091289409044294027677873736623824417203681551257511951114368720998680115897717278884292764454634416980580590352186279067462117414078674812637225806980087780954752883271451170815817616733710654889711776499815046370785551814900248179741866336593248858392819131853410267050005040260063836755181430880812747864998653127048410769540840263890231843531772479839674022197394592080346288803614712942596717516427248725036138884853624552879665131301440259200397003929938673574859684757957510861039934155813263559885\n"
},
{
"input": "6212\n",
"output": "718828780749497450032379379564/52818775009509558395695966891\n"
},
{
"input": "64\n",
"output": "6/1\n"
},
{
"input": "46\n",
"output": "13719/2047\n"
},
{
"input": "563\n",
"output": "13880251801665520090148870069821814422429790384486504048582895486382118580803670864520/1295112594817152713946307937882345937761604559368093014167874939825936190136805665451\n"
},
{
"input": "9993\n",
"output": "12637244675354581352253260560857374/865382809755804604755082721536683\n"
},
{
"input": "915\n",
"output": "24489920882263416/2329134352741105\n"
},
{
"input": "43\n",
"output": "896/129\n"
},
{
"input": "96\n",
"output": "23/3\n"
},
{
"input": "8947\n",
"output": "92217769650613941080630745376651933397191302347912593530353833699082767482320053295873976335261338396309773662884101662842457408770833712224740258269916309119393363719163880754797784504204928376494183707150687254382915622323093679978287895961773920594292978995513577964215777504112090455173786839038765078953566596501076201082418241675636449015103402653720191796734537241208020262611562799789253796538147209979307343496482329841157415668866988738359135695532638926095881556206387247047275982889596856215502497372454403017804736518377694017093145759135565451187077401200832721851731046427121501133656571935612796455781816807902515476728658693498476446412506031202442245240570035236662350020575294290901650771066909827076845032177288445995720592293708358208797029207264762880645247427257707612939826564013721632684623704064398177623643552898057972509138117104547949763433335143917052862499770462405614211667395567829627153587228986443476520743298461920576721953351927084670699264245007148998170282414097200641632369261731232256384042741053414359751300178849126336761514536162023150815249146560705170439304772066253851777701029064668052252444327326087007689616954432155738920844369876980684180971739371626802860827933850173815284965901524281521807500221496567884872319546677778723089803624/6252036342560819570523112832025531962797490003966039732870902011446197609660581599850268257010152251205336955451824856293775321046192908822509001667528039037689681221037726800127247595498549747717526779751261968533262734275081426256774201583510902785280975078796902985150189558168793985039170092737929518556877204050527242044694197761677768740255793809823325324216134476513445529910234140126414877638524195984384623274359548332179860494414935751283376521152364168761511367061700395657677451748372910430794830742985757681312008806438144591613429595112348166020095169464928020831137306693186069988326477281465032562179039766410882532876992751585321457123600572371668503678644725794827683161183187164959409239149862517059913493904108154244777276213869162615900352358556227894640678920224620252048592352609924480747509120115706107045674107471294367279720247581576228206622006920802946451725437656694068893660680498529140390069153092207810555916628716364087683749197123889518859398928036584563930522367458311612861285208884232697419053862464308098864083457354215421425951599282242184046104866832500282657797392186803207610331402306315126035831454975913405099442625817545247918142274133748306880770190568103485303008422266954828535985762501328186014923158523827467759649904650333404692217855\n"
},
{
"input": "9991\n",
"output": "6382125632197575640171909108366323999672572433833222272392411654952806480364944179628596547334889065794512754663260535014179926913634410060297543083266944529654281991142775738499030710183320227853166673816892482763220210176769895648821886542105816/436994993873214129706097166956708350993678881411295357199729151951767944417616335439228580716318181998128654620651240845861768505204366709906692902245553277900892247131030458103436298545516643924637451297481464347472084863384057367177715867713535\n"
},
{
"input": "1649\n",
"output": "1103258059369546/93824992236885\n"
},
{
"input": "408\n",
"output": "481/51\n"
},
{
"input": "9556\n",
"output": "61105610582596188064013632976018238169594847263124154642386689594807697097885447064570207703083797375229286491941164437689434529990291086697099939303795410031817348526076989232509267027565641811597218817018817025267674646870116016782259903322684685324891049798873702815116504349778081974046190242424181610803910534907237209386333892868457625884598750479036332/4139057561631190052420042715397268145091328063809781231185874234711716512317727312355164552220203407039993009382683073987640607521830928131007598529502095515543149872994228577135740359740397866323669967408427049574842712804865521444685714847605280429022880715321979321806389083601610908845490570307126892922112190564007539156785460626278585200940747870441409\n"
},
{
"input": "16\n",
"output": "4/1\n"
},
{
"input": "91\n",
"output": "704/91\n"
},
{
"input": "7708\n",
"output": "39413297508974631726391031213171923271142554912679270458193728426423636026646334915727139650713682692479792411879633606353758285856351703126/2977131414714805823690030317109266572712515013375254774912983855843898524112477893944078543723575564536883288499266264815757728270805630975\n"
},
{
"input": "698\n",
"output": "261084475895343697268604849722313704014143081638278003/23945242826029513411849172299223580994042798784118785\n"
},
{
"input": "377\n",
"output": "42877948701338/4398046511105\n"
},
{
"input": "9859\n",
"output": "97375564875859552710857257263475485245872015150154159409742126964779182762643082446089319960510145599477278715485258439846460300625068332427651118034416501442686377626793456360113581501157759087688960055802143216287038684355484042396762264359960403926704844149909425763766341457216806367693536067206432651075198691127588916420476804076478746658658023803466680068762064908145889385697518113114359392346598640883967611367897988991624393548051091664507952791730942125971565547106392956691209669780229555235202438855255794019000921171549420192999015238112509496532316750570319815809655206552721206293067341273639421021965567073260870827807392294831930629646379401978966733087112069358716912846766412303196634451076031066079956837629059177170048030972622525029555337583764651631049334455610692138052593093947511364692321205405385002454933574475419016360524655415844182022437368453118181570693029677857477506665909191395707456794665378068881663661605928129286724609088224972033263553402215822565698200814687889578567152857719719092867521377534941657609474679845672885532933976895375591415049759550178150185246432147540404349497656619717599874838652250947951177310462729418401362305425416426586758305028116511635937540760865154551702859543508608294300521944993342492698120674763653834888118184019182478585368460360033050972822901924636673968468405685748843065150057388284549646737772327988070397810180542766311272621109742146466204069612665219252089658629990789090591243706759175949093962008/6646700628514403311471896743397300436332555330937165010732719027837713954215391230313006059698837210258138125041572866405233275288926528075035715903050487152579968721636703542575087447433874784011341173605843592712366867464551290043424713528068465939734903510810873784556280347565108849556006793033896058659418631622035528034645047400542901074603278385383354754857709815915021324211447265160350251229593002838457215812149153747562284211667786478039901868553705175094205368626149685829390255087710259716499035805282120904477243226297245473185288668226400238540581998766906264507279615185674949927280423733706427411295149669923085185162949911996032663245212759411608521436270634603469390153876467527983973009617504991693479244010110831403932408175434250448523111391917158293179538249489193891571460588346598883145633988383757562811628759602804814556767097994329230167559745956458779802311515910156930121326321000807571024851412644754028052002500677482303476276329778032540782560537010053994894075430493367168014042331312193665532505313106527943685330069133416923785034092280330871685301400959810603780663108378946734197550863598233222351106072308281847541184932866996257623319033304206461887329800804826333050477795571534690816878016295466310312101574369032547477017194842135479513667489219494086143589875348942771771852787692773803792971237190674015543915678839180738347649724324416991273290383522161552450821357227584404443488918493903636670490093097384582622626303913196367789657657\n"
},
{
"input": "27\n",
"output": "320/57\n"
},
{
"input": "69\n",
"output": "32740246/4194303\n"
},
{
"input": "21\n",
"output": "38/7\n"
},
{
"input": "9749\n",
"output": "24420738504895369936029275850163071991656213953040750251776948750246796077962845691317677269631705913994021086756383098235089231208690232714718182051661959094144212987702253303432217073773124260159318146666200117041612592906844115211509040675212920139551853176678612535045654292046757526749492513241228125837513438956933418658716846512730365072509590131877465449441381623988912185373433489319776194980015068338689021210658939139364253499030464561574097560424964521204779116215457677726768619050046856738764484240389262833903373023132839740002736774915426122802238815407817050693856360952407545226333981896371433729874311657730340419746680805378905702168666514377525913884873553751714155904205031709262115464030534807143888700039849995711800671406127912163382933986015685240389569396807457398304726818373517814077265886528890585763062131364555734521607919713137187807658107106103376981378323172002338180348049030319707116151597120087047456178402809544871620530165936798803297978162622508652805080201485681178041361165961347313090217348403318922506112704312304156650558494700459948184483142107408891022462564899591639479697445627266468118776891821012071431633275985890307805299829762601232691986762912806985999108672619322038677748498306049452995705026758802905382276104042099895012248388280300961696806504069643072689548038490993315819434426936765296065726033493251456080278483753254193225043853870782435870985742176970373530465074443098411876172230726422871158542366506/1660347017002617714488606778538307249454081204143987146498575337165132958737138209959678784502210971205739074168354790718346566325012668504527186905879565081234897585958097173763231197610303698122881948041967623952744387482742860772966864750594290041574689109551917322621553772201862798796436236284520108428674136774547680292840751886809416972596562130605474050074593326909866195459448284422830706715433130725326630947306715927693236908996579034923899343328494620393383183133288660062302008351958547067952801708155516017825647752022977500748412927168362666820601247466619898045678730876569666167916867016800470854877468025159952443494297525060762576154719106633197342274456001815808439997093298938542364958830187119532864980955583141881565003394297337758664601174076037155519665173980601997176330267145233086875952430035258635268720607170579532136126085282961192021945410024711648428486045014668481020534887254915483146379759743582367539028246841629774846096550211590827301839779858452393725051190310768159722653619142777675349102678935518703583706107757021816885992427662659893937916261403794788543307969092291970441498332522026165657401526620077687131667565240216342076492209149314820320785474262554798281896211169067828976372906598068990091901902231877134122149795957801824298289067399088302792517748366920708634383171665576235224624533213135417206031161073482478461006626139211198630019446267887361147680197888350507317883904724462949265962076136239934476369526785\n"
},
{
"input": "8622\n",
"output": "2346970612497798292051684863778787677688918498337895665035233783242368128286257851467636458012981817792946447606933694463959158768680516918810044760234529638520868683195790661167605124671831213269266007988150361676380026247303195939614144448935172977317349504257500667344413574778276538084533093523373859439640543406392557232735743996270882880554311714917225257533788072187384837827098726745502145040757646538864148126423442625937245/158450103580531636036828827760200463708558264074197895770614130238733548787583684152724709587811859737216181571248100013762215682730756320071818118043767724270459420257714506357027386375070761460082246558018893533772011466701231582991394416190882917676565785822100399450009192822976794870861997661290175933763162180529059984116060787778454199555587743992742904650146111513904831859678244868920370808097155872403849701260040561055061\n"
},
{
"input": "5379\n",
"output": "369970662679510300707473720654925140999880897391589444623141436368705516892112173326991585567498714963884175295883677699016/27543998699593691622996471168032126659516861790178384136860366469766907968179639409382883768321470201982967167709306596011\n"
},
{
"input": "898\n",
"output": "54181807382553033285317903788494851/5192296858534827628530496329220097\n"
},
{
"input": "9883\n",
"output": "3585169013008320587733453934540655406968508071250655174069676351966247095891666666457951370861261022535907218197677774600785190516321049571099175528120462561383326438548822604717683501452327840790897918994708328294710567693091965543331903184071652577937298158191755916197924842106107578819028940776121678861464188820255086932973183740793372165945865009415954786595728774195980645745127346052687115724325004061229398519190748075580806663121266449693574278118081790297078495193488775980028423355059820522243653725874632878510045835553519741832072550463732084440328479802757883822909816376632890811035439142421989449863044208586517399880008863407492496206323270830482631638372716663110223514171732041108713906301160805034170356396842166510003100992178793709386042537964760180749873610550892321524236421203672563269319950307992448377781123935998679097946148059114351779548141469866569341951745396332639499438188190815082774623731116948453999214458330207016238401484362043219831905888672028360776820475855330015482747522043053354249914178134040244185110051911485974319449824722583973072546384468573330564589187898015237282681548921919611841954714952547395797273043248344370035395990109256951956434133363924387603461250518602022484830305070939839063616330207734382452009330287037414957658873609136317223268183549799388228885998953454699718350330403675879708887230727150794790578035321318346228048669908308488864491704843219546622006983096396305733734212669415968084578686794694798437666747022528/245023971969554963674100001548598083284963319719667650955650954242209487208196182314258655384737934918956003841532542147162519460250987530958116631050053158392707966954415439393488023662202360037794081023805818201748692202213218756160808639498715928402387483022532051193882718732640172630032634418401544306420808436114717705469155027373613505214175254398771989683074614653891346095730791982871151661327716456636886803699066403750136045178921280726462942482363787574672786709034382018414642363553351014189020455925920105022649094294221657123502481465498018393560014802543232534796355734204721354119265540519353740089984397432044612265846985555821748097871523162949536534226680674022295598632502098951601181026539704013788418851188725688874564294979208208534355978351634123319770498029169643618890323128809021228280651347778838795487882593997796683820662300462952740896922474938896458632411722512025071992573497373770298260122475736212490109020184974707635349450620937391583408311636338630467775196669707487281669656501492707286190275862359046116016007668534281478411496777822117253806950844982458097770364827281492409458515035685269508751174249572502027758241365208950041026032843726267011014525776869117941572813455949054842273391192716070063345312437540015830192761870660482316791838322587429991597297164863426338597581165506413503024091687797006909010907584727558738447759437495307966298576698160963469547078512837671485404775491359263662220946791941985253800496067456070902197939863553\n"
},
{
"input": "9803\n",
"output": "3273210180788326072665779956874407303695209430301336271835983946088930098968971592446649088493870209185601637297946849124915345946101994703881396454817629317067995483358046696632270413949397783371061147815617923539634120806955265009854911188530306501324761896490486400736980978270851173985761450205468514371802366150508965142349402634775190541932571215772934087049601511151015580218962449832712507548850463067009640345032653747650848021793733486635063672276271184797891474270402353352104959589784879937226619631450622372801836784254780047580520552480710915034334830077235403144885444713231997122651029623193719081606830187339528932202520708400927484122175520586418859966084212848690640894333604345214778602427783597772052518000554782737270290980515925878265370322995156392497748140171133095749065170222804510706059714322514254283376693941404435829879255457277967393238087816555358380272466214436430777426033426837629266695879765238233176316258666048369521314622222658677664616511902093975562338612751867496209652181946196463606422353383104107812596334613198740452548306659208445516691530536050604634513689227620071954907294939937244234855896302003859771540054305586466389588586625478638436931865675356838997676239216955771564982882752970004654747040198185582364456872545570483489206688716013710536947301312846273423736064935003964044795795191383397598165999437078614987833270147703891978941201213909953516817760145834793630851002075671081977655885477265842182227630711346029216/222848004313668719691213483700810759987656019547710139664241936991138106539616439762775058065688367531907719095700069508131964048744509937894796740738505066831483388299980505865722101281973991752051079878406943136495731052685385981167936406108052259153180314590401441086107951134763582222178806130979450523610292690241037876575460384059273115066548829780705991363970146861803501538571064868730128783979777341880332463641995130956398538891263597839918422762242505609422357073557925121726514010836900537641686656503152430580165941404831443945570282690367110620682083028935478555282639476176629026776268383873097027471871476729615653553852994769678614918913374970497476655715836999681683299634189187555967856521001252998565559074621638218445299839894876830416575083610618206257432118972401116133269463833866230950916952995411373918148349361215693246613829888213288305357239073545221307206167441574530195787313912090912979929382777969487951949322618906724196994628638037640106093305472621641881937827447206916332715678892320927194478168405438778896510491602870644308869938666086561401068093659871427096523225215861650585301063106894861911088059286678346350307257457833611661977586521721847940184057530922580500894412994920507883101337204349029037389584516440678117026220089119744731571552913544501272187787585483807869056891982387618102642674500927575453725610336484859306845245953350338792277922673893920973157108631164802759853751459885883070656697593169142468287187573383626753\n"
},
{
"input": "9995\n",
"output": "1368770541403820619075110203708490210616145992745821521870208914365828115565556194877572535511077690510688277376757546565243584175363368143317667278940670502781186329534839008398699279841764334491329910860701074569229951248069967340109056226002539889667430100999595433067983400778886042165596127864919572486395941238704720403024794261441096255620000217687954366591408789194462597191661175824028310400352/93746319107175952683864071964918454730461746778024627464635174121600584812748548703282543376385452193806936431137231560052128838065111583392770646215498841416082979442330648067511176282732199184911147558161483085919841893469290827996255650168474543134607110617533756037909735459668069833444196401816994512004002417933496313555598963173697952072590902286596238498989761054870081835578169164103256375295\n"
},
{
"input": "9998\n",
"output": "4285402091468445389426164244750423198106729816197961669529078982307315890678968433526215498100171962888335447/293567822846729153486185074598667128421960318613539983838411371441526128139326055432962374798096087878991871\n"
},
{
"input": "9901\n",
"output": "1838099364825091485842998238489502638352163208605775246129613825541675258139803932850287467779059152113767067936585018625986257156889365449198856216156597215096982506298229063072584364817360767528951048690402306736891920567120457283597208730483707878597646111737127186752299112571526574444743928839110241560725998077538870670908652964981237795923920133705668072188172055098674658571105524472734987571439013958589827622877679807533101349696441175687163721291688130495577638100992957486490904022264860238167307326966426591671355541318530110693823370267769955298274501764387363143753324201392980117580626370923156755357235271953717705218606174361705745607690592162188659919159503909577911890370970307505310006952184882295896878809489448279733854445719768942424699644398057419073652907805636830184662379668640311223728733045708550684860813272116912712928434533540137586553447726767616634480071951755086848411168207402152500267945846598199304627785126081886349021085239907165847936787381451395789868857912620418181602257637943517461795756567745027242135635746499764849207120672778956961370729031070654229684060835173403463861644712283677533769437289456513866506359310854677128562818680682992941321465381508384264781767572418820540784203355739555956391413113575042931607212249685559517635004403000728597654807705351363988397543735139434999563378705775136326919194852966154650224921931475263079667563204688934744417553326412692788253071675108998704506853416086820413944387432670284519676275301802962/125452273648412141401139200792882218641901219696469837289293288572011257450596445344900431556985822678505473966864661579347209963648505615850555715097627217097066479080660704969465868115047608339350569484188578919295330407533168003154334023423342555342022391307536410211267951991111768386576708822221590684887453919290735465200207374015290114669657730252171258717734202702792369201014165495230029650599790825798086043493921998720069655131607695731949026550970259238232466795025603593428296890139315719264778473434071093771596336278641488447233270510334985417502727578902135057815734135912817333309063956745909114926072011485206841480113656604580735026110219859430162705524060505099415346499841074663219804685588328455059670451808627552703776919029354602769590260916036671139722494990934857532871845441950218868879693490062765463289795888126871902116179097837031803339224307168714986819794801926156836860197630655370392709182707576940794935818334707050309298918717919944490705055557805378799500900694890233488214864128764266130529421241527831611400195926289552116946686350244924033949158832631018546058426791568124113642759698270857988480601215781121038212219578986982421005328815987848709639437197756988386085280489445916079243976290670627872432799968020488105058694077778166946197421221164764155697816148410074285361961556739283713548334944152067537413584683380510074085252831997597678744871269458413296408104198572887800527245051575942995057124757474296449945853986537508301925345210138625\n"
},
{
"input": "29\n",
"output": "89074/16385\n"
},
{
"input": "9901\n",
"output": "1838099364825091485842998238489502638352163208605775246129613825541675258139803932850287467779059152113767067936585018625986257156889365449198856216156597215096982506298229063072584364817360767528951048690402306736891920567120457283597208730483707878597646111737127186752299112571526574444743928839110241560725998077538870670908652964981237795923920133705668072188172055098674658571105524472734987571439013958589827622877679807533101349696441175687163721291688130495577638100992957486490904022264860238167307326966426591671355541318530110693823370267769955298274501764387363143753324201392980117580626370923156755357235271953717705218606174361705745607690592162188659919159503909577911890370970307505310006952184882295896878809489448279733854445719768942424699644398057419073652907805636830184662379668640311223728733045708550684860813272116912712928434533540137586553447726767616634480071951755086848411168207402152500267945846598199304627785126081886349021085239907165847936787381451395789868857912620418181602257637943517461795756567745027242135635746499764849207120672778956961370729031070654229684060835173403463861644712283677533769437289456513866506359310854677128562818680682992941321465381508384264781767572418820540784203355739555956391413113575042931607212249685559517635004403000728597654807705351363988397543735139434999563378705775136326919194852966154650224921931475263079667563204688934744417553326412692788253071675108998704506853416086820413944387432670284519676275301802962/125452273648412141401139200792882218641901219696469837289293288572011257450596445344900431556985822678505473966864661579347209963648505615850555715097627217097066479080660704969465868115047608339350569484188578919295330407533168003154334023423342555342022391307536410211267951991111768386576708822221590684887453919290735465200207374015290114669657730252171258717734202702792369201014165495230029650599790825798086043493921998720069655131607695731949026550970259238232466795025603593428296890139315719264778473434071093771596336278641488447233270510334985417502727578902135057815734135912817333309063956745909114926072011485206841480113656604580735026110219859430162705524060505099415346499841074663219804685588328455059670451808627552703776919029354602769590260916036671139722494990934857532871845441950218868879693490062765463289795888126871902116179097837031803339224307168714986819794801926156836860197630655370392709182707576940794935818334707050309298918717919944490705055557805378799500900694890233488214864128764266130529421241527831611400195926289552116946686350244924033949158832631018546058426791568124113642759698270857988480601215781121038212219578986982421005328815987848709639437197756988386085280489445916079243976290670627872432799968020488105058694077778166946197421221164764155697816148410074285361961556739283713548334944152067537413584683380510074085252831997597678744871269458413296408104198572887800527245051575942995057124757474296449945853986537508301925345210138625\n"
},
{
"input": "768\n",
"output": "32/3\n"
},
{
"input": "9997\n",
"output": "115045178372494165897872226686512107429178048300340407805913417043457084371526821355671616896548808082243735275331446/7880401239278895842455808020028722761015947854093089333589658680849144354299442122282853250976983128161325598061363\n"
},
{
"input": "199\n",
"output": "5416016912792671923933831206744/633825300114114700748351602687\n"
},
{
"input": "8192\n",
"output": "13/1\n"
},
{
"input": "19\n",
"output": "2936/513\n"
},
{
"input": "9803\n",
"output": "3273210180788326072665779956874407303695209430301336271835983946088930098968971592446649088493870209185601637297946849124915345946101994703881396454817629317067995483358046696632270413949397783371061147815617923539634120806955265009854911188530306501324761896490486400736980978270851173985761450205468514371802366150508965142349402634775190541932571215772934087049601511151015580218962449832712507548850463067009640345032653747650848021793733486635063672276271184797891474270402353352104959589784879937226619631450622372801836784254780047580520552480710915034334830077235403144885444713231997122651029623193719081606830187339528932202520708400927484122175520586418859966084212848690640894333604345214778602427783597772052518000554782737270290980515925878265370322995156392497748140171133095749065170222804510706059714322514254283376693941404435829879255457277967393238087816555358380272466214436430777426033426837629266695879765238233176316258666048369521314622222658677664616511902093975562338612751867496209652181946196463606422353383104107812596334613198740452548306659208445516691530536050604634513689227620071954907294939937244234855896302003859771540054305586466389588586625478638436931865675356838997676239216955771564982882752970004654747040198185582364456872545570483489206688716013710536947301312846273423736064935003964044795795191383397598165999437078614987833270147703891978941201213909953516817760145834793630851002075671081977655885477265842182227630711346029216/222848004313668719691213483700810759987656019547710139664241936991138106539616439762775058065688367531907719095700069508131964048744509937894796740738505066831483388299980505865722101281973991752051079878406943136495731052685385981167936406108052259153180314590401441086107951134763582222178806130979450523610292690241037876575460384059273115066548829780705991363970146861803501538571064868730128783979777341880332463641995130956398538891263597839918422762242505609422357073557925121726514010836900537641686656503152430580165941404831443945570282690367110620682083028935478555282639476176629026776268383873097027471871476729615653553852994769678614918913374970497476655715836999681683299634189187555967856521001252998565559074621638218445299839894876830416575083610618206257432118972401116133269463833866230950916952995411373918148349361215693246613829888213288305357239073545221307206167441574530195787313912090912979929382777969487951949322618906724196994628638037640106093305472621641881937827447206916332715678892320927194478168405438778896510491602870644308869938666086561401068093659871427096523225215861650585301063106894861911088059286678346350307257457833611661977586521721847940184057530922580500894412994920507883101337204349029037389584516440678117026220089119744731571552913544501272187787585483807869056891982387618102642674500927575453725610336484859306845245953350338792277922673893920973157108631164802759853751459885883070656697593169142468287187573383626753\n"
},
{
"input": "380\n",
"output": "17089848754/1762037865\n"
},
{
"input": "82\n",
"output": "7739/1025\n"
},
{
"input": "256\n",
"output": "8/1\n"
},
{
"input": "2337\n",
"output": "6429067313146769086191243390708972817399071295570593226/510831846955296286119449009050103061206246374061200725\n"
},
{
"input": "7901\n",
"output": "154524871223548423123495185797654506574461761702003065846910905746685998647514825069390588667489327248905358174327876552502957660057253253483877516101528529986709707135176302376822177221161432613294608372321628357823583864101273914414227874808941949788705240048101067284633674852304568823278847645592602559676080522967116394164201940415879553271492035834028327398486009600093157465503523211488955021953127268647916111031703682619831400080346816600935122503273822918215392148364075637874362562003886513246910604701515426048343641513851237428592540111811008678402471757951449650412535345381923708040483001118261857832491735489869517576740499550045310104023129873482509874323682634142866901829084234882445385200295319524648351689094720128553785639719221969264129589951800322116024545902369342877667788536967565125990256796799578322951449803408736681264649241378320858137626918605730290281622575456429027323727694782739314124549860068706433370934863613425473482843884549752732489665702585505388955369522536754702394875839852529518821561333302341509362321195291824828007269021295402144559299990594887703714374425464288060958835387801765108977136997785318571620158461213961462833468536927703562738/11708004285457312755126666863217644760055861406773594249600054075715122508974581228961888366743801655492643437810966154300770740887430126947893305147118944410195839406784735953274330671167286093169745122932079008472101285489067230450306319942053264911861843858846013256127918927680942561098504170833048864333768657182434590844327804335990621076825744270870324389495315888792715548357390675237849554405351811596599797655317280518276360549141571034933129894218745679847870164916740677879764869800871601845140782167652942474700432778572851450966443631222817719445949290846552185879120812492319719862315771781394854730275436023186795781303781840036204405022306942239374739830768947586427274411392455925485082460607204057421762514961554176729112109598477706758573572158753606767581854626464460620360300538015606769824377407345840454826888698131026097851727716692518589246731498897676124408346168821318136621626754567759664177038839955381358225129907645563115937666757425864999645653438548784189677256397395962427979423494151205540932406527491201269878128444061666062993821362430091038452053553637944869816002598967413541372965358839069476857294840674149717585402596923888822980913065149411098625\n"
},
{
"input": "629\n",
"output": "49843473149688266962934/4722366482869645213695\n"
},
{
"input": "9923\n",
"output": "3760299283807515305392881669921685380087483626665387583310740045779392618490518061864438198412014466565364228291295311284131760183238506480296641521584717001189575119537493891940454933801650905249443352246953782854872613017048635048443614120554701976326536039594670095564945312513189153593550500517921950184962024588992584781239533465993501341159180970745350678104403343694528834994019085606787711931776684194936418570665879951352474415566347678136222813280481902061127946763865268688300550988394467968839427831476642475507856733491281467764508214106535203243052393575405292358868470813735971960765501058279775977978030573791129899519277415389902700239026919247980979527451730380980472670105835211342752731828345683483462323646594371504049372940439266303990974893632430579149551268895678583153720791224950534759778851291627442428157985110658561730352163307118794880980048721449385869746576091026550888327297357898605889141961077282796364157526745937107341872728740687038596285146407533730421930092930276945716734155916067113852174300467379937502904191927521252135950255956504149093128341783431227487283983351865444285852258683713459524558123548207017084006902917163157763229391288430112144112020068120688896821326535586200626213610044286687320856131797617153232959645033928534332319957752653966344480388578387275931286170730869888406739091108118872791757012867192042173164675250862437159941800851341264571676718462429556497603409387737027536322645374934694161916847152916606849505635131538412760/256926256431948065589533083223822783778613697938370226768472654995479055258821520066356083828706964845579210684138826914503086005552139501261938104519940540614792149157193123777466097899617501878989966303618209626716836674627928070460076079971005553340461857397834568112676765677796901655709099667909817722649505626707426232730024701983314154843459031556446737853919647135318772123677010934231100724428371611234480217075552253378702653709532560859031606376387090919900091996212436159341152031005318593054266313592977600044229296698657768339933738005166050135045586081591572598406623510349449898616962983415621867368595479521703611351272768726181345333473730272112973220913275914443602629631674520910274159996084896675962205085304069227937335130172118226472120854356043102494151669741434588227321539465114048243465612267648543668817501978883833655533934792370241133238731381081528293006939754344769201889684747582198564268406185117574748028555949480039033444185534300046316963953782385415781377844623135198183864041735709217035324254702648999140147601257041002735506813645301604421527877289228325982327658069131518184740371862058717160408271289919735886258625697765339998218913415143114157341567381006312214702654442385236130291663443293445882742374334505959639160205471289685905812318660945436990869127471943832136421297268202053045346989965623434316623021431563284631726597799931080046069496359850830431043797398677274215479797865627531253876991503307359129489108964428817002343106990363901953\n"
},
{
"input": "826\n",
"output": "28584112877549284603281069376719144007233968270323045/2660582536225501490205463588802620110449199864902087\n"
},
{
"input": "1024\n",
"output": "10/1\n"
},
{
"input": "2050\n",
"output": "2663/205\n"
},
{
"input": "778\n",
"output": "266081190240146347461776796003542832080357458393960689731819/25108406941546723055343157692830665664409421777856138051585\n"
},
{
"input": "6629\n",
"output": "2887307659130237302642554273423838808127851411579740408603950850448329124209429578113205979182558694432261838498919298006073282090488747091133824076367223385537560048772408256051559991222428913480943619030448796454451464748405569577077070495809049315150455270612613741854545427076463694803465943631755282225609026765330663439059215627258266275926212560658364641003632351846514061002732653254081394744335331237509798266695411546509090369792904212760685221160746857281893822469878668200610823671894328098385881817861753695800065416971052016223369182639822884039635988536652840558612597041060408982777496899496636365058808687724981165384757681315381211128069241997040989872305659907708921647388171645286221722272322318854767537934213556895841513237023702848005057904349430483402077740905836879687396728501991700731675965774958896511445289952574454217713912566/210439709873991868905206709999487052984247952276039156343252616574532754705650722004300298245964825362541587628789248356606056728825748083942006748155990988733576708756338714208397994866134077823164471642182865530873338775979158574778322326012875645668888540050539820400471552142636150392765860518915979128399304922907514476757775002100975564775155375051147014479116634277960454265544812809261486134003372557704674756415706698752926716676005834544745324365026103039698132331727376732083132706909169583428843558754538001272157568020053994702446025739684348595183905880943973524896471821030796954828997801978429332618493785988334324089876014640158374627531328161119894647301897935862230495210208307169854685591765674073647881852443540003672714918865561046500967855257355789561470414296094139059049963931413883590960007395542147128447042694814123776167378943\n"
},
{
"input": "32\n",
"output": "5/1\n"
},
{
"input": "7708\n",
"output": "39413297508974631726391031213171923271142554912679270458193728426423636026646334915727139650713682692479792411879633606353758285856351703126/2977131414714805823690030317109266572712515013375254774912983855843898524112477893944078543723575564536883288499266264815757728270805630975\n"
},
{
"input": "42\n",
"output": "45/7\n"
},
{
"input": "9923\n",
"output": "3760299283807515305392881669921685380087483626665387583310740045779392618490518061864438198412014466565364228291295311284131760183238506480296641521584717001189575119537493891940454933801650905249443352246953782854872613017048635048443614120554701976326536039594670095564945312513189153593550500517921950184962024588992584781239533465993501341159180970745350678104403343694528834994019085606787711931776684194936418570665879951352474415566347678136222813280481902061127946763865268688300550988394467968839427831476642475507856733491281467764508214106535203243052393575405292358868470813735971960765501058279775977978030573791129899519277415389902700239026919247980979527451730380980472670105835211342752731828345683483462323646594371504049372940439266303990974893632430579149551268895678583153720791224950534759778851291627442428157985110658561730352163307118794880980048721449385869746576091026550888327297357898605889141961077282796364157526745937107341872728740687038596285146407533730421930092930276945716734155916067113852174300467379937502904191927521252135950255956504149093128341783431227487283983351865444285852258683713459524558123548207017084006902917163157763229391288430112144112020068120688896821326535586200626213610044286687320856131797617153232959645033928534332319957752653966344480388578387275931286170730869888406739091108118872791757012867192042173164675250862437159941800851341264571676718462429556497603409387737027536322645374934694161916847152916606849505635131538412760/256926256431948065589533083223822783778613697938370226768472654995479055258821520066356083828706964845579210684138826914503086005552139501261938104519940540614792149157193123777466097899617501878989966303618209626716836674627928070460076079971005553340461857397834568112676765677796901655709099667909817722649505626707426232730024701983314154843459031556446737853919647135318772123677010934231100724428371611234480217075552253378702653709532560859031606376387090919900091996212436159341152031005318593054266313592977600044229296698657768339933738005166050135045586081591572598406623510349449898616962983415621867368595479521703611351272768726181345333473730272112973220913275914443602629631674520910274159996084896675962205085304069227937335130172118226472120854356043102494151669741434588227321539465114048243465612267648543668817501978883833655533934792370241133238731381081528293006939754344769201889684747582198564268406185117574748028555949480039033444185534300046316963953782385415781377844623135198183864041735709217035324254702648999140147601257041002735506813645301604421527877289228325982327658069131518184740371862058717160408271289919735886258625697765339998218913415143114157341567381006312214702654442385236130291663443293445882742374334505959639160205471289685905812318660945436990869127471943832136421297268202053045346989965623434316623021431563284631726597799931080046069496359850830431043797398677274215479797865627531253876991503307359129489108964428817002343106990363901953\n"
},
{
"input": "589\n",
"output": "13383001136884230836493585742/1237940039285380274899124223\n"
},
{
"input": "9996\n",
"output": "2016420396858486097238844042485568452071214924046/138111634978483258420134114867245645268334710595\n"
},
{
"input": "9861\n",
"output": "48205401549715737511233606679265031152996036546952288925330285615396586708825956490117819026249283326464870369563186432330830706792989284262067110327971987394928549360770263191516012692848869076552182149927367930957872055698792311482405327082065553619653685393875355497796244989262571944371234203749880818792381890143341459002264984197001955297069409069640536538793687219440766877509028035223421720178766484630650779161811795215598122460003343408475412680746717692338/3290879900222849827608052539430658202162644647861847314923076320003764758653341969980190752914563139807162048895505755870361486648381383099691844932800204324120184612702378973553707797050274474225453114896913503651972909544659079317451280550706528208210350955646021191856774287744501662258236298537350308345677099157123880199583378106453686203843351330612430156752066264373448200439828567114920448248846344529227554677699885755768618085582483438055430499449947116885\n"
},
{
"input": "9994\n",
"output": "328111741450887949842612914629663563870667385755914671475880468765597732133644189201477475631016157102196465309313603105997367498853523555219429574372156305589342576904681777669621642789685732152516470981488940483457222729888431634814996047114588192424934982619578590333352356824505599885346208604686640013912007278131140168074843179989404904098932867784958631796493911251322964342171286347711440847528587716152688971709472145028339076565107322973849148823672370940479279050593505938843022603186669429075130910303472288303142806635591625595576397751027913049133872317533138902530682243854978333257389708443495600092253550929008177825146050803538322954406061665750593526888003528964818008291369534145972335833863/22470281903677621670250247166669183922229960101627612313077582146501531597897683295548755131836777256722553150105278210785740255007194406467420221632183294251493775739503061818015450881289061585718518714293630672935099903923167258972709629019731504964188639048893314099165623757150270233178679692469056074668837831125346088169097676377507702197574788074401206685038546481463782121795012524205029060909495765804295971801257245095886645483279056744938803269137681981662490941733391184387603544922138763350922034288576129143249631254095529412261405225805556666002169396658673992839072308122031150344079372945346548610062626553928189740089369188595341086144906548995484731331412032827766756779151970118929462154581\n"
},
{
"input": "9995\n",
"output": "1368770541403820619075110203708490210616145992745821521870208914365828115565556194877572535511077690510688277376757546565243584175363368143317667278940670502781186329534839008398699279841764334491329910860701074569229951248069967340109056226002539889667430100999595433067983400778886042165596127864919572486395941238704720403024794261441096255620000217687954366591408789194462597191661175824028310400352/93746319107175952683864071964918454730461746778024627464635174121600584812748548703282543376385452193806936431137231560052128838065111583392770646215498841416082979442330648067511176282732199184911147558161483085919841893469290827996255650168474543134607110617533756037909735459668069833444196401816994512004002417933496313555598963173697952072590902286596238498989761054870081835578169164103256375295\n"
},
{
"input": "99\n",
"output": "82792/10923\n"
},
{
"input": "77\n",
"output": "8215881550/1073741823\n"
},
{
"input": "512\n",
"output": "9/1\n"
},
{
"input": "9861\n",
"output": "48205401549715737511233606679265031152996036546952288925330285615396586708825956490117819026249283326464870369563186432330830706792989284262067110327971987394928549360770263191516012692848869076552182149927367930957872055698792311482405327082065553619653685393875355497796244989262571944371234203749880818792381890143341459002264984197001955297069409069640536538793687219440766877509028035223421720178766484630650779161811795215598122460003343408475412680746717692338/3290879900222849827608052539430658202162644647861847314923076320003764758653341969980190752914563139807162048895505755870361486648381383099691844932800204324120184612702378973553707797050274474225453114896913503651972909544659079317451280550706528208210350955646021191856774287744501662258236298537350308345677099157123880199583378106453686203843351330612430156752066264373448200439828567114920448248846344529227554677699885755768618085582483438055430499449947116885\n"
},
{
"input": "9851\n",
"output": "18265268265520540785908331599388596086601686893936229266975936149663252475233854868431481692229058024923431589387659887867902680080183462504251855907294546963177054676412752415280943300166703724954104193781416518797928286826415325332840928794180900409037356267851073782046598387404127155718808844538373667244444328956542214789965312060454053447621394245918870851186507344747417605653775585109692134356662244321759849102328545344784420668995358085194630127711431602472710880078819974685888683913959613604493112607285755338616455009301468715782989705834386644957400388390566758392150728632659510383880551633428476788516339901525016398990001474110188269351024831528207885540825997319998166104138747638272941441134463442026326873236217051663959231958241680370115809166365792021138069848917961267525948375559165503280962387996982888846030231981715588925232378210229430804794913608024007017149934655717953874398908493758773482266278494809575155035699163146831855305715514980662636600137664244032908275561765291731574659214609335181436215261784472370334656269736145983983299651958393592650363097522621151977579876823874400736328643285043574846932479789412227618717036882664289326702680070901993665489716988043011337934536983844751946964735793973495903486597880356428661975609996251202975190898308197830114324065800497484920958433532502516025186842292166331207944400540709960586195814487225935384488510616614943463793147585780366578287019794729442704404133845784855565244538577819709563958432/1246256367846450620900980639386993831812354124550718439512384817719571366415385855683688636193531976923400898445294912450981239116673724014069196731821966341108744135306881914232828896393851522002126470051095673633568787649603366883142133786512837363700294408277038834604302565168457909291751273693855510998640993429131661506495946387601793951488114697259379016535820590484066498289646362217565672105548688032210727964777966327667928289687709964632481600353819720330163506617403066093010672828945673696843569213490397669589483104930733526222241625292450044726359124768794924595114927847314053111365079450069955139617840563110578472218053108499256124358477392389676597769300743988150510653851837661496994939303282185942527358251895780888237326532893921959098083385984467179971163421779223854669648860314987290589806372821954543027180392425525902729393830873936730656417452366836021212933409233154424397748685187651419567159639870891380259750468877027931901801811833381101396730100689385124042639143217506344002632937121036312287344746207473989440999387962515673209693892302562038440994012679964488208874332821052512662040786924668729190832388557802846413972174912561798304372318744538711603874337650904937446964586669662754528164628055399933183519045194193602651940724032900402408812654228655141151923101627926769707222397692395088211182106973251377914484189782346388440184323310828185863741946910405291084529004480172075833154172217606931875716892455759609241742431983724318960560811\n"
},
{
"input": "2614\n",
"output": "467288820759363880397722656040592964020719930972683440703193351374700405080631777580381050558531644513848619882285655907104502715940077345333622944378242416293600447930921066507506568704500773773633/37375513539561023231108477793896786533525327931380202951304745106630862169773485150256437750311906506986637800026885384689161869077507588081685801531164378630160340372359290471078905382884178132993\n"
},
{
"input": "2048\n",
"output": "11/1\n"
},
{
"input": "128\n",
"output": "7/1\n"
},
{
"input": "56\n",
"output": "45/7\n"
},
{
"input": "13\n",
"output": "306/65\n"
},
{
"input": "6\n",
"output": "11/3\n"
},
{
"input": "7\n",
"output": "24/7\n"
},
{
"input": "49\n",
"output": "1985714/299593\n"
},
{
"input": "9883\n",
"output": "3585169013008320587733453934540655406968508071250655174069676351966247095891666666457951370861261022535907218197677774600785190516321049571099175528120462561383326438548822604717683501452327840790897918994708328294710567693091965543331903184071652577937298158191755916197924842106107578819028940776121678861464188820255086932973183740793372165945865009415954786595728774195980645745127346052687115724325004061229398519190748075580806663121266449693574278118081790297078495193488775980028423355059820522243653725874632878510045835553519741832072550463732084440328479802757883822909816376632890811035439142421989449863044208586517399880008863407492496206323270830482631638372716663110223514171732041108713906301160805034170356396842166510003100992178793709386042537964760180749873610550892321524236421203672563269319950307992448377781123935998679097946148059114351779548141469866569341951745396332639499438188190815082774623731116948453999214458330207016238401484362043219831905888672028360776820475855330015482747522043053354249914178134040244185110051911485974319449824722583973072546384468573330564589187898015237282681548921919611841954714952547395797273043248344370035395990109256951956434133363924387603461250518602022484830305070939839063616330207734382452009330287037414957658873609136317223268183549799388228885998953454699718350330403675879708887230727150794790578035321318346228048669908308488864491704843219546622006983096396305733734212669415968084578686794694798437666747022528/245023971969554963674100001548598083284963319719667650955650954242209487208196182314258655384737934918956003841532542147162519460250987530958116631050053158392707966954415439393488023662202360037794081023805818201748692202213218756160808639498715928402387483022532051193882718732640172630032634418401544306420808436114717705469155027373613505214175254398771989683074614653891346095730791982871151661327716456636886803699066403750136045178921280726462942482363787574672786709034382018414642363553351014189020455925920105022649094294221657123502481465498018393560014802543232534796355734204721354119265540519353740089984397432044612265846985555821748097871523162949536534226680674022295598632502098951601181026539704013788418851188725688874564294979208208534355978351634123319770498029169643618890323128809021228280651347778838795487882593997796683820662300462952740896922474938896458632411722512025071992573497373770298260122475736212490109020184974707635349450620937391583408311636338630467775196669707487281669656501492707286190275862359046116016007668534281478411496777822117253806950844982458097770364827281492409458515035685269508751174249572502027758241365208950041026032843726267011014525776869117941572813455949054842273391192716070063345312437540015830192761870660482316791838322587429991597297164863426338597581165506413503024091687797006909010907584727558738447759437495307966298576698160963469547078512837671485404775491359263662220946791941985253800496067456070902197939863553\n"
},
{
"input": "1\n",
"output": "0/1\n"
},
{
"input": "9999\n",
"output": "396504919788033353440140876437127916065460257739670266843919813860579129943101204509709504/27160479684459814483579275845458375480686245248879150008481872658058417330177822749111965\n"
},
{
"input": "8947\n",
"output": "92217769650613941080630745376651933397191302347912593530353833699082767482320053295873976335261338396309773662884101662842457408770833712224740258269916309119393363719163880754797784504204928376494183707150687254382915622323093679978287895961773920594292978995513577964215777504112090455173786839038765078953566596501076201082418241675636449015103402653720191796734537241208020262611562799789253796538147209979307343496482329841157415668866988738359135695532638926095881556206387247047275982889596856215502497372454403017804736518377694017093145759135565451187077401200832721851731046427121501133656571935612796455781816807902515476728658693498476446412506031202442245240570035236662350020575294290901650771066909827076845032177288445995720592293708358208797029207264762880645247427257707612939826564013721632684623704064398177623643552898057972509138117104547949763433335143917052862499770462405614211667395567829627153587228986443476520743298461920576721953351927084670699264245007148998170282414097200641632369261731232256384042741053414359751300178849126336761514536162023150815249146560705170439304772066253851777701029064668052252444327326087007689616954432155738920844369876980684180971739371626802860827933850173815284965901524281521807500221496567884872319546677778723089803624/6252036342560819570523112832025531962797490003966039732870902011446197609660581599850268257010152251205336955451824856293775321046192908822509001667528039037689681221037726800127247595498549747717526779751261968533262734275081426256774201583510902785280975078796902985150189558168793985039170092737929518556877204050527242044694197761677768740255793809823325324216134476513445529910234140126414877638524195984384623274359548332179860494414935751283376521152364168761511367061700395657677451748372910430794830742985757681312008806438144591613429595112348166020095169464928020831137306693186069988326477281465032562179039766410882532876992751585321457123600572371668503678644725794827683161183187164959409239149862517059913493904108154244777276213869162615900352358556227894640678920224620252048592352609924480747509120115706107045674107471294367279720247581576228206622006920802946451725437656694068893660680498529140390069153092207810555916628716364087683749197123889518859398928036584563930522367458311612861285208884232697419053862464308098864083457354215421425951599282242184046104866832500282657797392186803207610331402306315126035831454975913405099442625817545247918142274133748306880770190568103485303008422266954828535985762501328186014923158523827467759649904650333404692217855\n"
},
{
"input": "9994\n",
"output": "328111741450887949842612914629663563870667385755914671475880468765597732133644189201477475631016157102196465309313603105997367498853523555219429574372156305589342576904681777669621642789685732152516470981488940483457222729888431634814996047114588192424934982619578590333352356824505599885346208604686640013912007278131140168074843179989404904098932867784958631796493911251322964342171286347711440847528587716152688971709472145028339076565107322973849148823672370940479279050593505938843022603186669429075130910303472288303142806635591625595576397751027913049133872317533138902530682243854978333257389708443495600092253550929008177825146050803538322954406061665750593526888003528964818008291369534145972335833863/22470281903677621670250247166669183922229960101627612313077582146501531597897683295548755131836777256722553150105278210785740255007194406467420221632183294251493775739503061818015450881289061585718518714293630672935099903923167258972709629019731504964188639048893314099165623757150270233178679692469056074668837831125346088169097676377507702197574788074401206685038546481463782121795012524205029060909495765804295971801257245095886645483279056744938803269137681981662490941733391184387603544922138763350922034288576129143249631254095529412261405225805556666002169396658673992839072308122031150344079372945346548610062626553928189740089369188595341086144906548995484731331412032827766756779151970118929462154581\n"
},
{
"input": "8622\n",
"output": "2346970612497798292051684863778787677688918498337895665035233783242368128286257851467636458012981817792946447606933694463959158768680516918810044760234529638520868683195790661167605124671831213269266007988150361676380026247303195939614144448935172977317349504257500667344413574778276538084533093523373859439640543406392557232735743996270882880554311714917225257533788072187384837827098726745502145040757646538864148126423442625937245/158450103580531636036828827760200463708558264074197895770614130238733548787583684152724709587811859737216181571248100013762215682730756320071818118043767724270459420257714506357027386375070761460082246558018893533772011466701231582991394416190882917676565785822100399450009192822976794870861997661290175933763162180529059984116060787778454199555587743992742904650146111513904831859678244868920370808097155872403849701260040561055061\n"
},
{
"input": "8771\n",
"output": "3770311067804988086442280897982793233953991174834038671591744622664235928848771481024534828492198884087581040596792755307166862630362254070801530083149662062951269890316117808935983174156710048296936374305714276676638609402088826404322038255398708095256451326373150897864019805504212731596330281332804357336587199175247125958363190591680678576959242590696722761770737808874948948372052533640442104091203823298252400438183921494229420351844306480773904754871502489649028646657382266084070860349033005494965904934674678701897132741589691407206106801097274732068221500031680182263162033602626934555304115531347928140446440945591592932427245012260789957940179101631138948460412286465099888122326063513750482682326723464319674902153298387858444971923715259477081311102501583036125526710504546004468511837265591006550003483782433783442621249901629744154439023643251315730670308764111394769023672384470337304766949908012304817829414520396407508489424725339513402783686552282423799572440910971783937158043549099496043303322625144503140639937779219011683940747291043243308548169647599229875802717140859867699015081564693403414716026392/254112337966185048145050697895207069641497458398647542649065418404498038139377759342595363554009019566161055062997751547500206639362949492006474301797022654801158128820196716326106362106403286457612190187456912920808412881293195186245842924967428385914585991275713605946412097136030572073310702795961125479891587077179636178892839685904381701467629134612525444360188175468415165967413472317456215346115391103529248749740115499825087295715358216112091166524304386153909742917759066425275552858607893964600949865402428132688562806038776462988818002383303936358784435432729816211202313646211831224161128933734347766003462051119834409589113808690470859331253464854227535288751197326551823917348985510776846798566465592269389798031307292408150096029799069606592885221319274957177584284853924291730279162417393707432764665977534279254034941775234643032493257138019086606309200964643412513016588705886261875780586661764409885704175582248774207023912960284462109642983958096910472753662964000422144867897639655797608668987269157109510390374051847424186461279227921367196511856812747079196793468282726294200550127922075416882636427849\n"
},
{
"input": "356\n",
"output": "20036/2047\n"
},
{
"input": "57\n",
"output": "1118/171\n"
},
{
"input": "54\n",
"output": "377/57\n"
},
{
"input": "897\n",
"output": "6303910445469575479185224346195379698702/604946430081668379490443746545365709255\n"
},
{
"input": "9907\n",
"output": "1633354865670482634892575473274177878269848372373759525765811325846788929611278968402771127221384695483915945198456285004476851582174958025985911899376499975337986661537173411180428490907671107896805361798951388912266345066652077866312114944286489782939084013056891167373799137114155515056010000276816186615290579398553645497061457349859874907706345855178899820840538136570385474191197090563464515778875629438803382571649568677198891486414476226932831825123576296441036124053704853315256369077062694497961110434982641810098930629547385147383059244374581651992456044925971934850442830194217280514603049112460209344747724704460094333483276967669942685299188841394315505390707812866736298697875298127848875145262191230878125445765654264972808396487147578694015479599857513297812474321479310509988898419240869755115441035610394724742733426143862263998840699035405386591348806972955989366740531496447026566482443584635769122576528379572484919769116532440328453434380368399747202088827429149682924434791294983263532249848151359239961565497074342143353501637548919300241662090353407294661111131471268545214977964856225076533564370498248492613685805161596682009974473114515513380958196492686912557866989055667956732635644620975053458902179010611928423215547799006570194462929051080094813251146339256886128285111370771379853589184069970476491616306084104329480579259858092153081246668787325700941970854871522339560167691629337094064099025875633061751502297990098463516213737680898668940099498771690328/111513132131921903467679289593673083237245528619084299812705145397343339956085729195467050272876286825338199081657476959419742189909782769644938413420113081864059092516142848861747438324486762968311617319278736817151404806696149336137185798598526715859575458940032364632238179547654905232512630064196969497677736817147320413511295443569146768595251315779707785526874846846926550400901480440204470800533147400709409816439041776640061915672540173983954690267529119322873303817800536527491819457901613972679803087496952083352530076692125767508651796009186653704446868959024120051391763676366948740719167961551919213267619565764628303537878805870738431134320195430604589071576942671199480307999858733033973159720522958626719707068274335602403357261359426313572969120814254818790864439991942095584774973726177972327893060880055791522924263011668330579658825864744028269634866050816635543839817601712139410542397893915884793519273517846169595498505186406266941599038860373283991737827162493670044000800617680207545079879225568236560470596659135850321244618601146268548397054533551043585732585629005349818718601592504999212126897509574095989760534414027663145077528514655095485338070058655865519679499731339545232075804879507480959327978925040558108829155527129322760052172513580592841064374418813123693953614354142288253655076939323807745376297728135171144367630829671564510298002517331197936662107795074145152362759287620344711579773379178615995606333117754930177729647988033340712822529075678777\n"
},
{
"input": "10000\n",
"output": "211285126026764324876224334024814529251789998319439411297242149907456038558/14474011154664524427946373126085988481658748083205070504932198000989141205\n"
},
{
"input": "8\n",
"output": "3/1\n"
},
{
"input": "2614\n",
"output": "467288820759363880397722656040592964020719930972683440703193351374700405080631777580381050558531644513848619882285655907104502715940077345333622944378242416293600447930921066507506568704500773773633/37375513539561023231108477793896786533525327931380202951304745106630862169773485150256437750311906506986637800026885384689161869077507588081685801531164378630160340372359290471078905382884178132993\n"
},
{
"input": "5484\n",
"output": "211086977989859276474150/15111572745182864683827\n"
},
{
"input": "6629\n",
"output": "2887307659130237302642554273423838808127851411579740408603950850448329124209429578113205979182558694432261838498919298006073282090488747091133824076367223385537560048772408256051559991222428913480943619030448796454451464748405569577077070495809049315150455270612613741854545427076463694803465943631755282225609026765330663439059215627258266275926212560658364641003632351846514061002732653254081394744335331237509798266695411546509090369792904212760685221160746857281893822469878668200610823671894328098385881817861753695800065416971052016223369182639822884039635988536652840558612597041060408982777496899496636365058808687724981165384757681315381211128069241997040989872305659907708921647388171645286221722272322318854767537934213556895841513237023702848005057904349430483402077740905836879687396728501991700731675965774958896511445289952574454217713912566/210439709873991868905206709999487052984247952276039156343252616574532754705650722004300298245964825362541587628789248356606056728825748083942006748155990988733576708756338714208397994866134077823164471642182865530873338775979158574778322326012875645668888540050539820400471552142636150392765860518915979128399304922907514476757775002100975564775155375051147014479116634277960454265544812809261486134003372557704674756415706698752926716676005834544745324365026103039698132331727376732083132706909169583428843558754538001272157568020053994702446025739684348595183905880943973524896471821030796954828997801978429332618493785988334324089876014640158374627531328161119894647301897935862230495210208307169854685591765674073647881852443540003672714918865561046500967855257355789561470414296094139059049963931413883590960007395542147128447042694814123776167378943\n"
},
{
"input": "5157\n",
"output": "12442026996165779252579088549925028791051874628606527535001439793690642457233638161529019846421853181052270799241868551212986207796366699090995251760167205669800367383798404842010608407622261408916491952483441600342434569609695004344095594024009977850762623682434851512646239134464063004097143662638365440174081126023896223921683437722733295889892578545470756216471344123755716244218454673450181136081429412200694122562864272387055688453940572665492798440345645405042887238318718726137613851002190135717975745282954/916119307130486371484938811610949500570915992967855785697969548899300200660412633087534804795290334247058449526064721755130252628518238104705541663446555412345459291552249537339439565178101712466299210066592331494439558699531214655871814510665233163203058047862310949865537041564429614401677524439408093277749806746812228460859170544171216999335090184880167120938847131318428546724316426560152386097690720636198234396967264524299251998623243334293646270184739398143551162801870892735897398759544003510218959097921\n"
},
{
"input": "63\n",
"output": "128/21\n"
},
{
"input": "9851\n",
"output": "18265268265520540785908331599388596086601686893936229266975936149663252475233854868431481692229058024923431589387659887867902680080183462504251855907294546963177054676412752415280943300166703724954104193781416518797928286826415325332840928794180900409037356267851073782046598387404127155718808844538373667244444328956542214789965312060454053447621394245918870851186507344747417605653775585109692134356662244321759849102328545344784420668995358085194630127711431602472710880078819974685888683913959613604493112607285755338616455009301468715782989705834386644957400388390566758392150728632659510383880551633428476788516339901525016398990001474110188269351024831528207885540825997319998166104138747638272941441134463442026326873236217051663959231958241680370115809166365792021138069848917961267525948375559165503280962387996982888846030231981715588925232378210229430804794913608024007017149934655717953874398908493758773482266278494809575155035699163146831855305715514980662636600137664244032908275561765291731574659214609335181436215261784472370334656269736145983983299651958393592650363097522621151977579876823874400736328643285043574846932479789412227618717036882664289326702680070901993665489716988043011337934536983844751946964735793973495903486597880356428661975609996251202975190898308197830114324065800497484920958433532502516025186842292166331207944400540709960586195814487225935384488510616614943463793147585780366578287019794729442704404133845784855565244538577819709563958432/1246256367846450620900980639386993831812354124550718439512384817719571366415385855683688636193531976923400898445294912450981239116673724014069196731821966341108744135306881914232828896393851522002126470051095673633568787649603366883142133786512837363700294408277038834604302565168457909291751273693855510998640993429131661506495946387601793951488114697259379016535820590484066498289646362217565672105548688032210727964777966327667928289687709964632481600353819720330163506617403066093010672828945673696843569213490397669589483104930733526222241625292450044726359124768794924595114927847314053111365079450069955139617840563110578472218053108499256124358477392389676597769300743988150510653851837661496994939303282185942527358251895780888237326532893921959098083385984467179971163421779223854669648860314987290589806372821954543027180392425525902729393830873936730656417452366836021212933409233154424397748685187651419567159639870891380259750468877027931901801811833381101396730100689385124042639143217506344002632937121036312287344746207473989440999387962515673209693892302562038440994012679964488208874332821052512662040786924668729190832388557802846413972174912561798304372318744538711603874337650904937446964586669662754528164628055399933183519045194193602651940724032900402408812654228655141151923101627926769707222397692395088211182106973251377914484189782346388440184323310828185863741946910405291084529004480172075833154172217606931875716892455759609241742431983724318960560811\n"
},
{
"input": "9991\n",
"output": "6382125632197575640171909108366323999672572433833222272392411654952806480364944179628596547334889065794512754663260535014179926913634410060297543083266944529654281991142775738499030710183320227853166673816892482763220210176769895648821886542105816/436994993873214129706097166956708350993678881411295357199729151951767944417616335439228580716318181998128654620651240845861768505204366709906692902245553277900892247131030458103436298545516643924637451297481464347472084863384057367177715867713535\n"
},
{
"input": "7901\n",
"output": "154524871223548423123495185797654506574461761702003065846910905746685998647514825069390588667489327248905358174327876552502957660057253253483877516101528529986709707135176302376822177221161432613294608372321628357823583864101273914414227874808941949788705240048101067284633674852304568823278847645592602559676080522967116394164201940415879553271492035834028327398486009600093157465503523211488955021953127268647916111031703682619831400080346816600935122503273822918215392148364075637874362562003886513246910604701515426048343641513851237428592540111811008678402471757951449650412535345381923708040483001118261857832491735489869517576740499550045310104023129873482509874323682634142866901829084234882445385200295319524648351689094720128553785639719221969264129589951800322116024545902369342877667788536967565125990256796799578322951449803408736681264649241378320858137626918605730290281622575456429027323727694782739314124549860068706433370934863613425473482843884549752732489665702585505388955369522536754702394875839852529518821561333302341509362321195291824828007269021295402144559299990594887703714374425464288060958835387801765108977136997785318571620158461213961462833468536927703562738/11708004285457312755126666863217644760055861406773594249600054075715122508974581228961888366743801655492643437810966154300770740887430126947893305147118944410195839406784735953274330671167286093169745122932079008472101285489067230450306319942053264911861843858846013256127918927680942561098504170833048864333768657182434590844327804335990621076825744270870324389495315888792715548357390675237849554405351811596599797655317280518276360549141571034933129894218745679847870164916740677879764869800871601845140782167652942474700432778572851450966443631222817719445949290846552185879120812492319719862315771781394854730275436023186795781303781840036204405022306942239374739830768947586427274411392455925485082460607204057421762514961554176729112109598477706758573572158753606767581854626464460620360300538015606769824377407345840454826888698131026097851727716692518589246731498897676124408346168821318136621626754567759664177038839955381358225129907645563115937666757425864999645653438548784189677256397395962427979423494151205540932406527491201269878128444061666062993821362430091038452053553637944869816002598967413541372965358839069476857294840674149717585402596923888822980913065149411098625\n"
},
{
"input": "8771\n",
"output": "3770311067804988086442280897982793233953991174834038671591744622664235928848771481024534828492198884087581040596792755307166862630362254070801530083149662062951269890316117808935983174156710048296936374305714276676638609402088826404322038255398708095256451326373150897864019805504212731596330281332804357336587199175247125958363190591680678576959242590696722761770737808874948948372052533640442104091203823298252400438183921494229420351844306480773904754871502489649028646657382266084070860349033005494965904934674678701897132741589691407206106801097274732068221500031680182263162033602626934555304115531347928140446440945591592932427245012260789957940179101631138948460412286465099888122326063513750482682326723464319674902153298387858444971923715259477081311102501583036125526710504546004468511837265591006550003483782433783442621249901629744154439023643251315730670308764111394769023672384470337304766949908012304817829414520396407508489424725339513402783686552282423799572440910971783937158043549099496043303322625144503140639937779219011683940747291043243308548169647599229875802717140859867699015081564693403414716026392/254112337966185048145050697895207069641497458398647542649065418404498038139377759342595363554009019566161055062997751547500206639362949492006474301797022654801158128820196716326106362106403286457612190187456912920808412881293195186245842924967428385914585991275713605946412097136030572073310702795961125479891587077179636178892839685904381701467629134612525444360188175468415165967413472317456215346115391103529248749740115499825087295715358216112091166524304386153909742917759066425275552858607893964600949865402428132688562806038776462988818002383303936358784435432729816211202313646211831224161128933734347766003462051119834409589113808690470859331253464854227535288751197326551823917348985510776846798566465592269389798031307292408150096029799069606592885221319274957177584284853924291730279162417393707432764665977534279254034941775234643032493257138019086606309200964643412513016588705886261875780586661764409885704175582248774207023912960284462109642983958096910472753662964000422144867897639655797608668987269157109510390374051847424186461279227921367196511856812747079196793468282726294200550127922075416882636427849\n"
},
{
"input": "4096\n",
"output": "12/1\n"
},
{
"input": "5157\n",
"output": "12442026996165779252579088549925028791051874628606527535001439793690642457233638161529019846421853181052270799241868551212986207796366699090995251760167205669800367383798404842010608407622261408916491952483441600342434569609695004344095594024009977850762623682434851512646239134464063004097143662638365440174081126023896223921683437722733295889892578545470756216471344123755716244218454673450181136081429412200694122562864272387055688453940572665492798440345645405042887238318718726137613851002190135717975745282954/916119307130486371484938811610949500570915992967855785697969548899300200660412633087534804795290334247058449526064721755130252628518238104705541663446555412345459291552249537339439565178101712466299210066592331494439558699531214655871814510665233163203058047862310949865537041564429614401677524439408093277749806746812228460859170544171216999335090184880167120938847131318428546724316426560152386097690720636198234396967264524299251998623243334293646270184739398143551162801870892735897398759544003510218959097921\n"
},
{
"input": "9949\n",
"output": "30771945768974312829849286149718032439798677467423493967010334358283994984326026515504661301394540080141512302827338824723593201789481739830982595229625700583149586238955431037653778739309457671890129351276923685142834902559798917246250215421521527437619966091451717584873598334082323796428001565577186322128798336073715122147162994673808366455578086459869026609967714613554824824759058832899783907543792360923791441961728662642435663487942507846671256543700983615951249949208724967800869867388054589031851260302269048408876735464545077279886559546809841455560742265338090287549868226487740814828047510635070623293003545071913364258117360949495583083158833097103857044434279928869747427297854639426953768566959891591203122862851297692620246536344125431027520526966343015915582695313902053937737605214941486508347934274945698807835217128834978971566963674180680330348426256461353890985386815655822602029905923905821026891198095526938372914444181903627938094196468774691975665647890550812376683751593905633065125611092957601442907415902644417519682901059153440286626841355350656757754077474910571424577932014202554351172899008539276212598195566148386803283414780184354222934329064815395828988176783012436153939221036332468551883344836802385258800011254159939415282139047054155201180580357201111671543663885937215403704436525087738509669353351862725364108467051762959998292239822805587007389198288780422715556343928293849868727893528481926649471509098886000214133618311655761794432794819144278520611314/2104739892690518553309455017769556244714403413511128897687327989722964420680265892383589038724767456014984893924465270083609280557483126794337796952227352908716377285895726069985002273993666575392685803959240373262064326038551986753208943247122477492965063535803060781979048064432512218363568944479517226783944750093987235698524362358647309556477616386510411676499309749332531381237162073573221177134517220239232861938282924059678332139188490738557186919435363048815821553632972277017322717437995569914300549640953672499562326398555404438240737181738320282706293441180398162726147059796782693569470160760140774337483534168241795984189626521404877580971816798389149476625721556291121992741942677675296965918687927473569482384058810935115262649386369992511259614038884705095632090478521832146758218051298214283210470295696576869734952976211016365306133993819097015363491687473819879776312850467592349301880297452193370638486783468483172335849930338140479761974767896985979428568709385301326081047303152723543522214229898929905953376294524100600956089149497679894409271817382310743421156370753358446447228174902325396969393126293985010978064558407022476380230661716093665265409338696852391176942119985203709662844145192019854379349306927459908671425530548272821364000403220805106940414514470465019829199892250163872861563267221111218547482541798387173921775791567366427703104289177035407737401314179898002891110788289964230373210504115220736031760314395093885988774780636600868883194732465061084790785\n"
},
{
"input": "9907\n",
"output": "1633354865670482634892575473274177878269848372373759525765811325846788929611278968402771127221384695483915945198456285004476851582174958025985911899376499975337986661537173411180428490907671107896805361798951388912266345066652077866312114944286489782939084013056891167373799137114155515056010000276816186615290579398553645497061457349859874907706345855178899820840538136570385474191197090563464515778875629438803382571649568677198891486414476226932831825123576296441036124053704853315256369077062694497961110434982641810098930629547385147383059244374581651992456044925971934850442830194217280514603049112460209344747724704460094333483276967669942685299188841394315505390707812866736298697875298127848875145262191230878125445765654264972808396487147578694015479599857513297812474321479310509988898419240869755115441035610394724742733426143862263998840699035405386591348806972955989366740531496447026566482443584635769122576528379572484919769116532440328453434380368399747202088827429149682924434791294983263532249848151359239961565497074342143353501637548919300241662090353407294661111131471268545214977964856225076533564370498248492613685805161596682009974473114515513380958196492686912557866989055667956732635644620975053458902179010611928423215547799006570194462929051080094813251146339256886128285111370771379853589184069970476491616306084104329480579259858092153081246668787325700941970854871522339560167691629337094064099025875633061751502297990098463516213737680898668940099498771690328/111513132131921903467679289593673083237245528619084299812705145397343339956085729195467050272876286825338199081657476959419742189909782769644938413420113081864059092516142848861747438324486762968311617319278736817151404806696149336137185798598526715859575458940032364632238179547654905232512630064196969497677736817147320413511295443569146768595251315779707785526874846846926550400901480440204470800533147400709409816439041776640061915672540173983954690267529119322873303817800536527491819457901613972679803087496952083352530076692125767508651796009186653704446868959024120051391763676366948740719167961551919213267619565764628303537878805870738431134320195430604589071576942671199480307999858733033973159720522958626719707068274335602403357261359426313572969120814254818790864439991942095584774973726177972327893060880055791522924263011668330579658825864744028269634866050816635543839817601712139410542397893915884793519273517846169595498505186406266941599038860373283991737827162493670044000800617680207545079879225568236560470596659135850321244618601146268548397054533551043585732585629005349818718601592504999212126897509574095989760534414027663145077528514655095485338070058655865519679499731339545232075804879507480959327978925040558108829155527129322760052172513580592841064374418813123693953614354142288253655076939323807745376297728135171144367630829671564510298002517331197936662107795074145152362759287620344711579773379178615995606333117754930177729647988033340712822529075678777\n"
},
{
"input": "89\n",
"output": "15942/2047\n"
},
{
"input": "3586\n",
"output": "1026714465140783036738474632330359205383783819874722347437634384119469704928190591460057095203615899196742515080053210107395/82631996098781074868989413504096379978550585370535152410581099409300723904538918228148651304964410605948901503127919788033\n"
},
{
"input": "6704\n",
"output": "3747509385261755254210316751920800389821077334621726013635892116/274250759553534340359161530426225084163789310938929977224768171\n"
},
{
"input": "9941\n",
"output": "384853449965821966704972732966307410533754716673001872990644754365090705756559909905259906468556983837473030874407257670396254711587695297525843978796573345385105966534793732922560851527360127165003492854386049121963401202049881466162284067795049692605928261294087682986229601310196379407661027753366447296128334837195369728352306910364221724819790584234590499773230968446949449654139435810921574651200199324826389837566367344938559238192678820640156721227690796296835372410818703029961426437218612250923546166131087887183128506236914642265107372940583059256790238734873109550064606852454241895688532803264957771260552966093023026993324786723535480684212796655647178515320455962010444291723038825881485337386595953872058254168410359964399040839348392327614519090725780698083807461735099275217105332435035753958774263103832408352846440135520908788781982960980537030064122924914534253061986335785798932585118262145429733521285255543276010510520192751011713072317121752117777795703412147228931454823584324564303527450001365318783625485155921101661017155244139248803962776096262658198375191699627453070323264267286645773802280627801063123133551237542788441825414046345338526837487440831294887788650949450267282162592637307013507372887692529215654653541232042283216484427420262459679041403322783917834492903078518685769388196722883649292951071615901964473014159404289255892968209177423128684793429579384323572081016759500108948811565542981757113040677115518347788350471128322691656105081491299216747682/26309248658631481916368187722119453058930042668889111221091599871537055258503323654794862984059593200187311174055815876045116006968539084929222461902841911358954716073696575874812528424920832192408572549490504665775804075481899834415111790589030968662063294197538259774738100805406402729544611805993965334799309376174840446231554529483091369455970204831380145956241371866656642265464525919665264714181465252990410774228536550745979151739856134231964836492942038110197769420412153462716533967974944623928756870511920906244529079981942555478009214771729003533828668014754977034076838247459783669618377009501759679218544177103022449802370331517560969762147709979864368457821519453639024909274283470941212073983599093419618529800735136688940783117329624906390745175486058813695401130981522901834477725641227678540130878696207210871686912202637704566326674922738712692043646093422748497203910630844904366273503718152417132981084793356039654198124129226755997024684598712324742857108867316266576013091289409044294027677873736623824417203681551257511951114368720998680115897717278884292764454634416980580590352186279067462117414078674812637225806980087780954752883271451170815817616733710654889711776499815046370785551814900248179741866336593248858392819131853410267050005040260063836755181430880812747864998653127048410769540840263890231843531772479839674022197394592080346288803614712942596717516427248725036138884853624552879665131301440259200397003929938673574859684757957510861039934155813263559885\n"
},
{
"input": "777\n",
"output": "242912325346/22906492245\n"
},
{
"input": "376\n",
"output": "81794781/8388607\n"
},
{
"input": "9749\n",
"output": "24420738504895369936029275850163071991656213953040750251776948750246796077962845691317677269631705913994021086756383098235089231208690232714718182051661959094144212987702253303432217073773124260159318146666200117041612592906844115211509040675212920139551853176678612535045654292046757526749492513241228125837513438956933418658716846512730365072509590131877465449441381623988912185373433489319776194980015068338689021210658939139364253499030464561574097560424964521204779116215457677726768619050046856738764484240389262833903373023132839740002736774915426122802238815407817050693856360952407545226333981896371433729874311657730340419746680805378905702168666514377525913884873553751714155904205031709262115464030534807143888700039849995711800671406127912163382933986015685240389569396807457398304726818373517814077265886528890585763062131364555734521607919713137187807658107106103376981378323172002338180348049030319707116151597120087047456178402809544871620530165936798803297978162622508652805080201485681178041361165961347313090217348403318922506112704312304156650558494700459948184483142107408891022462564899591639479697445627266468118776891821012071431633275985890307805299829762601232691986762912806985999108672619322038677748498306049452995705026758802905382276104042099895012248388280300961696806504069643072689548038490993315819434426936765296065726033493251456080278483753254193225043853870782435870985742176970373530465074443098411876172230726422871158542366506/1660347017002617714488606778538307249454081204143987146498575337165132958737138209959678784502210971205739074168354790718346566325012668504527186905879565081234897585958097173763231197610303698122881948041967623952744387482742860772966864750594290041574689109551917322621553772201862798796436236284520108428674136774547680292840751886809416972596562130605474050074593326909866195459448284422830706715433130725326630947306715927693236908996579034923899343328494620393383183133288660062302008351958547067952801708155516017825647752022977500748412927168362666820601247466619898045678730876569666167916867016800470854877468025159952443494297525060762576154719106633197342274456001815808439997093298938542364958830187119532864980955583141881565003394297337758664601174076037155519665173980601997176330267145233086875952430035258635268720607170579532136126085282961192021945410024711648428486045014668481020534887254915483146379759743582367539028246841629774846096550211590827301839779858452393725051190310768159722653619142777675349102678935518703583706107757021816885992427662659893937916261403794788543307969092291970441498332522026165657401526620077687131667565240216342076492209149314820320785474262554798281896211169067828976372906598068990091901902231877134122149795957801824298289067399088302792517748366920708634383171665576235224624533213135417206031161073482478461006626139211198630019446267887361147680197888350507317883904724462949265962076136239934476369526785\n"
},
{
"input": "570\n",
"output": "81780152549/7635497415\n"
},
{
"input": "60\n",
"output": "94/15\n"
},
{
"input": "4710\n",
"output": "62214231544449127/4503599627370495\n"
},
{
"input": "100\n",
"output": "1548/205\n"
}
] |
code_contests
|
python
| 0 |
ae860349d677eed84649f6f7498685a6
|
Bob is an active user of the social network Faithbug. On this network, people are able to engage in a mutual friendship. That is, if a is a friend of b, then b is also a friend of a. Each user thus has a non-negative amount of friends.
This morning, somebody anonymously sent Bob the following link: [graph realization problem](https://en.wikipedia.org/wiki/Graph_realization_problem) and Bob wants to know who that was. In order to do that, he first needs to know how the social network looks like. He investigated the profile of every other person on the network and noted down the number of his friends. However, he neglected to note down the number of his friends. Help him find out how many friends he has. Since there may be many possible answers, print all of them.
Input
The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5), the number of people on the network excluding Bob.
The second line contains n numbers a_1,a_2, ..., a_n (0 ≤ a_i ≤ n), with a_i being the number of people that person i is a friend of.
Output
Print all possible values of a_{n+1} — the amount of people that Bob can be friend of, in increasing order.
If no solution exists, output -1.
Examples
Input
3
3 3 3
Output
3
Input
4
1 1 1 1
Output
0 2 4
Input
2
0 2
Output
-1
Input
35
21 26 18 4 28 2 15 13 16 25 6 32 11 5 31 17 9 3 24 33 14 27 29 1 20 4 12 7 10 30 34 8 19 23 22
Output
13 15 17 19 21
Note
In the first test case, the only solution is that everyone is friends with everyone. That is why Bob should have 3 friends.
In the second test case, there are three possible solutions (apart from symmetries):
* a is friend of b, c is friend of d, and Bob has no friends, or
* a is a friend of b and both c and d are friends with Bob, or
* Bob is friends of everyone.
The third case is impossible to solve, as the second person needs to be a friend with everybody, but the first one is a complete stranger.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
def main():
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
mod=sum(a)%2
counts=[0]*(n+1)
for guy in a:
counts[guy]+=1
cumcounts=[counts[0]]
for i in range(n):
cumcounts.append(cumcounts[-1]+counts[i+1])
partialsums=[0]
curr=0
for i in range(n):
curr+=(i+1)*counts[i+1]
partialsums.append(curr)
partialsums.append(0)
cumcounts.append(0)
sumi=0
diffs=[]
altdiffs=[]
for i in range(n):
sumi+=a[i]
rhs=i*(i+1)
if a[i]>i:
rhs+=partialsums[i]+(i+1)*(n-i-1-cumcounts[i])
else:
rhs+=partialsums[a[i]-1]+a[i]*(n-i-1-cumcounts[a[i]-1])
diffs.append(sumi-rhs)
rhs2=(i+1)*(i+2)
if a[i]>i+1:
rhs2+=partialsums[i+1]+(i+2)*(n-i-1-cumcounts[i+1])
else:
rhs2+=partialsums[a[i]-1]+a[i]*(n-i-1-cumcounts[a[i]-1])
altdiffs.append(sumi-rhs2)
mini=max(diffs)
maxi=-max(altdiffs)
mini=max(mini,0)
maxi=min(maxi,n)
out=""
if mini%2!=mod:
mini+=1
if maxi%2==mod:
maxi+=1
for guy in range(mini,maxi,2):
out+=str(guy)+" "
if mini>maxi:
print(-1)
else:
print(out)
main()
|
python
|
code_algorithm
|
[
{
"input": "2\n0 2\n",
"output": "-1\n"
},
{
"input": "4\n1 1 1 1\n",
"output": "0 2 4 \n"
},
{
"input": "35\n21 26 18 4 28 2 15 13 16 25 6 32 11 5 31 17 9 3 24 33 14 27 29 1 20 4 12 7 10 30 34 8 19 23 22\n",
"output": "13 15 17 19 21 \n"
},
{
"input": "3\n3 3 3\n",
"output": "3 \n"
},
{
"input": "8\n3 8 8 4 8 3 4 3\n",
"output": "3 5 \n"
},
{
"input": "4\n2 2 3 4\n",
"output": "1 3 \n"
},
{
"input": "4\n1 2 4 3\n",
"output": "2 \n"
},
{
"input": "5\n5 4 3 2 1\n",
"output": "3 \n"
},
{
"input": "1\n0\n",
"output": "0 \n"
},
{
"input": "3\n3 2 1\n",
"output": "2 \n"
},
{
"input": "4\n4 4 3 3\n",
"output": "2 4 \n"
},
{
"input": "10\n3 7 1 2 6 5 4 10 9 8\n",
"output": "5 \n"
},
{
"input": "1\n1\n",
"output": "1 \n"
},
{
"input": "19\n2 3 2 2 2 2 2 2 2 2 19 3 2 2 2 2 2 2 19\n",
"output": "2 4 \n"
},
{
"input": "19\n2 2 2 2 2 2 2 2 19 19 2 2 2 2 2 2 2 2 2\n",
"output": "2 \n"
},
{
"input": "10\n3 10 3 3 3 10 10 3 3 3\n",
"output": "3 \n"
},
{
"input": "2\n2 2\n",
"output": "2 \n"
},
{
"input": "5\n4 3 2 1 5\n",
"output": "3 \n"
},
{
"input": "9\n4 7 8 4 1 9 5 6 2\n",
"output": "4 6 \n"
},
{
"input": "10\n4 2 3 6 8 9 5 2 7 1\n",
"output": "3 5 7 \n"
},
{
"input": "19\n2 19 2 2 2 2 19 2 2 3 2 2 2 2 2 2 2 2 2\n",
"output": "3 \n"
}
] |
code_contests
|
python
| 0 |
3b223bd5519ea2ade6b5c2a7eda55c2c
|
Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed n cans in a row on a table. Cans are numbered from left to right from 1 to n. Vasya has to knock down each can exactly once to finish the exercise. He is allowed to choose the order in which he will knock the cans down.
Vasya knows that the durability of the i-th can is a_i. It means that if Vasya has already knocked x cans down and is now about to start shooting the i-th one, he will need (a_i ⋅ x + 1) shots to knock it down. You can assume that if Vasya starts shooting the i-th can, he will be shooting it until he knocks it down.
Your task is to choose such an order of shooting so that the number of shots required to knock each of the n given cans down exactly once is minimum possible.
Input
The first line of the input contains one integer n (2 ≤ n ≤ 1 000) — the number of cans.
The second line of the input contains the sequence a_1, a_2, ..., a_n (1 ≤ a_i ≤ 1 000), where a_i is the durability of the i-th can.
Output
In the first line print the minimum number of shots required to knock each of the n given cans down exactly once.
In the second line print the sequence consisting of n distinct integers from 1 to n — the order of indices of cans that minimizes the number of shots required. If there are several answers, you can print any of them.
Examples
Input
3
20 10 20
Output
43
1 3 2
Input
4
10 10 10 10
Output
64
2 1 4 3
Input
6
5 4 5 4 4 5
Output
69
6 1 3 5 2 4
Input
2
1 4
Output
3
2 1
Note
In the first example Vasya can start shooting from the first can. He knocks it down with the first shot because he haven't knocked any other cans down before. After that he has to shoot the third can. To knock it down he shoots 20 ⋅ 1 + 1 = 21 times. After that only second can remains. To knock it down Vasya shoots 10 ⋅ 2 + 1 = 21 times. So the total number of shots is 1 + 21 + 21 = 43.
In the second example the order of shooting does not matter because all cans have the same durability.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n = map(int, input().split())
A = list(map(int, input().split()))
la = []
ind = 1
for a in A:
la.append((a, ind))
ind += 1
la.sort(key=lambda x: x[0], reverse=True)
# print(la)
x = 0
sm = 0
li = []
for tp in la:
a = tp[0]
sm += (a * x + 1)
x += 1
li.append(tp[1])
print(sm)
print(" ".join(str(i) for i in li))
|
python
|
code_algorithm
|
[
{
"input": "3\n20 10 20\n",
"output": "43\n1 3 2\n"
},
{
"input": "2\n1 4\n",
"output": "3\n2 1\n"
},
{
"input": "4\n10 10 10 10\n",
"output": "64\n1 2 3 4\n"
},
{
"input": "6\n5 4 5 4 4 5\n",
"output": "69\n1 3 6 2 4 5\n"
},
{
"input": "5\n13 16 20 18 11\n",
"output": "138\n3 4 2 1 5\n"
}
] |
code_contests
|
python
| 0.3 |
cfc4279b3b7b42fbb0c401a86e2a48ba
|
In the snake exhibition, there are n rooms (numbered 0 to n - 1) arranged in a circle, with a snake in each room. The rooms are connected by n conveyor belts, and the i-th conveyor belt connects the rooms i and (i+1) mod n. In the other words, rooms 0 and 1, 1 and 2, …, n-2 and n-1, n-1 and 0 are connected with conveyor belts.
The i-th conveyor belt is in one of three states:
* If it is clockwise, snakes can only go from room i to (i+1) mod n.
* If it is anticlockwise, snakes can only go from room (i+1) mod n to i.
* If it is off, snakes can travel in either direction.
<image>
Above is an example with 4 rooms, where belts 0 and 3 are off, 1 is clockwise, and 2 is anticlockwise.
Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there?
Input
Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000): the number of test cases. The description of the test cases follows.
The first line of each test case description contains a single integer n (2 ≤ n ≤ 300 000): the number of rooms.
The next line of each test case description contains a string s of length n, consisting of only '<', '>' and '-'.
* If s_{i} = '>', the i-th conveyor belt goes clockwise.
* If s_{i} = '<', the i-th conveyor belt goes anticlockwise.
* If s_{i} = '-', the i-th conveyor belt is off.
It is guaranteed that the sum of n among all test cases does not exceed 300 000.
Output
For each test case, output the number of returnable rooms.
Example
Input
4
4
-><-
5
>>>>>
3
<--
2
<>
Output
3
5
3
0
Note
In the first test case, all rooms are returnable except room 2. The snake in the room 2 is trapped and cannot exit. This test case corresponds to the picture from the problem statement.
In the second test case, all rooms are returnable by traveling on the series of clockwise belts.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
from sys import stdin
import sys
tt = int(stdin.readline())
for loop in range(tt):
n = int(stdin.readline())
s = stdin.readline()[:-1]
if ("<" not in s) or (">" not in s):
print (n)
continue
ans = 0
for i in range(n):
if s[(i-1)%n] == "-" or s[i] == "-":
ans += 1
print (ans)
|
python
|
code_algorithm
|
[
{
"input": "4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>\n",
"output": "4\n5\n3\n2\n"
},
{
"input": "1\n6\n->>-<-\n",
"output": "5\n"
},
{
"input": "1\n7\n->>-<<-\n",
"output": "5\n"
},
{
"input": "1\n15\n--->>>---<<<---\n",
"output": "11\n"
},
{
"input": "1\n5\n>-<<-\n",
"output": "4\n"
},
{
"input": "1\n4\n--<>\n",
"output": "3\n"
},
{
"input": "1\n6\n-<<<->\n",
"output": "4\n"
},
{
"input": "1\n12\n--->>>---<<<\n",
"output": "8\n"
},
{
"input": "1\n5\n<<->-\n",
"output": "4\n"
},
{
"input": "1\n7\n-->>-<-\n",
"output": "6\n"
},
{
"input": "1\n5\n<<->>\n",
"output": "2\n"
},
{
"input": "1\n8\n>>>-<---\n",
"output": "6\n"
},
{
"input": "1\n6\n<<->>-\n",
"output": "4\n"
},
{
"input": "4\n5\n->>-<\n4\n-><-\n5\n>>>>>\n3\n<--\n",
"output": "4\n3\n5\n3\n"
},
{
"input": "3\n3\n->>\n11\n><<>---><>-\n7\n-<<<<-<\n",
"output": "3\n6\n7\n"
},
{
"input": "4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>\n",
"output": "3\n5\n3\n0\n"
},
{
"input": "1\n5\n-<<->\n",
"output": "4\n"
},
{
"input": "1\n7\n-->>--<\n",
"output": "6\n"
},
{
"input": "1\n10\n->>>>-<<--\n",
"output": "6\n"
},
{
"input": "1\n6\n->-<<<\n",
"output": "4\n"
},
{
"input": "1\n6\n->-<<-\n",
"output": "5\n"
},
{
"input": "1\n7\n>--<<--\n",
"output": "6\n"
},
{
"input": "1\n15\n-->>>>---<<<---\n",
"output": "10\n"
},
{
"input": "1\n8\n>>--<<--\n",
"output": "6\n"
},
{
"input": "1\n8\n<<-->>--\n",
"output": "6\n"
},
{
"input": "1\n6\n>>>-<-\n",
"output": "4\n"
},
{
"input": "1\n7\n-<<->>-\n",
"output": "5\n"
},
{
"input": "1\n5\n->>-<\n",
"output": "4\n"
},
{
"input": "1\n5\n->-<<\n",
"output": "4\n"
},
{
"input": "1\n24\n>>>----->>>>----<<<<----\n",
"output": "16\n"
},
{
"input": "1\n8\n--<<-->>\n",
"output": "6\n"
},
{
"input": "1\n6\n-<->>-\n",
"output": "5\n"
},
{
"input": "1\n5\n<->>-\n",
"output": "4\n"
},
{
"input": "6\n5\n>-<<-\n5\n<->-<\n6\n>>-<<-\n6\n>-<<->\n7\n>>-<-<-\n7\n>>-<->-\n",
"output": "4\n4\n4\n4\n6\n6\n"
},
{
"input": "1\n11\n-->--<<<<--\n",
"output": "8\n"
},
{
"input": "1\n9\n->>>-<<<-\n",
"output": "5\n"
},
{
"input": "1\n6\n>-<->>\n",
"output": "4\n"
},
{
"input": "36\n2\n--\n2\n>-\n2\n<-\n2\n->\n2\n>>\n2\n<>\n2\n-<\n2\n><\n2\n<<\n3\n---\n3\n>--\n3\n<--\n3\n->-\n3\n>>-\n3\n<>-\n3\n-<-\n3\n><-\n3\n<<-\n3\n-->\n3\n>->\n3\n<->\n3\n->>\n3\n>>>\n3\n<>>\n3\n-<>\n3\n><>\n3\n<<>\n3\n--<\n3\n>-<\n3\n<-<\n3\n-><\n3\n>><\n3\n<><\n3\n-<<\n3\n><<\n3\n<<<\n",
"output": "2\n2\n2\n2\n2\n0\n2\n0\n2\n3\n3\n3\n3\n3\n2\n3\n2\n3\n3\n3\n2\n3\n3\n0\n2\n0\n0\n3\n2\n3\n2\n0\n0\n3\n0\n3\n"
},
{
"input": "1\n5\n>>-<-\n",
"output": "4\n"
},
{
"input": "1\n12\n->>>>--<<<<-\n",
"output": "6\n"
},
{
"input": "1\n8\n>>>-<<<-\n",
"output": "4\n"
},
{
"input": "1\n6\n>>-<<-\n",
"output": "4\n"
},
{
"input": "1\n12\n<<->>-<<->>-\n",
"output": "8\n"
}
] |
code_contests
|
python
| 0 |
c0d507c3e08cff7911ae41301530b6f7
|
Bob likes to draw camels: with a single hump, two humps, three humps, etc. He draws a camel by connecting points on a coordinate plane. Now he's drawing camels with t humps, representing them as polylines in the plane. Each polyline consists of n vertices with coordinates (x1, y1), (x2, y2), ..., (xn, yn). The first vertex has a coordinate x1 = 1, the second — x2 = 2, etc. Coordinates yi might be any, but should satisfy the following conditions:
* there should be t humps precisely, i.e. such indexes j (2 ≤ j ≤ n - 1), so that yj - 1 < yj > yj + 1,
* there should be precisely t - 1 such indexes j (2 ≤ j ≤ n - 1), so that yj - 1 > yj < yj + 1,
* no segment of a polyline should be parallel to the Ox-axis,
* all yi are integers between 1 and 4.
For a series of his drawings of camels with t humps Bob wants to buy a notebook, but he doesn't know how many pages he will need. Output the amount of different polylines that can be drawn to represent camels with t humps for a given number n.
Input
The first line contains a pair of integers n and t (3 ≤ n ≤ 20, 1 ≤ t ≤ 10).
Output
Output the required amount of camels with t humps.
Examples
Input
6 1
Output
6
Input
4 2
Output
0
Note
In the first sample test sequences of y-coordinates for six camels are: 123421, 123431, 123432, 124321, 134321 и 234321 (each digit corresponds to one value of yi).
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, t = map(int, input().split())
dp = [[[0] * 5 for _ in range(2 * t + 1)] for _ in range(n)]
dp[0][0] = [0] + [1] * 4
for i in range(n - 1):
for j in range(min(2 * t, i + 1)):
if (j & 1) == 0:
for k in range(1, 4):
for l in range(k + 1, 5):
# //
dp[i + 1][j][l] += dp[i][j][k]
# /\
dp[i + 1][j + 1][l] += dp[i][j][k]
else:
for k in range(4, 1, -1):
for l in range(k - 1, 0, -1):
# \\
dp[i + 1][j][l] += dp[i][j][k]
# \/
dp[i + 1][j + 1][l] += dp[i][j][k]
print(sum(dp[-1][2 * t]))
|
python
|
code_algorithm
|
[
{
"input": "6 1\n",
"output": "6\n"
},
{
"input": "4 2\n",
"output": "0\n"
},
{
"input": "19 10\n",
"output": "0\n"
},
{
"input": "19 4\n",
"output": "32632\n"
},
{
"input": "20 9\n",
"output": "90700276\n"
},
{
"input": "19 7\n",
"output": "197939352\n"
},
{
"input": "4 9\n",
"output": "0\n"
},
{
"input": "19 9\n",
"output": "5846414\n"
},
{
"input": "4 1\n",
"output": "22\n"
},
{
"input": "20 1\n",
"output": "0\n"
},
{
"input": "19 1\n",
"output": "0\n"
},
{
"input": "20 10\n",
"output": "0\n"
},
{
"input": "3 2\n",
"output": "0\n"
},
{
"input": "5 5\n",
"output": "0\n"
},
{
"input": "5 10\n",
"output": "0\n"
},
{
"input": "19 6\n",
"output": "69183464\n"
},
{
"input": "6 10\n",
"output": "0\n"
},
{
"input": "3 3\n",
"output": "0\n"
},
{
"input": "4 3\n",
"output": "0\n"
},
{
"input": "5 3\n",
"output": "0\n"
},
{
"input": "20 4\n",
"output": "12628\n"
},
{
"input": "20 8\n",
"output": "503245466\n"
},
{
"input": "19 2\n",
"output": "0\n"
},
{
"input": "6 2\n",
"output": "232\n"
},
{
"input": "20 5\n",
"output": "3715462\n"
},
{
"input": "6 3\n",
"output": "0\n"
},
{
"input": "3 10\n",
"output": "0\n"
},
{
"input": "19 8\n",
"output": "109824208\n"
},
{
"input": "6 4\n",
"output": "0\n"
},
{
"input": "5 9\n",
"output": "0\n"
},
{
"input": "20 7\n",
"output": "468541040\n"
},
{
"input": "20 2\n",
"output": "0\n"
},
{
"input": "5 1\n",
"output": "16\n"
},
{
"input": "20 6\n",
"output": "96046590\n"
},
{
"input": "3 1\n",
"output": "14\n"
},
{
"input": "5 2\n",
"output": "70\n"
},
{
"input": "19 5\n",
"output": "4594423\n"
},
{
"input": "19 3\n",
"output": "1\n"
},
{
"input": "20 3\n",
"output": "0\n"
}
] |
code_contests
|
python
| 0 |
7fe7d3f69872521814978696dcb00389
|
As Sherlock Holmes was investigating another crime, he found a certain number of clues. Also, he has already found direct links between some of those clues. The direct links between the clues are mutual. That is, the direct link between clues A and B and the direct link between clues B and A is the same thing. No more than one direct link can exist between two clues.
Of course Sherlock is able to find direct links between all clues. But it will take too much time and the criminals can use this extra time to hide. To solve the crime, Sherlock needs each clue to be linked to all other clues (maybe not directly, via some other clues). Clues A and B are considered linked either if there is a direct link between them or if there is a direct link between A and some other clue C which is linked to B.
Sherlock Holmes counted the minimum number of additional direct links that he needs to find to solve the crime. As it turns out, it equals T.
Please count the number of different ways to find exactly T direct links between the clues so that the crime is solved in the end. Two ways to find direct links are considered different if there exist two clues which have a direct link in one way and do not have a direct link in the other way.
As the number of different ways can turn out rather big, print it modulo k.
Input
The first line contains three space-separated integers n, m, k (1 ≤ n ≤ 105, 0 ≤ m ≤ 105, 1 ≤ k ≤ 109) — the number of clues, the number of direct clue links that Holmes has already found and the divisor for the modulo operation.
Each of next m lines contains two integers a and b (1 ≤ a, b ≤ n, a ≠ b), that represent a direct link between clues. It is guaranteed that any two clues are linked by no more than one direct link. Note that the direct links between the clues are mutual.
Output
Print the single number — the answer to the problem modulo k.
Examples
Input
2 0 1000000000
Output
1
Input
3 0 100
Output
3
Input
4 1 1000000000
1 4
Output
8
Note
The first sample only has two clues and Sherlock hasn't found any direct link between them yet. The only way to solve the crime is to find the link.
The second sample has three clues and Sherlock hasn't found any direct links between them. He has to find two of three possible direct links between clues to solve the crime — there are 3 ways to do it.
The third sample has four clues and the detective has already found one direct link between the first and the fourth clue. There are 8 ways to find two remaining clues to solve the crime.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
def dfs(node, my_cc):
vis[node] = True
acc[my_cc]+=1
for i in adj[node]:
if not vis[i]:
dfs(i, my_cc)
def ittDfs(node):
queue = [node]
curr = 0
while(queue):
node = queue.pop()
if vis[node]:
continue
vis[node] = True
acc[cc] += 1
for i in adj[node]:
if not vis[i]:
queue.append(i)
def bfs(node):
vis[node] = True
cola = [node]
cur = 0
while (cur < len(cola)):
x = cola[cur]
acc[cc] += 1
cur += 1;
for i in adj[x]:
if not vis[i]:
vis[i] = True
cola.append(i)
if __name__ == '__main__':
_input = input().split()
n = int(_input[0])
m = int(_input[1])
k = int(_input[2])
adj = []
vis = []
acc = []
cc = 0
for i in range(n):
vis.append(False)
adj.append([])
acc.append(0)
for i in range(m):
_in2 = input().split()
v = int(_in2[0]) - 1
w = int(_in2[1]) - 1
adj[v].append(w)
adj[w].append(v)
for i in range(n):
if not vis[i]:
# dfs(i, cc)
ittDfs(i)
cc+=1
if cc == 1:
print(1 % k)
exit()
ans = 1
for i in range(cc - 2):
ans = ans * n
ans = ans % k
for i in range(cc):
ans = ans * acc[i]
ans = ans % k
print(ans)
|
python
|
code_algorithm
|
[
{
"input": "4 1 1000000000\n1 4\n",
"output": "8\n"
},
{
"input": "3 0 100\n",
"output": "3\n"
},
{
"input": "2 0 1000000000\n",
"output": "1\n"
},
{
"input": "100000 0 1\n",
"output": "0\n"
},
{
"input": "2 1 100000\n1 2\n",
"output": "1\n"
},
{
"input": "2 1 819865995\n2 1\n",
"output": "1\n"
},
{
"input": "83 33 367711297\n14 74\n26 22\n55 19\n8 70\n6 42\n53 49\n54 56\n52 17\n62 44\n78 61\n76 4\n78 30\n51 2\n31 42\n33 67\n45 41\n64 62\n15 25\n33 35\n37 20\n38 65\n65 83\n61 14\n20 67\n62 47\n7 34\n78 41\n38 83\n26 69\n54 58\n11 62\n30 55\n15 74\n",
"output": "131377693\n"
},
{
"input": "8 4 17\n1 2\n2 3\n3 4\n4 1\n",
"output": "8\n"
},
{
"input": "10 45 220178113\n9 1\n8 1\n5 8\n1 5\n7 8\n6 7\n7 9\n6 2\n3 2\n1 4\n8 3\n8 9\n3 6\n4 5\n5 3\n10 4\n3 9\n9 6\n5 9\n2 9\n10 7\n1 10\n9 4\n3 10\n2 5\n7 1\n6 10\n6 5\n8 6\n8 4\n8 10\n1 6\n4 2\n9 10\n2 10\n7 3\n6 4\n7 5\n1 2\n4 3\n10 5\n4 7\n3 1\n7 2\n8 2\n",
"output": "1\n"
},
{
"input": "9 11 498920381\n2 8\n5 4\n1 8\n8 3\n4 9\n3 6\n8 9\n1 7\n5 1\n5 6\n9 6\n",
"output": "1\n"
},
{
"input": "2 1 1000\n1 2\n",
"output": "1\n"
},
{
"input": "30 18 918975816\n30 18\n23 1\n21 14\n14 8\n18 9\n23 29\n3 23\n29 19\n18 4\n27 19\n30 2\n9 10\n9 28\n16 15\n10 6\n18 12\n23 9\n19 14\n",
"output": "782410104\n"
},
{
"input": "3 2 11\n1 2\n2 3\n",
"output": "1\n"
},
{
"input": "2 0 753780649\n",
"output": "1\n"
},
{
"input": "3 3 975373207\n1 2\n1 3\n3 2\n",
"output": "1\n"
},
{
"input": "1 0 997185958\n",
"output": "1\n"
},
{
"input": "1 0 773734495\n",
"output": "1\n"
},
{
"input": "9 35 480175322\n6 3\n8 6\n7 5\n7 9\n3 4\n2 8\n5 3\n4 5\n4 6\n7 1\n7 6\n2 5\n8 3\n6 9\n8 4\n8 5\n6 1\n8 1\n3 2\n5 1\n8 9\n3 1\n8 7\n5 6\n5 9\n4 9\n7 4\n2 7\n3 9\n2 4\n7 3\n9 1\n2 9\n1 4\n1 2\n",
"output": "1\n"
},
{
"input": "1 0 10000\n",
"output": "1\n"
},
{
"input": "5 7 729985252\n2 3\n3 1\n2 5\n1 5\n1 2\n1 4\n4 3\n",
"output": "1\n"
},
{
"input": "57 28 776442742\n31 10\n25 28\n51 45\n14 40\n21 52\n53 51\n52 53\n4 6\n51 35\n53 15\n17 16\n40 44\n37 51\n33 43\n55 40\n42 16\n30 8\n19 45\n7 27\n31 8\n49 8\n43 44\n45 3\n16 22\n32 36\n52 36\n5 26\n2 23\n",
"output": "135540294\n"
},
{
"input": "10 5 1000000000\n1 2\n4 3\n5 6\n8 7\n10 9\n",
"output": "32000\n"
},
{
"input": "24 68 862907549\n6 9\n16 22\n11 23\n12 17\n18 2\n15 5\n5 22\n16 4\n21 9\n7 11\n19 16\n9 13\n21 20\n5 24\n7 12\n17 1\n24 21\n23 7\n16 17\n16 18\n10 13\n18 7\n8 21\n13 5\n10 18\n4 11\n21 6\n15 13\n2 1\n20 16\n11 16\n22 19\n2 4\n21 1\n6 18\n24 12\n21 19\n6 14\n22 24\n11 20\n2 19\n1 11\n24 18\n14 8\n10 24\n5 3\n11 3\n17 4\n4 20\n2 10\n12 11\n24 7\n23 16\n2 3\n19 24\n22 1\n22 4\n4 6\n3 4\n11 13\n6 5\n18 23\n4 23\n22 13\n20 5\n2 5\n2 11\n9 5\n",
"output": "1\n"
},
{
"input": "10 0 766953983\n",
"output": "100000000\n"
},
{
"input": "67 2 818380264\n4 52\n15 44\n",
"output": "517849052\n"
},
{
"input": "3 2 21502109\n3 2\n1 2\n",
"output": "1\n"
},
{
"input": "47 51 283106191\n18 14\n30 26\n24 2\n18 41\n35 31\n16 24\n29 39\n6 12\n17 21\n7 19\n36 16\n27 39\n28 34\n22 35\n28 43\n40 5\n2 26\n18 16\n27 13\n21 6\n19 5\n35 30\n13 31\n7 10\n25 7\n44 42\n45 1\n35 47\n11 28\n47 46\n18 15\n27 16\n24 41\n10 8\n25 41\n4 40\n5 11\n24 6\n10 17\n41 38\n47 28\n8 29\n25 24\n35 37\n44 17\n24 47\n8 32\n33 11\n26 28\n23 9\n5 9\n",
"output": "189974\n"
},
{
"input": "15 10 1\n1 2\n4 5\n6 3\n11 8\n8 5\n5 9\n9 1\n11 12\n12 1\n2 8\n",
"output": "0\n"
},
{
"input": "588 32 634894588\n535 26\n562 406\n70 368\n357 513\n108 361\n515 5\n159 56\n522 81\n169 229\n312 252\n492 43\n476 405\n524 555\n537 169\n142 149\n586 112\n7 159\n76 370\n295 376\n33 455\n278 225\n377 88\n526 308\n517 303\n300 576\n230 493\n588 525\n177 312\n356 215\n515 34\n196 236\n323 9\n",
"output": "478655040\n"
},
{
"input": "2 1 855341703\n2 1\n",
"output": "1\n"
},
{
"input": "100000 0 1000000000\n",
"output": "0\n"
},
{
"input": "2 1 719418546\n1 2\n",
"output": "1\n"
},
{
"input": "10 7 587143295\n1 10\n7 1\n1 8\n7 10\n8 10\n4 8\n6 8\n",
"output": "6000\n"
},
{
"input": "10 30 407595309\n3 6\n6 10\n6 7\n7 10\n7 8\n3 10\n3 4\n1 4\n9 10\n8 4\n3 7\n5 1\n2 4\n6 2\n8 9\n10 5\n7 5\n10 4\n5 8\n8 2\n10 2\n1 6\n4 7\n2 3\n5 6\n8 10\n3 5\n1 8\n9 7\n1 9\n",
"output": "1\n"
},
{
"input": "5 10 93196990\n1 5\n1 4\n4 2\n1 3\n3 4\n1 2\n5 2\n5 4\n5 3\n2 3\n",
"output": "1\n"
},
{
"input": "1 0 21080115\n",
"output": "1\n"
},
{
"input": "7 7 302838679\n5 3\n4 1\n5 4\n6 5\n1 6\n3 2\n6 4\n",
"output": "6\n"
},
{
"input": "8 8 999999937\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n8 7\n",
"output": "1\n"
},
{
"input": "2 1 100\n1 2\n",
"output": "1\n"
},
{
"input": "1 0 1\n",
"output": "0\n"
},
{
"input": "1 0 10\n",
"output": "1\n"
},
{
"input": "6 4 100000\n1 4\n4 6\n6 1\n2 5\n",
"output": "36\n"
},
{
"input": "99 12 832839308\n66 23\n36 5\n16 57\n70 62\n94 96\n63 33\n99 23\n63 10\n6 85\n73 23\n69 46\n72 95\n",
"output": "71450536\n"
},
{
"input": "3 2 42\n1 2\n2 3\n",
"output": "1\n"
},
{
"input": "5 4 100000\n1 2\n2 3\n3 4\n4 5\n",
"output": "1\n"
},
{
"input": "3 3 100\n1 2\n2 3\n3 1\n",
"output": "1\n"
},
{
"input": "6 1 310732484\n4 2\n",
"output": "432\n"
},
{
"input": "9 33 321578376\n9 5\n6 3\n8 4\n4 1\n3 5\n2 6\n8 2\n7 6\n7 9\n8 6\n4 5\n1 6\n1 2\n5 6\n9 4\n7 8\n3 9\n9 6\n4 7\n7 2\n1 8\n4 6\n8 3\n3 7\n8 9\n5 7\n3 4\n7 1\n9 2\n5 1\n2 5\n9 1\n3 2\n",
"output": "1\n"
},
{
"input": "10 0 123456789\n",
"output": "100000000\n"
},
{
"input": "9 6 342597160\n1 2\n3 4\n4 5\n6 7\n7 8\n8 9\n",
"output": "216\n"
},
{
"input": "10 36 279447540\n10 7\n10 8\n1 8\n1 5\n4 5\n9 5\n3 9\n7 3\n10 4\n8 9\n2 10\n6 2\n4 8\n10 3\n1 4\n10 1\n10 6\n8 3\n3 6\n9 7\n10 5\n6 9\n3 1\n8 6\n4 9\n5 3\n9 10\n7 2\n2 4\n7 4\n5 6\n5 8\n7 5\n5 2\n6 7\n1 9\n",
"output": "1\n"
},
{
"input": "30 70 288262020\n27 18\n5 19\n23 17\n16 17\n29 17\n1 22\n23 5\n10 13\n22 26\n14 3\n8 3\n29 9\n9 1\n3 9\n16 4\n9 22\n10 22\n20 1\n3 7\n23 19\n26 8\n24 1\n5 7\n28 29\n20 11\n16 12\n6 9\n24 29\n30 4\n5 26\n18 21\n5 21\n30 6\n12 13\n16 23\n28 14\n30 1\n7 27\n7 19\n27 17\n5 30\n30 27\n28 30\n12 28\n27 9\n30 26\n20 18\n21 16\n8 30\n4 26\n13 22\n2 14\n12 30\n4 2\n6 12\n29 25\n19 29\n14 15\n3 23\n10 28\n7 1\n21 10\n4 12\n1 14\n7 21\n21 8\n17 26\n7 6\n26 29\n9 8\n",
"output": "1\n"
},
{
"input": "86 23 608266393\n62 78\n44 84\n42 37\n20 24\n40 36\n41 76\n14 38\n80 72\n39 52\n31 58\n71 17\n81 6\n32 65\n11 69\n43 86\n85 59\n28 77\n78 64\n15 19\n36 39\n53 49\n48 75\n33 85\n",
"output": "235915236\n"
}
] |
code_contests
|
python
| 0 |
e00bad78ec8adf5678d25c0908df59c2
|
Fibonacci strings are defined as follows:
* f1 = «a»
* f2 = «b»
* fn = fn - 1 fn - 2, n > 2
Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba".
You are given a Fibonacci string and m strings si. For each string si, find the number of times it occurs in the given Fibonacci string as a substring.
Input
The first line contains two space-separated integers k and m — the number of a Fibonacci string and the number of queries, correspondingly.
Next m lines contain strings si that correspond to the queries. It is guaranteed that strings si aren't empty and consist only of characters "a" and "b".
The input limitations for getting 30 points are:
* 1 ≤ k ≤ 3000
* 1 ≤ m ≤ 3000
* The total length of strings si doesn't exceed 3000
The input limitations for getting 100 points are:
* 1 ≤ k ≤ 1018
* 1 ≤ m ≤ 104
* The total length of strings si doesn't exceed 105
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
For each string si print the number of times it occurs in the given Fibonacci string as a substring. Since the numbers can be large enough, print them modulo 1000000007 (109 + 7). Print the answers for the strings in the order in which they are given in the input.
Examples
Input
6 5
a
b
ab
ba
aba
Output
3
5
3
3
1
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
F = ['', 'a', 'b', 'ba', 'bab', 'babba', 'babbabab', 'babbababbabba', 'babbababbabbababbabab', 'babbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbabab', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabab', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabab', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabab', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabab', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabab']
d = 1000000007
def sqr(t):
return [[sum(t[i][k] * t[k][j] for k in range(4)) % d for j in range(4)] for i in range(4)]
def mul(a, b):
return [[sum(a[i][k] * b[k][j] for k in range(4)) % d for j in range(4)] for i in range(4)]
def fib(k):
s, p = format(k, 'b')[:: -1], [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
t = [[[0, 1, 0, 0], [1, 1, 1, 0], [0, 0, 0, 1], [0, 0, 1, 0]]] + [0] * (len(s) - 1)
for i in range(1, len(s)):
t[i] = sqr(t[i - 1])
for i, k in enumerate(s):
if k == '1': p = mul(p, t[i])
return p
def cnt(t, p):
s, i = 0, p.find(t) + 1
while i > 0:
i = p.find(t, i) + 1
s += 1
return s
def f(t, p, k):
l = len(t) - 1
if l: x, y = cnt(t, F[k - 1][- l: ] + F[k][:l ]), cnt(t, F[k][- l: ] + F[k + 1][:l ])
else: x, y = 0, 0
a, b = cnt(t, F[k - 1]), cnt(t, F[k])
return (p[0] * a + p[1] * b + p[2] * y + p[3] * x) % d
k, m = map(int, input().split())
if k > 15:
a, b = fib(k - 7)[0], fib(k - 18)[0]
for i in range(m):
t = input()
if len(t) < len(F[7]): print(f(t, a, 8))
else: print(f(t, b, 19))
else:
p = F[k]
for i in range(m):
print(cnt(input(), p))
|
python
|
code_algorithm
|
[
{
"input": "6 5\na\nb\nab\nba\naba\n",
"output": "3\n5\n3\n3\n1\n"
},
{
"input": "50 100\nbb\naa\nb\nbaa\nbbba\naa\nba\na\nabba\nbaa\naa\naab\nab\nbabb\naabb\nbaa\nbaaa\nbaa\naab\nbba\nbb\naba\naaba\nbab\naaba\naa\naaaa\nbabb\nbbb\naaba\naaa\nab\nbab\nb\nb\naa\naaab\naa\nbba\nbaa\nbabb\nbaba\nba\naaba\nbba\nba\nab\nabb\nb\nba\nbbb\nba\naaa\nbbb\nbaa\nbb\na\naaa\naaba\nab\nbba\nba\nb\nbbb\naaa\na\na\nb\nb\naba\nbb\nba\na\nb\nbaa\nb\naaaa\na\naaab\nbaba\nba\nbb\nbaba\nab\nbaaa\nbbbb\na\naabb\nab\nb\nb\naaa\nb\nb\nabab\nabb\nb\nb\nbb\nb\n",
"output": "971215058\n0\n778742000\n0\n0\n0\n807526948\n807526948\n971215058\n0\n0\n0\n807526948\n971215058\n0\n0\n0\n0\n0\n971215058\n971215058\n836311896\n0\n807526948\n0\n0\n0\n971215058\n0\n0\n0\n807526948\n807526948\n778742000\n778742000\n0\n0\n0\n971215058\n0\n971215058\n836311896\n807526948\n0\n971215058\n807526948\n807526948\n971215058\n778742000\n807526948\n0\n807526948\n0\n0\n0\n971215058\n807526948\n0\n0\n807526948\n971215058\n807526948\n778742000\n0\n0\n807526948\n807526948\n778742000\n778742000\n836311896\n971215058\n807526948\n807526948\n778742000\n0\n778742000\n0\n807526948\n0\n836311896\n807526948\n971215058\n836311896\n807526948\n0\n0\n807526948\n0\n807526948\n778742000\n778742000\n0\n778742000\n778742000\n836311896\n971215058\n778742000\n778742000\n971215058\n778742000\n"
},
{
"input": "15 100\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\nb\na\n",
"output": "377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n377\n233\n"
},
{
"input": "15 100\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb\nbab\naab\n",
"output": "0\n144\n232\n0\n144\n88\n0\n0\n0\n144\n232\n0\n144\n88\n0\n0\n0\n144\n232\n0\n144\n88\n0\n0\n0\n144\n232\n0\n144\n88\n0\n0\n0\n144\n232\n0\n144\n88\n0\n0\n0\n144\n232\n0\n144\n88\n0\n0\n0\n144\n232\n0\n144\n88\n0\n0\n0\n144\n232\n0\n144\n88\n0\n0\n0\n144\n232\n0\n144\n88\n0\n0\n0\n144\n232\n0\n144\n88\n0\n0\n0\n144\n232\n0\n144\n88\n0\n0\n0\n144\n232\n0\n144\n88\n0\n0\n0\n144\n232\n0\n"
},
{
"input": "10 10\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\n",
"output": "12\n21\n21\n0\n12\n21\n21\n0\n12\n21\n"
},
{
"input": "2 14\na\nb\naa\nab\nba\nbb\naaa\naab\naba\nabb\nbaa\nbab\nbba\nbbb\n",
"output": "0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n"
},
{
"input": "3 10\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb\n",
"output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n"
},
{
"input": "50 100\nb\naab\nab\naaa\na\naab\naaa\nbb\na\na\nb\naab\nbbb\naa\nbbb\nb\nab\nab\nbbb\nb\nbaa\na\nbab\nbbb\na\naba\nab\na\nba\nb\nbba\naba\nba\nbba\nb\nb\nb\nb\nab\na\nabb\nab\nbb\nbba\nb\nbbb\nbb\nb\naba\naab\nba\nbb\na\na\nbb\nba\nbaa\nba\nba\na\nb\nbb\nb\nbaa\nbab\nbba\nb\nbb\nbbb\nb\naba\nbba\nbba\naaa\nab\na\nbbb\nab\nb\nba\nbab\nb\naab\nbb\naba\nb\na\naa\nbaa\nbbb\naa\naba\nb\nbb\nba\nb\nb\naaa\nab\nba\n",
"output": "778742000\n0\n807526948\n0\n807526948\n0\n0\n971215058\n807526948\n807526948\n778742000\n0\n0\n0\n0\n778742000\n807526948\n807526948\n0\n778742000\n0\n807526948\n807526948\n0\n807526948\n836311896\n807526948\n807526948\n807526948\n778742000\n971215058\n836311896\n807526948\n971215058\n778742000\n778742000\n778742000\n778742000\n807526948\n807526948\n971215058\n807526948\n971215058\n971215058\n778742000\n0\n971215058\n778742000\n836311896\n0\n807526948\n971215058\n807526948\n807526948\n971215058\n807526948\n0\n807526948\n807526948\n807526948\n778742000\n971215058\n778742000\n0\n807526948\n971215058\n778742000\n971215058\n0\n778742000\n836311896\n971215058\n971215058\n0\n807526948\n807526948\n0\n807526948\n778742000\n807526948\n807526948\n778742000\n0\n971215058\n836311896\n778742000\n807526948\n0\n0\n0\n0\n836311896\n778742000\n971215058\n807526948\n778742000\n778742000\n0\n807526948\n807526948\n"
},
{
"input": "4 14\na\nb\naa\nab\nba\nbb\naaa\naab\naba\nabb\nbaa\nbab\nbba\nbbb\n",
"output": "1\n2\n0\n1\n1\n0\n0\n0\n0\n0\n0\n1\n0\n0\n"
},
{
"input": "2 10\nb\na\nb\na\nb\na\nb\na\nb\na\n",
"output": "1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n"
},
{
"input": "10 10\nbbb\nabb\nbab\naab\nbba\naba\nbaa\naaa\nbbb\nabb\n",
"output": "0\n12\n21\n0\n12\n8\n0\n0\n0\n12\n"
},
{
"input": "50 100\nb\naa\na\na\na\nb\na\nb\nbb\na\naa\naa\naa\nba\naa\na\na\naa\na\na\naa\nb\nbb\naa\naa\nbb\nb\nbb\na\naa\naa\naa\na\na\nb\nb\na\naa\nb\naa\nab\nb\nb\na\naa\nbb\nb\nb\na\nb\na\na\nb\na\nbb\nb\nab\nbb\na\naa\naa\nb\nb\na\nbb\nba\naa\nba\nbb\nba\nbb\na\nb\na\nba\na\nab\na\nbb\nab\na\nab\nbb\na\na\nb\na\nba\na\nbb\nb\nab\nab\naa\na\nab\nab\nbb\nab\nab\n",
"output": "778742000\n0\n807526948\n807526948\n807526948\n778742000\n807526948\n778742000\n971215058\n807526948\n0\n0\n0\n807526948\n0\n807526948\n807526948\n0\n807526948\n807526948\n0\n778742000\n971215058\n0\n0\n971215058\n778742000\n971215058\n807526948\n0\n0\n0\n807526948\n807526948\n778742000\n778742000\n807526948\n0\n778742000\n0\n807526948\n778742000\n778742000\n807526948\n0\n971215058\n778742000\n778742000\n807526948\n778742000\n807526948\n807526948\n778742000\n807526948\n971215058\n778742000\n807526948\n971215058\n807526948\n0\n0\n778742000\n778742000\n807526948\n971215058\n807526948\n0\n807526948\n971215058\n807526948\n971215058\n807526948\n778742000\n807526948\n807526948\n807526948\n807526948\n807526948\n971215058\n807526948\n807526948\n807526948\n971215058\n807526948\n807526948\n778742000\n807526948\n807526948\n807526948\n971215058\n778742000\n807526948\n807526948\n0\n807526948\n807526948\n807526948\n971215058\n807526948\n807526948\n"
},
{
"input": "15 100\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\nbb\nab\nba\naa\n",
"output": "144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n144\n232\n233\n0\n"
},
{
"input": "3 14\na\nb\naa\nab\nba\nbb\naaa\naab\naba\nabb\nbaa\nbab\nbba\nbbb\n",
"output": "1\n1\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n"
},
{
"input": "1 14\na\nb\naa\nab\nba\nbb\naaa\naab\naba\nabb\nbaa\nbab\nbba\nbbb\n",
"output": "1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n"
},
{
"input": "5 14\na\nb\naa\nab\nba\nbb\naaa\naab\naba\nabb\nbaa\nbab\nbba\nbbb\n",
"output": "2\n3\n0\n1\n2\n1\n0\n0\n0\n1\n0\n1\n1\n0\n"
},
{
"input": "50 100\na\na\nb\na\na\nb\nb\nb\na\na\nb\nb\na\na\na\na\nb\nb\na\nb\nb\nb\na\na\na\na\na\na\nb\nb\na\nb\na\nb\na\nb\na\nb\nb\nb\na\na\nb\na\na\na\nb\na\nb\na\na\na\nb\na\nb\na\na\nb\na\na\nb\na\na\na\na\nb\na\nb\na\nb\nb\na\nb\nb\nb\na\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\na\na\na\nb\nb\nb\nb\na\na\na\nb\nb\nb\na\n",
"output": "807526948\n807526948\n778742000\n807526948\n807526948\n778742000\n778742000\n778742000\n807526948\n807526948\n778742000\n778742000\n807526948\n807526948\n807526948\n807526948\n778742000\n778742000\n807526948\n778742000\n778742000\n778742000\n807526948\n807526948\n807526948\n807526948\n807526948\n807526948\n778742000\n778742000\n807526948\n778742000\n807526948\n778742000\n807526948\n778742000\n807526948\n778742000\n778742000\n778742000\n807526948\n807526948\n778742000\n807526948\n807526948\n807526948\n778742000\n807526948\n778742000\n807526948\n807526948\n807526948\n778742000\n807526948\n778742000\n807526948\n807526948\n778742000\n807526948\n807526948\n778742000\n807526948\n807526948\n807526948\n807526948\n778742000\n807526948\n778742000\n807526948\n778742000\n778742000\n807526948\n778742000\n778742000\n778742000\n807526948\n778742000\n778742000\n778742000\n778742000\n778742000\n778742000\n778742000\n778742000\n778742000\n778742000\n807526948\n807526948\n807526948\n778742000\n778742000\n778742000\n778742000\n807526948\n807526948\n807526948\n778742000\n778742000\n778742000\n807526948\n"
},
{
"input": "1 10\nb\na\nb\na\nb\na\nb\na\nb\na\n",
"output": "0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n"
}
] |
code_contests
|
python
| 0 |
7af590908b9cbdb72cb0a94bdf32e733
|
The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.
One needs exactly di years to rise from rank i to rank i + 1. Reaching a certain rank i having not reached all the previous i - 1 ranks is impossible.
Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream.
Input
The first input line contains an integer n (2 ≤ n ≤ 100). The second line contains n - 1 integers di (1 ≤ di ≤ 100). The third input line contains two integers a and b (1 ≤ a < b ≤ n). The numbers on the lines are space-separated.
Output
Print the single number which is the number of years that Vasya needs to rise from rank a to rank b.
Examples
Input
3
5 6
1 2
Output
5
Input
3
5 6
1 3
Output
11
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
#!/usr/bin/python3
def readln(): return tuple(map(int, input().split()))
n, = readln()
d = readln()
a, b = readln()
print(sum(d[a - 1:b - 1]))
|
python
|
code_algorithm
|
[
{
"input": "3\n5 6\n1 2\n",
"output": "5\n"
},
{
"input": "3\n5 6\n1 3\n",
"output": "11\n"
},
{
"input": "80\n65 15 43 6 43 98 100 16 69 98 4 54 25 40 2 35 12 23 38 29 10 89 30 6 4 8 7 96 64 43 11 49 89 38 20 59 54 85 46 16 16 89 60 54 28 37 32 34 67 9 78 30 50 87 58 53 99 48 77 3 5 6 19 99 16 20 31 10 80 76 82 56 56 83 72 81 84 60 28\n18 24\n",
"output": "219\n"
},
{
"input": "51\n85 38 22 38 42 36 55 24 36 80 49 15 66 91 88 61 46 82 1 61 89 92 6 56 28 8 46 80 56 90 91 38 38 17 69 64 57 68 13 44 45 38 8 72 61 39 87 2 73 88\n15 27\n",
"output": "618\n"
},
{
"input": "3\n85 78\n1 3\n",
"output": "163\n"
},
{
"input": "30\n35 69 50 44 19 56 86 56 98 24 21 2 61 24 85 30 2 22 57 35 59 84 12 77 92 53 50 92 9\n1 16\n",
"output": "730\n"
},
{
"input": "96\n1 1 2 3 3 5 8 9 9 10 10 10 11 11 11 11 11 12 13 13 13 14 15 15 16 16 17 17 17 17 18 18 20 20 20 21 21 21 23 24 24 25 25 26 27 27 27 27 29 29 29 30 30 30 32 32 32 32 32 32 33 33 34 34 34 35 35 35 36 36 37 37 37 38 39 40 41 41 41 41 42 42 43 43 45 45 45 46 46 47 47 49 50 52 52\n76 96\n",
"output": "898\n"
},
{
"input": "100\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11 12 12 12 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17\n39 52\n",
"output": "82\n"
},
{
"input": "70\n1 2 3 3 4 5 5 7 7 7 8 8 8 8 9 9 10 12 12 12 12 13 16 16 16 16 16 16 17 17 18 18 20 20 21 23 24 25 25 26 29 29 29 29 31 32 32 34 35 36 36 37 37 38 39 39 40 40 40 40 41 41 42 43 44 44 44 45 45\n62 65\n",
"output": "126\n"
},
{
"input": "90\n61 35 100 99 67 87 42 90 44 4 81 65 29 63 66 56 53 22 55 87 39 30 34 42 27 80 29 97 85 28 81 22 50 22 24 75 67 86 78 79 94 35 13 97 48 76 68 66 94 13 82 1 22 85 5 36 86 73 65 97 43 56 35 26 87 25 74 47 81 67 73 75 99 75 53 38 70 21 66 78 38 17 57 40 93 57 68 55 1\n12 44\n",
"output": "1713\n"
},
{
"input": "60\n24 28 25 21 43 71 64 73 71 90 51 83 69 43 75 43 78 72 56 61 99 7 23 86 9 16 16 94 23 74 18 56 20 72 13 31 75 34 35 86 61 49 4 72 84 7 65 70 66 52 21 38 6 43 69 40 73 46 5\n28 60\n",
"output": "1502\n"
},
{
"input": "2\n55\n1 2\n",
"output": "55\n"
},
{
"input": "35\n2 34 47 15 27 61 6 88 67 20 53 65 29 68 77 5 78 86 44 98 32 81 91 79 54 84 95 23 65 97 22 33 42 87\n8 35\n",
"output": "1663\n"
},
{
"input": "8\n82 14 24 5 91 49 94\n3 8\n",
"output": "263\n"
},
{
"input": "98\n2 3 4 4 5 7 8 10 10 10 11 11 12 12 12 12 13 14 15 15 16 16 18 19 19 20 21 21 21 21 22 23 24 25 26 26 27 27 27 27 29 29 30 30 31 31 37 40 40 40 41 41 41 42 43 44 44 44 46 46 47 49 49 50 50 50 51 53 55 55 56 56 56 56 56 57 57 58 59 60 60 60 62 62 63 64 64 64 65 66 66 67 68 70 70 71 71\n8 90\n",
"output": "3016\n"
},
{
"input": "95\n37 74 53 96 65 84 65 72 95 45 6 77 91 35 58 50 51 51 97 30 51 20 79 81 92 10 89 34 40 76 71 54 26 34 73 72 72 28 53 19 95 64 97 10 44 15 12 38 5 63 96 95 86 8 36 96 45 53 81 5 18 18 47 97 65 9 33 53 41 86 37 53 5 40 15 76 83 45 33 18 26 5 19 90 46 40 100 42 10 90 13 81 40 53\n6 15\n",
"output": "570\n"
},
{
"input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3\n5 17\n",
"output": "23\n"
},
{
"input": "4\n63 4 49\n2 3\n",
"output": "4\n"
},
{
"input": "60\n1 2 4 4 4 6 6 8 9 10 10 13 14 18 20 20 21 22 23 23 26 29 30 32 33 34 35 38 40 42 44 44 46 48 52 54 56 56 60 60 66 67 68 68 69 73 73 74 80 80 81 81 82 84 86 86 87 89 89\n56 58\n",
"output": "173\n"
},
{
"input": "10\n95 81 32 59 71 30 50 61 100\n1 6\n",
"output": "338\n"
},
{
"input": "80\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 5 5 5 5 5 5 5 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12\n17 65\n",
"output": "326\n"
},
{
"input": "99\n46 5 16 66 53 12 84 89 26 27 35 68 41 44 63 17 88 43 80 15 59 1 42 50 53 34 75 16 16 55 92 30 28 11 12 71 27 65 11 28 86 47 24 10 60 47 7 53 16 75 6 49 56 66 70 3 20 78 75 41 38 57 89 23 16 74 30 39 1 32 49 84 9 33 25 95 75 45 54 59 17 17 29 40 79 96 47 11 69 86 73 56 91 4 87 47 31 24\n23 36\n",
"output": "514\n"
},
{
"input": "100\n63 65 21 41 95 23 3 4 12 23 95 50 75 63 58 34 71 27 75 31 23 94 96 74 69 34 43 25 25 55 44 19 43 86 68 17 52 65 36 29 72 96 84 25 84 23 71 54 6 7 71 7 21 100 99 58 93 35 62 47 36 70 68 9 75 13 35 70 76 36 62 22 52 51 2 87 66 41 54 35 78 62 30 35 65 44 74 93 78 37 96 70 26 32 71 27 85 85 63\n43 92\n",
"output": "2599\n"
},
{
"input": "95\n2 2 3 3 4 6 6 7 7 7 9 10 12 12 12 12 13 14 15 16 17 18 20 20 20 20 21 21 21 21 22 22 22 22 22 23 23 23 25 26 26 27 27 27 28 29 29 30 30 31 32 33 34 36 37 37 38 39 39 39 42 43 43 43 45 47 48 50 50 51 52 53 54 54 54 55 55 55 58 59 60 61 61 61 61 62 62 63 64 65 66 67 67 67\n64 93\n",
"output": "1636\n"
},
{
"input": "6\n22 9 87 89 57\n1 6\n",
"output": "264\n"
},
{
"input": "50\n1 8 8 13 14 15 15 16 19 21 22 24 26 31 32 37 45 47 47 47 50 50 51 54 55 56 58 61 61 61 63 63 64 66 66 67 67 70 71 80 83 84 85 92 92 94 95 95 100\n4 17\n",
"output": "285\n"
},
{
"input": "20\n91 1 41 51 95 67 92 35 23 70 44 91 57 50 21 8 9 71 40\n8 17\n",
"output": "399\n"
},
{
"input": "40\n32 88 59 36 95 45 28 78 73 30 97 13 13 47 48 100 43 21 22 45 88 25 15 13 63 25 72 92 29 5 25 11 50 5 54 51 48 84 23\n7 26\n",
"output": "862\n"
},
{
"input": "6\n3 12 27 28 28\n3 4\n",
"output": "27\n"
},
{
"input": "25\n1 1 1 4 5 6 8 11 11 11 11 12 13 14 14 14 15 16 16 17 17 17 19 19\n4 8\n",
"output": "23\n"
},
{
"input": "9\n12 40 69 39 59 21 59 5\n4 6\n",
"output": "98\n"
},
{
"input": "2\n3\n1 2\n",
"output": "3\n"
},
{
"input": "51\n5 7 9 16 19 25 26 29 29 30 31 32 32 41 43 44 47 49 50 50 51 52 54 55 56 63 64 66 67 70 74 74 77 78 79 80 80 85 86 87 89 89 90 92 93 94 94 95 95 97\n3 44\n",
"output": "2268\n"
},
{
"input": "25\n70 95 21 84 97 39 12 98 53 24 78 29 84 65 70 22 100 17 69 27 62 48 35 80\n8 23\n",
"output": "846\n"
},
{
"input": "70\n69 95 34 14 67 61 6 95 94 44 28 94 73 66 39 13 19 71 73 71 28 48 26 22 32 88 38 95 43 59 88 77 80 55 17 95 40 83 67 1 38 95 58 63 56 98 49 2 41 4 73 8 78 41 64 71 60 71 41 61 67 4 4 19 97 14 39 20 27\n9 41\n",
"output": "1767\n"
},
{
"input": "35\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n30 31\n",
"output": "2\n"
},
{
"input": "7\n52 36 31 23 74 78\n2 7\n",
"output": "242\n"
},
{
"input": "99\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n66 95\n",
"output": "29\n"
},
{
"input": "45\n1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 4 5 5 5 5 6 6 6 6 6 6 6 7 7 7 7 8 8 8 9 9 9 9 9 10 10 10\n42 45\n",
"output": "30\n"
},
{
"input": "5\n6 8 22 22\n2 3\n",
"output": "8\n"
},
{
"input": "5\n93 83 42 56\n2 5\n",
"output": "181\n"
},
{
"input": "9\n1 2 2 2 2 3 3 5\n3 7\n",
"output": "9\n"
},
{
"input": "96\n51 32 95 75 23 54 70 89 67 3 1 51 4 100 97 30 9 35 56 38 54 77 56 98 43 17 60 43 72 46 87 61 100 65 81 22 74 38 16 96 5 10 54 22 23 22 10 91 9 54 49 82 29 73 33 98 75 8 4 26 24 90 71 42 90 24 94 74 94 10 41 98 56 63 18 43 56 21 26 64 74 33 22 38 67 66 38 60 64 76 53 10 4 65 76\n21 26\n",
"output": "328\n"
},
{
"input": "97\n18 90 84 7 33 24 75 55 86 10 96 72 16 64 37 9 19 71 62 97 5 34 85 15 46 72 82 51 52 16 55 68 27 97 42 72 76 97 32 73 14 56 11 86 2 81 59 95 60 93 1 22 71 37 77 100 6 16 78 47 78 62 94 86 16 91 56 46 47 35 93 44 7 86 70 10 29 45 67 62 71 61 74 39 36 92 24 26 65 14 93 92 15 28 79 59\n6 68\n",
"output": "3385\n"
},
{
"input": "50\n28 8 16 29 19 82 70 51 96 84 74 72 17 69 12 21 37 21 39 3 18 66 19 49 86 96 94 93 2 90 96 84 59 88 58 15 61 33 55 22 35 54 51 29 64 68 29 38 40\n23 28\n",
"output": "344\n"
},
{
"input": "90\n1 1 3 5 8 9 10 11 11 11 11 12 13 14 15 15 15 16 16 19 19 20 22 23 24 25 25 28 29 29 30 31 33 34 35 37 37 38 41 43 43 44 45 47 51 54 55 56 58 58 59 59 60 62 66 67 67 67 68 68 69 70 71 72 73 73 76 77 77 78 78 78 79 79 79 82 83 84 85 85 87 87 89 93 93 93 95 99 99\n28 48\n",
"output": "784\n"
},
{
"input": "15\n89 55 94 4 15 69 19 60 91 77 3 94 91 62\n3 14\n",
"output": "617\n"
},
{
"input": "45\n83 74 73 95 10 31 100 26 29 15 80 100 22 70 31 88 9 56 19 70 2 62 48 30 27 47 52 50 94 44 21 94 23 85 15 3 95 72 43 62 94 89 68 88\n17 40\n",
"output": "1061\n"
},
{
"input": "98\n32 47 26 86 43 42 79 72 6 68 40 46 29 80 24 89 29 7 21 56 8 92 13 33 50 79 5 7 84 85 24 23 1 80 51 21 26 55 96 51 24 2 68 98 81 88 57 100 64 84 54 10 14 2 74 1 89 71 1 20 84 85 17 31 42 58 69 67 48 60 97 90 58 10 21 29 2 21 60 61 68 89 77 39 57 18 61 44 67 100 33 74 27 40 83 29 6\n8 77\n",
"output": "3319\n"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1\n6 8\n",
"output": "2\n"
}
] |
code_contests
|
python
| 0.8 |
5cede7b7b9a4e8304ab941a49d78322f
|
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly n lowercase English letters into s to make it a palindrome. (A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.) You can choose any n lowercase English letters, and insert each of them to any position of s, possibly to the beginning or the end of s. You have to insert exactly n letters even if it is possible to turn s into a palindrome by inserting less than n letters.
Find the number of the palindromes that can be obtained in this way, modulo 10007.
Input
The first line contains a string s (1 ≤ |s| ≤ 200). Each character in s is a lowercase English letter.
The second line contains an integer n (1 ≤ n ≤ 109).
Output
Print the number of the palindromes that can be obtained, modulo 10007.
Examples
Input
revive
1
Output
1
Input
add
2
Output
28
Note
For the first sample, you can obtain the palindrome "reviver" by inserting 'r' to the end of "revive".
For the second sample, the following 28 palindromes can be obtained: "adada", "adbda", ..., "adzda", "dadad" and "ddadd".
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
palindrom = lambda s: s == s[::-1]
printans = lambda l: print(''.join(l))
s = list(input())
for i in range(len(s)+1):
for letter in 'abcdefghijklmnopqrstvwuxyz':
tmp = s[:]
tmp.insert(i,letter)
if palindrom(tmp):
printans(tmp)
exit()
print('NA')
|
python
|
code_algorithm
|
[
{
"input": "add\n2\n",
"output": "adda\n"
},
{
"input": "revive\n1\n",
"output": "reviver\n"
},
{
"input": "noon\n5\n",
"output": "nooon\n"
},
{
"input": "lsdijfjisl\n1\n",
"output": "lsdijfjidsl\n"
},
{
"input": "lsdijfjisl\n209\n",
"output": "lsdijfjidsl\n"
},
{
"input": "nsngnnnnnnnnnnvnnnnnbe\n948\n",
"output": "NA\n"
},
{
"input": "squirrel\n32\n",
"output": "NA\n"
},
{
"input": "cnonnpbnpptppgntggtggtngpptppnbpnnonc\n294295\n",
"output": "cnonnpbnpptppgntggttggtngpptppnbpnnonc\n"
},
{
"input": "k\n46277432\n",
"output": "kk\n"
},
{
"input": "nevceypryxidffdixyrpyecven\n2916\n",
"output": "nevceypryxidfffdixyrpyecven\n"
},
{
"input": "yosupo\n2\n",
"output": "NA\n"
},
{
"input": "irrjoktogwxektwrfihfjtertgdhttktrgiwtgttwkjthkewwewtrefejwforhwfjkrkifxkhtogothkxfikrkjfwhrofwjefertwewwekhtjkwttgtwigrtktthdgtretjfhifrwtkexwgotkojrri\n618\n",
"output": "irrjoktogwxektwrfihfjtertgdhttktrgiwtgttwkjthkewwewtrefejwforhwfjkrkifxkhtoggothkxfikrkjfwhrofwjefertwewwekhtjkwttgtwigrtktthdgtretjfhifrwtkexwgotkojrri\n"
},
{
"input": "nqwcvcwqn\n52\n",
"output": "nqwcvvcwqn\n"
},
{
"input": "bbbhbbibhjjhbibbhbbb\n41891\n",
"output": "bbbhbbibhjjjhbibbhbbb\n"
},
{
"input": "bxyfyfokfzycqtqfatolwxccaqnsncaqnqkztjsksocflsxzzxslfcosksjtzkqnqacnsnqaccxwlotafqtqcyzfkofyfyxb\n82245714\n",
"output": "bxyfyfokfzycqtqfatolwxccaqnsncaqnqkztjsksocflsxzzzxslfcosksjtzkqnqacnsnqaccxwlotafqtqcyzfkofyfyxb\n"
},
{
"input": "hopeyouenjoyedthematch\n20150118\n",
"output": "NA\n"
},
{
"input": "zlllzzzzzlzzzzllllzzzllzlzzzzzlzlllzzlzzlllzlllzzllzzlllzlzlzzzllllzlzzzzlllzlzllzlzlllzzzzlzllllzzzlzlzlllzzllzzlllzlllzzlzzlllzlzzzzzlzllzzzllllzzzzlzzzzzlllz\n8\n",
"output": "zlllzzzzzlzzzzllllzzzllzlzzzzzlzlllzzlzzlllzlllzzllzzlllzlzlzzzllllzlzzzzlllzlzlllzlzlllzzzzlzllllzzzlzlzlllzzllzzlllzlllzzlzzlllzlzzzzzlzllzzzllllzzzzlzzzzzlllz\n"
},
{
"input": "jfoewijalkemfwmamjakldsvkdsvksdkmvmkvmkmkkwemfkmkemgkweghweufewufwefewfewkoewoijfiewfelwjfee\n2319\n",
"output": "NA\n"
},
{
"input": "oawjfiowejafoiewajfjiewajowimafjiowajfoijmfoiwjfe\n790221666\n",
"output": "NA\n"
},
{
"input": "yozppppppppppzzppppppppoppppppppppnpppppprpyypvppvppppppppopypppppppypppppppkppppppppvpppppppp\n1\n",
"output": "NA\n"
},
{
"input": "evima\n4\n",
"output": "NA\n"
},
{
"input": "lrlmrlrmmfzlffrmorrlrzzrmelflfrzzlorlllrzzfzmjlffoofflrororforoefrjzlmollmfllrmlorozoomfoorozfrjmjroozrlljlrmfmrl\n251851\n",
"output": "NA\n"
},
{
"input": "ewcdcwerp\n1\n",
"output": "NA\n"
},
{
"input": "kitayuta\n6\n",
"output": "NA\n"
},
{
"input": "mrkitayuta\n536870899\n",
"output": "NA\n"
},
{
"input": "fft\n2\n",
"output": "tfft\n"
},
{
"input": "racecar\n10\n",
"output": "raceecar\n"
},
{
"input": "czlhddcngwzrmbsvceirdwoezlboxsbehwgccncyrmvbgyrdmzocmlwgmcrmcocmrcmgwlmcozmdrygbvmrycnccgwhebsxoblneowrievsbmrzwgncddhlz\n87205\n",
"output": "NA\n"
},
{
"input": "eeeee\n41104\n",
"output": "eeeeee\n"
},
{
"input": "a\n1\n",
"output": "aa\n"
},
{
"input": "hogloid\n5\n",
"output": "NA\n"
},
{
"input": "b\n5\n",
"output": "bb\n"
},
{
"input": "zzzzzzzzzzzzzznizzzzzzzzzzzzzzzzzzzyzzyzzzzzzzzzzzzzyzzzzzzyzzyzzzzzzznzzzzzzzzzzzzzzznzzzzznzizzzzzzizzzyzzzzzzzzynzzzi\n541\n",
"output": "NA\n"
},
{
"input": "mrtoudai\n2347832\n",
"output": "NA\n"
},
{
"input": "vnwmvvmonv\n12345\n",
"output": "NA\n"
},
{
"input": "sgjzgbvvsztjqsrnqqgsvcgmxyvxjbxvvszjxx\n31489\n",
"output": "NA\n"
},
{
"input": "oyxbepxbeqaqpzwwzugzwwisxngkwegnqgbweqokoxpkxkkeqoqtwgxsgekgnasiwzguzwwazaxebxyo\n559047\n",
"output": "NA\n"
},
{
"input": "shuseki\n4\n",
"output": "NA\n"
},
{
"input": "mvvxvqzxqvmqqmjljmqzxxqvxxmmqxqjzzxmmmqqqqmxzxqmxqzdvzqvqqqqqqxxmxjjlvvljljmxxxqqqqqvqvdzqxmqxvzxmqxqmmmzxzzjxxqmmqxvzqxxzqmqjljmqqvmjqxzqvv\n38\n",
"output": "NA\n"
},
{
"input": "thankyoumrkitayuta\n39\n",
"output": "NA\n"
},
{
"input": "stat\n9\n",
"output": "stats\n"
},
{
"input": "iwiwi\n8\n",
"output": "iwiiwi\n"
},
{
"input": "ee\n1\n",
"output": "eee\n"
},
{
"input": "wanwdnnwnnwinwaxaadnwawiaiawwwiniiwnxiwdnawnaiiiwywiwnyindan\n818007692\n",
"output": "NA\n"
},
{
"input": "zennyuu\n114514\n",
"output": "NA\n"
},
{
"input": "slime\n41\n",
"output": "NA\n"
},
{
"input": "level\n7\n",
"output": "levvel\n"
},
{
"input": "dddddzdzddddddddddddddddddddddddddbddddddddbdddddddddddddddddddbdb\n20\n",
"output": "NA\n"
},
{
"input": "fmlmflmfzllffrmlrlfzmoelflfrzzlorllzrozfzmjoeflofflrororlffooffjrzfmzrllmjozrrlffemzzmlomrfzflzlmjmrlromlrr\n251851\n",
"output": "NA\n"
},
{
"input": "yu\n1000000000\n",
"output": "uyu\n"
},
{
"input": "mrkitayutasgift\n2500\n",
"output": "NA\n"
},
{
"input": "yutampo\n3\n",
"output": "NA\n"
},
{
"input": "ljszsxovlxdsdsjvaufyfftmoyfuyaplpzxjucujxzplpayufyomtffyfuavjsdsdxlvoxszsjl\n1880\n",
"output": "ljszsxovlxdsdsjvaufyfftmoyfuyaplpzxjuccujxzplpayufyomtffyfuavjsdsdxlvoxszsjl\n"
},
{
"input": "wiiisiiiuoiiiiitixiiv\n251851\n",
"output": "NA\n"
},
{
"input": "iq\n1\n",
"output": "qiq\n"
},
{
"input": "zzz\n536870908\n",
"output": "zzzz\n"
},
{
"input": "dog\n28\n",
"output": "NA\n"
},
{
"input": "ipzmkijimzipmjkjhctpckcjpkjkicbdtwpbkkzizpijzpbkidkchhckdikbpzjipzizkkbpwtdbcikjkpjckcptchjkjmpizmijikmzpi\n209\n",
"output": "ipzmkijimzipmjkjhctpckcjpkjkicbdtwpbkkzizpijzpbkidkchhhckdikbpzjipzizkkbpwtdbcikjkpjckcptchjkjmpizmijikmzpi\n"
},
{
"input": "jewiiwefj\n3223\n",
"output": "jfewiiwefj\n"
},
{
"input": "palindrome\n123454321\n",
"output": "NA\n"
},
{
"input": "pppppppppppppppppppppppppppppppppppppppppppppppcpppppppppppppppppppppppppppppcppppppplppppppppppppppppppppppppppppppppppppppppa\n1515688\n",
"output": "NA\n"
},
{
"input": "codeforcesround\n286\n",
"output": "NA\n"
},
{
"input": "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnngnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnz\n536870712\n",
"output": "NA\n"
},
{
"input": "ccxsecrxosqsrsoolxzcoolqllexxssxqoqeqkocerchlxckqschxxczlxscoxhszsoxzxrzohsccsclocxxzshrhzoexxhrohqrrqhorhxxeozhrhszxxcolcsccshozrxzxoszshxocsxlzcxxhcsqkcxlhcrecokqeqoqxssxxellqlooczxloosrsqsoxrcesxcc\n536870712\n",
"output": "ccxsecrxosqsrsoolxzcoolqllexxssxqoqeqkocerchlxckqschxxczlxscoxhszsoxzxrzohsccsclocxxzshrhzoexxhrohqrrrqhorhxxeozhrhszxxcolcsccshozrxzxoszshxocsxlzcxxhcsqkcxlhcrecokqeqoqxssxxellqlooczxloosrsqsoxrcesxcc\n"
},
{
"input": "ussiudlvjsdjduujuljvdrdljdjluarusdaiiujjsdudjslpmujdspixxljjjuiqasjlsxpppspuisdaljjxsiqqujudjljxlmqjjqmlxjljdujuqqisxjjladsiupspppxsljsaqiujjjlxxipsdjumplsjdudsjjuiiadsurauljdjldrdvjlujuudjdsjvlduissu\n4347\n",
"output": "ussiudlvjsdjduujuljvdrdljdjluarusdaiiujjsdudjslpmujdspixxljjjuiqasjlsxpppspuisdaljjxsiqqujudjljxlmqjjjqmlxjljdujuqqisxjjladsiupspppxsljsaqiujjjlxxipsdjumplsjdudsjjuiiadsurauljdjldrdvjlujuudjdsjvlduissu\n"
},
{
"input": "gggmmggmgjjmmjggglmmgmjmjjgggkjmmjgmmmmjmmmgggmmgjjjmjjmmmkmmmkgmggmgmjmmmgggjmmgggggjmmmkgggggmgmgjgggmmmmmgmggmmgmjmjgmmgjjjmjggmgggggmmmmgmjgmjjkgggmjmjmmmmmmmmjjgmggmmggg\n566605\n",
"output": "NA\n"
},
{
"input": "cszaetjydpkfzbihfzjmsfklibikgskhdfdrfgorggirpcmshkgicyjzjkkakmhfjasyrrbmabbdzsgyqkzgkehzasosaztcazvpfbiabfpojtbkgrvztkvsgzcgmimgskztceeghubbacrjlzzskffaskgvzsdckkphszibtajfrcldeyakgvkdhphhliayzszhghzt\n33\n",
"output": "NA\n"
},
{
"input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssi\n67106614\n",
"output": "isssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssi\n"
},
{
"input": "stat\n",
"output": "stats\n"
},
{
"input": "zzz\n",
"output": "zzzz\n"
},
{
"input": "mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n469761845\n",
"output": "mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxm\n"
},
{
"input": "eviver\n",
"output": "reviver\n"
},
{
"input": "qqqqqqqqqqqqqqiqqqqqqiqqqqqqqqqqqqqqqqqqqqqqqiqqqiqqqqqqqqiqqqqqqqqqqqqqqqqqiqqqqqqqqqqqqqiqqqqqqqqqqqqqqqqqqqqqqqqqqiqqqqqqqqqqqqqqqiqqqqqqqqqqqqqqqqqqqqqiqqqqqqqqqqqqqqqqqqqqqqqqqqqqqiqqqqqiqqqqqqqi\n536870709\n",
"output": "NA\n"
},
{
"input": "mooooooooojoooowooooooooooomooooooooocoooooooooooooooolooooooooooooooooooooopoooooooooooooooooooooooooooooooooooooooooooooioooooooooooouoooojoooooojooooooooomooooolodokoooooooooooocooooooooooomoooooo\n179\n",
"output": "NA\n"
},
{
"input": "yttyysttyyttttsytytyyttysstttstyttssttsytyttststyssyysttyyttstytttstststttttttytttststttttttytttyttttttytttytttttttststttytttttttstststttytsttyyttsyyssytststtytysttssttytstttssyttyytytysttttyyttsyytty\n4203\n",
"output": "yttyysttyyttttsytytyyttysstttstyttssttsytyttststyssyysttyyttstytttstststttttttytttststttttttytttytttttttytttytttttttststttytttttttstststttytsttyyttsyyssytststtytysttssttytstttssyttyytytysttttyyttsyytty\n"
},
{
"input": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhht\n536870709\n",
"output": "NA\n"
},
{
"input": "nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhvhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n67108663\n",
"output": "NA\n"
},
{
"input": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxkxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxt\n536870677\n",
"output": "NA\n"
},
{
"input": "olnrttrnnptltrxooobokxrrtoxrnnrlxnxnkkddnslonolnxlxnsolrvlsslnxofoxofrcttnlxrordloxtnxvoonsloptksorvrosktpolsnoovxntxoldrorxlnttcrfoxofoxnlsslvrlosnxlxnlonolsnddkknxnxlrnnrxotrrxkoboooxrtltpnnrttrnlo\n61309576\n",
"output": "olnrttrnnptltrxooobokxrrtoxrnnrlxnxnkkddnslonolnxlxnsolrvlsslnxofoxofrcttnlxrordloxtnxvoonsloptksorvvrosktpolsnoovxntxoldrorxlnttcrfoxofoxnlsslvrlosnxlxnlonolsnddkknxnxlrnnrxotrrxkoboooxrtltpnnrttrnlo\n"
},
{
"input": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\n535442\n",
"output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\n"
},
{
"input": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxkxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxt\n66977589\n",
"output": "NA\n"
},
{
"input": "jewiiwefj\n",
"output": "jfewiiwefj\n"
},
{
"input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssl\n536870709\n",
"output": "lsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssl\n"
},
{
"input": "qkqiiwkwqivqkdfiimkqiwkimikfkkvoivwvilvmiwwqkvqvidimwiddwqqqqkqqkviqldiqqoqvwqvktwiqkqiwfkitoitkqiowoiqktiotikfwiqkqiwtkvqwvqoqqidlqivkqqkqqqqwddiwmidivqvkqwwimvlivwviovkkfkimikwiqkmiifdkqviqwkwiiqkq\n671088441\n",
"output": "qkqiiwkwqivqkdfiimkqiwkimikfkkvoivwvilvmiwwqkvqvidimwiddwqqqqkqqkviqldiqqoqvwqvktwiqkqiwfkitoitkqiowwoiqktiotikfwiqkqiwtkvqwvqoqqidlqivkqqkqqqqwddiwmidivqvkqwwimvlivwviovkkfkimikwiqkmiifdkqviqwkwiiqkq\n"
},
{
"input": "evima\n",
"output": "NA\n"
},
{
"input": "bbb\n",
"output": "bbbb\n"
},
{
"input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssi\n536870678\n",
"output": "isssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssi\n"
},
{
"input": "yryralvogdsfsfdonrrofkkssfgvfsrslrrdsggfygddsykgrrdaovyydddadvsdrfogdygsrsydysokafrddssykakhangyasgsfnygrsrddyfkdsvvvfsrrrdydflkyryydgadrasndsraanoldgffgfdsgrydsfrdrfglgffrfryngfygvoordravyfryfrnfrrky\n5481\n",
"output": "NA\n"
},
{
"input": "yosupo\n",
"output": "NA\n"
},
{
"input": "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddzddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddj\n67108662\n",
"output": "NA\n"
},
{
"input": "chhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n67104566\n",
"output": "NA\n"
},
{
"input": "btmtbrrmmmbmtprmtbrrrmllttlrprmpmptprmmbtmmmtmtbbmbtrtbbrbtmttltttmtbmbrrtmtbmmbmtlrmlmbmbtmmmbbttbtbttbbmmmtbmbmlmrltmbmmbtmtrrbmbtmtttlttmtbrbbtrtbmbbtmtmmmtbmmrptpmpmrprlttllmrrrbtmrptmbmmmrrbtmtb\n536870712\n",
"output": "btmtbrrmmmbmtprmtbrrrmllttlrprmpmptprmmbtmmmtmtbbmbtrtbbrbtmttltttmtbmbrrtmtbmmbmtlrmlmbmbtmmmbbttbttbttbbmmmtbmbmlmrltmbmmbtmtrrbmbtmtttlttmtbrbbtrtbmbbtmtmmmtbmmrptpmpmrprlttllmrrrbtmrptmbmmmrrbtmtb\n"
},
{
"input": "prrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr\n536870709\n",
"output": "prrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrp\n"
},
{
"input": "jjjjjjjjjjjjjnjjjjjjjjjjjjjjjjjjjvjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjajjjdjjjjjjjjjjjjjjjjjjjjjjjjjjjajajjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjajjjjd\n1176214\n",
"output": "NA\n"
},
{
"input": "nqwcvcwqn\n",
"output": "nqwcvvcwqn\n"
},
{
"input": "vvvvvvvgvvvgvvvvvvvvvvvvvvvvrvvvvvvvvvgvvvvvvvvvvvvvvvvrvgvvvvvvgvvrggvvgvgvvvvvvvvvvvgvgvvvvvvgvvvvgvvvvvvvvvvgvvvvvvvgvgvvvvvvvvqvvvvvvvvvvvvgvvvvvvvvvvvvvvvvvvvvgvvvgvvvvvvvvvgvvvvvgvvqvrvgvrv\n536870712\n",
"output": "NA\n"
},
{
"input": "ewklfjwefjlkwejflmklgjlkewjrklgjkjewnjkfnewjfhukewjfjkejkfdjskfhdkjshfkjhfjhjhjewhjhjehrfwhhfjefhjwfhjefkjwjfhjwhfjewhfkjwhkjhfjkehjdksjnfdjqwkehgqgwegwqfetywqfeytqfetyefgirgoigjhityhujyuirhjegeywefwe\n536870709\n",
"output": "NA\n"
},
{
"input": "mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n67108657\n",
"output": "mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxm\n"
},
{
"input": "xmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm\n536870712\n",
"output": "xmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmx\n"
},
{
"input": "zennyuu\n",
"output": "NA\n"
},
{
"input": "mdskmksdksdddddddddddddddmkcsdmcksdmkkkkkkkkkkkkkkkkkkkkkkkkkmmfekwmewwwweeeeeeeeeeeeeeeeeeeeeeeeeeeeefkwefjlwkekfwskdfkjkkkkkkkkkkkkkkkkkkkkkkkkfjewkfjekfjfefjefkkkkkkkkkkkkkkkkkkkkkkeefefejfekekkkkk\n199\n",
"output": "NA\n"
},
{
"input": "kuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\n66060087\n",
"output": "NA\n"
},
{
"input": "a\n",
"output": "aa\n"
},
{
"input": "gsossssqsosssossssssssssgsssgssssssrsssssgszsssssssssssssossssssssssgssssssssssssssssosossossgssssqssssqqsssssssossssssssssgsssssssssssssssssssssssssssgssssssssssssrsssssssssssssssqssszsrgsssos\n232\n",
"output": "NA\n"
},
{
"input": "kuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\n528482103\n",
"output": "NA\n"
},
{
"input": "lgllsggozxlzotlgozolxlloiozigtxloolzggxgoloixgllgxzzgtoxioxizggoogzozlzlfolzlloxlxotoglllgotoxlxollzloflzlzozgooggzixoixotgzzxgllgxiologxggzloolxtgizoiollxlozogltozlxzoggsllgl\n88200048\n",
"output": "lgllsggozxlzotlgozolxlloiozigtxloolzggxgoloixgllgxzzgtoxioxizggoogzozlzlfolzlloxlxotogllllgotoxlxollzloflzlzozgooggzixoixotgzzxgllgxiologxggzloolxtgizoiollxlozogltozlxzoggsllgl\n"
},
{
"input": "chhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n534773558\n",
"output": "NA\n"
},
{
"input": "lsdijfjisl\n",
"output": "lsdijfjidsl\n"
},
{
"input": "iwiwi\n",
"output": "iwiiwi\n"
},
{
"input": "uuuuuuuuuuuuuouuuuuuueuuuuuuuuuuuuuquuuuuuuuuuuuuuuuuuuuuuuuufiuuuuuuuukuuuuuuuuuuuuoueuuuuuuuuuquuuuuuucuuuiuuuuiuuuuuuuuuuuuuuuuuuuucuuuuueuuuuaeuuuuuucuuuuuuuuuuuuuuuiuuuuuuuuuuutuuuuuuuxi\n84\n",
"output": "NA\n"
},
{
"input": "aaaaa\n",
"output": "aaaaaa\n"
},
{
"input": "ydydvoddlvjqdmvszssdozedvqmvqlyvvqlzqzsazqyslavmdlovqoylezcqvlsvmqqmvvdvjsdsdvvszavaszldqvmxmsvmvddyyddvmvsmxmvqdlzsavazsvvdsdsjvdvvmqqmvslvqczelyoqvoldmvalsyqzaszqzlqvvylqvmqvdezodsszsvmdqjvlddovdydy\n535822134\n",
"output": "ydydvoddlvjqdmvszssdozedvqmvqlyvvqlzqzsazqyslavmdlovqoylezcqvlsvmqqmvvdvjsdsdvvszavaszldqvmxmsvmvddyyyddvmvsmxmvqdlzsavazsvvdsdsjvdvvmqqmvslvqczelyoqvoldmvalsyqzaszqzlqvvylqvmqvdezodsszsvmdqjvlddovdydy\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaw\n67108680\n",
"output": "NA\n"
},
{
"input": "mrtoudai\n",
"output": "NA\n"
},
{
"input": "hogloid\n",
"output": "NA\n"
},
{
"input": "iq\n",
"output": "qiq\n"
},
{
"input": "prphfjzjfhnvnjnhgpojpnfgtrqqjnfgnjqtnnhpzoeansnhjnoqpqegnjnvhgpppgfnjvjhpnpngjhqefjpalnznftjtlqooprrnpoqqtjzfxnnlqjpeqhjgnpnghjvjrnfgrrppgqpnphgeqtqqnjhghnaozjhnnthqjfgnjqrefnpjonghzngnqhfzjfhrpt\n536870709\n",
"output": "NA\n"
},
{
"input": "qaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n67108663\n",
"output": "qaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaq\n"
},
{
"input": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhht\n67108661\n",
"output": "NA\n"
},
{
"input": "dog\n",
"output": "NA\n"
},
{
"input": "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjm\n535822135\n",
"output": "mjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjm\n"
},
{
"input": "uttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt\n67108662\n",
"output": "utttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttu\n"
},
{
"input": "bttfjttthttttttutttbytttttkthkttttktttttuttttttttttttjtttttbjfttnjtttttttktttttttkntttttttttttttutjtttnfthttttttuttttttttttkktttbttthttttttttttttkjttttttttttktttbfhtmtttttutttttkttutttttttttutkttttttt\n535822135\n",
"output": "NA\n"
},
{
"input": "ee\n",
"output": "eee\n"
},
{
"input": "ijcntmpascomjmssnblmxbgagzgprrmtlligkgubujxksxguslxglvcngamneassmgtguamjaqthxszvfaraxslsuatlavltjkxuaugxkyztvavalrbsanaetsxhtqaejtckztkgmkmafxknvlmaabnavlvgjfxsgjjumcgkillgtgrpzagbmgxbvzxfyjsoymgtnci\n536870711\n",
"output": "NA\n"
},
{
"input": "toudairiichishusekizennyuumrtoudaikanojomochitoudaiigakubunotennsaitoudaihougakubunoshuusaitoudaiigakubushusekitoudaiiqkikoushisuugakugorinnkinnkyoudaikeizaigakubushusekichishikimonstertoudainoitannji\n1000000000\n",
"output": "NA\n"
},
{
"input": "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddzddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddj\n536870710\n",
"output": "NA\n"
},
{
"input": "kitayuta\n",
"output": "NA\n"
},
{
"input": "ggvsraybrobbgcgwcsgugvsbvcwsiwuvykbswukgavigvcwbgysajwsgziwwssuavcgvsjsvggbbwuwsgcbwykvagwgawiwwuuwyiwgwsasvkywvkbaguzwkuwbbggvssjgcuuawwvzgsuvuwysybwcvgisgkuksbkyvuwisbwgcabgugvcwgcvbocrsgg\n489028\n",
"output": "NA\n"
},
{
"input": "ceesempelcmcdewcmmswcppmswssmocswpowcwpeepdmsesmemceerspmwppscmdwmpoopwdesssdsccsomccpposdmmdmcwesmmsepccomwdpmmdsrppeccmoscsmmspspowwmpmwdccsppemmreecmlmsesmmdcepwcwspmpcwmmmswsdmpcwsmomcpsedcoclmsec\n536870712\n",
"output": "NA\n"
},
{
"input": "vnwmvvmonv\n",
"output": "NA\n"
},
{
"input": "revive\n",
"output": "reviver\n"
},
{
"input": "cndkjsnmncmnmxnncmxncnbcvcvavsxcsavcxvxsvxvxsvccvvcvcvcvdcvcvvcvvcvcvvsdvdfvhjgnjbgnjbgngbnbgnjgbjnbgnbnbngbjhjhjjjhjjhiujuoujukoyoktotrutryryrfhfjnfekfiejfjewkfjewigrjjgbjgyedgfgfgfggfgfgfgeuwfewhejf\n536870453\n",
"output": "NA\n"
},
{
"input": "zaa\n",
"output": "zaaz\n"
},
{
"input": "racecar\n",
"output": "raceecar\n"
},
{
"input": "noon\n",
"output": "nooon\n"
},
{
"input": "xmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm\n67108664\n",
"output": "xmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmx\n"
},
{
"input": "palindrome\n",
"output": "NA\n"
},
{
"input": "dkvulkdhmdloduumhqdmludvflmvldvddmmmtkulhduoluulmmlfvmqvfvkddmtumhvfdqluhdohlludvkfkvdullhodhulqdfvhmutmddkvfvqmvflmmluuloudhluktmmmddvdlvmlfvdulmdqhmuudoldmhdkluvkd\n166547\n",
"output": "dkvulkdhmdloduumhqdmludvflmvldvddmmmtkulhduoluulmmlfvmqvfvkddmtumhvfdqluhdohlludvkffkvdullhodhulqdfvhmutmddkvfvqmvflmmluuloudhluktmmmddvdlvmlfvdulmdqhmuudoldmhdkluvkd\n"
},
{
"input": "battaba\n",
"output": "abattaba\n"
},
{
"input": "squirrel\n",
"output": "NA\n"
},
{
"input": "jfjtmtjjjjmjtfjfjmtjafftfajfjfftmjmmmtffmjaajjmjafttjftfftaaajtjjtmjttatffjjjmjfmtmjtmjffjfjmattjfjmftjmajjmjajfftffjmjaajtmmjtjmmffmfaftjfjtfjtjtmmfftmjatmfjtftmmjtmfamjjjfmfjmjmmfjjjjatfjfffjmjjjmjj\n536870709\n",
"output": "NA\n"
},
{
"input": "fiwjoefejwiajoeklwjfaewfjlkewjfjewioafjewaklfewfcmklweamkmkmvkmvmijweqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqijfewfjwiqqwqiojiifjifkjwejfff\n95697\n",
"output": "NA\n"
},
{
"input": "abbabab\n",
"output": "NA\n"
},
{
"input": "z\n",
"output": "zz\n"
},
{
"input": "level\n",
"output": "levvel\n"
},
{
"input": "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjm\n66977591\n",
"output": "mjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjm\n"
},
{
"input": "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnngnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnz\n67108664\n",
"output": "NA\n"
},
{
"input": "xcmmmmmmmmmfmmmmmmmmmjmmmfmmmrmmmxmmmmmmmmmmmkmmmjmtmmmmmmmmmmmmmmmmmmbcmmhmmmmsmmmfmmmmjmmmmmmmmmmmmmmmmmmmmmmmmdmjmmmmbmmktmhmmrhmmmxmmmmmmofmmmlbmmmmmmmmmmmmmdmmmmmmmmhmmmxmmvqmmmmjmjjmbmmmmmmmmmmm\n536870728\n",
"output": "NA\n"
},
{
"input": "susssskllsskrsbukkllrlssususukssukslblbsukbuurlsskkksbsrsubukusuklursluslskruuksskrslublkruklulkrbkskbrklulkurklbulsrksskuurkslsulsrulkusukubusrsbskkksslruubkusblblskusskusususslrllkkubsrkssllkssssus\n536870703\n",
"output": "susssskllsskrsbukkllrlssususukssukslblbsukbuurlsskkksbsrsubukusuklursluslskruuksskrslublkruklulkrbksskbrklulkurklbulsrksskuurkslsulsrulkusukubusrsbskkksslruubkusblblskusskusususslrllkkubsrkssllkssssus\n"
},
{
"input": "yutampo\n",
"output": "NA\n"
},
{
"input": "shuseki\n",
"output": "NA\n"
},
{
"input": "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjh\n67108662\n",
"output": "hjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjh\n"
},
{
"input": "gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggx\n536870711\n",
"output": "xgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggx\n"
},
{
"input": "gvdfhdhfhffcfgcfccgyhfhgfgcccgcfvfgvvfvgcdfhfcvvgchvvvfchhccyfjhfhcyccccvwchcgfhchvhfgfgfccfchvcvccfhvhcfcfdvfgffhfhcfgffhfhcfffvfghfcfdvvfhhvgfhfvwvghchcfchvvgchfcwfwfyvhwfwcfgchvcffgccffvvgghfchffgv\n5654\n",
"output": "NA\n"
},
{
"input": "dhhddddddhddhhhdhdddhdhhhddhdhdddhhhdhddddhddhhhhdhdddhhdhhddddhhddhhhdhhddddddhdddddddhdhddhhdhhddddddhhdhhddhdhdddddddhddddddhhdhhhddhhddddhhdhhdddhdhhhhddhddddhdhhhdddhdhddhhhdhdddhdhhhddhddddddhhd\n536870711\n",
"output": "dhhddddddhddhhhdhdddhdhhhddhdhdddhhhdhddddhddhhhhdhdddhhdhhddddhhddhhhdhhddddddhdddddddhdhddhhdhhdddddddhhdhhddhdhdddddddhddddddhhdhhhddhhddddhhdhhdddhdhhhhddhddddhdhhhdddhdhddhhhdhdddhdhhhddhddddddhhd\n"
},
{
"input": "ewcdcwerp\n",
"output": "NA\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaw\n537395000\n",
"output": "NA\n"
},
{
"input": "kiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\n67125048\n",
"output": "kiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiik\n"
},
{
"input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssl\n67108661\n",
"output": "lsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssl\n"
},
{
"input": "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjh\n536870710\n",
"output": "hjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjh\n"
},
{
"input": "babccba\n",
"output": "babccbab\n"
},
{
"input": "mjjjamtfmjjjtfjmtjafftjmfajmjaffjtfmjmmmtfftaaaajmjafttjftjattajtjtttajfjjjfjfmtmjtmjfjfjjtjjfjjmjfafjjtamjfjffjtmtjtmmfjfjjfjajtajtjmjjtjaaftfmjjtmjjaamfjtmmmjtftfjaftffjtmfjfjtjjjjjtmtjfj\n536870709\n",
"output": "NA\n"
},
{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iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\n536887096\n",
"output": "kiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiik\n"
},
{
"input": "slime\n",
"output": "NA\n"
},
{
"input": "nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhvhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n536870711\n",
"output": "NA\n"
},
{
"input": "eee\n",
"output": "eeee\n"
},
{
"input": "xflbzlwyyjxdmwwwwxzzxbzdzzmzzzwmegjlgymzmywzlfjdwzzmelbwzwxjyfyyzffezwxxzzwfyzjcdylyzexdmjmwcejjfywxzlxfwzyxjxwewzfdlwyxfzzwzzwylfdwwwyywjxfxywzwmczylzfxxlfxfyzzwlzlzywfx\n6017\n",
"output": "NA\n"
}
] |
code_contests
|
python
| 0 |
45697781ec0fe983ff23e8b25e0a4e15
|
Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
* take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color;
* take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color.
She repeats this process until there is only one card left. What are the possible colors for the final card?
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200) — the total number of cards.
The next line contains a string s of length n — the colors of the cards. s contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.
Output
Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order.
Examples
Input
2
RB
Output
G
Input
3
GRG
Output
BR
Input
5
BBBBB
Output
B
Note
In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.
In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card.
In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
'''
Author : Md. Rezwanul Haque
Email : [email protected]
'''
import sys
from sys import stdout,stdin
input = lambda : sys.stdin.readline()
if __name__ == '__main__':
n = int(input())
s = input()
s = (s.count('B'), s.count('G'), s.count('R'))
if s[0] > 0 and s[1] > 0 and s[2] > 0:
stdout.write("BGR")
elif s[0] == 0 and s[1] == 0:
stdout.write("R")
elif s[1] == 0 and s[2] == 0:
stdout.write("B")
elif s[0] == 0 and s[2] == 0:
stdout.write("G")
elif s == (0,1,1):
stdout.write("B")
elif s == (1, 0, 1):
stdout.write("G")
elif s == (1, 1, 0):
stdout.write("R")
elif s[0] == 0 and s[1] == 1:
stdout.write("BG")
elif s[0] == 0 and s[2] == 1:
stdout.write("BR")
elif s[1] == 0 and s[0] == 1:
stdout.write("BG")
elif s[1] == 0 and s[2] == 1:
stdout.write("GR")
elif s[2] == 0 and s[0] == 1:
stdout.write("BR")
elif s[2] == 0 and s[1] == 1:
stdout.write("GR")
else:
stdout.write("BGR")
|
python
|
code_algorithm
|
[
{
"input": "2\nRB\n",
"output": "G"
},
{
"input": "5\nBBBBB\n",
"output": "B"
},
{
"input": "3\nGRG\n",
"output": "BR"
},
{
"input": "2\nRG\n",
"output": "B"
},
{
"input": "6\nGRRGBB\n",
"output": "BGR"
},
{
"input": "1\nB\n",
"output": "B"
},
{
"input": "4\nRBGB\n",
"output": "BGR"
},
{
"input": "7\nBBBGBRG\n",
"output": "BGR"
},
{
"input": "3\nGGR\n",
"output": "BR"
},
{
"input": "102\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGRGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG\n",
"output": "BGR"
},
{
"input": "3\nGGB\n",
"output": "BR"
},
{
"input": "1\nR\n",
"output": "R"
},
{
"input": "5\nGRRGR\n",
"output": "BGR"
},
{
"input": "2\nBG\n",
"output": "R"
},
{
"input": "200\nRGRGRRRRRGRRGRRRGRGRRRGGRGRRGGGRRGGRRRRRRRRRRRGRRGRRRGRRRGRRRRRRRGRRRRRRRRRRRGGRRGGRRRRGGRRRRRRRRRGGGRGRGRGRRGRGGRGRGRRRGRRRRRRGGRGRRRRGRRGRGGRRRRRRRGRGGRRGRRRRRRRGGRRRRGRRRRRRRGRRRGGRRRRRRGRRGGGRRRGR\n",
"output": "BGR"
},
{
"input": "101\nRRRRRRRRRRRRRRRRRRRBRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\n",
"output": "BG"
},
{
"input": "4\nRGGR\n",
"output": "BGR"
},
{
"input": "4\nRRBB\n",
"output": "BGR"
},
{
"input": "16\nRRGRRRRRRGGRGRRR\n",
"output": "BGR"
},
{
"input": "3\nBGB\n",
"output": "GR"
},
{
"input": "5\nRBRBG\n",
"output": "BGR"
},
{
"input": "5\nBRGRG\n",
"output": "BGR"
},
{
"input": "52\nBBBBBBBBBBBBBBBBBBBBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n",
"output": "BGR"
},
{
"input": "3\nBRB\n",
"output": "GR"
},
{
"input": "3\nRBR\n",
"output": "BG"
},
{
"input": "200\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG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
"output": "R"
},
{
"input": "2\nBB\n",
"output": "B"
},
{
"input": "3\nGBG\n",
"output": "BR"
},
{
"input": "4\nBGBG\n",
"output": "BGR"
},
{
"input": "3\nGBR\n",
"output": "BGR"
},
{
"input": "90\nBGBGGRRBGGRRRRRGGRGBBBBBRRBGBGBGBGGBBGRGGGGRBRBBRRRGBRRGBBGBBGGGRGRGRBGBBBRRGRRBRBRRGGRBRB\n",
"output": "BGR"
},
{
"input": "4\nGGRB\n",
"output": "BGR"
},
{
"input": "5\nBGBGR\n",
"output": "BGR"
},
{
"input": "193\nRRRGGGRBGGBGGGBGGBBGRBGGRBGGBBRBGGRBBBRBRRGGBBRBRGRRRBGBBRGGRGGGBGGRRGGRGRRBRBRBRRGRGBGBRGBBRGRRRBGRGGBGBRBBBGBRBBGBGBGGGBGGGGBRBBRRBGRGGBBBRBBBBBGRRRGBRGBRRRBBBGBGGGGRGGRRBRBGRRGBGBRBGGGRBRRGG\n",
"output": "BGR"
},
{
"input": "2\nBR\n",
"output": "G"
},
{
"input": "4\nBRRG\n",
"output": "BGR"
},
{
"input": "3\nRRG\n",
"output": "BG"
},
{
"input": "1\nG\n",
"output": "G"
},
{
"input": "3\nBGR\n",
"output": "BGR"
}
] |
code_contests
|
python
| 0 |
91e5a36ca3a1b63c15fcd6615152b01f
|
Note that girls in Arpa’s land are really attractive.
Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw n pairs of friends sitting around a table. i-th pair consisted of a boy, sitting on the ai-th chair, and his girlfriend, sitting on the bi-th chair. The chairs were numbered 1 through 2n in clockwise direction. There was exactly one person sitting on each chair.
<image>
There were two types of food: Kooft and Zahre-mar. Now Mehrdad wonders, was there any way to serve food for the guests such that:
* Each person had exactly one type of food,
* No boy had the same type of food as his girlfriend,
* Among any three guests sitting on consecutive chairs, there was two of them who had different type of food. Note that chairs 2n and 1 are considered consecutive.
Find the answer for the Mehrdad question. If it was possible, find some arrangement of food types that satisfies the conditions.
Input
The first line contains an integer n (1 ≤ n ≤ 105) — the number of pairs of guests.
The i-th of the next n lines contains a pair of integers ai and bi (1 ≤ ai, bi ≤ 2n) — the number of chair on which the boy in the i-th pair was sitting and the number of chair on which his girlfriend was sitting. It's guaranteed that there was exactly one person sitting on each chair.
Output
If there is no solution, print -1.
Otherwise print n lines, the i-th of them should contain two integers which represent the type of food for the i-th pair. The first integer in the line is the type of food the boy had, and the second integer is the type of food the girl had. If someone had Kooft, print 1, otherwise print 2.
If there are multiple solutions, print any of them.
Example
Input
3
1 4
2 5
3 6
Output
1 2
2 1
1 2
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import sys
def solve():
n = int(input())
partner = [0]*(2*n)
pacani = []
for line in sys.stdin:
pacan, telka = [int(x) - 1 for x in line.split()]
partner[pacan] = telka
partner[telka] = pacan
pacani.append(pacan)
khavka = [None]*(2*n)
for i in range(2*n):
while khavka[i] is None:
khavka[i] = 1
khavka[i^1] = 2
i = partner[i^1]
for pacan in pacani:
print(khavka[pacan], khavka[partner[pacan]])
solve()
|
python
|
code_algorithm
|
[
{
"input": "3\n1 4\n2 5\n3 6\n",
"output": "1 2\n2 1\n1 2\n"
},
{
"input": "6\n2 11\n7 1\n12 8\n4 10\n3 9\n5 6\n",
"output": "2 1\n2 1\n2 1\n2 1\n1 2\n1 2\n"
},
{
"input": "26\n8 10\n52 21\n2 33\n18 34\n30 51\n5 19\n22 32\n36 28\n42 16\n13 49\n11 17\n31 39\n43 37\n50 15\n29 20\n35 46\n47 23\n3 1\n44 7\n9 27\n6 48\n40 24\n26 14\n45 4\n12 25\n41 38\n",
"output": "2 1\n1 2\n2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n"
},
{
"input": "7\n3 14\n7 4\n13 10\n11 8\n6 1\n5 9\n2 12\n",
"output": "2 1\n2 1\n2 1\n2 1\n2 1\n1 2\n2 1\n"
},
{
"input": "8\n14 2\n7 9\n15 6\n13 11\n12 16\n10 5\n8 1\n3 4\n",
"output": "1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n"
},
{
"input": "4\n4 2\n6 8\n5 1\n3 7\n",
"output": "1 2\n1 2\n2 1\n2 1\n"
},
{
"input": "8\n16 5\n10 15\n8 11\n2 14\n6 4\n7 3\n1 13\n9 12\n",
"output": "1 2\n1 2\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n"
},
{
"input": "23\n46 21\n17 3\n27 38\n34 43\n7 6\n8 37\n22 4\n16 42\n36 32\n12 9\n10 45\n26 2\n13 24\n23 29\n18 15\n33 30\n31 5\n11 25\n1 14\n44 39\n19 20\n35 28\n41 40\n",
"output": "2 1\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n"
},
{
"input": "17\n3 14\n34 22\n24 9\n16 17\n6 30\n33 12\n5 10\n21 8\n32 2\n26 23\n31 27\n19 15\n29 4\n7 18\n25 13\n20 28\n1 11\n",
"output": "1 2\n1 2\n1 2\n2 1\n1 2\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n1 2\n1 2\n2 1\n1 2\n1 2\n"
},
{
"input": "19\n10 7\n9 17\n21 30\n36 8\n14 11\n25 24\n1 23\n38 33\n4 20\n3 37\n27 5\n28 19\n22 2\n6 34\n12 15\n31 32\n35 13\n16 29\n18 26\n",
"output": "1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n1 2\n2 1\n"
},
{
"input": "10\n19 6\n8 2\n15 18\n17 14\n16 7\n20 10\n5 1\n13 3\n9 12\n11 4\n",
"output": "2 1\n1 2\n2 1\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n1 2\n"
},
{
"input": "20\n34 12\n9 6\n5 3\n13 26\n18 15\n16 22\n7 14\n17 37\n38 40\n4 2\n11 23\n21 8\n10 36\n30 33\n28 19\n29 31\n39 20\n35 24\n25 32\n1 27\n",
"output": "1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n"
},
{
"input": "6\n2 7\n5 9\n12 8\n1 4\n3 6\n10 11\n",
"output": "2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n"
},
{
"input": "5\n2 5\n10 9\n1 6\n3 8\n4 7\n",
"output": "2 1\n2 1\n1 2\n1 2\n2 1\n"
},
{
"input": "17\n11 12\n17 22\n34 7\n3 1\n5 24\n18 20\n27 30\n16 33\n23 21\n19 4\n2 15\n29 28\n9 8\n13 25\n6 10\n32 26\n31 14\n",
"output": "1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 1\n1 2\n"
},
{
"input": "15\n21 14\n25 5\n7 28\n2 6\n8 27\n29 18\n9 15\n4 26\n12 1\n19 16\n17 20\n24 10\n11 23\n13 22\n30 3\n",
"output": "1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n"
},
{
"input": "15\n16 22\n4 17\n27 3\n23 24\n18 20\n15 21\n9 7\n2 28\n29 19\n8 30\n14 10\n6 26\n25 11\n12 1\n13 5\n",
"output": "2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n"
},
{
"input": "19\n30 27\n6 38\n10 28\n20 5\n14 18\n32 2\n36 29\n12 1\n31 24\n15 4\n35 11\n3 7\n21 17\n25 19\n16 8\n23 22\n37 33\n13 9\n34 26\n",
"output": "1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n"
},
{
"input": "9\n12 7\n10 15\n16 14\n2 4\n1 17\n6 9\n8 3\n13 5\n11 18\n",
"output": "1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n"
},
{
"input": "5\n4 6\n5 1\n2 3\n7 8\n9 10\n",
"output": "2 1\n2 1\n2 1\n1 2\n1 2\n"
},
{
"input": "2\n2 3\n1 4\n",
"output": "2 1\n1 2\n"
},
{
"input": "24\n30 4\n41 1\n2 11\n22 42\n29 43\n7 14\n16 6\n40 5\n27 34\n46 33\n17 10\n21 39\n28 31\n19 32\n23 20\n25 48\n12 9\n47 37\n38 3\n44 8\n36 18\n13 26\n24 15\n45 35\n",
"output": "1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 2\n1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2\n"
},
{
"input": "17\n17 31\n11 23\n34 22\n24 8\n4 1\n7 14\n20 27\n3 19\n12 26\n32 25\n28 18\n16 29\n21 9\n6 2\n33 30\n5 13\n10 15\n",
"output": "1 2\n1 2\n2 1\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n1 2\n2 1\n2 1\n"
},
{
"input": "4\n2 8\n3 5\n4 7\n1 6\n",
"output": "2 1\n2 1\n1 2\n1 2\n"
},
{
"input": "7\n10 14\n4 6\n1 11\n7 2\n9 8\n5 13\n3 12\n",
"output": "2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n"
},
{
"input": "6\n3 2\n5 11\n7 12\n6 9\n8 4\n1 10\n",
"output": "1 2\n1 2\n2 1\n2 1\n1 2\n1 2\n"
},
{
"input": "8\n10 3\n2 16\n14 13\n5 15\n1 7\n11 8\n6 4\n12 9\n",
"output": "1 2\n2 1\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n"
},
{
"input": "8\n13 6\n10 5\n1 12\n11 15\n7 16\n4 14\n9 2\n8 3\n",
"output": "1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n"
}
] |
code_contests
|
python
| 0 |
d250f761225252389c40828de1c11073
|
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.
To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol a, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with b, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs.
You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation.
Input
In the only line of input there is a string S of lowercase English letters (1 ≤ |S| ≤ 500) — the identifiers of a program with removed whitespace characters.
Output
If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO".
Examples
Input
abacaba
Output
YES
Input
jinotega
Output
NO
Note
In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program:
* replace all occurences of number with a, the result would be "a string a character a string a",
* replace all occurences of string with b, the result would be "a b a character a b a",
* replace all occurences of character with c, the result would be "a b a c a b a",
* all identifiers have been replaced, thus the obfuscation is finished.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
Alphabet = "abcdefghijklmnopqrstuvwxyz"
X = input()
Checked = []
i, Index = 0, 0
while i < len(X):
if X[i] not in Checked and X[i] == Alphabet[Index]:
Checked.append(Alphabet[Index])
Index += 1
elif X[i] not in Checked and X[i] != Alphabet[Index]:
print("NO")
exit()
i += 1
print("YES")
|
python
|
code_algorithm
|
[
{
"input": "jinotega\n",
"output": "NO\n"
},
{
"input": "abacaba\n",
"output": "YES\n"
},
{
"input": "ac\n",
"output": "NO\n"
},
{
"input": "za\n",
"output": "NO\n"
},
{
"input": "bab\n",
"output": "NO\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbabbbabbaaabbaaaaabaabbaa\n",
"output": "YES\n"
},
{
"input": "aacb\n",
"output": "NO\n"
},
{
"input": "darbbbcwynbbbbaacbkvbakavabbbabzajlbajryaabbbccxraakgniagbtsswcfbkubdmcasccepybkaefcfsbzdddxgcjadybcfjtmqbspflqrdghgfwnccfveogdmifkociqscahdejctacwzbkhihajfilrgcjiofwfklifobozikcmvcfeqlidrgsgdfxffaaebzjxngsjxiclyolhjokqpdbfffooticxsezpgqkhhzmbmqgskkqvefzyijrwhpftcmbedmaflapmeljaudllojfpgfkpvgylaglrhrslxlprbhgknrctilngqccbddvpamhifsbmyowohczizjcbleehfrecjbqtxertnpfmalejmbxkhkkbyopuwlhkxuqellsybgcndvniyyxfoufalstdsdfjoxlnmigkqwmgojsppaannfstxytelluvvkdcezlqfsperwyjsdsmkvgjdbksswamhmoukcawiigkggztr\n",
"output": "NO\n"
},
{
"input": "abbb\n",
"output": "YES\n"
},
{
"input": "abd\n",
"output": "NO\n"
},
{
"input": "aac\n",
"output": "NO\n"
},
{
"input": "bbbbbbbbbb\n",
"output": "NO\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazz\n",
"output": "NO\n"
},
{
"input": "z\n",
"output": "NO\n"
},
{
"input": "abb\n",
"output": "YES\n"
},
{
"input": "abcdefghijklmnopqrsuvwxyz\n",
"output": "NO\n"
},
{
"input": "aaaaaaaaad\n",
"output": "NO\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz\n",
"output": "NO\n"
},
{
"input": "acbccccccccccc\n",
"output": "NO\n"
},
{
"input": "abcbcb\n",
"output": "YES\n"
},
{
"input": "aaac\n",
"output": "NO\n"
},
{
"input": "bbbbbb\n",
"output": "NO\n"
},
{
"input": "aaaaaaac\n",
"output": "NO\n"
},
{
"input": "bac\n",
"output": "NO\n"
},
{
"input": "aamlaswqzotaanasdhcvjoaiwdhctezzawagkdgfffeqkyrvbcrfqgkdsvximsnvmkmjyofswmtjdoxgwamsaatngenqvsvrvwlbzuoeaolfcnmdacrmdleafbsmerwmxzyylfhemnkoayuhtpbikm\n",
"output": "NO\n"
},
{
"input": "abcdefghijklmnopqrsutvwxyz\n",
"output": "NO\n"
},
{
"input": "aaaaaaaaaaad\n",
"output": "NO\n"
},
{
"input": "bbb\n",
"output": "NO\n"
},
{
"input": "c\n",
"output": "NO\n"
},
{
"input": "abdefghijklmnopqrstuvwxyz\n",
"output": "NO\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaababaaababaabababccbabdbcbadccacdbdedabbeecbcabbdcaecdabbedddafeffaccgeacefbcahabfiiegecdbebabhhbdgfeghhbfahgagefbgghdbhadeicbdfgdchhefhigfcgdhcihecacfhadfgfejccibcjkfhbigbealjjkfldiecfdcafbamgfkbjlbifldghmiifkkglaflmjfmkfdjlbliijkgfdelklfnadbifgbmklfbqkhirhcadoadhmjrghlmelmjfpakqkdfcgqdkaeqpbcdoeqglqrarkipncckpfmajrqsfffldegbmahsfcqdfdqtrgrouqajgsojmmukptgerpanpcbejmergqtavwsvtveufdseuemwrhfmjqinxjodddnpcgqullrhmogflsxgsbapoghortiwcovejtinncozk\n",
"output": "NO\n"
},
{
"input": "bcddcb\n",
"output": "NO\n"
},
{
"input": "acd\n",
"output": "NO\n"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\n",
"output": "YES\n"
},
{
"input": "ade\n",
"output": "NO\n"
},
{
"input": "aaacb\n",
"output": "NO\n"
},
{
"input": "abcccccccc\n",
"output": "YES\n"
},
{
"input": "bc\n",
"output": "NO\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
"output": "YES\n"
},
{
"input": "acdef\n",
"output": "NO\n"
},
{
"input": "aaaaaaaaaaa\n",
"output": "YES\n"
},
{
"input": "b\n",
"output": "NO\n"
},
{
"input": "abcdefghijklmnopqrstuvwxyzz\n",
"output": "YES\n"
},
{
"input": "bcd\n",
"output": "NO\n"
},
{
"input": "aaaaac\n",
"output": "NO\n"
},
{
"input": "cde\n",
"output": "NO\n"
},
{
"input": "fihyxmbnzq\n",
"output": "NO\n"
},
{
"input": "a\n",
"output": "YES\n"
},
{
"input": "aababbabbaabbbbbaabababaabbbaaaaabbabbabbaabbbbabaabbaaababbaaacbbabbbbbbcbcababbccaaacbaccaccaababbccaacccaabaaccaaabacacbaabacbaacbaaabcbbbcbbaacaabcbcbccbacabbcbabcaccaaaaaabcbacabcbabbbbbabccbbcacbaaabbccbbaaaaaaaaaaaadbbbabdacabdaddddbaabbddbdabbdacbacbacaaaabbacadbcddddadaddabbdccaddbaaacbceebbceadbeaadecddbbbcaaecbdeaebaddbbdebbcbaabcacbdcdc\n",
"output": "YES\n"
},
{
"input": "bb\n",
"output": "NO\n"
},
{
"input": "zx\n",
"output": "NO\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbaabaabaababbbabbacacbbbacbbaaaabbccacbaabaaccbbbbbcbbbacabbccaaabbaaacabcbacbcabbbbecbecadcbacbaadeeadabeacdebccdbbcaecdbeeebbebcaaaeacdcbdeccdbbdcdebdcbdacebcecbacddeeaebcedffedfggbeedceacaecagdfedfabcfchffceachgcbicbcffeeebgcgiefcafhibhceiedgbfebbccegbehhibhhfedbaeedbghggffehggaeaidifhdhaggdjcfjhiaieaichjacedchejg\n",
"output": "NO\n"
},
{
"input": "aabbbd\n",
"output": "NO\n"
},
{
"input": "x\n",
"output": "NO\n"
},
{
"input": "abcdeghijklmnopqrstuvwxyz\n",
"output": "NO\n"
},
{
"input": "abcb\n",
"output": "YES\n"
},
{
"input": "aba\n",
"output": "YES\n"
},
{
"input": "abcdefghijklmnopqrstuvwxy\n",
"output": "YES\n"
}
] |
code_contests
|
python
| 0 |
9e7c029b37a7bf51072ebca14c91e72e
|
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after x is the smallest prime number greater than x. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly x Roman soldiers, where x is a prime number, and next day they beat exactly y Roman soldiers, where y is the next prime number after x, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat n Roman soldiers and it turned out that the number n was prime! Today their victims were a troop of m Romans (m > n). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
Input
The first and only input line contains two positive integers — n and m (2 ≤ n < m ≤ 50). It is guaranteed that n is prime.
Pretests contain all the cases with restrictions 2 ≤ n < m ≤ 4.
Output
Print YES, if m is the next prime number after n, or NO otherwise.
Examples
Input
3 5
Output
YES
Input
7 11
Output
YES
Input
7 9
Output
NO
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
from math import ceil, sqrt
def array(arr, struc):
return (list(map(struc, arr.split())))
def isPrime(x):
for i in range(2, ceil(sqrt(x))+1):
if x % i == 0:
return False
return True
arr = array(input(), int)
prime1 = arr[0]
prime2 = arr[1]
counter = 0
tmp = prime1 + 1
while tmp <= prime2:
if isPrime(tmp):
if tmp == prime2:
counter = 1
print('YES')
break
else:
break
tmp += 1
if counter == 0:
print('NO')
|
python
|
code_algorithm
|
[
{
"input": "7 9\n",
"output": "NO\n"
},
{
"input": "3 5\n",
"output": "YES\n"
},
{
"input": "7 11\n",
"output": "YES\n"
},
{
"input": "2 6\n",
"output": "NO\n"
},
{
"input": "31 33\n",
"output": "NO\n"
},
{
"input": "2 11\n",
"output": "NO\n"
},
{
"input": "41 49\n",
"output": "NO\n"
},
{
"input": "13 17\n",
"output": "YES\n"
},
{
"input": "23 29\n",
"output": "YES\n"
},
{
"input": "7 8\n",
"output": "NO\n"
},
{
"input": "5 13\n",
"output": "NO\n"
},
{
"input": "47 50\n",
"output": "NO\n"
},
{
"input": "43 47\n",
"output": "YES\n"
},
{
"input": "17 19\n",
"output": "YES\n"
},
{
"input": "5 9\n",
"output": "NO\n"
},
{
"input": "2 50\n",
"output": "NO\n"
},
{
"input": "2 3\n",
"output": "YES\n"
},
{
"input": "3 7\n",
"output": "NO\n"
},
{
"input": "13 20\n",
"output": "NO\n"
},
{
"input": "11 13\n",
"output": "YES\n"
},
{
"input": "19 23\n",
"output": "YES\n"
},
{
"input": "5 11\n",
"output": "NO\n"
},
{
"input": "3 9\n",
"output": "NO\n"
},
{
"input": "5 6\n",
"output": "NO\n"
},
{
"input": "23 25\n",
"output": "NO\n"
},
{
"input": "43 49\n",
"output": "NO\n"
},
{
"input": "5 7\n",
"output": "YES\n"
},
{
"input": "3 4\n",
"output": "NO\n"
},
{
"input": "7 13\n",
"output": "NO\n"
},
{
"input": "3 6\n",
"output": "NO\n"
},
{
"input": "37 41\n",
"output": "YES\n"
},
{
"input": "13 15\n",
"output": "NO\n"
},
{
"input": "2 7\n",
"output": "NO\n"
},
{
"input": "5 15\n",
"output": "NO\n"
},
{
"input": "47 48\n",
"output": "NO\n"
},
{
"input": "2 5\n",
"output": "NO\n"
},
{
"input": "31 37\n",
"output": "YES\n"
},
{
"input": "29 31\n",
"output": "YES\n"
},
{
"input": "19 21\n",
"output": "NO\n"
},
{
"input": "2 4\n",
"output": "NO\n"
},
{
"input": "41 43\n",
"output": "YES\n"
},
{
"input": "47 49\n",
"output": "NO\n"
}
] |
code_contests
|
python
| 0.9 |
609a4ac0b42beb6d33f8abba2fb77a98
|
Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.
After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has h2 health points and an attack power of a2. Knowing that, Vova has decided to buy a lot of strong healing potions and to prepare for battle.
Vova's character has h1 health points and an attack power of a1. Also he has a large supply of healing potions, each of which increases his current amount of health points by c1 when Vova drinks a potion. All potions are identical to each other. It is guaranteed that c1 > a2.
The battle consists of multiple phases. In the beginning of each phase, Vova can either attack the monster (thus reducing its health by a1) or drink a healing potion (it increases Vova's health by c1; Vova's health can exceed h1). Then, if the battle is not over yet, the Modcrab attacks Vova, reducing his health by a2. The battle ends when Vova's (or Modcrab's) health drops to 0 or lower. It is possible that the battle ends in a middle of a phase after Vova's attack.
Of course, Vova wants to win the fight. But also he wants to do it as fast as possible. So he wants to make up a strategy that will allow him to win the fight after the minimum possible number of phases.
Help Vova to make up a strategy! You may assume that Vova never runs out of healing potions, and that he can always win.
Input
The first line contains three integers h1, a1, c1 (1 ≤ h1, a1 ≤ 100, 2 ≤ c1 ≤ 100) — Vova's health, Vova's attack power and the healing power of a potion.
The second line contains two integers h2, a2 (1 ≤ h2 ≤ 100, 1 ≤ a2 < c1) — the Modcrab's health and his attack power.
Output
In the first line print one integer n denoting the minimum number of phases required to win the battle.
Then print n lines. i-th line must be equal to HEAL if Vova drinks a potion in i-th phase, or STRIKE if he attacks the Modcrab.
The strategy must be valid: Vova's character must not be defeated before slaying the Modcrab, and the monster's health must be 0 or lower after Vova's last action.
If there are multiple optimal solutions, print any of them.
Examples
Input
10 6 100
17 5
Output
4
STRIKE
HEAL
STRIKE
STRIKE
Input
11 6 100
12 5
Output
2
STRIKE
STRIKE
Note
In the first example Vova's character must heal before or after his first attack. Otherwise his health will drop to zero in 2 phases while he needs 3 strikes to win.
In the second example no healing needed, two strikes are enough to get monster to zero health and win with 6 health left.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
class Character:
def __init__(self, hPoints, attPoints, healPoints):
self.hPoints = hPoints
self.attPoints = attPoints
self.healPoints = healPoints
def attack(self, boss):
boss.setHP(boss.getHP() - self.attPoints)
def recAttack(self, boss):
self.hPoints -= boss.getAP()
def heal(self):
self.hPoints += self.healPoints
def getHP(self):
return self.hPoints
def getAP(self):
return self.attPoints
def getHLP(self):
return self.healPoints
class Boss:
def __init__(self, hPoints, attPoints):
self.hPoints = hPoints
self.attPoints = attPoints
def setHP(self, nextHP):
self.hPoints = nextHP
def getAP(self):
return self.attPoints
def getHP(self):
return self.hPoints
def game(vova, modcrab):
numTurns = 0
vovaHP = vova.getHP()
vovaAP = vova.getAP()
vovaHeal = vova.getHLP()
mcHP = modcrab.getHP()
mcAP = modcrab.getAP()
while mcHP > 0:
if vovaHP - mcAP > 0 or vovaAP >= mcHP:
mcHP -= vovaAP
vovaHP -= mcAP
else:
vovaHP += vovaHeal
vovaHP -= mcAP
numTurns += 1
print(numTurns)
while modcrab.getHP() > 0:
if vova.getHP() - modcrab.getAP() > 0 or vova.getAP() >= modcrab.getHP():
vova.attack(modcrab)
vova.recAttack(modcrab)
print('STRIKE')
else:
vova.heal()
vova.recAttack(modcrab)
print('HEAL')
return
vStats = input().split()
mStats = input().split()
vova = Character(int(vStats[0]),int(vStats[1]), int(vStats[2]))
modcrab = Boss(int(mStats[0]),int(mStats[1]))
game(vova, modcrab)
|
python
|
code_algorithm
|
[
{
"input": "10 6 100\n17 5\n",
"output": "4\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n"
},
{
"input": "11 6 100\n12 5\n",
"output": "2\nSTRIKE\nSTRIKE\n"
},
{
"input": "6 6 100\n12 5\n",
"output": "2\nSTRIKE\nSTRIKE\n"
},
{
"input": "79 4 68\n9 65\n",
"output": "21\nSTRIKE\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL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nHEAL\nHEAL\nSTRIKE\nSTRIKE\n"
},
{
"input": "12 12 19\n83 8\n",
"output": "11\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n"
},
{
"input": "5 12 11\n4 2\n",
"output": "1\nSTRIKE\n"
},
{
"input": "25 27 91\n10 87\n",
"output": "1\nSTRIKE\n"
},
{
"input": "9 76 78\n86 69\n",
"output": "9\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nSTRIKE\nSTRIKE\n"
},
{
"input": "1 1 2\n3 1\n",
"output": "5\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n"
},
{
"input": "9 1 20\n4 19\n",
"output": "53\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nSTRIKE\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nSTRIKE\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL\nSTRIKE\nSTRIKE\n"
},
{
"input": "14 5 2\n99 1\n",
"output": "26\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n"
},
{
"input": "62 21 10\n47 2\n",
"output": "3\nSTRIKE\nSTRIKE\nSTRIKE\n"
},
{
"input": "20 1 5\n8 4\n",
"output": "17\nSTRIKE\nSTRIKE\nSTRIKE\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nHEAL\nHEAL\nHEAL\nSTRIKE\nHEAL\nHEAL\nHEAL\nHEAL\nSTRIKE\nSTRIKE\n"
},
{
"input": "34 14 18\n74 14\n",
"output": "16\nSTRIKE\nSTRIKE\nHEAL\nHEAL\nHEAL\nSTRIKE\nHEAL\nHEAL\nHEAL\nSTRIKE\nHEAL\nHEAL\nHEAL\nHEAL\nSTRIKE\nSTRIKE\n"
},
{
"input": "4 1 2\n10 1\n",
"output": "16\nSTRIKE\nSTRIKE\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n"
}
] |
code_contests
|
python
| 0 |
1228f1b40aa0623c6061db8e6496128a
|
Little town Nsk consists of n junctions connected by m bidirectional roads. Each road connects two distinct junctions and no two roads connect the same pair of junctions. It is possible to get from any junction to any other junction by these roads. The distance between two junctions is equal to the minimum possible number of roads on a path between them.
In order to improve the transportation system, the city council asks mayor to build one new road. The problem is that the mayor has just bought a wonderful new car and he really enjoys a ride from his home, located near junction s to work located near junction t. Thus, he wants to build a new road in such a way that the distance between these two junctions won't decrease.
You are assigned a task to compute the number of pairs of junctions that are not connected by the road, such that if the new road between these two junctions is built the distance between s and t won't decrease.
Input
The firt line of the input contains integers n, m, s and t (2 ≤ n ≤ 1000, 1 ≤ m ≤ 1000, 1 ≤ s, t ≤ n, s ≠ t) — the number of junctions and the number of roads in Nsk, as well as the indices of junctions where mayors home and work are located respectively. The i-th of the following m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi), meaning that this road connects junctions ui and vi directly. It is guaranteed that there is a path between any two junctions and no two roads connect the same pair of junctions.
Output
Print one integer — the number of pairs of junctions not connected by a direct road, such that building a road between these two junctions won't decrease the distance between junctions s and t.
Examples
Input
5 4 1 5
1 2
2 3
3 4
4 5
Output
0
Input
5 4 3 5
1 2
2 3
3 4
4 5
Output
5
Input
5 6 1 5
1 2
1 3
1 4
4 5
3 5
2 5
Output
3
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
from collections import deque
def bfs(s, graph):
q = deque()
d = [0] * len(graph)
used = [False] * len(graph)
used[s] = True
q.append(s)
while len(q):
cur = q[0]
q.popleft()
for to in graph[cur]:
if not used[to]:
used[to] = True
d[to] = d[cur] + 1
q.append(to)
return d
n, m, s, t = map(int, input().split())
graph = [set() for _ in range(n + 1)]
for i in range(m):
u, v = map(int, input().split())
graph[u].add(v)
graph[v].add(u)
ds = bfs(s, graph)
dt = bfs(t, graph)
ans = 0
for u in range(1, n + 1):
for v in range(u + 1, n + 1):
if v not in graph[u] and min(ds[u] + dt[v], dt[u] + ds[v]) + 1 >= ds[t]:
ans += 1
print(ans)
|
python
|
code_algorithm
|
[
{
"input": "5 4 3 5\n1 2\n2 3\n3 4\n4 5\n",
"output": "5\n"
},
{
"input": "5 6 1 5\n1 2\n1 3\n1 4\n4 5\n3 5\n2 5\n",
"output": "3\n"
},
{
"input": "5 4 1 5\n1 2\n2 3\n3 4\n4 5\n",
"output": "0\n"
},
{
"input": "3 3 2 3\n1 2\n2 3\n1 3\n",
"output": "0\n"
},
{
"input": "2 1 2 1\n1 2\n",
"output": "0\n"
},
{
"input": "3 2 2 3\n1 2\n2 3\n",
"output": "1\n"
},
{
"input": "3 2 1 3\n1 2\n2 3\n",
"output": "0\n"
}
] |
code_contests
|
python
| 1 |
32a2ca06543d202e6ca78665eeb932c6
|
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy.
But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.
Input
Input data contains the only number n (1 ≤ n ≤ 109).
Output
Output the only number — answer to the problem.
Examples
Input
10
Output
2
Note
For n = 10 the answer includes numbers 1 and 10.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n=int(input())
a=[]
c=int
for i in range(515):
a.append(c(bin(i)[2:]))
a.remove(0)
ans=0
for i in a:
if i<=n:
ans+=1
print(ans)
|
python
|
code_algorithm
|
[
{
"input": "10\n",
"output": "2\n"
},
{
"input": "100\n",
"output": "4\n"
},
{
"input": "1010011\n",
"output": "83\n"
},
{
"input": "1\n",
"output": "1\n"
},
{
"input": "999999999\n",
"output": "511\n"
},
{
"input": "112\n",
"output": "7\n"
},
{
"input": "101\n",
"output": "5\n"
},
{
"input": "121212121\n",
"output": "511\n"
},
{
"input": "99\n",
"output": "3\n"
},
{
"input": "101010101\n",
"output": "341\n"
},
{
"input": "901556123\n",
"output": "511\n"
},
{
"input": "2\n",
"output": "1\n"
},
{
"input": "312410141\n",
"output": "511\n"
},
{
"input": "1000000000\n",
"output": "512\n"
},
{
"input": "100100\n",
"output": "36\n"
},
{
"input": "111111111\n",
"output": "511\n"
},
{
"input": "100111001\n",
"output": "313\n"
},
{
"input": "745\n",
"output": "7\n"
},
{
"input": "7\n",
"output": "1\n"
},
{
"input": "832513432\n",
"output": "511\n"
},
{
"input": "12\n",
"output": "3\n"
},
{
"input": "111100100\n",
"output": "484\n"
},
{
"input": "732875234\n",
"output": "511\n"
},
{
"input": "23536\n",
"output": "31\n"
},
{
"input": "13\n",
"output": "3\n"
},
{
"input": "9\n",
"output": "1\n"
},
{
"input": "102\n",
"output": "5\n"
},
{
"input": "106341103\n",
"output": "383\n"
},
{
"input": "11\n",
"output": "3\n"
},
{
"input": "3\n",
"output": "1\n"
},
{
"input": "72\n",
"output": "3\n"
},
{
"input": "101020101\n",
"output": "351\n"
},
{
"input": "110100102\n",
"output": "421\n"
},
{
"input": "20\n",
"output": "3\n"
},
{
"input": "110110101\n",
"output": "437\n"
},
{
"input": "111\n",
"output": "7\n"
}
] |
code_contests
|
python
| 0 |
40eb36ac733090ffdcb0ce16d6d00984
|
As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon.
Elections are coming. You know the number of voters and the number of parties — n and m respectively. For each voter you know the party he is going to vote for. However, he can easily change his vote given a certain amount of money. In particular, if you give i-th voter c_i bytecoins you can ask him to vote for any other party you choose.
The United Party of Berland has decided to perform a statistical study — you need to calculate the minimum number of bytecoins the Party needs to spend to ensure its victory. In order for a party to win the elections, it needs to receive strictly more votes than any other party.
Input
The first line of input contains two integers n and m (1 ≤ n, m ≤ 3000) — the number of voters and the number of parties respectively.
Each of the following n lines contains two integers p_i and c_i (1 ≤ p_i ≤ m, 1 ≤ c_i ≤ 10^9) — the index of this voter's preferred party and the number of bytecoins needed for him to reconsider his decision.
The United Party of Berland has the index 1.
Output
Print a single number — the minimum number of bytecoins needed for The United Party of Berland to win the elections.
Examples
Input
1 2
1 100
Output
0
Input
5 5
2 100
3 200
4 300
5 400
5 900
Output
500
Input
5 5
2 100
3 200
4 300
5 800
5 900
Output
600
Note
In the first sample, The United Party wins the elections even without buying extra votes.
In the second sample, The United Party can buy the votes of the first and the fourth voter. This way The Party gets two votes, while parties 3, 4 and 5 get one vote and party number 2 gets no votes.
In the third sample, The United Party can buy the votes of the first three voters and win, getting three votes against two votes of the fifth party.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n, m = map(int, input().split())
pc = [(0, 0) for _ in range(n)]
party_votes = [0 for _ in range(m)]
for i in range(n):
p, c = map(int, input().split())
pc[i] = (p - 1, c)
party_votes[p - 1] += 1
pc.sort(key=lambda x: x[1])
min_cost = 10**20
for votes in range(n + 1):
_party_votes = party_votes[:]
dangerous = list(map(lambda party: _party_votes[party] >= votes, range(0, m)))
used = list(map(lambda i: pc[i][0] == 0, range(n)))
cur_cost = 0
for i in range(n):
if dangerous[pc[i][0]] and pc[i][0] != 0:
cur_cost += pc[i][1]
_party_votes[0] += 1
_party_votes[pc[i][0]] -= 1
dangerous[pc[i][0]] = _party_votes[pc[i][0]] >= votes
used[i] = True
for i in range(n):
if _party_votes[0] >= votes:
break
if not used[i]:
_party_votes[0] += 1
cur_cost += pc[i][1]
min_cost = min(min_cost, cur_cost)
print(min_cost)
|
python
|
code_algorithm
|
[
{
"input": "1 2\n1 100\n",
"output": "0\n"
},
{
"input": "5 5\n2 100\n3 200\n4 300\n5 800\n5 900\n",
"output": "600\n"
},
{
"input": "5 5\n2 100\n3 200\n4 300\n5 400\n5 900\n",
"output": "500\n"
},
{
"input": "5 5\n2 5\n2 4\n2 1\n3 6\n3 7\n",
"output": "10\n"
},
{
"input": "1 3000\n918 548706881\n",
"output": "548706881\n"
},
{
"input": "1 3000\n2006 226621946\n",
"output": "226621946\n"
},
{
"input": "10 2\n1 1\n1 1\n1 1\n1 1\n1 1\n2 1\n2 1\n2 1\n2 1\n2 1\n",
"output": "1\n"
},
{
"input": "5 5\n1 3\n1 6\n5 4\n3 7\n2 10\n",
"output": "0\n"
},
{
"input": "10 10\n1 73\n2 8\n3 88\n1 5\n2 100\n1 29\n1 57\n3 37\n7 46\n3 21\n",
"output": "0\n"
},
{
"input": "5 5\n1 7\n3 3\n2 7\n2 4\n1 2\n",
"output": "3\n"
},
{
"input": "10 10\n5 81\n7 68\n7 48\n1 10\n5 37\n7 97\n8 54\n7 41\n7 56\n5 21\n",
"output": "110\n"
},
{
"input": "10 10\n7 29\n10 31\n9 40\n5 17\n5 30\n6 85\n2 53\n7 23\n4 57\n10 9\n",
"output": "49\n"
}
] |
code_contests
|
python
| 0 |
5dba697fcb6f735cb0d534feef84e067
|
You are given a tube which is reflective inside represented as two non-coinciding, but parallel to Ox lines. Each line has some special integer points — positions of sensors on sides of the tube.
You are going to emit a laser ray in the tube. To do so, you have to choose two integer points A and B on the first and the second line respectively (coordinates can be negative): the point A is responsible for the position of the laser, and the point B — for the direction of the laser ray. The laser ray is a ray starting at A and directed at B which will reflect from the sides of the tube (it doesn't matter if there are any sensors at a reflection point or not). A sensor will only register the ray if the ray hits exactly at the position of the sensor.
<image> Examples of laser rays. Note that image contains two examples. The 3 sensors (denoted by black bold points on the tube sides) will register the blue ray but only 2 will register the red.
Calculate the maximum number of sensors which can register your ray if you choose points A and B on the first and the second lines respectively.
Input
The first line contains two integers n and y_1 (1 ≤ n ≤ 10^5, 0 ≤ y_1 ≤ 10^9) — number of sensors on the first line and its y coordinate.
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — x coordinates of the sensors on the first line in the ascending order.
The third line contains two integers m and y_2 (1 ≤ m ≤ 10^5, y_1 < y_2 ≤ 10^9) — number of sensors on the second line and its y coordinate.
The fourth line contains m integers b_1, b_2, …, b_m (0 ≤ b_i ≤ 10^9) — x coordinates of the sensors on the second line in the ascending order.
Output
Print the only integer — the maximum number of sensors which can register the ray.
Example
Input
3 1
1 5 6
1 3
3
Output
3
Note
One of the solutions illustrated on the image by pair A_2 and B_2.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n, y1 = map(int, input().split())
a = list(map(int, input().split()))
m, y2 = map(int, input().split())
b = list(map(int, input().split()))
a_st, b_st = dict(), dict()
osn = 2 ** 30
k_a, k_b = set(), set()
for el in a:
try:
a_st[el % osn] += 1
except KeyError:
a_st[el % osn] = 1
finally:
k_a.add(el % osn)
for el in b:
try:
b_st[el % osn] += 1
except KeyError:
b_st[el % osn] = 1
finally:
k_b.add(el % osn)
ans = 2
for i in range(1, 31)[::-1]:
temp = 0
for el in k_a:
try:
temp = max(temp, a_st[el] + b_st[(el + osn // 2) % osn])
except KeyError:
temp = max(temp, a_st[el])
for el in k_b:
try:
temp = max(temp, b_st[el] + a_st[(el + osn // 2) % osn])
except KeyError:
temp = max(temp, b_st[el])
ans = max(ans, temp)
osn //= 2
k_ = set()
k_add = set()
for el in k_a:
if el >= osn:
try:
a_st[el - osn] += a_st[el]
except KeyError:
a_st[el - osn] = a_st[el]
finally:
del a_st[el]
k_add.add(el - osn)
k_.add(el)
for el in k_:
k_a.remove(el)
for el in k_add:
k_a.add(el)
k_ = set()
k_add = set()
for el in k_b:
if el >= osn:
try:
b_st[el - osn] += b_st[el]
except KeyError:
b_st[el - osn] = b_st[el]
finally:
del b_st[el]
k_add.add(el - osn)
k_.add(el)
for el in k_:
k_b.remove(el)
for el in k_add:
k_b.add(el)
print(ans)
|
python
|
code_algorithm
|
[
{
"input": "3 1\n1 5 6\n1 3\n3\n",
"output": "3\n"
},
{
"input": "6 94192\n0 134217728 268435456 402653184 536870912 671088640\n6 435192\n67108864 201326592 335544320 469762048 603979776 738197504\n",
"output": "12\n"
},
{
"input": "8 896753688\n106089702 120543561 161218905 447312211 764275096 764710792 813135974 841008065\n8 933908609\n20162935 104158090 483658135 499325847 728277205 735070694 855995285 879244384\n",
"output": "9\n"
},
{
"input": "8 492203512\n98566550 171717746 339893791 370819580 755813098 774632721 775762385 997216159\n8 780893623\n126572826 185519858 200153392 395703045 594904233 795104446 848860665 987834782\n",
"output": "9\n"
},
{
"input": "1 0\n268435456\n2 1\n0 536870912\n",
"output": "3\n"
},
{
"input": "22 369666\n1 9 17 25 33 41 49 57 65 73 81 89 97 105 113 121 129 137 145 153 161 169\n16 492689\n5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65\n",
"output": "30\n"
},
{
"input": "8 252920536\n244638831 495795451 571294469 608283654 824658394 848820488 889026403 989575878\n8 536603650\n173809980 459083932 618916368 671025009 824972497 845836688 910492805 996913393\n",
"output": "8\n"
},
{
"input": "1 1\n0\n1 2\n0\n",
"output": "2\n"
},
{
"input": "8 670286936\n388336854 391155719 408017710 459915835 583763838 598232267 651837043 677546042\n8 739744483\n77918488 346255845 684268992 706730425 729280923 764781472 851729309 960597662\n",
"output": "8\n"
},
{
"input": "2 32871\n0 268435456\n2 244027\n134217728 402653184\n",
"output": "4\n"
},
{
"input": "8 13637560\n75803938 118458082 578587112 599074426 675903899 825712388 835922815 876673516\n8 823205164\n54450960 552515514 586968563 590678437 611812464 705676588 725408561 901537037\n",
"output": "10\n"
},
{
"input": "8 553403064\n90389644 110886835 224843533 416499061 494331076 500074828 631337283 827633884\n8 657307279\n149565245 163218715 233843732 346670915 508274748 782271108 878164651 972834939\n",
"output": "9\n"
},
{
"input": "5 999999999\n999999996 999999997 999999998 999999999 1000000000\n5 1000000000\n999999996 999999997 999999998 999999999 1000000000\n",
"output": "5\n"
},
{
"input": "2 0\n0 2\n4 1000000000\n0 2 4 6\n",
"output": "4\n"
},
{
"input": "1 828613\n0\n1 951087\n268435456\n",
"output": "2\n"
},
{
"input": "1 1\n1\n1 2\n1\n",
"output": "2\n"
},
{
"input": "13 968288\n0 67108864 134217728 201326592 268435456 335544320 402653184 469762048 536870912 603979776 671088640 738197504 805306368\n13 986214\n33554432 100663296 167772160 234881024 301989888 369098752 436207616 503316480 570425344 637534208 704643072 771751936 838860800\n",
"output": "26\n"
},
{
"input": "8 136036664\n126269260 262156105 282965964 352160984 697058273 782155472 852153700 917928159\n8 683144774\n61397867 113538443 319336093 384894230 392472203 597064745 621785013 743973848\n",
"output": "11\n"
},
{
"input": "1 1\n1\n1 3\n1\n",
"output": "2\n"
},
{
"input": "8 314120088\n96023745 125339289 248259794 279673378 308309305 545296057 624420255 846280440\n8 567898834\n218919064 398609068 402104390 521955395 551024729 612549267 863097158 874451603\n",
"output": "9\n"
},
{
"input": "1 2\n1\n1 3\n1\n",
"output": "2\n"
},
{
"input": "8 369804408\n295549995 297155803 364413607 495086842 522088849 729029685 791692715 987594669\n8 773248229\n167810330 261639682 321080432 453152328 502142334 643215633 657539609 917625873\n",
"output": "12\n"
},
{
"input": "8 934901355\n37124098 77222116 138199181 249214100 487897674 738878092 880827398 954080351\n8 945722121\n54836744 340149103 518507628 534560545 659693096 807080067 837037908 971967276\n",
"output": "9\n"
},
{
"input": "1 100\n0\n1 200\n0\n",
"output": "2\n"
}
] |
code_contests
|
python
| 0 |
5af360f095c88bb8bfc66dfa58dd65a1
|
Lunar New Year is approaching, and Bob is struggling with his homework – a number division problem.
There are n positive integers a_1, a_2, …, a_n on Bob's homework paper, where n is always an even number. Bob is asked to divide those numbers into groups, where each group must contain at least 2 numbers. Suppose the numbers are divided into m groups, and the sum of the numbers in the j-th group is s_j. Bob's aim is to minimize the sum of the square of s_j, that is $$$∑_{j = 1}^{m} s_j^2.$$$
Bob is puzzled by this hard problem. Could you please help him solve it?
Input
The first line contains an even integer n (2 ≤ n ≤ 3 ⋅ 10^5), denoting that there are n integers on Bob's homework paper.
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^4), describing the numbers you need to deal with.
Output
A single line containing one integer, denoting the minimum of the sum of the square of s_j, which is $$$∑_{i = j}^{m} s_j^2, where m$$$ is the number of groups.
Examples
Input
4
8 5 2 3
Output
164
Input
6
1 1 1 2 2 2
Output
27
Note
In the first sample, one of the optimal solutions is to divide those 4 numbers into 2 groups \{2, 8\}, \{5, 3\}. Thus the answer is (2 + 8)^2 + (5 + 3)^2 = 164.
In the second sample, one of the optimal solutions is to divide those 6 numbers into 3 groups \{1, 2\}, \{1, 2\}, \{1, 2\}. Thus the answer is (1 + 2)^2 + (1 + 2)^2 + (1 + 2)^2 = 27.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n = int(input())
a = [int(s) for s in input().split(" ")]
a.sort()
ans = 0
for i in range(n//2):
ans += (a[i]+a[n-i-1])**2
print(ans)
|
python
|
code_algorithm
|
[
{
"input": "6\n1 1 1 2 2 2\n",
"output": "27\n"
},
{
"input": "4\n8 5 2 3\n",
"output": "164\n"
},
{
"input": "100\n28 27 23 6 23 11 25 20 28 15 29 23 20 2 8 24 8 9 30 8 8 1 11 7 6 17 17 27 26 30 12 22 17 22 9 25 4 26 9 26 10 30 13 4 16 12 23 19 10 22 12 20 3 16 10 4 29 11 15 4 5 7 29 16 3 1 7 16 26 14 28 1 15 19 30 28 5 22 14 28 13 12 11 30 3 4 7 10 22 8 4 10 22 12 17 27 23 11 18 7\n",
"output": "48573\n"
},
{
"input": "4\n10000 10000 10000 10000\n",
"output": "800000000\n"
},
{
"input": "50\n9 16 3 3 12 2 9 13 6 11 18 15 6 20 14 13 20 5 19 4 10 2 10 19 20 3 15 3 9 1 9 4 16 3 19 14 12 13 12 5 9 16 4 1 8 20 8 2 11 5\n",
"output": "10075\n"
},
{
"input": "8\n726 372 2425 5063 3153 1702 1658 4692\n",
"output": "99071799\n"
},
{
"input": "2\n4556 1770\n",
"output": "40018276\n"
},
{
"input": "50\n1321 1464 2036 1106 9084 9681 8004 2941 4653 6863 3870 6695 6163 7996 7749 2372 7339 9621 6688 3083 4373 2443 3513 296 4119 5189 5183 1532 5352 2733 3573 3528 4854 9807 2817 3830 8785 3229 9886 736 5389 733 394 55 2820 9417 2744 1517 7778 1118\n",
"output": "2069788730\n"
},
{
"input": "4\n9540 7069 4914 2241\n",
"output": "282384250\n"
},
{
"input": "2\n1 1\n",
"output": "4\n"
},
{
"input": "10\n2978 1695 4979 2943 3114 9622 3446 4871 8308 5427\n",
"output": "459972653\n"
},
{
"input": "6\n7229 5073 766 748 4111 3544\n",
"output": "156325475\n"
},
{
"input": "2\n10000 10000\n",
"output": "400000000\n"
},
{
"input": "20\n8 10 10 1 1 5 9 2 1 5 4 3 4 4 2 10 3 9 9 4\n",
"output": "1096\n"
}
] |
code_contests
|
python
| 1 |
f4419709729fa1b9daee771333429119
|
You are given two arrays a and b, each contains n integers.
You want to create a new array c as follows: choose some real (i.e. not necessarily integer) number d, and then for every i ∈ [1, n] let c_i := d ⋅ a_i + b_i.
Your goal is to maximize the number of zeroes in array c. What is the largest possible answer, if you choose d optimally?
Input
The first line contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in both arrays.
The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≤ a_i ≤ 10^9).
The third line contains n integers b_1, b_2, ..., b_n (-10^9 ≤ b_i ≤ 10^9).
Output
Print one integer — the maximum number of zeroes in array c, if you choose d optimally.
Examples
Input
5
1 2 3 4 5
2 4 7 11 3
Output
2
Input
3
13 37 39
1 2 3
Output
2
Input
4
0 0 0 0
1 2 3 4
Output
0
Input
3
1 2 -1
-6 -12 6
Output
3
Note
In the first example, we may choose d = -2.
In the second example, we may choose d = -1/13.
In the third example, we cannot obtain any zero in array c, no matter which d we choose.
In the fourth example, we may choose d = 6.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
from fractions import Fraction
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count = {}
ans = 0
zeros = 0
for i in range(n):
if A[i] == 0 and B[i] != 0:
continue
elif A[i] == 0 and B[i] == 0:
zeros += 1
else:
temp = Fraction(abs(B[i]), abs(A[i]))
if A[i] > 0 and B[i] > 0:
temp *= -1
elif A[i] < 0 and B[i] < 0:
temp *= -1
temp = str(temp)
if temp not in count:
count[temp] = 1
else:
count[temp] += 1
ans = max(ans, count[temp])
print(ans + zeros)
# for i in range(n):
# if A[i] == 0 and B[i] != 0:
# continue
# elif A[i] == 0 and B[i] == 0:
# temp = 0
# else:
# temp = Fraction(abs(B[i]), abs(A[i]))
# if A[i] > 0 and B[i] < 0:
# pass
# elif A[i] < 0 and B[i] < 0:
# temp *= -1
# elif A[i] > 0 and B[i] > 0:
# temp *= -1
# elif A[i] > 0 and B[i] < 0:
# pass
# temp = str(temp)
# if temp not in count:
# count[temp] = 1
# else:
# count[temp] += 1
# ans = max(ans, count[temp])
|
python
|
code_algorithm
|
[
{
"input": "4\n0 0 0 0\n1 2 3 4\n",
"output": "0\n"
},
{
"input": "5\n1 2 3 4 5\n2 4 7 11 3\n",
"output": "2\n"
},
{
"input": "3\n13 37 39\n1 2 3\n",
"output": "2\n"
},
{
"input": "3\n1 2 -1\n-6 -12 6\n",
"output": "3\n"
},
{
"input": "5\n-2 2 1 0 2\n0 0 2 -1 -2\n",
"output": "2\n"
},
{
"input": "4\n0 1 2 3\n0 0 0 3\n",
"output": "3\n"
},
{
"input": "2\n0 1000000000\n0 0\n",
"output": "2\n"
},
{
"input": "3\n999999999 999999998 999999999\n999999998 999999997 999999998\n",
"output": "2\n"
},
{
"input": "2\n0 0\n0 0\n",
"output": "2\n"
},
{
"input": "2\n999999999 1000000000\n999999998 999999999\n",
"output": "1\n"
},
{
"input": "3\n0 5 7\n0 10 13\n",
"output": "2\n"
},
{
"input": "14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "14\n"
},
{
"input": "2\n1 13\n1 3\n",
"output": "1\n"
},
{
"input": "5\n-999999999 999999999 999999999 999999998 -999999999\n-999999999 -1000000000 -1000000000 -999999999 1000000000\n",
"output": "3\n"
},
{
"input": "2\n999999998 999999999\n999999999 1000000000\n",
"output": "1\n"
}
] |
code_contests
|
python
| 0 |
9a9bed225b2731d410001953d5da4110
|
You are both a shop keeper and a shop assistant at a small nearby shop. You have n goods, the i-th good costs a_i coins.
You got tired of remembering the price of each product when customers ask for it, thus you decided to simplify your life. More precisely you decided to set the same price for all n goods you have.
However, you don't want to lose any money so you want to choose the price in such a way that the sum of new prices is not less than the sum of the initial prices. It means that if you sell all n goods for the new price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.
On the other hand, you don't want to lose customers because of big prices so among all prices you can choose you need to choose the minimum one.
So you need to find the minimum possible equal price of all n goods so if you sell them for this price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.
You have to answer q independent queries.
Input
The first line of the input contains one integer q (1 ≤ q ≤ 100) — the number of queries. Then q queries follow.
The first line of the query contains one integer n (1 ≤ n ≤ 100) — the number of goods. The second line of the query contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^7), where a_i is the price of the i-th good.
Output
For each query, print the answer for it — the minimum possible equal price of all n goods so if you sell them for this price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.
Example
Input
3
5
1 2 3 4 5
3
1 2 2
4
1 1 1 1
Output
3
2
1
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import math
for _ in range(int(input())):
k=int(input())
l=list(map(int,input().split()))
k=sum(l)/k
print(math.ceil(k))
|
python
|
code_algorithm
|
[
{
"input": "3\n5\n1 2 3 4 5\n3\n1 2 2\n4\n1 1 1 1\n",
"output": "3\n2\n1\n"
},
{
"input": "3\n5\n1 2 3 4 5\n3\n1 2 3\n2\n777 778\n",
"output": "3\n2\n778\n"
},
{
"input": "1\n2\n777 778\n",
"output": "778\n"
},
{
"input": "1\n2\n777 1\n",
"output": "389\n"
},
{
"input": "1\n1\n2441139\n",
"output": "2441139\n"
}
] |
code_contests
|
python
| 0.9 |
830c6aea010a6761ea8850017224cb84
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string s consisting of n lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in s).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 200) — the length of s.
The second line of the input contains the string s consisting of exactly n lowercase Latin letters.
Output
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of n characters, the i-th character should be '0' if the i-th character is colored the first color and '1' otherwise).
Examples
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
n = int(input())
s = input()
indexes = [[] for i in range(26)]
for i in range(len(s)):
indexes[ord(s[i])-97] += [i]
#print(indexes)
order = [0]*n
count = 1
for each in indexes:
incount = False
for k in each:
incount=True
order[k] = count
if incount:
count += 1
coloring = ['']*n
opposites = [[] for i in range(n+1)]
#print(order, opposites)
for i in range(n):
for j in range(i+1, n):
if order[i] > order[j]:
#print(i, j)
for k in range(i, j):
opposites[j] += [i]
opposites[i] += [j]
coloring[0] = '0'
def opp(x): return '0' if x == '1' else '1'
poss = True
for i in range(n):
if not coloring[i]:
coloring[i] = '0'
for k in opposites[i]:
#print(i, k, coloring)
if coloring[k] == '':
coloring[k] = opp(coloring[i])
else:
if coloring[k] != opp(coloring[i]):
poss = False
break
if poss:
print('YES')
print(''.join(coloring))
else:
print('NO')
|
python
|
code_algorithm
|
[
{
"input": "7\nabcdedc\n",
"output": "NO\n"
},
{
"input": "9\nabacbecfd\n",
"output": "YES\n001010101\n"
},
{
"input": "5\nabcde\n",
"output": "YES\n00000\n"
},
{
"input": "8\naaabbcbb\n",
"output": "YES\n00000011\n"
},
{
"input": "6\nqdlrhw\n",
"output": "NO\n"
},
{
"input": "500\nxwxpgalijfbdbdmluuaubobxztpkfnuparzxczfzchinxdtaevbepdxlouzfzaizkinuaufhckjvydmgnkuaneqohcqocfrsbmmohgpoacnqlgspppfogdkkbrkrhdpdlnknjyeccbqssqtaqmyamtkedlhpbjmchfnmwhxepzfrfmlrxrirbvvlryzmulxqjlthclocmiudxbtqpihlnielggjxjmvqjbeozjpskenampuszybcorplicekprqbsdkidwpgwkrpvbpcsdcngawcgeyxsjimalrrwttjjualmhypzrmyauvtothnermlednvjbpgkehxbtbpxolmaapmlcuetghikbgtaspqesjkqwxtvccphjdqpuairsaypfudwvelmupbzhxwuchnfumcxmhflkpyzeppddtczbcjrookncgtojmujyvponennuudppqwwjtnwpgapokwzvbxohrdcvcckzbcrwwvfqlbnwbnmmvh\n",
"output": "NO\n"
},
{
"input": "200\naadfgghjjjkmnpqqtuuwwxyzaaaaaaaabbbbbbbbcccccddddeeeeeeeeeffgggghhhhhhiiiiiiiijjjjjjjjkkkkklllllmmmmmmmmmmmnnnnnoooooppppppppqqqqqqqqrrrrrrrrrrrssssstttttttttuuuuuuuuvvvvvvvwwwwwwxxxxxxxyyyyyzzzzzzzzz\n",
"output": "YES\n00000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000\n"
},
{
"input": "4\nzcza\n",
"output": "NO\n"
},
{
"input": "200\naaaaabbbbbbbbbbbccccccdddddddddeeeeeefffffffffggggggggggggggghhhhhhhhhiiiiijjjjjjjjjjjkkkkkklllllllmmmmmmmmmnnnnnnnnnnoooooppppppqqqqqqqrrrrrssssssstttttuuuuuuuuvvvvwwwwwwwwwwwwxxxxxxyyyyyyzzzzzzzzzmu\n",
"output": "YES\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011\n"
},
{
"input": "1\nr\n",
"output": "YES\n0\n"
},
{
"input": "200\naaaaaabbbbbbbbbbbbbccccccccccccdddeeeeeeffffggghhhhhhhhhiiiiiiiijjjjjjjjjjkkkkklllllmmmmmmmmmnnnnnnnoooooooppppppppqqqqqqrrrrrrrrrsssssssttttttttuuuuuuuuvvvvvvvvwwwwwwxxxxxxxyyyyyyyyyyzzzzzzzzzzzeinuy\n",
"output": "YES\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111\n"
},
{
"input": "200\naaaaaaabcbbbbcccccdccdcdddddeeddeeeeeeeeeefffffffggghgghghhhhhhhihhhiiiiiiiijijijjjjkjkkkkkkkklkkllllllllmmmmmmmmmmmnnnnnnnnoooppnqnnqoqroooorsoppqqstttqruuurruvrrvvtvttvvtuwvwwwwxxxwxyzzxzzyyzzyyzzzz\n",
"output": "YES\n00000000011110000001101000000011000000000000000000000110100000000111000000000101000001000000000110000000000000000000000000000000010110100111100111110000110001100110010110011010000000100001001100110000\n"
},
{
"input": "200\ntoimpgygoklxroowdhpacrtrrwmkhcgcpidapeyxrjmiqgilveimnazyydvnujtqpenfkeqdbylfdinompxupfwvirxohaampqihjueasygkucweptgcowjibgnwyqetynykgoujeargnhjbmntfovwusqavpdwtpnpqpkcgaxbhgdxloyealksmgkxprtpfugixdyfn\n",
"output": "NO\n"
},
{
"input": "5\nadcbz\n",
"output": "NO\n"
},
{
"input": "200\nraaaaabbbccccccccccdddddeeeeeeeeeeeeeeffffffffffggggggggghhhhhiiiiiiiiijjjjkkkkkkkkkkllllllllmmmmmmmmnnnnnnnooooooooppppppqqqqqqqqqqrrrrrrrrssssttttttttttuuuuuuuuvvvvvvwwwwwwxxxxxxxyyyyyyyzzzzzzzzzzzz\n",
"output": "YES\n01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "200\naaaaaadeafgibbbbbbjbjlncpccccsdsdddtdtdtdeetuevwwezzefffffgggghhhhhhhiijjjjjjjjkkklllllllmmmmmmmmmmmmmnnnnnnnooooooooopppppppppppppqqqqrrrrrrsssssssttttttttttuuuuuuuuuvvvvvvvwwwwwwxxxxxyyyyyyyyyzzzzzz\n",
"output": "YES\n00000000100011111101000101111010111010101110010001001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000\n"
},
{
"input": "200\nftiqlgirbkmlpzkthoivcifhflyietxsfiwiojenqgxrnetzutdsyfuhrbfpedyksfzuvnqonbyydogbrwsfuuivboanufitbjngppagzfgqwyroaofcdgrwoxwfpvcgzdnkhnwtlavnoppdbddpfpcaaipdcqskcqtccrrspvjyqpvjwziexnmmnlqvacdpgnzzhude\n",
"output": "NO\n"
},
{
"input": "200\nazaaaaaabbbbbbbcccccccccdeeeeeeefffffffgggggggghhhhhhiijjjjjkkkkkkkkkllllllmmmmmmmmmmmmnnnnnnoooooopppppppppppqqqqqrrrrrrrrrrrrrssssssssssstttttttttttuuuuuuuuvvvvvvvwwwwwwwwwxxxxxxxyyyyyyyyyyyyzzzzzzz\n",
"output": "YES\n00111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000\n"
},
{
"input": "100\neivzgzvqvlgzdltwjcmpublpvopzxylucxhrrltwmizxtdxdrnmuivvcewvaunkqmnjgqgcwdphbvapebhkltmkfcslvgmnqoseu\n",
"output": "NO\n"
},
{
"input": "3\nedc\n",
"output": "NO\n"
},
{
"input": "30\nlpxzyiymhgfemqbhburdctevpybxlv\n",
"output": "NO\n"
},
{
"input": "200\naaaaeillaoobbwbbxbzbbcccccccdddddddddeeeeeeeffffffffggggghhhhhiiiijjjjjjjkkkkklllllmmmmmmmmmnnnnnnnnnnnnnooooooooppppqqqqqqqqqqrrrrrrrrrrrsssssssssttttttttttuuuuuuuvvvvvvvwwwwwwwxxxxxxyyyyzzzzzzzzzzzz\n",
"output": "YES\n00000000100110110101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000000\n"
},
{
"input": "37\nxxxxxxxxxxxxxaaaaaaaaaaaccccccccccacx\n",
"output": "NO\n"
},
{
"input": "4\nhcha\n",
"output": "NO\n"
},
{
"input": "100\nyojtyktazyfegvnnsexxiosqxdlpdwlyojsghpvjpavnvjvttbylqcdabyhleltltzalmgoelxdalcbjejsjxnfebzsxusnujdyk\n",
"output": "NO\n"
},
{
"input": "8\naaabbcbb\n",
"output": "YES\n00000011\n"
},
{
"input": "30\nxsvbtliwvggtjbvdebjwcirlfnnuio\n",
"output": "NO\n"
},
{
"input": "200\naaaabbbbcceefffgghhhhijjllnnnnopqrrsstuuvvvwwxxyyyaaaabbbbbbbbcccdddddeeeeeefffffggggghhhhhhhhhiiiiiiiiijjjjkkkkkkllllllmmmmmmmnnnnnoooooooopppppppqqqrrrrrrsssssstttttuuuuuuuvvvvvwwwxxxxxyyyyzzzzzzzzz\n",
"output": "YES\n00000000000000000000000000000000000000000000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000\n"
},
{
"input": "200\nfhrvyaaaaaaaaabbbbbbbccccccccccdddddeeeeeeeeeeeeefffffggggggghhiiiiiiiiiiiijjjjjkkkklllllllmmmmmmmmnnnnnoooooppppppppqqqrrrrrrrrrrsssssssstttttttttttttuuuuuuuvvvvvvwwwwwwwwwwwwwwxxxxxxyyyyyyyyzzzzzzzz\n",
"output": "YES\n00000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000\n"
},
{
"input": "200\njaaaabbbbbbccccccccccccdddddddddddeeeeeeffffffggggghhhhhhhiiiijjjjjjjjjkkkkkkkkkkkllllllllllllmmmmmmmmmmmnnnooooppppppqqqqqqqqqqqqqqrrrrrrrrrrrrsssssttttttuuuuuuuvvvvvwwwwwwwwwwwwxxxxxxxyyyyyyyyzzzzzz\n",
"output": "YES\n01111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "4\ncbca\n",
"output": "NO\n"
},
{
"input": "200\naaaabbbbbbcccccdddddeeeeeeeffffggggggggghhhhhiiiiijjjjjjjkkkkkkkkllmmmmmmmmmmnnoooooppppqqqqqrrrrrrsssssttttttttttttuuuvvvvvwwwwwwxxxxxxxxyyyzzzzzzzzzaccddddeeffgjjjjkkklllllmmmmnnooppqrrsssttwwxyyzzz\n",
"output": "YES\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111000\n"
},
{
"input": "500\ndqkumomydseavvuukspjmbvtwbtsaquomfojmvcmzokytzyhbhsmhwonrqnuocadbwvpdwtxvanwiacyijmdjbwpgvkllzrpgbuyekvmkmzwnnvetlrodcxaitkrsakkaxuajkhdmmjqtpehyyzelygbdzsauqgnnvveoeulmufgeqxqfiqxuckbbbyxinwtbtewhvycarhunsebyznqxskdqvwtvdelnpmhfagvmouidoytfwnpxjnmgabudblycswciftoeeuxpnyicfibfutvnadvretbunshkdpaxtzzyxbpyzyxynyjjhgwyshjkksvbcffveldqwqevmpnemtzxuomtewvsrqdrmqmbkruartebmvjqaksbhotfbysoorthvattezazpvxrytlzurpfkjscnkitkjvhlirzbnsoujicmrvaecespknvkjufsudkiznsyatgbtkebqpycukbcdqxdwqicrhphbiiesxftkicwsx\n",
"output": "NO\n"
},
{
"input": "200\naaabbsbbbbbbbbbbbbbcccccccccdddddddddddddeeeeeeeeffffffffgggggggggghhhhhhhhhhhhijjjjjjjjjjkkkkkkllllmmmmmnnnnnnoooooooppppppqqqqqqqqqqqqrrrrrsssssssssttttttuuuuuuvvvvvvvvvwwwwwwxxxxxxyyyyyyzzzzzzzzzzz\n",
"output": "YES\n00000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "6\ncbaabc\n",
"output": "NO\n"
},
{
"input": "200\nbdimoqrstvaaaaaaaaabbbbbbbbbbcccccddddddeeeeeeeeeeeeeeeffffffgggggggghhhhhhhhhiiiiiiiijjjjjjjjjjjjkkkkkkkklllllllllmmmmmmmmnnnnnoooooooppppppqqqqqqrrrrrrrrssssssstttttuuvvvvvvwwwwwwwwxxxxxxxyyyyyyyzzz\n",
"output": "YES\n00000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000000000000000\n"
},
{
"input": "5\ncbbda\n",
"output": "NO\n"
},
{
"input": "200\naaaabccccdddddddeefffffffgghhhiiiiiijjjjjjjkkkkkllllmmmmnnnnnoooooooppqqqqqrrrrsssttuuuuuvwwxxyyyzzzaaaaaabbbbbccccddddddeefffffffggghhiiiikkllmmnnnnnnoooooppppqqqqrrrrsttttuuuuuvvvvwwwwwwxxxxyyyzzzzz\n",
"output": "YES\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n"
},
{
"input": "200\naaaaaaaaabbbbcccccccccccdddeeeeeeeefffgggghhhhhhhhiiiiiiijjjjjjjkkklllmmmmmnnnnnnnoooooppppppppqqqqrrrrrrrssssssttttuuuuuuvvvvvwwwwxxxxxxyyyyyzzzzzzzzaabbbcccdeeefggggghhhhiijjjjkllnpqqqrrsssstuuvwyzz\n",
"output": "YES\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111100\n"
},
{
"input": "4\ndcda\n",
"output": "NO\n"
},
{
"input": "200\naaaaaaaaaabbbbbbccccccddddddddddddeeeeeeeeeeffffffffggggghhhhhhiiijjjjjjkkkkkklllllllllllllmmmmmmmnnnnnooooooooooppppppppppqqqqqqqqqrrrrrrrrsssssstttttttttuuuuvvvvvvwwwwwwwwwwwxxxxxyyyyyyyyyyzzzzzzzzw\n",
"output": "YES\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n"
},
{
"input": "200\naaaabbbbbbccccddddefffffgghhhiiiiiiiiijjjjjkkklmmmmnnnnnnooopppppppprrrstuuuuuuvvvvvvvwwxxxxyyyyyyzzaabbbbbbcccdddddddddeffggggghhhhhhiiijjjjjjkkkkllllmmmnnnoopqqqrrssssttttuuuvvvvvwwwwwxxxxyyyyyzzzzz\n",
"output": "YES\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000\n"
},
{
"input": "9\nbefblmbhg\n",
"output": "NO\n"
},
{
"input": "200\naaaaaaabbbbbbcccccccccdddddddeeeeffffffggggghhhhhiiiiiiiijjjjkkkkkllllllllmmmmmmmmmnnnnnnnnnooooooooopppppppppqqqqqqqqrrrrrrrrrrrsssssssttttuuvvvvvvvvvvwwwwwwwxxxxxxyyyyyyzzzzzbceghhhijjjmmooqrrttvvwx\n",
"output": "YES\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111111111\n"
},
{
"input": "200\nndwpatpnvwldptairxlxqmzzysfvglpjkwbebtosqvfnoebfvxfpupvohcaazsjbdshoducigmfoqzltdgvmdmputqmoaqscilmtafqrxdunwnijhrtbwonpvpeouednmjswhauahmgyozmbiilxxflkkmwywvuojbrwwbkyhxtdywiktkfcsmozklhrwlwyajekejrx\n",
"output": "NO\n"
},
{
"input": "200\naaaaaaaaaabbbbbccccccccccccccdddddddddeeeeeeefffffffffgggggghhhhhhiiiiiiijjjjjjjjjjkkkkkkllllllllmmmmmmmmnnnnnnoooooooppppppqqqqqqqqqqqrrrrrrsssssssttttttttuuuuuuvvvvvwwwwwxxxyyyyzzzzzzzzzzzcddddjksvw\n",
"output": "YES\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111\n"
},
{
"input": "1\na\n",
"output": "YES\n0\n"
},
{
"input": "100\nkshxumdmoygtdgjkwmpsiffhoswmapcogjkngvcznwhtufgjstqrbgwjtxrnoevhwaoaxporxbnrijtwkqnteergtvvwkxvbvwch\n",
"output": "NO\n"
},
{
"input": "200\nzywmerhahxlqsjekpqsdqxnjiduyjrytswiweohctztgpiorwimhjmdfofqynyggcrtzslbyvkuvqrsgwyacyvcuathplliwwshusluiqwuhutnzwvuchfedhwwfdzizltdxibtsaocpnqezstblgkfdcvfsjjyzwalkksumsaljqljmmkcyejwwdkolmcgmodoiclte\n",
"output": "NO\n"
},
{
"input": "500\nlbwrbavuwfcryqijwcsoafplpiafchmfrrrfagmracruvzendlvjbhqvgskhjtksnjbglefsqmwmwleturpkutdqyxunrkzznfrlnzlvijntlckzaleovnsvpksawjlqndzoixhmjbuysxbffcimcorlndwxowittgtyiomqewnkmxkpdunvnynoybqtdunavsjhgkmtdwugqmaqnduocxzpeqimjguwnjbkvmstekjpppwcuhabmdemqskzrgorgfbuxlsccxsmsrtxgeppwenecutwhxxfevjtxipmsbymvjsprftfqqndumwtissszzzewtbwyeijkvcifexnuzjmtgrilojhrtdaefhwumwafcujhrqlntzqoubqazzmfsbwlvkqijfahdgokzyuskplbkzgomdweqttoqduzurxnslagqgmgywbojnfjuiiattdmuxqmtgrkypqhpxszroffmimhbheasenpvzerzpzamhbealj\n",
"output": "NO\n"
},
{
"input": "200\naaawaaaabbbbccccccccddddddddddeeeeeeeffffffffffgggggggggghhhhhhhhiiiiiiiiijjjjjjjkkkkkkkkklllllllmmmmmmmmnnnnnnooooooooppppppppqqqqrrrrrrrsssssssttttttuuuuuuuuuvvvvvvvvvwwwwwwwxxxxxxxyyyyyyyzzzzzzzzzz\n",
"output": "YES\n00001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000000000000000\n"
},
{
"input": "200\naaaabccdeffgghhijklllmnnnoopqrrrrssssssttuuvvvwxyyaaaabbbcccccddddddeeeeeeffffgggggghhhhiiiiiiiiiiijjjjjjjjjkkkkllmmmmmmmmnnoooooooooooppppppppppqqqqqqrrrsssstttttuuuuvvvvwwwwwwwxxxxxxxxxyyyyyyyyyyzzz\n",
"output": "YES\n00000000000000000000000000000000000000000000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000\n"
},
{
"input": "500\ndhlmtnvecsbwbycahddxnvwpsxwxgfmidfetpkpeevpjzfbgfafbjpyuevupuptoxutnketcxwrllooyxtxjzwxpzcbpiqzeiplcqvdxyyznjxgkwstpxogdihsamoqhyspbjlelxpbarzqawsgidjtmnpmmupohnslirorliapvntasudhpuuxynyoipuqxdiysbyctpmfpbxqfdlmlsmsvtbxoypkbhwrtpwbsbcdhypsbqhqpdlilquppdwsszrpavcowudreygmpwckbzlpnxxqxjdpqmtidjatvgcbxjrpqqxhhsvlpyxxkoqxutsvebrlxqeggvsnshetkpnfygpwbmnuujfvqnlgavwppufxadhxtffsrdknfmqbsjjegcwokbauzivhnldkvykkytkyrwhimmkznkkofcuioqmpbshskvdhsetyidubcgvuerbozqfbkcmaguaszaivtuswzmtnqcpoiqlvronibiqyeoqms\n",
"output": "NO\n"
},
{
"input": "200\naaaabbbbabcaccaadbebfbbbfgbbggchhcccchhhcccicjdkkldldddldmdenoeeooffpppfqrfffuuufggguvgggvggwghhxhyyyhhhhzhiiiiiiijjjjjjjkkkllmmmnnnooooppppppppppppqqqqrssssttttttuuuvvvvwwwwwwwwxxxxxxxxyyyyzzzzzzzzzz\n",
"output": "YES\n00000000100100110101011100110010011110001110101000101110101100110011000100111000111100111011011101000111101111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000\n"
},
{
"input": "200\ncnaaaaaabbbbbccccdddddddddddddeeeeeeeeefffffffgggggggggghhhhhhhhhiiijjjjjkkkkkkklllllllmmmmmmmnnnnnnnnnooooooooooooppppppppqqqqqqqqqqqrrrssssssstuuuuuuuuvvvvvvvvvvvvwwwwwwxxxxxxxxyyyyyyyzzzzzzzzzzzzzz\n",
"output": "YES\n00111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"
},
{
"input": "2\ntj\n",
"output": "YES\n01\n"
},
{
"input": "200\naacdaeabblbxbbbbbbcccccdddddeeeeeeefffffffggggggghhhhhhhhhiiiiiiiiiijjjjjjjkkkkkkkklllllllllmmmmmmmmnnnoooooooopppppqqqqqqqqqqqrrrrrrrrrrsstttttttttuuuuuuuvvvvvvvvvvwwwwwwwxxxxxxxxxxxyyyyyyyyyzzzzzzzz\n",
"output": "YES\n00001011101011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000000000000\n"
},
{
"input": "8\nenjmfmcb\n",
"output": "NO\n"
},
{
"input": "100\nyvharmmxcxhibqfixtjmhurxchhkvhubxjcveajrkssbsbrxpijxolrtmvanzyybzbdpgzocicakipmkpxhcjtegksbvabfghpfg\n",
"output": "NO\n"
},
{
"input": "30\ndcjajwrqosgljwltqlozqmldwuukkg\n",
"output": "NO\n"
},
{
"input": "30\nrzlwlvhfatfwmlpvndtgrxyphfjnnm\n",
"output": "NO\n"
},
{
"input": "500\nrmjqqncoqtblylyxilxrmkjdgmivdwdywfwbnqvwatarwbntepxhwrteyteseixiyvhatntnjyceluhldcssemkppagowvhjuiqbypzeffzqlrbuhnsnovopvabjdtoxzjezilgtgpfjsiycjhquudzuvhbshdkwaspsbxeyxxxowezqafmtgxrauahozegjponudxakgchruhxdcgaohdpzslxexkhflfpmjxduthxwbowjkqnobxxlylvddkoinqgonrssasszuxrmnevcopeqrniwarejpcafknswomzypuhpikqojrdzfooqsrddoogmojvpedirgvplnvemknzzprrgbwuunxswpxyglqeglmwopxjnlpnqchnlvwaeyyjysvuoxpjartofbbdcncngzlqtzlwkoydrxyyzzlxepqmrlxsbkqqxleqxadfxsttdofvteonpqtjumaduagibkxnhsysrshowpiyzywnaueeuhgcv\n",
"output": "NO\n"
},
{
"input": "9\nabcabcabc\n",
"output": "NO\n"
},
{
"input": "30\nrhkegyacbthzhghossgtqdxtmjfhhx\n",
"output": "NO\n"
},
{
"input": "200\naaaaabbaaaaabcbebebbccecccffgjklccmcmnccoccooddoqqqdddqderreerrsfffsfsfghuuhhhvhhhhvviwixixixxixijjjxjyjzzjzkkklllllmmmmmmmnnnnnnnoooooppppppppppppqqqqqrrrrrrrsssssstttuuuvvvvvvvwwwwwwxxxyyyyyyyyyzzzz\n",
"output": "YES\n00000001111100101011110111000000110100110110011000011101100110001110101110011101111001010101001011110101001011111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000\n"
},
{
"input": "200\naaaaaaaaaaaabbbbccccccdddddddeeeeeeffgggggggggggghhhhhhiiiiiiiiiiiijjjjjjjjjkkkkklllllllmmmmmmmmnnnnnnnnoooooooopppppppppqqqqqrrrrrrrrrssssssssssttuuuuuuuvvvvvvvvvvwwwwwwwwxxxxxxxyyyyyyyyzzzzzzzzzzzzw\n",
"output": "YES\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n"
},
{
"input": "100\nqdvwjzmgfmgngaxzgvuuukxyfzecafuflxpkvemenkorwhmnsxuoxsatlymyjugwjmutfxcksnwhxrwruyqbouyflxhwqhflczzx\n",
"output": "NO\n"
},
{
"input": "8\nhinzrvgh\n",
"output": "NO\n"
}
] |
code_contests
|
python
| 0.1 |
a9dcbac4ca77eddad3533a9f5d83b109
|
A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and the bishop.
There are m queens on a square n × n chessboard. You know each queen's positions, the i-th queen is positioned in the square (ri, ci), where ri is the board row number (numbered from the top to the bottom from 1 to n), and ci is the board's column number (numbered from the left to the right from 1 to n). No two queens share the same position.
For each queen one can count w — the number of other queens that the given queen threatens (attacks). For a fixed attack direction only the first queen in this direction is under attack if there are many queens are on the ray of the attack. Obviously, for any queen w is between 0 and 8, inclusive.
Print the sequence t0, t1, ..., t8, where ti is the number of queens that threaten exactly i other queens, i.e. the number of queens that their w equals i.
Input
The first line of the input contains a pair of integers n, m (1 ≤ n, m ≤ 105), where n is the size of the board and m is the number of queens on the board. Then m following lines contain positions of the queens, one per line. Each line contains a pair of integers ri, ci (1 ≤ ri, ci ≤ n) — the queen's position. No two queens stand on the same square.
Output
Print the required sequence t0, t1, ..., t8, separating the numbers with spaces.
Examples
Input
8 4
4 3
4 8
6 5
1 6
Output
0 3 0 1 0 0 0 0 0
Input
10 3
1 1
1 2
1 3
Output
0 2 1 0 0 0 0 0 0
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
#sys.setrecursionlimit(300000)
#threading.stack_size(10**8)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------------------------------------------------------------
#mod = 9223372036854775807
class SegmentTree:
def __init__(self, data, default=10**10, func=lambda a, b: min(a,b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
MOD=10**9+7
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod=10**9+7
omod=998244353
#-------------------------------------------------------------------------
n,m=list(map(int,input().split()))
f=[]
maxx=[-999999999]*n
minx=[999999999]*n
maxy=[-999999999]*n
miny=[999999999]*n
maxm=[-999999999]*(2*n-1)
minm=[999999999]*(2*n-1)
maxs=[-999999999]*(2*n-1)
mins=[999999999]*(2*n-1)
r=[0 for i in range(9)]
for i in range(m):
y,x=list(map(int,input().split()))
a,b,c,d=y-1,x-1,y+x-2,y-x+n-1
f.append((a,b,c,d))
if a>maxx[b]:maxx[b]=a
if a<minx[b]:minx[b]=a
if x-1>maxy[a]:maxy[a]=x-1
if x-1<miny[a]:miny[a]=x-1
if c>maxs[d]:maxs[d]=c
if c<mins[d]:mins[d]=c
if d>maxm[c]:maxm[c]=d
if d<minm[c]:minm[c]=d
for i in f:
k=0
if i[0]<maxx[i[1]]:k+=1
if i[0]>minx[i[1]]:k+=1
if i[1]<maxy[i[0]]:k+=1
if i[1]>miny[i[0]]:k+=1
if i[2]<maxs[i[3]]:k+=1
if i[2]>mins[i[3]]:k+=1
if i[3]<maxm[i[2]]:k+=1
if i[3]>minm[i[2]]:k+=1
r[k]+=1
print(*r)
|
python
|
code_algorithm
|
[
{
"input": "10 3\n1 1\n1 2\n1 3\n",
"output": "0 2 1 0 0 0 0 0 0\n"
},
{
"input": "8 4\n4 3\n4 8\n6 5\n1 6\n",
"output": "0 3 0 1 0 0 0 0 0\n"
},
{
"input": "10 10\n6 5\n3 5\n3 4\n6 10\n3 10\n4 6\n6 2\n7 5\n1 8\n2 2\n",
"output": "0 5 1 2 1 1 0 0 0\n"
},
{
"input": "10 20\n6 10\n3 10\n10 4\n5 3\n9 4\n10 1\n10 3\n10 7\n8 5\n7 2\n4 7\n5 1\n2 9\n5 5\n6 6\n9 8\n2 10\n9 10\n1 4\n7 4\n",
"output": "0 0 4 9 4 1 2 0 0\n"
},
{
"input": "2 1\n1 1\n",
"output": "1 0 0 0 0 0 0 0 0\n"
},
{
"input": "10 4\n5 6\n4 8\n8 4\n7 4\n",
"output": "0 2 2 0 0 0 0 0 0\n"
},
{
"input": "10 5\n2 3\n1 3\n3 3\n2 1\n2 5\n",
"output": "0 4 0 0 1 0 0 0 0\n"
},
{
"input": "2 2\n1 1\n1 2\n",
"output": "0 2 0 0 0 0 0 0 0\n"
},
{
"input": "8 8\n8 3\n3 7\n7 1\n4 4\n1 6\n1 7\n3 3\n2 1\n",
"output": "0 3 2 3 0 0 0 0 0\n"
},
{
"input": "1 1\n1 1\n",
"output": "1 0 0 0 0 0 0 0 0\n"
},
{
"input": "2 4\n2 1\n1 2\n2 2\n1 1\n",
"output": "0 0 0 4 0 0 0 0 0\n"
},
{
"input": "100 10\n97 5\n53 35\n92 86\n54 95\n98 13\n36 23\n55 56\n96 94\n25 96\n49 31\n",
"output": "6 4 0 0 0 0 0 0 0\n"
}
] |
code_contests
|
python
| 0.1 |
3a63c984d34c6469834a838baab15dcd
|
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range (1, 10^9)! Therefore, the planet was named Longlifer.
In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!
Input
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of people.
Each of the following n lines contain two integers b and d (1 ≤ b < d ≤ 10^9) representing birth and death year (respectively) of each individual.
Output
Print two integer numbers separated by blank character, y — the year with a maximum number of people alive and k — the number of people alive in year y.
In the case of multiple possible solutions, print the solution with minimum year.
Examples
Input
3
1 5
2 4
5 6
Output
2 2
Input
4
3 4
4 5
4 6
8 10
Output
4 2
Note
You can assume that an individual living from b to d has been born at the beginning of b and died at the beginning of d, and therefore living for d - b years.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
dct = {}
for i in range(int(input())):
a,b = map(int,input().split())
dct[a] = dct.get(a,0)+1
dct[b] = dct.get(b,0)-1
cnt = curr = y = 0
for i in sorted(dct.keys()):
curr += dct[i]
if curr > cnt :
cnt = curr
y = i
print(y,cnt)
|
python
|
code_algorithm
|
[
{
"input": "3\n1 5\n2 4\n5 6\n",
"output": "2 2\n"
},
{
"input": "4\n3 4\n4 5\n4 6\n8 10\n",
"output": "4 2\n"
},
{
"input": "1\n1 2\n",
"output": "1 1\n"
},
{
"input": "1\n1 1000000000\n",
"output": "1 1\n"
},
{
"input": "1\n125 126\n",
"output": "125 1\n"
},
{
"input": "3\n1 2\n2 4\n2 4\n",
"output": "2 2\n"
}
] |
code_contests
|
python
| 1 |
da4cc49469f71074e2c108c364871af5
|
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types:
* replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4);
* swap any pair of digits in string a.
Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task.
Input
The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105.
Output
Print on the single line the single number — the minimum number of operations needed to convert string a into string b.
Examples
Input
47
74
Output
1
Input
774
744
Output
1
Input
777
444
Output
3
Note
In the first sample it is enough simply to swap the first and the second digit.
In the second sample we should replace the second digit with its opposite.
In the third number we should replace all three digits with their opposites.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
a=input()
b=input()
da={'4':0,'7':0}
db={'4':0,'7':0}
for i in a:
da[i]+=1
for i in b:
db[i]+=1
dif=0
for i in range(len(a)):
if(a[i]!=b[i]):
dif+=1
ans=0
if(da==db):
ans=dif//2
else:
x=abs(da['4']-db['4'])
ans+=x
dif-=x
ans+=(dif//2)
print(ans)
|
python
|
code_algorithm
|
[
{
"input": "47\n74\n",
"output": "1\n"
},
{
"input": "774\n744\n",
"output": "1\n"
},
{
"input": "777\n444\n",
"output": "3\n"
},
{
"input": "44447777447744444777777747477444777444447744444\n47444747774774744474747744447744477747777777447\n",
"output": "13\n"
},
{
"input": "74747474\n77777777\n",
"output": "4\n"
},
{
"input": "77747\n47474\n",
"output": "3\n"
},
{
"input": "474777477774444\n774747777774477\n",
"output": "4\n"
},
{
"input": "47744447444\n74477447744\n",
"output": "4\n"
},
{
"input": "4447744774744774744747744774474474444447477477444747477444\n7477477444744774744744774774744474744447744774744477744477\n",
"output": "14\n"
},
{
"input": "4747447477\n4747444744\n",
"output": "3\n"
},
{
"input": "4744744447774474447474774\n4477774777444444444777447\n",
"output": "8\n"
},
{
"input": "44747744777777444\n47774747747744777\n",
"output": "6\n"
},
{
"input": "47747477747744447774774444444777444747474747777774\n44777444774477447777444774477777477774444477447777\n",
"output": "14\n"
},
{
"input": "77447447444777777744744747744747774747477774777774447447777474477477774774777\n74777777444744447447474474477747747444444447447774444444747777444747474777447\n",
"output": "28\n"
},
{
"input": "44447774444474477747774774477777474774744744477444447777477477744747477774744444744777777777747777477447744774744444747477744744\n77777474477477747774777777474474477444474777477747747777477747747744474474747774747747444777474444744744444477477777747744747477\n",
"output": "37\n"
},
{
"input": "774774747744474477447477777447477747477474777477744744747444774474477477747474477447774444774744777\n744477444747477447477777774477447444447747477747477747774477474447474477477474444777444444447474747\n",
"output": "27\n"
},
{
"input": "47744474447747744777777447\n44744747477474777744777477\n",
"output": "7\n"
},
{
"input": "7\n4\n",
"output": "1\n"
},
{
"input": "444\n444\n",
"output": "0\n"
},
{
"input": "447444777744\n777747744477\n",
"output": "6\n"
},
{
"input": "47777777777\n77777777774\n",
"output": "1\n"
},
{
"input": "7777777777\n7777777774\n",
"output": "1\n"
},
{
"input": "7\n7\n",
"output": "0\n"
},
{
"input": "4\n7\n",
"output": "1\n"
},
{
"input": "444444444444\n777777777777\n",
"output": "12\n"
}
] |
code_contests
|
python
| 0.7 |
c4d043c2388f399e26cad738b016f5ac
|
One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited.
The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state.
Input
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of cells in the array. The second line contains n distinct integers from 1 to n — permutation. The last line contains n integers from 1 to n — favourite numbers of the cells.
Output
If the given state is reachable in the described game, output YES, otherwise NO.
Examples
Input
5
5 4 3 2 1
1 1 1 1 1
Output
YES
Input
7
4 3 5 1 2 7 6
4 6 6 1 6 6 1
Output
NO
Input
7
4 2 5 1 3 7 6
4 6 6 1 6 6 1
Output
YES
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[[] for i in range(n)]
for i in range(n):
if i-b[i]>=0:
c[i].append(i-b[i])
c[i-b[i]].append(i)
if i+b[i]<n:
c[i].append(i+b[i])
c[i+b[i]].append(i)
v=[1]*n
def dfs(u):
global v,c
v[u]=0
for i in c[u]:
if v[i]:
dfs(i)
for i in range(n):
v=[1]*n
dfs(a[i]-1)
if v[i]:
print('NO')
break
else:
print('YES')
|
python
|
code_algorithm
|
[
{
"input": "7\n4 3 5 1 2 7 6\n4 6 6 1 6 6 1\n",
"output": "NO\n"
},
{
"input": "5\n5 4 3 2 1\n1 1 1 1 1\n",
"output": "YES\n"
},
{
"input": "7\n4 2 5 1 3 7 6\n4 6 6 1 6 6 1\n",
"output": "YES\n"
},
{
"input": "80\n39 2 33 16 36 27 65 62 40 17 44 6 13 10 43 31 66 64 63 20 59 72 9 24 12 29 77 47 71 79 50 32 55 4 35 60 7 69 14 54 3 42 15 11 75 22 28 30 49 18 46 56 51 68 5 38 25 58 73 26 61 21 37 80 19 45 53 1 70 67 23 52 41 74 34 76 57 8 48 78\n6 23 42 42 13 72 14 45 66 76 74 44 49 10 14 64 17 15 4 68 14 34 42 56 50 65 17 52 15 26 1 42 27 22 6 52 25 47 76 45 48 67 18 44 74 48 62 58 59 79 13 5 12 14 5 13 51 21 57 59 49 43 8 34 7 16 34 29 38 74 40 72 18 46 47 43 2 4 17 1\n",
"output": "NO\n"
},
{
"input": "1\n1\n1\n",
"output": "YES\n"
},
{
"input": "68\n1 2 3 46 5 6 7 8 9 63 11 57 13 14 15 16 40 18 19 20 21 22 23 24 25 26 27 28 29 35 31 32 33 34 30 36 37 64 39 17 41 12 43 52 58 4 47 44 49 50 51 48 53 54 55 56 42 59 45 60 61 62 10 38 65 66 67 68\n13 48 67 55 4 39 47 8 4 35 50 28 28 30 63 60 52 29 2 33 48 57 40 43 25 34 62 50 60 5 3 66 32 15 7 51 51 26 47 23 67 30 27 53 40 42 5 4 60 67 11 4 31 10 62 46 45 13 14 13 24 66 53 25 22 60 14 42\n",
"output": "YES\n"
},
{
"input": "17\n1 11 3 4 5 6 7 8 9 10 2 12 13 14 15 16 17\n13 9 16 5 16 12 11 4 4 7 12 16 2 7 14 6 3\n",
"output": "YES\n"
},
{
"input": "2\n2 1\n2 2\n",
"output": "NO\n"
},
{
"input": "2\n2 1\n1 1\n",
"output": "YES\n"
},
{
"input": "76\n44 47 38 4 31 6 33 8 50 69 35 26 73 14 74 16 41 9 59 75 46 7 23 52 58 10 17 49 29 64 42 19 12 36 65 34 3 37 39 1 30 76 27 2 22 55 61 48 24 5 54 11 51 28 68 18 57 60 56 71 63 25 15 66 62 32 67 53 43 70 45 72 13 40 20 21\n54 63 9 55 65 59 4 1 42 31 63 5 28 26 19 35 50 21 39 23 40 64 45 36 74 74 70 67 53 20 19 27 13 2 71 62 6 51 2 65 61 58 55 55 32 75 54 75 48 45 40 45 7 43 72 75 54 9 32 52 8 36 33 59 57 58 68 32 71 21 63 69 7 40 28 68\n",
"output": "NO\n"
},
{
"input": "10\n6 2 9 4 8 7 5 10 3 1\n2 9 7 9 4 5 1 5 3 2\n",
"output": "YES\n"
},
{
"input": "2\n1 2\n1 1\n",
"output": "YES\n"
},
{
"input": "13\n13 1 12 4 6 10 7 8 9 3 11 5 2\n6 12 12 7 11 7 10 3 1 5 2 2 1\n",
"output": "NO\n"
},
{
"input": "19\n7 2 17 18 4 16 1 9 12 10 8 11 6 13 14 19 3 5 15\n12 4 9 1 13 18 14 10 18 2 17 16 12 3 16 6 5 7 7\n",
"output": "NO\n"
},
{
"input": "71\n1 63 3 4 5 6 7 8 9 44 29 12 13 14 55 34 42 18 52 20 21 33 23 24 25 26 27 28 19 30 47 32 15 71 37 36 69 38 39 40 41 17 43 10 45 58 35 48 49 11 51 50 53 54 22 56 57 46 59 60 61 62 2 64 65 66 67 68 31 70 16\n21 45 8 62 56 53 25 22 65 34 39 43 30 63 18 18 25 10 31 64 70 33 49 70 34 21 69 25 21 4 38 41 4 36 4 28 6 48 6 25 57 11 62 48 62 69 12 14 12 70 41 2 49 30 40 37 67 12 13 22 50 35 61 42 33 30 10 47 10 65 37\n",
"output": "YES\n"
},
{
"input": "4\n1 2 3 4\n1 1 1 1\n",
"output": "YES\n"
},
{
"input": "50\n5 2 4 31 1 10 44 24 9 38 20 27 35 14 37 46 8 18 41 34 7 22 25 45 32 43 6 47 39 15 26 48 30 23 16 36 17 21 50 40 3 11 12 19 42 29 28 49 33 13\n27 15 18 20 19 23 49 18 28 32 29 2 16 23 23 2 17 25 27 43 32 31 11 3 49 46 22 44 14 48 35 15 32 35 2 49 10 22 5 36 49 16 43 46 33 11 31 15 45 23\n",
"output": "NO\n"
},
{
"input": "8\n5 2 3 4 8 6 1 7\n6 7 7 7 7 7 2 7\n",
"output": "YES\n"
},
{
"input": "2\n1 2\n2 2\n",
"output": "YES\n"
},
{
"input": "52\n17 35 19 41 21 51 46 45 13 10 15 43 37 30 34 12 39 20 14 48 49 3 23 6 4 26 47 18 16 5 31 36 27 29 24 11 52 38 33 42 1 8 9 32 44 7 28 22 40 50 2 25\n47 6 50 13 49 22 17 18 3 11 2 43 35 8 25 38 19 41 17 5 7 8 10 51 17 30 34 48 41 8 46 10 11 45 15 28 42 32 37 33 43 31 38 13 43 19 32 19 2 47 42 46\n",
"output": "NO\n"
},
{
"input": "82\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 59 17 18 19 20 21 22 23 24 25 26 27 28 29 61 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 16 60 30 79 63 64 65 66 67 68 69 70 71 72 73 74 75 76 82 78 62 80 81 77\n8 79 66 53 45 15 70 17 53 28 30 70 14 49 51 43 45 14 27 30 37 51 29 55 6 5 24 6 61 31 64 47 71 60 79 64 28 64 17 38 11 13 3 72 24 70 16 14 30 72 52 33 31 71 32 66 29 45 55 32 48 14 63 60 50 50 61 2 47 26 4 26 72 3 56 19 1 47 17 26 66 5\n",
"output": "YES\n"
},
{
"input": "6\n3 2 1 4 6 5\n3 6 1 6 6 1\n",
"output": "YES\n"
},
{
"input": "79\n1 2 3 67 5 6 7 60 9 71 63 12 31 57 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 64 32 79 34 35 45 37 38 39 40 41 42 43 44 36 46 47 48 11 50 51 52 74 54 55 56 14 58 59 8 61 62 49 13 65 66 4 68 72 70 10 69 73 53 75 76 77 78 33\n17 46 68 35 48 11 78 40 65 61 52 45 51 66 13 56 53 63 61 43 22 60 13 67 34 16 64 19 11 27 33 8 9 1 68 9 17 62 65 23 50 1 55 20 70 61 65 55 38 47 9 45 55 70 39 31 43 47 40 52 20 5 20 75 25 25 63 2 36 12 60 3 35 21 78 38 39 25 46\n",
"output": "YES\n"
},
{
"input": "60\n1 2 17 4 27 6 43 26 32 10 11 12 29 14 15 16 3 44 56 20 21 22 53 24 25 8 5 28 58 7 31 9 33 57 48 36 37 38 39 30 41 50 40 35 45 46 13 18 47 55 51 52 23 54 42 19 34 49 59 60\n59 25 14 52 1 24 36 16 42 8 59 22 41 47 49 33 36 35 37 30 25 6 30 8 50 2 25 3 29 10 52 20 8 45 13 43 53 45 10 33 54 53 47 26 32 4 2 38 33 45 19 4 56 22 13 40 45 45 24 14\n",
"output": "YES\n"
},
{
"input": "6\n3 5 1 4 6 2\n3 6 1 6 6 1\n",
"output": "NO\n"
},
{
"input": "5\n1 3 2 4 5\n1 4 1 2 4\n",
"output": "YES\n"
},
{
"input": "47\n1 32 29 9 47 6 8 36 37 10 11 16 2 14 38 40 15 44 19 35 18 22 23 12 17 41 5 31 26 25 4 27 33 34 42 7 24 28 45 20 46 13 43 30 21 3 39\n38 28 41 46 28 20 36 9 4 10 44 28 9 39 12 36 32 38 43 3 13 33 34 35 22 23 1 4 39 2 11 34 20 19 25 13 20 26 45 36 36 43 45 13 31 9 5\n",
"output": "NO\n"
}
] |
code_contests
|
python
| 0 |
8c7204dcc82d7a99bf6f2de9545b242e
|
Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter.
Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode for each of them (produce matter or antimatter) and finally take a photo of it. However he will be successful only if the amounts of matter and antimatter produced in the selected subarray will be the same (otherwise there would be overflowing matter or antimatter in the photo).
You are requested to compute the number of different ways Iahub can successful take a photo. A photo is different than another if it represents another subarray, or if at least one device of the subarray is set to produce matter in one of the photos and antimatter in the other one.
Input
The first line contains an integer n (1 ≤ n ≤ 1000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000).
The sum a1 + a2 + ... + an will be less than or equal to 10000.
Output
Output a single integer, the number of ways Iahub can take a photo, modulo 1000000007 (109 + 7).
Examples
Input
4
1 1 1 1
Output
12
Note
The possible photos are [1+, 2-], [1-, 2+], [2+, 3-], [2-, 3+], [3+, 4-], [3-, 4+], [1+, 2+, 3-, 4-], [1+, 2-, 3+, 4-], [1+, 2-, 3-, 4+], [1-, 2+, 3+, 4-], [1-, 2+, 3-, 4+] and [1-, 2-, 3+, 4+], where "i+" means that the i-th element produces matter, and "i-" means that the i-th element produces antimatter.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))
n = int(input())
a = list(map(int, input().split()))
m = sum(a)
M = 10**9+7
dp = [0]*(2*m+1)
ans = 0
dp[m] = 1
val = 0
for i in range(n):
v = a[i]
ndp = [0]*(2*m+1)
for j in range(2*m+1):
if j-v>=0:
ndp[j-v] += dp[j]
if ndp[j-v]>M:
ndp[j-v] -= M
if j+v<=2*m:
ndp[j+v] += dp[j]
if ndp[j+v]>M:
ndp[j+v] -= M
dp = ndp
ans += dp[m]
ans %= M
dp[m] += 1
val += v
print(ans%M)
|
python
|
code_algorithm
|
[
{
"input": "4\n1 1 1 1\n",
"output": "12\n"
},
{
"input": "50\n2 1 5 2 1 3 1 2 3 2 1 1 5 2 2 2 3 2 1 2 2 2 3 3 1 3 1 1 2 2 2 2 1 2 3 1 2 4 1 1 1 3 2 1 1 1 3 2 1 3\n",
"output": "115119382\n"
},
{
"input": "250\n2 2 2 2 3 2 4 2 3 2 5 1 2 3 4 4 5 3 5 1 2 5 2 3 5 3 2 3 3 3 5 1 5 5 5 4 1 3 2 5 1 2 3 5 3 3 5 2 1 1 3 3 5 1 4 2 3 3 2 2 3 5 5 4 1 4 1 5 1 3 3 4 1 5 2 5 5 3 2 4 4 4 4 3 5 1 3 4 3 4 2 1 4 3 5 1 2 3 4 2 5 5 3 2 5 3 5 4 2 3 2 3 1 1 2 4 2 5 2 3 3 2 4 5 4 2 2 5 5 5 5 4 3 4 5 2 2 3 3 4 5 1 5 5 2 5 1 5 5 4 4 1 4 2 1 2 1 2 2 3 1 4 5 4 2 4 5 1 1 3 2 1 4 1 5 2 3 1 2 3 2 3 3 2 4 2 5 5 2 3 4 2 2 4 2 4 1 5 5 3 1 3 4 5 2 5 5 1 3 1 3 3 2 5 3 5 2 4 3 5 5 3 3 2 3 2 5 3 4 3 5 3 3 4 5 3 1 2 2 5 4 4 5 1 4 1 2 5 2 3\n",
"output": "257270797\n"
},
{
"input": "3\n1 2 4\n",
"output": "0\n"
},
{
"input": "3\n999 999 999\n",
"output": "4\n"
},
{
"input": "10\n16 9 9 11 10 12 9 6 10 8\n",
"output": "86\n"
},
{
"input": "1\n1\n",
"output": "0\n"
},
{
"input": "250\n6 1 4 3 3 7 4 5 3 2 4 4 2 5 4 2 1 7 6 2 4 5 3 3 4 5 3 4 5 4 6 4 6 5 3 3 1 5 4 5 3 4 2 4 2 5 1 4 3 3 3 2 6 6 4 7 2 6 5 3 3 6 5 2 1 3 3 5 2 2 3 7 3 5 6 4 7 3 5 3 4 5 5 4 11 5 1 5 3 3 3 1 4 6 4 4 5 5 5 5 2 5 5 3 2 2 5 6 10 5 4 2 5 4 2 5 5 3 4 2 5 4 3 2 4 4 2 5 4 1 5 3 9 6 4 6 3 5 4 5 3 6 7 4 5 5 3 6 2 6 3 3 4 5 6 3 3 3 5 2 4 4 4 5 4 2 5 4 6 5 3 3 6 3 1 5 6 5 4 6 2 3 4 4 5 2 1 7 4 5 5 5 2 2 7 6 1 5 3 2 7 5 8 2 2 2 3 5 2 4 4 2 2 6 4 6 3 2 8 3 4 7 3 2 7 3 5 5 3 2 2 4 5 3 4 3 5 3 5 4 3 1 2 4 7 4 2 3 3 5\n",
"output": "377970747\n"
},
{
"input": "100\n8 3 3 7 3 6 4 6 9 4 6 5 5 5 4 3 4 2 3 5 3 6 5 3 6 5 6 6 2 6 4 5 5 4 6 4 3 2 8 5 6 6 7 4 4 9 5 6 6 3 7 1 6 2 6 5 9 3 8 6 2 6 3 2 4 4 3 5 4 7 6 5 4 6 3 5 6 8 8 6 3 7 7 1 4 6 8 6 5 3 7 8 4 7 5 3 8 5 4 4\n",
"output": "450259307\n"
},
{
"input": "1\n1000\n",
"output": "0\n"
},
{
"input": "3\n1 2 2\n",
"output": "2\n"
},
{
"input": "2\n1000 1000\n",
"output": "2\n"
},
{
"input": "2\n1 1\n",
"output": "2\n"
},
{
"input": "2\n1 2\n",
"output": "0\n"
},
{
"input": "250\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "533456111\n"
}
] |
code_contests
|
python
| 0 |
0cbb9843fa2b1d2bec0ed3251732f709
|
Valera had an undirected connected graph without self-loops and multiple edges consisting of n vertices. The graph had an interesting property: there were at most k edges adjacent to each of its vertices. For convenience, we will assume that the graph vertices were indexed by integers from 1 to n.
One day Valera counted the shortest distances from one of the graph vertices to all other ones and wrote them out in array d. Thus, element d[i] of the array shows the shortest distance from the vertex Valera chose to vertex number i.
Then something irreparable terrible happened. Valera lost the initial graph. However, he still has the array d. Help him restore the lost graph.
Input
The first line contains two space-separated integers n and k (1 ≤ k < n ≤ 105). Number n shows the number of vertices in the original graph. Number k shows that at most k edges were adjacent to each vertex in the original graph.
The second line contains space-separated integers d[1], d[2], ..., d[n] (0 ≤ d[i] < n). Number d[i] shows the shortest distance from the vertex Valera chose to the vertex number i.
Output
If Valera made a mistake in his notes and the required graph doesn't exist, print in the first line number -1. Otherwise, in the first line print integer m (0 ≤ m ≤ 106) — the number of edges in the found graph.
In each of the next m lines print two space-separated integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi), denoting the edge that connects vertices with numbers ai and bi. The graph shouldn't contain self-loops and multiple edges. If there are multiple possible answers, print any of them.
Examples
Input
3 2
0 1 1
Output
3
1 2
1 3
3 2
Input
4 2
2 0 1 3
Output
3
1 3
1 4
2 3
Input
3 1
0 0 0
Output
-1
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
from sys import exit
n, k = map(int, input().split())
nodes = [[] for _ in range(n+1)]
edges = []
for node, dist in enumerate(map(int, input().split())):
nodes[dist].append(node)
if len(nodes[0]) != 1 or len(nodes[1]) > k:
print(-1)
else:
for i in range(1, n):
if len(nodes[i])*(k-1) < len(nodes[i+1]):
print(-1)
exit(0)
for i in range(n):
next = 0
if len(nodes[i+1]) > 0:
for j, node in enumerate(nodes[i]):
current = 0
while current < (k if i == 0 else k-1) and next < len(nodes[i+1]):
edges.append((node+1, nodes[i+1][next]+1))
next += 1
current += 1
print(len(edges))
print('\n'.join(map(lambda x: ' '.join([str(x[0]), str(x[1])]), edges)))
|
python
|
code_algorithm
|
[
{
"input": "3 2\n0 1 1\n",
"output": "2\n1 2\n1 3\n"
},
{
"input": "3 1\n0 0 0\n",
"output": "-1\n"
},
{
"input": "4 2\n2 0 1 3\n",
"output": "3\n2 3\n3 1\n1 4\n"
},
{
"input": "3 1\n0 1 2\n",
"output": "-1\n"
},
{
"input": "5 3\n0 2 1 2 1\n",
"output": "4\n1 3\n1 5\n3 2\n3 4\n"
},
{
"input": "4 3\n1 1 1 2\n",
"output": "-1\n"
},
{
"input": "2 1\n1 0\n",
"output": "1\n2 1\n"
},
{
"input": "2 1\n1 1\n",
"output": "-1\n"
},
{
"input": "3 2\n0 1 1\n",
"output": "2\n1 2\n1 3\n"
},
{
"input": "9 4\n2 1 1 3 1 2 2 1 0\n",
"output": "8\n9 2\n9 3\n9 5\n9 8\n2 1\n2 6\n2 7\n1 4\n"
},
{
"input": "4 2\n0 1 0 1\n",
"output": "-1\n"
},
{
"input": "7 3\n2 2 0 1 3 2 1\n",
"output": "6\n3 4\n3 7\n4 1\n4 2\n7 6\n1 5\n"
},
{
"input": "2 1\n0 0\n",
"output": "-1\n"
},
{
"input": "5 4\n1 2 2 2 3\n",
"output": "-1\n"
},
{
"input": "7 6\n1 1 2 2 3 3 3\n",
"output": "-1\n"
},
{
"input": "4 3\n1 2 2 3\n",
"output": "-1\n"
},
{
"input": "10 5\n0 1 1 1 1 1 1 2 2 2\n",
"output": "-1\n"
},
{
"input": "4 3\n1 2 3 3\n",
"output": "-1\n"
},
{
"input": "5 4\n0 1 1 1 4\n",
"output": "-1\n"
},
{
"input": "5 3\n3 1 4 2 1\n",
"output": "-1\n"
}
] |
code_contests
|
python
| 0 |
e0cf1a4394c9a09202c20bc56bba9d86
|
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n > 1) is an n × n matrix with a diamond inscribed into it.
You are given an odd integer n. You need to draw a crystal of size n. The diamond cells of the matrix should be represented by character "D". All other cells of the matrix should be represented by character "*". Look at the examples to understand what you need to draw.
Input
The only line contains an integer n (3 ≤ n ≤ 101; n is odd).
Output
Output a crystal of size n.
Examples
Input
3
Output
*D*
DDD
*D*
Input
5
Output
**D**
*DDD*
DDDDD
*DDD*
**D**
Input
7
Output
***D***
**DDD**
*DDDDD*
DDDDDDD
*DDDDD*
**DDD**
***D***
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n=int(input())
a=int(n/2)
b=1
for i in range(int(n/2)):
for j in range(a):
print("*",end="")
for j in range(b):
print('D',end="")
b=b+2
for j in range(a):
print("*",end="")
a=a-1
print()
for i in range(b):
print("D",end="")
print()
a=a+1
b=b-2
for i in range(int(n/2)):
for j in range(a):
print("*",end="")
for j in range(b):
print('D',end="")
b=b-2
for j in range(a):
print("*",end="")
a=a+1
print()
|
python
|
code_algorithm
|
[
{
"input": "5\n",
"output": "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n"
},
{
"input": "7\n",
"output": "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n"
},
{
"input": "3\n",
"output": "*D*\nDDD\n*D*\n"
},
{
"input": "101\n",
"output": "**************************************************D**************************************************\n*************************************************DDD*************************************************\n************************************************DDDDD************************************************\n***********************************************DDDDDDD***********************************************\n**********************************************DDDDDDDDD**********************************************\n*********************************************DDDDDDDDDDD*********************************************\n********************************************DDDDDDDDDDDDD********************************************\n*******************************************DDDDDDDDDDDDDDD*******************************************\n******************************************DDDDDDDDDDDDDDDDD******************************************\n*****************************************DDDDDDDDDDDDDDDDDDD*****************************************\n****************************************DDDDDDDDDDDDDDDDDDDDD****************************************\n***************************************DDDDDDDDDDDDDDDDDDDDDDD***************************************\n**************************************DDDDDDDDDDDDDDDDDDDDDDDDD**************************************\n*************************************DDDDDDDDDDDDDDDDDDDDDDDDDDD*************************************\n************************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDD************************************\n***********************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********************************\n**********************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********************************\n*********************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********************************\n********************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********************************\n*******************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******************************\n******************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******************************\n*****************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****************************\n****************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****************************\n***************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***************************\n**************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************************\n*************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************************\n************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************************\n***********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********************\n**********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********************\n*********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********************\n********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********************\n*******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******************\n******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******************\n*****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****************\n****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****************\n***************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***************\n**************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************\n*************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************\n************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************\n***********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********\n**********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********\n*********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********\n********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********\n*******DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******\n******DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******\n*****DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****\n****DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****\n***DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***\n**DDDDDDDDDD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DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********\n*********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********\n**********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********\n***********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********\n************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************\n*************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************\n**************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************\n***************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***************\n****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****************\n*****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****************\n******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******************\n*******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******************\n********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********************\n*********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********************\n**********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********************\n***********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********************\n************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************************\n*************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************************\n**************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************************\n***************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***************************\n****************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****************************\n*****************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****************************\n******************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******************************\n*******************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******************************\n********************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********************************\n*********************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********************************\n**********************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********************************\n***********************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********************************\n************************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDD************************************\n*************************************DDDDDDDDDDDDDDDDDDDDDDDDDDD*************************************\n**************************************DDDDDDDDDDDDDDDDDDDDDDDDD**************************************\n***************************************DDDDDDDDDDDDDDDDDDDDDDD***************************************\n****************************************DDDDDDDDDDDDDDDDDDDDD****************************************\n*****************************************DDDDDDDDDDDDDDDDDDD*****************************************\n******************************************DDDDDDDDDDDDDDDDD******************************************\n*******************************************DDDDDDDDDDDDDDD*******************************************\n********************************************DDDDDDDDDDDDD********************************************\n*********************************************DDDDDDDDDDD*********************************************\n**********************************************DDDDDDDDD**********************************************\n***********************************************DDDDDDD***********************************************\n************************************************DDDDD************************************************\n*************************************************DDD*************************************************\n**************************************************D**************************************************\n"
},
{
"input": "11\n",
"output": "*****D*****\n****DDD****\n***DDDDD***\n**DDDDDDD**\n*DDDDDDDDD*\nDDDDDDDDDDD\n*DDDDDDDDD*\n**DDDDDDD**\n***DDDDD***\n****DDD****\n*****D*****\n"
},
{
"input": "81\n",
"output": "****************************************D****************************************\n***************************************DDD***************************************\n**************************************DDDDD**************************************\n*************************************DDDDDDD*************************************\n************************************DDDDDDDDD************************************\n***********************************DDDDDDDDDDD***********************************\n**********************************DDDDDDDDDDDDD**********************************\n*********************************DDDDDDDDDDDDDDD*********************************\n********************************DDDDDDDDDDDDDDDDD********************************\n*******************************DDDDDDDDDDDDDDDDDDD*******************************\n******************************DDDDDDDDDDDDDDDDDDDDD******************************\n*****************************DDDDDDDDDDDDDDDDDDDDDDD*****************************\n****************************DDDDDDDDDDDDDDDDDDDDDDDDD****************************\n***************************DDDDDDDDDDDDDDDDDDDDDDDDDDD***************************\n**************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************************\n*************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************************\n************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************************\n***********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********************\n**********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********************\n*********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********************\n********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********************\n*******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******************\n******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******************\n*****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****************\n****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****************\n***************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***************\n**************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************\n*************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************\n************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************\n***********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********\n**********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********\n*********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********\n********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********\n*******DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******\n******DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******\n*****DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****\n****DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****\n***DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***\n**DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**\n*DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\n*DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*\n**DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**\n***DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***\n****DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****\n*****DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****\n******DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******\n*******DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******\n********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********\n*********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********\n**********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********\n***********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********\n************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************\n*************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************\n**************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************\n***************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***************\n****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****************\n*****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****************\n******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******************\n*******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******************\n********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********************\n*********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********************\n**********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********************\n***********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********************\n************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************************\n*************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************************\n**************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************************\n***************************DDDDDDDDDDDDDDDDDDDDDDDDDDD***************************\n****************************DDDDDDDDDDDDDDDDDDDDDDDDD****************************\n*****************************DDDDDDDDDDDDDDDDDDDDDDD*****************************\n******************************DDDDDDDDDDDDDDDDDDDDD******************************\n*******************************DDDDDDDDDDDDDDDDDDD*******************************\n********************************DDDDDDDDDDDDDDDDD********************************\n*********************************DDDDDDDDDDDDDDD*********************************\n**********************************DDDDDDDDDDDDD**********************************\n***********************************DDDDDDDDDDD***********************************\n************************************DDDDDDDDD************************************\n*************************************DDDDDDD*************************************\n**************************************DDDDD**************************************\n***************************************DDD***************************************\n****************************************D****************************************\n"
},
{
"input": "21\n",
"output": "**********D**********\n*********DDD*********\n********DDDDD********\n*******DDDDDDD*******\n******DDDDDDDDD******\n*****DDDDDDDDDDD*****\n****DDDDDDDDDDDDD****\n***DDDDDDDDDDDDDDD***\n**DDDDDDDDDDDDDDDDD**\n*DDDDDDDDDDDDDDDDDDD*\nDDDDDDDDDDDDDDDDDDDDD\n*DDDDDDDDDDDDDDDDDDD*\n**DDDDDDDDDDDDDDDDD**\n***DDDDDDDDDDDDDDD***\n****DDDDDDDDDDDDD****\n*****DDDDDDDDDDD*****\n******DDDDDDDDD******\n*******DDDDDDD*******\n********DDDDD********\n*********DDD*********\n**********D**********\n"
},
{
"input": "15\n",
"output": "*******D*******\n******DDD******\n*****DDDDD*****\n****DDDDDDD****\n***DDDDDDDDD***\n**DDDDDDDDDDD**\n*DDDDDDDDDDDDD*\nDDDDDDDDDDDDDDD\n*DDDDDDDDDDDDD*\n**DDDDDDDDDDD**\n***DDDDDDDDD***\n****DDDDDDD****\n*****DDDDD*****\n******DDD******\n*******D*******\n"
},
{
"input": "57\n",
"output": "****************************D****************************\n***************************DDD***************************\n**************************DDDDD**************************\n*************************DDDDDDD*************************\n************************DDDDDDDDD************************\n***********************DDDDDDDDDDD***********************\n**********************DDDDDDDDDDDDD**********************\n*********************DDDDDDDDDDDDDDD*********************\n********************DDDDDDDDDDDDDDDDD********************\n*******************DDDDDDDDDDDDDDDDDDD*******************\n******************DDDDDDDDDDDDDDDDDDDDD******************\n*****************DDDDDDDDDDDDDDDDDDDDDDD*****************\n****************DDDDDDDDDDDDDDDDDDDDDDDDD****************\n***************DDDDDDDDDDDDDDDDDDDDDDDDDDD***************\n**************DDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************\n*************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************\n************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************\n***********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********\n**********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********\n*********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********\n********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********\n*******DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******\n******DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******\n*****DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****\n****DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****\n***DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***\n**DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**\n*DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\n*DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*\n**DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**\n***DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***\n****DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****\n*****DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****\n******DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******\n*******DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******\n********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********\n*********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********\n**********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********\n***********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********\n************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************\n*************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************\n**************DDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************\n***************DDDDDDDDDDDDDDDDDDDDDDDDDDD***************\n****************DDDDDDDDDDDDDDDDDDDDDDDDD****************\n*****************DDDDDDDDDDDDDDDDDDDDDDD*****************\n******************DDDDDDDDDDDDDDDDDDDDD******************\n*******************DDDDDDDDDDDDDDDDDDD*******************\n********************DDDDDDDDDDDDDDDDD********************\n*********************DDDDDDDDDDDDDDD*********************\n**********************DDDDDDDDDDDDD**********************\n***********************DDDDDDDDDDD***********************\n************************DDDDDDDDD************************\n*************************DDDDDDD*************************\n**************************DDDDD**************************\n***************************DDD***************************\n****************************D****************************\n"
},
{
"input": "33\n",
"output": "****************D****************\n***************DDD***************\n**************DDDDD**************\n*************DDDDDDD*************\n************DDDDDDDDD************\n***********DDDDDDDDDDD***********\n**********DDDDDDDDDDDDD**********\n*********DDDDDDDDDDDDDDD*********\n********DDDDDDDDDDDDDDDDD********\n*******DDDDDDDDDDDDDDDDDDD*******\n******DDDDDDDDDDDDDDDDDDDDD******\n*****DDDDDDDDDDDDDDDDDDDDDDD*****\n****DDDDDDDDDDDDDDDDDDDDDDDDD****\n***DDDDDDDDDDDDDDDDDDDDDDDDDDD***\n**DDDDDDDDDDDDDDDDDDDDDDDDDDDDD**\n*DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\n*DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*\n**DDDDDDDDDDDDDDDDDDDDDDDDDDDDD**\n***DDDDDDDDDDDDDDDDDDDDDDDDDDD***\n****DDDDDDDDDDDDDDDDDDDDDDDDD****\n*****DDDDDDDDDDDDDDDDDDDDDDD*****\n******DDDDDDDDDDDDDDDDDDDDD******\n*******DDDDDDDDDDDDDDDDDDD*******\n********DDDDDDDDDDDDDDDDD********\n*********DDDDDDDDDDDDDDD*********\n**********DDDDDDDDDDDDD**********\n***********DDDDDDDDDDD***********\n************DDDDDDDDD************\n*************DDDDDDD*************\n**************DDDDD**************\n***************DDD***************\n****************D****************\n"
},
{
"input": "69\n",
"output": "**********************************D**********************************\n*********************************DDD*********************************\n********************************DDDDD********************************\n*******************************DDDDDDD*******************************\n******************************DDDDDDDDD******************************\n*****************************DDDDDDDDDDD*****************************\n****************************DDDDDDDDDDDDD****************************\n***************************DDDDDDDDDDDDDDD***************************\n**************************DDDDDDDDDDDDDDDDD**************************\n*************************DDDDDDDDDDDDDDDDDDD*************************\n************************DDDDDDDDDDDDDDDDDDDDD************************\n***********************DDDDDDDDDDDDDDDDDDDDDDD***********************\n**********************DDDDDDDDDDDDDDDDDDDDDDDDD**********************\n*********************DDDDDDDDDDDDDDDDDDDDDDDDDDD*********************\n********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDD********************\n*******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******************\n******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******************\n*****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****************\n****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****************\n***************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***************\n**************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************\n*************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************\n************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************\n***********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********\n**********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD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DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******\n*******DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******\n********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********\n*********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********\n**********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********\n***********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********\n************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************\n*************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************\n**************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************\n***************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***************\n****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****************\n*****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****************\n******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******************\n*******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******************\n********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDD********************\n*********************DDDDDDDDDDDDDDDDDDDDDDDDDDD*********************\n**********************DDDDDDDDDDDDDDDDDDDDDDDDD**********************\n***********************DDDDDDDDDDDDDDDDDDDDDDD***********************\n************************DDDDDDDDDDDDDDDDDDDDD************************\n*************************DDDDDDDDDDDDDDDDDDD*************************\n**************************DDDDDDDDDDDDDDDDD**************************\n***************************DDDDDDDDDDDDDDD***************************\n****************************DDDDDDDDDDDDD****************************\n*****************************DDDDDDDDDDD*****************************\n******************************DDDDDDDDD******************************\n*******************************DDDDDDD*******************************\n********************************DDDDD********************************\n*********************************DDD*********************************\n**********************************D**********************************\n"
},
{
"input": "91\n",
"output": "*********************************************D*********************************************\n********************************************DDD********************************************\n*******************************************DDDDD*******************************************\n******************************************DDDDDDD******************************************\n*****************************************DDDDDDDDD*****************************************\n****************************************DDDDDDDDDDD****************************************\n***************************************DDDDDDDDDDDDD***************************************\n**************************************DDDDDDDDDDDDDDD**************************************\n*************************************DDDDDDDDDDDDDDDDD*************************************\n************************************DDDDDDDDDDDDDDDDDDD************************************\n***********************************DDDDDDDDDDDDDDDDDDDDD***********************************\n**********************************DDDDDDDDDDDDDDDDDDDDDDD**********************************\n*********************************DDDDDDDDDDDDDDDDDDDDDDDDD*********************************\n********************************DDDDDDDDDDDDDDDDDDDDDDDDDDD********************************\n*******************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******************************\n******************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******************************\n*****************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****************************\n****************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****************************\n***************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***************************\n**************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************************\n*************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************************\n************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************************\n***********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********************\n**********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********************\n*********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********************\n********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********************\n*******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******************\n******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******************\n*****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****************\n****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****************\n***************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***************\n**************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************\n*************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************\n************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************\n***********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********\n**********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********\n*********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********\n********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********\n*******DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******\n******DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******\n*****DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****\n****DDDDDDDDDDDDDDDDDDDDDDD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DDDDDDDDDDDDDD*******\n********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********\n*********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********\n**********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********\n***********DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********\n************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************\n*************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************\n**************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************\n***************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***************\n****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****************\n*****************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****************\n******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******************\n*******************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******************\n********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD********************\n*********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*********************\n**********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**********************\n***********************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***********************\n************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD************************\n*************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*************************\n**************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD**************************\n***************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD***************************\n****************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD****************************\n*****************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD*****************************\n******************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD******************************\n*******************************DDDDDDDDDDDDDDDDDDDDDDDDDDDDD*******************************\n********************************DDDDDDDDDDDDDDDDDDDDDDDDDDD********************************\n*********************************DDDDDDDDDDDDDDDDDDDDDDDDD*********************************\n**********************************DDDDDDDDDDDDDDDDDDDDDDD**********************************\n***********************************DDDDDDDDDDDDDDDDDDDDD***********************************\n************************************DDDDDDDDDDDDDDDDDDD************************************\n*************************************DDDDDDDDDDDDDDDDD*************************************\n**************************************DDDDDDDDDDDDDDD**************************************\n***************************************DDDDDDDDDDDDD***************************************\n****************************************DDDDDDDDDDD****************************************\n*****************************************DDDDDDDDD*****************************************\n******************************************DDDDDDD******************************************\n*******************************************DDDDD*******************************************\n********************************************DDD********************************************\n*********************************************D*********************************************\n"
}
] |
code_contests
|
python
| 0 |
cde745665b6de27683d4a9da67d4f27d
|
Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i × j. The rows and columns are numbered starting from 1.
You are given a positive integer x. Your task is to count the number of cells in a table that contain number x.
Input
The single line contains numbers n and x (1 ≤ n ≤ 105, 1 ≤ x ≤ 109) — the size of the table and the number that we are looking for in the table.
Output
Print a single number: the number of times x occurs in the table.
Examples
Input
10 5
Output
2
Input
6 12
Output
4
Input
5 13
Output
0
Note
A table for the second sample test is given below. The occurrences of number 12 are marked bold.
<image>
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import sys
n, x = map(int, sys.stdin.readline().split())
s = 0
for i in range(1, n + 1):
if (x % i == 0 and x / i <= n):
s += 1
print(s)
|
python
|
code_algorithm
|
[
{
"input": "5 13\n",
"output": "0\n"
},
{
"input": "10 5\n",
"output": "2\n"
},
{
"input": "6 12\n",
"output": "4\n"
},
{
"input": "100000 997920\n",
"output": "222\n"
},
{
"input": "100000 989460910\n",
"output": "4\n"
},
{
"input": "22740 989460910\n",
"output": "0\n"
},
{
"input": "1 1000000000\n",
"output": "0\n"
},
{
"input": "19999 399960001\n",
"output": "1\n"
},
{
"input": "100000 1000000000\n",
"output": "16\n"
},
{
"input": "100000 1\n",
"output": "1\n"
},
{
"input": "100000 479001600\n",
"output": "254\n"
},
{
"input": "4 4\n",
"output": "3\n"
},
{
"input": "100000 25\n",
"output": "3\n"
},
{
"input": "58942 936593001\n",
"output": "0\n"
},
{
"input": "100000 98280\n",
"output": "128\n"
},
{
"input": "2 4\n",
"output": "1\n"
},
{
"input": "100000 720720\n",
"output": "226\n"
},
{
"input": "2 1\n",
"output": "1\n"
},
{
"input": "1 4\n",
"output": "0\n"
},
{
"input": "9551 975275379\n",
"output": "0\n"
},
{
"input": "40000 551350800\n",
"output": "150\n"
},
{
"input": "31621 999887641\n",
"output": "1\n"
},
{
"input": "4 9\n",
"output": "1\n"
},
{
"input": "100000 8648640\n",
"output": "348\n"
},
{
"input": "100000 362880\n",
"output": "154\n"
},
{
"input": "2 6\n",
"output": "0\n"
},
{
"input": "100000 999887641\n",
"output": "3\n"
},
{
"input": "89874 1\n",
"output": "1\n"
},
{
"input": "10 3\n",
"output": "2\n"
},
{
"input": "19999 400000000\n",
"output": "0\n"
},
{
"input": "50000 989460910\n",
"output": "4\n"
},
{
"input": "100000 551350800\n",
"output": "392\n"
},
{
"input": "22741 989460910\n",
"output": "0\n"
},
{
"input": "100000 183783600\n",
"output": "438\n"
},
{
"input": "17286 948615687\n",
"output": "0\n"
},
{
"input": "100000 2162160\n",
"output": "282\n"
},
{
"input": "9 12\n",
"output": "4\n"
},
{
"input": "20000 400000000\n",
"output": "1\n"
},
{
"input": "20 100\n",
"output": "3\n"
},
{
"input": "31620 999887641\n",
"output": "0\n"
},
{
"input": "100000 4324320\n",
"output": "320\n"
},
{
"input": "10 123\n",
"output": "0\n"
},
{
"input": "31622 999887641\n",
"output": "1\n"
},
{
"input": "100000 3628800\n",
"output": "220\n"
},
{
"input": "1 1\n",
"output": "1\n"
},
{
"input": "100000 39916800\n",
"output": "328\n"
}
] |
code_contests
|
python
| 0.8 |
53cb17d0410a75216170922d84eb00b6
|
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input
The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row.
The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl.
Output
On the first line print integer k — the maximal number of segments in a partition of the row.
Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment.
Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type.
If there are several optimal solutions print any of them. You can print the segments in any order.
If there are no correct partitions of the row print the number "-1".
Examples
Input
5
1 2 3 4 1
Output
1
1 5
Input
5
1 2 3 4 5
Output
-1
Input
7
1 2 1 3 1 2 1
Output
2
1 3
4 7
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n=int(input())
d={}
b=[]
e=1
a=list(map(int,input().split()))
for i in range(n):
if a[i] in d:
b.append([e,i+1])
e=i+2
d.clear()
else:
d[a[i]]=i+1
if len(b)==0:
print(-1)
exit()
print(len(b))
k=b[-1]
b[-1]=[k[0],n]
for i in b:
print(*i)
|
python
|
code_algorithm
|
[
{
"input": "5\n1 2 3 4 1\n",
"output": "1\n1 5\n"
},
{
"input": "7\n1 2 1 3 1 2 1\n",
"output": "2\n1 3\n4 7\n"
},
{
"input": "5\n1 2 3 4 5\n",
"output": "-1\n"
},
{
"input": "7\n13 9 19 13 3 13 12\n",
"output": "1\n1 7\n"
},
{
"input": "4\n1 2 1 2\n",
"output": "1\n1 4\n"
},
{
"input": "5\n1 2 2 2 3\n",
"output": "1\n1 5\n"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "6\n1 2\n3 4\n5 6\n7 8\n9 10\n11 13\n"
},
{
"input": "3\n1 1 1\n",
"output": "1\n1 3\n"
},
{
"input": "11\n1 1 2 1 2 1 2 1 2 1 1\n",
"output": "4\n1 2\n3 5\n6 8\n9 11\n"
},
{
"input": "1\n576560149\n",
"output": "-1\n"
},
{
"input": "10\n522312461 21923894 21923894 544064902 488228616 329635457 522312461 488228616 654502493 598654597\n",
"output": "2\n1 3\n4 10\n"
},
{
"input": "10\n933677171 80672280 80672280 933677171 933677171 933677171 933677171 80672280 80672280 933677171\n",
"output": "4\n1 3\n4 5\n6 7\n8 10\n"
},
{
"input": "9\n1 2 1 2 1 2 1 2 1\n",
"output": "3\n1 3\n4 6\n7 9\n"
},
{
"input": "5\n1 2 2 2 1\n",
"output": "1\n1 5\n"
},
{
"input": "10\n460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451\n",
"output": "5\n1 2\n3 4\n5 6\n7 8\n9 10\n"
}
] |
code_contests
|
python
| 0 |
ca0cdbada85cc1fd12fadf743323b561
|
Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known data structure: multiset.
Artem wants to create a basic multiset of integers. He wants these structure to support operations of three types:
1. Add integer to the multiset. Note that the difference between set and multiset is that multiset may store several instances of one integer.
2. Remove integer from the multiset. Only one instance of this integer is removed. Artem doesn't want to handle any exceptions, so he assumes that every time remove operation is called, that integer is presented in the multiset.
3. Count the number of instances of the given integer that are stored in the multiset.
But what about time machine? Artem doesn't simply apply operations to the multiset one by one, he now travels to different moments of time and apply his operation there. Consider the following example.
* First Artem adds integer 5 to the multiset at the 1-st moment of time.
* Then Artem adds integer 3 to the multiset at the moment 5.
* Then Artem asks how many 5 are there in the multiset at moment 6. The answer is 1.
* Then Artem returns back in time and asks how many integers 3 are there in the set at moment 4. Since 3 was added only at moment 5, the number of integers 3 at moment 4 equals to 0.
* Then Artem goes back in time again and removes 5 from the multiset at moment 3.
* Finally Artyom asks at moment 7 how many integers 5 are there in the set. The result is 0, since we have removed 5 at the moment 3.
Note that Artem dislikes exceptions so much that he assures that after each change he makes all delete operations are applied only to element that is present in the multiset. The answer to the query of the third type is computed at the moment Artem makes the corresponding query and are not affected in any way by future changes he makes.
Help Artem implement time travellers multiset.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of Artem's queries.
Then follow n lines with queries descriptions. Each of them contains three integers ai, ti and xi (1 ≤ ai ≤ 3, 1 ≤ ti, xi ≤ 109) — type of the query, moment of time Artem travels to in order to execute this query and the value of the query itself, respectively. It's guaranteed that all moments of time are distinct and that after each operation is applied all operations of the first and second types are consistent.
Output
For each ask operation output the number of instances of integer being queried at the given moment of time.
Examples
Input
6
1 1 5
3 5 5
1 2 5
3 6 5
2 3 5
3 7 5
Output
1
2
1
Input
3
1 1 1
2 2 1
3 3 1
Output
0
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
new = lambda xx: (xx|xx-1)+1
def buildBIT(bit,n):
for i in range(1,n+1):
x = new(i)
if x <= n:
bit[x] += bit[i]
def pointUpdate(bit,point,n,diff):
while point <= n:
bit[point] += diff
point = new(point)
def calculatePrefix(bit,point):
su = 0
while point:
su += bit[point]
point &= point-1
return su
def rangeQuery(bit,start,stop):
# [start,stop]
return calculatePrefix(bit,stop)-calculatePrefix(bit,start-1)
def compressCoordinate(lst):
return {i:ind+1 for ind,i in enumerate(sorted(set(lst)))}
def main():
from collections import defaultdict
n = int(input())
dct = defaultdict(list)
oper = [list(map(int,input().split())) for _ in range(n)]
for a,t,x in oper:
dct[x].append(t)
new = {i:compressCoordinate(dct[i]) for i in dct}
for i in range(n):
oper[i][1] = new[oper[i][2]][oper[i][1]]
bit = {i:[0]*(len(dct[i])+1) for i in dct}
for a,t,x in oper:
if a == 1:
pointUpdate(bit[x],t,len(bit[x])-1,1)
elif a == 2:
pointUpdate(bit[x],t,len(bit[x])-1,-1)
else:
print(calculatePrefix(bit[x],t))
# Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
|
python
|
code_algorithm
|
[
{
"input": "3\n1 1 1\n2 2 1\n3 3 1\n",
"output": "0\n"
},
{
"input": "6\n1 1 5\n3 5 5\n1 2 5\n3 6 5\n2 3 5\n3 7 5\n",
"output": "1\n2\n1\n"
},
{
"input": "10\n1 1 1000000000\n1 4 1000000000\n2 2 1000000000\n1 5 1000000000\n1 8 1000000000\n2 15 1000000000\n3 3 1000000000\n3 10 1000000000\n3 6 1000000000\n3 7 1000000000\n",
"output": "0\n3\n2\n2\n"
},
{
"input": "20\n1 1 1\n1 2 2\n1 3 3\n1 4 4\n1 5 5\n2 11 5\n2 12 4\n2 13 3\n2 14 2\n2 15 1\n3 6 1\n3 7 2\n3 8 3\n3 9 4\n3 10 5\n3 16 1\n3 17 2\n3 18 3\n3 19 4\n3 20 5\n",
"output": "1\n1\n1\n1\n1\n0\n0\n0\n0\n0\n"
},
{
"input": "12\n1 9 1\n1 8 1\n1 7 1\n1 6 1\n1 1 1\n1 2 1\n1 3 1\n1 4 1\n2 5 1\n3 12 1\n3 14 2\n3 15 999999999\n",
"output": "7\n0\n0\n"
}
] |
code_contests
|
python
| 0.4 |
842139d7d66d3d425fcf144d8544aa3e
|
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n=int(input())
A=[]
js=0
B=[]
for i in range(n):
A.append(list(map(int,input().split())))
def product(a,b,c):
pr=0
for m in range(5):
pr=pr+(A[b][m]-A[a][m])*(A[c][m]-A[a][m])
return (pr)
if(n>11):
print(0)
else:
for j in range(n):
k=0
l=0
flag=0
while(k<n):
l=k+1
while(l<n):
pro=product(j,k,l)
if(l!=j and k!=j and pro>0):
flag=1
break
else:
l=l+1
if(flag==1):
break
else:
k=k+1
if(k==n):
js=js+1
B.append(j+1)
print(js)
for f in range(js):
print(B[f])
|
python
|
code_algorithm
|
[
{
"input": "3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0\n",
"output": "0\n"
},
{
"input": "6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1\n",
"output": "1\n1\n"
},
{
"input": "10\n0 -110 68 -51 -155\n-85 -110 68 -51 -155\n85 -70 51 68 -230\n0 -40 51 68 75\n0 5 -51 -68 -190\n85 0 0 0 0\n85 -115 -68 51 35\n85 -75 -187 34 -40\n-85 -110 -136 102 -155\n85 -110 -17 119 -155\n",
"output": "0\n"
},
{
"input": "11\n1 0 0 0 0\n-1 0 0 0 0\n0 1 0 0 0\n0 -1 0 0 0\n0 0 1 0 0\n0 0 -1 0 0\n0 0 0 1 0\n0 0 0 -1 0\n0 0 0 0 1\n0 0 0 0 -1\n0 0 0 0 0\n",
"output": "1\n11\n"
},
{
"input": "8\n-559 581 509 257 343\n-544 451 569 277 343\n-451 451 434 401 343\n-559 451 509 257 83\n-664 451 89 117 343\n-559 451 509 257 993\n-715 451 509 374 343\n-811 451 684 -79 343\n",
"output": "0\n"
},
{
"input": "6\n-305 -390 638 -623 343\n479 755 -343 144 89\n-268 843 -461 989 -301\n-986 -274 347 -847 -728\n278 718 -372 -674 270\n-477 562 -489 -858 611\n",
"output": "0\n"
},
{
"input": "11\n358 -724 -232 53 -520\n486 -554 -328 53 -220\n358 -554 -232 -372 -520\n358 -554 -232 308 -520\n868 -554 448 53 -520\n478 -554 -322 53 -600\n358 296 -232 53 -520\n256 -554 -368 53 -520\n230 -554 -136 53 -820\n-182 -554 173 53 -160\n358 -554 -232 53 -520\n",
"output": "1\n11\n"
},
{
"input": "11\n8 8 8 8 8\n2 2 2 2 2\n0 0 0 0 0\n6 6 6 6 6\n7 7 7 7 7\n10 10 10 10 10\n9 9 9 9 9\n3 3 3 3 3\n1 1 1 1 1\n5 5 5 5 5\n4 4 4 4 4\n",
"output": "0\n"
},
{
"input": "2\n0 1 2 3 4\n5 6 7 8 9\n",
"output": "2\n1\n2\n"
},
{
"input": "1\n0 0 0 0 0\n",
"output": "1\n1\n"
},
{
"input": "4\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 1 1 0 0\n",
"output": "0\n"
},
{
"input": "7\n49 457 -650 325 -325\n0 0 325 325 0\n253 204 -325 0 -325\n204 -253 325 325 325\n408 -506 -325 -325 325\n49 457 -650 325 -650\n0 0 0 650 -325\n",
"output": "0\n"
},
{
"input": "10\n-705 38 170 -768 689\n-705 86 248 -768 709\n-705 86 170 -742 709\n-705 86 144 -768 709\n-705 86 170 -820 709\n-705 106 170 -768 661\n-822 86 170 -768 709\n-705 98 170 -768 714\n-705 86 170 -768 709\n-601 86 170 -768 709\n",
"output": "1\n9\n"
}
] |
code_contests
|
python
| 0.2 |
59ce6c54070d61b3673538696e1453d8
|
This problem is same as the previous one, but has larger constraints.
Shiro's just moved to the new house. She wants to invite all friends of her to the house so they can play monopoly. However, her house is too small, so she can only invite one friend at a time.
For each of the n days since the day Shiro moved to the new house, there will be exactly one cat coming to the Shiro's house. The cat coming in the i-th day has a ribbon with color u_i. Shiro wants to know the largest number x, such that if we consider the streak of the first x days, it is possible to remove exactly one day from this streak so that every ribbon color that has appeared among the remaining x - 1 will have the same number of occurrences.
For example, consider the following sequence of u_i: [2, 2, 1, 1, 5, 4, 4, 5]. Then x = 7 makes a streak, since if we remove the leftmost u_i = 5, each ribbon color will appear exactly twice in the prefix of x - 1 days. Note that x = 8 doesn't form a streak, since you must remove exactly one day.
Since Shiro is just a cat, she is not very good at counting and needs your help finding the longest streak.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the total number of days.
The second line contains n integers u_1, u_2, …, u_n (1 ≤ u_i ≤ 10^5) — the colors of the ribbons the cats wear.
Output
Print a single integer x — the largest possible streak of days.
Examples
Input
13
1 1 1 2 2 2 3 3 3 4 4 4 5
Output
13
Input
5
10 100 20 200 1
Output
5
Input
1
100000
Output
1
Input
7
3 2 1 1 4 5 1
Output
6
Input
6
1 1 1 2 2 2
Output
5
Note
In the first example, we can choose the longest streak of 13 days, since upon removing the last day out of the streak, all of the remaining colors 1, 2, 3, and 4 will have the same number of occurrences of 3. Note that the streak can also be 10 days (by removing the 10-th day from this streak) but we are interested in the longest streak.
In the fourth example, if we take the streak of the first 6 days, we can remove the third day from this streak then all of the remaining colors 1, 2, 3, 4 and 5 will occur exactly once.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n = int(input())
a = list(map(int,input().split()))
if(n == 1 or n == 2):
print(n)
exit()
notpar = 0
occ = [0 for i in range(10**5 + 1)]
base = 1
gotone = False
leader = -1
leadby = 0
best = 0
occ[a[0]] += 1
cnt = 1
at1 = 1
for i in range(1, n):
occ[a[i]] +=1
if(occ[a[i]] == 1):
notpar += 1
at1 += 1
cnt += 1
elif(occ[a[i]] == 2):
at1 -= 1
if(occ[a[i]] == base):
notpar -= 1
elif(occ[a[i]] > base):
if(gotone):
if(a[i] != leader):
base += 1
notpar = cnt - 2
leadby -= 1
if(leadby == 0):
gotone = False
leader = -1
else:
leadby += 1
else:
gotone = True
leader = a[i]
leadby = 1
if(notpar == 0 and (leadby == 1 or (leadby == 0 and base == 1)) or (notpar == 1 and leadby == 0 and at1 > 0)):
best = i + 1
if(cnt == 1):
best = i + 1
#print(i, base, leader, leadby, gotone, notpar, cnt)
print(best)
|
python
|
code_algorithm
|
[
{
"input": "5\n10 100 20 200 1\n",
"output": "5\n"
},
{
"input": "6\n1 1 1 2 2 2\n",
"output": "5\n"
},
{
"input": "1\n100000\n",
"output": "1\n"
},
{
"input": "13\n1 1 1 2 2 2 3 3 3 4 4 4 5\n",
"output": "13\n"
},
{
"input": "7\n3 2 1 1 4 5 1\n",
"output": "6\n"
},
{
"input": "10\n30518 96518 74071 59971 50121 4862 43967 73607 19138 90754\n",
"output": "10\n"
},
{
"input": "10\n4 10 4 4 5 10 10 4 10 10\n",
"output": "9\n"
},
{
"input": "10\n63649 14562 779 31060 84730 3390 1402 70955 27426 79066\n",
"output": "10\n"
},
{
"input": "10\n8 8 1 1 1 2 7 7 8 4\n",
"output": "5\n"
},
{
"input": "10\n4131 4373 75721 60904 4027 25878 13621 3245 60722 8295\n",
"output": "10\n"
},
{
"input": "10\n1 4 5 2 5 2 3 3 4 1\n",
"output": "9\n"
},
{
"input": "6\n6 1 2 1 6 2\n",
"output": "5\n"
},
{
"input": "10\n30518 30518 30518 30518 30518 30518 30518 30518 30518 30518\n",
"output": "10\n"
}
] |
code_contests
|
python
| 0.2 |
4e78e4cd4170845322b0130f4172bfb7
|
The only difference between the easy and the hard versions is constraints.
A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between them. For example, for the string "abaca" the following strings are subsequences: "abaca", "aba", "aaa", "a" and "" (empty string). But the following strings are not subsequences: "aabaca", "cb" and "bcaa".
You are given a string s consisting of n lowercase Latin letters.
In one move you can take any subsequence t of the given string and add it to the set S. The set S can't contain duplicates. This move costs n - |t|, where |t| is the length of the added subsequence (i.e. the price equals to the number of the deleted characters).
Your task is to find out the minimum possible total cost to obtain a set S of size k or report that it is impossible to do so.
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10^{12}) — the length of the string and the size of the set, correspondingly.
The second line of the input contains a string s consisting of n lowercase Latin letters.
Output
Print one integer — if it is impossible to obtain the set S of size k, print -1. Otherwise, print the minimum possible total cost to do it.
Examples
Input
4 5
asdf
Output
4
Input
5 6
aaaaa
Output
15
Input
5 7
aaaaa
Output
-1
Input
10 100
ajihiushda
Output
233
Note
In the first example we can generate S = { "asdf", "asd", "adf", "asf", "sdf" }. The cost of the first element in S is 0 and the cost of the others is 1. So the total cost of S is 4.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
def main():
from sys import stdin
input = stdin.readline
# input = open('25-B.txt', 'r').readline
n, k = map(int, input().split())
s = input()[:-1]
dp = [[0] * 26 for i in range(n + 1)]
dp[0][0] = 1
for ch in s:
j = ord(ch) - ord('a')
for i in range(n, 0, -1):
dp[i][j] = sum(dp[i - 1])
x = 0
y = 0
for i in range(n, -1, -1):
if x + sum(dp[i]) >= k:
print(k * n - y - (k - x) * i)
break
x += sum(dp[i])
y += i * sum(dp[i])
else:
print(-1)
main()
|
python
|
code_algorithm
|
[
{
"input": "4 5\nasdf\n",
"output": "4\n"
},
{
"input": "5 6\naaaaa\n",
"output": "15\n"
},
{
"input": "5 7\naaaaa\n",
"output": "-1\n"
},
{
"input": "10 100\najihiushda\n",
"output": "233\n"
},
{
"input": "50 50\ndxldyzmsrrwzwaofkcxwehgvtrsximxgdqrhjthkgfucrjdvwl\n",
"output": "49\n"
},
{
"input": "10 25\nbpehfvamul\n",
"output": "38\n"
},
{
"input": "1 10\ns\n",
"output": "-1\n"
},
{
"input": "10 10\nhittmcsvmo\n",
"output": "9\n"
},
{
"input": "30 656341937\nqrzlwlvhfatfwmlpvndtgrxyphfjnn\n",
"output": "-1\n"
},
{
"input": "5 50\nbhhaj\n",
"output": "-1\n"
},
{
"input": "10 1023\nhsjztkorpv\n",
"output": "5110\n"
},
{
"input": "5 5\nwnxcc\n",
"output": "4\n"
},
{
"input": "7 100\nasdfgha\n",
"output": "299\n"
},
{
"input": "10 889\nltwnwdluhx\n",
"output": "-1\n"
},
{
"input": "1 50\ns\n",
"output": "-1\n"
},
{
"input": "45 1000000000000\nsakuacuunmcmnrqewlpukirumntsygulpywneaaipboho\n",
"output": "15850182637674\n"
},
{
"input": "100 5\nayvharmmxcxhibqfixtjmhurxchhkvhubxjcveajrkssbsbrxpijxolrtmvanzyybzbdpgzocicakipmkpxhcjtegksbvabfghpf\n",
"output": "4\n"
},
{
"input": "25 5\nxcrhvdevynotmxzxqafeijadl\n",
"output": "4\n"
},
{
"input": "25 10\nquomusasazkywxnfvfjimiytg\n",
"output": "9\n"
},
{
"input": "1 5\nw\n",
"output": "-1\n"
},
{
"input": "7 87\ndjfjfdj\n",
"output": "-1\n"
},
{
"input": "40 1000000000000\nazipixmkcmxyzsyxerzggtjbfknpebgtwggrhyuu\n",
"output": "-1\n"
},
{
"input": "100 10\nmaorgdrrnhytzrswsuomkdkdrqyqmwcdekbkgymqaqnacrbbbvwqzcqsdboztxygqjxsqwhjnftiguhemxhvvrnjwpdvbjexhlqt\n",
"output": "9\n"
},
{
"input": "30 642235040\nqxkzwaiqbtffqogfkznyjfcshyjoao\n",
"output": "9468426224\n"
},
{
"input": "1 25\no\n",
"output": "-1\n"
},
{
"input": "50 10\ndnovfytvosvwbeykfnkkebgonntfqapbuphspjsclowovrgrae\n",
"output": "9\n"
},
{
"input": "5 10\nbzitq\n",
"output": "13\n"
},
{
"input": "100 25\nihxdcuahvemeipfkmdqqiktqnyrsrxfdmclwmvgretjsulnlxlvcuvjxxvnmrhjlerhvrzfdvxehnvgslrjzvbscfehtsxvvcabq\n",
"output": "24\n"
},
{
"input": "5 25\nwjsel\n",
"output": "52\n"
},
{
"input": "1 2\nu\n",
"output": "1\n"
},
{
"input": "6 50\nfdjfjd\n",
"output": "139\n"
},
{
"input": "50 2\nvjrvahvokiudpiocpvoqsqhukavyrckhcbctrbprqxizcofrfr\n",
"output": "1\n"
},
{
"input": "6 49\nfdjfjd\n",
"output": "133\n"
},
{
"input": "20 999409\nbfxajupatylfrczbfsgi\n",
"output": "-1\n"
},
{
"input": "25 50\nqbntoutmcylbrtfzauvxmqvyn\n",
"output": "73\n"
},
{
"input": "100 100\noaxflkpcwimoiocbudbxgzvekmengbumbcumwxjjcdtqzlijdqoelpevcqfiommjgioxaxdrhbyoszifgxjfprraisgzpxrjhyln\n",
"output": "101\n"
},
{
"input": "7 100\nasdagha\n",
"output": "309\n"
},
{
"input": "10 50\nfpsafelqno\n",
"output": "88\n"
},
{
"input": "25 100\niasrasqpntslqjkefyzbklmtr\n",
"output": "173\n"
},
{
"input": "20 688037\nttwnmquescldhxwdzxdi\n",
"output": "6756991\n"
},
{
"input": "100 50\nmhnzadklojbuumkrxjayikjhwuxihgkinllackcavhjpxlydxcgcxjdloyicqkfwulytkpiflkrsdjseynwohymlehmtgswjfxzp\n",
"output": "49\n"
},
{
"input": "1 100\np\n",
"output": "-1\n"
},
{
"input": "50 25\naxxjyqblymjgkciyzwnochociulhtdsabhrdtfldmtugmlsbwu\n",
"output": "24\n"
},
{
"input": "40 313915447382\nfjljjtmxouncvyrsawkkflkzarwolwkuznyqtnnk\n",
"output": "6160842348859\n"
},
{
"input": "50 100\nbybehmveefoqvsronaztdwjzhfspmoszgibthctsamgixqailz\n",
"output": "149\n"
},
{
"input": "30 363904895\nfwhadwbsskiitjkuwupbrsobdttmqz\n",
"output": "5380084386\n"
},
{
"input": "100 1\nyyojtyktazyfegvnnsexxiosqxdlpdwlyojsghpvjpavnvjvttbylqcdabyhleltltzalmgoelxdalcbjejsjxnfebzsxusnujdy\n",
"output": "0\n"
},
{
"input": "40 550188209247\nsxspwbifsqgndvxlrrdxwyvwygtvyiusxiyjgnuz\n",
"output": "10734053749240\n"
},
{
"input": "7 86\ndjfjfdj\n",
"output": "273\n"
},
{
"input": "10 100\nwfykkiubdk\n",
"output": "242\n"
},
{
"input": "50 1000000000000\nfltdysjwwsfhuklxnzfesrnmvdinquktuaaqduxyacvdsgxshy\n",
"output": "13601148116701\n"
},
{
"input": "5 100\nnvyoj\n",
"output": "-1\n"
},
{
"input": "25 2\nvwxvqvouhtbprdhrhlhotyqjp\n",
"output": "1\n"
},
{
"input": "100 1000000\npjsakcxuoyyivmfmzuqafyqvcmvmjqitckfnixurgmdshuejptqvrwomnalijputhnylyqesycwjvxflneuwyecyiaxwahlougoa\n",
"output": "3833346\n"
},
{
"input": "20 1019648\nalhmijcknryfkeurtcqk\n",
"output": "10129664\n"
},
{
"input": "10 5\nnrdmcxnnbb\n",
"output": "4\n"
},
{
"input": "41 1000000000000\nxfubvojhogeggntkezhpbigfqbdkdnzxueylitqxr\n",
"output": "19636604785323\n"
},
{
"input": "100 10000\nxxprqtlnkqpurdilqdjnnmpsloumhbxymxmzplcwuyfexardpwodnhhkktipqcfwudbivaehhmqexffzgkpztmwrpzzzoudypoqe\n",
"output": "25621\n"
},
{
"input": "50 5\nxplfeoiobchekdeiwkmgkbunixgcyzngznoicllobsqbpkbwnp\n",
"output": "4\n"
},
{
"input": "40 739620532705\nfdawkecoubadbyxcmkahawfhiapgvwvdhjklxaec\n",
"output": "-1\n"
},
{
"input": "10 2\nmllbxoykle\n",
"output": "1\n"
},
{
"input": "100 1000000000000\ndjgykfqaywhkhpocyxcpvbiiouyielmighclnuopadzuvrirbecucwnzwahahagvfstbxxaednajfauscxwttiglbbxtomnnalcl\n",
"output": "8854753825335\n"
},
{
"input": "100 1000000000\ngaoxttalzmmhfhjphaftcwnnhjotuyxcnzlhqoynmcfhhmpzumichrghshdmbtjxmkwegnajkbtfhglkhnapizhltzxgfhyxyvfc\n",
"output": "5936118201\n"
},
{
"input": "6 51\nfdjfjd\n",
"output": "-1\n"
},
{
"input": "10 992\nlzgbtqybar\n",
"output": "4912\n"
},
{
"input": "7 100\nasafgsa\n",
"output": "319\n"
},
{
"input": "25 25\nmdxynjiiivwifvaspplpkoffc\n",
"output": "27\n"
},
{
"input": "5 2\nufdpx\n",
"output": "1\n"
},
{
"input": "100 2\nzqdvwjzmgfmgngaxzgvuuukxyfzecafuflxpkvemenkorwhmnsxuoxsatlymyjugwjmutfxcksnwhxrwruyqbouyflxhwqhflczz\n",
"output": "1\n"
},
{
"input": "100 1000\nojlksfclwvhxhyhddsosbkwxgpbhnvdgtvvcvrajpiimqsqlxicqyehwsiqcbzqzdxsfbtlldefawclzezvbpwiomvkneibmwtfw\n",
"output": "1902\n"
}
] |
code_contests
|
python
| 0 |
483ab27a6fb381a17d6a722341395dd1
|
Filled with optimism, Hyunuk will host a conference about how great this new year will be!
The conference will have n lectures. Hyunuk has two candidate venues a and b. For each of the n lectures, the speaker specified two time intervals [sa_i, ea_i] (sa_i ≤ ea_i) and [sb_i, eb_i] (sb_i ≤ eb_i). If the conference is situated in venue a, the lecture will be held from sa_i to ea_i, and if the conference is situated in venue b, the lecture will be held from sb_i to eb_i. Hyunuk will choose one of these venues and all lectures will be held at that venue.
Two lectures are said to overlap if they share any point in time in common. Formally, a lecture held in interval [x, y] overlaps with a lecture held in interval [u, v] if and only if max(x, u) ≤ min(y, v).
We say that a participant can attend a subset s of the lectures if the lectures in s do not pairwise overlap (i.e. no two lectures overlap). Note that the possibility of attending may depend on whether Hyunuk selected venue a or venue b to hold the conference.
A subset of lectures s is said to be venue-sensitive if, for one of the venues, the participant can attend s, but for the other venue, the participant cannot attend s.
A venue-sensitive set is problematic for a participant who is interested in attending the lectures in s because the participant cannot be sure whether the lecture times will overlap. Hyunuk will be happy if and only if there are no venue-sensitive sets. Determine whether Hyunuk will be happy.
Input
The first line contains an integer n (1 ≤ n ≤ 100 000), the number of lectures held in the conference.
Each of the next n lines contains four integers sa_i, ea_i, sb_i, eb_i (1 ≤ sa_i, ea_i, sb_i, eb_i ≤ 10^9, sa_i ≤ ea_i, sb_i ≤ eb_i).
Output
Print "YES" if Hyunuk will be happy. Print "NO" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
2
1 2 3 6
3 4 7 8
Output
YES
Input
3
1 3 2 4
4 5 6 7
3 4 5 5
Output
NO
Input
6
1 5 2 9
2 4 5 8
3 6 7 11
7 10 12 16
8 11 13 17
9 12 14 18
Output
YES
Note
In second example, lecture set \{1, 3\} is venue-sensitive. Because participant can't attend this lectures in venue a, but can attend in venue b.
In first and third example, venue-sensitive set does not exist.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import sys
input = sys.stdin.readline
import heapq
n=int(input())
C=[tuple(map(int,input().split())) for i in range(n)]
CA=[]
CB=[]
for ind,(a,b,c,d) in enumerate(C):
CA.append((a,0,ind))
CA.append((b,1,ind))
CB.append((c,0,ind))
CB.append((d,1,ind))
CA.sort()
CB.sort()
SMAX=[]
EMIN=[]
FINISHED=[0]*n
for time,flag,ind in CA:
if flag==0:
heapq.heappush(SMAX,(-C[ind][2],ind))
heapq.heappush(EMIN,(C[ind][3],ind))
while FINISHED[SMAX[0][1]]:
heapq.heappop(SMAX)
while FINISHED[EMIN[0][1]]:
heapq.heappop(EMIN)
if -SMAX[0][0]>EMIN[0][0]:
print("NO")
sys.exit()
else:
FINISHED[ind]=1
SMAX=[]
EMIN=[]
FINISHED=[0]*n
for time,flag,ind in CB:
if flag==0:
heapq.heappush(SMAX,(-C[ind][0],ind))
heapq.heappush(EMIN,(C[ind][1],ind))
while FINISHED[SMAX[0][1]]:
heapq.heappop(SMAX)
while FINISHED[EMIN[0][1]]:
heapq.heappop(EMIN)
if -SMAX[0][0]>EMIN[0][0]:
print("NO")
sys.exit()
else:
FINISHED[ind]=1
print("YES")
|
python
|
code_algorithm
|
[
{
"input": "3\n1 3 2 4\n4 5 6 7\n3 4 5 5\n",
"output": "NO\n"
},
{
"input": "6\n1 5 2 9\n2 4 5 8\n3 6 7 11\n7 10 12 16\n8 11 13 17\n9 12 14 18\n",
"output": "YES\n"
},
{
"input": "2\n1 2 3 6\n3 4 7 8\n",
"output": "YES\n"
},
{
"input": "4\n1 5 1 3\n2 6 2 4\n3 7 3 5\n4 8 4 6\n",
"output": "NO\n"
},
{
"input": "4\n1 5 1 5\n2 3 2 3\n4 6 6 8\n100 200 100 200\n",
"output": "NO\n"
},
{
"input": "4\n1 2 5 6\n2 3 1 2\n5 6 2 3\n6 7 6 7\n",
"output": "NO\n"
},
{
"input": "4\n1 3 5 7\n2 4 1 3\n5 7 6 8\n6 8 2 4\n",
"output": "NO\n"
},
{
"input": "16\n3 4 3 4\n3 4 1 2\n1 2 3 4\n1 2 1 2\n1 2 1 2\n1 2 3 4\n3 4 1 2\n3 4 3 4\n1 2 1 2\n1 2 3 4\n3 4 1 2\n3 4 3 4\n3 4 3 4\n3 4 1 2\n1 2 3 4\n1 2 1 2\n",
"output": "NO\n"
},
{
"input": "2\n311374951 311375694 79710796 79710890\n311374081 311374676 79712235 79712404\n",
"output": "YES\n"
},
{
"input": "6\n1 6 7 12\n2 3 2 3\n4 5 4 5\n7 12 1 6\n8 9 8 9\n10 11 10 11\n",
"output": "NO\n"
},
{
"input": "4\n1 4 5 8\n2 3 2 3\n6 7 6 7\n5 8 1 4\n",
"output": "NO\n"
},
{
"input": "4\n1 2 1 2\n2 3 3 4\n3 4 2 3\n4 5 4 5\n",
"output": "NO\n"
},
{
"input": "2\n4 4 4 5\n4 5 1 2\n",
"output": "NO\n"
},
{
"input": "4\n1 1 1 1\n2 2 2 2\n3 3 1 1\n4 4 4 4\n",
"output": "NO\n"
},
{
"input": "3\n1 4 1 2\n2 5 2 3\n3 6 3 4\n",
"output": "NO\n"
},
{
"input": "4\n1 1 1 1\n1 1 2 2\n2 2 1 1\n2 2 2 2\n",
"output": "NO\n"
},
{
"input": "5\n5 15 5 15\n3 4 3 5\n6 7 6 7\n4 5 8 16\n8 9 16 17\n",
"output": "NO\n"
},
{
"input": "4\n1 5 1 5\n2 8 7 10\n7 10 2 8\n9 20 9 20\n",
"output": "NO\n"
},
{
"input": "6\n1 4 11 14\n2 5 2 5\n3 6 3 6\n11 14 1 4\n12 15 12 15\n13 16 13 16\n",
"output": "NO\n"
},
{
"input": "4\n1 2 1 2\n3 4 3 4\n1 2 3 4\n3 4 1 2\n",
"output": "NO\n"
},
{
"input": "4\n544431836 544432042 793496989 793497079\n544429970 544430041 793496343 793496350\n544432412 544432541 793497670 793498269\n544431029 544431033 793494552 793494859\n",
"output": "YES\n"
},
{
"input": "5\n1 4 1 4\n2 6 5 8\n5 8 2 6\n7 10 7 10\n9 11 9 11\n",
"output": "NO\n"
},
{
"input": "5\n1 6 1 4\n2 7 2 5\n3 8 3 6\n4 9 4 7\n5 10 5 8\n",
"output": "NO\n"
},
{
"input": "3\n1 3 1 4\n3 5 2 5\n5 7 3 6\n",
"output": "NO\n"
},
{
"input": "1\n21044762 968128997 570202182 610619156\n",
"output": "YES\n"
},
{
"input": "5\n1 10 1 10\n2 20 11 30\n11 30 2 20\n21 40 21 40\n31 50 31 50\n",
"output": "NO\n"
},
{
"input": "4\n922033367 922033530 246113700 246113747\n922034178 922034457 246112224 246112584\n922032889 922035756 246111602 246114286\n922032155 922035184 246111686 246114644\n",
"output": "YES\n"
}
] |
code_contests
|
python
| 0 |
336621ebf397961a513333ee95e29199
|
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, n coins of arbitrary values a1, a2, ..., an. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.
As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.
Input
The first line contains integer n (1 ≤ n ≤ 100) — the number of coins. The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the coins' values. All numbers are separated with spaces.
Output
In the single line print the single number — the minimum needed number of coins.
Examples
Input
2
3 3
Output
2
Input
3
2 1 2
Output
2
Note
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n = int(input())
a = sorted(list(map(int, input().split())))[::-1]
b = sum(a)//2
sum1 = count = 0
for i in a:
sum1+=i
count+=1
if sum1>b:
break
print(count)
|
python
|
code_algorithm
|
[
{
"input": "2\n3 3\n",
"output": "2\n"
},
{
"input": "3\n2 1 2\n",
"output": "2\n"
},
{
"input": "100\n5 5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3\n",
"output": "33\n"
},
{
"input": "5\n2 2 2 4 4\n",
"output": "2\n"
},
{
"input": "100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52\n",
"output": "29\n"
},
{
"input": "5\n3 2 3 3 1\n",
"output": "3\n"
},
{
"input": "7\n10 10 5 5 5 5 1\n",
"output": "3\n"
},
{
"input": "3\n2 1 3\n",
"output": "2\n"
},
{
"input": "6\n1 1 1 1 1 1\n",
"output": "4\n"
},
{
"input": "20\n2 1 2 2 2 1 1 2 1 2 2 1 1 1 1 2 1 1 1 1\n",
"output": "8\n"
},
{
"input": "7\n1 10 1 2 1 1 1\n",
"output": "1\n"
},
{
"input": "20\n4 2 4 4 3 4 2 2 4 2 3 1 1 2 2 3 3 3 1 4\n",
"output": "8\n"
},
{
"input": "1\n5\n",
"output": "1\n"
},
{
"input": "100\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2\n",
"output": "30\n"
},
{
"input": "4\n100 99 99 100\n",
"output": "2\n"
},
{
"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n",
"output": "30\n"
},
{
"input": "4\n4 1 2 3\n",
"output": "2\n"
},
{
"input": "50\n19 2 12 26 17 27 10 26 17 17 5 24 11 15 3 9 16 18 19 1 25 23 18 6 2 7 25 7 21 25 13 29 16 9 25 3 14 30 18 4 10 28 6 10 8 2 2 4 8 28\n",
"output": "14\n"
},
{
"input": "100\n16 9 11 8 11 4 9 17 4 8 4 10 9 10 6 3 3 15 1 6 1 15 12 18 6 14 13 18 1 7 18 4 10 7 10 12 3 16 14 4 10 8 10 7 19 13 15 1 4 8 16 10 6 4 3 16 11 10 7 3 4 16 1 20 1 11 4 16 10 7 7 12 18 19 3 17 19 3 4 19 2 12 11 3 18 20 2 2 14 4 20 13 13 11 16 20 19 14 7 2\n",
"output": "29\n"
},
{
"input": "20\n7 84 100 10 31 35 41 2 63 44 57 4 63 11 23 49 98 71 16 90\n",
"output": "6\n"
},
{
"input": "20\n35 26 41 40 45 46 22 26 39 23 11 15 47 42 18 15 27 10 45 40\n",
"output": "8\n"
},
{
"input": "2\n2 1\n",
"output": "1\n"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "51\n"
},
{
"input": "1\n1\n",
"output": "1\n"
},
{
"input": "100\n2 46 4 6 38 19 15 34 10 35 37 30 3 25 5 45 40 45 33 31 6 20 10 44 11 9 2 14 35 5 9 23 20 2 48 22 25 35 38 31 24 33 35 16 4 30 27 10 12 22 6 24 12 30 23 21 14 12 32 21 7 12 25 43 18 34 34 28 47 13 28 43 18 39 44 42 35 26 35 14 8 29 32 20 29 3 20 6 20 9 9 27 8 42 10 37 42 27 8 1\n",
"output": "30\n"
},
{
"input": "70\n2 18 18 47 25 5 14 9 19 46 36 49 33 32 38 23 32 39 8 29 31 17 24 21 10 15 33 37 46 21 22 11 20 35 39 13 11 30 28 40 39 47 1 17 24 24 21 46 12 2 20 43 8 16 44 11 45 10 13 44 31 45 45 46 11 10 33 35 23 42\n",
"output": "22\n"
},
{
"input": "100\n1 2 2 1 2 1 1 2 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 1 1 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 1 1 1 2 1 1 1 1 2 2 2 2\n",
"output": "37\n"
},
{
"input": "100\n1 2 3 2 1 2 2 3 1 3 3 2 2 1 1 2 2 1 1 1 1 2 3 3 2 1 1 2 2 2 3 3 3 2 1 3 1 3 3 2 3 1 2 2 2 3 2 1 1 3 3 3 3 2 1 1 2 3 2 2 3 2 3 2 2 3 2 2 2 2 3 3 3 1 3 3 1 1 2 3 2 2 2 2 3 3 3 2 1 2 3 1 1 2 3 3 1 3 3 2\n",
"output": "36\n"
},
{
"input": "5\n4 2 2 2 2\n",
"output": "3\n"
}
] |
code_contests
|
python
| 0.7 |
6424820afb681c09a6bbd9ee3c249db3
|
An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!).
The flying saucer, on which the brave pioneers set off, consists of three sections. These sections are connected by a chain: the 1-st section is adjacent only to the 2-nd one, the 2-nd one — to the 1-st and the 3-rd ones, the 3-rd one — only to the 2-nd one. The transitions are possible only between the adjacent sections.
The spacecraft team consists of n aliens. Each of them is given a rank — an integer from 1 to n. The ranks of all astronauts are distinct. The rules established on the Saucer, state that an alien may move from section a to section b only if it is senior in rank to all aliens who are in the segments a and b (besides, the segments a and b are of course required to be adjacent). Any alien requires exactly 1 minute to make a move. Besides, safety regulations require that no more than one alien moved at the same minute along the ship.
Alien A is senior in rank to alien B, if the number indicating rank A, is more than the corresponding number for B.
At the moment the whole saucer team is in the 3-rd segment. They all need to move to the 1-st segment. One member of the crew, the alien with the identification number CFR-140, decided to calculate the minimum time (in minutes) they will need to perform this task.
Help CFR-140, figure out the minimum time (in minutes) that all the astronauts will need to move from the 3-rd segment to the 1-st one. Since this number can be rather large, count it modulo m.
Input
The first line contains two space-separated integers: n and m (1 ≤ n, m ≤ 109) — the number of aliens on the saucer and the number, modulo which you should print the answer, correspondingly.
Output
Print a single number — the answer to the problem modulo m.
Examples
Input
1 10
Output
2
Input
3 8
Output
2
Note
In the first sample the only crew member moves from segment 3 to segment 2, and then from segment 2 to segment 1 without any problems. Thus, the whole moving will take two minutes.
To briefly describe the movements in the second sample we will use value <image>, which would correspond to an alien with rank i moving from the segment in which it is at the moment, to the segment number j. Using these values, we will describe the movements between the segments in the second sample: <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>, <image>; In total: the aliens need 26 moves. The remainder after dividing 26 by 8 equals 2, so the answer to this test is 2.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
def binpow(a,n):
res = 1
while(n>0):
if(n&1):
res = (res*a)%m
a = (a*a)%m
n>>=1
return res
n,m = map(int,input().split())
ans = binpow(3,n)-1
if(ans%m ==0 and ans != 0):
print(m-1)
else:
print(ans%m)
|
python
|
code_algorithm
|
[
{
"input": "1 10\n",
"output": "2\n"
},
{
"input": "3 8\n",
"output": "2\n"
},
{
"input": "8 100\n",
"output": "60\n"
},
{
"input": "514853447 9\n",
"output": "8\n"
},
{
"input": "7 63\n",
"output": "44\n"
},
{
"input": "9 95\n",
"output": "17\n"
},
{
"input": "333734901 647005907\n",
"output": "40746267\n"
},
{
"input": "602799218 494169337\n",
"output": "105935725\n"
},
{
"input": "6 29\n",
"output": "3\n"
},
{
"input": "1 3\n",
"output": "2\n"
},
{
"input": "3 1\n",
"output": "0\n"
},
{
"input": "2 3\n",
"output": "2\n"
},
{
"input": "6 5\n",
"output": "3\n"
},
{
"input": "523061914 144515354\n",
"output": "127493116\n"
},
{
"input": "2 81\n",
"output": "8\n"
},
{
"input": "3 27\n",
"output": "26\n"
},
{
"input": "357780112 9\n",
"output": "8\n"
},
{
"input": "528551307 729\n",
"output": "728\n"
},
{
"input": "1 39\n",
"output": "2\n"
},
{
"input": "234899623 6561\n",
"output": "6560\n"
},
{
"input": "622152471 448257864\n",
"output": "210299666\n"
},
{
"input": "9 30\n",
"output": "2\n"
},
{
"input": "549662082 945236243\n",
"output": "239869294\n"
},
{
"input": "8 12\n",
"output": "8\n"
},
{
"input": "7 90\n",
"output": "26\n"
},
{
"input": "7 34\n",
"output": "10\n"
},
{
"input": "508185014 3\n",
"output": "2\n"
},
{
"input": "451688701 6561\n",
"output": "6560\n"
},
{
"input": "591892483 729\n",
"output": "728\n"
},
{
"input": "331358794 820674098\n",
"output": "2619146\n"
},
{
"input": "576449056 59049\n",
"output": "59048\n"
},
{
"input": "10 3\n",
"output": "2\n"
},
{
"input": "286996517 27\n",
"output": "26\n"
},
{
"input": "321823343 19683\n",
"output": "19682\n"
},
{
"input": "868095112 994962872\n",
"output": "606909752\n"
},
{
"input": "661983283 9\n",
"output": "8\n"
},
{
"input": "296519935 960061928\n",
"output": "171150618\n"
},
{
"input": "880162386 653879733\n",
"output": "193558859\n"
},
{
"input": "199154351 3\n",
"output": "2\n"
},
{
"input": "5 35\n",
"output": "32\n"
},
{
"input": "3 9\n",
"output": "8\n"
},
{
"input": "422262807 3\n",
"output": "2\n"
},
{
"input": "854939092 4244941\n",
"output": "2105846\n"
},
{
"input": "592821498 42617080\n",
"output": "2923848\n"
},
{
"input": "2 9\n",
"output": "8\n"
},
{
"input": "3 49\n",
"output": "26\n"
},
{
"input": "792362041 423498933\n",
"output": "182386349\n"
},
{
"input": "4 81\n",
"output": "80\n"
},
{
"input": "1 37\n",
"output": "2\n"
},
{
"input": "822957727 6561\n",
"output": "6560\n"
},
{
"input": "1 2\n",
"output": "0\n"
},
{
"input": "916546405 6561\n",
"output": "6560\n"
},
{
"input": "647732356 84460643\n",
"output": "28044795\n"
},
{
"input": "593511479 711449475\n",
"output": "641995841\n"
},
{
"input": "3 3\n",
"output": "2\n"
},
{
"input": "853906091 809812670\n",
"output": "50540996\n"
},
{
"input": "10 22\n",
"output": "0\n"
},
{
"input": "4 84\n",
"output": "80\n"
},
{
"input": "725891944 969448805\n",
"output": "599793690\n"
},
{
"input": "624216668 19683\n",
"output": "19682\n"
},
{
"input": "108260816 609551797\n",
"output": "237749529\n"
},
{
"input": "264926775 887044705\n",
"output": "448954191\n"
},
{
"input": "8 73\n",
"output": "63\n"
},
{
"input": "6 25\n",
"output": "3\n"
},
{
"input": "7 88\n",
"output": "74\n"
},
{
"input": "4 27\n",
"output": "26\n"
},
{
"input": "596386879 356583466\n",
"output": "134606022\n"
},
{
"input": "238972792 59049\n",
"output": "59048\n"
},
{
"input": "140068687 419634856\n",
"output": "40442298\n"
},
{
"input": "519976508 777084731\n",
"output": "290288763\n"
},
{
"input": "5 56\n",
"output": "18\n"
},
{
"input": "969271595 9\n",
"output": "8\n"
},
{
"input": "1 57\n",
"output": "2\n"
},
{
"input": "474026177 729\n",
"output": "728\n"
},
{
"input": "3 60\n",
"output": "26\n"
},
{
"input": "1 1\n",
"output": "0\n"
},
{
"input": "450526186 6561\n",
"output": "6560\n"
},
{
"input": "1 38\n",
"output": "2\n"
}
] |
code_contests
|
python
| 0.2 |
270505f4cff173687d0180a90bf1ebf4
|
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.
Note that the order of the points inside the group of three chosen points doesn't matter.
Input
The first line contains two integers: n and d (1 ≤ n ≤ 105; 1 ≤ d ≤ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 — the x-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input strictly increase.
Output
Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed d.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
4 3
1 2 3 4
Output
4
Input
4 2
-3 -2 -1 0
Output
2
Input
5 19
1 10 20 30 50
Output
1
Note
In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
from sys import stdin
a,b=map(int,stdin.readline().split());a+=1
z=[1]+list(map(int,stdin.readline().split()));i,j=1,1;ans=0
r=lambda x:(x*(x+1))//2
while i<a:
if j<=i:j=i
while j<a and abs(z[j]-z[i])<=b:j+=1
if j-i-1>=2:ans+=r(j-i-2)
i+=1
print(ans)
|
python
|
code_algorithm
|
[
{
"input": "4 2\n-3 -2 -1 0\n",
"output": "2\n"
},
{
"input": "4 3\n1 2 3 4\n",
"output": "4\n"
},
{
"input": "5 19\n1 10 20 30 50\n",
"output": "1\n"
},
{
"input": "1 14751211\n847188590\n",
"output": "0\n"
},
{
"input": "10 90\n24 27 40 41 61 69 73 87 95 97\n",
"output": "120\n"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100\n",
"output": "25\n"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86\n",
"output": "2\n"
},
{
"input": "100 100\n-98 -97 -96 -93 -92 -91 -90 -87 -86 -84 -81 -80 -79 -78 -76 -75 -73 -71 -69 -67 -65 -64 -63 -62 -61 -54 -51 -50 -49 -48 -46 -45 -44 -37 -36 -33 -30 -28 -27 -16 -15 -13 -12 -10 -9 -7 -6 -5 -4 2 3 5 8 9 10 11 13 14 15 16 17 19 22 24 25 26 27 28 30 31 32 36 40 43 45 46 47 50 51 52 53 58 60 63 69 70 73 78 80 81 82 85 88 89 90 91 95 96 97 99\n",
"output": "79351\n"
},
{
"input": "2 1000000000\n-14348867 1760823\n",
"output": "0\n"
},
{
"input": "2 1000000000\n-907894512 -289906312\n",
"output": "0\n"
},
{
"input": "3 1000000000\n-5 -1 1\n",
"output": "1\n"
}
] |
code_contests
|
python
| 0.9 |
fbf9eadad933d5a6c135c8c62620838d
|
The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules:
* The players move in turns; In one move the player can remove an arbitrary letter from string s.
* If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't.
Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
Input
The input contains a single line, containing string s (1 ≤ |s| ≤ 103). String s consists of lowercase English letters.
Output
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
Examples
Input
aba
Output
First
Input
abca
Output
Second
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import sys
#sys.stdin = open('in', 'r')
#sys.stdout = open('out', 'w')
def Out(x):
sys.stdout.write(str(x) + '\n')
def In():
return sys.stdin.readline().strip()
def main():
s = str(input())
Map = {}
for word in s:
if word not in Map:
Map[word] = 1
else:
Map[word] += 1
odd = 0
for key, value in Map.items():
if value&1 == 1:
odd +=1
if odd&1 or odd == 0:
print("First")
else:
print("Second")
if __name__ == '__main__':
main()
|
python
|
code_algorithm
|
[
{
"input": "aba\n",
"output": "First\n"
},
{
"input": "abca\n",
"output": "Second\n"
},
{
"input": "zz\n",
"output": "First\n"
},
{
"input": "aabc\n",
"output": "Second\n"
},
{
"input": "vqdtkbvlbdyndheoiiwqhnvcmmhnhsmwwrvesnpdfxvprqbwzbodoihrywagphlsrcbtnvppjsquuuzkjazaenienjiyctyajsqdfsdiedzugkymgzllvpxfetkwfabbiotjcknzdwsvmbbuqrxrulvgljagvxdmfsqtcczhifhoghqgffkbviphbabwiaqburerfkbqfjbptkwlahysrrfwjbqfnrgnsnsukqqcxxwqtuhvdzqmpfwrbqzdwxcaifuyhvojgurmchh\n",
"output": "First\n"
},
{
"input": "gfhuidxgxpxduqrfnqrnefgtyxgmrtehmddjkddwdiayyilaknxhlxszeslnsjpcrwnoqubmbpcehiftteirkfvbtfyibiikdaxmondnawtvqccctdxrjcfxqwqhvvrqmhqflbzskrayvruqvqijrmikucwzodxvufwxpxxjxlifdjzxrttjzatafkbzsjupsiefmipdufqltedjlytphzppoevxawjdhbxgennevbvdgpoeihasycctyddenzypoprchkoioouhcexjqwjflxvkgpgjatstlmledxasecfhwvabzwviywsiaryqrxyeceefblherqjevdzkfxslqiytwzz\n",
"output": "First\n"
},
{
"input": "vnvtvnxjrtffdhrfvczzoyeokjabxcilmmsrhwuakghvuabcmfpmblyroodmhfivmhqoiqhapoglwaluewhqkunzitmvijaictjdncivccedfpaezcnpwemlohbhjjlqsonuclaumgbzjamsrhuzqdqtitygggsnruuccdtxkgbdd\n",
"output": "First\n"
},
{
"input": "desktciwoidfuswycratvovutcgjrcyzmilsmadzaegseetexygedzxdmorxzxgiqhcuppshcsjcozkopebegfmxzxxagzwoymlghgjexcgfojychyt\n",
"output": "First\n"
},
{
"input": "tsvxmeixijyavdalmrvscwohzubhhgsocdvnjmjtctojbxxpezzbgfltixwgzmkfwdnlhidhrdgyajggmrvmwaoydodjmzqvgabyszfqcuhwdncyfqvmackvijgpjyiauxljvvwgiofdxccwmybdfcfcrqppbvbagmnvvvhngxauwbpourviyfokwjweypzzrrzjcmddnpoaqgqfgglssjnlshrerfffmrwhapzknxveiqixflykjbnpivogtdpyjakwrdoklsbvbkjhdojfnuwbpcfdycwxecysbyjfvoykxsxgg\n",
"output": "First\n"
},
{
"input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo\n",
"output": "Second\n"
},
{
"input": "aabbcccc\n",
"output": "First\n"
},
{
"input": "aaabbbccdd\n",
"output": "Second\n"
},
{
"input": "knaxhkbokmtfvnjvlsbrfoefpjpkqwlumeqqbeohodnwevhllkylposdpjuoizyunuxivzrjofiyxxiliuwhkjqpkqxukxroivfhikxjdtwcqngqswptdwrywxszxrqojjphzwzxqftnfhkapeejdgckfyrxtpuipfljsjwgpjfatmxpylpnerllshuvkbomlpghjrxcgxvktgeyuhrcwgvdmppqnkdmjtxukzlzqhfbgrishuhkyggkpstvqabpxoqjuovwjwcmazmvpfpnljdgpokpatjnvwacotkvxheorzbsrazldsquijzkmtmqahakjrjvzkquvayxpqrmqqcknilpqpjapagezonfpz\n",
"output": "Second\n"
},
{
"input": "abacaba\n",
"output": "First\n"
},
{
"input": "aabb\n",
"output": "First\n"
},
{
"input": "aassddxyz\n",
"output": "First\n"
},
{
"input": "xvhtcbtouuddhylxhplgjxwlo\n",
"output": "First\n"
},
{
"input": "qilwpsuxogazrfgfznngwklnioueuccyjfatjoizcctgsweitzofwkyjustizbopzwtaqxbtovkdrxeplukrcuozhpymldstbbfynkgsmafigetvzkxloxqtphvtwkgfjkiczttcsxkjpsoutdpzxytrsqgjtbdljjrbmkudrkodfvcwkcuggbsthxdyogeeyfuyhmnwgyuatfkvchavpzadfacckdurlbqjkthqbnirzzbpusxcenkpgtizayjmsahvobobudfeaewcqmrlxxnocqzmkessnguxkiccrxyvnxxlqnqfwuzmupk\n",
"output": "First\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccddddddddddeeeeeeeeeeffffgggghhhhiiiijjjjqqqqwwwweeeerrrrttttyyyyuuuuiiiiooooppppaaaassssddddffffgggghhhhjjjjkkkkllllzzzzxxxxccccvvvvbbbbnnnnmmmm\n",
"output": "First\n"
},
{
"input": "hxueikegwnrctlciwguepdsgupguykrntbszeqzzbpdlouwnmqgzcxejidstxyxhdlnttnibxstduwiflouzfswfikdudkazoefawm\n",
"output": "Second\n"
},
{
"input": "upgqmhfmfnodsyosgqswugfvpdxhtkxvhlsxrjiqlojchoddxkpsamwmuvopdbncymcgrkurwlxerexgswricuqxhvqvgekeofkgqabypamozmyjyfvpifsaotnyzqydcenphcsmplekinwkmwzpjnlapfdbhxjdcnarlgkfgxzfbpgsuxqfyhnxjhtojrlnprnxprfbkkcyriqztjeeepkzgzcaiutvbqqofyhddfebozhvtvrigtidxqmydjxegxipakzjcnenjkdroyjmxugj\n",
"output": "Second\n"
},
{
"input": "ab\n",
"output": "Second\n"
},
{
"input": "a\n",
"output": "First\n"
},
{
"input": "fezzkpyctjvvqtncmmjsitrxaliyhirspnjjngvzdoudrkkvvdiwcwtcxobpobzukegtcrwsgxxzlcphdxkbxdximqbycaicfdeqlvzboptfimkzvjzdsvahorqqhcirpkhtwjkplitpacpkpbhnxtoxuoqsxcxnhtrmzvexmpvlethbkvmlzftimjnidrzvcunbpysvukzgwghjmwrvstsunaocnoqohcsggtrwxiworkliqejajewbrtdwgnyynpupbrrvtfqtlaaq\n",
"output": "Second\n"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\n",
"output": "Second\n"
},
{
"input": "gevqgtaorjixsxnbcoybr\n",
"output": "First\n"
},
{
"input": "opfokvwzpllctflkphutcrkferbjyyrasqqkrcvoymyrxwaudgsugcqveccymdplxmtlzfoptmrapfeizpnnhbzlkuyznwacnswibxhqunazbhdvrlidghisuqunstbuevjzimvlfvopgqxrvahhngnaumgywscfrfwfpnfxwhfrelbunmedvkssykwjyartxjiplerntzkpiiaalijiwhyuhxlvhxpkgfypvrpqqsacuwocdampnnhvibsbolyduvscsjfayxpldyvqzjbqojjxdvxtctwtifcdfcaoonzbgegyllngwvjivtxeezoabhsihcuvgvdsgjtzbzwovjshvwrljkxavowovzrfpdufpogdtujkerdorpboufrxhyswirjehgsxthlvjufvahdpeajidqipwaxokbeycrievgcfkyuyavaq\n",
"output": "Second\n"
},
{
"input": "abazaba\n",
"output": "First\n"
},
{
"input": "abcabc\n",
"output": "First\n"
},
{
"input": "ershkhsywqftixappwqzoojtnamvqjbyfauvuubwpctspioqusnnivwsiyszfhlrskbswaiaczurygcioonjcndntwvrlaejyrghfnecltqytfmkvjxuujifgtujrqsisdawpwgttxynewiqhdhronamabysvpxankxeybcjqttbqnciwuqiehzyfjoedaradqnfthuuwrezwrkjiytpgwfwbslawbiezdbdltenjlaygwaxddplgseiaojndqjcopvolqbvnacuvfvirzbrnlnyjixngeevcggmirzatenjihpgnyfjhgsjgzepohbyhmzbatfwuorwutavlqsogrvcjpqziuifrhurq\n",
"output": "First\n"
}
] |
code_contests
|
python
| 0 |
bc5e8751ffaa93f8c0a9c6d7fd2b9af0
|
Fox Ciel has some flowers: r red flowers, g green flowers and b blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
* To make a "red bouquet", it needs 3 red flowers.
* To make a "green bouquet", it needs 3 green flowers.
* To make a "blue bouquet", it needs 3 blue flowers.
* To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower.
Help Fox Ciel to find the maximal number of bouquets she can make.
Input
The first line contains three integers r, g and b (0 ≤ r, g, b ≤ 109) — the number of red, green and blue flowers.
Output
Print the maximal number of bouquets Fox Ciel can make.
Examples
Input
3 6 9
Output
6
Input
4 4 4
Output
4
Input
0 0 0
Output
0
Note
In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
a,b,c = map(int,input().split())
max_mix = min(a,b,c)
res = -99999999999999
for i in range (0,min(3,max_mix)+1):
pos = (i+(a-i)//3 + (b-i)//3 + (c-i)//3)
res=max(res,pos)
print(res)
|
python
|
code_algorithm
|
[
{
"input": "3 6 9\n",
"output": "6\n"
},
{
"input": "4 4 4\n",
"output": "4\n"
},
{
"input": "0 0 0\n",
"output": "0\n"
},
{
"input": "0 1 0\n",
"output": "0\n"
},
{
"input": "2 2 0\n",
"output": "0\n"
},
{
"input": "7 8 9\n",
"output": "7\n"
},
{
"input": "666806767 385540591 357848286\n",
"output": "470065214\n"
},
{
"input": "3 3 5\n",
"output": "3\n"
},
{
"input": "494914467 356982656 757942689\n",
"output": "536613270\n"
},
{
"input": "242854896 442432924 180395753\n",
"output": "288561190\n"
},
{
"input": "32 62 92\n",
"output": "62\n"
},
{
"input": "8 8 9\n",
"output": "8\n"
},
{
"input": "139978911 5123031 935395222\n",
"output": "360165721\n"
},
{
"input": "937984449 184405994 992844522\n",
"output": "705078321\n"
},
{
"input": "0 1 1\n",
"output": "0\n"
},
{
"input": "3 5 5\n",
"output": "4\n"
},
{
"input": "0 2 2\n",
"output": "0\n"
},
{
"input": "9 9 7\n",
"output": "8\n"
},
{
"input": "829651016 732259171 572879931\n",
"output": "711596705\n"
},
{
"input": "835108464 525983528 452876698\n",
"output": "604656229\n"
},
{
"input": "775140200 616574841 630329230\n",
"output": "674014756\n"
},
{
"input": "0 5 5\n",
"output": "2\n"
},
{
"input": "524780569 326748594 90361407\n",
"output": "313963523\n"
},
{
"input": "0 3 6\n",
"output": "3\n"
},
{
"input": "0 1000000000 0\n",
"output": "333333333\n"
},
{
"input": "952726009 629846517 972974334\n",
"output": "851848953\n"
},
{
"input": "1000000000 999999999 999999998\n",
"output": "999999998\n"
},
{
"input": "292920005 241298326 667908343\n",
"output": "400708891\n"
},
{
"input": "80010646 727118126 817880463\n",
"output": "541669744\n"
},
{
"input": "597790453 720437830 855459575\n",
"output": "724562619\n"
},
{
"input": "1000000000 1000000000 1000000000\n",
"output": "1000000000\n"
},
{
"input": "879716125 531124573 207876166\n",
"output": "539572288\n"
},
{
"input": "908118348 67156409 217974865\n",
"output": "397749873\n"
},
{
"input": "553182792 10264076 395427398\n",
"output": "319624755\n"
},
{
"input": "1 0 0\n",
"output": "0\n"
},
{
"input": "65 30 74\n",
"output": "56\n"
},
{
"input": "15 3 999\n",
"output": "339\n"
},
{
"input": "999999998 999999998 999999999\n",
"output": "999999998\n"
},
{
"input": "2 0 11\n",
"output": "3\n"
},
{
"input": "123456789 123456789 123456789\n",
"output": "123456789\n"
}
] |
code_contests
|
python
| 0 |
5b52a9db29416f455c94e2c25dc7cb6c
|
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days, become unfit to eat).
Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
Input
The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.
Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ 3000) — the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.
Output
Print a single integer — the maximum number of fruit that Valera can collect.
Examples
Input
2 3
1 5
2 3
Output
8
Input
5 10
3 20
2 20
1 20
4 20
5 20
Output
60
Note
In the first sample, in order to obtain the optimal answer, you should act as follows.
* On the first day collect 3 fruits from the 1-st tree.
* On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.
* On the third day collect the remaining fruits from the 2-nd tree.
In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
frukti_po_dnyam = {}
n, resurs =map(int,input().split(' '))
for i in range(n):
den, chislo_fruktov = map(int, input().split(' '))
if den in frukti_po_dnyam:
frukti_po_dnyam[den] += chislo_fruktov
else:
frukti_po_dnyam[den] = chislo_fruktov
if den + 1 not in frukti_po_dnyam:
frukti_po_dnyam[den + 1] = 0
def ubir(chislo, vichet):
tmp = chislo-vichet
if tmp<0:
return 0, -tmp
return tmp, 0
vsego = 0
# frukti_po_dnyam[max(frukti_po_dnyam.keys())+1] =0
for i in sorted(frukti_po_dnyam):
ostatok = resurs
if i-1 in frukti_po_dnyam:
frukti_po_dnyam[i-1], ostatok = ubir(frukti_po_dnyam[i-1], ostatok)
frukti_po_dnyam[i], ostatok = ubir(frukti_po_dnyam[i], ostatok)
vsego+= resurs - ostatok
print (vsego)
|
python
|
code_algorithm
|
[
{
"input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n",
"output": "60\n"
},
{
"input": "2 3\n1 5\n2 3\n",
"output": "8\n"
},
{
"input": "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426\n",
"output": "4740\n"
},
{
"input": "2 100\n3000 100\n3000 100\n",
"output": "200\n"
},
{
"input": "1 40\n3000 42\n",
"output": "42\n"
},
{
"input": "1 10\n3000 20\n",
"output": "20\n"
},
{
"input": "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202\n",
"output": "10596\n"
},
{
"input": "1 1\n3000 2\n",
"output": "2\n"
},
{
"input": "1 1\n3000 3000\n",
"output": "2\n"
},
{
"input": "2 10\n2999 100\n3000 100\n",
"output": "30\n"
},
{
"input": "1 10\n3000 100\n",
"output": "20\n"
},
{
"input": "2 2\n2999 3\n3000 2\n",
"output": "5\n"
},
{
"input": "2 1500\n2 575\n1 2522\n",
"output": "3097\n"
},
{
"input": "5 1\n10 100\n2698 100\n200 100\n3000 100\n1500 100\n",
"output": "10\n"
},
{
"input": "2 3000\n3000 3000\n3000 3000\n",
"output": "6000\n"
},
{
"input": "2 3\n1 6\n3 6\n",
"output": "12\n"
},
{
"input": "1 100\n3000 200\n",
"output": "200\n"
},
{
"input": "1 50\n3000 100\n",
"output": "100\n"
},
{
"input": "1 1000\n3000 2000\n",
"output": "2000\n"
},
{
"input": "2 1\n1 1\n1 1\n",
"output": "2\n"
},
{
"input": "2 5\n2999 10\n3000 5\n",
"output": "15\n"
},
{
"input": "4 2061\n1 426\n3 2522\n1 772\n1 1447\n",
"output": "5167\n"
},
{
"input": "1 5\n3000 10\n",
"output": "10\n"
},
{
"input": "1 10\n3000 30\n",
"output": "20\n"
},
{
"input": "2 1000\n2999 2000\n3000 1000\n",
"output": "3000\n"
},
{
"input": "24 1524\n16 934\n23 1940\n21 1447\n20 417\n24 1340\n22 1932\n13 775\n19 2918\n12 2355\n9 593\n11 2676\n3 1857\n16 868\n13 426\n18 1679\n22 991\n9 2728\n10 2497\n16 1221\n9 772\n23 2522\n24 982\n12 1431\n18 757\n",
"output": "25893\n"
},
{
"input": "1 3\n5 3\n",
"output": "3\n"
},
{
"input": "1 10\n3000 15\n",
"output": "15\n"
},
{
"input": "2 1\n30 3\n31 2\n",
"output": "3\n"
},
{
"input": "1 2\n3000 3\n",
"output": "3\n"
},
{
"input": "12 2856\n9 2728\n8 417\n3 1857\n10 1932\n1 775\n12 982\n9 1447\n1 426\n7 2918\n11 2522\n10 2497\n9 772\n",
"output": "18465\n"
}
] |
code_contests
|
python
| 0 |
5a388a75dc43e27ac09c30e71ab56bbf
|
Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.
Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy:
* Each piece should contain at least l numbers.
* The difference between the maximal and the minimal number on the piece should be at most s.
Please help Alexandra to find the minimal number of pieces meeting the condition above.
Input
The first line contains three space-separated integers n, s, l (1 ≤ n ≤ 105, 0 ≤ s ≤ 109, 1 ≤ l ≤ 105).
The second line contains n integers ai separated by spaces ( - 109 ≤ ai ≤ 109).
Output
Output the minimal number of strip pieces.
If there are no ways to split the strip, output -1.
Examples
Input
7 2 2
1 3 1 2 4 1 2
Output
3
Input
7 2 2
1 100 1 100 1 100 1
Output
-1
Note
For the first sample, we can split the strip into 3 pieces: [1, 3, 1], [2, 4], [1, 2].
For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
def split(a,n,s,l):
pieces = []
i = 1
tmpmin = a[0]
tmpmax = a[0]
tmppc = [a[0]]
while i<n:
if abs(a[i]-tmpmin)<=s and abs(a[i]-tmpmax)<=s:
tmppc.append(a[i])
if a[i]<tmpmin: tmpmin=a[i]
elif a[i]>tmpmax: tmpmax = a[i]
else:
pieces.append(tmppc)
tmppc = [a[i]]
tmpmin = a[i]
tmpmax = a[i]
i += 1
pieces.append(tmppc)
fail = False
for j in range(len(pieces)):
if len(pieces[j])<l:
if j>0:
prevpc = pieces[j-1]
minj = min(pieces[j])
maxj = max(pieces[j])
while len(pieces[j])<l:
tmp = prevpc.pop()
if abs(tmp-minj)<=s and abs(tmp-maxj)<=s:
pieces[j].insert(0,tmp)
if tmp<minj: minj=tmp
elif tmp>maxj: maxj=tmp
else:
return -1
if len(prevpc)<l:
return -1
else:
return -1
return len(pieces)
n,s,l = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
res = split(a,n,s,l)
if res<0:
a.reverse()
res = split(a,n,s,l)
print(res)
|
python
|
code_algorithm
|
[
{
"input": "7 2 2\n1 100 1 100 1 100 1\n",
"output": "-1\n"
},
{
"input": "7 2 2\n1 3 1 2 4 1 2\n",
"output": "3\n"
},
{
"input": "1 0 1\n0\n",
"output": "1\n"
},
{
"input": "10 3 3\n1 1 1 1 1 5 6 7 8 9\n",
"output": "-1\n"
},
{
"input": "2 1000000000 2\n-1000000000 1000000000\n",
"output": "-1\n"
},
{
"input": "6 565 2\n31 76 162 -182 -251 214\n",
"output": "1\n"
},
{
"input": "1 0 1\n-1000000000\n",
"output": "1\n"
},
{
"input": "2 1000000000 1\n-1000000000 1000000000\n",
"output": "2\n"
},
{
"input": "1 100 2\n42\n",
"output": "-1\n"
},
{
"input": "10 3 3\n1 1 1 2 2 5 6 7 8 9\n",
"output": "3\n"
}
] |
code_contests
|
python
| 0 |
d439aa68a8c0fbb798964842f03a816b
|
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a n by m table. Denote c-th cell of r-th row as (r, c). The tail of the snake is located at (1, 1), then it's body extends to (1, m), then goes down 2 rows to (3, m), then goes left to (3, 1) and so on.
Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').
Consider sample tests in order to understand the snake pattern.
Input
The only line contains two integers: n and m (3 ≤ n, m ≤ 50).
n is an odd number.
Output
Output n lines. Each line should contain a string consisting of m characters. Do not output spaces.
Examples
Input
3 3
Output
###
..#
###
Input
3 4
Output
####
...#
####
Input
5 3
Output
###
..#
###
#..
###
Input
9 9
Output
#########
........#
#########
#........
#########
........#
#########
#........
#########
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n,m=map(int,input().split())
s="."*(m-1)+"#"
#print(s)
for i in range(n):
if i%2==0:print("#"*m)
else:
print(s)
s=s[::-1]
|
python
|
code_algorithm
|
[
{
"input": "9 9\n",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
},
{
"input": "5 3\n",
"output": "###\n..#\n###\n#..\n###\n"
},
{
"input": "3 3\n",
"output": "###\n..#\n###\n"
},
{
"input": "3 4\n",
"output": "####\n...#\n####\n"
},
{
"input": "45 45\n",
"output": "#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n"
},
{
"input": "11 3\n",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n"
},
{
"input": "11 15\n",
"output": "###############\n..............#\n###############\n#..............\n###############\n..............#\n###############\n#..............\n###############\n..............#\n###############\n"
},
{
"input": "7 7\n",
"output": "#######\n......#\n#######\n#......\n#######\n......#\n#######\n"
},
{
"input": "5 6\n",
"output": "######\n.....#\n######\n#.....\n######\n"
},
{
"input": "19 3\n",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n"
},
{
"input": "7 5\n",
"output": "#####\n....#\n#####\n#....\n#####\n....#\n#####\n"
},
{
"input": "45 4\n",
"output": "####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n"
},
{
"input": "45 3\n",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n"
},
{
"input": "3 6\n",
"output": "######\n.....#\n######\n"
},
{
"input": "45 49\n",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n"
},
{
"input": "43 27\n",
"output": "###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n"
},
{
"input": "33 43\n",
"output": "###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n"
},
{
"input": "49 49\n",
"output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n"
},
{
"input": "7 3\n",
"output": "###\n..#\n###\n#..\n###\n..#\n###\n"
},
{
"input": "49 50\n",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n"
},
{
"input": "5 5\n",
"output": "#####\n....#\n#####\n#....\n#####\n"
},
{
"input": "3 5\n",
"output": "#####\n....#\n#####\n"
},
{
"input": "7 6\n",
"output": "######\n.....#\n######\n#.....\n######\n.....#\n######\n"
},
{
"input": "33 44\n",
"output": "############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n"
},
{
"input": "5 4\n",
"output": "####\n...#\n####\n#...\n####\n"
},
{
"input": "43 50\n",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n"
},
{
"input": "7 4\n",
"output": "####\n...#\n####\n#...\n####\n...#\n####\n"
},
{
"input": "23 50\n",
"output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n"
}
] |
code_contests
|
python
| 0 |
f86595da33108a8cdf415f43987e55c9
|
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to s and elevator initially starts on floor s at time 0.
The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0.
Input
The first line of input contains two integers n and s (1 ≤ n ≤ 100, 1 ≤ s ≤ 1000) — the number of passengers and the number of the top floor respectively.
The next n lines each contain two space-separated integers fi and ti (1 ≤ fi ≤ s, 1 ≤ ti ≤ 1000) — the floor and the time of arrival in seconds for the passenger number i.
Output
Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.
Examples
Input
3 7
2 1
3 8
5 2
Output
11
Input
5 10
2 77
3 33
8 21
9 12
10 64
Output
79
Note
In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: takes 1 second.
7. Pick up passenger 1.
8. Go to floor 0: takes 2 seconds.
This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
I=lambda:map(int,input().split())
n,s=I()
print(max(max(sum(I()),s)for _ in '0'*n))
|
python
|
code_algorithm
|
[
{
"input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n",
"output": "79\n"
},
{
"input": "3 7\n2 1\n3 8\n5 2\n",
"output": "11\n"
},
{
"input": "2 10\n9 10\n6 11\n",
"output": "19\n"
},
{
"input": "2 7\n6 3\n1 5\n",
"output": "9\n"
},
{
"input": "2 10\n9 3\n1 4\n",
"output": "12\n"
},
{
"input": "2 20\n10 10\n19 9\n",
"output": "28\n"
},
{
"input": "2 20\n1 1\n2 2\n",
"output": "20\n"
},
{
"input": "2 100\n4 100\n7 99\n",
"output": "106\n"
},
{
"input": "4 4\n4 6\n4 8\n1 7\n2 9\n",
"output": "12\n"
},
{
"input": "2 100\n99 9\n1 10\n",
"output": "108\n"
},
{
"input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n",
"output": "2\n"
},
{
"input": "1 1\n1 1\n",
"output": "2\n"
},
{
"input": "2 100\n99 2\n1 10\n",
"output": "101\n"
},
{
"input": "2 1000\n1 2\n1000 1\n",
"output": "1001\n"
},
{
"input": "1 1000\n1 1\n",
"output": "1000\n"
},
{
"input": "2 5\n4 4\n5 4\n",
"output": "9\n"
},
{
"input": "1 1000\n1000 1000\n",
"output": "2000\n"
},
{
"input": "2 7\n3 5\n7 4\n",
"output": "11\n"
},
{
"input": "1 1000\n1 1000\n",
"output": "1001\n"
},
{
"input": "3 7\n1 6\n5 5\n6 1\n",
"output": "10\n"
},
{
"input": "5 5\n1 1\n2 1\n3 1\n4 1\n5 1\n",
"output": "6\n"
}
] |
code_contests
|
python
| 0.5 |
7af7f25d539640feaf87b9edede7ef7b
|
Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells.
Vova's character can learn new spells during the game. Every spell is characterized by two values xi and yi — damage per second and mana cost per second, respectively. Vova doesn't have to use a spell for an integer amount of seconds. More formally, if he uses a spell with damage x and mana cost y for z seconds, then he will deal x·z damage and spend y·z mana (no rounding). If there is no mana left (mana amount is set in the start of the game and it remains the same at the beginning of every fight), then character won't be able to use any spells. It is prohibited to use multiple spells simultaneously.
Also Vova can fight monsters. Every monster is characterized by two values tj and hj — monster kills Vova's character in tj seconds and has hj health points. Mana refills after every fight (or Vova's character revives with full mana reserve), so previous fights have no influence on further ones.
Vova's character kills a monster, if he deals hj damage to it in no more than tj seconds using his spells (it is allowed to use more than one spell in a fight) and spending no more mana than he had at the beginning of the fight. If monster's health becomes zero exactly in tj seconds (it means that the monster and Vova's character kill each other at the same time), then Vova wins the fight.
You have to write a program which can answer two types of queries:
* 1 x y — Vova's character learns new spell which deals x damage per second and costs y mana per second.
* 2 t h — Vova fights the monster which kills his character in t seconds and has h health points.
Note that queries are given in a different form. Also remember that Vova's character knows no spells at the beginning of the game.
For every query of second type you have to determine if Vova is able to win the fight with corresponding monster.
Input
The first line contains two integer numbers q and m (2 ≤ q ≤ 105, 1 ≤ m ≤ 1012) — the number of queries and the amount of mana at the beginning of every fight.
i-th of each next q lines contains three numbers ki, ai and bi (1 ≤ ki ≤ 2, 1 ≤ ai, bi ≤ 106).
Using them you can restore queries this way: let j be the index of the last query of second type with positive answer (j = 0 if there were none of these).
* If ki = 1, then character learns spell with x = (ai + j) mod 106 + 1, y = (bi + j) mod 106 + 1.
* If ki = 2, then you have to determine if Vova is able to win the fight against monster with t = (ai + j) mod 106 + 1, h = (bi + j) mod 106 + 1.
Output
For every query of second type print YES if Vova is able to win the fight with corresponding monster and NO otherwise.
Example
Input
3 100
1 4 9
2 19 49
2 19 49
Output
YES
NO
Note
In first example Vova's character at first learns the spell with 5 damage and 10 mana cost per second. Next query is a fight with monster which can kill character in 20 seconds and has 50 health points. Vova kills it in 10 seconds (spending 100 mana). Next monster has 52 health, so Vova can't deal that much damage with only 100 mana.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
#!/usr/bin/env python3
# solution after hint
# (instead of best hit/mana spell store convex hull of spells)
# O(n^2) instead of O(n log n)
[q, m] = map(int, input().strip().split())
qis = [tuple(map(int, input().strip().split())) for _ in range(q)]
mod = 10**6
j = 0
spell_chull = [(0, 0)] # lower hull _/
def is_right(xy0, xy1, xy):
(x0, y0) = xy0
(x1, y1) = xy1
(x, y) = xy
return (x0 - x) * (y1 - y) >= (x1 - x) * (y0 - y)
def in_chull(x, y):
i = 0
if x > spell_chull[-1][0]:
return False
while spell_chull[i][0] < x:
i += 1
if spell_chull[i][0] == x:
return spell_chull[i][1] <= y
else:
return is_right(spell_chull[i - 1], spell_chull[i], (x, y))
def add_spell(x, y):
global spell_chull
if in_chull(x, y):
return
i_left = 0
while i_left < len(spell_chull) - 1 and not is_right(spell_chull[i_left + 1], spell_chull[i_left], (x, y)):
i_left += 1
i_right = i_left + 1
while i_right < len(spell_chull) - 1 and is_right(spell_chull[i_right + 1], spell_chull[i_right], (x, y)):
i_right += 1
if i_right == len(spell_chull) - 1 and x >= spell_chull[-1][0]:
i_right += 1
spell_chull = spell_chull[:i_left + 1] + [(x, y)] + spell_chull[i_right:]
for i, qi in enumerate(qis):
(k, a, b) = qi
x = (a + j) % mod + 1
y = (b + j) % mod + 1
if k == 1:
add_spell(x, y)
else: #2
if in_chull(y / x, m / x):
print ('YES')
j = i + 1
else:
print ('NO')
|
python
|
code_algorithm
|
[
{
"input": "3 100\n1 4 9\n2 19 49\n2 19 49\n",
"output": "YES\nNO\n"
},
{
"input": "2 424978864039\n2 7 3\n2 10 8\n",
"output": "NO\nNO\n"
},
{
"input": "15 100\n1 8 8\n2 200 101\n2 10 99\n1 9 9\n2 10 99\n2 200 101\n1 14 4\n2 194 195\n2 194 194\n2 990 290\n1 2 999992\n2 6 256\n2 7 256\n1 2 999988\n2 2 252\n",
"output": "NO\nNO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nYES\n"
},
{
"input": "3 10\n1 1 1\n2 1 1\n2 999999 999999\n",
"output": "YES\nYES\n"
},
{
"input": "12 100\n1 8 8\n2 200 101\n2 10 99\n1 9 9\n2 10 99\n2 200 101\n1 14 4\n2 194 195\n2 194 194\n2 990 290\n2 999991 11\n2 999991 10\n",
"output": "NO\nNO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\n"
},
{
"input": "10 442006988299\n2 10 47\n1 9 83\n1 15 24\n2 19 47\n2 75 99\n2 85 23\n2 8 33\n2 9 82\n1 86 49\n2 71 49\n",
"output": "NO\nYES\nYES\nYES\nYES\nYES\nYES\n"
},
{
"input": "3 12\n1 99 9\n1 49 1\n2 1 149\n",
"output": "YES\n"
}
] |
code_contests
|
python
| 0 |
be7ccf64138f33e020cb953e8f1c53db
|
A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineering team asking each engineer the number of the desk they currently sit at, and the number of the desk they would like to sit at (which may be the same as their current desk). Each engineer must either remain where they sit, or move to the desired seat they indicated in the survey. No two engineers currently sit at the same desk, nor may any two engineers sit at the same desk in the new seating arrangement.
How many seating arrangements can you create that meet the specified requirements? The answer may be very large, so compute it modulo 1000000007 = 109 + 7.
Input
Input will begin with a line containing N (1 ≤ N ≤ 100000), the number of engineers.
N lines follow, each containing exactly two integers. The i-th line contains the number of the current desk of the i-th engineer and the number of the desk the i-th engineer wants to move to. Desks are numbered from 1 to 2·N. It is guaranteed that no two engineers sit at the same desk.
Output
Print the number of possible assignments, modulo 1000000007 = 109 + 7.
Examples
Input
4
1 5
5 2
3 7
7 3
Output
6
Input
5
1 10
2 10
3 10
4 10
5 5
Output
5
Note
These are the possible assignments for the first example:
* 1 5 3 7
* 1 2 3 7
* 5 2 3 7
* 1 5 7 3
* 1 2 7 3
* 5 2 7 3
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n = int(input())
m = 2 * n + 1
u = [[] for i in range(m)]
v = [0] * m
s = [0] * m
d = 10 ** 9 + 7
y = 1
for j in range(n):
a, b = map(int, input().split())
v[a] = b
if a != b:
s[b] += 1
u[b].append(a)
for b in range(m):
if not v[b]:
x = 0
p = [b]
while p:
x += 1
a = p.pop()
s[a] = -1
p += u[a]
y = (x * y) % d
for a in range(m):
if s[a] == 0:
b = v[a]
while s[b] == 1:
s[b] = -1
b = v[b]
s[b] -= 1
for a in range(m):
if s[a] == 1:
y = (2 * y) % d
while s[a]:
s[a] = 0
a = v[a]
print(y)
|
python
|
code_algorithm
|
[
{
"input": "4\n1 5\n5 2\n3 7\n7 3\n",
"output": "6\n"
},
{
"input": "5\n1 10\n2 10\n3 10\n4 10\n5 5\n",
"output": "5\n"
},
{
"input": "1\n1 2\n",
"output": "2\n"
},
{
"input": "30\n22 37\n12 37\n37 58\n29 57\n43 57\n57 58\n58 53\n45 4\n1 4\n4 51\n35 31\n21 31\n31 51\n51 53\n53 48\n60 55\n52 55\n55 33\n36 9\n10 9\n9 33\n33 19\n5 23\n47 23\n23 32\n50 44\n26 44\n44 32\n32 19\n19 48\n",
"output": "31\n"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5\n5 1\n",
"output": "2\n"
},
{
"input": "10\n15 8\n8 13\n13 3\n1 4\n14 3\n11 17\n9 10\n10 18\n19 20\n17 20\n",
"output": "120\n"
},
{
"input": "50\n73 1\n65 73\n16 65\n57 65\n33 16\n34 57\n98 16\n84 98\n55 34\n64 84\n80 55\n75 64\n28 75\n20 75\n42 75\n88 42\n50 20\n48 28\n32 48\n58 88\n92 76\n76 53\n53 15\n15 1\n1 10\n10 71\n71 37\n37 95\n95 63\n63 92\n45 97\n97 51\n51 96\n96 12\n12 62\n62 31\n31 5\n5 29\n29 19\n19 49\n49 6\n6 40\n40 18\n18 22\n22 17\n17 46\n46 72\n72 82\n82 14\n14 14\n",
"output": "2\n"
},
{
"input": "4\n5 6\n6 7\n7 8\n8 5\n",
"output": "2\n"
}
] |
code_contests
|
python
| 0 |
7e0baa13fdf2c76950b837c22e9c7f35
|
Ivan has n different boxes. The first of them contains some balls of n different colors.
Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every i (1 ≤ i ≤ n) i-th box will contain all balls with color i.
In order to do this, Ivan will make some turns. Each turn he does the following:
1. Ivan chooses any non-empty box and takes all balls from this box;
2. Then Ivan chooses any k empty boxes (the box from the first step becomes empty, and Ivan is allowed to choose it), separates the balls he took on the previous step into k non-empty groups and puts each group into one of the boxes. He should put each group into a separate box. He can choose either k = 2 or k = 3.
The penalty of the turn is the number of balls Ivan takes from the box during the first step of the turn. And penalty of the game is the total penalty of turns made by Ivan until he distributes all balls to corresponding boxes.
Help Ivan to determine the minimum possible penalty of the game!
Input
The first line contains one integer number n (1 ≤ n ≤ 200000) — the number of boxes and colors.
The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the number of balls with color i.
Output
Print one number — the minimum possible penalty of the game.
Examples
Input
3
1 2 3
Output
6
Input
4
2 3 4 5
Output
19
Note
In the first example you take all the balls from the first box, choose k = 3 and sort all colors to corresponding boxes. Penalty is 6.
In the second example you make two turns:
1. Take all the balls from the first box, choose k = 3, put balls of color 3 to the third box, of color 4 — to the fourth box and the rest put back into the first box. Penalty is 14;
2. Take all the balls from the first box, choose k = 2, put balls of color 1 to the first box, of color 2 — to the second box. Penalty is 5.
Total penalty is 19.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
from heapq import *
n = int(input())
a = list(map(int, input().split()))
heap = []
res = 0
for i in range(n):
heappush(heap, a[i])
if n % 2 == 0:
heappush(heap, 0)
while n > 1:
cur = heappop(heap)
cur += heappop(heap)
cur += heappop(heap)
res += cur
heappush(heap, cur)
n -= 2
print(res)
|
python
|
code_algorithm
|
[
{
"input": "3\n1 2 3\n",
"output": "6\n"
},
{
"input": "4\n2 3 4 5\n",
"output": "19\n"
},
{
"input": "2\n3 4\n",
"output": "7\n"
},
{
"input": "8\n821407370 380061316 428719552 90851747 825473738 704702117 845629927 245820158\n",
"output": "8176373828\n"
},
{
"input": "1\n10\n",
"output": "0\n"
},
{
"input": "1\n1\n",
"output": "0\n"
},
{
"input": "1\n4\n",
"output": "0\n"
},
{
"input": "6\n1 4 4 4 4 4\n",
"output": "38\n"
},
{
"input": "1\n12312\n",
"output": "0\n"
}
] |
code_contests
|
python
| 0 |
72446bea232272648e8a93922a1b5b5e
|
Misha was interested in water delivery from childhood. That's why his mother sent him to the annual Innovative Olympiad in Irrigation (IOI). Pupils from all Berland compete there demonstrating their skills in watering. It is extremely expensive to host such an olympiad, so after the first n olympiads the organizers introduced the following rule of the host city selection.
The host cities of the olympiads are selected in the following way. There are m cities in Berland wishing to host the olympiad, they are numbered from 1 to m. The host city of each next olympiad is determined as the city that hosted the olympiad the smallest number of times before. If there are several such cities, the city with the smallest index is selected among them.
Misha's mother is interested where the olympiad will be held in some specific years. The only information she knows is the above selection rule and the host cities of the first n olympiads. Help her and if you succeed, she will ask Misha to avoid flooding your house.
Input
The first line contains three integers n, m and q (1 ≤ n, m, q ≤ 500 000) — the number of olympiads before the rule was introduced, the number of cities in Berland wishing to host the olympiad, and the number of years Misha's mother is interested in, respectively.
The next line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ m), where a_i denotes the city which hosted the olympiad in the i-th year. Note that before the rule was introduced the host city was chosen arbitrarily.
Each of the next q lines contains an integer k_i (n + 1 ≤ k_i ≤ 10^{18}) — the year number Misha's mother is interested in host city in.
Output
Print q integers. The i-th of them should be the city the olympiad will be hosted in the year k_i.
Examples
Input
6 4 10
3 1 1 1 2 2
7
8
9
10
11
12
13
14
15
16
Output
4
3
4
2
3
4
1
2
3
4
Input
4 5 4
4 4 5 1
15
9
13
6
Output
5
3
3
3
Note
In the first example Misha's mother is interested in the first 10 years after the rule was introduced. The host cities these years are 4, 3, 4, 2, 3, 4, 1, 2, 3, 4.
In the second example the host cities after the new city is introduced are 2, 3, 1, 2, 3, 5, 1, 2, 3, 4, 5, 1.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
from bisect import bisect_left as bl
import sys
N, M, Q = map(int, sys.stdin.readline().split())
count = [0] * (M + 1)
A = []
for a in sys.stdin.readline().split():
a = int(a)
A.append(count[a] * M + a)
count[a] += 1
A.sort()
A = [a - i for i, a in enumerate(A, 1)]
for _ in range(Q):
q = int(sys.stdin.readline()) - N
if q > A[-1]:
q += N
else:
q += bl(A, q)
sys.stdout.write(f'{(q - 1) % M + 1}\n')
|
python
|
code_algorithm
|
[
{
"input": "4 5 4\n4 4 5 1\n15\n9\n13\n6\n",
"output": "5\n3\n3\n3\n"
},
{
"input": "6 4 10\n3 1 1 1 2 2\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n",
"output": "4\n3\n4\n2\n3\n4\n1\n2\n3\n4\n"
},
{
"input": "100 21 20\n11 17 21 14 7 15 18 6 17 11 21 3 17 21 21 7 21 17 14 21 14 14 3 6 18 21 17 17 18 14 14 21 15 13 3 15 11 11 16 11 6 10 15 17 11 15 13 13 21 16 21 13 11 14 21 21 13 18 16 3 21 16 13 16 15 3 16 21 21 21 14 15 16 17 16 16 21 2 14 21 7 7 21 16 17 21 17 15 21 10 7 17 21 11 13 17 14 3 11 14\n170\n118\n164\n118\n178\n177\n127\n117\n109\n108\n142\n150\n129\n139\n178\n112\n114\n117\n117\n108\n",
"output": "7\n1\n1\n1\n1\n20\n20\n20\n1\n20\n5\n20\n2\n1\n1\n5\n9\n20\n20\n20\n"
},
{
"input": "1 100 20\n5\n2\n3\n4\n5\n100\n101\n102\n103\n200\n78\n6\n7\n8\n9\n10\n104\n105\n106\n107\n108\n",
"output": "1\n2\n3\n4\n100\n1\n2\n3\n100\n78\n6\n7\n8\n9\n10\n4\n5\n6\n7\n8\n"
},
{
"input": "100 11 20\n10 6 6 9 1 10 10 6 6 10 9 6 9 1 9 6 1 10 9 9 10 9 6 6 9 10 6 6 6 10 6 9 9 9 10 6 10 6 9 6 6 6 9 10 9 6 9 1 9 9 9 10 9 10 6 6 9 9 6 10 10 10 6 6 10 9 10 6 10 9 6 10 6 9 6 6 10 6 6 9 9 9 9 9 9 6 6 6 6 9 10 10 6 10 6 10 6 9 6 9\n195\n170\n126\n189\n143\n122\n166\n170\n168\n166\n177\n153\n138\n198\n171\n127\n118\n123\n154\n113\n",
"output": "3\n2\n7\n5\n8\n2\n7\n2\n11\n7\n1\n1\n2\n7\n3\n8\n5\n3\n2\n8\n"
},
{
"input": "100 6 20\n6 4 6 3 6 6 3 1 1 3 1 3 1 6 2 1 4 6 4 1 6 6 4 1 6 1 3 4 3 2 1 4 1 4 6 1 1 4 2 3 2 6 4 1 1 1 2 6 2 2 4 2 1 1 1 2 6 4 6 4 3 3 4 6 4 2 3 4 6 4 6 1 3 6 6 3 3 2 2 3 6 2 1 4 4 3 2 2 3 1 3 3 6 3 4 4 2 6 3 6\n147\n105\n121\n139\n129\n128\n122\n133\n187\n168\n102\n144\n108\n110\n117\n113\n144\n124\n104\n113\n",
"output": "3\n5\n2\n1\n1\n5\n5\n5\n1\n6\n5\n6\n5\n5\n2\n5\n6\n5\n5\n5\n"
},
{
"input": "100 16 20\n9 16 14 12 14 4 9 7 3 3 4 6 15 1 6 15 12 5 11 10 8 10 4 6 4 15 4 3 8 7 4 7 13 10 15 10 1 2 7 9 7 15 14 6 4 4 14 6 3 7 2 2 2 5 10 7 3 11 11 6 12 14 13 4 7 4 11 11 3 9 6 8 1 11 3 11 7 15 8 10 1 10 3 13 11 8 3 3 8 8 13 12 14 13 8 14 8 15 1 1\n164\n106\n152\n147\n186\n137\n144\n121\n143\n192\n137\n127\n108\n168\n162\n171\n140\n153\n181\n200\n",
"output": "4\n2\n8\n1\n10\n5\n14\n12\n13\n16\n5\n6\n9\n8\n2\n11\n10\n9\n5\n8\n"
},
{
"input": "100 21 20\n21 21 15 21 1 4 21 3 11 11 21 3 16 11 4 3 21 21 4 16 4 21 21 21 11 16 21 14 14 14 8 1 1 4 11 21 8 14 11 4 6 8 6 1 8 21 11 3 3 21 1 8 11 1 4 16 1 21 1 4 14 11 13 1 21 21 16 6 21 13 15 13 21 13 21 1 5 6 14 7 21 11 8 8 11 14 5 3 3 3 8 5 3 11 13 1 16 4 21 3\n127\n178\n192\n174\n164\n118\n108\n404159127218619270\n14469197281678073\n127\n139\n139\n555738333143181764\n906223987227162448\n101\n138\n747440919795929604\n127\n138\n122\n",
"output": "20\n2\n20\n17\n2\n2\n20\n15\n11\n20\n2\n2\n2\n19\n2\n20\n21\n20\n20\n12\n"
},
{
"input": "100 51 20\n2 5 17 5 16 14 23 36 27 41 31 36 44 50 6 22 14 2 37 39 49 31 26 9 11 49 5 38 8 25 6 4 49 5 29 8 47 38 11 1 18 21 21 15 26 34 6 43 2 28 48 30 48 39 12 26 32 26 12 22 37 9 10 5 13 44 32 3 19 15 37 42 40 22 16 46 11 42 15 17 44 50 43 32 39 8 10 28 43 14 43 49 45 39 39 7 4 8 16 10\n102\n106\n101\n101\n106\n161\n105\n105\n106\n105\n113\n127\n118\n101\n106\n104\n135\n127\n105\n105\n",
"output": "24\n1\n20\n20\n1\n51\n51\n51\n1\n51\n23\n51\n30\n20\n1\n35\n17\n51\n51\n51\n"
},
{
"input": "100 17 20\n8 16 4 7 12 6 1 17 6 1 2 7 16 16 12 7 17 8 12 12 1 17 16 4 16 17 2 2 6 6 17 1 2 2 6 4 6 17 16 12 17 16 17 1 12 12 4 6 8 17 1 4 16 12 17 8 1 1 6 8 4 4 12 8 12 2 16 1 16 6 2 8 12 4 2 6 4 4 2 8 2 8 1 16 16 8 1 2 6 1 17 4 2 6 12 17 12 7 16 6\n101\n108\n112\n116\n108\n141\n133\n832741425065423238\n460535959993121846\n433996273266058278\n119\n132326735886440059\n132\n117\n196\n76769211260841343\n162\n116\n112\n141\n",
"output": "3\n15\n10\n15\n15\n15\n3\n12\n14\n11\n9\n17\n15\n3\n15\n17\n7\n15\n10\n15\n"
},
{
"input": "100 41 20\n36 27 30 37 31 23 37 27 36 35 15 7 7 4 36 36 35 23 30 30 36 35 4 36 25 4 23 25 36 7 31 25 36 27 30 30 25 25 4 15 35 25 15 27 4 15 35 7 23 30 35 36 36 25 30 7 36 36 25 23 27 35 30 30 35 23 27 36 36 15 25 7 16 8 8 4 4 30 35 36 36 36 31 30 36 36 35 36 30 27 31 8 7 25 25 4 27 27 36 36\n180\n176\n168\n161\n164\n127\n194\n143\n143\n183\n186\n141\n160\n130\n170\n163\n162\n151\n147\n156\n",
"output": "32\n24\n14\n5\n10\n40\n9\n19\n19\n37\n40\n17\n3\n2\n17\n9\n6\n32\n24\n40\n"
},
{
"input": "100 74 20\n9 15 16 18 55 41 64 44 5 1 27 31 36 25 71 28 71 35 47 40 21 53 31 11 24 1 69 67 58 16 19 52 33 17 63 1 49 28 17 52 46 60 53 21 21 60 19 63 11 61 8 27 3 22 38 31 45 69 61 18 58 22 8 71 17 1 64 70 56 10 66 47 70 1 45 8 66 8 66 25 39 45 47 7 41 24 41 72 16 42 28 7 15 10 38 29 50 4 37 11\n123\n140\n156\n123\n681178055639444431\n402923644436772466\n122\n101\n705403096072274104\n169676975611015773\n108\n122\n164\n131\n164\n164\n365209906715274474\n122\n111\n122\n",
"output": "2\n35\n57\n2\n23\n54\n74\n2\n26\n37\n26\n74\n74\n14\n74\n74\n20\n74\n34\n74\n"
},
{
"input": "1 1 20\n1\n2\n5\n200\n199\n198\n24\n123\n100\n101\n100\n3\n6\n200\n193\n191\n24\n123\n78\n109\n13\n",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n"
},
{
"input": "100 99 20\n89 96 26 16 28 26 96 14 46 92 76 66 93 65 45 7 89 6 95 53 34 59 15 75 8 25 20 99 41 90 51 14 94 23 68 25 58 81 50 85 87 53 27 67 64 30 55 77 7 30 10 32 38 1 67 94 44 16 49 38 63 76 81 47 55 92 67 25 61 96 2 52 33 69 4 64 24 29 88 70 45 76 83 79 22 87 5 62 11 30 17 82 77 48 73 88 96 35 96 82\n106\n198\n109\n190\n154\n160\n127\n147\n163\n153\n143\n194\n189\n172\n181\n129\n162\n104\n175\n172\n",
"output": "19\n86\n36\n74\n32\n39\n97\n22\n42\n31\n18\n80\n73\n52\n63\n1\n41\n13\n57\n52\n"
},
{
"input": "20 9 20\n9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9\n172\n27\n41\n96\n137\n111\n33\n36\n67\n173\n176\n150\n72\n75\n38\n81\n186\n180\n169\n40\n",
"output": "8\n7\n5\n4\n5\n3\n5\n8\n7\n1\n4\n2\n4\n7\n2\n5\n6\n8\n5\n4\n"
}
] |
code_contests
|
python
| 0 |
e54f115ffffd3749c1c060e4c82471a6
|
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input
The input contains three positive integer numbers in the first line: n, m and a (1 ≤ n, m, a ≤ 109).
Output
Write the needed number of flagstones.
Examples
Input
6 6 4
Output
4
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import math
def main():
n, m, a = map(int, input().split())
sq_area = n * m
stone_area = a * a
if stone_area > sq_area:
return 1
return math.ceil(m / a) * math.ceil(n / a)
if __name__ == '__main__':
print(main())
|
python
|
code_algorithm
|
[
{
"input": "6 6 4\n",
"output": "4\n"
},
{
"input": "1 1 3\n",
"output": "1\n"
},
{
"input": "1000000000 1000000000 1\n",
"output": "1000000000000000000\n"
},
{
"input": "2 1 2\n",
"output": "1\n"
},
{
"input": "222 332 5\n",
"output": "3015\n"
},
{
"input": "2 2 1\n",
"output": "4\n"
},
{
"input": "456784567 1000000000 51\n",
"output": "175618850864484\n"
},
{
"input": "1001 1000 10\n",
"output": "10100\n"
},
{
"input": "2 3 4\n",
"output": "1\n"
},
{
"input": "1000000000 1000000000 999999999\n",
"output": "4\n"
},
{
"input": "2 1 1\n",
"output": "2\n"
},
{
"input": "100 10001 1000000000\n",
"output": "1\n"
},
{
"input": "39916800 134217728 40320\n",
"output": "3295710\n"
},
{
"input": "12 13 4\n",
"output": "12\n"
},
{
"input": "1000 1000 10\n",
"output": "10000\n"
},
{
"input": "1 1 1\n",
"output": "1\n"
},
{
"input": "1000000000 987654321 1\n",
"output": "987654321000000000\n"
},
{
"input": "1000000000 1000000000 192\n",
"output": "27126743055556\n"
},
{
"input": "1000000000 1000000000 1000000000\n",
"output": "1\n"
},
{
"input": "1 2 1\n",
"output": "2\n"
}
] |
code_contests
|
python
| 1 |
b5363242180e9890d76365494ca6553d
|
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
<image>
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output
On the single line of the output print the number of groups of magnets.
Examples
Input
6
10
10
10
01
10
10
Output
3
Input
4
01
01
10
10
Output
2
Note
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
s=0
prev=''
for i in range(int(input())):
kk=input()
if kk!=prev:
s+=1
prev=kk
print(s)
|
python
|
code_algorithm
|
[
{
"input": "4\n01\n01\n10\n10\n",
"output": "2\n"
},
{
"input": "6\n10\n10\n10\n01\n10\n10\n",
"output": "3\n"
},
{
"input": "1\n10\n",
"output": "1\n"
},
{
"input": "3\n10\n01\n10\n",
"output": "3\n"
},
{
"input": "3\n10\n10\n01\n",
"output": "2\n"
},
{
"input": "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10\n",
"output": "55\n"
},
{
"input": "3\n01\n10\n10\n",
"output": "2\n"
},
{
"input": "2\n01\n10\n",
"output": "2\n"
},
{
"input": "2\n10\n10\n",
"output": "1\n"
},
{
"input": "1\n01\n",
"output": "1\n"
},
{
"input": "2\n10\n01\n",
"output": "2\n"
},
{
"input": "2\n01\n01\n",
"output": "1\n"
},
{
"input": "3\n01\n01\n01\n",
"output": "1\n"
}
] |
code_contests
|
python
| 1 |
ef33c709a884a31fa2dc576f72913748
|
Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property:
* consider all pairs of numbers x, y (x ≠ y), such that number x occurs in the array a and number y occurs in the array a;
* for each pair x, y must exist some position j (1 ≤ j < n), such that at least one of the two conditions are met, either aj = x, aj + 1 = y, or aj = y, aj + 1 = x.
Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers qi, wi. Coupon i costs wi and allows you to use as many numbers qi as you want when constructing the array a. Values qi are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes wi rubles from Sereja for each qi, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay.
Help Sereja, find the maximum amount of money he can pay to Dima.
Input
The first line contains two integers n and m (1 ≤ n ≤ 2·106, 1 ≤ m ≤ 105). Next m lines contain pairs of integers. The i-th line contains numbers qi, wi (1 ≤ qi, wi ≤ 105).
It is guaranteed that all qi are distinct.
Output
In a single line print maximum amount of money (in rubles) Sereja can pay.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
5 2
1 2
2 3
Output
5
Input
100 3
1 2
2 1
3 1
Output
4
Input
1 2
1 1
2 100
Output
100
Note
In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test.
In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2].
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
def readdata():
#fread = open('input.txt', 'r')
global n, m, w, q
n, m = [int(x) for x in input().split()]
q = [0] * m
w = [0] * m
for i in range(m):
q[i], w[i] = [int(x) for x in input().split()]
def podg():
global summ
w.sort(reverse = True)
summ = [w[0]] * m
for i in range(1, m):
summ[i] = summ[i - 1] + w[i]
def may(k):
if (k % 2 == 1):
return n > (k * (k - 1)) // 2
return n > (k * (k - 1)) // 2 + (k - 2) // 2
def solve():
for i in range(1, m + 1):
if may(i) and not may(i + 1):
print(summ[i - 1])
return
print(sum(w))
readdata()
podg()
solve()
|
python
|
code_algorithm
|
[
{
"input": "100 3\n1 2\n2 1\n3 1\n",
"output": "4\n"
},
{
"input": "1 2\n1 1\n2 100\n",
"output": "100\n"
},
{
"input": "5 2\n1 2\n2 3\n",
"output": "5\n"
},
{
"input": "58 38\n6384 48910\n97759 90589\n28947 5031\n45169 32592\n85656 26360\n88538 42484\n44042 88351\n42837 79021\n96022 59200\n485 96735\n98000 3939\n3789 64468\n10894 58484\n26422 26618\n25515 95617\n37452 5250\n39557 66304\n79009 40610\n80703 60486\n90344 37588\n57504 61201\n62619 79797\n51282 68799\n15158 27623\n28293 40180\n9658 62192\n2889 3512\n66635 24056\n18647 88887\n28434 28143\n9417 23999\n22652 77700\n52477 68390\n10713 2511\n22870 66689\n41790 76424\n74586 34286\n47427 67758\n",
"output": "910310\n"
},
{
"input": "3 3\n1 1\n2 1\n3 1\n",
"output": "2\n"
},
{
"input": "11 10\n1 5\n2 5\n3 5\n4 5\n5 5\n6 5\n7 5\n8 5\n9 5\n10 5\n",
"output": "25\n"
},
{
"input": "53 1\n16942 81967\n",
"output": "81967\n"
},
{
"input": "59 29\n93008 65201\n62440 8761\n26325 69109\n30888 54851\n42429 3385\n66541 80705\n52357 33351\n50486 15217\n41358 45358\n7272 37362\n85023 54113\n62697 44042\n60130 32566\n96933 1856\n12963 17735\n44973 38370\n26964 26484\n63636 66849\n12939 58143\n34512 32176\n5826 89871\n63935 91784\n17399 50702\n88735 10535\n93994 57706\n94549 92301\n32642 84856\n55463 82878\n679 82444\n",
"output": "864141\n"
},
{
"input": "10 6\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n",
"output": "4\n"
},
{
"input": "7 4\n1 2\n2 3\n3 4\n4 5\n",
"output": "12\n"
},
{
"input": "2 5\n1 1\n2 1\n3 1\n4 1\n5 1\n",
"output": "2\n"
},
{
"input": "73 19\n21018 52113\n53170 12041\n44686 99498\n73991 59354\n66652 2045\n56336 99193\n85265 20504\n51776 85293\n21550 17562\n70468 38130\n7814 88602\n84216 64214\n69825 55393\n90671 24028\n98076 67499\n46288 36605\n17222 21707\n25011 99490\n92165 51620\n",
"output": "860399\n"
},
{
"input": "7 5\n1 1\n2 1\n3 1\n4 1\n5 1\n",
"output": "3\n"
},
{
"input": "47 10\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n",
"output": "9\n"
},
{
"input": "11 5\n1 1\n2 1\n3 1\n4 1\n5 1\n",
"output": "5\n"
},
{
"input": "44 25\n65973 66182\n23433 87594\n13032 44143\n35287 55901\n92361 46975\n69171 50834\n77761 76668\n32551 93695\n61625 10126\n53695 82303\n94467 18594\n57485 4465\n31153 18088\n21927 24758\n60316 62228\n98759 53110\n41087 83488\n78475 25628\n59929 64521\n78963 60597\n97262 72526\n56261 72117\n80327 82772\n77548 17521\n94925 37764\n",
"output": "717345\n"
},
{
"input": "6 26\n48304 25099\n17585 38972\n70914 21546\n1547 97770\n92520 48290\n10866 3246\n84319 49602\n57133 31153\n12571 45902\n10424 75601\n22016 80029\n1348 18944\n6410 21050\n93589 44609\n41222 85955\n30147 87950\n97431 40749\n48537 74036\n47186 25854\n39225 55924\n20258 16945\n83319 57412\n20356 54550\n90585 97965\n52076 32143\n93949 24427\n",
"output": "283685\n"
},
{
"input": "1 1\n1 1\n",
"output": "1\n"
},
{
"input": "31 8\n1 1\n2 2\n3 4\n4 8\n5 16\n6 32\n7 64\n8 128\n",
"output": "254\n"
},
{
"input": "90 27\n30369 65426\n63435 75442\n14146 41719\n12140 52280\n88688 50550\n3867 68194\n43298 40287\n84489 36456\n6115 63317\n77787 20314\n91186 96913\n57833 44314\n20322 79647\n24482 31197\n11130 57536\n11174 24045\n14293 65254\n94155 24746\n81187 20475\n6169 94788\n77959 22203\n26478 57315\n97335 92373\n99834 47488\n11519 81774\n41764 93193\n23103 89214\n",
"output": "1023071\n"
},
{
"input": "8 7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n",
"output": "4\n"
},
{
"input": "17 9\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n",
"output": "5\n"
},
{
"input": "25 29\n82963 53706\n63282 73962\n14996 48828\n84392 31903\n96293 41422\n31719 45448\n46772 17870\n9668 85036\n36704 83323\n73674 63142\n80254 1548\n40663 44038\n96724 39530\n8317 42191\n44289 1041\n63265 63447\n75891 52371\n15007 56394\n55630 60085\n46757 84967\n45932 72945\n72627 41538\n32119 46930\n16834 84640\n78705 73978\n23674 57022\n66925 10271\n54778 41098\n7987 89162\n",
"output": "575068\n"
},
{
"input": "17 6\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n",
"output": "20\n"
},
{
"input": "27 13\n30094 96037\n81142 53995\n98653 82839\n25356 81132\n77842 2012\n88187 81651\n5635 86354\n25453 63263\n61455 12635\n10257 47125\n48214 12029\n21081 92859\n24156 67265\n",
"output": "588137\n"
},
{
"input": "7 4\n1 1\n2 1\n3 1\n4 1\n",
"output": "3\n"
},
{
"input": "2 2\n1 1\n2 1\n",
"output": "2\n"
},
{
"input": "8 10\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n",
"output": "4\n"
}
] |
code_contests
|
python
| 0 |
79f3cb1267656f9cd9b6200559e4822e
|
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 the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n=input()
d=[]
sp="!?.,_"
for i in n:
if len(n)>=5:
d.append(1)
if i.isupper()==True:
d.append(2)
if i.islower()==True:
d.append(3)
if i.isdigit()==True:
d.append(4)
if i in sp:
d.append(5)
s=set(d)
if s=={1,2,3,4} or s=={1,2,3,4,5}:
print("Correct")
else:
print("Too weak")
|
python
|
code_algorithm
|
[
{
"input": "X12345\n",
"output": "Too weak\n"
},
{
"input": "CONTEST_is_STARTED!!11\n",
"output": "Correct\n"
},
{
"input": "abacaba\n",
"output": "Too weak\n"
},
{
"input": "Vu7jQU8.!FvHBYTsDp6AphaGfnEmySP9te\n",
"output": "Correct\n"
},
{
"input": "P1H\n",
"output": "Too weak\n"
},
{
"input": "c7jqaudcqmv8o7zvb5x_gp6zcgl6nwr7tz5or!28.tj8s1m2.wxz5a4id03!rq07?662vy.7.p5?vk2f2mc7ag8q3861rgd0rmbr\n",
"output": "Too weak\n"
},
{
"input": "Hi7zYuVXCPhaho68YgCMzzgLILM6toQTJq8akMqqrnUn6ZCD36iA1yVVpvlsIiMpCu!1QZd4ycIrQ5Kcrhk5k0jTrwdAAEEP_T2f\n",
"output": "Correct\n"
},
{
"input": "T,NDMUYCCXH_L_FJHMCCAGX_XSCPGOUZSY?D?CNDSYRITYS,VAT!PJVKNTBMXGGRYKACLYU.RJQ_?UWKXYIDE_AE\n",
"output": "Too weak\n"
},
{
"input": "Ro1HcZ.piN,JRR88DLh,WtW!pbFM076?wCSbqfK7N2s5zUySFBtzk7HV,BxHXR0zALAr016z5jvvB.WUdEcKgYFav5TygwHQC..C\n",
"output": "Correct\n"
},
{
"input": "SdoOuJ?nj_wJyf\n",
"output": "Too weak\n"
},
{
"input": "qgw\n",
"output": "Too weak\n"
},
{
"input": "34__39_02!,!,82!129!2!566\n",
"output": "Too weak\n"
},
{
"input": "J2\n",
"output": "Too weak\n"
},
{
"input": "C672F429Y8X6XU7S,.K9111UD3232YXT81S4!729ER7DZ.J7U1R_7VG6.FQO,LDH\n",
"output": "Too weak\n"
},
{
"input": "h6y1l\n",
"output": "Too weak\n"
},
{
"input": "l4!m_44kpw8.jg!?oh,?y5oraw1tg7_x1.osl0!ny?_aihzhtt0e2!mr92tnk0es!1f,9he40_usa6c50l\n",
"output": "Too weak\n"
},
{
"input": "y\n",
"output": "Too weak\n"
},
{
"input": "FwX\n",
"output": "Too weak\n"
},
{
"input": "Qf7\n",
"output": "Too weak\n"
},
{
"input": "90328_\n",
"output": "Too weak\n"
},
{
"input": "Yb1x\n",
"output": "Too weak\n"
},
{
"input": "EFHI,,Y?HMMUI,,FJGAY?FYPBJQMYM!DZHLFCTFWT?JOPDW,S_!OR?ATT?RWFBMAAKUHIDMHSD?LCZQY!UD_CGYGBAIRDPICYS\n",
"output": "Too weak\n"
},
{
"input": "0\n",
"output": "Too weak\n"
},
{
"input": "Oj9vu\n",
"output": "Correct\n"
},
{
"input": "txguglvclyillwnono\n",
"output": "Too weak\n"
},
{
"input": "i6a.,8jb,n0kv4.1!7h?p.96pnhhgy6cl7dg7e4o6o384ys3z.t71kkq,,w,oqi4?u,,m5!rzu6wym_4hm,ohjy!.vvksl?pt,,1\n",
"output": "Too weak\n"
},
{
"input": "H.FZ\n",
"output": "Too weak\n"
},
{
"input": "1A___\n",
"output": "Too weak\n"
},
{
"input": "d4r!ak.igzhnu!boghwd6jl\n",
"output": "Too weak\n"
},
{
"input": "KSHMICWPK,LSBM_JVZ!IPDYDG_GOPCHXFJTKJBIFY,FPHMY,CB?PZEAG..,X,.GFHPIDBB,IQ?MZ\n",
"output": "Too weak\n"
},
{
"input": "Oq2LYmV9HmlaW\n",
"output": "Correct\n"
},
{
"input": "x5hve\n",
"output": "Too weak\n"
},
{
"input": "Cq7r3Wrb.lDb_0wsf7!ruUUGSf08RkxD?VsBEDdyE?SHK73TFFy0f8gmcATqGafgTv8OOg8or2HyMPIPiQ2Hsx8q5rn3_WZe\n",
"output": "Correct\n"
},
{
"input": "Um3Fj?QLhNuRE_Gx0cjMLOkGCm\n",
"output": "Correct\n"
},
{
"input": "Wx4p1fOrEMDlQpTlIx0p.1cnFD7BnX2K8?_dNLh4cQBx_Zqsv83BnL5hGKNcBE9g3QB,!fmSvgBeQ_qiH7\n",
"output": "Correct\n"
},
{
"input": "96156027.65935663!_87!,44,..7914_!0_1,.4!!62!.8350!17_282!!9.2584,!!7__51.526.7\n",
"output": "Too weak\n"
},
{
"input": "1zA__\n",
"output": "Correct\n"
},
{
"input": "CpWxDVzwHfYFfoXNtXMFuAZr\n",
"output": "Too weak\n"
},
{
"input": "i9nij\n",
"output": "Too weak\n"
},
{
"input": "b27fk\n",
"output": "Too weak\n"
},
{
"input": "7\n",
"output": "Too weak\n"
},
{
"input": "Uf24o\n",
"output": "Correct\n"
},
{
"input": "MhnfZjsUyXYw?f?ubKA\n",
"output": "Too weak\n"
},
{
"input": "D\n",
"output": "Too weak\n"
},
{
"input": "k673,\n",
"output": "Too weak\n"
},
{
"input": "d_iymyvxolmjayhwpedocopqwmy.oalrdg!_n?.lrxpamhygps?kkzxydsbcaihfs.j?eu!oszjsy.vzu?!vs.bprz_j\n",
"output": "Too weak\n"
},
{
"input": "g\n",
"output": "Too weak\n"
},
{
"input": "._,.!.,...?_,!.\n",
"output": "Too weak\n"
},
{
"input": "_\n",
"output": "Too weak\n"
},
{
"input": "p1j\n",
"output": "Too weak\n"
},
{
"input": "PodE\n",
"output": "Too weak\n"
},
{
"input": "9.,0\n",
"output": "Too weak\n"
},
{
"input": "M6BCAKW!85OSYX1D?.53KDXP42F\n",
"output": "Too weak\n"
},
{
"input": "zA___\n",
"output": "Too weak\n"
},
{
"input": "?\n",
"output": "Too weak\n"
},
{
"input": "Gf5Q6\n",
"output": "Correct\n"
},
{
"input": "z1\n",
"output": "Too weak\n"
},
{
"input": "v8eycoylzv0qkix5mfs_nhkn6k!?ovrk9!b69zy!4frc?k\n",
"output": "Too weak\n"
},
{
"input": "!_?_,?,?.,.,_!!!.!,.__,?!!,_!,?_,!??,?!..._!?_,?_!,?_.,._,,_.,.\n",
"output": "Too weak\n"
},
{
"input": "z1___\n",
"output": "Too weak\n"
},
{
"input": "Ka4hGE,vkvNQbNolnfwp\n",
"output": "Correct\n"
},
{
"input": "a\n",
"output": "Too weak\n"
},
{
"input": "It0\n",
"output": "Too weak\n"
},
{
"input": "R\n",
"output": "Too weak\n"
},
{
"input": "LzuYQ\n",
"output": "Too weak\n"
},
{
"input": "XZX\n",
"output": "Too weak\n"
},
{
"input": "!?.,_\n",
"output": "Too weak\n"
},
{
"input": "?..!.,,?,__.,...????_???__!,?...?.,,,,___!,.!,_,,_,??!_?_,!!?_!_??.?,.!!?_?_.,!\n",
"output": "Too weak\n"
},
{
"input": "1zA_\n",
"output": "Too weak\n"
},
{
"input": "Bk2Q38vDSW5JqYu.077iYC.9YoiPc!Dh6FJWOVze6?YXiFjPNa4F1RG?154m9mY2jQobBnbxM,cDV8l1UX1?v?p.tTYIyJO!NYmE\n",
"output": "Correct\n"
},
{
"input": "Ee9oluD?amNItsjeQVtOjwj4w_ALCRh7F3eaZah\n",
"output": "Correct\n"
},
{
"input": "B9\n",
"output": "Too weak\n"
},
{
"input": "W2PI__!.O91H8OFY6AB__R30L9XOU8800?ZUD84L5KT99818NFNE35V.8LJJ5P2MM.B6B\n",
"output": "Too weak\n"
},
{
"input": "M10V_MN_1K8YX2LA!89EYV7!5V9?,.IDHDP6JEC.OGLY.180LMZ6KW3Z5E17IT94ZNHS!79GN09Q6LH0,F3AYNKP?KM,QP_?XRD6\n",
"output": "Too weak\n"
},
{
"input": "Pasq!\n",
"output": "Too weak\n"
},
{
"input": "loaray\n",
"output": "Too weak\n"
},
{
"input": "5,8\n",
"output": "Too weak\n"
},
{
"input": "Zi\n",
"output": "Too weak\n"
},
{
"input": "j9\n",
"output": "Too weak\n"
}
] |
code_contests
|
python
| 0.4 |
b00c046a8c16a58a61b08c2e641289b2
|
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n = int(input())
for i in range(n):
l,r=map(int,input().split())
while(l|(l+1)<=r): # or make like max function here .
l|=l+1 # or here like equal
print(l)
|
python
|
code_algorithm
|
[
{
"input": "3\n1 2\n2 4\n1 10\n",
"output": "1\n3\n7\n"
},
{
"input": "18\n1 10\n1 100\n1 1000\n1 10000\n1 100000\n1 1000000\n1 10000000\n1 100000000\n1 1000000000\n1 10000000000\n1 100000000000\n1 1000000000000\n1 10000000000000\n1 100000000000000\n1 1000000000000000\n1 10000000000000000\n1 100000000000000000\n1 1000000000000000000\n",
"output": "7\n63\n511\n8191\n65535\n524287\n8388607\n67108863\n536870911\n8589934591\n68719476735\n549755813887\n8796093022207\n70368744177663\n562949953421311\n9007199254740991\n72057594037927935\n576460752303423487\n"
},
{
"input": "17\n0 0\n0 8\n1 8\n36 39\n3 4\n3 7\n2 17\n8 12\n9 12\n10 12\n10 15\n6 14\n8 15\n9 15\n15 15\n100000000000000000 1000000000000000000\n99999999999999999 1000000000000000000\n",
"output": "0\n7\n7\n39\n3\n7\n15\n11\n11\n11\n15\n7\n15\n15\n15\n576460752303423487\n576460752303423487\n"
},
{
"input": "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n6 6\n6 7\n6 8\n6 9\n6 10\n7 7\n7 8\n7 9\n7 10\n8 8\n8 9\n8 10\n9 9\n9 10\n10 10\n",
"output": "1\n1\n3\n3\n3\n3\n7\n7\n7\n7\n2\n3\n3\n3\n3\n7\n7\n7\n7\n3\n3\n3\n3\n7\n7\n7\n7\n4\n5\n5\n7\n7\n7\n7\n5\n5\n7\n7\n7\n7\n6\n7\n7\n7\n7\n7\n7\n7\n7\n8\n9\n9\n9\n9\n10\n"
},
{
"input": "3\n0 0\n1 3\n2 4\n",
"output": "0\n3\n3\n"
}
] |
code_contests
|
python
| 0 |
175a62a91d18ed78f5b42a45bbc13581
|
Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing ai cows. During each player's turn, that player calls upon the power of Sunlight, and uses it to either:
1. Remove a single cow from a chosen non-empty pile.
2. Choose a pile of cows with even size 2·x (x > 0), and replace it with k piles of x cows each.
The player who removes the last cow wins. Given n, k, and a sequence a1, a2, ..., an, help Kevin and Nicky find the winner, given that both sides play in optimal way.
Input
The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).
The second line contains n integers, a1, a2, ... an (1 ≤ ai ≤ 109) describing the initial state of the game.
Output
Output the name of the winning player, either "Kevin" or "Nicky" (without quotes).
Examples
Input
2 1
3 4
Output
Kevin
Input
1 2
3
Output
Nicky
Note
In the second sample, Nicky can win in the following way: Kevin moves first and is forced to remove a cow, so the pile contains two cows after his move. Next, Nicky replaces this pile of size 2 with two piles of size 1. So the game state is now two piles of size 1. Kevin then removes one of the remaining cows and Nicky wins by removing the other.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
G_EVEN = {0:0, 1:1, 2:2}
G_ODD = {0:0, 1:1, 2:0, 3:1}
def grundy(k, ai):
if k % 2:
if ai <= 3:
return G_ODD[ai]
elif ai % 2:
return 0
else:
p = 0
j = ai
while not j & 1:
p += 1
j >>= 1
if j == 3:
return 2 if p % 2 else 1
else:
return 1 if p % 2 else 2
return 1 + p % 2
else:
if ai <= 2:
return G_EVEN[ai]
else:
return ~ai & 1
def nim_sum(ns):
s = 0
for ni in ns:
s ^= ni
return s
def winner(k, a):
return bool(nim_sum(grundy(k, ai) for ai in a))
if __name__ == '__main__':
n, k = map(int, input().split())
a = list(map(int, input().split()))
print("Kevin" if winner(k, a) else "Nicky")
|
python
|
code_algorithm
|
[
{
"input": "1 2\n3\n",
"output": "Nicky\n"
},
{
"input": "2 1\n3 4\n",
"output": "Kevin\n"
},
{
"input": "2 1\n24 1\n",
"output": "Kevin\n"
},
{
"input": "1 1\n1\n",
"output": "Kevin\n"
},
{
"input": "5 1\n1 7 7 6 6\n",
"output": "Kevin\n"
},
{
"input": "2 3\n12345678 23456789\n",
"output": "Kevin\n"
},
{
"input": "2 1\n160 150\n",
"output": "Nicky\n"
},
{
"input": "2 3\n7 7\n",
"output": "Nicky\n"
},
{
"input": "2 2\n2 5\n",
"output": "Kevin\n"
},
{
"input": "9 2\n8 2 9 4 7 5 2 4 9\n",
"output": "Kevin\n"
},
{
"input": "6 2\n5 3 5 6 2 2\n",
"output": "Kevin\n"
},
{
"input": "7 2\n9 1 7 6 10 3 5\n",
"output": "Kevin\n"
},
{
"input": "2 2\n2 4\n",
"output": "Kevin\n"
},
{
"input": "6 1\n1 4 4 4 2 2\n",
"output": "Kevin\n"
},
{
"input": "2 2\n2 2\n",
"output": "Nicky\n"
},
{
"input": "1 2\n1\n",
"output": "Kevin\n"
},
{
"input": "4 5\n20 21 22 25\n",
"output": "Kevin\n"
},
{
"input": "10 1\n2 3 5 2 7 4 7 7 4 2\n",
"output": "Kevin\n"
},
{
"input": "7 1\n8 6 10 10 1 5 8\n",
"output": "Kevin\n"
},
{
"input": "10 2\n3 10 10 8 6 10 9 9 5 7\n",
"output": "Kevin\n"
},
{
"input": "2 2\n2 3\n",
"output": "Kevin\n"
},
{
"input": "1 1\n1000000000\n",
"output": "Kevin\n"
},
{
"input": "2 2\n2 6\n",
"output": "Kevin\n"
},
{
"input": "2 2\n1 2\n",
"output": "Kevin\n"
},
{
"input": "4 100\n2 1 2 2\n",
"output": "Kevin\n"
},
{
"input": "3 2\n1 1 1\n",
"output": "Kevin\n"
},
{
"input": "9 2\n2 8 4 2 5 7 1 8 10\n",
"output": "Kevin\n"
},
{
"input": "10 1\n5 6 3 10 6 6 1 1 5 3\n",
"output": "Kevin\n"
},
{
"input": "1 1\n111111112\n",
"output": "Kevin\n"
},
{
"input": "2 3\n1000000000 1000000000\n",
"output": "Nicky\n"
}
] |
code_contests
|
python
| 0 |
00a80c210cc7f86deac3491cba505711
|
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).
Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.
Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
Input
The first line of the input contains two positive integers a1 and a2 (1 ≤ a1, a2 ≤ 100), the initial charge level of first and second joystick respectively.
Output
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
Examples
Input
3 5
Output
6
Input
4 4
Output
5
Note
In the first sample game lasts for 6 minute by using the following algorithm:
* at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%;
* continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%;
* at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%;
* continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%;
* at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%;
* at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.
After that the first joystick is completely discharged and the game is stopped.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import sys
input = sys.stdin.readline
def inp():
return (int(input()))
def inlt():
return (list(map(int, input().split())))
def insr():
s = input()
return (list(s[:len(s) - 1]))
def invr():
return list((map(int, input().split())))
hash_map = {}
def solve(a1, a2):
if a1 <= 0 or a2 <= 0:
return 0
if a1 == 1 and a2 == 1:
return 0
if a1 <= 2 and a2 <= 2:
return 1
if (a1, a2) in hash_map:
return hash_map[(a1, a2)]
hash_map[(a1, a2)] = max(1 + solve(a1-2, a2 + 1), 1 + solve(a1+1, a2 - 2))
return hash_map[(a1, a2)]
if __name__ == '__main__':
a = inlt()
print(solve(a[0], a[1]))
|
python
|
code_algorithm
|
[
{
"input": "4 4\n",
"output": "5\n"
},
{
"input": "3 5\n",
"output": "6\n"
},
{
"input": "1 4\n",
"output": "2\n"
},
{
"input": "7 2\n",
"output": "7\n"
},
{
"input": "100 25\n",
"output": "122\n"
},
{
"input": "29 1\n",
"output": "28\n"
},
{
"input": "3 73\n",
"output": "74\n"
},
{
"input": "14 15\n",
"output": "27\n"
},
{
"input": "1 1\n",
"output": "0\n"
},
{
"input": "24 57\n",
"output": "78\n"
},
{
"input": "1 2\n",
"output": "1\n"
},
{
"input": "3 2\n",
"output": "3\n"
},
{
"input": "24 15\n",
"output": "36\n"
},
{
"input": "2 97\n",
"output": "97\n"
},
{
"input": "15 31\n",
"output": "44\n"
},
{
"input": "15 25\n",
"output": "38\n"
},
{
"input": "2 3\n",
"output": "3\n"
},
{
"input": "8 8\n",
"output": "13\n"
},
{
"input": "2 99\n",
"output": "99\n"
},
{
"input": "59 45\n",
"output": "102\n"
},
{
"input": "23 12\n",
"output": "33\n"
},
{
"input": "3 1\n",
"output": "2\n"
},
{
"input": "74 25\n",
"output": "97\n"
},
{
"input": "85 73\n",
"output": "155\n"
},
{
"input": "2 2\n",
"output": "1\n"
},
{
"input": "32 53\n",
"output": "82\n"
},
{
"input": "48 1\n",
"output": "47\n"
},
{
"input": "1 100\n",
"output": "98\n"
},
{
"input": "100 1\n",
"output": "98\n"
},
{
"input": "58 33\n",
"output": "89\n"
},
{
"input": "40 49\n",
"output": "86\n"
},
{
"input": "30 54\n",
"output": "81\n"
},
{
"input": "98 2\n",
"output": "97\n"
},
{
"input": "32 54\n",
"output": "84\n"
},
{
"input": "19 30\n",
"output": "47\n"
},
{
"input": "100 100\n",
"output": "197\n"
},
{
"input": "1 3\n",
"output": "2\n"
},
{
"input": "2 1\n",
"output": "1\n"
}
] |
code_contests
|
python
| 0 |
6c35d843c192333245e482167168c9df
|
Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name "dot" with the following rules:
* On the checkered paper a coordinate system is drawn. A dot is initially put in the position (x, y).
* A move is shifting a dot to one of the pre-selected vectors. Also each player can once per game symmetrically reflect a dot relatively to the line y = x.
* Anton and Dasha take turns. Anton goes first.
* The player after whose move the distance from the dot to the coordinates' origin exceeds d, loses.
Help them to determine the winner.
Input
The first line of the input file contains 4 integers x, y, n, d ( - 200 ≤ x, y ≤ 200, 1 ≤ d ≤ 200, 1 ≤ n ≤ 20) — the initial coordinates of the dot, the distance d and the number of vectors. It is guaranteed that the initial dot is at the distance less than d from the origin of the coordinates. The following n lines each contain two non-negative numbers xi and yi (0 ≤ xi, yi ≤ 200) — the coordinates of the i-th vector. It is guaranteed that all the vectors are nonzero and different.
Output
You should print "Anton", if the winner is Anton in case of both players play the game optimally, and "Dasha" otherwise.
Examples
Input
0 0 2 3
1 1
1 2
Output
Anton
Input
0 0 2 4
1 1
1 2
Output
Dasha
Note
In the first test, Anton goes to the vector (1;2), and Dasha loses. In the second test Dasha with her first move shifts the dot so that its coordinates are (2;3), and Anton loses, as he has the only possible move — to reflect relatively to the line y = x. Dasha will respond to it with the same move and return the dot in position (2;3).
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
x, y, n, d = map(int, input().split())
vector = [list(map(int, input().split())) for _ in range(n)]
dp = [[-1] * (d * 2 + 1) for _ in range(d * 2 + 1)]
for i in range(d * 2 + 1):
for j in range(d * 2 + 1):
if (i - d) ** 2 + (j - d) ** 2 > d**2:
dp[i][j] = 1
def solve(x, y):
if dp[x][y] != -1:
return dp[x][y]
for dx, dy in vector:
if 0 <= x + dx <= 2 * d and 0 <= y + dy <= 2 * d and solve(x + dx, y + dy) == 0:
dp[x][y] = 1
return 1
dp[x][y] = 0
return 0
if solve(x + d, y + d):
print('Anton')
else:
print('Dasha')
|
python
|
code_algorithm
|
[
{
"input": "0 0 2 4\n1 1\n1 2\n",
"output": "Dasha\n"
},
{
"input": "0 0 2 3\n1 1\n1 2\n",
"output": "Anton\n"
},
{
"input": "3 -1 20 200\n19 12\n24 121\n25 32\n28 19\n28 87\n29 49\n32 88\n33 70\n37 77\n54 33\n56 27\n61 59\n67 42\n73 15\n76 40\n80 73\n83 39\n91 34\n91 112\n95 95\n",
"output": "Anton\n"
},
{
"input": "0 0 5 100\n17 3\n42 24\n72 22\n72 25\n120 25\n",
"output": "Dasha\n"
},
{
"input": "0 0 5 100\n12 105\n15 59\n21 1\n27 6\n27 76\n",
"output": "Anton\n"
},
{
"input": "-3 -14 20 200\n6 90\n7 12\n15 24\n16 67\n26 35\n34 63\n35 48\n36 30\n48 28\n56 35\n59 91\n60 34\n76 43\n77 90\n77 95\n79 34\n87 69\n93 6\n99 10\n99 41\n",
"output": "Anton\n"
},
{
"input": "-100 -100 10 200\n0 1\n1 0\n1 1\n31 41\n3 4\n5 2\n1 2\n3 3\n9 8\n10 2\n",
"output": "Anton\n"
},
{
"input": "0 0 15 98\n5 14\n9 133\n10 128\n15 140\n17 53\n33 43\n50 15\n69 55\n74 134\n77 100\n99 82\n100 140\n102 12\n110 65\n128 110\n",
"output": "Anton\n"
},
{
"input": "0 0 5 100\n16 24\n29 6\n44 24\n66 37\n102 19\n",
"output": "Anton\n"
},
{
"input": "-3 -14 20 200\n11 24\n13 8\n14 8\n15 44\n15 54\n20 79\n24 72\n27 7\n28 6\n30 18\n46 34\n51 5\n64 83\n69 48\n78 76\n79 2\n89 43\n92 31\n94 76\n99 64\n",
"output": "Anton\n"
},
{
"input": "0 0 5 100\n52 144\n55 58\n56 103\n98 65\n134 16\n",
"output": "Anton\n"
},
{
"input": "0 0 19 34\n0 116\n6 11\n6 32\n9 84\n14 3\n27 85\n42 58\n46 31\n52 104\n65 83\n66 37\n68 130\n69 69\n78 7\n78 23\n81 66\n90 27\n91 39\n96 10\n",
"output": "Anton\n"
},
{
"input": "0 0 17 141\n9 30\n9 55\n11 64\n18 37\n20 94\n23 37\n23 140\n28 134\n36 43\n38 77\n50 47\n54 42\n70 32\n74 151\n85 68\n87 53\n88 91\n",
"output": "Anton\n"
},
{
"input": "3 -1 20 200\n3 51\n6 75\n7 105\n8 109\n12 59\n12 90\n15 71\n17 150\n18 161\n19 106\n23 71\n26 68\n34 95\n36 47\n38 29\n38 153\n41 91\n43 128\n43 164\n44 106\n",
"output": "Anton\n"
},
{
"input": "-133 -133 20 200\n1 0\n0 1\n1 1\n2 0\n0 2\n2 1\n1 2\n3 0\n0 3\n3 1\n3 2\n3 3\n2 2\n2 3\n1 3\n4 0\n0 4\n4 1\n1 4\n2 4\n",
"output": "Anton\n"
},
{
"input": "0 0 19 27\n1 25\n11 3\n12 38\n27 52\n35 111\n36 51\n44 7\n45 106\n58 104\n63 108\n75 4\n76 84\n89 2\n89 44\n92 23\n98 66\n111 58\n113 9\n114 76\n",
"output": "Anton\n"
},
{
"input": "-3 -14 20 200\n1 60\n5 47\n10 6\n14 17\n14 32\n34 93\n40 9\n43 85\n44 47\n49 59\n57 85\n68 50\n69 93\n71 42\n71 57\n73 5\n74 70\n83 41\n83 83\n89 8\n",
"output": "Anton\n"
},
{
"input": "12 -11 20 200\n6 80\n12 62\n14 15\n16 133\n41 28\n43 47\n79 136\n90 196\n99 151\n99 187\n119 42\n121 11\n147 132\n149 166\n161 102\n174 4\n182 122\n194 50\n200 182\n200 197\n",
"output": "Anton\n"
},
{
"input": "-140 -140 2 200\n1 0\n0 1\n",
"output": "Dasha\n"
},
{
"input": "-130 -130 20 200\n0 1\n1 0\n1 1\n31 41\n3 4\n5 2\n1 2\n3 3\n9 8\n10 2\n0 2\n0 3\n0 4\n0 5\n0 6\n2 0\n3 0\n4 0\n5 0\n6 0\n",
"output": "Anton\n"
},
{
"input": "3 -1 20 200\n1 28\n9 80\n20 92\n29 82\n38 65\n42 9\n50 65\n67 57\n71 60\n73 51\n78 89\n86 31\n90 39\n97 96\n104 27\n115 49\n119 59\n125 18\n132 37\n133 9\n",
"output": "Anton\n"
},
{
"input": "12 -11 20 200\n12 147\n14 181\n14 198\n33 51\n34 93\n43 29\n47 44\n56 161\n66 111\n96 119\n102 71\n117 184\n133 69\n151 189\n152 28\n173 27\n173 120\n176 12\n183 1\n188 196\n",
"output": "Anton\n"
},
{
"input": "-12 -34 5 200\n1 0\n2 0\n3 1\n10 3\n11 4\n",
"output": "Dasha\n"
},
{
"input": "12 -11 20 200\n8 176\n11 162\n25 130\n32 124\n58 175\n59 170\n61 98\n66 37\n78 5\n87 150\n94 172\n99 171\n121 11\n121 31\n124 172\n131 71\n134 190\n162 50\n182 99\n194 119\n",
"output": "Anton\n"
},
{
"input": "0 0 5 100\n2 164\n23 107\n30 167\n46 178\n66 148\n",
"output": "Dasha\n"
},
{
"input": "0 0 5 100\n4 108\n5 170\n7 30\n7 101\n21 117\n",
"output": "Anton\n"
},
{
"input": "3 -1 20 200\n1 139\n8 76\n10 97\n25 99\n26 147\n29 51\n48 79\n56 164\n67 80\n71 35\n89 90\n108 16\n108 127\n127 54\n137 13\n140 156\n146 104\n160 155\n164 138\n172 102\n",
"output": "Anton\n"
},
{
"input": "-3 -14 20 200\n14 51\n26 54\n30 50\n38 41\n40 68\n47 12\n50 86\n63 4\n65 52\n67 83\n70 88\n71 61\n79 82\n82 53\n89 84\n90 16\n92 79\n97 37\n100 37\n100 93\n",
"output": "Dasha\n"
},
{
"input": "0 0 17 160\n31 75\n32 149\n49 132\n54 98\n54 100\n57 48\n65 20\n67 177\n72 76\n74 25\n99 49\n105 86\n128 116\n147 176\n156 130\n160 26\n178 177\n",
"output": "Anton\n"
},
{
"input": "12 -11 20 200\n6 108\n14 188\n23 60\n28 44\n35 151\n36 82\n58 49\n65 81\n97 100\n104 26\n114 143\n136 156\n139 112\n142 119\n147 184\n148 46\n149 152\n175 178\n184 85\n187 12\n",
"output": "Anton\n"
},
{
"input": "0 0 5 100\n30 9\n53 14\n84 7\n94 18\n121 16\n",
"output": "Anton\n"
},
{
"input": "3 -1 20 200\n2 27\n12 61\n14 76\n16 20\n19 72\n20 22\n30 27\n39 61\n42 44\n45 8\n46 23\n57 13\n62 56\n64 67\n80 30\n94 34\n94 77\n100 36\n101 13\n107 9\n",
"output": "Anton\n"
},
{
"input": "-3 -14 20 200\n5 54\n10 62\n20 43\n20 79\n21 47\n32 75\n33 48\n40 61\n44 65\n52 7\n52 28\n55 65\n55 67\n59 78\n68 52\n70 20\n71 72\n76 50\n90 100\n99 9\n",
"output": "Dasha\n"
},
{
"input": "0 0 5 100\n21 38\n43 42\n59 29\n69 3\n84 52\n",
"output": "Anton\n"
},
{
"input": "12 -11 20 200\n11 189\n12 108\n19 190\n21 27\n24 193\n26 86\n26 123\n31 180\n39 196\n107 193\n122 46\n129 103\n131 129\n132 135\n142 51\n157 22\n161 27\n195 163\n198 55\n199 64\n",
"output": "Anton\n"
}
] |
code_contests
|
python
| 0 |
37dcb42661f2af9fe43afa1cab6227da
|
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a × b squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia <https://en.wikipedia.org/wiki/Japanese_crossword>).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of n squares (e.g. japanese crossword sized 1 × n), which he wants to encrypt in the same way as in japanese crossword.
<image> The example of encrypting of a single row of japanese crossword.
Help Adaltik find the numbers encrypting the row he drew.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the length of the row. The second line of the input contains a single string consisting of n characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
Output
The first line should contain a single integer k — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain k integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
Examples
Input
3
BBW
Output
1
2
Input
5
BWBWB
Output
3
1 1 1
Input
4
WWWW
Output
0
Input
4
BBBB
Output
1
4
Input
13
WBBBBWWBWBBBW
Output
3
4 1 3
Note
The last sample case correspond to the picture in the statement.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n=int(input())
s=input()
arr,k=[],0
for i in range(len(s)):
if(s[i]=='B'):
k+=1
else:
if(k>0):
arr.append(k)
k=0
if(k>0):
arr.append(k)
print(len(arr))
print(*arr,sep=' ')
|
python
|
code_algorithm
|
[
{
"input": "3\nBBW\n",
"output": "1\n2\n"
},
{
"input": "5\nBWBWB\n",
"output": "3\n1 1 1\n"
},
{
"input": "4\nWWWW\n",
"output": "0\n\n"
},
{
"input": "13\nWBBBBWWBWBBBW\n",
"output": "3\n4 1 3\n"
},
{
"input": "4\nBBBB\n",
"output": "1\n4\n"
},
{
"input": "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB\n",
"output": "12\n5 1 1 1 1 1 1 1 1 1 1 1\n"
},
{
"input": "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\n",
"output": "0\n\n"
},
{
"input": "10\nBBBBBWWBBB\n",
"output": "2\n5 3\n"
},
{
"input": "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB\n",
"output": "11\n4 1 1 1 1 2 1 1 1 1 6\n"
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n",
"output": "1\n50\n"
},
{
"input": "1\nB\n",
"output": "1\n1\n"
},
{
"input": "20\nBBBBBWWBWBBWBWWBWBBB\n",
"output": "6\n5 1 2 1 1 3\n"
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n",
"output": "1\n100\n"
},
{
"input": "65\nWWWWBWWWBBBBBWWWWWWBBBWWBBBBWWWWWWWWBBBWWWWBWBWWBBWWWWBWWWBBWBBBB\n",
"output": "11\n1 5 3 4 3 1 1 2 1 2 4\n"
},
{
"input": "20\nBBBBBBBBWBBBWBWBWBBB\n",
"output": "5\n8 3 1 1 3\n"
},
{
"input": "2\nBB\n",
"output": "1\n2\n"
},
{
"input": "3\nWWW\n",
"output": "0\n\n"
},
{
"input": "90\nWBWBBBBBBWWWBBWWBWWWBBWWBWWWBWBBWBWBBWWWWBWBWBBWBBWBWWWBBWBBWWWWBWBBWWWBBBWBBWBWBBBBWWBWWB\n",
"output": "25\n1 6 2 1 2 1 1 2 1 2 1 1 2 2 1 2 2 1 2 3 2 1 4 1 1\n"
},
{
"input": "10\nWWBWWWBWBB\n",
"output": "3\n1 1 2\n"
},
{
"input": "5\nWWBBB\n",
"output": "1\n3\n"
},
{
"input": "3\nBBB\n",
"output": "1\n3\n"
},
{
"input": "3\nWWB\n",
"output": "1\n1\n"
},
{
"input": "5\nWWWWB\n",
"output": "1\n1\n"
},
{
"input": "40\nBBBBBBWWWWBWBWWWBWWWWWWWWWWWBBBBBBBBBBBB\n",
"output": "5\n6 1 1 1 12\n"
},
{
"input": "3\nBWB\n",
"output": "2\n1 1\n"
},
{
"input": "50\nWWWWBWWBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWBWWWWWWWBBBBB\n",
"output": "6\n1 1 1 1 1 5\n"
},
{
"input": "2\nWW\n",
"output": "0\n\n"
},
{
"input": "100\nBBBBBBBBBBBWBWWWWBWWBBWBBWWWWWWWWWWBWBWWBWWWWWWWWWWWBBBWWBBWWWWWBWBWWWWBWWWWWWWWWWWBWWWWWBBBBBBBBBBB\n",
"output": "15\n11 1 1 2 2 1 1 1 3 2 1 1 1 1 11\n"
},
{
"input": "20\nBBBWBWBWWWBBWWWWBWBB\n",
"output": "6\n3 1 1 2 1 2\n"
},
{
"input": "100\nBWWWBWBWBBBBBWBWWBWBWWWBWBWBWWBBWWBBBWBBBWWBWBWWBBBBWBWBBBWBWBBWWWWWWBWWBBBBWBWBWWBWBWWWBWBWWBWBWWWB\n",
"output": "31\n1 1 1 5 1 1 1 1 1 1 2 3 3 1 1 4 1 3 1 2 1 4 1 1 1 1 1 1 1 1 1\n"
},
{
"input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB\n",
"output": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
},
{
"input": "3\nWBW\n",
"output": "1\n1\n"
},
{
"input": "2\nBW\n",
"output": "1\n1\n"
},
{
"input": "5\nBWWWW\n",
"output": "1\n1\n"
},
{
"input": "50\nBBBBBBBBBBBBBBBBBWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n",
"output": "2\n17 31\n"
},
{
"input": "40\nBBBBBWBWWWBBWWWBWBWWBBBBWWWWBWBWBBBBBBBB\n",
"output": "9\n5 1 2 1 1 4 1 1 8\n"
},
{
"input": "5\nBBBWB\n",
"output": "2\n3 1\n"
},
{
"input": "3\nBWW\n",
"output": "1\n1\n"
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n",
"output": "2\n24 42\n"
},
{
"input": "2\nWB\n",
"output": "1\n1\n"
},
{
"input": "100\nBBBWWWWWWBBWWBBWWWBBWBBBBBBBBBBBWBBBWBBWWWBBWWBBBWBWWBBBWWBBBWBBBBBWWWBWWBBWWWWWWBWBBWWBWWWBWBWWWWWB\n",
"output": "21\n3 2 2 2 11 3 2 2 3 1 3 3 5 1 2 1 2 1 1 1 1\n"
},
{
"input": "5\nBBBWW\n",
"output": "1\n3\n"
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBWBWBWWWWWBWWWWWWWWWWWWWWBBWWWBWWWWBWWBWWWWWWBWWWWWWWWWWWWWBWBBBBBBBBBBBBBBBBBBBB\n",
"output": "11\n20 1 1 1 2 1 1 1 1 1 20\n"
},
{
"input": "10\nBBBBWBBWBB\n",
"output": "3\n4 2 2\n"
},
{
"input": "20\nBBBWWWWBBWWWBWBWWBBB\n",
"output": "5\n3 2 1 1 3\n"
},
{
"input": "90\nWWBWWBWBBWBBWWBWBWBBBWBWBBBWBWBWBWBWBWBWBWBBBBBWBBWWWWBWBBWBWWBBBWBWBWWBWBWBWBWWWWWWBWBBBB\n",
"output": "30\n1 1 2 2 1 1 3 1 3 1 1 1 1 1 1 1 5 2 1 2 1 3 1 1 1 1 1 1 1 4\n"
},
{
"input": "3\nWBB\n",
"output": "1\n2\n"
},
{
"input": "1\nW\n",
"output": "0\n\n"
},
{
"input": "5\nBWWWB\n",
"output": "2\n1 1\n"
},
{
"input": "50\nBBBBBWWWWWBWWWBWWWWWBWWWBWWWWWWBBWBBWWWWBWWWWWWWBW\n",
"output": "9\n5 1 1 1 1 2 2 1 1\n"
},
{
"input": "80\nBBWWBBBWBBWWWWBBWBWBBWWWWWBWBBWWBWBWBWBWBWWBWWBWWWBWBBWBBWBBWBBBWWBBBBBBBWBBBWBB\n",
"output": "23\n2 3 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 3 7 3 2\n"
},
{
"input": "50\nBBBBBBBBBBBWWWWBWBWWWWBBBBBBBBWWWWWWWBWWWWBWBBBBBB\n",
"output": "7\n11 1 1 8 1 1 6\n"
}
] |
code_contests
|
python
| 0.8 |
b164d4a5ee69017921f421506b29d29c
|
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a1, a2, ..., ak such that ai and ai + 1 are friends for each 1 ≤ i < k, and a1 = x and ak = y.
<image>
Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it.
Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.
Input
The first line contains integers n, m and w (1 ≤ n ≤ 1000, <image>, 1 ≤ w ≤ 1000) — the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 1000) — the weights of the Hoses.
The third line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 106) — the beauties of the Hoses.
The next m lines contain pairs of friends, the i-th of them contains two integers xi and yi (1 ≤ xi, yi ≤ n, xi ≠ yi), meaning that Hoses xi and yi are friends. Note that friendship is bidirectional. All pairs (xi, yi) are distinct.
Output
Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.
Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
Note
In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.
In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
from sys import stdin, stdout
from collections import defaultdict as dd
read, write = stdin.readline, stdout.write
class DisjointSetUnion:
def __init__(self, n):
self.parent = list(range(n))
self.size = [1] * n
self.num_sets = n
def find(self, a):
acopy = a
while a != self.parent[a]:
a = self.parent[a]
while acopy != a:
self.parent[acopy], acopy = a, self.parent[acopy]
return a
def union(self, a, b):
a, b = self.find(a), self.find(b)
if a != b:
if self.size[a] < self.size[b]:
a, b = b, a
self.num_sets -= 1
self.parent[b] = a
self.size[a] += self.size[b]
def set_size(self, a):
return self.size[self.find(a)]
def __len__(self):
return self.num_sets
n, m, w = map(int, read().split())
weights = list(map(int, read().split()))
beauties = list(map(int, read().split()))
DSU = DisjointSetUnion(n)
for _ in range(m):
h1, h2 = map(int, read().split())
DSU.union(h1-1, h2-1)
groups = dd(list)
for i in range(n): DSU.find(i)
for hose, parent in enumerate(DSU.parent): groups[parent].append(hose)
dp = [0]*(w+1)
for friends in groups.values():
dp_aux = dp[:]
group_weight = group_beauty = 0
for friend in friends:
f_weight, f_beauty = weights[friend], beauties[friend]
group_weight += f_weight; group_beauty += f_beauty
for weight in range(f_weight, w+1):
dp[weight] = max(dp[weight], dp_aux[weight - f_weight] + f_beauty)
for weight in range(group_weight, w+1):
dp[weight] = max(dp[weight], dp_aux[weight - group_weight] + group_beauty)
print(dp[-1])
|
python
|
code_algorithm
|
[
{
"input": "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3\n",
"output": "7\n"
},
{
"input": "3 1 5\n3 2 5\n2 4 2\n1 2\n",
"output": "6\n"
},
{
"input": "10 5 100\n64 90 3 94 96 97 52 54 82 31\n796554 444893 214351 43810 684158 555762 686198 339093 383018 699152\n6 8\n8 3\n3 9\n2 3\n10 3\n",
"output": "1495706\n"
},
{
"input": "10 5 100\n48 73 30 46 95 19 98 73 94 24\n501216 675859 843572 565104 879875 828759 80776 766980 213551 492652\n1 2\n6 5\n7 6\n10 3\n8 1\n",
"output": "2237435\n"
},
{
"input": "10 5 100\n6 18 35 6 87 58 4 53 37 71\n465782 57034 547741 748298 315223 370368 679320 349012 9740 622511\n1 2\n10 9\n6 7\n3 6\n7 1\n",
"output": "2050129\n"
},
{
"input": "10 5 100\n78 89 3 2 95 96 87 11 13 60\n694709 921 799687 428614 221900 536251 117674 36488 219932 771513\n4 5\n3 4\n6 2\n2 3\n8 3\n",
"output": "1791132\n"
},
{
"input": "10 5 100\n19 8 95 18 9 79 42 94 20 49\n735491 935681 717266 935275 521356 866021 356037 394445 589369 585077\n9 4\n5 6\n5 1\n1 4\n7 1\n",
"output": "2456033\n"
},
{
"input": "10 5 100\n68 55 15 94 53 100 52 68 24 3\n286803 660813 226501 624597 215418 290774 416040 961916 910482 50278\n1 5\n7 2\n2 8\n5 3\n10 3\n",
"output": "1922676\n"
},
{
"input": "10 5 100\n70 67 8 64 28 82 18 61 82 7\n596434 595982 237932 275698 361351 850374 936914 877996 789231 331012\n1 7\n2 4\n3 6\n5 7\n1 5\n",
"output": "2383854\n"
}
] |
code_contests
|
python
| 0.3 |
a4624425f0badb70048e4a8f6bc748fc
|
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
Input
The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
Output
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
Examples
Input
abcd
defgh
Output
5
Input
a
a
Output
-1
Note
In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
def uncommon(a, b):
if (a == b):
return -1
return max(len(a), len(b))
A = input()
B = input()
print(uncommon(A, B))
|
python
|
code_algorithm
|
[
{
"input": "abcd\ndefgh\n",
"output": "5\n"
},
{
"input": "a\na\n",
"output": "-1\n"
},
{
"input": "abb\nabb\n",
"output": "-1\n"
},
{
"input": "abcde\nbbcde\n",
"output": "5\n"
},
{
"input": "abc\ncba\n",
"output": "3\n"
},
{
"input": "aaa\naaa\n",
"output": "-1\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbb\n",
"output": "99\n"
},
{
"input": "mmmmm\nmnmmm\n",
"output": "5\n"
},
{
"input": "mo\nmomo\n",
"output": "4\n"
},
{
"input": "abcdefgh\nabdcefgh\n",
"output": "8\n"
},
{
"input": "ab\nab\n",
"output": "-1\n"
},
{
"input": "aaa\naa\n",
"output": "3\n"
},
{
"input": "aaaaaa\naaaaa\n",
"output": "6\n"
},
{
"input": "ab\nba\n",
"output": "2\n"
},
{
"input": "aaaaaa\naaaaaa\n",
"output": "-1\n"
},
{
"input": "aabb\nbbaa\n",
"output": "4\n"
},
{
"input": "acb\nabc\n",
"output": "3\n"
},
{
"input": "abcd\nabcd\n",
"output": "-1\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddddddddd\n",
"output": "100\n"
},
{
"input": "baa\nzaa\n",
"output": "3\n"
},
{
"input": "aa\naab\n",
"output": "3\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaa\n",
"output": "34\n"
},
{
"input": "abacaba\nabacaba\n",
"output": "-1\n"
},
{
"input": "abcde\nfghij\n",
"output": "5\n"
},
{
"input": "a\naa\n",
"output": "2\n"
},
{
"input": "ahc\nahc\n",
"output": "-1\n"
},
{
"input": "a\nab\n",
"output": "2\n"
},
{
"input": "abcde\neabcd\n",
"output": "5\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n",
"output": "199\n"
},
{
"input": "abababab\nab\n",
"output": "8\n"
},
{
"input": "ab\nabcd\n",
"output": "4\n"
},
{
"input": "abc\ncab\n",
"output": "3\n"
},
{
"input": "abcccc\naccccc\n",
"output": "6\n"
},
{
"input": "len\nlena\n",
"output": "4\n"
},
{
"input": "abc\nabcd\n",
"output": "4\n"
},
{
"input": "abc\nabc\n",
"output": "-1\n"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\nzabcdefghijklmnopqrstuvwxy\n",
"output": "26\n"
},
{
"input": "abc\nbac\n",
"output": "3\n"
},
{
"input": "aaabbc\naaaccc\n",
"output": "6\n"
},
{
"input": "aa\naaa\n",
"output": "3\n"
},
{
"input": "abaa\nabaa\n",
"output": "-1\n"
},
{
"input": "ababab\nab\n",
"output": "6\n"
},
{
"input": "abcde\nabcdf\n",
"output": "5\n"
},
{
"input": "bcd\nabcd\n",
"output": "4\n"
},
{
"input": "aba\naab\n",
"output": "3\n"
},
{
"input": "aba\naba\n",
"output": "-1\n"
},
{
"input": "abc\nacb\n",
"output": "3\n"
},
{
"input": "abc\nab\n",
"output": "3\n"
},
{
"input": "koooooooooooooooo\nloooooooooooooooo\n",
"output": "17\n"
},
{
"input": "ab\nc\n",
"output": "2\n"
},
{
"input": "abcdefgh\nabcdefgh\n",
"output": "-1\n"
},
{
"input": "b\nab\n",
"output": "2\n"
},
{
"input": "aaa\naaaa\n",
"output": "4\n"
},
{
"input": "ab\nb\n",
"output": "2\n"
},
{
"input": "aaaaa\naa\n",
"output": "5\n"
},
{
"input": "abcd\nabc\n",
"output": "4\n"
},
{
"input": "asdf\nadfs\n",
"output": "4\n"
},
{
"input": "abcd\nzycd\n",
"output": "4\n"
}
] |
code_contests
|
python
| 0.6 |
c5922938aaef716cedf3ef954399bc43
|
There is an automatic door at the entrance of a factory. The door works in the following way:
* when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside,
* when one or several people come to the door and it is open, all people immediately come inside,
* opened door immediately closes in d seconds after its opening,
* if the door is closing and one or several people are coming to the door at the same moment, then all of them will have enough time to enter and only after that the door will close.
For example, if d = 3 and four people are coming at four different moments of time t1 = 4, t2 = 7, t3 = 9 and t4 = 13 then the door will open three times: at moments 4, 9 and 13. It will close at moments 7 and 12.
It is known that n employees will enter at moments a, 2·a, 3·a, ..., n·a (the value a is positive integer). Also m clients will enter at moments t1, t2, ..., tm.
Write program to find the number of times the automatic door will open. Assume that the door is initially closed.
Input
The first line contains four integers n, m, a and d (1 ≤ n, a ≤ 109, 1 ≤ m ≤ 105, 1 ≤ d ≤ 1018) — the number of the employees, the number of the clients, the moment of time when the first employee will come and the period of time in which the door closes.
The second line contains integer sequence t1, t2, ..., tm (1 ≤ ti ≤ 1018) — moments of time when clients will come. The values ti are given in non-decreasing order.
Output
Print the number of times the door will open.
Examples
Input
1 1 3 4
7
Output
1
Input
4 3 4 2
7 9 11
Output
4
Note
In the first example the only employee will come at moment 3. At this moment the door will open and will stay open until the moment 7. At the same moment of time the client will come, so at first he will enter and only after it the door will close. Thus the door will open one time.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
BigNum = 10 ** 20
n, m, a, d = map(int, input().split(' '))
ts = [0] + list(map(int, input().split(' '))) + [BigNum]
def empsInRange(l, r):
em1 = l // a + 1
em2 = r // a
return (em1, min(em2, n))
empDoorGroup = d // a + 1
def moveEmps(emps, last):
em1, em2 = emps
if em1 > em2:
return last, 0
if em1 * a <= last + d:
gr1 = (last + d - em1 * a) // a
em1 += 1 + gr1
if em1 > em2:
return last, 0
doorGroups = (em2 - em1 + 1 + empDoorGroup - 1) // empDoorGroup
last = (em1 + empDoorGroup * (doorGroups - 1)) * a
return last, doorGroups
res = 0
last = -BigNum
for i in range(1, len(ts)):
#print(i, ' ------------ ')
emps = empsInRange(ts[i - 1], ts[i])
#print(ts[i-1], ts[i], emps, last)
last, inc = moveEmps(emps, last)
#print('last:', last, ' inc:', inc)
res += inc
if ts[i] < BigNum and last + d < ts[i]:
res += 1
last = ts[i]
#print('temp res:', res)
print(res)
|
python
|
code_algorithm
|
[
{
"input": "1 1 3 4\n7\n",
"output": "1\n"
},
{
"input": "4 3 4 2\n7 9 11\n",
"output": "4\n"
},
{
"input": "100 30 36 47\n44 155 275 390 464 532 1186 1205 1345 1349 1432 1469 1482 1775 1832 1856 1869 2049 2079 2095 2374 2427 2577 2655 2792 2976 3020 3317 3482 3582\n",
"output": "51\n"
},
{
"input": "100 20 49 52\n224 380 690 1585 1830 1973 2490 2592 3240 3341 3406 3429 3549 3560 3895 3944 4344 4390 4649 4800\n",
"output": "55\n"
},
{
"input": "70 10 26 17\n361 371 579 585 629 872 944 1017 1048 1541\n",
"output": "70\n"
},
{
"input": "1000000000 1 1000000000 1000000000000000000\n1000000000000000000\n",
"output": "1\n"
},
{
"input": "10 10 51 69\n154 170 170 183 251 337 412 426 445 452\n",
"output": "6\n"
},
{
"input": "97 60 1 1\n5 6 6 7 9 10 10 11 11 11 12 13 13 13 13 14 14 15 16 18 20 23 23 24 25 26 29 31 32 35 38 41 43 43 46 47 48 48 49 52 53 54 55 56 58 59 68 70 72 74 78 81 81 82 91 92 96 96 97 98\n",
"output": "49\n"
},
{
"input": "1000000000 1 157 468\n57575875712\n",
"output": "333333334\n"
}
] |
code_contests
|
python
| 0 |
e55239f7813ed3a8467026ccb90375bc
|
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!
He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!
The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two paths have at least one common vertex. Each edge of the tree should be in exactly one path.
Help Remesses, find such a decomposition of the tree or derermine that there is no such decomposition.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^{5}) the number of nodes in the tree.
Each of the next n - 1 lines contains two integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) — the edges of the tree. It is guaranteed that the given edges form a tree.
Output
If there are no decompositions, print the only line containing "No".
Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition m.
Each of the next m lines should contain two integers u_i, v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i) denoting that one of the paths in the decomposition is the simple path between nodes u_i and v_i.
Each pair of paths in the decomposition should have at least one common vertex, and each edge of the tree should be presented in exactly one path. You can print the paths and the ends of each path in arbitrary order.
If there are multiple decompositions, print any.
Examples
Input
4
1 2
2 3
3 4
Output
Yes
1
1 4
Input
6
1 2
2 3
3 4
2 5
3 6
Output
No
Input
5
1 2
1 3
1 4
1 5
Output
Yes
4
1 2
1 3
1 4
1 5
Note
The tree from the first example is shown on the picture below: <image> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.
The tree from the second example is shown on the picture below: <image> We can show that there are no valid decompositions of this tree.
The tree from the third example is shown on the picture below: <image> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n = int(input())
flag = True
f = [0] * (n - 1)
t = [0] * (n - 1)
co = [0] * n
for i in range(n - 1):
f[i], t[i] = map(int, input().split())
co[f[i] - 1] += 1
co[t[i] - 1] += 1
mid = 0
en = []
for i in range(n):
if co[i] == 1:
en.append(i + 1)
elif co[i] > 2:
if mid == 0:
mid = i + 1
else:
print("No")
flag = False
break
if flag:
print("Yes")
if mid != 0:
print(len(en))
for i in range(len(en)):
if (en[i] != mid):
print(mid, en[i])
else:
print(1)
print(en[0], en[1])
|
python
|
code_algorithm
|
[
{
"input": "6\n1 2\n2 3\n3 4\n2 5\n3 6\n",
"output": "No\n"
},
{
"input": "4\n1 2\n2 3\n3 4\n",
"output": "Yes\n1\n1 4\n"
},
{
"input": "5\n1 2\n1 3\n1 4\n1 5\n",
"output": "Yes\n4\n1 2\n1 3\n1 4\n1 5\n"
},
{
"input": "9\n1 2\n1 3\n1 4\n1 5\n1 6\n6 7\n7 8\n7 9\n",
"output": "No\n"
},
{
"input": "8\n1 2\n1 3\n1 4\n1 8\n7 8\n6 8\n5 8\n",
"output": "No\n"
},
{
"input": "3\n2 3\n1 2\n",
"output": "Yes\n1\n1 3\n"
},
{
"input": "2\n1 2\n",
"output": "Yes\n1\n1 2\n"
}
] |
code_contests
|
python
| 0 |
39ce352f98a9fdeba2a28318cd353df9
|
As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon.
Elections are coming. You know the number of voters and the number of parties — n and m respectively. For each voter you know the party he is going to vote for. However, he can easily change his vote given a certain amount of money. In particular, if you give i-th voter c_i bytecoins you can ask him to vote for any other party you choose.
The United Party of Berland has decided to perform a statistical study — you need to calculate the minimum number of bytecoins the Party needs to spend to ensure its victory. In order for a party to win the elections, it needs to receive strictly more votes than any other party.
Input
The first line of input contains two integers n and m (1 ≤ n, m ≤ 3000) — the number of voters and the number of parties respectively.
Each of the following n lines contains two integers p_i and c_i (1 ≤ p_i ≤ m, 1 ≤ c_i ≤ 10^9) — the index of this voter's preferred party and the number of bytecoins needed for him to reconsider his decision.
The United Party of Berland has the index 1.
Output
Print a single number — the minimum number of bytecoins needed for The United Party of Berland to win the elections.
Examples
Input
1 2
1 100
Output
0
Input
5 5
2 100
3 200
4 300
5 400
5 900
Output
500
Input
5 5
2 100
3 200
4 300
5 800
5 900
Output
600
Note
In the first sample, The United Party wins the elections even without buying extra votes.
In the second sample, The United Party can buy the votes of the first and the fourth voter. This way The Party gets two votes, while parties 3, 4 and 5 get one vote and party number 2 gets no votes.
In the third sample, The United Party can buy the votes of the first three voters and win, getting three votes against two votes of the fifth party.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import sys
f=sys.stdin
out=sys.stdout
n,m=map(int,f.readline().rstrip('\r\n').split())
cos={}
cost=[]
nvot=[0 for i in range(m+1)]
party=[[] for i in range(m+1)]
for i in range(n):
p,c=map(int,f.readline().rstrip('\r\n').split())
if p!=1:
if c in cos:
cos[c]+=1
else:
cos[c]=1
cost.append(c)
party[p].append(c)
nvot[p]+=1
cost.sort()
for i in party:
i.sort()
mi=float('inf')
for x in range(1,n+1):
dcos=dict(cos)
tmp=0
vot=nvot[1]
for j in range(2,m+1):
if nvot[j]>=x:
for k in range(nvot[j]-x+1):
vot+=1
tmp+=party[j][k]
dcos[party[j][k]]-=1
j=0
while vot<x:
if(dcos[cost[j]]>0):
dcos[cost[j]]-=1
tmp+=cost[j]
vot+=1
j+=1
#print(tmp)
mi=min(mi,tmp)
out.write(str(mi)+"\n")
|
python
|
code_algorithm
|
[
{
"input": "1 2\n1 100\n",
"output": "0\n"
},
{
"input": "5 5\n2 100\n3 200\n4 300\n5 800\n5 900\n",
"output": "600\n"
},
{
"input": "5 5\n2 100\n3 200\n4 300\n5 400\n5 900\n",
"output": "500\n"
},
{
"input": "1 3000\n2006 226621946\n",
"output": "226621946\n"
},
{
"input": "10 2\n1 1\n1 1\n1 1\n1 1\n1 1\n2 1\n2 1\n2 1\n2 1\n2 1\n",
"output": "1\n"
},
{
"input": "10 10\n1 73\n2 8\n3 88\n1 5\n2 100\n1 29\n1 57\n3 37\n7 46\n3 21\n",
"output": "0\n"
},
{
"input": "5 5\n1 3\n1 6\n5 4\n3 7\n2 10\n",
"output": "0\n"
},
{
"input": "1 3000\n918 548706881\n",
"output": "548706881\n"
},
{
"input": "10 10\n7 29\n10 31\n9 40\n5 17\n5 30\n6 85\n2 53\n7 23\n4 57\n10 9\n",
"output": "49\n"
},
{
"input": "5 5\n1 7\n3 3\n2 7\n2 4\n1 2\n",
"output": "3\n"
},
{
"input": "10 10\n5 81\n7 68\n7 48\n1 10\n5 37\n7 97\n8 54\n7 41\n7 56\n5 21\n",
"output": "110\n"
},
{
"input": "5 5\n2 5\n2 4\n2 1\n3 6\n3 7\n",
"output": "10\n"
}
] |
code_contests
|
python
| 0 |
5dba697fcb6f735cb0d534feef84e067
|
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list.
For example, if x=4 and y=6 then the given list can be any permutation of the list [1, 2, 4, 1, 2, 3, 6]. Some of the possible lists are: [1, 1, 2, 4, 6, 3, 2], [4, 6, 1, 1, 2, 3, 2] or [1, 6, 3, 2, 4, 1, 2].
Your problem is to restore suitable positive integer numbers x and y that would yield the same list of divisors (possibly in different order).
It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers x and y.
Input
The first line contains one integer n (2 ≤ n ≤ 128) — the number of divisors of x and y.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 ≤ d_i ≤ 10^4), where d_i is either divisor of x or divisor of y. If a number is divisor of both numbers x and y then there are two copies of this number in the list.
Output
Print two positive integer numbers x and y — such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.
Example
Input
10
10 2 8 1 2 4 1 20 4 5
Output
20 8
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
t=int(input())
lis=list(map(int,input().split()))
maxnum=max(lis)
lis.remove(maxnum)
for x in range (1,maxnum//2+1):
if maxnum%x==0:
lis.remove(x)
maxnum2=max(lis)
print("{} {}".format(maxnum,maxnum2))
|
python
|
code_algorithm
|
[
{
"input": "10\n10 2 8 1 2 4 1 20 4 5\n",
"output": "20 8\n"
},
{
"input": "4\n1 2 53 1\n",
"output": "53 2\n"
},
{
"input": "6\n1 58 29 1 2 2\n",
"output": "58 2\n"
},
{
"input": "6\n29 29 1 1 58 2\n",
"output": "58 29\n"
},
{
"input": "9\n7 49 1 1 98 14 49 7 2\n",
"output": "98 49\n"
},
{
"input": "3\n1 2 1\n",
"output": "2 1\n"
},
{
"input": "3\n5 1 1\n",
"output": "5 1\n"
},
{
"input": "6\n1 2 4 8 1 16\n",
"output": "16 1\n"
},
{
"input": "18\n10 1 4 5 20 10 40 16 20 8 2 5 8 40 2 80 1 4\n",
"output": "80 40\n"
},
{
"input": "5\n7 49 2 1 1\n",
"output": "49 2\n"
},
{
"input": "6\n6 1 3 3 2 1\n",
"output": "6 3\n"
},
{
"input": "8\n9 9 1 81 3 27 1 3\n",
"output": "81 9\n"
},
{
"input": "6\n1 2 5 95 1 19\n",
"output": "95 2\n"
},
{
"input": "14\n12 18 4 2 2 72 6 36 24 8 3 1 9 1\n",
"output": "72 2\n"
},
{
"input": "6\n7 1 11 7 77 1\n",
"output": "77 7\n"
},
{
"input": "10\n3 1 5 30 10 2 15 6 3 1\n",
"output": "30 3\n"
},
{
"input": "18\n72 24 2 3 6 8 3 6 18 9 9 36 1 2 1 12 18 4\n",
"output": "72 18\n"
},
{
"input": "66\n35 90 36 7560 189 14 360 180 168 12 1 252 21 8 630 15 40 1512 18 9973 108 7 540 3 210 270 2520 504 1890 6 378 70 1080 30 20 84 1260 420 105 9 135 28 60 72 315 24 63 126 27 280 45 5 120 1 42 945 216 4 756 140 840 56 10 2 54 3780\n",
"output": "9973 7560\n"
},
{
"input": "4\n1 61 31 1\n",
"output": "61 31\n"
},
{
"input": "15\n5 3 3 6 15 18 45 9 9 10 1 90 2 1 30\n",
"output": "90 9\n"
},
{
"input": "5\n1 3 3 9 1\n",
"output": "9 3\n"
},
{
"input": "4\n1 3 9 1\n",
"output": "9 1\n"
},
{
"input": "18\n2 6 8 6 2 4 1 3 1 36 72 3 12 24 12 4 18 9\n",
"output": "72 12\n"
},
{
"input": "12\n66 6 3 33 22 3 1 1 2 11 11 33\n",
"output": "66 33\n"
},
{
"input": "14\n4 56 14 4 2 7 28 8 14 7 1 1 2 28\n",
"output": "56 28\n"
},
{
"input": "7\n9 3 1 31 93 3 1\n",
"output": "93 9\n"
},
{
"input": "13\n2 1 8 10 2 4 16 5 40 1 4 20 80\n",
"output": "80 4\n"
},
{
"input": "69\n1 7560 2 3780 3 2520 4 1890 5 1512 6 1260 7 1080 8 945 9 840 10 756 12 630 14 540 15 504 18 420 20 378 21 360 24 315 27 280 28 270 30 252 35 216 36 210 40 189 42 180 45 168 54 140 56 135 60 126 63 120 70 108 72 105 84 90 1 2 4 8 16\n",
"output": "7560 16\n"
},
{
"input": "14\n24 9 18 8 6 12 72 1 3 4 1 5 2 36\n",
"output": "72 5\n"
},
{
"input": "7\n3 27 1 81 3 1 9\n",
"output": "81 3\n"
},
{
"input": "10\n1 3 5 15 1 3 5 9 15 45\n",
"output": "45 15\n"
},
{
"input": "10\n6 10 1 3 15 5 2 61 30 1\n",
"output": "61 30\n"
},
{
"input": "9\n9 27 81 3 27 1 9 3 1\n",
"output": "81 27\n"
},
{
"input": "4\n4 1 2 1\n",
"output": "4 1\n"
},
{
"input": "10\n4 32 16 4 1 2 8 64 2 1\n",
"output": "64 4\n"
},
{
"input": "11\n54 18 1 3 27 9 6 1 9 3 2\n",
"output": "54 9\n"
},
{
"input": "18\n1 4 12 6 72 8 3 36 1 18 9 18 24 2 3 2 9 6\n",
"output": "72 18\n"
},
{
"input": "8\n1 2 4 1 2 4 8 16\n",
"output": "16 4\n"
},
{
"input": "5\n1 2 4 1 2\n",
"output": "4 2\n"
},
{
"input": "12\n5 2 10 8 20 4 2 4 1 40 1 8\n",
"output": "40 8\n"
},
{
"input": "12\n8 6 1 3 1 4 12 24 2 16 48 3\n",
"output": "48 3\n"
},
{
"input": "10\n1 1 2 2 3 3 4 6 6 12\n",
"output": "12 6\n"
},
{
"input": "9\n20 10 5 4 2 1 4 2 1\n",
"output": "20 4\n"
},
{
"input": "9\n1 2 4 1 2 4 5 10 20\n",
"output": "20 4\n"
},
{
"input": "11\n36 2 3 1 18 6 2 4 1 9 12\n",
"output": "36 2\n"
},
{
"input": "5\n1 2 1 2 4\n",
"output": "4 2\n"
},
{
"input": "21\n72 9 3 6 3 1 18 36 2 24 36 2 12 4 9 12 8 18 6 4 1\n",
"output": "72 36\n"
},
{
"input": "64\n945 130 78 135 91 630 14 2730 27 1 35 2 5 210 9 65 195 1365 7 3 390 70 455 10 15 378 3 315 39 105 273 10 21 2 45 15 546 35 42 90 18 182 26 910 63 189 30 210 6 70 105 30 54 270 1890 6 13 5 21 7 1 42 14 126\n",
"output": "2730 1890\n"
},
{
"input": "12\n3 15 1 10 2 15 1 3 30 5 5 6\n",
"output": "30 15\n"
},
{
"input": "5\n1 5 5 25 1\n",
"output": "25 5\n"
},
{
"input": "12\n2 32 64 4 16 16 8 8 2 1 1 4\n",
"output": "64 16\n"
},
{
"input": "12\n2 5 50 25 25 5 10 20 100 1 4 1\n",
"output": "100 25\n"
},
{
"input": "10\n4 1 1 6 3 24 8 3 2 12\n",
"output": "24 3\n"
},
{
"input": "7\n1 1 2 2 4 4 8\n",
"output": "8 4\n"
},
{
"input": "10\n1 7 42 7 1 2 21 3 14 6\n",
"output": "42 7\n"
},
{
"input": "10\n95 1 19 6 18 1 9 5 3 2\n",
"output": "95 18\n"
},
{
"input": "6\n1 1 29 3 87 29\n",
"output": "87 29\n"
},
{
"input": "6\n1 1 2 5 5 10\n",
"output": "10 5\n"
},
{
"input": "6\n47 47 2 94 1 1\n",
"output": "94 47\n"
},
{
"input": "16\n4 36 3 4 2 1 72 9 8 2 6 8 12 24 18 1\n",
"output": "72 8\n"
},
{
"input": "65\n108 90 27 72 2520 30 3780 35 20 21 315 42 63 120 1 945 135 1512 28 40 210 756 9 24 180 1890 1 2 189 378 5 1080 280 168 126 840 45 7 6 216 630 4 7560 18 8 56 140 504 60 105 54 252 3 360 1260 15 420 12 14 36 270 70 10 540 84\n",
"output": "7560 1\n"
},
{
"input": "6\n58 2 2 1 29 1\n",
"output": "58 2\n"
},
{
"input": "8\n3 12 6 4 3 1 1 2\n",
"output": "12 3\n"
},
{
"input": "9\n81 4 1 9 3 1 27 8 2\n",
"output": "81 8\n"
},
{
"input": "9\n64 32 16 1 2 1 8 3 4\n",
"output": "64 3\n"
},
{
"input": "10\n9 1 11 33 1 11 99 3 33 3\n",
"output": "99 33\n"
},
{
"input": "15\n96 48 16 4 2 24 12 6 1 8 2 1 4 32 3\n",
"output": "96 4\n"
},
{
"input": "18\n4 2 30 5 3 1 12 6 4 60 12 15 1 3 6 10 2 20\n",
"output": "60 12\n"
},
{
"input": "10\n1 7 11 77 121 847 1 7 11 77\n",
"output": "847 77\n"
},
{
"input": "7\n1 2 4 8 16 1 2\n",
"output": "16 2\n"
},
{
"input": "12\n3 7 1 1 21 14 21 6 3 42 2 7\n",
"output": "42 21\n"
},
{
"input": "7\n1 27 81 1 9 3 7\n",
"output": "81 7\n"
},
{
"input": "8\n15 5 3 75 1 5 1 25\n",
"output": "75 5\n"
},
{
"input": "10\n2 1 5 6 15 2 30 10 3 1\n",
"output": "30 2\n"
},
{
"input": "4\n9973 9973 1 1\n",
"output": "9973 9973\n"
},
{
"input": "6\n85 17 5 17 1 1\n",
"output": "85 17\n"
},
{
"input": "12\n2 1 3 12 4 8 24 4 1 8 6 2\n",
"output": "24 8\n"
},
{
"input": "11\n36 3 1 1 4 9 12 2 3 18 6\n",
"output": "36 3\n"
},
{
"input": "7\n1 2 4 1 2 4 8\n",
"output": "8 4\n"
},
{
"input": "6\n1 2 3 6 1 3\n",
"output": "6 3\n"
},
{
"input": "6\n1 1 2 3 3 6\n",
"output": "6 3\n"
},
{
"input": "10\n3 11 1 11 1 33 33 3 9 99\n",
"output": "99 33\n"
},
{
"input": "3\n1 1 2\n",
"output": "2 1\n"
},
{
"input": "5\n1 1 67 2 4\n",
"output": "67 4\n"
},
{
"input": "13\n4 16 8 4 2 1 8 64 1 2 32 16 32\n",
"output": "64 32\n"
},
{
"input": "20\n12 8 6 96 4 3 16 8 32 12 6 4 48 1 24 3 24 1 2 2\n",
"output": "96 24\n"
},
{
"input": "14\n48 16 4 6 1 8 3 4 12 1 2 2 8 24\n",
"output": "48 8\n"
},
{
"input": "10\n1 2 4 5 10 20 1 2 5 10\n",
"output": "20 10\n"
},
{
"input": "6\n6 3 1 3 2 1\n",
"output": "6 3\n"
},
{
"input": "5\n5 3 1 25 1\n",
"output": "25 3\n"
},
{
"input": "10\n21 3 63 9 5 1 15 7 1 3\n",
"output": "63 15\n"
},
{
"input": "14\n2 2 3 7 1 42 14 28 84 4 21 6 12 1\n",
"output": "84 2\n"
},
{
"input": "5\n1 1 2 2 4\n",
"output": "4 2\n"
},
{
"input": "5\n1 3 9 3 1\n",
"output": "9 3\n"
},
{
"input": "10\n11 11 1 44 2 22 4 22 1 2\n",
"output": "44 22\n"
},
{
"input": "8\n87 7 14 1 2 29 1 3\n",
"output": "87 14\n"
},
{
"input": "9\n27 6 81 3 3 1 1 2 9\n",
"output": "81 6\n"
},
{
"input": "14\n2 1 3 1 16 2 12 8 24 6 3 6 48 4\n",
"output": "48 6\n"
},
{
"input": "14\n1 6 9 90 10 5 5 2 30 1 18 15 3 45\n",
"output": "90 5\n"
},
{
"input": "4\n9 1 1 3\n",
"output": "9 1\n"
},
{
"input": "9\n8 5 16 1 32 1 4 2 64\n",
"output": "64 5\n"
},
{
"input": "3\n1 3 1\n",
"output": "3 1\n"
},
{
"input": "13\n100 50 25 20 10 5 4 2 1 10 5 2 1\n",
"output": "100 10\n"
},
{
"input": "6\n1 7 1 14 7 2\n",
"output": "14 7\n"
},
{
"input": "8\n1 2 17 17 34 68 1 4\n",
"output": "68 17\n"
},
{
"input": "6\n1 2 31 31 1 62\n",
"output": "62 31\n"
},
{
"input": "6\n13 5 1 1 13 65\n",
"output": "65 13\n"
},
{
"input": "12\n3 1 2 6 5 1 10 2 10 5 30 15\n",
"output": "30 10\n"
},
{
"input": "8\n5 33 9 99 3 11 1 1\n",
"output": "99 5\n"
},
{
"input": "18\n1 2 4 5 10 20 1 2 4 5 10 20 30 60 15 3 6 12\n",
"output": "60 20\n"
},
{
"input": "6\n29 58 2 29 1 1\n",
"output": "58 29\n"
},
{
"input": "5\n25 5 5 1 1\n",
"output": "25 5\n"
},
{
"input": "6\n65 1 5 5 1 13\n",
"output": "65 5\n"
},
{
"input": "12\n10 1 5 100 25 20 4 2 50 1 5 25\n",
"output": "100 25\n"
},
{
"input": "5\n1 3 1 3 9\n",
"output": "9 3\n"
},
{
"input": "11\n6 24 8 1 2 4 1 12 3 4 2\n",
"output": "24 4\n"
},
{
"input": "18\n6 1 36 3 1 9 9 72 4 18 12 6 2 3 18 8 2 24\n",
"output": "72 18\n"
},
{
"input": "128\n540 90 378 3780 270 35 180 15 6 14 20 3780 2520 140 1080 54 540 120 1890 15 420 840 20 756 10 126 42 54 36 14 216 8 168 210 60 7 63 2 216 21 30 189 28 135 2 630 21 30 60 1512 7560 70 5 12 40 7560 252 378 3 108 5 72 10 3 28 24 1 27 9 45 180 56 1260 945 1080 420 168 2520 18 70 1 27 9 7 315 4 84 40 504 360 252 6 8 360 315 140 45 210 84 56 945 135 1260 280 756 90 108 630 36 42 72 504 1512 189 120 105 105 280 24 270 63 18 840 1890 126 35 12 4\n",
"output": "7560 7560\n"
},
{
"input": "9\n4 4 11 44 2 22 2 1 1\n",
"output": "44 4\n"
},
{
"input": "12\n5 70 5 1 35 2 1 2 7 14 10 10\n",
"output": "70 10\n"
},
{
"input": "20\n9 12 2 24 36 24 1 3 18 6 8 72 12 4 1 2 8 3 6 4\n",
"output": "72 24\n"
},
{
"input": "6\n1 2 1 2 3 6\n",
"output": "6 2\n"
},
{
"input": "10\n76 38 1 2 1 4 5 3 15 19\n",
"output": "76 15\n"
},
{
"input": "4\n1 1 29 19\n",
"output": "29 19\n"
},
{
"input": "8\n16 8 4 2 1 4 2 1\n",
"output": "16 4\n"
},
{
"input": "11\n5 2 25 100 20 50 10 1 5 1 4\n",
"output": "100 5\n"
},
{
"input": "12\n4 1 1 12 6 21 63 2 9 3 7 3\n",
"output": "63 12\n"
},
{
"input": "12\n2 3 13 3 39 13 1 6 39 26 78 1\n",
"output": "78 39\n"
},
{
"input": "11\n1 9 54 27 6 3 2 1 9 3 18\n",
"output": "54 9\n"
},
{
"input": "10\n1 2 5 10 1 2 4 5 10 20\n",
"output": "20 10\n"
},
{
"input": "12\n2 1 16 4 6 3 8 1 48 24 2 12\n",
"output": "48 2\n"
},
{
"input": "11\n2 18 4 27 54 3 2 1 6 1 9\n",
"output": "54 4\n"
},
{
"input": "6\n1 2 1 2 4 8\n",
"output": "8 2\n"
},
{
"input": "6\n55 5 11 1 1 5\n",
"output": "55 5\n"
},
{
"input": "6\n1 2 4 1 5 25\n",
"output": "25 4\n"
},
{
"input": "10\n1 2 1 2 4 5 5 10 10 20\n",
"output": "20 10\n"
},
{
"input": "18\n90 18 2 9 5 6 18 1 6 3 1 3 10 45 9 15 2 30\n",
"output": "90 18\n"
},
{
"input": "12\n3 4 1 12 48 16 1 24 2 6 8 3\n",
"output": "48 3\n"
},
{
"input": "12\n1 24 2 16 48 3 4 8 3 1 6 12\n",
"output": "48 3\n"
},
{
"input": "10\n4 3 6 2 12 1 24 3 8 1\n",
"output": "24 3\n"
},
{
"input": "18\n10 20 4 12 30 6 5 5 3 4 10 1 20 1 15 2 2 60\n",
"output": "60 20\n"
},
{
"input": "5\n1 25 1 5 5\n",
"output": "25 5\n"
},
{
"input": "14\n4 12 1 1 2 6 30 10 5 20 3 60 15 5\n",
"output": "60 5\n"
},
{
"input": "18\n1 4 16 3 12 12 3 24 1 4 6 48 8 6 2 24 2 8\n",
"output": "48 24\n"
},
{
"input": "6\n1 2 2 14 1 7\n",
"output": "14 2\n"
},
{
"input": "6\n87 29 29 3 1 1\n",
"output": "87 29\n"
},
{
"input": "11\n2 6 12 4 18 3 1 3 36 1 9\n",
"output": "36 3\n"
},
{
"input": "5\n1 1 3 9 3\n",
"output": "9 3\n"
},
{
"input": "6\n62 1 31 31 2 1\n",
"output": "62 31\n"
},
{
"input": "6\n1 11 1 11 5 55\n",
"output": "55 11\n"
},
{
"input": "15\n12 36 8 4 6 9 72 2 4 2 1 18 24 3 1\n",
"output": "72 4\n"
},
{
"input": "20\n8 96 5 2 6 12 10 1 4 6 3 48 3 32 30 15 2 16 1 24\n",
"output": "96 30\n"
},
{
"input": "10\n39 26 6 1 1 2 13 78 3 13\n",
"output": "78 13\n"
},
{
"input": "20\n1 18 10 9 2 15 5 45 3 10 1 30 15 6 5 2 30 3 6 90\n",
"output": "90 30\n"
},
{
"input": "10\n27 54 18 1 2 1 9 3 6 3\n",
"output": "54 3\n"
},
{
"input": "8\n23 46 2 4 1 1 23 92\n",
"output": "92 23\n"
},
{
"input": "6\n3 1 3 1 6 2\n",
"output": "6 3\n"
},
{
"input": "16\n30 1 3 90 9 27 3 9 45 10 6 18 1 15 2 5\n",
"output": "90 27\n"
},
{
"input": "18\n12 28 3 3 14 6 4 7 2 42 12 21 6 1 2 1 84 4\n",
"output": "84 12\n"
},
{
"input": "16\n28 2 14 4 3 12 84 6 7 21 1 2 3 42 6 1\n",
"output": "84 6\n"
},
{
"input": "10\n1 1 2 2 4 4 5 8 10 20\n",
"output": "20 8\n"
},
{
"input": "4\n5 1 1 61\n",
"output": "61 5\n"
},
{
"input": "4\n1 43 1 13\n",
"output": "43 13\n"
},
{
"input": "8\n10 4 20 2 1 1 5 2\n",
"output": "20 2\n"
},
{
"input": "14\n14 28 2 2 56 1 14 28 4 7 1 7 8 4\n",
"output": "56 28\n"
},
{
"input": "10\n1 1 2 2 4 5 5 10 10 20\n",
"output": "20 10\n"
},
{
"input": "23\n16 128 256 27 32 243 1 512 64 8192 2 1024 81 8 1 4 729 4096 3 2187 6561 9 2048\n",
"output": "8192 6561\n"
},
{
"input": "14\n1 2 4 5 8 10 20 40 1 2 4 5 10 20\n",
"output": "40 20\n"
},
{
"input": "6\n71 47 2 1 94 1\n",
"output": "94 71\n"
},
{
"input": "11\n2 1 6 12 8 2 24 3 4 1 4\n",
"output": "24 4\n"
},
{
"input": "8\n1 65 29 58 5 2 1 13\n",
"output": "65 58\n"
},
{
"input": "12\n21 2 33 6 66 7 3 3 1 1 11 22\n",
"output": "66 21\n"
},
{
"input": "5\n1 7 1 49 7\n",
"output": "49 7\n"
},
{
"input": "9\n1 18 2 6 9 1 3 3 9\n",
"output": "18 9\n"
},
{
"input": "4\n67 1 13 1\n",
"output": "67 13\n"
},
{
"input": "11\n4 10 5 20 25 2 50 1 2 100 1\n",
"output": "100 2\n"
},
{
"input": "9\n81 2 1 9 27 3 6 3 1\n",
"output": "81 6\n"
},
{
"input": "5\n25 5 1 5 1\n",
"output": "25 5\n"
},
{
"input": "10\n1 8 3 9 4 2 33 11 99 1\n",
"output": "99 8\n"
},
{
"input": "8\n10 1 1 20 2 5 5 4\n",
"output": "20 5\n"
},
{
"input": "6\n23 23 2 1 1 46\n",
"output": "46 23\n"
},
{
"input": "18\n75 3 9 8 18 2 12 36 25 3 15 72 24 4 6 1 5 1\n",
"output": "75 72\n"
},
{
"input": "6\n11 1 2 22 2 1\n",
"output": "22 2\n"
},
{
"input": "11\n18 2 1 3 12 6 1 4 2 36 9\n",
"output": "36 2\n"
},
{
"input": "8\n7 14 7 1 2 4 1 28\n",
"output": "28 7\n"
},
{
"input": "6\n1 1 17 51 3 3\n",
"output": "51 3\n"
},
{
"input": "6\n1 3 2 1 39 13\n",
"output": "39 2\n"
},
{
"input": "18\n8 8 3 16 4 2 20 2 5 4 24 6 40 1 1 10 80 12\n",
"output": "80 24\n"
},
{
"input": "5\n31 1 1 7 49\n",
"output": "49 31\n"
},
{
"input": "13\n50 25 5 100 1 4 10 1 2 20 2 4 8\n",
"output": "100 8\n"
},
{
"input": "6\n1 16 4 1 8 2\n",
"output": "16 1\n"
},
{
"input": "6\n2 1 43 86 1 2\n",
"output": "86 2\n"
},
{
"input": "28\n8192 4 128 1024 8 4 2048 8 16 64 2 512 1 2048 32 256 8192 4096 64 4096 256 16 1024 512 128 2 32 1\n",
"output": "8192 8192\n"
},
{
"input": "89\n1080 126 315 18 3780 84 180 2520 12 756 70 504 15 9 36 630 20 2 2500 360 200 1000 100 108 5000 5 14 1890 10 90 105 7560 2 80 16 28 35 840 1 189 125 6 4 1512 945 40 10 210 8 25 280 8 20 270 27 1260 72 420 120 168 30 625 500 540 140 42 252 1 54 50 56 40 21 7 1250 63 216 250 4 10000 5 400 3 60 45 24 135 2000 378\n",
"output": "10000 7560\n"
},
{
"input": "16\n2 7 84 14 6 1 7 1 3 21 12 42 28 2 4 14\n",
"output": "84 14\n"
},
{
"input": "6\n23 1 2 46 23 1\n",
"output": "46 23\n"
},
{
"input": "8\n2 2 1 5 50 25 10 1\n",
"output": "50 2\n"
},
{
"input": "6\n1 2 5 10 1 5\n",
"output": "10 5\n"
},
{
"input": "6\n1 7 1 7 5 35\n",
"output": "35 7\n"
},
{
"input": "4\n1 1 5 25\n",
"output": "25 1\n"
},
{
"input": "12\n4 8 7 14 14 2 2 7 28 56 1 1\n",
"output": "56 14\n"
},
{
"input": "6\n6 1 1 2 3 3\n",
"output": "6 3\n"
},
{
"input": "14\n8 2 16 5 2 1 10 1 4 80 20 10 5 40\n",
"output": "80 10\n"
},
{
"input": "20\n1 243 1 6561 128 81 4 8 32 16 3 2187 64 512 9 27 256 1024 2 729\n",
"output": "6561 1024\n"
},
{
"input": "12\n15 5 10 1 1 5 6 30 3 2 3 15\n",
"output": "30 15\n"
},
{
"input": "8\n1 5 1 2 4 5 10 20\n",
"output": "20 5\n"
},
{
"input": "7\n1 16 1 4 2 2 8\n",
"output": "16 2\n"
},
{
"input": "9\n9 2 6 3 18 1 1 3 9\n",
"output": "18 9\n"
},
{
"input": "8\n1234 4321 29 1 2 1 149 617\n",
"output": "4321 1234\n"
},
{
"input": "15\n24 8 4 3 2 6 1 2 32 1 48 12 96 4 16\n",
"output": "96 4\n"
},
{
"input": "6\n1 1 2 2 5 10\n",
"output": "10 2\n"
},
{
"input": "50\n1250 5000 250 1000 500 10 40 250 80 16 10000 125 200 50 80 1 4 20 1 10000 2500 100 4 20 625 10 2 200 8 1000 16 2000 400 5 5 2500 8 400 5000 2 625 125 50 25 2000 1250 100 40 500 25\n",
"output": "10000 10000\n"
},
{
"input": "10\n1 2 3 6 1 2 3 4 6 12\n",
"output": "12 6\n"
},
{
"input": "10\n3 1 15 2 30 10 1 5 23 6\n",
"output": "30 23\n"
},
{
"input": "12\n25 20 2 5 1 1 4 10 50 100 5 25\n",
"output": "100 25\n"
},
{
"input": "10\n17 17 1 34 4 68 2 2 34 1\n",
"output": "68 34\n"
},
{
"input": "11\n3 36 12 3 9 18 6 4 2 1 1\n",
"output": "36 3\n"
},
{
"input": "6\n94 2 47 1 1 3\n",
"output": "94 3\n"
},
{
"input": "5\n1 1 3 3 9\n",
"output": "9 3\n"
},
{
"input": "20\n24 16 32 2 3 96 1 2 12 48 4 6 8 12 6 8 24 3 4 1\n",
"output": "96 24\n"
},
{
"input": "6\n1 1 2 2 4 8\n",
"output": "8 2\n"
},
{
"input": "4\n5 25 1 1\n",
"output": "25 1\n"
},
{
"input": "16\n2 1 5 30 1 6 12 2 4 10 60 20 10 5 15 3\n",
"output": "60 10\n"
},
{
"input": "12\n7 5 14 2 1 14 70 35 2 1 7 10\n",
"output": "70 14\n"
},
{
"input": "13\n1 2 3 4 6 9 12 18 36 1 2 3 6\n",
"output": "36 6\n"
},
{
"input": "4\n1 1 2 7\n",
"output": "7 2\n"
},
{
"input": "8\n32 64 1 4 16 8 1 2\n",
"output": "64 1\n"
},
{
"input": "10\n32 1 1 2 2 8 4 4 8 16\n",
"output": "32 8\n"
},
{
"input": "12\n1 2 8 4 3 24 4 6 1 2 8 12\n",
"output": "24 8\n"
},
{
"input": "5\n1 7 49 1 7\n",
"output": "49 7\n"
},
{
"input": "3\n67 1 1\n",
"output": "67 1\n"
},
{
"input": "8\n1 3 9 27 81 1 3 9\n",
"output": "81 9\n"
},
{
"input": "6\n5 1 5 19 1 95\n",
"output": "95 5\n"
},
{
"input": "6\n1 6 3 2 3 1\n",
"output": "6 3\n"
},
{
"input": "11\n2 4 1 4 16 32 16 8 8 1 2\n",
"output": "32 16\n"
},
{
"input": "6\n2 5 3 15 1 1\n",
"output": "15 2\n"
},
{
"input": "6\n47 1 1 94 7 2\n",
"output": "94 7\n"
},
{
"input": "10\n22 1 33 11 3 6 66 11 1 2\n",
"output": "66 11\n"
},
{
"input": "10\n7 14 5 35 70 1 7 2 10 1\n",
"output": "70 7\n"
},
{
"input": "6\n23 23 2 46 1 1\n",
"output": "46 23\n"
},
{
"input": "16\n6 4 1 1 6 2 2 36 8 3 12 9 3 18 24 72\n",
"output": "72 6\n"
},
{
"input": "8\n7 6 1 1 5 3 2 35\n",
"output": "35 6\n"
},
{
"input": "20\n12 21 7 21 2 1 6 42 3 42 3 7 4 84 14 14 2 6 28 1\n",
"output": "84 42\n"
},
{
"input": "2\n1 1\n",
"output": "1 1\n"
}
] |
code_contests
|
python
| 0 |
a926e1d55e2f64423aab364a7c8aba99
|
Bob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor — a square tile that is diagonally split into white and black part as depicted in the figure below.
<image>
The dimension of this tile is perfect for this kitchen, as he will need exactly w × h tiles without any scraps. That is, the width of the kitchen is w tiles, and the height is h tiles. As each tile can be rotated in one of four ways, he still needs to decide on how exactly he will tile the floor. There is a single aesthetic criterion that he wants to fulfil: two adjacent tiles must not share a colour on the edge — i.e. one of the tiles must have a white colour on the shared border, and the second one must be black.
<image> The picture on the left shows one valid tiling of a 3 × 2 kitchen. The picture on the right shows an invalid arrangement, as the bottom two tiles touch with their white parts.
Find the number of possible tilings. As this number may be large, output its remainder when divided by 998244353 (a prime number).
Input
The only line contains two space separated integers w, h (1 ≤ w,h ≤ 1 000) — the width and height of the kitchen, measured in tiles.
Output
Output a single integer n — the remainder of the number of tilings when divided by 998244353.
Examples
Input
2 2
Output
16
Input
2 4
Output
64
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
def powmod(x, k, m):
res = 1
s = 1
while s <= k:
if k & s:
res = res * x % m
x = x * x % m
s <<= 1
return res
m = 998244353
w, h = map(int, input().split())
print(powmod(2, w + h, m))
|
python
|
code_algorithm
|
[
{
"input": "2 4\n",
"output": "64\n"
},
{
"input": "2 2\n",
"output": "16\n"
},
{
"input": "2 1\n",
"output": "8\n"
},
{
"input": "2 3\n",
"output": "32\n"
},
{
"input": "17 23\n",
"output": "444595123\n"
},
{
"input": "2 5\n",
"output": "128\n"
},
{
"input": "1 1000\n",
"output": "46452554\n"
},
{
"input": "3 16\n",
"output": "524288\n"
},
{
"input": "843 134\n",
"output": "230806096\n"
},
{
"input": "1000 1000\n",
"output": "708964705\n"
},
{
"input": "15 22\n",
"output": "679477111\n"
},
{
"input": "1 2\n",
"output": "8\n"
},
{
"input": "1 1\n",
"output": "4\n"
},
{
"input": "912 584\n",
"output": "626052968\n"
},
{
"input": "432 333\n",
"output": "726933080\n"
},
{
"input": "20 10\n",
"output": "75497471\n"
},
{
"input": "88 88\n",
"output": "412395273\n"
},
{
"input": "1000 122\n",
"output": "712990290\n"
}
] |
code_contests
|
python
| 0.2 |
14e423508acd9e2a238a3883faba8956
|
The only difference between easy and hard versions is the number of elements in the array.
You are given an array a consisting of n integers. In one move you can choose any a_i and divide it by 2 rounding down (in other words, in one move you can set a_i := ⌊(a_i)/(2)⌋).
You can perform such an operation any (possibly, zero) number of times with any a_i.
Your task is to calculate the minimum possible number of operations required to obtain at least k equal numbers in the array.
Don't forget that it is possible to have a_i = 0 after some operations, thus the answer always exists.
Input
The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of elements in the array and the number of equal numbers required.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 2 ⋅ 10^5), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible number of operations required to obtain at least k equal numbers in the array.
Examples
Input
5 3
1 2 2 4 5
Output
1
Input
5 3
1 2 3 4 5
Output
2
Input
5 3
1 2 3 3 3
Output
0
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
from sys import stdin
n, k = [int(i) for i in stdin.readline().strip().split()]
a = [int(i) for i in stdin.readline().strip().split()]
p = [19 * [0] for _ in range(max(a) + 1)]
nums = set()
for m in a:
for i in range(19):
p[m >> i][i] += 1
nums.add(m >> i)
if (m >> i) == 0:
break
res = 10000000000000000000
for m in nums:
d = p[m]
sum = 0
steps = 0
for i in range(19):
if sum + d[i] >= k:
add = (k - sum) * i
steps += add
res = min(steps, res)
break
else:
sum += d[i]
steps += (i * d[i])
print(res)
|
python
|
code_algorithm
|
[
{
"input": "5 3\n1 2 3 3 3\n",
"output": "0\n"
},
{
"input": "5 3\n1 2 3 4 5\n",
"output": "2\n"
},
{
"input": "5 3\n1 2 2 4 5\n",
"output": "1\n"
},
{
"input": "50 7\n199961 199990 199995 199997 199963 199995 199985 199994 199974 199974 199997 199991 199993 199982 199991 199982 199963 200000 199994 199997 199963 199991 199947 199996 199994 199995 199995 199990 199972 199973 199980 199955 199984 199998 199998 199992 199986 199986 199997 199995 199987 199958 199982 199998 199996 199995 199979 199943 199992 199993\n",
"output": "7\n"
},
{
"input": "50 50\n86175 169571 61423 53837 33228 49923 87369 11875 167105 101762 128203 19011 191596 19500 11213 950 192557 164451 58008 34390 39704 128606 191084 14227 57911 129189 124795 42481 69510 59862 146348 57352 158069 68387 196697 46595 84330 168274 88721 191842 155836 39164 195031 53880 188281 11150 132256 87853 179233 135499\n",
"output": "780\n"
},
{
"input": "50 7\n155076 162909 18349 8937 38161 128479 127526 128714 164477 163037 130796 160247 17004 73321 175301 175796 79144 75670 46299 197255 10139 2112 195709 124860 6485 137601 63708 117985 94924 65661 113294 85898 7511 137431 115791 66126 146803 121145 96379 126408 195646 70033 131093 86487 94591 3086 59652 188702 27036 78631\n",
"output": "79\n"
},
{
"input": "50 25\n199970 199997 199998 199988 199999 199981 200000 199990 199974 199985 199932 200000 199966 199999 199999 199951 199983 199975 199974 199996 199974 199992 199979 199995 199955 199989 199960 199975 199983 199990 199950 199952 199999 199999 199962 199939 199979 199977 199962 199996 199910 199997 199976 200000 199999 199997 199998 199973 199996 199917\n",
"output": "125\n"
},
{
"input": "50 7\n1 2 27 54 6 15 24 1 9 28 3 26 8 12 7 6 8 54 23 8 7 13 18 10 1 33 24 10 34 13 12 9 16 11 36 50 39 9 8 10 2 5 6 4 7 67 21 12 6 55\n",
"output": "3\n"
},
{
"input": "50 50\n199987 199984 199987 199977 199996 199923 199984 199995 199991 200000 199998 199990 199983 199981 199973 199989 199981 199993 199959 199994 199973 199962 199998 199970 199999 199981 199996 199996 199985 199980 199959 199990 199982 199987 199992 199997 199985 199976 199947 199998 199962 199987 199984 199982 199999 199997 199985 199992 199979 199974\n",
"output": "450\n"
},
{
"input": "50 50\n8 63 44 78 3 65 7 27 13 45 7 5 18 94 25 17 26 10 21 44 5 13 6 30 10 11 44 14 71 17 10 5 4 9 8 21 4 9 25 18 3 14 15 8 7 11 5 28 9 1\n",
"output": "167\n"
},
{
"input": "50 2\n199995 199977 199982 199979 199998 199991 199999 199976 199974 199971 199966 199999 199978 199987 199989 199995 199968 199987 199988 199987 199987 199998 199988 199958 199985 199999 199997 199939 199992 199999 199985 199994 199987 199965 199947 199991 199993 199997 199998 199994 199971 199999 199999 199990 199993 199983 199983 199999 199970 199952\n",
"output": "0\n"
},
{
"input": "50 2\n72548 51391 1788 171949 148789 151619 19225 8774 52484 74830 20086 51129 151145 87650 108005 112019 126739 124087 158096 59027 34500 87415 115058 194160 171792 136832 1114 112592 171746 199013 101484 182930 185656 154861 191455 165701 140450 3475 160191 122350 66759 93252 60972 124615 119327 108068 149786 8698 63546 187913\n",
"output": "12\n"
},
{
"input": "50 2\n3 6 10 1 14 5 26 11 6 1 23 43 7 23 20 11 15 11 2 1 8 37 2 19 31 18 2 4 15 84 9 29 38 46 9 21 2 2 13 114 28 9 6 20 14 46 4 20 39 99\n",
"output": "0\n"
},
{
"input": "50 25\n19 1 17 6 4 21 9 16 5 21 2 12 17 11 54 18 36 20 34 17 32 1 4 14 26 11 6 2 7 5 2 3 12 16 20 5 16 1 18 55 16 20 2 3 2 12 65 20 7 11\n",
"output": "43\n"
},
{
"input": "1 1\n1337\n",
"output": "0\n"
},
{
"input": "50 25\n162847 80339 131433 130128 135933 64805 74277 145697 92574 169638 26992 155045 32254 97675 177503 143802 44012 171388 185307 33652 194764 80214 169507 71832 180118 117737 198279 89826 9941 120250 158894 31871 616 190147 159249 158867 131076 77551 95165 54709 51376 145758 74581 26670 48775 29351 4750 55294 129850 19793\n",
"output": "364\n"
},
{
"input": "50 1\n156420 126738 188531 85575 23728 72842 190346 24786 118328 137944 126942 115577 175247 85409 146194 31398 189417 52337 135886 162083 146559 131125 31741 152481 57935 26624 106893 55028 81626 99143 182257 129556 100261 11429 156642 27997 105720 173400 140250 164944 26466 132034 86679 190160 161138 179688 2975 149862 38336 67959\n",
"output": "0\n"
}
] |
code_contests
|
python
| 0.1 |
0b6256ef902cfa5453407cbe7e1a7d0e
|
As the name of the task implies, you are asked to do some work with segments and trees.
Recall that a tree is a connected undirected graph such that there is exactly one simple path between every pair of its vertices.
You are given n segments [l_1, r_1], [l_2, r_2], ..., [l_n, r_n], l_i < r_i for every i. It is guaranteed that all segments' endpoints are integers, and all endpoints are unique — there is no pair of segments such that they start in the same point, end in the same point or one starts in the same point the other one ends.
Let's generate a graph with n vertices from these segments. Vertices v and u are connected by an edge if and only if segments [l_v, r_v] and [l_u, r_u] intersect and neither of it lies fully inside the other one.
For example, pairs ([1, 3], [2, 4]) and ([5, 10], [3, 7]) will induce the edges but pairs ([1, 2], [3, 4]) and ([5, 7], [3, 10]) will not.
Determine if the resulting graph is a tree or not.
Input
The first line contains a single integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the number of segments.
The i-th of the next n lines contain the description of the i-th segment — two integers l_i and r_i (1 ≤ l_i < r_i ≤ 2n).
It is guaranteed that all segments borders are pairwise distinct.
Output
Print "YES" if the resulting graph is a tree and "NO" otherwise.
Examples
Input
6
9 12
2 11
1 3
6 10
5 7
4 8
Output
YES
Input
5
1 3
2 4
5 9
6 8
7 10
Output
NO
Input
5
5 8
3 6
2 9
7 10
1 4
Output
NO
Note
The graph corresponding to the first example:
<image>
The graph corresponding to the second example:
<image>
The graph corresponding to the third example:
<image>
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import sys
class segmTree():
def __init__(self, size=None, array=None):
if array is not None:
size = len(array)
N = 1
while N < size:
N <<= 1
self.N = N
self.tree = [0] * (2*self.N)
if array is not None:
for i in range(size):
self.tree[i+self.N] = array[i]
self.build()
def build(self):
for i in range(self.N - 1, 0, -1):
self.tree[i] = self.tree[i<<1] + self.tree[i<<1|1]
def add(self, i, value=1):
i += self.N
while i > 0:
self.tree[i] += value
i >>= 1
def findNonzero(self, l, r):
N = self.N
l += N
r += N
cand = []
while l < r:
if l & 1:
cand.append(l)
l += 1
if r & 1:
r -= 1
cand.append(r)
l >>= 1
r >>= 1
nonzeros = []
while cand:
i = cand.pop()
if self.tree[i]:
if i < N:
cand.append(i<<1)
cand.append(i<<1|1)
else:
nonzeros.append(i - N)
return nonzeros
# inf = open('input.txt', 'r')
# reader = (line.rstrip() for line in inf)
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
n = int(input())
segm = [0] * (2 * n + 1)
edge = [0] * (2 * n + 1)
for i in range(n):
l, r = map(int, input().split())
segm[l] = segm[r] = i
edge[l] = edge[r] = r
# inf.close()
opened = segmTree(size=2*n+1)
g = [[] for _ in range(n)]
ctr = 0
for e in range(1, 2 * n + 1):
r = edge[e]
if e == r:
opened.add(e, -1)
else:
opened.add(r, 1)
for R in opened.findNonzero(0, r):
ctr += 1
if ctr >= n:
print('NO')
sys.exit()
i = segm[r]
j = segm[R]
g[i].append(j)
g[j].append(i)
# print(g)
visited = [False] * n
stack = [0]
while stack:
v = stack.pop()
if not visited[v]:
visited[v] = True
for to in g[v]:
stack.append(to)
print('YES' if all(visited) else 'NO')
|
python
|
code_algorithm
|
[
{
"input": "5\n5 8\n3 6\n2 9\n7 10\n1 4\n",
"output": "NO\n"
},
{
"input": "5\n1 3\n2 4\n5 9\n6 8\n7 10\n",
"output": "NO\n"
},
{
"input": "6\n9 12\n2 11\n1 3\n6 10\n5 7\n4 8\n",
"output": "YES\n"
},
{
"input": "4\n1 2\n3 6\n4 7\n5 8\n",
"output": "NO\n"
},
{
"input": "8\n2 16\n7 13\n12 14\n4 15\n8 9\n1 11\n3 6\n5 10\n",
"output": "NO\n"
},
{
"input": "5\n4 6\n2 5\n3 9\n8 10\n1 7\n",
"output": "YES\n"
},
{
"input": "5\n1 4\n2 5\n3 10\n6 8\n7 9\n",
"output": "NO\n"
},
{
"input": "6\n9 12\n2 3\n6 10\n4 7\n1 5\n8 11\n",
"output": "NO\n"
},
{
"input": "6\n1 3\n2 10\n8 11\n4 12\n5 7\n6 9\n",
"output": "YES\n"
},
{
"input": "6\n4 11\n1 5\n7 9\n2 12\n6 8\n3 10\n",
"output": "NO\n"
},
{
"input": "4\n1 6\n2 3\n4 7\n5 8\n",
"output": "NO\n"
},
{
"input": "7\n5 8\n7 11\n2 6\n1 3\n4 14\n10 12\n9 13\n",
"output": "YES\n"
},
{
"input": "5\n1 4\n7 8\n3 10\n2 6\n5 9\n",
"output": "NO\n"
},
{
"input": "20\n11 13\n21 38\n29 33\n10 18\n4 9\n2 6\n26 28\n15 39\n12 17\n8 19\n27 36\n20 22\n14 16\n3 5\n1 7\n24 37\n31 35\n30 32\n34 40\n23 25\n",
"output": "YES\n"
},
{
"input": "6\n2 8\n6 9\n4 11\n5 7\n1 12\n3 10\n",
"output": "NO\n"
},
{
"input": "7\n1 13\n6 9\n4 7\n3 10\n8 11\n2 5\n12 14\n",
"output": "NO\n"
},
{
"input": "8\n2 5\n3 6\n4 7\n10 13\n11 14\n12 15\n1 9\n8 16\n",
"output": "NO\n"
},
{
"input": "20\n20 22\n9 11\n32 36\n8 12\n14 16\n4 6\n28 30\n29 37\n15 18\n33 35\n27 31\n21 25\n2 7\n19 23\n10 39\n34 40\n5 13\n24 38\n17 26\n1 3\n",
"output": "YES\n"
},
{
"input": "4\n2 5\n3 6\n4 7\n1 8\n",
"output": "NO\n"
},
{
"input": "7\n4 6\n11 13\n8 12\n5 9\n2 7\n10 14\n1 3\n",
"output": "YES\n"
},
{
"input": "20\n3 13\n33 35\n6 8\n27 31\n25 28\n15 17\n11 29\n30 37\n1 5\n9 12\n20 23\n19 21\n14 18\n16 24\n7 10\n32 36\n22 26\n38 40\n34 39\n2 4\n",
"output": "YES\n"
},
{
"input": "5\n3 6\n4 7\n5 8\n1 9\n2 10\n",
"output": "NO\n"
},
{
"input": "6\n1 12\n6 9\n4 7\n3 10\n8 11\n2 5\n",
"output": "NO\n"
},
{
"input": "7\n2 12\n1 3\n5 7\n9 11\n4 8\n10 13\n6 14\n",
"output": "YES\n"
},
{
"input": "1\n1 2\n",
"output": "YES\n"
},
{
"input": "5\n1 3\n2 4\n5 8\n6 9\n7 10\n",
"output": "NO\n"
},
{
"input": "4\n1 4\n2 5\n3 8\n6 7\n",
"output": "NO\n"
},
{
"input": "5\n1 3\n4 9\n8 10\n5 7\n2 6\n",
"output": "YES\n"
},
{
"input": "6\n3 5\n4 6\n1 10\n7 11\n9 12\n2 8\n",
"output": "NO\n"
},
{
"input": "5\n1 4\n9 10\n2 6\n5 7\n3 8\n",
"output": "NO\n"
},
{
"input": "8\n9 12\n5 10\n1 6\n2 7\n3 4\n14 15\n8 13\n11 16\n",
"output": "NO\n"
},
{
"input": "7\n9 13\n3 12\n7 11\n5 10\n6 8\n2 4\n1 14\n",
"output": "NO\n"
},
{
"input": "4\n1 8\n2 5\n3 6\n4 7\n",
"output": "NO\n"
},
{
"input": "7\n2 7\n3 6\n4 5\n1 11\n8 12\n9 13\n10 14\n",
"output": "NO\n"
},
{
"input": "6\n6 9\n4 7\n3 10\n8 11\n2 5\n1 12\n",
"output": "NO\n"
},
{
"input": "5\n1 4\n2 5\n3 6\n7 9\n8 10\n",
"output": "NO\n"
},
{
"input": "4\n1 4\n5 6\n3 8\n2 7\n",
"output": "NO\n"
},
{
"input": "3\n1 4\n2 6\n3 5\n",
"output": "YES\n"
},
{
"input": "6\n7 10\n3 8\n2 11\n9 12\n1 4\n5 6\n",
"output": "NO\n"
},
{
"input": "5\n1 3\n2 7\n6 8\n4 10\n5 9\n",
"output": "YES\n"
},
{
"input": "5\n1 3\n4 9\n7 8\n5 10\n2 6\n",
"output": "NO\n"
},
{
"input": "5\n1 4\n3 5\n2 8\n7 9\n6 10\n",
"output": "YES\n"
},
{
"input": "5\n7 10\n4 6\n3 8\n2 5\n1 9\n",
"output": "YES\n"
},
{
"input": "4\n1 6\n3 5\n4 7\n2 8\n",
"output": "YES\n"
},
{
"input": "8\n5 8\n1 16\n7 10\n4 14\n13 15\n3 6\n2 11\n9 12\n",
"output": "NO\n"
},
{
"input": "4\n3 8\n2 7\n5 6\n1 4\n",
"output": "NO\n"
},
{
"input": "5\n5 8\n6 9\n2 3\n4 10\n1 7\n",
"output": "NO\n"
},
{
"input": "7\n8 11\n5 7\n1 6\n10 12\n2 14\n4 9\n3 13\n",
"output": "YES\n"
},
{
"input": "5\n2 5\n1 3\n4 8\n7 9\n6 10\n",
"output": "YES\n"
},
{
"input": "5\n7 10\n6 9\n5 8\n1 3\n2 4\n",
"output": "NO\n"
},
{
"input": "5\n1 6\n2 3\n4 9\n5 8\n7 10\n",
"output": "NO\n"
}
] |
code_contests
|
python
| 0.1 |
b1c363e08aeaf7c060beabc5a840d973
|
Mr. Chanek is currently participating in a science fair that is popular in town. He finds an exciting puzzle in the fair and wants to solve it.
There are N atoms numbered from 1 to N. These atoms are especially quirky. Initially, each atom is in normal state. Each atom can be in an excited. Exciting atom i requires D_i energy. When atom i is excited, it will give A_i energy. You can excite any number of atoms (including zero).
These atoms also form a peculiar one-way bond. For each i, (1 ≤ i < N), if atom i is excited, atom E_i will also be excited at no cost. Initially, E_i = i+1. Note that atom N cannot form a bond to any atom.
Mr. Chanek must change exactly K bonds. Exactly K times, Mr. Chanek chooses an atom i, (1 ≤ i < N) and changes E_i to a different value other than i and the current E_i. Note that an atom's bond can remain unchanged or changed more than once. Help Mr. Chanek determine the maximum energy that he can achieve!
note: You must first change exactly K bonds before you can start exciting atoms.
Input
The first line contains two integers N K (4 ≤ N ≤ 10^5, 0 ≤ K < N), the number of atoms, and the number of bonds that must be changed.
The second line contains N integers A_i (1 ≤ A_i ≤ 10^6), which denotes the energy given by atom i when on excited state.
The third line contains N integers D_i (1 ≤ D_i ≤ 10^6), which denotes the energy needed to excite atom i.
Output
A line with an integer that denotes the maximum number of energy that Mr. Chanek can get.
Example
Input
6 1
5 6 7 8 10 2
3 5 6 7 1 10
Output
35
Note
An optimal solution to change E_5 to 1 and then excite atom 5 with energy 1. It will cause atoms 1, 2, 3, 4, 5 be excited. The total energy gained by Mr. Chanek is (5 + 6 + 7 + 8 + 10) - 1 = 35.
Another possible way is to change E_3 to 1 and then exciting atom 3 (which will excite atom 1, 2, 3) and exciting atom 4 (which will excite atom 4, 5, 6). The total energy gained by Mr. Chanek is (5 + 6 + 7 + 8 + 10 + 2) - (6 + 7) = 25 which is not optimal.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = list(map(int, input().split()))
pref=[0]
for i in range(n):
pref.append(pref[-1]+a[i])
if k==0:
ans=0
for i in range(1,n+1):
ans=max(ans,pref[-1]-pref[i-1]-d[i-1])
print(ans)
elif k == 1:
best = sum(a[:n-1]) - min(d[:n-1])
other = sum(a)
other -= sorted(d)[0]
other -= sorted(d)[1]
curr = sum(a)
for i in range(n):
if i:
best = max(best, curr - d[i])
curr -= a[i]
o2 = sum(a) - min(a[1:]) - d[0]
print(max((best,other,0, o2)))
else:
print(max((sum(a) - min(d[:-1]),0,a[-1] - d[-1])))
|
python
|
code_algorithm
|
[
{
"input": "6 1\n5 6 7 8 10 2\n3 5 6 7 1 10\n",
"output": "35\n"
},
{
"input": "4 1\n1 12 13 20\n10 5 4 100\n",
"output": "40\n"
},
{
"input": "6 1\n1 10 10 5 20 100\n1000000 1 10 10 100 1000000\n",
"output": "144\n"
},
{
"input": "5 0\n1 1 1 1 1\n10 10 10 10 10\n",
"output": "0\n"
},
{
"input": "4 3\n1 2 4 8\n5 1 3 5\n",
"output": "14\n"
},
{
"input": "4 3\n1 2 4 8\n17 15 16 1\n",
"output": "7\n"
},
{
"input": "6 1\n1 10 10 20 5 100\n1000000 1 10 100 10 1000000\n",
"output": "144\n"
},
{
"input": "4 2\n1 2 4 8\n1 5 3 5\n",
"output": "14\n"
},
{
"input": "4 2\n1 2 4 8\n5 3 1 5\n",
"output": "14\n"
},
{
"input": "4 3\n1 2 4 8\n1 5 3 5\n",
"output": "14\n"
},
{
"input": "4 1\n3 2 1 5\n8 5 4 4\n",
"output": "3\n"
},
{
"input": "4 1\n2 5 2 1\n101 2 101 100\n",
"output": "7\n"
},
{
"input": "4 1\n2 5 11 11\n1 2 100 100\n",
"output": "26\n"
},
{
"input": "5 1\n1 2 2 2 1\n1 101 101 101 100\n",
"output": "6\n"
},
{
"input": "4 3\n1 1 1 1\n10 10 10 10\n",
"output": "0\n"
},
{
"input": "4 1\n3 2 3 4\n8 1 2 8\n",
"output": "9\n"
},
{
"input": "5 1\n1 1 1 1 1\n10 10 10 10 10\n",
"output": "0\n"
},
{
"input": "4 3\n1 2 4 8\n6 5 3 1\n",
"output": "12\n"
},
{
"input": "4 2\n1 1 1 1\n10 10 10 10\n",
"output": "0\n"
},
{
"input": "5 1\n2 5 11 12 13\n1 2 100 100 100\n",
"output": "40\n"
},
{
"input": "5 1\n3 2 3 4 5\n8 1 2 8 8\n",
"output": "14\n"
},
{
"input": "4 1\n10 9 9 7\n1 11 11 10\n",
"output": "27\n"
},
{
"input": "4 1\n1 1 3 5\n100 100 1 100\n",
"output": "7\n"
},
{
"input": "4 2\n1 2 4 8\n17 15 16 1\n",
"output": "7\n"
},
{
"input": "5 1\n3 2 1 4 8\n8 1 10 3 5\n",
"output": "14\n"
},
{
"input": "5 1\n1 12 13 20 30\n10 5 4 1 100\n",
"output": "71\n"
},
{
"input": "4 0\n5 3 2 2\n13 8 5 1\n",
"output": "1\n"
},
{
"input": "4 2\n1 2 4 8\n6 5 3 1\n",
"output": "12\n"
},
{
"input": "4 2\n1 2 4 8\n5 1 3 5\n",
"output": "14\n"
},
{
"input": "4 1\n10 10 9 100\n1 10 10 1000000\n",
"output": "119\n"
},
{
"input": "4 3\n1 2 4 8\n5 3 1 5\n",
"output": "14\n"
},
{
"input": "5 1\n1 1 4 5 12\n100 100 7 2 10\n",
"output": "15\n"
},
{
"input": "4 1\n10 9 10 100\n1 10 10 1000000\n",
"output": "119\n"
}
] |
code_contests
|
python
| 0 |
7271d3c722f5148f0a9728010dbd5eff
|
Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks.
Sergey totally forgot about the task until half an hour before the next lesson and hastily scribbled something down. But then he recollected that in the last lesson he learned the grammar of N-ish. The spelling rules state that N-ish contains some "forbidden" pairs of letters: such letters can never occur in a sentence next to each other. Also, the order of the letters doesn't matter (for example, if the pair of letters "ab" is forbidden, then any occurrences of substrings "ab" and "ba" are also forbidden). Also, each pair has different letters and each letter occurs in no more than one forbidden pair.
Now Sergey wants to correct his sentence so that it doesn't contain any "forbidden" pairs of letters that stand next to each other. However, he is running out of time, so he decided to simply cross out some letters from the sentence. What smallest number of letters will he have to cross out? When a letter is crossed out, it is "removed" so that the letters to its left and right (if they existed), become neighboring. For example, if we cross out the first letter from the string "aba", we get the string "ba", and if we cross out the second letter, we get "aa".
Input
The first line contains a non-empty string s, consisting of lowercase Latin letters — that's the initial sentence in N-ish, written by Sergey. The length of string s doesn't exceed 105.
The next line contains integer k (0 ≤ k ≤ 13) — the number of forbidden pairs of letters.
Next k lines contain descriptions of forbidden pairs of letters. Each line contains exactly two different lowercase Latin letters without separators that represent the forbidden pairs. It is guaranteed that each letter is included in no more than one pair.
Output
Print the single number — the smallest number of letters that need to be removed to get a string without any forbidden pairs of neighboring letters. Please note that the answer always exists as it is always possible to remove all letters.
Examples
Input
ababa
1
ab
Output
2
Input
codeforces
2
do
cs
Output
1
Note
In the first sample you should remove two letters b.
In the second sample you should remove the second or the third letter. The second restriction doesn't influence the solution.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
ans = 0
t = []
x = input()
y = int(input())
for i in range(y):
z = input()
t.append(z)
#x = codeforces
#y = 2
#t = [do, cs]
pt = -1
ln = len(x)
for i in t:
a = i[0]
b = i[1]
pt = 0
for j in range(ln):
ded1=0
ded2=0
if j >= pt:
if x[j] in [a,b]:
pt = j
while pt < ln and x[pt] in [a,b]:
if x[pt] == a:
ded1+=1
else:
ded2+=1
pt += 1
ans += min(ded1, ded2)
print(ans)
|
python
|
code_algorithm
|
[
{
"input": "ababa\n1\nab\n",
"output": "2\n"
},
{
"input": "codeforces\n2\ndo\ncs\n",
"output": "1\n"
},
{
"input": "vefneyamdzoytemupniw\n13\nve\nfg\noi\nan\nck\nwx\npq\nml\nbt\nud\nrz\nsj\nhy\n",
"output": "1\n"
},
{
"input": "pgpgppgggpbbnnn\n2\npg\nnb\n",
"output": "7\n"
},
{
"input": "mbmxuuuuxuuuuhhooooxxxuxxxuxuuxuuuxxjvjvjjjjvvvjjjjjvvjvjjjvvvjjvjjvvvjjjvjvvjvjjjjjmmbmbbbbbmbbbbmm\n5\nmb\nho\nxu\njv\nyp\n",
"output": "37\n"
},
{
"input": "eowsgsewestwsootoetteoeeeetwssesstswegswetwetggewsteeteoggetssetseegwteswtteowsgowwoowetwgogewssogwgtttgwwoeotgoswwwwswsgeeoowwwwetwgeswsgwtsgewswtstwgggtegsssggsstwsoggeoseotgwswwggtggweewwgwegggoteweessotsewttwseosgegswwsoewgwstetwteegseowgwoteegwttwwowtwtosweeggweeeeoeesgseetgwgtswteotgwewetssggteewteeetetweeotwttwoeswggoosogoeg\n3\nst\neo\ngw\n",
"output": "49\n"
},
{
"input": "nllnrlrnll\n1\nrl\n",
"output": "1\n"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n1\nab\n",
"output": "75\n"
},
{
"input": "aludfbjtwnkgnfl\n1\noy\n",
"output": "0\n"
},
{
"input": "pninnihzipirpbdggrdglzdpbldtzihgbzdnrgznbpdanhnlag\n4\nli\nqh\nad\nbp\n",
"output": "4\n"
},
{
"input": "t\n13\nzx\nig\nyq\nbd\nph\nar\nne\nwo\ntk\njl\ncv\nfs\nmu\n",
"output": "0\n"
},
{
"input": "z\n0\n",
"output": "0\n"
},
{
"input": "drvwfaacccwnncfwuptsorrrvvvrgdzytrwweeexzyyyxuwuuk\n13\nld\nac\nnp\nrv\nmo\njh\ngb\nuw\nfq\nst\nkx\nzy\nei\n",
"output": "11\n"
},
{
"input": "ttspivgoupgupvgpusvppogsseueusuglpiugssviuutlvgvugtpovuvspvpipggooplgvgugpogvesppulovugsvuougveiivgvslllviogpvtolepglguuellotpvgevspvoiiggiiplppgosuguvtstttpielteuglopgeoeeuivtptggltoltpgliviotsospvitupiopisoetupvvspooilsopslpoloptigstspoiuutiuvvuvlpplvioitsuvlpvtleveslslovolloogsgpvpepgueesslgtssttuupieppsstoeopeeppvopglpvtvuugpsuoplttsgstsiplpiugtoolisgpeeiuvutstpulvtllipsvsslvoepooslvteoevipvpsuoiippeuegoovoovstlvgsstitsivlvseguoolpslueuepgeooltviovpveeivolssloieuugovguoleulvssopetlpivpgoigtv\n1\ngs\n",
"output": "8\n"
},
{
"input": "rbnxovfcwkdjctdjfskaozjzthlcntuaoiavnbsfpuzxyvhfbxetvryvwrqetokdshadxpxijtpkrqvghsrejgnqntwiypiglzmp\n13\njr\nnf\nyk\ntq\nwe\nil\ngu\npb\naz\nxm\nhc\nvd\nso\n",
"output": "0\n"
},
{
"input": "eepeeeeppppppeepeppe\n1\npe\n",
"output": "10\n"
},
{
"input": "yynynnyyyiynyniiiinyynniiyiyyyniyniyynyyyynyynnniiiniyyniiyyiynyiynnnnyiiyiyniyyininiyiiiyynnnyiyinnnnyiinnnnnyninyinyynynyiynyyyiyinyynnyyinynyinininyniniynniiyyiiyy\n1\nni\n",
"output": "28\n"
}
] |
code_contests
|
python
| 0.1 |
c51d50d78c0f3d626b7e347a65cb62fc
|
You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence.
We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2... s|s|.
String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or exists such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. Characters in lines are compared like their ASCII codes.
Input
The single line contains a non-empty string s, consisting only of lowercase English letters. The string's length doesn't exceed 105.
Output
Print the lexicographically maximum subsequence of string s.
Examples
Input
ababba
Output
bbba
Input
abbcbccacbbcbaaba
Output
cccccbba
Note
Let's look at samples and see what the sought subsequences look like (they are marked with uppercase bold letters).
The first sample: aBaBBA
The second sample: abbCbCCaCbbCBaaBA
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
s = input()
n = len(s)
temp = list(set(s))
x = {}
temp = sorted(temp,reverse=True)
i = 0
while(i < n ):
x[s[i]] = i
i +=1
string = ""
i = 0
j = 0
while(i< n and j < len(temp)):
if i <= x[temp[j]]:
if s[i]== temp[j]:
string += temp[j]
if i== x[temp[j]]:
j += 1
if(len(temp) > 2):
while( j < len(temp)-1 and x[temp[j]] < i):
j+=1
i+=1
print(string)
|
python
|
code_algorithm
|
[
{
"input": "ababba\n",
"output": "bbba\n"
},
{
"input": "abbcbccacbbcbaaba\n",
"output": "cccccbba\n"
},
{
"input": "b\n",
"output": "b\n"
},
{
"input": "abcdeabcd\n",
"output": "ed\n"
},
{
"input": "aza\n",
"output": "za\n"
},
{
"input": "abcdedcba\n",
"output": "edcba\n"
},
{
"input": "aa\n",
"output": "aa\n"
},
{
"input": "zzyzyy\n",
"output": "zzzyy\n"
},
{
"input": "cantouristsolveitlessthaninoneminute\n",
"output": "vute\n"
},
{
"input": "aababb\n",
"output": "bbb\n"
},
{
"input": "zz\n",
"output": "zz\n"
},
{
"input": "whyareyoulookingfortestsdoyouhavewa\n",
"output": "yyywa\n"
},
{
"input": "z\n",
"output": "z\n"
},
{
"input": "arepretestsstrongforthisproblem\n",
"output": "ttttsrom\n"
},
{
"input": "zaz\n",
"output": "zz\n"
},
{
"input": "y\n",
"output": "y\n"
},
{
"input": "a\n",
"output": "a\n"
},
{
"input": "zyxzxzwyxywxxwabcdabdacdbcacdbcacabaaba\n",
"output": "zzzyyxxwddddccbba\n"
},
{
"input": "dcbaedcba\n",
"output": "edcba\n"
},
{
"input": "thankstosamarasauteddybearsforthiscontest\n",
"output": "yttt\n"
}
] |
code_contests
|
python
| 0.7 |
f3cb0d0a24cf5e61c1ae3195ee2d1544
|
Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where
* <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 and 16, inclusive.
* <hostname> — is a sequence of word separated by periods (characters «.»), where each word should contain only characters allowed for <username>, the length of each word is between 1 and 16, inclusive. The length of <hostname> is between 1 and 32, inclusive.
* <resource> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <resource> is between 1 and 16, inclusive.
The content of square brackets is optional — it can be present or can be absent.
There are the samples of correct Jabber IDs: [email protected], [email protected]/contest.
Your task is to write program which checks if given string is a correct Jabber ID.
Input
The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive.
Output
Print YES or NO.
Examples
Input
[email protected]
Output
YES
Input
[email protected]/contest.icpc/12
Output
NO
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
s = input()
if s.count('@') != 1 or s.count('/') > 1:
print('NO')
exit()
p1 = s.find('@')
p2 = s.find('/')
if p2 == -1: p2 = len(s)
import re
u = re.compile('(\w){1,16}$')
h = re.compile('(\w{1,16}\.)*\w{1,16}$')
k1 = h.match(s[p1 + 1 : p2])
k2 = u.match(s[0:p1])
k3 = u.match(s[p2 + 1 : len(s)])
if len(s[p1 + 1 : p2]) >= 1 and len(s[p1 + 1 : p2])<= 32 and k1 and k2 and (p2 == len(s) or k3):
print('YES')
else:
print('NO')
|
python
|
code_algorithm
|
[
{
"input": "[email protected]\n",
"output": "YES\n"
},
{
"input": "[email protected]/contest.icpc/12\n",
"output": "NO\n"
},
{
"input": "@ops\n",
"output": "NO\n"
},
{
"input": "xLEctap0T@22U9W_fA/7iQeJGFu1lSgMZ\n",
"output": "YES\n"
},
{
"input": "[email protected]!_!CcAOEEx.0z.aiW/S430sbQT\n",
"output": "NO\n"
},
{
"input": "test@test.\n",
"output": "NO\n"
},
{
"input": "[email protected]\n",
"output": "YES\n"
},
{
"input": "[email protected]/0sN\n",
"output": "NO\n"
},
{
"input": "[email protected]/_97Ltj3\n",
"output": "YES\n"
},
{
"input": "[email protected]!Tg..wGN5YOi68U.oP2Yl3/\n",
"output": "NO\n"
},
{
"input": "eWfLL@gW!BEJUxF[email protected]/2.Pr7a/5O6zXdAkikjCEDrb\n",
"output": "NO\n"
},
{
"input": "4@@..f3ZT./oUGZ@\n",
"output": "NO\n"
},
{
"input": "[email protected]/iUij1x7\n",
"output": "YES\n"
},
{
"input": "oooop/oooop\n",
"output": "NO\n"
},
{
"input": "@\n",
"output": "NO\n"
},
{
"input": "[email protected]/M_jTHS_6!\n",
"output": "NO\n"
},
{
"input": "[email protected]\n",
"output": "YES\n"
},
{
"input": "[email protected]/\n",
"output": "NO\n"
},
{
"input": "[email protected]!AFAEk7glM[email protected]/OLKoJpZlac\n",
"output": "NO\n"
},
{
"input": "lGwo[email protected]\n",
"output": "NO\n"
},
{
"input": "[email protected]\n",
"output": "YES\n"
},
{
"input": "this-is-the-test\n",
"output": "NO\n"
},
{
"input": "[email protected]@codeforces.com\n",
"output": "NO\n"
},
{
"input": "Zu5VFUtSbIw@ner5e\n",
"output": "YES\n"
},
{
"input": "qG3@LKp\n",
"output": "YES\n"
},
{
"input": "al_Y2I4IKp@A_N.ruCw0VL/hRzJtx.S7sp/r!c.n9ffh\n",
"output": "NO\n"
},
{
"input": "8oI/a@Q\n",
"output": "NO\n"
},
{
"input": "[email protected]../.\n",
"output": "NO\n"
},
{
"input": "[email protected]/0EY3XmYatfY\n",
"output": "YES\n"
},
{
"input": "C1rE26_rTAVzLm@[email protected]./kkBEVlcU\n",
"output": "NO\n"
},
{
"input": "mail.ru/a\n",
"output": "NO\n"
},
{
"input": "[email protected]\n",
"output": "YES\n"
},
{
"input": "[email protected]/VE7gjf\n",
"output": "NO\n"
},
{
"input": "@alK@pR\n",
"output": "NO\n"
},
{
"input": "bgko@1../xwSj_J\n",
"output": "NO\n"
},
{
"input": "G/AZdVMTzRLV4Ucm@eQ!..pq!..tRTi5.Ejkqa/HGpFYk\n",
"output": "NO\n"
},
{
"input": "Y@[email protected]_MK7.g_..0.\n",
"output": "NO\n"
},
{
"input": "[email protected]\n",
"output": "YES\n"
},
{
"input": "[email protected]\n",
"output": "YES\n"
},
{
"input": "[email protected]\n",
"output": "NO\n"
},
{
"input": "WKxNIM79u@I.RM\n",
"output": "NO\n"
},
{
"input": "[email protected].\n",
"output": "NO\n"
},
{
"input": "/pqi7WXQPJFM4q1@hxUyUy/_pWo0n\n",
"output": "NO\n"
},
{
"input": "[email protected]_.38./zgVGNjpldr\n",
"output": "NO\n"
},
{
"input": "[email protected]/UXC\n",
"output": "NO\n"
},
{
"input": "/\n",
"output": "NO\n"
},
{
"input": "asd@asd@\n",
"output": "NO\n"
},
{
"input": "[email protected]/tT5d36\n",
"output": "NO\n"
},
{
"input": "[email protected]./MzuI\n",
"output": "NO\n"
},
{
"input": "[email protected]/juNlxB\n",
"output": "YES\n"
},
{
"input": "Ccz9T5rKZQuEerGo@6l.\n",
"output": "NO\n"
},
{
"input": "@/YTd.K1@lD\n",
"output": "NO\n"
},
{
"input": "[email protected]\n",
"output": "YES\n"
},
{
"input": "@mail.ru\n",
"output": "NO\n"
},
{
"input": "@mike\n",
"output": "NO\n"
},
{
"input": "mike@\n",
"output": "NO\n"
},
{
"input": "xC_5Vx8NgF..[email protected]@/PQYPeq@_y8!h_iF\n",
"output": "NO\n"
},
{
"input": "w@S8/XU.5._R7fHq.@../e.WP!54Ey1L.9jv\n",
"output": "NO\n"
},
{
"input": "s@mH@RO_/iWD\n",
"output": "NO\n"
},
{
"input": "BPxNVANhtEh@Oh_go.\n",
"output": "NO\n"
},
{
"input": "mGIY@cHRNC8GlJ/2pcl3LYxpi3PaKGs\n",
"output": "YES\n"
},
{
"input": "flTq1knyb@2!Mtfss\n",
"output": "NO\n"
},
{
"input": ".\n",
"output": "NO\n"
},
{
"input": "[email protected]\n",
"output": "NO\n"
},
{
"input": "[email protected].\n",
"output": "NO\n"
},
{
"input": "[email protected]/4TBzLWf724zE1r\n",
"output": "YES\n"
},
{
"input": "[email protected]_TQ2.z/qfi5CZrH\n",
"output": "YES\n"
},
{
"input": "bdHl525me@XzR_iO23v.YFXbnHUybbgw.i/WVEhm\n",
"output": "YES\n"
},
{
"input": "feGSXP@eyUfr8.x4Re.JL.6B.r/fX_\n",
"output": "NO\n"
},
{
"input": "[email protected]\n",
"output": "YES\n"
},
{
"input": "[email protected]!KtpX4tzs/0yQGzZCPJPJoda\n",
"output": "NO\n"
},
{
"input": "_TlPy65w/@[email protected]\n",
"output": "NO\n"
},
{
"input": "J@Y9Gz550l@PqVZdQ!u\n",
"output": "NO\n"
},
{
"input": "[email protected]./FJ4X\n",
"output": "NO\n"
},
{
"input": "est.@test\n",
"output": "NO\n"
},
{
"input": "UP51i49wX@pvx@2LWm8w/G4M3J./9L6Szy\n",
"output": "NO\n"
},
{
"input": "zr.KB_6ZMSwI2GA5@R/4iP1ZKHpszW!YN/\n",
"output": "NO\n"
},
{
"input": "VTE6aTTta@[email protected]@.l..3Bs\n",
"output": "NO\n"
},
{
"input": "test.me\n",
"output": "NO\n"
},
{
"input": "[email protected]/abacaba\n",
"output": "YES\n"
},
{
"input": "o3EaAnc3K6@h\n",
"output": "YES\n"
},
{
"input": "xpS@._s8.e0lJci/.LdiT\n",
"output": "NO\n"
},
{
"input": "[email protected]/aaa\n",
"output": "YES\n"
},
{
"input": "$@ru\n",
"output": "NO\n"
},
{
"input": "pbRIiuA@[email protected]\n",
"output": "NO\n"
},
{
"input": "[email protected]!.Ntz/QEh_sl\n",
"output": "NO\n"
},
{
"input": "[email protected]\n",
"output": "NO\n"
},
{
"input": "Yesx@9_KiJq2cBI6.\n",
"output": "NO\n"
},
{
"input": "[email protected]/i8cnKHT\n",
"output": "YES\n"
},
{
"input": "MiWPE8@fc./IViqq4T4PSUuMdhH\n",
"output": "NO\n"
},
{
"input": "[email protected]/ooooo\n",
"output": "YES\n"
},
{
"input": "[email protected]\n",
"output": "YES\n"
},
{
"input": "Q2/6y!SP9s[email protected]_nR8.\n",
"output": "NO\n"
},
{
"input": "[email protected]\n",
"output": "YES\n"
},
{
"input": "nrKbWV@P0irxQoRxDsNvG/69WxCwCsfB\n",
"output": "YES\n"
},
{
"input": "[email protected]@g.9u.v.A..XNH/1/tloIceXydZf3\n",
"output": "NO\n"
},
{
"input": "[email protected]@.\n",
"output": "NO\n"
}
] |
code_contests
|
python
| 0.4 |
668050a5954017b06638c6fb2d2faf2f
|
Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very creative teacher. One of his favorite warm-up exercises is throwing balls. Students line up. Each one gets a single ball in the beginning. The balls are numbered from 1 to n (by the demand of the inventory commission).
<image> Figure 1. The initial position for n = 5.
After receiving the balls the students perform the warm-up exercise. The exercise takes place in a few throws. For each throw the teacher chooses any two arbitrary different students who will participate in it. The selected students throw their balls to each other. Thus, after each throw the students remain in their positions, and the two balls are swapped.
<image> Figure 2. The example of a throw.
In this case there was a throw between the students, who were holding the 2-nd and the 4-th balls. Since the warm-up has many exercises, each of them can only continue for little time. Therefore, for each student we know the maximum number of throws he can participate in. For this lessons maximum number of throws will be 1 or 2.
Note that after all phases of the considered exercise any ball can end up with any student. Smart Beaver decided to formalize it and introduced the concept of the "ball order". The ball order is a sequence of n numbers that correspond to the order of balls in the line. The first number will match the number of the ball of the first from the left student in the line, the second number will match the ball of the second student, and so on. For example, in figure 2 the order of the balls was (1, 2, 3, 4, 5), and after the throw it was (1, 4, 3, 2, 5). Smart beaver knows the number of students and for each student he knows the maximum number of throws in which he can participate. And now he is wondering: what is the number of distinct ways of ball orders by the end of the exercise.
Input
The first line contains a single number n — the number of students in the line and the number of balls. The next line contains exactly n space-separated integers. Each number corresponds to a student in the line (the i-th number corresponds to the i-th from the left student in the line) and shows the number of throws he can participate in.
The input limits for scoring 30 points are (subproblem D1):
* 1 ≤ n ≤ 10.
The input limits for scoring 70 points are (subproblems D1+D2):
* 1 ≤ n ≤ 500.
The input limits for scoring 100 points are (subproblems D1+D2+D3):
* 1 ≤ n ≤ 1000000.
Output
The output should contain a single integer — the number of variants of ball orders after the warm up exercise is complete. As the number can be rather large, print it modulo 1000000007 (109 + 7).
Examples
Input
5
1 2 2 1 2
Output
120
Input
8
1 2 2 1 2 1 1 2
Output
16800
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
m = 1000000007
n = int(input())
a = map(int, input().split())
t1, t2 = 0, 0
for i in a:
if i == 1:
t1 += 1
else:
t2 += 1
a = [1, 2]
for i in range(3, t1+1):
a = a[::-1]
a[1] = (a[0]+(i-1)*a[1])%m
if not t1 or t1 == 1:
a[1] = 1
for i in range(t1+1, n+1):
a[1] = a[1]*i%m
print(a[1])
|
python
|
code_algorithm
|
[
{
"input": "8\n1 2 2 1 2 1 1 2\n",
"output": "16800\n"
},
{
"input": "5\n1 2 2 1 2\n",
"output": "120\n"
},
{
"input": "10\n2 2 2 2 2 2 2 2 2 2\n",
"output": "3628800\n"
},
{
"input": "100\n2 2 2 2 1 1 2 2 1 2 2 1 1 2 2 2 2 2 2 1 1 2 2 2 2 1 2 1 1 2 2 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 1 1 2 1 1 2 2 2 2 1 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 1 2 2 2 2\n",
"output": "834603967\n"
},
{
"input": "2\n2 2\n",
"output": "2\n"
},
{
"input": "9\n1 1 1 2 2 1 1 1 1\n",
"output": "16704\n"
},
{
"input": "10\n2 2 2 2 2 2 1 2 1 1\n",
"output": "2419200\n"
},
{
"input": "200\n1 2 1 1 2 2 1 1 1 1 1 1 2 1 2 2 2 2 2 1 2 2 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 2 2 2 1 1 2 2 2 1 2 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 1 2 1 1 2 2 2 2 2 2 2 1 2 2 2 1 1 2 2 2 2 1 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 1 1 1 2 2 2 2 2 2 2 2 1 1 2 2 2 2 2 1 2 1 2 1 1 1 2 2 2 1 2 1 2 2 1 2 2 1 2 1 2 1 1 2 2 1 2 2 1 2 1 1 2 1 1 2 2 2 2 1 2 1 1 1 1 1 1 1 1 2 1 2 1 1 2 1 2 1 2 2 1 2 1 1 1 2\n",
"output": "83780780\n"
},
{
"input": "10\n1 1 1 1 1 2 1 1 2 1\n",
"output": "68760\n"
},
{
"input": "10\n2 1 2 2 2 2 2 2 2 2\n",
"output": "3628800\n"
},
{
"input": "10\n2 1 1 2 1 2 1 2 2 1\n",
"output": "786240\n"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1\n",
"output": "9496\n"
},
{
"input": "1\n2\n",
"output": "1\n"
},
{
"input": "2\n1 2\n",
"output": "2\n"
},
{
"input": "10\n1 1 1 1 2 1 1 1 1 1\n",
"output": "26200\n"
},
{
"input": "2\n1 1\n",
"output": "2\n"
},
{
"input": "1\n1\n",
"output": "1\n"
}
] |
code_contests
|
python
| 0 |
35a14e8ee06be66da167bee08bc76337
|
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".
For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).
It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again.
Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative.
As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.
We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one.
Input
The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c (0 ≤ c ≤ 106) — its residual viability.
It's guaranteed that each tooth row has positive amount of teeth.
Output
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
Examples
Input
4 3 18
2 3
1 2
3 6
2 3
Output
11
Input
2 2 13
1 13
2 12
Output
13
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n, m, k = list(map(int,input().split()))
tooth = [[0,True]] * n
for i in range(n):
r, c = list(map(int,input().split()))
if tooth[r-1][0] > c or tooth[r-1][1] == True:
tooth[r-1] = [c,False]
ad = 0
for i in tooth:
ad += i[0]
print(min(ad,k))
|
python
|
code_algorithm
|
[
{
"input": "2 2 13\n1 13\n2 12\n",
"output": "13\n"
},
{
"input": "4 3 18\n2 3\n1 2\n3 6\n2 3\n",
"output": "11\n"
},
{
"input": "10 4 14\n2 6\n1 5\n2 8\n2 6\n2 5\n4 1\n4 0\n2 4\n3 4\n1 0\n",
"output": "8\n"
},
{
"input": "4 2 8\n1 9\n1 10\n1 4\n2 6\n",
"output": "8\n"
},
{
"input": "1 1 0\n1 3\n",
"output": "0\n"
},
{
"input": "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3\n",
"output": "8\n"
},
{
"input": "4 3 181818\n3 1299\n1 1694\n3 1164\n2 1278\n",
"output": "4136\n"
},
{
"input": "1 1 1000000\n1 1000000\n",
"output": "1000000\n"
},
{
"input": "50 50 0\n33 0\n26 0\n30 0\n41 0\n38 0\n36 0\n16 0\n7 0\n23 0\n5 0\n39 0\n29 0\n40 0\n47 0\n24 0\n43 0\n14 0\n10 0\n20 0\n3 0\n6 0\n34 0\n13 0\n18 0\n21 0\n9 0\n8 0\n22 0\n25 0\n4 0\n11 0\n17 0\n32 0\n44 0\n49 0\n50 0\n27 0\n28 0\n45 0\n12 0\n35 0\n15 0\n42 0\n31 0\n2 0\n1 0\n48 0\n19 0\n37 0\n46 0\n",
"output": "0\n"
},
{
"input": "19 12 199\n7 1\n8 6\n6 14\n1 7\n4 1\n6 6\n3 4\n1 5\n9 2\n5 3\n11 3\n9 4\n1 12\n4 7\n7 3\n12 14\n2 1\n10 8\n6 12\n",
"output": "54\n"
},
{
"input": "54 22 1009\n15 7\n17 7\n11 9\n5 11\n12 9\n13 8\n13 12\n22 11\n20 9\n20 7\n16 11\n19 12\n3 12\n15 9\n1 12\n2 10\n16 10\n16 10\n14 10\n9 11\n9 9\n14 8\n10 10\n16 12\n1 8\n3 8\n21 11\n18 12\n2 6\n9 11\n11 7\n15 9\n20 11\n6 8\n8 8\n19 11\n15 7\n9 9\n22 7\n12 9\n17 9\n17 11\n12 7\n15 9\n5 11\n11 6\n18 8\n7 10\n4 10\n13 12\n4 8\n20 6\n15 12\n9 7\n",
"output": "180\n"
},
{
"input": "7 1 30\n1 8\n1 15\n1 5\n1 17\n1 9\n1 16\n1 16\n",
"output": "5\n"
}
] |
code_contests
|
python
| 0.1 |
827f506598b217d489bdaf34f82723ff
|
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction).
Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different.
Input
The first line of the input contains n (2 ≤ n ≤ 1000) — number of bidders. The second line contains n distinct integer numbers p1, p2, ... pn, separated by single spaces (1 ≤ pi ≤ 10000), where pi stands for the price offered by the i-th bidder.
Output
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
Examples
Input
2
5 7
Output
2 5
Input
3
10 2 8
Output
1 8
Input
6
3 8 2 9 4 14
Output
6 9
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
a=int(input())
a=list(map(int,input().split()))
ind=a.index(max(a))
a.sort()
print(str(ind+1)+' '+str(a[-2]))
|
python
|
code_algorithm
|
[
{
"input": "6\n3 8 2 9 4 14\n",
"output": "6 9\n"
},
{
"input": "2\n5 7\n",
"output": "2 5\n"
},
{
"input": "3\n10 2 8\n",
"output": "1 8\n"
},
{
"input": "3\n30 20 10\n",
"output": "1 20\n"
},
{
"input": "3\n3 4 1\n",
"output": "2 3\n"
},
{
"input": "3\n30 10 20\n",
"output": "1 20\n"
},
{
"input": "100\n2515 3324 7975 6171 4240 1217 4829 5203 8603 6900 3031 4699 4732 6070 4221 3228 6497 7359 9130 4346 4619 1109 3945 5442 3271 16 9711 2045 6410 2301 3406 8125 6003 1892 1260 9661 3940 6692 4708 7027 4930 6925 1979 5361 4263 3144 867 8639 6230 5562 9714 3676 4231 3347 4733 4920 4881 3431 1059 7313 8912 3038 9308 72 9583 7009 3034 7425 2398 6141 3245 2495 2933 6710 8289 9806 1226 8393 7349 6462 1618 9613 3546 6012 2964 9995 1578 210 2123 4874 1252 8625 348 8020 803 7244 9080 5088 706 2602\n",
"output": "86 9806\n"
},
{
"input": "3\n20 10 30\n",
"output": "3 20\n"
},
{
"input": "5\n3304 4227 4869 6937 6002\n",
"output": "4 6002\n"
},
{
"input": "2\n1 2\n",
"output": "2 1\n"
},
{
"input": "2\n10000 999\n",
"output": "1 999\n"
},
{
"input": "2\n1 10000\n",
"output": "2 1\n"
},
{
"input": "50\n9237 3904 407 9052 6657 9229 9752 3888 7732 2512 4614 1055 2355 7108 6506 6849 2529 8862 159 8630 7906 7941 960 8470 333 8659 54 9475 3163 5625 6393 6814 2656 3388 169 7918 4881 8468 9983 6281 6340 280 5108 2996 101 7617 3313 8172 326 1991\n",
"output": "39 9752\n"
},
{
"input": "7\n9038 6222 3392 1706 3778 1807 2657\n",
"output": "1 6222\n"
},
{
"input": "4\n4707 7586 4221 5842\n",
"output": "2 5842\n"
},
{
"input": "3\n10 30 20\n",
"output": "2 20\n"
},
{
"input": "8\n7062 2194 4481 3864 7470 1814 8091 733\n",
"output": "7 7470\n"
},
{
"input": "2\n2 1\n",
"output": "1 1\n"
},
{
"input": "6\n5083 3289 7708 5362 9031 7458\n",
"output": "5 7708\n"
},
{
"input": "2\n3458 1504\n",
"output": "1 1504\n"
},
{
"input": "3\n20 30 10\n",
"output": "2 20\n"
},
{
"input": "6\n1 2 24 6 5 7\n",
"output": "3 7\n"
},
{
"input": "9\n2678 5659 9199 2628 7906 7496 4524 2663 3408\n",
"output": "3 7906\n"
},
{
"input": "3\n10 20 30\n",
"output": "3 20\n"
}
] |
code_contests
|
python
| 0.9 |
317a195f80e19d6282fb9d63f88a8919
|
Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in order to remember, she takes a notebook with her, called Ryouko's Memory Note. She writes what she sees and what she hears on the notebook, and the notebook became her memory.
Though Ryouko is forgetful, she is also born with superb analyzing abilities. However, analyzing depends greatly on gathered information, in other words, memory. So she has to shuffle through her notebook whenever she needs to analyze, which is tough work.
Ryouko's notebook consists of n pages, numbered from 1 to n. To make life (and this problem) easier, we consider that to turn from page x to page y, |x - y| pages should be turned. During analyzing, Ryouko needs m pieces of information, the i-th piece of information is on page ai. Information must be read from the notebook in order, so the total number of pages that Ryouko needs to turn is <image>.
Ryouko wants to decrease the number of pages that need to be turned. In order to achieve this, she can merge two pages of her notebook. If Ryouko merges page x to page y, she would copy all the information on page x to y (1 ≤ x, y ≤ n), and consequently, all elements in sequence a that was x would become y. Note that x can be equal to y, in which case no changes take place.
Please tell Ryouko the minimum number of pages that she needs to turn. Note she can apply the described operation at most once before the reading. Note that the answer can exceed 32-bit integers.
Input
The first line of input contains two integers n and m (1 ≤ n, m ≤ 105).
The next line contains m integers separated by spaces: a1, a2, ..., am (1 ≤ ai ≤ n).
Output
Print a single integer — the minimum number of pages Ryouko needs to turn.
Examples
Input
4 6
1 2 3 4 3 2
Output
3
Input
10 5
9 4 3 8 8
Output
6
Note
In the first sample, the optimal solution is to merge page 4 to 3, after merging sequence a becomes {1, 2, 3, 3, 3, 2}, so the number of pages Ryouko needs to turn is |1 - 2| + |2 - 3| + |3 - 3| + |3 - 3| + |3 - 2| = 3.
In the second sample, optimal solution is achieved by merging page 9 to 4.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
def median(a):
if len(a) == 0:
return 0
if len(a) % 2 == 1:
return a[len(a) // 2]
else:
return (a[len(a) // 2] + a[(len(a) // 2) - 1]) // 2
def profit(a, old_val):
a.sort()
med = median(a)
sum_old = 0
sum_new = 0
for i in a:
sum_old += abs(i - old_val)
sum_new += abs(i - med)
return sum_old - sum_new
n, m = [int(c) for c in input().split()]
pages = [int(c) for c in input().split()]
count = {pages[0]: []}
current_page_switches = 0
for i in range(1, len(pages)):
cur_i = pages[i]
prev_i = pages[i - 1]
if not(cur_i in count):
count[cur_i] = []
if cur_i != prev_i:
count[cur_i].append(prev_i)
count[prev_i].append(cur_i)
current_page_switches += abs(cur_i - prev_i)
max_profit = 0
for i in count:
if len(count[i]) > 0:
tmp = profit(count[i], i)
if tmp > max_profit:
max_profit = tmp
print(current_page_switches - max_profit)
|
python
|
code_algorithm
|
[
{
"input": "4 6\n1 2 3 4 3 2\n",
"output": "3\n"
},
{
"input": "10 5\n9 4 3 8 8\n",
"output": "6\n"
},
{
"input": "5 10\n2 5 2 2 3 5 3 2 1 3\n",
"output": "7\n"
},
{
"input": "1000 10\n1 1 1 1 1 1000 1000 1000 1000 1000\n",
"output": "0\n"
},
{
"input": "10 20\n6 3 9 6 1 9 1 9 8 2 7 6 9 8 4 7 1 2 4 2\n",
"output": "52\n"
},
{
"input": "100000 1\n14542\n",
"output": "0\n"
},
{
"input": "100000 50\n43104 45692 17950 43454 99127 33540 80887 7990 116 79790 66870 61322 5479 24876 7182 99165 81535 3498 54340 7460 43666 921 1905 68827 79308 59965 8437 13422 40523 59605 39474 22019 65794 40905 35727 78900 41981 91502 66506 1031 92025 84135 19675 67950 81327 95915 92076 89843 43174 73177\n",
"output": "1583927\n"
},
{
"input": "100 6\n1 1 3 3 1 1\n",
"output": "0\n"
},
{
"input": "3 6\n1 1 1 3 3 3\n",
"output": "0\n"
},
{
"input": "2 3\n1 1 2\n",
"output": "0\n"
},
{
"input": "44 44\n22 26 30 41 2 32 7 12 13 22 5 43 33 12 40 14 32 40 3 28 35 26 26 43 3 14 15 16 18 13 42 10 21 19 1 17 34 26 10 40 7 25 20 12\n",
"output": "568\n"
},
{
"input": "10 4\n7 1 1 8\n",
"output": "1\n"
},
{
"input": "3 18\n1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3\n",
"output": "0\n"
},
{
"input": "11 5\n1 1 1 10 11\n",
"output": "1\n"
},
{
"input": "100000 1\n97735\n",
"output": "0\n"
},
{
"input": "1 1\n1\n",
"output": "0\n"
},
{
"input": "100 100\n11 41 76 12 57 12 31 68 92 52 63 40 71 18 69 21 15 27 80 72 69 43 67 37 21 98 36 100 39 93 24 98 6 72 37 33 60 4 38 52 92 60 21 39 65 60 57 87 68 34 23 72 45 13 7 55 81 61 61 49 10 89 52 63 12 21 75 2 69 38 71 35 80 41 1 57 22 60 50 60 40 83 22 70 84 40 61 14 65 93 41 96 51 19 21 36 96 97 12 69\n",
"output": "3302\n"
},
{
"input": "100 100\n28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28\n",
"output": "0\n"
},
{
"input": "100 14\n1 2 100 100 100 100 100 100 100 100 100 100 2 1\n",
"output": "2\n"
},
{
"input": "10 100\n3 2 5 7 1 1 5 10 1 4 7 4 4 10 1 3 8 1 7 4 4 8 5 7 2 10 10 2 2 4 4 5 5 4 8 8 8 9 10 5 1 3 10 3 6 10 6 4 9 10 10 4 10 1 2 5 9 8 9 7 10 9 10 1 6 3 4 7 8 6 3 5 7 10 5 5 8 3 1 2 1 7 6 10 4 4 2 9 9 9 9 8 8 5 4 3 9 7 7 10\n",
"output": "218\n"
},
{
"input": "5 4\n5 5 2 1\n",
"output": "1\n"
},
{
"input": "10 10\n8 8 8 7 7 7 6 1 1 1\n",
"output": "2\n"
}
] |
code_contests
|
python
| 0.4 |
01feb03c75bed6d789189bc90083a719
|
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him.
Input
The first line contains integer n (1 ≤ n ≤ 105) that shows how many numbers are in Alex's sequence.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105).
Output
Print a single integer — the maximum number of points that Alex can earn.
Examples
Input
2
1 2
Output
2
Input
3
1 2 3
Output
4
Input
9
1 2 1 3 2 2 2 2 3
Output
10
Note
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
s=0
n = int(input())
dp=[0]*(10**5+1)
sec = [int(x) for x in input().split()]
ls = [0]*(10**5+1)
for x in sec:
ls[x]+=1
dp[1]=ls[1]
for i in range(2,10**5+1):
dp[i]=max(dp[i-1],dp[i-2]+ls[i]*i)
print(dp[10**5])
|
python
|
code_algorithm
|
[
{
"input": "9\n1 2 1 3 2 2 2 2 3\n",
"output": "10\n"
},
{
"input": "3\n1 2 3\n",
"output": "4\n"
},
{
"input": "2\n1 2\n",
"output": "2\n"
},
{
"input": "5\n3 3 4 5 4\n",
"output": "11\n"
},
{
"input": "10\n8 9 6 5 6 4 10 9 1 4\n",
"output": "39\n"
},
{
"input": "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4\n",
"output": "296\n"
},
{
"input": "100\n7 5 1 8 5 6 6 2 6 2 7 7 3 6 2 4 4 2 10 2 2 2 10 6 6 1 5 10 9 1 5 9 8 9 4 1 10 5 7 5 7 6 4 8 8 1 7 8 3 8 2 1 8 4 10 3 5 6 6 10 9 6 5 1 10 7 6 9 9 2 10 10 9 1 2 1 7 7 4 10 1 10 5 5 3 8 9 8 1 4 10 2 4 5 4 4 1 6 2 9\n",
"output": "328\n"
},
{
"input": "10\n1 7 1 4 9 10 8 2 9 9\n",
"output": "40\n"
},
{
"input": "2\n1 2\n\nSAMPLE",
"output": "2\n"
},
{
"input": "100\n6 1 5 7 10 10 2 7 3 7 2 10 7 6 3 5 5 5 3 7 2 4 2 7 7 4 2 8 2 10 4 7 9 1 1 7 9 7 1 10 10 9 5 6 10 1 7 5 8 1 1 5 3 10 2 4 3 5 2 7 4 9 5 10 1 3 7 6 6 9 3 6 6 10 1 10 6 1 10 3 4 1 7 9 2 7 8 9 3 3 2 4 6 6 1 2 9 4 1 2\n",
"output": "313\n"
},
{
"input": "10\n10 5 8 9 5 6 8 7 2 8\n",
"output": "46\n"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8\n",
"output": "380\n"
},
{
"input": "5\n5 3 5 3 4\n",
"output": "16\n"
},
{
"input": "100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5\n",
"output": "312\n"
},
{
"input": "1\n100000\n",
"output": "100000\n"
},
{
"input": "100\n5 6 10 7 1 7 10 1 9 1 5 1 4 1 3 3 7 9 1 6 1 6 5 7 1 6 3 1 3 6 3 8 2 4 1 5 2 10 7 3 10 4 10 1 5 4 2 9 7 9 5 7 10 4 1 4 8 9 3 1 3 7 7 4 3 7 7 10 6 9 5 5 6 5 3 9 8 8 5 5 4 10 9 4 10 4 1 8 3 5 4 10 9 3 10 4 10 7 10 9\n",
"output": "324\n"
},
{
"input": "100\n10 5 8 4 4 4 1 4 5 8 3 10 2 4 1 10 8 1 1 6 8 4 2 9 1 3 1 7 7 9 3 5 5 8 6 9 9 4 8 1 3 3 2 6 1 5 4 5 3 5 5 6 7 5 7 9 3 5 4 9 2 6 8 1 1 7 7 3 8 9 8 7 3 2 4 1 6 1 3 9 4 2 2 8 5 10 1 8 8 5 1 5 6 9 4 5 6 5 10 2\n",
"output": "265\n"
},
{
"input": "10\n1 1 1 1 1 1 2 3 4 4\n",
"output": "14\n"
},
{
"input": "100\n4 9 7 10 4 7 2 6 1 9 1 8 7 5 5 7 6 7 9 8 10 5 3 5 7 10 3 2 1 3 8 9 4 10 4 7 6 4 9 6 7 1 9 4 3 5 8 9 2 7 10 5 7 5 3 8 10 3 8 9 3 4 3 10 6 5 1 8 3 2 5 8 4 7 5 3 3 2 6 9 9 8 2 7 6 3 2 2 8 8 4 5 6 9 2 3 2 2 5 2\n",
"output": "287\n"
},
{
"input": "100\n7 6 3 8 8 3 10 5 3 8 6 4 6 9 6 7 3 9 10 7 5 5 9 10 7 2 3 8 9 5 4 7 9 3 6 4 9 10 7 6 8 7 6 6 10 3 7 4 5 7 7 5 1 5 4 8 7 3 3 4 7 8 5 9 2 2 3 1 6 4 6 6 6 1 7 10 7 4 5 3 9 2 4 1 5 10 9 3 9 6 8 5 2 1 10 4 8 5 10 9\n",
"output": "298\n"
},
{
"input": "5\n4 2 3 2 5\n",
"output": "9\n"
},
{
"input": "10\n7 4 5 3 9 1 10 3 4 5\n",
"output": "34\n"
}
] |
code_contests
|
python
| 0.6 |
305215dbf1df4fb3940774f0f14bc4df
|
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
* 1+2*3=7
* 1*(2+3)=5
* 1*2*3=6
* (1+2)*3=9
Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given a, b and c print the maximum value that you can get.
Input
The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
Output
Print the maximum value of the expression that you can obtain.
Examples
Input
1
2
3
Output
9
Input
2
10
3
Output
60
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
a1 = int(input())
a2 = int(input())
a3 = int(input())
listValue = [a1*a2*a3, a1*(a2+a3), a1*a2+a3, a1+a2*a3, (a1+a2)*a3, a1+a2+a3]
maxValue = listValue[0]
for x in listValue:
if x > maxValue:
maxValue = x
print(maxValue)
|
python
|
code_algorithm
|
[
{
"input": "2\n10\n3\n",
"output": "60\n"
},
{
"input": "1\n2\n3\n",
"output": "9\n"
},
{
"input": "2\n1\n2\n",
"output": "6\n"
},
{
"input": "5\n6\n1\n",
"output": "35\n"
},
{
"input": "10\n10\n10\n",
"output": "1000\n"
},
{
"input": "8\n9\n7\n",
"output": "504\n"
},
{
"input": "9\n2\n1\n",
"output": "27\n"
},
{
"input": "6\n7\n1\n",
"output": "48\n"
},
{
"input": "1\n2\n1\n",
"output": "4\n"
},
{
"input": "9\n7\n2\n",
"output": "126\n"
},
{
"input": "1\n9\n1\n",
"output": "11\n"
},
{
"input": "10\n1\n1\n",
"output": "20\n"
},
{
"input": "1\n3\n1\n",
"output": "5\n"
},
{
"input": "2\n6\n1\n",
"output": "14\n"
},
{
"input": "2\n8\n3\n",
"output": "48\n"
},
{
"input": "1\n10\n1\n",
"output": "12\n"
},
{
"input": "4\n2\n10\n",
"output": "80\n"
},
{
"input": "3\n1\n5\n",
"output": "20\n"
},
{
"input": "2\n1\n1\n",
"output": "4\n"
},
{
"input": "9\n1\n1\n",
"output": "18\n"
},
{
"input": "1\n1\n10\n",
"output": "20\n"
},
{
"input": "1\n1\n1\n",
"output": "3\n"
},
{
"input": "3\n5\n7\n",
"output": "105\n"
},
{
"input": "5\n1\n3\n",
"output": "20\n"
},
{
"input": "1\n8\n3\n",
"output": "27\n"
},
{
"input": "1\n9\n2\n",
"output": "20\n"
},
{
"input": "10\n5\n6\n",
"output": "300\n"
},
{
"input": "1\n6\n1\n",
"output": "8\n"
},
{
"input": "2\n2\n2\n",
"output": "8\n"
}
] |
code_contests
|
python
| 0.9 |
6611559dfb9a9c0703c856687bc32498
|
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books should be assigned with a number from 1 to n. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
Input
The first line contains integer n (1 ≤ n ≤ 109) — the number of books in the library.
Output
Print the number of digits needed to number all the books.
Examples
Input
13
Output
17
Input
4
Output
4
Note
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n = input()
s = len(n)
'''
9 - 1 1 1 1 1 1 1 1 1
90 - 11 11 11 11 11 11 11 11 11 11 ... 11 11
900 - 111 111 111 111 111 111 111 ... 111 111
9000 - 1111 1111 1111 ... 1111 1111
'''
q = 0
if s > 2:
for c in range(s-1):
v = int('9' + c*'0')
q += v*(c+1)
k = int(n) - (int('1' + (s-1)*'0') - 1)
q += k * s
elif s == 2:
q += 9
k = int(n) - 9
q += k * s
else:
q += s*int(n)
print(q)
|
python
|
code_algorithm
|
[
{
"input": "13\n",
"output": "17\n"
},
{
"input": "4\n",
"output": "4\n"
},
{
"input": "995\n",
"output": "2877\n"
},
{
"input": "100000\n",
"output": "488895\n"
},
{
"input": "10000\n",
"output": "38894\n"
},
{
"input": "99995\n",
"output": "488869\n"
},
{
"input": "100001\n",
"output": "488901\n"
},
{
"input": "1\n",
"output": "1\n"
},
{
"input": "10001\n",
"output": "38899\n"
},
{
"input": "36123011\n",
"output": "277872985\n"
},
{
"input": "290092\n",
"output": "1629447\n"
},
{
"input": "10\n",
"output": "11\n"
},
{
"input": "999999998\n",
"output": "8888888880\n"
},
{
"input": "35\n",
"output": "61\n"
},
{
"input": "996\n",
"output": "2880\n"
},
{
"input": "999\n",
"output": "2889\n"
},
{
"input": "999999999\n",
"output": "8888888889\n"
},
{
"input": "349463\n",
"output": "1985673\n"
},
{
"input": "30660\n",
"output": "142194\n"
},
{
"input": "96482216\n",
"output": "760746625\n"
},
{
"input": "9999\n",
"output": "38889\n"
},
{
"input": "1342\n",
"output": "4261\n"
},
{
"input": "7\n",
"output": "7\n"
},
{
"input": "100\n",
"output": "192\n"
},
{
"input": "100000001\n",
"output": "788888907\n"
},
{
"input": "99\n",
"output": "189\n"
},
{
"input": "99999999\n",
"output": "788888889\n"
},
{
"input": "222222222\n",
"output": "1888888896\n"
},
{
"input": "1000000000\n",
"output": "8888888899\n"
},
{
"input": "986747865\n",
"output": "8769619683\n"
},
{
"input": "999999995\n",
"output": "8888888853\n"
},
{
"input": "9999999\n",
"output": "68888889\n"
},
{
"input": "2156660\n",
"output": "13985516\n"
},
{
"input": "8171970\n",
"output": "56092686\n"
},
{
"input": "8\n",
"output": "8\n"
},
{
"input": "95\n",
"output": "181\n"
},
{
"input": "1001\n",
"output": "2897\n"
},
{
"input": "10000001\n",
"output": "68888905\n"
},
{
"input": "6120\n",
"output": "23373\n"
},
{
"input": "11\n",
"output": "13\n"
},
{
"input": "30140\n",
"output": "139594\n"
},
{
"input": "1000000\n",
"output": "5888896\n"
},
{
"input": "100000000\n",
"output": "788888898\n"
},
{
"input": "943006819\n",
"output": "8375950269\n"
},
{
"input": "313\n",
"output": "831\n"
},
{
"input": "9\n",
"output": "9\n"
},
{
"input": "9995\n",
"output": "38873\n"
},
{
"input": "10000000\n",
"output": "68888897\n"
},
{
"input": "1000\n",
"output": "2893\n"
},
{
"input": "999999\n",
"output": "5888889\n"
},
{
"input": "1000001\n",
"output": "5888903\n"
},
{
"input": "55\n",
"output": "101\n"
},
{
"input": "101\n",
"output": "195\n"
},
{
"input": "99999\n",
"output": "488889\n"
}
] |
code_contests
|
python
| 0.7 |
bace2fad081e0de46be7607b591a96db
|
You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: for example, the string s=";;" contains three empty words separated by ';'.
You should find all words in the given string that are nonnegative INTEGER numbers without leading zeroes and build by them new string a. String a should contain all words that are numbers separating them by ',' (the order of numbers should remain the same as in the string s). By all other words you should build string b in the same way (the order of numbers should remain the same as in the string s).
Here strings "101", "0" are INTEGER numbers, but "01" and "1.0" are not.
For example, for the string aba,123;1a;0 the string a would be equal to "123,0" and string b would be equal to "aba,1a".
Input
The only line of input contains the string s (1 ≤ |s| ≤ 105). The string contains only symbols '.' (ASCII 46), ',' (ASCII 44), ';' (ASCII 59), digits, lowercase and uppercase latin letters.
Output
Print the string a to the first line and string b to the second line. Each string should be surrounded by quotes (ASCII 34).
If there are no words that are numbers print dash (ASCII 45) on the first line. If all words are numbers print dash on the second line.
Examples
Input
aba,123;1a;0
Output
"123,0"
"aba,1a"
Input
1;;01,a0,
Output
"1"
",01,a0,"
Input
1
Output
"1"
-
Input
a
Output
-
"a"
Note
In the second example the string s contains five words: "1", "", "01", "a0", "".
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
def main():
str = input().replace(';', ',')
input_list = str.split(',')
def pred(x):
return x.isdigit() and (x[0] != '0' or len(x) == 1)
lA = list(filter(pred, input_list))
lB = list(filter(lambda x: not pred(x), input_list))
print('"{}"'.format(','.join(lA))) if lA else print("-")
print('"{}"'.format(','.join(lB))) if lB else print("-")
if __name__ == '__main__':
main()
|
python
|
code_algorithm
|
[
{
"input": "1;;01,a0,\n",
"output": "\"1\"\n\",01,a0,\"\n"
},
{
"input": "a\n",
"output": "-\n\"a\"\n"
},
{
"input": "aba,123;1a;0\n",
"output": "\"123,0\"\n\"aba,1a\"\n"
},
{
"input": "1\n",
"output": "\"1\"\n-\n"
},
{
"input": "5345rhhr34t.k;k;k;k;k;5677;000000,000000;000098,0.70k;89.;;;\n",
"output": "\"5677\"\n\"5345rhhr34t.k,k,k,k,k,000000,000000,000098,0.70k,89.,,,\"\n"
},
{
"input": ",2\n",
"output": "\"2\"\n\"\"\n"
},
{
"input": ";\n",
"output": "-\n\",\"\n"
},
{
"input": "00\n",
"output": "-\n\"00\"\n"
},
{
"input": "ashasg,00000,00,;,hahaha,kheng\n",
"output": "-\n\"ashasg,00000,00,,,hahaha,kheng\"\n"
},
{
"input": "01\n",
"output": "-\n\"01\"\n"
},
{
"input": "6;2,\n",
"output": "\"6,2\"\n\"\"\n"
},
{
"input": "000\n",
"output": "-\n\"000\"\n"
},
{
"input": "123456789\n",
"output": "\"123456789\"\n-\n"
},
{
"input": ",;,,;\n",
"output": "-\n\",,,,,\"\n"
},
{
"input": "000.0039255805110943267,0.7362934823735448084,Y3x2yDItgcQYwqPy,0.4300802119053827563\n",
"output": "-\n\"000.0039255805110943267,0.7362934823735448084,Y3x2yDItgcQYwqPy,0.4300802119053827563\"\n"
},
{
"input": ";.,;,.;,.;,.;,.,,.,.,,,,,....;;...;..,,;,aa,00a,01a,0,0.,.,,.0.;10.1;1b1,A,A.n,000000;00,0000.0,0.0000;;;;;;;;...\n",
"output": "\"0\"\n\",.,,,.,,.,,.,,.,,.,.,,,,,....,,...,..,,,,aa,00a,01a,0.,.,,.0.,10.1,1b1,A,A.n,000000,00,0000.0,0.0000,,,,,,,,...\"\n"
},
{
"input": "asbad,0000,00,;,\n",
"output": "-\n\"asbad,0000,00,,,\"\n"
},
{
"input": "123;abacab,123;1,sadasfas,123213132g;02131313;aaa,0,012;0;03242;1\n",
"output": "\"123,123,1,0,0,1\"\n\"abacab,sadasfas,123213132g,02131313,aaa,012,03242\"\n"
},
{
"input": "12345678912345\n",
"output": "\"12345678912345\"\n-\n"
},
{
"input": "0000\n",
"output": "-\n\"0000\"\n"
},
{
"input": "123.123232,123.,.123,..,231.;0.,,.0;;123;123.1;.a\n",
"output": "\"123\"\n\"123.123232,123.,.123,..,231.,0.,,.0,,123.1,.a\"\n"
},
{
"input": "100.000\n",
"output": "-\n\"100.000\"\n"
},
{
"input": "thisisahack\n",
"output": "-\n\"thisisahack\"\n"
},
{
"input": ",,;,;,5345rh;hr;34t.k;k;k0,;,0,;k;k;5677.;000000,000000;000098,000.70k;89.;;;\n",
"output": "\"0\"\n\",,,,,,5345rh,hr,34t.k,k,k0,,,,k,k,5677.,000000,000000,000098,000.70k,89.,,,\"\n"
},
{
"input": "00,0.0;00;0;,,0,0.0.0,,000,010;;\n",
"output": "\"0,0\"\n\"00,0.0,00,,,0.0.0,,000,010,,\"\n"
},
{
"input": ".\n",
"output": "-\n\".\"\n"
}
] |
code_contests
|
python
| 0 |
086ec51b065691b229d9175fd94e3cc9
|
As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup.
<image>
Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start.
After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right.
Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that
<image>
in other words, n is multiplication of all elements of the given array.
Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7.
Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7.
Input
The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you.
The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array.
Output
In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7.
Examples
Input
1
2
Output
1/2
Input
3
1 1 1
Output
0/1
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
k = int(input())
n = list(map(int, input().split()))
for i in range(k):
n[i] = bin(n[i])
n[i] = n[i][2:]
magic = 1000000007
def par(s):
if s[-1] == '0':
return True
else:
return False
def mod_pow(x, s, p):
ans = 1
for i in range(len(s)):
if s[i] == '1':
ans = (((ans * ans) % p) * x) % p
else:
ans = (ans * ans) % p
return ans
def div_in_field(a, b, p):
b_op = pow(b, p - 2, p)
return (b_op * a) % p
denominator = 2
n_par = False
for i in range(len(n)):
denominator = mod_pow(denominator, n[i], magic)
if par(n[i]):
n_par = True
denominator = div_in_field(denominator, 2, magic)
numerator = 0
if n_par:
numerator = div_in_field(1 + denominator, 3, magic)
else:
numerator = div_in_field(-1 + denominator, 3, magic)
ans = str(numerator) + '/' + str(denominator)
print(ans)
|
python
|
code_algorithm
|
[
{
"input": "1\n2\n",
"output": "1/2\n"
},
{
"input": "3\n1 1 1\n",
"output": "0/1\n"
},
{
"input": "1\n983155795040951739\n",
"output": "145599903/436799710\n"
},
{
"input": "12\n254904759290707697 475737283258450340 533306428548398547 442127134828578937 779740159015946254 272877594683860919 93000149670491971 349640818793278778 498293278222136720 551099726729989816 149940343283925029 989425634209891686\n",
"output": "674872752/24618241\n"
},
{
"input": "1\n1000000005\n",
"output": "750000005/250000002\n"
},
{
"input": "1\n1000000006\n",
"output": "500000004/500000004\n"
},
{
"input": "1\n1000000000000000000\n",
"output": "453246046/359738130\n"
},
{
"input": "2\n500000003 500000004\n",
"output": "500000004/500000004\n"
},
{
"input": "10\n217673221404542171 806579927281665969 500754531396239406 214319484250163112 328494187336342674 427465830578952934 951554014286436941 664022909283791499 653206814724654845 66704816231807388\n",
"output": "896298678/688896019\n"
},
{
"input": "1\n500000003\n",
"output": "833333339/500000004\n"
},
{
"input": "2\n1000000005 500000004\n",
"output": "416666670/250000002\n"
},
{
"input": "2\n467131402341701583 956277077729692725\n",
"output": "63467752/190403257\n"
},
{
"input": "2\n500000004 1000000006\n",
"output": "500000004/500000004\n"
},
{
"input": "1\n3\n",
"output": "1/4\n"
},
{
"input": "1\n500000004\n",
"output": "666666672/1\n"
},
{
"input": "2\n500000003 500000003\n",
"output": "833333339/500000004\n"
},
{
"input": "9\n174496219779575399 193634487267697117 972518022554199573 695317701399937273 464007855398119159 881020180696239657 296973121744507377 544232692627163469 751214074246742731\n",
"output": "149736910/449210731\n"
},
{
"input": "1\n1\n",
"output": "0/1\n"
},
{
"input": "8\n137264686188377169 524477139880847337 939966121107073137 244138018261712937 158070587508987781 35608416591331673 378899027510195451 81986819972451999\n",
"output": "993002178/979006521\n"
},
{
"input": "2\n500000004 500000004\n",
"output": "666666672/1\n"
}
] |
code_contests
|
python
| 0 |
e54af3e9e0a525a530e41e74268a81c8
|
In this problem you will write a simple generator of Brainfuck (<https://en.wikipedia.org/wiki/Brainfuck>) calculators.
You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, when executed, will print the result of evaluating this expression.
We use a fairly standard Brainfuck interpreter for checking the programs:
* 30000 memory cells.
* memory cells store integers from 0 to 255 with unsigned 8-bit wraparound.
* console input (, command) is not supported, but it's not needed for this problem.
Input
The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. The calculations result is guaranteed to be an integer between 0 and 255, inclusive (results of intermediary calculations might be outside of these boundaries).
Output
Output a Brainfuck program which, when executed, will print the result of evaluating this expression. The program must be at most 5000000 characters long (including the non-command characters), and its execution must be complete in at most 50000000 steps.
Examples
Input
2+3
Output
++>
+++>
<[<+>-]<
++++++++++++++++++++++++++++++++++++++++++++++++.
Input
9-7
Output
+++++++++>
+++++++>
<[<->-]<
++++++++++++++++++++++++++++++++++++++++++++++++.
Note
You can download the source code of the Brainfuck interpreter by the link [http://assets.codeforces.com/rounds/784/bf.cpp](//assets.codeforces.com/rounds/784/bf.cpp). We use this code to interpret outputs.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
for n in str(eval(input())):
for _ in range(ord(n)):
print('+',sep='',end='')
print('.>')
|
python
|
code_algorithm
|
[
{
"input": "2+3\n",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "9-7\n",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "255-255+255-255+255-255+255-255+255\n",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "255-12-34-56-69-78\n",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "1+1+1\n",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "0+0+0+0+0+0+0+0+0+0\n",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "9+1\n",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "34+45+29-49+52-111-4+4+2+9\n",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "31+49+49+71-51-61+59-111+51\n",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "1+11+111\n",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "255+255+255+255+255-255-255-255-255-255\n",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "10-1\n",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "2+3\n",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "243-173+90-56+78-53+53-21\n",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "100+100+10+10+10+10+10+5\n",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "66-165-34+209+76\n",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "193+235+47+150+222-3-90-248-187-100\n",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "9-7\n",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "0-255-255-255-255+255+255+255+255+255\n",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "111-11-1\n",
"output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "36+90+6+102\n",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
},
{
"input": "1+1-1+1-1+1-1+1-1+1\n",
"output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n"
}
] |
code_contests
|
python
| 0 |
e7c4b72dda38d76e4074df7bae8e7599
|
Array of integers is unimodal, if:
* it is strictly increasing in the beginning;
* after that it is constant;
* after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.
For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6].
Write a program that checks if an array is unimodal.
Input
The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000) — the elements of the array.
Output
Print "YES" if the given array is unimodal. Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
6
1 5 5 5 4 2
Output
YES
Input
5
10 20 30 20 10
Output
YES
Input
4
1 2 1 2
Output
NO
Input
7
3 3 3 3 3 3 3
Output
YES
Note
In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n=int(input())
arr=list(map(int,input().split()))
s,t,p=0,0,0
for i in range(1,n) :
if arr[i] < arr[i - 1]: s = 1
elif arr[i]==arr[i-1] and s: t=1
elif arr[i]==arr[i-1] and not s: p=1
if arr[i]>arr[i-1] and (s or p):t=1
if t: print("NO")
else : print("YES")
|
python
|
code_algorithm
|
[
{
"input": "7\n3 3 3 3 3 3 3\n",
"output": "YES\n"
},
{
"input": "6\n1 5 5 5 4 2\n",
"output": "YES\n"
},
{
"input": "4\n1 2 1 2\n",
"output": "NO\n"
},
{
"input": "5\n10 20 30 20 10\n",
"output": "YES\n"
},
{
"input": "5\n2 2 1 1 1\n",
"output": "NO\n"
},
{
"input": "3\n1 2 3\n",
"output": "YES\n"
},
{
"input": "6\n5 7 11 11 2 1\n",
"output": "YES\n"
},
{
"input": "4\n4 5 5 6\n",
"output": "NO\n"
},
{
"input": "2\n1 3\n",
"output": "YES\n"
},
{
"input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 525 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333\n",
"output": "NO\n"
},
{
"input": "50\n462 465 465 465 463 459 454 449 444 441 436 435 430 429 426 422 421 418 417 412 408 407 406 403 402 399 395 392 387 386 382 380 379 376 374 371 370 365 363 359 358 354 350 349 348 345 342 341 338 337\n",
"output": "YES\n"
},
{
"input": "5\n5 4 3 2 1\n",
"output": "YES\n"
},
{
"input": "2\n1 2\n",
"output": "YES\n"
},
{
"input": "100\n998 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999\n",
"output": "NO\n"
},
{
"input": "4\n1 4 2 3\n",
"output": "NO\n"
},
{
"input": "2\n4 3\n",
"output": "YES\n"
},
{
"input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 333 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475\n",
"output": "YES\n"
},
{
"input": "100\n527 527 527 527 527 527 527 527 872 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527\n",
"output": "NO\n"
},
{
"input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521\n",
"output": "YES\n"
},
{
"input": "3\n3 1 2\n",
"output": "NO\n"
},
{
"input": "5\n1 2 3 4 5\n",
"output": "YES\n"
},
{
"input": "4\n5 5 2 2\n",
"output": "NO\n"
},
{
"input": "2\n3 2\n",
"output": "YES\n"
},
{
"input": "2\n5 4\n",
"output": "YES\n"
},
{
"input": "5\n1 2 3 2 2\n",
"output": "NO\n"
},
{
"input": "1\n1000\n",
"output": "YES\n"
},
{
"input": "2\n4 2\n",
"output": "YES\n"
},
{
"input": "4\n4 4 1 1\n",
"output": "NO\n"
},
{
"input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 431 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333\n",
"output": "YES\n"
},
{
"input": "5\n1 3 3 2 2\n",
"output": "NO\n"
},
{
"input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 363 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496\n",
"output": "YES\n"
},
{
"input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 32 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346\n",
"output": "NO\n"
},
{
"input": "6\n3 3 1 2 2 1\n",
"output": "NO\n"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "NO\n"
},
{
"input": "99\n433 435 439 444 448 452 457 459 460 464 469 470 471 476 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 479 478 477 476 474 469 468 465 460 457 453 452 450 445 443 440 438 433 432 431 430 428 425 421 418 414 411 406 402 397 396 393\n",
"output": "YES\n"
},
{
"input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 208 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521\n",
"output": "NO\n"
},
{
"input": "4\n1 2 3 4\n",
"output": "YES\n"
},
{
"input": "9\n1 2 3 4 4 3 2 2 1\n",
"output": "NO\n"
},
{
"input": "5\n1 2 2 1 1\n",
"output": "NO\n"
},
{
"input": "3\n1 3 2\n",
"output": "YES\n"
},
{
"input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 351 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173\n",
"output": "YES\n"
},
{
"input": "3\n2 1 2\n",
"output": "NO\n"
},
{
"input": "4\n3 3 2 2\n",
"output": "NO\n"
},
{
"input": "2\n2 1\n",
"output": "YES\n"
},
{
"input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 346 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504\n",
"output": "YES\n"
},
{
"input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 498 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271\n",
"output": "YES\n"
},
{
"input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 335 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173\n",
"output": "NO\n"
},
{
"input": "3\n2 2 3\n",
"output": "NO\n"
},
{
"input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 497 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271\n",
"output": "YES\n"
},
{
"input": "100\n527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527\n",
"output": "YES\n"
},
{
"input": "5\n1 2 2 3 5\n",
"output": "NO\n"
},
{
"input": "9\n5 6 6 5 5 4 4 3 3\n",
"output": "NO\n"
},
{
"input": "7\n1 5 5 4 3 3 1\n",
"output": "NO\n"
},
{
"input": "3\n1 1 2\n",
"output": "NO\n"
},
{
"input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 691 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543\n",
"output": "NO\n"
},
{
"input": "15\n452 454 455 455 450 448 443 442 439 436 433 432 431 428 426\n",
"output": "YES\n"
},
{
"input": "3\n516 516 515\n",
"output": "YES\n"
},
{
"input": "6\n1 2 1 2 2 1\n",
"output": "NO\n"
},
{
"input": "5\n5 5 6 6 1\n",
"output": "NO\n"
},
{
"input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 247 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475\n",
"output": "NO\n"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "YES\n"
},
{
"input": "4\n2 2 1 1\n",
"output": "NO\n"
},
{
"input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543\n",
"output": "YES\n"
},
{
"input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 921 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504\n",
"output": "NO\n"
},
{
"input": "3\n2 1 1\n",
"output": "NO\n"
},
{
"input": "4\n5 5 4 4\n",
"output": "NO\n"
},
{
"input": "7\n4 3 3 3 3 3 3\n",
"output": "NO\n"
},
{
"input": "20\n497 501 504 505 509 513 513 513 513 513 513 513 513 513 513 513 513 513 513 513\n",
"output": "YES\n"
},
{
"input": "5\n3 5 4 4 3\n",
"output": "NO\n"
},
{
"input": "5\n4 4 3 2 2\n",
"output": "NO\n"
},
{
"input": "6\n1 5 5 3 2 2\n",
"output": "NO\n"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1\n",
"output": "YES\n"
},
{
"input": "3\n3 2 1\n",
"output": "YES\n"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 99\n",
"output": "YES\n"
},
{
"input": "5\n5 6 6 5 5\n",
"output": "NO\n"
},
{
"input": "3\n5 5 2\n",
"output": "YES\n"
},
{
"input": "3\n4 3 3\n",
"output": "NO\n"
},
{
"input": "4\n3 3 1 1\n",
"output": "NO\n"
},
{
"input": "2\n5 1\n",
"output": "YES\n"
},
{
"input": "100\n1 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "YES\n"
},
{
"input": "10\n538 538 538 538 538 538 538 538 538 538\n",
"output": "YES\n"
},
{
"input": "3\n4 4 2\n",
"output": "YES\n"
},
{
"input": "3\n3 2 2\n",
"output": "NO\n"
},
{
"input": "4\n1 3 2 2\n",
"output": "NO\n"
},
{
"input": "4\n4 4 2 2\n",
"output": "NO\n"
},
{
"input": "3\n2 2 1\n",
"output": "YES\n"
},
{
"input": "1\n7\n",
"output": "YES\n"
},
{
"input": "5\n2 1 3 3 1\n",
"output": "NO\n"
},
{
"input": "7\n1 3 3 3 2 1 1\n",
"output": "NO\n"
},
{
"input": "5\n502 503 508 508 507\n",
"output": "YES\n"
},
{
"input": "6\n2 5 3 3 2 2\n",
"output": "NO\n"
},
{
"input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 497 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346\n",
"output": "YES\n"
},
{
"input": "9\n1 2 2 3 3 4 3 2 1\n",
"output": "NO\n"
},
{
"input": "4\n5 4 3 2\n",
"output": "YES\n"
},
{
"input": "5\n1 2 1 2 1\n",
"output": "NO\n"
},
{
"input": "8\n4 4 4 4 5 6 7 8\n",
"output": "NO\n"
},
{
"input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 119 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496\n",
"output": "NO\n"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "YES\n"
},
{
"input": "5\n3 2 2 1 1\n",
"output": "NO\n"
},
{
"input": "70\n290 292 294 297 299 300 303 305 310 312 313 315 319 320 325 327 328 333 337 339 340 341 345 350 351 354 359 364 367 372 374 379 381 382 383 384 389 393 395 397 398 400 402 405 409 411 416 417 422 424 429 430 434 435 440 442 445 449 451 453 458 460 465 470 474 477 482 482 482 479\n",
"output": "YES\n"
},
{
"input": "5\n5 4 3 3 2\n",
"output": "NO\n"
}
] |
code_contests
|
python
| 0.5 |
b9425b003423c1ec158d18b90cc847f1
|
Due to the recent popularity of the Deep learning new countries are starting to look like Neural Networks. That is, the countries are being built deep with many layers, each layer possibly having many cities. They also have one entry, and one exit point.
There are exactly L layers, each having N cities. Let us look at the two adjacent layers L1 and L2. Each city from the layer L1 is connected to each city from the layer L2 with the traveling cost cij for <image>, and each pair of adjacent layers has the same cost in between their cities as any other pair (they just stacked the same layers, as usual). Also, the traveling costs to each city from the layer L2 are same for all cities in the L1, that is cij is the same for <image>, and fixed j.
Doctor G. needs to speed up his computations for this country so he asks you to find the number of paths he can take from entry to exit point such that his traveling cost is divisible by given number M.
Input
The first line of input contains N (1 ≤ N ≤ 106), L (2 ≤ L ≤ 105) and M (2 ≤ M ≤ 100), the number of cities in each layer, the number of layers and the number that travelling cost should be divisible by, respectively.
Second, third and fourth line contain N integers each denoting costs 0 ≤ cost ≤ M from entry point to the first layer, costs between adjacent layers as described above, and costs from the last layer to the exit point.
Output
Output a single integer, the number of paths Doctor G. can take which have total cost divisible by M, modulo 109 + 7.
Example
Input
2 3 13
4 6
2 1
3 4
Output
2
Note
<image>
This is a country with 3 layers, each layer having 2 cities. Paths <image>, and <image> are the only paths having total cost divisible by 13. Notice that input edges for layer cities have the same cost, and that they are same for all layers.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
from sys import stdin
input = stdin.readline
def main():
mod = 10**9 + 7
n,l,m = map(int,input().split())
ar = [0 for i in range(m)]
ar3 = [0 for i in range(m)]
def f(num):
return int(num) % m
def f2(num):
return num % 1000000007
ai1 = list(map(f,input().split()))
ai2 = list(map(f,input().split()))
ai3 = list(map(f,input().split()))
mm = m**2
ar2 = [0 for i in range(mm)]
def mult(m1,m2):
ans = [0 for i in range(mm)]
m12 = [0 for i in range(m)]
for i in range(m):
for j in range(m):
m12[i] += m1[i+j*m]
for i in range(m):
for j in range(m):
temp = (i+j)%m
for j2 in range(m):
ans[temp+j2*m] += m12[i] * m2[j+j2*m]
ans = list(map(f2,ans))
return ans
def mult2(m1,m2):
ans = [0] * m
for i in range(m):
for j in range(m):
ans[(i+j)%m] += m1[i] * m2[j]
print(ans[0] % mod)
def mult3(m1,m2):
m12 = [0 for i in range(m)]
for i in range(m):
for j in range(m):
m12[i] += m1[i+j*m]
m12[i] %= mod
m22 = [0 for i in range(m)]
for i in range(m):
for j in range(m):
m22[i] += m2[i+j*m]
m22[i] %= mod
ans = [0 for i in range(mm)]
for i in range(m):
for j in range(m):
ans[(i+j)%m] += m12[i] * m22[j]
ans[(i+j)%m] %= mod
return ans
def power(number, n):
n -= 1
if n == -1:
return number
res = number
number2 = [number[i] for i in range(mm)]
while(n):
if n & 1:
res = mult3(res,number)
number = mult3(number,number)
n >>= 1
return mult(res,number2)
for i in range(n):
ar[ai1[i]] += 1
ar2[ai2[i] + ai3[i]* m] += 1
ar3[ai2[i]] += 1
if l == 1:
mult2(ar,ar3)
return
ans = power(ar2,l-2)
ar4 = [0] * m
for i in range(m):
for j in range(m):
ar4[(i+j)%m] += ans[i + j*m]
mult2(ar,ar4)
main()
|
python
|
code_algorithm
|
[
{
"input": "2 3 13\n4 6\n2 1\n3 4\n",
"output": "2\n"
},
{
"input": "5 4 3\n2 1 0 1 2\n0 1 2 1 0\n1 2 1 0 2\n",
"output": "209\n"
},
{
"input": "1 1234 5\n1\n1\n1\n",
"output": "1\n"
},
{
"input": "3 2 2\n0 1 0\n0 0 1\n1 1 0\n",
"output": "3\n"
},
{
"input": "4 4 4\n0 1 3 2\n1 2 0 3\n2 3 1 0\n",
"output": "64\n"
},
{
"input": "2 4 5\n1 1\n1 1\n1 1\n",
"output": "16\n"
}
] |
code_contests
|
python
| 0 |
f0fd20d9641a9dbf3880a35b8bb52517
|
Imp is in a magic forest, where xorangles grow (wut?)
<image>
A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers not exceeding n, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order n to get out of the forest.
Formally, for a given integer n you have to find the number of such triples (a, b, c), that:
* 1 ≤ a ≤ b ≤ c ≤ n;
* <image>, where <image> denotes the [bitwise xor](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of integers x and y.
* (a, b, c) form a non-degenerate (with strictly positive area) triangle.
Input
The only line contains a single integer n (1 ≤ n ≤ 2500).
Output
Print the number of xorangles of order n.
Examples
Input
6
Output
1
Input
10
Output
2
Note
The only xorangle in the first sample is (3, 5, 6).
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import math
n = int(input())
ans = 0
for a in range(1, n+1):
for b in range(a, n+1):
c= a^b
if c < b or c > n:
continue
if a+b > c:
ans += 1
print(ans)
|
python
|
code_algorithm
|
[
{
"input": "6\n",
"output": "1\n"
},
{
"input": "10\n",
"output": "2\n"
},
{
"input": "1051\n",
"output": "145985\n"
},
{
"input": "2498\n",
"output": "699536\n"
},
{
"input": "846\n",
"output": "82106\n"
},
{
"input": "1508\n",
"output": "247634\n"
},
{
"input": "2451\n",
"output": "681980\n"
},
{
"input": "1566\n",
"output": "273341\n"
},
{
"input": "194\n",
"output": "3240\n"
},
{
"input": "952\n",
"output": "118547\n"
},
{
"input": "1322\n",
"output": "183405\n"
},
{
"input": "1946\n",
"output": "529383\n"
},
{
"input": "2444\n",
"output": "679373\n"
},
{
"input": "2\n",
"output": "0\n"
},
{
"input": "1294\n",
"output": "175915\n"
},
{
"input": "1703\n",
"output": "352045\n"
},
{
"input": "1731\n",
"output": "369691\n"
},
{
"input": "1781\n",
"output": "402718\n"
},
{
"input": "1079\n",
"output": "146833\n"
},
{
"input": "2433\n",
"output": "675245\n"
},
{
"input": "2500\n",
"output": "700393\n"
},
{
"input": "857\n",
"output": "85529\n"
},
{
"input": "818\n",
"output": "73972\n"
},
{
"input": "2207\n",
"output": "621708\n"
},
{
"input": "5\n",
"output": "0\n"
},
{
"input": "331\n",
"output": "9877\n"
},
{
"input": "2179\n",
"output": "618074\n"
},
{
"input": "88\n",
"output": "536\n"
},
{
"input": "603\n",
"output": "37312\n"
},
{
"input": "1\n",
"output": "0\n"
},
{
"input": "1965\n",
"output": "545494\n"
},
{
"input": "2394\n",
"output": "663240\n"
},
{
"input": "1040\n",
"output": "145820\n"
},
{
"input": "2218\n",
"output": "623386\n"
},
{
"input": "779\n",
"output": "63500\n"
},
{
"input": "4\n",
"output": "0\n"
},
{
"input": "166\n",
"output": "2200\n"
},
{
"input": "593\n",
"output": "36605\n"
},
{
"input": "1216\n",
"output": "160822\n"
},
{
"input": "116\n",
"output": "1332\n"
},
{
"input": "2140\n",
"output": "614785\n"
},
{
"input": "564\n",
"output": "35087\n"
},
{
"input": "3\n",
"output": "0\n"
},
{
"input": "1488\n",
"output": "239580\n"
}
] |
code_contests
|
python
| 0.3 |
aaab50851ff2af861be866c12dfc5647
|
Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well.
This time Igor K. got disappointed in one of his hobbies: editing and voicing videos. Moreover, he got disappointed in it so much, that he decided to destroy his secret archive for good.
Igor K. use Pindows XR operation system which represents files and folders by small icons. At that, m icons can fit in a horizontal row in any window.
Igor K.'s computer contains n folders in the D: disk's root catalog. The folders are numbered from 1 to n in the order from the left to the right and from top to bottom (see the images). At that the folders with secret videos have numbers from a to b inclusive. Igor K. wants to delete them forever, at that making as few frame selections as possible, and then pressing Shift+Delete exactly once. What is the minimum number of times Igor K. will have to select the folder in order to select folders from a to b and only them? Let us note that if some selected folder is selected repeatedly, then it is deselected. Each selection possesses the shape of some rectangle with sides parallel to the screen's borders.
Input
The only line contains four integers n, m, a, b (1 ≤ n, m ≤ 109, 1 ≤ a ≤ b ≤ n). They are the number of folders in Igor K.'s computer, the width of a window and the numbers of the first and the last folders that need to be deleted.
Output
Print a single number: the least possible number of times Igor K. will have to select the folders using frames to select only the folders with numbers from a to b.
Examples
Input
11 4 3 9
Output
3
Input
20 5 2 20
Output
2
Note
The images below illustrate statement tests.
The first test:
<image>
In this test we can select folders 3 and 4 with out first selection, folders 5, 6, 7, 8 with our second selection and folder 9 with our third, last selection.
The second test:
<image>
In this test we can first select all folders in the first row (2, 3, 4, 5), then — all other ones.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import math
n,m,a,b=map(int,input().split())
if (a-1)//m==(b-1)//m:
print(1)
elif (a-1)%m==0 and b%m==0:
print(1)
elif (a-1)%m==0 and b==n or m==1:
print(1)
elif (a-1)%m==0 or b%m==0 or b==n:
print(2)
elif abs((a-1)//m - (b-1)//m)==1 or m==2:
print(2)
elif (a-1)%m==b%m:
print(2)
else:
print(3)
|
python
|
code_algorithm
|
[
{
"input": "20 5 2 20\n",
"output": "2\n"
},
{
"input": "11 4 3 9\n",
"output": "3\n"
},
{
"input": "28 5 4 26\n",
"output": "3\n"
},
{
"input": "4 3 3 4\n",
"output": "2\n"
},
{
"input": "14 8 2 12\n",
"output": "2\n"
},
{
"input": "7 3 2 6\n",
"output": "2\n"
},
{
"input": "79 8 41 64\n",
"output": "1\n"
},
{
"input": "63 11 23 48\n",
"output": "2\n"
},
{
"input": "51474721 867363452 12231088 43489285\n",
"output": "1\n"
},
{
"input": "7 3 1 3\n",
"output": "1\n"
},
{
"input": "8 3 6 6\n",
"output": "1\n"
},
{
"input": "9 2 4 7\n",
"output": "2\n"
},
{
"input": "7 3 5 7\n",
"output": "2\n"
},
{
"input": "149 49 92 129\n",
"output": "2\n"
},
{
"input": "192293793 2864 5278163 190776899\n",
"output": "3\n"
},
{
"input": "7 3 1 7\n",
"output": "1\n"
},
{
"input": "8 3 1 1\n",
"output": "1\n"
},
{
"input": "8 3 2 8\n",
"output": "2\n"
},
{
"input": "566377385 227 424126063 478693454\n",
"output": "3\n"
},
{
"input": "7 3 4 6\n",
"output": "1\n"
},
{
"input": "20 4 1 20\n",
"output": "1\n"
},
{
"input": "21 5 4 15\n",
"output": "2\n"
},
{
"input": "960442940 572344654 77422042 406189391\n",
"output": "1\n"
},
{
"input": "476 398 77 256\n",
"output": "1\n"
},
{
"input": "908 6 407 531\n",
"output": "3\n"
},
{
"input": "5 5 2 4\n",
"output": "1\n"
},
{
"input": "29 5 12 27\n",
"output": "3\n"
},
{
"input": "21 5 1 21\n",
"output": "1\n"
},
{
"input": "7 3 3 7\n",
"output": "2\n"
},
{
"input": "8 3 2 6\n",
"output": "2\n"
},
{
"input": "7 3 2 4\n",
"output": "2\n"
},
{
"input": "21 5 3 12\n",
"output": "2\n"
},
{
"input": "17 3 1 16\n",
"output": "2\n"
},
{
"input": "30 5 5 29\n",
"output": "2\n"
},
{
"input": "8 3 1 8\n",
"output": "1\n"
},
{
"input": "8 3 1 6\n",
"output": "1\n"
},
{
"input": "446237720 920085248 296916273 439113596\n",
"output": "1\n"
},
{
"input": "8 3 1 4\n",
"output": "2\n"
},
{
"input": "291071313 592207814 6792338 181083636\n",
"output": "1\n"
},
{
"input": "7 3 4 4\n",
"output": "1\n"
},
{
"input": "691 27 313 499\n",
"output": "3\n"
},
{
"input": "886 251 61 672\n",
"output": "3\n"
},
{
"input": "8 3 7 7\n",
"output": "1\n"
},
{
"input": "7 3 1 6\n",
"output": "1\n"
},
{
"input": "8 3 5 6\n",
"output": "1\n"
},
{
"input": "26 5 7 21\n",
"output": "2\n"
},
{
"input": "17 8 3 15\n",
"output": "2\n"
},
{
"input": "8 3 3 7\n",
"output": "3\n"
},
{
"input": "7 3 1 4\n",
"output": "2\n"
},
{
"input": "8 3 4 8\n",
"output": "1\n"
},
{
"input": "357 182 73 247\n",
"output": "2\n"
},
{
"input": "488 519 203 211\n",
"output": "1\n"
},
{
"input": "609162932 300548167 21640850 411089609\n",
"output": "2\n"
},
{
"input": "21 5 1 13\n",
"output": "2\n"
},
{
"input": "7 3 2 5\n",
"output": "2\n"
},
{
"input": "25 2 8 11\n",
"output": "2\n"
},
{
"input": "444819690 3519 48280371 117052060\n",
"output": "3\n"
},
{
"input": "7 3 3 5\n",
"output": "2\n"
},
{
"input": "8 3 1 7\n",
"output": "2\n"
},
{
"input": "17 3 12 16\n",
"output": "3\n"
},
{
"input": "939 42 86 827\n",
"output": "3\n"
},
{
"input": "7 3 2 2\n",
"output": "1\n"
},
{
"input": "16 4 1 16\n",
"output": "1\n"
},
{
"input": "15 8 10 14\n",
"output": "1\n"
},
{
"input": "21 3 6 11\n",
"output": "2\n"
},
{
"input": "12 4 5 8\n",
"output": "1\n"
},
{
"input": "191971162 306112722 18212391 188328807\n",
"output": "1\n"
},
{
"input": "8 3 4 7\n",
"output": "2\n"
},
{
"input": "775589210 6930 266348458 604992807\n",
"output": "3\n"
},
{
"input": "61 1 10 38\n",
"output": "1\n"
},
{
"input": "8 3 5 8\n",
"output": "2\n"
},
{
"input": "100 1 2 15\n",
"output": "1\n"
},
{
"input": "21 5 7 9\n",
"output": "1\n"
},
{
"input": "8 3 3 6\n",
"output": "2\n"
},
{
"input": "244 25 94 199\n",
"output": "3\n"
},
{
"input": "7 3 2 7\n",
"output": "2\n"
},
{
"input": "8 3 3 5\n",
"output": "2\n"
},
{
"input": "7 3 4 5\n",
"output": "1\n"
},
{
"input": "18 4 6 18\n",
"output": "2\n"
},
{
"input": "21 5 9 12\n",
"output": "2\n"
},
{
"input": "733405771 830380469 19971607 389270995\n",
"output": "1\n"
},
{
"input": "7 3 2 3\n",
"output": "1\n"
},
{
"input": "97 9 18 54\n",
"output": "2\n"
},
{
"input": "8 3 6 7\n",
"output": "2\n"
},
{
"input": "19 5 7 19\n",
"output": "2\n"
},
{
"input": "92 54 20 53\n",
"output": "1\n"
},
{
"input": "645010014 34698301 217620581 416292490\n",
"output": "3\n"
},
{
"input": "729584406 8367 456501516 557088265\n",
"output": "3\n"
},
{
"input": "410 36 109 191\n",
"output": "2\n"
},
{
"input": "21 5 4 21\n",
"output": "2\n"
},
{
"input": "491259590 529594367 305425951 326414536\n",
"output": "1\n"
},
{
"input": "7 3 7 7\n",
"output": "1\n"
},
{
"input": "8 3 2 2\n",
"output": "1\n"
},
{
"input": "21 5 1 15\n",
"output": "1\n"
},
{
"input": "8 3 2 7\n",
"output": "2\n"
},
{
"input": "18 100 6 6\n",
"output": "1\n"
},
{
"input": "8 3 6 8\n",
"output": "2\n"
},
{
"input": "8 3 3 4\n",
"output": "2\n"
},
{
"input": "8 3 8 8\n",
"output": "1\n"
},
{
"input": "268836959 6117 166683294 249843000\n",
"output": "3\n"
},
{
"input": "8 3 4 5\n",
"output": "1\n"
},
{
"input": "8 3 3 8\n",
"output": "2\n"
},
{
"input": "8 3 2 3\n",
"output": "1\n"
},
{
"input": "8 3 1 3\n",
"output": "1\n"
},
{
"input": "6 7 5 6\n",
"output": "1\n"
},
{
"input": "12 6 3 10\n",
"output": "2\n"
},
{
"input": "8 3 5 7\n",
"output": "2\n"
},
{
"input": "7 3 5 5\n",
"output": "1\n"
},
{
"input": "21 3 6 10\n",
"output": "3\n"
},
{
"input": "1 1 1 1\n",
"output": "1\n"
},
{
"input": "7 3 6 7\n",
"output": "2\n"
},
{
"input": "7 3 3 4\n",
"output": "2\n"
},
{
"input": "20 4 7 14\n",
"output": "2\n"
},
{
"input": "7 3 5 6\n",
"output": "1\n"
},
{
"input": "41 1 8 27\n",
"output": "1\n"
},
{
"input": "629207296 3735 112288653 309364482\n",
"output": "3\n"
},
{
"input": "21 3 6 8\n",
"output": "2\n"
},
{
"input": "7 3 1 2\n",
"output": "1\n"
},
{
"input": "261 686 243 254\n",
"output": "1\n"
},
{
"input": "280 32 64 277\n",
"output": "3\n"
},
{
"input": "134 110 11 52\n",
"output": "1\n"
},
{
"input": "8 3 7 8\n",
"output": "1\n"
},
{
"input": "21 1 5 17\n",
"output": "1\n"
},
{
"input": "7 3 6 6\n",
"output": "1\n"
},
{
"input": "458 12 203 310\n",
"output": "2\n"
},
{
"input": "484381636 927869638 57278216 175514226\n",
"output": "1\n"
},
{
"input": "75 18 20 23\n",
"output": "1\n"
},
{
"input": "7 3 3 6\n",
"output": "2\n"
},
{
"input": "27 2 5 13\n",
"output": "2\n"
},
{
"input": "6 3 1 6\n",
"output": "1\n"
},
{
"input": "488 655 290 457\n",
"output": "1\n"
},
{
"input": "17 5 6 17\n",
"output": "1\n"
},
{
"input": "11 8 2 7\n",
"output": "1\n"
},
{
"input": "8 3 5 5\n",
"output": "1\n"
},
{
"input": "8 3 4 6\n",
"output": "1\n"
},
{
"input": "264 2 9 63\n",
"output": "2\n"
},
{
"input": "7 3 1 5\n",
"output": "2\n"
},
{
"input": "66 42 43 44\n",
"output": "1\n"
},
{
"input": "7 3 1 1\n",
"output": "1\n"
},
{
"input": "149 334 78 105\n",
"output": "1\n"
},
{
"input": "8 3 4 4\n",
"output": "1\n"
},
{
"input": "70 5 31 33\n",
"output": "1\n"
},
{
"input": "18 2 1 13\n",
"output": "2\n"
},
{
"input": "258 224 84 174\n",
"output": "1\n"
},
{
"input": "27 5 4 24\n",
"output": "3\n"
},
{
"input": "21 3 6 7\n",
"output": "2\n"
},
{
"input": "32 90 31 32\n",
"output": "1\n"
},
{
"input": "5 2 1 5\n",
"output": "1\n"
},
{
"input": "7 3 4 7\n",
"output": "1\n"
},
{
"input": "8 3 2 5\n",
"output": "2\n"
},
{
"input": "38644205 2729 9325777 31658388\n",
"output": "3\n"
},
{
"input": "18 4 6 17\n",
"output": "2\n"
},
{
"input": "8 3 1 2\n",
"output": "1\n"
},
{
"input": "91 2 15 72\n",
"output": "1\n"
},
{
"input": "8 3 3 3\n",
"output": "1\n"
},
{
"input": "21 5 6 18\n",
"output": "2\n"
},
{
"input": "249414894 1999 34827655 127026562\n",
"output": "3\n"
},
{
"input": "10 1 4 5\n",
"output": "1\n"
},
{
"input": "12 4 8 9\n",
"output": "2\n"
},
{
"input": "301 38 97 171\n",
"output": "3\n"
},
{
"input": "15 6 7 15\n",
"output": "1\n"
},
{
"input": "8 3 2 4\n",
"output": "2\n"
},
{
"input": "84 9 6 80\n",
"output": "3\n"
},
{
"input": "21 5 8 14\n",
"output": "2\n"
},
{
"input": "8 3 1 5\n",
"output": "2\n"
},
{
"input": "13 2 1 6\n",
"output": "1\n"
},
{
"input": "7 3 3 3\n",
"output": "1\n"
},
{
"input": "162 309 68 98\n",
"output": "1\n"
},
{
"input": "26 5 2 18\n",
"output": "3\n"
},
{
"input": "831447817 8377 549549158 577671489\n",
"output": "3\n"
}
] |
code_contests
|
python
| 0 |
229e52db7fec0d3c035e798bb882b990
|
Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.
Input
The first line contains a single integer n (1 ≤ n ≤ 50) — the number of elements in Petya's array.
The following line contains a sequence a_1, a_2, ..., a_n (1 ≤ a_i ≤ 1 000) — the Petya's array.
Output
In the first line print integer x — the number of elements which will be left in Petya's array after he removed the duplicates.
In the second line print x integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.
Examples
Input
6
1 5 5 1 6 1
Output
3
5 6 1
Input
5
2 4 2 4 4
Output
2
2 4
Input
5
6 6 6 6 6
Output
1
6
Note
In the first example you should remove two integers 1, which are in the positions 1 and 4. Also you should remove the integer 5, which is in the position 2.
In the second example you should remove integer 2, which is in the position 1, and two integers 4, which are in the positions 2 and 4.
In the third example you should remove four integers 6, which are in the positions 1, 2, 3 and 4.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n = int(input())
A = list(map(int, input().split()))
from collections import Counter
C = Counter(A)
res = []
for a in A:
C[a] -= 1
if C[a] == 0:
res.append(a)
print(len(res))
print(*res)
|
python
|
code_algorithm
|
[
{
"input": "5\n6 6 6 6 6\n",
"output": "1\n6\n"
},
{
"input": "6\n1 5 5 1 6 1\n",
"output": "3\n5 6 1\n"
},
{
"input": "5\n2 4 2 4 4\n",
"output": "2\n2 4\n"
},
{
"input": "28\n997 994 991 994 994 995 1000 992 995 994 994 995 991 996 991 996 991 999 999 993 994 997 995 992 991 992 998 1000\n",
"output": "10\n996 999 993 994 997 995 991 992 998 1000\n"
},
{
"input": "6\n1000 1 1000 2 1 1000\n",
"output": "3\n2 1 1000\n"
},
{
"input": "36\n999 1000 993 993 1000 999 996 997 998 995 995 997 999 995 1000 998 998 994 993 998 994 999 1000 995 996 994 991 991 999 996 993 999 996 998 991 997\n",
"output": "9\n1000 995 994 993 999 996 998 991 997\n"
},
{
"input": "1\n1\n",
"output": "1\n1\n"
},
{
"input": "13\n5 37 375 5 37 33 37 375 37 2 3 3 2\n",
"output": "6\n5 33 375 37 3 2\n"
},
{
"input": "15\n991 995 995 1000 991 993 997 998 1000 994 1000 992 991 995 992\n",
"output": "8\n993 997 998 994 1000 991 995 992\n"
},
{
"input": "50\n1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 4 3 2 5 1 6 6 6 6 6\n",
"output": "6\n4 3 2 5 1 6\n"
},
{
"input": "48\n992 995 992 991 994 992 995 999 996 993 999 995 993 992 1000 992 997 996 991 993 992 998 998 998 999 995 992 992 993 992 992 995 996 995 997 991 997 991 999 994 994 997 1000 998 1000 992 1000 999\n",
"output": "10\n993 996 995 991 994 997 998 992 1000 999\n"
},
{
"input": "49\n991 997 995 991 995 998 994 996 997 991 998 993 992 999 996 995 991 991 999 997 995 993 997 1000 997 993 993 994 999 994 992 991 1000 996 994 996 996 999 992 992 1000 991 997 993 991 994 997 991 996\n",
"output": "10\n998 995 999 992 1000 993 994 997 991 996\n"
},
{
"input": "47\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "1\n1\n"
},
{
"input": "3\n6 6 3\n",
"output": "2\n6 3\n"
},
{
"input": "2\n1000 999\n",
"output": "2\n1000 999\n"
},
{
"input": "9\n100 100 100 99 99 99 100 100 100\n",
"output": "2\n99 100\n"
},
{
"input": "6\n994 993 1000 998 991 994\n",
"output": "5\n993 1000 998 991 994\n"
},
{
"input": "45\n991 991 996 996 992 992 999 1000 998 1000 992 999 996 999 991 991 999 993 992 999 1000 997 992 999 996 991 994 996 991 999 1000 993 999 997 999 992 991 997 991 998 998 995 998 994 993\n",
"output": "10\n996 1000 999 992 997 991 995 998 994 993\n"
},
{
"input": "2\n1000 1000\n",
"output": "1\n1000\n"
},
{
"input": "7\n1 2 3 4 2 2 3\n",
"output": "4\n1 4 2 3\n"
},
{
"input": "47\n233 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "2\n233 1\n"
},
{
"input": "27\n489 489 487 488 750 230 43 645 42 42 489 42 973 42 973 750 645 355 868 112 868 489 750 489 887 489 868\n",
"output": "13\n487 488 230 43 42 973 645 355 112 750 887 489 868\n"
},
{
"input": "40\n151 421 421 909 117 222 909 954 227 421 227 954 954 222 421 227 421 421 421 151 421 227 222 222 222 222 421 183 421 227 421 954 222 421 954 421 222 421 909 421\n",
"output": "8\n117 151 183 227 954 222 909 421\n"
},
{
"input": "48\n2 2 2 903 903 2 726 2 2 2 2 2 2 2 2 2 2 726 2 2 2 2 2 2 2 726 2 2 2 2 62 2 2 2 2 2 2 2 2 726 62 726 2 2 2 903 903 2\n",
"output": "4\n62 726 903 2\n"
},
{
"input": "2\n964 964\n",
"output": "1\n964\n"
},
{
"input": "6\n1000 1 1000 2 1000 1\n",
"output": "3\n2 1000 1\n"
},
{
"input": "1\n1000\n",
"output": "1\n1000\n"
},
{
"input": "7\n1 1000 1 999 1000 1 2\n",
"output": "4\n999 1000 1 2\n"
}
] |
code_contests
|
python
| 0.1 |
bae4dccc2633d4c788ccfbc3727e2fe2
|
On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for each cell of the chessboard you can assign the coordinates (x,y), where x is the column number and y is the row number.
Every day there are fights between black and white pieces on this board. Today, the black ones won, but at what price? Only the rook survived, and it was driven into the lower left corner — a cell with coordinates (1,1). But it is still happy, because the victory has been won and it's time to celebrate it! In order to do this, the rook needs to go home, namely — on the upper side of the field (that is, in any cell that is in the row with number 10^9).
Everything would have been fine, but the treacherous white figures put spells on some places of the field before the end of the game. There are two types of spells:
* Vertical. Each of these is defined by one number x. Such spells create an infinite blocking line between the columns x and x+1.
* Horizontal. Each of these is defined by three numbers x_1, x_2, y. Such spells create a blocking segment that passes through the top side of the cells, which are in the row y and in columns from x_1 to x_2 inclusive. The peculiarity of these spells is that it is impossible for a certain pair of such spells to have a common point. Note that horizontal spells can have common points with vertical spells.
<image> An example of a chessboard.
Let's recall that the rook is a chess piece that in one move can move to any point that is in the same row or column with its initial position. In our task, the rook can move from the cell (r_0,c_0) into the cell (r_1,c_1) only under the condition that r_1 = r_0 or c_1 = c_0 and there is no blocking lines or blocking segments between these cells (For better understanding, look at the samples).
Fortunately, the rook can remove spells, but for this it has to put tremendous efforts, therefore, it wants to remove the minimum possible number of spells in such way, that after this it can return home. Find this number!
Input
The first line contains two integers n and m (0 ≤ n,m ≤ 10^5) — the number of vertical and horizontal spells.
Each of the following n lines contains one integer x (1 ≤ x < 10^9) — the description of the vertical spell. It will create a blocking line between the columns of x and x+1.
Each of the following m lines contains three integers x_1, x_2 and y (1 ≤ x_{1} ≤ x_{2} ≤ 10^9, 1 ≤ y < 10^9) — the numbers that describe the horizontal spell. It will create a blocking segment that passes through the top sides of the cells that are in the row with the number y, in columns from x_1 to x_2 inclusive.
It is guaranteed that all spells are different, as well as the fact that for each pair of horizontal spells it is true that the segments that describe them do not have common points.
Output
In a single line print one integer — the minimum number of spells the rook needs to remove so it can get from the cell (1,1) to at least one cell in the row with the number 10^9
Examples
Input
2 3
6
8
1 5 6
1 9 4
2 4 2
Output
1
Input
1 3
4
1 5 3
1 9 4
4 6 6
Output
1
Input
0 2
1 1000000000 4
1 1000000000 2
Output
2
Input
0 0
Output
0
Input
2 3
4
6
1 4 3
1 5 2
1 6 5
Output
2
Note
In the first sample, in order for the rook return home, it is enough to remove the second horizontal spell.
<image> Illustration for the first sample. On the left it shows how the field looked at the beginning. On the right it shows how the field looked after the deletion of the second horizontal spell. It also shows the path, on which the rook would be going home.
In the second sample, in order for the rook to return home, it is enough to remove the only vertical spell. If we tried to remove just one of the horizontal spells, it would not allow the rook to get home, because it would be blocked from above by one of the remaining horizontal spells (either first one or second one), and to the right it would be blocked by a vertical spell.
<image> Illustration for the second sample. On the left it shows how the field looked at the beginning. On the right it shows how it looked after the deletion of the vertical spell. It also shows the path, on which the rook would be going home.
In the third sample, we have two horizontal spells that go through the whole field. These spells can not be bypassed, so we need to remove both of them.
<image> Illustration for the third sample. On the left it shows how the field looked at the beginning. On the right it shows how the field looked after the deletion of the horizontal spells. It also shows the path, on which the rook would be going home.
In the fourth sample, we have no spells, which means that we do not need to remove anything.
In the fifth example, we can remove the first vertical and third horizontal spells.
<image> Illustration for the fifth sample. On the left it shows how the field looked at the beginning. On the right it shows how it looked after the deletions. It also shows the path, on which the rook would be going home.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
import bisect
n, m = map(int, input().split())
ar1 = [1] + [int(input()) for _ in range(n)]
ar1.append(10 ** 9)
ar1.sort()
ar2 = [list(map(int, input().split())) for _ in range(m)]
kek = list()
for x in ar2:
j1 = bisect.bisect_left(ar1, x[0])
j2 = bisect.bisect_right(ar1, x[1])
if x[0] == 1:
kek.append(j2)
res = [0] * (len(ar1) + 1)
res[0] = len(kek)
for x in kek:
res[x] -= 1
for i in range(1, len(res)):
res[i] += res[i - 1]
min_ = float('inf')
for i in range(1, len(res) - 1):
min_ = min(min_, res[i] + i - 1)
print(min_)
|
python
|
code_algorithm
|
[
{
"input": "1 3\n4\n1 5 3\n1 9 4\n4 6 6\n",
"output": "1\n"
},
{
"input": "0 0\n",
"output": "0\n"
},
{
"input": "0 2\n1 1000000000 4\n1 1000000000 2\n",
"output": "2\n"
},
{
"input": "2 3\n6\n8\n1 5 6\n1 9 4\n2 4 2\n",
"output": "1\n"
},
{
"input": "2 3\n4\n6\n1 4 3\n1 5 2\n1 6 5\n",
"output": "2\n"
},
{
"input": "0 1\n1 999999999 1\n",
"output": "0\n"
},
{
"input": "0 5\n1 96762320 50510976\n243235878 312125306 50510976\n326016273 338641867 50510976\n385105810 445224816 50510976\n456157384 569789185 50510976\n",
"output": "0\n"
},
{
"input": "4 7\n1\n2\n3\n4\n1 1000000000 1\n1 1000000000 2\n1 1000000000 3\n1 1000000000 4\n1 1000000000 5\n1 1000000000 6\n1 1000000000 7\n",
"output": "7\n"
}
] |
code_contests
|
python
| 0 |
09c25a55a89af8eeabe6d9cd4952c958
|
Vasya is preparing a contest, and now he has written a statement for an easy problem. The statement is a string of length n consisting of lowercase Latin latters. Vasya thinks that the statement can be considered hard if it contains a subsequence hard; otherwise the statement is easy. For example, hard, hzazrzd, haaaaard can be considered hard statements, while har, hart and drah are easy statements.
Vasya doesn't want the statement to be hard. He may remove some characters from the statement in order to make it easy. But, of course, some parts of the statement can be crucial to understanding. Initially the ambiguity of the statement is 0, and removing i-th character increases the ambiguity by a_i (the index of each character is considered as it was in the original statement, so, for example, if you delete character r from hard, and then character d, the index of d is still 4 even though you delete it from the string had).
Vasya wants to calculate the minimum ambiguity of the statement, if he removes some characters (possibly zero) so that the statement is easy. Help him to do it!
Recall that subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
Input
The first line contains one integer n (1 ≤ n ≤ 10^5) — the length of the statement.
The second line contains one string s of length n, consisting of lowercase Latin letters — the statement written by Vasya.
The third line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 998244353).
Output
Print minimum possible ambiguity of the statement after Vasya deletes some (possibly zero) characters so the resulting statement is easy.
Examples
Input
6
hhardh
3 2 9 11 7 1
Output
5
Input
8
hhzarwde
3 2 6 9 4 8 7 1
Output
4
Input
6
hhaarr
1 2 3 4 5 6
Output
0
Note
In the first example, first two characters are removed so the result is ardh.
In the second example, 5-th character is removed so the result is hhzawde.
In the third example there's no need to remove anything.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
_ = input()
s = input()
a = list(map(int, input().split()))
hard = "hard"
dp = [0]*4
for i in range(len(s)):
if s[i] == hard[0]:
dp[0] += a[i]
for j in range(1, 4):
if s[i] == hard[j]:
# If same letter, either leave as-is (extend prefix) or remove it
dp[j] = min(dp[j-1], dp[j] + a[i])
print(min(dp))
|
python
|
code_algorithm
|
[
{
"input": "6\nhhaarr\n1 2 3 4 5 6\n",
"output": "0\n"
},
{
"input": "6\nhhardh\n3 2 9 11 7 1\n",
"output": "5\n"
},
{
"input": "8\nhhzarwde\n3 2 6 9 4 8 7 1\n",
"output": "4\n"
},
{
"input": "13\nahrhzhdrrhrra\n129663316 931385006 161287509 358388863 419876340 273873401 62842415 300480437 457244082 211902320 180793874 526023462 380455601\n",
"output": "0\n"
},
{
"input": "3\nxdd\n1 2 3\n",
"output": "0\n"
},
{
"input": "14\nhrdddddzdaahdh\n618683599 53236412 430255850 527201063 76877367 826920910 356360303 624569082 297964311 44495952 517620490 340742688 240436374 571682489\n",
"output": "0\n"
},
{
"input": "24\nrrahadzaazddazzhzzdhraha\n265852838 320169593 970608735 902599099 119386675 144665100 96373679 132726215 209528936 871254634 201034515 906845092 115425177 413968020 890900173 85086595 699910480 453220213 438438250 929633897 921995394 476878031 754757548 672254776\n",
"output": "0\n"
},
{
"input": "25\ndadddhrdhradrdzzzahazaddr\n582987584 956970393 414785252 587245865 701672370 65936511 563890835 69653917 387506178 123924921 989335244 647820709 445085282 809768866 105799145 196558041 783108504 134067229 875977231 488184174 41982468 225574390 702881847 472688490 185455403\n",
"output": "445085282\n"
},
{
"input": "14\nrahhdrzdhrrhzz\n951309899 385220001 934595226 18784743 57310284 511611181 942783561 834145008 478743470 100491136 754890652 172806043 573294593 744178158\n",
"output": "0\n"
},
{
"input": "8\nhhaarrdd\n500000000 500000000 500000000 500000000 500000000 500000000 500000000 500000000\n",
"output": "1000000000\n"
}
] |
code_contests
|
python
| 0 |
9464ffc699ce5184791f5ab06a82c71b
|
Phoenix is picking berries in his backyard. There are n shrubs, and each shrub has a_i red berries and b_i blue berries.
Each basket can contain k berries. But, Phoenix has decided that each basket may only contain berries from the same shrub or berries of the same color (red or blue). In other words, all berries in a basket must be from the same shrub or/and have the same color.
For example, if there are two shrubs with 5 red and 2 blue berries in the first shrub and 2 red and 1 blue berries in the second shrub then Phoenix can fill 2 baskets of capacity 4 completely:
* the first basket will contain 3 red and 1 blue berries from the first shrub;
* the second basket will contain the 2 remaining red berries from the first shrub and 2 red berries from the second shrub.
Help Phoenix determine the maximum number of baskets he can fill completely!
Input
The first line contains two integers n and k ( 1≤ n, k ≤ 500) — the number of shrubs and the basket capacity, respectively.
The i-th of the next n lines contain two integers a_i and b_i (0 ≤ a_i, b_i ≤ 10^9) — the number of red and blue berries in the i-th shrub, respectively.
Output
Output one integer — the maximum number of baskets that Phoenix can fill completely.
Examples
Input
2 4
5 2
2 1
Output
2
Input
1 5
2 3
Output
1
Input
2 5
2 1
1 3
Output
0
Input
1 2
1000000000 1
Output
500000000
Note
The first example is described above.
In the second example, Phoenix can fill one basket fully using all the berries from the first (and only) shrub.
In the third example, Phoenix cannot fill any basket completely because there are less than 5 berries in each shrub, less than 5 total red berries, and less than 5 total blue berries.
In the fourth example, Phoenix can put all the red berries into baskets, leaving an extra blue berry behind.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
n,k=map(int,input().split())
totA=0
totB=0
A=[0]
B=[0]
dp=[]
for i in range(n+1):
h=[]
for j in range(k):
h.append(False)
dp.append(h)
dp[0][0]=True
for i in range(n):
a,b=map(int,input().split())
A.append(a)
B.append(b)
totA+=a
totB+=b
for i in range(1,n+1):
for j in range(k):
dp[i][j]=dp[i-1][(j-(A[i]%k)+k)%k]
for l in range(0,min(k-1,A[i])):
if((A[i]-l)%k + B[i]>=k):
dp[i][j]|=dp[i-1][(j-l)%k]
ans=0
for i in range(k):
if(dp[n][i]):
ans=max(ans,(totA+totB-i)//k)
print(ans)
|
python
|
code_algorithm
|
[
{
"input": "1 5\n2 3\n",
"output": "1\n"
},
{
"input": "1 2\n1000000000 1\n",
"output": "500000000\n"
},
{
"input": "2 4\n5 2\n2 1\n",
"output": "2\n"
},
{
"input": "2 5\n2 1\n1 3\n",
"output": "0\n"
},
{
"input": "3 4\n7 0\n0 3\n3 3\n",
"output": "4\n"
},
{
"input": "1 5\n999999999 1\n",
"output": "200000000\n"
},
{
"input": "5 500\n87 43\n44 29\n15 58\n94 29\n65 7\n",
"output": "0\n"
},
{
"input": "1 5\n0 0\n",
"output": "0\n"
},
{
"input": "5 11\n3 7\n2 10\n4 7\n7 4\n9 2\n",
"output": "5\n"
},
{
"input": "3 5\n1 8\n8 0\n0 8\n",
"output": "4\n"
},
{
"input": "5 7\n4 0\n3 1\n1 6\n6 4\n2 2\n",
"output": "4\n"
},
{
"input": "3 5\n2 2\n1 1\n4 1\n",
"output": "1\n"
},
{
"input": "15 5\n19 6\n10 15\n19 2\n12 17\n13 17\n0 18\n11 13\n4 13\n12 9\n20 9\n8 17\n10 5\n0 1\n3 2\n18 15\n",
"output": "63\n"
},
{
"input": "5 6\n5 8\n2 2\n0 5\n6 2\n10 2\n",
"output": "7\n"
},
{
"input": "1 5\n5 5\n",
"output": "2\n"
},
{
"input": "3 9\n17 17\n15 0\n14 0\n",
"output": "7\n"
},
{
"input": "3 9\n12 9\n9 9\n11 9\n",
"output": "6\n"
},
{
"input": "5 9\n8 1\n5 4\n8 1\n9 0\n7 2\n",
"output": "5\n"
},
{
"input": "5 4\n5 4\n5 3\n4 3\n3 6\n1 4\n",
"output": "9\n"
},
{
"input": "3 7\n6 2\n3 2\n8 2\n",
"output": "3\n"
},
{
"input": "9 61\n52 1\n56 9\n12 18\n1 49\n3 32\n5 53\n56 10\n7 55\n12 59\n",
"output": "8\n"
},
{
"input": "6 9\n0 0\n3 6\n0 0\n0 0\n3 6\n5 4\n",
"output": "3\n"
},
{
"input": "4 6\n2 5\n1 1\n1 2\n1 1\n",
"output": "1\n"
},
{
"input": "4 9\n2 12\n4 9\n5 7\n6 0\n",
"output": "5\n"
},
{
"input": "4 8\n8 7\n1 10\n0 9\n0 13\n",
"output": "6\n"
},
{
"input": "2 5\n3 0\n11 1\n",
"output": "3\n"
},
{
"input": "2 500\n468 32\n748346713 0\n",
"output": "1496694\n"
},
{
"input": "3 10\n3 9\n5 0\n0 5\n",
"output": "1\n"
},
{
"input": "10 8\n19 13\n9 9\n8 3\n4 19\n9 11\n18 14\n5 8\n20 9\n4 10\n8 4\n",
"output": "25\n"
},
{
"input": "3 9\n8 1\n6 3\n6 3\n",
"output": "3\n"
},
{
"input": "3 6\n5 4\n2 1\n3 3\n",
"output": "3\n"
},
{
"input": "3 5\n0 4\n4 2\n0 0\n",
"output": "2\n"
},
{
"input": "4 7\n4 3\n2 5\n2 5\n2 5\n",
"output": "4\n"
},
{
"input": "3 5\n1 5\n5 0\n3 1\n",
"output": "2\n"
},
{
"input": "1 5\n8 7\n",
"output": "3\n"
},
{
"input": "1 5\n2 2\n",
"output": "0\n"
},
{
"input": "20 4\n0 1\n0 2\n0 0\n1 2\n3 2\n1 3\n1 3\n2 0\n3 1\n0 2\n3 3\n2 3\n2 0\n3 2\n1 2\n1 1\n1 1\n1 2\n0 0\n1 3\n",
"output": "14\n"
},
{
"input": "1 5\n4 0\n",
"output": "0\n"
},
{
"input": "3 7\n3 4\n3 4\n6 1\n",
"output": "3\n"
},
{
"input": "3 5\n1 1\n0 2\n7 1\n",
"output": "1\n"
},
{
"input": "4 5\n1 3\n4 6\n4 2\n20 0\n",
"output": "8\n"
},
{
"input": "5 11\n3 8\n3 8\n3 8\n3 8\n3 8\n",
"output": "5\n"
},
{
"input": "2 4\n1 2\n2 7\n",
"output": "2\n"
},
{
"input": "5 4\n2 3\n0 4\n3 0\n3 4\n1 1\n",
"output": "5\n"
},
{
"input": "4 5\n1 4\n2 4\n3 2\n3 1\n",
"output": "4\n"
},
{
"input": "6 10\n5 5\n6 4\n2 0\n4 4\n2 2\n4 4\n",
"output": "4\n"
},
{
"input": "4 8\n11 5\n1 4\n1 4\n1 6\n",
"output": "4\n"
},
{
"input": "3 9\n7 2\n0 0\n5 5\n",
"output": "2\n"
},
{
"input": "11 21\n6 6\n15 3\n15 7\n5 5\n9 7\n2 12\n6 13\n0 5\n4 13\n14 8\n11 3\n",
"output": "7\n"
},
{
"input": "3 10\n2 8\n2 8\n0 1\n",
"output": "2\n"
},
{
"input": "1 5\n5 0\n",
"output": "1\n"
},
{
"input": "3 5\n2 3\n0 3\n6 1\n",
"output": "2\n"
},
{
"input": "6 500\n450 50\n200 300\n50 450\n248 252\n2 0\n0 498\n",
"output": "5\n"
},
{
"input": "5 10\n3 7\n10 0\n2 8\n1 9\n898294589 0\n",
"output": "89829462\n"
}
] |
code_contests
|
python
| 0 |
83da13d3f4793ab42bdbd08c92a16972
|
Consider a conveyor belt represented using a grid consisting of n rows and m columns. The cell in the i-th row from the top and the j-th column from the left is labelled (i,j).
Every cell, except (n,m), has a direction R (Right) or D (Down) assigned to it. If the cell (i,j) is assigned direction R, any luggage kept on that will move to the cell (i,j+1). Similarly, if the cell (i,j) is assigned direction D, any luggage kept on that will move to the cell (i+1,j). If at any moment, the luggage moves out of the grid, it is considered to be lost.
There is a counter at the cell (n,m) from where all luggage is picked. A conveyor belt is called functional if and only if any luggage reaches the counter regardless of which cell it is placed in initially. More formally, for every cell (i,j), any luggage placed in this cell should eventually end up in the cell (n,m).
This may not hold initially; you are, however, allowed to change the directions of some cells to make the conveyor belt functional. Please determine the minimum amount of cells you have to change.
Please note that it is always possible to make any conveyor belt functional by changing the directions of some set of cells.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10). Description of the test cases follows.
The first line of each test case contains two integers n, m (1 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of rows and columns, respectively.
The following n lines each contain m characters. The j-th character in the i-th line, a_{i,j} is the initial direction of the cell (i, j). Please note that a_{n,m}= C.
Output
For each case, output in a new line the minimum number of cells that you have to change to make the conveyor belt functional.
Example
Input
4
3 3
RRD
DDR
RRC
1 4
DDDC
6 9
RDDDDDRRR
RRDDRRDDD
RRDRDRRDR
DDDDRDDRR
DRRDRDDDR
DDRDRRDDC
1 1
C
Output
1
3
9
0
Note
In the first case, just changing the direction of (2,3) to D is enough.
You can verify that the resulting belt is functional. For example, if we place any luggage at (2,2), it first moves to (3,2) and then to (3,3).
In the second case, we have no option but to change the first 3 cells from D to R making the grid equal to RRRC.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
for _ in range(int(input())):
n,m=map(int,input().split())
a,result=[],0
for i in range(n):
a.append(input())
for i in range(n):
if i==n-1:
for k in range(m):
if a[n-1][k]=='D':
a[n-1]=a[i][:k]+'R'+a[i][k+1:]
result += 1
elif a[i][m-1]=='R':
a[i]=a[i][:-1]+'D'
result+=1
print(result)
|
python
|
code_algorithm
|
[
{
"input": "4\n3 3\nRRD\nDDR\nRRC\n1 4\nDDDC\n6 9\nRDDDDDRRR\nRRDDRRDDD\nRRDRDRRDR\nDDDDRDDRR\nDRRDRDDDR\nDDRDRRDDC\n1 1\nC\n",
"output": "1\n3\n9\n0\n"
},
{
"input": "10\n1 1\nC\n1 1\nC\n1 1\nC\n1 1\nC\n1 1\nC\n1 1\nC\n1 1\nC\n1 1\nC\n1 1\nC\n1 1\nC\n",
"output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n"
},
{
"input": "10\n4 4\nDDDD\nDRDR\nDRDD\nDRRC\n4 4\nDDRR\nDDRR\nDDRD\nDRRC\n4 4\nRRDR\nDRRR\nRRRR\nDDRC\n4 4\nDRRR\nRDDD\nDDDR\nRDRC\n4 4\nRDDD\nRRDR\nDDRD\nDRRC\n4 4\nRDRR\nRDRR\nRDDR\nRDDC\n4 4\nDRDD\nDRRR\nDDDD\nDDRC\n4 4\nRDDR\nRRRD\nRRRR\nRRRC\n4 4\nDRRR\nRDRR\nRDDD\nRDRC\n4 4\nRRDR\nDRRD\nRRDR\nDDDC\n",
"output": "2\n3\n5\n3\n2\n5\n3\n2\n3\n5\n"
},
{
"input": "1\n6 4\nRRRR\nRRRR\nRRRR\nRRRR\nRRRR\nRRRC\n",
"output": "5\n"
},
{
"input": "10\n1 2\nRC\n1 2\nDC\n2 1\nR\nC\n2 1\nD\nC\n7 6\nDRDDRR\nRDDDRR\nDRRRDD\nRRDRRR\nDDRRRR\nRRDRDR\nDDRDRC\n8 5\nDRDRD\nDRRRR\nRDRRD\nDDDRR\nRDDRR\nRRDDD\nDDRRR\nDDDRC\n8 3\nDDD\nDDR\nDRD\nRRR\nDRR\nDRD\nRRR\nRDC\n6 6\nDRDDDR\nDDDRDR\nRDDRRD\nDRRRRR\nRRRRRR\nDRDRRC\n6 8\nRRDDDRRR\nRDRDDRRR\nDRRDRRRD\nDRDRRDRR\nDDDDDDDR\nRRDRRDDC\n7 9\nRDDDDRDDR\nDRRRRDRDR\nDDRRDDDRR\nDDDDDRDRR\nDDRDRDDRR\nDRRDDDDRD\nDDDDRRRDC\n",
"output": "0\n1\n1\n0\n8\n7\n5\n6\n7\n10\n"
}
] |
code_contests
|
python
| 0.9 |
40ed700a6f617730bb1388eade0c010f
|
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal a instant damage to him, and then heal that enemy b health points at the end of every second, for exactly c seconds, starting one second after the ability is used. That means that if the ability is used at time t, the enemy's health decreases by a at time t, and then increases by b at time points t + 1, t + 2, ..., t + c due to this ability.
The ability has a cooldown of d seconds, i. e. if Meka-Naruto uses it at time moment t, next time he can use it is the time t + d. Please note that he can only use the ability at integer points in time, so all changes to the enemy's health also occur at integer times only.
The effects from different uses of the ability may stack with each other; that is, the enemy which is currently under k spells gets k⋅ b amount of heal this time. Also, if several health changes occur at the same moment, they are all counted at once.
Now Meka-Naruto wonders if he can kill the enemy by just using the ability each time he can (that is, every d seconds). The enemy is killed if their health points become 0 or less. Assume that the enemy's health is not affected in any way other than by Meka-Naruto's character ability. What is the maximal number of health points the enemy can have so that Meka-Naruto is able to kill them?
Input
The first line contains an integer t (1≤ t≤ 10^5) standing for the number of testcases.
Each test case is described with one line containing four numbers a, b, c and d (1≤ a, b, c, d≤ 10^6) denoting the amount of instant damage, the amount of heal per second, the number of heals and the ability cooldown, respectively.
Output
For each testcase in a separate line print -1 if the skill can kill an enemy hero with an arbitrary number of health points, otherwise print the maximal number of health points of the enemy that can be killed.
Example
Input
7
1 1 1 1
2 2 2 2
1 2 3 4
4 3 2 1
228 21 11 3
239 21 11 3
1000000 1 1000000 1
Output
1
2
1
5
534
-1
500000500000
Note
In the first test case of the example each unit of damage is cancelled in a second, so Meka-Naruto cannot deal more than 1 damage.
In the fourth test case of the example the enemy gets:
* 4 damage (1-st spell cast) at time 0;
* 4 damage (2-nd spell cast) and 3 heal (1-st spell cast) at time 1 (the total of 5 damage to the initial health);
* 4 damage (3-nd spell cast) and 6 heal (1-st and 2-nd spell casts) at time 2 (the total of 3 damage to the initial health);
* and so on.
One can prove that there is no time where the enemy gets the total of 6 damage or more, so the answer is 5. Please note how the health is recalculated: for example, 8-health enemy would not die at time 1, as if we first subtracted 4 damage from his health and then considered him dead, before adding 3 heal.
In the sixth test case an arbitrarily healthy enemy can be killed in a sufficient amount of time.
In the seventh test case the answer does not fit into a 32-bit integer type.
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
Write Python code to solve the problem. Present the code in the code block:
```python
Your code
```
|
# region fastio # from https://codeforces.com/contest/1333/submission/75948789
import sys, io, os
BUFSIZE = 8192
class FastIO(io.IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = io.BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(io.IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#endregion
T = int(input())
for _ in range(T):
A, B, C, D = map(int, input().split())
if C * B < A:
print(-1)
continue
n = A // B // D
ans = A * (n + 1) - n*(n+1)//2 * B*D
#print(f"n={n}")
print(ans)
|
python
|
code_algorithm
|
[
{
"input": "7\n1 1 1 1\n2 2 2 2\n1 2 3 4\n4 3 2 1\n228 21 11 3\n239 21 11 3\n1000000 1 1000000 1\n",
"output": "1\n2\n1\n5\n534\n-1\n500000500000\n"
},
{
"input": "4\n568133 729913 934882 371491\n916127 997180 932938 203988\n112133 793452 857041 842130\n572010 190716 396183 683429\n",
"output": "568133\n916127\n112133\n572010\n"
},
{
"input": "2\n395916 225366 921987 169483\n604656 668976 459504 264596\n",
"output": "395916\n604656\n"
},
{
"input": "1\n1000000 1000000 1 1000000\n",
"output": "1000000\n"
},
{
"input": "6\n879274 712902 672766 383030\n997653 839911 351405 69197\n31160 917403 281506 245835\n234837 489356 452352 448472\n382561 916024 805514 657373\n287796 831046 710305 568719\n",
"output": "879274\n997653\n31160\n234837\n382561\n287796\n"
}
] |
code_contests
|
python
| 0 |
d6a34e5ac982b4af239fe758d7f501f8
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.