text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly k\ \% magic essence and (100 - k)\ \% water.
In one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don't care about the total volume of the potion, only about the ratio between magic essence and water in it.
A small reminder: if you pour e liters of essence and w liters of water (e + w > 0) into the cauldron, then it contains (e)/(e + w) β
100\ \% (without rounding) magic essence and (w)/(e + w) β
100\ \% water.
Input
The first line contains the single t (1 β€ t β€ 100) β the number of test cases.
The first and only line of each test case contains a single integer k (1 β€ k β€ 100) β the percentage of essence in a good potion.
Output
For each test case, print the minimum number of steps to brew a good potion. It can be proved that it's always possible to achieve it in a finite number of steps.
Example
Input
3
3
100
25
Output
100
1
4
Note
In the first test case, you should pour 3 liters of magic essence and 97 liters of water into the cauldron to get a potion with 3\ \% of magic essence.
In the second test case, you can pour only 1 liter of essence to get a potion with 100\ \% of magic essence.
In the third test case, you can pour 1 liter of magic essence and 3 liters of water.
Submitted Solution:
```
import sys
import math
input = sys.stdin.readline
imp = 'IMPOSSIBLE'
t = int(input())
for test in range(t):
k = int(input())
if 100 % k != 0:
print(100)
else:
print(100 // k)
```
No
| 86,900 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything.
At last, after some thought, he thought of something. Let's say there is a word s, consisting of |s| lowercase Latin letters. Then for one operation you can choose a certain position p (1 β€ p < |s|) and perform one of the following actions:
* either replace letter sp with the one that alphabetically follows it and replace letter sp + 1 with the one that alphabetically precedes it;
* or replace letter sp with the one that alphabetically precedes it and replace letter sp + 1 with the one that alphabetically follows it.
Let us note that letter "z" doesn't have a defined following letter and letter "a" doesn't have a defined preceding letter. That's why the corresponding changes are not acceptable. If the operation requires performing at least one unacceptable change, then such operation cannot be performed.
Two words coincide in their meaning iff one of them can be transformed into the other one as a result of zero or more operations.
Sherlock Holmes needs to learn to quickly determine the following for each word: how many words can exist that coincide in their meaning with the given word, but differs from the given word in at least one character? Count this number for him modulo 1000000007 (109 + 7).
Input
The input data contains several tests. The first line contains the only integer t (1 β€ t β€ 104) β the number of tests.
Next t lines contain the words, one per line. Each word consists of lowercase Latin letters and has length from 1 to 100, inclusive. Lengths of words can differ.
Output
For each word you should print the number of different other words that coincide with it in their meaning β not from the words listed in the input data, but from all possible words. As the sought number can be very large, print its value modulo 1000000007 (109 + 7).
Examples
Input
1
ab
Output
1
Input
1
aaaaaaaaaaa
Output
0
Input
2
ya
klmbfxzb
Output
24
320092793
Note
Some explanations about the operation:
* Note that for each letter, we can clearly define the letter that follows it. Letter "b" alphabetically follows letter "a", letter "c" follows letter "b", ..., "z" follows letter "y".
* Preceding letters are defined in the similar manner: letter "y" precedes letter "z", ..., "a" precedes letter "b".
* Note that the operation never changes a word's length.
In the first sample you can obtain the only other word "ba". In the second sample you cannot obtain any other word, so the correct answer is 0.
Consider the third sample. One operation can transform word "klmbfxzb" into word "klmcexzb": we should choose p = 4, and replace the fourth letter with the following one ("b" β "c"), and the fifth one β with the preceding one ("f" β "e"). Also, we can obtain many other words from this one. An operation can transform word "ya" only into one other word "xb".
Word "ya" coincides in its meaning with words "xb", "wc", "vd", ..., "ay" (overall there are 24 other words). The word "klmbfxzb has many more variants β there are 3320092814 other words that coincide with in the meaning. So the answer for the first word equals 24 and for the second one equals 320092793 β the number 3320092814 modulo 109 + 7
Tags: combinatorics, dp
Correct Solution:
```
S, N = 2505, 105
m = 1000000007
k = 26
p = [[0] * (S + k) for i in range(N)]
p[0][0] = 1
for n in range(1, N):
for s in range(S):
p[n][s] = (p[n][s - 1] + p[n - 1][s] - p[n - 1][s - k]) % m
r = []
for j in range(int(input())):
t = input()
s = sum(ord(q) - 97 for q in t)
print(p[len(t)][s] - 1)
```
| 86,901 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything.
At last, after some thought, he thought of something. Let's say there is a word s, consisting of |s| lowercase Latin letters. Then for one operation you can choose a certain position p (1 β€ p < |s|) and perform one of the following actions:
* either replace letter sp with the one that alphabetically follows it and replace letter sp + 1 with the one that alphabetically precedes it;
* or replace letter sp with the one that alphabetically precedes it and replace letter sp + 1 with the one that alphabetically follows it.
Let us note that letter "z" doesn't have a defined following letter and letter "a" doesn't have a defined preceding letter. That's why the corresponding changes are not acceptable. If the operation requires performing at least one unacceptable change, then such operation cannot be performed.
Two words coincide in their meaning iff one of them can be transformed into the other one as a result of zero or more operations.
Sherlock Holmes needs to learn to quickly determine the following for each word: how many words can exist that coincide in their meaning with the given word, but differs from the given word in at least one character? Count this number for him modulo 1000000007 (109 + 7).
Input
The input data contains several tests. The first line contains the only integer t (1 β€ t β€ 104) β the number of tests.
Next t lines contain the words, one per line. Each word consists of lowercase Latin letters and has length from 1 to 100, inclusive. Lengths of words can differ.
Output
For each word you should print the number of different other words that coincide with it in their meaning β not from the words listed in the input data, but from all possible words. As the sought number can be very large, print its value modulo 1000000007 (109 + 7).
Examples
Input
1
ab
Output
1
Input
1
aaaaaaaaaaa
Output
0
Input
2
ya
klmbfxzb
Output
24
320092793
Note
Some explanations about the operation:
* Note that for each letter, we can clearly define the letter that follows it. Letter "b" alphabetically follows letter "a", letter "c" follows letter "b", ..., "z" follows letter "y".
* Preceding letters are defined in the similar manner: letter "y" precedes letter "z", ..., "a" precedes letter "b".
* Note that the operation never changes a word's length.
In the first sample you can obtain the only other word "ba". In the second sample you cannot obtain any other word, so the correct answer is 0.
Consider the third sample. One operation can transform word "klmbfxzb" into word "klmcexzb": we should choose p = 4, and replace the fourth letter with the following one ("b" β "c"), and the fifth one β with the preceding one ("f" β "e"). Also, we can obtain many other words from this one. An operation can transform word "ya" only into one other word "xb".
Word "ya" coincides in its meaning with words "xb", "wc", "vd", ..., "ay" (overall there are 24 other words). The word "klmbfxzb has many more variants β there are 3320092814 other words that coincide with in the meaning. So the answer for the first word equals 24 and for the second one equals 320092793 β the number 3320092814 modulo 109 + 7
Tags: combinatorics, dp
Correct Solution:
```
S, N = 2501, 101
m = 1000000007
k = 26
p = [[0] * (S + k) for i in range(N)]
p[0][0] = 1
for n in range(1, N):
for s in range(S):
p[n][s] = (p[n][s - 1] + p[n - 1][s] - p[n - 1][s - k]) % m
r = []
for j in range(int(input())):
t = input()
s = sum(ord(q) - 97 for q in t)
print(p[len(t)][s] - 1)
```
| 86,902 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything.
At last, after some thought, he thought of something. Let's say there is a word s, consisting of |s| lowercase Latin letters. Then for one operation you can choose a certain position p (1 β€ p < |s|) and perform one of the following actions:
* either replace letter sp with the one that alphabetically follows it and replace letter sp + 1 with the one that alphabetically precedes it;
* or replace letter sp with the one that alphabetically precedes it and replace letter sp + 1 with the one that alphabetically follows it.
Let us note that letter "z" doesn't have a defined following letter and letter "a" doesn't have a defined preceding letter. That's why the corresponding changes are not acceptable. If the operation requires performing at least one unacceptable change, then such operation cannot be performed.
Two words coincide in their meaning iff one of them can be transformed into the other one as a result of zero or more operations.
Sherlock Holmes needs to learn to quickly determine the following for each word: how many words can exist that coincide in their meaning with the given word, but differs from the given word in at least one character? Count this number for him modulo 1000000007 (109 + 7).
Input
The input data contains several tests. The first line contains the only integer t (1 β€ t β€ 104) β the number of tests.
Next t lines contain the words, one per line. Each word consists of lowercase Latin letters and has length from 1 to 100, inclusive. Lengths of words can differ.
Output
For each word you should print the number of different other words that coincide with it in their meaning β not from the words listed in the input data, but from all possible words. As the sought number can be very large, print its value modulo 1000000007 (109 + 7).
Examples
Input
1
ab
Output
1
Input
1
aaaaaaaaaaa
Output
0
Input
2
ya
klmbfxzb
Output
24
320092793
Note
Some explanations about the operation:
* Note that for each letter, we can clearly define the letter that follows it. Letter "b" alphabetically follows letter "a", letter "c" follows letter "b", ..., "z" follows letter "y".
* Preceding letters are defined in the similar manner: letter "y" precedes letter "z", ..., "a" precedes letter "b".
* Note that the operation never changes a word's length.
In the first sample you can obtain the only other word "ba". In the second sample you cannot obtain any other word, so the correct answer is 0.
Consider the third sample. One operation can transform word "klmbfxzb" into word "klmcexzb": we should choose p = 4, and replace the fourth letter with the following one ("b" β "c"), and the fifth one β with the preceding one ("f" β "e"). Also, we can obtain many other words from this one. An operation can transform word "ya" only into one other word "xb".
Word "ya" coincides in its meaning with words "xb", "wc", "vd", ..., "ay" (overall there are 24 other words). The word "klmbfxzb has many more variants β there are 3320092814 other words that coincide with in the meaning. So the answer for the first word equals 24 and for the second one equals 320092793 β the number 3320092814 modulo 109 + 7
Tags: combinatorics, dp
Correct Solution:
```
p = [[0] * 2527 for i in range(101)]
p[0][0] = 1
for n in range(100):
for s in range(2501):
p[n + 1][s] = (p[n + 1][s - 1] + p[n][s] - p[n][s - 26]) % 1000000007
for j in range(int(input())):
t = input()
s = sum(ord(q) - 97 for q in t)
print(p[len(t)][s] - 1)
```
| 86,903 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything.
At last, after some thought, he thought of something. Let's say there is a word s, consisting of |s| lowercase Latin letters. Then for one operation you can choose a certain position p (1 β€ p < |s|) and perform one of the following actions:
* either replace letter sp with the one that alphabetically follows it and replace letter sp + 1 with the one that alphabetically precedes it;
* or replace letter sp with the one that alphabetically precedes it and replace letter sp + 1 with the one that alphabetically follows it.
Let us note that letter "z" doesn't have a defined following letter and letter "a" doesn't have a defined preceding letter. That's why the corresponding changes are not acceptable. If the operation requires performing at least one unacceptable change, then such operation cannot be performed.
Two words coincide in their meaning iff one of them can be transformed into the other one as a result of zero or more operations.
Sherlock Holmes needs to learn to quickly determine the following for each word: how many words can exist that coincide in their meaning with the given word, but differs from the given word in at least one character? Count this number for him modulo 1000000007 (109 + 7).
Input
The input data contains several tests. The first line contains the only integer t (1 β€ t β€ 104) β the number of tests.
Next t lines contain the words, one per line. Each word consists of lowercase Latin letters and has length from 1 to 100, inclusive. Lengths of words can differ.
Output
For each word you should print the number of different other words that coincide with it in their meaning β not from the words listed in the input data, but from all possible words. As the sought number can be very large, print its value modulo 1000000007 (109 + 7).
Examples
Input
1
ab
Output
1
Input
1
aaaaaaaaaaa
Output
0
Input
2
ya
klmbfxzb
Output
24
320092793
Note
Some explanations about the operation:
* Note that for each letter, we can clearly define the letter that follows it. Letter "b" alphabetically follows letter "a", letter "c" follows letter "b", ..., "z" follows letter "y".
* Preceding letters are defined in the similar manner: letter "y" precedes letter "z", ..., "a" precedes letter "b".
* Note that the operation never changes a word's length.
In the first sample you can obtain the only other word "ba". In the second sample you cannot obtain any other word, so the correct answer is 0.
Consider the third sample. One operation can transform word "klmbfxzb" into word "klmcexzb": we should choose p = 4, and replace the fourth letter with the following one ("b" β "c"), and the fifth one β with the preceding one ("f" β "e"). Also, we can obtain many other words from this one. An operation can transform word "ya" only into one other word "xb".
Word "ya" coincides in its meaning with words "xb", "wc", "vd", ..., "ay" (overall there are 24 other words). The word "klmbfxzb has many more variants β there are 3320092814 other words that coincide with in the meaning. So the answer for the first word equals 24 and for the second one equals 320092793 β the number 3320092814 modulo 109 + 7
Submitted Solution:
```
S, N = 2501, 101
m = 1000000007
k = 26
p = [[0] * (S + k) for i in range(N)]
p[0][0] = 1
for n in range(1, N):
for s in range(S):
p[n][s] = (p[n][s - 1] + p[n - 1][s] - p[n - 1][s - k]) % m
d = [0] * S
r = []
for j in range(int(input())):
t = input()
n, s = len(t), sum(ord(q) - 97 for q in t)
d[s] += 1
r.append((n, s))
for n, s in r: print(p[n][s] - d[s])
```
No
| 86,904 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything.
At last, after some thought, he thought of something. Let's say there is a word s, consisting of |s| lowercase Latin letters. Then for one operation you can choose a certain position p (1 β€ p < |s|) and perform one of the following actions:
* either replace letter sp with the one that alphabetically follows it and replace letter sp + 1 with the one that alphabetically precedes it;
* or replace letter sp with the one that alphabetically precedes it and replace letter sp + 1 with the one that alphabetically follows it.
Let us note that letter "z" doesn't have a defined following letter and letter "a" doesn't have a defined preceding letter. That's why the corresponding changes are not acceptable. If the operation requires performing at least one unacceptable change, then such operation cannot be performed.
Two words coincide in their meaning iff one of them can be transformed into the other one as a result of zero or more operations.
Sherlock Holmes needs to learn to quickly determine the following for each word: how many words can exist that coincide in their meaning with the given word, but differs from the given word in at least one character? Count this number for him modulo 1000000007 (109 + 7).
Input
The input data contains several tests. The first line contains the only integer t (1 β€ t β€ 104) β the number of tests.
Next t lines contain the words, one per line. Each word consists of lowercase Latin letters and has length from 1 to 100, inclusive. Lengths of words can differ.
Output
For each word you should print the number of different other words that coincide with it in their meaning β not from the words listed in the input data, but from all possible words. As the sought number can be very large, print its value modulo 1000000007 (109 + 7).
Examples
Input
1
ab
Output
1
Input
1
aaaaaaaaaaa
Output
0
Input
2
ya
klmbfxzb
Output
24
320092793
Note
Some explanations about the operation:
* Note that for each letter, we can clearly define the letter that follows it. Letter "b" alphabetically follows letter "a", letter "c" follows letter "b", ..., "z" follows letter "y".
* Preceding letters are defined in the similar manner: letter "y" precedes letter "z", ..., "a" precedes letter "b".
* Note that the operation never changes a word's length.
In the first sample you can obtain the only other word "ba". In the second sample you cannot obtain any other word, so the correct answer is 0.
Consider the third sample. One operation can transform word "klmbfxzb" into word "klmcexzb": we should choose p = 4, and replace the fourth letter with the following one ("b" β "c"), and the fifth one β with the preceding one ("f" β "e"). Also, we can obtain many other words from this one. An operation can transform word "ya" only into one other word "xb".
Word "ya" coincides in its meaning with words "xb", "wc", "vd", ..., "ay" (overall there are 24 other words). The word "klmbfxzb has many more variants β there are 3320092814 other words that coincide with in the meaning. So the answer for the first word equals 24 and for the second one equals 320092793 β the number 3320092814 modulo 109 + 7
Submitted Solution:
```
S, N = 2505, 105
m = 100000007
k = 26
p = [[0] * (S + k) for i in range(N)]
p[0][0] = 1
for n in range(1, N):
for s in range(S):
p[n][s] = (p[n][s - 1] + p[n - 1][s] - p[n - 1][s - k]) % m
r = []
for j in range(int(input())):
t = input()
s = sum(ord(q) - 97 for q in t)
print(p[len(t)][s] - 1)
```
No
| 86,905 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything.
At last, after some thought, he thought of something. Let's say there is a word s, consisting of |s| lowercase Latin letters. Then for one operation you can choose a certain position p (1 β€ p < |s|) and perform one of the following actions:
* either replace letter sp with the one that alphabetically follows it and replace letter sp + 1 with the one that alphabetically precedes it;
* or replace letter sp with the one that alphabetically precedes it and replace letter sp + 1 with the one that alphabetically follows it.
Let us note that letter "z" doesn't have a defined following letter and letter "a" doesn't have a defined preceding letter. That's why the corresponding changes are not acceptable. If the operation requires performing at least one unacceptable change, then such operation cannot be performed.
Two words coincide in their meaning iff one of them can be transformed into the other one as a result of zero or more operations.
Sherlock Holmes needs to learn to quickly determine the following for each word: how many words can exist that coincide in their meaning with the given word, but differs from the given word in at least one character? Count this number for him modulo 1000000007 (109 + 7).
Input
The input data contains several tests. The first line contains the only integer t (1 β€ t β€ 104) β the number of tests.
Next t lines contain the words, one per line. Each word consists of lowercase Latin letters and has length from 1 to 100, inclusive. Lengths of words can differ.
Output
For each word you should print the number of different other words that coincide with it in their meaning β not from the words listed in the input data, but from all possible words. As the sought number can be very large, print its value modulo 1000000007 (109 + 7).
Examples
Input
1
ab
Output
1
Input
1
aaaaaaaaaaa
Output
0
Input
2
ya
klmbfxzb
Output
24
320092793
Note
Some explanations about the operation:
* Note that for each letter, we can clearly define the letter that follows it. Letter "b" alphabetically follows letter "a", letter "c" follows letter "b", ..., "z" follows letter "y".
* Preceding letters are defined in the similar manner: letter "y" precedes letter "z", ..., "a" precedes letter "b".
* Note that the operation never changes a word's length.
In the first sample you can obtain the only other word "ba". In the second sample you cannot obtain any other word, so the correct answer is 0.
Consider the third sample. One operation can transform word "klmbfxzb" into word "klmcexzb": we should choose p = 4, and replace the fourth letter with the following one ("b" β "c"), and the fifth one β with the preceding one ("f" β "e"). Also, we can obtain many other words from this one. An operation can transform word "ya" only into one other word "xb".
Word "ya" coincides in its meaning with words "xb", "wc", "vd", ..., "ay" (overall there are 24 other words). The word "klmbfxzb has many more variants β there are 3320092814 other words that coincide with in the meaning. So the answer for the first word equals 24 and for the second one equals 320092793 β the number 3320092814 modulo 109 + 7
Submitted Solution:
```
S, N = 2501, 101
m = 1000000007
k = 26
p = [[0] * (S + k) for i in range(N)]
p[0][0] = 1
for n in range(1, N):
for s in range(S):
p[n][s] = (p[n][s - 1] + p[n - 1][s] - p[n - 1][s - k]) % m
d = [0] * (S * N)
r = []
for j in range(int(input())):
t = input()
n, s = len(t), sum(ord(q) - 97 for q in t)
d[s * N + n] += 1
r.append((n, s))
for n, s in r: print(p[n][s] - d[s * N + n])
```
No
| 86,906 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
* climb one area up;
* climb one area down;
* jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall.
If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon.
The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" β first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
The level is considered completed if the ninja manages to get out of the canyon.
After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.
Input
The first line contains two integers n and k (1 β€ n, k β€ 105) β the height of the canyon and the height of ninja's jump, correspondingly.
The second line contains the description of the left wall β a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
The third line describes the right wall in the same format.
It is guaranteed that the first area of the left wall is not dangerous.
Output
Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).
Examples
Input
7 3
---X--X
-X--XX-
Output
YES
Input
6 2
--X-X-
X--XX-
Output
NO
Note
In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
In the second sample there's no way the ninja can get out of the canyon.
Tags: shortest paths
Correct Solution:
```
n, k = map(int, input().split())
lzid = input()
dzid = input()
zidovi = [lzid, dzid]
q = [[-1, [False,0]]] #koraci, [zid, visina]
izasao = 0
bio = [[0 for i in range(n+k+100)], [0 for i in range(n+k+100)]]
while len(q) != 0:
trenutni = q.pop(0)
korak = trenutni[0]
pozicija = trenutni[1]
tren_zid = pozicija[0]
tren_visina = pozicija[1]
if bio[tren_zid][tren_visina] == 0:
bio[tren_zid][tren_visina] = 1
if tren_visina > n-1:
print("YES")
izasao = 1
break
elif tren_visina == n-1 and zidovi[tren_zid][tren_visina] != 'X' and tren_visina > korak:
print("YES")
izasao = 1
break
elif zidovi[tren_zid][tren_visina] != 'X' and tren_visina > korak:
q.append([korak+1, [tren_zid, tren_visina-1]])
q.append([korak+1, [tren_zid, tren_visina+1]])
q.append([korak+1, [not(tren_zid), tren_visina+k]])
## if tren_visina - 1 > korak+1:
## if zidovi[tren_zid][tren_visina-1] != 'X':
## q.append([korak+1, [tren_zid, tren_visina-1]])
## if tren_visina + 1 > korak:
## if tren_visina + k <= n-1:
## if zidovi[tren_zid][tren_visina+1] != 'X':
## q.append([korak+1, [tren_zid, tren_visina+1]])
## else:
## print("YES")
## izasao = 1
## break
## if tren_visina + k > korak:
## if tren_visina + k <= n-1:
## if zidovi[not(tren_zid)][tren_visina+k] != 'X':
## q.append([korak+1, [not(tren_zid), tren_visina+k]])
## else:
## print("YES")
## izasao = 1
if izasao == 0:
print("NO")
```
| 86,907 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
* climb one area up;
* climb one area down;
* jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall.
If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon.
The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" β first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
The level is considered completed if the ninja manages to get out of the canyon.
After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.
Input
The first line contains two integers n and k (1 β€ n, k β€ 105) β the height of the canyon and the height of ninja's jump, correspondingly.
The second line contains the description of the left wall β a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
The third line describes the right wall in the same format.
It is guaranteed that the first area of the left wall is not dangerous.
Output
Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).
Examples
Input
7 3
---X--X
-X--XX-
Output
YES
Input
6 2
--X-X-
X--XX-
Output
NO
Note
In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
In the second sample there's no way the ninja can get out of the canyon.
Tags: shortest paths
Correct Solution:
```
n, k = map(int, input().split())
lzid = input()
dzid = input()
zidovi = [lzid, dzid]
q = [[-1, [False,0]]] #[koraci, [zid, visina]]
izasao = 0
bio = [[0 for i in range(n+k+100)], [0 for i in range(n+k+100)]]
while len(q) != 0:
trenutni = q.pop(0)
korak = trenutni[0]
pozicija = trenutni[1]
tren_zid = pozicija[0]
tren_visina = pozicija[1]
if bio[tren_zid][tren_visina] == 0:
bio[tren_zid][tren_visina] = 1
if tren_visina > n-1:
print("YES")
izasao = 1
break
elif tren_visina == n-1 and zidovi[tren_zid][tren_visina] != 'X' and tren_visina > korak:
print("YES")
izasao = 1
break
elif zidovi[tren_zid][tren_visina] != 'X' and tren_visina > korak:
q.append([korak+1, [tren_zid, tren_visina-1]])
q.append([korak+1, [tren_zid, tren_visina+1]])
q.append([korak+1, [not(tren_zid), tren_visina+k]])
## if tren_visina - 1 > korak+1:
## if zidovi[tren_zid][tren_visina-1] != 'X':
## q.append([korak+1, [tren_zid, tren_visina-1]])
## if tren_visina + 1 > korak:
## if tren_visina + k <= n-1:
## if zidovi[tren_zid][tren_visina+1] != 'X':
## q.append([korak+1, [tren_zid, tren_visina+1]])
## else:
## print("YES")
## izasao = 1
## break
## if tren_visina + k > korak:
## if tren_visina + k <= n-1:
## if zidovi[not(tren_zid)][tren_visina+k] != 'X':
## q.append([korak+1, [not(tren_zid), tren_visina+k]])
## else:
## print("YES")
## izasao = 1
if izasao == 0:
print("NO")
```
| 86,908 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
* climb one area up;
* climb one area down;
* jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall.
If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon.
The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" β first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
The level is considered completed if the ninja manages to get out of the canyon.
After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.
Input
The first line contains two integers n and k (1 β€ n, k β€ 105) β the height of the canyon and the height of ninja's jump, correspondingly.
The second line contains the description of the left wall β a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
The third line describes the right wall in the same format.
It is guaranteed that the first area of the left wall is not dangerous.
Output
Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).
Examples
Input
7 3
---X--X
-X--XX-
Output
YES
Input
6 2
--X-X-
X--XX-
Output
NO
Note
In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
In the second sample there's no way the ninja can get out of the canyon.
Tags: shortest paths
Correct Solution:
```
from sys import stdin, stdout
from collections import deque
n, k = map(int, stdin.readline().split())
maps = []
maps.append(list(stdin.readline() + '-'))
maps.append(list(stdin.readline() + '-'))
visit = [[0, 0] for i in range(n + 1)]
visit[0][0] = 1
queue = deque()
label = 0
queue.append((0, -1, 0))#ΡΠ²ΠΎΠΉ ΡΡΠΎΠ²Π΅Π½Ρ, ΡΡΠΎΠ²Π΅Π½Ρ Π²ΠΎΠ΄Ρ, Π½ΠΎΠΌΠ΅Ρ ΡΡΠ΅Π½Ρ
while queue:
mine, line, num = queue.popleft()
if line >= mine:
continue
if mine + k >= n:
label = 1
if mine + 1 < n and not visit[mine + 1][num] and maps[num][mine + 1] == '-':
queue.append((mine + 1, line + 1, num))
visit[mine + 1][num] = 1
if mine and mine - line > 1 and not visit[mine - 1][num] and maps[num][mine - 1] == '-':
queue.append((mine - 1, line + 1, num))
visit[mine - 1][num] = 1
if mine + k < n and not visit[mine + k][(num + 1) % 2] and maps[(num + 1) % 2][mine + k] == '-':
queue.append((min(mine + k, n), line + 1, (num + 1) % 2))
visit[min(mine + k, n)][(num + 1) % 2] = 1
if label:
stdout.write('YES')
else:
stdout.write('NO')
```
| 86,909 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
* climb one area up;
* climb one area down;
* jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall.
If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon.
The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" β first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
The level is considered completed if the ninja manages to get out of the canyon.
After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.
Input
The first line contains two integers n and k (1 β€ n, k β€ 105) β the height of the canyon and the height of ninja's jump, correspondingly.
The second line contains the description of the left wall β a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
The third line describes the right wall in the same format.
It is guaranteed that the first area of the left wall is not dangerous.
Output
Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).
Examples
Input
7 3
---X--X
-X--XX-
Output
YES
Input
6 2
--X-X-
X--XX-
Output
NO
Note
In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
In the second sample there's no way the ninja can get out of the canyon.
Tags: shortest paths
Correct Solution:
```
from collections import deque
l, j = [int(i) for i in input().split(' ')]
wallA = list(input())
wallB = list(input())
g = {}
for i in range(l):
# Each 4-tuple represents: (Visited?, Current Height, Current Water Height, Drowned?)
if wallA[i] == '-':
g[(1,i+1)] = (-1, 0, 0, False)
if wallB[i] == '-':
g[(-1,i+1)] = (-1, 0, 0, False)
g[(1, 1)] = ('VISITED', 1, 0, False)
q = deque([(1, 1)])
while q:
c = q.popleft()
up = (c[0], c[1]+1)
down = (c[0], c[1]-1)
jump = (c[0]*-1, c[1] + j)
if g[c][1] <= g[c][2]:
g[c] = (g[c][0], g[c][1], g[c][2], True)
if up in g and g[up][0] == -1:
q.append(up)
g[up] = ('VISITED', g[c][1] + 1, g[c][2] + 1, g[c][3])
if down in g and g[down][0] == -1:
q.append(down)
g[down] = ('VISITED', g[c][1] - 1, g[c][2] + 1, g[c][3])
if jump in g and g[jump][0] == -1:
q.append(jump)
g[jump] = ('VISITED', g[c][1] + j, g[c][2] + 1, g[c][3])
def graphHasEscape(graph):
for node in graph:
result = graph[node]
if result[0] == 'VISITED' and ((result[1] + 1 > l) or (result[1] + j > l)) and not result[3]:
return True
break
return False
if graphHasEscape(g):
print('YES')
else:
print('NO')
```
| 86,910 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
* climb one area up;
* climb one area down;
* jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall.
If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon.
The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" β first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
The level is considered completed if the ninja manages to get out of the canyon.
After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.
Input
The first line contains two integers n and k (1 β€ n, k β€ 105) β the height of the canyon and the height of ninja's jump, correspondingly.
The second line contains the description of the left wall β a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
The third line describes the right wall in the same format.
It is guaranteed that the first area of the left wall is not dangerous.
Output
Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).
Examples
Input
7 3
---X--X
-X--XX-
Output
YES
Input
6 2
--X-X-
X--XX-
Output
NO
Note
In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
In the second sample there's no way the ninja can get out of the canyon.
Submitted Solution:
```
n, k = map(int, input().split())
lzid = input()
dzid = input()
zidovi = [lzid, dzid]
q = [[-1, [False,0]]] #[koraci, [zid, visina]]
izasao = 0
while len(q) != 0:
trenutni = q.pop(0)
korak = trenutni[0]
pozicija = trenutni[1]
tren_zid = pozicija[0]
tren_visina = pozicija[1]
print("Korak:", korak)
print("pozicija:", pozicija)
if pozicija[1] == n-1:
print("YES")
izasao = 1
break
if tren_visina - 1 > korak+1:
if zidovi[tren_zid][tren_visina-1] != 'X':
q.append([korak+1, [tren_zid, tren_visina-1]])
if tren_visina + 1 > korak:
if tren_visina + k <= n-1:
if zidovi[tren_zid][tren_visina+1] != 'X':
q.append([korak+1, [tren_zid, tren_visina+1]])
else:
print("YES")
izasao = 1
break
if tren_visina + k > korak:
if tren_visina + k <= n-1:
if zidovi[not(tren_zid)][tren_visina+k] != 'X':
q.append([korak+1, [not(tren_zid), tren_visina+k]])
else:
print("YES")
izasao = 1
if izasao == 0:
print("NO")
```
No
| 86,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
* climb one area up;
* climb one area down;
* jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall.
If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon.
The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" β first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
The level is considered completed if the ninja manages to get out of the canyon.
After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.
Input
The first line contains two integers n and k (1 β€ n, k β€ 105) β the height of the canyon and the height of ninja's jump, correspondingly.
The second line contains the description of the left wall β a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
The third line describes the right wall in the same format.
It is guaranteed that the first area of the left wall is not dangerous.
Output
Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).
Examples
Input
7 3
---X--X
-X--XX-
Output
YES
Input
6 2
--X-X-
X--XX-
Output
NO
Note
In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
In the second sample there's no way the ninja can get out of the canyon.
Submitted Solution:
```
from collections import deque
l, j = [int(i) for i in input().split(' ')]
wallA = list(input())
wallB = list(input())
g = {}
for i in range(l):
# Each 3-tuple represents: (Visited?, Current Height, Current Water Height)
if wallA[i] == '-':
g[(1,i+1)] = (-1, 0, 0)
if wallB[i] == '-':
g[(-1,i+1)] = (-1, 0, 0)
g[(1, 1)] = ('VISITED', 1, 0)
q = deque([(1, 1)])
while q:
c = q.popleft()
up = (c[0], c[1]+1)
down = (c[0], c[1]-1)
jump = (c[0]*-1, c[1] + j)
if c[1] + 1 > l or c[1] + j > l and g[c][2] < c[1]:
print('YES')
break
if c[1] <= g[c][2]:
print('NO')
break
if up in g and g[up][0] == -1:
q.append(up)
g[up] = ('VISITED', g[c][1] + 1, g[c][2] + 1)
if down in g and g[down][0] == -1:
q.append(down)
g[down] = ('VISITED', g[c][1] - 1, g[c][2] + 1)
if jump in g and g[jump][0] == -1:
q.append(jump)
g[jump] = ('VISITED', g[c][1] + j, g[c][2] + 1)
```
No
| 86,912 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
* climb one area up;
* climb one area down;
* jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall.
If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon.
The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" β first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
The level is considered completed if the ninja manages to get out of the canyon.
After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.
Input
The first line contains two integers n and k (1 β€ n, k β€ 105) β the height of the canyon and the height of ninja's jump, correspondingly.
The second line contains the description of the left wall β a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
The third line describes the right wall in the same format.
It is guaranteed that the first area of the left wall is not dangerous.
Output
Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).
Examples
Input
7 3
---X--X
-X--XX-
Output
YES
Input
6 2
--X-X-
X--XX-
Output
NO
Note
In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
In the second sample there's no way the ninja can get out of the canyon.
Submitted Solution:
```
from collections import deque
l, j = [int(i) for i in input().split(' ')]
wallA = list(input())
wallB = list(input())
g = {}
for i in range(l):
# Each 3-tuple represents: (Visited?, Current Height, Current Water Height)
if wallA[i] == '-':
g[(1,i+1)] = (-1, 0, 0)
if wallB[i] == '-':
g[(-1,i+1)] = (-1, 0, 0)
g[(1, 1)] = ('VISITED', 1, 0)
q = deque([(1, 1)])
escape = False
while q:
c = q.popleft()
up = (c[0], c[1]+1)
down = (c[0], c[1]-1)
jump = (c[0]*-1, c[1] + j)
if c[1] + 1 > l or c[1] + j > l and g[c][2] < c[1]:
escape = True
break
if c[1] <= g[c][2]:
break
if up in g and g[up][0] == -1:
q.append(up)
g[up] = ('VISITED', g[c][1] + 1, g[c][2] + 1)
if down in g and g[down][0] == -1:
q.append(down)
g[down] = ('VISITED', g[c][1] - 1, g[c][2] + 1)
if jump in g and g[jump][0] == -1:
q.append(jump)
g[jump] = ('VISITED', g[c][1] + j, g[c][2] + 1)
if escape:
print('YES')
else:
print('NO')
```
No
| 86,913 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is k.
The needs of gene research required information about the quantity of correct n-long chains of the Martian DNA. Your task is to write a program that will calculate this value.
Input
The first line contains three space-separated integers n, m, k (1 β€ n β€ 1015, 1 β€ m β€ 52, 0 β€ k β€ m2).
Next k lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide.
The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z").
It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than m. Note that order is important in nucleotide pairs.
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
Print a single integer β the sought number modulo 1000000007 (109 + 7).
Examples
Input
3 3 2
ab
ba
Output
17
Input
3 3 0
Output
27
Input
2 1 1
aa
Output
0
Note
In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs.
In the third test sample we cannot make any DNA of two nucleotides β the only possible nucleotide "a" cannot occur two times consecutively.
Tags: dp, matrices
Correct Solution:
```
import os
from io import BytesIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
import string
def main():
d = 0
class Matrix():
def __init__(self,ar):
self.ar = ar
def __mul__(self,other):
n = d
m = d
p = d
ans = [[0 for i in range(p)] for i in range(m)]
for i in range(m):
for j in range(p):
for k in range(n):
ans[i][j] += self[i][k] * other[k][j]
ans[i][j] %= mod
return Matrix(ans)
def __mod__(self,other):
m = len(self[0])
for i in range(len(self.ar)):
for j in range(m):
self[i][j] %= other
return self
def __getitem__(self, key):
return self.ar[key]
mod = 10**9 + 7
def power(number, n):
res = number
while(n):
if n & 1:
res *= number
n -= 1
number *= number
n >>= 1
return res
n,m,k = map(int,input().split())
d = m
m2 = Matrix([[1 for i in range(m)]for i in range(m)])
alth = string.ascii_letters
for i in range(k):
s = str(input())
temp = alth.find(s[2])
temp2 = alth.find(s[3])
m2[temp2][temp] = 0
if n == 1:
print(m)
elif n==2:
print(m**2-k)
else:
ar = power(m2,n-2).ar
ans = 0
for i in range(m):
for j in range(m):
ans += ar[i][j]
ans %= mod
print(ans)
main()
```
| 86,914 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is k.
The needs of gene research required information about the quantity of correct n-long chains of the Martian DNA. Your task is to write a program that will calculate this value.
Input
The first line contains three space-separated integers n, m, k (1 β€ n β€ 1015, 1 β€ m β€ 52, 0 β€ k β€ m2).
Next k lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide.
The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z").
It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than m. Note that order is important in nucleotide pairs.
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
Print a single integer β the sought number modulo 1000000007 (109 + 7).
Examples
Input
3 3 2
ab
ba
Output
17
Input
3 3 0
Output
27
Input
2 1 1
aa
Output
0
Note
In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs.
In the third test sample we cannot make any DNA of two nucleotides β the only possible nucleotide "a" cannot occur two times consecutively.
Tags: dp, matrices
Correct Solution:
```
import sys
def pyes_no(condition) :
if condition :
print ("YES")
else :
print ("NO")
def plist(a, s = ' ') :
print (s.join(map(str, a)))
def rint() :
return int(sys.stdin.readline())
def rints() :
return map(int, sys.stdin.readline().split())
def rfield(n, m = None) :
if m == None :
m = n
field = []
for i in xrange(n) :
chars = sys.stdin.readline().strip()
assert(len(chars) == m)
field.append(chars)
return field
def pfield(field, separator = '') :
print ('\n'.join(map(lambda x: separator.join(x), field)))
def check_field_equal(field, i, j, value) :
if i >= 0 and i < len(field) and j >= 0 and j < len(field[i]) :
return value == field[i][j]
return None
def digits(x, p) :
digits = []
while x > 0 :
digits.append(x % p)
x /= p
return digits
def modpower(a, n, mod) :
r = a ** (n % 2)
if n > 1 :
r *= modpower(a, n / 2, mod) ** 2
return r % mod
def modmatrixproduct(a, b, mod) :
n, m1 = len(a), len(a[0])
m2, k = len(b), len(b[0])
assert(m1 == m2)
m = m1
r = [[0] * k for i in range(n)]
for i in range(n) :
for j in range(k) :
for l in range(m) :
r[i][j] += a[i][l] * b[l][j]
r[i][j] %= mod
return r
def modmatrixpower(a, n, mod) :
magic = 2
for m in [2, 3, 5, 7] :
if n % m == 0 :
magic = m
break
r = None
if n < magic :
r = a
n -= 1
else :
s = modmatrixpower(a, n // magic, mod)
r = s
for i in range(magic - 1) :
r = modmatrixproduct(r, s, mod)
for i in range(n % magic) :
r = modmatrixproduct(r, a, mod)
return r
def gcd(a, b) :
if a > b :
a, b = b, a
while a > 0 :
a, b = b % a, a
return b
n, m, k = rints()
charn = dict(zip('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', range(52)))
matrix = [[1] * m for i in range(m)]
for i in range(k) :
a, b = map(lambda c: charn[c], list(sys.stdin.readline().strip()))
matrix[a][b] = 0
mod = 1000000007
if n > 1 :
matrix = modmatrixpower(matrix, n - 1, mod)
results = modmatrixproduct([[1] * m], matrix, mod)
print (sum(map(sum, results)) % mod)
else :
print (m)
```
| 86,915 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is k.
The needs of gene research required information about the quantity of correct n-long chains of the Martian DNA. Your task is to write a program that will calculate this value.
Input
The first line contains three space-separated integers n, m, k (1 β€ n β€ 1015, 1 β€ m β€ 52, 0 β€ k β€ m2).
Next k lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide.
The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z").
It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than m. Note that order is important in nucleotide pairs.
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
Print a single integer β the sought number modulo 1000000007 (109 + 7).
Examples
Input
3 3 2
ab
ba
Output
17
Input
3 3 0
Output
27
Input
2 1 1
aa
Output
0
Note
In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs.
In the third test sample we cannot make any DNA of two nucleotides β the only possible nucleotide "a" cannot occur two times consecutively.
Submitted Solution:
```
# How many ways to generate length-N array where elements can take one of m values (m <= 52; denoted a..z,A..Z)
# s.t. none of k ordered value pair appears:
# e.g. ab = ab can't appear but ba can; aa = aa can't appear
# Input: N (N < 10^18), m (n<=52), k patterns 0 <= k <= m^2
# E.g.
# N=3, m=3, k=2
# ab
# ba
# -> return 17
# Ideas
# * divide and conquer
# * for each n, memo[n][i][j] = number of paths of length n satisfying bans, that start at i and end at j
MOD = 1000000007
memo = {}
def _solve(n, m, ban):
if n in memo: return memo[n]
if n == 0: return [[0]*m for _ in range(m)]
if n == 1:
memo[n] = [[0]*m for _ in range(m)]
for i in range(m):
memo[n][i][i] = 1
return memo[n]
left, right = _solve(n // 2, m, ban), _solve(n - n // 2, m, ban)
memo[n] = [[0]*m for _ in range(m)]
# count all paths starting at i, ending at j
si, sj = [0]*m, [0]*m
for i in range(m):
si[i] = sum(left[i]) % MOD
for j in range(m):
sj[j] = sum(right[s][j] for s in range(m)) % MOD
for i in range(m):
for j in range(m):
memo[n][i][j] = si[i]*sj[j]%MOD
# subtract left path ending at x * right path ending at y for each banned pair (x, y)
si, sj = [0]*m, [0]*m
for i in range(m):
si[i] = sum(left[s][i] for s in range(m))
for j in range(m):
sj[j] = sum(right[j]) % MOD
for x, y in ban:
memo[n][i][j] -= si[x] * sj[y] % MOD
memo[n][i][j] %= MOD
return memo[n]
def solve(n, m, ban):
counts = _solve(n, m, ban)
return sum(sum(row) for row in counts)%MOD
def main():
from sys import stdin
n, m, k = list(map(int, stdin.readline().strip().split()))
ban = set()
for _ in range(k):
x, y = list(stdin.readline().strip())
x = ord(x)-97 if 'a' <= x <= 'z' else ord(x)-39
y = ord(y)-97 if 'a' <= y <= 'z' else ord(y)-39
ban.add((x,y))
out = solve(n, m, ban)
print('{}'.format(out))
if __name__ == '__main__':
main()
```
No
| 86,916 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is k.
The needs of gene research required information about the quantity of correct n-long chains of the Martian DNA. Your task is to write a program that will calculate this value.
Input
The first line contains three space-separated integers n, m, k (1 β€ n β€ 1015, 1 β€ m β€ 52, 0 β€ k β€ m2).
Next k lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide.
The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z").
It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than m. Note that order is important in nucleotide pairs.
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
Print a single integer β the sought number modulo 1000000007 (109 + 7).
Examples
Input
3 3 2
ab
ba
Output
17
Input
3 3 0
Output
27
Input
2 1 1
aa
Output
0
Note
In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs.
In the third test sample we cannot make any DNA of two nucleotides β the only possible nucleotide "a" cannot occur two times consecutively.
Submitted Solution:
```
import math
__author__ = 'esadeqia'
import operator
def toInd(c):
if c.islower():
return ord(c)-ord('a')
elif c.isupper():
return ord(c)-ord('A')+26
def toInd(c):
x=ord(c)
if ord('a')<=x and x<=ord('z'):
return x-ord('a')
elif ord('A')<=x and x<=ord('Z'):
return x-ord('A')+26
def emptyMatrix(a,b,value=None):
return [[value]*b for j in range(a)]
def eyeMatrix(a):
return [[0]*j+[1]+[0]*(a-j-1) for j in range(a)]
def multiply(A,B,p):
C=emptyMatrix(len(A),len(B[0]))
for i in range(len(A)):
for j in range(len(B[0])):
t=0
for k in range(len(B)):
t+=(A[i][k]*B[k][j])
C[i][j]=t%p
return C
def fourSplits(M):
horizontal=int(len(M)/2)
vertical=int(len(M[0])/2)
up=M[:horizontal]
down=M[horizontal:]
return (([x[:vertical] for x in up],
[x[vertical:] for x in up]),
([x[:vertical] for x in down],
[x[vertical:] for x in down]))
def addMatrix(A,B):
return [list(map(operator.add, A[i], B[i])) for i in range(len(A))]
def subMatrix(A,B):
assert len(A)==len(B)
return [
list(
map(
operator.sub, A[i], B[i]))
for i in range(len(A))]
def allResidual(M,p):
return [[x%p for x in y] for y in M]
def strassen(A,B,p):
if len(A)<2 or len(B)<2 or len(B[0])<2:
return multiply(A,B,p)
As=fourSplits(A)
Bs=fourSplits(B)
m=[None]*8
m[1]=strassen(addMatrix(As[0][0],As[1][1]), addMatrix(Bs[0][0],Bs[1][1]),p)
m[2]=strassen(addMatrix(As[1][0],As[1][1]), Bs[0][0] ,p)
m[3]=strassen( As[0][0] , subMatrix(Bs[0][1],Bs[1][1]) ,p)
m[4]=strassen( As[1][1] , subMatrix(Bs[1][0],Bs[0][0]) ,p)
m[5]=strassen(addMatrix(As[0][0],As[0][1]), Bs[1][1] ,p)
m[6]=strassen(subMatrix(As[1][0],As[0][0]), addMatrix(Bs[0][0],Bs[0][1]),p)
m[7]=strassen(subMatrix(As[0][1],As[1][1]), addMatrix(Bs[1][0],Bs[1][1]),p)
C=emptyMatrix(len(A),len(B[0]))
c11=addMatrix(subMatrix(addMatrix(m[1],m[4]),m[5]),m[7])
c21=addMatrix(m[3],m[5])
c12=addMatrix(m[2],m[4])
c22=addMatrix(addMatrix(subMatrix(m[1],m[2]),m[3]),m[6])
return allResidual(list(map(operator.concat, c11+c12,c21+c22)),p)
def strassenPower(M,n,p):
l=len(M)
newl=int(2**math.ceil(math.log2(l)))
padding=[0]*(newl-l)
M=[x+padding for x in M]
M+=emptyMatrix(newl-l,newl,0)
# print(l,newl)
# print(M)
# exit(0)
powers=M
result=eyeMatrix(len(M))
while n>0:
# print(n)
if n%2==1:
result=strassen(result,powers,p)
powers=strassen(powers,powers,p)
n=n>>1
return result
def fastMethod(n,allowedpairs):
m=len(allowedPairs)
result=strassenPower(allowedPairs,n-1,p)
return sum(map(sum, result))%p
p=1000000007 #(10**9β+β7)
n,m,k=map(int,input().split())
allowedPairs=emptyMatrix(m,m,1)
for i in range(k):
pair=input()
allowedPairs[toInd(pair[0])][toInd(pair[1])]=0
resultMain=fastMethod(n,allowedPairs)
print(resultMain)
```
No
| 86,917 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is k.
The needs of gene research required information about the quantity of correct n-long chains of the Martian DNA. Your task is to write a program that will calculate this value.
Input
The first line contains three space-separated integers n, m, k (1 β€ n β€ 1015, 1 β€ m β€ 52, 0 β€ k β€ m2).
Next k lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide.
The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z").
It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than m. Note that order is important in nucleotide pairs.
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
Print a single integer β the sought number modulo 1000000007 (109 + 7).
Examples
Input
3 3 2
ab
ba
Output
17
Input
3 3 0
Output
27
Input
2 1 1
aa
Output
0
Note
In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs.
In the third test sample we cannot make any DNA of two nucleotides β the only possible nucleotide "a" cannot occur two times consecutively.
Submitted Solution:
```
MOD = 1000000007
def _solve(n, m, ban, memo):
if n in memo: return memo[n]
if n == 0: return [[0]*m for _ in range(m)]
if n == 1:
memo[n] = [[0]*m for _ in range(m)]
for i in range(m):
memo[n][i][i] = 1
return memo[n]
left, right = _solve(n // 2, m, ban, memo), _solve(n - n // 2, m, ban, memo)
memo[n] = [[0]*m for _ in range(m)]
# count all paths starting at i, ending at j
for i in range(m):
for j in range(m):
memo[n][i][j] = sum(left[i])*sum(right[s][j] for s in range(m)) % MOD
# subtract left path ending at x * right path ending at y for each banned pair (x, y)
for x, y in ban:
for i in range(m):
for j in range(m):
memo[n][i][j] -= left[i][x] * right[y][j] % MOD
memo[n][i][j] %= MOD
return memo[n]
def solve(n, m, ban):
counts = _solve(n, m, ban, {})
return sum(sum(row) for row in counts)
def main():
from sys import stdin
n, m, k = list(map(int, stdin.readline().strip().split()))
ban = set()
for _ in range(k):
x, y = list(stdin.readline().strip())
x = ord(x)-97 if 'a' <= x <= 'z' else ord(x)-39
y = ord(y)-97 if 'a' <= y <= 'z' else ord(y)-39
ban.add((x,y))
out = solve(n, m, ban)
print('{}'.format(out))
if __name__ == '__main__':
main()
```
No
| 86,918 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is k.
The needs of gene research required information about the quantity of correct n-long chains of the Martian DNA. Your task is to write a program that will calculate this value.
Input
The first line contains three space-separated integers n, m, k (1 β€ n β€ 1015, 1 β€ m β€ 52, 0 β€ k β€ m2).
Next k lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide.
The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z").
It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than m. Note that order is important in nucleotide pairs.
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
Print a single integer β the sought number modulo 1000000007 (109 + 7).
Examples
Input
3 3 2
ab
ba
Output
17
Input
3 3 0
Output
27
Input
2 1 1
aa
Output
0
Note
In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs.
In the third test sample we cannot make any DNA of two nucleotides β the only possible nucleotide "a" cannot occur two times consecutively.
Submitted Solution:
```
mul=lambda A,B,r:[[sum([A[i][k]*B[k][j] for k in r]) for j in r] for i in r]
def binpower(A,e):
r = range(len(A))
B = A
e -= 1
while True:
if e &1: B = mul(B,A,r)
e =e>>1
if e==0: break
A =mul(A,A,r)
return B
c2i = lambda c: ord(c)-ord('a') if c.islower() else ord(c)-ord('A')+26
def f(l1,l2):
n,m,_ = l1
if n==1: return m
M = [[1]*m for _ in range(m)]
for s in l2:
i = c2i(s[0])
j = c2i(s[1])
M[i][j]=0
return sum([sum(l) for l in binpower(M,n-1)])
l1 = list(map(int,input().split()))
l2 = [input() for _ in range(l1[2])]
print(f(l1,l2))
```
No
| 86,919 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
n, k = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
t = [[i] for i in p]
for i in range(1, n):
t += [t[-1] + i for i in t[: n - i]]
print('\n'.join(str(len(i)) + ' ' + ' '.join(map(str, i)) for i in t[: k]))
# Made By Mostafa_Khaled
```
| 86,920 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
n, k = map(int, input().split())
l = sorted(map(int, input().split()), reverse=True)
c = 0
for i in range(n):
for x in l[i:]:
if c == k:
exit()
c += 1
print(i + 1, end=" ")
for y in l[:i]:
print(y, end=" ")
print(x, end=" ")
print()
```
| 86,921 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
n, k = map(int, input().split())
soldiers = list(map(int, input().split()))
count = 0
seen = { 0: 0 }
while count != k:
for beauty, bits in list(seen.items()):
for i, x in enumerate(soldiers):
if (bits&(1 << i)) != 0 or beauty+x in seen:
continue
new_bits = (bits|(1 << i))
seen[beauty+x] = new_bits
#print('%d + %d = %d' % (beauty, x, beauty+x))
group = []
for j, y in enumerate(soldiers):
if (new_bits&(1 << j)) != 0:
group.append(y)
print(' '.join(map(str, [len(group)]+group)))
count += 1
if count == k:
break
if count == k:
break
```
| 86,922 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
n, k = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
t = [[i] for i in p]
for i in range(1, n):
t += [t[-1] + i for i in t[: n - i]]
print('\n'.join(str(len(i)) + ' ' + ' '.join(map(str, i)) for i in t[: k]))
```
| 86,923 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
n, k = map(int, input().split())
soldiers = list(map(int, input().split()))
count = 0
seen = { 0: 0 }
beauties = [ 0 ]
while count != k:
for beauty in beauties:
bits = seen[beauty]
for i, x in enumerate(soldiers):
if (bits&(1 << i)) != 0 or beauty+x in seen:
continue
new_bits = (bits|(1 << i))
seen[beauty+x] = new_bits
beauties.append(beauty+x)
group = []
for j, y in enumerate(soldiers):
if (new_bits&(1 << j)) != 0:
group.append(y)
print(' '.join(map(str, [len(group)]+group)))
count += 1
if count == k:
break
if count == k:
break
```
| 86,924 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
import random
def S(L):
Ans=[]
s=0
for item in L:
s+=item
Ans.append(s)
return Ans
n,k=map(int,input().split())
B=list(map(int,input().split()))
Sums=[]
s=0
for i in range(n):
s+=B[i]
Sums.append(s)
if(k<=n):
for i in range(k):
print(i+1,end="")
for j in range(i+1):
print(" "+str(B[j]),end="")
print()
else:
Ans=[]
length=1
Taken={}
Sums=S(B)
while(len(Ans)<k):
if(length>n):
length=1
random.shuffle(B)
Sums=S(B)
for i in range(n):
if(i+length-1>=n):
break
x=Sums[i+length-1]-Sums[i]+B[i]
if(x in Taken):
continue
Taken[x]=True
L=[length]
done=True
for j in range(i,i+length):
if(B[j] in L[1:]):
done=False
break
L.append(B[j])
if(done):
Ans.append(list(L))
length+=1
for i in range(k):
item=Ans[i]
print(item[0],end="")
for z in range(1,len(item)):
print(" "+str(item[z]),end="")
print()
```
| 86,925 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
from collections import *
import sys
input=sys.stdin.readline
# "". join(strings)
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def getKthBit(n, k):
return (n & (1 << (k - 1))) >> (k - 1)
n, K = rl()
aa = rl()
aa.sort()
for i in range(n + 1):
if K == 0:
break
smalls = aa[:n - i]
bigs = aa[n-i:]
# if bigs:
# print(len(bigs), " ".join([str(x) for x in bigs]))
# K -= 1
for small in smalls:
print(len(bigs) + 1, " ".join([str(x) for x in bigs]), small)
K -= 1
if K == 0:
break
```
| 86,926 |
Provide tags and a correct Python 3 solution for this coding contest problem.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
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")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=10**9+7
EPS=1e-6
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
n,k=value()
a=sorted(array())
ma=set()
setNo=1
while(True):
t=ma
for i in a:
if(k<setNo):exit()
if(i not in t):
print(len(ma)+1,*ma,i)
setNo+=1
key=-1
for i in a:
if(i not in ma):
key=max(key,i)
ma.add(key)
```
| 86,927 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
from sys import stdin
def arr_inp(n):
if n == 1:
return [int(x) for x in stdin.readline().split()]
elif n == 2:
return [float(x) for x in stdin.readline().split()]
else:
return list(stdin.readline()[:-1])
n, k = arr_inp(1)
c = sorted(arr_inp(1))[::-1]
for i in range(min(n, k)):
print(1, c[i])
k -= 1
tem = []
for i in range(min(n - 1, k)):
tem.append(c[i])
for j in range(n - 1, i, -1):
print(i + 2, end=' ')
print(*(tem + [c[j]]))
k -= 1
if not k:
exit()
```
Yes
| 86,928 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
n,k=list(map(int,input().split()))
A=list(map(int,input().split()))
C=[]
U=len(A)
c=0
g=0
for i in range(k):
print(len(C+[A[g]]),' '.join(map(str,C+[A[g]])))
g+=1
if g==len(A):
g=0
C.append(max(A))
A.remove(max(A))
```
Yes
| 86,929 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
import sys
def fastio():
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
def debug(*var, sep = ' ', end = '\n'):
print(*var, file=sys.stderr, end = end, sep = sep)
INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
n, k = I()
a = I()
a.sort(reverse = 1)
p = [0] * (n + 1)
for i in range(1, n + 1):
p[i] += p[i - 1] + a[i - 1]
s = set()
window = 1
ans = []
while k and window <= n:
for i in range(window, n + 1):
print(window, *ans, a[i - 1])
k -= 1
if not k:
break
ans.append(a[window - 1])
window += 1
```
Yes
| 86,930 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
n,k=list(map(int,input().split()))
a=sorted(list(map(int,input().split())))
j=0
c=0
for i in range(k):
b=[a[i-c]]
for l in range(n-j,n):
b.append(a[l])
print(j+1,*b)
if i-c==n-j-1:
c+=n-j
j+=1
```
Yes
| 86,931 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
n,m =[int(i) for i in input().split()]
arr = sorted([int(i) for i in input().split()])
out = []
for i in range(len(arr)):
for j in range(i,len(arr)):
out.append(arr[i:j+1])
out.append({arr[i],arr[j]})
s = set()
for i in out:
if sum(i) in s:
continue
else:
s.add(sum(i))
m-=1
print(len(i),*i)
if m==0:
break
```
No
| 86,932 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
n,m =[int(i) for i in input().split()]
arr = sorted([int(i) for i in input().split()])
out = []
for i in range(len(arr)):
for j in range(i,len(arr)):
out.append(arr[i:j+1])
for i in range(m):
print(len(out[i]),*out[i])
```
No
| 86,933 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
from itertools import combinations
n, m = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(1, n + 1):
if cnt == m:
exit(0)
f = list(combinations(a, i))
for j in range(len(f)):
if cnt == m:
exit(0)
cnt += 1
print(i, end=' ')
for k in range(len(f[j])):
print(f[j][k], end=' ')
print()
```
No
| 86,934 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The value ai represents the beauty of the i-th soldier.
On each of k days Generals has to send a detachment of soldiers to the pageant. The beauty of the detachment is the sum of the beauties of the soldiers, who are part of this detachment. Payne wants to surprise the jury of the beauty pageant, so each of k days the beauty of the sent detachment should be unique. In other words, all k beauties of the sent detachments must be distinct numbers.
Help Payne choose k detachments of different beauties for the pageant. Please note that Payne cannot just forget to send soldiers on one day, that is, the detachment of soldiers he sends to the pageant should never be empty.
Input
The first line contains two integers n, k (1 β€ n β€ 50; 1 β€ k β€ <image>) β the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 107) β the beauties of the battalion soldiers.
It is guaranteed that Payne's battalion doesn't have two soldiers with the same beauty.
Output
Print k lines: in the i-th line print the description of the detachment that will participate in the pageant on the i-th day. The description consists of integer ci (1 β€ ci β€ n) β the number of soldiers in the detachment on the i-th day of the pageant and ci distinct integers p1, i, p2, i, ..., pci, i β the beauties of the soldiers in the detachment on the i-th day of the pageant. The beauties of the soldiers are allowed to print in any order.
Separate numbers on the lines by spaces. It is guaranteed that there is the solution that meets the problem conditions. If there are multiple solutions, print any of them.
Examples
Input
3 3
1 2 3
Output
1 1
1 2
2 3 2
Input
2 1
7 12
Output
1 12
Submitted Solution:
```
# import itertools
# import bisect
# import heapq
# import math
from collections import defaultdict, Counter
import os
import sys
from io import BytesIO, IOBase
# sys.setrecursionlimit(10 ** 5)
ii = lambda: int(input())
lmii = lambda: list(map(int, input().split()))
slmii = lambda: sorted(map(int, input().split()))
li = lambda: list(input())
mii = lambda: map(int, input().split())
msi = lambda: map(str, input().split())
def gcd(a, b):
if b == 0: return a
return gcd(b, a % b)
def lcm(a, b): return (a * b) // gcd(a, b)
def main():
# for _ in " " * int(input()):
n, k = mii()
a = lmii()
d = defaultdict(int)
cnt = 0
for i in range(0,2 ** n,2):
sm = 0
lst = []
ln = 0
for j in range(n):
if i & (1 << j):
lst.append(a[n - j - 1])
sm += a[n - j - 1]
ln += 1
if not d[sm] and lst != []:
d[sm] = 1
print(ln, *lst)
cnt += 1
if cnt == k:
break
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()
```
No
| 86,935 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Tags: data structures, strings
Correct Solution:
```
# -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 1/7/20
"""
import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
def solve(S, B, K):
MOD = (1 << 50) + 9
s = set()
N = len(S)
pow = [1 for _ in range(N+1)]
for i in range(1, N+1):
pow[i] = pow[i-1] * 26
pow[i] %= MOD
for i in range(N-1, -1, -1):
k, h = 0, 0
for j in range(i, -1, -1):
ch = S[j]
if B[ch]:
k += 1
if k > K:
# print(i, j, S[i: j+1])
break
h += (ord(ch) - ord('a') + 1) * pow[i-j]
h %= MOD
# print(S[i: j + 1], h)
s.add(h)
return len(s)
S = input()
B = list(input())
K = int(input())
B = {chr(ord('a') + i): False if B[i] == '1' else True for i in range(26)}
print(solve(S, B, K))
```
| 86,936 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Tags: data structures, strings
Correct Solution:
```
s = input()
a = input()
k = int(input())
S=sorted(s[i:] for i in range(len(s)))
p=''
r=0
for e in S:
t=0
s=0
for i in range(len(e)):
if i >= len(p) or e[i] != p[i]: s=1
t+=a[ord(e[i])-ord('a')]=='0'
if t > k:break
if s: r+=1
p = e
print(r)
```
| 86,937 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Tags: data structures, strings
Correct Solution:
```
s = input()
l = input()
k = int(input())
no_bad = []
curr = 0
p =31
m = 67280421310721
hashes = []
currh = 0
cnt = 0
P = [pow(p,i,m) for i in range(len(s)+2)]
for i in s:
currh+=(P[cnt]*ord(i))%m
cnt+=1
hashes.append(currh)
if(l[ord(i) - ord('a')] =='0'):
no_bad.append(curr+1)
curr+=1
else:
no_bad.append(curr)
no_bad.append(0)
hashes.append(0)
ans = set()
for i in range(len(s)):
for j in range(i,len(s)):
if(no_bad[j] - no_bad[i-1]<=k):
has = ((hashes[j] - hashes[i-1])*P[len(s)-i+1])%m
ans.add(has)
print(len(ans))
```
| 86,938 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Tags: data structures, strings
Correct Solution:
```
s = input()
a = input()
k = int(input())
d = sorted(s[i:] for i in range(len(s)))
c = ''
r = 0
for j in d:
pos = 0
s = 0
for i in range(len(j)):
if i >= len(c) or j[i] != c[i]:
s = 1
if a[ord(j[i]) - ord('a')] == '0':
pos += 1
if pos > k:
break
if s:
r += 1
c = j
print(r)
```
| 86,939 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Tags: data structures, strings
Correct Solution:
```
def index(c):
return ord(c) - ord('a')
class Trie:
def __init__(self):
self._children = {}
self.mark = False
def get(self, c):
i = index(c)
if i not in self._children:
self._children[i] = Trie()
return self._children[i]
def solve(s, k, is_good):
n = len(s)
trie = Trie()
res = 0
for i in range(n):
bad = 0
cur = trie
for j in range(i, n):
if not is_good[index(s[j])]:
bad += 1
if bad > k:
break
cur = cur.get(s[j])
if not cur.mark:
res += 1
cur.mark = True
return res
s = input()
is_good = [c == '1' for c in input()]
k = int(input())
print(solve(s, k, is_good))
```
| 86,940 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Tags: data structures, strings
Correct Solution:
```
import sys
input=sys.stdin.readline
s=input().rstrip()
flag=input().rstrip()
k=int(input())
n=len(s)
ss=[s[i:] for i in range(n)]
ss.sort()
pre=""
ans=0
for e in ss:
veri,cnt_bad=0,0
for i in range(len(e)):
if i>=len(pre) or e[i]!=pre[i]:veri=1
cnt_bad+=flag[ord(e[i])-ord("a")]=="0"
if cnt_bad>k:break
if veri:ans+=1
pre=e
print(ans)
```
| 86,941 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Tags: data structures, strings
Correct Solution:
```
import sys
import math as mt
#input=sys.stdin.buffer.readline
#t=int(input())
t=1
mod=9007199254740881
for ___ in range(t):
#n,m=map(int,input().split())
s1=input()
s2=input()
k=int(input())
d={}
for i in range(len(s1)):
suma=0
pre=0
D=256
for j in range(i,len(s1)):
pre=(pre*D+ord(s1[j]))%mod
posi=ord(s1[j])-ord('a')
if s2[posi]=='0':
suma+=1
if suma<=k:
d[pre]=1
else:
break
print(len(d))
```
| 86,942 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Tags: data structures, strings
Correct Solution:
```
s = input()
a = input()
k = int(input())
S=sorted(s[i:] for i in range(len(s)))
p=''
r=0
for e in S:
t=0
s=0
for i in range(len(e)):
if i >= len(p) or e[i] != p[i]:
s=1
if a[ord(e[i])-ord('a')]=='0':
t+=1
if t > k:
break
if s:
r+=1
p = e
print(r)
```
| 86,943 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Submitted Solution:
```
# Author : nitish420 --------------------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
alph = dict()
for i in range(26):
alph[chr(i+97)] = i
def main():
txt = input()
n = len(txt)
arr = list(map(int, input()))
k = int(input())
suffixArr = [txt[i:] for i in range(n)]
suffixArr.sort()
prev = ""
ans = 0
for s in suffixArr:
count = 0
flag = 0
for j in range(len(s)):
if j >= len(prev) or s[j] != prev[j]:
flag = 1
count += 1-arr[alph[s[j]]]
if count > k:
break
if flag:
ans += 1
prev = s
print(ans)
# ----------------------------------------------------------------------------------------
# region fastio
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)
def input(): return sys.stdin.readline().rstrip('\r\n')
# endregion
if __name__ == '__main__':
main()
```
Yes
| 86,944 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Submitted Solution:
```
s = input()
L = input()
k = int(input())
'''from datetime import *
time1 = datetime.now()'''
good = set()
string = set()
LIST = [chr(i) for i in range(97,123)]
for i in range(26):
if L[i]=='1':
good.add(LIST[i])
t = [s[i] not in good for i in range(len(s))]
end = [0]*len(s)
badchars = 0
front=0; rear=0
while(front<len(s)):
while(rear<len(s)):
badchars+=t[rear]
if badchars>k:
badchars-=1
break
rear+=1
end[front]=rear
badchars -= t[front]
front+=1
for i in range(len(s)):
tempStrHash = 0
for j in range(i, end[i]):
tempStrHash = (tempStrHash*29+ord(s[j])-96)&1152921504606846975
string.add(tempStrHash)
print(len(string))
#print(datetime.now()-time1)
```
Yes
| 86,945 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Submitted Solution:
```
import collections as cc
import sys
input=sys.stdin.readline
I=lambda:list(map(int,input().split()))
S=lambda :list(input().strip())
s=S()
t=S()
k,=I()
ans=0
prev=''
ss=sorted([s[i:] for i in range(len(s))])
for j in ss:
now=0
f=0
for i in range(len(j)):
if i>=len(prev) or j[i]!=prev[i]:
f=1
now+=t[ord(j[i])-ord('a')]=='0'
if now>k:
break
if f:
ans+=1
prev=j
print(ans)
```
Yes
| 86,946 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Submitted Solution:
```
s = input()
L = input()
k = int(input())
l=len(s)
good = set()
string = set()
LIST = [chr(i) for i in range(97, 123)]
for i in range(26):
if L[i] == '1':
good.add(LIST[i])
t = [s[i] not in good for i in range(l)]
end = [0]*l
sumbad = 0
i,j=0,0
while i<l:
if j<l:
sumbad+=t[j]
if sumbad>k or j==l:
sumbad-=t[i]
end[i]=j
i+=1
if sumbad>k:
sumbad-=t[j]
continue
if j<l:
j+=1
for i in range(len(s)):
t = 0
for j in range(i, end[i]):
t = (t*29 + ord(s[j])-96)&1152921504606846975
string.add(t)
print(len(string))
```
Yes
| 86,947 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Submitted Solution:
```
import sys
input=sys.stdin.readline
s=input().rstrip()
flag=input().rstrip()
k=int(input())
n=len(s)
ss=[s[i:] for i in range(n)]
ss.sort()
pre=""
ans=0
for e in ss:
veri,cnt_bad=0,0
for i in range(len(e)):
if i>=len(pre) or e[i]!=pre[i]:
veri=1
cnt_bad+=flag[ord(s[i])-ord("a")]=="0"
if cnt_bad>k:
break
if veri:
ans+=1
pre=e
print(ans)
```
No
| 86,948 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Submitted Solution:
```
# ------------------- 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 --------------------
s = input()
l = [int(k) for k in input()]
bad = set()
for i in range(26):
if l[i] == 0:
bad.add(97+i)
k = int(input())
hashes = set()
base = 999983
s = [ord(x) for x in s]
value = 0
badcount = 0
mod = 10**13 + 11
basemod = [1]*1501
for i in range(1, 1501):
basemod[i] = basemod[i-1] * base % mod
for length in range(1, len(s)+1):
value = value * base % mod
value = (value + s[length-1]) % mod
if s[length-1] in bad:
badcount += 1
if badcount <= k:
hashes.add(value)
val, brbad = value, badcount
for i in range(length, len(s)):
if s[i] in bad:
brbad += 1
if s[i-length] in bad:
brbad -= 1
val = ((val - s[i-length]*(basemod[length-1]))*base + s[i]) % mod
if brbad <= k:
#print(length, i)
hashes.add(val)
print(len(hashes))
```
No
| 86,949 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Submitted Solution:
```
s=input()
good=[int(x) for x in input()]
k=int(input())
n=len(s)
ans=0
mod=10**9+9
dp=[[0 for _ in range(n)] for _ in range(n)]
hashes=[(ord(s[0])-ord('a')+1)]
if good[ord(s[0])-ord('a')]:
dp[0][0]=0
else:
dp[0][0]= 1
for i in range(1,n):
hashes.append(hashes[-1]+(ord(s[i])-ord('a')+1)*(29**i))
for i in range(n):
hashes[i]=hashes[i]%(mod)
occ=set()
ppowi=[]
for i in range(n+1):
ppowi.append((29**i)%mod)
for i in range(n):
for j in range(i,n):
if i-1>=0:x=((hashes[j]-hashes[i-1])*(ppowi[n-i]))%mod
else:x=((hashes[j])*(ppowi[n]))%mod
if i==0 and j==0:
dp[i][j]=1^good[ord(s[j])-ord('a')]
elif good[ord(s[j])-ord('a')]==0:
dp[i][j]=dp[i][j-1]+1
else:
dp[i][j]=dp[i][j-1]
if dp[i][j]>k:break
if dp[i][j]<=k:
occ.add(x)
print(len(occ))
```
No
| 86,950 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 β€ l β€ r β€ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr.
The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] β s[p...q].
Input
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 β€ k β€ |s|) β the maximum acceptable number of bad characters in a good substring.
Output
Print a single integer β the number of distinct good substrings of string s.
Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
Note
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
Submitted Solution:
```
# maa chudaaye duniya
s = input()
badwords = input()
k = int(input())
md = 10**9 + 9
p = 31
h = [0 for i in range(len(s) + 1)]
for i in range(len(s)):
h[i+1] = (h[i] + (ord(s[i]) - ord('a') + 1)*pow(p, i, md)) % md
cn = set([])
# print(h)
for i in range(len(s)):
count = 0
for j in range(i, len(s)):
if badwords[ord(s[j]) - ord('a')] == '0':
count += 1
cur_h = (h[j+1] - h[i] + md) % md
cur_h = (cur_h * pow(p, len(s)-i-1, md)) % md
# print(i, j, s[i:j+1], cur_h, count)
if count > k:
break
else:
cn.add(cur_h)
print(len(cn))
```
No
| 86,951 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Tags: data structures, implementation
Correct Solution:
```
import io,os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n,m,k=map(int,input().split())
l=list(map(int,input().split()))
op=[]
for i in range(m):
op.append(list(map(int,input().split())))
kk=[]
for i in range(k):
kk.append(list(map(int,input().split())))
da1=[0]*(1+m)
for s,e in kk:
da1[s]+=1
if e+1 < m+1:
da1[e+1]-=1
r=0
for i in range(1,m+1):
r+=da1[i]
op[i-1][2]*=r
da2=[-1]+[l[0]]
for i in range(n-1):
da2.append(l[i+1]-l[i])
for s,e,w in op:
da2[s]+=w
if e+1 < n+1:
da2[e+1]-=w
r=0
for i in range(1,n+1):
r+=da2[i]
print(r,end=" ")
```
| 86,952 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Tags: data structures, implementation
Correct Solution:
```
if __name__ == '__main__':
n, m, k = map(int, input().split())
nums = list(map(int, input().split()))
operations = [tuple(map(int, input().split())) for _ in range(m)]
op_counter = [0] * (m+1)
# queries
for _ in range(k):
x, y = map(int, input().split())
op_counter[x-1] += 1
op_counter[y] -= 1
acc = 0
offset = [0]*(n+1)
for i in range(m):
l, r, d = operations[i]
acc += op_counter[i]
offset[l-1] += acc * d
offset[r] -= acc * d
acc = 0
for i in range(n):
acc += offset[i]
nums[i] += acc
print(' '.join(map(str, nums)))
```
| 86,953 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Tags: data structures, implementation
Correct Solution:
```
import sys
def answer(n, m, k, a, ops, q):
cnt_m = [0 for i in range(m+1)] # number of operations of each type to be performed. 1 to m, based on q.
for i in range(k):
l = q[i][0]
r = q[i][1]
cnt_m[l-1] += 1
cnt_m[r] -= 1
summ_a = [0 for i in range(n+1)]
s = 0
for i in range(m):
d = ops[i][2]
s += cnt_m[i]
summ = s * d
l = ops[i][0]
r = ops[i][1]
summ_a[l-1] += summ
summ_a[r] -= summ
s = 0
for i in range(n):
s += summ_a[i]
a[i] += s
return ' '.join(map(str, a))
def main():
n, m, k = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
ops = [0 for i in range(m)]
q = [0 for i in range(k)]
for i in range(m):
ops[i] = list(map(int, sys.stdin.readline().split()))
for j in range(k):
q[j] = list(map(int, sys.stdin.readline().split()))
print(answer(n, m, k, a, ops, q))
return
main()
```
| 86,954 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Tags: data structures, implementation
Correct Solution:
```
from sys import *
rd = lambda: list(map(int, stdin.readline().split()))
n, m, k = rd()
a = rd()
b = [rd() for _ in range(m)]
x = [0]*(m+1)
y = [0]*(n+1)
for _ in range(k):
l, r = rd()
x[l-1] += 1
x[r] -= 1
s = 0
for i in range(m):
l, r, d = b[i]
s += x[i]
y[l-1] += s*d
y[r] -= s*d
s = 0
for i in range(n):
s += y[i]
a[i] += s
print(*a)
```
| 86,955 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Tags: data structures, implementation
Correct Solution:
```
n , m , k =map(int,input().split())
a = list(map(int,input().split()))[:n]
s = []
x = [0]*(m+1)
y = [0]*(n+1)
for i in range(m):
l,r,d = map(int,input().split())
s.append((l,r,d))
for i in range(k):
j , v = map(int,input().split())
x[j-1]+=1
x[v]-=1
cnt = 0
for i in range(m):
cnt+=x[i]
l,r,d = s[i]
y[l-1]+=cnt*d
y[r]-=cnt*d
cnt1 = 0
for i in range(n):
cnt1+=y[i]
a[i]+=cnt1
print(*a[:n])
```
| 86,956 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Tags: data structures, implementation
Correct Solution:
```
from itertools import accumulate
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
oper = [tuple(map(int, input().split())) for i in range(m)]
zapr = [tuple(map(int, input().split())) for i in range(k)]
count_ = [0 for i in range(m + 1)]
for el in zapr:
x, y = el
count_[x - 1] += 1
count_[y] -= 1
counter_ = list(accumulate(count_))[:-1]
a.append(0)
a_count = [a[0]]
for i, el in enumerate(a[1:]):
a_count.append(el - a[i])
for i, el in enumerate(oper):
l, r, d = el
d *= counter_[i]
a_count[l - 1] += d
a_count[r] -= d
a = list(accumulate(a_count))[:-1]
print(' '.join(map(str, a)))
```
| 86,957 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Tags: data structures, implementation
Correct Solution:
```
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
ops = [list(map(int,input().split())) for _ in range(m)]
qus = [list(map(int,input().split())) for _ in range(k)]
starts = [0]*(m+1)
for l,r in qus:
starts[l-1] += 1
starts[r] -= 1
opcount = [0]*m
active = 0
for i in range(m):
active += starts[i]
opcount[i] = active
suffixOffset = [0]*(n+1)
for i in range(m):
l,r,d = ops[i]
suffixOffset[l-1] += opcount[i]*d
suffixOffset[r] -= opcount[i]*d
active = 0
for i in range(n):
active += suffixOffset[i]
a[i] += active
print(*a)
```
| 86,958 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Tags: data structures, implementation
Correct Solution:
```
def main():
n,m,k = map(int,input().split())
arr = list(map(int,input().split()))
ops = [0]*m
ops_arr = []
for i in range(m):
l,r,d = map(int,input().split())
ops_arr.append([l,r,d])
for i in range(k):
x,y = map(int,input().split())
x -= 1
y -= 1
ops[x] += 1
if y+1 < m:
ops[y+1] -= 1
for i in range(1,m):
ops[i] += ops[i-1]
#print(ops)
for i in range(m):
ops_arr[i][2] *= ops[i]
ans = [0]*n
for op in ops_arr:
l,r,d = op[0],op[1],op[2]
l -= 1
r -= 1
ans[l] += d
if r+1 < n:
ans[r+1] -= d
for i in range(1,n):
ans[i] += ans[i-1]
for i in range(n):
ans[i] += arr[i]
for i in ans:
print(i,end = ' ')
main()
```
| 86,959 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Submitted Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
##################################
# University of Wisconsin-Madison
# Author: Yaqi Zhang
##################################
# standard library
import sys
def main():
n, m, k = map(int, input().split())
nums = list(map(int, input().split()))
pre_reps = [0] * (m + 1)
ops = []
for _ in range(m):
l, r, d = map(int, input().split())
ops.append((l - 1, r - 1, d))
for _ in range(k):
x, y = map(int, input().split())
x -= 1
y -= 1
pre_reps[x] += 1
pre_reps[y + 1] -= 1
cur = 0
add = [0] * (n + 1)
for i, (l, r, d) in enumerate(ops):
cur += pre_reps[i]
add[l] += d * cur
add[r + 1] -= d * cur
cur = 0
ans = []
for i, num in enumerate(nums):
cur += add[i]
ans.append(num + cur)
print(' '.join(map(str, ans)))
if __name__ == "__main__":
main()
```
Yes
| 86,960 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Submitted Solution:
```
import sys
n,m,k=map(int,sys.stdin.readline().split())
a=list(map(int,sys.stdin.readline().split()))
s=sum(a)
m1=[]
for i in range(m):
g=list(map(int,sys.stdin.readline().split()))
m1.append(g)
k1=[]
for i in range(k):
g=list(map(int,sys.stdin.readline().split()))
k1.append(g)
cnt=[0]*(m+1)
for i in range(k):
cnt[k1[i][0]-1]+=1
cnt[k1[i][1]]+=-1
s=0
for i in range(m+1):
s+=cnt[i]
cnt[i]=s
cnt1=[0]*(n+1)
for i in range(m):
cnt1[m1[i][0]-1]+=cnt[i]*m1[i][2]
cnt1[m1[i][1]]+=-cnt[i]*m1[i][2]
s=0
for i in range(n):
s+=cnt1[i]
a[i]+=s
print(a[i],end=" ")
```
Yes
| 86,961 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Submitted Solution:
```
first_line = [int(num) for num in input().split()]
n = first_line[0]
m = first_line[1]
k = first_line[2]
initial_array = [int(num) for num in input().split()]
operations = []
for _ in range(m):
curr_line = [int(num) for num in input().split()]
operations.append(curr_line)
queries = []
for _ in range(k):
curr_line = [int(num) for num in input().split()]
queries.append(curr_line)
counter = [0] * (m+1)
for query in queries:
x = query[0]
y = query[1]
counter[x-1] += 1
counter[y] -= 1
res = 0
other = [0] * (n+1)
for index in range(m):
operation = operations[index]
l = operation[0]
r = operation[1]
d = operation[2]
res += counter[index]
other[l-1] += res*d
other[r] -= res*d
res = 0
for index in range(n):
res += other[index]
initial_array[index] += res
print(" ".join(str(value) for value in initial_array))
```
Yes
| 86,962 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Submitted Solution:
```
import sys
input = sys.stdin.readline
n,m,k=map(int,input().split())
arr=list(map(int,input().split()))
querry_arr=[list(map(int, input().split())) for _ in range(m)]
tmp_ans=[0]*n
tmp=[0]*(m+1)
for _ in range(k):
l,r=map(lambda k:int(k)-1,input().split())
tmp[l]+=1
tmp[r+1]-=1
for x in range(1,m):
tmp[x]+=tmp[x-1]
arr_tmp=[0]*(n+1)
tmp.pop()
for x in range(m):
u,v,w=querry_arr[x]
u-=1
v-=1
arr_tmp[u]+=w*tmp[x]
arr_tmp[v+1]-=w*tmp[x]
arr[0]+=arr_tmp[0]
for x in range(1,n):
arr_tmp[x]+=arr_tmp[x-1]
arr[x]+=arr_tmp[x]
print(' '.join(map(str, arr)))
```
Yes
| 86,963 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Submitted Solution:
```
if __name__ == '__main__':
n, m, k = map(int, input().split())
nums = list(map(int, input().split()))
operations = [tuple(map(int, input().split())) for _ in range(m)]
op_counter = [0] * (m+1)
# queries
for _ in range(k):
x, y = map(int, input().split())
op_counter[x-1] += 1
op_counter[y] -= 1
acc = 0
offset = [0]*(n+1)
for i in range(m):
l, r, d = operations[i]
acc += op_counter[i]
offset[l-1] += acc * d
offset[r] -= acc * d
acc = 0
for i in range(n):
acc += offset[i]
nums[i] += acc
print(nums)
```
No
| 86,964 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Submitted Solution:
```
# Legends Always Come Up with Solution
# Author: Manvir Singh
import os
import sys
from io import BytesIO, IOBase
def main():
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
ma=max(a)
q=[tuple(map(int,input().split())) for _ in range(m)]
qans=[0]*(m+1)
for i in range(k):
x,y=map(int,input().split())
x-=1
qans[x]+=1
qans[y]-=1
for i in range(1,m+1):
qans[i]+=qans[i-1]
ans=[0]*(ma+2)
for j,i in enumerate(q):
x=qans[j]*i[2]
ans[i[0]]+=x
ans[i[1]+1]-=x
for i in range(1,ma+1):
ans[i]+=ans[i-1]
for i in a:
print(i+ans[i],end=" ")
# region fastio
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()
```
No
| 86,965 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Submitted Solution:
```
def fastio():
import sys
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
n, m, k = I()
l = I()
a = [0]*(100005)
q = []
b = [0]*(100005)
for i in range(m):
o = I()
o[0] -= 1
q.append(o)
for i in range(k):
x, y = I()
b[x-1] += 1
b[y] -= 1
for i in range(1, n):
b[i] += b[i-1]
for i in range(m):
x, y, z = q[i]
a[x] += b[i]*z
a[y] -= b[i]*z
for i in range(n):
a[i] += a[i-1]
print(a[i] + l[i], end = ' ')
```
No
| 86,966 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 β€ li β€ ri β€ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 β€ xi β€ yi β€ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 β€ n, m, k β€ 105). The second line contains n integers: a1, a2, ..., an (0 β€ ai β€ 105) β the initial array.
Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 β€ li β€ ri β€ n), (0 β€ di β€ 105).
Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 β€ xi β€ yi β€ m).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, a2, ..., an β the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
Submitted Solution:
```
import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math,datetime,functools,itertools,operator,bisect,fractions,statistics
from collections import deque,defaultdict,OrderedDict,Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify ,_heapify_max,_heappop_max,nsmallest,nlargest
sys.setrecursionlimit(111111)
INF=99999999999999999999999999999999
def main():
mod=1000000007
# InverseofNumber(mod)
# InverseofFactorial(mod)
# factorial(mod)
starttime=datetime.datetime.now()
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
###CODE
tc = 1
for _ in range(tc):
n,m,k=ria()
arr=ria()
operations=[]
queries=[]
ansrange=[0]*(100005)
oprange=[0]*(m+5)
for i in range(m):
operations.append(ria())
for i in range(k):
a,b=ria()
oprange[a-1]+=1
oprange[b]-=1
for i in range(1,len(oprange)):
oprange[i]+=oprange[i-1]
# print(oprange)
for i in range(len(oprange)):
if oprange[i]:
l,r,d=operations[i]
ansrange[l]+=d*oprange[i]
ansrange[r+1]-=d*oprange[i]
for i in range(1,len(oprange)):
ansrange[i]+=ansrange[i-1]
ans=[]
for i in arr:
ans.append(i+ansrange[i])
wia(ans)
#<--Solving Area Ends
endtime=datetime.datetime.now()
time=(endtime-starttime).total_seconds()*1000
if(os.path.exists('input.txt')):
print("Time:",time,"ms")
class FastReader(io.IOBase):
newlines = 0
def __init__(self, fd, chunk_size=1024 * 8):
self._fd = fd
self._chunk_size = chunk_size
self.buffer = io.BytesIO()
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
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, size=-1):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
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()
class FastWriter(io.IOBase):
def __init__(self, fd):
self._fd = fd
self.buffer = io.BytesIO()
self.write = self.buffer.write
def flush(self):
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class FastStdin(io.IOBase):
def __init__(self, fd=0):
self.buffer = FastReader(fd)
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
class FastStdout(io.IOBase):
def __init__(self, fd=1):
self.buffer = FastWriter(fd)
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.flush = self.buffer.flush
if __name__ == '__main__':
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()
```
No
| 86,967 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Tags: implementation
Correct Solution:
```
def vahta(x, lst):
for elem in lst:
ra, rb = min(elem[0], elem[1]), min(elem[2], elem[3])
if ra + rb <= x:
return lst.index(elem) + 1, ra, x - ra
return [-1]
n = int(input())
a = list()
for i in range(4):
t = [int(j) for j in input().split()]
a.append(t)
print(*vahta(n, a))
```
| 86,968 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Tags: implementation
Correct Solution:
```
import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import (
accumulate, combinations, combinations_with_replacement, groupby,
permutations, product)
from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,
log2, pi, radians, sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits
def inp():
return(int(input()))
def inlist():
return(list(map(int, input().split())))
def instr():
s = input()
return(list(s[:len(s)]))
def invr():
return(map(int, input().split()))
def def_value():
return 0
# For getting input from input.txt file
#sys.stdin = open('input.txt', 'r')
# Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')
n = inp()
a = []
for i in range(4):
a.append(inlist()+[i+1])
a = sorted(a, key=lambda d: min(d[0], d[1])+min(d[2], d[3]))
b = a[0]
if min(b[0], b[1]) + min(b[2], b[3]) > n:
print(-1)
else:
c1 = min(b[0], b[1])
c2 = n - c1
print(b[4], c1, c2)
```
| 86,969 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Tags: implementation
Correct Solution:
```
n = int(input())
a = [list(map(int, input().split())) for i in range(4)]
b = []
c = []
d = []
for i in range(4):
b.append(min(a[i][:2]))
b.append(min(a[i][2:]))
b.insert(0, sum(b))
d.append(b[0])
c.append(b)
b = []
k = d.index(min(d))
if c[k][0] <= n: print(k+1,c[k][1],n-c[k][1])
else: print(-1)
```
| 86,970 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Tags: implementation
Correct Solution:
```
import itertools as it
n = int(input())
res = None
for i in range(4):
a = list(map(int, input().split()))
for v in list(it.product(a[:2], a[2:])):
if sum(v) <= n:
res = [i + 1, v[0], n - v[0]]
break
if res is not None:
break
print(-1 if res is None else ' '.join(map(str, res)))
```
| 86,971 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Tags: implementation
Correct Solution:
```
def solve(arr, n):
for i,v in enumerate(arr):
c1 = min(v[0], v[1])
c2 = min(v[2], v[3])
if c1+c2 <= n:
return [i+1, c1,n-c1]
return [-1]
def main() :
n = int(input())
arr = []
for _ in range(4):
i = list(map(int, input().split(' ')))
arr.append(i)
print(*solve(arr, n))
main()
```
| 86,972 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Tags: implementation
Correct Solution:
```
n = int(input())
for _ in range(4):
a,b,c,d = map(int,input().split())
for i in [a,b]:
for j in [c,d]:
if i+j<=n:
print(_+1,i,n-i)
exit(0)
print(-1)
```
| 86,973 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Tags: implementation
Correct Solution:
```
if __name__ == "__main__":
n = int(input())
l1 = [int(v) for v in input().split()]
l2 = [int(v) for v in input().split()]
l3 = [int(v) for v in input().split()]
l4 = [int(v) for v in input().split()]
if min(l1[0],l1[1]) + min(l1[2],l1[3]) <= n:
print("1 %d %d" % (min(l1[0],l1[1]), n-min(l1[0],l1[1])))
elif min(l2[0],l2[1]) + min(l2[2],l2[3]) <= n:
print("2 %d %d" % (min(l2[0],l2[1]), n-min(l2[0],l2[1])))
elif min(l3[0],l3[1]) + min(l3[2],l3[3]) <= n:
print("3 %d %d" % (min(l3[0],l3[1]), n-min(l3[0],l3[1])))
elif min(l4[0],l4[1]) + min(l4[2],l4[3]) <= n:
print("4 %d %d" % (min(l4[0],l4[1]), n-min(l4[0],l4[1])))
else:
print("-1")
```
| 86,974 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Tags: implementation
Correct Solution:
```
n = int(input())
for i in range(4):
a = list(map(int, input().split()))
if n >= min(a[0], a[1]) + min(a[2], a[3]):
print(i + 1, min(a[0], a[1]), n - min(a[0], a[1]))
exit()
print(-1)
```
| 86,975 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Submitted Solution:
```
import sys
n = int(input())
for i in range(4):
a, b, c, d = map(int, input().split())
if min(a, b) + min(c, d) <= n:
print("{} {} {}".format(i + 1, min(a, b), n - min(a, b)))
sys.exit(0)
print(-1)
```
Yes
| 86,976 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Submitted Solution:
```
import sys
n=int(sys.stdin.readline())
A=[]
t=0
for i in range(1,5):
A.append(list(map(int,sys.stdin.readline().split())))
for i in range(0,4):
if A[i][0]+A[i][2]<=n:
print(i+1,A[i][0],n-A[i][0])
t=1
break
elif A[i][0]+A[i][3]<=n:
print(i+1,A[i][0],n-A[i][0])
t=1
break
elif A[i][1]+A[i][2]<=n:
print(i+1,A[i][1],n-A[i][1])
t=1
break
elif A[i][1]+A[i][3]<=n:
print(i+1,A[i][1],n-A[i][1])
t=1
break
if t==0:
print(-1)
```
Yes
| 86,977 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Submitted Solution:
```
from functools import reduce
from operator import *
from math import *
from sys import *
from string import *
from collections import *
setrecursionlimit(10**7)
dX= [-1, 1, 0, 0,-1, 1,-1, 1]
dY= [ 0, 0,-1, 1, 1,-1,-1, 1]
RI=lambda: list(map(int,input().split()))
RS=lambda: input().rstrip().split()
#################################################
n=RI()[0]
ind=0
ans1,ans2=10**6, 10**6
for i in range(4):
a,b,c,d=RI()
a=min(a,b)
c=min(c,d)
if a+c < ans1+ans2:
ind=i+1
ans1=a
ans2=c
if n-ans1<ans2:
print(-1)
else:
print(ind, ans1,n-ans1)
```
Yes
| 86,978 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Submitted Solution:
```
n=int(input())
for x in range(4):
a,b,c,d=map(int,input().split())
k1=min(a,b)
k2=min(c,d)
ans=-1
con=0
while True:
if n-k1>=0:
if n-k1>=k2:
ans=[x+1,k1,n-k1]
con=1
break
else:
k1+=1
else:
break
if con:
print(*ans)
break
else:
print(ans)
```
Yes
| 86,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Submitted Solution:
```
def guardpost(m, cash):
for v in range(4):
if m[v][0] + m[v][2] <= cash:
print(str(v+1) + " " + str(m[v][0]) + " " + str(cash - m[v][2]))
return None
elif m[v][0] + m[v][3] <= cash:
print(str(v+1) + " " + str(m[v][0]) + " " + str(cash - m[v][3]))
return None
elif m[v][1] + m[v][2] <= cash:
print(str(v+1) + " " + str(m[v][1]) + " " + str(cash - m[v][2]))
return None
elif m[v][1] + m[v][3] <= cash:
print(str(v+1) + " " + str(m[v][1]) + " " + str(cash - m[v][3]))
return None
print("-1")
return None
cash = int(input())
matriz = []
for i in range(4):
matriz.append([int(item) for item in input().split()])
guardpost(matriz, cash)
```
No
| 86,980 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Submitted Solution:
```
def search_guardports(guardports):
for i in range(4):
if guardports[i][0] > guardports[i][1]:
p1 = guardports[i][1]
else:
p1 = guardports[i][0]
if guardports[i][2] > guardports[i][3]:
p2 = guardports[i][3]
else:
p2 = guardports[i][2]
if p1 + p2 <= n:
return [i + 1, p1, p2]
return []
n = int(input())
guardports = []
for _ in range(4):
guardports.append([int(x) for x in input().split()])
res = search_guardports(guardports)
if res:
print(" ".join(map(str, res)))
else:
print(-1)
```
No
| 86,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Submitted Solution:
```
import sys
def readInputs():
global budget, prices
budget = int(f.readline())
prices = []
for _ in range(4):
(a1,b1,a2,b2) = map(int,f.readline().split())
prices += [((a1,b1),(a2,b2))]
#print(budget)
#print(prices)
def isPartOk(a,b):
for i in range(4):
((a1,b1),(a2,b2)) = prices[i]
#print(a,((a1,b1),(a2,b2)))
if(((a >= a1 or a >= b1) and (b >= a2 or b >= b2)) or (b >= a1 or b >= b1) and (a >= a2 or a >= b2)):
return i+1
return -1
def solve():
for a in range(1,budget//2+1):
res = isPartOk(a,budget-a)
if(res!=-1):
return ' '.join([str(res),str(a),str(budget-a)])
return -1
def main():
global f
f = sys.stdin
readInputs()
print(solve())
main()
```
No
| 86,982 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 β€ a, b, c, d β€ 105) β the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Submitted Solution:
```
n = int(input())
already = False
for i in range(4):
string = input().split()
numList = list(map(int, string))
first = numList[0:2]
second = numList[2:4]
minFirst = min(first)
minSecond = min(second)
if(already == False):
if((minFirst + minSecond) <= n):
print(i+1, minFirst, 10 - minSecond)
already = True
if(already == False):
print(-1)
```
No
| 86,983 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Tags: games, greedy, sortings
Correct Solution:
```
chef_sum = 0
ramsay_sum = 0
odds_mids = []
for n in range(int(input())):
c, *c_list = map(int, input().split())
if c%2 == 1:
odds_mids.append(c_list.pop(c//2))
for index,element in enumerate(c_list):
if index < len(c_list)/2:
chef_sum += element
else:
ramsay_sum += element
odds_mids.sort(reverse = True)
for index, element in enumerate(odds_mids):
if index%2 == 0:
chef_sum += element
else:
ramsay_sum += element
print(chef_sum, ramsay_sum)
```
| 86,984 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Tags: games, greedy, sortings
Correct Solution:
```
from functools import reduce
n = int(input())
cards = [list(map(int, input().split()[1:])) for i in range(n)]
mid = sorted((c[len(c) >> 1] for c in cards if len(c) & 1 == 1), reverse=True)
add = lambda x=0, y=0: x + y
a, b = reduce(add, mid[::2] or [0]), reduce(add, mid[1::2] or [0])
for c in cards:
m = len(c) >> 1
a += reduce(add, c[:m] or [0])
b += reduce(add, c[m + (len(c) & 1):] or [0])
print(a, b)
```
| 86,985 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Tags: games, greedy, sortings
Correct Solution:
```
n=int(input())
s1,s2=0,0
tab = []
for i in range(n):
c = list(map(int,input().split()))
for j in range(1,c[0]+1):
if(j*2<=c[0]): s1+=c[j]
else: s2+=c[j]
if(c[0] & 1):
s2-=c[(c[0]+1)//2]
tab.append(c[(c[0]+1)//2])
if(len(tab)):
tab.sort()
tab.reverse()
for i in range(len(tab)):
if(i & 1): s2+=tab[i]
else: s1+=tab[i]
print(s1,s2)
```
| 86,986 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Tags: games, greedy, sortings
Correct Solution:
```
odd = []
first, second = 0, 0
for i in range(int(input())):
pile = list(map(int, input().split()))
s, pile = pile[0], pile[1:]
sh = s >> 1
if (s & 1) == 0:
first += sum(pile[:sh])
second += sum(pile[sh:])
else:
first += sum(pile[:sh])
second += sum(pile[sh+1:])
odd.append(pile[sh])
odd = sorted(odd, reverse=True)
first += sum(odd[::2])
second += sum(odd[1::2])
print(first, second)
```
| 86,987 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Tags: games, greedy, sortings
Correct Solution:
```
#!/usr/bin/env python3
odd, even = [], []
player1_turn = True
player1 = player2 = 0
pile_number = int(input())
for _ in range(pile_number):
n, *pile = tuple(map(int, input().split()))
if n % 2 == 0:
even.append(pile)
else:
odd.append(pile)
for pile in even:
n = len(pile)
player1 += sum(pile[:n//2])
player2 += sum(pile[n//2:])
for pile in sorted(odd, reverse=True, key=lambda x: x[len(x)//2]):
n = len(pile)
top, middle, bottom = pile[:n//2], pile[n//2], pile[n//2+1:]
player1 += sum(top)
player2 += sum(bottom)
if player1_turn:
player1 += middle
player1_turn = not player1_turn
else:
player2 += middle
player1_turn = not player1_turn
print(player1, player2)
```
| 86,988 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Tags: games, greedy, sortings
Correct Solution:
```
n = int(input())
c = [list(map(int, input().split())) for _ in range(n)]
a, b = 0, 0
d = []
for i in range(n):
if len(c[i]) % 2:
a += sum(c[i][1:c[i][0]//2+1])
b += sum(c[i][c[i][0]//2+1:])
else:
a += sum(c[i][1:c[i][0]//2+1])
b += sum(c[i][c[i][0]//2+2:])
d.append(c[i][c[i][0]//2+1])
d.sort(reverse=True)
print(a+sum(d[0::2]), b+sum(d[1::2]))
```
| 86,989 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Tags: games, greedy, sortings
Correct Solution:
```
#!/usr/bin/env pypy
rr= lambda: input().strip()
rri= lambda: int(rr())
rrm= lambda: [int(x) for x in rr().split()]
def sol(n):
cm=[]
res1=0
res2=0
for i in range(n):
x=rrm()
if x[0]%2==1:
cm.append(x[x[0]//2+1])
res1+=sum(x[1:x[0]//2+1])
res2+=sum(x[(x[0]+1)//2+1:])
cm.sort(reverse=True)
for i,v in enumerate(cm):
if i%2==0:
#print(v)
res1+=v
else:
res2+=v
return str(res1)+" "+str(res2)
T=1
for _ in range(T):
n=rri()
ans=sol(n)
print(ans)
```
| 86,990 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Tags: games, greedy, sortings
Correct Solution:
```
n = int(input())
a,b = 0,0
l = []
for _ in range(n):
inpt = list(map(int,input().split()))[1:]
li = len(inpt)
if li%2:
l.append(inpt[li//2])
a += sum((inpt[:li//2]))
b += sum((inpt[(li + 1)//2:]))
l.sort(reverse=True)
a += sum(l[::2])
b += sum(l[1::2])
print(a, b)
```
| 86,991 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Submitted Solution:
```
import sys
from functools import reduce
for n in sys.stdin:
n = int(n)
cards = [list(map(int, input().split()[1:])) for i in range(n)]
mid = []
a, b = 0, 0
add = lambda x=0, y=0: x + y
for c in cards:
s = len(c)
m = s >> 1
a += reduce(add, c[:m] or [0])
b += reduce(add, c[m + (s & 1):] or [0])
if s & 1 == 1:
mid.append(c[m])
mid.sort(reverse=True)
j = True
for c in mid:
if j:
a += c
else:
b += c
j = not j
print(a, b)
```
Yes
| 86,992 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Submitted Solution:
```
import sys
from functools import reduce
for n in sys.stdin:
n = int(n)
cards = [list(map(int, input().split()[1:])) for i in range(n)]
mid = []
a, b = 0, 0
add = lambda x=0, y=0: x + y
for c in cards:
s = len(c)
m = s >> 1
if s & 1 == 0:
a += reduce(add, c[:m])
b += reduce(add, c[m:])
else:
a += reduce(add, c[:m] or [0])
b += reduce(add, c[m + 1:] or [0])
mid.append(c[m])
mid.sort(reverse=True)
j = True
for c in mid:
if j:
a += c
else:
b += c
j = not j
print(a, b)
```
Yes
| 86,993 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Submitted Solution:
```
from functools import reduce
n = int(input())
cards = [list(map(int, input().split()[1:])) for i in range(n)]
mid = [c[len(c) >> 1] for c in cards if len(c) & 1 == 1]
a, b = 0, 0
add = lambda x=0, y=0: x + y
for c in cards:
m = len(c) >> 1
a += reduce(add, c[:m] or [0])
b += reduce(add, c[m + (len(c) & 1):] or [0])
mid.sort(reverse=True)
a += reduce(add, mid[::2] or [0])
b += reduce(add, mid[1::2] or [0])
print(a, b)
```
Yes
| 86,994 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Submitted Solution:
```
rr= lambda: input().strip()
rri= lambda: int(rr())
rrm= lambda: [int(x) for x in rr().split()]
def sol(n):
cm=[]
res1=0
res2=0
for i in range(n):
x=rrm()
if x[0]%2==1:
cm.append(x[x[0]//2+1])
res1+=sum(x[1:x[0]//2+1])
res2+=sum(x[(x[0]+1)//2+1:])
cm.sort(reverse=True)
for i,v in enumerate(cm):
if i%2==0:
#print(v)
res1+=v
else:
res2+=v
return str(res1)+" "+str(res2)
T=1
for _ in range(T):
n=rri()
ans=sol(n)
print(ans)
```
Yes
| 86,995 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Submitted Solution:
```
n = int(input())
ar = list()
til = list()
for i in range(n) :
line = input()
pui = line.split()
til.append(int(pui[0]))
del(pui[0])
por = [int(j) for j in pui]
ar.append(por)
time = sum(til)
f1 = 0
f2 = 0
t = 1
while t <= time :
if t%2 == 1 :
m = 0
for i in range(len(ar)) :
if len(ar[i])!=0 and ar[i][0] > m :
m = ar[i][0]
ind = i
f1 = f1 + m
del(ar[ind][0])
else :
m = 0
for i in range(len(ar)) :
if len(ar[i])!=0 and ar[i][len(ar[i])-1] > m :
m = ar[i][len(ar[i])-1]
ind = i
elif len(ar[i])!=0 and ar[i][len(ar[i])-1] == m :
if len(ar[ind]) > len(ar[i]) :
ind = i
f2 = f2 + m
del(ar[ind][-1])
t = t+1
print(f1, f2)
```
No
| 86,996 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Submitted Solution:
```
rr= lambda: input().strip()
rri= lambda: int(rr())
rrm= lambda: [int(x) for x in rr().split()]
def sol(n):
cm=[]
res1=0
res2=0
for i in range(n):
x=rrm()
if x[0]%2==1:
cm.append(x[x[0]//2+1])
res1+=sum(x[1:x[0]//2+1])
res2+=sum(x[(x[0]+1)//2+1:])
for i,v in enumerate(cm):
if i%2==0:
#print(v)
res1+=v
else:
res2+=v
return str(res1)+" "+str(res2)
T=1
for _ in range(T):
n=rri()
ans=sol(n)
print(ans)
```
No
| 86,997 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Submitted Solution:
```
def main(args):
nPiles = int(input())
piles = []
for i in range (nPiles):
line = list(map(int, input().split(' ')))
piles.append(line[1:])
ciel = 0
jiro = 0
turn = 1
while piles:
if turn%2 != 0:
ciel += piles[0][0]
del piles[0][0]
turn += 1
if not piles[0]:
del piles[0]
elif turn%2 == 0:
jiro += piles[0][-1]
del piles[0][-1]
turn += 1
if not piles[0]:
del piles[0]
print(ciel, jiro)
return 0
if __name__ == '__main__':
import sys
sys.exit(main(sys.argv))
```
No
| 86,998 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.
Suppose Ciel and Jiro play optimally, what is the score of the game?
Input
The first line contain an integer n (1 β€ n β€ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 β€ si β€ 100) β the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 β€ ck β€ 1000) β the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.
Output
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
Examples
Input
2
1 100
2 1 10
Output
101 10
Input
1
9 2 8 6 5 9 4 7 1 3
Output
30 15
Input
3
3 1 3 2
3 5 4 6
2 8 7
Output
18 18
Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output
7000 7000
Note
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.
In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 2 12:17:43 2019
@author: Saurav Sihag
"""
rr= lambda: input().strip()
rri= lambda: int(rr())
rrm= lambda: [int(x) for x in rr().split()]
def sol(n):
cm=[]
res=0
for i in range(n):
x=rrm()
if x[0]%2==1:
cm.append(x[x[0]//2+1])
res+=sum(x[1:x[0]//2+1])
for i,v in enumerate(cm):
if i%2==0:
#print(v)
res+=v
return res
T=1
for _ in range(T):
n=rri()
ans=sol(n)
print(ans)
```
No
| 86,999 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.