output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
Print the abbreviation of s.
* * * | s951316209 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | a = input
count = a.count()
print(a[0] + str(count) + a[count - 1])
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s714177252 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | l = list(input())
print("{}{}{}".format(l[0],len(l)-2,l[-1]) | Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s935361205 | Wrong Answer | p03636 | Input is given from Standard Input in the following format:
s | sent = input()
print(sent[1] + str(len(sent) - 2) + sent[-1])
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s787461189 | Wrong Answer | p03636 | Input is given from Standard Input in the following format:
s | def func3(s):
return s[0] + str(len(s) - 2) + s[-1]
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s575111735 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | s = input()
m = str(len(s) -2)
print(s[0] + m + s[-1]) | Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s643294750 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | s = input()
print('{}{}{}'.format(s[0], len(s)-2, s[-1]) | Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s179813116 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | s=str(input())
a=len(s)
b=len(s[1:len[s])
print(s[0]+'a'+s[-1])
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s708712190 | Accepted | p03636 | Input is given from Standard Input in the following format:
s | st = input()
length = len(st[1:-1])
print(st[0] + str(length) + st[-1])
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s497399612 | Accepted | p03636 | Input is given from Standard Input in the following format:
s | head, *body, tail = input()
print("".join(map(str, (head, len(body), tail))))
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s992356260 | Accepted | p03636 | Input is given from Standard Input in the following format:
s | moji = str(input())
start = moji[0]
length = len(moji)
end = moji[length - 1]
centre = length - 2
print(start + str(centre) + end)
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s833381992 | Accepted | p03636 | Input is given from Standard Input in the following format:
s | line = input()
num = len(line)
a = line[0]
b = line[num - 1]
print(a + str(num - 2) + b)
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s008051091 | Accepted | p03636 | Input is given from Standard Input in the following format:
s | str_list = list(input())
length = len(str_list)
len_2 = str(length - 2)
connect = "".join([str_list[0], len_2, str_list[length - 1]])
print(connect)
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s748741613 | Accepted | p03636 | Input is given from Standard Input in the following format:
s | a = input().split()
b = list(a[0])
c = b[0]
d = b[-1]
l = len(b) - 2
l = str(l)
print(c + l + d)
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s957859786 | Accepted | p03636 | Input is given from Standard Input in the following format:
s | strings = list(input())
print(strings[0] + str(len(strings[1:-1])) + strings[-1])
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s584479459 | Accepted | p03636 | Input is given from Standard Input in the following format:
s | input_str = input("")
start = input_str[:1]
end = input_str[-1:]
print(start + str((len(input_str) - 2)) + end)
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s236545301 | Accepted | p03636 | Input is given from Standard Input in the following format:
s | S = list(input())
saisho = S[0]
del S[0]
saigo = S[-1]
del S[-1]
kazu = str(len(S))
print(saisho + kazu + saigo)
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s502467917 | Accepted | p03636 | Input is given from Standard Input in the following format:
s | word = input()
print("{}{}{}".format(word[0], len(word) - 2, word[-1]))
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s755423920 | Accepted | p03636 | Input is given from Standard Input in the following format:
s | a = list(str(input()))
a[1 : len(a) - 1] = [str(len(a) - 2)]
print("".join(a))
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s981496277 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | def main():
s = input()
print(s[0] + str(len(s)-2) + s[-1])
if __name__ == '__main__':
main() | Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s282696094 | Wrong Answer | p03636 | Input is given from Standard Input in the following format:
s | S = "internationalization"
print(S[0] + str(len(S[1 : len(S) - 1])) + S[len(S) - 1])
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s845173361 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | # -*- coding: utf8 -*-
s = input()
if s => 3:
if s <= 100:
print(s[0],len(s)-2,s[-1])
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s224018846 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | s = input()
print(s[0] + str(len(s) - 2) + s[-1])s = input()
print(s[0] + str(len(s) - 2) + s[-1]) | Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s771288217 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s |
#文字列を受け取る
s = input()
#replaceで文字列を置き換え
print(s.replace('2017', '2018', 1))
#置き換え回数も指定できる。今回は必要なさそうだけど
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s758674604 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | str = input("")
start = str[:1]
end = str[-1:]
print(start + (len(str) - 2) + end)
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s196110587 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | n = int(input())
i = 0
while 1:
if 2**i > n:
break
i += 1
print(2 ** (i - 1))
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s989963676 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | print(input()[0] + str(len(input()) - 2) + input()[len(input()) - 1])
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s304564016 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | s = input()
l = list(s)
a = len(l)-2
print(l[0],end='')
print(a,end='')
print(l[len(l)-1] | Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s570771939 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | s=input()
print(s[0]+str(len(s)-2)+s[-1] | Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s290305011 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | print(input()[:1] + str(len() - 2) + input()[-1:])
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s618558586 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | s = input()
print(s[0]+str(len(s[1:-1]))+s[-1]) | Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s977983890 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | n, k, x, y = [int(input()) for i in range(4)]
print(k * x + y * (n - k))
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s215031684 | Accepted | p03636 | Input is given from Standard Input in the following format:
s | value = input()
print("{}{}{}".format(value[0], len(value) - 2, value[len(value) - 1]))
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s010672986 | Accepted | p03636 | Input is given from Standard Input in the following format:
s | N = input()
A = len(N)
# print(N[A-1])
print(N[0], end="")
print(len(N) - 2, end="")
print(N[A - 1])
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s245669749 | Accepted | p03636 | Input is given from Standard Input in the following format:
s | # 一文字ずつ区切る
chars = list(input())
# 文字列で入っているぽい[internationalization]
# len(chars)で文字の長さを数える
# 最初の文字と真ん中の数と最後の文字を出力させる
# strでInt型をStringに変換する
print(chars[0] + str(len(chars) - 2) + chars[len(chars) - 1])
| Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s711196609 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | def main(str):
print("{}{}{}".format(str[0],str(len(str)-2),str[len(str)-1]) | Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the abbreviation of s.
* * * | s573680444 | Runtime Error | p03636 | Input is given from Standard Input in the following format:
s | s = input()
print(s)s=input()
out = s[0] + str(len(s)-2) + s[-1]
print(out) | Statement
The word `internationalization` is sometimes abbreviated to `i18n`. This comes
from the fact that there are 18 letters between the first `i` and the last
`n`.
You are given a string s of length at least 3 consisting of lowercase English
letters. Abbreviate s in the same way. | [{"input": "internationalization", "output": "i18n\n \n\n* * *"}, {"input": "smiles", "output": "s4s\n \n\n* * *"}, {"input": "xyz", "output": "x1z"}] |
Print the product in a line. | s101408945 | Accepted | p02477 | Two integers $A$ and $B$ separated by a space character are given in a line. | a,b=map(int,input().split())
print(a*b)
| Multiplication of Big Integers II
Given two integers $A$ and $B$, compute the product, $A \times B$. | [{"input": "5 8", "output": "40"}, {"input": "100 25", "output": "2500"}, {"input": "-1 0", "output": "0"}, {"input": "12 -3", "output": "-36"}] |
Print the product in a line. | s420160326 | Accepted | p02477 | Two integers $A$ and $B$ separated by a space character are given in a line. | print(eval(input().replace(" ", "*")))
| Multiplication of Big Integers II
Given two integers $A$ and $B$, compute the product, $A \times B$. | [{"input": "5 8", "output": "40"}, {"input": "100 25", "output": "2500"}, {"input": "-1 0", "output": "0"}, {"input": "12 -3", "output": "-36"}] |
Print the answer.
* * * | s323896298 | Accepted | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | (a, b, m), x, y, *c = [list(map(int, i.split())) for i in open(0)]
print(min([x[~-i] + y[~-j] - k for i, j, k in c] + [min(x) + min(y)]))
| Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
Print the answer.
* * * | s890409728 | Wrong Answer | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | s = input()
s_len = len(s)
if s_len % 2:
print("No")
else:
prev = 0
count = 0
for i in range(1, (s_len // 2) + 1):
if s[prev : i * 2] != "hi":
print("No")
break
else:
count += 1
prev = i * 2
if count == s_len // 2:
print("Yes")
| Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
Print the answer.
* * * | s707407657 | Accepted | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | #!/usr/bin/env python3
import sys
input = sys.stdin.buffer.readline
def inn(func=int):
return list(map(func, input().split()))
def ins():
return input().split()
an, bn, m = inn()
a = inn()
b = inn()
m_a = min(a)
m_b = min(b)
min_n = min(a) + min(b)
coupon = {}
for i in range(m):
xi, yi, ci = inn()
xi = xi - 1
yi = yi - 1
sum_vou = a[xi] + b[yi] - ci
if sum_vou < min_n:
min_n = sum_vou
print(min_n)
"""
for i in range(m):
xi,yi,ci = inn()
xi = xi-1
yi = yi-1
if not (xi,yi) in coupon.keys():
coupon[(xi,yi)] = ci
else:
if coupon[(xi,yi)] < ci:
coupon[(xi,yi)] = ci
"""
| Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
Print the answer.
* * * | s806974316 | Runtime Error | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | input = input()
price = {}
lowest1 = 100000
my_price = 0
def trans(s):
return int(s)
def split_with_blank(row):
return row.split(" ")
arr = input.split("\n")
arr2 = list(map(split_with_blank, arr))
for (
index1,
obj,
) in enumerate(arr2):
for (
index2,
st,
) in enumerate(obj):
# print(st)
arr2[index1][index2] = int(st)
A = arr2[0][0]
B = arr2[0][1]
M = arr2[0][2]
price = {"a": arr2[1], "b": arr2[2]}
coupons = arr2[3:]
def vali(coupon):
my_price = price["a"][coupon[0] - 1] + price["b"][coupon[1] - 1] - coupon[2]
global lowest1
if my_price < lowest1:
lowest1 = my_price
map(vali, coupons)
lowest2 = min(price["a"]) + min(price["b"])
if lowest1 <= lowest2:
print(lowest1)
else:
print(lowest2)
| Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
Print the answer.
* * * | s076041556 | Runtime Error | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | p = []
list1 = input()
a = input()
b = input()
list_1 = list(map(int, list1.split(" ")))
alist = list(map(int, a.split(" ")))
blist = list(map(int, b.split(" ")))
A = list_1[0]
B = list_1[1]
M = list_1[2]
for i in range(M):
l = input()
xyc = list(map(int, l.split(" ")))
x = xyc[0] - 1
y = xyc[1] - 1
c = xyc[2]
for i in range(A):
for j in range(B):
if x == i and y == j:
p.append(alist[i] + blist[j] - c)
p.append(alist[i] + blist[j])
print(min(p))
| Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
Print the answer.
* * * | s237253911 | Runtime Error | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | a,b,m=map(int, input().split())
rei=list(map(int, input().split()))
den=list(map(int, input().split()))
cou = [0] * m
ans = []
for i in range(m):
cou[i]=list(map(int, input().split()))
ans.append(rei[cou[i][0]-1]+den[cou[i][1]-1]-cou[i][2])
for i in range(b):
for j in range(a):
ans.append(rei[j]+den[i] | Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
Print the answer.
* * * | s982609954 | Wrong Answer | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | a, b, m = input().split()
a = int(a)
b = int(b)
m = int(m)
al = input().split()
bl = input().split()
ml = [list(map(int, input().split())) for i in range(m)]
al = list(map(int, al))
bl = list(map(int, bl))
al = sorted(al)
bl = sorted(bl)
tmp = al[0] + bl[0]
comp = 0
fp = tmp
for i in ml:
comp = al[i[0] - 1] + bl[i[1] - 1] - i[2]
if comp < fp:
fp = comp
print(fp)
| Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
Print the answer.
* * * | s936803495 | Wrong Answer | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | a, b, m = map(int, input().split())
A = input().split()
B = input().split()
AA = []
for i in range(len(A)):
AA.append(int(A[i]))
BB = []
for i in range(len(B)):
BB.append(int(B[i]))
print(AA)
print(BB)
C = []
for i in range(m):
x, y, c = map(int, input().split())
C.append(AA[x - 1] + BB[y - 1] - c)
C.append(min(AA) + min(BB))
print(min(C))
| Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
Print the answer.
* * * | s761256927 | Wrong Answer | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | abm = input("")
a = int(abm.split(" ")[0])
b = int(abm.split(" ")[1])
m = int(abm.split(" ")[2])
clist = []
dlist = []
wdic = {}
cin = input("")
din = input("")
for i in range(0, a):
clist.append(int(cin.split(" ")[i]))
for i in range(0, b):
dlist.append(int(din.split(" ")[i]))
for i in range(0, m):
win = input("")
wc = win.split(" ")[0]
wd = win.split(" ")[1]
wkey = wc + "-" + wd
wp = int(win.split(" ")[2])
if wkey in wdic.keys():
if wp > wdic[wkey]:
wdic[wkey] = wp
else:
wdic[wkey] = wp
min_price = -1
for i in range(0, a):
for j in range(0, b):
total = clist[i] + dlist[j]
if min_price == -1:
min_price = total
elif total < min_price:
min_price = total
wkey = str(i + 1) + "-" + str(j + 1)
if wkey in wdic.keys():
w = wdic[wkey]
total = clist[i] + dlist[j] - wp
if total < min_price:
min_price = total
print(min_price)
| Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
Print the answer.
* * * | s635705081 | Accepted | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | lines = []
line = input()
s = line.split(" ")
entries = int(s[2]) + 2
for i in range(entries + 1):
lines.append(line.split(" "))
if i < entries:
line = input()
discounts = []
for idx, line in enumerate(lines):
if idx == 0:
A = line[0]
B = line[1]
M = line[2]
elif idx == 1:
refrigerators = line
elif idx == 2:
microwaves = line
else:
discounts.append(line)
ref_reg = int(10**5)
for r in refrigerators:
reg = int(r)
if ref_reg > reg:
ref_reg = reg
ref_mic = int(10**5)
for m in microwaves:
mic = int(m)
if ref_mic > mic:
ref_mic = mic
ref_min = ref_reg + ref_mic
for discount in discounts:
d = (
int(refrigerators[int(discount[0]) - 1])
+ int(microwaves[int(discount[1]) - 1])
- int(discount[2])
)
if d < ref_min:
ref_min = d
print(ref_min)
| Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
Print the answer.
* * * | s809416956 | Accepted | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | (A, B, M) = (int(x) for x in input().split(" "))
# print(A, B, M)
ai = [int(x) for x in input().split(" ")]
bj = [int(x) for x in input().split(" ")]
ck = []
for k in range(int(M)):
ck.append([int(x) for x in input().split(" ")])
amin = min(ai)
bmin = min(bj)
abmin = amin + bmin
# print(abmin)
for cupon in ck:
ac = ai[cupon[0] - 1]
bc = bj[cupon[1] - 1]
cost = ac + bc - cupon[2]
# print(cost)
if cost < abmin:
abmin = cost
print(abmin)
| Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
Print the answer.
* * * | s011296972 | Accepted | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | (R, D, M) = list(map(int, input().split()))
R_yen = list(map(int, input().split()))
D_yen = list(map(int, input().split()))
min = 100000000
min_R = 10000000
min_D = 10000000
for i in range(M):
(R_dis, D_dis, Dis) = list(map(int, input().split()))
a = R_dis - 1
b = D_dis - 1
k = R_yen[a] + D_yen[b] - Dis
if min > k:
min = k
for i in R_yen:
if min_R > i:
min_R = i
for i in D_yen:
if min_D > i:
min_D = i
if min > min_R + min_D:
min = min_R + min_D
print(str(min))
| Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
Print the answer.
* * * | s740397668 | Runtime Error | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | R = lambda: tuple(map(int, input().split()))
A, B, M = R()
a, b = R(), R()
l = (R() for _ in range(M))
print(min(a[x - 1] + b[x - 1] - c for x, y, c in l))
| Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
Print the answer.
* * * | s442921583 | Accepted | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | line1 = input().split()
price_a = input().split()
price_b = input().split()
min_a = int(min(price_a))
min_b = int(min(price_b))
n = int(line1[2])
candidate = [min_a + min_b]
for i in range(n):
discount_data = input().split()
target_a = int(discount_data[0])
target_b = int(discount_data[1])
discount = int(discount_data[2])
total = int(price_a[target_a - 1]) + int(price_b[target_b - 1]) - discount
candidate.append(total)
print(min(candidate))
| Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
Print the answer.
* * * | s389510727 | Accepted | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | import sys
numbers = input().rstrip().split(" ")
A = int(numbers[0])
B = int(numbers[1])
M = int(numbers[2])
ref = input().rstrip().split(" ")
mic = input().rstrip().split(" ")
koopons = []
for line in sys.stdin.readlines():
koopons.append(line.rstrip().split(" "))
"""print(A)
print(B)
print(M)
print(ref)
print(mic)
print(koopons)"""
prices = []
for koopon in koopons:
price = int(ref[int(koopon[0]) - 1]) + int(mic[int(koopon[1]) - 1]) - int(koopon[2])
prices.append(price)
# print(prices)
lowest2 = sorted(prices)[0]
refs = sorted(ref)
mics = sorted(mic)
lowest1 = int(refs[0]) + int(mics[0])
# print(lowest1)
# print(lowest2)
if lowest1 >= lowest2:
print(lowest2)
else:
print(lowest1)
| Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
Print the answer.
* * * | s405117790 | Runtime Error | p02748 | Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M | zyouken = [int(i) for i in input().split()]
reizouko = [int(a) for a in input().split()]
densirenzi = [int(b) for b in input().split()]
minkouho = min(reizouko) + min(densirenzi)
while zyouken[2] > 0:
zyouken[2] = zyouken[2] - 1
waribiki = [int(w) for w in input().split()]
mink = reizouko[waribiki[0]] + densirenzi[waribiki[1]] - waribiki[2]
if mink < minkouho:
minkouho = mink
print(minkouho)
| Statement
You are visiting a large electronics store to buy a refrigerator and a
microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th
refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and
the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can
get a discount of c_i yen from the total price when buying the x_i-th
refrigerator and the y_i-th microwave together. Only one ticket can be used at
a time.
You are planning to buy one refrigerator and one microwave. Find the minimum
amount of money required. | [{"input": "2 3 1\n 3 3\n 3 3 3\n 1 2 1", "output": "5\n \n\nWith the ticket, you can get the 1-st refrigerator and the 2-nd microwave for\n3+3-1=5 yen.\n\n* * *"}, {"input": "1 1 2\n 10\n 10\n 1 1 5\n 1 1 10", "output": "10\n \n\nNote that you cannot use more than one ticket at a time.\n\n* * *"}, {"input": "2 2 1\n 3 5\n 3 5\n 2 2 2", "output": "6\n \n\nYou can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is\nthe minimum amount to pay in this case. Note that using a ticket is optional."}] |
For each dataset, output a line containing the number indicating the time _t_
of the last moment when the sunlight is blocked. The value should not have an
error greater than 0.001. No extra characters should appear in the output. | s161492097 | Wrong Answer | p00775 | The input consists of multiple datasets. The first line of a dataset contains
two integers _r_ and _n_ separated by a space. _r_ is the radius of the sun
and _n_ is the number of silhouettes of the buildings. (1 ≤ _r_ ≤ 20, 0 ≤ _n_
≤ 20)
Each of following _n_ lines contains three integers _x li_, _x ri_, _h i_ (1 ≤
_i_ ≤ _n_) separated by a space.
These three integers represent a silhouette rectangle of a building. The
silhouette rectangle is parallel to the horizon, and its left and right edges
are at _x_ = _x li_ and _x_ = _x ri_, its top edge is at _y_ = _h i_, and its
bottom edge is on the horizon. (-20 ≤ _x li_ < _x ri_ ≤ 20, 0 < _h i_ ≤ 20)
The end of the input is indicated by a line containing two zeros separated by
a space.
Note that these silhouettes may overlap one another. | import sys
EPS = 1e-9
def normalize(x):
return 2 * (x + 20)
def check(seg, r, t):
for x in range(40 - r, 40 + r + 1):
ok = False
for s in seg:
if s[2] < t - r:
# print("over!!!! x:{}, s[2]:{}, t-r:{}",x,s[2],t-r)
return False
if s[0] <= x and x <= s[1]:
k1 = (s[0] - 40) ** 2 + (s[2] - (t - r)) ** 2
k2 = (s[1] - 40) ** 2 + (s[2] - (t - r)) ** 2
# print("\tx:{}\ts[2]:{}\tt/2:{}\tr:{}\tk1:{}\tk2:{}\tkk:{}".format(x, s[2], t/2, r, k1, k2,kk))
if k1 >= r * r and k2 >= r * r:
ok = True
break
if not ok:
return False
return True
def main():
while True:
r, n = map(int, sys.stdin.readline().split())
if r == 0 and n == 0:
break
seq = [0] * 100 # 2?????§?¨??????????
for i in range(n):
x1, x2, h = map(int, sys.stdin.readline().split())
for x in range(normalize(x1), normalize(x2) + 1):
seq[x] = max(seq[x], 2 * h)
prev = 0
st = 0
seg = []
for i in range(100):
if prev != seq[i]:
if i % 2 == 0:
seg.append([st, i, prev])
st = i
else:
seg.append([st, i - 1, prev])
st = i - 1
prev = seq[i]
# ????????????????????¨?????????????????????????????????????????§?????????append?????????
# ??????1??\?????????????????\???
r *= 2
seg = [x for x in seg if x[2] > 0 and (40 - r <= x[0] or x[1] <= 40 + r)]
# ????????§?¨???????????????????????????????????????????????????????
for i in range(len(seg) - 1):
if seg[i][1] == seg[i + 1][0]:
if seg[i][2] > seg[i + 1][2]:
seg[i + 1][0] += EPS
elif seg[i][2] < seg[i + 1][2]:
seg[i][1] -= EPS
# print(seg)
tl = 0.0
tr = 40.0
for k in range(60):
tm = (tr + tl) / 2.0
if check(seg, r, tm):
tl = tm
else:
tr = tm
print("{0:.4f}".format(tl / 2))
if __name__ == "__main__":
main()
| Vampire
Mr. C is a vampire. If he is exposed to the sunlight directly, he turns into
ash. Nevertheless, last night, he attended to the meeting of Immortal and
Corpse Programmers Circle, and he has to go home in the near dawn.
Fortunately, there are many tall buildings around Mr. C's home, and while the
sunlight is blocked by the buildings, he can move around safely. The top end
of the sun has just reached the horizon now. In how many seconds does Mr. C
have to go into his safe coffin?
To simplify the problem, we represent the eastern dawn sky as a 2-dimensional
_x_ -_y_ plane, where the _x_ axis is horizontal and the _y_ axis is vertical,
and approximate building silhouettes by rectangles and the sun by a circle on
this plane.
The _x_ axis represents the horizon. We denote the time by _t_ , and the
current time is _t_ =0. The radius of the sun is _r_ and its center is at (0,
-_r_) when the time _t_ =0. The sun moves on the _x_ -_y_ plane in a uniform
linear motion at a constant velocity of (0, 1) per second.
The sunlight is blocked if and only if the entire region of the sun (including
its edge) is included in the union of the silhouettes (including their edges)
and the region below the horizon (y ≤ 0).
Write a program that computes the time of the last moment when the sunlight is
blocked.
The following figure shows the layout of silhouettes and the position of the
sun at the last moment when the sunlight is blocked, that corresponds to the
first dataset of Sample Input below. As this figure indicates, there are
possibilities that the last moment when the sunlight is blocked can be the
time _t_ =0.

The sunlight is blocked even when two silhouettes share parts of their edges.
The following figure shows the layout of silhouettes and the position of the
sun at the last moment when the sunlight is blocked, corresponding to the
second dataset of Sample Input. In this dataset the radius of the sun is 2 and
there are two silhouettes: the one with height 4 is in -2 ≤ _x_ ≤ 0, and the
other with height 3 is in 0 ≤ _x_ ≤ 2\.
 | [{"input": "3\n -2 -1 3\n 0 1 3\n 2 3 3\n 2 2\n -2 0 4\n 0 2 3\n 2 6\n -3 3 1\n -2 3 2\n -1 3 3\n 0 3 4\n 1 3 5\n 2 3 6\n 2 6\n -3 3 1\n -3 2 2\n -3 1 3\n -3 0 4\n -3 -1 5\n -3 -2 6\n 0 0", "output": ".0000\n 3.0000\n 2.2679\n 2.2679"}] |
Print the edit distance in a line. | s496142975 | Wrong Answer | p02318 | s1
s2
Two words s1 and s2 are given in the first line and the second line
respectively. The words will consist of lower case characters. | # ?????????http://ja.wikipedia.org/wiki/??¬??????????????\??????????????¢
def levenshtein_distance(str1, str2):
d = [[0] * (len(str2)) for _ in range(len(str1))]
for i1 in range(len(str1)):
d[i1][0] = i1
for i2 in range(len(str2)):
d[0][i2] = i2
for i1 in range(1, len(str1)):
for i2 in range(1, len(str2)):
cost = 0 if str1[i1] == str2[i2] else 1
d[i1][i2] = min(
d[i1 - 1][i2] + 1, # ??????????????\
d[i1][i2 - 1] + 1, # ???????????????
d[i1 - 1][i2 - 1] + cost,
) # ???????????????
return d[-1][-1]
from sys import stdin
readline = stdin.readline
s1, s2 = [readline().strip() for _ in range(2)]
print(levenshtein_distance(s1, s2))
| Edit Distance (Levenshtein Distance)
Find the edit distance between given two words s1 and s2.
The disntace is the minimum number of single-character edits required to
change one word into the other. The edits including the following operations:
* **insertion** : Insert a character at a particular position.
* **deletion** : Delete a character at a particular position.
* **substitution** : Change the character at a particular position to a different character | [{"input": "acac\n acm", "output": "2"}, {"input": "icpc\n icpc", "output": "0"}] |
Print the edit distance in a line. | s297639505 | Wrong Answer | p02318 | s1
s2
Two words s1 and s2 are given in the first line and the second line
respectively. The words will consist of lower case characters. | s1 = input()
s2 = input()
ls1 = len(s1)
ls2 = len(s2)
f = [[0 for j in range(ls2 + 1)] for i in range(ls1 + 1)]
for i in range(ls1 + 1):
f[i][0] = i
for i in range(ls2 + 1):
f[0][i] = i
for i in range(1, ls1 + 1):
for j in range(1, ls2 + 1):
if s1[i - 1] != s2[j - 1]:
f[i][j] = min(f[i - 1][j] + 1, f[i][j - 1] + 1, f[i - 1][j - 1] + 1)
else:
f[i][j] = f[i - 1][j - 1]
print(f)
| Edit Distance (Levenshtein Distance)
Find the edit distance between given two words s1 and s2.
The disntace is the minimum number of single-character edits required to
change one word into the other. The edits including the following operations:
* **insertion** : Insert a character at a particular position.
* **deletion** : Delete a character at a particular position.
* **substitution** : Change the character at a particular position to a different character | [{"input": "acac\n acm", "output": "2"}, {"input": "icpc\n icpc", "output": "0"}] |
Print the edit distance in a line. | s811420697 | Wrong Answer | p02318 | s1
s2
Two words s1 and s2 are given in the first line and the second line
respectively. The words will consist of lower case characters. | def main():
X = input()
Y = input()
dp = []
for y in range(len(Y)):
now = 0
for i in range(len(dp)):
d = dp[i]
if Y[y] in X[now:d]:
dp[i] = now + X[now:d].index(Y[y])
now = d + 1
if Y[y] in X[now:]:
dp.append(now + X[now:].index(Y[y]))
return max(len(X), len(Y)) - len(dp)
print(main())
| Edit Distance (Levenshtein Distance)
Find the edit distance between given two words s1 and s2.
The disntace is the minimum number of single-character edits required to
change one word into the other. The edits including the following operations:
* **insertion** : Insert a character at a particular position.
* **deletion** : Delete a character at a particular position.
* **substitution** : Change the character at a particular position to a different character | [{"input": "acac\n acm", "output": "2"}, {"input": "icpc\n icpc", "output": "0"}] |
Print the edit distance in a line. | s841862908 | Accepted | p02318 | s1
s2
Two words s1 and s2 are given in the first line and the second line
respectively. The words will consist of lower case characters. | def main():
S = input()
T = input()
ns = len(S)
nt = len(T)
dp = [[0] * (nt + 1) for _ in [0] * (ns + 1)]
for i in range(ns + 1):
dp[i][0] = i
for j in range(nt + 1):
dp[0][j] = j
di_1 = dp[0]
for s, di in zip(S, dp[1:]):
j = 0
di_1j_1 = di_1[0]
dij_1 = di[0]
for t in T:
j += 1
if s == t:
dmin = di_1j_1
di_1j = di_1[j]
else:
dmin = di_1j = di_1[j]
if dij_1 < dmin:
dmin = dij_1
if di_1j_1 < dmin:
dmin = di_1j_1
dmin += 1
di[j] = dij_1 = dmin
di_1j_1 = di_1j
di_1 = di
print(dp[-1][-1])
if __name__ == "__main__":
main()
| Edit Distance (Levenshtein Distance)
Find the edit distance between given two words s1 and s2.
The disntace is the minimum number of single-character edits required to
change one word into the other. The edits including the following operations:
* **insertion** : Insert a character at a particular position.
* **deletion** : Delete a character at a particular position.
* **substitution** : Change the character at a particular position to a different character | [{"input": "acac\n acm", "output": "2"}, {"input": "icpc\n icpc", "output": "0"}] |
Print the edit distance in a line. | s238188558 | Accepted | p02318 | s1
s2
Two words s1 and s2 are given in the first line and the second line
respectively. The words will consist of lower case characters. | S1 = input()
S2 = input()
dp = [[0 for i in range(len(S1) + 1)] for j in range(len(S2) + 1)]
for i in range(len(S1) + 1):
dp[0][i] = i
for j in range(len(S2) + 1):
dp[j][0] = j
for i in range(1, len(S1) + 1):
for j in range(1, len(S2) + 1):
if S1[i - 1] == S2[j - 1]:
dp[j][i] = dp[j - 1][i - 1]
else:
dp[j][i] = min(dp[j - 1][i], dp[j][i - 1], dp[j - 1][i - 1]) + 1
print(dp[len(S2)][len(S1)])
| Edit Distance (Levenshtein Distance)
Find the edit distance between given two words s1 and s2.
The disntace is the minimum number of single-character edits required to
change one word into the other. The edits including the following operations:
* **insertion** : Insert a character at a particular position.
* **deletion** : Delete a character at a particular position.
* **substitution** : Change the character at a particular position to a different character | [{"input": "acac\n acm", "output": "2"}, {"input": "icpc\n icpc", "output": "0"}] |
Print the edit distance in a line. | s986520316 | Accepted | p02318 | s1
s2
Two words s1 and s2 are given in the first line and the second line
respectively. The words will consist of lower case characters. | X = input()
Y = input()
m = len(X)
n = len(Y)
res = [[m + n for j in range(n + 1)] for i in range(m + 1)]
for i in range(m + 1):
res[i][0] = i
for j in range(n + 1):
res[0][j] = j
for i in range(1, m + 1):
for j in range(1, n + 1):
a = 1
if X[i - 1] == Y[j - 1]:
a = 0
res[i][j] = min(a + res[i - 1][j - 1], 1 + res[i - 1][j], 1 + res[i][j - 1])
print(res[m][n])
| Edit Distance (Levenshtein Distance)
Find the edit distance between given two words s1 and s2.
The disntace is the minimum number of single-character edits required to
change one word into the other. The edits including the following operations:
* **insertion** : Insert a character at a particular position.
* **deletion** : Delete a character at a particular position.
* **substitution** : Change the character at a particular position to a different character | [{"input": "acac\n acm", "output": "2"}, {"input": "icpc\n icpc", "output": "0"}] |
Print the answer.
* * * | s401190302 | Wrong Answer | p03159 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
U_1 V_1
U_2 V_2
:
U_{N - 1} V_{N - 1} | n = int(input())
l = list(map(int, input().split()))
cnt = 0
for i in range(n - 1):
a, b = map(int, input().split())
if (l[a - 1] < 0 or l[b - 1] < 0) and l[a - 1] + l[b - 1] >= 0:
cnt += 1
print(cnt)
| Statement
The server in company A has a structure where N devices numbered 1, 2, ..., N
are connected with N - 1 cables. The i-th cable connects Device U_i and Device
V_i. Any two different devices are connected through some number of cables.
Each device v (1 \leq v \leq N) has a non-zero integer A_v, which represents
the following:
* If A_v < 0, Device v is a computer that consumes an electric power of -A_v.
* If A_v > 0, Device v is a battery that supplies an electric power of A_v.
You have decided to disconnect some number of cables (possibly zero) to
disable the server. When some cables are disconnected, the devices will be
divided into some number of connected components. The server will be disabled
if all of these connected components satisfy one of the following conditions:
* There is no computer in the connected component. That is, A_v is positive for every device v that belongs to the connected component.
* There is not enough supply of electric power in the connected component. That is, the sum of A_v over all devices v that belong to the connected component is negative.
At least how many cables do you need to disconnect in order to disable the
server? | [{"input": "7\n -2 7 5 6 -8 3 4\n 1 2\n 2 3\n 2 4\n 1 5\n 5 6\n 5 7", "output": "1\n \n\nWe should disconnect the cable connecting Device 1 and Device 2.\n\n* * *"}, {"input": "4\n 1 2 3 4\n 1 2\n 1 3\n 1 4", "output": "0\n \n\n* * *"}, {"input": "6\n 10 -1 10 -1 10 -1\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6", "output": "5\n \n\n* * *"}, {"input": "8\n -2 3 6 -2 -2 -5 3 2\n 3 4\n 7 6\n 6 2\n 8 2\n 5 3\n 1 8\n 3 7", "output": "3\n \n\n* * *"}, {"input": "10\n 3 4 9 6 1 5 -1 10 -10 -10\n 7 4\n 5 6\n 8 1\n 9 5\n 7 1\n 10 3\n 2 8\n 4 10\n 9 2", "output": "3"}] |
Print the answer.
* * * | s426269337 | Runtime Error | p03159 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
U_1 V_1
U_2 V_2
:
U_{N - 1} V_{N - 1} | from collections import deque
N=int(input())
*A,=map(int,input().split())
G=[[] for _ in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
def bfs(s):
seen = [0]*N
d = [0]*N
prev = [0]*N
todo = deque()
seen[s]=1
todo.append(s)
while len(todo):
a = todo.popleft()
for b in G[a]:
if seen[b] == 0:
seen[b] = 1
todo.append(b)
d[b] += d[a] + 1
prev[b] = a
return d, prev
d,prev = bfs(0)
order = list(zip(*sorted(enumerate(d),key=lambda x:x[1])))[0]
dp1=[set() for _ in range(N)]
dp2=[0]*N
for a in reversed(order):
for b in G[a]:
if prev[a]==b:continue
if len(G[b])==1:
if A[b]>0:
dp1[b].add(b)
dp2[b] = A[b]
if len(G[b])==2:
for d in G[b]:
if d == prev[b]:continue
c = d
if A[b]>0 and dp1[c] != []:
dp1[b] = dp1[c]+[b]
elif A[b]>0:
dp1[b].add(b)
dp2[b] = dp2[c] + A[b]
if len(G[b])>2:
for c in G[b]:
if c == prev[b]:continue
if A[b]>0 and dp1[c] != []:
dp1[b] |= dp1[c]
dp2[b] += dp2[c]
if A[b]>0:
dp1[b].add(b)
dp2[b] += A[b]
print(dp1)
print(dp2)
DP1 = [{} for _ in range(N)]
DP2 = [{} for _ in range(N)]
for a in order:
if a == 0:
for i in range(len(G[a])):
DP1[a][i] = dp1[G[a][i]]
DP2[a][i] = dp2[G[a][i]]
continue
for b in G[a]:
if prev[a]==b:
if dp1[a] != [] and | Statement
The server in company A has a structure where N devices numbered 1, 2, ..., N
are connected with N - 1 cables. The i-th cable connects Device U_i and Device
V_i. Any two different devices are connected through some number of cables.
Each device v (1 \leq v \leq N) has a non-zero integer A_v, which represents
the following:
* If A_v < 0, Device v is a computer that consumes an electric power of -A_v.
* If A_v > 0, Device v is a battery that supplies an electric power of A_v.
You have decided to disconnect some number of cables (possibly zero) to
disable the server. When some cables are disconnected, the devices will be
divided into some number of connected components. The server will be disabled
if all of these connected components satisfy one of the following conditions:
* There is no computer in the connected component. That is, A_v is positive for every device v that belongs to the connected component.
* There is not enough supply of electric power in the connected component. That is, the sum of A_v over all devices v that belong to the connected component is negative.
At least how many cables do you need to disconnect in order to disable the
server? | [{"input": "7\n -2 7 5 6 -8 3 4\n 1 2\n 2 3\n 2 4\n 1 5\n 5 6\n 5 7", "output": "1\n \n\nWe should disconnect the cable connecting Device 1 and Device 2.\n\n* * *"}, {"input": "4\n 1 2 3 4\n 1 2\n 1 3\n 1 4", "output": "0\n \n\n* * *"}, {"input": "6\n 10 -1 10 -1 10 -1\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6", "output": "5\n \n\n* * *"}, {"input": "8\n -2 3 6 -2 -2 -5 3 2\n 3 4\n 7 6\n 6 2\n 8 2\n 5 3\n 1 8\n 3 7", "output": "3\n \n\n* * *"}, {"input": "10\n 3 4 9 6 1 5 -1 10 -10 -10\n 7 4\n 5 6\n 8 1\n 9 5\n 7 1\n 10 3\n 2 8\n 4 10\n 9 2", "output": "3"}] |
Print the answer.
* * * | s218625153 | Wrong Answer | p03159 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
U_1 V_1
U_2 V_2
:
U_{N - 1} V_{N - 1} | import sys
readline = sys.stdin.readline
inf = 10**9 + 7
def merge(d1a, d2a, d1b, d2b):
la = len(d1a)
lb = len(d1b)
k = la + lb
res1 = [inf] * k
res2 = [inf] * k
for i in range(la):
for j in range(lb):
res1[i + j] = min(
res1[i + j], d1a[i] + d1b[j], d1a[i] + d2b[j], d2a[i] + d1b[j]
)
res2[i + j] = min(res2[i + j], d2a[i] + d2b[j])
for j in range(lb):
if d1b[j] < 0:
for i in range(la):
res1[i + j + 1] = min(res1[i + j + 1], d1a[i])
res2[i + j + 1] = min(res2[i + j + 1], d2a[i])
if d2b[j] < inf:
for i in range(la):
res1[i + j + 1] = min(res1[i + j + 1], d1a[i])
res2[i + j + 1] = min(res2[i + j + 1], d2a[i])
return res1, res2
def parorder(Edge, p):
N = len(Edge)
par = [0] * N
par[p] = -1
stack = [p]
order = []
visited = set([p])
ast = stack.append
apo = order.append
while stack:
vn = stack.pop()
apo(vn)
for vf in Edge[vn]:
if vf in visited:
continue
visited.add(vf)
par[vf] = vn
ast(vf)
return par, order
def getcld(p):
res = [[] for _ in range(len(p))]
for i, v in enumerate(p[1:], 1):
res[v].append(i)
return res
N = int(readline())
A = list(map(int, readline().split()))
Edge = [[] for _ in range(N)]
for _ in range(N - 1):
a, b = map(int, readline().split())
a -= 1
b -= 1
Edge[a].append(b)
Edge[b].append(a)
P, L = parorder(Edge, 0)
# C = getcld(P)
dp1 = [[A[i] if A[i] < 0 else inf] for i in range(N)]
dp2 = [[A[i] if A[i] > 0 else inf] for i in range(N)]
for l in L[:0:-1]:
p = P[l]
dp1[p], dp2[p] = merge(dp1[p], dp2[p], dp1[l], dp2[l])
ans = inf
for i in range(N):
if dp1[0][i] < 0 or dp2[0][i] < inf:
ans = i
break
print(ans)
| Statement
The server in company A has a structure where N devices numbered 1, 2, ..., N
are connected with N - 1 cables. The i-th cable connects Device U_i and Device
V_i. Any two different devices are connected through some number of cables.
Each device v (1 \leq v \leq N) has a non-zero integer A_v, which represents
the following:
* If A_v < 0, Device v is a computer that consumes an electric power of -A_v.
* If A_v > 0, Device v is a battery that supplies an electric power of A_v.
You have decided to disconnect some number of cables (possibly zero) to
disable the server. When some cables are disconnected, the devices will be
divided into some number of connected components. The server will be disabled
if all of these connected components satisfy one of the following conditions:
* There is no computer in the connected component. That is, A_v is positive for every device v that belongs to the connected component.
* There is not enough supply of electric power in the connected component. That is, the sum of A_v over all devices v that belong to the connected component is negative.
At least how many cables do you need to disconnect in order to disable the
server? | [{"input": "7\n -2 7 5 6 -8 3 4\n 1 2\n 2 3\n 2 4\n 1 5\n 5 6\n 5 7", "output": "1\n \n\nWe should disconnect the cable connecting Device 1 and Device 2.\n\n* * *"}, {"input": "4\n 1 2 3 4\n 1 2\n 1 3\n 1 4", "output": "0\n \n\n* * *"}, {"input": "6\n 10 -1 10 -1 10 -1\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6", "output": "5\n \n\n* * *"}, {"input": "8\n -2 3 6 -2 -2 -5 3 2\n 3 4\n 7 6\n 6 2\n 8 2\n 5 3\n 1 8\n 3 7", "output": "3\n \n\n* * *"}, {"input": "10\n 3 4 9 6 1 5 -1 10 -10 -10\n 7 4\n 5 6\n 8 1\n 9 5\n 7 1\n 10 3\n 2 8\n 4 10\n 9 2", "output": "3"}] |
Print the answer.
* * * | s355279845 | Wrong Answer | p03159 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
U_1 V_1
U_2 V_2
:
U_{N - 1} V_{N - 1} | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N = int(readline())
A = [0] + list(map(int, readline().split()))
m = map(int, read().split())
UV = zip(m, m)
graph = [[] for _ in range(N + 1)]
for u, v in UV:
graph[u].append(v)
graph[v].append(u)
root = 1
parent = [0] * (N + 1)
ts = []
stack = [root]
while stack:
x = stack.pop()
ts.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
INF = 10**18
"""
各頂点において、
・「根側を全て正にするための切断回数」
・「各切断回数ごとの、根側に残る数の和の最小値」(array)
を持つ
"""
positive_cut_cnt = [None] * (N + 1)
rest_sum_array = [None] * (N + 1)
def merge(dp1, dp2):
# 回数 -> 和の最小値が入っている
L1, L2 = len(dp1), len(dp2)
if L1 > L2:
L1, L2 = L2, L1
dp1, dp2 = dp2, dp1
dp = np.full(L1 + L2 - 1, INF)
for i, x in enumerate(dp1):
np.minimum(dp[i : L2 + i], x + dp2, out=dp[i : L2 + i])
return dp
for x in ts[::-1]:
a = A[x]
arr = np.array([a], np.int64)
cut = 0
for c in graph[x]:
if c == parent[x]:
continue
arr = merge(arr, rest_sum_array[c])
cut += positive_cut_cnt[c]
arr = np.append(arr, 0)
negative = np.where(arr < 0)[0]
if a > 0:
positive_cut_cnt[x] = cut
# 全て正として切る
np.minimum(arr[cut + 1 :], 0, out=arr[cut + 1 :])
if a < 0:
positive_cut_cnt[x] = negative[0] + 1
if len(negative):
# 負として切る
np.minimum(arr[negative + 1], 0, out=arr[negative + 1])
if cut > negative[0]:
cut = negative[0]
rest_sum_array[x] = arr
negative = np.where(rest_sum_array[1] < 0)[0]
answer = INF
if len(negative):
answer = negative[0]
if answer > positive_cut_cnt[1]:
answer = positive_cut_cnt[1]
print(answer)
| Statement
The server in company A has a structure where N devices numbered 1, 2, ..., N
are connected with N - 1 cables. The i-th cable connects Device U_i and Device
V_i. Any two different devices are connected through some number of cables.
Each device v (1 \leq v \leq N) has a non-zero integer A_v, which represents
the following:
* If A_v < 0, Device v is a computer that consumes an electric power of -A_v.
* If A_v > 0, Device v is a battery that supplies an electric power of A_v.
You have decided to disconnect some number of cables (possibly zero) to
disable the server. When some cables are disconnected, the devices will be
divided into some number of connected components. The server will be disabled
if all of these connected components satisfy one of the following conditions:
* There is no computer in the connected component. That is, A_v is positive for every device v that belongs to the connected component.
* There is not enough supply of electric power in the connected component. That is, the sum of A_v over all devices v that belong to the connected component is negative.
At least how many cables do you need to disconnect in order to disable the
server? | [{"input": "7\n -2 7 5 6 -8 3 4\n 1 2\n 2 3\n 2 4\n 1 5\n 5 6\n 5 7", "output": "1\n \n\nWe should disconnect the cable connecting Device 1 and Device 2.\n\n* * *"}, {"input": "4\n 1 2 3 4\n 1 2\n 1 3\n 1 4", "output": "0\n \n\n* * *"}, {"input": "6\n 10 -1 10 -1 10 -1\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6", "output": "5\n \n\n* * *"}, {"input": "8\n -2 3 6 -2 -2 -5 3 2\n 3 4\n 7 6\n 6 2\n 8 2\n 5 3\n 1 8\n 3 7", "output": "3\n \n\n* * *"}, {"input": "10\n 3 4 9 6 1 5 -1 10 -10 -10\n 7 4\n 5 6\n 8 1\n 9 5\n 7 1\n 10 3\n 2 8\n 4 10\n 9 2", "output": "3"}] |
Print the answer.
* * * | s929622175 | Wrong Answer | p03159 | Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
U_1 V_1
U_2 V_2
:
U_{N - 1} V_{N - 1} | import sys
import copy
sys.setrecursionlimit(1000000)
def dfs(used, tree, node, capacity_and_cut_num):
if used[node] != 0:
return
if energy[node] > 0:
capacity_and_cut_num[0] += energy[node]
else:
capacity_and_cut_num[1] += 1
return
used[node] = 1
for x in tree[node]:
dfs(used, tree, x, capacity_and_cut_num)
N = int(input())
energy = list(map(int, input().split()))
battery = []
for i, x in enumerate(energy):
if x > 0:
battery.append(i)
cable = [[] for _ in range(N)]
used = [0 for _ in range(N)]
for i in range(N - 1):
U, V = list(map(int, input().split()))
cable[U - 1].append(V - 1)
cable[V - 1].append(U - 1)
new_battery = []
for b in battery:
capacity_and_cut_num = [0, 0]
dfs(used, cable, b, capacity_and_cut_num)
if capacity_and_cut_num[0] == 0:
continue
new_battery.append(capacity_and_cut_num)
new_battery = sorted(new_battery, key=lambda x: x[1])
sum_energy = sum(energy)
ans = 0
dp = [[0, copy.deepcopy(new_battery)] for _ in range(N)]
for i in range(1, N):
for j in range(0, i):
for k, b in enumerate(dp[j][1]):
if b[1] == i - j and dp[j][0] + b[0] > dp[i][0]:
dp[i][0] = dp[j][0] + b[0]
dp[i][1] = dp[j][1][:k] + dp[j][1][k + 1 :]
if dp[i][0] > sum_energy:
ans = i
break
print(ans)
| Statement
The server in company A has a structure where N devices numbered 1, 2, ..., N
are connected with N - 1 cables. The i-th cable connects Device U_i and Device
V_i. Any two different devices are connected through some number of cables.
Each device v (1 \leq v \leq N) has a non-zero integer A_v, which represents
the following:
* If A_v < 0, Device v is a computer that consumes an electric power of -A_v.
* If A_v > 0, Device v is a battery that supplies an electric power of A_v.
You have decided to disconnect some number of cables (possibly zero) to
disable the server. When some cables are disconnected, the devices will be
divided into some number of connected components. The server will be disabled
if all of these connected components satisfy one of the following conditions:
* There is no computer in the connected component. That is, A_v is positive for every device v that belongs to the connected component.
* There is not enough supply of electric power in the connected component. That is, the sum of A_v over all devices v that belong to the connected component is negative.
At least how many cables do you need to disconnect in order to disable the
server? | [{"input": "7\n -2 7 5 6 -8 3 4\n 1 2\n 2 3\n 2 4\n 1 5\n 5 6\n 5 7", "output": "1\n \n\nWe should disconnect the cable connecting Device 1 and Device 2.\n\n* * *"}, {"input": "4\n 1 2 3 4\n 1 2\n 1 3\n 1 4", "output": "0\n \n\n* * *"}, {"input": "6\n 10 -1 10 -1 10 -1\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6", "output": "5\n \n\n* * *"}, {"input": "8\n -2 3 6 -2 -2 -5 3 2\n 3 4\n 7 6\n 6 2\n 8 2\n 5 3\n 1 8\n 3 7", "output": "3\n \n\n* * *"}, {"input": "10\n 3 4 9 6 1 5 -1 10 -10 -10\n 7 4\n 5 6\n 8 1\n 9 5\n 7 1\n 10 3\n 2 8\n 4 10\n 9 2", "output": "3"}] |
Print q lines. The i-th line should contain the response to the i-th query. If
S_{a_i} S_{{a_i}+1} ... S_{b_i} can be made into T_{c_i} T_{{c_i}+1} ...
T_{d_i}, print `YES`. Otherwise, print `NO`.
* * * | s101192775 | Accepted | p03765 | Input is given from Standard Input in the following format:
S
T
q
a_1 b_1 c_1 d_1
...
a_q b_q c_q d_q | # -*- coding: utf-8 -*-
import sys
from itertools import accumulate
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
S = [ord(s) - 65 for s in input()]
T = [ord(t) - 65 for t in input()]
acc1 = [0] + list(accumulate(S))
acc2 = [0] + list(accumulate(T))
# 3つのタイプを判定(0: aが残る, 1: bが残る, 2: 何も残らない)
def check(cnta, cntb):
if cnta == cntb:
return 2
elif cnta < cntb:
cntb -= cnta
if cntb % 3 == 0:
return 2
elif cntb % 3 == 1:
return 1
else:
return 0
else:
cnta -= cntb
if cnta % 3 == 0:
return 2
elif cnta % 3 == 1:
return 0
else:
return 1
Q = INT()
for _ in range(Q):
l1, r1, l2, r2 = MAP()
ln1 = r1 - l1 + 1
ln2 = r2 - l2 + 1
# 累積和を使ってO(1)でAとBの個数を取得
cntb1 = acc1[r1] - acc1[l1 - 1]
cnta1 = ln1 - cntb1
cntb2 = acc2[r2] - acc2[l2 - 1]
cnta2 = ln2 - cntb2
# 同じタイプかどうか判定する
if check(cnta1, cntb1) == check(cnta2, cntb2):
YES()
else:
NO()
| Statement
Let us consider the following operations on a string consisting of `A` and
`B`:
1. Select a character in a string. If it is `A`, replace it with `BB`. If it is `B`, replace with `AA`.
2. Select a substring that is equal to either `AAA` or `BBB`, and delete it from the string.
For example, if the first operation is performed on `ABA` and the first
character is selected, the string becomes `BBBA`. If the second operation is
performed on `BBBAAAA` and the fourth through sixth characters are selected,
the string becomes `BBBA`.
These operations can be performed any number of times, in any order.
You are given two string S and T, and q queries a_i, b_i, c_i, d_i. For each
query, determine whether S_{a_i} S_{{a_i}+1} ... S_{b_i}, a substring of S,
can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i}, a substring of T. | [{"input": "BBBAAAABA\n BBBBA\n 4\n 7 9 2 5\n 7 9 1 4\n 1 7 2 5\n 1 7 2 4", "output": "YES\n NO\n YES\n NO\n \n\nThe first query asks whether the string `ABA` can be made into `BBBA`. As\nexplained in the problem statement, it can be done by the first operation.\n\nThe second query asks whether `ABA` can be made into `BBBB`, and the fourth\nquery asks whether `BBBAAAA` can be made into `BBB`. Neither is possible.\n\nThe third query asks whether the string `BBBAAAA` can be made into `BBBA`. As\nexplained in the problem statement, it can be done by the second operation.\n\n* * *"}, {"input": "AAAAABBBBAAABBBBAAAA\n BBBBAAABBBBBBAAAAABB\n 10\n 2 15 2 13\n 2 13 6 16\n 1 13 2 20\n 4 20 3 20\n 1 18 9 19\n 2 14 1 11\n 3 20 3 15\n 6 16 1 17\n 4 18 8 20\n 7 20 3 14", "output": "YES\n YES\n YES\n YES\n YES\n YES\n NO\n NO\n NO\n NO"}] |
Print q lines. The i-th line should contain the response to the i-th query. If
S_{a_i} S_{{a_i}+1} ... S_{b_i} can be made into T_{c_i} T_{{c_i}+1} ...
T_{d_i}, print `YES`. Otherwise, print `NO`.
* * * | s238257142 | Accepted | p03765 | Input is given from Standard Input in the following format:
S
T
q
a_1 b_1 c_1 d_1
...
a_q b_q c_q d_q | #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return list(map(list, sys.stdin.readline().split()))
def S():
return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = LS()
return l
sys.setrecursionlimit(1000000)
mod = 1000000007
# A
def A():
x = S()
s = 0
ans = len(x)
for i in x:
if i == "S":
s += 1
else:
if s > 0:
s -= 1
ans -= 2
print(ans)
return
# B
def B():
n = I()
a = LI()
f = [0 for i in range(n + 1)]
for i in range(n):
f[a[i]] = i
l = [i for i in range(n + 1)]
r = [i for i in range(n + 1)]
ans = 0
for i in range(1, n + 1)[::-1]:
j = f[i]
ans += (j - l[j] + 1) * (r[j] - j + 1) * i
l[r[j] + 1] = l[j]
r[l[j] - 1] = r[j]
print(ans)
return
# C
def C():
n, x = LI()
if x == 1 or x == 2 * n - 1:
print("No")
quit()
else:
ans = [i + 1 for i in range(2 * n - 1)]
k = x - n
if k < 0:
ans = ans[2 * n - 1 + k :] + ans[: 2 * n - 1 + k]
if k > 0:
ans = ans[k:] + ans[:k]
print("Yes")
for i in ans:
print(i)
return
# D
def D():
s = S()
t = S()
n = len(s)
m = len(t)
fs = [1 if s[i] == "A" else 2 for i in range(n)]
ft = [1 if t[i] == "A" else 2 for i in range(m)]
for i in range(n - 1):
fs[i + 1] += fs[i]
fs[i + 1] %= mod
for i in range(m - 1):
ft[i + 1] += ft[i]
ft[i + 1] %= mod
fs.insert(0, 0)
ft.insert(0, 0)
q = I()
for i in range(q):
a, b, c, d = LI()
a -= 1
c -= 1
if (fs[b] - fs[a]) % 3 == (ft[d] - ft[c]) % 3:
print("YES")
else:
print("NO")
return
# E
def E():
return
# F
def F():
return
# G
def G():
return
# H
def H():
return
# Solve
if __name__ == "__main__":
D()
| Statement
Let us consider the following operations on a string consisting of `A` and
`B`:
1. Select a character in a string. If it is `A`, replace it with `BB`. If it is `B`, replace with `AA`.
2. Select a substring that is equal to either `AAA` or `BBB`, and delete it from the string.
For example, if the first operation is performed on `ABA` and the first
character is selected, the string becomes `BBBA`. If the second operation is
performed on `BBBAAAA` and the fourth through sixth characters are selected,
the string becomes `BBBA`.
These operations can be performed any number of times, in any order.
You are given two string S and T, and q queries a_i, b_i, c_i, d_i. For each
query, determine whether S_{a_i} S_{{a_i}+1} ... S_{b_i}, a substring of S,
can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i}, a substring of T. | [{"input": "BBBAAAABA\n BBBBA\n 4\n 7 9 2 5\n 7 9 1 4\n 1 7 2 5\n 1 7 2 4", "output": "YES\n NO\n YES\n NO\n \n\nThe first query asks whether the string `ABA` can be made into `BBBA`. As\nexplained in the problem statement, it can be done by the first operation.\n\nThe second query asks whether `ABA` can be made into `BBBB`, and the fourth\nquery asks whether `BBBAAAA` can be made into `BBB`. Neither is possible.\n\nThe third query asks whether the string `BBBAAAA` can be made into `BBBA`. As\nexplained in the problem statement, it can be done by the second operation.\n\n* * *"}, {"input": "AAAAABBBBAAABBBBAAAA\n BBBBAAABBBBBBAAAAABB\n 10\n 2 15 2 13\n 2 13 6 16\n 1 13 2 20\n 4 20 3 20\n 1 18 9 19\n 2 14 1 11\n 3 20 3 15\n 6 16 1 17\n 4 18 8 20\n 7 20 3 14", "output": "YES\n YES\n YES\n YES\n YES\n YES\n NO\n NO\n NO\n NO"}] |
Print q lines. The i-th line should contain the response to the i-th query. If
S_{a_i} S_{{a_i}+1} ... S_{b_i} can be made into T_{c_i} T_{{c_i}+1} ...
T_{d_i}, print `YES`. Otherwise, print `NO`.
* * * | s849403570 | Wrong Answer | p03765 | Input is given from Standard Input in the following format:
S
T
q
a_1 b_1 c_1 d_1
...
a_q b_q c_q d_q | def examC():
N = I()
d = defaultdict(int)
for i in range(N):
curD = defaultdict(int)
S = SI()
for s in S:
curD[s] += 1
if i == 0:
d = curD
continue
for s in alphabet:
d[s] = min(d[s], curD[s])
d = sorted(d.items())
ans = ""
for key, i in d:
ans += key * i
print(ans)
return
def examD():
N, M = LI()
X = LI()
Y = LI()
distX = [0] * N
distY = [0] * M
for i in range(N - 1):
distX[i + 1] = X[i + 1] - X[i]
for i in range(M - 1):
distY[i + 1] = Y[i + 1] - Y[i]
numX = [0] * N
numY = [0] * M
for i in range(N):
numX[i] = i * (N - i)
for i in range(M):
numY[i] = i * (M - i)
LX = 0
LY = 0
for i in range(N):
LX += distX[i] * numX[i]
LX %= mod
for i in range(M):
LY += distY[i] * numY[i]
LY %= mod
# print(numX,distX); print(numY,distY)
ans = (LX * LY) % mod
print(ans)
return
def examE():
S = SI()
T = SI()
numaS = [0] * (len(S) + 1)
numaT = [0] * (len(T) + 1)
for i, s in enumerate(S):
numaS[i + 1] = numaS[i]
if s == "A":
numaS[i + 1] += 1
for i, s in enumerate(T):
numaT[i + 1] = numaT[i]
if s == "A":
numaT[i + 1] += 1
# print(numaS); print(numaT)
Q = I()
ans = ["YES"] * Q
for i in range(Q):
a, b, c, d = LI()
curaS = numaS[b] - numaS[a - 1]
curbS = (b - a) - curaS + 1
curaT = numaT[d] - numaT[c - 1]
curbT = (d - c) - curaT + 1
print(curaS, curbS, curaT, curbT)
if (curaS % 3 + (curaS + curbS) % 3) % 3 != (
curaT % 3 + (curaT + curbT) % 3
) % 3:
# if (curbS % 3 + (curaS + curbS) % 3) % 3 != (curbT % 3 + (curaT + curbT) % 3) % 3:
ans[i] = "NO"
for v in ans:
print(v)
return
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LSI():
return list(map(str, sys.stdin.readline().split()))
def LS():
return sys.stdin.readline().split()
def SI():
return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord("a") + i) for i in range(26)]
if __name__ == "__main__":
examE()
| Statement
Let us consider the following operations on a string consisting of `A` and
`B`:
1. Select a character in a string. If it is `A`, replace it with `BB`. If it is `B`, replace with `AA`.
2. Select a substring that is equal to either `AAA` or `BBB`, and delete it from the string.
For example, if the first operation is performed on `ABA` and the first
character is selected, the string becomes `BBBA`. If the second operation is
performed on `BBBAAAA` and the fourth through sixth characters are selected,
the string becomes `BBBA`.
These operations can be performed any number of times, in any order.
You are given two string S and T, and q queries a_i, b_i, c_i, d_i. For each
query, determine whether S_{a_i} S_{{a_i}+1} ... S_{b_i}, a substring of S,
can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i}, a substring of T. | [{"input": "BBBAAAABA\n BBBBA\n 4\n 7 9 2 5\n 7 9 1 4\n 1 7 2 5\n 1 7 2 4", "output": "YES\n NO\n YES\n NO\n \n\nThe first query asks whether the string `ABA` can be made into `BBBA`. As\nexplained in the problem statement, it can be done by the first operation.\n\nThe second query asks whether `ABA` can be made into `BBBB`, and the fourth\nquery asks whether `BBBAAAA` can be made into `BBB`. Neither is possible.\n\nThe third query asks whether the string `BBBAAAA` can be made into `BBBA`. As\nexplained in the problem statement, it can be done by the second operation.\n\n* * *"}, {"input": "AAAAABBBBAAABBBBAAAA\n BBBBAAABBBBBBAAAAABB\n 10\n 2 15 2 13\n 2 13 6 16\n 1 13 2 20\n 4 20 3 20\n 1 18 9 19\n 2 14 1 11\n 3 20 3 15\n 6 16 1 17\n 4 18 8 20\n 7 20 3 14", "output": "YES\n YES\n YES\n YES\n YES\n YES\n NO\n NO\n NO\n NO"}] |
Print q lines. The i-th line should contain the response to the i-th query. If
S_{a_i} S_{{a_i}+1} ... S_{b_i} can be made into T_{c_i} T_{{c_i}+1} ...
T_{d_i}, print `YES`. Otherwise, print `NO`.
* * * | s578061122 | Accepted | p03765 | Input is given from Standard Input in the following format:
S
T
q
a_1 b_1 c_1 d_1
...
a_q b_q c_q d_q | s, t, _, *z = open(0)
v, w = [0], [0]
for c in s:
v += (v[-1] + (c < "B" or 2),)
for c in t:
w += (w[-1] + (c < "B" or 2),)
for x in z:
a, b, c, d = map(int, x.split())
print("YNEOS"[(v[b] - v[a - 1]) % 3 != (w[d] - w[c - 1]) % 3 :: 2])
| Statement
Let us consider the following operations on a string consisting of `A` and
`B`:
1. Select a character in a string. If it is `A`, replace it with `BB`. If it is `B`, replace with `AA`.
2. Select a substring that is equal to either `AAA` or `BBB`, and delete it from the string.
For example, if the first operation is performed on `ABA` and the first
character is selected, the string becomes `BBBA`. If the second operation is
performed on `BBBAAAA` and the fourth through sixth characters are selected,
the string becomes `BBBA`.
These operations can be performed any number of times, in any order.
You are given two string S and T, and q queries a_i, b_i, c_i, d_i. For each
query, determine whether S_{a_i} S_{{a_i}+1} ... S_{b_i}, a substring of S,
can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i}, a substring of T. | [{"input": "BBBAAAABA\n BBBBA\n 4\n 7 9 2 5\n 7 9 1 4\n 1 7 2 5\n 1 7 2 4", "output": "YES\n NO\n YES\n NO\n \n\nThe first query asks whether the string `ABA` can be made into `BBBA`. As\nexplained in the problem statement, it can be done by the first operation.\n\nThe second query asks whether `ABA` can be made into `BBBB`, and the fourth\nquery asks whether `BBBAAAA` can be made into `BBB`. Neither is possible.\n\nThe third query asks whether the string `BBBAAAA` can be made into `BBBA`. As\nexplained in the problem statement, it can be done by the second operation.\n\n* * *"}, {"input": "AAAAABBBBAAABBBBAAAA\n BBBBAAABBBBBBAAAAABB\n 10\n 2 15 2 13\n 2 13 6 16\n 1 13 2 20\n 4 20 3 20\n 1 18 9 19\n 2 14 1 11\n 3 20 3 15\n 6 16 1 17\n 4 18 8 20\n 7 20 3 14", "output": "YES\n YES\n YES\n YES\n YES\n YES\n NO\n NO\n NO\n NO"}] |
For each get operation, print the corresponding value.
For each dump operation, print the corresponding elements formed by a pair of
the key and the value. For the dump operation, print the elements (a pair of
key and value separated by a space character) in ascending order of the keys. | s562991889 | Wrong Answer | p02461 | The input is given in the following format.
$q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $key$ $x$
or
1 $key$
or
2 $key$
or
3 $L$ $R$
where the first digits 0, 1, 2 and 3 represent insert, get, delete and dump
operations. | from collections import OrderedDict
dict = OrderedDict()
q = int(input())
for i in range(q):
query, *val = input().split(" ")
if query == "0":
dict[val[0]] = int(val[1])
elif query == "1":
print(dict.get(val[0], 0))
elif query == "2":
if val[0] in dict:
dict.pop(val[0])
else:
ans = ""
for k, v in dict.items():
if val[0] <= k and k <= val[1]:
ans += str(k) + " " + str(v) + " "
print(ans.strip())
| Map: Range Search
For a dictionary $M$ that stores elements formed by a pair of a string key and
an integer value, perform a sequence of the following operations. Note that
_each key in $M$ must be unique_.
* insert($key$, $x$): Insert an element formed by a pair of $key$ and $x$ to $M$.
* get($key$): Print the value with the specified $key$. _Print 0 if there is no such element_.
* delete($key$): Delete the element with the specified $key$.
* dump($L$, $R$): Print all elements formed by a pair of the key and the value such that the key is greater than or equal to $L$ and less than or equal to $R$ in lexicographic order. | [{"input": "9\n 0 blue 4\n 0 red 1\n 0 white 5\n 1 red\n 1 blue\n 2 red\n 1 black\n 1 red\n 3 w z", "output": "1\n 4\n 0\n 0\n white 5"}] |
Print the smallest number of operations required to make strings A and B
equal, or -1 if the goal is unreachable.
* * * | s251529171 | Wrong Answer | p03620 | Input is given from Standard Input in the following format:
A
B | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10**13
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return sys.stdin.readline().rstrip().split()
def S():
return sys.stdin.readline().rstrip()
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 10**9 + 7
A = S()
B = S()
n = len(B)
A *= 2
B *= 2
l = [0] * n
r = [0] * n
for i in range(n):
if A[i] != B[i]:
for j in range(n):
if B[(i + j) % n] == "1":
r[i] = j
break
for k in range(n):
if B[(i - k) % n] == "1":
l[i] = k
break
D = [0] * n
for m in range(n):
ret = 0
ss = []
for h in range(n):
if D[h]:
continue
if B[(m + h) % n]:
D[h] = 1
else:
r[h] -= 1
ss += l[h]
ss += r[h]
ss.sort()
ss *= 2
print(l, r)
| Statement
You have two strings A = A_1 A_2 ... A_n and B = B_1 B_2 ... B_n of the same
length consisting of 0 and 1.
You can transform A using the following operations in any order and as many
times as you want:
* Shift A by one character to the left (i.e., if A = A_1 A_2 ... A_n, replace A with A_2 A_3 ... A_n A_1).
* Shift A by one character to the right (i.e., if A = A_1 A_2 ... A_n, replace A with A_n A_1 A_2 ... A_{n-1}).
* Choose any i such that B_i = 1. Flip A_i (i.e., set A_i = 1 - A_i).
You goal is to make strings A and B equal.
Print the smallest number of operations required to achieve this, or -1 if the
goal is unreachable. | [{"input": "1010\n 1100", "output": "3\n \n\nHere is one fastest way to achieve the goal:\n\n * Flip A_1: A = 0010\n * Shift A to the left: A = 0100\n * Flip A_1 again: A = 1100\n\n* * *"}, {"input": "1\n 0", "output": "-1\n \n\nThere is no way to flip the only bit in A.\n\n* * *"}, {"input": "11010\n 10001", "output": "4\n \n\nHere is one fastest way to achieve the goal:\n\n * Shift A to the right: A = 01101\n * Flip A_5: A = 01100\n * Shift A to the left: A = 11000\n * Shift A to the left again: A = 10001\n\n* * *"}, {"input": "0100100\n 1111111", "output": "5\n \n\nFlip A_1, A_3, A_4, A_6 and A_7 in any order."}] |
Print the smallest number of operations required to make strings A and B
equal, or -1 if the goal is unreachable.
* * * | s719250891 | Wrong Answer | p03620 | Input is given from Standard Input in the following format:
A
B | A = input("")
B = input("")
def left(x):
return x[1:] + x[0]
def right(x):
return x[-1] + x[:-2]
def rev(x, y):
return bin(int(x, 2) ^ 1 << (len(x) - y + 1))
| Statement
You have two strings A = A_1 A_2 ... A_n and B = B_1 B_2 ... B_n of the same
length consisting of 0 and 1.
You can transform A using the following operations in any order and as many
times as you want:
* Shift A by one character to the left (i.e., if A = A_1 A_2 ... A_n, replace A with A_2 A_3 ... A_n A_1).
* Shift A by one character to the right (i.e., if A = A_1 A_2 ... A_n, replace A with A_n A_1 A_2 ... A_{n-1}).
* Choose any i such that B_i = 1. Flip A_i (i.e., set A_i = 1 - A_i).
You goal is to make strings A and B equal.
Print the smallest number of operations required to achieve this, or -1 if the
goal is unreachable. | [{"input": "1010\n 1100", "output": "3\n \n\nHere is one fastest way to achieve the goal:\n\n * Flip A_1: A = 0010\n * Shift A to the left: A = 0100\n * Flip A_1 again: A = 1100\n\n* * *"}, {"input": "1\n 0", "output": "-1\n \n\nThere is no way to flip the only bit in A.\n\n* * *"}, {"input": "11010\n 10001", "output": "4\n \n\nHere is one fastest way to achieve the goal:\n\n * Shift A to the right: A = 01101\n * Flip A_5: A = 01100\n * Shift A to the left: A = 11000\n * Shift A to the left again: A = 10001\n\n* * *"}, {"input": "0100100\n 1111111", "output": "5\n \n\nFlip A_1, A_3, A_4, A_6 and A_7 in any order."}] |
Print the number of people among the Takahashi's friends who can ride the
roller coaster.
* * * | s536804646 | Accepted | p02898 | Input is given from Standard Input in the following format:
N K
h_1 h_2 \ldots h_N | A, K = [int(x) for x in input().split()]
print(sum(int(x) >= K for x in input().split()))
| Statement
N friends of Takahashi has come to a theme park.
To ride the most popular roller coaster in the park, you must be at least K
centimeters tall.
The i-th friend is h_i centimeters tall.
How many of the Takahashi's friends can ride the roller coaster? | [{"input": "4 150\n 150 140 100 200", "output": "2\n \n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\n* * *"}, {"input": "1 500\n 499", "output": "0\n \n\n* * *"}, {"input": "5 1\n 100 200 300 400 500", "output": "5"}] |
Print the number of people among the Takahashi's friends who can ride the
roller coaster.
* * * | s409109980 | Accepted | p02898 | Input is given from Standard Input in the following format:
N K
h_1 h_2 \ldots h_N | n, k, *h = map(int, open(0).read().split())
print(sum(map(lambda x: x >= k, h)))
| Statement
N friends of Takahashi has come to a theme park.
To ride the most popular roller coaster in the park, you must be at least K
centimeters tall.
The i-th friend is h_i centimeters tall.
How many of the Takahashi's friends can ride the roller coaster? | [{"input": "4 150\n 150 140 100 200", "output": "2\n \n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\n* * *"}, {"input": "1 500\n 499", "output": "0\n \n\n* * *"}, {"input": "5 1\n 100 200 300 400 500", "output": "5"}] |
Print the number of people among the Takahashi's friends who can ride the
roller coaster.
* * * | s809196630 | Runtime Error | p02898 | Input is given from Standard Input in the following format:
N K
h_1 h_2 \ldots h_N | N, K = list(map(lambda n: int(n), input().split(" ")))
h = list(map(lambda x: int(n), input().split(" ")))
print(len(list(filter(lambda height: height >= K, h))))
| Statement
N friends of Takahashi has come to a theme park.
To ride the most popular roller coaster in the park, you must be at least K
centimeters tall.
The i-th friend is h_i centimeters tall.
How many of the Takahashi's friends can ride the roller coaster? | [{"input": "4 150\n 150 140 100 200", "output": "2\n \n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\n* * *"}, {"input": "1 500\n 499", "output": "0\n \n\n* * *"}, {"input": "5 1\n 100 200 300 400 500", "output": "5"}] |
Print the number of people among the Takahashi's friends who can ride the
roller coaster.
* * * | s801906487 | Runtime Error | p02898 | Input is given from Standard Input in the following format:
N K
h_1 h_2 \ldots h_N | N = input()
K = input()
N = int(N)
K = int(K)
high = list()
for i in range N-1:
F = input()
F = int(F)
high.append(F)
count = 0
for j in range N-1:
if high[j] >= K:
count+=1
print(count)
| Statement
N friends of Takahashi has come to a theme park.
To ride the most popular roller coaster in the park, you must be at least K
centimeters tall.
The i-th friend is h_i centimeters tall.
How many of the Takahashi's friends can ride the roller coaster? | [{"input": "4 150\n 150 140 100 200", "output": "2\n \n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\n* * *"}, {"input": "1 500\n 499", "output": "0\n \n\n* * *"}, {"input": "5 1\n 100 200 300 400 500", "output": "5"}] |
Print the number of people among the Takahashi's friends who can ride the
roller coaster.
* * * | s884656828 | Runtime Error | p02898 | Input is given from Standard Input in the following format:
N K
h_1 h_2 \ldots h_N | N = input()
K = input()
N = int(N)
K = int(K)
high = list()
for i in range N-1:
F = input()
F = int(F)
list[0] = F
count = 0
for j in range N-1:
if list[j] <= K:
count+=1
print(count)
| Statement
N friends of Takahashi has come to a theme park.
To ride the most popular roller coaster in the park, you must be at least K
centimeters tall.
The i-th friend is h_i centimeters tall.
How many of the Takahashi's friends can ride the roller coaster? | [{"input": "4 150\n 150 140 100 200", "output": "2\n \n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\n* * *"}, {"input": "1 500\n 499", "output": "0\n \n\n* * *"}, {"input": "5 1\n 100 200 300 400 500", "output": "5"}] |
Print the number of people among the Takahashi's friends who can ride the
roller coaster.
* * * | s817660730 | Runtime Error | p02898 | Input is given from Standard Input in the following format:
N K
h_1 h_2 \ldots h_N | N = input()
K = input()
A = int(N)
B = int(K)
j = 0
for i in range(1,A+1):
n = input()
a = int(n)
if a >= B:
j += 1
continue
else: continue
print(j) | Statement
N friends of Takahashi has come to a theme park.
To ride the most popular roller coaster in the park, you must be at least K
centimeters tall.
The i-th friend is h_i centimeters tall.
How many of the Takahashi's friends can ride the roller coaster? | [{"input": "4 150\n 150 140 100 200", "output": "2\n \n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\n* * *"}, {"input": "1 500\n 499", "output": "0\n \n\n* * *"}, {"input": "5 1\n 100 200 300 400 500", "output": "5"}] |
Print the number of people among the Takahashi's friends who can ride the
roller coaster.
* * * | s907772411 | Runtime Error | p02898 | Input is given from Standard Input in the following format:
N K
h_1 h_2 \ldots h_N | N ,K = input().strip().split()
N = int(N)
K = int(K)
a = list(map(int, input().strip().split()))
p = 0
for i range (N):
if a[i] >= K:
p += 1
print(p) | Statement
N friends of Takahashi has come to a theme park.
To ride the most popular roller coaster in the park, you must be at least K
centimeters tall.
The i-th friend is h_i centimeters tall.
How many of the Takahashi's friends can ride the roller coaster? | [{"input": "4 150\n 150 140 100 200", "output": "2\n \n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\n* * *"}, {"input": "1 500\n 499", "output": "0\n \n\n* * *"}, {"input": "5 1\n 100 200 300 400 500", "output": "5"}] |
Print the number of people among the Takahashi's friends who can ride the
roller coaster.
* * * | s965495942 | Runtime Error | p02898 | Input is given from Standard Input in the following format:
N K
h_1 h_2 \ldots h_N | n,k = map(int, input().split())
a = list(map(int, input(),split()))
ans = 0
for i in range(len(a):
if a[i] >= k:
ans += 1
print(ans) | Statement
N friends of Takahashi has come to a theme park.
To ride the most popular roller coaster in the park, you must be at least K
centimeters tall.
The i-th friend is h_i centimeters tall.
How many of the Takahashi's friends can ride the roller coaster? | [{"input": "4 150\n 150 140 100 200", "output": "2\n \n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\n* * *"}, {"input": "1 500\n 499", "output": "0\n \n\n* * *"}, {"input": "5 1\n 100 200 300 400 500", "output": "5"}] |
Print the number of people among the Takahashi's friends who can ride the
roller coaster.
* * * | s911468317 | Runtime Error | p02898 | Input is given from Standard Input in the following format:
N K
h_1 h_2 \ldots h_N | N, K = map(int, input().split())
l = list(map(int, input().split())
ans = 0
for i in range(len(l)):
if l[i] >= K
ans += 1
print(ans)
| Statement
N friends of Takahashi has come to a theme park.
To ride the most popular roller coaster in the park, you must be at least K
centimeters tall.
The i-th friend is h_i centimeters tall.
How many of the Takahashi's friends can ride the roller coaster? | [{"input": "4 150\n 150 140 100 200", "output": "2\n \n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\n* * *"}, {"input": "1 500\n 499", "output": "0\n \n\n* * *"}, {"input": "5 1\n 100 200 300 400 500", "output": "5"}] |
Print the number of people among the Takahashi's friends who can ride the
roller coaster.
* * * | s907082727 | Runtime Error | p02898 | Input is given from Standard Input in the following format:
N K
h_1 h_2 \ldots h_N | N, K = map(int, input().split())
List = list(map(int, input().split()))
count = 0
for i in List:
if i>=K:
count +=
print(count) | Statement
N friends of Takahashi has come to a theme park.
To ride the most popular roller coaster in the park, you must be at least K
centimeters tall.
The i-th friend is h_i centimeters tall.
How many of the Takahashi's friends can ride the roller coaster? | [{"input": "4 150\n 150 140 100 200", "output": "2\n \n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\n* * *"}, {"input": "1 500\n 499", "output": "0\n \n\n* * *"}, {"input": "5 1\n 100 200 300 400 500", "output": "5"}] |
Print the number of people among the Takahashi's friends who can ride the
roller coaster.
* * * | s261480395 | Accepted | p02898 | Input is given from Standard Input in the following format:
N K
h_1 h_2 \ldots h_N | (N, M) = (int(i) for i in input().split(" "))
print(sum([int(i) >= M for i in input().split()]))
| Statement
N friends of Takahashi has come to a theme park.
To ride the most popular roller coaster in the park, you must be at least K
centimeters tall.
The i-th friend is h_i centimeters tall.
How many of the Takahashi's friends can ride the roller coaster? | [{"input": "4 150\n 150 140 100 200", "output": "2\n \n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\n* * *"}, {"input": "1 500\n 499", "output": "0\n \n\n* * *"}, {"input": "5 1\n 100 200 300 400 500", "output": "5"}] |
Print the number of people among the Takahashi's friends who can ride the
roller coaster.
* * * | s990362259 | Runtime Error | p02898 | Input is given from Standard Input in the following format:
N K
h_1 h_2 \ldots h_N | def ri():
return int(input())
def rli():
return list(map(int, input().split()))
def rls():
return list(map(str, input().split()))
def pl(a):
print(" ".join(list(map(str, a))))
def ma():
return map(int, input().split())
def nli(x):
return [input for _ in range(x)]
def hukusuu():
listA = [] # appendのために宣言が必要
while True:
try:
listA.append(list(map(int, input().split())))
except:
break # または、quit(),os.exit()をして止める。
return listA
n, k = ma()
h = rli()
from itertools import accumulate, groupby as acc, gp
import operator as op
import copy as cp
import math
from bisect import bisect_left as bisl
from bisect import bisect_right as bisr
def ifif(s):
if s:
print("Yes")
else:
print("No")
h.sort()
inde = bisl(h, k)
print(n - inde)
| Statement
N friends of Takahashi has come to a theme park.
To ride the most popular roller coaster in the park, you must be at least K
centimeters tall.
The i-th friend is h_i centimeters tall.
How many of the Takahashi's friends can ride the roller coaster? | [{"input": "4 150\n 150 140 100 200", "output": "2\n \n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\n* * *"}, {"input": "1 500\n 499", "output": "0\n \n\n* * *"}, {"input": "5 1\n 100 200 300 400 500", "output": "5"}] |
Print the number of people among the Takahashi's friends who can ride the
roller coaster.
* * * | s074073465 | Accepted | p02898 | Input is given from Standard Input in the following format:
N K
h_1 h_2 \ldots h_N | N, K = list(map(int, input().split()))[:2]
height = list(map(int, input().split()))[:N]
able2ride = [a for a in height if a >= K]
print(len(able2ride))
| Statement
N friends of Takahashi has come to a theme park.
To ride the most popular roller coaster in the park, you must be at least K
centimeters tall.
The i-th friend is h_i centimeters tall.
How many of the Takahashi's friends can ride the roller coaster? | [{"input": "4 150\n 150 140 100 200", "output": "2\n \n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\n* * *"}, {"input": "1 500\n 499", "output": "0\n \n\n* * *"}, {"input": "5 1\n 100 200 300 400 500", "output": "5"}] |
Print the number of people among the Takahashi's friends who can ride the
roller coaster.
* * * | s241100673 | Accepted | p02898 | Input is given from Standard Input in the following format:
N K
h_1 h_2 \ldots h_N | n, k = list(map(int, input().split(" ")))
print(sum([tall >= k for tall in list(map(int, input().split(" ")))]))
| Statement
N friends of Takahashi has come to a theme park.
To ride the most popular roller coaster in the park, you must be at least K
centimeters tall.
The i-th friend is h_i centimeters tall.
How many of the Takahashi's friends can ride the roller coaster? | [{"input": "4 150\n 150 140 100 200", "output": "2\n \n\nTwo of them can ride the roller coaster: the first and fourth friends.\n\n* * *"}, {"input": "1 500\n 499", "output": "0\n \n\n* * *"}, {"input": "5 1\n 100 200 300 400 500", "output": "5"}] |
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer
for i=t+1.
* * * | s771423777 | Accepted | p03270 | Input is given from Standard Input in the following format:
K N | k, n = map(int, input().split())
mod = 998244353
max_n = 5000
fac, finv, inv = [0] * max_n, [0] * max_n, [0] * max_n
def comInit(max_n):
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, max_n):
fac[i] = fac[i - 1] * i % mod
inv[i] = mod - inv[mod % i] * (mod // i) % mod
finv[i] = finv[i - 1] * inv[i] % mod
comInit(max_n)
# 二項係数の計算
def com(n, k):
if n < k:
return 0
if (n < 0) | (k < 0):
return 0
return fac[n] * (finv[k] * finv[n - k] % mod) % mod
ex2 = [1] * 1010
for i in range(1, 1010):
ex2[i] = (ex2[i - 1] * 2) % mod
ans = []
for j in range(2, k + 2):
tmp = 0
x = (j - 1) // 2
for i in range(j // 2 + 1):
comb1 = com(n + k - j, n - i)
comb2 = (com(x, i) * ex2[i]) % mod
if j % 2 == 0:
comb1 += com(n + k - j - 1, n - i - 1)
comb1 %= mod
tmp += comb1 * comb2
tmp %= mod
ans.append(tmp)
ans2 = ans[:-1]
ans += ans2[::-1]
print("\n".join(map(str, ans)))
| Statement
Takahashi throws N dice, each having K sides with all integers from 1 to K.
The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the
following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are
considered different when there exists an integer k such that the number of
dice showing k is different in those two. | [{"input": "3 3", "output": "7\n 7\n 4\n 7\n 7\n \n\n * For i=2, the combinations (1,2,2),(1,2,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3) satisfy the condition, so the answer is 7.\n * For i=3, the combinations (1,1,1),(1,1,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3) satisfy the condition, so the answer is 7.\n * For i=4, the combinations (1,1,1),(1,1,2),(2,3,3),(3,3,3) satisfy the condition, so the answer is 4.\n\n* * *"}, {"input": "4 5", "output": "36\n 36\n 20\n 20\n 20\n 36\n 36\n \n\n* * *"}, {"input": "6 1000", "output": "149393349\n 149393349\n 668669001\n 668669001\n 4000002\n 4000002\n 4000002\n 668669001\n 668669001\n 149393349\n 149393349"}] |
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer
for i=t+1.
* * * | s234939043 | Runtime Error | p03270 | Input is given from Standard Input in the following format:
K N | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define f first
#define s second
ll MOD = 998244353;
ll INF = 1e15;
#define lb lower_bound
#define ub upper_bound
#define SZ(x) (ll)x.size()
#define ALL(x) x.begin(),x.end()
ll mod(ll a, ll m){
return (a+m)%m;
}
ll inverse(ll a, ll m){
a = mod(a, m);
if (a <= 1)return a;
return mod((1 - inverse(m, a) * m) / a,m);
}
ll N,K,tmp,l;
ll memo[2020][2020][2];
stack<ll> st;
ll ask(ll a, ll b, ll c){
// cout<<"Ask " << a << ' ' << b << '\n';
if (memo[a][b][c] != -1)return memo[a][b][c];
assert(b);
return memo[a][b][c] = (2*ask(a-1,b-1,c) - ask(a-2,b-1,c)) % MOD;
}
int main(){
// freopen("input.txt","r",stdin);
cin>>K>>N;
memset(memo,-1,sizeof(memo));
tmp = 1;
memo[0][0][0] = 0;
memo[1][0][0] = 1;
for (int i=2;i<=K;++i){
tmp = (tmp * (i+N-1)) % MOD;
tmp = (tmp * inverse(i-1, MOD)) % MOD;
memo[i][0][0] = tmp;
}
tmp = 1;
memo[0][0][1] = 0;
memo[1][0][1] = 1;
for (int i=2;i<=K;++i){
tmp = (tmp * (i+N-2)) % MOD;
tmp = (tmp * inverse(i-1, MOD)) % MOD;
memo[i][0][1] = tmp;
}
for (int i=2;i<=K+1;++i){
if (i % 2 == 0){
l = ask(K-1,(i-1)/2,0) + ask(K-1,(i-1)/2,1);
}
else l = ask(K,i/2,0);
cout<<l<<'\n';
st.push(l);
}
st.pop();
while(SZ(st)){cout<<st.top()<<'\n';st.pop();}
}
| Statement
Takahashi throws N dice, each having K sides with all integers from 1 to K.
The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the
following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are
considered different when there exists an integer k such that the number of
dice showing k is different in those two. | [{"input": "3 3", "output": "7\n 7\n 4\n 7\n 7\n \n\n * For i=2, the combinations (1,2,2),(1,2,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3) satisfy the condition, so the answer is 7.\n * For i=3, the combinations (1,1,1),(1,1,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3) satisfy the condition, so the answer is 7.\n * For i=4, the combinations (1,1,1),(1,1,2),(2,3,3),(3,3,3) satisfy the condition, so the answer is 4.\n\n* * *"}, {"input": "4 5", "output": "36\n 36\n 20\n 20\n 20\n 36\n 36\n \n\n* * *"}, {"input": "6 1000", "output": "149393349\n 149393349\n 668669001\n 668669001\n 4000002\n 4000002\n 4000002\n 668669001\n 668669001\n 149393349\n 149393349"}] |
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer
for i=t+1.
* * * | s871978340 | Wrong Answer | p03270 | Input is given from Standard Input in the following format:
K N | mod = 998244353
k, n = map(int, input().split())
def inv(a, mod):
r = [1, 0, a]
w = [0, 1, mod]
while w[2] != 1:
q = r[2] // w[2]
r_new = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]]
r = w
w = r_new
x, y = w[0], w[1] # a*x+y*mod = 1
return (mod + x % mod) % mod
max_num = 2 * 10**5 + 1
fact = [0 for _ in range(max_num)]
ifact = [0 for _ in range(max_num)]
fact[0] = fact[1] = 1
ifact[0] = ifact[1] = 1
for i in range(2, max_num):
fact[i] = fact[i - 1] * i % mod
ifact[max_num - 1] = inv(fact[max_num - 1], mod)
for i in range(2, max_num):
ifact[max_num - i] = (ifact[max_num - i + 1] * (max_num - i + 1)) % mod
def comb(x, y):
return fact[x] * ifact[y] * ifact[x - y] % mod
if k == 1:
print(0)
exit()
elif k == 2:
print(2)
print(2)
print(2)
exit()
for i in range(2, 2 * k + 1):
ans = 0
j = 1
while i - j > k:
j += 1
pair = 0
mid = 0
while j <= i - j:
if j != i - j:
pair += 1
else:
mid += 1
j += 1
if pair == 0:
ans += comb(n - 1 + k - 2, k - 2) + comb(n + k - 2, k - 2)
ans %= mod
else:
if mid == 0:
for i in range(pair + 1):
if k - 2 * pair + i == 0:
continue
ans += (
comb(pair, i)
* 2**i
* comb(n - i + k - 2 * pair + i - 1, k - 2 * pair + i - 1)
)
ans %= mod
else:
for i in range(pair + 1):
if k - 2 * pair - mid + i == 0:
continue
ans += (
comb(pair, i)
* 2**i
* comb(
n - i - 1 + k - 2 * pair - mid + i - 1,
k - 2 * pair - mid + i - 1,
)
)
ans += (
comb(pair, i)
* 2**i
* comb(
n - i + k - 2 * pair - mid + i - 1, k - 2 * pair - mid + i - 1
)
)
ans %= mod
print(ans)
| Statement
Takahashi throws N dice, each having K sides with all integers from 1 to K.
The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the
following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are
considered different when there exists an integer k such that the number of
dice showing k is different in those two. | [{"input": "3 3", "output": "7\n 7\n 4\n 7\n 7\n \n\n * For i=2, the combinations (1,2,2),(1,2,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3) satisfy the condition, so the answer is 7.\n * For i=3, the combinations (1,1,1),(1,1,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3) satisfy the condition, so the answer is 7.\n * For i=4, the combinations (1,1,1),(1,1,2),(2,3,3),(3,3,3) satisfy the condition, so the answer is 4.\n\n* * *"}, {"input": "4 5", "output": "36\n 36\n 20\n 20\n 20\n 36\n 36\n \n\n* * *"}, {"input": "6 1000", "output": "149393349\n 149393349\n 668669001\n 668669001\n 4000002\n 4000002\n 4000002\n 668669001\n 668669001\n 149393349\n 149393349"}] |
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer
for i=t+1.
* * * | s222126934 | Runtime Error | p03270 | Input is given from Standard Input in the following format:
K N | def check(Ncount, min, K, not_this, i):
count = 0
if Ncount == 0:
return 1
for x in range(min, K + 1):
if x in not_this:
continue
elif K >= (i - x) >= 1:
not_this.append(i - x)
count += check(Ncount - 1, x, K, not_this, i)
not_this.pop()
else:
count += check(Ncount - 1, x, K, not_this, i)
return count
K, N = [int(x) for x in input().split()]
for i in range(2, 2 * K):
not_this = []
print(check(N, 1, K, not_this, i))
| Statement
Takahashi throws N dice, each having K sides with all integers from 1 to K.
The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the
following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are
considered different when there exists an integer k such that the number of
dice showing k is different in those two. | [{"input": "3 3", "output": "7\n 7\n 4\n 7\n 7\n \n\n * For i=2, the combinations (1,2,2),(1,2,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3) satisfy the condition, so the answer is 7.\n * For i=3, the combinations (1,1,1),(1,1,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3) satisfy the condition, so the answer is 7.\n * For i=4, the combinations (1,1,1),(1,1,2),(2,3,3),(3,3,3) satisfy the condition, so the answer is 4.\n\n* * *"}, {"input": "4 5", "output": "36\n 36\n 20\n 20\n 20\n 36\n 36\n \n\n* * *"}, {"input": "6 1000", "output": "149393349\n 149393349\n 668669001\n 668669001\n 4000002\n 4000002\n 4000002\n 668669001\n 668669001\n 149393349\n 149393349"}] |
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer
for i=t+1.
* * * | s303913020 | Runtime Error | p03270 | Input is given from Standard Input in the following format:
K N | K, N = map(int, input().split())
mod = 998244353
table = [1] * (2 * N + 5)
t = 1
for i in range(1, 2 * N + 5):
t *= i
t %= mod
table[i] = t
rtable = [1] * (2 * N + 5)
t = 1
for i in range(1, 2 * N + 5):
t *= pow(i, mod - 2, mod)
t %= mod
rtable[i] = t
ans = []
for k in range(2, K + 2):
num = 0
if k % 2 == 1:
l = k // 2
p = l
r = K - 2 * l
for q in range(l + 1):
if N - q >= 0 and r + q - 1 >= 0:
s = (table[l] * rtable[q] * rtable[l - q]) % mod
s = (s * pow(2, q, mod)) % mod
t = (table[N + r - 1] * rtable[N - q] * rtable[r + q - 1]) % mod
s = (s * t) % mod
num += s
num = num % mod
# print(10,q,k,l,p,num,s)
ans.append(num)
else:
l = k // 2
p = l - 1
r = K - k + 1
for q in range(p + 1):
if N - q - 1 >= 0 and r + q - 1 >= 0:
s = (table[p] * rtable[q] * rtable[p - q]) % mod
s = (s * pow(2, q, mod)) % mod
t = (table[N + r - 2] * rtable[N - q - 1] * rtable[r + q - 1]) % mod
s = (s * t) % mod
num += s
num %= mod
# print(9,q,k,l,p,num,s)
if N - q >= 0 and r + q - 1 >= 0:
s = (table[p] * rtable[q] * rtable[p - q]) % mod
s = (s * pow(2, q, mod)) % mod
t = (table[N + r - 1] * rtable[N - q] * rtable[r + q - 1]) % mod
s = (s * t) % mod
num += s
num %= mod
# print(10,q,k,l,p,num,s)
ans.append(num)
print("\n".join(map(str, ans)))
ans = ans[::-1]
print("\n".join(map(str, ans[1:])))
| Statement
Takahashi throws N dice, each having K sides with all integers from 1 to K.
The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the
following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are
considered different when there exists an integer k such that the number of
dice showing k is different in those two. | [{"input": "3 3", "output": "7\n 7\n 4\n 7\n 7\n \n\n * For i=2, the combinations (1,2,2),(1,2,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3) satisfy the condition, so the answer is 7.\n * For i=3, the combinations (1,1,1),(1,1,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3) satisfy the condition, so the answer is 7.\n * For i=4, the combinations (1,1,1),(1,1,2),(2,3,3),(3,3,3) satisfy the condition, so the answer is 4.\n\n* * *"}, {"input": "4 5", "output": "36\n 36\n 20\n 20\n 20\n 36\n 36\n \n\n* * *"}, {"input": "6 1000", "output": "149393349\n 149393349\n 668669001\n 668669001\n 4000002\n 4000002\n 4000002\n 668669001\n 668669001\n 149393349\n 149393349"}] |
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer
for i=t+1.
* * * | s473577943 | Accepted | p03270 | Input is given from Standard Input in the following format:
K N | import sys
stdin = sys.stdin
def li():
return map(int, stdin.readline().split())
def li_():
return map(lambda x: int(x) - 1, stdin.readline().split())
def lf():
return map(float, stdin.readline().split())
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
# nの逆元のリスト
def inv_mod(n: int, mod: int) -> list:
inv = [0, 1]
for i in range(2, n + 1):
inv.append(mod - ((mod // i) * inv[mod % i]) % mod)
return inv
# nの階乗のリスト
def fact(n: int, mod: int) -> list:
fac = [1, 1]
res = 1
for i in range(2, n + 1):
res = res * i % mod
fac.append(res)
return fac
# nの階乗の逆元のリスト
def fact_inv(n: int, inv: list, mod: int) -> list:
facInv = [1, 1]
for i in range(2, n + 1):
facInv.append(facInv[i - 1] * inv[i] % mod)
return facInv
# 二項係数
def nCr(n: int, r: int, mod: int, fac: list, facInv: list) -> int:
if not (0 <= r and r <= n):
return 0
return ((fac[n] * facInv[r]) % mod) * facInv[n - r] % mod
MOD = 998244353
k, n = li()
inv = inv_mod(n + k, MOD)
fac = fact(n + k, MOD)
facInv = fact_inv(n + k, inv, MOD)
answers = []
if k == 1:
print(0)
else:
for t in range(2, k + 2):
p = t // 2
ans = 0
if t % 2 == 0:
temp = 0
for q in range(p):
temp = temp + nCr(p - 1, q, MOD, fac, facInv) * (2**q) * nCr(
n + k - 2 * p, n - q, MOD, fac, facInv
)
temp %= MOD
temp = temp + nCr(p - 1, q, MOD, fac, facInv) * (2**q) * nCr(
n + k - 2 * p - 1, n - q - 1, MOD, fac, facInv
)
temp %= MOD
ans = temp % MOD
else:
temp = 0
for q in range(p + 1):
temp = temp + nCr(p, q, MOD, fac, facInv) * (2**q) * nCr(
n + k - 2 * p - 1, n - q, MOD, fac, facInv
)
temp %= MOD
ans = temp % MOD
answers.append(ans)
print(ans)
for ans in answers[-2::-1]:
print(ans)
| Statement
Takahashi throws N dice, each having K sides with all integers from 1 to K.
The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the
following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are
considered different when there exists an integer k such that the number of
dice showing k is different in those two. | [{"input": "3 3", "output": "7\n 7\n 4\n 7\n 7\n \n\n * For i=2, the combinations (1,2,2),(1,2,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3) satisfy the condition, so the answer is 7.\n * For i=3, the combinations (1,1,1),(1,1,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3) satisfy the condition, so the answer is 7.\n * For i=4, the combinations (1,1,1),(1,1,2),(2,3,3),(3,3,3) satisfy the condition, so the answer is 4.\n\n* * *"}, {"input": "4 5", "output": "36\n 36\n 20\n 20\n 20\n 36\n 36\n \n\n* * *"}, {"input": "6 1000", "output": "149393349\n 149393349\n 668669001\n 668669001\n 4000002\n 4000002\n 4000002\n 668669001\n 668669001\n 149393349\n 149393349"}] |
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer
for i=t+1.
* * * | s649067241 | Accepted | p03270 | Input is given from Standard Input in the following format:
K N | K, N = map(int, input().split())
mod = 998244353
def inved(a):
x, y, u, v, k, l = 1, 0, 0, 1, a, mod
while l != 0:
x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
k, l = l, k % l
return x % mod
X = [0 for i in range(2 * K - 1)]
frac = [1]
for i in range(N + K):
frac.append(((i + 1) * frac[i]) % mod)
invf = []
for i in range(N + K + 1):
invf.append(inved(frac[i]))
for k in range(2, K + 2):
S = 0
sign = 1
l = k // 2
for m in range(min(l + 1, N // 2 + 1)):
prod = (sign * (frac[l] * frac[N + K - 2 * m - 1])) % mod
prod *= (invf[m] * invf[l - m]) % mod
prod %= mod
prod *= (invf[N - 2 * m] * invf[K - 1]) % mod
prod %= mod
S += prod
S %= mod
sign *= -1
X[k - 2], X[2 * K - k] = S, S
for i in range(2 * K - 1):
print(X[i])
| Statement
Takahashi throws N dice, each having K sides with all integers from 1 to K.
The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the
following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are
considered different when there exists an integer k such that the number of
dice showing k is different in those two. | [{"input": "3 3", "output": "7\n 7\n 4\n 7\n 7\n \n\n * For i=2, the combinations (1,2,2),(1,2,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3) satisfy the condition, so the answer is 7.\n * For i=3, the combinations (1,1,1),(1,1,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3) satisfy the condition, so the answer is 7.\n * For i=4, the combinations (1,1,1),(1,1,2),(2,3,3),(3,3,3) satisfy the condition, so the answer is 4.\n\n* * *"}, {"input": "4 5", "output": "36\n 36\n 20\n 20\n 20\n 36\n 36\n \n\n* * *"}, {"input": "6 1000", "output": "149393349\n 149393349\n 668669001\n 668669001\n 4000002\n 4000002\n 4000002\n 668669001\n 668669001\n 149393349\n 149393349"}] |
Print the minimum total cost to decrease Takahashi's expected profit by at
least 1 yen.
* * * | s818645047 | Accepted | p03948 | The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N | n, _, *a = map(int, open(0).read().split())
m = d = c = 0
for t in a[::-1]:
if t > m:
m = t
if m - t > d:
d = m - t
c = 1
elif m - t == d:
c += 1
print(c)
| Statement
There are N towns located in a line, conveniently numbered 1 through N.
Takahashi the merchant is going on a travel from town 1 to town N, buying and
selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession.
The actions that can be performed during the travel are as follows:
* _Move_ : When at town i (i < N), move to town i + 1.
* _Merchandise_ : Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the
travel: the sum of the number of apples bought and the number of apples sold
during the whole travel, must be at most T. (Note that a single apple can be
counted in both.)
During the travel, Takahashi will perform actions so that the _profit_ of the
travel is maximized. Here, the profit of the travel is the amount of money
that is gained by selling apples, minus the amount of money that is spent on
buying apples. Note that we are not interested in apples in his possession at
the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by
manipulating the market price of apples. Prior to the beginning of Takahashi's
travel, Aoki can change A_i into another arbitrary non-negative integer A_i'
for any town i, any number of times. The cost of performing this operation is
|A_i - A_i'|. After performing this operation, different towns may have equal
values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen.
Find the minimum total cost to achieve it. You may assume that Takahashi's
expected profit is initially at least 1 yen. | [{"input": "3 2\n 100 50 200", "output": "1\n \n\nIn the initial state, Takahashi can achieve the maximum profit of 150 yen as\nfollows:\n\n 1. Move from town 1 to town 2.\n 2. Buy one apple for 50 yen at town 2.\n 3. Move from town 2 to town 3.\n 4. Sell one apple for 200 yen at town 3.\n\nIf, for example, Aoki changes the price of an apple at town 2 from 50 yen to\n51 yen, Takahashi will not be able to achieve the profit of 150 yen. The cost\nof performing this operation is 1, thus the answer is 1.\n\nThere are other ways to decrease Takahashi's expected profit, such as changing\nthe price of an apple at town 3 from 200 yen to 199 yen.\n\n* * *"}, {"input": "5 8\n 50 30 40 10 20", "output": "2\n \n\n* * *"}, {"input": "10 100\n 7 10 4 5 9 3 6 8 2 1", "output": "2"}] |
Print the minimum total cost to decrease Takahashi's expected profit by at
least 1 yen.
* * * | s932892907 | Accepted | p03948 | The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N | import numpy as np
N, T = np.array(input().split(), dtype="int")
A = np.array(input().split(), dtype="int")
max_num = A[-1]
num_dict = {}
for i in range(len(A) - 1):
##print(A[-i-1],max_num - A[-i-2],num_dict)
if A[-i - 1] > max_num:
max_num = A[-i - 1]
if max_num > A[-i - 2]:
if max_num - A[-i - 2] in num_dict:
num_dict[max_num - A[-i - 2]] += 1
else:
num_dict[max_num - A[-i - 2]] = 1
key = max(num_dict.keys())
print(num_dict[key])
| Statement
There are N towns located in a line, conveniently numbered 1 through N.
Takahashi the merchant is going on a travel from town 1 to town N, buying and
selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession.
The actions that can be performed during the travel are as follows:
* _Move_ : When at town i (i < N), move to town i + 1.
* _Merchandise_ : Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the
travel: the sum of the number of apples bought and the number of apples sold
during the whole travel, must be at most T. (Note that a single apple can be
counted in both.)
During the travel, Takahashi will perform actions so that the _profit_ of the
travel is maximized. Here, the profit of the travel is the amount of money
that is gained by selling apples, minus the amount of money that is spent on
buying apples. Note that we are not interested in apples in his possession at
the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by
manipulating the market price of apples. Prior to the beginning of Takahashi's
travel, Aoki can change A_i into another arbitrary non-negative integer A_i'
for any town i, any number of times. The cost of performing this operation is
|A_i - A_i'|. After performing this operation, different towns may have equal
values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen.
Find the minimum total cost to achieve it. You may assume that Takahashi's
expected profit is initially at least 1 yen. | [{"input": "3 2\n 100 50 200", "output": "1\n \n\nIn the initial state, Takahashi can achieve the maximum profit of 150 yen as\nfollows:\n\n 1. Move from town 1 to town 2.\n 2. Buy one apple for 50 yen at town 2.\n 3. Move from town 2 to town 3.\n 4. Sell one apple for 200 yen at town 3.\n\nIf, for example, Aoki changes the price of an apple at town 2 from 50 yen to\n51 yen, Takahashi will not be able to achieve the profit of 150 yen. The cost\nof performing this operation is 1, thus the answer is 1.\n\nThere are other ways to decrease Takahashi's expected profit, such as changing\nthe price of an apple at town 3 from 200 yen to 199 yen.\n\n* * *"}, {"input": "5 8\n 50 30 40 10 20", "output": "2\n \n\n* * *"}, {"input": "10 100\n 7 10 4 5 9 3 6 8 2 1", "output": "2"}] |
Print the minimum total cost to decrease Takahashi's expected profit by at
least 1 yen.
* * * | s918612647 | Accepted | p03948 | The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N | from collections import Counter
N, T = map(int, input().split())
A = list(map(int, input().split()))
maxA = [0 for _ in range(N + 1)]
minA = [float("inf") for _ in range(N + 1)]
for i, a in enumerate(A):
minA[i + 1] = min(minA[i], a)
for i, a in enumerate(reversed(A)):
maxA[-1 - i] = max(maxA[-1 - (i - 1)], a)
maxProfit = 0
for i in range(1, N):
if maxProfit < maxA[i + 1] - minA[i]:
maxProfit = maxA[i + 1] - minA[i]
pairs = set([])
for i in range(1, N):
if maxProfit == maxA[i + 1] - minA[i]:
pairs.add((minA[i], maxA[i + 1]))
ans = len(pairs)
print(ans)
| Statement
There are N towns located in a line, conveniently numbered 1 through N.
Takahashi the merchant is going on a travel from town 1 to town N, buying and
selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession.
The actions that can be performed during the travel are as follows:
* _Move_ : When at town i (i < N), move to town i + 1.
* _Merchandise_ : Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the
travel: the sum of the number of apples bought and the number of apples sold
during the whole travel, must be at most T. (Note that a single apple can be
counted in both.)
During the travel, Takahashi will perform actions so that the _profit_ of the
travel is maximized. Here, the profit of the travel is the amount of money
that is gained by selling apples, minus the amount of money that is spent on
buying apples. Note that we are not interested in apples in his possession at
the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by
manipulating the market price of apples. Prior to the beginning of Takahashi's
travel, Aoki can change A_i into another arbitrary non-negative integer A_i'
for any town i, any number of times. The cost of performing this operation is
|A_i - A_i'|. After performing this operation, different towns may have equal
values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen.
Find the minimum total cost to achieve it. You may assume that Takahashi's
expected profit is initially at least 1 yen. | [{"input": "3 2\n 100 50 200", "output": "1\n \n\nIn the initial state, Takahashi can achieve the maximum profit of 150 yen as\nfollows:\n\n 1. Move from town 1 to town 2.\n 2. Buy one apple for 50 yen at town 2.\n 3. Move from town 2 to town 3.\n 4. Sell one apple for 200 yen at town 3.\n\nIf, for example, Aoki changes the price of an apple at town 2 from 50 yen to\n51 yen, Takahashi will not be able to achieve the profit of 150 yen. The cost\nof performing this operation is 1, thus the answer is 1.\n\nThere are other ways to decrease Takahashi's expected profit, such as changing\nthe price of an apple at town 3 from 200 yen to 199 yen.\n\n* * *"}, {"input": "5 8\n 50 30 40 10 20", "output": "2\n \n\n* * *"}, {"input": "10 100\n 7 10 4 5 9 3 6 8 2 1", "output": "2"}] |
Print the minimum total cost to decrease Takahashi's expected profit by at
least 1 yen.
* * * | s875525552 | Wrong Answer | p03948 | The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N | import collections
input()
a = [int(x) for x in input().split()]
lowest = 9999
diff = -1
diffcnt = 0
for x in a:
if diff == x - lowest:
diffcnt += 1
elif diff < x - lowest:
diffcnt = 1
diff = x - lowest
lowest = min(lowest, x)
print(diffcnt)
| Statement
There are N towns located in a line, conveniently numbered 1 through N.
Takahashi the merchant is going on a travel from town 1 to town N, buying and
selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession.
The actions that can be performed during the travel are as follows:
* _Move_ : When at town i (i < N), move to town i + 1.
* _Merchandise_ : Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the
travel: the sum of the number of apples bought and the number of apples sold
during the whole travel, must be at most T. (Note that a single apple can be
counted in both.)
During the travel, Takahashi will perform actions so that the _profit_ of the
travel is maximized. Here, the profit of the travel is the amount of money
that is gained by selling apples, minus the amount of money that is spent on
buying apples. Note that we are not interested in apples in his possession at
the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by
manipulating the market price of apples. Prior to the beginning of Takahashi's
travel, Aoki can change A_i into another arbitrary non-negative integer A_i'
for any town i, any number of times. The cost of performing this operation is
|A_i - A_i'|. After performing this operation, different towns may have equal
values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen.
Find the minimum total cost to achieve it. You may assume that Takahashi's
expected profit is initially at least 1 yen. | [{"input": "3 2\n 100 50 200", "output": "1\n \n\nIn the initial state, Takahashi can achieve the maximum profit of 150 yen as\nfollows:\n\n 1. Move from town 1 to town 2.\n 2. Buy one apple for 50 yen at town 2.\n 3. Move from town 2 to town 3.\n 4. Sell one apple for 200 yen at town 3.\n\nIf, for example, Aoki changes the price of an apple at town 2 from 50 yen to\n51 yen, Takahashi will not be able to achieve the profit of 150 yen. The cost\nof performing this operation is 1, thus the answer is 1.\n\nThere are other ways to decrease Takahashi's expected profit, such as changing\nthe price of an apple at town 3 from 200 yen to 199 yen.\n\n* * *"}, {"input": "5 8\n 50 30 40 10 20", "output": "2\n \n\n* * *"}, {"input": "10 100\n 7 10 4 5 9 3 6 8 2 1", "output": "2"}] |
Print the minimum total cost to decrease Takahashi's expected profit by at
least 1 yen.
* * * | s725857539 | Wrong Answer | p03948 | The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N | print(1)
| Statement
There are N towns located in a line, conveniently numbered 1 through N.
Takahashi the merchant is going on a travel from town 1 to town N, buying and
selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession.
The actions that can be performed during the travel are as follows:
* _Move_ : When at town i (i < N), move to town i + 1.
* _Merchandise_ : Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the
travel: the sum of the number of apples bought and the number of apples sold
during the whole travel, must be at most T. (Note that a single apple can be
counted in both.)
During the travel, Takahashi will perform actions so that the _profit_ of the
travel is maximized. Here, the profit of the travel is the amount of money
that is gained by selling apples, minus the amount of money that is spent on
buying apples. Note that we are not interested in apples in his possession at
the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by
manipulating the market price of apples. Prior to the beginning of Takahashi's
travel, Aoki can change A_i into another arbitrary non-negative integer A_i'
for any town i, any number of times. The cost of performing this operation is
|A_i - A_i'|. After performing this operation, different towns may have equal
values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen.
Find the minimum total cost to achieve it. You may assume that Takahashi's
expected profit is initially at least 1 yen. | [{"input": "3 2\n 100 50 200", "output": "1\n \n\nIn the initial state, Takahashi can achieve the maximum profit of 150 yen as\nfollows:\n\n 1. Move from town 1 to town 2.\n 2. Buy one apple for 50 yen at town 2.\n 3. Move from town 2 to town 3.\n 4. Sell one apple for 200 yen at town 3.\n\nIf, for example, Aoki changes the price of an apple at town 2 from 50 yen to\n51 yen, Takahashi will not be able to achieve the profit of 150 yen. The cost\nof performing this operation is 1, thus the answer is 1.\n\nThere are other ways to decrease Takahashi's expected profit, such as changing\nthe price of an apple at town 3 from 200 yen to 199 yen.\n\n* * *"}, {"input": "5 8\n 50 30 40 10 20", "output": "2\n \n\n* * *"}, {"input": "10 100\n 7 10 4 5 9 3 6 8 2 1", "output": "2"}] |
Print the minimum total cost to decrease Takahashi's expected profit by at
least 1 yen.
* * * | s793573135 | Accepted | p03948 | The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N | N, T = map(int, input().split())
(*A,) = map(int, input().split())
max_price = A[N - 1]
max_prof = 0
count = 1
for a in reversed(A[: N - 1]):
prof = max_price - a
if prof < 0:
max_price = a
elif prof == max_prof:
count += 1
elif prof > max_prof:
max_prof = prof
count = 1
print(count)
| Statement
There are N towns located in a line, conveniently numbered 1 through N.
Takahashi the merchant is going on a travel from town 1 to town N, buying and
selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession.
The actions that can be performed during the travel are as follows:
* _Move_ : When at town i (i < N), move to town i + 1.
* _Merchandise_ : Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the
travel: the sum of the number of apples bought and the number of apples sold
during the whole travel, must be at most T. (Note that a single apple can be
counted in both.)
During the travel, Takahashi will perform actions so that the _profit_ of the
travel is maximized. Here, the profit of the travel is the amount of money
that is gained by selling apples, minus the amount of money that is spent on
buying apples. Note that we are not interested in apples in his possession at
the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by
manipulating the market price of apples. Prior to the beginning of Takahashi's
travel, Aoki can change A_i into another arbitrary non-negative integer A_i'
for any town i, any number of times. The cost of performing this operation is
|A_i - A_i'|. After performing this operation, different towns may have equal
values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen.
Find the minimum total cost to achieve it. You may assume that Takahashi's
expected profit is initially at least 1 yen. | [{"input": "3 2\n 100 50 200", "output": "1\n \n\nIn the initial state, Takahashi can achieve the maximum profit of 150 yen as\nfollows:\n\n 1. Move from town 1 to town 2.\n 2. Buy one apple for 50 yen at town 2.\n 3. Move from town 2 to town 3.\n 4. Sell one apple for 200 yen at town 3.\n\nIf, for example, Aoki changes the price of an apple at town 2 from 50 yen to\n51 yen, Takahashi will not be able to achieve the profit of 150 yen. The cost\nof performing this operation is 1, thus the answer is 1.\n\nThere are other ways to decrease Takahashi's expected profit, such as changing\nthe price of an apple at town 3 from 200 yen to 199 yen.\n\n* * *"}, {"input": "5 8\n 50 30 40 10 20", "output": "2\n \n\n* * *"}, {"input": "10 100\n 7 10 4 5 9 3 6 8 2 1", "output": "2"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.