description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
def main():
s, t = [0] * 123, [0] * 123
for c in input():
s[ord(c)] += 1
for c in input():
t[ord(c)] += 1
yay = whoops = 0
for i, x, y in zip(range(123), s, t):
if x > y:
s[i] = x - y
t[i] = 0
yay += y
else:
s[i] = 0
t[i] = y - x
yay += x
t[ord("A") : ord("Z") + 1], t[ord("a") : ord("z") + 1] = (
t[ord("a") : ord("z") + 1],
t[ord("A") : ord("Z") + 1],
)
for i, x, y in zip(range(123), s, t):
if x > y:
s[i] = x - y
t[i] = 0
whoops += y
else:
s[i] = 0
t[i] = y - x
whoops += x
print(yay, whoops)
main()
|
FUNC_DEF ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
a = A.swapcase()
Al = A + a
numS = [(0) for i in Al]
numT = [(0) for i in Al]
numT_ = [(0) for i in Al]
s = input()
t = input()
t_ = t.swapcase()
yay = 0
whoops = 0
for i in range(len(Al)):
numS[i] = s.count(Al[i])
numT[i] = t.count(Al[i])
numT_[i] += t_.count(Al[i])
yay += min(numS[i], numT[i])
if i <= 25:
k = i + 26
else:
k = i - 26
numT_[k] -= min(numS[i], numT[i])
numS[i] -= min(numS[i], numT[i])
for i in range(len(Al)):
whoops += min(numS[i], numT_[i])
print(yay, whoops)
|
ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = input()
d = dict()
t = input()
for x in t:
if x in d:
d[x] += 1
else:
d[x] = 1
yay = 0
whoops = 0
mark = [True] * len(s)
i = -1
for x in s:
i += 1
if x in d:
d[x] -= 1
yay += 1
if d[x] == 0:
d.pop(x)
mark[i] = False
i = -1
for x in s:
i += 1
if mark[i] == True:
if x.islower():
temp = chr(ord(x) - 32)
if temp in d:
whoops += 1
d[temp] -= 1
if d[temp] == 0:
d.pop(temp)
if x.isupper():
temp = chr(ord(x) + 32)
if temp in d:
whoops += 1
d[temp] -= 1
if d[temp] == 0:
d.pop(temp)
print(yay, whoops)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR VAR NUMBER IF FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
def count_correct_case():
global dict_s, dict_t
correctCase = 0
for char in dict_s:
if char in dict_t:
yay = min(dict_s[char], dict_t[char])
correctCase += yay
dict_s[char] -= yay
dict_t[char] -= yay
return correctCase
def count_wrong_case():
wrongCase = 0
for char in dict_s:
if dict_s[char] > 0:
if char <= "Z" and chr(ord(char) + 32) in dict_t:
wrongCase += min(dict_s[char], dict_t[chr(ord(char) + 32)])
elif char >= "a" and chr(ord(char) - 32) in dict_t:
wrongCase += min(dict_s[char], dict_t[chr(ord(char) - 32)])
return wrongCase
s = input()
t = input()
dict_s = {}
dict_t = {}
for char in s:
if not char in dict_s:
dict_s[char] = 1
else:
dict_s[char] += 1
for char in t:
if not char in dict_t:
dict_t[char] = 1
else:
dict_t[char] += 1
print(count_correct_case(), count_wrong_case())
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR STRING FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = set()
sc = set()
t = set()
tc = set()
ms = []
mt = []
for letter in input():
if letter == letter.lower():
s.add(letter)
else:
sc.add(letter.lower())
if letter not in ms:
ms.append(letter)
ms.append(1)
else:
ms[ms.index(letter) + 1] += 1
for letter in input():
if letter == letter.lower():
t.add(letter)
else:
tc.add(letter.lower())
if letter not in mt:
mt.append(letter)
mt.append(1)
else:
mt[mt.index(letter) + 1] += 1
y = 0
w = 0
for letter in s.intersection(t):
a = ms[ms.index(letter) + 1]
b = mt[mt.index(letter) + 1]
rs = set()
rt = set()
if a == b:
y += a
ms[ms.index(letter) + 1], mt[mt.index(letter) + 1] = 0, 0
rs.add(letter)
rt.add(letter)
elif a > b:
y += b
ms[ms.index(letter) + 1], mt[mt.index(letter) + 1] = (
ms[ms.index(letter) + 1] - mt[mt.index(letter) + 1],
0,
)
rt.add(letter)
else:
y += a
ms[ms.index(letter) + 1], mt[mt.index(letter) + 1] = (
0,
mt[mt.index(letter) + 1] - ms[ms.index(letter) + 1],
)
rs.add(letter)
s, t = s - rs, t - rt
for letter in sc.intersection(tc):
letter = letter.upper()
a = ms[ms.index(letter) + 1]
b = mt[mt.index(letter) + 1]
rsc = set()
rtc = set()
if a == b:
y += a
ms[ms.index(letter) + 1], mt[mt.index(letter) + 1] = 0, 0
rsc.add(letter.lower())
rtc.add(letter.lower())
elif a > b:
y += b
ms[ms.index(letter) + 1], mt[mt.index(letter) + 1] = (
ms[ms.index(letter) + 1] - mt[mt.index(letter) + 1],
0,
)
rtc.add(letter.lower())
else:
y += a
ms[ms.index(letter) + 1], mt[mt.index(letter) + 1] = (
0,
mt[mt.index(letter) + 1] - ms[ms.index(letter) + 1],
)
rsc.add(letter.lower())
sc, tc = sc - rsc, tc - rtc
for letter in sc.intersection(t):
a = ms[ms.index(letter.upper()) + 1]
b = mt[mt.index(letter) + 1]
rsc = set()
rt = set()
if a == b:
w += a
rsc.add(letter)
rt.add(letter)
elif a > b:
w += b
rt.add(letter)
else:
w += a
rsc.add(letter)
sc, t = sc - rsc, t - rt
for letter in s.intersection(tc):
a = ms[ms.index(letter) + 1]
b = mt[mt.index(letter.upper()) + 1]
rs = set()
rtc = set()
if a == b:
w += a
rs.add(letter)
rtc.add(letter)
elif a > b:
w += b
rtc.add(letter)
else:
w += a
rs.add(letter)
s, tc = s - rs, tc - rtc
print(y, w)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = input()
t = input()
ds = {}
for i in range(len(s)):
key = s[i]
if key in ds:
ds[key] += 1
else:
ds[key] = 1
dt = {}
for i in range(len(t)):
key = t[i]
if key in dt:
dt[key] += 1
else:
dt[key] = 1
y, w = 0, 0
for i in range(len(s)):
if s[i] in dt and dt[s[i]] > 0:
dt[s[i]] -= 1
ds[s[i]] -= 1
y += 1
for i in range(len(s)):
if ds[s[i]] > 0:
if s[i].isupper():
if s[i].lower() in dt and dt[s[i].lower()] > 0:
w += 1
ds[s[i]] -= 1
dt[s[i].lower()] -= 1
elif s[i].islower():
if s[i].upper() in dt and dt[s[i].upper()] > 0:
w += 1
ds[s[i]] -= 1
dt[s[i].upper()] -= 1
print(y, w)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = input()
t = input()
alf = "qwertyuiopasdfghjklzxcvbnm"
ALF = "QWERTYUIOPASDFGHJKLZXCVBNM"
d, di = {}, {}
for i, x in enumerate(alf):
d[x] = ALF[i]
di[ALF[i]] = x
T, res1, res2 = {}, 0, 0
for i, x in enumerate(t):
if T.get(x) == None:
T[x] = 0
T[x] += 1
new = ""
for i, x in enumerate(s):
if T.get(x) != None:
T[x] -= 1
res1 += 1
if T[x] == 0:
T.pop(x)
else:
new += x
for i, x in enumerate(new):
if d.get(x) == None:
y = di[x]
else:
y = d[x]
if T.get(y) != None:
T[y] -= 1
res2 += 1
if T[y] == 0:
T.pop(y)
print(res1, res2)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR DICT DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR DICT NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NONE VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NONE VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = input()
t = input()
yay = 0
whoops = 0
message = {}
newspaper = {}
for i in s:
message[i] = message.get(i, 0) + 1
for j in t:
newspaper[j] = newspaper.get(j, 0) + 1
for i in message:
newspaper[i] = newspaper.get(i, 0)
used = min(newspaper[i], message[i])
yay += used
newspaper[i] -= used
message[i] -= used
for i in message:
if i.isupper():
newspaper[i.lower()] = newspaper.get(i.lower(), 0)
whoops += min(newspaper[i.lower()], message[i])
else:
newspaper[i.upper()] = newspaper.get(i.upper(), 0)
whoops += min(newspaper[i.upper()], message[i])
print(str(yay) + " " + str(whoops))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR IF FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = list(input())
t = list(input())
cnt = dict()
for ch in t:
if not ch in cnt:
cnt[ch] = 1
else:
cnt[ch] = cnt[ch] + 1
yay = 0
check = [False] * len(s)
for i in range(len(s)):
ch = s[i]
if ch in cnt and cnt[ch] > 0:
cnt[ch] -= 1
check[i] = True
yay += 1
whoops = 0
for i in range(len(s)):
if not check[i]:
if s[i].islower() == True:
ch = s[i].upper()
elif s[i].isupper() == True:
ch = s[i].lower()
if ch in cnt and cnt[ch] > 0:
cnt[ch] -= 1
check[i] = True
whoops += 1
print(yay, whoops)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
def upc(c):
if c >= "a" and c <= "z":
c = chr(ord(c) - ord("a") + ord("A"))
return c
a1, a2 = {}, {}
for i in input():
if i in a1:
a1[i] += 1
else:
a1[i] = 1
for i in input():
if i in a2:
a2[i] += 1
else:
a2[i] = 1
r1, r2 = 0, 0
a3, a4 = {}, {}
for k in a1:
v = a1[k]
if not k in a2:
continue
c = min(v, a2[k])
a2[k] -= c
a1[k] -= c
r1 += c
for k in a1:
v = a1[k]
c = upc(k)
if c in a3:
a3[c] += v
else:
a3[c] = v
for k in a2:
v = a2[k]
c = upc(k)
if c in a4:
a4[c] += v
else:
a4[c] = v
for k in a3:
if not k in a4:
continue
v = a3[k]
c = min(v, a4[k])
a3[k] -= c
a4[k] -= c
r2 += c
print(r1, r2)
|
FUNC_DEF IF VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING RETURN VAR ASSIGN VAR VAR DICT DICT FOR VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR DICT DICT FOR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s1 = list(input())
s2 = list(input())
n = len(s1)
d1 = dict()
for i in s1:
try:
d1[i] += 1
except:
d1[i] = 1
d2 = dict()
for i in s2:
try:
d2[i] += 1
except:
d2[i] = 1
for i in d1:
try:
m = min(d1[i], d2[i])
d1[i] -= m
d2[i] -= m
except:
pass
sum = 0
for i in d1:
sum += d1[i]
a = n - sum
n = sum
sum = 0
for i in d1:
try:
if d1[i] > 0:
if i.islower():
x = i.upper()
else:
x = i.lower()
d1[i] -= min(d1[i], d2[x])
d2[x] -= min(d1[i], d2[x])
except:
pass
for i in d1:
sum += d1[i]
b = n - sum
print(a, b)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
def main():
s = input()
t = input()
arrS = [0] * 70
arrT = [0] * 70
count = 0
count2 = 0
n = len(s)
for x in s:
arrS[ord(x) - 65] += 1
for x in t:
arrT[ord(x) - 65] += 1
for i in range(60):
temp = min(arrS[i], arrT[i])
arrS[i] -= temp
arrT[i] -= temp
count += temp
for i in range(28):
temp = min(arrS[i], arrT[i + 32])
arrS[i] -= temp
arrT[i + 32] -= temp
count2 += temp
for i in range(32, 68):
temp = min(arrS[i], arrT[i - 32])
arrS[i] -= temp
arrT[i - 32] -= temp
count2 += temp
print(count, count2)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = input()
t = input()
visit = list()
lis = list()
for i in range(60):
visit.append(0)
yay = 0
whoops = 0
for i in range(len(t)):
visit[ord(t[i]) - ord("a")] += 1
for i in range(len(s)):
if visit[ord(s[i]) - ord("a")] > 0:
yay += 1
visit[ord(s[i]) - ord("a")] -= 1
else:
lis.append(s[i])
for i in range(len(lis)):
if visit[ord(lis[i].upper()) - ord("a")] > 0:
whoops += 1
visit[ord(lis[i].upper()) - ord("a")] -= 1
elif visit[ord(lis[i].lower()) - ord("a")] > 0:
whoops += 1
visit[ord(lis[i].lower()) - ord("a")] -= 1
print(yay, whoops)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
cnt = [0] * 130
s = input()
t = input()
for x in t:
cnt[ord(x)] += 1
n = len(s)
mark = [True] * n
cnt_Yays = 0
cnt_Whoops = 0
for i in range(n):
x = s[i]
if cnt[ord(x)] > 0:
cnt_Yays += 1
cnt[ord(x)] -= 1
mark[i] = False
for i in range(n):
x = s[i]
if mark[i] == True:
if ord(x) >= 97 and cnt[ord(x.upper())] > 0:
cnt_Whoops += 1
cnt[ord(x.upper())] -= 1
if ord(x) < 97 and cnt[ord(x.lower())] > 0:
cnt_Whoops += 1
cnt[ord(x.lower())] -= 1
print(cnt_Yays, cnt_Whoops)
|
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
text = input()
letters = input()
d = {}
for ch in letters:
d[ch] = d.get(ch, 0) + 1
a = []
for ch in text:
a.append(False)
yaycount = 0
whoopscount = 0
for i in range(len(text)):
ch = text[i]
if ch in d and d[ch] > 0:
yaycount = yaycount + 1
d[ch] = d[ch] - 1
a[i] = True
for i in range(len(text)):
ch = text[i]
if a[i] == False:
if ch.lower() == ch:
upper = ch.upper()
if upper in d and d[upper] > 0:
whoopscount = whoopscount + 1
d[upper] = d[upper] - 1
elif ch.upper() == ch:
lower = ch.lower()
if lower in d and d[lower] > 0:
whoopscount = whoopscount + 1
d[lower] = d[lower] - 1
print(str(yaycount) + " " + str(whoopscount))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
message = input()
newspaper = input()
a = dict([(i, 0) for i in range(52)])
b = dict([(i, 0) for i in range(52)])
for ch in message:
id = ord(ch) - 65
if ch > "Z":
id = ord(ch) - 97 + 26
if not id in a:
a[id] = 1
else:
a[id] += 1
for ch in newspaper:
id = ord(ch) - 65
if ch > "Z":
id = ord(ch) - 97 + 26
if not id in b:
b[id] = 1
else:
b[id] += 1
yay = 0
whoops = 0
for i in range(52):
tmp = min(a[i], b[i])
yay += tmp
a[i] -= tmp
b[i] -= tmp
for i in range(26):
whoops += min(a[i], b[i + 26]) + min(a[i + 26], b[i])
print("%d %d" % (yay, whoops))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
x = input()
y = input()
g1 = {}
g2 = {}
g3 = {}
g4 = {}
for i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
g2[i] = 0
g4[i] = 0
for i in "abcdefghijklmnopqrstuvwxyz":
g1[i] = 0
g3[i] = 0
e = 0
f = 0
u = []
l = []
u2 = []
l2 = []
for i in x:
if i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
u.append(i)
g2[i] += 1
else:
l.append(i)
g1[i] += 1
for i in y:
if i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
u2.append(i)
g4[i] += 1
else:
l2.append(i)
g3[i] += 1
for i in g1:
ct = g1[i]
can = g3[i]
if ct != 0 and can != 0:
if ct > can:
g1[i] = ct - can
g3[i] = 0
e += can
else:
g3[i] = can - ct
e += g1[i]
g1[i] = 0
for i in g2:
ct = g2[i]
can = g4[i]
if ct != 0 and can != 0:
if ct > can:
g2[i] = ct - can
g4[i] = 0
e += can
else:
g4[i] = can - ct
e += g2[i]
g2[i] = 0
for i in g1:
ct = g1[i]
can = g4[i.upper()]
if ct != 0 and can != 0:
if ct > can:
g1[i] = ct - can
g4[i.upper()] = 0
f += can
else:
g4[i.upper()] = can - ct
f += g1[i]
g1[i] = 0
for i in g2:
ct = g2[i]
can = g3[i.lower()]
if ct != 0 and can != 0:
if ct > can:
g2[i] = ct - can
g3[i.lower()] = 0
f += can
else:
g3[i.lower()] = can - ct
f += g2[i]
g2[i] = 0
print(e, f)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
msg = input()
letters = input()
yays = 0
whoops = 0
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
rest = []
leaks = []
i = 0
for l in alphabet:
original = msg.count(l)
journal = letters.count(l)
if journal >= original:
yays += original
journal -= original
if len(rest) < 26:
rest.append(journal)
leaks.append(0)
else:
rest[i % 26] += journal
else:
yays += journal
original -= journal
if len(leaks) < 26:
leaks.append(original)
rest.append(0)
else:
leaks[i % 26] += original
i += 1
for i in range(26):
if rest[i] > 0 and leaks[i] > 0:
if rest[i] >= leaks[i]:
whoops += leaks[i]
else:
whoops += rest[i]
print(yays, whoops)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
st = input()
d = {}
match = {}
for i in range(26):
d[chr(i + 65)] = 0
d[chr(i + 97)] = 0
match[chr(i + 65)] = chr(i + 97)
match[chr(i + 97)] = chr(i + 65)
for i in input():
d[i] += 1
ans1 = ans2 = 0
remain = ""
for i in st:
if d[i] > 0:
ans1 += 1
d[i] -= 1
else:
remain += i
for i in remain:
i = match[i]
if d[i] > 0:
ans2 += 1
d[i] -= 1
print(ans1, ans2)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = input()
t = input()
a = [0] * 200
b = [0] * 200
for i in range(len(s)):
a[ord(s[i])] += 1
for i in range(len(t)):
b[ord(t[i])] += 1
ans1 = ans2 = 0
for i in range(ord("A"), ord("Z") + 1):
r = min(a[i], b[i]) + min(a[i + 32], b[i + 32])
ans1 += r
ans2 += min(a[i] + a[i + 32], b[i] + b[i + 32]) - r
print(ans1, ans2)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
m = {a: (0) for a in "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM"}
m1 = {a: (0) for a in "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM"}
t, s = input(), input()
for i in range(len(t)):
m[t[i]] += 1
for i in range(len(s)):
m1[s[i]] += 1
ura = 0
opa = 0
for a in "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM":
if m[a] == 0 or m1[a] == 0:
continue
temple = min(m[a], m1[a])
ura += temple
m[a] -= temple
m1[a] -= temple
print(ura, end=" ", sep="")
for a in "qwertyuiopasdfghjklzxcvbnm":
opa += min(m[a] + m[a.upper()], m1[a] + m1[a.upper()])
print(opa)
|
ASSIGN VAR VAR NUMBER VAR STRING ASSIGN VAR VAR NUMBER VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR STRING IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING STRING FOR VAR STRING VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
def process(str):
d = {}
for c in str:
d[c] = d.setdefault(c, 0) + 1
return d
def match(d1, d2, case):
ans = 0
for c in d1:
if case(c) not in d2:
continue
m = min(d1[c], d2[case(c)])
ans += m
d1[c] -= m
d2[case(c)] -= m
return ans
sd = process(input())
td = process(input())
yay = match(sd, td, lambda x: x)
whoops = match(sd, td, lambda x: x.lower() if x.isupper() else x.upper())
print(yay, whoops)
|
FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = input()
t = input()
scount = []
tcount = []
yay = 0
whoop = 0
for i in range(130):
scount.append(0)
tcount.append(0)
for i in range(len(s)):
scount[ord(s[i])] += 1
for i in range(len(t)):
tcount[ord(t[i])] += 1
for i in range(ord("a"), ord("z") + 1):
lowmin = min(scount[i], tcount[i])
upmin = min(scount[ord(chr(i).upper())], tcount[ord(chr(i).upper())])
yay += lowmin + upmin
scount[i] -= lowmin
tcount[i] -= lowmin
scount[ord(chr(i).upper())] -= upmin
tcount[ord(chr(i).upper())] -= upmin
whoop += min(scount[i], tcount[ord(chr(i).upper())]) + min(
scount[ord(chr(i).upper())], tcount[i]
)
print(yay, whoop)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s, t = input(), input()
yay, whoops = 0, 0
a, b = {}, {}
for i in s:
a[i] = a.get(i, 0) + 1
for i in t:
b[i] = b.get(i, 0) + 1
for i in a:
if i not in b:
continue
tmp = min(a[i], b[i])
yay += tmp
a[i] -= tmp
b[i] -= tmp
for i in a:
if i.swapcase() not in b:
continue
tmp = min(a[i], b[i.swapcase()])
whoops += tmp
a[i] -= tmp
b[i.swapcase()] -= tmp
print(yay, whoops)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR DICT DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s1 = input()
s2 = input()
a = [0] * 52
b = [0] * 52
for ch in s1:
if "a" <= ch <= "z":
index = ord(ch) - ord("a")
else:
index = ord(ch) - ord("A") + 26
a[index] += 1
for ch in s2:
if "a" <= ch <= "z":
index = ord(ch) - ord("a")
else:
index = ord(ch) - ord("A") + 26
b[index] += 1
ans1 = ans2 = 0
for i in range(52):
min_number = min(a[i], b[i])
ans1 += min_number
a[i] -= min_number
b[i] -= min_number
for i in range(52):
if i < 26:
ans2 += min(a[i], b[i + 26])
else:
ans2 += min(a[i], b[i - 26])
print(ans1, ans2)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR IF STRING VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER VAR VAR NUMBER FOR VAR VAR IF STRING VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
msg = input()
l = input()
msg = list(msg)
d = {}
y = 0
w = 0
for i in l:
if i not in d:
d[i] = 0
d[i] += 1
for j in range(len(msg)):
i = msg[j]
if i in d and d[i] > 0:
d[i] -= 1
y += 1
msg[j] = chr(30)
for i in msg:
if ord(i) >= 97:
if chr(ord(i) - 32) in d and d[chr(ord(i) - 32)] > 0:
w += 1
d[chr(ord(i) - 32)] -= 1
elif chr(ord(i) + 32) in d and d[chr(ord(i) + 32)] > 0:
d[chr(ord(i) + 32)] -= 1
w += 1
print(y, w)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = list(input())
t = list(input())
count = {}
ans1 = 0
ans2 = 0
for i in range(len(s)):
a = str.lower(s[i])
b = str.upper(s[i])
count[a] = count[b] = 0
for i in range(len(t)):
a = t[i]
count[a] = 0
for i in range(len(t)):
a = t[i]
count[a] += 1
l = []
for i in range(len(s)):
a = s[i]
if count[a] > 0:
ans1 += 1
count[a] -= 1
else:
l.append(a)
li = l
for i in range(len(li)):
a = li[i]
b = str.lower(li[i])
c = str.upper(li[i])
if a == b:
if count[c] > 0:
ans2 += 1
count[c] -= 1
elif count[b] > 0:
ans2 += 1
count[b] -= 1
print(ans1, ans2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = input()
t = input()
n = len(s)
made = [False] * n
d = dict()
for c in t:
if c in d:
d[c] += 1
else:
d[c] = 1
yays = whoops = 0
for i in range(n):
if s[i] in d and d[s[i]] > 0:
d[s[i]] -= 1
yays += 1
made[i] = True
for i in range(n):
if made[i] == False:
c = s[i]
if c.upper() in d and d[c.upper()] > 0:
d[c.upper()] -= 1
whoops += 1
elif c.lower() in d and d[c.lower()] > 0:
d[c.lower()] -= 1
whoops += 1
print(yays, whoops)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = input().strip()
t = input().strip()
d = {}
for i in s:
if i in d:
d[i] += 1
else:
d[i] = 1
x1 = 0
x2 = 0
e = [(True) for i in range(len(t))]
for i in range(len(t)):
if t[i] in d and d[t[i]] > 0:
d[t[i]] -= 1
x1 += 1
e[i] = False
t = t.swapcase()
for i in range(len(t)):
if t[i] in d and e[i] and d[t[i]] > 0:
d[t[i]] -= 1
x2 += 1
print(x1, x2)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = input().strip()
t = input().strip()
count_s = [0] * 100
count_t = [0] * 100
ans1, ans2 = [0, 0]
for i in range(len(t)):
count_t[ord(t[i]) - ord("A")] += 1
for i in range(len(s)):
count_s[ord(s[i]) - ord("A")] += 1
for i in range(58):
Min = min(count_s[i], count_t[i])
count_s[i] -= Min
count_t[i] -= Min
ans1 += Min
for i in range(58):
Min = min(count_s[i], count_t[(i + 32) % 64])
count_s[i] -= Min
count_t[(i + 32) % 64] -= Min
ans2 += Min
print(ans1, ans2)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = input()
t = input()
s_letters = {}
t_letters = {}
for i in s:
tt = tuple([i.lower()])
if tt not in t_letters:
t_letters[tt] = [0, 0]
if tt not in s_letters:
s_letters[tt] = [0, 0]
if i == i.lower():
s_letters[tt][0] += 1
else:
s_letters[tt][1] += 1
for i in t:
tt = tuple([i.lower()])
if i == i.lower():
if tt in t_letters.keys():
t_letters[tt][0] += 1
elif tt in t_letters.keys():
t_letters[tt][1] += 1
yay = 0
oops = 0
for i in s_letters.keys():
tmp_yay_lower = min(s_letters[i][0], t_letters[i][0])
tmp_yay_upper = min(s_letters[i][1], t_letters[i][1])
tmp_oops = max(
0,
min(
s_letters[i][0] + s_letters[i][1] - tmp_yay_lower - tmp_yay_upper,
t_letters[i][0] + t_letters[i][1] - tmp_yay_lower - tmp_yay_upper,
),
)
yay += tmp_yay_lower + tmp_yay_upper
oops += tmp_oops
print(yay, oops)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR IF VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
import sys
sys.setrecursionlimit(100000)
def reverseCase(a):
if ord(a) >= ord("A") and ord(a) <= ord("Z"):
return a.lower()
else:
return a.upper()
def main():
mes = input()
news = input()
M = dict()
n, m = len(mes), len(news)
yay = oops = 0
for i in range(n):
if mes[i] in M:
M[mes[i]] += 1
else:
M[mes[i]] = 1
mark = [False] * m
for i in range(m):
if news[i] in M and M[news[i]] != 0:
M[news[i]] -= 1
yay += 1
else:
mark[i] = True
for i in range(m):
if mark[i]:
tmp = reverseCase(news[i])
if tmp in M and M[tmp] != 0:
M[tmp] -= 1
oops += 1
print(yay, oops)
main()
|
IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR STRING RETURN FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = str(input())
t = str(input())
mapa = {}
yays = 0
whoops = 0
for i in t:
if i in mapa:
mapa[i] += 1
else:
mapa[i] = 1
other = ""
for i in s:
if i in mapa and mapa[i] > 0:
yays += 1
mapa[i] -= 1
else:
other += i
for i in other:
l = i.lower() if i.isupper() else i.upper()
if l in mapa and mapa[l] > 0:
whoops += 1
mapa[l] -= 1
print(yays, whoops)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
alth = "abcdefghijklmnopqrstuvwxyz"
alth2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
s2 = [([0] * 26) for i in range(2)]
s3 = [([0] * 26) for i in range(2)]
s = input()
t = input()
num = 0
num2 = 0
for i in s:
temp = alth.find(i)
if temp != -1:
s2[0][temp] += 1
temp = alth2.find(i)
if temp != -1:
s2[1][temp] += 1
for i in t:
temp = alth.find(i)
if temp != -1:
s3[0][temp] += 1
temp = alth2.find(i)
if temp != -1:
s3[1][temp] += 1
for i in range(2):
for j in range(26):
x = min(s2[i][j], s3[i][j])
num += x
s2[i][j] -= x
s3[i][j] -= x
for i in range(2):
for j in range(26):
num2 += min(s2[i][j], s3[1 - i][j])
print(num, num2)
|
ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
sm = "abcdefghijklmnopqrstuvwxyz"
la = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
s1 = input()
s2 = input()
d1 = {}
d2 = {}
ya = wh = 0
for i in s1:
if i in d1:
d1[i] += 1
else:
d1[i] = 1
for i in s2:
if i in d2:
d2[i] += 1
else:
d2[i] = 1
for i in d1:
if i in d2:
t = min(d1[i], d2[i])
d1[i] -= t
d2[i] -= t
ya += t
for i in d1:
j = i
j = j.swapcase()
if j in d2:
t = min(d1[i], d2[j])
d1[i] -= t
d2[j] -= t
wh += t
print(ya, wh)
|
ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
w = "abcdefghijklmnopqrstuvwxyz"
u = str.upper
s, t = {}, {}
a, b = 0, 0
q = input()
e = input()
for i in w + u(w):
s[i] = q.count(i)
t[i] = e.count(i)
p = min(s[i], t[i])
a += p
s[i] -= p
t[i] -= p
for i in w:
b += min(s[i] + s[u(i)], t[i] + t[u(i)])
print(a, b)
|
ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR DICT DICT ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
def invert_case(c):
if c.isupper():
return c.lower()
return c.upper()
letters = {c: (0) for c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"}
whoops = 0
yay = 0
message = list(input())
newspaper = list(input())
for c in newspaper:
letters[c] += 1
for i in range(len(message)):
if letters[message[i]] > 0:
letters[message[i]] -= 1
message[i] = "."
yay += 1
for i in range(len(message) - 1, -1, -1):
if message[i] == ".":
message.pop(i)
for c in message:
if letters[invert_case(c)] > 0:
letters[invert_case(c)] -= 1
whoops += 1
print(yay, whoops)
|
FUNC_DEF IF FUNC_CALL VAR RETURN FUNC_CALL VAR RETURN FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = input()
t = input()
oc = {}
yay = 0
whoops = 0
resto = ""
for l1 in t:
oc[l1] = oc.get(l1, 0) + 1
for l2 in s:
if oc.get(l2, 0) > 0:
oc[l2] -= 1
yay += 1
else:
resto += l2
for l3 in resto:
aux = l3.swapcase()
if oc.get(aux, 0) > 0:
oc[aux] -= 1
whoops += 1
print(yay, whoops)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
a = input()
mapa = {}
per = 0
imp = 0
for i in a:
if i in mapa:
mapa[i] += 1
else:
mapa[i] = 1
b = input()
c = []
for i in b:
if i in mapa:
if mapa[i] != 0:
mapa[i] -= 1
per += 1
c.append(True)
else:
c.append(False)
else:
c.append(False)
for i in range(len(b)):
k = b[i]
if not c[i]:
k = k.lower() if k.isupper() else k.upper()
if k in mapa:
if mapa[k] != 0:
mapa[k] -= 1
imp += 1
print(per, imp)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s, t = input(), input()
a1, a2 = list(s), list(t)
r1, r2 = 0, 0
for i in range(ord("a"), ord("z") + 1, 1):
l1 = a1.count(chr(i))
l2 = a2.count(chr(i))
u1 = a1.count(chr(i + ord("A") - ord("a")))
u2 = a2.count(chr(i + ord("A") - ord("a")))
c = min(l1, l2) + min(u1, u2)
r1 += c
r2 += min(l2 + u2, l1 + u1) - c
print(r1, r2)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = input()
t = input()
c = -ord("A") + ord("a")
ura = 0
opa = 0
s2 = set()
ind = set()
s1 = dict()
for i in range(len(s)):
if ord(s[i]) not in s2:
s2.add(ord(s[i]))
s1[ord(s[i])] = 1
else:
s1[ord(s[i])] += 1
for i in range(len(t)):
if ord(t[i]) in s2 and s1[ord(t[i])] >= 1:
s1[ord(t[i])] -= 1
ura += 1
ind.add(i)
for i in range(len(t)):
if i not in ind:
if ord("z") >= ord(t[i]) >= ord("a"):
if ord(t[i]) - c in s2 and s1[ord(t[i]) - c] >= 1:
opa += 1
s1[ord(t[i]) - c] -= 1
ind.add(i)
elif ord(t[i]) + c in s2 and s1[ord(t[i]) + c] >= 1:
opa += 1
s1[ord(t[i]) + c] -= 1
ind.add(i)
print(ura, opa)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
__author__ = "PrimuS"
s = input()
t = input()
sd = {}
td = {}
for x in s:
sd[x] = sd.get(x, 0) + 1
for x in t:
td[x] = td.get(x, 0) + 1
res1 = 0
res2 = 0
for x in sd.keys():
if x not in td:
continue
k = min(sd[x], td[x])
res1 += k
sd[x] -= k
td[x] -= k
for x in sd.keys():
if x.islower():
y = x.upper()
else:
y = x.lower()
if y not in td:
continue
k = min(sd[x], td[y])
sd[x] -= k
td[y] -= k
res2 += k
print(res1, res2)
|
ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
def solve():
d1 = {}
d2 = {}
yay = 0
whoops = 0
s1 = input()
s2 = input()
for i in s2:
d2[i] = d2.get(i, 0) + 1
for i in s1:
d1[i] = d1.get(i, 0) + 1
for i in range(26):
k = chr(i + 97)
c1 = d1.get(k, 0)
c2 = d2.get(k, 0)
cnt = min(c1, c2)
yay += cnt
if k in d1:
d1[k] -= cnt
if d1[k] == 0:
d1.pop(k)
if k in d2:
d2[k] -= cnt
if d2[k] == 0:
d2.pop(k)
k = k.upper()
c1 = d1.get(k, 0)
c2 = d2.get(k, 0)
cnt = min(c1, c2)
yay += cnt
if k in d1:
d1[k] -= cnt
if d1[k] == 0:
d1.pop(k)
if k in d2:
d2[k] -= cnt
if d2[k] == 0:
d2.pop(k)
for i in range(26):
k = chr(i + 97)
j = k.upper()
c1 = d1.get(k, 0)
c2 = d2.get(j, 0)
cnt = min(c1, c2)
whoops += cnt
if k in d1:
d1[k] -= cnt
if d1[k] == 0:
d1.pop(k)
if j in d2:
d2[j] -= cnt
if d2[j] == 0:
d2.pop(j)
k, j = j, k
c1 = d1.get(k, 0)
c2 = d2.get(j, 0)
cnt = min(c1, c2)
whoops += cnt
if k in d1:
d1[k] -= cnt
if d1[k] == 0:
d1.pop(k)
if j in d2:
d2[j] -= cnt
if d2[j] == 0:
d2.pop(j)
print(yay, whoops)
return
def main():
t = 1
for _ in range(t):
solve()
main()
|
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
def solve():
d = {}
s = input()
t = input()
n = len(s)
m = len(t)
for i in range(0, 26):
d[chr(ord("a") + i)] = 0
d[chr(ord("A") + i)] = 0
for i in range(0, m):
d[t[i]] += 1
y = 0
w = 0
x = [0] * n
for i in range(0, n):
if d[s[i]] > 0:
x[i] = 1
y += 1
d[s[i]] -= 1
for i in range(0, n):
if x[i]:
continue
if ord(s[i]) <= ord("z") and ord(s[i]) >= ord("a"):
if d[chr(ord(s[i]) - ord("a") + ord("A"))] > 0:
w += 1
d[chr(ord(s[i]) - ord("a") + ord("A"))] -= 1
elif d[chr(ord(s[i]) - ord("A") + ord("a"))] > 0:
w += 1
d[chr(ord(s[i]) - ord("A") + ord("a"))] -= 1
print(y, w)
t = 1
for _ in range(t):
solve()
|
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER IF VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message β string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.
The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".
Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
-----Input-----
The first line contains line s (1 β€ |s| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text of Tanya's message.
The second line contains line t (|s| β€ |t| β€ 2Β·10^5), consisting of uppercase and lowercase English letters β the text written in the newspaper.
Here |a| means the length of the string a.
-----Output-----
Print two integers separated by a space: the first number is the number of times Tanya shouts "YAY!" while making the message, the second number is the number of times Tanya says "WHOOPS" while making the message.
-----Examples-----
Input
AbC
DCbA
Output
3 0
Input
ABC
abc
Output
0 3
Input
abacaba
AbaCaBA
Output
3 4
|
s = input()
t = input()
a = [0] * 26
A = [0] * 26
b = [0] * 26
B = [0] * 26
for i in s:
o = ord(i)
if o >= 97:
a[o - 97] += 1
else:
A[o - 65] += 1
for i in t:
o = ord(i)
if o >= 97:
b[o - 97] += 1
else:
B[o - 65] += 1
ura = 0
opa = 0
for i in range(26):
u1 = 0
o1 = 0
c = a[i]
C = A[i]
d = b[i]
D = B[i]
m = min(c, d)
u1 += m
c -= m
d -= m
m = min(c, D)
o1 += m
c -= m
D -= m
m = min(C, D)
u1 += m
C -= m
D -= m
m = min(C, d)
o1 += m
C -= m
D -= m
u2 = 0
o2 = 0
c = a[i]
C = A[i]
d = b[i]
D = B[i]
m = min(C, D)
u2 += m
C -= m
D -= m
m = min(C, d)
o2 += m
C -= m
D -= m
m = min(c, d)
u2 += m
c -= m
d -= m
m = min(c, D)
o2 += m
c -= m
D -= m
if u1 > u2 or u1 == u2 and o1 >= o2:
ura += u1
opa += o1
else:
ura += u2
opa += o2
print(ura, opa)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
kk = lambda: map(int, input().split())
ll = lambda: list(kk())
n, k = kk()
su = (k + 1) * k // 2
start = (n - su) // k + 1
if n < su or n > start * (2**k - 1):
print("NO")
exit()
ls = [(start + i) for i in range(k)]
currsum = (start - 1) * k + su
delayed = 0
for i in range(1, k):
ls[i] += delayed
while ls[i - 1] * 2 > ls[i] and k - i <= n - currsum:
delayed += 1
ls[i] += 1
currsum += k - i
print("YES")
print(*ls)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR WHILE BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
n, k = map(int, input().split())
d = [0] * k
if k == 1:
print("YES")
print(n)
else:
for i in range(k):
d[i] = i + 1
if sum(d) > n:
print("NO")
else:
t = n - sum(d)
if t >= k:
a = t // k
t = t % k
for i in range(k):
d[i] += a
if t > 0:
if d[0] > 1:
for i in range(k - 1, k - 1 - t, -1):
d[i] += 1
elif d[0] == 1:
for i in range(k - 1, 1, -1):
d[i] += 1
t -= 1
if t == 0:
break
if t > 0:
for i in range(k - 1, 2, -1):
d[i] += 1
t -= 1
if t == 0:
break
chk = True
for i in range(k - 1):
if d[i + 1] > 2 * d[i]:
chk = False
break
if sum(d) != n:
chk = False
if chk:
print("YES")
s = ""
for i in d:
s += str(i) + " "
print(s[:-1])
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
n, k = [int(i) for i in input().split()]
s = int(k * (k + 1) / 2)
a = []
if k == 1:
print("YES")
print(n)
exit(0)
if n - s < 0:
print("NO")
exit(0)
c = (n - s) // k
r = (n - s) % k
if k == 2 and r == 1 and c == 0 or k == 3 and r == 2 and c == 0:
print("NO")
exit(0)
for i in range(k):
a.append(i + 1 + c)
b = (k - r) * [0] + r * [1]
for i in range(k):
b[i] += a[i]
if r == k - 1:
b[1] -= 1
b[k - 1] += 1
print("YES")
res = ""
for x in b:
res = res + str(x) + " "
print(res)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR LIST NUMBER BIN_OP VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
def mp():
return map(int, input().split())
n, k = mp()
a = [i for i in range(1, k + 1)]
s = (1 + k) * k // 2
p = [0] * k
pp = 0
i = 0
while i < k and s < n:
q = (n - s) // (k - i)
if i == 0 or a[i] + q <= 2 * a[i - 1] + pp:
p[i] = q
pp += q
s += q * (k - i)
i += 1
if s == n:
print("YES")
q = 0
for i in range(k):
q += p[i]
print(a[i] + q, end=" ")
else:
print("NO")
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
n, k = map(int, input().split())
y = pow(2, k)
y = y - 1
x = 0
if n % y == 0:
x = n // y
else:
x = n // y + 1
if (x + k) * (x + k - 1) / 2 - x * (x - 1) / 2 > n:
print("NO")
else:
a = x
n -= x
b = []
c = 0
b.insert(c, a)
c = c + 1
print("YES")
for i in range(1, k):
y = pow(2, k - i)
y = y - 1
p = 0
if n % y == 0:
p = n // y
else:
p = n // y + 1
if p <= a:
p = a + 1
b.insert(c, p)
c = c + 1
a = p
n = n - p
print(*b)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
n, k = list(map(int, input().split()))
if n < k * (k + 1) / 2:
print("NO")
exit(0)
dif = n - k * (k + 1) // 2
a = [(i + 1 + dif // k) for i in range(k)]
dif %= k
if dif == 0:
print("YES")
print(*a)
exit(0)
if a[-1] + dif > 2 * a[-2]:
if k == 2:
print("NO")
exit(0)
if a[-2] == 2 * a[-3]:
print("NO")
exit(0)
a[-2] += 1
a[-1] += dif - 1
else:
a[-1] += dif
print("YES")
print(*a)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
def solve(n, k):
r = n - k * (k + 1) // 2
if r < 0:
return None
b0 = r // k
r -= b0 * k
seq = [None] * k
seq[0] = b0
b = b0
for i in range(1, k):
bn = b * 2 + i - 1
h = r // (k - i)
if h > 0:
if h + b > bn:
h = bn - b
r -= h * (k - i)
b = h + b
seq[i] = b
if r != 0:
return None
A = [(b + i + 1) for i, b in enumerate(seq)]
return A
def main():
n, k = map(int, input().split())
res = solve(n, k)
if res is None:
print("NO")
else:
print("YES")
print(*res)
main()
|
FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER RETURN NONE ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER RETURN NONE ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
n, k = map(int, input().split())
m = k * (k + 1) // 2
if n >= m:
a = []
a.append(0)
rem = n - m
t = rem // k
for i in range(1, k + 1):
a.append(i + t)
rem = rem % k
if t == 0:
if k == 1:
print("YES")
print(n)
elif k == 2:
if n % 2 != 0:
print("YES")
print(n // k, n // k + 1)
else:
print("NO")
elif k == 3:
if rem == 2:
print("NO")
elif rem == 1:
print("YES")
print("1 2 4")
else:
for i in range(k, 0, -1):
temp = 2 * a[i - 1] - a[i]
blah = min(temp, rem)
rem = rem - blah
a[i] += blah
if rem == 0:
break
print("YES")
a = a[1:]
print(*a)
elif k == 1:
print("YES")
print(n)
elif k == 2:
print("YES")
if n % 2 == 0:
print(n // k - 1, n // k + 1)
else:
print(n // k, n // k + 1)
else:
for i in range(k, 0, -1):
temp = 2 * a[i - 1] - a[i]
blah = min(temp, rem)
rem = rem - blah
a[i] += blah
if rem == 0:
break
print("YES")
a = a[1:]
print(*a)
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
n, k = [int(i) for i in input().split()]
def ok(a):
print("YES")
print(*a)
if k * (k + 1) // 2 > n:
print("NO")
else:
v = (n - k * (k + 1) // 2) // k
a = [(v + i) for i in range(1, k + 1)]
if v == 0:
if k == 2:
if sum(a) != n:
print("NO")
else:
ok(a)
elif k == 3:
if n == 6:
ok(a)
elif n == 7:
ok([1, 2, 4])
else:
print("NO")
else:
if n - sum(a) >= 2:
a[-2] += 1
a[-1] += n - sum(a)
ok(a)
else:
a[-1] += n - sum(a)
ok(a)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
n, k = map(int, input().split())
max_x = (n - k * (k - 1) // 2) / k
if max_x < 1:
print("NO")
exit(0)
x = int(max_x)
r = n - (k * x + k * (k - 1) // 2)
A = [(x + i) for i in range(k)]
p = r + 1
while r > 0 and r != p:
p = r
for i in range(k - 1, 0, -1):
q = min(r, 2 * A[i - 1] - A[i])
r -= q
A[i] += q
if r == 0:
break
if r == 0:
print("YES")
print(*A, sep=" ")
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
n, k = map(int, input().split())
mn = k * (k + 1) // 2
if n < mn:
print("NO")
elif k == 2 and n == 4 or k == 3 and n == 8:
print("NO")
else:
print("YES")
t = (n - mn) // k + 1
ans = [t]
tot = t
for i in range(k - 1):
ans.append(ans[-1] + 1)
tot += ans[-1]
rem = n - tot
ptr = k - 1
while rem > 0:
if ans[ptr] < 2 * ans[ptr - 1]:
ans[ptr] += 1
rem -= 1
else:
ptr -= 1
if ptr == 1:
ptr = k - 1
print(*ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
input_ = input().split(" ")
n = int(input_[0])
k = int(input_[1])
last = 0
output = ""
if n < (k + 1) * k / 2 or k == 3 and n == 8 or k == 2 and n == 4:
print("NO")
elif k == 2 and n == 3:
print("YES")
print("1 2")
elif k == 3 and n == 7:
print("YES")
print("1 2 4")
elif k <= 20001:
for i in range(k - 1):
last = max(n // (2**k - 1) + 1, last + 1)
output = output + " " + str(last)
n = n - last
k = k - 1
output = output + " " + str(n)
print("YES")
print(output[1:])
else:
last = k - 50
output = " ".join([str(i) for i in range(1, last + 1)])
n = n - last * (last + 1) // 2
k = k - last
for i in range(k - 1):
last = max(n // (2**k - 1) + 1, last + 1)
output = output + " " + str(last)
n = n - last
k = k - 1
output = output + " " + str(n)
print("YES")
print(output)
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
import sys
n, k = map(int, input().split())
if k * (k + 1) > n * 2:
print("NO")
elif k * (k + 1) == n * 2:
print("YES")
for i in range(1, k + 1):
print(i, end=" ")
elif k == 1:
print("YES")
print(n)
else:
list1 = [n // k] * k
list1[k - 1] += n % k
if k == 2 and n % 2 != 0:
print("YES")
for i in list1:
print(i, end=" ")
sys.exit()
for i in range(k // 2):
list1[i] -= k // 2 - i
if i > 0 and list1[i] > 2 * list1[i - 1]:
print("NO")
sys.exit()
if k % 2 != 0:
for i in range(k // 2, k):
list1[i] += i - k // 2
if list1[i] > 2 * list1[i - 1]:
print("NO")
sys.exit()
else:
for i in range(k // 2, k):
list1[i] += i - k // 2 + 1
if list1[i] > 2 * list1[i - 1]:
print("NO")
sys.exit()
print("YES")
for i in list1:
print(i, end=" ")
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
m, n = map(int, input().split())
a = [0] * n
d = 0
for i in range(n):
a[i] += i + 1
if sum(a) > m:
d = 1
for i in range(n):
a[i] += (m - (n + 1) * n // 2) // n
k = n - 1
if d == 0:
while sum(a) < m:
if m - sum(a) >= a[k - 1] * 2 - a[k]:
a[k] += a[k - 1] * 2 - a[k]
else:
a[k] += m - sum(a)
k -= 1
c = 0
for i in range(n - 1):
if a[i] == a[i + 1]:
c = 1
if sum(a) != m or d == 1 or c == 1:
print("NO")
else:
print("YES")
print(*a)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER WHILE FUNC_CALL VAR VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
def solve(n, k):
if (k + 1) * k // 2 > n:
return ""
if k == 1:
return str(n)
if k == 2:
if n % 2:
return "%d %d" % (n // 2, n // 2 + 1)
else:
if n <= 4:
return ""
return "%d %d" % (n // 2 - 2, n // 2 + 2)
s = (k + 1) * k // 2
t, m = divmod(n, s)
res = [(v * t) for v in range(1, k + 1)]
t, m = divmod(m, k)
res = [(v + t) for v in res]
res = helper(res, m)
if not check(res):
return ""
return " ".join(map(str, res))
def check(res):
for i in range(1, len(res)):
if res[i] > res[i - 1] and res[i] <= 2 * res[i - 1]:
continue
return False
return True
def helper(res, m):
if res[0] == 1 and m >= 2 * k - 4:
return []
index = len(res) - 1
while m:
res[index] += 1
index -= 1
if index == 1:
index = len(res) - 1
m -= 1
return res
n, k = map(int, input().split())
res = solve(n, k)
if not res:
print("NO")
else:
print("YES")
print(res)
|
FUNC_DEF IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR RETURN STRING IF VAR NUMBER RETURN FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER RETURN BIN_OP STRING BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER RETURN STRING RETURN BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR RETURN STRING RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
rint = lambda: int(input())
rmint = lambda: map(int, input().split())
rlist = lambda: list(rmint())
n, k = rmint()
t = k
a = [0] * k
def no():
print("NO")
exit(0)
d = [-1] * (k + 1)
d[0] = 1
mx = 10**9
for i in range(1, k + 1):
if d[i - 1] * 2 > mx:
break
d[i] = d[i - 1] * 2
for i in range(k):
if n < 0:
break
if d[t] < 0:
p = 1
if i:
p = a[i - 1] + 1
else:
f = d[t] - 1
p = max(1, (n + f - 1) // f)
if i:
p = max(p, a[i - 1] + 1)
p = min(p, a[i - 1] * 2)
a[i] = p
t -= 1
n -= p
if n:
no()
print("YES")
for i in range(k):
print(a[i], end=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR IF VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
n, k = map(int, input().split())
base = k * (k + 1) // 2
if n < base:
print("NO")
exit(0)
l = [(i + 1 + (n - base) // k) for i in range(k)]
rem = (n - base) % k
if (n - base) // k == 0 and rem != 0 and rem == k - 1:
if k in (2, 3):
print("NO")
exit(0)
else:
l[-1] += 2
for i in range(rem - 2):
l[-i - 2] += 1
else:
for i in range(rem):
l[-i - 1] += 1
print("YES")
print(" ".join(map(str, l)))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
def top(d, f, tot):
zero = f * (k - d) + (k - d) * (k - d - 1) // 2
return tot - zero
n, k = map(int, input().split())
a = []
if n < k * (k + 1) // 2:
print("NO")
elif k == 1:
print("YES")
print(n)
else:
const = 0
if n > 2**k - 1:
const = (n - k * (k + 1) // 2) // k
n -= const * k
if const == 0:
print("NO")
if const > 0 or n <= 2**k - 1:
print("YES")
a = [const] * k
summ = n
for i in range(0, k):
a[i] += i + 1
summ -= i + 1
for i in range(1, k):
if (
summ // (k - i) < 2**i - i - 1
and a[i] + summ // (k - i) <= a[i - 1] * 2
):
add = summ // (k - i)
for j in range(i, k):
a[j] += add
summ -= add
break
while summ > 0:
for i in range(k - 1, 0, -1):
if a[i - 1] * 2 >= a[i] + 1:
add = min(a[i - 1] * 2 - a[i], summ)
a[i] += add
summ -= add
if summ == 0:
break
for x in a:
print(x)
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR WHILE VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
_ = input().split()
n = int(_[0])
k = int(_[1])
def lower(k, i):
return k * i + int(k * (k - 1) / 2)
def _max(k, i):
return i * (pow(2, k) - 1)
if n < lower(k, 1):
print("NO")
else:
i = int((n - int(k * (k - 1) / 2)) / k) - 1
while lower(k, i) <= n:
i = i + 1
i = i - 1
if _max(k, i) < n:
print("NO")
else:
answer = [(_ + i) for _ in range(k)]
adder = n - lower(k, i)
for _ in range(adder):
answer[-_ - 1] = answer[-_ - 1] + 1
if k > 2 and answer[0] == 1 and answer[1] == 3:
answer[1] = answer[1] - 1
answer[-1] = answer[-1] + 1
answer = [str(_) for _ in answer]
print("YES")
print(" ".join(answer))
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
N, K = list(map(int, input().split()))
a = K * (K + 1) // 2
if a > N:
print("NO")
else:
b = (N - a) // K
c = N - a - b * K
r = []
for i in range(K):
r.append(i + 1 + b + (1 if i + c >= K else 0))
for i in range(K - 2):
if r[i] * 2 < r[i + 1]:
r[K - 1] += r[i + 1] - r[i] * 2
r[i + 1] = r[i] * 2
if r[K - 2] * 2 < r[K - 1]:
print("NO")
else:
print("YES")
print(" ".join(list(map(str, r))))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
n, k = [int(s) for s in input().split()]
if n < k * (k + 1) / 2:
print("NO")
exit()
if k == 3 and n == 8 or k == 2 and (n < 3 or n == 4):
print("NO")
exit()
print("YES")
if k == 1:
print(n)
elif k == 2:
print((n + 2) // 3, n - (n + 2) // 3)
else:
i = 1
while i * k + k * (k - 1) // 2 <= n:
i += 1
i -= 1
last = i + k - 1
last_ = last - 1
sum = i * (k - 1) + (k - 2) * (k - 1) // 2
last = n - sum
if last_ * 2 >= last:
for q in range(i, last_ + 1):
print(q, end=" ")
print(last)
exit()
last_ += 1
last -= 1
for q in range(i, i + k - 2):
print(q, end=" ")
print(last_, end=" ")
print(last)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
n, k = map(int, input().split())
x = k * (k + 1) // 2
y, s = 0, 0
a = []
if n < x:
print("NO")
quit()
y = (n - x) // k
s = x + k * y
a = [(i + y) for i in range(1, k + 1)]
x = n - s
for i in range(k - 1, 0, -1):
if x <= a[i - 1] * 2 - a[i]:
a[i] += x
x = 0
break
else:
x -= a[i - 1] * 2 - a[i]
a[i] = a[i - 1] * 2
if sum(a) != n:
print("NO")
quit()
print("YES")
print(" ".join(list(map(str, a))))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
import sys
class Main:
def __init__(self):
self.buff = None
self.index = 0
def __next__(self):
if self.buff is None or self.index == len(self.buff):
self.buff = self.next_line()
self.index = 0
val = self.buff[self.index]
self.index += 1
return val
def next_line(self, _map=str):
return list(map(_map, sys.stdin.readline().split()))
def next_int(self):
return int(next(self))
def solve(self):
n = self.next_int()
k = self.next_int()
rs = []
low = 1
high = n + 1
for i in range(0, k):
kk = k - i
high1 = high
low1 = low
while high1 - low1 > 1:
mid = (low1 + high1) // 2
if self.test_low(mid, n, kk):
low1 = mid
else:
high1 = mid
high2 = high
low2 = low1
while high2 - low2 > 1:
mid = (low2 + high2) // 2
if self.test_high(mid, n, kk):
low2 = mid
else:
high2 = mid
if not self.test_low(low1, n, kk) or not self.test_high(low2, n, kk):
print("NO")
return
rs.append(low1)
low = rs[-1] + 1
high = rs[-1] * 2 + 1
n -= rs[-1]
print("YES")
print(" ".join([str(x) for x in rs]))
def test_low(self, d, n, k):
return (2 * d + k - 1) * k // 2 <= n
def test_high(self, d, n, k):
return k >= 33 or (2**k - 1) * d >= n
def __starting_point():
Main().solve()
__starting_point()
|
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NUMBER FUNC_DEF IF VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER VAR FUNC_DEF RETURN VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR FUNC_DEF EXPR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
import sys
input = sys.stdin.readline
def main():
n, k = map(int, input().split())
if n < k or k * (k + 1) // 2 > n:
print("NO")
return
if k == 1:
print("YES")
print(n)
return
d = n - k * (k + 1) // 2
ans = [(i + d // k) for i in range(1, k + 1)]
ans[-1] += d % k
if ans[-1] > 2 * ans[-2]:
need = ans[-1] - 2 * ans[-2]
ans[-1] -= need
assert 0 <= need <= 1
if need == 1:
if len(ans) >= 3 and ans[-3] == 1:
print("NO")
return
if ans[-2] >= ans[-1] - 1:
print("NO")
return
ans[-2] += 1
print("YES")
print(" ".join(map(str, ans)))
main()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR VAR IF VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
import sys
def check(s, st, n):
sum = (st * 2 + (n - 1)) * n // 2
return s >= sum
m, n = list(map(int, input().split()))
a = [0] * n
last = 0
for i in range(n):
le = last + 1
if i == 0:
ri = m + 1
else:
ri = last * 2 + 1
while ri - le > 1:
mid = (le + ri) // 2
if check(m, mid, n - i):
le = mid
else:
ri = mid
if not check(m, le, n - i):
print("NO")
return
a[i] = le
m -= le
last = le
if m == 0:
print("YES")
print(*a)
else:
print("NO")
|
IMPORT FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
n, k = map(int, input().split())
if n < k * (k + 1) / 2:
print("NO")
else:
ar = [(i + 1) for i in range(k)]
n -= k * (k + 1) // 2
c = n // k
s = n % k
for i in range(k):
ar[i] += c
j = k - 1
while s > 0:
ar[j] += ar[j - 1] - 1
s -= ar[j - 1] - 1
if s < 0:
ar[j] += s
j -= 1
b = True
for i in range(k - 1):
if (ar[i + 1] > ar[i] * 2) | (ar[i] == ar[i + 1]):
b = False
break
if b:
print("YES")
print(" ".join(map(str, ar)))
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
import sys
n, k = tuple(map(int, input().split()))
if n == 1 == k:
print("YES")
print(1)
sys.exit(0)
sum_s = sum(i + 1 for i in range(k))
if sum_s > n:
print("NO")
sys.exit(0)
r = (n - sum_s) // k
ost = (n - sum_s) % k
if r == 0 and ost == k - 1:
if n == 4 or n == 8:
print("NO")
sys.exit(0)
else:
print("YES")
print(1, 2, end="")
for i in range(2, k - 1):
print(" {}".format(i + 2), end="")
print(" {}".format(k + 2), end="")
else:
print("YES")
print(r + 1, end="")
for i in range(1, k - ost):
print(" {}".format(r + i + 1), end="")
for i in range(k - ost, k):
print(" {}".format(r + i + 2), end="")
print()
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
s = k * (k + 1) // 2
if n < s:
ans = "NO"
else:
j = (n - s) // k
a = [(i + j) for i in range(1, k + 1)]
ans = "NO"
x = a[0]
c = 0
for _ in range(k):
c += x
x *= 2
if n <= c:
ans = "YES"
break
if ans == "YES":
s = sum(a)
while s ^ n:
for j in range(k - 1, 0, -1):
if a[j] + 1 <= 2 * a[j - 1]:
a[j] += 1
s += 1
else:
break
if s == n:
break
print(ans)
if ans == "YES":
print(*a)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
ANS = list(range(1, k + 1))
ANS.append(10**9)
SUM = k * (k + 1) // 2
PLUS = 0
for i in range(k):
if n < SUM:
print("NO")
sys.exit()
y = 2 * ANS[i - 1] - ANS[i]
x = min((n - SUM) // (k - i), y - PLUS)
SUM += x * (k - i)
PLUS += x
ANS[i] = ANS[i] + PLUS
if sum(ANS[:k]) == n:
print("YES")
print(*ANS[:k])
else:
print("NO")
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
import sys
n, k = map(int, input().split())
min_cnt = k * (k + 1) // 2
if n < min_cnt:
print("NO")
sys.exit()
t = (n - min_cnt) // k
assert t >= 0
delta = n - (min_cnt + k * t)
a = [(i + t) for i in range(1, k + 1)]
pos = k - 1
while delta > 0:
if pos == 0:
print("NO")
sys.exit()
assert pos > 0
while (
delta > 0
and (pos == k - 1 or a[pos] + 1 < a[pos + 1])
and a[pos] < 2 * a[pos - 1]
):
a[pos] += 1
delta -= 1
pos -= 1
print("YES")
print(*a)
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
def get_tail(k):
return k * (k - 1) // 2
def find_starter(n, k):
f = get_tail(k)
starter = (n - f) // k
return starter
def answerYES(A):
return "YES\n" + " ".join(map(str, A))
def get_array(n, k):
starter = find_starter(n, k)
if starter < 1:
return "NO"
A = [0] * k
s = 0
last = starter + k - 1
for i in range(starter, starter + k):
A[i - starter] = i
s += i
diff = n - s
maxe = last - 2
if diff > maxe:
while diff > 0 and A[-2] * 2 - A[-1] >= 1:
for i in range(k - 1, -1, -1):
if i - 1 > -1 and A[i - 1] * 2 - A[i] >= 1:
A[i] += 1
diff -= 1
if diff == 0:
break
if diff == 0:
return answerYES(A)
else:
return "NO"
else:
A[-1] += diff
return answerYES(A)
return "NO"
n, k = map(int, input().split())
print(get_array(n, k))
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR WHILE VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR RETURN STRING VAR NUMBER VAR RETURN FUNC_CALL VAR VAR RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
x, y = map(int, input().split())
if x == 8 and y == 3:
print("NO")
exit()
if x == 4 and y == 2:
print("NO")
exit()
z = []
leftover = 0
day = 0
mini = y * (y + 1) // 2
if mini > x:
print("NO")
exit()
elif mini == x:
for i in range(y):
z.append(i + 1)
else:
leftover = x - mini
day = leftover // y
for i in range(y):
z.append(i + 1 + day)
leftover = leftover % y
while -1 * leftover != 0:
z[-1 * leftover] = z[-1 * leftover] + 1
leftover = leftover - 1
for i in range(len(z) - 1):
if z[i + 1] > 2 * z[i]:
z[i + 1] = z[i + 1] - 1
z[-1] = z[-1] + 1
print("YES")
print(" ".join(map(str, z)))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR WHILE BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
n, k = [int(x) for x in input().split()]
a = [i for i in range(1, k + 1)]
s = k * (k + 1) // 2
p = 0
if n == s:
p = 0
elif n > s:
if n - s == k:
p = 0
for i in range(k):
a[i] += 1
elif n - s > k:
d = (n - s) // k
for i in range(k):
a[i] += d
p = n - s - d * k
for i in range(k - 2, -1, -1):
c = 2 * a[i] - a[i + 1]
if p <= 0:
break
elif p >= c:
a[i + 1] += c
p -= c
elif p < c:
a[i + 1] += p
p = 0
elif n - s < k:
p = n - s
for i in range(k - 2, -1, -1):
c = 2 * a[i] - a[i + 1]
if p <= 0:
break
elif p >= c:
a[i + 1] += c
p -= c
elif p < c:
a[i + 1] += p
p = 0
else:
p = 1
if p <= 0:
print("YES")
for i in range(k):
print(a[i], end=" ")
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
def solve():
n, k = map(int, input().split())
Ans = list(range(1, k + 1))
s = k * (k + 1) // 2
if n < s:
print("NO")
return
add = (n - s) // k
Ans = list(range(1 + add, k + 1 + add))
add = (n - s) % k
i = k - 1
while i and add:
x = min(2 * Ans[i - 1] - Ans[i], add)
Ans[i] += x
add -= x
i -= 1
if sum(Ans) != n:
print("NO")
return
print("YES")
print(*Ans)
solve()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
import sys
n, k = map(int, input().split())
a = [0] * (k + 2)
if k * (k + 1) > n * 2:
print("NO")
sys.exit()
for i in range(1, k + 1):
a[i] = i
n -= k * (k + 1) // 2
rest = n // k
n -= rest * k
a[1] += rest
for i in range(2, k + 1):
a[i] = a[i - 1] + 1
rest = n // (k - i + 1)
tmp = min(rest, a[i - 1] * 2 - a[i])
a[i] += tmp
n -= (k - i + 1) * tmp
if n > 0:
print("NO")
sys.exit()
print("YES")
for i in range(1, k + 1):
print(a[i], end=" ")
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
def check(a):
for x, y in zip(a[:-1], a[1:]):
if x >= y or y > 2 * x:
return False
return True
def solve(n, k):
if n < k * (k + 1) // 2:
return "NO", None
ans = list(range(1, k + 1))
plus = n - sum(ans)
add = plus // k
r = plus % k
for i in range(k):
ans[i] += add
if r != 0:
last = 2 * ans[-2] - ans[-1]
ans[-1] += min(last, r)
if r > last:
ans[-2] += r - last
if check(ans) == True:
return "YES", ans
return "NO", None
n, k = map(int, input().split())
flg, ans = solve(n, k)
if flg == "NO":
print(flg)
else:
print(flg)
print(" ".join([str(x) for x in ans]))
|
FUNC_DEF FOR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN STRING NONE ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN STRING VAR RETURN STRING NONE ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
def check(n, k, fl, fr):
if n < k * (2 * fl + k - 1) // 2:
return 1
if k <= 32 and n > fr * (2**k - 1):
return -1
return 0
def main():
n, k = map(int, input().split(" "))
l, r = 1, n
ans = []
while k > 0:
ll, rr = l, r
cnt = -1
while rr >= ll:
mid = (ll + rr) // 2
ck = check(n - mid, k - 1, mid + 1, mid * 2)
if ck == 0:
cnt = mid
break
elif ck < 0:
ll = mid + 1
else:
rr = mid - 1
if cnt == -1:
print("NO")
return
ans.append(cnt)
k -= 1
n -= cnt
l = cnt + 1
r = min(n, cnt * 2)
print("YES")
print(*ans)
main()
|
FUNC_DEF IF VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
n, k = map(int, input().split())
s = k * (k + 1) // 2
a = []
if k == 1:
print("YES")
print(n)
exit()
if n - s < 0:
print("NO")
exit()
c = (n - s) // k
r = (n - s) % k
if k == 2 and r == 1 and c == 0 or k == 3 and r == 2 and c == 0:
print("NO")
exit(0)
for i in range(k):
if i < k - r:
a.append(i + 1 + c)
else:
a.append(i + 1 + c + 1)
if r == k - 1:
a[1] -= 1
a[k - 1] += 1
for i in range(len(a)):
a[i] = str(a[i])
print("YES")
print(" ".join(a))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
def main():
n, k = map(int, input().split())
if n < k * (k + 1) // 2:
print("NO")
else:
add = (n - k * (k + 1) // 2) // k
res = [(x + add) for x in range(1, k + 1)]
left = n - sum(res)
added = True
while left > 0 and added:
added = False
pos = k - 1
while pos > 0:
while left > 0 and res[pos] + 1 <= 2 * res[pos - 1]:
res[pos] += 1
left -= 1
added = True
pos -= 1
ok = True
for i in range(k - 1):
if res[i + 1] <= res[i] or res[i + 1] > 2 * res[i]:
ok = False
break
if ok and left == 0:
print("YES")
print(*res)
else:
print("NO")
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER WHILE VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
|
Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $k$ days. He also doesn't want to overwork, so if he solves $x$ problems during some day, he should solve no more than $2x$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $x$ problems during some day, he should solve at least $x+1$ problem during the next day.
More formally: let $[a_1, a_2, \dots, a_k]$ be the array of numbers of problems solved by Polycarp. The $i$-th element of this array is the number of problems Polycarp solves during the $i$-th day of his training. Then the following conditions must be satisfied: sum of all $a_i$ for $i$ from $1$ to $k$ should be $n$; $a_i$ should be greater than zero for each $i$ from $1$ to $k$; the condition $a_i < a_{i + 1} \le 2 a_i$ should be satisfied for each $i$ from $1$ to $k-1$.
Your problem is to find any array $a$ of length $k$ satisfying the conditions above or say that it is impossible to do it.
-----Input-----
The first line of the input contains two integers $n$ and $k$ ($1 \le n \le 10^9, 1 \le k \le 10^5$) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
-----Output-----
If it is impossible to find any array $a$ of length $k$ satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print $k$ integers $a_1, a_2, \dots, a_k$ in the second line, where $a_i$ should be the number of problems Polycarp should solve during the $i$-th day. If there are multiple answers, you can print any.
-----Examples-----
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
|
n, k = list(map(int, input().split()))
mi = k * (k + 1) // 2
mx = 2 ** (k - 1)
if n < mi:
print("NO")
else:
ans = []
for i in range(1, k + 1):
ans.append(i)
remain = n - mi
add = remain // k
if add:
for i in range(k):
ans[i] += add
remain -= k * add
while remain:
i = k - 1
while remain and ans[i] < add + ans[0] * 2**i:
ans[i] += 1
i -= 1
remain -= 1
if ans[-1] == add + ans[0] * 2 ** (k - 1):
break
if remain:
print("NO")
else:
print("YES")
for a in ans[:-1]:
print(a, end=" ")
print(ans[-1])
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
|
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
-----Input-----
The first line contains number t (1 β€ t β€ 50) β the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
-----Output-----
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
-----Examples-----
Input
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
YES
NO
-----Note-----
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
|
def main():
n = int(input())
out = ""
for t in range(n):
knights = [(0) for i in range(16)]
valid = [(False) for i in range(16)]
for i in range(8):
line = input()
for j in range(8):
if line[j] != "#":
valid[get(i, j)] = True
if line[j] == "K":
knights[get(i, j)] += 1
for i in range(16):
if knights[i] == 2 and valid[i]:
out += "YES\n"
break
else:
out += "NO\n"
if t != n - 1:
input()
print(out[:-1])
def get(i, j):
return [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]][i % 4][j % 4]
def __starting_point():
main()
__starting_point()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR STRING VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR STRING VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN LIST LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
-----Input-----
The first line contains number t (1 β€ t β€ 50) β the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
-----Output-----
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
-----Examples-----
Input
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
YES
NO
-----Note-----
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
|
def check():
board = []
for cont in range(0, 8):
board.append(input())
l = True
for cont in range(0, 8):
for cont2 in range(0, 8):
if board[cont][cont2] == "K":
if l:
xk1 = cont2
yk1 = cont
l = False
else:
xk2 = cont2
yk2 = cont
break
for cont in range(0, 8):
for cont2 in range(0, 8):
if cont2 % 2 == xk1 % 2 == xk2 % 2:
if cont % 2 == yk1 % 2 == yk2 % 2:
if abs(cont2 - xk1) % 4 == abs(cont2 - xk2) % 4:
if abs(cont - yk1) % 4 == abs(cont - yk2) % 4:
if board[cont][cont2] != "#":
print("YES")
return
print("NO")
return
n = int(input())
check()
for t in range(0, n - 1):
a = str(input())
check()
|
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR STRING IF VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
-----Input-----
The first line contains number t (1 β€ t β€ 50) β the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
-----Output-----
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
-----Examples-----
Input
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
YES
NO
-----Note-----
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
|
def solve(m, x, y, w, z):
for i in range(8):
for j in range(8):
if m[i][j]:
a, pa = movePossible(x, y, i, j)
b, pb = movePossible(w, z, i, j)
if a and b and pa == pb:
return True
return False
def movePossible(x, y, w, z):
a = x - w
b = y - z
pos = False
ka = a // 2
kb = b // 2
if a % 2 == 0 and b % 2 == 0 and (ka + kb) % 2 == 0:
pos = True
return pos, ka % 2
t = int(input())
for _c in range(t):
m = []
primo = True
for i in range(8):
m.append([])
s = input()
k = 0
for c in s:
if c == "#":
m[i].append(False)
else:
m[i].append(True)
if c == "K" and primo:
x = i
y = k
primo = False
if c == "K" and not primo:
w = i
z = k
k += 1
if solve(m, x, y, w, z):
print("YES")
else:
print("NO")
if _c != t - 1:
m = input()
|
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR
|
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
-----Input-----
The first line contains number t (1 β€ t β€ 50) β the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
-----Output-----
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
-----Examples-----
Input
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
YES
NO
-----Note-----
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
|
t = int(input())
for _ in range(t):
if _:
input()
knights = []
for i in range(8):
s = input().strip()
for j in range(8):
if s[j] == "K":
knights.append((i, j))
n1 = knights[0]
n2 = knights[1]
if n1[0] % 4 == n2[0] % 4 and n1[1] % 4 == n2[1] % 4:
print("YES")
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
-----Input-----
The first line contains number t (1 β€ t β€ 50) β the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
-----Output-----
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
-----Examples-----
Input
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
YES
NO
-----Note-----
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
|
def f():
t = []
for i in range(8):
p = input()
for j in range(8):
if p[j] == "K":
t += [i, j]
if t[2] - t[0] in (0, 4) and t[1] - t[3] in (-4, 0, 4):
return "YES"
return "NO"
for i in range(int(input()) - 1):
print(f())
input()
print(f())
|
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR LIST VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER NUMBER RETURN STRING RETURN STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
-----Input-----
The first line contains number t (1 β€ t β€ 50) β the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
-----Output-----
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
-----Examples-----
Input
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
YES
NO
-----Note-----
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
|
t = int(input())
for _ in range(t):
s = [input() for i in range(8)]
oh = True
flag = True
for i in range(8):
for j in range(8):
if s[i][j] == "K":
if flag:
pos1x = i
pos1y = j
flag = False
else:
pos2x = i
pos2y = j
if pos1x % 4 == pos2x % 4 and pos1y % 4 == pos2y % 4:
print("YES")
else:
print("NO")
if _ < t - 1:
k = input()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING IF VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR
|
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
-----Input-----
The first line contains number t (1 β€ t β€ 50) β the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
-----Output-----
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
-----Examples-----
Input
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
YES
NO
-----Note-----
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
|
t = int(input())
el = [
[1, 2, 3, 4, 1, 2, 3, 4],
[5, 6, 7, 8, 5, 6, 7, 8],
[9, 10, 11, 12, 9, 10, 11, 12],
[13, 14, 15, 16, 13, 14, 15, 16],
[1, 2, 3, 4, 1, 2, 3, 4],
[5, 6, 7, 8, 5, 6, 7, 8],
[9, 10, 11, 12, 9, 10, 11, 12],
[13, 14, 15, 16, 13, 14, 15, 16],
]
for x in range(t):
arr = [[] for i in range(8)]
for i in range(8):
s = input()
for j in range(len(s)):
arr[i].append(s[j])
l = 0
for i in range(8):
for j in range(8):
if l == 0:
if arr[i][j] == "K":
k1 = el[i][j]
l = 1
elif arr[i][j] == "K":
k2 = el[i][j]
break
if k1 == k2:
print("YES")
else:
print("NO")
if x != t - 1:
y = list(map(int, input().split()))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR
|
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
-----Input-----
The first line contains number t (1 β€ t β€ 50) β the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
-----Output-----
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
-----Examples-----
Input
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
YES
NO
-----Note-----
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
|
t = int(input())
while t:
t += -1
l = []
mp = []
for i in range(8):
tmp = list(input())
l.append(tmp)
mp.append([0] * 8)
i1, j1, i2, j2 = -1, -1, -1, -1
for i in range(8):
for j in range(8):
if l[i][j] == "K" and i1 == -1:
i1, j1 = i, j
if l[i][j] == "K":
i2, j2 = i, j
if abs(i2 - i1) % 4 == 0 and abs(j2 - j1) % 4 == 0:
print("YES")
else:
print("NO")
if t != 0:
input()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR
|
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
-----Input-----
The first line contains number t (1 β€ t β€ 50) β the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
-----Output-----
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
-----Examples-----
Input
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
YES
NO
-----Note-----
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
|
a = []
def first(i, j):
nonlocal a
a[i][j] = 1
if i - 2 >= 0 and j + 2 < 8:
a[i - 2][j + 2] = 1
if i - 2 >= 0 and j - 2 >= 0:
a[i - 2][j - 2] = 1
if i + 2 < 8 and j + 2 < 8:
a[i + 2][j + 2] = 1
if i + 2 < 8 and j - 2 >= 0:
a[i + 2][j - 2] = 1
def second(i, j):
nonlocal a
if a[i][j] == 1:
return True
if i - 2 >= 0 and j + 2 < 8:
if a[i - 2][j + 2] == 1:
return True
if i - 2 >= 0 and j - 2 >= 0:
if a[i - 2][j - 2] == 1:
return True
if i + 2 < 8 and j + 2 < 8:
if a[i + 2][j + 2] == 1:
return True
if i + 2 < 8 and j - 2 >= 0:
if a[i + 2][j - 2] == 1:
return True
return False
t = int(input())
for i in range(t):
a = []
exist = False
for j in range(8):
a.append(list(input()))
d = 0
for j in range(8):
for k in range(8):
if a[j][k] == "K":
d += 1
if d == 1:
first(j, k)
elif d == 2:
if second(j, k):
exist = True
if exist:
print("YES")
else:
print("NO")
if i != t - 1:
input()
|
ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
|
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
-----Input-----
The first line contains number t (1 β€ t β€ 50) β the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
-----Output-----
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
-----Examples-----
Input
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
YES
NO
-----Note-----
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
|
def check(x, y):
return 0 <= x < 8 and 0 <= y < 8
def dfs1(x, y, T=0):
nonlocal first, used
if not check(x, y) or used[x][y]:
return
used[x][y] = True
first.add((x, y, T))
for pair in ((2, 2), (2, -2), (-2, 2), (-2, -2)):
dfs1(x + pair[0], y + pair[1], 1 - T)
def dfs2(x, y, T=0):
nonlocal second, used
if not check(x, y) or used[x][y]:
return
used[x][y] = True
second.add((x, y, T))
for pair in ((2, 2), (2, -2), (-2, 2), (-2, -2)):
dfs2(x + pair[0], y + pair[1], 1 - T)
t = int(input())
for i in range(t):
if i > 0:
kuzma = input()
board = [input() for i in range(8)]
FoundFirst = False
for i in range(8):
for j in range(8):
if board[i][j] == "K":
if not FoundFirst:
First = i, j
FoundFirst = True
else:
Second = i, j
used = [[(0) for i in range(8)] for j in range(8)]
first = set()
dfs1(First[0], First[1])
used = [[(0) for i in range(8)] for j in range(8)]
second = set()
dfs2(Second[0], Second[1])
intersection = first & second
IsOk = False
for x, y, t in intersection:
if board[x][y] != "#":
print("YES")
IsOk = True
break
if not IsOk:
print("NO")
board = []
|
FUNC_DEF RETURN NUMBER VAR NUMBER NUMBER VAR NUMBER FUNC_DEF NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR FUNC_DEF NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING IF VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST
|
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
-----Input-----
The first line contains number t (1 β€ t β€ 50) β the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
-----Output-----
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
-----Examples-----
Input
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
YES
NO
-----Note-----
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
|
for i in range(int(input())):
if i:
input()
ans = []
for i in range(8):
s = input()
for j in range(8):
if s[j] == "K":
ans.append((i, j))
print(
["NO", "YES"][
abs(ans[0][0] - ans[1][0]) % 4 == 0 and abs(ans[0][1] - ans[1][1]) % 4 == 0
]
)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST STRING STRING BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER NUMBER
|
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
-----Input-----
The first line contains number t (1 β€ t β€ 50) β the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
-----Output-----
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
-----Examples-----
Input
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
YES
NO
-----Note-----
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
|
t = int(input())
for _ in range(t):
if _ != 0:
tmp = input()
pos = []
n = 8
g = []
for i in range(n):
g.append([i for i in input()])
for i in range(n):
for j in range(n):
if g[i][j] == "K":
pos.append((i, j))
ok = False
for i in range(n):
for j in range(n):
if (
i % 2 == pos[0][0] % 2
and i % 2 == pos[1][0] % 2
and j % 2 == pos[0][1] % 2
and j % 2 == pos[1][1] % 2
):
dist1 = i - pos[0][0], j - pos[0][1]
dist2 = i - pos[1][0], j - pos[1][1]
if dist1[0] - dist2[0] % 4 == 0 and dist1[1] - dist2[1] % 4 == 0:
ok = True
print("YES" if ok else "NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
|
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
-----Input-----
The first line contains number t (1 β€ t β€ 50) β the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
-----Output-----
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
-----Examples-----
Input
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
YES
NO
-----Note-----
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
|
n = int(input())
for t in range(n):
if t:
input()
board = [[c for c in input()] for i in range(8)]
k1, k2 = ((i, j) for i in range(8) for j in range(8) if board[i][j] == "K")
if (k1[0] - k2[0]) % 4 == 0 and (k1[1] - k2[1]) % 4 == 0:
print("YES")
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR VAR STRING IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
-----Input-----
The first line contains number t (1 β€ t β€ 50) β the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
-----Output-----
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
-----Examples-----
Input
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
YES
NO
-----Note-----
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
|
T = int(input())
for t in range(T):
L = []
for i in range(8):
L.append(input())
Moves1 = []
Moves2 = []
K = []
for i in range(8):
Moves1.append([-1] * 8)
Moves2.append([-1] * 8)
for j in range(8):
if L[i][j] == "K":
K.append((i, j))
Now = K[0]
Explored = [(Now[0], Now[1], 0)]
Moves1[Now[0]][Now[1]] = 0
while len(Explored) != 0:
x = Explored[0][0]
y = Explored[0][1]
p = Explored[0][2]
Explored.pop(0)
if x - 2 >= 0 and y - 2 >= 0:
if Moves1[x - 2][y - 2] == -1:
Moves1[x - 2][y - 2] = 1 - p
Explored.append((x - 2, y - 2, 1 - p))
if x + 2 < 8 and y - 2 >= 0:
if Moves1[x + 2][y - 2] == -1:
Moves1[x + 2][y - 2] = 1 - p
Explored.append((x + 2, y - 2, 1 - p))
if x - 2 >= 0 and y + 2 < 8:
if Moves1[x - 2][y + 2] == -1:
Moves1[x - 2][y + 2] = 1 - p
Explored.append((x - 2, y + 2, 1 - p))
if x + 2 < 8 and y + 2 < 8:
if Moves1[x + 2][y + 2] == -1:
Moves1[x + 2][y + 2] = 1 - p
Explored.append((x + 2, y + 2, 1 - p))
Now = K[1]
Explored = [(Now[0], Now[1], 0)]
Moves2[Now[0]][Now[1]] = 0
while len(Explored) != 0:
x = Explored[0][0]
y = Explored[0][1]
p = Explored[0][2]
Explored.pop(0)
if x - 2 >= 0 and y - 2 >= 0:
if Moves2[x - 2][y - 2] == -1:
Moves2[x - 2][y - 2] = 1 - p
Explored.append((x - 2, y - 2, 1 - p))
if x + 2 < 8 and y - 2 >= 0:
if Moves2[x + 2][y - 2] == -1:
Moves2[x + 2][y - 2] = 1 - p
Explored.append((x + 2, y - 2, 1 - p))
if x - 2 >= 0 and y + 2 < 8:
if Moves2[x - 2][y + 2] == -1:
Moves2[x - 2][y + 2] = 1 - p
Explored.append((x - 2, y + 2, 1 - p))
if x + 2 < 8 and y + 2 < 8:
if Moves2[x + 2][y + 2] == -1:
Moves2[x + 2][y + 2] = 1 - p
Explored.append((x + 2, y + 2, 1 - p))
valid = False
for i in range(8):
for j in range(8):
if Moves1[i][j] != -1 and Moves1[i][j] == Moves2[i][j] and L[i][j] != "#":
valid = True
if valid:
print("YES")
else:
print("NO")
if t != T - 1:
s = input()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR
|
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.
Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.
Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.
Please see the test case analysis.
-----Input-----
The first line contains number t (1 β€ t β€ 50) β the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.
-----Output-----
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
-----Examples-----
Input
2
........
........
......#.
K..##..#
.......#
...##..#
......#.
K.......
........
........
..#.....
..#..#..
..####..
...##...
........
....K#K#
Output
YES
NO
-----Note-----
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).
On the second board the semiknights will never meet.
|
n = int(input())
for i in range(n):
if i:
input()
x1 = y1 = x2 = y2 = 0
s = [input() for i in range(8)]
for i in range(8):
for j in range(8):
if s[i][j] == "K":
x1, y1, x2, y2 = x2, y2, i, j
if abs(x1 - x2) % 4 == 0 and abs(y1 - y2) % 4 == 0:
print("YES")
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.