message stringlengths 2 43.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 853 107k | cluster float64 24 24 | __index_level_0__ int64 1.71k 214k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is an experienced participant in Codehorses programming contests. Now he wants to become a problemsetter.
He sent to the coordinator a set of n problems. Each problem has it's quality, the quality of the i-th problem is ai (ai can be positive, negative or equal to zero). The problems are ordered by expected difficulty, but the difficulty is not related to the quality in any way. The easiest problem has index 1, the hardest problem has index n.
The coordinator's mood is equal to q now. After reading a problem, the mood changes by it's quality. It means that after the coordinator reads a problem with quality b, the value b is added to his mood. The coordinator always reads problems one by one from the easiest to the hardest, it's impossible to change the order of the problems.
If after reading some problem the coordinator's mood becomes negative, he immediately stops reading and rejects the problemset.
Polycarp wants to remove the minimum number of problems from his problemset to make the coordinator's mood non-negative at any moment of time. Polycarp is not sure about the current coordinator's mood, but he has m guesses "the current coordinator's mood q = bi".
For each of m guesses, find the minimum number of problems Polycarp needs to remove so that the coordinator's mood will always be greater or equal to 0 while he reads problems from the easiest of the remaining problems to the hardest.
Input
The first line of input contains two integers n and m (1 ≤ n ≤ 750, 1 ≤ m ≤ 200 000) — the number of problems in the problemset and the number of guesses about the current coordinator's mood.
The second line of input contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the qualities of the problems in order of increasing difficulty.
The third line of input contains m integers b1, b2, ..., bm (0 ≤ bi ≤ 1015) — the guesses of the current coordinator's mood q.
Output
Print m lines, in i-th line print single integer — the answer to the problem with q = bi.
Example
Input
6 3
8 -5 -4 1 -7 4
0 7 3
Output
2
0
1
Submitted Solution:
```
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(0,m):
start = b[i]
k = 0
i = 0
tmp = a[:]
while i < len(tmp):
start += tmp[i]
if start >= 0:
i += 1
else:
index = tmp[0:i+1].index(min(tmp[0:i+1]))
#start-=tmp.pop(index)
start -= tmp[index]
tmp[index] = 1
k += 1
print(k)
``` | instruction | 0 | 53,536 | 24 | 107,072 |
No | output | 1 | 53,536 | 24 | 107,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is an experienced participant in Codehorses programming contests. Now he wants to become a problemsetter.
He sent to the coordinator a set of n problems. Each problem has it's quality, the quality of the i-th problem is ai (ai can be positive, negative or equal to zero). The problems are ordered by expected difficulty, but the difficulty is not related to the quality in any way. The easiest problem has index 1, the hardest problem has index n.
The coordinator's mood is equal to q now. After reading a problem, the mood changes by it's quality. It means that after the coordinator reads a problem with quality b, the value b is added to his mood. The coordinator always reads problems one by one from the easiest to the hardest, it's impossible to change the order of the problems.
If after reading some problem the coordinator's mood becomes negative, he immediately stops reading and rejects the problemset.
Polycarp wants to remove the minimum number of problems from his problemset to make the coordinator's mood non-negative at any moment of time. Polycarp is not sure about the current coordinator's mood, but he has m guesses "the current coordinator's mood q = bi".
For each of m guesses, find the minimum number of problems Polycarp needs to remove so that the coordinator's mood will always be greater or equal to 0 while he reads problems from the easiest of the remaining problems to the hardest.
Input
The first line of input contains two integers n and m (1 ≤ n ≤ 750, 1 ≤ m ≤ 200 000) — the number of problems in the problemset and the number of guesses about the current coordinator's mood.
The second line of input contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the qualities of the problems in order of increasing difficulty.
The third line of input contains m integers b1, b2, ..., bm (0 ≤ bi ≤ 1015) — the guesses of the current coordinator's mood q.
Output
Print m lines, in i-th line print single integer — the answer to the problem with q = bi.
Example
Input
6 3
8 -5 -4 1 -7 4
0 7 3
Output
2
0
1
Submitted Solution:
```
def check(plank, points):
summ = 0
for point in points:
summ += point
if plank + summ < 0:
return False
return True
_ = input()
inpt = input()
tasks = list(map(lambda x: int(x), str(inpt).split(" ")))
alt = list(tasks)
moods = list(map(lambda x: int(x), str(input()).split(" ")))
alt.sort()
for tsk in range(len(alt)):
if alt[tsk] > 0:
b = alt[tsk:]
b.reverse()
alt[tsk:] = b
break
for mood in moods:
count = 0
tasks = list(map(lambda x: int(x), str(inpt).split(" ")))
if check(mood, tasks): print(0)
else:
for i in range(len(tasks)):
count += 1
try:
tasks.remove(alt[0])
except:
print(count)
break
del alt[0]
if check(mood, tasks):
print(count)
break
``` | instruction | 0 | 53,537 | 24 | 107,074 |
No | output | 1 | 53,537 | 24 | 107,075 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is an experienced participant in Codehorses programming contests. Now he wants to become a problemsetter.
He sent to the coordinator a set of n problems. Each problem has it's quality, the quality of the i-th problem is ai (ai can be positive, negative or equal to zero). The problems are ordered by expected difficulty, but the difficulty is not related to the quality in any way. The easiest problem has index 1, the hardest problem has index n.
The coordinator's mood is equal to q now. After reading a problem, the mood changes by it's quality. It means that after the coordinator reads a problem with quality b, the value b is added to his mood. The coordinator always reads problems one by one from the easiest to the hardest, it's impossible to change the order of the problems.
If after reading some problem the coordinator's mood becomes negative, he immediately stops reading and rejects the problemset.
Polycarp wants to remove the minimum number of problems from his problemset to make the coordinator's mood non-negative at any moment of time. Polycarp is not sure about the current coordinator's mood, but he has m guesses "the current coordinator's mood q = bi".
For each of m guesses, find the minimum number of problems Polycarp needs to remove so that the coordinator's mood will always be greater or equal to 0 while he reads problems from the easiest of the remaining problems to the hardest.
Input
The first line of input contains two integers n and m (1 ≤ n ≤ 750, 1 ≤ m ≤ 200 000) — the number of problems in the problemset and the number of guesses about the current coordinator's mood.
The second line of input contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the qualities of the problems in order of increasing difficulty.
The third line of input contains m integers b1, b2, ..., bm (0 ≤ bi ≤ 1015) — the guesses of the current coordinator's mood q.
Output
Print m lines, in i-th line print single integer — the answer to the problem with q = bi.
Example
Input
6 3
8 -5 -4 1 -7 4
0 7 3
Output
2
0
1
Submitted Solution:
```
n, m = list(map(int,input().split()))
spikes = []
a = list(map(int,input().split()))
s = 0
for i in range(len(a)):
s += a[i]
if s < 0:
spikes.append(s)
b = list(map(int,input().split()))
for i in b:
r = 0
delta = 0
for j in spikes:
if i + j + delta < 0:
r += 1
delta -= j
print(r)
``` | instruction | 0 | 53,538 | 24 | 107,076 |
No | output | 1 | 53,538 | 24 | 107,077 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc | instruction | 0 | 54,893 | 24 | 109,786 |
Tags: brute force, strings, two pointers
Correct Solution:
```
t = int(input())
for i in range(t):
s = input()
ans = ""
j=0
while(j<len(s)):
if(j==len(s)-1):
if s[j] not in ans:
ans += s[j]
break
elif (s[j]==s[j+1]):
j+=2
continue
else:
if s[j] not in ans:
ans += s[j]
j+=1
ans = sorted(list(set(ans)))
ans = ''.join(ans)
print(ans)
``` | output | 1 | 54,893 | 24 | 109,787 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc | instruction | 0 | 54,894 | 24 | 109,788 |
Tags: brute force, strings, two pointers
Correct Solution:
```
def broken_keyboard(s1):
if len(s1) == 1:
return s1
size = len(s1)
letters = []
count = 0
for i in range(size):
if(i == size-1) or (s1[i] != s1[i+1]):
count += 1
if(count % 2 != 0):
letters.append(s1[i])
count = 0
else:
count += 1
letters = set(letters)
letters = list(letters)
letters.sort()
result = ""
return result.join(letters)
t = int(input())
for i in range(t):
s1 = input()
print(broken_keyboard(s1))
``` | output | 1 | 54,894 | 24 | 109,789 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc | instruction | 0 | 54,895 | 24 | 109,790 |
Tags: brute force, strings, two pointers
Correct Solution:
```
for item in [0]*int(input()):
x = input()
d = sorted(set(x))
answer = ''
for tiem in d:
if x.count(tiem)>2*x.count(tiem+tiem):
answer = answer+tiem
print(answer)
``` | output | 1 | 54,895 | 24 | 109,791 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc | instruction | 0 | 54,896 | 24 | 109,792 |
Tags: brute force, strings, two pointers
Correct Solution:
```
t = int(input())
def run_length_compress(string):
"""文字列をランレングス圧縮する
例) string = "aabccaaabb" -> [(2, a), (1, b), (2, c), (3, a), (2, b)]
"""
string = string + "@" # string中に絶対に現れない文字を番兵とする
n = len(string)
begin = 0
end = 1
cnt = 1
ans = []
while True:
if end >= n:
break
if string[begin] == string[end]:
end += 1
cnt += 1
else:
ans.append((cnt, string[begin]))
begin = end
end = begin + 1
cnt = 1
return ans
for _ in range(t):
s = input()
r = run_length_compress(s)
memo = {}
for i, char in r:
if i %2 == 1:
memo[char] = 1
ans = []
for i in memo:
ans.append(i)
ans = sorted(ans)
print("".join(ans))
``` | output | 1 | 54,896 | 24 | 109,793 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc | instruction | 0 | 54,897 | 24 | 109,794 |
Tags: brute force, strings, two pointers
Correct Solution:
```
n = int(input())
for _ in range(n):
s = input()
l = len(s)
if l == 1:
print(s)
continue
inx = 0
ones = set()
while inx < l-1:
if s[inx] == s[inx+1]:
inx += 1
else:
ones.update(s[inx])
inx+=1
if inx == l-1:
ones.update(s[-1])
print(''.join(sorted(ones)))
``` | output | 1 | 54,897 | 24 | 109,795 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc | instruction | 0 | 54,898 | 24 | 109,796 |
Tags: brute force, strings, two pointers
Correct Solution:
```
for _ in range(int(input())):
s = input()
i = 0
correct = set()
while i < len(s):
if i == len(s) - 1:
correct.add(s[i])
break
if s[i] == s[i+1]:
i += 2
continue
correct.add(s[i])
i += 1
r = list(correct)
r.sort()
print("".join(r))
``` | output | 1 | 54,898 | 24 | 109,797 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc | instruction | 0 | 54,899 | 24 | 109,798 |
Tags: brute force, strings, two pointers
Correct Solution:
```
t=int(input())
while t:
t-=1
s=input()
i=0
if(len(s)==1):
print(s)
continue
ans=[]
while(i<len(s)-1):
if(s[i] != s[i+1]):
ans+=[s[i]]
i+=1
else:
i+=2
if(i==len(s)-1):
ans+=[s[i]]
#ans.sort()
print("".join(sorted(set(ans))))
``` | output | 1 | 54,899 | 24 | 109,799 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc | instruction | 0 | 54,900 | 24 | 109,800 |
Tags: brute force, strings, two pointers
Correct Solution:
```
N = int(input())
counts = []
for _ in range(N):
s = input()
last_c = None
last_count = 0
ans = set()
for c in s:
if last_c == None:
last_c = c
last_count = 1
else:
if c == last_c:
last_count += 1
else:
if last_count %2 == 1:
ans.add(last_c)
last_c = c
last_count = 1
if last_count % 2 == 1:
ans.add(c)
print(''.join(sorted(list(ans))))
``` | output | 1 | 54,900 | 24 | 109,801 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc
Submitted Solution:
```
t = int(input())
for _ in range(t):
a = input().strip()
n = len(a)
a += "0"
ans = set()
lo = 0
hi = 0
while lo < n:
while a[hi] == a[lo]:
hi += 1
count = hi - lo
if count % 2 == 1:
ans.add(a[lo])
lo = hi
print(*sorted(ans), sep='')
``` | instruction | 0 | 54,901 | 24 | 109,802 |
Yes | output | 1 | 54,901 | 24 | 109,803 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc
Submitted Solution:
```
vezes = int(input())
for __ in range(vezes):
letras = []
string = input()
tamanho =1
if len(string) == 1:
print(string[0])
else:
for i in range(len(string)-1):
if string[i] == string[i+1]:
tamanho += 1
if i == len(string) - 2:
if tamanho % 2 != 0 and string[i] not in letras:
letras.append(string[i])
else:
if tamanho % 2 != 0 and string[i] not in letras:
letras.append(string[i])
tamanho = 1
if string[len(string) - 1] != string[len(string) - 2]:
if string[len(string) - 1] not in letras:
letras.append(string[len(string)-1])
letras.sort()
print(*letras,sep="")
``` | instruction | 0 | 54,902 | 24 | 109,804 |
Yes | output | 1 | 54,902 | 24 | 109,805 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc
Submitted Solution:
```
# for testes in range(int(input())):
# s = input()
# i = 0
# cont = 0
# while i < len(s):
# c = s[i]
# for x in s[i:]:
# if x == c:
# cont += 1
for testes in range(int(input())):
s = input()
ult = s[0]
cont = 1
res = []
for c in s[1:]:
if c != ult:
if cont % 2 == 1 and ult not in res:
res.append(ult)
ult = c
cont = 1
else:
cont += 1
if cont % 2 == 1 and ult not in res:
res.append(ult)
for c in sorted(res):
print(c,end="")
print()
``` | instruction | 0 | 54,903 | 24 | 109,806 |
Yes | output | 1 | 54,903 | 24 | 109,807 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc
Submitted Solution:
```
numberTestCases = int(input())
allWorkingCharactersLists = []
for test in range(numberTestCases):
guaranteedWorkingCharactersPerCase = []
testString = input() + " "
for i in range(1, len(testString) - 1):
previousCharacter = testString[i-1]
if testString[i] == previousCharacter:
testStringList = list(testString)
testStringList[i] = " "
testStringList[i-1] = " "
testString = ''.join(testStringList)
for character in testString:
if character != " " and character not in guaranteedWorkingCharactersPerCase:
guaranteedWorkingCharactersPerCase.append(character)
allWorkingCharactersLists.append(guaranteedWorkingCharactersPerCase)
for characterList in allWorkingCharactersLists:
characterList.sort()
if characterList == []:
characterList.append("")
answer = ''.join(characterList)
print(answer)
``` | instruction | 0 | 54,904 | 24 | 109,808 |
Yes | output | 1 | 54,904 | 24 | 109,809 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc
Submitted Solution:
```
#Ashish Sagar
q=int(input())
for _ in range(q):
s=list(input())
ans=""
i=0
n=len(s)
if n==1:
print(s[0])
else:
while(i<n-1):
if s[i]!=s[i+1]:
ans+=s[i]
ans+=s[i+1]
i+=2
if s[n-1]!=s[n-2]:
ans+=s[n-1]
ans=list(ans)
ans.sort()
print(''.join(ans))
``` | instruction | 0 | 54,905 | 24 | 109,810 |
No | output | 1 | 54,905 | 24 | 109,811 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc
Submitted Solution:
```
t=int(input())
for i in range(t):
s=input()
res = sorted(set(s))
for j in res:
if s.count(j) != 2 * s.count(j + j):
print(j,end='')
print('\n')
``` | instruction | 0 | 54,906 | 24 | 109,812 |
No | output | 1 | 54,906 | 24 | 109,813 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc
Submitted Solution:
```
q = int(input())
for re in range(q):
s = input()
dob = set()
n = len(s)
s = '0' + s + '0'
for i in range(1, n+1):
if s[i] != s[i-1] and s[i] != s[i+1]:
dob.add(s[i])
l = []
for i in dob:
if i != '0':
l.append(i)
l.sort()
if len(l) == 0:
print("")
else:
for i in range(len(l)):
if i < len(l) - 1:
print(l[i], end = "")
else:
print(l[i])
``` | instruction | 0 | 54,907 | 24 | 109,814 |
No | output | 1 | 54,907 | 24 | 109,815 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.
To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:
* if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
* if the button was malfunctioning, two characters c appeared at the end of the string.
For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.
You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).
You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases in the input.
Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.
Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.
Example
Input
4
a
zzaaz
ccff
cbddbb
Output
a
z
bc
Submitted Solution:
```
n=int(input())
for i in range(n):
p=input()
#p=p.split()
#p=list(map(int,p))
#p.sort()
if(len(p)==1):
print(p[0])
else:
curr=0
ans=list()
for j in range(len(p)-1):
if(p[j]==p[j+1]):
curr+=1
else:
break
if(curr%2==0):
ans.append(p[j])
curr=1
last=-1
for j in range(1,len(p)):
if(p[j]==p[j-1]):
curr+=1
else:
if(curr%2==1 and p[j-1] not in ans):
ans.append(p[j-1])
curr=1
curr=0
for j in range(len(p)-1,0,-1):
if(p[j]==p[j-1]):
curr+=1
else:
break
if(curr%2==0):
ans.append(p[j])
ans.sort()
for j in range(len(ans)):
print(ans[j],end="")
print()
``` | instruction | 0 | 54,908 | 24 | 109,816 |
No | output | 1 | 54,908 | 24 | 109,817 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031 | instruction | 0 | 55,323 | 24 | 110,646 |
Tags: implementation
Correct Solution:
```
n = int(input())
s = input()
ans = ""
array_from_s = s.split("0")
for c in array_from_s:
ans += str(len(c))
print(ans)
``` | output | 1 | 55,323 | 24 | 110,647 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031 | instruction | 0 | 55,324 | 24 | 110,648 |
Tags: implementation
Correct Solution:
```
n=int(input())
s=input()+'0'
i=0
for x in range(n):
if s[x]=='1':
i+=1
elif s[x]=='0':
print(i,end='')
i=0
print(i,end='')
``` | output | 1 | 55,324 | 24 | 110,649 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031 | instruction | 0 | 55,325 | 24 | 110,650 |
Tags: implementation
Correct Solution:
```
n = int(input())
a = input()
new = ""
c = 0
m = "1"
for i in a:
if(i == m):
c += 1
else:
if(m == "0"):
new += ("0" * (c - 1))
else:
new += str(c)
m = i
c = 1
if(m == "0"):
new += ("0" * (c))
else:
new += str(c)
print(new)
``` | output | 1 | 55,325 | 24 | 110,651 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031 | instruction | 0 | 55,326 | 24 | 110,652 |
Tags: implementation
Correct Solution:
```
length = input("")
string = input("")
string = string.split('0')
result = ""
for i in string:
result += str(len(i))
print(int(result))
``` | output | 1 | 55,326 | 24 | 110,653 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031 | instruction | 0 | 55,327 | 24 | 110,654 |
Tags: implementation
Correct Solution:
```
n=input()
s=input()
d=0
c=0
for i in range(len(s)):
if s[i]=='0':
c=c*10+d
d=0
else:
d=d+1
c=c*10+d
print(c)
``` | output | 1 | 55,327 | 24 | 110,655 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031 | instruction | 0 | 55,328 | 24 | 110,656 |
Tags: implementation
Correct Solution:
```
n = int(input())
s = input() + '0'
ans = ''
c = 0
for i in s:
if i == '0':
ans += str(c)
c = 0
else:
c += 1
print(ans)
``` | output | 1 | 55,328 | 24 | 110,657 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031 | instruction | 0 | 55,329 | 24 | 110,658 |
Tags: implementation
Correct Solution:
```
input()
print(''.join([str(len(i)) for i in input().strip().split('0')]))
``` | output | 1 | 55,329 | 24 | 110,659 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031 | instruction | 0 | 55,330 | 24 | 110,660 |
Tags: implementation
Correct Solution:
```
n=int(input())
s=input()
c=0
r=''
if(n==1):
print(s)
else:
for i in range(n-1):
if(s[0]=='0'):
c=0
elif(s[i]=='1'):
c=c+1
elif(s[i-1]=='1' and s[i]=='0'):
r=r+str(c)
c=0
elif(s[i-1]=='0' and s[i]=='0'):
r=r+'0'
c=0
if(s[-1]=='1' and s[-2]=='0'):
r=r+'1'
elif(s[-1]=='1' and s[-2]=='1'):
c=c+1
r=r+str(c)
elif(s[-1]=='0' and s[-2]=='0'):
r=r+'00'
elif(s[-1]=='0' and s[-2]=='1'):
r=r+str(c)+'0'
print(r)
``` | output | 1 | 55,330 | 24 | 110,661 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031
Submitted Solution:
```
input()
s = input().split('0')
for i in s:
print(len(i), end='')
``` | instruction | 0 | 55,331 | 24 | 110,662 |
Yes | output | 1 | 55,331 | 24 | 110,663 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031
Submitted Solution:
```
N = int(input())
li = input().split('0')
for i in range(len(li)):
li[i] = li[i].count('1')
if len(li) == 0:
print ("0")
else:
li = map(str,li)
print ("".join(li))
``` | instruction | 0 | 55,332 | 24 | 110,664 |
Yes | output | 1 | 55,332 | 24 | 110,665 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031
Submitted Solution:
```
n = int(input())
s = input()
v = s.split('0')
ans = ""
for x in v:
ans += str(len(x))
print(ans)
``` | instruction | 0 | 55,333 | 24 | 110,666 |
Yes | output | 1 | 55,333 | 24 | 110,667 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031
Submitted Solution:
```
n=int(input())
s=input()
j=-1
for i in range(n):
if s[i]=='0':
print(i-j-1,end='')
j=i
print(n-j-1)
``` | instruction | 0 | 55,334 | 24 | 110,668 |
Yes | output | 1 | 55,334 | 24 | 110,669 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031
Submitted Solution:
```
n=int(input())
b=list(input())
count=0
for i in range(n-1):
if b[i]=='1':
count+=1
else:
print(count,end='')
count=0
print(count+int(b[-1]),end='')
``` | instruction | 0 | 55,335 | 24 | 110,670 |
No | output | 1 | 55,335 | 24 | 110,671 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031
Submitted Solution:
```
n = int(input())
encoded_number = input()
decoded_number = []
current_digit = 0
for i, bit in enumerate(encoded_number):
if bit is '1':
current_digit += 1
elif bit is '0':
if current_digit != 0:
decoded_number.append(current_digit)
current_digit = 0
else:
decoded_number.append(current_digit)
if current_digit != 0:
decoded_number.append(current_digit)
print("".join(map(str, decoded_number)))
``` | instruction | 0 | 55,336 | 24 | 110,672 |
No | output | 1 | 55,336 | 24 | 110,673 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031
Submitted Solution:
```
s = input().strip()
n = 0
for c in s:
if c == '1':
n += 1
else:
print(n, end='')
n = 0
print()
``` | instruction | 0 | 55,337 | 24 | 110,674 |
No | output | 1 | 55,337 | 24 | 110,675 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:
* Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
* Digits are written one by one in order corresponding to number and separated by single '0' character.
Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.
Input
The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.
The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.
Output
Print the decoded number.
Examples
Input
3
111
Output
3
Input
9
110011101
Output
2031
Submitted Solution:
```
def find(s):
A=[]
count=0
for i in range(len(s)):
if s[i]=='1':
count+=1
else:
A+=[count]
count=0
if s[-1]=='1':
A+=[count]
TT=''
for i in range(len(A)):
TT+=str(A[i])
return TT
N=input()
s=input()
print(find(s))
``` | instruction | 0 | 55,338 | 24 | 110,676 |
No | output | 1 | 55,338 | 24 | 110,677 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food.
The flight menu has k dishes in total and when Polycarp boarded the flight, he had time to count the number of portions of each dish on board. Thus, he knows values a1, a2, ..., ak, where ai is the number of portions of the i-th dish.
The stewardess has already given food to m - 1 passengers, gave Polycarp a polite smile and asked him what he would prefer. That's when Polycarp realized that they might have run out of some dishes by that moment. For some of the m - 1 passengers ahead of him, he noticed what dishes they were given. Besides, he's heard some strange mumbling from some of the m - 1 passengers ahead of him, similar to phrase 'I'm disappointed'. That happened when a passenger asked for some dish but the stewardess gave him a polite smile and said that they had run out of that dish. In that case the passenger needed to choose some other dish that was available. If Polycarp heard no more sounds from a passenger, that meant that the passenger chose his dish at the first try.
Help Polycarp to find out for each dish: whether they could have run out of the dish by the moment Polyarp was served or that dish was definitely available.
Input
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line.
The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000, 1 ≤ k ≤ 100 000) — the number of Polycarp's seat and the number of dishes, respectively.
The second line contains a sequence of k integers a1, a2, ..., ak (1 ≤ ai ≤ 100 000), where ai is the initial number of portions of the i-th dish.
Then m - 1 lines follow, each line contains the description of Polycarp's observations about giving food to a passenger sitting in front of him: the j-th line contains a pair of integers tj, rj (0 ≤ tj ≤ k, 0 ≤ rj ≤ 1), where tj is the number of the dish that was given to the j-th passenger (or 0, if Polycarp didn't notice what dish was given to the passenger), and rj — a 1 or a 0, depending on whether the j-th passenger was or wasn't disappointed, respectively.
We know that sum ai equals at least m, that is,Polycarp will definitely get some dish, even if it is the last thing he wanted. It is guaranteed that the data is consistent.
Sum m for all input sets doesn't exceed 100 000. Sum k for all input sets doesn't exceed 100 000.
Output
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
Examples
Input
2
3 4
2 3 2 1
1 0
0 0
5 5
1 2 1 3 1
3 0
0 0
2 1
4 0
Output
YNNY
YYYNY
Note
In the first input set depending on the choice of the second passenger the situation could develop in different ways:
* If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish;
* If he chose the fourth dish, then by the moment the stewardess reaches Polycarp, they will have run out of the fourth dish;
* Otherwise, Polycarp will be able to choose from any of the four dishes.
Thus, the answer is "YNNY".
In the second input set there is, for example, the following possible scenario. First, the first passenger takes the only third dish, then the second passenger takes the second dish. Then, the third passenger asks for the third dish, but it is not available, so he makes disappointed muttering and ends up with the second dish. Then the fourth passenger takes the fourth dish, and Polycarp ends up with the choice between the first, fourth and fifth dish.
Likewise, another possible scenario is when by the time the stewardess comes to Polycarp, they will have run out of either the first or the fifth dish (this can happen if one of these dishes is taken by the second passenger). It is easy to see that there is more than enough of the fourth dish, so Polycarp can always count on it. Thus, the answer is "YYYNY". | instruction | 0 | 56,019 | 24 | 112,038 |
Tags: greedy
Correct Solution:
```
t = int(input())
for i in range(t):
input()
m, k = [int(l) for l in input().split()]
a = [int(j) for j in input().split()]
upset = -1
unknown = 0
unknownBeforeUpset = 0
ti, r = [], []
for i1 in range(m-1):
n = input().split()
ti.append(int(n[0]))
r.append(int(n[1]))
ti[i1] -= 1
if r[i1] == 1 and upset == -1:
upset = i1
if ti[i1] != -1:
a[ti[i1]] -= 1
else:
unknown+=1
if upset == -1:
unknownBeforeUpset+=1
st = ["N" for j in range(k)]
if upset == -1:
for j in range(k):
if a[j] <= unknown:
st[j] = "Y"
else:
usedAfter = [False for i in range(k)]
for j in range(upset, m-1):
if ti[j] != -1:
usedAfter[ti[j]] = True
minFirstFinished = -1
for j in range(k):
if not usedAfter[j] and unknownBeforeUpset >= a[j]:
st[j] = 'Y'
if minFirstFinished == -1 or a[minFirstFinished] > a[j]:
minFirstFinished = j
if minFirstFinished != -1:
restUnknown = unknown - a[minFirstFinished]
for j in range(k):
if a[j] <= restUnknown:
st[j] = 'Y'
print("".join(st))
``` | output | 1 | 56,019 | 24 | 112,039 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food.
The flight menu has k dishes in total and when Polycarp boarded the flight, he had time to count the number of portions of each dish on board. Thus, he knows values a1, a2, ..., ak, where ai is the number of portions of the i-th dish.
The stewardess has already given food to m - 1 passengers, gave Polycarp a polite smile and asked him what he would prefer. That's when Polycarp realized that they might have run out of some dishes by that moment. For some of the m - 1 passengers ahead of him, he noticed what dishes they were given. Besides, he's heard some strange mumbling from some of the m - 1 passengers ahead of him, similar to phrase 'I'm disappointed'. That happened when a passenger asked for some dish but the stewardess gave him a polite smile and said that they had run out of that dish. In that case the passenger needed to choose some other dish that was available. If Polycarp heard no more sounds from a passenger, that meant that the passenger chose his dish at the first try.
Help Polycarp to find out for each dish: whether they could have run out of the dish by the moment Polyarp was served or that dish was definitely available.
Input
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line.
The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000, 1 ≤ k ≤ 100 000) — the number of Polycarp's seat and the number of dishes, respectively.
The second line contains a sequence of k integers a1, a2, ..., ak (1 ≤ ai ≤ 100 000), where ai is the initial number of portions of the i-th dish.
Then m - 1 lines follow, each line contains the description of Polycarp's observations about giving food to a passenger sitting in front of him: the j-th line contains a pair of integers tj, rj (0 ≤ tj ≤ k, 0 ≤ rj ≤ 1), where tj is the number of the dish that was given to the j-th passenger (or 0, if Polycarp didn't notice what dish was given to the passenger), and rj — a 1 or a 0, depending on whether the j-th passenger was or wasn't disappointed, respectively.
We know that sum ai equals at least m, that is,Polycarp will definitely get some dish, even if it is the last thing he wanted. It is guaranteed that the data is consistent.
Sum m for all input sets doesn't exceed 100 000. Sum k for all input sets doesn't exceed 100 000.
Output
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
Examples
Input
2
3 4
2 3 2 1
1 0
0 0
5 5
1 2 1 3 1
3 0
0 0
2 1
4 0
Output
YNNY
YYYNY
Note
In the first input set depending on the choice of the second passenger the situation could develop in different ways:
* If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish;
* If he chose the fourth dish, then by the moment the stewardess reaches Polycarp, they will have run out of the fourth dish;
* Otherwise, Polycarp will be able to choose from any of the four dishes.
Thus, the answer is "YNNY".
In the second input set there is, for example, the following possible scenario. First, the first passenger takes the only third dish, then the second passenger takes the second dish. Then, the third passenger asks for the third dish, but it is not available, so he makes disappointed muttering and ends up with the second dish. Then the fourth passenger takes the fourth dish, and Polycarp ends up with the choice between the first, fourth and fifth dish.
Likewise, another possible scenario is when by the time the stewardess comes to Polycarp, they will have run out of either the first or the fifth dish (this can happen if one of these dishes is taken by the second passenger). It is easy to see that there is more than enough of the fourth dish, so Polycarp can always count on it. Thus, the answer is "YYYNY". | instruction | 0 | 56,020 | 24 | 112,040 |
Tags: greedy
Correct Solution:
```
t = int(input())
for i in range(t):
input()
m,k = map(int,input().split())
ak = list(map(int,input().split()))
ak2 = [0]*k
tjrj = [list(map(int,input().split())) for j in range(m-1)]
num = 0
num2 = 0
num3 = 100002
for j in range(m-1):
if num2 == 1 or tjrj[j][1] == 0:
if tjrj[j][0] != 0:
ak[tjrj[j][0]-1] -= 1
else:
num += 1
else:
for z in range(k):
if ak[z] - num < 1:
ak2[z] = 1
num2 = 1
if tjrj[j][0] != 0:
ak[tjrj[j][0]-1] -= 1
else:
num += 1
for f in range(j,m-1):
if tjrj[f][0] != 0:
ak2[tjrj[f][0]-1] = 0
for f in range(k):
if ak2[f] == 1:
if num3 > ak[f]:
num3 = ak[f]
num -= num3
for z in range(k):
if ak[z] - num < 1 or ak2[z] == 1:
print("Y",end="")
else:
print("N",end="")
print()
``` | output | 1 | 56,020 | 24 | 112,041 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food.
The flight menu has k dishes in total and when Polycarp boarded the flight, he had time to count the number of portions of each dish on board. Thus, he knows values a1, a2, ..., ak, where ai is the number of portions of the i-th dish.
The stewardess has already given food to m - 1 passengers, gave Polycarp a polite smile and asked him what he would prefer. That's when Polycarp realized that they might have run out of some dishes by that moment. For some of the m - 1 passengers ahead of him, he noticed what dishes they were given. Besides, he's heard some strange mumbling from some of the m - 1 passengers ahead of him, similar to phrase 'I'm disappointed'. That happened when a passenger asked for some dish but the stewardess gave him a polite smile and said that they had run out of that dish. In that case the passenger needed to choose some other dish that was available. If Polycarp heard no more sounds from a passenger, that meant that the passenger chose his dish at the first try.
Help Polycarp to find out for each dish: whether they could have run out of the dish by the moment Polyarp was served or that dish was definitely available.
Input
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line.
The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000, 1 ≤ k ≤ 100 000) — the number of Polycarp's seat and the number of dishes, respectively.
The second line contains a sequence of k integers a1, a2, ..., ak (1 ≤ ai ≤ 100 000), where ai is the initial number of portions of the i-th dish.
Then m - 1 lines follow, each line contains the description of Polycarp's observations about giving food to a passenger sitting in front of him: the j-th line contains a pair of integers tj, rj (0 ≤ tj ≤ k, 0 ≤ rj ≤ 1), where tj is the number of the dish that was given to the j-th passenger (or 0, if Polycarp didn't notice what dish was given to the passenger), and rj — a 1 or a 0, depending on whether the j-th passenger was or wasn't disappointed, respectively.
We know that sum ai equals at least m, that is,Polycarp will definitely get some dish, even if it is the last thing he wanted. It is guaranteed that the data is consistent.
Sum m for all input sets doesn't exceed 100 000. Sum k for all input sets doesn't exceed 100 000.
Output
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
Examples
Input
2
3 4
2 3 2 1
1 0
0 0
5 5
1 2 1 3 1
3 0
0 0
2 1
4 0
Output
YNNY
YYYNY
Note
In the first input set depending on the choice of the second passenger the situation could develop in different ways:
* If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish;
* If he chose the fourth dish, then by the moment the stewardess reaches Polycarp, they will have run out of the fourth dish;
* Otherwise, Polycarp will be able to choose from any of the four dishes.
Thus, the answer is "YNNY".
In the second input set there is, for example, the following possible scenario. First, the first passenger takes the only third dish, then the second passenger takes the second dish. Then, the third passenger asks for the third dish, but it is not available, so he makes disappointed muttering and ends up with the second dish. Then the fourth passenger takes the fourth dish, and Polycarp ends up with the choice between the first, fourth and fifth dish.
Likewise, another possible scenario is when by the time the stewardess comes to Polycarp, they will have run out of either the first or the fifth dish (this can happen if one of these dishes is taken by the second passenger). It is easy to see that there is more than enough of the fourth dish, so Polycarp can always count on it. Thus, the answer is "YYYNY". | instruction | 0 | 56,021 | 24 | 112,042 |
Tags: greedy
Correct Solution:
```
import sys
test_count = int(sys.stdin.readline())
for test in range(test_count):
sys.stdin.readline()
m, k = map(int, sys.stdin.readline().split())
counts = list(map(int, sys.stdin.readline().split()))
took = []
unhappy = []
for i in range(m - 1):
t, r = map(int, sys.stdin.readline().split())
t -= 1 # -1 means unknown
took.append(t)
unhappy.append(r)
took_in_total = [0 for dish_count in counts]
for i in range(m - 1):
if took[i] != -1:
took_in_total[took[i]] += 1
took_already = [0 for dish_count in counts]
left = [dish_count for dish_count in counts]
answer = [False for dish_count in counts]
unknown = 0
all_present = True
for i in range(m - 1):
if unhappy[i] == 1 and all_present:
could_exhaust = []
for j in range(k):
if took_already[j] < took_in_total[j]:
continue
if left[j] > unknown:
continue
could_exhaust.append(j)
if len(could_exhaust) == 0:
raise AssertionError
for j in could_exhaust:
answer[j] = True
unknown -= min(map(lambda j: left[j], could_exhaust))
all_present = False
if took[i] != -1:
left[took[i]] -= 1
took_already[took[i]] += 1
if left[took[i]] == 0:
all_present = False
else:
unknown += 1
for j in range(k):
if left[j] <= unknown:
answer[j] = True
sys.stdout.write(
''.join(map(lambda x: 'Y' if x else 'N', answer)) + '\n'
)
``` | output | 1 | 56,021 | 24 | 112,043 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food.
The flight menu has k dishes in total and when Polycarp boarded the flight, he had time to count the number of portions of each dish on board. Thus, he knows values a1, a2, ..., ak, where ai is the number of portions of the i-th dish.
The stewardess has already given food to m - 1 passengers, gave Polycarp a polite smile and asked him what he would prefer. That's when Polycarp realized that they might have run out of some dishes by that moment. For some of the m - 1 passengers ahead of him, he noticed what dishes they were given. Besides, he's heard some strange mumbling from some of the m - 1 passengers ahead of him, similar to phrase 'I'm disappointed'. That happened when a passenger asked for some dish but the stewardess gave him a polite smile and said that they had run out of that dish. In that case the passenger needed to choose some other dish that was available. If Polycarp heard no more sounds from a passenger, that meant that the passenger chose his dish at the first try.
Help Polycarp to find out for each dish: whether they could have run out of the dish by the moment Polyarp was served or that dish was definitely available.
Input
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line.
The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000, 1 ≤ k ≤ 100 000) — the number of Polycarp's seat and the number of dishes, respectively.
The second line contains a sequence of k integers a1, a2, ..., ak (1 ≤ ai ≤ 100 000), where ai is the initial number of portions of the i-th dish.
Then m - 1 lines follow, each line contains the description of Polycarp's observations about giving food to a passenger sitting in front of him: the j-th line contains a pair of integers tj, rj (0 ≤ tj ≤ k, 0 ≤ rj ≤ 1), where tj is the number of the dish that was given to the j-th passenger (or 0, if Polycarp didn't notice what dish was given to the passenger), and rj — a 1 or a 0, depending on whether the j-th passenger was or wasn't disappointed, respectively.
We know that sum ai equals at least m, that is,Polycarp will definitely get some dish, even if it is the last thing he wanted. It is guaranteed that the data is consistent.
Sum m for all input sets doesn't exceed 100 000. Sum k for all input sets doesn't exceed 100 000.
Output
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
Examples
Input
2
3 4
2 3 2 1
1 0
0 0
5 5
1 2 1 3 1
3 0
0 0
2 1
4 0
Output
YNNY
YYYNY
Note
In the first input set depending on the choice of the second passenger the situation could develop in different ways:
* If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish;
* If he chose the fourth dish, then by the moment the stewardess reaches Polycarp, they will have run out of the fourth dish;
* Otherwise, Polycarp will be able to choose from any of the four dishes.
Thus, the answer is "YNNY".
In the second input set there is, for example, the following possible scenario. First, the first passenger takes the only third dish, then the second passenger takes the second dish. Then, the third passenger asks for the third dish, but it is not available, so he makes disappointed muttering and ends up with the second dish. Then the fourth passenger takes the fourth dish, and Polycarp ends up with the choice between the first, fourth and fifth dish.
Likewise, another possible scenario is when by the time the stewardess comes to Polycarp, they will have run out of either the first or the fifth dish (this can happen if one of these dishes is taken by the second passenger). It is easy to see that there is more than enough of the fourth dish, so Polycarp can always count on it. Thus, the answer is "YYYNY". | instruction | 0 | 56,022 | 24 | 112,044 |
Tags: greedy
Correct Solution:
```
n=int(input())
for i in range(n):
input().strip()
q,w=map(int,input().strip().split())
kol=list(map(int,input().strip().split()))
r=[]
e=[]
for ii in range(q-1):
a,s=map(int,input().strip().split())
a-=1
r.append(a)
e.append(s)
rw=[0 for uu in kol]
for ii in range(q-1):
if r[ii]!=-1:
rw[r[ii]]+=1
nd=[0 for uu in kol]
l=[uu for uu in kol]
rez=[False for uu in kol]
qw=0
tr=True
for ii in range(q-1):
if e[ii]==1 and tr:
su=[]
for iii in range(w):
if nd[iii]<rw[iii]:
continue
if l[iii]>qw:
continue
su.append(iii)
if len(su)==0:
raise AssertionError
for iii in su:
rez[iii]=True
qw-=min(map(lambda iii:l[iii],su))
tr=False
if r[ii]!=-1:
l[r[ii]]-=1
nd[r[ii]]+=1
if l[r[ii]]==0:
tr=False
else:
qw+=1
for iii in range(w):
if l[iii]<=qw:
rez[iii]=True
print(''.join(map(lambda x:'Y' if x else 'N',rez)))
``` | output | 1 | 56,022 | 24 | 112,045 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food.
The flight menu has k dishes in total and when Polycarp boarded the flight, he had time to count the number of portions of each dish on board. Thus, he knows values a1, a2, ..., ak, where ai is the number of portions of the i-th dish.
The stewardess has already given food to m - 1 passengers, gave Polycarp a polite smile and asked him what he would prefer. That's when Polycarp realized that they might have run out of some dishes by that moment. For some of the m - 1 passengers ahead of him, he noticed what dishes they were given. Besides, he's heard some strange mumbling from some of the m - 1 passengers ahead of him, similar to phrase 'I'm disappointed'. That happened when a passenger asked for some dish but the stewardess gave him a polite smile and said that they had run out of that dish. In that case the passenger needed to choose some other dish that was available. If Polycarp heard no more sounds from a passenger, that meant that the passenger chose his dish at the first try.
Help Polycarp to find out for each dish: whether they could have run out of the dish by the moment Polyarp was served or that dish was definitely available.
Input
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line.
The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000, 1 ≤ k ≤ 100 000) — the number of Polycarp's seat and the number of dishes, respectively.
The second line contains a sequence of k integers a1, a2, ..., ak (1 ≤ ai ≤ 100 000), where ai is the initial number of portions of the i-th dish.
Then m - 1 lines follow, each line contains the description of Polycarp's observations about giving food to a passenger sitting in front of him: the j-th line contains a pair of integers tj, rj (0 ≤ tj ≤ k, 0 ≤ rj ≤ 1), where tj is the number of the dish that was given to the j-th passenger (or 0, if Polycarp didn't notice what dish was given to the passenger), and rj — a 1 or a 0, depending on whether the j-th passenger was or wasn't disappointed, respectively.
We know that sum ai equals at least m, that is,Polycarp will definitely get some dish, even if it is the last thing he wanted. It is guaranteed that the data is consistent.
Sum m for all input sets doesn't exceed 100 000. Sum k for all input sets doesn't exceed 100 000.
Output
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
Examples
Input
2
3 4
2 3 2 1
1 0
0 0
5 5
1 2 1 3 1
3 0
0 0
2 1
4 0
Output
YNNY
YYYNY
Note
In the first input set depending on the choice of the second passenger the situation could develop in different ways:
* If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish;
* If he chose the fourth dish, then by the moment the stewardess reaches Polycarp, they will have run out of the fourth dish;
* Otherwise, Polycarp will be able to choose from any of the four dishes.
Thus, the answer is "YNNY".
In the second input set there is, for example, the following possible scenario. First, the first passenger takes the only third dish, then the second passenger takes the second dish. Then, the third passenger asks for the third dish, but it is not available, so he makes disappointed muttering and ends up with the second dish. Then the fourth passenger takes the fourth dish, and Polycarp ends up with the choice between the first, fourth and fifth dish.
Likewise, another possible scenario is when by the time the stewardess comes to Polycarp, they will have run out of either the first or the fifth dish (this can happen if one of these dishes is taken by the second passenger). It is easy to see that there is more than enough of the fourth dish, so Polycarp can always count on it. Thus, the answer is "YYYNY". | instruction | 0 | 56,023 | 24 | 112,046 |
Tags: greedy
Correct Solution:
```
def ris():
return map(int, input().split())
def testCase():
m, k = ris()
q = 0
a = list(ris())
some_is_out = False
tmp = set()
for i in range(m - 1):
t, r = ris()
t -= 1
if r == 1 and not some_is_out:
some_is_out = True
tmp = tmp.union(set(filter(lambda x: a[x] <= q, range(k))))
if t == -1:
q += 1
else:
if t in tmp:
tmp.remove(t)
a[t] -= 1
if a[t] < 0:
a[t] = 0
q += 1
if tmp:
q -= min(map(lambda x: a[x], tmp))
print("".join(list(map(lambda x: 'Y' if a[x] - q <= 0 or x in tmp else 'N', range(len(a))))))
for i in range(int(input())):
input()
testCase()
``` | output | 1 | 56,023 | 24 | 112,047 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food.
The flight menu has k dishes in total and when Polycarp boarded the flight, he had time to count the number of portions of each dish on board. Thus, he knows values a1, a2, ..., ak, where ai is the number of portions of the i-th dish.
The stewardess has already given food to m - 1 passengers, gave Polycarp a polite smile and asked him what he would prefer. That's when Polycarp realized that they might have run out of some dishes by that moment. For some of the m - 1 passengers ahead of him, he noticed what dishes they were given. Besides, he's heard some strange mumbling from some of the m - 1 passengers ahead of him, similar to phrase 'I'm disappointed'. That happened when a passenger asked for some dish but the stewardess gave him a polite smile and said that they had run out of that dish. In that case the passenger needed to choose some other dish that was available. If Polycarp heard no more sounds from a passenger, that meant that the passenger chose his dish at the first try.
Help Polycarp to find out for each dish: whether they could have run out of the dish by the moment Polyarp was served or that dish was definitely available.
Input
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line.
The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000, 1 ≤ k ≤ 100 000) — the number of Polycarp's seat and the number of dishes, respectively.
The second line contains a sequence of k integers a1, a2, ..., ak (1 ≤ ai ≤ 100 000), where ai is the initial number of portions of the i-th dish.
Then m - 1 lines follow, each line contains the description of Polycarp's observations about giving food to a passenger sitting in front of him: the j-th line contains a pair of integers tj, rj (0 ≤ tj ≤ k, 0 ≤ rj ≤ 1), where tj is the number of the dish that was given to the j-th passenger (or 0, if Polycarp didn't notice what dish was given to the passenger), and rj — a 1 or a 0, depending on whether the j-th passenger was or wasn't disappointed, respectively.
We know that sum ai equals at least m, that is,Polycarp will definitely get some dish, even if it is the last thing he wanted. It is guaranteed that the data is consistent.
Sum m for all input sets doesn't exceed 100 000. Sum k for all input sets doesn't exceed 100 000.
Output
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
Examples
Input
2
3 4
2 3 2 1
1 0
0 0
5 5
1 2 1 3 1
3 0
0 0
2 1
4 0
Output
YNNY
YYYNY
Note
In the first input set depending on the choice of the second passenger the situation could develop in different ways:
* If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish;
* If he chose the fourth dish, then by the moment the stewardess reaches Polycarp, they will have run out of the fourth dish;
* Otherwise, Polycarp will be able to choose from any of the four dishes.
Thus, the answer is "YNNY".
In the second input set there is, for example, the following possible scenario. First, the first passenger takes the only third dish, then the second passenger takes the second dish. Then, the third passenger asks for the third dish, but it is not available, so he makes disappointed muttering and ends up with the second dish. Then the fourth passenger takes the fourth dish, and Polycarp ends up with the choice between the first, fourth and fifth dish.
Likewise, another possible scenario is when by the time the stewardess comes to Polycarp, they will have run out of either the first or the fifth dish (this can happen if one of these dishes is taken by the second passenger). It is easy to see that there is more than enough of the fourth dish, so Polycarp can always count on it. Thus, the answer is "YYYNY". | instruction | 0 | 56,024 | 24 | 112,048 |
Tags: greedy
Correct Solution:
```
t = int(input())
for j in range(t):
e = input()
m, k = map(int, input().split())
arr = [int(i) for i in input().split()]
sum, bfail = [0] * k, [0] * k
ffail, undef = -1, 0
used = [False] * k
ubfail = 0
for i in range(m - 1):
c, ns = map(int, input().split())
if c == 0:
undef += 1
if ns == 0 and ffail == -1:
ubfail += 1
else:
sum[c - 1] += 1
if ns == 0 and ffail == -1:
bfail[c - 1] += 1
if ns and ffail == -1:
ffail = i
if ffail != -1 and c > 0:
used[c - 1] = True
if ffail == -1:
for i in range(k):
if sum[i] + undef >= arr[i]:
print('Y', end = '')
else:
print('N', end = '')
print()
continue
minu = 10 ** 6
for i in range(k):
if not used[i] and arr[i] - bfail[i] < minu:
minu = arr[i] - bfail[i]
best = i
for i in range(k):
if i == best or undef - minu + sum[i] >= arr[i]:
print('Y', end = '')
elif bfail[i] + ubfail >= arr[i] and not used[i]:
print('Y', end = '')
else:
print('N', end = '')
print()
``` | output | 1 | 56,024 | 24 | 112,049 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food.
The flight menu has k dishes in total and when Polycarp boarded the flight, he had time to count the number of portions of each dish on board. Thus, he knows values a1, a2, ..., ak, where ai is the number of portions of the i-th dish.
The stewardess has already given food to m - 1 passengers, gave Polycarp a polite smile and asked him what he would prefer. That's when Polycarp realized that they might have run out of some dishes by that moment. For some of the m - 1 passengers ahead of him, he noticed what dishes they were given. Besides, he's heard some strange mumbling from some of the m - 1 passengers ahead of him, similar to phrase 'I'm disappointed'. That happened when a passenger asked for some dish but the stewardess gave him a polite smile and said that they had run out of that dish. In that case the passenger needed to choose some other dish that was available. If Polycarp heard no more sounds from a passenger, that meant that the passenger chose his dish at the first try.
Help Polycarp to find out for each dish: whether they could have run out of the dish by the moment Polyarp was served or that dish was definitely available.
Input
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line.
The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000, 1 ≤ k ≤ 100 000) — the number of Polycarp's seat and the number of dishes, respectively.
The second line contains a sequence of k integers a1, a2, ..., ak (1 ≤ ai ≤ 100 000), where ai is the initial number of portions of the i-th dish.
Then m - 1 lines follow, each line contains the description of Polycarp's observations about giving food to a passenger sitting in front of him: the j-th line contains a pair of integers tj, rj (0 ≤ tj ≤ k, 0 ≤ rj ≤ 1), where tj is the number of the dish that was given to the j-th passenger (or 0, if Polycarp didn't notice what dish was given to the passenger), and rj — a 1 or a 0, depending on whether the j-th passenger was or wasn't disappointed, respectively.
We know that sum ai equals at least m, that is,Polycarp will definitely get some dish, even if it is the last thing he wanted. It is guaranteed that the data is consistent.
Sum m for all input sets doesn't exceed 100 000. Sum k for all input sets doesn't exceed 100 000.
Output
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
Examples
Input
2
3 4
2 3 2 1
1 0
0 0
5 5
1 2 1 3 1
3 0
0 0
2 1
4 0
Output
YNNY
YYYNY
Note
In the first input set depending on the choice of the second passenger the situation could develop in different ways:
* If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish;
* If he chose the fourth dish, then by the moment the stewardess reaches Polycarp, they will have run out of the fourth dish;
* Otherwise, Polycarp will be able to choose from any of the four dishes.
Thus, the answer is "YNNY".
In the second input set there is, for example, the following possible scenario. First, the first passenger takes the only third dish, then the second passenger takes the second dish. Then, the third passenger asks for the third dish, but it is not available, so he makes disappointed muttering and ends up with the second dish. Then the fourth passenger takes the fourth dish, and Polycarp ends up with the choice between the first, fourth and fifth dish.
Likewise, another possible scenario is when by the time the stewardess comes to Polycarp, they will have run out of either the first or the fifth dish (this can happen if one of these dishes is taken by the second passenger). It is easy to see that there is more than enough of the fourth dish, so Polycarp can always count on it. Thus, the answer is "YYYNY". | instruction | 0 | 56,025 | 24 | 112,050 |
Tags: greedy
Correct Solution:
```
import sys
n=int(input())
for i in range(n):
sys.stdin.readline()
q,w=map(int,sys.stdin.readline().split())
kol=list(map(int,sys.stdin.readline().split()))
r=[]
e=[]
for ii in range(q-1):
a,s=map(int,sys.stdin.readline().split())
a-=1
r.append(a)
e.append(s)
rw=[0 for uu in kol]
for ii in range(q-1):
if r[ii]!=-1:
rw[r[ii]]+=1
nd=[0 for uu in kol]
l=[uu for uu in kol]
rez=[False for uu in kol]
qw=0
tr=True
for ii in range(q-1):
if e[ii]==1 and tr:
su=[]
for iii in range(w):
if nd[iii]<rw[iii]:
continue
if l[iii]>qw:
continue
su.append(iii)
if len(su)==0:
raise AssertionError
for iii in su:
rez[iii]=True
qw-=min(map(lambda iii:l[iii],su))
tr=False
if r[ii]!=-1:
l[r[ii]]-=1
nd[r[ii]]+=1
if l[r[ii]]==0:
tr=False
else:
qw+=1
for iii in range(w):
if l[iii]<=qw:
rez[iii]=True
sys.stdout.write(''.join(map(lambda x:'Y' if x else 'N',rez))+'\n')
``` | output | 1 | 56,025 | 24 | 112,051 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food.
The flight menu has k dishes in total and when Polycarp boarded the flight, he had time to count the number of portions of each dish on board. Thus, he knows values a1, a2, ..., ak, where ai is the number of portions of the i-th dish.
The stewardess has already given food to m - 1 passengers, gave Polycarp a polite smile and asked him what he would prefer. That's when Polycarp realized that they might have run out of some dishes by that moment. For some of the m - 1 passengers ahead of him, he noticed what dishes they were given. Besides, he's heard some strange mumbling from some of the m - 1 passengers ahead of him, similar to phrase 'I'm disappointed'. That happened when a passenger asked for some dish but the stewardess gave him a polite smile and said that they had run out of that dish. In that case the passenger needed to choose some other dish that was available. If Polycarp heard no more sounds from a passenger, that meant that the passenger chose his dish at the first try.
Help Polycarp to find out for each dish: whether they could have run out of the dish by the moment Polyarp was served or that dish was definitely available.
Input
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line.
The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000, 1 ≤ k ≤ 100 000) — the number of Polycarp's seat and the number of dishes, respectively.
The second line contains a sequence of k integers a1, a2, ..., ak (1 ≤ ai ≤ 100 000), where ai is the initial number of portions of the i-th dish.
Then m - 1 lines follow, each line contains the description of Polycarp's observations about giving food to a passenger sitting in front of him: the j-th line contains a pair of integers tj, rj (0 ≤ tj ≤ k, 0 ≤ rj ≤ 1), where tj is the number of the dish that was given to the j-th passenger (or 0, if Polycarp didn't notice what dish was given to the passenger), and rj — a 1 or a 0, depending on whether the j-th passenger was or wasn't disappointed, respectively.
We know that sum ai equals at least m, that is,Polycarp will definitely get some dish, even if it is the last thing he wanted. It is guaranteed that the data is consistent.
Sum m for all input sets doesn't exceed 100 000. Sum k for all input sets doesn't exceed 100 000.
Output
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
Examples
Input
2
3 4
2 3 2 1
1 0
0 0
5 5
1 2 1 3 1
3 0
0 0
2 1
4 0
Output
YNNY
YYYNY
Note
In the first input set depending on the choice of the second passenger the situation could develop in different ways:
* If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish;
* If he chose the fourth dish, then by the moment the stewardess reaches Polycarp, they will have run out of the fourth dish;
* Otherwise, Polycarp will be able to choose from any of the four dishes.
Thus, the answer is "YNNY".
In the second input set there is, for example, the following possible scenario. First, the first passenger takes the only third dish, then the second passenger takes the second dish. Then, the third passenger asks for the third dish, but it is not available, so he makes disappointed muttering and ends up with the second dish. Then the fourth passenger takes the fourth dish, and Polycarp ends up with the choice between the first, fourth and fifth dish.
Likewise, another possible scenario is when by the time the stewardess comes to Polycarp, they will have run out of either the first or the fifth dish (this can happen if one of these dishes is taken by the second passenger). It is easy to see that there is more than enough of the fourth dish, so Polycarp can always count on it. Thus, the answer is "YYYNY". | instruction | 0 | 56,026 | 24 | 112,052 |
Tags: greedy
Correct Solution:
```
import sys
t = int(input())
for i in range(t):
remove_from_all = 0
input()
m, k = (int(x) for x in input().split())
dishes = [int(x) for x in input().split()]
inputs = []
for j in range(m - 1):
t, r = (int(x) for x in input().split())
inputs.append((t - 1, r))
seen_upset = False
for i, v in enumerate(inputs):
t, r = v
if r == 1 and not seen_upset:
impossible = set()
for j in range(i, len(inputs)):
_t, _r = inputs[j]
impossible.add(_t)
for j in range(len(dishes)):
if dishes[j] > remove_from_all:
impossible.add(j)
minimal = float("inf")
for j in range(len(dishes)):
if j not in impossible:
minimal = min(dishes[j], minimal)
dishes[j] = 0
remove_from_all -= minimal
seen_upset = True
if t == -1:
remove_from_all += 1
else:
dishes[t] -= 1
for j in dishes:
sys.stdout.write("Y" if j - remove_from_all <= 0 else "N")
print("")
``` | output | 1 | 56,026 | 24 | 112,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food.
The flight menu has k dishes in total and when Polycarp boarded the flight, he had time to count the number of portions of each dish on board. Thus, he knows values a1, a2, ..., ak, where ai is the number of portions of the i-th dish.
The stewardess has already given food to m - 1 passengers, gave Polycarp a polite smile and asked him what he would prefer. That's when Polycarp realized that they might have run out of some dishes by that moment. For some of the m - 1 passengers ahead of him, he noticed what dishes they were given. Besides, he's heard some strange mumbling from some of the m - 1 passengers ahead of him, similar to phrase 'I'm disappointed'. That happened when a passenger asked for some dish but the stewardess gave him a polite smile and said that they had run out of that dish. In that case the passenger needed to choose some other dish that was available. If Polycarp heard no more sounds from a passenger, that meant that the passenger chose his dish at the first try.
Help Polycarp to find out for each dish: whether they could have run out of the dish by the moment Polyarp was served or that dish was definitely available.
Input
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line.
The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000, 1 ≤ k ≤ 100 000) — the number of Polycarp's seat and the number of dishes, respectively.
The second line contains a sequence of k integers a1, a2, ..., ak (1 ≤ ai ≤ 100 000), where ai is the initial number of portions of the i-th dish.
Then m - 1 lines follow, each line contains the description of Polycarp's observations about giving food to a passenger sitting in front of him: the j-th line contains a pair of integers tj, rj (0 ≤ tj ≤ k, 0 ≤ rj ≤ 1), where tj is the number of the dish that was given to the j-th passenger (or 0, if Polycarp didn't notice what dish was given to the passenger), and rj — a 1 or a 0, depending on whether the j-th passenger was or wasn't disappointed, respectively.
We know that sum ai equals at least m, that is,Polycarp will definitely get some dish, even if it is the last thing he wanted. It is guaranteed that the data is consistent.
Sum m for all input sets doesn't exceed 100 000. Sum k for all input sets doesn't exceed 100 000.
Output
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
Examples
Input
2
3 4
2 3 2 1
1 0
0 0
5 5
1 2 1 3 1
3 0
0 0
2 1
4 0
Output
YNNY
YYYNY
Note
In the first input set depending on the choice of the second passenger the situation could develop in different ways:
* If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish;
* If he chose the fourth dish, then by the moment the stewardess reaches Polycarp, they will have run out of the fourth dish;
* Otherwise, Polycarp will be able to choose from any of the four dishes.
Thus, the answer is "YNNY".
In the second input set there is, for example, the following possible scenario. First, the first passenger takes the only third dish, then the second passenger takes the second dish. Then, the third passenger asks for the third dish, but it is not available, so he makes disappointed muttering and ends up with the second dish. Then the fourth passenger takes the fourth dish, and Polycarp ends up with the choice between the first, fourth and fifth dish.
Likewise, another possible scenario is when by the time the stewardess comes to Polycarp, they will have run out of either the first or the fifth dish (this can happen if one of these dishes is taken by the second passenger). It is easy to see that there is more than enough of the fourth dish, so Polycarp can always count on it. Thus, the answer is "YYYNY".
Submitted Solution:
```
def ris():
return map(int, input().split())
def testCase():
m, k = ris()
q = 0
a = list(ris())
some_is_out = False
tmp = set()
for i in range(m - 1):
t, r = ris()
t -= 1
if r == 1 and not some_is_out:
some_is_out = True
tmp = tmp.union(set(filter(lambda x: a[x] <= q, range(k))))
if t == -1:
q += 1
else:
if t in tmp:
tmp.remove(t)
a[t] -= 1
if a[t] < 0:
a[t] = 0
q += 1
if tmp:
q -= min(map(lambda x: a[x], tmp))
print("".join(list(map(lambda x: 'Y' if a[x] - q <= 0 or x in tmp else 'N', range(len(a))))))
for i in range(int(input())):
input()
testCase()
# Made By Mostafa_Khaled
``` | instruction | 0 | 56,027 | 24 | 112,054 |
Yes | output | 1 | 56,027 | 24 | 112,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food.
The flight menu has k dishes in total and when Polycarp boarded the flight, he had time to count the number of portions of each dish on board. Thus, he knows values a1, a2, ..., ak, where ai is the number of portions of the i-th dish.
The stewardess has already given food to m - 1 passengers, gave Polycarp a polite smile and asked him what he would prefer. That's when Polycarp realized that they might have run out of some dishes by that moment. For some of the m - 1 passengers ahead of him, he noticed what dishes they were given. Besides, he's heard some strange mumbling from some of the m - 1 passengers ahead of him, similar to phrase 'I'm disappointed'. That happened when a passenger asked for some dish but the stewardess gave him a polite smile and said that they had run out of that dish. In that case the passenger needed to choose some other dish that was available. If Polycarp heard no more sounds from a passenger, that meant that the passenger chose his dish at the first try.
Help Polycarp to find out for each dish: whether they could have run out of the dish by the moment Polyarp was served or that dish was definitely available.
Input
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line.
The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000, 1 ≤ k ≤ 100 000) — the number of Polycarp's seat and the number of dishes, respectively.
The second line contains a sequence of k integers a1, a2, ..., ak (1 ≤ ai ≤ 100 000), where ai is the initial number of portions of the i-th dish.
Then m - 1 lines follow, each line contains the description of Polycarp's observations about giving food to a passenger sitting in front of him: the j-th line contains a pair of integers tj, rj (0 ≤ tj ≤ k, 0 ≤ rj ≤ 1), where tj is the number of the dish that was given to the j-th passenger (or 0, if Polycarp didn't notice what dish was given to the passenger), and rj — a 1 or a 0, depending on whether the j-th passenger was or wasn't disappointed, respectively.
We know that sum ai equals at least m, that is,Polycarp will definitely get some dish, even if it is the last thing he wanted. It is guaranteed that the data is consistent.
Sum m for all input sets doesn't exceed 100 000. Sum k for all input sets doesn't exceed 100 000.
Output
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
Examples
Input
2
3 4
2 3 2 1
1 0
0 0
5 5
1 2 1 3 1
3 0
0 0
2 1
4 0
Output
YNNY
YYYNY
Note
In the first input set depending on the choice of the second passenger the situation could develop in different ways:
* If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish;
* If he chose the fourth dish, then by the moment the stewardess reaches Polycarp, they will have run out of the fourth dish;
* Otherwise, Polycarp will be able to choose from any of the four dishes.
Thus, the answer is "YNNY".
In the second input set there is, for example, the following possible scenario. First, the first passenger takes the only third dish, then the second passenger takes the second dish. Then, the third passenger asks for the third dish, but it is not available, so he makes disappointed muttering and ends up with the second dish. Then the fourth passenger takes the fourth dish, and Polycarp ends up with the choice between the first, fourth and fifth dish.
Likewise, another possible scenario is when by the time the stewardess comes to Polycarp, they will have run out of either the first or the fifth dish (this can happen if one of these dishes is taken by the second passenger). It is easy to see that there is more than enough of the fourth dish, so Polycarp can always count on it. Thus, the answer is "YYYNY".
Submitted Solution:
```
for i in range(int(input())):
_ = input()
m, k = [int(x) for x in input().split()]
foods = [[int(x), 0] for x in input().split()]
n = 0
for i in range(m-1):
eat, sad = [int(x) for x in input().split()]
if sad:
maybe = [(i, x) for i, x in enumerate(foods) if x[0] - x[1] - n <= 0]
if len(maybe) == 1:
i = maybe[0][0]
x = maybe[0][1]
dif = x[0] - x[1]
foods[i] = [x[0], x[0]]
n -= dif
if not eat: n += 1
else: foods[eat-1][1] += 1
print(''.join(['N' if x[0] - x[1] - n > 0 else 'Y' for x in foods]))
``` | instruction | 0 | 56,028 | 24 | 112,056 |
No | output | 1 | 56,028 | 24 | 112,057 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food.
The flight menu has k dishes in total and when Polycarp boarded the flight, he had time to count the number of portions of each dish on board. Thus, he knows values a1, a2, ..., ak, where ai is the number of portions of the i-th dish.
The stewardess has already given food to m - 1 passengers, gave Polycarp a polite smile and asked him what he would prefer. That's when Polycarp realized that they might have run out of some dishes by that moment. For some of the m - 1 passengers ahead of him, he noticed what dishes they were given. Besides, he's heard some strange mumbling from some of the m - 1 passengers ahead of him, similar to phrase 'I'm disappointed'. That happened when a passenger asked for some dish but the stewardess gave him a polite smile and said that they had run out of that dish. In that case the passenger needed to choose some other dish that was available. If Polycarp heard no more sounds from a passenger, that meant that the passenger chose his dish at the first try.
Help Polycarp to find out for each dish: whether they could have run out of the dish by the moment Polyarp was served or that dish was definitely available.
Input
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line.
The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000, 1 ≤ k ≤ 100 000) — the number of Polycarp's seat and the number of dishes, respectively.
The second line contains a sequence of k integers a1, a2, ..., ak (1 ≤ ai ≤ 100 000), where ai is the initial number of portions of the i-th dish.
Then m - 1 lines follow, each line contains the description of Polycarp's observations about giving food to a passenger sitting in front of him: the j-th line contains a pair of integers tj, rj (0 ≤ tj ≤ k, 0 ≤ rj ≤ 1), where tj is the number of the dish that was given to the j-th passenger (or 0, if Polycarp didn't notice what dish was given to the passenger), and rj — a 1 or a 0, depending on whether the j-th passenger was or wasn't disappointed, respectively.
We know that sum ai equals at least m, that is,Polycarp will definitely get some dish, even if it is the last thing he wanted. It is guaranteed that the data is consistent.
Sum m for all input sets doesn't exceed 100 000. Sum k for all input sets doesn't exceed 100 000.
Output
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
Examples
Input
2
3 4
2 3 2 1
1 0
0 0
5 5
1 2 1 3 1
3 0
0 0
2 1
4 0
Output
YNNY
YYYNY
Note
In the first input set depending on the choice of the second passenger the situation could develop in different ways:
* If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish;
* If he chose the fourth dish, then by the moment the stewardess reaches Polycarp, they will have run out of the fourth dish;
* Otherwise, Polycarp will be able to choose from any of the four dishes.
Thus, the answer is "YNNY".
In the second input set there is, for example, the following possible scenario. First, the first passenger takes the only third dish, then the second passenger takes the second dish. Then, the third passenger asks for the third dish, but it is not available, so he makes disappointed muttering and ends up with the second dish. Then the fourth passenger takes the fourth dish, and Polycarp ends up with the choice between the first, fourth and fifth dish.
Likewise, another possible scenario is when by the time the stewardess comes to Polycarp, they will have run out of either the first or the fifth dish (this can happen if one of these dishes is taken by the second passenger). It is easy to see that there is more than enough of the fourth dish, so Polycarp can always count on it. Thus, the answer is "YYYNY".
Submitted Solution:
```
import sys
t = int(input())
for i in range(t):
remove_from_all = 0
input()
m, k = (int(x) for x in input().split())
dishes = [int(x) for x in input().split()]
for j in range(m - 1):
t, r = (int(x) for x in input().split())
if t == 0:
remove_from_all += 1
else:
dishes[t - 1] -= 1
for j in dishes:
sys.stdout.write("Y" if j - remove_from_all <= 0 else "N")
print("")
``` | instruction | 0 | 56,029 | 24 | 112,058 |
No | output | 1 | 56,029 | 24 | 112,059 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food.
The flight menu has k dishes in total and when Polycarp boarded the flight, he had time to count the number of portions of each dish on board. Thus, he knows values a1, a2, ..., ak, where ai is the number of portions of the i-th dish.
The stewardess has already given food to m - 1 passengers, gave Polycarp a polite smile and asked him what he would prefer. That's when Polycarp realized that they might have run out of some dishes by that moment. For some of the m - 1 passengers ahead of him, he noticed what dishes they were given. Besides, he's heard some strange mumbling from some of the m - 1 passengers ahead of him, similar to phrase 'I'm disappointed'. That happened when a passenger asked for some dish but the stewardess gave him a polite smile and said that they had run out of that dish. In that case the passenger needed to choose some other dish that was available. If Polycarp heard no more sounds from a passenger, that meant that the passenger chose his dish at the first try.
Help Polycarp to find out for each dish: whether they could have run out of the dish by the moment Polyarp was served or that dish was definitely available.
Input
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line.
The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000, 1 ≤ k ≤ 100 000) — the number of Polycarp's seat and the number of dishes, respectively.
The second line contains a sequence of k integers a1, a2, ..., ak (1 ≤ ai ≤ 100 000), where ai is the initial number of portions of the i-th dish.
Then m - 1 lines follow, each line contains the description of Polycarp's observations about giving food to a passenger sitting in front of him: the j-th line contains a pair of integers tj, rj (0 ≤ tj ≤ k, 0 ≤ rj ≤ 1), where tj is the number of the dish that was given to the j-th passenger (or 0, if Polycarp didn't notice what dish was given to the passenger), and rj — a 1 or a 0, depending on whether the j-th passenger was or wasn't disappointed, respectively.
We know that sum ai equals at least m, that is,Polycarp will definitely get some dish, even if it is the last thing he wanted. It is guaranteed that the data is consistent.
Sum m for all input sets doesn't exceed 100 000. Sum k for all input sets doesn't exceed 100 000.
Output
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
Examples
Input
2
3 4
2 3 2 1
1 0
0 0
5 5
1 2 1 3 1
3 0
0 0
2 1
4 0
Output
YNNY
YYYNY
Note
In the first input set depending on the choice of the second passenger the situation could develop in different ways:
* If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish;
* If he chose the fourth dish, then by the moment the stewardess reaches Polycarp, they will have run out of the fourth dish;
* Otherwise, Polycarp will be able to choose from any of the four dishes.
Thus, the answer is "YNNY".
In the second input set there is, for example, the following possible scenario. First, the first passenger takes the only third dish, then the second passenger takes the second dish. Then, the third passenger asks for the third dish, but it is not available, so he makes disappointed muttering and ends up with the second dish. Then the fourth passenger takes the fourth dish, and Polycarp ends up with the choice between the first, fourth and fifth dish.
Likewise, another possible scenario is when by the time the stewardess comes to Polycarp, they will have run out of either the first or the fifth dish (this can happen if one of these dishes is taken by the second passenger). It is easy to see that there is more than enough of the fourth dish, so Polycarp can always count on it. Thus, the answer is "YYYNY".
Submitted Solution:
```
n = int(input())
for _ in range(n):
input()
m, k = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
unknowns = 0
firstDispleased = False
for i in range(m - 1):
t, r = [int(s) for s in input().split()]
if r == 1:
unknowns += 1
if not firstDispleased:
firstDispleased = True
for j in range(len(a)):
if a[j] + unknowns < j:
a[j] = 0
if t == 0:
a = [v - 1 for v in a]
else:
a[t - 1] -= 1
for v in a:
if v <= 0:
print('Y', end='')
else:
print('N', end='')
print()
``` | instruction | 0 | 56,030 | 24 | 112,060 |
No | output | 1 | 56,030 | 24 | 112,061 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is flying in the airplane. Finally, it is his favorite time — the lunchtime. The BerAvia company stewardess is giving food consecutively to all the passengers from the 1-th one to the last one. Polycarp is sitting on seat m, that means, he will be the m-th person to get food.
The flight menu has k dishes in total and when Polycarp boarded the flight, he had time to count the number of portions of each dish on board. Thus, he knows values a1, a2, ..., ak, where ai is the number of portions of the i-th dish.
The stewardess has already given food to m - 1 passengers, gave Polycarp a polite smile and asked him what he would prefer. That's when Polycarp realized that they might have run out of some dishes by that moment. For some of the m - 1 passengers ahead of him, he noticed what dishes they were given. Besides, he's heard some strange mumbling from some of the m - 1 passengers ahead of him, similar to phrase 'I'm disappointed'. That happened when a passenger asked for some dish but the stewardess gave him a polite smile and said that they had run out of that dish. In that case the passenger needed to choose some other dish that was available. If Polycarp heard no more sounds from a passenger, that meant that the passenger chose his dish at the first try.
Help Polycarp to find out for each dish: whether they could have run out of the dish by the moment Polyarp was served or that dish was definitely available.
Input
Each test in this problem consists of one or more input sets. First goes a string that contains a single integer t (1 ≤ t ≤ 100 000) — the number of input data sets in the test. Then the sets follow, each set is preceded by an empty line.
The first line of each set of the input contains integers m, k (2 ≤ m ≤ 100 000, 1 ≤ k ≤ 100 000) — the number of Polycarp's seat and the number of dishes, respectively.
The second line contains a sequence of k integers a1, a2, ..., ak (1 ≤ ai ≤ 100 000), where ai is the initial number of portions of the i-th dish.
Then m - 1 lines follow, each line contains the description of Polycarp's observations about giving food to a passenger sitting in front of him: the j-th line contains a pair of integers tj, rj (0 ≤ tj ≤ k, 0 ≤ rj ≤ 1), where tj is the number of the dish that was given to the j-th passenger (or 0, if Polycarp didn't notice what dish was given to the passenger), and rj — a 1 or a 0, depending on whether the j-th passenger was or wasn't disappointed, respectively.
We know that sum ai equals at least m, that is,Polycarp will definitely get some dish, even if it is the last thing he wanted. It is guaranteed that the data is consistent.
Sum m for all input sets doesn't exceed 100 000. Sum k for all input sets doesn't exceed 100 000.
Output
For each input set print the answer as a single line. Print a string of k letters "Y" or "N". Letter "Y" in position i should be printed if they could have run out of the i-th dish by the time the stewardess started serving Polycarp.
Examples
Input
2
3 4
2 3 2 1
1 0
0 0
5 5
1 2 1 3 1
3 0
0 0
2 1
4 0
Output
YNNY
YYYNY
Note
In the first input set depending on the choice of the second passenger the situation could develop in different ways:
* If he chose the first dish, then by the moment the stewardess reaches Polycarp, they will have run out of the first dish;
* If he chose the fourth dish, then by the moment the stewardess reaches Polycarp, they will have run out of the fourth dish;
* Otherwise, Polycarp will be able to choose from any of the four dishes.
Thus, the answer is "YNNY".
In the second input set there is, for example, the following possible scenario. First, the first passenger takes the only third dish, then the second passenger takes the second dish. Then, the third passenger asks for the third dish, but it is not available, so he makes disappointed muttering and ends up with the second dish. Then the fourth passenger takes the fourth dish, and Polycarp ends up with the choice between the first, fourth and fifth dish.
Likewise, another possible scenario is when by the time the stewardess comes to Polycarp, they will have run out of either the first or the fifth dish (this can happen if one of these dishes is taken by the second passenger). It is easy to see that there is more than enough of the fourth dish, so Polycarp can always count on it. Thus, the answer is "YYYNY".
Submitted Solution:
```
b = []
t = int(input())
s = ""
for i in range(t):
input()
m, k = [int(l) for l in input().split()]
a = [int(j) for j in input().split()]
upset = -1
unknownBeforeUpset = 0
for i1 in range(m-1):
ti, r = [int(i) for i in input().split()]
ti-=1
#if r == 0:
if ti != -1:
a[ti] -= 1
else:
a = [j-1 for j in a]
#if upset == -1:
# unknownBeforeUpset += 1
#else:
# upset = i1
s += "".join(["Y" if j <=0 else "N" for j in a]) + '\n'
print(s)
``` | instruction | 0 | 56,031 | 24 | 112,062 |
No | output | 1 | 56,031 | 24 | 112,063 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is constraints.
Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly T minutes.
In the player, Polycarp stores n songs, each of which is characterized by two parameters: t_i and g_i, where t_i is the length of the song in minutes (1 ≤ t_i ≤ 15), g_i is its genre (1 ≤ g_i ≤ 3).
Polycarp wants to create such a playlist so that he can listen to music all the time on the way from the university to his home, and at the time of his arrival home, the playlist is over. Polycarp never interrupts songs and always listens to them from beginning to end. Thus, if he started listening to the i-th song, he would spend exactly t_i minutes on its listening. Polycarp also does not like when two songs of the same genre play in a row (i.e. successively/adjacently) or when the songs in his playlist are repeated.
Help Polycarpus count the number of different sequences of songs (their order matters), the total duration is exactly T, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different.
Input
The first line of the input contains two integers n and T (1 ≤ n ≤ 15, 1 ≤ T ≤ 225) — the number of songs in the player and the required total duration, respectively.
Next, the n lines contain descriptions of songs: the i-th line contains two integers t_i and g_i (1 ≤ t_i ≤ 15, 1 ≤ g_i ≤ 3) — the duration of the i-th song and its genre, respectively.
Output
Output one integer — the number of different sequences of songs, the total length of exactly T, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different. Since the answer may be huge, output it modulo 10^9 + 7 (that is, the remainder when dividing the quantity by 10^9 + 7).
Examples
Input
3 3
1 1
1 2
1 3
Output
6
Input
3 3
1 1
1 1
1 3
Output
2
Input
4 10
5 3
2 1
3 2
5 1
Output
10
Note
In the first example, Polycarp can make any of the 6 possible playlist by rearranging the available songs: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2] and [3, 2, 1] (indices of the songs are given).
In the second example, the first and second songs cannot go in succession (since they have the same genre). Thus, Polycarp can create a playlist in one of 2 possible ways: [1, 3, 2] and [2, 3, 1] (indices of the songs are given).
In the third example, Polycarp can make the following playlists: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1], [1, 4], [4, 1], [2, 3, 4] and [4, 3, 2] (indices of the songs are given). | instruction | 0 | 56,458 | 24 | 112,916 |
Tags: bitmasks, combinatorics, dp
Correct Solution:
```
import sys
input=sys.stdin.readline
mod=10**9+7
n,t=map(int,input().split())
a=[] #Denote song number by it's index in this list
for i in range(n):
time,genre=map(int,input().split())
genre-=1 #converting to 0-based indexing
a.append((time,genre))
dp=[[0 for j in range(3)] for i in range(1<<n)] #dp[permuation of song][last genre of that permutation]
for i in range(n):
dp[1<<i][a[i][1]]=1
for i in range(1<<n):
for j in range(3):
if(dp[i][j]==0):
continue
mask=1 #Will correspond to the kth bit, i.e 1<<k for each iteration, for the case of including the kth song
for k in range(n):
if(i&mask or a[k][1]==j): #as we are not allowed to repeat same song or have same genre successively
mask<<=1
continue
dp[i|mask][a[k][1]]=(dp[i|mask][a[k][1]]+dp[i][j])%mod
mask<<=1
ans=0
for i in range(1<<n):
mask=1
duration=0
for j in range(n):
if(i&mask):
duration+=a[j][0]
mask<<=1
if(duration==t):
ans=(ans+sum(dp[i]))%mod
print(ans)
``` | output | 1 | 56,458 | 24 | 112,917 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is constraints.
Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly T minutes.
In the player, Polycarp stores n songs, each of which is characterized by two parameters: t_i and g_i, where t_i is the length of the song in minutes (1 ≤ t_i ≤ 15), g_i is its genre (1 ≤ g_i ≤ 3).
Polycarp wants to create such a playlist so that he can listen to music all the time on the way from the university to his home, and at the time of his arrival home, the playlist is over. Polycarp never interrupts songs and always listens to them from beginning to end. Thus, if he started listening to the i-th song, he would spend exactly t_i minutes on its listening. Polycarp also does not like when two songs of the same genre play in a row (i.e. successively/adjacently) or when the songs in his playlist are repeated.
Help Polycarpus count the number of different sequences of songs (their order matters), the total duration is exactly T, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different.
Input
The first line of the input contains two integers n and T (1 ≤ n ≤ 15, 1 ≤ T ≤ 225) — the number of songs in the player and the required total duration, respectively.
Next, the n lines contain descriptions of songs: the i-th line contains two integers t_i and g_i (1 ≤ t_i ≤ 15, 1 ≤ g_i ≤ 3) — the duration of the i-th song and its genre, respectively.
Output
Output one integer — the number of different sequences of songs, the total length of exactly T, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different. Since the answer may be huge, output it modulo 10^9 + 7 (that is, the remainder when dividing the quantity by 10^9 + 7).
Examples
Input
3 3
1 1
1 2
1 3
Output
6
Input
3 3
1 1
1 1
1 3
Output
2
Input
4 10
5 3
2 1
3 2
5 1
Output
10
Note
In the first example, Polycarp can make any of the 6 possible playlist by rearranging the available songs: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2] and [3, 2, 1] (indices of the songs are given).
In the second example, the first and second songs cannot go in succession (since they have the same genre). Thus, Polycarp can create a playlist in one of 2 possible ways: [1, 3, 2] and [2, 3, 1] (indices of the songs are given).
In the third example, Polycarp can make the following playlists: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1], [1, 4], [4, 1], [2, 3, 4] and [4, 3, 2] (indices of the songs are given). | instruction | 0 | 56,459 | 24 | 112,918 |
Tags: bitmasks, combinatorics, dp
Correct Solution:
```
import sys
input = sys.stdin.readline
n,T=map(int,input().split())
S=[list(map(int,input().split())) for i in range(n)]
DP=[[0]*(4) for i in range(T+1)]
mod=10**9+7
from functools import lru_cache
@lru_cache(maxsize=None)
def calc(used,recent,time):
ANS=0
for i in range(n):
#print(i,used)
if i in used:
continue
if time+S[i][0]>T:
continue
if S[i][1]==recent:
continue
if time+S[i][0]==T:
ANS+=1
if time+S[i][0]<T:
used2=list(used)+[i]
used2.sort()
recent2=S[i][1]
time2=time+S[i][0]
ANS=(ANS+calc(tuple(used2),recent2,time2))%mod
return ANS
print(calc(tuple(),-1,0)%mod)
``` | output | 1 | 56,459 | 24 | 112,919 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.